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

Method write

src/serializers/GltfSerializer.cpp:178–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176}
177
178void GltfSerializer::write(const IfcGeom::TriangulationElement* o) {
179 if (o->geometry().material_ids().empty()) {
180 return;
181 }
182
183 size_t current_node_index = json_["nodes"].size();
184 auto current_leaf_index = current_node_index;
185 json_["nodes"].emplace_back();
186 node_indices_[o->product()] = current_node_index;
187 node_array_.push_back(current_node_index);
188
189 auto m = o->transformation().data()->ccomponents();
190
191 if (o->parents().empty()) {
192 roots_.push_back(current_node_index);
193 }
194 if (!o->parents().empty()) {
195 // apply inverse of last parent -> overwrite product transform (m)
196 m = o->parents().back()->transformation().data()->ccomponents().inverse() * m;
197
198 for (auto it = o->parents().rbegin(); it != o->parents().rend(); ++it) {
199 const auto jt = it + 1;
200 const bool is_root = jt == o->parents().rend();
201
202 auto kt = node_indices_.find((*it)->product());
203 if (kt != node_indices_.end()) {
204 // parent already processed as part of other parent sequence
205 json_["nodes"][kt->second]["children"].push_back(current_node_index);
206 break;
207 }
208
209
210 auto mm = (*it)->transformation().data()->ccomponents();
211 if (!is_root) {
212 mm = (*jt)->transformation().data()->ccomponents().inverse() * mm;
213 }
214
215 json parent_node = json::object();
216
217 std::array<double, 16> matrix_flat;
218 if (settings_.get<ifcopenshell::geometry::settings::SeparateZUpNode>().get() || settings_.get<ifcopenshell::geometry::settings::WriteGltfEcef>().get() || !is_root) {
219 // y-up transform is only accounted for on root
220 matrix_flat = {
221 mm(0,0), mm(1,0), mm(2,0), mm(3,0),
222 mm(0,1), mm(1,1), mm(2,1), mm(3,1),
223 mm(0,2), mm(1,2), mm(2,2), mm(3,2),
224 mm(0,3), mm(1,3), mm(2,3), mm(3,3)
225 };
226 } else {
227 // nb: note that this contains the Y-UP transform.
228 matrix_flat = {
229 mm(0,0), mm(2,0), -mm(1,0), mm(3,0),
230 mm(0,1), mm(2,1), -mm(1,1), mm(3,1),
231 mm(0,2), mm(2,2), -mm(1,2), mm(3,2),
232 mm(0,3), mm(2,3), -mm(1,3), mm(3,3)
233 };
234 }
235

Callers 4

write_accessorFunction · 0.45
write_headerFunction · 0.45
write_blockFunction · 0.45
finalizeMethod · 0.45

Calls 15

object_idFunction · 0.85
productMethod · 0.80
push_backMethod · 0.80
dataMethod · 0.80
inverseMethod · 0.80
reserveMethod · 0.80
mmFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected