|
47 | 47 | #include <geode/model/representation/builder/detail/copy.hpp> |
48 | 48 | #include <geode/model/representation/builder/detail/register.hpp> |
49 | 49 | #include <geode/model/representation/core/brep.hpp> |
50 | | - |
51 | | -namespace |
52 | | -{ |
53 | | - void remove_component_meshes_in_mapping( const geode::BRep& brep, |
54 | | - geode::BRepBuilder& builder, |
55 | | - const geode::ModelCopyMapping& mapping ) |
56 | | - { |
57 | | - for( const auto& in2out : |
58 | | - mapping.at( geode::Corner3D::component_type_static() ) |
59 | | - .in2out_map() ) |
60 | | - { |
61 | | - builder.update_corner_mesh( |
62 | | - brep.corner( in2out.first ), geode::PointSet3D::create() ); |
63 | | - } |
64 | | - for( const auto& in2out : |
65 | | - mapping.at( geode::Line3D::component_type_static() ).in2out_map() ) |
66 | | - { |
67 | | - builder.update_line_mesh( |
68 | | - brep.line( in2out.first ), geode::EdgedCurve3D::create() ); |
69 | | - } |
70 | | - for( const auto& in2out : |
71 | | - mapping.at( geode::Surface3D::component_type_static() ) |
72 | | - .in2out_map() ) |
73 | | - { |
74 | | - builder.update_surface_mesh( |
75 | | - brep.surface( in2out.first ), geode::SurfaceMesh3D::create() ); |
76 | | - } |
77 | | - for( const auto& in2out : |
78 | | - mapping.at( geode::Block3D::component_type_static() ).in2out_map() ) |
79 | | - { |
80 | | - builder.update_block_mesh( |
81 | | - brep.block( in2out.first ), geode::SolidMesh3D::create() ); |
82 | | - } |
83 | | - } |
84 | | - |
85 | | - template < typename Mesh > |
86 | | - absl::FixedArray< geode::index_t > save_mesh_unique_vertices( |
87 | | - const geode::BRep& model, |
88 | | - const Mesh& mesh, |
89 | | - const geode::ComponentID& component_id ) |
90 | | - { |
91 | | - const auto nb_vertices = mesh.nb_vertices(); |
92 | | - absl::FixedArray< geode::index_t > unique_vertices( nb_vertices ); |
93 | | - for( const auto v : geode::Range{ nb_vertices } ) |
94 | | - { |
95 | | - unique_vertices[v] = model.unique_vertex( { component_id, v } ); |
96 | | - } |
97 | | - return unique_vertices; |
98 | | - } |
99 | | - |
100 | | - void set_mesh_unique_vertices( geode::BRepBuilder& builder, |
101 | | - absl::Span< const geode::index_t > unique_vertices, |
102 | | - const geode::ComponentID& component_id, |
103 | | - geode::index_t first_new_unique_vertex ) |
104 | | - { |
105 | | - for( const auto v : geode::Indices{ unique_vertices } ) |
106 | | - { |
107 | | - if( unique_vertices[v] != geode::NO_ID ) |
108 | | - { |
109 | | - builder.set_unique_vertex( { component_id, v }, |
110 | | - first_new_unique_vertex + unique_vertices[v] ); |
111 | | - } |
112 | | - } |
113 | | - } |
114 | | -} // namespace |
| 50 | +#include <geode/model/representation/core/detail/transfer_meshes.hpp> |
115 | 51 |
|
116 | 52 | namespace geode |
117 | 53 | { |
@@ -150,63 +86,8 @@ namespace geode |
150 | 86 | void BRepBuilder::replace_components_meshes_by_others( |
151 | 87 | BRep&& other, const ModelCopyMapping& mapping ) |
152 | 88 | { |
153 | | - BRepBuilder other_builder{ other }; |
154 | | - remove_component_meshes_in_mapping( brep_, *this, mapping ); |
155 | | - this->delete_isolated_vertices(); |
156 | | - const auto first_new_unique_vertex_id = |
157 | | - create_unique_vertices( other.nb_unique_vertices() ); |
158 | | - for( const auto& in2out : |
159 | | - mapping.at( Corner3D::component_type_static() ).in2out_map() ) |
160 | | - { |
161 | | - const auto corner_unique_vertices = save_mesh_unique_vertices( |
162 | | - other, other.corner( in2out.second ).mesh(), |
163 | | - other.corner( in2out.second ).component_id() ); |
164 | | - this->update_corner_mesh( brep_.corner( in2out.first ), |
165 | | - other_builder.steal_corner_mesh( in2out.second ) ); |
166 | | - this->corner_mesh_builder( in2out.first )->set_id( in2out.first ); |
167 | | - set_mesh_unique_vertices( *this, corner_unique_vertices, |
168 | | - brep_.corner( in2out.first ).component_id(), |
169 | | - first_new_unique_vertex_id ); |
170 | | - } |
171 | | - for( const auto& in2out : |
172 | | - mapping.at( Line3D::component_type_static() ).in2out_map() ) |
173 | | - { |
174 | | - const auto line_unique_vertices = save_mesh_unique_vertices( other, |
175 | | - other.line( in2out.second ).mesh(), |
176 | | - other.line( in2out.second ).component_id() ); |
177 | | - this->update_line_mesh( brep_.line( in2out.first ), |
178 | | - other_builder.steal_line_mesh( in2out.second ) ); |
179 | | - this->line_mesh_builder( in2out.first )->set_id( in2out.first ); |
180 | | - set_mesh_unique_vertices( *this, line_unique_vertices, |
181 | | - brep_.line( in2out.first ).component_id(), |
182 | | - first_new_unique_vertex_id ); |
183 | | - } |
184 | | - for( const auto& in2out : |
185 | | - mapping.at( Surface3D::component_type_static() ).in2out_map() ) |
186 | | - { |
187 | | - const auto surface_unique_vertices = save_mesh_unique_vertices( |
188 | | - other, other.surface( in2out.second ).mesh(), |
189 | | - other.surface( in2out.second ).component_id() ); |
190 | | - this->update_surface_mesh( brep_.surface( in2out.first ), |
191 | | - other_builder.steal_surface_mesh( in2out.second ) ); |
192 | | - this->surface_mesh_builder( in2out.first )->set_id( in2out.first ); |
193 | | - set_mesh_unique_vertices( *this, surface_unique_vertices, |
194 | | - brep_.surface( in2out.first ).component_id(), |
195 | | - first_new_unique_vertex_id ); |
196 | | - } |
197 | | - for( const auto& in2out : |
198 | | - mapping.at( Block3D::component_type_static() ).in2out_map() ) |
199 | | - { |
200 | | - const auto block_unique_vertices = save_mesh_unique_vertices( other, |
201 | | - other.block( in2out.second ).mesh(), |
202 | | - other.block( in2out.second ).component_id() ); |
203 | | - this->update_block_mesh( brep_.block( in2out.first ), |
204 | | - other_builder.steal_block_mesh( in2out.second ) ); |
205 | | - this->block_mesh_builder( in2out.first )->set_id( in2out.first ); |
206 | | - set_mesh_unique_vertices( *this, block_unique_vertices, |
207 | | - brep_.block( in2out.first ).component_id(), |
208 | | - first_new_unique_vertex_id ); |
209 | | - } |
| 89 | + detail::transfer_brep_meshes( |
| 90 | + brep_, *this, std::move( other ), mapping ); |
210 | 91 | } |
211 | 92 |
|
212 | 93 | ModelCopyMapping BRepBuilder::copy_components( const BRep& brep ) |
|
0 commit comments