Merge pull request #42 from Ybalrid/pr_raytrace_texture_loading

raytrace: add simple code that load texture data
This commit is contained in:
Syoyo Fujita 2018-03-03 00:55:58 +09:00 committed by GitHub
commit abf4bd1800
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,7 +60,7 @@ bool LoadGLTF(const std::string &filename, float scale,
<< model.scenes.size() << " scenes\n"
<< model.lights.size() << " lights\n";
// Iterate through all the meses in the glTF file
// Iterate through all the meshes in the glTF file
for (const auto &gltfMesh : model.meshes) {
std::cout << "Current mesh has " << gltfMesh.primitives.size()
<< " primitives:\n";
@ -469,9 +469,23 @@ bool LoadGLTF(const std::string &filename, float scale,
meshes->push_back(loadedMesh);
ret = true;
}
}
// Iterate through all texture declaration in glTF file
for (const auto &gltfTexture : model.textures) {
std::cout << "Found texture!";
Texture loadedTexture;
const auto &image = model.images[gltfTexture.source];
loadedTexture.components = image.component;
loadedTexture.width = image.width;
loadedTexture.height = image.height;
const auto size =
image.component * image.width * image.height * sizeof(unsigned char);
loadedTexture.image = new unsigned char[size];
memcpy(loadedTexture.image, image.image.data(), size);
textures->push_back(loadedTexture);
}
return ret;
}
} // namespace example