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

Bim 272 converter packed metadata from gltfpack and output metadata file #1

Prev Previous commit
Next Next commit
Factorize mesh unique identifier computation
  • Loading branch information
pirlande-fw committed Aug 28, 2024
commit 5721396f8f7e7df697d687bfb70309937f84d263
19 changes: 11 additions & 8 deletions gltf/gltfpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ 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
*mesh_name = std::string(mesh.parent_node_name) + "_" + std::to_string(mesh.index_in_parent_node);
}

static void printMeshStats(const std::vector<Mesh>& meshes, const char* name)
{
size_t mesh_triangles = 0;
Expand Down Expand Up @@ -188,12 +194,12 @@ 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];
// compute the unique key for the mesh, since a parent node with a given name can have several meshes
std::string mesh_unique_name = std::string(mesh.parent_node_name) + "_" + std::to_string(mesh.index_in_parent_node);
std::string mesh_unique_name = std::string();
mesh_name_with_parent_node_info(mesh, &mesh_unique_name);

comma(json);
append(json, "\"");
append(json, std::string(mesh.parent_node_name) + "_" + std::to_string(mesh.index_in_parent_node));
append(json, mesh_unique_name);
append(json, "\":{");

// the first mesh is the initial one, in which all others were merged into
Expand Down Expand Up @@ -618,12 +624,9 @@ static void process(cgltf_data* data, const char* input_path, const char* output
{
const Mesh& mesh = meshes[i];

//
const char* mesh_name = nullptr;
std::string mesh_name = std::string();
if (settings.keep_mesh_parent_nodes) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Allman style brackets

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

comma(json_meshes);
Expand Down
2 changes: 1 addition & 1 deletion gltf/gltfpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ void writeMeshAttributes(std::string& json, std::vector<BufferView>& views, std:
size_t writeMeshIndices(std::vector<BufferView>& views, std::string& json_accessors, size_t& accr_offset, const Mesh& mesh, const Settings& settings);
size_t writeJointBindMatrices(std::vector<BufferView>& views, std::string& json_accessors, size_t& accr_offset, const cgltf_skin& skin, const QuantizationPosition& qp, const Settings& settings);
size_t writeInstances(std::vector<BufferView>& views, std::string& json_accessors, size_t& accr_offset, const std::vector<Transform>& transforms, const QuantizationPosition& qp, const Settings& settings);
void writeMeshNode(std::string& json, size_t mesh_offset, const char* name, cgltf_node* node, cgltf_skin* skin, cgltf_data* data, const QuantizationPosition* qp);
void writeMeshNode(std::string& json, size_t mesh_offset, std::string& name, cgltf_node* node, cgltf_skin* skin, cgltf_data* data, const QuantizationPosition* qp);
void writeMeshNodeInstanced(std::string& json, size_t mesh_offset, size_t accr_offset);
void writeSkin(std::string& json, const cgltf_skin& skin, size_t matrix_accr, const std::vector<NodeInfo>& nodes, cgltf_data* data);
void writeNode(std::string& json, const cgltf_node& node, const std::vector<NodeInfo>& nodes, cgltf_data* data);
Expand Down
4 changes: 2 additions & 2 deletions gltf/write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1180,12 +1180,12 @@ size_t writeInstances(std::vector<BufferView>& views, std::string& json_accessor
return result;
}

void writeMeshNode(std::string& json, size_t mesh_offset, const char* name, cgltf_node* node, cgltf_skin* skin, cgltf_data* data, const QuantizationPosition* qp)
void writeMeshNode(std::string& json, size_t mesh_offset, std::string& name, cgltf_node* node, cgltf_skin* skin, cgltf_data* data, const QuantizationPosition* qp)
{
comma(json);
append(json, "{\"mesh\":");
append(json, mesh_offset);
if (name) {
if (!name.empty()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Allman

append(json, ",\"name\":\"");
append(json, name);
append(json, "\"");
Expand Down