mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-12 04:29:05 +08:00
Fix gltf gen(WIP).
This commit is contained in:
parent
8ffc4e400d
commit
814b3fce56
@ -792,12 +792,23 @@ static bool ConvertNodeToGLTF(picojson::object *out, const Node *node)
|
|||||||
|
|
||||||
picojson::object json_node;
|
picojson::object json_node;
|
||||||
picojson::array json_xform;
|
picojson::array json_xform;
|
||||||
|
picojson::array json_meshes;
|
||||||
for (size_t i = 0; i < 16; i++) {
|
for (size_t i = 0; i < 16; i++) {
|
||||||
json_xform.push_back(picojson::value(xform->xform[i]));
|
json_xform.push_back(picojson::value(xform->xform[i]));
|
||||||
}
|
}
|
||||||
json_node["matrix"] = picojson::value(json_xform);
|
json_node["matrix"] = picojson::value(json_xform);
|
||||||
json_node["name"] = picojson::value(xform->name);
|
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;
|
picojson::array json_children;
|
||||||
if (xform->children.size() > 0) {
|
if (xform->children.size() > 0) {
|
||||||
@ -1222,7 +1233,12 @@ static bool SaveSceneToGLTF(const std::string& output_filename,
|
|||||||
root["assets"] = picojson::value(asset);
|
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;
|
picojson::object buffers;
|
||||||
{
|
{
|
||||||
@ -1295,11 +1311,8 @@ static bool SaveSceneToGLTF(const std::string& output_filename,
|
|||||||
picojson::object m;
|
picojson::object m;
|
||||||
m["primitives"] = picojson::value(primitive_array);
|
m["primitives"] = picojson::value(primitive_array);
|
||||||
|
|
||||||
picojson::object meshes;
|
meshes[mesh.name] = picojson::value(m);
|
||||||
meshes["mesh_1"] = 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["accessors"] = picojson::value(accessors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
root["meshes"] = picojson::value(meshes);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Use Default Material(Do not supply `material.technique`)
|
// Use Default Material(Do not supply `material.technique`)
|
||||||
picojson::object default_material;
|
picojson::object default_material;
|
||||||
@ -1334,7 +1350,7 @@ static bool SaveSceneToGLTF(const std::string& output_filename,
|
|||||||
root["materials"] = picojson::value(materials);
|
root["materials"] = picojson::value(materials);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
std::ofstream ifs(output_filename.c_str());
|
std::ofstream ifs(output_filename.c_str());
|
||||||
if (ifs.bad()) {
|
if (ifs.bad()) {
|
||||||
@ -1368,8 +1384,8 @@ static void FlattenCurves(Curves *flatten_curves, const Scene &scene)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Flatten
|
// Flatten node tree.
|
||||||
void ConvertNodeToScene(Scene *scene, const Node *node)
|
static void ConvertNodeToScene(Scene *scene, const Node *node)
|
||||||
{
|
{
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user