-- Leo's gemini proxy
-- Connecting to git.thebackupbox.net:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
repo: janusweb action: commit revision: path_from: revision_from: 8b24ea3302553f67eea367f5cfc9a05149685398: path_to: revision_to:
commit 8b24ea3302553f67eea367f5cfc9a05149685398 Author: James Baicoianu <james_github@baicoianu.com> Date: Wed Sep 14 08:46:58 2016 -0700 Added particle object support diff --git a/media/tests/particles.html b/media/tests/particles.html new file mode 100644 index 0000000000000000000000000000000000000000..792af54bcb2b65180183f06fc53c3b69340495fa --- /dev/null +++ b/media/tests/particles.html @@ -0,0 +1,17 @@ +<FireBoxRoom> + <Assets> + <AssetImage id="water_particle" src="images/water2.png" /> + <AssetImage id="water_particle2" src="http://www.janusvr.com/newlobby/images/water3.png" tex_compress="true" /> + </Assets> + <Room> + <!-- Particle pos="0 1 5" count="5" rand_pos="1 1 1" col="1 0 0" loop="true" / --> + +<Particle pos="-.11 4.09 -.88" scale=".111 .11 .11" vel="-.5 0 -1.2" accel="0 -9.8 0" rate="100" count="200" lighting="false" image_id="water_particle" duration="1" fade_in="0.1" fade_out="0.1" loop="true" rand_pos=".25 0.1 0" rand_vel="1 0 -.5" rand_accel="0 0.5 0" col="0.8 0.8 1 0.5" rand_col="0 0 0.3" blend_src="src_alpha" blend_dest="one" /> +<Particle pos="-.11 4.09 .9" scale=".11 .08 .08" vel="-.5 0 1.2" accel="0 -9.8 0" rate="100" count="200" lighting="false" image_id="water_particle" duration="1" fade_in="0.1" fade_out="0.1" loop="true" rand_pos=".25 0.1 0" rand_vel="1 0 .5" rand_accel="0 0.5 0" col="0.8 0.8 1 0.5" rand_col="0 0 0.3" blend_src="src_alpha" blend_dest="one" /> +<Particle pos="-.11 4.09 -.91" scale=".111 .11 .11" vel="-.5 0 -1.2" accel="0 -9.8 0" rate="100" count="200" lighting="false" image_id="water_particle2" duration="1" fade_in="0.2" fade_out="0.2" loop="true" rand_pos=".25 0.1 0" rand_vel="1 0 -.5" rand_accel="0 0.5 0" col="0.8 0.8 1 0.5" rand_col="0 0 0.3" blend_src="src_alpha" blend_dest="one" /> +<Particle pos="-.11 4.09 .92" scale=".11 .09 .09" vel="-.5 0 1.2" accel="0 -9.8 0" rate="100" count="200" lighting="false" image_id="water_particle2" duration="1" fade_in="0.2" fade_out="0.2" loop="true" rand_pos=".25 0.1 0" rand_vel="1 0 .5" rand_accel="0 0.5 0" col="0.8 0.8 1 0.5" rand_col="0 0 0.3" blend_src="src_alpha" blend_dest="one" /> + + + </Room> +</FireBoxRoom> + diff --git a/scripts/janusparticle.js b/scripts/janusparticle.js new file mode 100644 index 0000000000000000000000000000000000000000..8083ae209dc7593303d05f174a135f3673a0c914 --- /dev/null +++ b/scripts/janusparticle.js @@ -0,0 +1,177 @@ +elation.require(['janusweb.janusbase'], function() { + elation.component.add('engine.things.janusparticle', function() { + this.postinit = function() { + elation.engine.things.janusparticle.extendclass.postinit.call(this); + this.defineProperties({ + image_id: { type: 'string', set: this.updateMaterial }, + rate: { type: 'float', default: 1 }, + count: { type: 'int', default: 0 }, + duration: { type: 'float', default: 1.0 }, + fade_in: { type: 'float', default: 1.0 }, + fade_out: { type: 'float', default: 1.0 }, + duration: { type: 'float', default: 1.0 }, + particle_scale: { type: 'vector3', default: [1, 1, 1]}, + particle_vel: { type: 'vector3', default: [0, 0, 0]}, + particle_accel: { type: 'vector3', default: [0, 0, 0]}, + rand_pos: { type: 'vector3', default: [0, 0, 0]}, + rand_vel: { type: 'vector3', default: [0, 0, 0]}, + rand_accel: { type: 'vector3', default: [0, 0, 0]}, + rand_col: { type: 'vector3', default: [0, 0, 0]}, + rand_scale: { type: 'vector3', default: [0, 0, 0]}, + loop: { type: 'bool', default: false }, + }); + this.particles = []; + this.emitted = 0; + this.currentpoint = 0; + this.lasttime = 0; + elation.events.add(this.engine, 'engine_frame', elation.bind(this, this.updateParticles)); + } + this.createObject3D = function() { + var geo = this.geometry = new THREE.Geometry() + + this.createParticles(); + + var texture = null; + if (this.image_id) { + texture = elation.engine.assets.find('image', this.image_id); + //elation.events.add(texture, 'asset_load', elation.bind(this, this.assignTextures)); + elation.events.add(texture, 'update', elation.bind(this, this.refresh)); + } + + var mat = new THREE.PointsMaterial({color: this.color, map: texture, size: this.particle_scale.x, transparent: true, alphaTest: 0.05}); + this.scale.set(1,1,1); + var obj = new THREE.Points(geo, mat); + return obj; + } + this.createForces = function() { + this.velocity.set(0,0,0); // FIXME - hack to override "vel" property mapping + } + this.createParticles = function() { + this.particles = []; + + var count = this.count; + for (var i = 0; i < count; i++) { + var point = this.createPoint(); + this.resetPoint(point); + + this.geometry.vertices[i] = point.pos; + this.particles[i] = point; + } + if (this.geometry.vertices.length > count) { + this.geometry.vertices.splice(count) + } + this.emitted = 0; + this.currentpoint = 0; + this.lasttime = performance.now(); + } + this.updateParticles = function(ev) { + //console.log('go!', ev); + //this.physics.step(ev.data.delta); +//console.log('pdate', this.particles[0].toArray()); + + var now = performance.now(), + elapsed = now - this.lasttime, + endtime = now + this.duration * 1000, + emitted = 0, + startpoint = this.currentpoint; + spawncount = this.rate * elapsed / 1000; + count = this.count, + loop = this.loop; + +//console.log('derp', elapsed, spawncount, count, this.particles.length); + if (count != this.particles.length) { + ths.createParticles(); + } + for (var i = 0; i < count; i++) { + var idx = (i + startpoint) % this.count; + var p = this.particles[idx]; + if (p.active == 1) { + this.updatePoint(p, elapsed/1000); + if (now > p.endtime) { + p.active = (loop ? 0 : 2); + } + + } else if (p.active == 0) { + if (spawncount > emitted) { + this.resetPoint(p); + p.starttime = now; + p.endtime = endtime; + p.active = 1; + emitted++; + this.currentpoint = (this.currentpoint + 1) % this.count; + } + } + } + this.lasttime = now; +/* + // FIXME - this is wrong but works for fast spawns + var numtospawn = Math.ceil(this.rate * ev.data.delta); + for (var i = 0; i < numtospawn; i++) { + var point = this.particles[this.currentpoint]; + this.resetPoint(point); + this.currentpoint = (this.currentpoint + 1) % this.count; + } +*/ + + this.objects['3d'].geometry.verticesNeedUpdate = true; + this.objects['3d'].geometry.computeBoundingSphere(); + this.refresh(); + } + this.createPoint = function() { + return { + pos: new THREE.Vector3(0, 0, 0), + vel: new THREE.Vector3(0, 0, 0), + accel: new THREE.Vector3(0, 0, 0), + scale: new THREE.Vector3(1,1,1), + color: new THREE.Color(255, 255, 255), + active: 0, + start: 0, + end: 0 + }; + } + this.updatePoint = function(point, delta) { + point.vel.x += point.accel.x * delta; + point.vel.y += point.accel.y * delta; + point.vel.z += point.accel.z * delta; + + point.pos.x += point.vel.x * delta; + point.pos.y += point.vel.y * delta; + point.pos.z += point.vel.z * delta; + } + this.resetPoint = function(point) { + point.pos.x = Math.random() * this.rand_pos.x; + point.pos.y = Math.random() * this.rand_pos.y; + point.pos.z = Math.random() * this.rand_pos.z; + + var vel = point.vel, + accel = point.accel, + rand_vel = this.properties.rand_vel, + rand_accel = this.properties.rand_accel; + + vel.copy(this.properties.particle_vel); + accel.copy(this.properties.particle_accel); + + if (rand_vel.lengthSq() > 0) { + vel.x += rand_vel.x * Math.random(); + vel.y += rand_vel.y * Math.random(); + vel.z += rand_vel.z * Math.random(); + } + if (rand_accel.lengthSq() > 0) { + accel.x += rand_accel.x * Math.random(); + accel.y += rand_accel.y * Math.random(); + accel.z += rand_accel.z * Math.random(); + } + } + this.getProxyObject = function() { + var proxy = elation.engine.things.janusparticle.extendclass.getProxyObject.call(this); + proxy._proxydefs = { + vel: [ 'property', 'particle_vel'], + accel: [ 'property', 'particle_accel'], + rand_pos: [ 'property', 'rand_pos'], + rand_vel: [ 'property', 'rand_vel'], + rand_accel: [ 'property', 'rand_accel'], + }; + return proxy; + } + }, elation.engine.things.janusbase); +});
-----END OF PAGE-----
-- Response ended
-- Page fetched on Sun Jun 2 16:30:41 2024