storing blendshape names as extras in primitives

This commit is contained in:
Akash Garg 2018-04-12 14:55:48 -07:00
parent 3bfe56b71f
commit b77909fab9
5 changed files with 19 additions and 3 deletions

View File

@ -787,6 +787,7 @@ static void ReadMesh(RawModel &raw, FbxScene *pScene, FbxNode *pNode, const std:
static_cast<float>(blendShapes.GetBlendChannel(channelIx).deformPercent), static_cast<float>(blendShapes.GetBlendChannel(channelIx).deformPercent),
shape.normals.LayerPresent(), shape.normals.LayerPresent(),
shape.tangents.LayerPresent(), shape.tangents.LayerPresent(),
shape.shape->GetName()
}); });
} }
} }

View File

@ -940,7 +940,7 @@ ModelData *Raw2Gltf(
GLT_VEC4F, tangents); GLT_VEC4F, tangents);
} }
primitive->AddTarget(pAcc.get(), nAcc.get(), tAcc.get()); primitive->AddTarget(pAcc.get(), nAcc.get(), tAcc.get(), channel.name);
} }
} }
if (options.useDraco) { if (options.useDraco) {

View File

@ -320,6 +320,7 @@ struct RawBlendChannel
float defaultDeform; float defaultDeform;
bool hasNormals; bool hasNormals;
bool hasTangents; bool hasTangents;
std::string name;
}; };
struct RawSurface struct RawSurface

View File

@ -39,13 +39,16 @@ void PrimitiveData::NoteDracoBuffer(const BufferViewData &data)
dracoBufferView = data.ix; dracoBufferView = data.ix;
} }
void PrimitiveData::AddTarget(const AccessorData *positions, const AccessorData *normals, const AccessorData *tangents) void PrimitiveData::AddTarget(const AccessorData *positions, const AccessorData *normals, const AccessorData *tangents,
const std::string &shape_name)
{ {
targetAccessors.push_back(std::make_tuple( targetAccessors.push_back(std::make_tuple(
positions->ix, positions->ix,
normals ? normals->ix : -1, normals ? normals->ix : -1,
tangents ? tangents ->ix : -1 tangents ? tangents ->ix : -1
)); ));
targetNames.push_back(shape_name);
} }
void to_json(json &j, const PrimitiveData &d) { void to_json(json &j, const PrimitiveData &d) {
@ -70,6 +73,15 @@ void to_json(json &j, const PrimitiveData &d) {
} }
j["targets"] = targets; j["targets"] = targets;
} }
if (!d.targetNames.empty()) {
json extras {};
json names {};
for (const auto &name : d.targetNames) {
names.push_back(name);
}
extras["target_names"] = names;
j["extras"] = extras;
}
if (!d.dracoAttributes.empty()) { if (!d.dracoAttributes.empty()) {
j["extensions"] = { j["extensions"] = {
{ KHR_DRACO_MESH_COMPRESSION, { { KHR_DRACO_MESH_COMPRESSION, {

View File

@ -31,7 +31,8 @@ struct PrimitiveData
void AddAttrib(std::string name, const AccessorData &accessor); void AddAttrib(std::string name, const AccessorData &accessor);
void AddTarget(const AccessorData *positions, const AccessorData *normals, const AccessorData *tangents); void AddTarget(const AccessorData *positions, const AccessorData *normals, const AccessorData *tangents,
const std::string &name);
template<class T> template<class T>
void AddDracoAttrib(const AttributeDefinition<T> attribute, const std::vector<T> &attribArr) void AddDracoAttrib(const AttributeDefinition<T> attribute, const std::vector<T> &attribArr)
@ -62,6 +63,7 @@ struct PrimitiveData
const MeshMode mode; const MeshMode mode;
std::vector<std::tuple<int, int, int>> targetAccessors {}; std::vector<std::tuple<int, int, int>> targetAccessors {};
std::vector<std::string> targetNames {};
std::map<std::string, int> attributes; std::map<std::string, int> attributes;
std::map<std::string, int> dracoAttributes; std::map<std::string, int> dracoAttributes;