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.getIndex()

概述

BufferGeometry.getIndex() 方法返回一个整数数组,其中包含用于渲染几何体的三角形索引。如果未使用索引,则返回null

语法

BufferGeometry.getIndex()

返回值

返回一个 BufferAttribute 类型的对象,其中包含三角形索引的整数数组。如果未使用索引,则返回null

用法

const geometry = new THREE.BufferGeometry();

// 设置几何体的顶点、法线和 uvs 属性

const indices = [0, 1, 2, 2, 1, 3, 4, 5, 6, 6, 5, 7];

const indexAttribute = new THREE.Uint16BufferAttribute(indices, 1);

geometry.setIndex(indexAttribute);

const indexArray = geometry.getIndex().array;

console.log(indexArray);

上述代码将创建一个BufferGeometry对象,并将一个包含3个和4个顶点的两个三角形的索引数组赋值给几何体的索引属性,然后通过getIndex()方法获取这个整数数组并打印出来。

注意事项

如果没有使用索引就尝试调用getIndex()方法,将会返回null

BufferGeometry 的顶点索引可以由 THREE.Uint8BufferAttributeTHREE.Uint16BufferAttributeTHREE.Uint32BufferAttribute 类型的对象表示。

参考文献