mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 13:43:40 +00:00
Use paths relative to .ifc instead of .blend choosing texture paths
Texture path file dialog is also filtering image files now. Removed subtype from `FILE_PATH` from all related props since `layout.prop()` for those props starts file dialog that cannot return path relative to .ifc. It can return path relative to .blend - though it can be processed in props update to convert to relative to .ifc, this doesn't allow setting relative paths if .blend is not saved. Therefore, I've created a separate operator. add
This commit is contained in:
@@ -25,6 +25,7 @@ classes = (
|
|||||||
operator.AddStyle,
|
operator.AddStyle,
|
||||||
operator.BrowseExternalStyle,
|
operator.BrowseExternalStyle,
|
||||||
operator.ClearTextureMapPath,
|
operator.ClearTextureMapPath,
|
||||||
|
operator.ChooseTextureMapPath,
|
||||||
operator.DisableAddingPresentationStyle,
|
operator.DisableAddingPresentationStyle,
|
||||||
operator.DisableEditingExternalStyle,
|
operator.DisableEditingExternalStyle,
|
||||||
operator.DisableEditingStyle,
|
operator.DisableEditingStyle,
|
||||||
|
|||||||
@@ -410,6 +410,46 @@ class SelectByStyle(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
core.select_by_style(tool.Style, tool.Spatial, style=tool.Ifc.get().by_id(self.style))
|
core.select_by_style(tool.Style, tool.Spatial, style=tool.Ifc.get().by_id(self.style))
|
||||||
|
|
||||||
|
|
||||||
|
class ChooseTextureMapPath(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.choose_texture_map_path"
|
||||||
|
bl_label = "Choose Texture Map Path"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
texture_map_prop: bpy.props.StringProperty(default="")
|
||||||
|
|
||||||
|
use_relative_path: bpy.props.BoolProperty(name="Use Relative Path", default=True)
|
||||||
|
filepath: bpy.props.StringProperty(
|
||||||
|
name="File Path", description="Filepath used to import from", maxlen=1024, default="", subtype="FILE_PATH"
|
||||||
|
)
|
||||||
|
filter_image: bpy.props.BoolProperty(default=True, options={"HIDDEN", "SKIP_SAVE"})
|
||||||
|
filter_folder: bpy.props.BoolProperty(default=True, options={"HIDDEN", "SKIP_SAVE"})
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
context.window_manager.fileselect_add(self)
|
||||||
|
return {"RUNNING_MODAL"}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
poll = getattr(context, "material", None)
|
||||||
|
if not poll:
|
||||||
|
cls.poll_message_set("Select a material")
|
||||||
|
return poll
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
if not self.texture_map_prop:
|
||||||
|
self.report({"ERROR"}, "Provide a texture map")
|
||||||
|
return {"CANCELLED"}
|
||||||
|
|
||||||
|
abs_path = Path(self.filepath)
|
||||||
|
if self.use_relative_path:
|
||||||
|
image_filepath = abs_path.relative_to(Path(tool.Ifc.get_path()).parent)
|
||||||
|
else:
|
||||||
|
image_filepath = abs_path
|
||||||
|
|
||||||
|
props = context.material.BIMStyleProperties
|
||||||
|
setattr(props, self.texture_map_prop, image_filepath.as_posix())
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class ClearTextureMapPath(bpy.types.Operator):
|
class ClearTextureMapPath(bpy.types.Operator):
|
||||||
bl_idname = "bim.clear_texture_map_path"
|
bl_idname = "bim.clear_texture_map_path"
|
||||||
bl_label = "Clear Texture Map Path"
|
bl_label = "Clear Texture Map Path"
|
||||||
|
|||||||
@@ -269,21 +269,18 @@ class BIMStyleProperties(PropertyGroup):
|
|||||||
name="NormalMap",
|
name="NormalMap",
|
||||||
maxlen=1024,
|
maxlen=1024,
|
||||||
default="",
|
default="",
|
||||||
subtype="FILE_PATH",
|
|
||||||
update=update_shader_graph,
|
update=update_shader_graph,
|
||||||
)
|
)
|
||||||
emissive_path: bpy.props.StringProperty(
|
emissive_path: bpy.props.StringProperty(
|
||||||
name="Emissive",
|
name="Emissive",
|
||||||
maxlen=1024,
|
maxlen=1024,
|
||||||
default="",
|
default="",
|
||||||
subtype="FILE_PATH",
|
|
||||||
update=update_shader_graph,
|
update=update_shader_graph,
|
||||||
)
|
)
|
||||||
metallic_roughness_path: bpy.props.StringProperty(
|
metallic_roughness_path: bpy.props.StringProperty(
|
||||||
name="Metallic/Roughness",
|
name="Metallic/Roughness",
|
||||||
maxlen=1024,
|
maxlen=1024,
|
||||||
default="",
|
default="",
|
||||||
subtype="FILE_PATH",
|
|
||||||
update=update_shader_graph,
|
update=update_shader_graph,
|
||||||
description="Green Channel = Roughness,\nBlue Channel = Metallic",
|
description="Green Channel = Roughness,\nBlue Channel = Metallic",
|
||||||
)
|
)
|
||||||
@@ -291,7 +288,6 @@ class BIMStyleProperties(PropertyGroup):
|
|||||||
name="Diffuse",
|
name="Diffuse",
|
||||||
maxlen=1024,
|
maxlen=1024,
|
||||||
default="",
|
default="",
|
||||||
subtype="FILE_PATH",
|
|
||||||
update=update_shader_graph,
|
update=update_shader_graph,
|
||||||
)
|
)
|
||||||
occlusion_path: bpy.props.StringProperty(
|
occlusion_path: bpy.props.StringProperty(
|
||||||
@@ -299,6 +295,5 @@ class BIMStyleProperties(PropertyGroup):
|
|||||||
description="Note that occlusion isn't actually used in Blender shader, we're just storing the data",
|
description="Note that occlusion isn't actually used in Blender shader, we're just storing the data",
|
||||||
maxlen=1024,
|
maxlen=1024,
|
||||||
default="",
|
default="",
|
||||||
subtype="FILE_PATH",
|
|
||||||
update=update_shader_graph,
|
update=update_shader_graph,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -417,15 +417,14 @@ class BIM_PT_STYLE_GRAPH(Panel):
|
|||||||
def add_texture_path(path_name):
|
def add_texture_path(path_name):
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.prop(props, path_name)
|
row.prop(props, path_name)
|
||||||
op = row.operator("bim.clear_texture_map_path", text="", icon="X")
|
op_path = row.operator("bim.choose_texture_map_path", text="", icon="FILEBROWSER")
|
||||||
op.texture_map_prop = path_name
|
op_clear = row.operator("bim.clear_texture_map_path", text="", icon="X")
|
||||||
|
op_path.texture_map_prop = op_clear.texture_map_prop = path_name
|
||||||
|
|
||||||
layout.separator()
|
layout.separator()
|
||||||
texture_maps = TEXTURE_MAPS_BY_METHODS.get(props.reflectance_method, [])
|
texture_maps = TEXTURE_MAPS_BY_METHODS.get(props.reflectance_method, [])
|
||||||
if not texture_maps:
|
if not texture_maps:
|
||||||
return
|
return
|
||||||
if not bpy.data.filepath:
|
|
||||||
layout.label(text="Save .blend file to keep relative paths", icon="ERROR")
|
|
||||||
|
|
||||||
layout.prop(props, "uv_mode")
|
layout.prop(props, "uv_mode")
|
||||||
layout.label(text="Texture Maps:")
|
layout.label(text="Texture Maps:")
|
||||||
|
|||||||
Reference in New Issue
Block a user