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:
Andrej730
2023-12-04 15:37:29 +05:00
parent 67ef292b85
commit fe9ad74fd5
4 changed files with 44 additions and 9 deletions
@@ -25,6 +25,7 @@ classes = (
operator.AddStyle,
operator.BrowseExternalStyle,
operator.ClearTextureMapPath,
operator.ChooseTextureMapPath,
operator.DisableAddingPresentationStyle,
operator.DisableEditingExternalStyle,
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))
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):
bl_idname = "bim.clear_texture_map_path"
bl_label = "Clear Texture Map Path"
@@ -269,21 +269,18 @@ class BIMStyleProperties(PropertyGroup):
name="NormalMap",
maxlen=1024,
default="",
subtype="FILE_PATH",
update=update_shader_graph,
)
emissive_path: bpy.props.StringProperty(
name="Emissive",
maxlen=1024,
default="",
subtype="FILE_PATH",
update=update_shader_graph,
)
metallic_roughness_path: bpy.props.StringProperty(
name="Metallic/Roughness",
maxlen=1024,
default="",
subtype="FILE_PATH",
update=update_shader_graph,
description="Green Channel = Roughness,\nBlue Channel = Metallic",
)
@@ -291,7 +288,6 @@ class BIMStyleProperties(PropertyGroup):
name="Diffuse",
maxlen=1024,
default="",
subtype="FILE_PATH",
update=update_shader_graph,
)
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",
maxlen=1024,
default="",
subtype="FILE_PATH",
update=update_shader_graph,
)
@@ -417,15 +417,14 @@ class BIM_PT_STYLE_GRAPH(Panel):
def add_texture_path(path_name):
row = layout.row(align=True)
row.prop(props, path_name)
op = row.operator("bim.clear_texture_map_path", text="", icon="X")
op.texture_map_prop = path_name
op_path = row.operator("bim.choose_texture_map_path", text="", icon="FILEBROWSER")
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()
texture_maps = TEXTURE_MAPS_BY_METHODS.get(props.reflectance_method, [])
if not texture_maps:
return
if not bpy.data.filepath:
layout.label(text="Save .blend file to keep relative paths", icon="ERROR")
layout.prop(props, "uv_mode")
layout.label(text="Texture Maps:")