light trails

This commit is contained in:
ericrius1 2015-12-17 10:04:51 -08:00
parent b127b6a9e8
commit 064c05e98c
4 changed files with 189 additions and 12 deletions

View file

@ -27,7 +27,7 @@ basePosition.y = MyAvatar.position.y + 1;
var lightBall = new LightBall(basePosition);
var raveStick = new RaveStick(Vec3.sum(basePosition, {x: 1, y: 0.5, z: 1}));
var raveStick2 = new RaveStick(Vec3.sum(basePosition, {x: 2, y: 0.5, z: 1}));
var lightSaber = new LightSaber(Vec3.sum(basePosition, {x: 3, y: 0.5, z: 1}));
// var lightSaber = new LightSaber(Vec3.sum(basePosition, {x: 3, y: 0.5, z: 1}));
var modelURL = "file:///C:/Users/Eric/Desktop/RaveRoom.fbx?v1" + Math.random();

View file

@ -0,0 +1,129 @@
Script.include("../../libraries/utils.js");
LightBall = function(spawnPosition) {
var colorPalette = [{
red: 25,
green: 20,
blue: 162
}];
var containerBall = Entities.addEntity({
type: "Sphere",
position: Vec3.sum(spawnPosition, {
x: 0,
y: .5,
z: 0
}),
dimensions: {
x: .1,
y: .1,
z: .1
},
color: {
red: 15,
green: 10,
blue: 150
},
collisionsWillMove: true,
gravity: {x: 0, y: -.5, z: 0},
visible: false,
userData: JSON.stringify({
grabbableKey: {
spatialKey: {
relativePosition: {
x: 0,
y: .1,
z: 0
}
},
invertSolidWhileHeld: true
}
})
});
var light = Entities.addEntity({
type: 'Light',
parentID: containerBall,
dimensions: {
x: 30,
y: 30,
z: 30
},
color: colorPalette[randInt(0, colorPalette.length)],
intensity: 5
});
var lightBall = Entities.addEntity({
type: "ParticleEffect",
position: spawnPosition,
// parentID: containerBall,
isEmitting: true,
"name": "ParticlesTest Emitter",
"colorStart": {
red: 200,
green: 20,
blue: 40
},
color: {
red: 200,
green: 200,
blue: 255
},
"colorFinish": {
red: 25,
green: 20,
blue: 255
},
"maxParticles": 100000,
"lifespan": 2,
"emitRate": 10000,
"emitSpeed": .0,
"speedSpread": 0.0,
"emitDimensions": {
"x": 5,
"y":0 ,
"z": 0
},
// "polarStart": 0,
// "polarFinish": Math.PI,
// "azimuthStart": -Math.PI,
// "azimuthFinish": Math.PI,
"emitAcceleration": {
"x": 0,
"y": 0,
"z": 0
},
"accelerationSpread": {
"x": .00,
"y": .0,
"z": .00
},
"particleRadius": 0.02,
"radiusSpread": 0,
"radiusStart": 0.03,
"radiusFinish": 0.0003,
"alpha": 0,
"alphaSpread": .5,
"alphaStart": 0,
"alphaFinish": 0.5,
// "textures": "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
"textures": "file:///C:/Users/Eric/Desktop/Particle-Sprite-Smoke-1.png?v1" + Math.random(),
emitterShouldTrail: true
})
function cleanup() {
Entities.deleteEntity(lightBall);
Entities.deleteEntity(containerBall);
Entities.deleteEntity(light);
}
this.cleanup = cleanup;
}
LightBall();

View file

