如何从组件中获取场景中的所有对象?
How to get all objects in the scene from a component?
在组件中获取场景中所有对象的正确方法是什么?
例如,如果我需要对所有内容进行光线投射。
AFRAME.registerComponent('foo', {
init: function () {
var el = this.el;
// Get all objects in scene?
}
});
您可以抓取场景,然后从那里获取所有 children。 https://aframe.io/docs/0.3.0/core/entity.html#sceneel
AFRAME.registerComponent('foo', {
init: function () {
var allObjects = this.el.sceneEl.object3D.children;
}
});
- this: 组件实例
- el:
<a-entity>
组件附加到的元素
- sceneEl:
<a-scene>
元素
- object3D:three.js场景object
- children: three.js 所有 object 场景
在组件中获取场景中所有对象的正确方法是什么?
例如,如果我需要对所有内容进行光线投射。
AFRAME.registerComponent('foo', {
init: function () {
var el = this.el;
// Get all objects in scene?
}
});
您可以抓取场景,然后从那里获取所有 children。 https://aframe.io/docs/0.3.0/core/entity.html#sceneel
AFRAME.registerComponent('foo', {
init: function () {
var allObjects = this.el.sceneEl.object3D.children;
}
});
- this: 组件实例
- el:
<a-entity>
组件附加到的元素 - sceneEl:
<a-scene>
元素 - object3D:three.js场景object
- children: three.js 所有 object 场景