MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / add

Method add

src/serializers/ColladaSerializer.cpp:180–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178}
179
180void ColladaSerializer::ColladaExporter::ColladaScene::add(
181 const std::string& node_id, const std::string& node_name, const std::string& geom_name,
182 const std::vector<std::string>& material_ids, const IfcGeom::Transformation& transformation)
183{
184 if (!scene_opened) {
185 openVisualScene(scene_id);
186 scene_opened = true;
187 }
188
189 COLLADASW::Node node(mSW);
190 node.setNodeId(node_id);
191 node.setNodeName(node_name);
192 node.setType(COLLADASW::Node::NODE);
193
194 // The matrix attribute of an entity is basically a 4x3 representation of its ObjectPlacement.
195 // Note that this placement is absolute, ie it is multiplied with all parent placements.
196
197 auto transformation_towrite = transformation.data()->ccomponents();
198
199 // If this is not the first parent, get the relative placement
200 if (parentNodes.size() > 0)
201 {
202 // @todo check order
203 transformation_towrite = matrixStack.top().ccomponents() * transformation_towrite;
204 }
205
206 const auto& posmatrix = transformation_towrite;
207
208 double matrix_array[4][4] = {
209 { (double)posmatrix(0,0), (double)posmatrix(0,1), (double)posmatrix(0,2), (double)posmatrix(0,3) },
210 { (double)posmatrix(1,0), (double)posmatrix(1,1), (double)posmatrix(1,2), (double)posmatrix(1,3) },
211 { (double)posmatrix(2,0), (double)posmatrix(2,1), (double)posmatrix(2,2), (double)posmatrix(2,3) },
212 { (double)posmatrix(3,0), (double)posmatrix(3,1), (double)posmatrix(3,2), (double)posmatrix(3,3) }
213 };
214
215 node.start();
216 node.addMatrix(matrix_array);
217 COLLADASW::InstanceGeometry instanceGeometry(mSW);
218 instanceGeometry.setUrl("#" + geom_name);
219 BOOST_FOREACH(const std::string &material_name, material_ids) {
220 // Unescape to avoid double escaping because OpenCollada's material URI parameter escapes XML internally
221 std::string unescaped = material_name;
222 IfcUtil::unescape_xml(unescaped);
223
224 COLLADASW::InstanceMaterial material(material_name, "#" + unescaped);
225 instanceGeometry.getBindMaterial().getInstanceMaterialList().push_back(material);
226 }
227 instanceGeometry.add();
228 node.end();
229}
230
231void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom::Element& parent){
232 //we open the visual scene tag if it's not.

Callers 4

writeMethod · 0.45
startDocumentMethod · 0.45
BOOST_FOREACHFunction · 0.45
endDocumentMethod · 0.45

Calls 8

containsFunction · 0.85
dataMethod · 0.80
push_backMethod · 0.80
sizeMethod · 0.45
startMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected