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() { Script.setTimeout(function() {
var props = Entities.getEntityProperties(self.pointer); var props = Entities.getEntityProperties(self.pointer);
Entities.editEntity(self.pointer, { Entities.editEntity(self.pointer, {
lifetime: props.age + EXTRA_TIME lifetime: props.age + EXTRA_TIME + LIFETIME
}); });
self.checkPointer(); self.checkPointer();
}, POINTER_CHECK_TIME); }, POINTER_CHECK_TIME);

View file

@ -1,5 +1,7 @@
(function() { (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"; GRAB_FRAME_USER_DATA_KEY = "grabFrame";
this.userData = {}; this.userData = {};
@ -18,13 +20,14 @@
var self = this; var self = this;
var stopSetting = JSON.stringify({ var timeSinceLastMoved = 0;
running: false var RESET_TIME_THRESHOLD = 5;
}); var DISTANCE_FROM_HOME_THRESHOLD = 0.5;
var startSetting = JSON.stringify({ var HOME_POSITION = {
running: true x: 549.12,
}); y: 495.555,
z: 503.77
};
this.getUserData = function() { this.getUserData = function() {
@ -40,14 +43,26 @@
} }
this.update = function(deltaTime) { this.update = function(deltaTime) {
self.properties = Entities.getEntityProperties(self.entityId);
self.getUserData(); 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.userData.grabKey && self.userData.grabKey.activated === true) {
if (self.activated !== true) { if (self.activated !== true) {
//We were just grabbed, so create a particle system
self.grab();
Entities.editEntity(self.paintStream, { Entities.editEntity(self.paintStream, {
animationSettings: startSetting animationSettings: startSetting
}); });
self.activated = true;
} }
//Move emitter to where entity is always when its activated //Move emitter to where entity is always when its activated
self.sprayStream(); 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() { this.sprayStream = function() {
var forwardVec = Quat.getFront(self.properties.rotation); var forwardVec = Quat.getFront(self.properties.rotation);
forwardVec = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 90, 0), forwardVec); forwardVec = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 90, 0), forwardVec);
@ -134,9 +197,9 @@
blue: randInt(190, 250) blue: randInt(190, 250)
}, },
dimensions: { dimensions: {
x: 5, x: 50,
y: 5, y: 50,
z: 5 z: 50
}, },
lifetime: 100 lifetime: 100
}); });
@ -167,41 +230,8 @@
} }
setEntityCustomData(GRAB_FRAME_USER_DATA_KEY, this.entityId, data); 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() { this.unload = function() {
Script.update.disconnect(this.update); Script.update.disconnect(this.update);

View file

@ -8,67 +8,31 @@
// 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
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 center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(Camera.getOrientation())));
var paintGun = Entities.addEntity({ var sprayCan = Entities.addEntity({
type: "Model", type: "Model",
modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/sprayGun.fbx?=v4", name: "spraycan",
position: center, modelURL: modelURL,
position: {x: 549.12, y:495.55, z:503.77},
rotation: {x: 0, y: 0, z: 0, w: 1},
dimensions: { dimensions: {
x: 0.03, x: 0.07,
y: 0.15, y: 0.17,
z: 0.34 z: 0.07
}, },
collisionsWillMove: true, collisionsWillMove: true,
shapeType: 'box', shapeType: 'box',
script: scriptURL script: scriptURL,
}); gravity: {x: 0, y: -0.5, z: 0},
velocity: {x: 0, y: -1, z: 0}
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
}); });
function cleanup() { function cleanup() {
Entities.deleteEntity(paintGun); Entities.deleteEntity(sprayCan);
Entities.deleteEntity(whiteboard);
} }
Script.scriptEnding.connect(cleanup); 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);
}