content/hifi-content/alan/dev/Scripts/Smoke-Column-1.js
2022-02-13 20:41:08 +01:00

92 lines
3.8 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: 255, green: 255, blue: 255 },
gravity: { x: 0, y: 0, z: 0 },
visible: true,
locked: false,
lifetime: 3000 });
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,
dimensions: {x: 2, y: 2, z: 2},
emitVelocity: {x: 0, y: 0.001, z: 0},
emitRate: 25,
particleRadius: 0.9,
velocitySpread: {x: 0.04, y: 0.04, z: 0.04},
accelerationSpread: {x: 0.04, y: 0.04, z: 0.04},
emitAcceleration: {x: 0, y: 0.15, z: 0},
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
color: color,
lifespan: 10.0,
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, green: 255, blue: 255 },
{ x: 0.5, y: 0.0, z: 0.0 },
1000, 3, 1));
}
function ShutDown() {
var i, len = objs.length;
for (i = 0; i < len; i++) {
objs[i].Destroy();
}
objs = [];
}
Init();
Script.scriptEnding.connect(ShutDown);
})();