mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
bmesh_to_ifc now creates separate representations for each distinct bmesh geometry
This commit is contained in:
@@ -53,10 +53,6 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
|
|
||||||
refresh_local: BoolProperty(name="Update Node", description="Update Node", update=refresh_node)
|
refresh_local: BoolProperty(name="Update Node", description="Update Node", update=refresh_node)
|
||||||
|
|
||||||
n_id: StringProperty()
|
|
||||||
flat_output: BoolProperty(
|
|
||||||
name="Flat output", description="Flatten output by list-joining level 1",
|
|
||||||
default=True, update=updateNode)
|
|
||||||
context_types = [
|
context_types = [
|
||||||
('Model', 'Model', 'Context type: Model', 0),
|
('Model', 'Model', 'Context type: Model', 0),
|
||||||
('Plan', 'Plan', 'Context type: Plan', 1),
|
('Plan', 'Plan', 'Context type: Plan', 1),
|
||||||
@@ -74,15 +70,10 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
('GRAPH_VIEW', 'GRAPH_VIEW', 'Target View: GRAPH_VIEW', 2),
|
('GRAPH_VIEW', 'GRAPH_VIEW', 'Target View: GRAPH_VIEW', 2),
|
||||||
('SKETCH_VIEW', 'SKETCH_VIEW', 'Target View: SKETCH_VIEW', 3),
|
('SKETCH_VIEW', 'SKETCH_VIEW', 'Target View: SKETCH_VIEW', 3),
|
||||||
]
|
]
|
||||||
paradigms = [
|
|
||||||
('Tessellation', 'Tessellation', 'Geometry paradigm: Tessellation', 0),
|
|
||||||
('Extrusion', 'Extrusion', 'Geometry paradigm: Extrusion', 1),
|
|
||||||
]
|
|
||||||
blender_objects: PointerProperty(name="Blender Mesh(es)", description="Blender Mesh Object(s)",update=updateNode, type=bpy.types.Object)
|
blender_objects: PointerProperty(name="Blender Mesh(es)", description="Blender Mesh Object(s)",update=updateNode, type=bpy.types.Object)
|
||||||
context_type: EnumProperty(name="Context Type", description="Default: Model", default="Model",items=context_types,update=updateNode)
|
context_type: EnumProperty(name="Context Type", description="Default: Model", default="Model",items=context_types,update=updateNode)
|
||||||
context_identifier: EnumProperty(name="Context Identifier", description="Default: Body", default="Body", items=context_identifiers, update=updateNode)
|
context_identifier: EnumProperty(name="Context Identifier", description="Default: Body", default="Body", items=context_identifiers, update=updateNode)
|
||||||
target_view: EnumProperty(name="Target View", description="Default: MODEL VIEW", default="MODEL_VIEW",items=target_views, update=updateNode)
|
target_view: EnumProperty(name="Target View", description="Default: MODEL VIEW", default="MODEL_VIEW",items=target_views, update=updateNode)
|
||||||
paradigm: EnumProperty(name="Paradigm", description="Which geometry type to convert to. Choose between tessellation or extrusion. Default: Tessellation.",default="Tessellation",items=paradigms, update=updateNode)
|
|
||||||
tooltip: StringProperty(name="Tooltip")
|
tooltip: StringProperty(name="Tooltip")
|
||||||
|
|
||||||
|
|
||||||
@@ -90,7 +81,6 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
self.inputs.new("SvStringsSocket", "context_type").prop_name = "context_type"
|
self.inputs.new("SvStringsSocket", "context_type").prop_name = "context_type"
|
||||||
self.inputs.new("SvStringsSocket", "context_identifier").prop_name = "context_identifier"
|
self.inputs.new("SvStringsSocket", "context_identifier").prop_name = "context_identifier"
|
||||||
self.inputs.new("SvStringsSocket", "target_view").prop_name = "target_view"
|
self.inputs.new("SvStringsSocket", "target_view").prop_name = "target_view"
|
||||||
self.inputs.new("SvStringsSocket", "paradigm").prop_name = "paradigm"
|
|
||||||
self.inputs.new("SvObjectSocket", "blender_objects").prop_name = "blender_objects" #no prop for now
|
self.inputs.new("SvObjectSocket", "blender_objects").prop_name = "blender_objects" #no prop for now
|
||||||
self.outputs.new("SvVerticesSocket", "Representations")
|
self.outputs.new("SvVerticesSocket", "Representations")
|
||||||
self.outputs.new("SvMatrixSocket", "Locations")
|
self.outputs.new("SvMatrixSocket", "Locations")
|
||||||
@@ -122,10 +112,6 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
blender_objects = self.inputs["blender_objects"].sv_get()
|
blender_objects = self.inputs["blender_objects"].sv_get()
|
||||||
self.file = SvIfcStore.get_file()
|
self.file = SvIfcStore.get_file()
|
||||||
|
|
||||||
#temporary
|
|
||||||
if self.paradigm == "Extrusion":
|
|
||||||
raise Exception("Extrusion not yet implemented.")
|
|
||||||
return
|
|
||||||
if self.refresh_local:
|
if self.refresh_local:
|
||||||
edit = True
|
edit = True
|
||||||
if self.node_id not in SvIfcStore.id_map:
|
if self.node_id not in SvIfcStore.id_map:
|
||||||
@@ -135,7 +121,6 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
self.edit()
|
self.edit()
|
||||||
representations, locations = self.create(blender_objects)
|
representations, locations = self.create(blender_objects)
|
||||||
else:
|
else:
|
||||||
# representations = self.get_existing_element()
|
|
||||||
representations = SvIfcStore.id_map[self.node_id]["Representations"]
|
representations = SvIfcStore.id_map[self.node_id]["Representations"]
|
||||||
locations = SvIfcStore.id_map[self.node_id]["Locations"]
|
locations = SvIfcStore.id_map[self.node_id]["Locations"]
|
||||||
|
|
||||||
@@ -148,25 +133,29 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
def create(self, blender_objects):
|
def create(self, blender_objects):
|
||||||
representations_ids = []
|
representations_ids = []
|
||||||
locations = []
|
locations = []
|
||||||
add_matrix = locations.extend if self.flat_output else locations.append
|
|
||||||
for blender_object in blender_objects:
|
for blender_object in blender_objects:
|
||||||
representation = ifcopenshell.api.run("geometry.add_representation", self.file, should_run_listeners=False,blender_object = blender_object, geometry=blender_object.data, context = self.get_context())
|
if blender_object.type == 'MESH':
|
||||||
if not representation:
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
raise Exception("Couldn't create representation. Possibly wrong context.")
|
blender_object.select_set(True)
|
||||||
representations_ids.append(representation.id())
|
bpy.ops.object.mode_set(mode='EDIT')
|
||||||
SvIfcStore.id_map.setdefault(self.node_id, {}).setdefault("Representations", []).append(representation.id())
|
bpy.ops.mesh.separate(type='LOOSE')
|
||||||
location = blender_object.matrix_world
|
for obj in bpy.context.selected_objects:
|
||||||
print("\n", "#"*30, "location: ", location)
|
representation = ifcopenshell.api.run("geometry.add_representation", self.file, should_run_listeners=False,blender_object = obj, geometry=obj.data, context = self.get_context())
|
||||||
add_matrix(location)
|
print("\n", "#"*30, "representation: ", representation)
|
||||||
SvIfcStore.id_map.setdefault(self.node_id, {}).setdefault("Locations", []).append(location)
|
if not representation:
|
||||||
|
raise Exception("Couldn't create representation. Possibly wrong context.")
|
||||||
|
representations_ids.append(representation.id())
|
||||||
|
SvIfcStore.id_map.setdefault(self.node_id, {}).setdefault("Representations", []).append(representation.id())
|
||||||
|
locations.append(blender_object.matrix_world)
|
||||||
|
SvIfcStore.id_map.setdefault(self.node_id, {}).setdefault("Locations", []).append(location)
|
||||||
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
|
bpy.ops.object.select_all(action='DESELECT')
|
||||||
return representations_ids, locations
|
return representations_ids, locations
|
||||||
|
|
||||||
def edit(self):
|
def edit(self):
|
||||||
# results = self.get_existing_element()
|
|
||||||
if "Representations" not in SvIfcStore.id_map[self.node_id]:
|
if "Representations" not in SvIfcStore.id_map[self.node_id]:
|
||||||
return
|
return
|
||||||
for step_id in SvIfcStore.id_map[self.node_id]["Representations"]:
|
for step_id in SvIfcStore.id_map[self.node_id]["Representations"]:
|
||||||
#if self.file.by_id(step_id).is_a('IfcShapeRepresentation'):
|
|
||||||
ifcopenshell.api.run("geometry.remove_representation", self.file, representation=self.file.by_id(step_id))
|
ifcopenshell.api.run("geometry.remove_representation", self.file, representation=self.file.by_id(step_id))
|
||||||
del SvIfcStore.id_map[self.node_id]["Representations"]
|
del SvIfcStore.id_map[self.node_id]["Representations"]
|
||||||
del SvIfcStore.id_map[self.node_id]["Locations"]
|
del SvIfcStore.id_map[self.node_id]["Locations"]
|
||||||
@@ -180,7 +169,6 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
|
|
||||||
def get_context(self):
|
def get_context(self):
|
||||||
context = ifcopenshell.util.representation.get_context(self.file, self.context_type, self.context_identifier, self.target_view)
|
context = ifcopenshell.util.representation.get_context(self.file, self.context_type, self.context_identifier, self.target_view)
|
||||||
|
|
||||||
if not context:
|
if not context:
|
||||||
parent = ifcopenshell.util.representation.get_context(self.file, self.context_type)
|
parent = ifcopenshell.util.representation.get_context(self.file, self.context_type)
|
||||||
if not parent:
|
if not parent:
|
||||||
@@ -194,11 +182,10 @@ class SvIfcBMeshToIfcRepr(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.help
|
|||||||
target_view=self.target_view,
|
target_view=self.target_view,
|
||||||
parent=parent,
|
parent=parent,
|
||||||
)
|
)
|
||||||
# SvIfcStore.id_map.setdefault(self.node_id, []).append(context.id())
|
|
||||||
SvIfcStore.id_map.setdefault(self.node_id, {}).setdefault("Contexts", []).append(context.id())
|
SvIfcStore.id_map.setdefault(self.node_id, {}).setdefault("Contexts", []).append(context.id())
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
def sv_free(self):
|
def sv_free(self):
|
||||||
try:
|
try:
|
||||||
self.file = SvIfcStore.get_file()
|
self.file = SvIfcStore.get_file()
|
||||||
@@ -229,6 +216,5 @@ def register():
|
|||||||
bpy.utils.register_class(SvIfcBMeshToIfcRepr)
|
bpy.utils.register_class(SvIfcBMeshToIfcRepr)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.utils.unregister_class(SvIfcBMeshToIfcRepr)
|
bpy.utils.unregister_class(SvIfcBMeshToIfcRepr)
|
||||||
@@ -69,7 +69,7 @@ class SvIfcCreateShape(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.
|
|||||||
|
|
||||||
def draw_buttons(self, context, layout):
|
def draw_buttons(self, context, layout):
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = "Create Blender shape from Ifc Entity. Takes one or multiple Ifc Entities."
|
row.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = "Create Blender shape from IfcEntity ID. Takes one or multiple IfcEntity IDs."
|
||||||
row.prop(self, 'refresh_local', icon='FILE_REFRESH')
|
row.prop(self, 'refresh_local', icon='FILE_REFRESH')
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user