@nkduy/scenejs
v1.2.1
Published
Particle effect renderer based on three.js and the Minecraft Bedrock particle format
Downloads
2
Readme
SceneJS
Particle effect renderer based on three.js and the Minecraft Bedrock particle format.
Installation
npm i scenejs
Usage
This is the simplest possible implementation of a SceneJS emitter into your scene
// Import scenejs
import SceneJS from "scenejs";
// Load JSON File
import RainbowParticle from "./rainbow.particle.json";
// Setup SceneJS Scene
const scenejs_scene = new SceneJS.Scene();
// Setup Emitter
const emitter = new SceneJS.Emitter(scenejs_scene, RainbowParticle);
// Add emitter into Three.JS scene
threejs_scene.add(scenejs_scene.space);
// Play Effect
emitter.playLoop();
// Update particle rotation in your app's rendering loop
scenejs_scene.updateFacingRotation(camera);Development
npm i: Install dependenciesnpm run watch: Activate compilernpm run build: Build for production
API
Scene
new SceneJS.Scene(options?)
Creates a new scene, which can hold multiple emitters
options: Object:fetchTexture: Function
Properties
emitters: ArrayList of all emittersspace: three.js Object3DGlobal particle space. Add this to your three.js scene.global_options: Objectmax_emitter_particles: NumberMaximum amount of particles per emittertick_rate: NumberEmitter tick rate per second.loop_mode: StringDefault emitter loop modeparent_mode: StringDefault emitter parent modescale: NumberEmitter scale. The default is 1 for block space. Set to 16 to run in a pixel space environment like Pixel Studio.
SceneJSScene#updateFacingRotation(camera)
Updates the particle facing rotation for all emitters
camera: Camerathree.js camera to orient the particle towards
SceneJSScene#fetchTexture( config )
Method to provide visuals for a texture. Null by default. Gets called by configs if the texture is updated. Should return a data URL, or a promise resulting in a data URL.
config: ConfigParticle config that is requesting the texture
Emitter
new SceneJS.Emitter(scene, config?, options?)
Creates a new particle emitter
scene: SceneJS Scene: SceneJS scene to add this emitter toconfig: Config: Config instancescene: Scene: SceneJS Sceneoptions: Object:loop_mode: StringHow the emitter loops:auto,onceorlooping. Default:autoloop_mode: StringHow the emitter is located in the world:world,entityorlocator. Default:world
Emitter#updateFacingRotation(camera)
Updates the particle facing rotation
camera: Camerathree.js camera to orient the particle towards
Emitter#delete()
Deletes the emitter
Default Playback Loop
Emitter#playLoop()
Starts to play the particle effect using the default play loop
Emitter#toggleLoop()
Pause/resume the default playback loop
Emitter#stopLoop()
Stops the default playback loop
Control Emitter
Emitter#start()
Starts the emitter, setting the time to 0 and initializing all variables
Emitter#tick()
Runs an emitter tick
Emitter#stop(clear_particles)
Stops the emitter
Emitter#jumpTo(second)
Jumps to a specific time in the emitter. This is optimited to run as few operations as possible so you can use it to hook the emitter to a custom playback loop
Config
Configs store the configuration of an emitter. All emitters have a config by default.
new SceneJS.Config(scene, config, options)
Creates a new emitter config instance
scene: SceneJS Scene: SceneJS sceneconfig: Config: Config instanceoptions: Object:path: StringLocation of the particle file that the config is based on.
Config#reset()
Resets the config to default values
Config#set(key, value)
Sets a property of the config to a specific value
key: StringKey of the value to changevalue: AnyValue to set
Config#setFromJSON(data)
Loads the configuration from a JSON particle file
json: ObjectParticle file content
Config#onTextureUpdate()
Method that runs when the texture of the config is updated. Null by default
