store node mesh vs. meshes

glTF nodes can only hold one mesh. this simply assigns to and check’s a Node’s Mesh
pull/1423/head
Daniel Hritzkiv 2017-09-01 17:56:13 -04:00
parent ab08a7c3cb
commit a0d97505e5
No known key found for this signature in database
GPG Key ID: D1D19875679D5CBF
5 changed files with 21 additions and 34 deletions

View File

@ -767,7 +767,7 @@ namespace glTF2
struct Node : public Object struct Node : public Object
{ {
std::vector< Ref<Node> > children; std::vector< Ref<Node> > children;
std::vector< Ref<Mesh> > meshes; Ref<Mesh> mesh;
Nullable<mat4> matrix; Nullable<mat4> matrix;
Nullable<vec3> translation; Nullable<vec3> translation;

View File

@ -954,16 +954,9 @@ inline void Node::Read(Value& obj, Asset& r)
} }
if (Value* mesh = FindUInt(obj, "mesh")) { 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()); Ref<Mesh> meshRef = r.meshes.Retrieve((*mesh).GetUint());
if (meshRef) this->meshes.push_back(meshRef); if (meshRef) this->mesh = meshRef;
} }
if (Value* camera = FindUInt(obj, "camera")) { if (Value* camera = FindUInt(obj, "camera")) {

View File

@ -441,7 +441,9 @@ namespace glTF2 {
AddRefsVector(obj, "children", n.children, w.mAl); AddRefsVector(obj, "children", n.children, w.mAl);
AddRefsVector(obj, "meshes", n.meshes, w.mAl); if (n.mesh) {
obj.AddMember("mesh", n.mesh->index, w.mAl);
}
AddRefsVector(obj, "skeletons", n.skeletons, w.mAl); AddRefsVector(obj, "skeletons", n.skeletons, w.mAl);

View File

@ -442,12 +442,11 @@ void glTF2Exporter::ExportMaterials()
*/ */
bool FindMeshNode(Ref<Node>& nodeIn, Ref<Node>& meshNode, std::string meshID) bool FindMeshNode(Ref<Node>& nodeIn, Ref<Node>& meshNode, std::string meshID)
{ {
for (unsigned int i = 0; i < nodeIn->meshes.size(); ++i) {
if (meshID.compare(nodeIn->meshes[i]->id) == 0) { if (nodeIn->mesh && meshID.compare(nodeIn->mesh->id) == 0) {
meshNode = nodeIn; meshNode = nodeIn;
return true; return true;
} }
}
for (unsigned int i = 0; i < nodeIn->children.size(); ++i) { for (unsigned int i = 0; i < nodeIn->children.size(); ++i) {
if(FindMeshNode(nodeIn->children[i], meshNode, meshID)) { if(FindMeshNode(nodeIn->children[i], meshNode, meshID)) {
@ -722,8 +721,8 @@ unsigned int glTF2Exporter::ExportNodeHierarchy(const aiNode* n)
CopyValue(n->mTransformation, node->matrix.value); CopyValue(n->mTransformation, node->matrix.value);
} }
for (unsigned int i = 0; i < n->mNumMeshes; ++i) { if (n->mNumMeshes > 0) {
node->meshes.push_back(mAsset->meshes.Get(n->mMeshes[i])); node->mesh = mAsset->meshes.Get(n->mMeshes[0]);
} }
for (unsigned int i = 0; i < n->mNumChildren; ++i) { for (unsigned int i = 0; i < n->mNumChildren; ++i) {
@ -751,8 +750,8 @@ unsigned int glTF2Exporter::ExportNode(const aiNode* n, Ref<Node>& parent)
CopyValue(n->mTransformation, node->matrix.value); CopyValue(n->mTransformation, node->matrix.value);
} }
for (unsigned int i = 0; i < n->mNumMeshes; ++i) { if (n->mNumMeshes > 0) {
node->meshes.push_back(mAsset->meshes.Get(n->mMeshes[i])); node->mesh = mAsset->meshes.Get(n->mMeshes[0]);
} }
for (unsigned int i = 0; i < n->mNumChildren; ++i) { for (unsigned int i = 0; i < n->mNumChildren; ++i) {

View File

@ -502,24 +502,17 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector<unsigned int>&
} }
} }
if (!node.meshes.empty()) { if (node.mesh) {
int count = 0; ainode->mNumMeshes = 1;
for (size_t i = 0; i < node.meshes.size(); ++i) { ainode->mMeshes = new unsigned int[1];
int idx = node.meshes[i].GetIndex();
count += meshOffsets[idx + 1] - meshOffsets[idx];
}
ainode->mNumMeshes = count;
ainode->mMeshes = new unsigned int[count];
int k = 0; int k = 0;
for (size_t i = 0; i < node.meshes.size(); ++i) { int idx = node.mesh.GetIndex();
int idx = node.meshes[i].GetIndex();
for (unsigned int j = meshOffsets[idx]; j < meshOffsets[idx + 1]; ++j, ++k) { for (unsigned int j = meshOffsets[idx]; j < meshOffsets[idx + 1]; ++j, ++k) {
ainode->mMeshes[k] = j; ainode->mMeshes[k] = j;
} }
} }
}
if (node.camera) { if (node.camera) {
pScene->mCameras[node.camera.GetIndex()]->mName = ainode->mName; pScene->mCameras[node.camera.GetIndex()]->mName = ainode->mName;