correct file

This commit is contained in:
ericrius1 2015-12-21 11:35:57 -08:00
parent ba3633710a
commit b89e25f8f7

View file

@ -1,84 +1,116 @@
// arcBallEntityScript.js
// //
// Script Type: Entity // arcBall.js
// examples/arcBall
//
// Created by Eric Levin on 12/17/15. // Created by Eric Levin on 12/17/15.
// Copyright 2015 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
//
// This script creats a particle light ball which makes particle trails as you move it.
//
// //
// This entity script handles the logic for the arcBall rave toy
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
(function() {
Script.include("../../libraries/utils.js"); Script.include("../../libraries/utils.js");
var _this;
var ArcBall = function() {
_this = this; var scriptURL = Script.resolvePath("arcBallEntityScript.js");
this.colorPalette = [{ ArcBall = function(spawnPosition) {
var colorPalette = [{
red: 25, red: 25,
green: 20, green: 20,
blue: 162 blue: 162
}, {
red: 200,
green: 10,
blue: 10
}]; }];
};
ArcBall.prototype = {
isGrabbed: false, var containerBall = Entities.addEntity({
startNearGrab: function() { type: "Sphere",
//Search for nearby balls and create an arc to it if one is found name: "Arc Ball",
var position = Entities.getEntityProperties(this.entityID, "position").position script: scriptURL,
var entities = Entities.findEntities(position, 10); position: Vec3.sum(spawnPosition, {
entities.forEach(function(entity) { x: 0,
var props = Entities.getEntityProperties(entity, ["position", "name"]); y: .7,
if (props.name === "Arc Ball" && JSON.stringify(_this.entityID) !== JSON.stringify(entity)) { z: 0
_this.target = entity; }),
_this.createBeam(position, props.position); dimensions: {
x: .05,
y: .05,
z: .05
},
color: {
red: 100,
green: 10,
blue: 150
},
ignoreForCollisions: true,
damping: 0.8,
collisionsWillMove: true,
userData: JSON.stringify({
grabbableKey: {
spatialKey: {
relativePosition: {
x: 0,
y: 0.0,
z: -0.5
},
},
// invertSolidWhileHeld: true
} }
})
}); });
var light = Entities.addEntity({
type: 'Light',
name: "ballLight",
parentID: containerBall,
dimensions: {
x: 30,
y: 30,
z: 30
}, },
color: colorPalette[randInt(0, colorPalette.length)],
createBeam: function(startPosition, endPosition) { intensity: 5
// Creates particle arc from start position to end position });
var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation;
var sourceToTargetVec = Vec3.subtract(endPosition, startPosition);
var emitOrientation = Quat.rotationBetween(Vec3.UNIT_Z, sourceToTargetVec);
emitOrientation = Quat.multiply(Quat.inverse(rotation), emitOrientation);
var color = this.colorPalette[randInt(0, this.colorPalette.length)]; var arcBall = Entities.addEntity({
var props = {
type: "ParticleEffect", type: "ParticleEffect",
name: "Particle Arc", parentID: containerBall,
parentID: this.entityID,
parentJointIndex: -1,
// position: startPosition,
isEmitting: true, isEmitting: true,
colorStart: color, name: "Arc Ball Particle Effect",
colorStart: {
red: 200,
green: 20,
blue: 40
},
color: { color: {
red: 200, red: 200,
green: 200, green: 200,
blue: 255 blue: 255
}, },
colorFinish: color, colorFinish: {
red: 25,
green: 20,
blue: 255
},
maxParticles: 100000, maxParticles: 100000,
lifespan: 1, lifespan: 2,
emitRate: 1000, emitRate: 400,
emitOrientation: emitOrientation, emitSpeed: .1,
emitSpeed: .2, lifetime: -1,
speedSpread: 0.1, speedSpread: 0.0,
emitDimensions: { emitDimensions: {
x: .1, x: 0,
y: .1, y: 0,
z: .1 z: 0
}, },
polarStart: 0, polarStart: 0,
polarFinish: .0, polarFinish: Math.PI,
azimuthStart: .1, azimuthStart: -Math.PI,
azimuthFinish: .01, azimuthFinish: Math.PI,
emitAcceleration: { emitAcceleration: {
x: 0, x: 0,
y: 0, y: 0,
@ -89,51 +121,25 @@
y: .00, y: .00,
z: .00 z: .00
}, },
radiusStart: 0.01, particleRadius: 0.02,
radiusFinish: 0.005, radiusSpread: 0,
radiusSpread: .005, radiusStart: 0.03,
alpha: 0.5, radiusFinish: 0.0003,
alphaSpread: .1, alpha: 0,
alphaStart: 0.5, alphaSpread: .5,
alphaFinish: 0.0, alphaStart: 0,
textures: "https://s3.amazonaws.com/hifi-public/eric/textures/particleSprites/beamParticle.png", alphaFinish: 0.5,
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
emitterShouldTrail: true emitterShouldTrail: true
})
function cleanup() {
Entities.deleteEntity(arcBall);
Entities.deleteEntity(containerBall);
Entities.deleteEntity(light);
} }
this.particleArc = Entities.addEntity(props);
},
updateBeam: function(startPosition) { this.cleanup = cleanup;
var targetPosition = Entities.getEntityProperties(this.target, "position").position;
print("TARGET position " + JSON.stringify(this.target));
var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation;
var sourceToTargetVec = Vec3.subtract(targetPosition, startPosition);
var emitOrientation = Quat.rotationBetween(Vec3.UNIT_Z, sourceToTargetVec);
// emitOrientation = Quat.multiply(emitOrientation,Quat.inverse(rotation));
Entities.editEntity(this.particleArc, {
emitOrientation: emitOrientation
});
},
continueNearGrab: function() {
var startPosition = Entities.getEntityProperties(this.entityID, "position").position;
this.updateBeam(startPosition);
},
releaseGrab: function() {
Entities.editEntity(this.particleArc, {
isEmitting: false
});
},
unload: function() {
if (this.particleArc) {
Entities.deleteEntity(this.particleArc);
} }
},
preload: function(entityID) {
this.entityID = entityID;
},
};
return new ArcBall();
});