Skip to content

Commit 222b73b

Browse files
authored
Room collections support (#70)
1 parent df1a4f7 commit 222b73b

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

src/resource/glacier2obj.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,18 +2439,39 @@ def load_scenario(context, collection, path_to_nav_json, path_to_output_obj_file
24392439
data = json.loads(f.read())
24402440
f.close()
24412441
transforms = {}
2442+
room_names = {}
2443+
roomColorIndex = 0
2444+
roomFolderColorIdx = 0
24422445
for hash_and_entity in data['meshes']:
24432446
if mesh_type == "ALOC":
24442447
mesh_hash = hash_and_entity['alocHash']
24452448
else:
24462449
mesh_hash = hash_and_entity['primHash']
2450+
2451+
room_folder_name = hash_and_entity["roomFolderName"]
2452+
if room_folder_name not in bpy.data.collections:
2453+
coll = bpy.data.collections.new(room_folder_name)
2454+
bpy.context.scene.collection.children.link(coll)
2455+
coll.color_tag = "COLOR_0" + str(roomFolderColorIdx%8 + 1)
2456+
roomFolderColorIdx += 1
2457+
room_folder_coll = bpy.data.collections.get(room_folder_name)
2458+
2459+
room_name = hash_and_entity["roomName"]
2460+
if room_name not in bpy.data.collections:
2461+
coll = bpy.data.collections.new(room_name)
2462+
room_folder_coll.children.link(coll)
2463+
coll.color_tag = "COLOR_0" + str(roomColorIndex%8 + 1)
2464+
roomColorIndex += 1
2465+
24472466
entity = hash_and_entity['entity']
24482467
transform = {"position": entity["position"], "rotate": entity["rotation"],
24492468
"scale": entity["scale"]["data"], "id": entity["id"]}
2450-
2469+
24512470
if mesh_hash not in transforms:
24522471
transforms[mesh_hash] = []
2472+
room_names[mesh_hash] = []
24532473
transforms[mesh_hash].append(transform)
2474+
room_names[mesh_hash].append(room_name)
24542475
output_dir = os.path.dirname(path_to_output_obj_file)
24552476
path_to_aloc_or_prim_dir = "%s\\%s" % (output_dir, mesh_type.lower())
24562477
log("INFO", "Path to " + mesh_type.lower() + " dir:" + path_to_aloc_or_prim_dir, "load_scenario")
@@ -2516,6 +2537,7 @@ def load_scenario(context, collection, path_to_nav_json, path_to_output_obj_file
25162537
t_size = len(t)
25172538
for i in range(0, t_size):
25182539
mesh_transform = transforms[mesh_hash][i]
2540+
room_name = room_names[mesh_hash][i]
25192541
p = mesh_transform["position"]
25202542
r = mesh_transform["rotate"]
25212543
s = mesh_transform["scale"]
@@ -2526,7 +2548,7 @@ def load_scenario(context, collection, path_to_nav_json, path_to_output_obj_file
25262548
cur = obj.copy()
25272549
else:
25282550
cur = obj
2529-
collection.objects.link(cur)
2551+
bpy.data.collections.get(room_name).objects.link(cur)
25302552
cur.select_set(True)
25312553
cur.name = mesh_hash + " " + mesh_transform["id"]
25322554
cur.scale = mathutils.Vector((s["x"], s["y"], s["z"]))
@@ -2587,4 +2609,4 @@ def main():
25872609
bpy.utils.register_class(c)
25882610
if bpy.app.version_string[0] == "3":
25892611
bpy.types.Mesh.aloc_properties = PointerProperty(type=AlocProperties)
2590-
main()
2612+
main()

0 commit comments

Comments
 (0)