fenomas / noa

Experimental voxel game engine.
MIT License
616 stars 91 forks source link

how do we add particle system to hello world example #77

Closed levlups closed 5 years ago

levlups commented 5 years ago

I tried to added but it doesnt work var makeParticles = require('./lib/particles') getting this error: Module not found: Error: Can't resolve './lib/particles'

fenomas commented 5 years ago

There's no particle code in noa. The old demo project that code came from is here, and the particles lib it used is here. I later made it its own library, but there may be better particle systems somewhere in the BabylonJS community.

itzTheMeow commented 3 years ago

I can't seem to get mesh-particle-system working. code:

import MPS from "./mesh-particle-system.js";
import { Texture } from "../../noalib/node_modules/@babylonjs/core/Materials/Textures/texture";
var tex = new Texture("img/blocks/stone.png", scene);
var capacity = 200;
var rate = 30; // particles/second
var mps = new MPS(capacity, rate, scene);
mps.setTexture(tex);
mps.mesh.position.x = 0;
mps.mesh.position.y = 0;
mps.mesh.position.z = 0;

this is run when a block is broken

mps.setMeshPosition(pos[0], pos[1], pos[2]);
    mps.start();
fenomas commented 3 years ago

Hi, unfortunately the mesh-particle-system library was written back before Babylon had module exports. So it assumes that the BABYLON object will be in global scope. You could probably use it that way if you try, but I believe that nowadays Babylon has several built-in ways of doing particles, so it would probably be easier to use those.

The only caveat is, any time you add your own mesh (e.g. the mesh for a particle system) to the Babylon scene, you'll need to call noa.rendering.addMeshToScene. This is because noa uses octrees to make scene mesh selection faster, and all new meshes need to be added to the octree somewhere.

itzTheMeow commented 3 years ago

i did put the object in global scope, but i changed the library to import everything mesh-particle-system.txt

fenomas commented 3 years ago

In that case it should work, as long as you add:

noa.rendering.addMeshToScene(mps.mesh)

Or at least, it worked for me in a quick test. But Babylon did have some breaking changes in 4.0, so it's possible that it may not fully work.

itzTheMeow commented 3 years ago

here? image

itzTheMeow commented 3 years ago

renders at 0,0,0 changing a few things, thanks