|
1 |
| -import os |
2 | 1 | import warnings
|
3 | 2 | from pathlib import Path
|
4 | 3 | from typing import ClassVar, List
|
@@ -128,29 +127,32 @@ def __init__(self, dae_path: str, cache: Optional[Set[str]] = None) -> None:
|
128 | 127 | )
|
129 | 128 | if img_lib_element:
|
130 | 129 | img_resource_paths = [
|
131 |
| - e.text for e in img_lib_element.iter() if e.tag.count("init_from") |
| 130 | + Path(e.text) |
| 131 | + for e in img_lib_element.iter() |
| 132 | + if e.tag.count("init_from") |
132 | 133 | ]
|
133 | 134 |
|
134 | 135 | # Convert textures to data URL for Three.js ColladaLoader to load them
|
135 | 136 | self.img_resources = {}
|
136 | 137 | for img_path in img_resource_paths:
|
| 138 | + img_key = str(img_path) |
137 | 139 | # Return empty string if already in cache
|
138 | 140 | if cache is not None:
|
139 | 141 | if img_path in cache:
|
140 |
| - self.img_resources[img_path] = "" |
| 142 | + self.img_resources[img_key] = "" |
141 | 143 | continue
|
142 | 144 | cache.add(img_path)
|
143 | 145 |
|
144 | 146 | # Encode texture in base64
|
145 |
| - img_path_abs = img_path |
146 |
| - if not Path(img_path).is_absolute(): |
147 |
| - img_path_abs = os.path.normpath(dae_dir / img_path_abs) |
148 |
| - if not Path(img_path_abs).is_file(): |
| 147 | + img_path_abs: Path = img_path |
| 148 | + if not img_path.is_absolute(): |
| 149 | + img_path_abs = (dae_dir / img_path_abs).resolve() |
| 150 | + if not img_path_abs.is_file(): |
149 | 151 | raise UserWarning(f"Texture '{img_path}' not found.")
|
150 |
| - with Path(img_path_abs).open("rb") as img_file: |
| 152 | + with img_path_abs.open("rb") as img_file: |
151 | 153 | img_data = base64.b64encode(img_file.read())
|
152 | 154 | img_uri = f"data:image/png;base64,{img_data.decode('utf-8')}"
|
153 |
| - self.img_resources[img_path] = img_uri |
| 155 | + self.img_resources[img_key] = img_uri |
154 | 156 |
|
155 | 157 | def lower(self) -> Dict[str, Any]:
|
156 | 158 | """Pack data into a dictionary of the format that must be passed to
|
|
0 commit comments