Use default material as the 1st material on the array

Signed-off by: Arthur Brainville (Ybalrid) <ybalrid@ybalrid.info>
This commit is contained in:
Arthur Brainville (Ybalrid) 2018-02-20 14:25:46 +01:00 committed by Arthur Brainville
parent 7218e40bfd
commit 02fce26c6c
No known key found for this signature in database
GPG Key ID: BC05C4812A06BCF3
2 changed files with 31 additions and 27 deletions

View File

@ -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,

View File

@ -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,15 +747,18 @@ int main(int argc, char **argv) {
<< " ]" << std::endl; << " ]" << std::endl;
return -1; return -1;
} }
}
if (!gRenderConfig.gltf_filename.empty()) { if (!gRenderConfig.gltf_filename.empty()) {
std::cout << "Found gltf file : " << gRenderConfig.gltf_filename std::cout << "Found gltf file : " << gRenderConfig.gltf_filename << "\n";
<< "\n";
bool ret = bool ret =
LoadGLTF(gRenderConfig.gltf_filename, gRenderConfig.scene_scale, LoadGLTF(gRenderConfig.gltf_filename, gRenderConfig.scene_scale,
&meshes, &materials, &textures); &meshes, &materials, &textures);
if (!ret) { if (!ret) {
// TODO handle error std::cerr << "Failed to load glTF file [ "
<< gRenderConfig.gltf_filename << " ]" << std::endl;
return -1;
} }
} }
@ -768,14 +774,12 @@ int main(int argc, char **argv) {
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()) {
std::cerr << "Failed to commit the scene." << std::endl; std::cerr << "Failed to commit the scene." << std::endl;