Merge pull request #5775 from ericrius1/paintCan

Paint can
This commit is contained in:
Seth Alves 2015-09-11 12:34:44 -07:00
commit f51f17b267
3 changed files with 92 additions and 98 deletions

View file

@ -144,7 +144,7 @@ controller.prototype.checkPointer = function() {
Script.setTimeout(function() {
var props = Entities.getEntityProperties(self.pointer);
Entities.editEntity(self.pointer, {
lifetime: props.age + EXTRA_TIME
lifetime: props.age + EXTRA_TIME + LIFETIME
});
self.checkPointer();
}, POINTER_CHECK_TIME);

View file

@ -1,5 +1,7 @@
(function() {
Script.include("../libraries/utils.js");
// Script.include("../libraries/utils.js");
//Need absolute path for now, for testing before PR merge and s3 cloning. Will change post-merge
Script.include("https://hifi-public.s3.amazonaws.com/scripts/libraries/utils.js");
GRAB_FRAME_USER_DATA_KEY = "grabFrame";
this.userData = {};
@ -18,13 +20,14 @@
var self = this;
var stopSetting = JSON.stringify({
running: false
});
var startSetting = JSON.stringify({
running: true
});
var timeSinceLastMoved = 0;
var RESET_TIME_THRESHOLD = 5;
var DISTANCE_FROM_HOME_THRESHOLD = 0.5;
var HOME_POSITION = {
x: 549.12,
y: 495.555,
z: 503.77
};
this.getUserData = function() {
@ -40,14 +43,26 @@
}
this.update = function(deltaTime) {
self.properties = Entities.getEntityProperties(self.entityId);
self.getUserData();
self.properties = Entities.getEntityProperties(self.entityId);
if (Vec3.length(self.properties.velocity) < 0.1 && Vec3.distance(HOME_POSITION, self.properties.position) > DISTANCE_FROM_HOME_THRESHOLD) {
timeSinceLastMoved += deltaTime;
if (timeSinceLastMoved > RESET_TIME_THRESHOLD) {
self.reset();
timeSinceLastMoved = 0;
}
} else {
timeSinceLastMoved = 0;
}
if (self.userData.grabKey && self.userData.grabKey.activated === true) {
if (self.activated !== true) {
//We were just grabbed, so create a particle system
self.grab();
Entities.editEntity(self.paintStream, {
animationSettings: startSetting
});
self.activated = true;
}
//Move emitter to where entity is always when its activated
self.sprayStream();
@ -59,6 +74,54 @@
}
}
this.grab = function() {
self.activated = true;
var animationSettings = JSON.stringify({
fps: 30,
loop: true,
firstFrame: 1,
lastFrame: 10000,
running: true
});
this.paintStream = Entities.addEntity({
type: "ParticleEffect",
animationSettings: animationSettings,
position: this.properties.position,
textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png",
emitVelocity: ZERO_VEC,
emitAcceleration: ZERO_VEC,
velocitySpread: {
x: .02,
y: .02,
z: 0.02
},
emitRate: 100,
particleRadius: 0.01,
color: {
red: 170,
green: 20,
blue: 150
},
lifetime: 500, //probably wont be holding longer than this straight
});
}
this.letGo = function() {
self.activated = false;
Entities.deleteEntity(this.paintStream);
}
this.reset = function() {
Entities.editEntity(self.entityId, {
position: HOME_POSITION,
rotation: Quat.fromPitchYawRollDegrees(0, 0, 0),
angularVelocity: ZERO_VEC,
velocity: ZERO_VEC
});
}
this.sprayStream = function() {
var forwardVec = Quat.getFront(self.properties.rotation);
forwardVec = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 90, 0), forwardVec);
@ -134,9 +197,9 @@
blue: randInt(190, 250)
},
dimensions: {
x: 5,
y: 5,
z: 5
x: 50,
y: 50,
z: 50
},
lifetime: 100
});
@ -167,41 +230,8 @@
}
setEntityCustomData(GRAB_FRAME_USER_DATA_KEY, this.entityId, data);
}
this.initialize();
}
this.initialize = function() {
var animationSettings = JSON.stringify({
fps: 30,
loop: true,
firstFrame: 1,
lastFrame: 10000,
running: false
});
this.paintStream = Entities.addEntity({
type: "ParticleEffect",
animationSettings: animationSettings,
position: this.properties.position,
textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png",
emitVelocity: ZERO_VEC,
emitAcceleration: ZERO_VEC,
velocitySpread: {
x: .02,
y: .02,
z: 0.02
},
emitRate: 100,
particleRadius: 0.01,
color: {
red: 170,
green: 20,
blue: 150
},
lifespan: 5,
});
}
this.unload = function() {
Script.update.disconnect(this.update);

View file

@ -8,67 +8,31 @@
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
var scriptURL = "entityScripts/sprayPaintCan.js";
//Just temporarily using my own bucket here so others can test the entity. Once PR is tested and merged, then the entity script will appear in its proper place in S3, and I wil switch it
var scriptURL = "https://hifi-public.s3.amazonaws.com/eric/scripts/sprayPaintCan.js?=v1";
var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx";
var center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(Camera.getOrientation())));
var paintGun = Entities.addEntity({
var sprayCan = Entities.addEntity({
type: "Model",
modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/sprayGun.fbx?=v4",
position: center,
name: "spraycan",
modelURL: modelURL,
position: {x: 549.12, y:495.55, z:503.77},
rotation: {x: 0, y: 0, z: 0, w: 1},
dimensions: {
x: 0.03,
y: 0.15,
z: 0.34
x: 0.07,
y: 0.17,
z: 0.07
},
collisionsWillMove: true,
shapeType: 'box',
script: scriptURL
});
var whiteboard = Entities.addEntity({
type: "Box",
position: center,
dimensions: {
x: 2,
y: 1.5,
z: .01
},
rotation: orientationOf(Vec3.subtract(MyAvatar.position, center)),
color: {
red: 250,
green: 250,
blue: 250
},
// visible: false
script: scriptURL,
gravity: {x: 0, y: -0.5, z: 0},
velocity: {x: 0, y: -1, z: 0}
});
function cleanup() {
Entities.deleteEntity(paintGun);
Entities.deleteEntity(whiteboard);
Entities.deleteEntity(sprayCan);
}
Script.scriptEnding.connect(cleanup);
function orientationOf(vector) {
var Y_AXIS = {
x: 0,
y: 1,
z: 0
};
var X_AXIS = {
x: 1,
y: 0,
z: 0
};
var theta = 0.0;
var RAD_TO_DEG = 180.0 / Math.PI;
var direction, yaw, pitch;
direction = Vec3.normalize(vector);
yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS);
pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS);
return Quat.multiply(yaw, pitch);
}