【问题标题】:How fill a sphere with random particles in three.js如何在three.js中用随机粒子填充球体
【发布时间】:2015-12-09 00:40:12
【问题描述】:

我阅读了关于用粒子随机填充球体的表面的优秀问题:How to make a sphere made out of random particles in three.js。如何用随机生成的粒子填充球体的总体积?我试试看:

var particleCount = 1800,
  particles = new THREE.Geometry(),

  pMaterial = new THREE.PointCloudMaterial({
    color: 0xFFFFFF,
    size: 20,
    map: THREE.ImageUtils.loadTexture(
      "images/particle.png"
    ),
    blending: THREE.AdditiveBlending,
    transparent: true
  });

for (var t = 0; t < particleCount; t++) {
  var angle3 = Math.random() * Math.PI * 2;
  var radius3 = Math.random() * 350 + 1;
  var pX1 = Math.cos(angle3) * radius3,
    pY1 = Math.random() * 70 - 35,
    pZ1 = Math.sin(angle3) * radius3,
    skparticle11 = new THREE.Vector3(pX1, pY1, pZ1);
  particles.vertices.push(skparticle11);
}

var particleSystem = new THREE.PointCloud(
  particles,
  pMaterial);

// add it to the scene
scene.add(particleSystem);

但我只得到一个磁盘。如何制作一个充满粒子的球体?

【问题讨论】:

标签: three.js


【解决方案1】:

一个角度是不够的,这就是为什么你得到一个圆盘

创建一个随机法线向量

var randomDirection = new THREE.Vector3(Math.random()-0.5,Math.random()-0.5,Math.random()-0.5).normalize();

像以前一样创建随机距离

var radius3 = Math.random() * 350 + 1;

原点周围球体中的一个随机点将是

var randomParticle = randomDirection.multiplyScalar(radius3);

为了更好的分布,使用比 Math.random 更好的生成器

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-17
    • 1970-01-01
    • 1970-01-01
    • 2012-12-23
    • 2014-01-26
    • 2016-08-15
    • 1970-01-01
    • 2012-06-28
    相关资源
    最近更新 更多