Merge pull request #5821 from ericrius1/paintCan

Paint can tweaks
This commit is contained in:
Brad Hefta-Gaub 2015-09-17 11:37:44 -07:00
commit 5549f4ec40
2 changed files with 26 additions and 24 deletions

View file

@ -1,7 +1,8 @@
(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 //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");
Script.include("../libraries/utils.js");
GRAB_FRAME_USER_DATA_KEY = "grabFrame"; GRAB_FRAME_USER_DATA_KEY = "grabFrame";
this.userData = {}; this.userData = {};
@ -56,26 +57,21 @@
timeSinceLastMoved = 0; timeSinceLastMoved = 0;
} }
if (self.userData.grabKey && self.userData.grabKey.activated === true) { //Only activate for the user who grabbed the object
if (self.userData.grabKey && self.userData.grabKey.activated === true && self.userData.grabKey.avatarId == MyAvatar.sessionUUID) {
if (self.activated !== true) { if (self.activated !== true) {
//We were just grabbed, so create a particle system //We were just grabbed, so create a particle system
self.grab(); self.grab();
Entities.editEntity(self.paintStream, {
animationSettings: startSetting
});
} }
//Move emitter to where entity is always when its activated //Move emitter to where entity is always when its activated
self.sprayStream(); self.sprayStream();
} else if (self.userData.grabKey && self.userData.grabKey.activated === false && self.activated) { } else if (self.userData.grabKey && self.userData.grabKey.activated === false && self.activated) {
Entities.editEntity(self.paintStream, { self.letGo();
animationSettings: stopSetting
});
self.activated = false;
} }
} }
this.grab = function() { this.grab = function() {
self.activated = true; this.activated = true;
var animationSettings = JSON.stringify({ var animationSettings = JSON.stringify({
fps: 30, fps: 30,
loop: true, loop: true,
@ -92,9 +88,9 @@
emitVelocity: ZERO_VEC, emitVelocity: ZERO_VEC,
emitAcceleration: ZERO_VEC, emitAcceleration: ZERO_VEC,
velocitySpread: { velocitySpread: {
x: .02, x: .1,
y: .02, y: .1,
z: 0.02 z: 0.1
}, },
emitRate: 100, emitRate: 100,
particleRadius: 0.01, particleRadius: 0.01,
@ -103,14 +99,14 @@
green: 20, green: 20,
blue: 150 blue: 150
}, },
lifetime: 500, //probably wont be holding longer than this straight lifetime: 50, //probably wont be holding longer than this straight
}); });
} }
this.letGo = function() { this.letGo = function() {
self.activated = false; this.activated = false;
Entities.deleteEntity(this.paintStream); Entities.deleteEntity(this.paintStream);
this.paintStream = null;
} }
this.reset = function() { this.reset = function() {
@ -123,8 +119,7 @@
} }
this.sprayStream = function() { this.sprayStream = function() {
var forwardVec = Quat.getFront(self.properties.rotation); var forwardVec = Quat.getFront(Quat.multiply(self.properties.rotation , Quat.fromPitchYawRollDegrees(0, 90, 0)));
forwardVec = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 90, 0), forwardVec);
forwardVec = Vec3.normalize(forwardVec); forwardVec = Vec3.normalize(forwardVec);
var upVec = Quat.getUp(self.properties.rotation); var upVec = Quat.getUp(self.properties.rotation);
@ -132,11 +127,10 @@
position = Vec3.sum(position, Vec3.multiply(upVec, TIP_OFFSET_Y)) position = Vec3.sum(position, Vec3.multiply(upVec, TIP_OFFSET_Y))
Entities.editEntity(self.paintStream, { Entities.editEntity(self.paintStream, {
position: position, position: position,
emitVelocity: Vec3.multiply(forwardVec, 4) emitVelocity: Vec3.multiply(5, forwardVec)
}); });
//Now check for an intersection with an entity //Now check for an intersection with an entity
//move forward so ray doesnt intersect with gun //move forward so ray doesnt intersect with gun
var origin = Vec3.sum(position, forwardVec); var origin = Vec3.sum(position, forwardVec);
var pickRay = { var pickRay = {
@ -216,6 +210,8 @@
this.entityId = entityId; this.entityId = entityId;
this.properties = Entities.getEntityProperties(self.entityId); this.properties = Entities.getEntityProperties(self.entityId);
this.getUserData(); this.getUserData();
//Only activate for the avatar who is grabbing the can!
if (this.userData.grabKey && this.userData.grabKey.activated) { if (this.userData.grabKey && this.userData.grabKey.activated) {
this.activated = true; this.activated = true;
} }
@ -235,7 +231,9 @@
this.unload = function() { this.unload = function() {
Script.update.disconnect(this.update); Script.update.disconnect(this.update);
Entities.deleteEntity(this.paintStream); if(this.paintStream) {
Entities.deleteEntity(this.paintStream);
}
this.strokes.forEach(function(stroke) { this.strokes.forEach(function(stroke) {
Entities.deleteEntity(stroke); Entities.deleteEntity(stroke);
}); });
@ -244,6 +242,7 @@
}); });
function randFloat(min, max) { function randFloat(min, max) {
return Math.random() * (max - min) + min; return Math.random() * (max - min) + min;
} }

View file

@ -9,9 +9,9 @@
// 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
//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 //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 scriptURL = "https://hifi-public.s3.amazonaws.com/eric/scripts/sprayPaintCan.js?=v6 ";
var scriptURL = Script.resolvePath("entityScripts/sprayPaintCan.js?v2");
var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; 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 sprayCan = Entities.addEntity({ var sprayCan = Entities.addEntity({
type: "Model", type: "Model",
@ -32,7 +32,10 @@ var sprayCan = Entities.addEntity({
}); });
function cleanup() { function cleanup() {
Entities.deleteEntity(sprayCan);
// Uncomment the below line to delete sprayCan on script reload- for faster iteration during development
// Entities.deleteEntity(sprayCan);
} }
Script.scriptEnding.connect(cleanup); Script.scriptEnding.connect(cleanup);