Skip to content

Commit 15ebea7

Browse files
authored
Merge pull request #2 from Fieldwire/BIM-325-Converter-Fix-gltfpack-issue-on-some-models-with-unexpected-gltf-structure
Fix corner case when the mesh parent node does not exist
2 parents 8c9fa1b + 2577691 commit 15ebea7

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

gltf/gltfpack.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static void finalizeBufferViews(std::string& json, std::vector<BufferView>& view
7777

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

@@ -196,6 +196,9 @@ static bool printMergeMetadata(const char* path, const std::vector<Mesh>& meshes
196196
for (size_t i = 0; i < meshes.size(); ++i)
197197
{
198198
const Mesh& mesh = meshes[i];
199+
if (!mesh.parent_node_name) {
200+
continue;
201+
}
199202
std::string mesh_unique_name = std::string();
200203
mesh_name_with_parent_node_info(mesh, &mesh_unique_name);
201204

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

632635
std::string mesh_name = std::string();
633-
if (settings.keep_mesh_parent_nodes)
636+
if (settings.keep_mesh_parent_nodes && mesh.parent_node_name)
634637
{
635638
mesh_name_with_parent_node_info(mesh, &mesh_name);
636639
}

gltf/mesh.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ static void mergeMeshes(Mesh& target, const Mesh& mesh, const Settings& settings
260260
for (size_t i = 0; i < index_count; ++i)
261261
{
262262
target.indices[index_offset + i] = unsigned(vertex_offset + mesh.indices[i]);
263-
if (settings.keep_mesh_parent_nodes)
263+
if (settings.keep_mesh_parent_nodes && mesh.parent_node_name)
264264
{
265265
target.merged_meshes_parent_node_info.push_back(std::pair<const char*, unsigned int>(mesh.parent_node_name, index_offset));
266266
}

0 commit comments

Comments
 (0)