Generate functions for all API usecases for better static code features. See #2693.

This commit is contained in:
Dion Moult
2024-05-06 14:35:39 +10:00
parent 10f894e2ea
commit d11ec67129
330 changed files with 13283 additions and 13751 deletions
@@ -20,39 +20,42 @@ import ifcopenshell
import ifcopenshell.api
def add_surface_textures(file, material=None, uv_maps=None, textures=None) -> None:
"""Add surface texture based on a Blender material definition or texture data.
:param material: The Blender material definition with a node tree that
is compatible with glTF. See one of the valid combinations here:
https://docs.blender.org/manual/en/dev/addons/import_export/scene_gltf2.html
:type material: bpy.types.Material
:param uv_maps: A list of IfcIndexedTextureMap for any
IfcTessellatedFaceSets that the representation has, obtained from
the HasTextures attribute.
:type uv_maps: list[ifcopenshell.entity_instance]
:param textures: A list of dictionaries containing:
1. Attributes to create IfcImageTexture.
2. One additional parameter `uv_mode` to map IfcImageTexture to correct
IfcTextureCoordinate type.
Possible `uv_mode` values:
* `UV` - use IfcTextureCoordinate from `uv_maps` parameter;
* `Generated` - IfcTextureCoordinateGenerator with mode COORD (autogenerated UV
based on geometry);
* `Camera` - IfcTextureCoordinateGenerator with mode COORD_EYE (autogenerated UV
based on camera position)
:type textures: list[dict]
:return: A list of IfcImageTexture
:rtype: list[ifcopenshell.entity_instance]
"""
usecase = Usecase()
# TODO: This usecase currently depends on Blender's data model
usecase.file = file
usecase.settings = {"material": material, "uv_maps": uv_maps or [], "textures": textures or []}
return usecase.execute()
class Usecase:
def __init__(self, file, material=None, uv_maps=None, textures=None):
"""Add surface texture based on a Blender material definition or texture data.
:param material: The Blender material definition with a node tree that
is compatible with glTF. See one of the valid combinations here:
https://docs.blender.org/manual/en/dev/addons/import_export/scene_gltf2.html
:type material: bpy.types.Material
:param uv_maps: A list of IfcIndexedTextureMap for any
IfcTessellatedFaceSets that the representation has, obtained from
the HasTextures attribute.
:type uv_maps: list[ifcopenshell.entity_instance]
:param textures: A list of dictionaries containing:
1. Attributes to create IfcImageTexture.
2. One additional parameter `uv_mode` to map IfcImageTexture to correct
IfcTextureCoordinate type.
Possible `uv_mode` values:
* `UV` - use IfcTextureCoordinate from `uv_maps` parameter;
* `Generated` - IfcTextureCoordinateGenerator with mode COORD (autogenerated UV
based on geometry);
* `Camera` - IfcTextureCoordinateGenerator with mode COORD_EYE (autogenerated UV
based on camera position)
:type textures: list[dict]
:return: A list of IfcImageTexture
:rtype: list[ifcopenshell.entity_instance]
"""
# TODO: This usecase currently depends on Blender's data model
self.file = file
self.settings = {"material": material, "uv_maps": uv_maps or [], "textures": textures or []}
def execute(self):
if self.file.schema == "IFC2X3":
# TODO: research how compatible IFC2X3 and IFC4 textures are