2015-08-27 15:12:23 -07:00
//
2015-09-03 14:33:25 -07:00
// breakdanceCore.js
2015-08-27 15:12:23 -07:00
//
2015-09-03 14:33:25 -07:00
// This is the core breakdance game library, it can be used as part of an entity script, or an omniTool module, or bootstapped on it's own
2015-08-27 15:12:23 -07:00
// Created by Brad Hefta-Gaub on August 24, 2015
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
2015-09-09 12:41:59 -07:00
getPuppetPosition = function ( props ) {
2015-09-05 22:05:53 -07:00
var MAX _DISTANCE = 10 ;
var searchPosition = MyAvatar . position ;
if ( props !== undefined && props . position !== undefined ) {
searchPosition = props . position ;
}
// first look for the "Table 1" entity
var ids = Entities . findEntities ( searchPosition , MAX _DISTANCE ) ;
for ( var i in ids ) {
var entityId = ids [ i ] ;
var foundProps = Entities . getEntityProperties ( entityId ) ;
if ( foundProps . name == "Table 1" ) {
2015-09-08 12:27:24 -07:00
// 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.
2015-09-05 22:05:53 -07:00
2015-09-08 12:27:24 -07:00
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 ) ;
2015-09-05 22:05:53 -07:00
2015-09-08 12:27:24 -07:00
var bestX = Math . min ( maxX , Math . max ( props . position . x , minX ) ) ;
var bestZ = Math . min ( maxZ , Math . max ( props . position . z , minZ ) ) ;
2015-09-05 22:05:53 -07:00
2015-09-08 12:27:24 -07:00
// 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 ) ;
2015-09-05 22:05:53 -07:00
2015-09-08 12:27:24 -07:00
position = { x : bestX , y : bestY , z : bestZ } ;
2015-09-05 22:05:53 -07:00
return position ;
}
}
if ( props !== undefined && props . position !== undefined ) {
return props . position ;
}
2015-08-27 15:12:23 -07:00
var DISTANCE _IN _FRONT = 2 ;
var DISTANCE _UP = 0.4 ;
var DISTANCE _TO _SIDE = 0.0 ;
var up = Quat . getUp ( MyAvatar . orientation ) ;
var front = Quat . getFront ( MyAvatar . orientation ) ;
var right = Quat . getRight ( MyAvatar . orientation ) ;
var left = Vec3 . multiply ( right , - 1 ) ;
var upOffset = Vec3 . multiply ( up , DISTANCE _UP ) ;
var leftOffset = Vec3 . multiply ( left , DISTANCE _TO _SIDE ) ;
var frontOffset = Vec3 . multiply ( front , DISTANCE _IN _FRONT ) ;
var offset = Vec3 . sum ( Vec3 . sum ( leftOffset , frontOffset ) , upOffset ) ;
var position = Vec3 . sum ( MyAvatar . position , offset ) ;
2015-09-05 22:05:53 -07:00
return position ;
}
2015-08-27 15:12:23 -07:00
function getPositionLeftFront ( ) {
var DISTANCE _IN _FRONT = 0.6 ;
var DISTANCE _UP = 0.4 ;
var DISTANCE _TO _SIDE = 0.3 ;
var up = Quat . getUp ( MyAvatar . orientation ) ;
var front = Quat . getFront ( MyAvatar . orientation ) ;
var right = Quat . getRight ( MyAvatar . orientation ) ;
var left = Vec3 . multiply ( right , - 1 ) ;
var upOffset = Vec3 . multiply ( up , DISTANCE _UP ) ;
var leftOffset = Vec3 . multiply ( left , DISTANCE _TO _SIDE ) ;
var frontOffset = Vec3 . multiply ( front , DISTANCE _IN _FRONT ) ;
var offset = Vec3 . sum ( Vec3 . sum ( leftOffset , frontOffset ) , upOffset ) ;
var position = Vec3 . sum ( MyAvatar . position , offset ) ;
return position ;
}
function getPositionLeftSide ( ) {
var DISTANCE _IN _FRONT = 0.0 ;
var DISTANCE _UP = 0.5 ;
var DISTANCE _TO _SIDE = 0.9 ;
var up = Quat . getUp ( MyAvatar . orientation ) ;
var front = Quat . getFront ( MyAvatar . orientation ) ;
var right = Quat . getRight ( MyAvatar . orientation ) ;
var left = Vec3 . multiply ( right , - 1 ) ;
var upOffset = Vec3 . multiply ( up , DISTANCE _UP ) ;
var leftOffset = Vec3 . multiply ( left , DISTANCE _TO _SIDE ) ;
var frontOffset = Vec3 . multiply ( front , DISTANCE _IN _FRONT ) ;
var offset = Vec3 . sum ( Vec3 . sum ( leftOffset , frontOffset ) , upOffset ) ;
var position = Vec3 . sum ( MyAvatar . position , offset ) ;
return position ;
}
function getPositionLeftOverhead ( ) {
var DISTANCE _IN _FRONT = 0.2 ;
var DISTANCE _UP = 1 ;
var DISTANCE _TO _SIDE = 0.3 ;
var up = Quat . getUp ( MyAvatar . orientation ) ;
var front = Quat . getFront ( MyAvatar . orientation ) ;
var right = Quat . getRight ( MyAvatar . orientation ) ;
var left = Vec3 . multiply ( right , - 1 ) ;
var upOffset = Vec3 . multiply ( up , DISTANCE _UP ) ;
var leftOffset = Vec3 . multiply ( left , DISTANCE _TO _SIDE ) ;
var frontOffset = Vec3 . multiply ( front , DISTANCE _IN _FRONT ) ;
var offset = Vec3 . sum ( Vec3 . sum ( leftOffset , frontOffset ) , upOffset ) ;
var position = Vec3 . sum ( MyAvatar . position , offset ) ;
return position ;
}
function getPositionLeftLowered ( ) {
var DISTANCE _IN _FRONT = 0.2 ;
var DISTANCE _DOWN = 0.1 ;
var DISTANCE _TO _SIDE = 0.3 ;
var up = Quat . getUp ( MyAvatar . orientation ) ;
var front = Quat . getFront ( MyAvatar . orientation ) ;
var right = Quat . getRight ( MyAvatar . orientation ) ;
var left = Vec3 . multiply ( right , - 1 ) ;
var downOffset = Vec3 . multiply ( up , DISTANCE _DOWN ) ;
var leftOffset = Vec3 . multiply ( left , DISTANCE _TO _SIDE ) ;
var frontOffset = Vec3 . multiply ( front , DISTANCE _IN _FRONT ) ;
var offset = Vec3 . sum ( Vec3 . sum ( leftOffset , frontOffset ) , downOffset ) ;
var position = Vec3 . sum ( MyAvatar . position , offset ) ;
return position ;
}
function getPositionLeftOnBase ( ) {
var DISTANCE _IN _FRONT = 0.2 ;
var DISTANCE _DOWN = - 0.4 ;
var DISTANCE _TO _SIDE = 0.3 ;
var up = Quat . getUp ( MyAvatar . orientation ) ;
var front = Quat . getFront ( MyAvatar . orientation ) ;
var right = Quat . getRight ( MyAvatar . orientation ) ;
var left = Vec3 . multiply ( right , - 1 ) ;
var downOffset = Vec3 . multiply ( up , DISTANCE _DOWN ) ;
var leftOffset = Vec3 . multiply ( left , DISTANCE _TO _SIDE ) ;
var frontOffset = Vec3 . multiply ( front , DISTANCE _IN _FRONT ) ;
var offset = Vec3 . sum ( Vec3 . sum ( leftOffset , frontOffset ) , downOffset ) ;
var position = Vec3 . sum ( MyAvatar . position , offset ) ;
return position ;
}
function getPositionRightFront ( ) {
var DISTANCE _IN _FRONT = 0.6 ;
var DISTANCE _UP = 0.4 ;
var DISTANCE _TO _SIDE = 0.3 ;
var up = Quat . getUp ( MyAvatar . orientation ) ;
var front = Quat . getFront ( MyAvatar . orientation ) ;
var right = Quat . getRight ( MyAvatar . orientation ) ;
var upOffset = Vec3 . multiply ( up , DISTANCE _UP ) ;
var rightOffset = Vec3 . multiply ( right , DISTANCE _TO _SIDE ) ;
var frontOffset = Vec3 . multiply ( front , DISTANCE _IN _FRONT ) ;
var offset = Vec3 . sum ( Vec3 . sum ( rightOffset , frontOffset ) , upOffset ) ;
var position = Vec3 . sum ( MyAvatar . position , offset ) ;
return position ;
}
function getPositionRightSide ( ) {
var DISTANCE _IN _FRONT = 0.0 ;
var DISTANCE _UP = 0.5 ;
var DISTANCE _TO _SIDE = 0.9 ;
var up = Quat . getUp ( MyAvatar . orientation ) ;
var front = Quat . getFront ( MyAvatar . orientation ) ;
var right = Quat . getRight ( MyAvatar . orientation ) ;
var upOffset = Vec3 . multiply ( up , DISTANCE _UP ) ;
var rightOffset = Vec3 . multiply ( right , DISTANCE _TO _SIDE ) ;
var frontOffset = Vec3 . multiply ( front , DISTANCE _IN _FRONT ) ;
var offset = Vec3 . sum ( Vec3 . sum ( rightOffset , frontOffset ) , upOffset ) ;
var position = Vec3 . sum ( MyAvatar . position , offset ) ;
return position ;
}
function getPositionRightOverhead ( ) {
var DISTANCE _IN _FRONT = 0.2 ;
var DISTANCE _UP = 1 ;
var DISTANCE _TO _SIDE = 0.3 ;
var up = Quat . getUp ( MyAvatar . orientation ) ;
var front = Quat . getFront ( MyAvatar . orientation ) ;
var right = Quat . getRight ( MyAvatar . orientation ) ;
var upOffset = Vec3 . multiply ( up , DISTANCE _UP ) ;
var rightOffset = Vec3 . multiply ( right , DISTANCE _TO _SIDE ) ;
var frontOffset = Vec3 . multiply ( front , DISTANCE _IN _FRONT ) ;
var offset = Vec3 . sum ( Vec3 . sum ( rightOffset , frontOffset ) , upOffset ) ;
var position = Vec3 . sum ( MyAvatar . position , offset ) ;
return position ;
}
function getPositionRightLowered ( ) {
var DISTANCE _IN _FRONT = 0.2 ;
var DISTANCE _DOWN = 0.1 ;
var DISTANCE _TO _SIDE = 0.3 ;
var up = Quat . getUp ( MyAvatar . orientation ) ;
var front = Quat . getFront ( MyAvatar . orientation ) ;
var right = Quat . getRight ( MyAvatar . orientation ) ;
var downOffset = Vec3 . multiply ( up , DISTANCE _DOWN ) ;
var rightOffset = Vec3 . multiply ( right , DISTANCE _TO _SIDE ) ;
var frontOffset = Vec3 . multiply ( front , DISTANCE _IN _FRONT ) ;
var offset = Vec3 . sum ( Vec3 . sum ( rightOffset , frontOffset ) , downOffset ) ;
var position = Vec3 . sum ( MyAvatar . position , offset ) ;
return position ;
}
function getPositionRightOnBase ( ) {
var DISTANCE _IN _FRONT = 0.2 ;
var DISTANCE _DOWN = - 0.4 ;
var DISTANCE _TO _SIDE = 0.3 ;
var up = Quat . getUp ( MyAvatar . orientation ) ;
var front = Quat . getFront ( MyAvatar . orientation ) ;
var right = Quat . getRight ( MyAvatar . orientation ) ;
var downOffset = Vec3 . multiply ( up , DISTANCE _DOWN ) ;
var rightOffset = Vec3 . multiply ( right , DISTANCE _TO _SIDE ) ;
var frontOffset = Vec3 . multiply ( front , DISTANCE _IN _FRONT ) ;
var offset = Vec3 . sum ( Vec3 . sum ( rightOffset , frontOffset ) , downOffset ) ;
var position = Vec3 . sum ( MyAvatar . position , offset ) ;
return position ;
}
2015-09-03 14:33:25 -07:00
// some globals we will need access to
var HAND _SIZE = 0.25 ;
var TARGET _SIZE = 0.3 ;
var TARGET _COLOR = { red : 128 , green : 128 , blue : 128 } ;
var TARGET _COLOR _HIT = { red : 0 , green : 255 , blue : 0 } ;
2015-08-27 15:12:23 -07:00
2015-09-03 14:33:25 -07:00
var textOverlay , leftHandOverlay , rightHandOverlay ,
leftOnBaseOverlay , leftLoweredOverlay , leftOverheadOverlay , leftSideOverlay , leftFrontOverlay ,
rightOnBaseOverlay , rightLoweredOverlay , rightOverheadOverlay , rightSideOverlay , rightFrontOverlay ;
function createOverlays ( ) {
textOverlay = Overlays . addOverlay ( "text" , {
2015-08-27 15:12:23 -07:00
x : 100 ,
y : 300 ,
width : 900 ,
height : 50 ,
backgroundColor : { red : 0 , green : 0 , blue : 0 } ,
color : { red : 255 , green : 255 , blue : 255 } ,
topMargin : 4 ,
leftMargin : 4 ,
text : "POSE..." ,
alpha : 1 ,
backgroundAlpha : 0.5
} ) ;
2015-09-03 14:33:25 -07:00
leftHandOverlay = Overlays . addOverlay ( "cube" , {
position : MyAvatar . getLeftPalmPosition ( ) ,
size : HAND _SIZE ,
2015-08-27 15:12:23 -07:00
color : { red : 0 , green : 0 , blue : 255 } ,
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
rightHandOverlay = Overlays . addOverlay ( "cube" , {
position : MyAvatar . getRightPalmPosition ( ) ,
size : HAND _SIZE ,
2015-08-27 15:12:23 -07:00
color : { red : 255 , green : 0 , blue : 0 } ,
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
leftOnBaseOverlay = Overlays . addOverlay ( "cube" , {
2015-08-27 15:12:23 -07:00
position : getPositionLeftOnBase ( ) ,
2015-09-03 14:33:25 -07:00
size : TARGET _SIZE ,
color : TARGET _COLOR ,
2015-08-27 15:12:23 -07:00
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
leftLoweredOverlay = Overlays . addOverlay ( "cube" , {
2015-08-27 15:12:23 -07:00
position : getPositionLeftLowered ( ) ,
2015-09-03 14:33:25 -07:00
size : TARGET _SIZE ,
color : TARGET _COLOR ,
2015-08-27 15:12:23 -07:00
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
leftOverheadOverlay = Overlays . addOverlay ( "cube" , {
2015-08-27 15:12:23 -07:00
position : getPositionLeftOverhead ( ) ,
2015-09-03 14:33:25 -07:00
size : TARGET _SIZE ,
color : TARGET _COLOR ,
2015-08-27 15:12:23 -07:00
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
leftSideOverlay = Overlays . addOverlay ( "cube" , {
2015-08-27 15:12:23 -07:00
position : getPositionLeftSide ( ) ,
2015-09-03 14:33:25 -07:00
size : TARGET _SIZE ,
color : TARGET _COLOR ,
2015-08-27 15:12:23 -07:00
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
leftFrontOverlay = Overlays . addOverlay ( "cube" , {
2015-08-27 15:12:23 -07:00
position : getPositionLeftFront ( ) ,
2015-09-03 14:33:25 -07:00
size : TARGET _SIZE ,
color : TARGET _COLOR ,
2015-08-27 15:12:23 -07:00
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
rightOnBaseOverlay = Overlays . addOverlay ( "cube" , {
2015-08-27 15:12:23 -07:00
position : getPositionRightOnBase ( ) ,
2015-09-03 14:33:25 -07:00
size : TARGET _SIZE ,
color : TARGET _COLOR ,
2015-08-27 15:12:23 -07:00
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
rightLoweredOverlay = Overlays . addOverlay ( "cube" , {
2015-08-27 15:12:23 -07:00
position : getPositionRightLowered ( ) ,
2015-09-03 14:33:25 -07:00
size : TARGET _SIZE ,
color : TARGET _COLOR ,
2015-08-27 15:12:23 -07:00
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
rightOverheadOverlay = Overlays . addOverlay ( "cube" , {
2015-08-27 15:12:23 -07:00
position : getPositionRightOverhead ( ) ,
2015-09-03 14:33:25 -07:00
size : TARGET _SIZE ,
color : TARGET _COLOR ,
2015-08-27 15:12:23 -07:00
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
rightSideOverlay = Overlays . addOverlay ( "cube" , {
2015-08-27 15:12:23 -07:00
position : getPositionRightSide ( ) ,
2015-09-03 14:33:25 -07:00
size : TARGET _SIZE ,
color : TARGET _COLOR ,
2015-08-27 15:12:23 -07:00
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
rightFrontOverlay = Overlays . addOverlay ( "cube" , {
2015-08-27 15:12:23 -07:00
position : getPositionRightFront ( ) ,
2015-09-03 14:33:25 -07:00
size : TARGET _SIZE ,
color : TARGET _COLOR ,
2015-08-27 15:12:23 -07:00
alpha : 1 ,
solid : false
} ) ;
2015-09-03 14:33:25 -07:00
}
2015-08-27 15:12:23 -07:00
2015-09-03 14:33:25 -07:00
var TEMPORARY _LIFETIME = 60 ;
2015-10-02 14:17:01 -07:00
var ANIMATION _SETTINGS = {
url : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" ,
2015-09-03 14:33:25 -07:00
fps : 30 ,
running : true ,
loop : true ,
firstFrame : 1 ,
lastFrame : 10000
2015-10-02 14:17:01 -07:00
} ;
2015-09-03 14:33:25 -07:00
var NATURAL _DIMENSIONS = { x : 1.63 , y : 1.67 , z : 0.31 } ;
var DIMENSIONS = Vec3 . multiply ( NATURAL _DIMENSIONS , 0.3 ) ;
var puppetEntityID ;
2015-09-04 16:20:12 -07:00
function createPuppet ( model , location ) {
if ( model === undefined ) {
model = "https://hifi-public.s3.amazonaws.com/models/Bboys/bboy1/bboy1.fbx" ;
}
if ( location == undefined ) {
2015-09-05 22:05:53 -07:00
location = getPuppetPosition ( ) ;
2015-09-04 16:20:12 -07:00
}
2015-09-03 14:33:25 -07:00
puppetEntityID = Entities . addEntity ( {
type : "Model" ,
2015-09-04 16:20:12 -07:00
modelURL : model ,
2015-09-05 22:05:53 -07:00
registrationPoint : { x : 0.5 , y : 0 , z : 0.5 } ,
2015-10-02 14:17:01 -07:00
animation : ANIMATION _SETTINGS ,
2015-09-04 16:20:12 -07:00
position : location ,
2016-01-18 13:29:23 -08:00
collisionless : true ,
2015-09-03 14:33:25 -07:00
dimensions : DIMENSIONS ,
lifetime : TEMPORARY _LIFETIME
} ) ;
}
2015-08-27 15:12:23 -07:00
var NO _POSE = 0 ;
var LEFT _ON _BASE = 1 ;
var LEFT _OVERHEAD = 2 ;
var LEFT _LOWERED = 4 ;
var LEFT _SIDE = 8 ;
var LEFT _FRONT = 16 ;
var RIGHT _ON _BASE = 32 ;
var RIGHT _OVERHEAD = 64 ;
var RIGHT _LOWERED = 128 ;
var RIGHT _SIDE = 256 ;
var RIGHT _FRONT = 512 ;
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/bboy_pose_to_idle.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/bboy_uprock.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/bboy_uprock_start.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_footwork_1.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_footwork_2.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_footwork_3.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_footwork_to_freeze.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_footwork_to_idle.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_freeze_var_1.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_freeze_var_2.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_freeze_var_3.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_freeze_var_4.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_freezes.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_swipes.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_uprock.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_uprock_var_1.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_uprock_var_1_end.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_uprock_var_1_start.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_uprock_var_2.fbx
//http://s3.amazonaws.com/hifi-public/animations/Breakdancing/flair.fbx
var poses = Array ( ) ;
/ *
poses [ 0 ] = { name : "no pose" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _OVERHEAD ] = { name : "Left Overhead" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _LOWERED ] = { name : "Left Lowered" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _SIDE ] = { name : "Left Side" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _FRONT ] = { name : "Left Front" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ RIGHT _OVERHEAD ] = { name : "Right Overhead" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ RIGHT _LOWERED ] = { name : "Right Lowered" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ RIGHT _SIDE ] = { name : "Right Side" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ RIGHT _FRONT ] = { name : "Right Front" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
* /
poses [ LEFT _ON _BASE + RIGHT _ON _BASE ] = { name : "Left On Base + Right On Base" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _OVERHEAD + RIGHT _ON _BASE ] = { name : "Left Overhead + Right On Base" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _LOWERED + RIGHT _ON _BASE ] = { name : "Left Lowered + Right On Base" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _SIDE + RIGHT _ON _BASE ] = { name : "Left Side + Right On Base" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _FRONT + RIGHT _ON _BASE ] = { name : "Left Front + Right On Base" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _ON _BASE + RIGHT _OVERHEAD ] = { name : "Left On Base + Right Overhead" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _ON _BASE + RIGHT _LOWERED ] = { name : "Left On Base + Right Lowered" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _ON _BASE + RIGHT _SIDE ] = { name : "Left On Base + Right Side" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _ON _BASE + RIGHT _FRONT ] = { name : "Left On Base + Right Front" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_ready.fbx" } ;
poses [ LEFT _OVERHEAD + RIGHT _OVERHEAD ] = { name : "Left Overhead + Right Overhead" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/bboy_uprock.fbx" } ;
poses [ LEFT _LOWERED + RIGHT _OVERHEAD ] = { name : "Left Lowered + Right Overhead" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_footwork_1.fbx" } ;
poses [ LEFT _SIDE + RIGHT _OVERHEAD ] = { name : "Left Side + Right Overhead" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_footwork_2.fbx" } ;
poses [ LEFT _FRONT + RIGHT _OVERHEAD ] = { name : "Left Front + Right Overhead" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_footwork_3.fbx" } ;
poses [ LEFT _OVERHEAD + RIGHT _LOWERED ] = { name : "Left Overhead + Right Lowered" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_footwork_to_freeze.fbx" } ;
poses [ LEFT _LOWERED + RIGHT _LOWERED ] = { name : "Left Lowered + Right Lowered" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_footwork_to_idle.fbx" } ;
poses [ LEFT _SIDE + RIGHT _LOWERED ] = { name : "Left Side + Right Lowered" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_freeze_var_1.fbx" } ;
poses [ LEFT _FRONT + RIGHT _LOWERED ] = { name : "Left Front + Right Lowered" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_freeze_var_2.fbx" } ;
poses [ LEFT _OVERHEAD + RIGHT _SIDE ] = { name : "Left Overhead + Right Side" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_freeze_var_3.fbx" } ;
poses [ LEFT _LOWERED + RIGHT _SIDE ] = { name : "Left Lowered + Right Side" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_freeze_var_4.fbx" } ;
poses [ LEFT _SIDE + RIGHT _SIDE ] = { name : "Left Side + Right Side" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_freezes.fbx" } ;
poses [ LEFT _FRONT + RIGHT _SIDE ] = { name : "Left Front + Right Side" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_swipes.fbx" } ;
poses [ LEFT _OVERHEAD + RIGHT _FRONT ] = { name : "Left Overhead + Right Front" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_uprock.fbx" } ;
poses [ LEFT _LOWERED + RIGHT _FRONT ] = { name : "Left Lowered + Right Front" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_uprock_var_1.fbx" } ;
poses [ LEFT _SIDE + RIGHT _FRONT ] = { name : "Left Side + Right Front" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_uprock_var_2.fbx" } ;
poses [ LEFT _FRONT + RIGHT _FRONT ] = { name : "Left Front + Right Front" , animation : "http://s3.amazonaws.com/hifi-public/animations/Breakdancing/breakdance_uprock_var_1_end.fbx" } ;
2015-09-04 16:20:12 -07:00
breakdanceStart = function ( model , location ) {
2015-09-03 14:33:25 -07:00
print ( "breakdanceStart..." ) ;
createOverlays ( ) ;
2015-09-04 16:20:12 -07:00
createPuppet ( model , location ) ;
2015-09-03 14:33:25 -07:00
}
breakdanceUpdate = function ( deltaTime ) {
//print("breakdanceUpdate...");
2015-08-27 15:12:23 -07:00
var leftHandPos = MyAvatar . getLeftPalmPosition ( ) ;
var rightHandPos = MyAvatar . getRightPalmPosition ( ) ;
2015-09-03 14:33:25 -07:00
Overlays . editOverlay ( leftHandOverlay , { position : leftHandPos } ) ;
Overlays . editOverlay ( rightHandOverlay , { position : rightHandPos } ) ;
2015-08-27 15:12:23 -07:00
2015-09-03 14:33:25 -07:00
var hitTargetLeftOnBase = findSphereSphereHit ( leftHandPos , HAND _SIZE / 2 , getPositionLeftOnBase ( ) , TARGET _SIZE / 2 ) ;
var hitTargetLeftOverhead = findSphereSphereHit ( leftHandPos , HAND _SIZE / 2 , getPositionLeftOverhead ( ) , TARGET _SIZE / 2 ) ;
var hitTargetLeftLowered = findSphereSphereHit ( leftHandPos , HAND _SIZE / 2 , getPositionLeftLowered ( ) , TARGET _SIZE / 2 ) ;
var hitTargetLeftSide = findSphereSphereHit ( leftHandPos , HAND _SIZE / 2 , getPositionLeftSide ( ) , TARGET _SIZE / 2 ) ;
var hitTargetLeftFront = findSphereSphereHit ( leftHandPos , HAND _SIZE / 2 , getPositionLeftFront ( ) , TARGET _SIZE / 2 ) ;
2015-08-27 15:12:23 -07:00
2015-09-03 14:33:25 -07:00
var hitTargetRightOnBase = findSphereSphereHit ( rightHandPos , HAND _SIZE / 2 , getPositionRightOnBase ( ) , TARGET _SIZE / 2 ) ;
var hitTargetRightOverhead = findSphereSphereHit ( rightHandPos , HAND _SIZE / 2 , getPositionRightOverhead ( ) , TARGET _SIZE / 2 ) ;
var hitTargetRightLowered = findSphereSphereHit ( rightHandPos , HAND _SIZE / 2 , getPositionRightLowered ( ) , TARGET _SIZE / 2 ) ;
var hitTargetRightSide = findSphereSphereHit ( rightHandPos , HAND _SIZE / 2 , getPositionRightSide ( ) , TARGET _SIZE / 2 ) ;
var hitTargetRightFront = findSphereSphereHit ( rightHandPos , HAND _SIZE / 2 , getPositionRightFront ( ) , TARGET _SIZE / 2 ) ;
2015-08-27 15:12:23 -07:00
// determine target colors
2015-09-03 14:33:25 -07:00
var targetColorLeftOnBase = hitTargetLeftOnBase ? TARGET _COLOR _HIT : TARGET _COLOR ;
var targetColorLeftOverhead = hitTargetLeftOverhead ? TARGET _COLOR _HIT : TARGET _COLOR ;
var targetColorLeftLowered = hitTargetLeftLowered ? TARGET _COLOR _HIT : TARGET _COLOR ;
var targetColorLeftSide = hitTargetLeftSide ? TARGET _COLOR _HIT : TARGET _COLOR ;
var targetColorLeftFront = hitTargetLeftFront ? TARGET _COLOR _HIT : TARGET _COLOR ;
var targetColorRightOnBase = hitTargetRightOnBase ? TARGET _COLOR _HIT : TARGET _COLOR ;
var targetColorRightOverhead = hitTargetRightOverhead ? TARGET _COLOR _HIT : TARGET _COLOR ;
var targetColorRightLowered = hitTargetRightLowered ? TARGET _COLOR _HIT : TARGET _COLOR ;
var targetColorRightSide = hitTargetRightSide ? TARGET _COLOR _HIT : TARGET _COLOR ;
var targetColorRightFront = hitTargetRightFront ? TARGET _COLOR _HIT : TARGET _COLOR ;
2015-08-27 15:12:23 -07:00
// calculate a combined arm pose based on left and right hits
var poseValue = NO _POSE ;
poseValue += hitTargetLeftOnBase ? LEFT _ON _BASE : 0 ;
poseValue += hitTargetLeftOverhead ? LEFT _OVERHEAD : 0 ;
poseValue += hitTargetLeftLowered ? LEFT _LOWERED : 0 ;
poseValue += hitTargetLeftSide ? LEFT _SIDE : 0 ;
poseValue += hitTargetLeftFront ? LEFT _FRONT : 0 ;
poseValue += hitTargetRightOnBase ? RIGHT _ON _BASE : 0 ;
poseValue += hitTargetRightOverhead ? RIGHT _OVERHEAD : 0 ;
poseValue += hitTargetRightLowered ? RIGHT _LOWERED : 0 ;
poseValue += hitTargetRightSide ? RIGHT _SIDE : 0 ;
poseValue += hitTargetRightFront ? RIGHT _FRONT : 0 ;
if ( poses [ poseValue ] == undefined ) {
2015-09-03 14:33:25 -07:00
Overlays . editOverlay ( textOverlay , { text : "no pose -- value:" + poseValue } ) ;
2015-08-27 15:12:23 -07:00
} else {
2015-09-03 14:33:25 -07:00
Overlays . editOverlay ( textOverlay , { text : "pose:" + poses [ poseValue ] . name + "\n" + "animation:" + poses [ poseValue ] . animation } ) ;
2015-08-27 15:12:23 -07:00
var props = Entities . getEntityProperties ( puppetEntityID ) ;
2015-09-04 09:40:09 -07:00
//print("puppetEntityID:" + puppetEntityID + "age:"+props.age);
2015-08-27 15:12:23 -07:00
Entities . editEntity ( puppetEntityID , {
2015-10-02 14:17:01 -07:00
animation : { url : poses [ poseValue ] . animation } ,
2015-08-27 15:12:23 -07:00
lifetime : TEMPORARY _LIFETIME + props . age // renew lifetime
} ) ;
}
2015-09-03 14:33:25 -07:00
Overlays . editOverlay ( leftOnBaseOverlay , { position : getPositionLeftOnBase ( ) , color : targetColorLeftOnBase } ) ;
Overlays . editOverlay ( leftOverheadOverlay , { position : getPositionLeftOverhead ( ) , color : targetColorLeftOverhead } ) ;
Overlays . editOverlay ( leftLoweredOverlay , { position : getPositionLeftLowered ( ) , color : targetColorLeftLowered } ) ;
Overlays . editOverlay ( leftSideOverlay , { position : getPositionLeftSide ( ) , color : targetColorLeftSide } ) ;
Overlays . editOverlay ( leftFrontOverlay , { position : getPositionLeftFront ( ) , color : targetColorLeftFront } ) ;
2015-08-27 15:12:23 -07:00
2015-09-03 14:33:25 -07:00
Overlays . editOverlay ( rightOnBaseOverlay , { position : getPositionRightOnBase ( ) , color : targetColorRightOnBase } ) ;
Overlays . editOverlay ( rightOverheadOverlay , { position : getPositionRightOverhead ( ) , color : targetColorRightOverhead } ) ;
Overlays . editOverlay ( rightLoweredOverlay , { position : getPositionRightLowered ( ) , color : targetColorRightLowered } ) ;
Overlays . editOverlay ( rightSideOverlay , { position : getPositionRightSide ( ) , color : targetColorRightSide } ) ;
Overlays . editOverlay ( rightFrontOverlay , { position : getPositionRightFront ( ) , color : targetColorRightFront } ) ;
}
breakdanceEnd = function ( ) {
print ( "breakdanceEnd..." ) ;
Overlays . deleteOverlay ( leftHandOverlay ) ;
Overlays . deleteOverlay ( rightHandOverlay ) ;
Overlays . deleteOverlay ( textOverlay ) ;
Overlays . deleteOverlay ( leftOnBaseOverlay ) ;
Overlays . deleteOverlay ( leftOverheadOverlay ) ;
Overlays . deleteOverlay ( leftLoweredOverlay ) ;
Overlays . deleteOverlay ( leftSideOverlay ) ;
Overlays . deleteOverlay ( leftFrontOverlay ) ;
Overlays . deleteOverlay ( rightOnBaseOverlay ) ;
Overlays . deleteOverlay ( rightOverheadOverlay ) ;
Overlays . deleteOverlay ( rightLoweredOverlay ) ;
Overlays . deleteOverlay ( rightSideOverlay ) ;
Overlays . deleteOverlay ( rightFrontOverlay ) ;
2015-08-27 15:12:23 -07:00
Entities . deleteEntity ( puppetEntityID ) ;
2016-01-18 13:29:23 -08:00
}