overte/script-archive/flowArts/lightSaber/lightSaberEntityScript.js

117 lines
3.5 KiB
JavaScript
Raw Permalink Normal View History

2015-12-17 08:55:57 -08:00
// lightSaberEntityScript.js
//
// Script Type: Entity
2015-12-17 11:32:48 -08:00
// Created by Eric Levin on 12/17/15.
2015-12-17 08:55:57 -08:00
// Copyright 2015 High Fidelity, Inc.
//
2015-12-17 11:32:48 -08:00
// This entity script creates the logic for displaying the lightsaber beam.
2015-12-17 08:55:57 -08:00
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
Script.include("../../libraries/utils.js");
var _this;
// this is the "constructor" for the entity as a JS object we don't do much here
var LightSaber = function() {
_this = this;
this.colorPalette = [{
red: 0,
green: 200,
blue: 40
}, {
red: 200,
green: 10,
blue: 40
}];
};
LightSaber.prototype = {
isGrabbed: false,
startNearGrab: function() {
2015-12-17 10:50:58 -08:00
Entities.editEntity(this.beam, {
isEmitting: true,
visible: true
2015-12-17 10:50:58 -08:00
});
2015-12-17 08:55:57 -08:00
},
releaseGrab: function() {
2015-12-17 10:50:58 -08:00
Entities.editEntity(this.beam, {
visible: false,
2015-12-17 10:50:58 -08:00
isEmitting: false
});
2015-12-17 08:55:57 -08:00
},
preload: function(entityID) {
this.entityID = entityID;
2015-12-17 10:35:20 -08:00
this.createBeam();
2015-12-17 08:55:57 -08:00
},
unload: function() {
Entities.deleteEntity(this.beam);
},
createBeam: function() {
2015-12-17 10:04:51 -08:00
this.props = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
var forwardVec = Quat.getFront(Quat.multiply(this.props.rotation, Quat.fromPitchYawRollDegrees(-90, 0, 0)));
2015-12-17 15:02:25 -08:00
var forwardQuat = Quat.rotationBetween(Vec3.UNIT_Z, forwardVec);
2015-12-22 11:02:36 -08:00
var position = this.props.position;
2015-12-17 10:35:20 -08:00
var color = this.colorPalette[randInt(0, this.colorPalette.length)];
2015-12-17 08:55:57 -08:00
var props = {
type: "ParticleEffect",
2015-12-17 11:32:48 -08:00
name: "LightSaber Beam",
2015-12-17 08:55:57 -08:00
position: position,
parentID: this.entityID,
2015-12-17 10:50:58 -08:00
isEmitting: false,
2015-12-17 11:32:48 -08:00
colorStart: color,
2015-12-17 08:55:57 -08:00
color: {
red: 200,
green: 200,
blue: 255
},
2015-12-17 11:32:48 -08:00
colorFinish: color,
maxParticles: 100000,
lifespan: 2,
emitRate: 1000,
2015-12-17 08:55:57 -08:00
emitOrientation: forwardQuat,
2015-12-21 15:20:36 -08:00
emitSpeed: 0.7,
2015-12-17 11:32:48 -08:00
speedSpread: 0.0,
emitDimensions: {
x: 0,
y: 0,
z: 0
2015-12-17 10:04:51 -08:00
},
2015-12-17 11:32:48 -08:00
polarStart: 0,
2015-12-21 15:20:36 -08:00
polarFinish: 0,
azimuthStart: 0.1,
azimuthFinish: 0.01,
2015-12-17 11:32:48 -08:00
emitAcceleration: {
x: 0,
y: 0,
z: 0
2015-12-17 08:55:57 -08:00
},
2015-12-17 11:32:48 -08:00
accelerationSpread: {
x: .00,
y: .00,
z: .00
2015-12-17 08:55:57 -08:00
},
2015-12-17 11:32:48 -08:00
radiusStart: 0.03,
adiusFinish: 0.025,
alpha: 0.7,
2015-12-21 15:20:36 -08:00
alphaSpread: 0.1,
2015-12-17 11:32:48 -08:00
alphaStart: 0.5,
alphaFinish: 0.5,
textures: "https://s3.amazonaws.com/hifi-public/eric/textures/particleSprites/beamParticle.png",
emitterShouldTrail: false
2015-12-17 08:55:57 -08:00
}
this.beam = Entities.addEntity(props);
}
};
// entity scripts always need to return a newly constructed object of our type
return new LightSaber();
2015-12-22 11:02:36 -08:00
});