如何更改Three.js自行车的厚度

时间:2018-08-08 11:09:58

标签: javascript three.js

如果我有一个像JSFiddle中那样使用three.js制作的基本空心单车,如何更改墙的厚度?

var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 95, window.innerWidth / window.innerHeight, 0.1, 1000 );

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

var geometry = new THREE.CylinderGeometry( 2, 2, 5, 360, 1, true );
var material = new THREE.MeshNormalMaterial( { color: 0x00ff00, side: THREE.DoubleSide } );
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );

camera.position.y = 5;
camera.position.z = 5;
camera.lookAt(0,0,0);

function animate() {
    requestAnimationFrame( animate );
    renderer.render( scene, camera );
}
animate();

JSFiddle example

1 个答案:

答案 0 :(得分:2)

否,您必须从一个圆柱中减去另一个圆柱。从中减去的是圆柱的内径。

所以我将您的代码更改为此:

var outerGeometry = new THREE.CylinderGeometry(2, 2, 5, 360, 1);
var innerGeometry = new THREE.CylinderGeometry(1.5, 1.5, 5, 360, 1);
var material = new THREE.MeshNormalMaterial({
    color: 0x00ff00,
    side: THREE.DoubleSide
});

var outerCylinder = new ThreeBSP(outerGeometry);
var innerCylinder = new ThreeBSP(innerGeometry);

var hollowedCylinder = innerCylinder.union(outerCylinder);

scene.add(hollowedCylinder.toMesh(material));

这是小提琴: http://jsfiddle.net/gerdonabbink/tephoLr1/133/

您可以看到内圆柱为1.5,例如将其更改为1以使厚度为1。