adds backgound to gltf when 'sky-box' equiretangular image is in directory

This commit is contained in:
buttle 2021-06-20 15:16:37 +02:00
parent 8c45cfbeab
commit f965544626
3 changed files with 24 additions and 10 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 914 KiB

View File

@ -46,10 +46,20 @@ def get_directory_content(dir_path):
return content
def find_skybox_image(dir):
print("find_skybox_image(dir): ", dir)
for p in Path(dir).iterdir():
extension = Path(p).suffix
print(f"sky-box{extension}")
if str(Path(p)).endswith(f"sky-box{extension}"):
print("return str(p): ", str(p))
return str(p)
return None
def find_file_with_extension(dir, extension):
for p in Path(dir).iterdir():
if Path(p).suffix.lstrip('.').lower() == extension:
return str(p)
return str(p).replace(OBJECT_DIR, "")
return None
@ -71,15 +81,22 @@ def get_object(file_path, result={}):
extension = Path(file_name).suffix.lstrip('.').lower()
print('get_object(extension):', extension)
if extension == "gltf":
result['type']="gltf"
if extension == "gltf" or extension == 'glb':
if extension == "gltf":
result['type']="gltf"
if extension == 'glb':
result['type'] = "glb"
object_path = str(file_path).replace(OBJECT_DIR, "")
result['urls'].append(f"/objects/{object_path}")
skybox_path = find_skybox_image(file_dir)
if skybox_path:
skybox_path = str(skybox_path).replace(OBJECT_DIR, '')
result['skybox'] = f"/objects{skybox_path}"
return result
if extension == "obj":
result['type']="obj"
object_path = str(file_path).replace(OBJECT_DIR, "")
result['urls'].append(f"/objects/{object_path}")
result['urls'].append(f"/objects{object_path}")
mtl_file = find_file_with_extension(file_dir, 'mtl')
if mtl_file:
result = get_object(mtl_file.replace(OBJECT_DIR, ""), result)
@ -104,11 +121,6 @@ def get_object(file_path, result={}):
object_path = str(file_path).replace(OBJECT_DIR, "")
result['urls'].append(f"/objects/{object_path}")
return result
if extension == 'glb':
result['type'] = "glb"
object_path = str(file_path).replace(OBJECT_DIR, "")
result['urls'].append(f"/objects/{object_path}")
return result
if extension == 'json':
result['type'] = "json"
object_path = str(file_path).replace(OBJECT_DIR, "")

View File

@ -27,7 +27,9 @@ model-viewer {
auto-rotate=""
camera-controls=""
background-color="#455A64"
skybox-image="/static/assets/equirectangular.png"
%if 'skybox' in object:
skybox-image="{{ object['skybox']}}"
%end
>
</model-viewer>
</div>