Created
September 11, 2018 00:17
-
-
Save ox/5b0a57d2c58156a799d9df603272d931 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Fbx2Raw.cpp b/src/Fbx2Raw.cpp | |
index a192d8e..df2afa8 100644 | |
--- a/src/Fbx2Raw.cpp | |
+++ b/src/Fbx2Raw.cpp | |
@@ -596,12 +596,14 @@ public: | |
const unsigned int blendShapeIx, | |
const unsigned int channelIx, | |
const FbxDouble deformPercent, | |
- const std::vector<TargetShape> &targetShapes | |
+ const std::vector<TargetShape> &targetShapes, | |
+ const std::string name | |
) : mesh(mesh), | |
blendShapeIx(blendShapeIx), | |
channelIx(channelIx), | |
deformPercent(deformPercent), | |
- targetShapes(targetShapes) | |
+ targetShapes(targetShapes), | |
+ name(name) | |
{} | |
FbxAnimCurve *ExtractAnimation(unsigned int animIx) const { | |
@@ -615,6 +617,7 @@ public: | |
const unsigned int blendShapeIx; | |
const unsigned int channelIx; | |
const std::vector<TargetShape> targetShapes; | |
+ const std::string name; | |
const FbxDouble deformPercent; | |
}; | |
@@ -649,11 +652,14 @@ private: | |
if (fbxChannel->GetTargetShapeCount() > 0) { | |
std::vector<TargetShape> targetShapes; | |
const double *fullWeights = fbxChannel->GetTargetShapeFullWeights(); | |
+ std::string name = std::string(fbxChannel->GetName()); | |
+ fmt::printf("extractChannels; channel name: %s\n", name); | |
+ | |
for (int targetIx = 0; targetIx < fbxChannel->GetTargetShapeCount(); targetIx ++) { | |
FbxShape *fbxShape = fbxChannel->GetTargetShape(targetIx); | |
targetShapes.push_back(TargetShape(fbxShape, fullWeights[targetIx])); | |
} | |
- channels.push_back(BlendChannel(mesh, shapeIx, channelIx, fbxChannel->DeformPercent * 0.01, targetShapes)); | |
+ channels.push_back(BlendChannel(mesh, shapeIx, channelIx, fbxChannel->DeformPercent * 0.01, targetShapes, name)); | |
} | |
} | |
} | |
@@ -785,11 +791,13 @@ static void ReadMesh(RawModel &raw, FbxScene *pScene, FbxNode *pNode, const std: | |
for (size_t targetIx = 0; targetIx < blendShapes.GetTargetShapeCount(channelIx); targetIx ++) { | |
const FbxBlendShapesAccess::TargetShape &shape = blendShapes.GetTargetShape(channelIx, targetIx); | |
targetShapes.push_back(&shape); | |
+ auto &blendChannel = blendShapes.GetBlendChannel(channelIx); | |
rawSurface.blendChannels.push_back(RawBlendChannel { | |
- static_cast<float>(blendShapes.GetBlendChannel(channelIx).deformPercent), | |
+ static_cast<float>(blendChannel.deformPercent), | |
shape.normals.LayerPresent(), | |
shape.tangents.LayerPresent(), | |
+ blendChannel.name | |
}); | |
} | |
} | |
diff --git a/src/Raw2Gltf.cpp b/src/Raw2Gltf.cpp | |
index 6931ac4..00a8171 100644 | |
--- a/src/Raw2Gltf.cpp | |
+++ b/src/Raw2Gltf.cpp | |
@@ -126,12 +126,22 @@ struct GLTFData | |
return result; | |
} | |
- | |
template<class T> | |
std::shared_ptr<AccessorData> AddAccessorWithView( | |
BufferViewData &bufferView, const GLType &type, const std::vector<T> &source) | |
{ | |
- auto accessor = accessors.hold(new AccessorData(bufferView, type)); | |
+ auto accessor = accessors.hold(new AccessorData(bufferView, type, std::string(""))); | |
+ accessor->appendAsBinaryArray(source, *binary); | |
+ bufferView.byteLength = accessor->byteLength(); | |
+ return accessor; | |
+ } | |
+ | |
+ | |
+ template<class T> | |
+ std::shared_ptr<AccessorData> AddAccessorWithView( | |
+ BufferViewData &bufferView, const GLType &type, const std::vector<T> &source, std::string name) | |
+ { | |
+ auto accessor = accessors.hold(new AccessorData(bufferView, type, name)); | |
accessor->appendAsBinaryArray(source, *binary); | |
bufferView.byteLength = accessor->byteLength(); | |
return accessor; | |
@@ -922,7 +932,7 @@ ModelData *Raw2Gltf( | |
} | |
std::shared_ptr<AccessorData> pAcc = gltf->AddAccessorWithView( | |
*gltf->GetAlignedBufferView(buffer, BufferViewData::GL_ARRAY_BUFFER), | |
- GLT_VEC3F, positions); | |
+ GLT_VEC3F, positions, channel.name); | |
pAcc->min = toStdVec(shapeBounds.min); | |
pAcc->max = toStdVec(shapeBounds.max); | |
@@ -930,14 +940,14 @@ ModelData *Raw2Gltf( | |
if (!normals.empty()) { | |
nAcc = gltf->AddAccessorWithView( | |
*gltf->GetAlignedBufferView(buffer, BufferViewData::GL_ARRAY_BUFFER), | |
- GLT_VEC3F, normals); | |
+ GLT_VEC3F, normals, channel.name); | |
} | |
std::shared_ptr<AccessorData> tAcc; | |
if (!tangents.empty()) { | |
nAcc = gltf->AddAccessorWithView( | |
*gltf->GetAlignedBufferView(buffer, BufferViewData::GL_ARRAY_BUFFER), | |
- GLT_VEC4F, tangents); | |
+ GLT_VEC4F, tangents, channel.name); | |
} | |
primitive->AddTarget(pAcc.get(), nAcc.get(), tAcc.get()); | |
diff --git a/src/RawModel.h b/src/RawModel.h | |
index 44bfccb..ac17dd6 100644 | |
--- a/src/RawModel.h | |
+++ b/src/RawModel.h | |
@@ -330,6 +330,7 @@ struct RawBlendChannel | |
float defaultDeform; | |
bool hasNormals; | |
bool hasTangents; | |
+ std::string name; | |
}; | |
struct RawSurface | |
diff --git a/src/glTF/AccessorData.cpp b/src/glTF/AccessorData.cpp | |
index 1f07650..7927289 100644 | |
--- a/src/glTF/AccessorData.cpp | |
+++ b/src/glTF/AccessorData.cpp | |
@@ -10,12 +10,13 @@ | |
#include "AccessorData.h" | |
#include "BufferViewData.h" | |
-AccessorData::AccessorData(const BufferViewData &bufferView, GLType type) | |
+AccessorData::AccessorData(const BufferViewData &bufferView, GLType type, std::string name) | |
: Holdable(), | |
bufferView(bufferView.ix), | |
type(std::move(type)), | |
byteOffset(0), | |
- count(0) | |
+ count(0), | |
+ name(name) | |
{ | |
} | |
@@ -45,5 +46,8 @@ json AccessorData::serialize() const | |
if (!max.empty()) { | |
result["max"] = max; | |
} | |
+ if (name.length() > 0) { | |
+ result["name"] = name; | |
+ } | |
return result; | |
} | |
diff --git a/src/glTF/AccessorData.h b/src/glTF/AccessorData.h | |
index 86f8f86..6daf5ec 100644 | |
--- a/src/glTF/AccessorData.h | |
+++ b/src/glTF/AccessorData.h | |
@@ -14,7 +14,7 @@ | |
struct AccessorData : Holdable | |
{ | |
- AccessorData(const BufferViewData &bufferView, GLType type); | |
+ AccessorData(const BufferViewData &bufferView, GLType type, std::string name); | |
explicit AccessorData(GLType type); | |
json serialize() const override; | |
@@ -43,6 +43,7 @@ struct AccessorData : Holdable | |
unsigned int count; | |
std::vector<float> min; | |
std::vector<float> max; | |
+ std::string name; | |
}; | |
#endif //FBX2GLTF_ACCESSORDATA_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment