From ebeedb5cdefc42ab163b5eef07b4c4b2eec90b59 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sat, 5 Sep 2015 22:05:53 -0700 Subject: [PATCH 1/3] work on moving dancers to center of table if it's present --- examples/entityScripts/breakdanceEntity.js | 3 +- examples/toys/breakdanceCore.js | 68 ++++++++++++++++++++-- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/examples/entityScripts/breakdanceEntity.js b/examples/entityScripts/breakdanceEntity.js index 40918bd65f..ece3e57062 100644 --- a/examples/entityScripts/breakdanceEntity.js +++ b/examples/entityScripts/breakdanceEntity.js @@ -50,7 +50,8 @@ // remember we're being grabbed so we can detect being released _this.beingGrabbed = true; var props = Entities.getEntityProperties(entityID); - breakdanceStart(props.modelURL, props.position); + var puppetPosition = getPuppetPosition(props); + breakdanceStart(props.modelURL, puppetPosition); print("I'm was grabbed..."); } else { breakdanceUpdate(); diff --git a/examples/toys/breakdanceCore.js b/examples/toys/breakdanceCore.js index dd7f989c1c..eeb4e137a2 100644 --- a/examples/toys/breakdanceCore.js +++ b/examples/toys/breakdanceCore.js @@ -11,7 +11,63 @@ // -function getPositionPuppet() { +function getPuppetPosition(props) { + print ("getPuppetPosition..."); + var MAX_DISTANCE = 10; + var searchPosition = MyAvatar.position; + +print ("getPuppetPosition... line: A" ); + + if (props !== undefined && props.position !== undefined) { + searchPosition = props.position; + } + +print ("getPuppetPosition... line: B"); + + // first look for the "Table 1" entity +Vec3.print("searchPosition:", searchPosition); + + var ids = Entities.findEntities(searchPosition, MAX_DISTANCE); + +print ("getPuppetPosition... line: C"); +print("ids:"+ ids.toString()); + + for (var i in ids) { + +print("i:"+ i); + var entityId = ids[i]; + +print ("findEntities entityId:" + entityId); + + var foundProps = Entities.getEntityProperties(entityId); + print ("foundProps.name:" + foundProps.name); + + if (foundProps.name == "Table 1") { + Vec3.print("foundProps.center:", foundProps.boundingBox.center); + + position = foundProps.boundingBox.center; + + position.y += foundProps.boundingBox.dimensions.y / 2; + + Vec3.print("found table 1 center, position:", position); + +print ("getPuppetPosition... line: D"); + + Vec3.print("found table 1 center, position:", position); + + return position; + } + } + +print ("getPuppetPosition... line: E"); + + if (props !== undefined && props.position !== undefined) { + Vec3.print("props.position:", props.position); + return props.position; + } + +print ("getPuppetPosition... line: F"); + var DISTANCE_IN_FRONT = 2; var DISTANCE_UP = 0.4; var DISTANCE_TO_SIDE = 0.0; @@ -27,11 +83,14 @@ function getPositionPuppet() { var offset = Vec3.sum(Vec3.sum(leftOffset, frontOffset), upOffset); var position = Vec3.sum(MyAvatar.position, offset); + + Vec3.print("default, position:", position); + +print ("getPuppetPosition... line: G"); + return position; } - - function getPositionLeftFront() { var DISTANCE_IN_FRONT = 0.6; var DISTANCE_UP = 0.4; @@ -363,11 +422,12 @@ function createPuppet(model, location) { model = "https://hifi-public.s3.amazonaws.com/models/Bboys/bboy1/bboy1.fbx"; } if (location == undefined) { - location = getPositionPuppet(); + location = getPuppetPosition(); } puppetEntityID = Entities.addEntity({ type: "Model", modelURL: model, + registrationPoint: { x: 0.5, y: 0, z: 0.5 }, animationURL: "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx", animationSettings: ANIMATION_SETTINGS, position: location, From 781f19c9e384a32e394b64af278db1dcd34bd633 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Tue, 8 Sep 2015 12:27:24 -0700 Subject: [PATCH 2/3] position the puppet on level of nearby table --- examples/toys/breakdanceCore.js | 46 ++++++++++----------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/examples/toys/breakdanceCore.js b/examples/toys/breakdanceCore.js index eeb4e137a2..57a679ff51 100644 --- a/examples/toys/breakdanceCore.js +++ b/examples/toys/breakdanceCore.js @@ -12,62 +12,46 @@ function getPuppetPosition(props) { - print ("getPuppetPosition..."); var MAX_DISTANCE = 10; var searchPosition = MyAvatar.position; -print ("getPuppetPosition... line: A" ); - if (props !== undefined && props.position !== undefined) { searchPosition = props.position; } -print ("getPuppetPosition... line: B"); - // first look for the "Table 1" entity -Vec3.print("searchPosition:", searchPosition); - var ids = Entities.findEntities(searchPosition, MAX_DISTANCE); -print ("getPuppetPosition... line: C"); -print("ids:"+ ids.toString()); - for (var i in ids) { - -print("i:"+ i); var entityId = ids[i]; - -print ("findEntities entityId:" + entityId); - var foundProps = Entities.getEntityProperties(entityId); - print ("foundProps.name:" + foundProps.name); - if (foundProps.name == "Table 1") { - Vec3.print("foundProps.center:", foundProps.boundingBox.center); + // we want to keep the puppet to be bound to the x/z bouds of the table + // and placed at the top of the table suface. But we want to generally position + // the puppet at the x/z of where the toy was grabbed. - position = foundProps.boundingBox.center; + var minX = foundProps.boundingBox.brn.x + (props.dimensions.x / 2); + var maxX = foundProps.boundingBox.tfl.x - (props.dimensions.x / 2); + var minZ = foundProps.boundingBox.brn.z + (props.dimensions.z / 2); + var maxZ = foundProps.boundingBox.tfl.z - (props.dimensions.z / 2); - position.y += foundProps.boundingBox.dimensions.y / 2; + var bestX = Math.min(maxX, Math.max(props.position.x, minX)); + var bestZ = Math.min(maxZ, Math.max(props.position.z, minZ)); - Vec3.print("found table 1 center, position:", position); + // Adjust the position to be the "top" of the table. Note: this assumes the table has registrationPoint of 0.5 + // this also assumes the table hasn't been rotated in such a manner that the table top isn't flat + var bestY = foundProps.boundingBox.center.y + (foundProps.boundingBox.dimensions.y / 2); -print ("getPuppetPosition... line: D"); - - Vec3.print("found table 1 center, position:", position); + position = { x: bestX, y: bestY, z: bestZ }; return position; } } -print ("getPuppetPosition... line: E"); - if (props !== undefined && props.position !== undefined) { - Vec3.print("props.position:", props.position); return props.position; } -print ("getPuppetPosition... line: F"); - var DISTANCE_IN_FRONT = 2; var DISTANCE_UP = 0.4; var DISTANCE_TO_SIDE = 0.0; @@ -84,10 +68,6 @@ print ("getPuppetPosition... line: F"); var offset = Vec3.sum(Vec3.sum(leftOffset, frontOffset), upOffset); var position = Vec3.sum(MyAvatar.position, offset); - Vec3.print("default, position:", position); - -print ("getPuppetPosition... line: G"); - return position; } From 717cbf3d5b2f98561b3c976e5b27760fed018724 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Sep 2015 16:13:17 -0700 Subject: [PATCH 3/3] handControllerGrab.js is active by default --- examples/defaultScripts.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index 44801ef737..4cb98a5df5 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -14,6 +14,7 @@ Script.load("selectAudioDevice.js"); Script.load("inspect.js"); Script.load("notifications.js"); Script.load("users.js"); +Script.load("handControllerGrab.js"); Script.load("grab.js"); Script.load("directory.js"); Script.load("dialTone.js");