无法在A帧中为.mtl分配材料

时间:2018-01-26 05:58:18

标签: javascript three.js aframe

我一直试图从.MTL文件中提取ID并使用javascript通过组件分配材料。但是,即使没有错误也无法分配材料。这是我的方法,想知道它出了什么问题。

还有其他方法可以通过javascript提取ID并分配资料吗?

 <a-scene>
      <a-assets>

        <a-asset-item id="tree-obj" src="model/skin/house/house.obj"></a-asset-item>
        <a-asset-item id="tree-mtl" src="model/skin/house/house.mtl"></a-asset-item>

      </a-assets>

      <a-camera position="0 1.6 0"> <a-entity cursor="fuse: true; maxDistance: 500; timeout: 200" position="0 0 -2" geometry="primitive:ring" material="color:black;shader:flat" scale=".03 .03 .03">

        </a-entity></a-camera>

        <a-entity example obj-model="obj: #tree-obj; mtl: #tree-mtl" position="0 0 0" rotation="0 0 0" scale="0.172 0.172 0.172"></a-entity>
        <a-image src="#shadow2" rotation="0 90 0" scale="0.015 0.015 0.015" ></a-image>
      </a-entity>


      <a-sky color="#ECECEC"></a-sky>
      <a-light type="directional" color="#fff" intensity="0.7" position="-1 2 1"></a-light>
      <a-light type="ambient" color="#fff"></a-light>     
    </a-scene>
    <script>
  var Black;
AFRAME.registerComponent('example', {
    init: function() {
       var tex = new THREE.TextureLoader().load('sofa/chair.jpg');
Black = new THREE.MeshPhongMaterial({
  //name:"ID1",

  map:tex,
    color:0xffffff,
    combine: THREE.MixOperation,
    specular: 0xfafafa,            //bbaa99,
     shininess: 70,
     metalness:0.2,
     emissive:0x000000,
    reflectivity:0.7


})

    var el = this.el;  // Element to add click listener.



el.addEventListener('model-loaded', function (e) {
  e.detail.model.traverse(function(child) {
    if (child instanceof THREE.Mesh)
    {
      if (child.material.name == "polySurface1_torso_MeshMat")  {
                                       child.material=Black;
                                        child.castShadow = true;
                                        child.receiveShadow = true;
                                    }

    }
  });
})    
    }
  })

    </script>
 </body>

0 个答案:

没有答案