This commit is contained in:
Andrej730
2024-12-04 14:44:04 +05:00
parent 69fb486778
commit 00a509aa0b
3 changed files with 16 additions and 5 deletions
+1 -1
View File
@@ -1227,7 +1227,7 @@ class IfcImportSettings:
self.has_filter = None self.has_filter = None
self.should_filter_spatial_elements = True self.should_filter_spatial_elements = True
self.should_setup_viewport_camera = True self.should_setup_viewport_camera = True
self.contexts = [] self.contexts: list[ifcopenshell.entity_instance] = []
self.context_settings: list[ifcopenshell.geom.main.settings] = [] self.context_settings: list[ifcopenshell.geom.main.settings] = []
self.gross_context_settings: list[ifcopenshell.geom.main.settings] = [] self.gross_context_settings: list[ifcopenshell.geom.main.settings] = []
self.elements: set[ifcopenshell.entity_instance] = set() self.elements: set[ifcopenshell.entity_instance] = set()
+2 -1
View File
@@ -68,7 +68,8 @@ class IFCFileSelector:
filepath = filepath.relative_to(bpy.path.abspath("//")) filepath = filepath.relative_to(bpy.path.abspath("//"))
return filepath.as_posix() return filepath.as_posix()
def draw(self, context): def draw(self, context: bpy.types.Context) -> None:
assert isinstance(context.space_data, bpy.types.SpaceFileBrowser)
# Access filepath & Directory https://blender.stackexchange.com/a/207665 # Access filepath & Directory https://blender.stackexchange.com/a/207665
params = context.space_data.params params = context.space_data.params
# Decode byte string https://stackoverflow.com/a/47737082/ # Decode byte string https://stackoverflow.com/a/47737082/
+13 -3
View File
@@ -37,7 +37,7 @@ import numpy as np
import numpy.typing as npt import numpy.typing as npt
from mathutils import Vector, Matrix from mathutils import Vector, Matrix
from pathlib import Path from pathlib import Path
from typing import Union from typing import Union, Any
# Progressively we'll refactor loading elements into Blender objects into this # Progressively we'll refactor loading elements into Blender objects into this
@@ -125,7 +125,9 @@ class Loader(bonsai.core.tool.Loader):
links.new(bsdf.outputs["BSDF"], output.inputs["Surface"]) links.new(bsdf.outputs["BSDF"], output.inputs["Surface"])
@classmethod @classmethod
def surface_style_to_dict(cls, surface_style): def surface_style_to_dict(
cls, surface_style: Union[ifcopenshell.entity_instance, dict[str, Any]]
) -> dict[str, Any]:
if isinstance(surface_style, dict): if isinstance(surface_style, dict):
return surface_style return surface_style
surface_style = surface_style.get_info() surface_style = surface_style.get_info()
@@ -181,8 +183,12 @@ class Loader(bonsai.core.tool.Loader):
return surface_texture return surface_texture
@classmethod @classmethod
def create_surface_style_rendering(cls, blender_material, surface_style): def create_surface_style_rendering(
cls, blender_material: bpy.types.Material, surface_style: ifcopenshell.entity_instance
) -> None:
surface_style = cls.surface_style_to_dict(surface_style) surface_style = cls.surface_style_to_dict(surface_style)
surface_style: dict[str, Any]
cls.create_surface_style_shading(blender_material, surface_style) cls.create_surface_style_shading(blender_material, surface_style)
reflectance_method = surface_style["ReflectanceMethod"] reflectance_method = surface_style["ReflectanceMethod"]
@@ -195,6 +201,7 @@ class Loader(bonsai.core.tool.Loader):
blender_material.use_nodes = True blender_material.use_nodes = True
cls.restart_material_node_tree(blender_material) cls.restart_material_node_tree(blender_material)
bsdf = tool.Blender.get_material_node(blender_material, "BSDF_PRINCIPLED") bsdf = tool.Blender.get_material_node(blender_material, "BSDF_PRINCIPLED")
assert bsdf
if surface_style["DiffuseColour"]: if surface_style["DiffuseColour"]:
color_type, color_value = surface_style["DiffuseColour"] color_type, color_value = surface_style["DiffuseColour"]
@@ -223,7 +230,10 @@ class Loader(bonsai.core.tool.Loader):
output = tool.Blender.get_material_node(blender_material, "OUTPUT_MATERIAL") output = tool.Blender.get_material_node(blender_material, "OUTPUT_MATERIAL")
bsdf = tool.Blender.get_material_node(blender_material, "BSDF_PRINCIPLED") bsdf = tool.Blender.get_material_node(blender_material, "BSDF_PRINCIPLED")
assert bsdf
assert output
assert blender_material.node_tree
mix = blender_material.node_tree.nodes.new(type="ShaderNodeMixShader") mix = blender_material.node_tree.nodes.new(type="ShaderNodeMixShader")
mix.location = bsdf.location mix.location = bsdf.location
blender_material.node_tree.links.new(mix.outputs[0], output.inputs["Surface"]) blender_material.node_tree.links.new(mix.outputs[0], output.inputs["Surface"])