From d74114ff55ed49b5e2b6808ada715b3b07b79df2 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sun, 27 Mar 2016 18:22:50 -0700 Subject: [PATCH] cleannnn --- .../Home/dressingRoom/transformer.js | 96 +++++++++++++------ .../Home/dressingRoom/wrapper.js | 32 ++++--- .../DomainContent/Home/reset.js | 27 +++--- 3 files changed, 100 insertions(+), 55 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/dressingRoom/transformer.js b/unpublishedScripts/DomainContent/Home/dressingRoom/transformer.js index 10154f7054..e290e5090b 100644 --- a/unpublishedScripts/DomainContent/Home/dressingRoom/transformer.js +++ b/unpublishedScripts/DomainContent/Home/dressingRoom/transformer.js @@ -3,17 +3,22 @@ (function() { - var TRIGGER_DISTANCE = 0.25; + var TRIGGER_DISTANCE = 0.85; var TRANSFORMATION_SOUND_URL = ''; + var _this; + function Transformer() { + _this = this; return this; } Transformer.prototype = { + locked: false, rotatorBlock: null, transformationSound: null, preload: function(entityID) { + print('PRELOAD TRANSFORMER SCRIPT') this.entityID = entityID; this.initialProperties = Entities.getEntityProperties(entityID); this.transformationSound = SoundCache.getSound(TRANSFORMATION_SOUND_URL); @@ -21,58 +26,78 @@ collisionWithEntity: function(myID, otherID, collisionInfo) { var otherProps = Entities.getEntityProperties(otherID); - if (otherProps.name = "hifi-home-dressing-room-transformer-collider") { - // this.playTransformationSound(collisionInfo.contactPoint); - // this.createTransformationParticles(); - this.findRotatorBlock(); + if (otherProps.name = "hifi-home-dressing-room-transformer-collider" && _this.locked === false) { + var myProps = Entities.getEntityProperties(myID); + var distance = Vec3.distance(myProps.position, otherProps.position); + print('transformer DISTANCE ' + distance) + if (distance < TRIGGER_DISTANCE) { + print('transformer should do magic!!!') + // this.playTransformationSound(collisionInfo.contactPoint); + // this.createTransformationParticles(); + _this.findRotatorBlock(); + } else { + return; + } + this.locked = true; + + } else { + return; } }, playTransformationSound: function(position) { - Audio.playSound(this.transformationSound, { + print('transformer should play a sound') + Audio.playSound(_this.transformationSound, { position: position, volume: 0.5 }); }, createTransformationParticles: function() { + print('transformer should create particles') var particleProps = {}; Entities.addEntity(particleProps); }, findRotatorBlock: function() { - var myProps = Entities.getEntityProperties(this.entityID); + print('transformer should find rotator block') + var myProps = Entities.getEntityProperties(_this.entityID); var results = Entities.findEntities(myProps.position, 10); results.forEach(function(result) { var resultProps = Entities.getEntityProperties(result); if (resultProps.name === "hifi-home-dressing-room-rotator-block") { - this.rotatorBlock = result; + _this.rotatorBlock = result; + _this.removeCurrentBigVersion(result); } }); }, - removeCurrentBigVersion: function() { - var myProps = Entities.getEntityProperties(this.entityID); + removeCurrentBigVersion: function(rotatorBlock) { + print('transformer should remove big version') + var myProps = Entities.getEntityProperties(_this.entityID); var results = Entities.findEntities(myProps.position, 10); results.forEach(function(result) { var resultProps = Entities.getEntityProperties(result); if (resultProps.name === "hifi-home-dressing-room-big-transformer") { - Entities.deleteEntity(result) + Entities.deleteEntity(result); } }); - this.createBigVersion(myProps); + _this.createBigVersion(myProps); + }, createBigVersion: function(smallProps) { - var rotatorProps = Entities.getEntityProperties(this.rotatorBlock); + print('transformer should create big version!!') + print('transformer has rotatorBlock??' + _this.rotatorBlock); + var rotatorProps = Entities.getEntityProperties(_this.rotatorBlock); var bigVersionProps = { name: "hifi-home-dressing-room-big-transformer", type: 'Model', - parentID: this.rotatorBlock, + parentID: _this.rotatorBlock, modelURL: smallProps.modelURL, - position: this.putTransformerOnRotatorBlock(rotatorProps.position), + position: _this.putTransformerOnRotatorBlock(rotatorProps.position), rotation: rotatorProps.rotation, userData: JSON.stringify({ 'grabbableKey': { @@ -84,33 +109,44 @@ }), } - Entities.addEntity(bigVersionProps); - this.putNewVersionOnShelf(); + var bigVersion = Entities.addEntity(bigVersionProps); + print('transformer created big version: ' + bigVersion) + _this.putNewVersionOnShelf(); }, putTransformerOnRotatorBlock: function(blockPosition) { - var myProps = Entities.getEntityProperties(this.entityID); - var halfHeight = myProps.dimensions.y / 2; - var newPosition = { - x: blockPosition.x, - y: blockPosition.x + halfHeight, - z: blockPosition.z - } - - return newPosition + print('transformer should get set on rotator block') + return blockPosition }, putNewVersionOnShelf: function() { - var littleVersionProps = Entities.getEntityProperties(this.entityID); + print('transformer should out a new version of itself on the shelf') + var littleVersionProps = Entities.getEntityProperties(_this.entityID); + delete littleVersionProps.id; + delete littleVersionProps.created; + delete littleVersionProps.age; + delete littleVersionProps.ageAsText; + delete littleVersionProps.position; + delete littleVersionProps.rotation; + delete littleVersionProps.localPosition; + delete littleVersionProps.localRotation; + delete littleVersionProps.naturalPosition; + var userData = JSON.parse(littleVersionProps.userData); var basePosition = userData["hifiHomeTransformerKey"].basePosition; + var baseRotation = userData["hifiHomeTransformerKey"].baseRotation; littleVersionProps.position = basePosition; - Entities.addEntity(littleVersionProps); - this.removeSelf(); + littleVersionProps.rotation = baseRotation; + // print('transformer new version ' + JSON.stringify(littleVersionProps)); + var littleTransformer = Entities.addEntity(littleVersionProps); + print('little transformer:: ' + littleTransformer); + _this.removeSelf(); }, removeSelf: function() { - Entities.deleteEntity(this.entityID); + print('transformer should remove itself') + var success = Entities.deleteEntity(_this.entityID); + print('transformer actually deleted self: ' + success); }, }; diff --git a/unpublishedScripts/DomainContent/Home/dressingRoom/wrapper.js b/unpublishedScripts/DomainContent/Home/dressingRoom/wrapper.js index c3def16ef3..c608128f67 100644 --- a/unpublishedScripts/DomainContent/Home/dressingRoom/wrapper.js +++ b/unpublishedScripts/DomainContent/Home/dressingRoom/wrapper.js @@ -1,6 +1,7 @@ var TRANSFORMER_SCRIPT = Script.resolvePath('transformer.js?' + Math.random()); + var SHRINK_AMOUNT = 1 / 2; TransformerDoll = function(modelURL, spawnPosition, spawnRotation) { - print('SCRIPT REF AT TRANSFORMER CREATE::' + TRANSFORMER_SCRIPT); + print('SCRIPT REF AT TRANSFORMER CREATE::' + TRANSFORMER_SCRIPT); var transformerProps = { name: 'hifi-home-dressing-room-little-transformer', type: 'Model', @@ -14,30 +15,39 @@ y: -5, z: 0 }, + visible:false, + damping:0.8, userData: JSON.stringify({ 'grabbableKey': { 'grabbable': true }, 'hifiHomeTransformerKey': { - 'basePosition': spawnPosition + 'basePosition': spawnPosition, + 'baseRotation':Quat.fromPitchYawRollDegrees(spawnRotation.x, spawnRotation.y, spawnRotation.z), }, 'hifiHomeKey': { 'reset': true } }), - // script: TRANSFORMER_SCRIPT + script: TRANSFORMER_SCRIPT } var transformer = Entities.addEntity(transformerProps); - // Script.setTimeout(function() { - // var actualProps = Entities.getEntityProperties(transformer); - // var quarterSize = Vec3.multiply(0.25, actualProps.naturalDimensions); - // Entities.editEntity(transformer, { - // dimensions: quarterSize - // }); - // }, 1500) + Script.setTimeout(function() { + var actualProps = Entities.getEntityProperties(transformer); + var quarterSize = Vec3.multiply(SHRINK_AMOUNT, actualProps.naturalDimensions); + Entities.editEntity(transformer, { + dimensions: quarterSize, + visible:true, + // velocity: { + // x: 0, + // y: -0.1, + // z: 0 + // } + }); + }, 1000) print('CREATED TRANSFORMER' + transformer); - print('at location: ' + JSON.stirngify(transformerProps.position)) + print('at location: ' + JSON.stringify(transformerProps.position)) return this; } \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/Home/reset.js b/unpublishedScripts/DomainContent/Home/reset.js index b7454d156f..e1d2d0239b 100644 --- a/unpublishedScripts/DomainContent/Home/reset.js +++ b/unpublishedScripts/DomainContent/Home/reset.js @@ -271,17 +271,19 @@ createTransformers: function() { print('CREATING TRANSFORMERS!') var firstDollPosition = { - x: 1108.2123, - y: 460.7516, - z: -80.9387 + x: 1107.61, + y: 460.8, + z: -77.34 } var dollRotation = { x: 0, - y: 28, + y: -55.86, z: 0, } + var rotationAsQuat = Quat.fromPitchYawRollDegrees(dollRotation.x,dollRotation.y,dollRotation.z); + var dolls = [ TRANSFORMER_URL_ARTEMIS, TRANSFORMER_URL_ALBERT, @@ -290,18 +292,15 @@ TRANSFORMER_URL_WILL ]; - var dollLateralSeparation = 0.5; + var dollLateralSeparation = 1.0; dolls.forEach(function(doll, index) { - print('CREATE TRANSFORMER:: ' + doll) + var separation = index * dollLateralSeparation; - var right = Quat.getRight(dollRotation); - var left = Vec3.multiply(-1, right); - var howFarLeft = Vec3.multiply(separation, left); - var distanceToLeft = Vec3.sum(firstDollPosition, howFarLeft); - print('PARAMS AT CREATE') - print('distanceToLeft : ' + JSON.stringify(distanceToLeft)) - print('dollRotation : ' + JSON.stringify(dollRotation)) - var transformer = new TransformerDoll(doll, distanceToLeft, dollRotation); + print('separation: ' + separation) + var left = Quat.getRight(rotationAsQuat); + var distanceToLeft = Vec3.multiply(separation,left); + var dollPosition = Vec3.sum(firstDollPosition,distanceToLeft) + var transformer = new TransformerDoll(doll, dollPosition, dollRotation); });