From d1ada7f3a4c1be56a6199361e2a822b2ea0997ea Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Wed, 22 Feb 2017 23:19:38 +0100 Subject: [PATCH] Loading visuals data from LuaModel, added stub for capsule mesh creation, added sample model rig --- data/models/model.lua | 1023 ++++++++++++++++++++++++++++++++ src/modules/CharacterModule.cc | 63 ++ src/modules/LuaTableTypes.h | 353 +++++++++++ src/modules/RenderUtils.cc | 81 +++ src/modules/RenderUtils.h | 1 + 5 files changed, 1521 insertions(+) create mode 100644 data/models/model.lua create mode 100644 src/modules/LuaTableTypes.h diff --git a/data/models/model.lua b/data/models/model.lua new file mode 100644 index 0000000..5e67ae0 --- /dev/null +++ b/data/models/model.lua @@ -0,0 +1,1023 @@ +return { + configuration = { + axis_front = { 1, 0, 0,}, + axis_right = { 0, -1, 0,}, + axis_up = { 0, 0, 1,}, + }, + constraint_sets = { + LeftFlat = { + { + normal = { 1, 0, 0,}, + point = "left_heel", + }, + { + normal = { 0, 1, 0,}, + point = "left_heel", + }, + { + normal = { 0, 0, 1,}, + point = "left_heel", + }, + { + normal = { 0, 1, 0,}, + point = "left_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "left_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "left_meta5", + }, + }, + LeftHallux = { + { + normal = { 1, 0, 0,}, + point = "left_hallux", + }, + { + normal = { 0, 1, 0,}, + point = "left_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "left_hallux", + }, + }, + LeftHalluxRightFlat = { + { + normal = { 1, 0, 0,}, + point = "left_hallux", + }, + { + normal = { 0, 1, 0,}, + point = "left_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "left_hallux", + }, + { + normal = { 1, 0, 0,}, + point = "right_heel", + }, + { + normal = { 0, 1, 0,}, + point = "right_heel", + }, + { + normal = { 0, 0, 1,}, + point = "right_heel", + }, + { + normal = { 0, 1, 0,}, + point = "right_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "right_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "right_meta5", + }, + }, + LeftHalluxRightHeel = { + { + normal = { 1, 0, 0,}, + point = "left_hallux", + }, + { + normal = { 0, 1, 0,}, + point = "left_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "left_hallux", + }, + { + normal = { 1, 0, 0,}, + point = "right_heel", + }, + { + normal = { 0, 1, 0,}, + point = "right_heel", + }, + { + normal = { 0, 0, 1,}, + point = "right_heel", + }, + }, + RightFlat = { + { + normal = { 1, 0, 0,}, + point = "right_heel", + }, + { + normal = { 0, 1, 0,}, + point = "right_heel", + }, + { + normal = { 0, 0, 1,}, + point = "right_heel", + }, + { + normal = { 0, 1, 0,}, + point = "right_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "right_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "right_meta5", + }, + }, + RightFlatLeftHeel = { + { + normal = { 1, 0, 0,}, + point = "right_heel", + }, + { + normal = { 0, 1, 0,}, + point = "right_heel", + }, + { + normal = { 0, 0, 1,}, + point = "right_heel", + }, + { + normal = { 0, 1, 0,}, + point = "right_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "right_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "right_meta5", + }, + { + normal = { 1, 0, 0,}, + point = "left_heel", + }, + { + normal = { 0, 1, 0,}, + point = "left_heel", + }, + { + normal = { 0, 0, 1,}, + point = "left_heel", + }, + }, + RightHallux = { + { + normal = { 1, 0, 0,}, + point = "right_hallux", + }, + { + normal = { 0, 1, 0,}, + point = "right_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "right_hallux", + }, + { + normal = { 1, 0, 0,}, + point = "right_meta5", + }, + { + normal = { 0, 0, 1,}, + point = "right_meta5", + }, + }, + RightHalluxLeftFlat = { + { + normal = { 1, 0, 0,}, + point = "right_hallux", + }, + { + normal = { 0, 1, 0,}, + point = "right_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "right_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "right_meta5", + }, + { + normal = { 1, 0, 0,}, + point = "left_heel", + }, + { + normal = { 0, 1, 0,}, + point = "left_heel", + }, + { + normal = { 0, 0, 1,}, + point = "left_heel", + }, + { + normal = { 0, 1, 0,}, + point = "left_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "left_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "left_meta5", + }, + }, + RightHalluxLeftHeel = { + { + normal = { 1, 0, 0,}, + point = "right_hallux", + }, + { + normal = { 0, 1, 0,}, + point = "right_hallux", + }, + { + normal = { 0, 0, 1,}, + point = "right_hallux", + }, + { + normal = { 1, 0, 0,}, + point = "right_meta5", + }, + { + normal = { 0, 0, 1,}, + point = "right_meta5", + }, + { + normal = { 1, 0, 0,}, + point = "left_heel", + }, + { + normal = { 0, 1, 0,}, + point = "left_heel", + }, + { + normal = { 0, 0, 1,}, + point = "left_heel", + }, + }, + }, + frames = { + { + joint = { "JointTypeTranslationXYZ",}, + joint_frame = { + r = { 0, 0, 0,}, + }, + name = "PelvisTrans", + parent = "ROOT", + }, + { + body = { + com = { 0, 0, 0.042646321347356,}, + inertia = { + { 0.038200528883491, 0, 0,}, + { 0, 0.030663543577386, 0,}, + { 0, 0, 0.034801290334736,}, + }, + mass = 8.3775, + }, + joint = { "JointTypeEulerYXZ",}, + joint_frame = { + r = { 0, 0, 0,}, + }, + markers = { + LASI = { 0.052991829812527, 0.11058157682419, 0.08067062497139,}, + LPSI = { -0.12932787835598, 0.045250821858644, 0.11889722943306,}, + RASI = { 0.058340698480606, -0.11695376038551, 0.089762836694717,}, + RPSI = { -0.1268265992403, -0.058085463941097, 0.12065640091896,}, + }, + name = "Pelvis", + parent = "PelvisTrans", + visuals = { + { + color = { 0.2, 0.2, 0.9,}, + dimensions = { 0.18, 0.28647, 0.10980000346899,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, 0, 0.054900001734495,}, + }, + }, + }, + { + body = { + com = { 0, 0, -0.18185894693434,}, + inertia = { + { 0.22671374155723, 0, 0,}, + { 0, 0.22671374155723, 0,}, + { 0, 0, 0.04650060306457,}, + }, + mass = 10.62, + }, + joint = { "JointTypeEulerYXZ",}, + joint_frame = { + r = { 0, -0.083235, 0,}, + }, + name = "ThighRight", + parent = "Pelvis", + visuals = { + { + color = { 1, 0.1, 0.1,}, + dimensions = { 0.15, 0.12, 0.44409999251366,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, 0, -0.22204999625683,}, + }, + }, + }, + { + body = { + com = { 0, 0, -0.20627166416645,}, + inertia = { + { 0.045209378540837, 0, 0,}, + { 0, 0.043106907787935, 0,}, + { 0, 0, 0.0073760291724681,}, + }, + mass = 3.2475, + }, + joint = { + { 0, 1, 0, 0, 0, 0,}, + }, + joint_frame = { + r = { 0, 0, -0.44409999251366,}, + }, + markers = { + RKNE = { 0.031680159270763, -0.064131885766983, 0.0048278677277267,}, + RTIB = { 0.011271089315414, -0.097036071121693, -0.11671927571297,}, + }, + name = "ShankRight", + parent = "ThighRight", + visuals = { + { + color = { 0.9, 0.3, 0.3,}, + dimensions = { 0.13, 0.1, 0.46270000934601,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, 0, -0.23135000467301,}, + }, + }, + }, + { + body = { + com = { 0.053982978, 0, -0.043524,}, + inertia = { + { 0.0033426271094276, 0, 0,}, + { 0, 0.0030377627555814, 0,}, + { 0, 0, 0.00077815310503656,}, + }, + mass = 1.0275, + }, + joint = { "JointTypeEulerYXZ",}, + joint_frame = { + r = { 0, 0, -0.46270000934601,}, + }, + markers = { + RANK = { 0.0054707257077098, -0.030474988743663, 0.0096247950568795,}, + RHEE = { -0.053590387105942, 0.006934370379895, -0.01508407574147,}, + RTOE = { 0.17356503009796, 0.011473462916911, -0.024925166741014,}, + }, + name = "FootRight", + parent = "ShankRight", + visuals = { + { + color = { 1, 0.1, 0.1,}, + dimensions = { 0.221932, 0.1, 0.087048,}, + geometry = { + box = { + length = 0.9, + radius = 0.09, + segments = 48, + }, + }, + mesh_center = { 0.066966, 0, -0.043524,}, + }, + { + color = { 1, 0.1, 0.1,}, + geometry = { + sphere = { + radius = 0.087048, + }, + }, + translate = { -0.044, 0, 0,}, + }, + }, + }, + { + body = { + com = { 0, 0, -0.18185894693434,}, + inertia = { + { 0.22671374155723, 0, 0,}, + { 0, 0.22671374155723, 0,}, + { 0, 0, 0.04650060306457,}, + }, + mass = 10.62, + }, + joint = { "JointTypeEulerYXZ",}, + joint_frame = { + r = { 0, 0.083235, 0,}, + }, + name = "ThighLeft", + parent = "Pelvis", + visuals = { + { + color = { 0.1, 1, 0.1,}, + dimensions = { 0.15, 0.12, 0.44409999251366,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, 0, -0.22204999625683,}, + }, + }, + }, + { + body = { + com = { 0, 0, -0.20627166416645,}, + inertia = { + { 0.045209378540837, 0, 0,}, + { 0, 0.043106907787935, 0,}, + { 0, 0, 0.0073760291724681,}, + }, + mass = 3.2475, + }, + joint = { + { 0, 1, 0, 0, 0, 0,}, + }, + joint_frame = { + r = { 0, 0, -0.44409999251366,}, + }, + markers = { + LKNE = { 0.032328642904758, 0.047998454421759, -0.0018083926988766,}, + LTIB = { 0.0066562313586473, 0.065629869699478, -0.29721513390541,}, + }, + name = "ShankLeft", + parent = "ThighLeft", + visuals = { + { + color = { 0.3, 0.9, 0.3,}, + dimensions = { 0.13, 0.1, 0.46270000934601,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, 0, -0.23135000467301,}, + }, + }, + }, + { + body = { + com = { 0.053982978, 0, -0.043524,}, + inertia = { + { 0.0033426271094276, 0, 0,}, + { 0, 0.0030377627555814, 0,}, + { 0, 0, 0.00077815310503656,}, + }, + mass = 1.0275, + }, + joint = { "JointTypeEulerYXZ",}, + joint_frame = { + r = { 0, 0, -0.46270000934601,}, + }, + markers = { + LANK = { 0.0081671224907041, 0.034606732428074, 0.0077109434641898,}, + LHEE = { -0.051829442381859, -0.016891548410058, -0.013164701871574,}, + LTOE = { 0.16798159480095, -0.0085604833438993, -0.017251666635275,}, + }, + name = "FootLeft", + parent = "ShankLeft", + visuals = { + { + color = { 0.1, 1, 0.1,}, + dimensions = { 0.221932, 0.1, 0.087048,}, + geometry = { + box = { + length = 0.9, + radius = 0.09, + segments = 48, + }, + }, + mesh_center = { 0.066966, 0, -0.043524,}, + }, + { + color = { 0.1, 1, 0.1,}, + geometry = { + sphere = { + radius = 0.087048, + }, + }, + translate = { -0.044, 0, 0,}, + }, + }, + }, + { + body = { + com = { 0, 0, 0.1218165427915,}, + inertia = { + { 0.13968333431522, 0, 0,}, + { 0, 0.088195832661997, 0,}, + { 0, 0, 0.13168679350845,}, + }, + mass = 12.2475, + }, + joint = { "JointTypeEulerYXZ",}, + joint_frame = { + r = { 0, 0, 0.10980000346899,}, + }, + name = "MiddleTrunk", + parent = "Pelvis", + visuals = { + { + color = { 0.3, 0.3, 1,}, + dimensions = { 0.216, 0.29189999602795, 0.22156519241815,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, 0, 0.11078259620908,}, + }, + }, + }, + { + body = { + com = { 0, 0, 0.16375339219495,}, + inertia = { + { 0.33572265599833, 0, 0,}, + { 0, 0.13497903265299, 0,}, + { 0, 0, 0.28439727764741,}, + }, + mass = 11.97, + }, + joint = {}, + joint_frame = { + r = { 0, 0, 0.22156519241815,}, + }, + markers = { + C7 = { -0.039351474493742, -0.0084890006110072, 0.28900960087776,}, + T10 = { -0.13401326537132, -0.010717937722802, 0.0360297113657,}, + }, + name = "UpperTrunk", + parent = "MiddleTrunk", + visuals = { + { + color = { 0.1, 0.1, 1,}, + dimensions = { 0.234, 0.2973299920559, 0.2339000031352,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, 0, 0.1169500015676,}, + }, + }, + }, + { + body = { + com = { 0, 0, 0,}, + inertia = { + { 0, 0, 0,}, + { 0, 0, 0,}, + { 0, 0, 0,}, + }, + mass = 0, + }, + joint = {}, + joint_frame = { + r = { 0, 0, 0.228900000453,}, + }, + name = "ClaviculaRight", + parent = "UpperTrunk", + visuals = { + { + color = { 0.3, 0.3, 1,}, + dimensions = { 0.06, 0.06, 0.174899995327,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, -0.0874499976635, 0,}, + rotate = { + angle = 90, + axis = { 1, 0, 0,}, + }, + }, + }, + }, + { + body = { + com = { 0, 0, -0.21910512,}, + inertia = { + { 0.02378880803637, 0, 0,}, + { 0, 0.021192760090117, 0,}, + { 0, 0, 0.0073113426139728,}, + }, + mass = 2.0325, + }, + joint = { "JointTypeEulerYXZ",}, + joint_frame = { + r = { 0, -0.174899995327, 0,}, + }, + markers = { + RUPA = { -0.0080910492688417, -0.03629956394434, -0.27596998214722,}, + }, + name = "UpperArmRight", + parent = "ClaviculaRight", + visuals = { + { + color = { 1, 0.1, 0.1,}, + dimensions = { 0.12, 0.09, 0.3796,}, + geometry = { + capsule = { + length = 0.88, + radius = 0.12, + }, + }, + mesh_center = { 0, 0, -0.1898,}, + }, + }, + }, + { + body = { + com = { 0, 0, -0.124133786,}, + inertia = { + { 0.0068168246715783, 0, 0,}, + { 0, 0.0062842826160678, 0,}, + { 0, 0, 0.0013101912678085,}, + }, + mass = 1.215, + }, + joint = { + { 0, 1, 0, 0, 0, 0,}, + }, + joint_frame = { + r = { 0, 0, -0.3796,}, + }, + markers = { + RELB = { -0.0073555246926844, -0.04216194152832, 0.0015217624604702,}, + RWRA = { 0.045201644301414, 0.039090558886528, -0.27397903800011,}, + RWRB = { -0.015719685703516, -0.017938679084182, -0.28111892938614,}, + }, + name = "LowerArmRight", + parent = "UpperArmRight", + visuals = { + { + color = { 1, 0.3, 0.3,}, + dimensions = { 0.1, 0.08, 0.27139,}, + geometry = { + capsule = { + length = 0.88, + radius = 0.12, + }, + }, + mesh_center = { 0, 0, -0.135695,}, + }, + }, + }, + { + body = { + com = { 0, 0, -0.05189568,}, + inertia = { + { 0.0007781478285312, 0, 0,}, + { 0, 0.00051809912508, 0,}, + { 0, 0, 0.0003176236121088,}, + }, + mass = 0.4575, + }, + joint = {}, + joint_frame = { + r = { 0, 0, -0.27139,}, + }, + name = "HandRight", + parent = "LowerArmRight", + visuals = { + { + color = { 1, 0.1, 0.1,}, + dimensions = { 0.1, 0.04, 0.1432,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, 0, -0.0716,}, + }, + }, + }, + { + body = { + com = { 0, 0, 0,}, + inertia = { + { 0, 0, 0,}, + { 0, 0, 0,}, + { 0, 0, 0,}, + }, + mass = 0, + }, + joint = {}, + joint_frame = { + r = { 0, 0, 0.228900000453,}, + }, + name = "ClaviculaLeft", + parent = "UpperTrunk", + visuals = { + { + color = { 0.3, 0.3, 1,}, + dimensions = { 0.06, 0.06, 0.174899995327,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, 0.0874499976635, 0,}, + rotate = { + angle = 90, + axis = { 1, 0, 0,}, + }, + }, + }, + }, + { + body = { + com = { 0, 0, -0.21910512,}, + inertia = { + { 0.02378880803637, 0, 0,}, + { 0, 0.021192760090117, 0,}, + { 0, 0, 0.0073113426139728,}, + }, + mass = 2.0325, + }, + joint = { "JointTypeEulerYXZ",}, + joint_frame = { + r = { 0, 0.174899995327, 0,}, + }, + markers = { + LUPA = { -0.0083068665117025, 0.041783545166254, -0.16908901929855,}, + }, + name = "UpperArmLeft", + parent = "ClaviculaLeft", + visuals = { + { + color = { 0.1, 1, 0.1,}, + dimensions = { 0.12, 0.09, 0.3796,}, + geometry = { + capsule = { + length = 0.88, + radius = 0.12, + }, + }, + mesh_center = { 0, 0, -0.1898,}, + }, + }, + }, + { + body = { + com = { 0, 0, -0.124133786,}, + inertia = { + { 0.0068168246715783, 0, 0,}, + { 0, 0.0062842826160678, 0,}, + { 0, 0, 0.0013101912678085,}, + }, + mass = 1.215, + }, + joint = { + { 0, 1, 0, 0, 0, 0,}, + }, + joint_frame = { + r = { 0, 0, -0.3796,}, + }, + markers = { + LELB = { -0.0020065398421139, 0.043605700135231, 0.0037837768904865,}, + LWRA = { 0.02726911008358, -0.025259353220463, -0.26385623216629,}, + LWRB = { -0.035459812730551, 0.032188482582569, -0.26435285806656,}, + }, + name = "LowerArmLeft", + parent = "UpperArmLeft", + visuals = { + { + color = { 0.3, 0.9, 0.3,}, + dimensions = { 0.1, 0.08, 0.27139,}, + geometry = { + capsule = { + length = 0.88, + radius = 0.12, + }, + }, + mesh_center = { 0, 0, -0.135695,}, + }, + }, + }, + { + body = { + com = { 0, 0, -0.05189568,}, + inertia = { + { 0.0007781478285312, 0, 0,}, + { 0, 0.00051809912508, 0,}, + { 0, 0, 0.0003176236121088,}, + }, + mass = 0.4575, + }, + joint = {}, + joint_frame = { + r = { 0, 0, -0.27139,}, + }, + name = "HandLeft", + parent = "LowerArmLeft", + visuals = { + { + color = { 0.1, 1, 0.1,}, + dimensions = { 0.1, 0.04, 0.1432,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, 0, -0.0716,}, + }, + }, + }, + { + body = { + com = { 0, 0, 0.017902498432397,}, + inertia = { + { 4.9072875886111e-05, 0, 0,}, + { 0, 4.5239218508482e-05, 0,}, + { 0, 0, 9.4317892229646e-06,}, + }, + mass = 0.5025, + }, + joint = {}, + joint_frame = { + r = { 0, 0, 0.2339000031352,}, + }, + name = "Neck", + parent = "UpperTrunk", + visuals = { + { + color = { 0.2, 0.2, 0.9,}, + dimensions = { 0.07, 0.07, 0.035804996864795,}, + geometry = { + capsule = { + length = 0.9, + radius = 0.09, + }, + }, + mesh_center = { 0, 0, 0.017902498432397,}, + }, + }, + }, + { + body = { + com = { 0, 0, 0.088409292,}, + inertia = { + { 0.032924391420566, 0, 0,}, + { 0, 0.035520273812414, 0,}, + { 0, 0, 0.024457372778941,}, + }, + mass = 5.205, + }, + joint = { "JointTypeEulerYXZ",}, + joint_frame = { + r = { 0, 0, 0.035804996864795,}, + }, + markers = { + LBHD = { 0.019333571195602, 0.088616423308849, 0.20507903397083,}, + LFHD = { 0.12930905818939, 0.067053556442261, 0.20482148230076,}, + RBHD = { 0.011489745229483, -0.087685711681843, 0.19465588033199,}, + RFHD = { 0.12186269462109, -0.073935218155384, 0.1992692053318,}, + }, + name = "Head", + parent = "Neck", + visuals = { + { + color = { 0.1, 0.1, 0.9,}, + dimensions = { 0.2, 0.18, 0.2416755,}, + geometry = { + capsule = { + length = 0.8, + radius = 0.2, + }, + }, + mesh_center = { 0, 0, 0.09886725,}, + }, + }, + }, + }, + gravity = { 0, 0, -9.81,}, + parameters = { + ClaviculaLeftLength = 0.174899995327, + ClaviculaRightLength = 0.174899995327, + FootLeftHeight = 0.087048, + FootLeftLength = 0.221932, + FootLeftMass = 1.0275, + FootLeftPosteriorPoint = 0.044, + FootRightHeight = 0.087048, + FootRightLength = 0.221932, + FootRightMass = 1.0275, + FootRightPosteriorPoint = 0.044, + HandLeftLength = 0.1432, + HandLeftMass = 0.4575, + HandRightLength = 0.1432, + HandRightMass = 0.4575, + HeadLength = 0.219705, + HeadMass = 5.205, + HipLeftWidth = 0.083235, + HipRightWidth = 0.083235, + LowerArmLeftLength = 0.27139, + LowerArmLeftMass = 1.215, + LowerArmRightLength = 0.27139, + LowerArmRightMass = 1.215, + LowerTrunkHeight = 0.10980000346899, + LowerTrunkMass = 8.3775, + MiddleTrunkHeight = 0.22156519241815, + MiddleTrunkMass = 12.2475, + NeckLength = 0.035804996864795, + NeckMass = 0.5025, + ShankLeftLength = 0.46270000934601, + ShankLeftMass = 3.2475, + ShankRightLength = 0.46270000934601, + ShankRightMass = 3.2475, + ShoulderLeftHeight = 0.228900000453, + ShoulderRightHeight = 0.228900000453, + SuprasternaleHeight = 0.2339000031352, + ThighLeftLength = 0.44409999251366, + ThighLeftMass = 10.62, + ThighRightLength = 0.44409999251366, + ThighRightMass = 10.62, + UpperArmLeftLength = 0.3796, + UpperArmLeftMass = 2.0325, + UpperArmRightLength = 0.3796, + UpperArmRightMass = 2.0325, + UpperTrunkAltHeight = 0.25864790350373, + UpperTrunkAltMass = 11.97, + UpperTrunkHeight = 0.2339000031352, + UpperTrunkMass = 11.97, + }, + points = { + { + body = "FootRight", + name = "right_heel", + point = { -0.044, 0, -0.087048,}, + }, + { + body = "FootRight", + name = "right_hallux", + point = { 0.177932, 0.03, -0.087048,}, + }, + { + body = "FootRight", + name = "right_meta5", + point = { 0.177932, -0.06, -0.087048,}, + }, + { + body = "FootLeft", + name = "left_heel", + point = { -0.044, 0, -0.087048,}, + }, + { + body = "FootLeft", + name = "left_hallux", + point = { 0.177932, -0.03, -0.087048,}, + }, + { + body = "FootLeft", + name = "left_meta5", + point = { 0.177932, 0.06, -0.087048,}, + }, + }, +} \ No newline at end of file diff --git a/src/modules/CharacterModule.cc b/src/modules/CharacterModule.cc index 5d3151c..d973682 100644 --- a/src/modules/CharacterModule.cc +++ b/src/modules/CharacterModule.cc @@ -14,6 +14,7 @@ #include "Serializer.h" #include "CharacterModule.h" +#include "LuaTableTypes.h" #include "rbdl/addons/luamodel/luatables.h" @@ -26,6 +27,8 @@ bool LuaModelReadFromTable (LuaTable &model_table, Model *model, bool verbose); } } +// Types needed to parse + using namespace std; using namespace RigidBodyDynamics; using namespace RigidBodyDynamics::Addons; @@ -108,6 +111,66 @@ bool CharacterEntity::LoadRig(const char* filename) { gLog ("Creating rig model from %s ... %s", filename, load_result ? "success" : "failed!"); gLog ("Rig model has %d degrees of freedom", mRigModel->qdot_size); + gLog ("Reading rig geometry information ... "); + + int frame_count = model_table["frames"].length(); + gLog ("Found %d frames", frame_count); + + for (int fi = 1; fi <= frame_count; ++fi) { + LuaTableNode frame_table = model_table["frames"][fi]; + string frame_name = frame_table["name"].getDefault(""); + int visuals_count = frame_table["visuals"].length(); + gLog (" Frame %s has %d visuals", frame_name.c_str(), visuals_count); + + for (int vi = 1; vi <= visuals_count; ++vi) { + LuaTableNode visual_table = frame_table["visuals"][vi]; + bool have_geometry = visual_table["geometry"].exists(); + + if (!have_geometry) { + gLog (" Warning: could not find geometry for visual %d of frame %s", + vi, frame_name.c_str()); + continue; + } + + Vector4f color (1.f, 0.f, 1.f, 1.f); + if (visual_table["color"].length() == 3) { + color.block<3,1>(0,0) = visual_table["color"].getDefault(Vector3f(color.block<3,1>(0,0))); + } if (visual_table["color"].length() == 4) { + color = visual_table["color"].getDefault(color); + } + + Mesh* mesh = nullptr; + + if (visual_table["geometry"]["box"].exists()) { + Vector3f dimensions = visual_table["geometry"]["box"]["dimensions"].getDefault(Vector3f (1.f, 1.f, 1.f)); + mesh = Mesh::sCreateCuboid ( + dimensions[0], + dimensions[1], + dimensions[2] + ); + } else if (visual_table["geometry"]["sphere"].exists()) { + int rows = static_cast( + visual_table["geometry"]["sphere"]["radius"].getDefault (16.f) + ); + int segments = static_cast( + visual_table["geometry"]["sphere"]["segments"].getDefault (16.f) + ); + float radius = visual_table["geometry"]["sphere"]["radius"].getDefault (1.f); + mesh = Mesh::sCreateUVSphere (rows, segments, radius); + } else if (visual_table["geometry"]["capsule"].exists()) { + int rows = static_cast( + visual_table["geometry"]["capsule"]["radius"].getDefault (16.f) + ); + int segments = static_cast( + visual_table["geometry"]["capsule"]["segments"].getDefault (16.f) + ); + float radius = visual_table["geometry"]["capsule"]["radius"].getDefault (1.f); + float length = visual_table["geometry"]["capsule"]["length"].getDefault (1.f); + mesh = Mesh::sCreateCapsule (rows, segments, length, radius); + } + } + } + return load_result; } diff --git a/src/modules/LuaTableTypes.h b/src/modules/LuaTableTypes.h new file mode 100644 index 0000000..bd2ea7f --- /dev/null +++ b/src/modules/LuaTableTypes.h @@ -0,0 +1,353 @@ +/* + * Puppeteer - A Motion Capture Mapping Tool + * Copyright (c) 2013-2015 Martin Felis . + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE* + */ + +#ifndef MARKER_MODEL_LUA_TYPES +#define MARKER_MODEL_LUA_TYPES + +#include + +// SimpleMath Vector3f +template<> Vector3f LuaTableNode::getDefault(const Vector3f &default_value) { + Vector3f result = default_value; + + if (stackQueryValue()) { + LuaTable vector_table = LuaTable::fromLuaState (luaTable->L); + + if (vector_table.length() != 3) { + std::cerr << "LuaModel Error at " << keyStackToString() << " : invalid 3d vector!" << std::endl; + abort(); + } + + result[0] = static_cast(vector_table[1].get()); + result[1] = static_cast(vector_table[2].get()); + result[2] = static_cast(vector_table[3].get()); + } + + stackRestore(); + + return result; +} + +template<> +void LuaTableNode::set(const Vector3f &value) { + LuaTable custom_table = stackCreateLuaTable(); + + custom_table[1] = static_cast(value[0]); + custom_table[2] = static_cast(value[1]); + custom_table[3] = static_cast(value[2]); + + stackRestore(); +} + +// SimpleMath Vector4f +template<> Vector4f LuaTableNode::getDefault(const Vector4f &default_value) { + Vector4f result = default_value; + + if (stackQueryValue()) { + LuaTable vector_table = LuaTable::fromLuaState (luaTable->L); + + if (vector_table.length() != 4) { + std::cerr << "LuaModel Error at " << keyStackToString() << " : invalid 4d vector!" << std::endl; + abort(); + } + + result[0] = static_cast(vector_table[1].get()); + result[1] = static_cast(vector_table[2].get()); + result[2] = static_cast(vector_table[3].get()); + result[3] = static_cast(vector_table[4].get()); + } + + stackRestore(); + + return result; +} + +// SimpleMath Matrix33f +template<> SimpleMath::Fixed::Matrix LuaTableNode::getDefault >(const SimpleMath::Fixed::Matrix &default_value) { + SimpleMath::Fixed::Matrix result = default_value; + + if (stackQueryValue()) { + LuaTable vector_table = LuaTable::fromLuaState (luaTable->L); + + if (vector_table.length() != 3) { + std::cerr << "LuaModel Error at " << keyStackToString() << " : invalid 3d matrix!" << std::endl; + abort(); + } + + if (vector_table[1].length() != 3 + || vector_table[2].length() != 3 + || vector_table[3].length() != 3) { + std::cerr << "LuaModel Error at " << keyStackToString() << " : invalid 3d matrix!" << std::endl; + abort(); + } + + result(0,0) = static_cast(vector_table[1][1].get()); + result(0,1) = static_cast(vector_table[1][2].get()); + result(0,2) = static_cast(vector_table[1][3].get()); + + result(1,0) = static_cast(vector_table[2][1].get()); + result(1,1) = static_cast(vector_table[2][2].get()); + result(1,2) = static_cast(vector_table[2][3].get()); + + result(2,0) = static_cast(vector_table[3][1].get()); + result(2,1) = static_cast(vector_table[3][2].get()); + result(2,2) = static_cast(vector_table[3][3].get()); + } + + stackRestore(); + + return result; +} + +template<> +void LuaTableNode::set >(const SimpleMath::Fixed::Matrix &value) { + LuaTable custom_table = stackCreateLuaTable(); + + custom_table[1][1] = static_cast(value(0,0)); + custom_table[1][2] = static_cast(value(0,1)); + custom_table[1][3] = static_cast(value(0,2)); + + custom_table[2][1] = static_cast(value(1,0)); + custom_table[2][2] = static_cast(value(1,1)); + custom_table[2][3] = static_cast(value(1,2)); + + custom_table[3][1] = static_cast(value(2,0)); + custom_table[3][2] = static_cast(value(2,1)); + custom_table[3][3] = static_cast(value(2,2)); + + stackRestore(); +} + +template<> RigidBodyDynamics::Math::Vector3d LuaTableNode::getDefault(const RigidBodyDynamics::Math::Vector3d &default_value) { + RigidBodyDynamics::Math::Vector3d result = default_value; + + if (stackQueryValue()) { + LuaTable vector_table = LuaTable::fromLuaState (luaTable->L); + + if (vector_table.length() != 3) { + std::cerr << "LuaModel Error at " << keyStackToString() << " : invalid 3d vector!" << std::endl; + abort(); + } + + result[0] = vector_table[1]; + result[1] = vector_table[2]; + result[2] = vector_table[3]; + } + + stackRestore(); + + return result; +} + +template<> RigidBodyDynamics::Math::SpatialVector LuaTableNode::getDefault(const RigidBodyDynamics::Math::SpatialVector &default_value) { + RigidBodyDynamics::Math::SpatialVector result = default_value; + + if (stackQueryValue()) { + LuaTable vector_table = LuaTable::fromLuaState (luaTable->L); + + if (vector_table.length() != 6) { + std::cerr << "LuaModel Error at " << keyStackToString() << " : invalid 6d vector!" << std::endl; + abort(); + } + result[0] = vector_table[1]; + result[1] = vector_table[2]; + result[2] = vector_table[3]; + result[3] = vector_table[4]; + result[4] = vector_table[5]; + result[5] = vector_table[6]; + } + + stackRestore(); + + return result; +} + +template<> RigidBodyDynamics::Math::Matrix3d LuaTableNode::getDefault(const RigidBodyDynamics::Math::Matrix3d &default_value) { + RigidBodyDynamics::Math::Matrix3d result = default_value; + + if (stackQueryValue()) { + LuaTable vector_table = LuaTable::fromLuaState (luaTable->L); + + if (vector_table.length() != 3) { + std::cerr << "LuaModel Error at " << keyStackToString() << " : invalid 3d matrix!" << std::endl; + abort(); + } + + if (vector_table[1].length() != 3 + || vector_table[2].length() != 3 + || vector_table[3].length() != 3) { + std::cerr << "LuaModel Error at " << keyStackToString() << " : invalid 3d matrix!" << std::endl; + abort(); + } + + result(0,0) = vector_table[1][1]; + result(0,1) = vector_table[1][2]; + result(0,2) = vector_table[1][3]; + + result(1,0) = vector_table[2][1]; + result(1,1) = vector_table[2][2]; + result(1,2) = vector_table[2][3]; + + result(2,0) = vector_table[3][1]; + result(2,1) = vector_table[3][2]; + result(2,2) = vector_table[3][3]; + } + + stackRestore(); + + return result; +} + +template<> RigidBodyDynamics::Math::SpatialTransform LuaTableNode::getDefault(const RigidBodyDynamics::Math::SpatialTransform &default_value) { + RigidBodyDynamics::Math::SpatialTransform result = default_value; + + if (stackQueryValue()) { + LuaTable vector_table = LuaTable::fromLuaState (luaTable->L); + + result.r = vector_table["r"].getDefault(RigidBodyDynamics::Math::Vector3d::Zero(3)); + result.E = vector_table["E"].getDefault(RigidBodyDynamics::Math::Matrix3d::Identity (3,3)); + } + + stackRestore(); + + return result; +} + +template<> RigidBodyDynamics::Joint LuaTableNode::getDefault(const RigidBodyDynamics::Joint &default_value) { + using namespace RigidBodyDynamics; + using namespace RigidBodyDynamics::Math; + + Joint result = default_value; + + if (stackQueryValue()) { + LuaTable vector_table = LuaTable::fromLuaState (luaTable->L); + + int joint_dofs = vector_table.length(); + + if (joint_dofs == 1) { + std::string dof_string = vector_table[1].getDefault(""); + if (dof_string == "JointTypeSpherical") { + stackRestore(); + return Joint(JointTypeSpherical); + } else if (dof_string == "JointTypeEulerZYX") { + stackRestore(); + return Joint(JointTypeEulerZYX); + } + if (dof_string == "JointTypeEulerXYZ") { + stackRestore(); + return Joint(JointTypeEulerXYZ); + } + if (dof_string == "JointTypeEulerYXZ") { + stackRestore(); + return Joint(JointTypeEulerYXZ); + } + if (dof_string == "JointTypeTranslationXYZ") { + stackRestore(); + return Joint(JointTypeTranslationXYZ); + } + } + + if (joint_dofs > 0) { + if (vector_table[1].length() != 6) { + std::cerr << "LuaModel Error: invalid joint motion subspace description at " << this->keyStackToString() << std::endl; + abort(); + } + } + + switch (joint_dofs) { + case 0: result = Joint(JointTypeFixed); + break; + case 1: result = Joint (vector_table[1].get()); + break; + case 2: result = Joint( + vector_table[1].get(), + vector_table[2].get() + ); + break; + case 3: result = Joint( + vector_table[1].get(), + vector_table[2].get(), + vector_table[3].get() + ); + break; + case 4: result = Joint( + vector_table[1].get(), + vector_table[2].get(), + vector_table[3].get(), + vector_table[4].get() + ); + break; + case 5: result = Joint( + vector_table[1].get(), + vector_table[2].get(), + vector_table[3].get(), + vector_table[4].get(), + vector_table[5].get() + ); + break; + case 6: result = Joint( + vector_table[1].get(), + vector_table[2].get(), + vector_table[3].get(), + vector_table[4].get(), + vector_table[5].get(), + vector_table[6].get() + ); + break; + default: + std::cerr << "Invalid number of DOFs for joint." << std::endl; + abort(); + } + } + + stackRestore(); + + return result; +} + +template<> RigidBodyDynamics::Body LuaTableNode::getDefault(const RigidBodyDynamics::Body &default_value) { + RigidBodyDynamics::Body result = default_value; + + if (stackQueryValue()) { + LuaTable vector_table = LuaTable::fromLuaState (luaTable->L); + + double mass = 0.; + RigidBodyDynamics::Math::Vector3d com (RigidBodyDynamics::Math::Vector3d::Zero(3)); + RigidBodyDynamics::Math::Matrix3d inertia (RigidBodyDynamics::Math::Matrix3d::Identity(3,3)); + + mass = vector_table["mass"]; + com = vector_table["com"].getDefault(com); + inertia = vector_table["inertia"].getDefault(inertia); + + result = RigidBodyDynamics::Body (mass, com, inertia); + } + + stackRestore(); + + return result; +} + +/* MARKER_MODEL_LUA_TYPES */ +#endif diff --git a/src/modules/RenderUtils.cc b/src/modules/RenderUtils.cc index 651a7b2..cdd48e5 100644 --- a/src/modules/RenderUtils.cc +++ b/src/modules/RenderUtils.cc @@ -1176,3 +1176,84 @@ Mesh* Mesh::sCreateCylinder (int segments) { return result; } + +Mesh* Mesh::sCreateCapsule (int rows, int segments, float length, float radius) { + Mesh* result = new Mesh(); + + // work arrays that we fill with data + std::vector &vertices = result->mVertices; + std::vector &normals = result->mNormals; + std::vector &colors = result->mColors; + + float delta = 2. * M_PI / static_cast(segments); + for (unsigned int i = 0; i < segments; i++) { + float r0 = (i - 0.5) * delta; + float r1 = (i + 0.5) * delta; + + float c0 = cos (r0); + float s0 = sin (r0); + + float c1 = cos (r1); + float s1 = sin (r1); + + Vector3f normal0 (-c0, -s0, 0.f); + Vector3f normal1 (-c1, -s1, 0.f); + + Vector4f normal0_4 (-c0, -s0, 0.f, 0.f); + Vector4f normal1_4 (-c1, -s1, 0.f, 0.f); + + Vector4f p0 = normal0_4 + Vector4f (0., 0., 0.5f, 1.0f); + Vector4f p1 = normal0_4 + Vector4f (0., 0., -0.5f, 1.0f); + Vector4f p2 = normal1_4 + Vector4f (0., 0., 0.5f, 1.0f); + Vector4f p3 = normal1_4 + Vector4f (0., 0., -0.5f, 1.0f); + + // side triangle 1 + vertices.push_back(p0); + normals.push_back(normal0); + + vertices.push_back(p1); + normals.push_back(normal0); + + vertices.push_back(p2); + normals.push_back(normal1); + + // side triangle 2 + vertices.push_back(p2); + normals.push_back(normal1); + + vertices.push_back(p1); + normals.push_back(normal0); + + vertices.push_back(p3); + normals.push_back(normal1); + + // upper end triangle + Vector3f normal (0.f, 0.f, 1.f); + + vertices.push_back(p0); + normals.push_back(normal); + + vertices.push_back(p2); + normals.push_back(normal); + + vertices.push_back(Vector4f (0.f, 0.f, 0.5f, 1.0f)); + normals.push_back(normal); + + // lower end triangle + normal = Vector3f(0.f, 0.f, -1.f); + + vertices.push_back(p3); + normals.push_back(normal); + + vertices.push_back(p1); + normals.push_back(normal); + + vertices.push_back(Vector4f (0.f, 0.f, -0.5f, 1.0f)); + normals.push_back(normal); + } + + result->Update(); + + return result; +}; + diff --git a/src/modules/RenderUtils.h b/src/modules/RenderUtils.h index b45e0e2..eaadb6e 100644 --- a/src/modules/RenderUtils.h +++ b/src/modules/RenderUtils.h @@ -26,6 +26,7 @@ struct Mesh { static Mesh *sCreateCuboid (float width, float height, float depth); static Mesh *sCreateUVSphere (int rows, int segments, float radius = 1.0f); static Mesh *sCreateCylinder (int segments); + static Mesh *sCreateCapsule (int rows, int segments, float length, float radius); }; namespace bgfxutils {