我不能制作线框盒子

时间:2013-07-21 18:37:15

标签: javascript three.js

我做了一个旋转的盒子,它正常工作。然后我使用linebasicmaterial将材质代码更改为线框材质。我阅读了three.js文档并按照示例进行操作。但它没有显示任何东西。只是纯白色。我已经更改了颜色十六进制,因为默认为白​​色。

这是js小提琴示例http://jsfiddle.net/wick3dsono/tXgcD/

  // revolutions per second
  var angularSpeed = 0.2; 
  var lastTime = 0;

  // this function is executed on each animation frame
  function animate(){
    // update
    var time = (new Date()).getTime();
    var timeDiff = time - lastTime;
    var angleChange = angularSpeed * timeDiff * 2 * Math.PI / 1000;
    cube.rotation.y += angleChange;
    lastTime = time;

    // render
    renderer.render(scene, camera);

    // request new frame
    requestAnimationFrame(function(){
        animate();
    });
  }

  // renderer
  var renderer = new THREE.WebGLRenderer();
  renderer.setSize(window.innerWidth, window.innerHeight);
  document.body.appendChild(renderer.domElement);

  // camera
  var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
  camera.position.z = 500;

  // scene
  var scene = new THREE.Scene();

  // material
  var mat = new THREE.LineaBasicMaterial({color: 0x00aeef});

  // primary cube (little one)
  var cube = new THREE.Mesh(new THREE.CubeGeometry(200, 200, 200), mat);
  cube.overdraw = true;
  cube.rotation.x = Math.PI * 0.1;
  scene.add(cube);

  // secondary cube (big one)
  //var cube_big = new THREE.Mesh(new THREE.CubeGeometry(200,200,200), mat);
  //cube_big.overdraw = true;
  //cube_big.rotation.x = Math.PI * 0.1;
  //scene.add(cube_big);

  // add subtle ambient lighting
  var ambientLight = new THREE.AmbientLight(0xbbbbbb);
  scene.add(ambientLight);

  // directional lighting
  var directionalLight = new THREE.DirectionalLight(0xffffff);
  directionalLight.position.set(1, 1, 1).normalize();
  scene.add(directionalLight);

  // start animation
  animate();

无论如何,我也是js小提琴的新手,所以当我把代码放在js小提琴上时可能会出现错误。我只是从我的代码编辑器中复制粘贴,删除html和head标签,然后将脚本复制到js字段。在我的代码编辑器上,我只是将它放在一个html文件中。

1 个答案:

答案 0 :(得分:2)

您可以使用MeshBasicMaterial或MeshLambert材质,并使用以下选项:wireframe:true