Optimized SubMesh to hold only used vertices #84

Merged
Bogdan Nagirniak merged 3 commits from BLEN-474 into hydra-render 2023-08-02 16:45:15 +02:00

Purpose

Following warning in Storm delegate could happen with multimaterials:
Invalid Hydra prim '/scene/O_000001C64A534808/SM_0001': Vertex primvar points has 42 elements, while its topology references only upto element index 40.

Technical steps

Moved vertices to MeshData::SubMesh. Optimized SubMesh to hold only used vertices.

### Purpose Following warning in Storm delegate could happen with multimaterials: `Invalid Hydra prim '/scene/O_000001C64A534808/SM_0001': Vertex primvar points has 42 elements, while its topology references only upto element index 40.` ### Technical steps Moved vertices to `MeshData::SubMesh`. Optimized SubMesh to hold only used vertices.
Bogdan Nagirniak added 1 commit 2023-08-02 03:56:09 +02:00
Bogdan Nagirniak requested review from Brecht Van Lommel 2023-08-02 03:56:29 +02:00
Bogdan Nagirniak requested review from Brian Savery (AMD) 2023-08-02 03:56:29 +02:00
Bogdan Nagirniak requested review from Georgiy Markelov 2023-08-02 03:56:29 +02:00
Bogdan Nagirniak requested review from Vasyl Pidhirskyi 2023-08-02 03:56:30 +02:00
Bogdan Nagirniak added 1 commit 2023-08-02 10:19:26 +02:00
Vasyl Pidhirskyi approved these changes 2023-08-02 12:08:06 +02:00
Brecht Van Lommel reviewed 2023-08-02 13:20:32 +02:00
@ -276,0 +283,4 @@
else {
/* Optimizing submeshes: getting only used vertices, rearranged indices */
for (SubMesh &sm : submeshes_) {
Map<int, int> index_map;
Collaborator

I would guess something like this is more efficient, instead of multiple loops and hash maps.

Vector<int> index_map(vertices.size(), 0);
for (int& face_vertex_index : sm.face_vertex_indices) {
  const int v = face_vertex_index;
  if (index_map[v] == 0) {
    sm.vertices.append(vertices[v]);
    index_map[v] = sm.vertices.size();
  }
  face_vertex_index = index_map[v] - 1;
}
I would guess something like this is more efficient, instead of multiple loops and hash maps. ``` Vector<int> index_map(vertices.size(), 0); for (int& face_vertex_index : sm.face_vertex_indices) { const int v = face_vertex_index; if (index_map[v] == 0) { sm.vertices.append(vertices[v]); index_map[v] = sm.vertices.size(); } face_vertex_index = index_map[v] - 1; } ```
Author
Owner

You are right, your algorithm is more efficient and faster, thank you.

You are right, your algorithm is more efficient and faster, thank you.
Bogdan Nagirniak added 1 commit 2023-08-02 14:17:28 +02:00
Georgiy Markelov approved these changes 2023-08-02 15:59:33 +02:00
Brecht Van Lommel approved these changes 2023-08-02 16:32:55 +02:00
Bogdan Nagirniak merged commit e35c1f5b6a into hydra-render 2023-08-02 16:45:15 +02:00
Sign in to join this conversation.
No Label
No Milestone
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: BogdanNagirniak/blender#84
No description provided.