overte/examples/ajt-test.js
Anthony Thibault b3af515224 Particle entity improvements based on code review.
* Updated variable naming to match coding standards.
* Changed particle raw float arrays to vectors.
* Bug fix: changing maxParticles will no longer lead to memory corruption.
* Made particle ring buffer more explicit, added _particleTailIndex.
* Added getLivingParticleCount() private method.
* Moved integration and bounds code into private methods.
* Bug fix: high emit rates now properly integrate particles forward for the
  remaing frame time, not the entire frame.
* Bug fix: new particles were not initiaized to origin.
* Added more particles to ajt-test.js.
* Bug fix: ajt-test.js script was not shutting down properly.
* Removed random seed, unless we have a psudo random number generator per
  particle system instance, it's unlikely that this will preserve sync.
* Bumped packet version number.
2015-05-11 19:21:33 -07:00

93 lines
3.7 KiB
JavaScript

(function () {
var spawnPoint = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation())));
// constructor
function TestBox() {
this.entity = Entities.addEntity({ type: "Box",
position: spawnPoint,
dimentions: { x: 1, y: 1, z: 1 },
color: { red: 100, green: 100, blue: 255 },
gravity: { x: 0, y: 0, z: 0 },
visible: true,
locked: false,
lifetime: 6000 });
var self = this;
this.timer = Script.setInterval(function () {
var colorProp = { color: { red: Math.random() * 255,
green: Math.random() * 255,
blue: Math.random() * 255 } };
Entities.editEntity(self.entity, colorProp);
}, 1000);
}
TestBox.prototype.Destroy = function () {
Script.clearInterval(this.timer);
Entities.editEntity(this.entity, { locked: false });
Entities.deleteEntity(this.entity);
}
// constructor
function TestFx(color, emitDirection, emitRate, emitStrength, blinkRate) {
var animationSettings = JSON.stringify({ fps: 30,
frameIndex: 0,
running: true,
firstFrame: 0,
lastFrame: 30,
loop: true });
this.entity = Entities.addEntity({ type: "ParticleEffect",
animationSettings: animationSettings,
position: spawnPoint,
textures: "http://www.hyperlogic.org/images/particle.png",
emitRate: emitRate,
emitStrength: emitStrength,
emitDirection: emitDirection,
color: color,
visible: true,
locked: false });
this.isPlaying = true;
var self = this;
this.timer = Script.setInterval(function () {
// flip is playing state
self.isPlaying = !self.isPlaying;
var animProp = { animationIsPlaying: self.isPlaying };
Entities.editEntity(self.entity, animProp);
}, (1 / blinkRate) * 1000);
}
TestFx.prototype.Destroy = function () {
Script.clearInterval(this.timer);
Entities.editEntity(this.entity, { locked: false });
Entities.deleteEntity(this.entity);
}
var objs = [];
function Init() {
objs.push(new TestBox());
objs.push(new TestFx({ red: 255, blue: 0, green: 0 },
{ x: 0.5, y: 1.0, z: 0.0 },
100, 3, 1));
objs.push(new TestFx({ red: 0, blue: 255, green: 0 },
{ x: 0, y: 1, z: 0 },
1000, 5, 0.5));
objs.push(new TestFx({ red: 0, blue: 0, green: 255 },
{ x: -0.5, y: 1, z: 0 },
100, 3, 1));
}
function ShutDown() {
var i, len = objs.length;
for (i = 0; i < len; i++) {
objs[i].Destroy();
}
objs = [];
}
Init();
Script.scriptEnding.connect(ShutDown);
})();