简体   繁体   English

尝试通过A-Frame内的three.js编辑材质的侧面属性会导致渲染错误

[英]Trying to edit side property of material via three.js inside A-Frame results in incorrect rendering

I've posted about this problem on my blog , as I can only post two links in this question while I still am a noob on Stack Overflow. 在我的博客上发布了这个问题 ,因为我只能在这个问题上发布两个链接,而我仍然是Stack Overflow上的菜鸟。

Since first posting this question, I've updated it to reflect the progress I've made. 自从首次发布此问题以来,我已对其进行了更新,以反映我所取得的进展。

You can see my attempted code in action here , and the key code below: 您可以在此处查看我尝试过的代码 ,以及下面的密钥代码:

var side = this.data.side; //should be 2, the default value, all I want to be able to do is material.side = side; - change the side property of the material to
var object3D = this.el.object3D;

console.log("Starting traverse of object3D");
object3D.traverse( function( child ){
    console.log("Traversing...")
    console.log("The current child object is: ", child);
    console.log("The type of the child is", typeof child);
    if ( child instanceof THREE.Group ) {
      console.log("Found a THREE.Group!")
      child.traverse(function(childOfChild) {
        console.log("Traversing the traversing...")
        console.log("The current child of child object is: ", childOfChild);
        console.log("The type of the child is", typeof childOfChild); //how is the mesh object always one away from me?
        if ( childOfChild instanceof THREE.Mesh ) {
          console.log("Found a THREE.Mesh!")
        }
      }
      );
    }
  }
);
console.log("Finished traverse of object3D");

All I want to be able to do is: 我想要做的就是:

theMaterialOfTheObject3D.side = 2 aka THREE.DoubleSide theMaterialOfTheObject3D.side = 2又名THREE.DoubleSide

But how can I access the material within Three.js? 但是我怎样才能访问Three.js中的资料? I can't traverse, because as @mrdoob himself says: 我不能遍历,因为@mrdoob自己说:

Geometries and Materials are not children. 几何和材料不是儿童。

I recommend writing code within components so you don't have to worry about timing. 我建议在组件中编写代码,这样您就不必担心时间问题了。 https://aframe.io/docs/0.3.0/core/component.html https://aframe.io/docs/0.3.0/core/component.html

AFRAME.registerComponent('material-side-modifier', {
  dependencies: ['yourlandscapecomponent'],  // Or wait on an event.

  init: function () {
    // Modify material side here.
  }
}); 

<a-entity yourlandscapecomponent material-side-modifier>

If you order the components in HTML like so, you might not even need to specify the dependencies . 如果您像这样在HTML中订购组件,则甚至可能不需要指定dependencies

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

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