Compare commits

..

No commits in common. "e37c81811bc905336f323736c0df45c3ed5e4c16" and "ecde2dc50e1c29311b7dcfba3a31f896bb9e4254" have entirely different histories.

11 changed files with 49 additions and 123 deletions

31
app.py
View File

@ -21,10 +21,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import os, sys
from pathlib import Path
from bottle import route, run, error, abort, template, response, static_file
from utils.utils import BASE_DIR, OBJECT_DIR
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')
def serve_static(filename):
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>')
def render(file_path):
file_path = file_path.replace('/render/', '')
parts = file_path.split('/')
file_name = parts.pop()
file_dir = os.path.join(OBJECT_DIR, *parts)
print("file_dir: ", file_dir)
print("file_name: ", file_name)
object = utils.get_object(file_dir, [], {})
if not object:
return "Opps, no object type"
print("object: ", object)
print(file_path)
current_path=os.path.join(OBJECT_DIR, file_path)
file = Path(current_path)
model_type = (Path(file.name).suffix).lstrip('.').lower()
current_dir=file_path.replace(file.name, '')
current_dir = current_dir.rstrip('/')
object_url = f"/objects/{current_dir}/{file.name}"
return template('render',
current_dir=file_path.replace(file_name, ""),
name=file_name,
object=object,
current_dir=current_dir,
name=file.name,
object_url=object_url,
model_type=model_type,
)
run(host='localhost', port=8080, debug=True)

Binary file not shown.

View File

@ -20,20 +20,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
from pathlib import Path
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']
MODEL_TYPES = ['gltf', 'obj', 'fbx', 'stl']
def get_directory_content(dir_path):
content = []
for p in Path(dir_path).iterdir():
file = Path(p)
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 = {
'name': os.path.basename(p),
'size': human_readable_bytes(os.path.getsize(p)),
@ -44,70 +38,13 @@ def get_directory_content(dir_path):
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):
""" 1 KibiByte == 1024 Bytes
1 Mebibyte == 1024*1024 Bytes
1 GibiByte == 1024*1024*1024 Bytes
"""
if bytes == 0:
return "0 bytes"
if bytes < 1024:
return f"{bytes} bytes"
return "0 KB"
if bytes < 1024*1024:
return f"{int(round(bytes/(1024), 2))} KB"
if bytes < 1024*1024*1024:

View File

@ -8,6 +8,10 @@ td .fa {
</style>
<h1>
Directory list
</h1>
<h3>
<i class="fa fa-folder-o" aria-hidden="true"></i>
objects{{current_dir}}

View File

@ -1,54 +1,42 @@
% rebase('base.tpl')
<script src="/static/vendor/vue/vue.js"></script>
<script src="/static/vendor/vue-3d-model/vue-3d-model.umd.js"></script>
<script src="/vendor/vue/vue.js"></script>
<script src="/vendor/vue-3d-model/vue-3d-model.umd.js"></script>
<h1>
Render {{name}}
</h1>
<h3>
<i class="fa fa-folder-o" aria-hidden="true"></i>
<a href="/list/{{current_dir}}">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":
%if model_type == "gltf":
<div id="object">
<model-gltf
src="{{ object['urls'][0] }}"
@on-mousemove="onMouseMove"
>
src="{{object_url}}"
@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>
</div>
%end
%if model_type == "obj":
<div id="object">
<model-obj src="{{object_url}}"></model-obj>
</div>
%end
%if model_type == "fbx":
<div id="object">
<model-fbx src="{{object_url}}"></model-fbx>
</div>
%end
%if model_type == "stl":
<div id="object">
<model-stl src="{{object_url}}"></model-stl>
</div>
%end
</div>
<script>