简体   繁体   English

三个粒子.js

[英]Particles in three.js

Can someone kindly explain me why there are no particles visible in the following code? 有人可以向我解释为什么下面的代码中没有可见的粒子? Followed a tutorial and everything seems ok. 按照教程,一切似乎都没问题。

(function() {

var camera, scene, renderer;

init();
animate();

function init() {

    scene = new THREE.Scene();
    var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
    var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
    camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
    scene.add(camera);
    camera.position.set(2,2,10);
    camera.lookAt(scene.position);
    console.log(scene.position);

    var geometry = new THREE.CubeGeometry(1,1,1);
    var material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
    var cube = new THREE.Mesh( geometry, material );
    scene.add( cube );

    var pGeometry = new THREE.Geometry();
    for (var p = 0; p < 2000; p++) {
        var particle = new THREE.Vector3(Math.random() * 50 - 25, Math.random() * 50 - 25, Math.random() * 50 - 25);
        pGeometry.vertices.push(particle);
    }
    var pMaterial = new THREE.ParticleBasicMaterial({ color: 0xfff, size: 1 });
    var pSystem = new THREE.ParticleSystem(pGeometry, pMaterial);
    scene.add(pSystem);

    renderer = new THREE.CanvasRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);

    document.body.appendChild(renderer.domElement);

}

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

}

})();

fiddle 小提琴

CanvasRenderer does not support ParticleSystem . CanvasRenderer不支持ParticleSystem You need to use WebGLRenderer . 您需要使用WebGLRenderer

If you need to use CanvasRenderer , then see http://threejs./examples/canvas_interactive_particles.html for how to use Sprites instead. 如果您需要使用CanvasRenderer ,请参阅http://threejs./examples/canvas_interactive_particles.html以了解如何使用Sprites

three.js r.64 three.js r.64

Also, as a side note, as of the time of this answer, IE11's WebGL implementation has an issue with points and sizing them. 此外,作为旁注,截至本回答时,IE11的WebGL实现存在点数和大小问题。 Particles in Three.js shaders use points to draw the particles and so in IE11, you will see very small squares and if you're not paying attention, you might not see anything at all ;) Three.js着色器中的粒子使用点来绘制粒子,因此在IE11中,您将看到非常小的正方形,如果您没有注意,您可能根本看不到任何东西;)

I do know that in the next version of IE (updates coming) that this is fixed and allows you not only to change the point size, but use bitmaps with them. 我知道在下一版本的IE(更新即将发布)中,这是固定的,不仅可以更改点大小,还可以使用位图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM