adds a new rendered

This commit is contained in:
buttle 2021-06-08 14:19:24 +02:00
parent 0d2cb155ce
commit 397fb2a031
8 changed files with 56785 additions and 83 deletions

9
app.py
View File

@ -73,14 +73,17 @@ def render(file_path):
#print("file_dir: ", file_dir) #print("file_dir: ", file_dir)
#print("file_name: ", file_name) #print("file_name: ", file_name)
object = utils.get_object(file_dir, [], {}) object = utils.get_object(file_path, {})
if not object: if not object:
return "Opps, no object type" return "Opps, no object type"
print("object: ", object) print("object: ", object)
if object['type'] == 'gltf':
page_tpl = "render"
else:
page_tpl = "render_1"
return template(page_tpl,
return template('render',
current_dir=file_path.replace(file_name, ""), current_dir=file_path.replace(file_name, ""),
name=file_name, name=file_name,
object=object, object=object,

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

56628
static/vendor/google/model-viewer.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -26,7 +26,7 @@ BASE_DIR = os.path.abspath(
'../') '../')
) )
OBJECT_DIR = os.path.join(BASE_DIR, 'objects') 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): def get_directory_content(dir_path):
content = [] content = []
@ -44,58 +44,78 @@ def get_directory_content(dir_path):
return content return content
def get_object(dir_path, extentions=[], result={}): def find_file_with_extension(dir, extension):
print('get_object(dir_path): ', dir_path) 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: if not result:
result['urls'] = [] result['urls'] = []
result['type'] = None result['type'] = None
if not extentions: extension = Path(file_name).suffix.lstrip('.').lower()
for p in Path(dir_path).iterdir(): print('get_object(extension):', extension)
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
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) print("p: ",p)
return 'obj-mtl' return 'obj-mtl'
if 'obj' in extentions: if 'obj' in extensions:
return 'obj' return 'obj'
if 'gltf' in extentions: if 'gltf' in extensions:
return 'gltf' return 'gltf'
if 'fbx' in extentions: if 'fbx' in extensions:
return 'fbx' return 'fbx'
if 'stl' in extentions: if 'stl' in extensions:
return 'stl' return 'stl'
""" """

View File

@ -3,6 +3,15 @@
<script src="/static/vendor/vue/vue.js"></script> <script src="/static/vendor/vue/vue.js"></script>
<script src="/static/vendor/vue-3d-model/vue-3d-model.umd.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> <h3>
<i class="fa fa-folder-o" aria-hidden="true"></i> <i class="fa fa-folder-o" aria-hidden="true"></i>
<a href="/list/{{ current_dir.rstrip('/') }}">objects{{current_dir}}</a> <a href="/list/{{ current_dir.rstrip('/') }}">objects{{current_dir}}</a>
@ -15,44 +24,15 @@
</h4> </h4>
<div class="model-wrap"> <div class="model-wrap">
<div id="object"> <div id="model">
%if object['type'] == "gltf": <model-viewer src="{{ object['urls'][0] }}"
<model-gltf alt="A 3D model of a robot"
src="{{ object['urls'][0] }}" auto-rotate=""
@on-mousemove="onMouseMove" camera-controls=""
> background-color="#455A64">
</model-gltf> </model-viewer>
%end </div>
%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>
</div> </div>
<script>
new Vue({ <script type="module" src="/static/vendor/google/model-viewer.js"></script>
el: "#object"
})
</script>

71
views/render_1.tpl Normal file
View File

@ -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>