mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-04-22 22:20:01 +08:00
Use default material as the 1st material on the array
Signed-off by: Arthur Brainville (Ybalrid) <ybalrid@ybalrid.info>
This commit is contained in:
parent
7218e40bfd
commit
02fce26c6c
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"obj_filename": "cornellbox_suzanne.obj",
|
"commented_out_obj_filename": "cornellbox_suzanne.obj",
|
||||||
"gltf_filename": "../../models/Cube/Cube.gltf",
|
"gltf_filename": "../../models/Cube/Cube.gltf",
|
||||||
"scene_scale": 1.0,
|
"scene_scale": 1.0,
|
||||||
"width": 512,
|
"width": 512,
|
||||||
@ -20,4 +20,4 @@
|
|||||||
0
|
0
|
||||||
],
|
],
|
||||||
"dummy": 0
|
"dummy": 0
|
||||||
}
|
}
|
||||||
|
@ -736,6 +736,9 @@ int main(int argc, char **argv) {
|
|||||||
default_material.specular[1] = 0;
|
default_material.specular[1] = 0;
|
||||||
default_material.specular[2] = 0;
|
default_material.specular[2] = 0;
|
||||||
|
|
||||||
|
// Material pushed as first material on the list
|
||||||
|
materials.push_back(default_material);
|
||||||
|
|
||||||
if (!gRenderConfig.obj_filename.empty()) {
|
if (!gRenderConfig.obj_filename.empty()) {
|
||||||
bool ret = LoadObj(gRenderConfig.obj_filename, gRenderConfig.scene_scale,
|
bool ret = LoadObj(gRenderConfig.obj_filename, gRenderConfig.scene_scale,
|
||||||
&meshes, &materials, &textures);
|
&meshes, &materials, &textures);
|
||||||
@ -744,37 +747,38 @@ int main(int argc, char **argv) {
|
|||||||
<< " ]" << std::endl;
|
<< " ]" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!gRenderConfig.gltf_filename.empty()) {
|
}
|
||||||
std::cout << "Found gltf file : " << gRenderConfig.gltf_filename
|
|
||||||
<< "\n";
|
|
||||||
|
|
||||||
bool ret =
|
if (!gRenderConfig.gltf_filename.empty()) {
|
||||||
LoadGLTF(gRenderConfig.gltf_filename, gRenderConfig.scene_scale,
|
std::cout << "Found gltf file : " << gRenderConfig.gltf_filename << "\n";
|
||||||
&meshes, &materials, &textures);
|
|
||||||
if (!ret) {
|
bool ret =
|
||||||
// TODO handle error
|
LoadGLTF(gRenderConfig.gltf_filename, gRenderConfig.scene_scale,
|
||||||
}
|
&meshes, &materials, &textures);
|
||||||
|
if (!ret) {
|
||||||
|
std::cerr << "Failed to load glTF file [ "
|
||||||
|
<< gRenderConfig.gltf_filename << " ]" << std::endl;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gAsset.materials = materials;
|
gAsset.materials = materials;
|
||||||
gAsset.default_material = default_material;
|
gAsset.default_material = default_material;
|
||||||
gAsset.textures = textures;
|
gAsset.textures = textures;
|
||||||
|
|
||||||
for (size_t n = 0; n < meshes.size(); n++) {
|
for (size_t n = 0; n < meshes.size(); n++) {
|
||||||
size_t mesh_id = gAsset.meshes.size();
|
size_t mesh_id = gAsset.meshes.size();
|
||||||
gAsset.meshes.push_back(meshes[mesh_id]);
|
gAsset.meshes.push_back(meshes[mesh_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t n = 0; n < gAsset.meshes.size(); n++) {
|
for (size_t n = 0; n < gAsset.meshes.size(); n++) {
|
||||||
nanosg::Node<float, example::Mesh<float> > node(&gAsset.meshes[n]);
|
nanosg::Node<float, example::Mesh<float> > node(&gAsset.meshes[n]);
|
||||||
node.SetName(meshes[n].name);
|
node.SetName(meshes[n].name);
|
||||||
node.SetLocalXform(
|
node.SetLocalXform(meshes[n].pivot_xform); // Use mesh's pivot transform
|
||||||
meshes[n].pivot_xform); // Use mesh's pivot transform
|
// as node's local transform.
|
||||||
// as node's local transform.
|
gNodes.push_back(node);
|
||||||
gNodes.push_back(node);
|
|
||||||
|
|
||||||
gScene.AddNode(node);
|
gScene.AddNode(node);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gScene.Commit()) {
|
if (!gScene.Commit()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user