簡體   English   中英

嘗試通過A-Frame內的three.js編輯材質的側面屬性會導致渲染錯誤

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

在我的博客上發布了這個問題 ,因為我只能在這個問題上發布兩個鏈接,而我仍然是Stack Overflow上的菜鳥。

自從首次發布此問題以來,我已對其進行了更新,以反映我所取得的進展。

您可以在此處查看我嘗試過的代碼 ,以及下面的密鑰代碼:

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");

我想要做的就是:

theMaterialOfTheObject3D.side = 2又名THREE.DoubleSide

但是我怎樣才能訪問Three.js中的資料? 我不能遍歷,因為@mrdoob自己說:

幾何和材料不是兒童。

我建議在組件中編寫代碼,這樣您就不必擔心時間問題了。 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>

如果您像這樣在HTML中訂購組件,則甚至可能不需要指定dependencies

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM