Fix gltf gen(WIP).

This commit is contained in:
Syoyo Fujita 2016-11-23 01:42:51 +09:00
parent 8ffc4e400d
commit 814b3fce56

View File

@ -792,12 +792,23 @@ static bool ConvertNodeToGLTF(picojson::object *out, const Node *node)
picojson::object json_node;
picojson::array json_xform;
picojson::array json_meshes;
for (size_t i = 0; i < 16; i++) {
json_xform.push_back(picojson::value(xform->xform[i]));
}
json_node["matrix"] = picojson::value(json_xform);
json_node["name"] = picojson::value(xform->name);
//json_xform["meshes"] = // TODO
if (xform->children.size() > 0) {
for (size_t i = 0; i < xform->children.size(); i++) {
if (dynamic_cast<const Mesh*>(xform->children[i])) {
json_meshes.push_back(picojson::value(xform->children[i]->name));
}
}
if (json_meshes.size() > 0) {
json_node["meshes"] = picojson::value(json_meshes);
}
}
picojson::array json_children;
if (xform->children.size() > 0) {
@ -1222,7 +1233,12 @@ static bool SaveSceneToGLTF(const std::string& output_filename,
root["assets"] = picojson::value(asset);
}
#if 0
// Mesh
picojson::object meshes;
std::map<std::string, const Mesh*>::const_iterator mesh_it(scene.mesh_map.begin());
for (; mesh_it != scene.mesh_map.end(); mesh_it++) {
const Mesh& mesh = *(mesh_it->second);
{
picojson::object buffers;
{
@ -1295,11 +1311,8 @@ static bool SaveSceneToGLTF(const std::string& output_filename,
picojson::object m;
m["primitives"] = picojson::value(primitive_array);
picojson::object meshes;
meshes["mesh_1"] = picojson::value(m);
meshes[mesh.name] = picojson::value(m);
root["meshes"] = picojson::value(meshes);
}
{
@ -1324,6 +1337,9 @@ static bool SaveSceneToGLTF(const std::string& output_filename,
root["accessors"] = picojson::value(accessors);
}
}
root["meshes"] = picojson::value(meshes);
{
// Use Default Material(Do not supply `material.technique`)
picojson::object default_material;
@ -1334,7 +1350,7 @@ static bool SaveSceneToGLTF(const std::string& output_filename,
root["materials"] = picojson::value(materials);
}
#endif
std::ofstream ifs(output_filename.c_str());
if (ifs.bad()) {
@ -1368,8 +1384,8 @@ static void FlattenCurves(Curves *flatten_curves, const Scene &scene)
}
#endif
// Flatten
void ConvertNodeToScene(Scene *scene, const Node *node)
// Flatten node tree.
static void ConvertNodeToScene(Scene *scene, const Node *node)
{
if (!node) return;