Skip to content

Commit 718a4af

Browse files
Merge pull request #1062 from Geode-solutions/fix/bug_in_replace_component_meshes_identifier
fix(replace_components_meshes_by_others): Fixed bug when copying vert…
2 parents e01c8df + d2b4b3e commit 718a4af

File tree

2 files changed

+94
-5
lines changed

2 files changed

+94
-5
lines changed

src/geode/model/mixin/core/vertex_identifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ namespace geode
439439
{
440440
return impl_->component_mesh_vertices( unique_vertex_id );
441441
}
442+
442443
index_t VertexIdentifier::unique_vertex(
443444
const ComponentMeshVertex& component_mesh_vertex ) const
444445
{

src/geode/model/representation/builder/brep_builder.cpp

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,71 @@
4747
#include <geode/model/representation/builder/detail/copy.hpp>
4848
#include <geode/model/representation/core/brep.hpp>
4949

50+
namespace
51+
{
52+
void remove_component_meshes_in_mapping( const geode::BRep& brep,
53+
geode::BRepBuilder& builder,
54+
const geode::ModelCopyMapping& mapping )
55+
{
56+
for( const auto& in2out :
57+
mapping.at( geode::Corner3D::component_type_static() )
58+
.in2out_map() )
59+
{
60+
builder.update_corner_mesh(
61+
brep.corner( in2out.first ), geode::PointSet3D::create() );
62+
}
63+
for( const auto& in2out :
64+
mapping.at( geode::Line3D::component_type_static() ).in2out_map() )
65+
{
66+
builder.update_line_mesh(
67+
brep.line( in2out.first ), geode::EdgedCurve3D::create() );
68+
}
69+
for( const auto& in2out :
70+
mapping.at( geode::Surface3D::component_type_static() )
71+
.in2out_map() )
72+
{
73+
builder.update_surface_mesh(
74+
brep.surface( in2out.first ), geode::SurfaceMesh3D::create() );
75+
}
76+
for( const auto& in2out :
77+
mapping.at( geode::Block3D::component_type_static() ).in2out_map() )
78+
{
79+
builder.update_block_mesh(
80+
brep.block( in2out.first ), geode::SolidMesh3D::create() );
81+
}
82+
}
83+
84+
template < typename Mesh >
85+
absl::FixedArray< geode::index_t > save_mesh_unique_vertices(
86+
const geode::BRep& model,
87+
const Mesh& mesh,
88+
const geode::ComponentID& component_id )
89+
{
90+
const auto nb_vertices = mesh.nb_vertices();
91+
absl::FixedArray< geode::index_t > unique_vertices( nb_vertices );
92+
for( const auto v : geode::Range{ nb_vertices } )
93+
{
94+
unique_vertices[v] = model.unique_vertex( { component_id, v } );
95+
}
96+
return unique_vertices;
97+
}
98+
99+
void set_mesh_unique_vertices( geode::BRepBuilder& builder,
100+
absl::Span< const geode::index_t > unique_vertices,
101+
const geode::ComponentID& component_id,
102+
geode::index_t first_new_unique_vertex )
103+
{
104+
for( const auto v : geode::Indices{ unique_vertices } )
105+
{
106+
if( unique_vertices[v] != geode::NO_ID )
107+
{
108+
builder.set_unique_vertex( { component_id, v },
109+
first_new_unique_vertex + unique_vertices[v] );
110+
}
111+
}
112+
}
113+
} // namespace
114+
50115
namespace geode
51116
{
52117
BRepBuilder::BRepBuilder( BRep& brep )
@@ -85,39 +150,62 @@ namespace geode
85150
BRep&& other, const ModelCopyMapping& mapping )
86151
{
87152
BRepBuilder other_builder{ other };
153+
remove_component_meshes_in_mapping( brep_, *this, mapping );
154+
this->delete_isolated_vertices();
155+
const auto first_new_unique_vertex_id =
156+
create_unique_vertices( other.nb_unique_vertices() );
88157
for( const auto& in2out :
89158
mapping.at( Corner3D::component_type_static() ).in2out_map() )
90159
{
160+
const auto corner_unique_vertices = save_mesh_unique_vertices(
161+
other, other.corner( in2out.second ).mesh(),
162+
other.corner( in2out.second ).component_id() );
91163
this->update_corner_mesh( brep_.corner( in2out.first ),
92164
other_builder.steal_corner_mesh( in2out.second ) );
93165
this->corner_mesh_builder( in2out.first )->set_id( in2out.first );
166+
set_mesh_unique_vertices( *this, corner_unique_vertices,
167+
brep_.corner( in2out.first ).component_id(),
168+
first_new_unique_vertex_id );
94169
}
95170
for( const auto& in2out :
96171
mapping.at( Line3D::component_type_static() ).in2out_map() )
97172
{
173+
const auto line_unique_vertices = save_mesh_unique_vertices( other,
174+
other.line( in2out.second ).mesh(),
175+
other.line( in2out.second ).component_id() );
98176
this->update_line_mesh( brep_.line( in2out.first ),
99177
other_builder.steal_line_mesh( in2out.second ) );
100178
this->line_mesh_builder( in2out.first )->set_id( in2out.first );
179+
set_mesh_unique_vertices( *this, line_unique_vertices,
180+
brep_.line( in2out.first ).component_id(),
181+
first_new_unique_vertex_id );
101182
}
102183
for( const auto& in2out :
103184
mapping.at( Surface3D::component_type_static() ).in2out_map() )
104185
{
186+
const auto surface_unique_vertices = save_mesh_unique_vertices(
187+
other, other.surface( in2out.second ).mesh(),
188+
other.surface( in2out.second ).component_id() );
105189
this->update_surface_mesh( brep_.surface( in2out.first ),
106190
other_builder.steal_surface_mesh( in2out.second ) );
107191
this->surface_mesh_builder( in2out.first )->set_id( in2out.first );
192+
set_mesh_unique_vertices( *this, surface_unique_vertices,
193+
brep_.surface( in2out.first ).component_id(),
194+
first_new_unique_vertex_id );
108195
}
109196
for( const auto& in2out :
110197
mapping.at( Block3D::component_type_static() ).in2out_map() )
111198
{
199+
const auto block_unique_vertices = save_mesh_unique_vertices( other,
200+
other.block( in2out.second ).mesh(),
201+
other.block( in2out.second ).component_id() );
112202
this->update_block_mesh( brep_.block( in2out.first ),
113203
other_builder.steal_block_mesh( in2out.second ) );
114204
this->block_mesh_builder( in2out.first )->set_id( in2out.first );
205+
set_mesh_unique_vertices( *this, block_unique_vertices,
206+
brep_.block( in2out.first ).component_id(),
207+
first_new_unique_vertex_id );
115208
}
116-
this->delete_isolated_vertices();
117-
const auto first_new_unique_vertex_id =
118-
create_unique_vertices( other.nb_unique_vertices() );
119-
detail::copy_vertex_identifier_components(
120-
other, *this, first_new_unique_vertex_id, mapping );
121209
}
122210

123211
ModelCopyMapping BRepBuilder::copy_components( const BRep& brep )

0 commit comments

Comments
 (0)