Commit a9cca557 authored by TheNumbat's avatar TheNumbat
Browse files

fix writing spheres with no mesh data

parent 5ecaca3a
...@@ -443,47 +443,49 @@ static void load_node(Scene &scobj, std::vector<std::string> &errors, ...@@ -443,47 +443,49 @@ static void load_node(Scene &scobj, std::vector<std::string> &errors,
Skeleton &skeleton = new_obj.armature; Skeleton &skeleton = new_obj.armature;
aiNode *arm_node = mesh->mBones[0]->mArmature; aiNode *arm_node = mesh->mBones[0]->mArmature;
{ if(arm_node) {
aiVector3D t, r, s; {
arm_node->mTransformation.Decompose(s, r, t); aiVector3D t, r, s;
skeleton.base() = aiVec(t); arm_node->mTransformation.Decompose(s, r, t);
} skeleton.base() = aiVec(t);
}
std::unordered_map<aiNode *, aiBone *> node_to_aibone;
for (unsigned int j = 0; j < mesh->mNumBones; j++) {
node_to_aibone[mesh->mBones[j]->mNode] = mesh->mBones[j];
}
std::function<void(Joint *, aiNode *)> build_tree; std::unordered_map<aiNode *, aiBone *> node_to_aibone;
build_tree = [&](Joint *p, aiNode *node) { for (unsigned int j = 0; j < mesh->mNumBones; j++) {
aiBone *bone = node_to_aibone[node]; node_to_aibone[mesh->mBones[j]->mNode] = mesh->mBones[j];
aiVector3D t, r, s; }
bone->mOffsetMatrix.Decompose(s, r, t);
std::string name(bone->mName.C_Str()); std::function<void(Joint *, aiNode *)> build_tree;
if (name.find("S3D-joint-IK") != std::string::npos) { build_tree = [&](Joint *p, aiNode *node) {
Skeleton::IK_Handle *h = skeleton.add_handle(aiVec(t), p); aiBone *bone = node_to_aibone[node];
h->enabled = bone->mWeights[0].mWeight > 1.0f; aiVector3D t, r, s;
} else { bone->mOffsetMatrix.Decompose(s, r, t);
Joint *c = skeleton.add_child(p, aiVec(t));
node_to_bone[node] = c; std::string name(bone->mName.C_Str());
c->pose = aiVec(r); if (name.find("S3D-joint-IK") != std::string::npos) {
c->radius = bone->mWeights[0].mWeight; Skeleton::IK_Handle *h = skeleton.add_handle(aiVec(t), p);
for (unsigned int j = 0; j < node->mNumChildren; j++) h->enabled = bone->mWeights[0].mWeight > 1.0f;
build_tree(c, node->mChildren[j]); } else {
Joint *c = skeleton.add_child(p, aiVec(t));
node_to_bone[node] = c;
c->pose = aiVec(r);
c->radius = bone->mWeights[0].mWeight;
for (unsigned int j = 0; j < node->mNumChildren; j++)
build_tree(c, node->mChildren[j]);
}
};
for (unsigned int j = 0; j < arm_node->mNumChildren; j++) {
aiNode *root_node = arm_node->mChildren[j];
aiBone *root_bone = node_to_aibone[root_node];
aiVector3D t, r, s;
root_bone->mOffsetMatrix.Decompose(s, r, t);
Joint *root = skeleton.add_root(aiVec(t));
node_to_bone[root_node] = root;
root->pose = aiVec(r);
root->radius = root_bone->mWeights[0].mWeight;
for (unsigned int k = 0; k < root_node->mNumChildren; k++)
build_tree(root, root_node->mChildren[k]);
} }
};
for (unsigned int j = 0; j < arm_node->mNumChildren; j++) {
aiNode *root_node = arm_node->mChildren[j];
aiBone *root_bone = node_to_aibone[root_node];
aiVector3D t, r, s;
root_bone->mOffsetMatrix.Decompose(s, r, t);
Joint *root = skeleton.add_root(aiVec(t));
node_to_bone[root_node] = root;
root->pose = aiVec(r);
root->radius = root_bone->mWeights[0].mWeight;
for (unsigned int k = 0; k < root_node->mNumChildren; k++)
build_tree(root, root_node->mChildren[k]);
} }
} }
...@@ -919,7 +921,7 @@ std::string Scene::write(std::string file, const Camera &render_cam, ...@@ -919,7 +921,7 @@ std::string Scene::write(std::string file, const Camera &render_cam,
face_idx++; face_idx++;
} }
} else if(obj.opt.shape_type == PT::Shape_Type::none) { } else {
const auto &verts = obj.mesh().verts(); const auto &verts = obj.mesh().verts();
const auto &elems = obj.mesh().indices(); const auto &elems = obj.mesh().indices();
...@@ -946,6 +948,7 @@ std::string Scene::write(std::string file, const Camera &render_cam, ...@@ -946,6 +948,7 @@ std::string Scene::write(std::string file, const Camera &render_cam,
face.mIndices[1] = elems[i + 1]; face.mIndices[1] = elems[i + 1];
face.mIndices[2] = elems[i + 2]; face.mIndices[2] = elems[i + 2];
} }
} }
std::string name(obj.opt.name); std::string name(obj.opt.name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment