14SceneHost *hostByName(
const std::string &
name) {
15 if (
name.empty())
return nullptr;
16 if (ecs::current()->getManager<SceneHost>() ==
nullptr)
return nullptr;
17 auto view = ecs::View<SceneHost, SceneHost::Meta>();
18 for (
auto it =
view.begin(); it !=
view.end(); ++it) {
20 if (meta->entity && meta->name ==
name)
return meta->entity;
25SceneHost *hostAt(
int index) {
26 if (index < 0 || ecs::current()->getManager<SceneHost>() ==
nullptr)
return nullptr;
27 auto view = ecs::View<SceneHost, SceneHost::Meta>();
29 for (
auto it =
view.begin(); it !=
view.end(); ++it, ++i) {
31 if (i == index)
return meta->entity;
36SceneNodeInfo toInfo(SceneHost *host,
const SceneNode &
n) {
40 info.path = host->getPathById(
n.id);
41 info.visible =
n.visible;
51 if (
auto *
p = host->getParentById(
n.id)) info.parent =
p->id;
52 for (
int i = 0; i < host->getChildCountById(
n.id); ++i) {
53 if (
auto *
c = host->getChildAtById(
n.id, i)) info.children.push_back(
c->id);
60 SceneHost *host()
const {
61 auto *
s = eve::ModuleManager::getInstance<Scene>(
"Scene");
62 return s ?
s->current() :
nullptr;
65 std::string activeHost()
const override {
67 return h ?
h->getName() : std::string();
70 int hostCount()
const override {
71 if (ecs::current()->getManager<SceneHost>() ==
nullptr)
return 0;
72 auto view = ecs::View<SceneHost, SceneHost::Meta>();
74 for (
auto it =
view.begin(); it !=
view.end(); ++it) ++
n;
78 std::string hostNameAt(
int index)
const override {
79 auto *
h = hostAt(index);
80 return h ?
h->getName() : std::string();
83 int nodeCount()
const override {
85 return h ?
h->getNodeCount() : 0;
88 std::string rootId()
const override {
90 auto *r =
h ?
h->getRoot() :
nullptr;
91 return r ? r->id : std::string();
94 std::vector<SceneNodeInfo> nodes(
int limit)
const override {
95 return nodesOf(host() ? host()->getName() : std::string(), limit);
98 std::vector<SceneNodeInfo> nodesOf(
const std::string &hostName,
int limit)
const override {
99 std::vector<SceneNodeInfo> out;
100 SceneHost *
h = hostName.empty() ? host() : hostByName(hostName);
102 h->walkDepthFirst([&](SceneHost *,
int, SceneNode &
n) {
103 if (
static_cast<int>(out.size()) >= limit)
return;
104 out.push_back(toInfo(
h,
n));
109 bool getNode(
const std::string &
id, SceneNodeInfo *out)
const override {
111 return h ? getNodeIn(
h->getName(),
id, out) : false;
114 bool getNodeIn(
const std::string &hostName,
const std::string &
id,
115 SceneNodeInfo *out)
const override {
116 SceneHost *
h = hostName.empty() ? host() : hostByName(hostName);
117 SceneNode *
n =
h ?
h->findById(
id) :
nullptr;
118 if (!
n || !out)
return false;
119 *out = toInfo(
h, *
n);
123 bool setNodeTransform(
const std::string &
id,
float x,
float y,
float z)
override {
125 SceneNode *
n =
h ?
h->findById(
id) :
nullptr;
126 if (!
n)
return false;
130 h->markTransformDirty();
134 bool setNodeVisible(
const std::string &
id,
bool visible)
override {
136 SceneNode *
n =
h ?
h->findById(
id) :
nullptr;
137 if (!
n)
return false;
138 n->visible = visible;
148 static SceneQueryImpl
impl;
Scene graph query/mutation surface (provided by the scene module).
void registerSceneCapabilities()