Three.js立方体不显示对角线
软源LOGO
讲述咱程序员自己的故事

位置:软源 »编程 »文章

Three.js立方体不显示对角线

coolapp;2016-05-18 23:02:39;浏览:1600

同问:Three.js中创建的立方体只显示它的12条边

描述:用 THREE.BoxGeometry 创建的立方体有对角线,无法去除。

解决方法:其他方法重建模型

// 画直线
function draw_line(v1,v2,color){var geometry=new THREE.Geometry();geometry.vertices.push(v1,v2);return new THREE.Line(geometry,new THREE.MeshPhongMaterial({emissive:color,color:color}));}
// 画立方体线
function draw_cube(width,height,depth,color){
  var hw=(width||200)/2,
    hh=(height||200)/2,
    hd=depth/2,
    c=color||0xff0000;

  var cube=new THREE.Object3D();

  cube.add(new draw_line(new THREE.Vector3(-hw,-hh,-hd),new THREE.Vector3(hw,-hh,-hd),c));
  cube.add(new draw_line(new THREE.Vector3(-hw,hh,-hd),new THREE.Vector3(hw,hh,-hd),c));
  cube.add(new draw_line(new THREE.Vector3(-hw,-hh,hd),new THREE.Vector3(hw,-hh,hd),c));
  cube.add(new draw_line(new THREE.Vector3(-hw,hh,hd),new THREE.Vector3(hw,hh,hd),c));

  cube.add(new draw_line(new THREE.Vector3(-hw,-hh,-hd),new THREE.Vector3(-hw,-hh,hd),c));
  cube.add(new draw_line(new THREE.Vector3(-hw,hh,-hd),new THREE.Vector3(-hw,hh,hd),c));
  cube.add(new draw_line(new THREE.Vector3(hw,-hh,-hd),new THREE.Vector3(hw,-hh,hd),c));
  cube.add(new draw_line(new THREE.Vector3(hw,hh,-hd),new THREE.Vector3(hw,hh,hd),c));

  cube.add(new draw_line(new THREE.Vector3(-hw,-hh,-hd),new THREE.Vector3(-hw,hh,-hd),c));
  cube.add(new draw_line(new THREE.Vector3(hw,-hh,-hd),new THREE.Vector3(hw,hh,-hd),c));
  cube.add(new draw_line(new THREE.Vector3(-hw,-hh,hd),new THREE.Vector3(-hw,hh,hd),c));
  cube.add(new draw_line(new THREE.Vector3(hw,-hh,hd),new THREE.Vector3(hw,hh,hd),c));

  return cube;
}
//var box=draw_cube(100,100,100,0x008000);
//scene.add(box);

例如:http://softsrc.cc (请用Firefox,Chrome,Opera,Edge浏览器查看)

分享到:
(转载→)