glTF nodes can only hold one mesh. this simply assigns to and check’s a Node’s Mesh
struct Node : public Object
{
std::vector< Ref<Node> > children;
- std::vector< Ref<Mesh> > meshes;
+ Ref<Mesh> mesh;
Nullable<mat4> matrix;
Nullable<vec3> translation;
}
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->meshes.push_back(meshRef);
+ if (meshRef) this->mesh = meshRef;
}
if (Value* camera = FindUInt(obj, "camera")) {
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);
*/
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) {
- meshNode = nodeIn;
- return true;
- }
+
+ if (nodeIn->mesh && meshID.compare(nodeIn->mesh->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;
}
}
CopyValue(n->mTransformation, node->matrix.value);
}
- for (unsigned int i = 0; i < n->mNumMeshes; ++i) {
- node->meshes.push_back(mAsset->meshes.Get(n->mMeshes[i]));
+ if (n->mNumMeshes > 0) {
+ node->mesh = mAsset->meshes.Get(n->mMeshes[0]);
}
for (unsigned int i = 0; i < n->mNumChildren; ++i) {
CopyValue(n->mTransformation, node->matrix.value);
}
- for (unsigned int i = 0; i < n->mNumMeshes; ++i) {
- node->meshes.push_back(mAsset->meshes.Get(n->mMeshes[i]));
+ if (n->mNumMeshes > 0) {
+ node->mesh = mAsset->meshes.Get(n->mMeshes[0]);
}
for (unsigned int i = 0; i < n->mNumChildren; ++i) {
}
}
- 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;
- ainode->mMeshes = new unsigned int[count];
+ if (node.mesh) {
+ ainode->mNumMeshes = 1;
+ ainode->mMeshes = new unsigned int[1];
int k = 0;
- 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;
- }
+ int idx = node.mesh.GetIndex();
+
+ for (unsigned int j = meshOffsets[idx]; j < meshOffsets[idx + 1]; ++j, ++k) {
+ ainode->mMeshes[k] = j;
}
}