简体   繁体   English

为什么不渲染? / 带有三个 object3D 的 Aframe

[英]Why does not render? / Aframe with three object3D

I want to use threejs with aframe.我想将threejs与aframe一起使用。 threejs object does not rendered. Threejs 对象不呈现。

How can I render three object in aframe?如何在aframe中渲染三个对象?

html html

<a-scene>
  <a-entity geometry material id="obje"></a-entity>
  <a-entity camera id="cam"></a-entity>
</a-scene>

js js

window.addEventListener('load', init);

function init() {
  width = document.body.clientWidth;
  height = document.body.clientHeight;

  camera = new THREE.PerspectiveCamera(100, width / height);
  camera.position.set(0, 0, +1000);

  const geometry = new THREE.BoxGeometry(400, 400, 400);
  const material = new THREE.MeshNormalMaterial();
  box = new THREE.Mesh(geometry, material);

  const entityEl = document.querySelector('#obje');
  entityEl.setObject3D('mesh', box);

  const cam = document.querySelector('#cam');
  cam.setObject3D('camera', camera);
};

Two main issues:两个主要问题:

  1. The presented THREE.js code is redundant.提供的 THREE.js 代码是多余的。 The camera component already initializes a THREE.PerspectiveCamera and geometry and material set a mesh on the entity with a geometry and a material .相机组件已经初始化THREE.PerspectiveCamera几何形状材料组中的mesh上用所述实体geometrymaterial See glitch illustrating 参见故障说明
  2. If the built-in components don't provide the functionality you need, you don't have to use them and I recommend encapsulating your code in a component .如果内置组件没有提供您需要的功能,您就不必使用它们,我建议将您的代码封装在一个组件中 Glitch illustrating 故障说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM