欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

threejs 裁剪

程序员文章站 2022-05-26 19:45:56
...

设置渲染器中的localClippingEnabled为true,即

renderer.localClippingEnabled = true;//设置为可剪裁

对于模型的material,如

let material = new THREE.MeshLambertMaterial(
				{
						color: colorToHex(meshData.Color[0]),
						flatShading: THREE.SmoothShading,
						clippingPlanes: clipPlanes,//裁剪
				});

clipPlanes可以理解为裁剪面,当clipPlanes中的constant的值,在模型的包围盒的范围内时,则发生裁剪

var clipPlanes= [
  new THREE.Plane( new THREE.Vector3( 1, 0, 0 ), 100 ),
  new THREE.Plane( new THREE.Vector3( 0, 1, 0 ), 100 ),
	new THREE.Plane( new THREE.Vector3( 0, 0, 1 ), 100 ),
	
  new THREE.Plane( new THREE.Vector3( -1, 0, 0 ), 100 ),
  new THREE.Plane( new THREE.Vector3( 0, -1, 0 ), 100 ),
  new THREE.Plane( new THREE.Vector3( 0, 0, -1 ), 100 ),
];
function clip(type,value){
	clipPlanes.map((n,i)=>{
		if(i==type){
			n.constant=value
		}
		
	})
	//clipPlanes[ j ].constant = value;
}

效果:

threejs 裁剪     threejs 裁剪

 

 

相关标签: threejs