25 lines
656 B
Python
25 lines
656 B
Python
import os
|
|
import json
|
|
|
|
TEMPLATE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'index.html')
|
|
|
|
|
|
def obj2html(obj_path, output_html_path=None):
|
|
with open(obj_path, "r") as f:
|
|
content = f.readlines()
|
|
content = '\n'.join(content)
|
|
js_cont = {'obj': content}
|
|
js_string = json.dumps(js_cont)
|
|
|
|
with open(TEMPLATE_PATH, "r") as f:
|
|
html_template = f.read()
|
|
html_string = html_template.replace("{{obj_3d}}", js_string)
|
|
|
|
if output_html_path != None:
|
|
with open(output_html_path, "w") as f:
|
|
f.write(html_string)
|
|
else:
|
|
return html_string
|
|
|
|
if __name__ == '__main__':
|
|
obj2html('test/assets/model.obj', 'tmp.html') |