Compare commits
No commits in common. "e37c81811bc905336f323736c0df45c3ed5e4c16" and "ecde2dc50e1c29311b7dcfba3a31f896bb9e4254" have entirely different histories.
e37c81811b
...
ecde2dc50e
31
app.py
31
app.py
|
@ -21,10 +21,12 @@ 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'))
|
||||||
|
@ -66,24 +68,19 @@ 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/', '')
|
||||||
parts = file_path.split('/')
|
print(file_path)
|
||||||
file_name = parts.pop()
|
current_path=os.path.join(OBJECT_DIR, file_path)
|
||||||
file_dir = os.path.join(OBJECT_DIR, *parts)
|
file = Path(current_path)
|
||||||
|
model_type = (Path(file.name).suffix).lstrip('.').lower()
|
||||||
print("file_dir: ", file_dir)
|
current_dir=file_path.replace(file.name, '')
|
||||||
print("file_name: ", file_name)
|
current_dir = current_dir.rstrip('/')
|
||||||
|
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=file_path.replace(file_name, ""),
|
current_dir=current_dir,
|
||||||
name=file_name,
|
name=file.name,
|
||||||
object=object,
|
object_url=object_url,
|
||||||
|
model_type=model_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
run(host='localhost', port=8080, debug=True)
|
run(host='localhost', port=8080, debug=True)
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -20,20 +20,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
BASE_DIR = os.path.abspath(
|
MODEL_TYPES = ['gltf', 'obj', 'fbx', 'stl']
|
||||||
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 OBJECT_TYPES else False
|
is_object_file = True if model_type in MODEL_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)),
|
||||||
|
@ -44,70 +38,13 @@ 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 bytes"
|
return "0 KB"
|
||||||
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:
|
||||||
|
|
|
@ -8,6 +8,10 @@ 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,54 +1,42 @@
|
||||||
% rebase('base.tpl')
|
% rebase('base.tpl')
|
||||||
|
|
||||||
<script src="/static/vendor/vue/vue.js"></script>
|
<script src="/vendor/vue/vue.js"></script>
|
||||||
<script src="/static/vendor/vue-3d-model/vue-3d-model.umd.js"></script>
|
<script src="/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">
|
||||||
<div id="object">
|
%if model_type == "gltf":
|
||||||
%if object['type'] == "gltf":
|
<div id="object">
|
||||||
<model-gltf
|
<model-gltf
|
||||||
src="{{ object['urls'][0] }}"
|
src="{{object_url}}"
|
||||||
@on-mousemove="onMouseMove"
|
@on-mousemove="onMouseMove"
|
||||||
>
|
>
|
||||||
</model-gltf>
|
</model-gltf>
|
||||||
%end
|
</div>
|
||||||
%if object['type'] == "obj-mtl":
|
%end
|
||||||
<model-obj
|
%if model_type == "obj":
|
||||||
src="{{ object['urls'][0] }}"
|
<div id="object">
|
||||||
mtl="{{ object['urls'][1] }}"
|
<model-obj src="{{object_url}}"></model-obj>
|
||||||
>
|
</div>
|
||||||
</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>
|
||||||
>
|
%end
|
||||||
</model-obj>
|
%if model_type == "stl":
|
||||||
%end
|
<div id="object">
|
||||||
%if object['type'] == "fbx":
|
<model-stl src="{{object_url}}"></model-stl>
|
||||||
<model-fbx
|
</div>
|
||||||
src="{{ object['urls'][0] }}"
|
%end
|
||||||
>
|
|
||||||
</model-fbx>
|
|
||||||
%end
|
|
||||||
%if object['type'] == "stl":
|
|
||||||
<model-stl
|
|
||||||
src="{{ object['urls'][0] }}"
|
|
||||||
>
|
|
||||||
</model-stl>
|
|
||||||
%end
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
Loading…
Reference in New Issue