adds a new rendered
This commit is contained in:
parent
0d2cb155ce
commit
397fb2a031
9
app.py
9
app.py
|
@ -73,14 +73,17 @@ def render(file_path):
|
|||
#print("file_dir: ", file_dir)
|
||||
#print("file_name: ", file_name)
|
||||
|
||||
object = utils.get_object(file_dir, [], {})
|
||||
object = utils.get_object(file_path, {})
|
||||
if not object:
|
||||
return "Opps, no object type"
|
||||
|
||||
print("object: ", object)
|
||||
if object['type'] == 'gltf':
|
||||
page_tpl = "render"
|
||||
else:
|
||||
page_tpl = "render_1"
|
||||
|
||||
|
||||
return template('render',
|
||||
return template(page_tpl,
|
||||
current_dir=file_path.replace(file_name, ""),
|
||||
name=file_name,
|
||||
object=object,
|
||||
|
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
File diff suppressed because one or more lines are too long
102
utils/utils.py
102
utils/utils.py
|
@ -26,7 +26,7 @@ BASE_DIR = os.path.abspath(
|
|||
'../')
|
||||
)
|
||||
OBJECT_DIR = os.path.join(BASE_DIR, 'objects')
|
||||
OBJECT_TYPES = ['gltf', 'obj', 'fbx', 'stl']
|
||||
OBJECT_TYPES = ['gltf', 'obj', 'fbx', 'stl', 'dae']
|
||||
|
||||
def get_directory_content(dir_path):
|
||||
content = []
|
||||
|
@ -44,58 +44,78 @@ def get_directory_content(dir_path):
|
|||
return content
|
||||
|
||||
|
||||
def get_object(dir_path, extentions=[], result={}):
|
||||
print('get_object(dir_path): ', dir_path)
|
||||
def find_file_with_extension(dir, extension):
|
||||
for p in Path(dir).iterdir():
|
||||
if Path(p).suffix.lstrip('.').lower() == extension:
|
||||
return str(p)
|
||||
return None
|
||||
|
||||
|
||||
def get_object(file_path, result={}):
|
||||
parts = file_path.split('/')
|
||||
file_name = parts.pop()
|
||||
file_dir = os.path.join(OBJECT_DIR, *parts)
|
||||
|
||||
print('get_object(file_dir): ', file_dir)
|
||||
print('get_object(file_name): ', file_name)
|
||||
print('get_object(file_path): ', os.path.join(OBJECT_DIR, *parts, file_name))
|
||||
if not os.path.exists(os.path.join(OBJECT_DIR, *parts, file_name)):
|
||||
print("cant find file")
|
||||
return result
|
||||
|
||||
if not result:
|
||||
result['urls'] = []
|
||||
result['type'] = None
|
||||
if not extentions:
|
||||
for p in Path(dir_path).iterdir():
|
||||
suffix = Path(p).suffix.lstrip('.').lower()
|
||||
if suffix in OBJECT_TYPES:
|
||||
extentions.append(suffix)
|
||||
for p in Path(dir_path).iterdir():
|
||||
suffix = Path(p).suffix.lstrip('.').lower()
|
||||
if suffix in extentions and suffix == "gltf":
|
||||
result['type']="gltf"
|
||||
print("p: ",p)
|
||||
print("Path(p): ",Path(p))
|
||||
object_path = str(p).replace(OBJECT_DIR, "")
|
||||
result['urls'].append(f"/objects{object_path}")
|
||||
return result
|
||||
if suffix in extentions and suffix == "obj":
|
||||
result['type']="obj"
|
||||
object_path = str(p).replace(OBJECT_DIR, "")
|
||||
result['urls'].append(f"/objects{object_path}")
|
||||
print("result_1: ", result)
|
||||
result = get_object(dir_path, extentions=['mtl'], result=result)
|
||||
print("result_2: ", result)
|
||||
return result
|
||||
if suffix in extentions and suffix == "mtl":
|
||||
if 'obj' in result['type']:
|
||||
result['type'] = "obj-mtl"
|
||||
object_path = str(p).replace(OBJECT_DIR, "")
|
||||
result['urls'].append(f"/objects{object_path}")
|
||||
return result
|
||||
if suffix in extentions and suffix == 'stl':
|
||||
result['type'] = "stl"
|
||||
object_path = str(p).replace(OBJECT_DIR, "")
|
||||
result['urls'].append(f"/objects{object_path}")
|
||||
return result
|
||||
extension = Path(file_name).suffix.lstrip('.').lower()
|
||||
print('get_object(extension):', extension)
|
||||
|
||||
if extension == "gltf":
|
||||
result['type']="gltf"
|
||||
object_path = str(file_path).replace(OBJECT_DIR, "")
|
||||
result['urls'].append(f"/objects{object_path}")
|
||||
return result
|
||||
if extension == "obj":
|
||||
result['type']="obj"
|
||||
object_path = str(file_path).replace(OBJECT_DIR, "")
|
||||
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)
|
||||
result['type']="obj-mtl"
|
||||
return result
|
||||
if extension == 'stl':
|
||||
result['type'] = "stl"
|
||||
object_path = str(file_path).replace(OBJECT_DIR, "")
|
||||
result['urls'].append(f"/objects{object_path}")
|
||||
return result
|
||||
if extension == 'mtl':
|
||||
object_path = str(file_path).replace(OBJECT_DIR, "")
|
||||
result['urls'].append(f"/objects{object_path}")
|
||||
return result
|
||||
if extension == 'fbx':
|
||||
result['type'] = "fbx"
|
||||
object_path = str(file_path).replace(OBJECT_DIR, "")
|
||||
result['urls'].append(f"/objects{object_path}")
|
||||
return result
|
||||
if extension == 'dae':
|
||||
result['type'] = "dae"
|
||||
object_path = str(file_path).replace(OBJECT_DIR, "")
|
||||
result['urls'].append(f"/objects{object_path}")
|
||||
return result
|
||||
return None
|
||||
|
||||
|
||||
"""
|
||||
if 'obj' in extentions and 'mtl' in extentions:
|
||||
if 'obj' in extensions and 'mtl' in extensions:
|
||||
print("p: ",p)
|
||||
return 'obj-mtl'
|
||||
if 'obj' in extentions:
|
||||
if 'obj' in extensions:
|
||||
return 'obj'
|
||||
if 'gltf' in extentions:
|
||||
if 'gltf' in extensions:
|
||||
return 'gltf'
|
||||
if 'fbx' in extentions:
|
||||
if 'fbx' in extensions:
|
||||
return 'fbx'
|
||||
if 'stl' in extentions:
|
||||
if 'stl' in extensions:
|
||||
return 'stl'
|
||||
"""
|
||||
|
||||
|
|
|
@ -3,6 +3,15 @@
|
|||
<script src="/static/vendor/vue/vue.js"></script>
|
||||
<script src="/static/vendor/vue-3d-model/vue-3d-model.umd.js"></script>
|
||||
|
||||
<style>
|
||||
model-viewer {
|
||||
width: 500px;
|
||||
height: 500px;
|
||||
outline: none;
|
||||
background-color: transparent;
|
||||
}
|
||||
</style>
|
||||
|
||||
<h3>
|
||||
<i class="fa fa-folder-o" aria-hidden="true"></i>
|
||||
<a href="/list/{{ current_dir.rstrip('/') }}">objects{{current_dir}}</a>
|
||||
|
@ -15,44 +24,15 @@
|
|||
</h4>
|
||||
|
||||
<div class="model-wrap">
|
||||
<div id="object">
|
||||
%if object['type'] == "gltf":
|
||||
<model-gltf
|
||||
src="{{ object['urls'][0] }}"
|
||||
@on-mousemove="onMouseMove"
|
||||
>
|
||||
</model-gltf>
|
||||
%end
|
||||
%if object['type'] == "obj-mtl":
|
||||
<model-obj
|
||||
src="{{ object['urls'][0] }}"
|
||||
mtl="{{ object['urls'][1] }}"
|
||||
>
|
||||
</model-obj>
|
||||
%end
|
||||
%if object['type'] == "obj":
|
||||
<model-obj
|
||||
src="{{ object['urls'][0] }}"
|
||||
>
|
||||
</model-obj>
|
||||
%end
|
||||
%if object['type'] == "fbx":
|
||||
<model-fbx
|
||||
src="{{ object['urls'][0] }}"
|
||||
>
|
||||
</model-fbx>
|
||||
%end
|
||||
%if object['type'] == "stl":
|
||||
<model-stl
|
||||
src="{{ object['urls'][0] }}"
|
||||
>
|
||||
</model-stl>
|
||||
%end
|
||||
<div id="model">
|
||||
<model-viewer src="{{ object['urls'][0] }}"
|
||||
alt="A 3D model of a robot"
|
||||
auto-rotate=""
|
||||
camera-controls=""
|
||||
background-color="#455A64">
|
||||
</model-viewer>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
new Vue({
|
||||
el: "#object"
|
||||
})
|
||||
</script>
|
||||
|
||||
<script type="module" src="/static/vendor/google/model-viewer.js"></script>
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
% rebase('base.tpl')
|
||||
|
||||
<script src="/static/vendor/vue/vue.js"></script>
|
||||
<script src="/static/vendor/vue-3d-model/vue-3d-model.umd.js"></script>
|
||||
|
||||
<h3>
|
||||
<i class="fa fa-folder-o" aria-hidden="true"></i>
|
||||
<a href="/list/{{ current_dir.rstrip('/') }}">objects{{current_dir}}</a>
|
||||
</h3>
|
||||
<h4>
|
||||
<span style="text-transform: uppercase">
|
||||
{{ object['type'] }}:
|
||||
</span>
|
||||
{{name}}
|
||||
</h4>
|
||||
|
||||
<div class="model-wrap">
|
||||
<div id="object">
|
||||
%if object['type'] == "gltf":
|
||||
<model-gltf
|
||||
src="{{ object['urls'][0] }}"
|
||||
@on-mousemove="onMouseMove"
|
||||
>
|
||||
</model-gltf>
|
||||
%end
|
||||
%if object['type'] == "obj-mtl":
|
||||
<model-obj
|
||||
src="{{ object['urls'][0] }}"
|
||||
mtl="{{ object['urls'][1] }}"
|
||||
>
|
||||
</model-obj>
|
||||
%end
|
||||
%if object['type'] == "obj":
|
||||
<model-obj
|
||||
src="{{ object['urls'][0] }}"
|
||||
>
|
||||
</model-obj>
|
||||
%end
|
||||
%if object['type'] == "fbx":
|
||||
<model-fbx
|
||||
src="{{ object['urls'][0] }}"
|
||||
>
|
||||
</model-fbx>
|
||||
%end
|
||||
%if object['type'] == "stl":
|
||||
<model-stl
|
||||
src="{{ object['urls'][0] }}"
|
||||
>
|
||||
</model-stl>
|
||||
%end
|
||||
%if object['type'] == "dae":
|
||||
<model-collada
|
||||
:backgroundAlpha="0"
|
||||
@on-load="onLoad"
|
||||
:rotation="rotation"
|
||||
src="{{ object['urls'][0] }}"
|
||||
>
|
||||
</model-collada>
|
||||
%end
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
new Vue({
|
||||
el: "#object"
|
||||
})
|
||||
</script>
|
||||
|
||||
<script type="module" src="/static/vendor/google/model-viewer.js"></script>
|
Loading…
Reference in New Issue