我需要使用ThreeJS隐藏框原语中显示的边。这些仅在我在面上放置纹理时绘制。
我尝试过很多选项,比如wireframe = false,但仍然会绘制边缘。
这是代码:
var container, stats;
var camera, scene, renderer;
var canvasWidth = 500;
var canvasHeight = 500;
var windowHalfX = 100;
var windowHalfY = 100;
container = document.createElement( 'div' );
document.body.appendChild( container );
// Camera
camera = new THREE.OrthographicCamera( canvasWidth / - 2, canvasWidth / 2, canvasHeight / 2, canvasHeight / - 2, - 500, 5000 );
// Scene
scene = new THREE.Scene();
camera.position.x = 200;
camera.position.y = 200;
camera.position.z = 200;
camera.lookAt( scene.position );
// Renderer
renderer = new THREE.CanvasRenderer();
renderer.setClearColor( "#fff" );
renderer.setSize( canvasWidth, canvasHeight );
container.appendChild( renderer.domElement );
var size = 100;
geometry = new THREE.BoxGeometry( size, size, size );
material = new THREE.MeshBasicMaterial({
color: "#0000ff",
side: THREE.DoubleSide,
wireframe: false
});
// Comment this line to paint a single color cube
material = new THREE.MeshLambertMaterial({ map: THREE.ImageUtils.loadTexture("http://upload.wikimedia.org/wikipedia/commons/8/81/Color_icon_black.png") });
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
var draw = function() {
requestAnimationFrame( draw );
renderer.render( scene, camera );
}
draw();
以及示例的链接:
http://jsfiddle.net/gyss/qg4x9/
干杯!
答案 0 :(得分:0)
我已经解决了改变这一行的问题
renderer = new THREE.CanvasRenderer();
对于其他
renderer = new THREE.WebGLRenderer();
其他可能的解决方案,正如WestLangley上面评论的那样,将这一行与CanvasRenderer一起使用
material.overdraw = 0.5; // or some number between 0 and 1
答案 1 :(得分:0)
使用renderer = new THREE.CanvasRenderer();
时
要删除边,需要将参数(overdraw:true
)添加到材质定义中,如下所示:
var material = new THREE.MeshBasicMaterial( { map: texture, overdraw: true } );
然后您可以使用将材质添加到3D对象:
mesh = new THREE.MeshBasicMaterial( geometry, material );