parent
d473a49456
commit
5147acfe65
|
@ -781,7 +781,7 @@ namespace glTF2
|
|||
struct Node : public Object
|
||||
{
|
||||
std::vector< Ref<Node> > children;
|
||||
Ref<Mesh> mesh;
|
||||
std::vector< Ref<Mesh> > meshes;
|
||||
|
||||
Nullable<mat4> matrix;
|
||||
Nullable<vec3> translation;
|
||||
|
|
|
@ -934,9 +934,16 @@ inline void Node::Read(Value& obj, Asset& r)
|
|||
}
|
||||
|
||||
if (Value* mesh = FindUInt(obj, "mesh")) {
|
||||
//unsigned numMeshes = (unsigned)meshes->Size();
|
||||
unsigned numMeshes = 1;
|
||||
|
||||
//std::vector<unsigned int> meshList;
|
||||
|
||||
this->meshes.reserve(numMeshes);
|
||||
|
||||
Ref<Mesh> meshRef = r.meshes.Retrieve((*mesh).GetUint());
|
||||
|
||||
if (meshRef) this->mesh = meshRef;
|
||||
if (meshRef) this->meshes.push_back(meshRef);
|
||||
}
|
||||
|
||||
if (Value* camera = FindUInt(obj, "camera")) {
|
||||
|
|
|
@ -417,9 +417,7 @@ namespace glTF2 {
|
|||
|
||||
AddRefsVector(obj, "children", n.children, w.mAl);
|
||||
|
||||
if (n.mesh) {
|
||||
obj.AddMember("mesh", n.mesh->index, w.mAl);
|
||||
}
|
||||
AddRefsVector(obj, "meshes", n.meshes, w.mAl);
|
||||
|
||||
AddRefsVector(obj, "skeletons", n.skeletons, w.mAl);
|
||||
|
||||
|
|
|
@ -476,15 +476,16 @@ void glTF2Exporter::ExportMaterials()
|
|||
*/
|
||||
bool FindMeshNode(Ref<Node>& nodeIn, Ref<Node>& meshNode, std::string meshID)
|
||||
{
|
||||
|
||||
if (nodeIn->mesh && meshID.compare(nodeIn->mesh->id) == 0) {
|
||||
meshNode = nodeIn;
|
||||
return true;
|
||||
for (unsigned int i = 0; i < nodeIn->meshes.size(); ++i) {
|
||||
if (meshID.compare(nodeIn->meshes[i]->id) == 0) {
|
||||
meshNode = nodeIn;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < nodeIn->children.size(); ++i) {
|
||||
if(FindMeshNode(nodeIn->children[i], meshNode, meshID)) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -755,8 +756,8 @@ unsigned int glTF2Exporter::ExportNodeHierarchy(const aiNode* n)
|
|||
CopyValue(n->mTransformation, node->matrix.value);
|
||||
}
|
||||
|
||||
if (n->mNumMeshes > 0) {
|
||||
node->mesh = mAsset->meshes.Get(n->mMeshes[0]);
|
||||
for (unsigned int i = 0; i < n->mNumMeshes; ++i) {
|
||||
node->meshes.push_back(mAsset->meshes.Get(n->mMeshes[i]));
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < n->mNumChildren; ++i) {
|
||||
|
@ -784,8 +785,8 @@ unsigned int glTF2Exporter::ExportNode(const aiNode* n, Ref<Node>& parent)
|
|||
CopyValue(n->mTransformation, node->matrix.value);
|
||||
}
|
||||
|
||||
if (n->mNumMeshes > 0) {
|
||||
node->mesh = mAsset->meshes.Get(n->mMeshes[0]);
|
||||
for (unsigned int i = 0; i < n->mNumMeshes; ++i) {
|
||||
node->meshes.push_back(mAsset->meshes.Get(n->mMeshes[i]));
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < n->mNumChildren; ++i) {
|
||||
|
|
|
@ -517,24 +517,22 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector<unsigned int>&
|
|||
}
|
||||
}
|
||||
|
||||
if (node.mesh) {
|
||||
if (!node.meshes.empty()) {
|
||||
int count = 0;
|
||||
for (size_t i = 0; i < node.meshes.size(); ++i) {
|
||||
int idx = node.meshes[i].GetIndex();
|
||||
count += meshOffsets[idx + 1] - meshOffsets[idx];
|
||||
}
|
||||
ainode->mNumMeshes = count;
|
||||
|
||||
int idx = node.mesh.GetIndex();
|
||||
ainode->mMeshes = new unsigned int[count];
|
||||
|
||||
ai_assert(idx >= 0 && idx < meshOffsets.size());
|
||||
|
||||
unsigned int offBegin = meshOffsets[idx];
|
||||
unsigned int offEnd = meshOffsets[idx + 1];
|
||||
int k = 0;
|
||||
|
||||
ai_assert(offEnd >= offBegin);
|
||||
|
||||
ainode->mNumMeshes = offEnd - offBegin;
|
||||
ainode->mMeshes = new unsigned int[ainode->mNumMeshes];
|
||||
|
||||
for (unsigned int j = offBegin; j < offEnd; ++j, ++k) {
|
||||
ai_assert(k < ainode->mNumMeshes);
|
||||
ainode->mMeshes[k] = j;
|
||||
for (size_t i = 0; i < node.meshes.size(); ++i) {
|
||||
int idx = node.meshes[i].GetIndex();
|
||||
for (unsigned int j = meshOffsets[idx]; j < meshOffsets[idx + 1]; ++j, ++k) {
|
||||
ainode->mMeshes[k] = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue