mirror of
https://github.com/DarkflameUniverse/NexusDashboard.git
synced 2024-11-25 15:07:18 +00:00
lod differentiation
pre-gen commands
This commit is contained in:
parent
ba0c4801df
commit
8646c40943
@ -12,7 +12,7 @@ from flask_wtf.csrf import CSRFProtect
|
|||||||
from flask_apscheduler import APScheduler
|
from flask_apscheduler import APScheduler
|
||||||
from app.luclient import query_cdclient, register_luclient_jinja_helpers
|
from app.luclient import query_cdclient, register_luclient_jinja_helpers
|
||||||
|
|
||||||
from app.commands import init_db, init_accounts, load_property
|
from app.commands import init_db, init_accounts, load_property, gen_image_cache, gen_model_cache
|
||||||
from app.models import Account, AccountInvitation
|
from app.models import Account, AccountInvitation
|
||||||
|
|
||||||
# Instantiate Flask extensions
|
# Instantiate Flask extensions
|
||||||
@ -65,6 +65,8 @@ def create_app():
|
|||||||
app.cli.add_command(init_db)
|
app.cli.add_command(init_db)
|
||||||
app.cli.add_command(init_accounts)
|
app.cli.add_command(init_accounts)
|
||||||
app.cli.add_command(load_property)
|
app.cli.add_command(load_property)
|
||||||
|
app.cli.add_command(gen_image_cache)
|
||||||
|
app.cli.add_command(gen_model_cache)
|
||||||
|
|
||||||
register_settings(app)
|
register_settings(app)
|
||||||
register_extensions(app)
|
register_extensions(app)
|
||||||
|
@ -7,6 +7,12 @@ from app import db
|
|||||||
from app.models import Account, PlayKey, CharacterInfo, Property, PropertyContent, UGC
|
from app.models import Account, PlayKey, CharacterInfo, Property, PropertyContent, UGC
|
||||||
import pathlib
|
import pathlib
|
||||||
import zlib
|
import zlib
|
||||||
|
import os
|
||||||
|
from wand import image
|
||||||
|
from wand.exceptions import BlobError as BE
|
||||||
|
import app.pylddlib as ldd
|
||||||
|
from multiprocessing import Pool
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
@click.command("init_db")
|
@click.command("init_db")
|
||||||
@click.argument('drop_tables', nargs=1)
|
@click.argument('drop_tables', nargs=1)
|
||||||
@ -89,6 +95,54 @@ def load_property(zone, player):
|
|||||||
)
|
)
|
||||||
new_prop_content.save()
|
new_prop_content.save()
|
||||||
|
|
||||||
|
@click.command("gen_image_cache")
|
||||||
|
def gen_image_cache():
|
||||||
|
luclient = pathlib.Path('app/luclient/res')
|
||||||
|
files = [path for path in luclient.rglob("*.dds") if path.is_file()]
|
||||||
|
|
||||||
|
for file in files:
|
||||||
|
cache = get_cache_file(file).with_suffix(".png")
|
||||||
|
if not cache.exists():
|
||||||
|
try:
|
||||||
|
print(f"Convert {file.as_posix()} to {cache}")
|
||||||
|
cache.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with image.Image(filename=str(file.as_posix())) as img:
|
||||||
|
img.compression = "no"
|
||||||
|
img.save(filename=str(cache.as_posix()))
|
||||||
|
except BE:
|
||||||
|
return print(f"Error on {file}")
|
||||||
|
|
||||||
|
@click.command("gen_model_cache")
|
||||||
|
def gen_model_cache():
|
||||||
|
luclient = pathlib.Path('app/luclient/res')
|
||||||
|
files = [path for path in luclient.rglob("*.lxfml") if path.is_file()]
|
||||||
|
pool = Pool(processes=4)
|
||||||
|
pool.map(partial(convert_lxfml_to_obj, lod=0), files)
|
||||||
|
pool.map(partial(convert_lxfml_to_obj, lod=1), files)
|
||||||
|
pool.map(partial(convert_lxfml_to_obj, lod=2), files)
|
||||||
|
|
||||||
|
def convert_lxfml_to_obj(file, lod):
|
||||||
|
mtl = get_cache_file(file).with_suffix(f".lod{lod}.mtl")
|
||||||
|
if not mtl.exists():
|
||||||
|
mtl.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
print(f"Convert LXFML {file.as_posix()} to obj and mtl @ {mtl}")
|
||||||
|
try:
|
||||||
|
ldd.main(str(file.as_posix()), str(mtl.with_suffix("").as_posix()), lod) # convert to OBJ
|
||||||
|
except Exception as e:
|
||||||
|
print(f"ERROR on {file}:\n {e}")
|
||||||
|
else:
|
||||||
|
# print(f"Already Exists: {file} with LOD {lod}")
|
||||||
|
return
|
||||||
|
|
||||||
|
def get_cache_file(path):
|
||||||
|
# convert to list so that we can change elements
|
||||||
|
parts = list(path.parts)
|
||||||
|
|
||||||
|
# replace part that matches src with dst
|
||||||
|
parts[parts.index("luclient")] = "cache"
|
||||||
|
del parts[parts.index("res")]
|
||||||
|
|
||||||
|
return pathlib.Path(*parts)
|
||||||
|
|
||||||
def find_or_create_account(name, email, password, gm_level=9):
|
def find_or_create_account(name, email, password, gm_level=9):
|
||||||
""" Find existing account or create new account """
|
""" Find existing account or create new account """
|
||||||
@ -119,5 +173,3 @@ def find_or_create_account(name, email, password, gm_level=9):
|
|||||||
db.session.add(play_key)
|
db.session.add(play_key)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return # account
|
return # account
|
||||||
|
|
||||||
|
|
||||||
|
@ -367,19 +367,13 @@ def prebuilt(content, file_format):
|
|||||||
|
|
||||||
cache = f"app/cache/{filename}.{file_format}"
|
cache = f"app/cache/{filename}.{file_format}"
|
||||||
|
|
||||||
if os.path.exists(cache):
|
if not os.path.exists(cache):
|
||||||
with open(cache, 'r') as file:
|
|
||||||
cache_data = file.read()
|
|
||||||
response = make_response(cache_data)
|
|
||||||
|
|
||||||
else:
|
|
||||||
lxfml = f'app/luclient/res/BrickModels/{filename.split(".")[0]}.lxfml'
|
lxfml = f'app/luclient/res/BrickModels/{filename.split(".")[0]}.lxfml'
|
||||||
ldd.main(lxfml, cache.split('.')[0]) # convert to OBJ
|
ldd.main(lxfml, cache.split('.')[0]) # convert to OBJ
|
||||||
|
|
||||||
if os.path.exists(cache):
|
with open(cache, 'r') as file:
|
||||||
with open(cache, 'r') as file:
|
cache_data = file.read()
|
||||||
cache_data = file.read()
|
response = make_response(cache_data)
|
||||||
response = make_response(cache_data)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise(Exception("INVALID FILE FORMAT"))
|
raise(Exception("INVALID FILE FORMAT"))
|
||||||
|
@ -30,7 +30,7 @@ if sys.version_info < (3, 0):
|
|||||||
sys.setdefaultencoding('utf-8')
|
sys.setdefaultencoding('utf-8')
|
||||||
|
|
||||||
PRIMITIVEPATH = '/Primitives/'
|
PRIMITIVEPATH = '/Primitives/'
|
||||||
GEOMETRIEPATH = PRIMITIVEPATH + 'LOD0/'
|
GEOMETRIEPATH = PRIMITIVEPATH
|
||||||
DECORATIONPATH = '/Decorations/'
|
DECORATIONPATH = '/Decorations/'
|
||||||
MATERIALNAMESPATH = '/MaterialNames/'
|
MATERIALNAMESPATH = '/MaterialNames/'
|
||||||
|
|
||||||
@ -238,10 +238,10 @@ class Scene:
|
|||||||
for childnode in node.childNodes:
|
for childnode in node.childNodes:
|
||||||
if childnode.nodeName == 'BrickSet':
|
if childnode.nodeName == 'BrickSet':
|
||||||
self.Version = str(childnode.getAttribute('version'))
|
self.Version = str(childnode.getAttribute('version'))
|
||||||
elif node.nodeName == 'Cameras':
|
# elif node.nodeName == 'Cameras':
|
||||||
for childnode in node.childNodes:
|
# for childnode in node.childNodes:
|
||||||
if childnode.nodeName == 'Camera':
|
# if childnode.nodeName == 'Camera':
|
||||||
self.Scenecamera.append(SceneCamera(node=childnode))
|
# self.Scenecamera.append(SceneCamera(node=childnode))
|
||||||
elif node.nodeName == 'Bricks':
|
elif node.nodeName == 'Bricks':
|
||||||
for childnode in node.childNodes:
|
for childnode in node.childNodes:
|
||||||
if childnode.nodeName == 'Brick':
|
if childnode.nodeName == 'Brick':
|
||||||
@ -720,8 +720,10 @@ class Converter:
|
|||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
out = open(filename + ".obj.tmp", "w+")
|
out = open(filename + ".obj.tmp", "w+")
|
||||||
|
out.truncate(0)
|
||||||
out.write("mtllib " + filename + ".mtl" + '\n\n')
|
out.write("mtllib " + filename + ".mtl" + '\n\n')
|
||||||
outtext = open(filename + ".mtl.tmp", "w+")
|
outtext = open(filename + ".mtl.tmp", "w+")
|
||||||
|
outtext.truncate(0)
|
||||||
|
|
||||||
total = len(self.scene.Bricks)
|
total = len(self.scene.Bricks)
|
||||||
current = 0
|
current = 0
|
||||||
@ -823,13 +825,13 @@ class Converter:
|
|||||||
sys.stdout.write('%s\r' % (' '))
|
sys.stdout.write('%s\r' % (' '))
|
||||||
# print("--- %s seconds ---" % (time.time() - start_time))
|
# print("--- %s seconds ---" % (time.time() - start_time))
|
||||||
|
|
||||||
def setDBFolderVars(dbfolderlocation):
|
def setDBFolderVars(dbfolderlocation, lod):
|
||||||
global PRIMITIVEPATH
|
global PRIMITIVEPATH
|
||||||
global GEOMETRIEPATH
|
global GEOMETRIEPATH
|
||||||
global DECORATIONPATH
|
global DECORATIONPATH
|
||||||
global MATERIALNAMESPATH
|
global MATERIALNAMESPATH
|
||||||
PRIMITIVEPATH = os.path.join(dbfolderlocation, 'Primitives', '')
|
PRIMITIVEPATH = os.path.join(dbfolderlocation, 'Primitives', '')
|
||||||
GEOMETRIEPATH = os.path.join(dbfolderlocation, 'brickprimitives', 'lod0', '')
|
GEOMETRIEPATH = os.path.join(dbfolderlocation, 'brickprimitives', f'lod{lod}', '')
|
||||||
DECORATIONPATH = os.path.join(dbfolderlocation, 'Decorations', '')
|
DECORATIONPATH = os.path.join(dbfolderlocation, 'Decorations', '')
|
||||||
MATERIALNAMESPATH = os.path.join(dbfolderlocation, 'MaterialNames', '')
|
MATERIALNAMESPATH = os.path.join(dbfolderlocation, 'MaterialNames', '')
|
||||||
# print(MATERIALNAMESPATH)
|
# print(MATERIALNAMESPATH)
|
||||||
@ -880,7 +882,7 @@ def progress(count, total, status='', suffix = ''):
|
|||||||
sys.stdout.write('Progress: [%s] %s%s %s %s\r' % (bar, percents, '%', suffix, status))
|
sys.stdout.write('Progress: [%s] %s%s %s %s\r' % (bar, percents, '%', suffix, status))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def main(lxf_filename, obj_filename):
|
def main(lxf_filename, obj_filename, lod="2"):
|
||||||
# print("- - - pylddlib - - -")
|
# print("- - - pylddlib - - -")
|
||||||
# print(" _ ")
|
# print(" _ ")
|
||||||
# print(" [_]")
|
# print(" [_]")
|
||||||
@ -890,10 +892,11 @@ def main(lxf_filename, obj_filename):
|
|||||||
# print(" [=|=]")
|
# print(" [=|=]")
|
||||||
# print("")
|
# print("")
|
||||||
# print("- - - - - - - - - - - -")
|
# print("- - - - - - - - - - - -")
|
||||||
|
global GEOMETRIEPATH
|
||||||
|
GEOMETRIEPATH = GEOMETRIEPATH + f"LOD{lod}/"
|
||||||
converter = Converter()
|
converter = Converter()
|
||||||
# print("Found DB folder. Will use this instead of db.lif!")
|
# print("Found DB folder. Will use this instead of db.lif!")
|
||||||
setDBFolderVars(dbfolderlocation = "app/luclient/res/")
|
setDBFolderVars(dbfolderlocation = "app/luclient/res/", lod=lod)
|
||||||
converter.LoadDBFolder(dbfolderlocation = "app/luclient/res/")
|
converter.LoadDBFolder(dbfolderlocation = "app/luclient/res/")
|
||||||
converter.LoadScene(filename=lxf_filename)
|
converter.LoadScene(filename=lxf_filename)
|
||||||
converter.Export(filename=obj_filename)
|
converter.Export(filename=obj_filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user