载入中...
搜索中...
未找到
SceneNodes.cpp
浏览该文件的文档.
1// Scene node / link / bounds / picking implementation.
2//
3// Split out of the original Scene.cpp so the script binding layer
4// (Scene.cpp) and the node manipulation methods live in separate
5// translation units. Pure move: no behavior change.
6
8#include "scene/Scene.h"
9#include "scene/SceneBounds.h"
10#include "scene/SceneInternal.h"
12#include "spatial/Octree.h"
13
14#include <simplesquirrel/simplesquirrel.hpp>
15
16#include <glm/glm.hpp>
17#include <glm/gtc/matrix_transform.hpp>
18#include <glm/gtc/quaternion.hpp>
19
20#include <limits>
21#include <string>
22#include <utility>
23#include <vector>
24
25namespace eve::scene {
26
27namespace {
28
29template <class T>
30T *borrowSceneResult(eve::Result<T *> result) {
31 if (!result.ok()) return nullptr;
32 return std::move(result).takeValue();
33}
34
35} // namespace
36
37bool Scene::setNodePosition(const std::string &id, float x, float y, float z) {
38 SceneHost *h = selected_;
39 if (!h) return false;
40 SceneNode *n = borrowSceneResult(h->findById(id));
41 if (!n) return false;
42 n->x = x;
43 n->y = y;
44 n->z = z;
45 h->markSubtreeDirtyById(id);
46 return true;
47}
48
49bool Scene::setNodeRotation(const std::string &id, float yaw, float pitch, float roll) {
50 SceneHost *h = selected_;
51 if (!h) return false;
52 SceneNode *n = borrowSceneResult(h->findById(id));
53 if (!n) return false;
54 n->yaw = yaw;
55 n->pitch = pitch;
56 n->roll = roll;
57 h->markSubtreeDirtyById(id);
58 return true;
59}
60
61bool Scene::setNodeScale(const std::string &id, float sx, float sy, float sz) {
62 SceneHost *h = selected_;
63 if (!h) return false;
64 SceneNode *n = borrowSceneResult(h->findById(id));
65 if (!n) return false;
66 n->sx = sx;
67 n->sy = sy;
68 n->sz = sz;
69 h->markSubtreeDirtyById(id);
70 return true;
71}
72
73bool Scene::setNodeVisible(const std::string &id, bool visible) {
74 SceneHost *h = selected_;
75 if (!h) return false;
76 SceneNode *n = borrowSceneResult(h->findById(id));
77 if (!n) return false;
78 n->visible = visible;
79 h->markSubtreeDirtyById(id); // resync renderable visibility via links
80 return true;
81}
82
86
90
91bool Scene::unlinkNode(const std::string &nodeId) {
93}
94
95// ---------------------------------------------------------------------------
96// Generic link system (host-scoped primitives)
97// ---------------------------------------------------------------------------
98
99bool Scene::linkRenderable2DAt(const std::string &hostName, const std::string &nodeId,
101 SceneHost *h = resolveHost(hostName);
102 if (!h) return false;
103 if (!h->linkRenderable2D(nodeId, r)) return false;
105 return true;
106}
107
108bool Scene::linkRenderable3DAt(const std::string &hostName, const std::string &nodeId,
110 SceneHost *h = resolveHost(hostName);
111 if (!h) return false;
112 if (!h->linkRenderable3D(nodeId, r)) return false;
114 return true;
115}
116
117bool Scene::linkPhysics2DAt(const std::string &hostName, const std::string &nodeId,
118 physics::Body *b, const std::string &mode) {
119 SceneHost *h = resolveHost(hostName);
120 if (!h) return false;
121 if (!h->linkPhysics2D(nodeId, b, syncModeFromString(mode))) return false;
123 return true;
124}
125
126bool Scene::linkPhysics3DAt(const std::string &hostName, const std::string &nodeId,
127 physics::Body3D *b, const std::string &mode) {
128 SceneHost *h = resolveHost(hostName);
129 if (!h) return false;
130 if (!h->linkPhysics3D(nodeId, b, syncModeFromString(mode))) return false;
132 return true;
133}
134
135bool Scene::linkCamera3DAt(const std::string &hostName, const std::string &nodeId,
137 SceneHost *h = resolveHost(hostName);
138 if (!h) return false;
139 if (!h->linkCamera3D(nodeId, c)) return false;
141 return true;
142}
143
144bool Scene::linkAudio3DAt(const std::string &hostName, const std::string &nodeId,
145 audio::Source *s) {
146 SceneHost *h = resolveHost(hostName);
147 if (!h) return false;
148 if (!h->linkAudio3D(nodeId, s)) return false;
150 return true;
151}
152
153bool Scene::unlinkNodeAt(const std::string &hostName, const std::string &nodeId) {
154 SceneHost *h = resolveHost(hostName);
155 return h ? h->unlink(nodeId) : false;
156}
157
158bool Scene::unlinkNodeKindAt(const std::string &hostName, const std::string &nodeId,
159 const std::string &kind) {
160 SceneHost *h = resolveHost(hostName);
161 if (!h) return false;
162 const int k = linkKindFromString(kind);
163 if (k < 0) return false;
164 const bool removed = h->unlink(nodeId, k);
166 return removed;
167}
168
169int Scene::linkCountAt(const std::string &hostName, const std::string &nodeId) {
170 SceneHost *h = resolveHost(hostName);
171 return h ? h->linkCount(nodeId) : 0;
172}
173
174// ---------------------------------------------------------------------------
175// Script-API completeness: transform getters / hierarchy / math / tags / layer
176// ---------------------------------------------------------------------------
177
178std::vector<float> Scene::getNodePositionAt(const std::string &hostName,
179 const std::string &nodeId) const {
180 SceneHost *h = resolveHost(hostName);
181 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
182 if (!n) return {0.f, 0.f, 0.f};
183 return {n->x, n->y, n->z};
184}
185
186std::vector<float> Scene::getNodeRotationAt(const std::string &hostName,
187 const std::string &nodeId) const {
188 SceneHost *h = resolveHost(hostName);
189 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
190 if (!n) return {0.f, 0.f, 0.f};
191 return {n->yaw, n->pitch, n->roll};
192}
193
194std::vector<float> Scene::getNodeScaleAt(const std::string &hostName,
195 const std::string &nodeId) const {
196 SceneHost *h = resolveHost(hostName);
197 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
198 if (!n) return {0.f, 0.f, 0.f};
199 return {n->sx, n->sy, n->sz};
200}
201
202bool Scene::getNodeVisibleAt(const std::string &hostName,
203 const std::string &nodeId) const {
204 SceneHost *h = resolveHost(hostName);
205 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
206 return n ? n->visible : false;
207}
208
209std::vector<float> Scene::getNodeWorldPositionAt(const std::string &hostName,
210 const std::string &nodeId) const {
211 SceneHost *h = resolveHost(hostName);
212 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
213 if (!n) return {0.f, 0.f, 0.f};
214 return {n->world[3][0], n->world[3][1], n->world[3][2]};
215}
216
217std::vector<float> Scene::getNodeWorldRotationAt(const std::string &hostName,
218 const std::string &nodeId) const {
219 SceneHost *h = resolveHost(hostName);
220 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
221 if (!n) return {0.f, 0.f, 0.f};
222 glm::vec3 pos, euler, scale;
223 decomposeWorld(n->world, pos, euler, scale);
224 return {euler.x, euler.y, euler.z};
225}
226
227std::vector<float> Scene::getNodeWorldScaleAt(const std::string &hostName,
228 const std::string &nodeId) const {
229 SceneHost *h = resolveHost(hostName);
230 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
231 if (!n) return {0.f, 0.f, 0.f};
232 glm::vec3 pos, euler, scale;
233 decomposeWorld(n->world, pos, euler, scale);
234 return {scale.x, scale.y, scale.z};
235}
236
237std::vector<float> Scene::localToWorldAt(const std::string &hostName,
238 const std::string &nodeId, float x, float y,
239 float z) const {
240 SceneHost *h = resolveHost(hostName);
241 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
242 if (!n) return {x, y, z};
243 glm::vec4 p = n->world * glm::vec4(x, y, z, 1.f);
244 return {p.x, p.y, p.z};
245}
246
247std::vector<float> Scene::worldToLocalAt(const std::string &hostName,
248 const std::string &nodeId, float x, float y,
249 float z) const {
250 SceneHost *h = resolveHost(hostName);
251 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
252 if (!n) return {x, y, z};
253 glm::vec4 p = glm::inverse(n->world) * glm::vec4(x, y, z, 1.f);
254 return {p.x, p.y, p.z};
255}
256
257bool Scene::setNodeParentAt(const std::string &hostName, const std::string &childId,
258 const std::string &parentId) {
259 SceneHost *h = resolveHost(hostName);
260 if (!h) return false;
261 const bool ok = h->setParentById(childId, parentId);
263 return ok;
264}
265
266bool Scene::removeNodeAt(const std::string &hostName, const std::string &nodeId) {
267 SceneHost *h = resolveHost(hostName);
268 if (!h) return false;
269 const bool ok = h->setParentById(nodeId, "");
271 return ok;
272}
273
274eve::Result<void> Scene::removeLeafAt(const std::string &hostName, const std::string &nodeId) {
275 auto *host = resolveHost(hostName);
276 if (!host || host->removeLeaf(nodeId) != SceneMutationStatus::Applied)
278 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "scene leaf cannot be removed", "scene.node"));
279 pruneOrphanObjects();
281}
282
283bool Scene::addChildAt(const std::string &hostName, const std::string &parentId,
284 const std::string &childId) {
285 SceneHost *h = resolveHost(hostName);
286 if (!h) return false;
287 const bool ok = h->setParentById(childId, parentId);
289 return ok;
290}
291
292bool Scene::removeChildAt(const std::string &hostName, const std::string &parentId,
293 const std::string &childId) {
294 SceneHost *h = resolveHost(hostName);
295 if (!h) return false;
296 const bool ok = h->removeChildById(parentId, childId);
298 return ok;
299}
300
301bool Scene::setNodeQuaternionAt(const std::string &hostName, const std::string &nodeId,
302 float qx, float qy, float qz, float qw) {
303 SceneHost *h = resolveHost(hostName);
304 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
305 if (!h || !n) return false;
306 glm::quat q(qw, qx, qy, qz);
307 eve::eulerYxzFromQuat(q, n->yaw, n->pitch, n->roll);
308 h->markSubtreeDirtyById(nodeId);
309 return true;
310}
311
312std::vector<float> Scene::getNodeQuaternionAt(const std::string &hostName,
313 const std::string &nodeId) const {
314 SceneHost *h = resolveHost(hostName);
315 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
316 if (!n) return {0.f, 0.f, 0.f, 1.f};
317 glm::quat q = nodeQuaternion(*n);
318 return {q.x, q.y, q.z, q.w};
319}
320
321bool Scene::setNodeLookAtAt(const std::string &hostName, const std::string &nodeId,
322 float tx, float ty, float tz) {
323 SceneHost *h = resolveHost(hostName);
324 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
325 if (!h || !n) return false;
326 glm::vec3 pos(n->x, n->y, n->z);
327 glm::vec3 target(tx, ty, tz);
328 glm::vec3 f = target - pos;
329 if (glm::dot(f, f) < 1e-8f) return false;
330 f = glm::normalize(f);
331 glm::vec3 up(0.f, 1.f, 0.f);
332 glm::vec3 right = glm::normalize(glm::cross(up, f));
333 if (glm::dot(right, right) < 1e-8f) right = glm::vec3(1.f, 0.f, 0.f); // f ∥ up
334 glm::vec3 up2 = glm::normalize(glm::cross(f, right));
335 glm::mat3 rot(right, up2, f);
336 glm::quat q = glm::quat_cast(rot);
337 eve::eulerYxzFromQuat(q, n->yaw, n->pitch, n->roll);
338 h->markSubtreeDirtyById(nodeId);
339 return true;
340}
341
342bool Scene::addNodeTagAt(const std::string &hostName, const std::string &nodeId,
343 const std::string &tag) {
344 SceneHost *h = resolveHost(hostName);
345 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
346 return h ? h->addTag(n, tag) : false;
347}
348
349bool Scene::removeNodeTagAt(const std::string &hostName, const std::string &nodeId,
350 const std::string &tag) {
351 SceneHost *h = resolveHost(hostName);
352 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
353 return h ? h->removeTag(n, tag) : false;
354}
355
356bool Scene::hasNodeTagAt(const std::string &hostName, const std::string &nodeId,
357 const std::string &tag) const {
358 SceneHost *h = resolveHost(hostName);
359 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
360 return h ? h->hasTag(n, tag) : false;
361}
362
363std::vector<std::string> Scene::getNodeTagsAt(const std::string &hostName,
364 const std::string &nodeId) const {
365 SceneHost *h = resolveHost(hostName);
366 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
367 if (!n) return {};
368 return n->tags;
369}
370
371std::vector<std::string> Scene::collectIdsByTagAt(const std::string &hostName,
372 const std::string &tag) const {
373 SceneHost *h = resolveHost(hostName);
374 if (!h) return {};
375 std::vector<std::string> out;
376 for (SceneNode *n : h->findAllByTag(tag)) {
377 if (n) out.push_back(n->id);
378 }
379 return out;
380}
381
382bool Scene::setNodeLayerAt(const std::string &hostName, const std::string &nodeId,
383 int layer) {
384 SceneHost *h = resolveHost(hostName);
385 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
386 if (!n) return false;
387 n->layer = layer;
388 return true;
389}
390
391int Scene::getNodeLayerAt(const std::string &hostName, const std::string &nodeId) const {
392 SceneHost *h = resolveHost(hostName);
393 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
394 return n ? n->layer : 0;
395}
396
397bool Scene::setNodeEventHandlerAt(const std::string &hostName, ssq::Object cb) {
398 if (!vm_) return false;
399 SceneHost *h = resolveHost(hostName);
400 if (!h) return false;
401 const std::string name = hostName.empty() ? h->getName() : hostName;
402
403 auto it = eventCbs_.find(name);
404 if (it != eventCbs_.end()) {
405 sq_release(vm_, &it->second);
406 eventCbs_.erase(it);
407 }
408 HSQOBJECT raw = cb.getRaw();
409 if (raw._type == OT_NULL) { // clear handler
410 h->setEventHandler({});
411 return true;
412 }
413 if (raw._type != OT_CLOSURE && raw._type != OT_NATIVECLOSURE) return false;
414 sq_addref(vm_, &raw);
415 eventCbs_[name] = raw;
416 h->setEventHandler(
417 [this, name](SceneHost *, const std::string &action, const std::string &nodeId,
418 const std::string &parentId) {
419 callEventCallback(name, action, nodeId, parentId);
420 });
421 return true;
422}
423
424void Scene::callEventCallback(const std::string &hostName, const std::string &action,
425 const std::string &nodeId, const std::string &parentId) {
426 if (!vm_) return;
427 auto it = eventCbs_.find(hostName);
428 if (it == eventCbs_.end()) return;
429 // Handler shape is (action, nodeId, parentId) with the root table as receiver, the
430 // same shape UI's callScriptHandler() uses. The count is derived, so the earlier
431 // "handler received two arguments and never ran" defect cannot come back.
432 (void)script::callFunction(vm_, it->second, script::rootTable, action, nodeId, parentId);
433}
434
435// ---------------------------------------------------------------------------
436// Bounds / serialization / picking / culling
437// ---------------------------------------------------------------------------
438
439bool Scene::setNodeBoundsAt(const std::string &hostName, const std::string &nodeId,
440 float minX, float minY, float minZ, float maxX, float maxY,
441 float maxZ) {
442 SceneHost *h = resolveHost(hostName);
443 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
444 if (!n) return false;
445 n->bminX = minX;
446 n->bminY = minY;
447 n->bminZ = minZ;
448 n->bmaxX = maxX;
449 n->bmaxY = maxY;
450 n->bmaxZ = maxZ;
451 n->hasBounds = true;
452 return true;
453}
454
455bool Scene::hasNodeBoundsAt(const std::string &hostName, const std::string &nodeId) const {
456 SceneHost *h = resolveHost(hostName);
457 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
458 return n ? n->hasBounds : false;
459}
460
461std::vector<float> Scene::getNodeBoundsAt(const std::string &hostName,
462 const std::string &nodeId) const {
463 SceneHost *h = resolveHost(hostName);
464 SceneNode *n = h ? borrowSceneResult(h->findById(nodeId)) : nullptr;
465 if (!n || !n->hasBounds) return {0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
466 return {n->bminX, n->bminY, n->bminZ, n->bmaxX, n->bmaxY, n->bmaxZ};
467}
468
469
470std::string Scene::pickRayAt(const std::string &hostName, float ox, float oy, float oz,
471 float dx, float dy, float dz) const {
472 SceneHost *h = resolveHost(hostName);
473 if (!h) return {};
474 const glm::vec3 origin(ox, oy, oz);
475 glm::vec3 dir(dx, dy, dz);
476 if (glm::dot(dir, dir) < 1e-12f) return {};
477 dir = glm::normalize(dir);
478
479 float bestT = std::numeric_limits<float>::max();
480 std::string best;
481 h->walkDepthFirst([&](SceneHost *, int, SceneNode &n) {
482 if (!n.hasBounds) return;
483 const AABB3f w = worldBoundsOf(n);
484 float t0 = 0.f, t1 = 0.f;
485 if (rayAABB(origin, dir, w, t0, t1) && t1 >= 0.f && t0 < bestT) {
486 bestT = std::max(t0, 0.f);
487 best = n.id;
488 }
489 });
490 return best;
491}
492
493bool Scene::syncSpatialIndexAt(const std::string &hostName, spatial::Octree *ot) const {
494 SceneHost *h = resolveHost(hostName);
495 if (!h || !ot) return false;
496 bool any = false;
497 h->walkDepthFirst([&](SceneHost *, int index, SceneNode &n) {
498 if (!n.hasBounds) return;
499 const AABB3f w = worldBoundsOf(n);
500 ot->insert(index, w.min.x, w.min.y, w.min.z, w.max.x, w.max.y, w.max.z);
501 any = true;
502 });
503 return any;
504}
505
506std::string Scene::nodeIdFromSpatialIdAt(const std::string &hostName, int index) const {
507 SceneHost *h = resolveHost(hostName);
508 SceneNode *n = h ? h->getNode(index) : nullptr;
509 return n ? n->id : std::string{};
510}
511
512bool Scene::hasNode(const std::string &id) {
513 SceneHost *h = selected_;
514 return h ? h->hasNode(id) : false;
515}
516
518 SceneHost *h = selected_;
519 return h ? h->getNodeCount() : 0;
520}
521
522std::string Scene::getRootId() {
523 SceneHost *h = selected_;
524 if (!h) return {};
525 SceneNode *r = h->getRoot();
526 return r ? r->id : std::string{};
527}
528
529std::string Scene::getParentId(const std::string &id) {
530 SceneHost *h = selected_;
531 if (!h) return {};
532 SceneNode *p = h->getParentById(id);
533 return p ? p->id : std::string{};
534}
535
536int Scene::getChildCount(const std::string &id) {
537 SceneHost *h = selected_;
538 return h ? h->getChildCountById(id) : 0;
539}
540
541std::string Scene::getChildIdAt(const std::string &parentId, int childOrdinal) {
542 SceneHost *h = selected_;
543 if (!h) return {};
544 SceneNode *c = h->getChildAtById(parentId, childOrdinal);
545 return c ? c->id : std::string{};
546}
547
548std::string Scene::findIdByName(const std::string &name) {
549 SceneHost *h = selected_;
550 if (!h) return {};
551 SceneNode *n = borrowSceneResult(h->findByName(name));
552 return n ? n->id : std::string{};
553}
554
555std::string Scene::findIdByPath(const std::string &path) {
556 SceneHost *h = selected_;
557 if (!h) return {};
558 SceneNode *n = borrowSceneResult(h->findByPath(path));
559 return n ? n->id : std::string{};
560}
561
562std::string Scene::getNodePath(const std::string &id) {
563 SceneHost *h = selected_;
564 return h ? h->getPathById(id) : std::string{};
565}
566
567bool Scene::isAncestor(const std::string &ancestorId, const std::string &nodeId) {
568 SceneHost *h = selected_;
569 return h ? h->isAncestorOfById(ancestorId, nodeId) : false;
570}
571
572bool Scene::isDescendant(const std::string &nodeId, const std::string &ancestorId) {
573 SceneHost *h = selected_;
574 return h ? h->isDescendantOfById(nodeId, ancestorId) : false;
575}
576
577std::vector<std::string> Scene::collectIds() {
578 SceneHost *h = selected_;
579 return h ? h->collectIds() : std::vector<std::string>{};
580}
581
582std::vector<std::string> Scene::collectIdsFrom(const std::string &id) {
583 SceneHost *h = selected_;
584 if (!h) return {};
585 return h->collectIdsFrom(h->findIndexById(id));
586}
587
588std::vector<std::string> Scene::collectIdsByName(const std::string &name) {
589 SceneHost *h = selected_;
590 return h ? h->collectIdsByName(name) : std::vector<std::string>{};
591}
592
593std::vector<std::string> Scene::collectIdsVisible(bool visible) {
594 SceneHost *h = selected_;
595 return h ? h->collectIdsVisible(visible) : std::vector<std::string>{};
596}
597
598std::vector<std::string> Scene::collectChildIds(const std::string &parentId) {
599 SceneHost *h = selected_;
600 return h ? h->getChildIds(parentId) : std::vector<std::string>{};
601}
602
603std::vector<std::string> Scene::walkDepthFirstIds() { return collectIds(); }
604
605std::vector<std::string> Scene::walkBreadthFirstIds() {
606 SceneHost *h = selected_;
607 if (!h) return {};
608 std::vector<std::string> out;
609 h->walkBreadthFirst([&](SceneHost *, int, SceneNode &n) { out.push_back(n.id); });
610 return out;
611}
612
613} // namespace eve::scene
double z
double y
double x
LogicalId target
float w
Definition AnimClip.cpp:738
const std::string & s
float yaw
Definition BushMesh.cpp:37
glm::vec4 p[6]
std::string nodeId
std::string name
Definition ECS.cpp:154
double raw
std::uint64_t parentId
glm::vec3 n
Definition Grass.cpp:63
std::array< double, 10 > q
double r
HexVec3 up
HexVec3 right
std::int32_t c
int h
std::array< float, 3 > scale
Poco::JSON::Object::Ptr result
MeleePoint3 b
Definition MeleeHit.cpp:41
const std::string * tag
glm::dvec3 origin
glm::dvec3 dx
glm::dvec3 dz
TileLayer * layer
float f
std::string action
Definition PlayHost.cpp:118
std::string path
Definition PlayHost.cpp:111
int removed
ScriptStructure out
std::string kind
float dy
Definition Shadow.cpp:151
The single Squirrel projection for common Result, Status and Value.
std::map< Cell, int > best
bool visible
V3 dir
Definition TreeMesh.cpp:151
UIHostHandle host
uint32_t index
double oy
double ox
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
A playable audio source (static buffer or streaming decoder). Not thread-safe for playback control ex...
Definition Source.h:30
EVENGINE_API_BACKENDS public API.
Default renderable entity for declarative 2D sprites / solid quads.
EVENGINE_API_BACKENDS public API.
Backend-neutral 3D rigid body in meter-space coordinates (+Y up by convention). Owned by a World3D; c...
Definition Body3D.h:31
2D rigid body (Box2D) in pixel-space coordinates. Owned by a World; create shapes with newRectangleFi...
Definition Body.h:21
ECS mount point for one scene graph (full scene or nested subtree root). Isomorphic to eve::ui::UIHos...
Definition SceneHost.h:89
bool isAncestorOfById(const std::string &ancestorId, const std::string &nodeId)
bool isDescendantOfById(const std::string &nodeId, const std::string &ancestorId)
int getChildCountById(const std::string &id)
std::vector< std::string > collectIdsVisible(bool visible=true)
std::vector< std::string > getChildIds(const std::string &parentId)
std::vector< std::string > collectIdsFrom(int nodeIndex)
std::vector< std::string > collectIdsByName(const std::string &name)
std::string getPathById(const std::string &id)
std::vector< std::string > collectIds()
void walkBreadthFirst(NodeVisitFn fn)
BFS from root (or from nodeIndex), inclusive.
bool hasNode(const std::string &id)
bool linkPhysics3DAt(const std::string &hostName, const std::string &nodeId, physics::Body3D *b, const std::string &mode)
Link physics 3 d at.
SceneHost * resolveHost(const std::string &hostName) const
Host-qualified resolution: empty hostName → currently selected host.
Definition Scene.cpp:869
std::vector< std::string > collectIdsFrom(const std::string &id)
Collect ids from.
bool setNodeParentAt(const std::string &hostName, const std::string &childId, const std::string &parentId)
Reparent by id; empty parentId detaches. Cycle-safe.
std::vector< std::string > collectIds()
Collect ids.
bool linkCamera3DAt(const std::string &hostName, const std::string &nodeId, graphics::Camera3D *c)
Link camera 3 d at.
std::vector< std::string > collectIdsByTagAt(const std::string &hostName, const std::string &tag) const
Collect ids by tag at.
std::vector< float > getNodeRotationAt(const std::string &hostName, const std::string &nodeId) const
Returns the node rotation at.
std::string findIdByPath(const std::string &path)
Finds id by path.
bool setNodeQuaternionAt(const std::string &hostName, const std::string &nodeId, float qx, float qy, float qz, float qw)
Sets the node quaternion at.
bool getNodeVisibleAt(const std::string &hostName, const std::string &nodeId) const
Returns the node visible at.
std::vector< float > worldToLocalAt(const std::string &hostName, const std::string &nodeId, float x, float y, float z) const
World to local at.
std::vector< float > getNodePositionAt(const std::string &hostName, const std::string &nodeId) const
Returns the node position at.
std::vector< float > getNodeWorldPositionAt(const std::string &hostName, const std::string &nodeId) const
Returns the node world position at.
int getNodeLayerAt(const std::string &hostName, const std::string &nodeId) const
Returns the node layer at.
bool linkPhysics2DAt(const std::string &hostName, const std::string &nodeId, physics::Body *b, const std::string &mode)
Link physics 2 d at.
bool removeNodeAt(const std::string &hostName, const std::string &nodeId)
Detach node from its parent (arena node stays; rebuild to delete).
std::vector< std::string > collectChildIds(const std::string &parentId)
Collect child ids.
bool unlinkNodeAt(const std::string &hostName, const std::string &nodeId)
Remove every link on the node.
bool setNodePosition(const std::string &id, float x, float y, float z)
Script-friendly TRS setters on the current host; each marks the transform dirty.
std::vector< std::string > collectIdsVisible(bool visible)
Collect ids visible.
bool linkAudio3DAt(const std::string &hostName, const std::string &nodeId, audio::Source *s)
Link audio 3 d at.
bool setNodeLookAtAt(const std::string &hostName, const std::string &nodeId, float tx, float ty, float tz)
Orient node so its local +Z axis points at (tx,ty,tz).
std::string currentHostName() const
Current host name.
Definition Scene.cpp:1138
std::vector< float > getNodeWorldRotationAt(const std::string &hostName, const std::string &nodeId) const
Returns the node world rotation at.
bool hasNode(const std::string &id)
True when node.
std::string getNodePath(const std::string &id)
Returns the node path.
std::string findIdByName(const std::string &name)
Finds id by name.
int getChildCount(const std::string &id)
Returns the child count.
bool removeNodeTagAt(const std::string &hostName, const std::string &nodeId, const std::string &tag)
Removes node tag at.
bool linkRenderable3DAt(const std::string &hostName, const std::string &nodeId, graphics::Renderable3D *r)
Link renderable 3 d at.
bool isAncestor(const std::string &ancestorId, const std::string &nodeId)
True when ancestor.
bool setNodeScale(const std::string &id, float sx, float sy, float sz)
Sets the local scale of a node.
std::string getParentId(const std::string &id)
Returns the parent id.
std::vector< std::string > collectIdsByName(const std::string &name)
Collect ids by name.
bool unlinkNodeKindAt(const std::string &hostName, const std::string &nodeId, const std::string &kind)
Remove links of one kind ("renderable2d"|"renderable3d"|"physics2d"|...).
std::vector< float > getNodeScaleAt(const std::string &hostName, const std::string &nodeId) const
Returns the node scale at.
std::string nodeIdFromSpatialIdAt(const std::string &hostName, int index) const
Map a spatial-index id (arena index) back to a node id.
std::vector< std::string > getNodeTagsAt(const std::string &hostName, const std::string &nodeId) const
Returns the node tags at.
int linkCountAt(const std::string &hostName, const std::string &nodeId)
Link count at.
bool hasNodeBoundsAt(const std::string &hostName, const std::string &nodeId) const
True when node bounds at.
std::vector< std::string > walkBreadthFirstIds()
Walk breadth first ids.
bool linkRenderable3D(const std::string &nodeId, graphics::Renderable3D *r)
Links a 3D renderable to a node in the current host.
bool setNodeLayerAt(const std::string &hostName, const std::string &nodeId, int layer)
Sets the node layer at.
bool setNodeRotation(const std::string &id, float yaw, float pitch, float roll)
Sets the local rotation (yaw/pitch/roll in degrees) of a node.
bool unlinkNode(const std::string &nodeId)
Removes every link on a node in the current host.
bool syncSpatialIndexAt(const std::string &hostName, spatial::Octree *ot) const
Insert every bounded node's world AABB into an octree (id = arena index).
bool setNodeEventHandlerAt(const std::string &hostName, ssq::Object cb)
Register a script callback for node lifecycle events on a host: The callback receives action,...
std::vector< float > getNodeQuaternionAt(const std::string &hostName, const std::string &nodeId) const
Returns the node quaternion at.
bool removeChildAt(const std::string &hostName, const std::string &parentId, const std::string &childId)
Removes child at.
bool setNodeBoundsAt(const std::string &hostName, const std::string &nodeId, float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
Sets the node bounds at.
bool setNodeVisible(const std::string &id, bool visible)
Shows/hides a node.
eve::Result< void > removeLeafAt(const std::string &hostName, const std::string &nodeId)
Delete a leaf node and release its scene-owned script/ECS companion.
std::string getRootId()
Returns the root id.
bool addChildAt(const std::string &hostName, const std::string &parentId, const std::string &childId)
Adds child at.
std::string getChildIdAt(const std::string &parentId, int childOrdinal)
Returns the child id at.
bool linkRenderable2DAt(const std::string &hostName, const std::string &nodeId, graphics::Renderable2D *r)
Link renderable 2 d at.
std::vector< float > localToWorldAt(const std::string &hostName, const std::string &nodeId, float x, float y, float z) const
Local to world at.
std::vector< float > getNodeWorldScaleAt(const std::string &hostName, const std::string &nodeId) const
Returns the node world scale at.
bool isDescendant(const std::string &nodeId, const std::string &ancestorId)
True when descendant.
bool hasNodeTagAt(const std::string &hostName, const std::string &nodeId, const std::string &tag) const
True when node tag at.
int getNodeCount()
Returns the node count.
std::vector< std::string > walkDepthFirstIds()
DFS order of ids under root (same as collectIds). Kept for script naming clarity.
std::vector< float > getNodeBoundsAt(const std::string &hostName, const std::string &nodeId) const
Returns the node bounds at.
std::string pickRayAt(const std::string &hostName, float ox, float oy, float oz, float dx, float dy, float dz) const
Nearest node id hit by a world ray (nodes with bounds), or "".
bool addNodeTagAt(const std::string &hostName, const std::string &nodeId, const std::string &tag)
Adds node tag at.
bool linkRenderable2D(const std::string &nodeId, graphics::Renderable2D *r)
Links a 2D renderable to a node in the current host.
static void updateHost(SceneHost *host)
Updates host.
Region octree for 3D AABB broad-phase / scene culling. Same storage rules as QuadTree (smallest fully...
Definition Octree.h:18
bool insert(int id, float minX, float minY, float minZ, float maxX, float maxY, float maxZ)
Inserts an item AABB; false if out of bounds or id already present.
Definition Octree.cpp:37
bool rayAABB(const glm::vec3 &o, const glm::vec3 &d, const AABB3f &b, float &t0, float &t1)
Slab ray-AABB intersection; fills entry/exit t (t0 <= t1).
Definition SceneBounds.h:49
AABB3f worldBoundsOf(const SceneNode &n)
World-space AABB of a node's local bounds (8 corners through world matrix).
Definition SceneBounds.h:26
SQRESULT callFunction(HSQUIRRELVM vm, const HSQOBJECT &fn, const Receiver &receiver, Args &&... args)
Call a script function, deriving sq_call's parameter count from the pushes.
constexpr RootTable rootTable
void eulerYxzFromQuat(const glm::qua< T, glm::defaultp > &q, T &yaw, T &pitch, T &roll)
Quaternion overload of eulerYxzFromMatrix(); float and double both work.
Axis-aligned box in world space.
Definition SceneBounds.h:20
Retained scene node (arena). Conceptual GameObject; isomorphic to eve::ui::UINode.
Definition SceneHost.h:46