-
Notifications
You must be signed in to change notification settings - Fork 0
/
models_builder.py
48 lines (41 loc) · 1.69 KB
/
models_builder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from copy import deepcopy
import tools
import config
import xml.etree.ElementTree as etree
def recursive_build_hierarchy(root, object, links_simple, links_revert, models_id, id) :
"""
Retrieves and apply all the transformations necessary from the hierarchy all the way to the root.
"""
if id in links_revert :
for parent_id in links_revert[id] : # If multiple parents, multiple instances of the object must be created.
current_object = deepcopy(object)
tools.transform_object(current_object, models_id[id])
if parent_id == "0" : # End recursion and add the transformation
root.append(current_object)
else :
recursive_build_hierarchy(root, current_object, links_simple, links_revert, models_id, parent_id)
def build(root, models, links_simple, links_revert, shapes_ids):
"""
Put shapes in the scene and apply the correct transforms.
"""
if config.verbose : print("models_builder_fbx launched")
comment = etree.Comment("Models.")
root.append(comment)
# Create a dictionnary of models to pass through every parent
models_id = {}
for model in models :
id, type, obj = model.get("value").replace("::","").split(",")
models_id[id] = tools.getProperties(model)
for model in models :
id, type, obj = model.get("value").replace("::","").split(",")
if id in links_simple :
for link in links_simple[id] :
if link in shapes_ids : # Only shapes (for now ?)
curr_shape = etree.Element("shape")
curr_shape.set("type", "instance")
curr_ref = etree.SubElement(curr_shape, "ref")
curr_ref.set("id", link)
recursive_build_hierarchy(root, curr_shape, links_simple, links_revert, models_id, id)
elif config.verbose :
print("id "+id+" not in links_simple")