refactoring, adding headers

This commit is contained in:
ericrius1 2015-12-17 11:32:48 -08:00
parent d4481818b2
commit 2aaefbcfcb
9 changed files with 195 additions and 146 deletions

View file

@ -1,11 +1,11 @@
//
// flowArtsHutSpawner.js
// examples
// examples/flowArts
//
// Created by Eric Levin on 5/14/15.
// Created by Eric Levin on 12/17/15.
// Copyright 2014 High Fidelity, Inc.
//
// This script creates a special flow arts hut with a numch of flow art toys people can go in and play with
// This script creates a special flow arts hut with a bunch of flow art toys people can go in and play with
//
//
// Distributed under the Apache License, Version 2.0.
@ -29,12 +29,13 @@ var raveStick = new RaveStick(Vec3.sum(basePosition, {x: 1, 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();
var modelURL = "https://s3.amazonaws.com/hifi-public/eric/models/rave/RaveRoom.fbx";
var roomDimensions = {x: 30.58, y: 15.29, z: 30.58};
var raveRoom = Entities.addEntity({
type: "Model",
name: "Rave Hut Room",
modelURL: modelURL,
position: basePosition,
dimensions:roomDimensions,
@ -43,7 +44,8 @@ var raveRoom = Entities.addEntity({
var floor = Entities.addEntity({
type: "Box",
position: Vec3.sum(basePosition, {x: 0, y: -1.5, z: 0}),
name: "Rave Floor",
position: Vec3.sum(basePosition, {x: 0, y: -1.2, z: 0}),
dimensions: {x: roomDimensions.x, y: 0.6, z: roomDimensions.z},
color: {red: 50, green: 10, blue: 100},
shapeType: 'box'
@ -53,6 +55,7 @@ var floor = Entities.addEntity({
var lightZone = Entities.addEntity({
type: "Zone",
name: "Rave Hut Zone",
shapeType: 'box',
keyLightIntensity: 0.4,
keyLightColor: {

View file

@ -1,3 +1,17 @@
//
// LightBall.js
// examples/lightBall
//
// Created by Eric Levin on 12/17/15.
// Copyright 2014 High Fidelity, Inc.
//
// This script creats a particle light ball which makes particle trails as you move it.
//
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
Script.include("../../libraries/utils.js");
LightBall = function(spawnPosition) {
@ -11,6 +25,7 @@ LightBall = function(spawnPosition) {
var containerBall = Entities.addEntity({
type: "Sphere",
name: "containerBall",
position: Vec3.sum(spawnPosition, {
x: 0,
y: .5,
@ -27,7 +42,11 @@ LightBall = function(spawnPosition) {
blue: 150
},
collisionsWillMove: true,
gravity: {x: 0, y: -.5, z: 0},
gravity: {
x: 0,
y: -.5,
z: 0
},
userData: JSON.stringify({
grabbableKey: {
spatialKey: {
@ -45,6 +64,7 @@ LightBall = function(spawnPosition) {
var light = Entities.addEntity({
type: 'Light',
name: "ballLight",
parentID: containerBall,
dimensions: {
x: 30,
@ -60,8 +80,8 @@ LightBall = function(spawnPosition) {
type: "ParticleEffect",
parentID: containerBall,
isEmitting: true,
"name": "ParticlesTest Emitter",
"colorStart": {
name: "particleBall",
colorStart: {
red: 200,
green: 20,
blue: 40
@ -71,45 +91,45 @@ LightBall = function(spawnPosition) {
green: 200,
blue: 255
},
"colorFinish": {
colorFinish: {
red: 25,
green: 20,
blue: 255
},
"maxParticles": 100000,
"lifespan": 2,
"emitRate": 10000,
"emitSpeed": .1,
"speedSpread": 0.0,
"emitDimensions": {
"x": 0,
"y": 0,
"z": 0
maxParticles: 100000,
lifespan: 2,
emitRate: 10000,
emitSpeed: .1,
lifetime: -1,
speedSpread: 0.0,
emitDimensions: {
x: 0,
y: 0,
z: 0
},
"polarStart": 0,
"polarFinish": Math.PI,
"azimuthStart": -Math.PI,
"azimuthFinish": Math.PI,
"emitAcceleration": {
"x": 0,
"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": .00,
"z": .00
accelerationSpread: {
x: .00,
y: .00,
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(),
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",
emitterShouldTrail: true
})

View file

@ -1,10 +1,25 @@
//
// LightSaber.js
// examples
//
// Created by Eric Levin on 12/17/15.
// Copyright 2014 High Fidelity, Inc.
//
// This script creates a lightsaber which activates on grab
//
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
Script.include("../../libraries/utils.js");
var modelURL = "file:///C:/Users/Eric/Desktop/lightSaber.fbx?v1" + Math.random();
var modelURL = "https://s3.amazonaws.com/hifi-public/eric/models/rave/lightSaber.fbx";
var scriptURL = Script.resolvePath("lightSaberEntityScript.js");
LightSaber = function(spawnPosition) {
var stick = Entities.addEntity({
var saberHandle = Entities.addEntity({
type: "Model",
name: "LightSaber Handle",
modelURL: modelURL,
position: spawnPosition,
shapeType: 'box',
@ -31,7 +46,7 @@ LightSaber = function(spawnPosition) {
function cleanup() {
Entities.deleteEntity(stick);
Entities.deleteEntity(saberHandle);
}
this.cleanup = cleanup;

View file

@ -1,10 +1,10 @@
// lightSaberEntityScript.js
//
// Script Type: Entity
// Created by Eric Levin on 12/16/15.
// Created by Eric Levin on 12/17/15.
// Copyright 2015 High Fidelity, Inc.
//
// This entity script creates a lightsaber.
// This entity script creates the logic for displaying the lightsaber beam.
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
@ -35,10 +35,6 @@
});
},
continueNearGrab: function() {
},
releaseGrab: function() {
Entities.editEntity(this.beam, {
isEmitting: false
@ -52,7 +48,6 @@
unload: function() {
Entities.deleteEntity(this.beam);
// Entities.deleteEntity(this.beamTrail);
},
createBeam: function() {
@ -68,56 +63,53 @@
var color = this.colorPalette[randInt(0, this.colorPalette.length)];
var props = {
type: "ParticleEffect",
name: "LightSaber Beam",
position: position,
parentID: this.entityID,
isEmitting: false,
"colorStart": color,
colorStart: color,
color: {
red: 200,
green: 200,
blue: 255
},
"colorFinish": color,
"maxParticles": 100000,
"lifespan": 2,
"emitRate": 1000,
colorFinish: color,
maxParticles: 100000,
lifespan: 2,
emitRate: 1000,
emitOrientation: forwardQuat,
"emitSpeed": .4,
"speedSpread": 0.0,
"emitDimensions": {
"x": 0,
"y": 0,
"z": 0
emitSpeed: .4,
speedSpread: 0.0,
emitDimensions: {
x: 0,
y: 0,
z: 0
},
"polarStart": 0,
"polarFinish": .0,
"azimuthStart": .1,
"azimuthFinish": .01,
"emitAcceleration": {
"x": 0,
"y": 0,
"z": 0
polarStart: 0,
polarFinish: .0,
azimuthStart: .1,
azimuthFinish: .01,
emitAcceleration: {
x: 0,
y: 0,
z: 0
},
"accelerationSpread": {
"x": .00,
"y": .00,
"z": .00
accelerationSpread: {
x: .00,
y: .00,
z: .00
},
"radiusStart": 0.03,
radiusFinish: 0.025,
"alpha": 0.7,
"alphaSpread": .1,
"alphaStart": 0.5,
"alphaFinish": 0.5,
// "textures": "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
"textures": "file:///C:/Users/Eric/Desktop/beamParticle.png?v1" + Math.random(),
radiusStart: 0.03,
adiusFinish: 0.025,
alpha: 0.7,
alphaSpread: .1,
alphaStart: 0.5,
alphaFinish: 0.5,
textures: "https://s3.amazonaws.com/hifi-public/eric/textures/particleSprites/beamParticle.png",
emitterShouldTrail: false
}
this.beam = Entities.addEntity(props);
// props.emitterShouldTrail = true;
// this.beamTrail = Entities.addEntity(props);
}
};
// entity scripts always need to return a newly constructed object of our type

View file

@ -1,11 +1,11 @@
//
// hydraPaint.js
// lightTrails.js
// examples
//
// Created by Eric Levin on 5/14/15.
// Copyright 2014 High Fidelity, Inc.
//
// This script allows you to paint with the hydra!
// This script creates light trails as you move your hydra hands
//
//
// Distributed under the Apache License, Version 2.0.
@ -25,24 +25,6 @@ var LIFETIME = 6000;
var DRAWING_DEPTH = 0.8;
var LINE_DIMENSIONS = 100;
var lightZone = Entities.addEntity({
type: "Zone",
shapeType: 'box',
keyLightIntensity: 0.02,
keyLightColor: {
red: 5,
green: 0,
blue: 5
},
keyLightAmbientIntensity: .05,
position: MyAvatar.position,
dimensions: {
x: 100,
y: 100,
z: 100
}
});
var MIN_POINT_DISTANCE = 0.02;
@ -192,7 +174,6 @@ function update(deltaTime) {
function scriptEnding() {
leftController.cleanup();
rightController.cleanup();
Entities.deleteEntity(lightZone);
}
function vectorIsZero(v) {

View file

@ -1,10 +1,32 @@
//
// RaveStick.js
// examples/flowArats/raveStick
//
// Created by Eric Levin on 12/17/15.
// Copyright 2014 High Fidelity, Inc.
//
// This script creates a rave stick which makes pretty light trails as you paint
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
Script.include("../../libraries/utils.js");
var modelURL = "file:///C:/Users/Eric/Desktop/raveStick.fbx?v1" + Math.random();
var modelURL = "https://s3.amazonaws.com/hifi-public/eric/models/rave/raveStick.fbx";
var scriptURL = Script.resolvePath("raveStickEntityScript.js");
RaveStick = function(spawnPosition) {
var colorPalette = [{
red: 0,
green: 200,
blue: 40
}, {
red: 200,
green: 10,
blue: 40
}];
var stick = Entities.addEntity({
type: "Model",
name: "raveStick",
modelURL: modelURL,
position: spawnPosition,
shapeType: 'box',
@ -29,9 +51,24 @@ RaveStick = function(spawnPosition) {
})
});
var light = Entities.addEntity({
type: 'Light',
name: "raveLight",
parentID: stick,
dimensions: {
x: 30,
y: 30,
z: 30
},
color: colorPalette[randInt(0, colorPalette.length)],
intensity: 5
});
function cleanup() {
Entities.deleteEntity(stick);
Entities.deleteEntity(light);
}
this.cleanup = cleanup;

View file

@ -46,7 +46,9 @@
},
textures: texture,
lifetime: LIFETIME
})
});
this.points = [];
this.normals = [];
this.strokeWidths = [];
@ -127,8 +129,8 @@
unload: function() {
Entities.deleteEntity(this.beam);
Entities.deleteEntity(this.trail);
if(this.trailEraseInterval) {
Script.clearInterval(this.trailEraseInterval);
if (this.trailEraseInterval) {
Script.clearInterval(this.trailEraseInterval);
}
},
@ -147,43 +149,46 @@
position: position,
parentID: this.entityID,
isEmitting: true,
"name": "ParticlesTest Emitter",
"colorStart": color,
colorSpread: {red: 200, green : 10, blue: 10},
name: "raveBeam",
colorStart: color,
colorSpread: {
red: 200,
green: 10,
blue: 10
},
color: {
red: 200,
green: 200,
blue: 255
},
"colorFinish": color,
"maxParticles": 100000,
"lifespan": 1,
"emitRate": 1000,
colorFinish: color,
maxParticles: 100000,
lifespan: 1,
emitRate: 1000,
emitOrientation: forwardQuat,
"emitSpeed": .2,
"speedSpread": 0.0,
"polarStart": 0,
"polarFinish": .0,
"azimuthStart": .1,
"azimuthFinish": .01,
"emitAcceleration": {
"x": 0,
"y": 0,
"z": 0
emitSpeed: .2,
speedSpread: 0.0,
polarStart: 0,
polarFinish: .0,
azimuthStart: .1,
azimuthFinish: .01,
emitAcceleration: {
x: 0,
y: 0,
z: 0
},
"accelerationSpread": {
"x": .00,
"y": .00,
"z": .00
accelerationSpread: {
x: .00,
y: .00,
z: .00
},
"radiusStart": 0.03,
radiusStart: 0.03,
radiusFinish: 0.025,
"alpha": 0.7,
"alphaSpread": .1,
"alphaStart": 0.5,
"alphaFinish": 0.5,
// "textures": "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
"textures": "file:///C:/Users/Eric/Desktop/beamParticle.png?v1" + Math.random(),
alpha: 0.7,
alphaSpread: .1,
alphaStart: 0.5,
alphaFinish: 0.5,
textures: "https://s3.amazonaws.com/hifi-public/eric/textures/particleSprites/beamParticle.png",
emitterShouldTrail: false
}
this.beam = Entities.addEntity(props);

View file

@ -245,6 +245,7 @@ void RenderableParticleEffectEntityItem::updateRenderItem() {
transform.setRotation(rotation);
}
render::PendingChanges pendingChanges;
pendingChanges.updateItem<ParticlePayloadData>(_renderItemId, [=](ParticlePayloadData& payload) {
payload.setVisibleFlag(true);

View file

@ -641,11 +641,7 @@ void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
ParticleEffectEntityItem::Particle ParticleEffectEntityItem::createParticle() {
Particle particle;
std::random_device rd;
std::mt19937_64 el(rd());
std::uniform_real_distribution<float> uniform_dist(0.0, 1.0);
particle.seed = randFloatInRange(-1.0f, 1.0f);
if (getEmitterShouldTrail()) {
@ -667,13 +663,13 @@ ParticleEffectEntityItem::Particle ParticleEffectEntityItem::createParticle() {
float elevationMinZ = sin(PI_OVER_TWO - _polarFinish);
float elevationMaxZ = sin(PI_OVER_TWO - _polarStart);
// float elevation = asin(elevationMinZ + (elevationMaxZ - elevationMinZ) * randFloat());
float elevation = asin(elevationMinZ + (elevationMaxZ - elevationMinZ) * uniform_dist(el));
float elevation = asin(elevationMinZ + (elevationMaxZ - elevationMinZ) *randFloat());
float azimuth;
if (_azimuthFinish >= _azimuthStart) {
azimuth = _azimuthStart + (_azimuthFinish - _azimuthStart) * uniform_dist(el);
azimuth = _azimuthStart + (_azimuthFinish - _azimuthStart) * randFloat();
} else {
azimuth = _azimuthStart + (TWO_PI + _azimuthFinish - _azimuthStart) * uniform_dist(el);
azimuth = _azimuthStart + (TWO_PI + _azimuthFinish - _azimuthStart) * randFloat();
}
glm::vec3 emitDirection;
@ -711,7 +707,6 @@ ParticleEffectEntityItem::Particle ParticleEffectEntityItem::createParticle() {
}
particle.velocity = (_emitSpeed + randFloatInRange(-1.0f, 1.0f) * _speedSpread) * (_emitOrientation * emitDirection);
// particle.velocity = (_emitSpeed + uniform_dist(el) * _speedSpread) * (_emitOrientation * emitDirection);
particle.acceleration = _emitAcceleration + randFloatInRange(-1.0f, 1.0f) * _accelerationSpread;
}