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

BufferGeometry.copy() 方法用于将一个 BufferGeometry 对象的数据复制到另一个 BufferGeometry 对象里。

语法

bufferGeometry.copy(source);

参数

  • source:一个 BufferGeometry 对象,数据将从它复制过来。

描述

使用 BufferGeometry.copy() 方法可以在不改变原有 BufferGeometry 对象的情况下,复制其数据到一个新的 BufferGeometry 对象中。这个新的 BufferGeometry 对象可以拥有与原对象相同的顶点坐标、法向量、颜色等属性,同时也可以添加新的属性。

值得注意的是, BufferGeometry.copy() 方法只复制属性数据,不复制材质数据,即它并不会把原有 BufferGeometry 对象的材质信息也复制到新对象中。

示例

const sourceGeometry = new THREE.BufferGeometry();
const vertices = new Float32Array([0, 0, 0, 1, 0, 0, 0, 1, 0]);
const colors = new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
sourceGeometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
sourceGeometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));

const targetGeometry = new THREE.BufferGeometry();
targetGeometry.copy(sourceGeometry);

console.log(targetGeometry.attributes.position.array); // [0, 0, 0, 1, 0, 0, 0, 1, 0]
console.log(targetGeometry.attributes.color.array); // [1, 0, 0, 0, 1, 0, 0, 0, 1]

参考链接