Lod picker

This commit is contained in:
Aaron Kimbre 2022-02-11 17:37:43 -06:00
parent 8646c40943
commit 869bbdf7e6
4 changed files with 67 additions and 36 deletions

View File

@ -23,6 +23,7 @@ import zlib
import xmltodict import xmltodict
import os import os
import app.pylddlib as ldd import app.pylddlib as ldd
import pathlib
property_blueprint = Blueprint('properties', __name__) property_blueprint = Blueprint('properties', __name__)
@ -206,16 +207,16 @@ def get(status="all"):
return data return data
@property_blueprint.route('/view_model/<id>', methods=['GET']) @property_blueprint.route('/view_model/<id>/<lod>', methods=['GET'])
@login_required @login_required
def view_model(id): def view_model(id, lod):
property_content_data = PropertyContent.query.filter(PropertyContent.id==id).all() property_content_data = PropertyContent.query.filter(PropertyContent.id==id).all()
# TODO: Restrict somehow # TODO: Restrict somehow
formatted_data = [ formatted_data = [
{ {
"obj": url_for('properties.get_model', id=property_content_data[0].id, file_format='obj'), "obj": url_for('properties.get_model', id=property_content_data[0].id, file_format='obj', lod=lod),
"mtl": url_for('properties.get_model', id=property_content_data[0].id, file_format='mtl'), "mtl": url_for('properties.get_model', id=property_content_data[0].id, file_format='mtl', lod=lod),
"lot": property_content_data[0].lot, "lot": property_content_data[0].lot,
"id": property_content_data[0].id, "id": property_content_data[0].id,
"pos": [{ "pos": [{
@ -232,7 +233,8 @@ def view_model(id):
return render_template( return render_template(
'ldd/ldd.html.j2', 'ldd/ldd.html.j2',
content=formatted_data content=formatted_data,
lod=lod
) )
property_center = { property_center = {
@ -245,9 +247,9 @@ property_center = {
} }
@property_blueprint.route('/view_models/<id>', methods=['GET']) @property_blueprint.route('/view_models/<id>/<lod>', methods=['GET'])
@login_required @login_required
def view_models(id): def view_models(id, lod):
property_content_data = PropertyContent.query.filter( property_content_data = PropertyContent.query.filter(
PropertyContent.property_id==id PropertyContent.property_id==id
).order_by(PropertyContent.lot).all() ).order_by(PropertyContent.lot).all()
@ -273,8 +275,8 @@ def view_models(id):
# add new lot # add new lot
consolidated_list.append( consolidated_list.append(
{ {
"obj": url_for('properties.get_model', id=property_content_data[item].id, file_format='obj'), "obj": url_for('properties.get_model', id=property_content_data[item].id, file_format='obj', lod=lod),
"mtl": url_for('properties.get_model', id=property_content_data[item].id, file_format='mtl'), "mtl": url_for('properties.get_model', id=property_content_data[item].id, file_format='mtl', lod=lod),
"lot": property_content_data[item].lot, "lot": property_content_data[item].lot,
"id": property_content_data[item].id, "id": property_content_data[item].id,
"pos": [{ "pos": [{
@ -293,18 +295,20 @@ def view_models(id):
'ldd/ldd.html.j2', 'ldd/ldd.html.j2',
property_data=property_data, property_data=property_data,
content=consolidated_list, content=consolidated_list,
center=property_center[property_data.zone_id] center=property_center[property_data.zone_id],
lod=lod
) )
@property_blueprint.route('/get_model/<id>/<file_format>', methods=['GET']) @property_blueprint.route('/get_model/<id>/<file_format>/<lod>', methods=['GET'])
@login_required @login_required
def get_model(id, file_format): def get_model(id, file_format, lod):
content = PropertyContent.query.filter(PropertyContent.id==id).first() content = PropertyContent.query.filter(PropertyContent.id==id).first()
if not(0 <= int(lod) <= 2):
abort(404)
if content.lot == 14: # ugc model if content.lot == 14: # ugc model
response = ugc(content)[0] response = ugc(content)[0]
else: # prebuild model else: # prebuild model
response = prebuilt(content, file_format)[0] response = prebuilt(content, file_format, lod)[0]
response.headers.set('Content-Type', 'text/xml') response.headers.set('Content-Type', 'text/xml')
return response return response
@ -337,7 +341,7 @@ def ugc(content):
return response, ugc_data.filename return response, ugc_data.filename
def prebuilt(content, file_format): def prebuilt(content, file_format, lod):
# translate LOT to component id # translate LOT to component id
# we need to get a type of 2 because reasons # we need to get a type of 2 because reasons
render_component_id = query_cdclient( render_component_id = query_cdclient(
@ -357,7 +361,7 @@ def prebuilt(content, file_format):
return f"No filename for LOT {content.lot}" return f"No filename for LOT {content.lot}"
if file_format == "lxfml": if file_format == "lxfml":
lxfml = f'app/luclient/res/BrickModels/{filename.split(".")[0]}.lxfml' lxfml = pathilob.Path(f'app/luclient/res/BrickModels/{filename.split(".")[0]}.lxfml')
with open(lxfml, 'r') as file: with open(lxfml, 'r') as file:
lxfml_data = file.read() lxfml_data = file.read()
# print(lxfml_data) # print(lxfml_data)
@ -365,7 +369,7 @@ def prebuilt(content, file_format):
elif file_format in ["obj", "mtl"]: elif file_format in ["obj", "mtl"]:
cache = f"app/cache/{filename}.{file_format}" cache = f"app/cache/BrickModels/{filename}.lod{lod}.{file_format}"
if not os.path.exists(cache): if not os.path.exists(cache):
lxfml = f'app/luclient/res/BrickModels/{filename.split(".")[0]}.lxfml' lxfml = f'app/luclient/res/BrickModels/{filename.split(".")[0]}.lxfml'

View File

@ -467,16 +467,16 @@
constructor(designID, database){ constructor(designID, database){
this.designID = designID this.designID = designID
this.Parts = [] this.Parts = []
this.studsFields2D = [] this.studsFields2D = []
let GeometryLocation = `${designID}.g` let lod = {{ lod }}
let GeometryLocation = `lod${lod}/${designID}.g`
let PrimitiveLocation = `${designID}.xml` let PrimitiveLocation = `${designID}.xml`
let GeometryCount = 0 let GeometryCount = 0
while (GeometryLocation in database.filelist) { while (GeometryLocation in database.filelist) {
this.Parts[GeometryCount] = new GeometryReader(database.filelist[GeometryLocation].read()) this.Parts[GeometryCount] = new GeometryReader(database.filelist[GeometryLocation].read())
GeometryCount = GeometryCount + 1 GeometryCount = GeometryCount + 1
GeometryLocation = `${designID}.g${GeometryCount}` GeometryLocation = `lod${lod}/${designID}.g${GeometryCount}`
} }
let primitive = new Primitive(database.filelist[PrimitiveLocation].read()) let primitive = new Primitive(database.filelist[PrimitiveLocation].read())
this.Partname = primitive.Designname this.Partname = primitive.Designname
@ -1019,7 +1019,7 @@
return self.filelist[filename]; return self.filelist[filename];
} }
parse(dburl) { parse(dburl, folder="") {
let self = this; let self = this;
let xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.open('GET', dburl, false); xhr.open('GET', dburl, false);
@ -1038,11 +1038,17 @@
let obj = data[i]; let obj = data[i];
if (obj.type == 'directory'){ if (obj.type == 'directory'){
// parse subdirs // parse subdirs
self.parse(dburl + obj.name + '/') self.parse(dburl + obj.name + '/', obj.name)
} }
else if (obj.type == 'file'){ else if (obj.type == 'file'){
if (folder.includes("lod")){
self.filelist[`${folder}/${obj.name}`] = new DBURLFile(dburl + obj.name, obj.name)
} else {
self.filelist[obj.name] = new DBURLFile(dburl + obj.name, obj.name) self.filelist[obj.name] = new DBURLFile(dburl + obj.name, obj.name)
} }
}
else { else {
console.log('Strange object parsed: ' + obj.type) console.log('Strange object parsed: ' + obj.type)
} }
@ -1063,7 +1069,7 @@
let lxfml_file_list = [ let lxfml_file_list = [
{% for model in content %} {% for model in content %}
{% if model.lot == 14 %} {% if model.lot == 14 %}
"{{url_for('properties.get_model', id=model.id, file_format='lxfml')}}"{{ ", " if not loop.last else "" }} "{{url_for('properties.get_model', id=model.id, file_format='lxfml', lod=lod)}}"{{ ", " if not loop.last else "" }}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
] ]

View File

@ -84,8 +84,16 @@
<div class="row"> <div class="row">
<div class="col text-center"> <div class="col text-center">
<a role="button" class="btn btn-primary btn-block" <a role="button" class="btn btn-primary btn-block"
href='{{ url_for('properties.view_models', id=property.id) }}'> href='{{ url_for('properties.view_models', id=property.id, lod=0) }}'>
Render Property Render: High
</a>
<a role="button" class="btn btn-primary btn-block"
href='{{ url_for('properties.view_models', id=property.id, lod=1) }}'>
Render: Medium
</a>
<a role="button" class="btn btn-primary btn-block"
href='{{ url_for('properties.view_models', id=property.id, lod=2) }}'>
Render: Low
</a> </a>
</div> </div>
</div> </div>

View File

@ -44,21 +44,12 @@
<div class="row"> <div class="row">
<div class="col text-center"> <div class="col text-center">
<a role="button" class="btn btn-primary btn-block" <a role="button" class="btn btn-primary btn-block"
href='{{ url_for('properties.get_model', id=item.id, file_format="lxfml") }}'> href='{{ url_for('properties.get_model', id=item.id, file_format="lxfml", lod=0) }}'>
View Model XML View Model XML
</a> </a>
</div> </div>
</div> </div>
<br/> <br/>
<div class="row">
<div class="col text-center">
<a role="button" class="btn btn-primary btn-block"
href='{{ url_for('properties.view_model', id=item.id) }}'>
Render Model
</a>
</div>
</div>
<br/>
<div class="row"> <div class="row">
<div class="col text-center"> <div class="col text-center">
<a role="button" class="btn btn-primary btn-block" <a role="button" class="btn btn-primary btn-block"
@ -67,5 +58,27 @@
</a> </a>
</div> </div>
</div> </div>
<br/>
<h5 class="text-center"> Render </h5>
<div class="row">
<div class="col text-center">
<a role="button" class="btn btn-primary"
href='{{ url_for('properties.view_model', id=item.id, lod=0) }}'>
0
</a>
</div>
<div class="col text-center">
<a role="button" class="btn btn-primary"
href='{{ url_for('properties.view_model', id=item.id, lod=1) }}'>
1
</a>
</div>
<div class="col text-center">
<a role="button" class="btn btn-primary"
href='{{ url_for('properties.view_model', id=item.id, lod=2) }}'>
2
</a>
</div>
</div>
</div> </div>
</div> </div>