mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-04-22 14:09:55 +08:00
Load inside the scene graph the gltf mesh (like the obj)
pivot is still invalid Signed-off by: Arthur Brainville (Ybalrid) <ybalrid@ybalrid.info>
This commit is contained in:
parent
aad6f06208
commit
2b10d88e42
@ -27,6 +27,11 @@ struct arrayAdapter {
|
|||||||
/// Stride in bytes between two elements
|
/// Stride in bytes between two elements
|
||||||
const size_t stride;
|
const size_t stride;
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
|
|
||||||
|
/// Construct an array adapter.
|
||||||
|
/// \param ptr Pointer to the start of the data, with offset applied
|
||||||
|
/// \param count Number of elements in the array
|
||||||
|
/// \param byte_stride Stride betweens elements in the array
|
||||||
arrayAdapter(const unsigned char *ptr, size_t count, size_t byte_stride = 1)
|
arrayAdapter(const unsigned char *ptr, size_t count, size_t byte_stride = 1)
|
||||||
: dataPtr(ptr), elemCount(count), stride(byte_stride) {}
|
: dataPtr(ptr), elemCount(count), stride(byte_stride) {}
|
||||||
|
|
||||||
@ -233,6 +238,7 @@ bool LoadGLTF(const std::string &filename, float scale,
|
|||||||
if (indicesArrayPtr)
|
if (indicesArrayPtr)
|
||||||
for (size_t i(0); i < indicesArrayPtr->size(); ++i) {
|
for (size_t i(0); i < indicesArrayPtr->size(); ++i) {
|
||||||
std::cout << indices[i] << " ";
|
std::cout << indices[i] << " ";
|
||||||
|
loadedMesh.faces.push_back(indices[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << '\n';
|
std::cout << '\n';
|
||||||
@ -263,11 +269,14 @@ bool LoadGLTF(const std::string &filename, float scale,
|
|||||||
/// 3D vector of float
|
/// 3D vector of float
|
||||||
v3fArray positions(
|
v3fArray positions(
|
||||||
arrayAdapter<v3f>(dataPtr, count, byte_stride));
|
arrayAdapter<v3f>(dataPtr, count, byte_stride));
|
||||||
for (size_t i{0}; i < indices.size(); ++i) {
|
for (size_t i{0}; i < positions.size(); ++i) {
|
||||||
const auto index(indices[i]);
|
const auto v = positions[i];
|
||||||
const auto v = positions[index];
|
|
||||||
std::cout << '(' << v.x << ", " << v.y << ", " << v.z
|
std::cout << '(' << v.x << ", " << v.y << ", " << v.z
|
||||||
<< ")\n";
|
<< ")\n";
|
||||||
|
|
||||||
|
loadedMesh.vertices.push_back(v.x * scale);
|
||||||
|
loadedMesh.vertices.push_back(v.y * scale);
|
||||||
|
loadedMesh.vertices.push_back(v.z * scale);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
@ -291,11 +300,14 @@ bool LoadGLTF(const std::string &filename, float scale,
|
|||||||
std::cout << "normal vec3\n";
|
std::cout << "normal vec3\n";
|
||||||
v3fArray normals(
|
v3fArray normals(
|
||||||
arrayAdapter<v3f>(dataPtr, count, byte_stride));
|
arrayAdapter<v3f>(dataPtr, count, byte_stride));
|
||||||
for (size_t i{0}; i < indices.size(); ++i) {
|
for (size_t i{0}; i < normals.size(); ++i) {
|
||||||
const auto index(indices[i]);
|
const auto v = normals[i];
|
||||||
const auto v = normals[index];
|
|
||||||
std::cout << '(' << v.x << ", " << v.y << ", " << v.z
|
std::cout << '(' << v.x << ", " << v.y << ", " << v.z
|
||||||
<< ")\n";
|
<< ")\n";
|
||||||
|
|
||||||
|
loadedMesh.facevarying_normals.push_back(v.x);
|
||||||
|
loadedMesh.facevarying_normals.push_back(v.y);
|
||||||
|
loadedMesh.facevarying_normals.push_back(v.z);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case TINYGLTF_TYPE_VEC4:
|
case TINYGLTF_TYPE_VEC4:
|
||||||
@ -329,9 +341,12 @@ bool LoadGLTF(const std::string &filename, float scale,
|
|||||||
std::cerr << "primitive is not triangle based, ignoring";
|
std::cerr << "primitive is not triangle based, ignoring";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << "LoadGLTF() function is not yet implemented!" << std::endl;
|
// TODO compute pivot point
|
||||||
return false;
|
meshes->push_back(loadedMesh);
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
// std::cerr << "LoadGLTF() function is not yet implemented!" << std::endl;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
} // namespace example
|
} // namespace example
|
||||||
|
@ -744,6 +744,17 @@ 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 =
|
||||||
|
LoadGLTF(gRenderConfig.gltf_filename, gRenderConfig.scene_scale,
|
||||||
|
&meshes, &materials, &textures);
|
||||||
|
if (!ret) {
|
||||||
|
// TODO handle error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gAsset.materials = materials;
|
gAsset.materials = materials;
|
||||||
gAsset.default_material = default_material;
|
gAsset.default_material = default_material;
|
||||||
@ -766,14 +777,6 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gRenderConfig.gltf_filename.empty()) {
|
|
||||||
std::cout << "Found gltf file : " << gRenderConfig.gltf_filename << "\n";
|
|
||||||
|
|
||||||
bool ret =
|
|
||||||
LoadGLTF(gRenderConfig.gltf_filename, gRenderConfig.scene_scale,
|
|
||||||
&meshes, &materials, &textures);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gScene.Commit()) {
|
if (!gScene.Commit()) {
|
||||||
std::cerr << "Failed to commit the scene." << std::endl;
|
std::cerr << "Failed to commit the scene." << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user