From ebeedb5cdefc42ab163b5eef07b4c4b2eec90b59 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Sat, 5 Sep 2015 22:05:53 -0700 Subject: [PATCH] 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,