utils returns list dict
This commit is contained in:
parent
3cd559fde5
commit
e37c81811b
31
app.py
31
app.py
|
@ -21,12 +21,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
import os, sys
|
import os, sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from bottle import route, run, error, abort, template, response, static_file
|
from bottle import route, run, error, abort, template, response, static_file
|
||||||
|
from utils.utils import BASE_DIR, OBJECT_DIR
|
||||||
from utils import utils
|
from utils import utils
|
||||||
|
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
OBJECT_DIR = os.path.join(BASE_DIR, 'objects')
|
|
||||||
|
|
||||||
@route('/static/<filename:path>', name='static')
|
@route('/static/<filename:path>', name='static')
|
||||||
def serve_static(filename):
|
def serve_static(filename):
|
||||||
return static_file(filename, root=os.path.join(BASE_DIR, 'static'))
|
return static_file(filename, root=os.path.join(BASE_DIR, 'static'))
|
||||||
|
@ -68,19 +66,24 @@ def list_dir(dir_path):
|
||||||
@route('/render/<file_path:path>')
|
@route('/render/<file_path:path>')
|
||||||
def render(file_path):
|
def render(file_path):
|
||||||
file_path = file_path.replace('/render/', '')
|
file_path = file_path.replace('/render/', '')
|
||||||
print(file_path)
|
parts = file_path.split('/')
|
||||||
current_path=os.path.join(OBJECT_DIR, file_path)
|
file_name = parts.pop()
|
||||||
file = Path(current_path)
|
file_dir = os.path.join(OBJECT_DIR, *parts)
|
||||||
model_type = (Path(file.name).suffix).lstrip('.').lower()
|
|
||||||
current_dir=file_path.replace(file.name, '')
|
print("file_dir: ", file_dir)
|
||||||
current_dir = current_dir.rstrip('/')
|
print("file_name: ", file_name)
|
||||||
object_url = f"/objects/{current_dir}/{file.name}"
|
|
||||||
|
object = utils.get_object(file_dir, [], {})
|
||||||
|
if not object:
|
||||||
|
return "Opps, no object type"
|
||||||
|
|
||||||
|
print("object: ", object)
|
||||||
|
|
||||||
|
|
||||||
return template('render',
|
return template('render',
|
||||||
current_dir=current_dir,
|
current_dir=file_path.replace(file_name, ""),
|
||||||
name=file.name,
|
name=file_name,
|
||||||
object_url=object_url,
|
object=object,
|
||||||
model_type=model_type,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
run(host='localhost', port=8080, debug=True)
|
run(host='localhost', port=8080, debug=True)
|
||||||
|
|
|
@ -20,14 +20,20 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
MODEL_TYPES = ['gltf', 'obj', 'fbx', 'stl']
|
BASE_DIR = os.path.abspath(
|
||||||
|
os.path.join(
|
||||||
|
os.path.dirname(os.path.realpath(__file__)),
|
||||||
|
'../')
|
||||||
|
)
|
||||||
|
OBJECT_DIR = os.path.join(BASE_DIR, 'objects')
|
||||||
|
OBJECT_TYPES = ['gltf', 'obj', 'fbx', 'stl']
|
||||||
|
|
||||||
def get_directory_content(dir_path):
|
def get_directory_content(dir_path):
|
||||||
content = []
|
content = []
|
||||||
for p in Path(dir_path).iterdir():
|
for p in Path(dir_path).iterdir():
|
||||||
file = Path(p)
|
file = Path(p)
|
||||||
model_type = (Path(file.name).suffix).lstrip('.').lower()
|
model_type = (Path(file.name).suffix).lstrip('.').lower()
|
||||||
is_object_file = True if model_type in MODEL_TYPES else False
|
is_object_file = True if model_type in OBJECT_TYPES else False
|
||||||
item = {
|
item = {
|
||||||
'name': os.path.basename(p),
|
'name': os.path.basename(p),
|
||||||
'size': human_readable_bytes(os.path.getsize(p)),
|
'size': human_readable_bytes(os.path.getsize(p)),
|
||||||
|
@ -38,13 +44,70 @@ def get_directory_content(dir_path):
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
def get_object(dir_path, extentions=[], result={}):
|
||||||
|
print('get_object(dir_path): ', dir_path)
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
if 'obj' in extentions and 'mtl' in extentions:
|
||||||
|
print("p: ",p)
|
||||||
|
return 'obj-mtl'
|
||||||
|
if 'obj' in extentions:
|
||||||
|
return 'obj'
|
||||||
|
if 'gltf' in extentions:
|
||||||
|
return 'gltf'
|
||||||
|
if 'fbx' in extentions:
|
||||||
|
return 'fbx'
|
||||||
|
if 'stl' in extentions:
|
||||||
|
return 'stl'
|
||||||
|
"""
|
||||||
|
|
||||||
def human_readable_bytes(bytes):
|
def human_readable_bytes(bytes):
|
||||||
""" 1 KibiByte == 1024 Bytes
|
""" 1 KibiByte == 1024 Bytes
|
||||||
1 Mebibyte == 1024*1024 Bytes
|
1 Mebibyte == 1024*1024 Bytes
|
||||||
1 GibiByte == 1024*1024*1024 Bytes
|
1 GibiByte == 1024*1024*1024 Bytes
|
||||||
"""
|
"""
|
||||||
if bytes == 0:
|
if bytes == 0:
|
||||||
return "0 KB"
|
return "0 bytes"
|
||||||
|
if bytes < 1024:
|
||||||
|
return f"{bytes} bytes"
|
||||||
if bytes < 1024*1024:
|
if bytes < 1024*1024:
|
||||||
return f"{int(round(bytes/(1024), 2))} KB"
|
return f"{int(round(bytes/(1024), 2))} KB"
|
||||||
if bytes < 1024*1024*1024:
|
if bytes < 1024*1024*1024:
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2017-present, Jiulong Hu
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
|
@ -1,6 +0,0 @@
|
||||||
# vue-3d-model
|
|
||||||
|
|
||||||
|
|
||||||
https://github.com/hujiulong/vue-3d-model
|
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
@ -8,10 +8,6 @@ td .fa {
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<h1>
|
|
||||||
Directory list
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<h3>
|
<h3>
|
||||||
<i class="fa fa-folder-o" aria-hidden="true"></i>
|
<i class="fa fa-folder-o" aria-hidden="true"></i>
|
||||||
objects{{current_dir}}
|
objects{{current_dir}}
|
||||||
|
|
|
@ -1,42 +1,54 @@
|
||||||
% rebase('base.tpl')
|
% rebase('base.tpl')
|
||||||
|
|
||||||
<script src="/vendor/vue/vue.js"></script>
|
<script src="/static/vendor/vue/vue.js"></script>
|
||||||
<script src="/vendor/vue-3d-model/vue-3d-model.umd.js"></script>
|
<script src="/static/vendor/vue-3d-model/vue-3d-model.umd.js"></script>
|
||||||
|
|
||||||
<h1>
|
|
||||||
Render {{name}}
|
|
||||||
</h1>
|
|
||||||
<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}}">objects{{current_dir}}</a>
|
<a href="/list/{{current_dir}}">objects{{current_dir}}</a>
|
||||||
</h3>
|
</h3>
|
||||||
|
<h4>
|
||||||
|
<span style="text-transform: uppercase">
|
||||||
|
{{ object['type'] }}:
|
||||||
|
</span>
|
||||||
|
{{name}}
|
||||||
|
</h4>
|
||||||
|
|
||||||
<div class="model-wrap">
|
<div class="model-wrap">
|
||||||
%if model_type == "gltf":
|
|
||||||
<div id="object">
|
<div id="object">
|
||||||
|
%if object['type'] == "gltf":
|
||||||
<model-gltf
|
<model-gltf
|
||||||
src="{{object_url}}"
|
src="{{ object['urls'][0] }}"
|
||||||
@on-mousemove="onMouseMove"
|
@on-mousemove="onMouseMove"
|
||||||
>
|
>
|
||||||
</model-gltf>
|
</model-gltf>
|
||||||
</div>
|
|
||||||
%end
|
%end
|
||||||
%if model_type == "obj":
|
%if object['type'] == "obj-mtl":
|
||||||
<div id="object">
|
<model-obj
|
||||||
<model-obj src="{{object_url}}"></model-obj>
|
src="{{ object['urls'][0] }}"
|
||||||
</div>
|
mtl="{{ object['urls'][1] }}"
|
||||||
|
>
|
||||||
|
</model-obj>
|
||||||
%end
|
%end
|
||||||
%if model_type == "fbx":
|
%if object['type'] == "obj":
|
||||||
<div id="object">
|
<model-obj
|
||||||
<model-fbx src="{{object_url}}"></model-fbx>
|
src="{{ object['urls'][0] }}"
|
||||||
</div>
|
>
|
||||||
|
</model-obj>
|
||||||
%end
|
%end
|
||||||
%if model_type == "stl":
|
%if object['type'] == "fbx":
|
||||||
<div id="object">
|
<model-fbx
|
||||||
<model-stl src="{{object_url}}"></model-stl>
|
src="{{ object['urls'][0] }}"
|
||||||
</div>
|
>
|
||||||
|
</model-fbx>
|
||||||
%end
|
%end
|
||||||
|
%if object['type'] == "stl":
|
||||||
|
<model-stl
|
||||||
|
src="{{ object['urls'][0] }}"
|
||||||
|
>
|
||||||
|
</model-stl>
|
||||||
|
%end
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
Loading…
Reference in New Issue