解答:將 createCapsule 函數的 sphGeom 替換為:
var capsule = new THREE.Object3D();
capsule.add( cyl );
if ( !openTop || !openBottom ) {
// instance geometry
var sphGeom = new THREE.SphereGeometry( radius, segmentsWidth, segmentsWidth/2 );
if ( !openTop ) {
var sphTop = new THREE.Mesh( sphGeom, material );
sphTop.position.set( top.x, top.y, top.z );
capsule.add( sphTop );
}
if ( !openBottom ) {
var sphBottom = new THREE.Mesh( sphGeom, material );
sphBottom.position.set( bottom.x, bottom.y, bottom.z );
capsule.add( sphBottom );
}
}
return capsule;