Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix corner case when the mesh parent node does not exist #2

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions gltf/gltfpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void finalizeBufferViews(std::string& json, std::vector<BufferView>& view

static void mesh_name_with_parent_node_info(const Mesh& mesh, std::string* mesh_name)
{
// compute a unique name for the mesh, since a parent node with a given name can have several meshes
// compute a unique name for the mesh, since a parent node with a given name can have several meshes
*mesh_name = std::string(mesh.parent_node_name) + "_" + std::to_string(mesh.index_in_parent_node);
}

Expand Down Expand Up @@ -196,6 +196,9 @@ static bool printMergeMetadata(const char* path, const std::vector<Mesh>& meshes
for (size_t i = 0; i < meshes.size(); ++i)
{
const Mesh& mesh = meshes[i];
if (!mesh.parent_node_name) {
continue;
}
std::string mesh_unique_name = std::string();
mesh_name_with_parent_node_info(mesh, &mesh_unique_name);

Expand Down Expand Up @@ -630,7 +633,7 @@ static void process(cgltf_data* data, const char* input_path, const char* output
const Mesh& mesh = meshes[i];

std::string mesh_name = std::string();
if (settings.keep_mesh_parent_nodes)
if (settings.keep_mesh_parent_nodes && mesh.parent_node_name)
{
mesh_name_with_parent_node_info(mesh, &mesh_name);
}
Expand Down
2 changes: 1 addition & 1 deletion gltf/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static void mergeMeshes(Mesh& target, const Mesh& mesh, const Settings& settings
for (size_t i = 0; i < index_count; ++i)
{
target.indices[index_offset + i] = unsigned(vertex_offset + mesh.indices[i]);
if (settings.keep_mesh_parent_nodes)
if (settings.keep_mesh_parent_nodes && mesh.parent_node_name)
{
target.merged_meshes_parent_node_info.push_back(std::pair<const char*, unsigned int>(mesh.parent_node_name, index_offset));
}
Expand Down