Action nodes support and lots of other updates

This commit is contained in:
2026-01-19 00:07:03 +03:00
parent f86e7fd96c
commit 4b24d85123
34 changed files with 7810 additions and 3488 deletions

View File

@@ -1,6 +1,7 @@
import bpy
import os, sys, time
import json
from mathutils import Matrix, Quaternion
argv = sys.argv
argv = argv[argv.index("--") + 1:]
@@ -9,6 +10,13 @@ incpath = os.path.dirname(__file__)
sys.path.insert(0, incpath)
outdir = argv[0]
basis_change = Matrix((
(1, 0, 0, 0),
(0, 0, 1, 0),
(0, -1, 0, 0),
(0, 0, 0, 1)
))
def export_root_objects_to_gltf(output_dir):
# Ensure the output directory exists
if not os.path.exists(output_dir):
@@ -40,6 +48,88 @@ def export_root_objects_to_gltf(output_dir):
desc["tags"] = [mtags]
else:
desc["tags"] = []
desc["sensors"] = []
desc["positions"] = []
for child in obj.children:
if child.name.startswith("sensor-"):
if not "action" in child:
continue
if not "height" in child:
continue
if not "radius" in child:
continue
local_matrix = child.matrix_local
ogre_local_matrix = basis_change @ local_matrix @ basis_change.inverted()
local_pos_d = ogre_local_matrix.to_translation()
local_rot_d = ogre_local_matrix.to_quaternion()
local_pos = [round(x, 4) for x in local_pos_d]
local_rot = [round(x, 4) for x in local_rot_d]
sensor = {}
sensor["position_x"] = local_pos[0]
sensor["position_y"] = local_pos[2]
sensor["position_z"] = local_pos[1]
sensor["rotation_w"] = local_rot[0]
sensor["rotation_x"] = local_rot[1]
sensor["rotation_y"] = local_rot[2]
sensor["rotation_z"] = local_rot[3]
sensor["height"] = child["height"]
sensor["radius"] = child["radius"]
sensor["action"] = child["action"]
if "action_text" in child:
sensor["action_text"] = child["action_text"]
else:
sensor["action_text"] = child["action"].capitalize()
if "name" in child:
sensor["name"] = child["name"]
else:
sensor["name"] = desc["name"] + "_" + str(len(desc["sensors"]))
sensor["furniture"] = {}
sensor["furniture"]["name"] = desc["name"]
sensor["furniture"]["tags"] = desc["tags"]
sensor["positions"] = []
for schild in child.children:
if schild.name.startswith("position-"):
local_matrix = schild.matrix_local
ogre_local_matrix = basis_change @ local_matrix @ basis_change.inverted()
local_pos_d = ogre_local_matrix.to_translation()
local_rot_d = ogre_local_matrix.to_quaternion()
local_pos = [round(x, 4) for x in local_pos_d]
local_rot = [round(x, 4) for x in local_rot_d]
position = {}
if "name" in schild:
position["name"] = schild["name"]
if "type" in schild:
position["type"] = schild["type"]
position["position_x"] = local_pos[0]
position["position_y"] = local_pos[2]
position["position_z"] = local_pos[1]
position["rotation_w"] = local_rot[0]
position["rotation_x"] = local_rot[1]
position["rotation_y"] = local_rot[2]
position["rotation_z"] = local_rot[3]
sensor["positions"].append(position)
desc["sensors"].append(sensor)
if child.name.startswith("position-"):
local_matrix = child.matrix_local
ogre_local_matrix = basis_change @ local_matrix @ basis_change.inverted()
local_pos_d = ogre_local_matrix.to_translation()
local_rot_d = ogre_local_matrix.to_quaternion()
local_pos = [round(x, 4) for x in local_pos_d]
local_rot = [round(x, 4) for x in local_rot_d]
position = {}
if "name" in child:
position["name"] = child["name"]
if "type" in child:
position["type"] = child["type"]
position["position_x"] = local_pos[0]
position["position_y"] = local_pos[2]
position["position_z"] = local_pos[1]
position["rotation_w"] = local_rot[0]
position["rotation_x"] = local_rot[1]
position["rotation_y"] = local_rot[2]
position["rotation_z"] = local_rot[3]
desc["positions"].append(position)
obj.select_set(True)
for child in obj.children_recursive:
child.select_set(True)