From d38f56e82d42463c359f2a3b25b89c843b2383a4 Mon Sep 17 00:00:00 2001 From: Jonas Frei <53214867+HelloJowet@users.noreply.github.com> Date: Thu, 20 Feb 2025 23:45:32 +0100 Subject: [PATCH] fix: bug in initialization of gltf serialiser fixed --- .../geometry_processing.rst | 76 ++++++++++--------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/src/ifcopenshell-python/docs/ifcopenshell-python/geometry_processing.rst b/src/ifcopenshell-python/docs/ifcopenshell-python/geometry_processing.rst index df7ae3321e..0c4753807a 100644 --- a/src/ifcopenshell-python/docs/ifcopenshell-python/geometry_processing.rst +++ b/src/ifcopenshell-python/docs/ifcopenshell-python/geometry_processing.rst @@ -306,39 +306,43 @@ In addition to geometry settings, serialisation has its own set of .. code-block:: python - import ifcopenshell - import ifcopenshell.geom - import multiprocessing - - settings = ifcopenshell.geom.settings() - - # Settings for glTF / glb - settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS) - # Note that applying default materials is required in glTF serialisation. - settings.set("apply-default-materials", True) - - # Settings for obj - # settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS) - # settings.set("apply-default-materials", True) - # settings.set("use-world-coords", True) - - # Serialise to glTF / glb - serialiser = ifcopenshell.geom.serializers.gltf("output.glb", settings) - self.serialiser_settings = ifcopenshell.geom.serializer_settings() - # 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) - - serialiser.setFile(self.file) - serialiser.setUnitNameAndMagnitude("METER", 1.0) - serialiser.writeHeader() - - iterator = ifcopenshell.geom.iterator(settings, self.file, multiprocessing.cpu_count()) - if iterator.initialize(): - while True: - serialiser.write(iterator.get()) - if not iterator.next(): - break - serialiser.finalize() + import multiprocessing + + import ifcopenshell + import ifcopenshell.geom + + ifc_file = ifcopenshell.open("model.ifc") + + settings = ifcopenshell.geom.settings() + + # Settings for glTF / glb + settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS) + # Note that applying default materials is required in glTF serialisation. + settings.set("apply-default-materials", True) + + # Settings for obj + # settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS) + # settings.set("apply-default-materials", True) + # settings.set("use-world-coords", True) + + serialiser_settings = ifcopenshell.geom.serializer_settings() + # Setting element GUIDs is optional, but useful to uniquely identify objects in non-semantic formats. + serialiser_settings.set("use-element-guids", True) + + # Serialise to glTF / glb + serialiser = ifcopenshell.geom.serializers.gltf("output.glb", settings, serialiser_settings) + + # Serialise to obj + # serialiser = ifcopenshell.geom.serializers.obj('output.obj', 'output.mtl', settings, serialiser_settings) + + serialiser.setFile(ifc_file) + serialiser.setUnitNameAndMagnitude("METER", 1.0) + serialiser.writeHeader() + + iterator = ifcopenshell.geom.iterator(settings, ifc_file, multiprocessing.cpu_count()) + if iterator.initialize(): + while True: + serialiser.write(iterator.get()) + if not iterator.next(): + break + serialiser.finalize()