概述
问题
- 视频中讲解的
SphereBufferGeometry 对象没有找到;使用SphereGeometry代替SphereBufferGeometry发现题图有为题。本意贴图到创建的粒子上但贴到整个物体上。
- 设置缓冲几何体的位置和颜色在
BufferGeometry实例对象上
设置位置
particlesGeometry.setAttribute('position', new BufferAttribute(positions, 3))
设置颜色
particlesGeometry.setAttribute('color', new BufferAttribute(colors, 3))
- 创建材质时使用
PointsMaterial()函数
const pointsMateial = new PointsMaterial()
- 创建粒子集合体使用
Points()函数
const points = new Points(particlesGeometry, pointsMaterial)
- 点材质的属性
- size 设置点的大小
- sizeAttenuation 设置点的大小是否因相机深度而衰减,默认为true(大概理解为近大远小)
- vertexColors 设置启动顶点颜色(设置完材质颜色后,要配合这个属性使用否则不生效)
function selfGeometry() {
const particlesGeometry = new BufferGeometry()
const count = 5000
const positions = new Float32Array(count * 3)
const colors = new Float32Array(count * 3)
for (let i = 0; i < count * 3; i++) {
positions[i] = (Math.random() - 0.5) * 100
colors[i] = Math.random()
}
particlesGeometry.setAttribute('position', new BufferAttribute(positions, 3))
particlesGeometry.setAttribute('color', new BufferAttribute(colors, 3))
const pointsMaterial = new PointsMaterial()
pointsMaterial.size = 0.5
pointsMaterial.sizeAttenuation = true
pointsMaterial.vertexColors = true
const points = new Points(particlesGeometry, pointsMaterial)
return points
}