2014-10-29 70 views
0

我正在嘗試將Three.js用於VRML(WRL)模型。我想知道的是,該模型加載了顏色變化(彩色)。我如何才能以純色作爲原始文件加載模型?Three.js - VRML加載程序

我的例子是:http://dev.logicarts.com.br/semapro/projeto-3d/teste-1.html

代碼:

<div id="info"> 
    <a href="http://threejs.org" target="_blank">three.js</a> - 
    vrml format loader test - 
    <!--model from <a href="http://cs.iupui.edu/~aharris/webDesign/vrml/" target="_blank">VRML 2.0 Tutorial</a>,--> 
    </div> 

    <script src="js/three.min.js"></script> 

    <script src="js/OrbitControls.js"></script> 

    <script src="js/VRMLLoader.js"></script> 

    <script src="js/Detector.js"></script> 
    <script src="js/stats.min.js"></script> 

    <script> 

     if (! Detector.webgl) Detector.addGetWebGLMessage(); 

     var container, stats; 

     var camera, controls, scene, renderer; 

     var cross; 

     init(); 
     animate(); 

     function init() { 

      camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 0.01, 1e10); 
      camera.position.z = 6; 

      controls = new THREE.OrbitControls(camera); 

      controls.rotateSpeed = 5.0; 
      controls.zoomSpeed = 5; 

      controls.noZoom = false; 
      controls.noPan = false; 

      scene = new THREE.Scene(); 
      scene.add(camera); 

      // light 

      var dirLight = new THREE.DirectionalLight(0xffffff); 
      dirLight.position.set(200, 200, 1000).normalize(); 

      camera.add(dirLight); 
      camera.add(dirLight.target); 

      var loader = new THREE.VRMLLoader(); 
      loader.addEventListener('load', function (event) { 

       scene.add(event.content); 

      }); 
      loader.load("3d/conjunto-carcaca.wrl"); 

      // renderer 

      renderer = new THREE.WebGLRenderer({ antialias: false }); 
      renderer.setSize(window.innerWidth, window.innerHeight); 

      container = document.createElement('div'); 
      document.body.appendChild(container); 
      container.appendChild(renderer.domElement); 

      stats = new Stats(); 
      stats.domElement.style.position = 'absolute'; 
      stats.domElement.style.top = '0px'; 
      container.appendChild(stats.domElement); 

      // 

      window.addEventListener('resize', onWindowResize, false); 

     } 

     function onWindowResize() { 

      camera.aspect = window.innerWidth/window.innerHeight; 
      camera.updateProjectionMatrix(); 

      renderer.setSize(window.innerWidth, window.innerHeight); 

      controls.handleResize(); 

     } 

     function animate() { 

      requestAnimationFrame(animate); 

      controls.update(); 
      renderer.render(scene, camera); 

      stats.update(); 

     } 

    </script> 

回答

2

如果在scene.add(event.content);聲明中添加此代碼,場景中的所有對象將變成紅色。

scene.traverse (function (object) 
{ 
    if (object instanceof THREE.Mesh) { 
     object.material.color.setHex(0xff0000); 
    } 
});