gpt4 book ai didi

javascript - 在 Three.JS 粒子系统中移动单个粒子

转载 作者:行者123 更新时间:2023-11-30 17:30:35 25 4
gpt4 key购买 nike

Three.js 遇到了一些问题。我目前正在尝试在渲染每一帧时在粒子系统内移动粒子。没有报告错误,但也没有任何移动!我从 http://aerotwist.com/tutorials/creating-particles-with-three-js/ 的代码中获取的示例使用语法 particle.position.y,但是当我更改以下代码以反射(reflect)该语法时,JS 控制台返回 Cannot set property 'y' of undefined。非常感谢任何关于我哪里出错的帮助或指示。

完整源代码:

        var scene, camera, renderer, particleCount = 0, particleSystem, particles;

init();
animate();

function init()
{
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
scene.add(camera);
camera.position.z = 5;

renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

particleCount = 1800,
particles = new THREE.Geometry();
var pMaterial = new THREE.ParticleBasicMaterial({color: 0xFFFFFF, size: 0.5});

for (var i = 0; i < particleCount; i++)
{
var pX = Math.random() * 500 - 250,
pY = Math.random() * 500 - 250,
pZ = Math.random() * 500 - 250,
particle = new THREE.Vector3(pX, pY, pZ);

particles.vertices.push(particle);
}

particleSystem = new THREE.ParticleSystem(particles, pMaterial);
scene.add(particleSystem);
}

function animate()
{
requestAnimationFrame(animate);
renderer.render(scene, camera);

var pCount = particleCount;
while (pCount--)
{
var particle = particles.vertices[pCount];
particle.y = Math.random() * 500 - 250;
particleSystem.geometry.vertices.needsUpdate = true;
}

}

最佳答案

看起来您必须在创建 particleSystem 之后添加 particleSystem.sortParticles = true;

关于javascript - 在 Three.JS 粒子系统中移动单个粒子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23155443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com