This commit is contained in:
James B. Pollack 2016-03-27 18:22:50 -07:00
parent a57ba39fdd
commit d74114ff55
3 changed files with 100 additions and 55 deletions

View file

@ -3,17 +3,22 @@
(function() { (function() {
var TRIGGER_DISTANCE = 0.25; var TRIGGER_DISTANCE = 0.85;
var TRANSFORMATION_SOUND_URL = ''; var TRANSFORMATION_SOUND_URL = '';
var _this;
function Transformer() { function Transformer() {
_this = this;
return this; return this;
} }
Transformer.prototype = { Transformer.prototype = {
locked: false,
rotatorBlock: null, rotatorBlock: null,
transformationSound: null, transformationSound: null,
preload: function(entityID) { preload: function(entityID) {
print('PRELOAD TRANSFORMER SCRIPT')
this.entityID = entityID; this.entityID = entityID;
this.initialProperties = Entities.getEntityProperties(entityID); this.initialProperties = Entities.getEntityProperties(entityID);
this.transformationSound = SoundCache.getSound(TRANSFORMATION_SOUND_URL); this.transformationSound = SoundCache.getSound(TRANSFORMATION_SOUND_URL);
@ -21,58 +26,78 @@
collisionWithEntity: function(myID, otherID, collisionInfo) { collisionWithEntity: function(myID, otherID, collisionInfo) {
var otherProps = Entities.getEntityProperties(otherID); var otherProps = Entities.getEntityProperties(otherID);
if (otherProps.name = "hifi-home-dressing-room-transformer-collider") { if (otherProps.name = "hifi-home-dressing-room-transformer-collider" && _this.locked === false) {
// this.playTransformationSound(collisionInfo.contactPoint); var myProps = Entities.getEntityProperties(myID);
// this.createTransformationParticles(); var distance = Vec3.distance(myProps.position, otherProps.position);
this.findRotatorBlock(); 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) { playTransformationSound: function(position) {
Audio.playSound(this.transformationSound, { print('transformer should play a sound')
Audio.playSound(_this.transformationSound, {
position: position, position: position,
volume: 0.5 volume: 0.5
}); });
}, },
createTransformationParticles: function() { createTransformationParticles: function() {
print('transformer should create particles')
var particleProps = {}; var particleProps = {};
Entities.addEntity(particleProps); Entities.addEntity(particleProps);
}, },
findRotatorBlock: function() { 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); var results = Entities.findEntities(myProps.position, 10);
results.forEach(function(result) { results.forEach(function(result) {
var resultProps = Entities.getEntityProperties(result); var resultProps = Entities.getEntityProperties(result);
if (resultProps.name === "hifi-home-dressing-room-rotator-block") { if (resultProps.name === "hifi-home-dressing-room-rotator-block") {
this.rotatorBlock = result; _this.rotatorBlock = result;
_this.removeCurrentBigVersion(result);
} }
}); });
}, },
removeCurrentBigVersion: function() { removeCurrentBigVersion: function(rotatorBlock) {
var myProps = Entities.getEntityProperties(this.entityID); print('transformer should remove big version')
var myProps = Entities.getEntityProperties(_this.entityID);
var results = Entities.findEntities(myProps.position, 10); var results = Entities.findEntities(myProps.position, 10);
results.forEach(function(result) { results.forEach(function(result) {
var resultProps = Entities.getEntityProperties(result); var resultProps = Entities.getEntityProperties(result);
if (resultProps.name === "hifi-home-dressing-room-big-transformer") { if (resultProps.name === "hifi-home-dressing-room-big-transformer") {
Entities.deleteEntity(result) Entities.deleteEntity(result);
} }
}); });
this.createBigVersion(myProps); _this.createBigVersion(myProps);
}, },
createBigVersion: function(smallProps) { 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 = { var bigVersionProps = {
name: "hifi-home-dressing-room-big-transformer", name: "hifi-home-dressing-room-big-transformer",
type: 'Model', type: 'Model',
parentID: this.rotatorBlock, parentID: _this.rotatorBlock,
modelURL: smallProps.modelURL, modelURL: smallProps.modelURL,
position: this.putTransformerOnRotatorBlock(rotatorProps.position), position: _this.putTransformerOnRotatorBlock(rotatorProps.position),
rotation: rotatorProps.rotation, rotation: rotatorProps.rotation,
userData: JSON.stringify({ userData: JSON.stringify({
'grabbableKey': { 'grabbableKey': {
@ -84,33 +109,44 @@
}), }),
} }
Entities.addEntity(bigVersionProps); var bigVersion = Entities.addEntity(bigVersionProps);
this.putNewVersionOnShelf(); print('transformer created big version: ' + bigVersion)
_this.putNewVersionOnShelf();
}, },
putTransformerOnRotatorBlock: function(blockPosition) { putTransformerOnRotatorBlock: function(blockPosition) {
var myProps = Entities.getEntityProperties(this.entityID); print('transformer should get set on rotator block')
var halfHeight = myProps.dimensions.y / 2; return blockPosition
var newPosition = {
x: blockPosition.x,
y: blockPosition.x + halfHeight,
z: blockPosition.z
}
return newPosition
}, },
putNewVersionOnShelf: function() { 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 userData = JSON.parse(littleVersionProps.userData);
var basePosition = userData["hifiHomeTransformerKey"].basePosition; var basePosition = userData["hifiHomeTransformerKey"].basePosition;
var baseRotation = userData["hifiHomeTransformerKey"].baseRotation;
littleVersionProps.position = basePosition; littleVersionProps.position = basePosition;
Entities.addEntity(littleVersionProps); littleVersionProps.rotation = baseRotation;
this.removeSelf(); // print('transformer new version ' + JSON.stringify(littleVersionProps));
var littleTransformer = Entities.addEntity(littleVersionProps);
print('little transformer:: ' + littleTransformer);
_this.removeSelf();
}, },
removeSelf: function() { removeSelf: function() {
Entities.deleteEntity(this.entityID); print('transformer should remove itself')
var success = Entities.deleteEntity(_this.entityID);
print('transformer actually deleted self: ' + success);
}, },
}; };

View file

@ -1,6 +1,7 @@
var TRANSFORMER_SCRIPT = Script.resolvePath('transformer.js?' + Math.random()); var TRANSFORMER_SCRIPT = Script.resolvePath('transformer.js?' + Math.random());
var SHRINK_AMOUNT = 1 / 2;
TransformerDoll = function(modelURL, spawnPosition, spawnRotation) { TransformerDoll = function(modelURL, spawnPosition, spawnRotation) {
print('SCRIPT REF AT TRANSFORMER CREATE::' + TRANSFORMER_SCRIPT); print('SCRIPT REF AT TRANSFORMER CREATE::' + TRANSFORMER_SCRIPT);
var transformerProps = { var transformerProps = {
name: 'hifi-home-dressing-room-little-transformer', name: 'hifi-home-dressing-room-little-transformer',
type: 'Model', type: 'Model',
@ -14,30 +15,39 @@
y: -5, y: -5,
z: 0 z: 0
}, },
visible:false,
damping:0.8,
userData: JSON.stringify({ userData: JSON.stringify({
'grabbableKey': { 'grabbableKey': {
'grabbable': true 'grabbable': true
}, },
'hifiHomeTransformerKey': { 'hifiHomeTransformerKey': {
'basePosition': spawnPosition 'basePosition': spawnPosition,
'baseRotation':Quat.fromPitchYawRollDegrees(spawnRotation.x, spawnRotation.y, spawnRotation.z),
}, },
'hifiHomeKey': { 'hifiHomeKey': {
'reset': true 'reset': true
} }
}), }),
// script: TRANSFORMER_SCRIPT script: TRANSFORMER_SCRIPT
} }
var transformer = Entities.addEntity(transformerProps); var transformer = Entities.addEntity(transformerProps);
// Script.setTimeout(function() { Script.setTimeout(function() {
// var actualProps = Entities.getEntityProperties(transformer); var actualProps = Entities.getEntityProperties(transformer);
// var quarterSize = Vec3.multiply(0.25, actualProps.naturalDimensions); var quarterSize = Vec3.multiply(SHRINK_AMOUNT, actualProps.naturalDimensions);
// Entities.editEntity(transformer, { Entities.editEntity(transformer, {
// dimensions: quarterSize dimensions: quarterSize,
// }); visible:true,
// }, 1500) // velocity: {
// x: 0,
// y: -0.1,
// z: 0
// }
});
}, 1000)
print('CREATED TRANSFORMER' + transformer); print('CREATED TRANSFORMER' + transformer);
print('at location: ' + JSON.stirngify(transformerProps.position)) print('at location: ' + JSON.stringify(transformerProps.position))
return this; return this;
} }

View file

@ -271,17 +271,19 @@
createTransformers: function() { createTransformers: function() {
print('CREATING TRANSFORMERS!') print('CREATING TRANSFORMERS!')
var firstDollPosition = { var firstDollPosition = {
x: 1108.2123, x: 1107.61,
y: 460.7516, y: 460.8,
z: -80.9387 z: -77.34
} }
var dollRotation = { var dollRotation = {
x: 0, x: 0,
y: 28, y: -55.86,
z: 0, z: 0,
} }
var rotationAsQuat = Quat.fromPitchYawRollDegrees(dollRotation.x,dollRotation.y,dollRotation.z);
var dolls = [ var dolls = [
TRANSFORMER_URL_ARTEMIS, TRANSFORMER_URL_ARTEMIS,
TRANSFORMER_URL_ALBERT, TRANSFORMER_URL_ALBERT,
@ -290,18 +292,15 @@
TRANSFORMER_URL_WILL TRANSFORMER_URL_WILL
]; ];
var dollLateralSeparation = 0.5; var dollLateralSeparation = 1.0;
dolls.forEach(function(doll, index) { dolls.forEach(function(doll, index) {
print('CREATE TRANSFORMER:: ' + doll)
var separation = index * dollLateralSeparation; var separation = index * dollLateralSeparation;
var right = Quat.getRight(dollRotation); print('separation: ' + separation)
var left = Vec3.multiply(-1, right); var left = Quat.getRight(rotationAsQuat);
var howFarLeft = Vec3.multiply(separation, left); var distanceToLeft = Vec3.multiply(separation,left);
var distanceToLeft = Vec3.sum(firstDollPosition, howFarLeft); var dollPosition = Vec3.sum(firstDollPosition,distanceToLeft)
print('PARAMS AT CREATE') var transformer = new TransformerDoll(doll, dollPosition, dollRotation);
print('distanceToLeft : ' + JSON.stringify(distanceToLeft))
print('dollRotation : ' + JSON.stringify(dollRotation))
var transformer = new TransformerDoll(doll, distanceToLeft, dollRotation);
}); });