簡體   English   中英

是否可以將Mutation Observer與Three js元素-A-Frame一起使用?

[英]Is it possible to use Mutation Observer with a Three js element - A-Frame?

export class ColliderComponent {

  constructor() {
    this.observer = this.mutationObserver();      
    this.aframe(); 
  }


  //Registers the AFRAME component.
  aframe(){
    const __this = this; 
    AFRAME.registerComponent('collider', {
      schema: {

      },
      init: function () {
          console.log("The element to be observed is:",this.el);

          __this.observer.observe(this.el, {characterData:true, subtree:true, attributes: true, attributeFilter: ['position'], childList : true}); 
      },

      tick : function(){
        console.log(this.el.getObject3D('mesh').position);
      }
    });

  }

  private tick(){

  }

  private mutationObserver() : MutationObserver{
    return new MutationObserver(mutations => {
      mutations.forEach(mutation => {
        console.log("Changed position");
      });
    });
  }

}

我正在創建一個簡單的對撞機。 我將跟蹤具有“對撞機”組件的元素,並使用intersectsBox檢查它們是否intersectsBox 不幸的是,我似乎無法使MutationObserver正常工作。 我寧願使用這種方法而不是滴答聲,因為它將開始每幀執行一次,而不是在元素移動時開始執行。

有什么建議么?

您可以使用

el.addEventListener('componentchanged', function (evt) {
  if (evt.detail.name === 'position') {

  }
});

但是通過刻度線進行輪詢/計時是同步的,可能仍然不是一個壞方法。

暫無
暫無

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

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