我是three.js的新手,正在建造一个太阳系,我需要一个粒子系统,其中的粒子是二十面体。我使用这个函数从教程中创建了一个粒子系统:
function createParticleSystem() {
// The number of particles in a particle system is not easily changed.
var particleCount = 2000;
// Particles are just individual vertices in a geometry
// Create the geometry that will hold all of the vertices
var particles = new THREE.IcosahedronGeometry(1, 0);
// Create the vertices and add them to the particles geometry
for (var p = 0; p < particleCount; p++) {
// This will create all the vertices in a range of -200 to 200 in all directions
var x = Math.random() * 400 - 200;
var y = Math.random() * 400 - 200;
var z = Math.random() * 400 - 200;
// Create the vertex
var particle = new THREE.Vector3(x, y, z);
// Add the vertex to the geometry
particles.vertices.push(particle);
}
// Create the material that will be used to render each vertex of the geometry
var particleMaterial = new THREE.PointsMaterial(
{color: 0xffffff,
size: 4,
shading: THREE.FlatShading,
blending: THREE.AdditiveBlending,
transparent: true,
});
var partMaterial2 = new THREE.MeshPhongMaterial({ color: 0xffffff, shading: THREE.FlatShading, vertexColors: THREE.VertexColors, shininess: 0 } );
// Create the particle system
particleSystem = new THREE.Points(particles, particleMaterial);
return particleSystem;
}
这会在不同的位置创建粒子,但是虽然我将几何体设置为THREE.IcosahedronGeometry
并尝试更改材质,但我唯一能够创建的是平白色方块。如果我将材质更改为MeshPhongMaterial
,就像我之前使用的那样,我的场景将无法渲染。
如何制作二十面体颗粒?
答案 0 :(得分:0)
(我意识到这已经晚了。)IcosahedronGeometry有顶点,但你通常不会单独设置它们。您可以设置点和线的顶点。我认为其他一切都是网状的。 (我希望别人有更好的措辞。)
要做点:
geometry = new THREE.Geometry();
material = new THREE.PointsMaterial( { color:0xffffff, size:1 } );
geometry.vertices.push( // your points get pushed
var object3d = new THREE.Points(geometry, material);
scene.add(object3d);
要做分段:
geometry = new THREE.Geometry();
geometry.vertices.push( // your line ends get pushed
material = new THREE.LineBasicMaterial( { color:0xffffff } );
object3d = new THREE.Line(geometry, material);
scene.add(object3d);
做二十面体或任何网格:
for (var i1=0; i1<N; i1+=1) {
geometry = new THREE.IcosahedronGeometry(1);
material = new THREE.MeshPhongMaterial( { color:0xffffff, shading:THREE.FlatShading } );
material.side = THREE.DoubleSide;
mesh= new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
scene.add(mesh);
}