2#include <ossia/dataflow/geometry_port.hpp>
27 float pos[3]{0, 0, 0};
28 float rot[3]{0, 0, 0};
29 float scale[3]{1, 1, 1};
34template <
typename Inputs>
36computeTRSMatrix(
const Inputs& inputs,
float out_transform16[16],
CachedTRS& cache)
38 const float px = inputs.position.value.x;
39 const float py = inputs.position.value.y;
40 const float pz = inputs.position.value.z;
41 const float rx = inputs.rotation.value.x;
42 const float ry = inputs.rotation.value.y;
43 const float rz = inputs.rotation.value.z;
44 const float sx = inputs.scale.value.x;
45 const float sy = inputs.scale.value.y;
46 const float sz = inputs.scale.value.z;
50 || cache.pos[0] != px || cache.pos[1] != py || cache.pos[2] != pz
51 || cache.rot[0] != rx || cache.rot[1] != ry || cache.rot[2] != rz
52 || cache.scale[0] != sx || cache.scale[1] != sy || cache.scale[2] != sz;
61 m.translate(px, py, pz);
62 m.rotate(QQuaternion::fromEulerAngles(rx, ry, rz));
64 std::memcpy(out_transform16, m.constData(),
sizeof(
float) * 16);
66 cache.pos[0] = px; cache.pos[1] = py; cache.pos[2] = pz;
67 cache.rot[0] = rx; cache.rot[1] = ry; cache.rot[2] = rz;
68 cache.scale[0] = sx; cache.scale[1] = sy; cache.scale[2] = sz;
85template <
typename Inputs>
86inline std::shared_ptr<const ossia::scene_state> wrapSceneWithTransform(
87 const std::shared_ptr<const ossia::scene_state>& raw,
88 const Inputs& inputs, CachedTRS& cache, int64_t& version_counter,
89 const ossia::gpu_slot_ref& xform_ref = {})
94 ossia::scene_transform xform;
95 xform.translation[0] = inputs.position.value.x;
96 xform.translation[1] = inputs.position.value.y;
97 xform.translation[2] = inputs.position.value.z;
98 auto q = QQuaternion::fromEulerAngles(
99 inputs.rotation.value.x, inputs.rotation.value.y,
100 inputs.rotation.value.z);
101 xform.rotation[0] = q.x();
102 xform.rotation[1] = q.y();
103 xform.rotation[2] = q.z();
104 xform.rotation[3] = q.scalar();
105 xform.scale[0] = inputs.scale.value.x;
106 xform.scale[1] = inputs.scale.value.y;
107 xform.scale[2] = inputs.scale.value.z;
110 xform.raw_slot = xform_ref;
112 auto children = std::make_shared<std::vector<ossia::scene_payload>>();
113 children->push_back(xform);
115 for(
const auto& root : *raw->roots)
116 children->push_back(root);
118 auto parent = std::make_shared<ossia::scene_node>();
119 parent->children = std::move(children);
121 auto new_roots = std::make_shared<std::vector<ossia::scene_node_ptr>>();
122 new_roots->push_back(std::move(parent));
124 auto wrapped = std::make_shared<ossia::scene_state>();
125 wrapped->roots = std::move(new_roots);
128 wrapped->materials = raw->materials;
129 wrapped->animations = raw->animations;
130 wrapped->cameras = raw->cameras;
131 wrapped->skeletons = raw->skeletons;
132 wrapped->collections = raw->collections;
133 wrapped->environment = raw->environment;
134 wrapped->shadow_cascades = raw->shadow_cascades;
135 wrapped->inject_buffers = raw->inject_buffers;
136 wrapped->inject_textures = raw->inject_textures;
137 wrapped->time_seconds = raw->time_seconds;
138 wrapped->active_variant_index = raw->active_variant_index;
139 wrapped->variant_names = raw->variant_names;
140 wrapped->active_camera_id = raw->active_camera_id;
141 wrapped->version = ++version_counter;
142 wrapped->dirty_index = 1;
144 cache.pos[0] = inputs.position.value.x;
145 cache.pos[1] = inputs.position.value.y;
146 cache.pos[2] = inputs.position.value.z;
147 cache.rot[0] = inputs.rotation.value.x;
148 cache.rot[1] = inputs.rotation.value.y;
149 cache.rot[2] = inputs.rotation.value.z;
150 cache.scale[0] = inputs.scale.value.x;
151 cache.scale[1] = inputs.scale.value.y;
152 cache.scale[2] = inputs.scale.value.z;
161template <
typename Inputs>
162inline bool transformChanged(
const Inputs& inputs,
const CachedTRS& cache)
165 || cache.pos[0] != inputs.position.value.x
166 || cache.pos[1] != inputs.position.value.y
167 || cache.pos[2] != inputs.position.value.z
168 || cache.rot[0] != inputs.rotation.value.x
169 || cache.rot[1] != inputs.rotation.value.y
170 || cache.rot[2] != inputs.rotation.value.z
171 || cache.scale[0] != inputs.scale.value.x
172 || cache.scale[1] != inputs.scale.value.y
173 || cache.scale[2] != inputs.scale.value.z;
Definition TransformHelper.hpp:26