mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Allow fetching Eevee or Cycles materials from a material pass file
This commit is contained in:
@@ -57,6 +57,7 @@ classes = (
|
||||
operator.UnassignClassification,
|
||||
operator.RemoveClassification,
|
||||
operator.FetchLibraryInformation,
|
||||
operator.FetchExternalMaterial,
|
||||
prop.BIMProperties,
|
||||
prop.BIMLibrary,
|
||||
prop.MapConversion,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
import bpy
|
||||
import time
|
||||
import json
|
||||
@@ -641,6 +642,37 @@ class RemoveClassification(bpy.types.Operator):
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
class FetchExternalMaterial(bpy.types.Operator):
|
||||
bl_idname = 'bim.fetch_external_material'
|
||||
bl_label = 'Fetch External Material'
|
||||
|
||||
def execute(self, context):
|
||||
location = bpy.context.active_object.active_material.BIMMaterialProperties.location
|
||||
if location[-6:] != '.mpass':
|
||||
return {'FINISHED'}
|
||||
with open(location) as f:
|
||||
self.material_pass = json.load(f)
|
||||
if bpy.context.scene.render.engine == 'BLENDER_EEVEE' \
|
||||
and 'eevee' in self.material_pass:
|
||||
self.fetch_eevee_or_cycles('eevee')
|
||||
elif bpy.context.scene.render.engine == 'CYCLES' \
|
||||
and 'cycles' in self.material_pass:
|
||||
self.fetch_eevee_or_cycles('cycles')
|
||||
return {'FINISHED'}
|
||||
|
||||
def fetch_eevee_or_cycles(self, name):
|
||||
identification = bpy.context.active_object.active_material.BIMMaterialProperties.identification
|
||||
bpy.ops.wm.link(
|
||||
filename=identification,
|
||||
directory=os.path.join(self.material_pass[name]['uri'], 'Material')
|
||||
)
|
||||
for material in bpy.data.materials:
|
||||
if material.name == identification \
|
||||
and material.library:
|
||||
bpy.context.active_object.material_slots[0].material = material
|
||||
return
|
||||
|
||||
|
||||
class FetchLibraryInformation(bpy.types.Operator):
|
||||
bl_idname = 'bim.fetch_library_information'
|
||||
bl_label = 'Fetch Library Information'
|
||||
|
||||
@@ -7,7 +7,7 @@ class BIM_PT_object(Panel):
|
||||
bl_space_type = 'PROPERTIES'
|
||||
bl_region_type = 'WINDOW'
|
||||
bl_context = 'object'
|
||||
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.active_object is not None and hasattr(context.active_object, "BIMObjectProperties")
|
||||
@@ -143,6 +143,9 @@ class BIM_PT_material(Panel):
|
||||
row = layout.row()
|
||||
row.prop(props, 'name')
|
||||
|
||||
row = layout.row()
|
||||
row.operator('bim.fetch_external_material')
|
||||
|
||||
|
||||
class BIM_PT_gis(Panel):
|
||||
bl_label = 'IFC Georeferencing'
|
||||
|
||||
Reference in New Issue
Block a user