BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

BufferGeometry.setDrawRange()

setDrawRange(start: number, count: number): void

BufferGeometry.setDrawRange() 方法用于设置网格绘制范围。仅绘制给定范围中的网格,而不绘制其他顶点或面。这个方法只是一种用于优化绘制的手段,可以指定需要绘制的网格的范围,在避免绘制不必要的网格的同时提高WebGL渲染性能。

参数

start - 从Geometry/BufferGeometry的哪个位置开始绘制。默认值为0.

count - 绘制多少个三角形或三角形带. 默认值为Infinity.

示例

下面的例子演示了如何使用setDrawRange()方法来调整模型绘制的范围:

const geometry = new THREE.BoxBufferGeometry(2, 2, 2);
const material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
const mesh = new THREE.Mesh(geometry, material);

scene.add(mesh);

// 设置绘制范围,从第一个面开始绘制,只绘制前6个面
geometry.setDrawRange(0, 6);

注意事项

  • setDrawRange()方法仅适用于实例化(instanced)网格的绘制范围,对其他WebGL渲染操作无影响。

  • setDrawRange()方法不应与Geometry/BufferGeometry剪辑(clipping),矩阵变换或相机近裁剪面(camera near clipping plane)混淆。这些操作并没有减少要绘制的网格数量,而只是通过转换或剪裁逐渐逼近渲染器。

参考文献