fix: bug in initialization of gltf serialiser fixed

This commit is contained in:
Jonas Frei
2025-02-20 23:45:32 +01:00
committed by Thomas Krijnen
parent c549dea943
commit d38f56e82d
@@ -306,39 +306,43 @@ In addition to geometry settings, serialisation has its own set of
.. code-block:: python .. code-block:: python
import ifcopenshell import multiprocessing
import ifcopenshell.geom
import multiprocessing import ifcopenshell
import ifcopenshell.geom
settings = ifcopenshell.geom.settings()
ifc_file = ifcopenshell.open("model.ifc")
# Settings for glTF / glb
settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS) settings = ifcopenshell.geom.settings()
# Note that applying default materials is required in glTF serialisation.
settings.set("apply-default-materials", True) # Settings for glTF / glb
settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS)
# Settings for obj # Note that applying default materials is required in glTF serialisation.
# settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS) settings.set("apply-default-materials", True)
# settings.set("apply-default-materials", True)
# settings.set("use-world-coords", True) # Settings for obj
# settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS)
# Serialise to glTF / glb # settings.set("apply-default-materials", True)
serialiser = ifcopenshell.geom.serializers.gltf("output.glb", settings) # settings.set("use-world-coords", True)
self.serialiser_settings = ifcopenshell.geom.serializer_settings()
# Setting element GUIDs is optional, but useful to uniquely identify objects in non-semantic formats. serialiser_settings = ifcopenshell.geom.serializer_settings()
serialiser_settings.set("use-element-guids", True) # Setting element GUIDs is optional, but useful to uniquely identify objects in non-semantic formats.
serialiser_settings.set("use-element-guids", True)
# Serialise to obj
# serialiser = ifcopenshell.geom.serializers.obj('output.obj', 'output.mtl', settings, serialiser_settings) # Serialise to glTF / glb
serialiser = ifcopenshell.geom.serializers.gltf("output.glb", settings, serialiser_settings)
serialiser.setFile(self.file)
serialiser.setUnitNameAndMagnitude("METER", 1.0) # Serialise to obj
serialiser.writeHeader() # serialiser = ifcopenshell.geom.serializers.obj('output.obj', 'output.mtl', settings, serialiser_settings)
iterator = ifcopenshell.geom.iterator(settings, self.file, multiprocessing.cpu_count()) serialiser.setFile(ifc_file)
if iterator.initialize(): serialiser.setUnitNameAndMagnitude("METER", 1.0)
while True: serialiser.writeHeader()
serialiser.write(iterator.get())
if not iterator.next(): iterator = ifcopenshell.geom.iterator(settings, ifc_file, multiprocessing.cpu_count())
break if iterator.initialize():
serialiser.finalize() while True:
serialiser.write(iterator.get())
if not iterator.next():
break
serialiser.finalize()