@ -31,7 +31,7 @@
startNearGrab: function() {
// this.createBeam();
this.createBeam();
},
continueNearGrab: function() {
@ -44,6 +44,7 @@
preload: function(entityID) {
this.entityID = entityID;
this.createBeam();
},
unload: function() {
@ -53,11 +54,12 @@
createBeam: function() {
var props = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
var forwardVec = Quat.getFront(Quat.multiply(props.rotation, Quat.fromPitchYawRollDegrees(-90, 0, 0)));
this.props = Entities.getEntityProperties(this.entityID, ["position", "rotation"]);
var forwardVec = Quat.getFront(Quat.multiply(this.props.rotation, Quat.fromPitchYawRollDegrees(-90, 0, 0)));
forwardVec = Vec3.normalize(forwardVec);
var forwardQuat = orientationOf(forwardVec);
var position = Vec3.sum(props.position, Vec3.multiply(Quat.getFront(props.rotation), 0.1));
var position = Vec3.sum(this.props.position, Vec3.multiply(Quat.getFront(this.props.rotation), 0.1));
position.z += 0.1;
position.x += -0.035;
var color = this.colorPalette[randInt(0, this.colorPalette.length)];
@ -66,7 +68,6 @@
position: position,
parentID: this.entityID,
isEmitting: true,
"name": "ParticlesTest Emitter",
"colorStart": color,
color: {
red: 200,
@ -80,11 +81,11 @@
emitOrientation: forwardQuat,
"emitSpeed": .4,
"speedSpread": 0.0,
// "emitDimensions": {
// "x": .1,
// "y": .1,
// "z": .1
// },
"emitDimensions": {
"x": 0,
"y": 0,
"z": 0
},
"polarStart": 0,
"polarFinish": .0,
"azimuthStart": .1,

View file

@ -13,6 +13,11 @@
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 LIFETIME = 6000;
var DRAWING_DEPTH = 0.8;
var LINE_DIMENSIONS = 100;
var MAX_POINTS_PER_LINE = 50;
var MIN_POINT_DISTANCE = 0.02;
var RaveStick = function() {
_this = this;
this.colorPalette = [{
@ -24,6 +29,21 @@
green: 10,
blue: 40
}];
var texture = "https://s3.amazonaws.com/hifi-public/eric/textures/paintStrokes/trails.png";
this.trail = Entities.addEntity({
type: "PolyLine",
dimensions: {x: LINE_DIMENSIONS, y: LINE_DIMENSIONS, z: LINE_DIMENSIONS},
color: {
red: 255,
green: 255,
blue: 255
},
textures: texture,
lifetime: LIFETIME
})
this.points = [];
this.normals = [];
this.strokeWidths = [];
};
RaveStick.prototype = {
@ -31,9 +51,31 @@
startNearGrab: function() {
// this.createBeam();
this.trailBasePosition = Entities.getEntityProperties(this.entityID, "position").position;
Entities.editEntity(this.trail, {
position: this.trailBasePosition
});
this.points = [];
this.normals = [];
this.strokeWidths = [];
},
continueNearGrab: function() {
var position = Entities.getEntityProperties(this.entityID, "position").position;
var localPoint = Vec3.subtract(position, this.trailBasePosition);
if (this.points.length >=1 && Vec3.distance(localPoint, this.points[this.points.length - 1]) < MIN_POINT_DISTANCE) {
//Need a minimum distance to avoid binormal NANs
return;
}
this.points.push(localPoint);
var normal = computeNormal(position, Camera.getPosition());
this.normals.push(normal);
this.strokeWidths.push(0.04);
Entities.editEntity(this.trail, {
linePoints: this.points,
normals: this.normals,
strokeWidths: this.strokeWidths
})
},
@ -48,6 +90,7 @@
unload: function() {
Entities.deleteEntity(this.beam);
Entities.deleteEntity(this.trail);
// Entities.deleteEntity(this.beamTrail);
},
@ -60,7 +103,7 @@
var position = Vec3.sum(props.position, Vec3.multiply(Quat.getFront(props.rotation), 0.1));
position.z += 0.1;
position.x += -0.035;
var color = this.colorPalette[randInt(0, this.colorPalette.length)];
var color = this.colorPalette[randInt(0, this.colorPalette.length)];
var props = {
type: "ParticleEffect",
position: position,
@ -118,4 +161,8 @@
};
// entity scripts always need to return a newly constructed object of our type
return new RaveStick();
function computeNormal(p1, p2) {
return Vec3.normalize(Vec3.subtract(p2, p1));
}
});