mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
improved relative path handling for textures #3365
now we're going to store all texture paths in .ifc as posix to keep them working if .ifc moved from one platform to another previously it was saving all paths as absolute
This commit is contained in:
@@ -215,6 +215,21 @@ class Blender:
|
|||||||
return current_iteration
|
return current_iteration
|
||||||
return cls.ensure_unique_name(name, objects, iteration + 1)
|
return cls.ensure_unique_name(name, objects, iteration + 1)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def blender_path_to_posix(cls, blender_path):
|
||||||
|
"""Process blender path to be saved as posix.
|
||||||
|
|
||||||
|
If path is relative the method will keep it relative to .ifc file
|
||||||
|
"""
|
||||||
|
if blender_path.startswith("//"): # detect relative blender path
|
||||||
|
ifc_path = Path(tool.Ifc.get_path())
|
||||||
|
abs_path = Path(bpy.path.abspath(blender_path))
|
||||||
|
path = abs_path.relative_to(ifc_path.parent)
|
||||||
|
else:
|
||||||
|
path = Path(blender_path)
|
||||||
|
|
||||||
|
return path.as_posix()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_default_selection_keypmap(cls):
|
def get_default_selection_keypmap(cls):
|
||||||
"""keymap to replicate default blender selection behaviour with click and box selection"""
|
"""keymap to replicate default blender selection behaviour with click and box selection"""
|
||||||
|
|||||||
@@ -191,16 +191,27 @@ class Loader(blenderbim.core.tool.Loader):
|
|||||||
mode = texture.get("Mode", None)
|
mode = texture.get("Mode", None)
|
||||||
node = None
|
node = None
|
||||||
|
|
||||||
if texture["type"] == "IfcImageTexture":
|
if texture["type"] != "IfcImageTexture":
|
||||||
image_url = texture["URLReference"]
|
print(f"WARNING. Texture of type {texture['type']} is not currently supported, it will be skipped.")
|
||||||
ifc_path = tool.Ifc.get_path()
|
continue
|
||||||
if ifc_path:
|
|
||||||
image_url = bpy.path.abspath(image_url, start=Path(ifc_path).parent)
|
|
||||||
|
|
||||||
if not os.path.exists(image_url):
|
original_image_url = texture["URLReference"]
|
||||||
|
is_relative = not os.path.isabs(original_image_url)
|
||||||
|
image_url = Path(original_image_url)
|
||||||
|
if is_relative:
|
||||||
|
ifc_path = Path(tool.Ifc.get_path())
|
||||||
|
image_url = ifc_path.parent / image_url
|
||||||
|
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
|
if not image_url.exists():
|
||||||
print(f"WARNING. Couldn't find texture by path {image_url}, it will be skipped.")
|
print(f"WARNING. Couldn't find texture by path {image_url}, it will be skipped.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# keep url relative if it was before
|
||||||
|
image_url = str(image_url)
|
||||||
|
if is_relative and bpy.data.filepath:
|
||||||
|
image_url = bpy.path.relpath(image_url)
|
||||||
|
|
||||||
if reflectance_method in ["PHYSICAL", "NOTDEFINED"]:
|
if reflectance_method in ["PHYSICAL", "NOTDEFINED"]:
|
||||||
bsdf = tool.Blender.get_material_node(blender_material, "BSDF_PRINCIPLED")
|
bsdf = tool.Blender.get_material_node(blender_material, "BSDF_PRINCIPLED")
|
||||||
if mode == "NORMAL":
|
if mode == "NORMAL":
|
||||||
|
|||||||
@@ -143,13 +143,10 @@ class Style(blenderbim.core.tool.Style):
|
|||||||
path = getattr(props, prop_name)
|
path = getattr(props, prop_name)
|
||||||
if not path:
|
if not path:
|
||||||
continue
|
continue
|
||||||
if not os.path.abspath(path) and tool.Ifc.get_path():
|
|
||||||
path = os.path.join(os.path.dirname(tool.Ifc.get_path()), path)
|
|
||||||
|
|
||||||
texture_data = {
|
texture_data = {
|
||||||
"Mode": prop_mode,
|
"Mode": prop_mode,
|
||||||
"type": "IfcImageTexture",
|
"type": "IfcImageTexture",
|
||||||
"URLReference": path,
|
"URLReference": tool.Blender.blender_path_to_posix(path),
|
||||||
}
|
}
|
||||||
textures.append(texture_data)
|
textures.append(texture_data)
|
||||||
|
|
||||||
|
|||||||
@@ -130,12 +130,14 @@ class Usecase:
|
|||||||
return self.create_surface_texture(links[0].from_node, "DIFFUSE")
|
return self.create_surface_texture(links[0].from_node, "DIFFUSE")
|
||||||
|
|
||||||
def create_surface_texture(self, node, mode):
|
def create_surface_texture(self, node, mode):
|
||||||
|
import blenderbim.tool as tool
|
||||||
|
|
||||||
texture = self.file.create_entity(
|
texture = self.file.create_entity(
|
||||||
"IfcImageTexture",
|
"IfcImageTexture",
|
||||||
RepeatS=node.extension == "REPEAT",
|
RepeatS=node.extension == "REPEAT",
|
||||||
RepeatT=node.extension == "REPEAT",
|
RepeatT=node.extension == "REPEAT",
|
||||||
Mode=mode,
|
Mode=mode,
|
||||||
URLReference=node.image.filepath,
|
URLReference=tool.Blender.blender_path_to_posix(node.image.filepath),
|
||||||
)
|
)
|
||||||
self.textures.append(texture)
|
self.textures.append(texture)
|
||||||
self.process_texture_coordinates(node, texture)
|
self.process_texture_coordinates(node, texture)
|
||||||
|
|||||||
Reference in New Issue
Block a user