Compare commits

...

3 Commits

Author SHA1 Message Date
buttle e37c81811b utils returns list dict 2021-06-08 11:08:02 +02:00
buttle 3cd559fde5 moves vendor library 2021-06-08 11:07:33 +02:00
buttle 7fa6ff73ff adds fontawsome 2021-06-08 09:53:14 +02:00
11 changed files with 123 additions and 49 deletions

31
app.py
View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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

View File

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

View File

@ -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 object['type'] == "obj-mtl":
%if model_type == "obj": <model-obj
<div id="object"> src="{{ object['urls'][0] }}"
<model-obj src="{{object_url}}"></model-obj> mtl="{{ object['urls'][1] }}"
</div> >
%end </model-obj>
%if model_type == "fbx": %end
<div id="object"> %if object['type'] == "obj":
<model-fbx src="{{object_url}}"></model-fbx> <model-obj
</div> src="{{ object['urls'][0] }}"
%end >
%if model_type == "stl": </model-obj>
<div id="object"> %end
<model-stl src="{{object_url}}"></model-stl> %if object['type'] == "fbx":
</div> <model-fbx
%end src="{{ object['urls'][0] }}"
>
</model-fbx>
%end
%if object['type'] == "stl":
<model-stl
src="{{ object['urls'][0] }}"
>
</model-stl>
%end
</div>
</div> </div>
<script> <script>