From 0bf822f17b54731cb6bffa66e7660842381b2ae7 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 11 Feb 2016 16:48:54 -0800 Subject: [PATCH] update and add another entity script --- .../CellScience/Scripts/moveRandomly.js | 138 ++------------- .../Scripts/zoomAndMoveRandomly.js | 159 ++++++++++++++++++ .../CellScience/backgroundMusicAC.js | 8 +- .../CellScience/importCellScience.js | 4 +- 4 files changed, 181 insertions(+), 128 deletions(-) create mode 100644 unpublishedScripts/DomainContent/CellScience/Scripts/zoomAndMoveRandomly.js diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js b/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js index a975f74733..8c3a6c0852 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/moveRandomly.js @@ -8,124 +8,32 @@ var self = this; - this.preload = function(entityId) { - //print('preload move randomly') + this.preload=function(entityId){ this.isConnected = false; this.entityId = entityId; - this.updateInterval = 100; - this.posFrame = 0; - this.rotFrame = 0; - this.posInterval = 100; - this.rotInterval = 100; this.minVelocity = 1; this.maxVelocity = 5; this.minAngularVelocity = 0.01; this.maxAngularVelocity = 0.03; - - this.initialize(entityId); - this.initTimeout = null; - - - var userData = { - ownershipKey: { - owner: MyAvatar.sessionUUID - }, - grabbableKey: { - grabbable: false - } - }; - - Entities.editEntity(entityId, { - userData: JSON.stringify(userData) - }) + Script.setTimeout(self.move,self.getTotalWait()) } - this.initialize = function(entityId) { - //print('move randomly should initialize' + entityId) - var properties = Entities.getEntityProperties(entityId); - if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { - self.initTimeout = Script.setTimeout(function() { - //print('no user data yet, try again in one second') - self.initialize(entityId); - }, 1000) - } else { - //print('userdata before parse attempt' + properties.userData) - self.userData = null; - try { - self.userData = JSON.parse(properties.userData); - } catch (err) { - //print('error parsing json'); - //print('properties are:' + properties.userData); - return; - } - Script.update.connect(self.update); - this.isConnected = true; - } - } - - this.update = function(deltaTime) { - // print('jbp in update') - var data = Entities.getEntityProperties(self.entityId, 'userData').userData; - var userData; - try { - userData = JSON.parse(data) - } catch (e) { - //print('error parsing json' + data) - return; - }; - - // print('userdata is' + data) - //if the entity doesnt have an owner set yet - if (userData.hasOwnProperty('ownershipKey') !== true) { - //print('no movement owner yet') - return; - } - - //print('owner is:::' + userData.ownershipKey.owner) - //get all the avatars to see if the owner is around + this.getTotalWait = function() { var avatars = AvatarList.getAvatarIdentifiers(); - var ownerIsAround = false; + var avatarCount = avatars.length; + var random = Math.random() * 2000; + var totalWait = random * (avatarCount * 2); - //if the current owner is not me... - if (userData.ownershipKey.owner !== MyAvatar.sessionUUID) { + return totalWait + } - //look to see if the current owner is around anymore - for (var i = 0; i < avatars.length; i++) { - if (avatars[i] === userData.ownershipKey.owner) { - ownerIsAround = true - //the owner is around - return; - }; - } - //if the owner is not around, then take ownership - if (ownerIsAround === false) { - //print('taking ownership') + this.move = function() { + print('jbp im the owner so move it') + + - var userData = { - ownershipKey: { - owner: MyAvatar.sessionUUID - }, - grabbableKey: { - grabbable: false - } - }; - Entities.editEntity(self.entityId, { - userData: JSON.stringify(data) - }) - } - } - //but if the current owner IS me, then move it - else { - //print('jbp im the owner so move it') - self.posFrame++; - self.rotFrame++; - - if (self.posFrame > self.posInterval) { - - self.posInterval = 100 * Math.random() + 300; - self.posFrame = 0; var magnitudeV = self.maxVelocity; var directionV = { @@ -137,16 +45,9 @@ //print("POS magnitude is " + magnitudeV + " and direction is " + directionV.x); Entities.editEntity(self.entityId, { velocity: Vec3.multiply(magnitudeV, Vec3.normalize(directionV)) - }); - } - - if (self.rotFrame > self.rotInterval) { - - self.rotInterval = 100 * Math.random() + 250; - self.rotFrame = 0; - + var magnitudeAV = self.maxAngularVelocity; var directionAV = { @@ -160,20 +61,13 @@ }); - } - - } + + Script.setTimeout(self.move,self.getTotalWait()) } - this.unload = function() { - if (this.initTimeout !== null) { - Script.clearTimeout(this.initTimeout); - } - if (this.isConnected === true) { - Script.update.disconnect(this.update); - } + this.unload = function() { } diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/zoomAndMoveRandomly.js b/unpublishedScripts/DomainContent/CellScience/Scripts/zoomAndMoveRandomly.js new file mode 100644 index 0000000000..f0f77b12e0 --- /dev/null +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/zoomAndMoveRandomly.js @@ -0,0 +1,159 @@ +// Copyright 2016 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 +// + +(function() { + var teleport; + var portalDestination; + var animationURL; + var self = this; + + this.entered = true; + + this.preload = function(entityID) { + this.entityId = entityID; + this.initialize(entityID); + this.initTimeout = null; + this.minVelocity = 1; + this.maxVelocity = 5; + this.minAngularVelocity = 0.01; + this.maxAngularVelocity = 0.03; + Script.setTimeout(self.move, self.getTotalWait()) + } + + this.initialize = function(entityID) { + // print(' should initialize') + var properties = Entities.getEntityProperties(entityID); + if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { + self.initTimeout = Script.setTimeout(function() { + // print(' no user data yet, try again in one second') + self.initialize(entityID); + }, 1000) + } else { + // print(' has userData') + self.portalDestination = properties.userData; + animationURL = properties.modelURL; + self.soundOptions = { + stereo: true, + loop: false, + localOnly: false, + position: properties.position, + volume: 0.5 + }; + + self.teleportSound = SoundCache.getSound("https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/whoosh.wav"); + // print(" portal destination is " + self.portalDestination); + } + } + + this.enterEntity = function(entityID) { + //print('ENTERED A BOUNDARY ENTITY, SHOULD ZOOM', entityID) + var data = JSON.parse(Entities.getEntityProperties(this.entityId).userData); + //print('DATA IS::' + data) + if (data != null) { + print("Teleporting to (" + data.location.x + ", " + data.location.y + ", " + data.location.z + ")"); + + MyAvatar.position = data.location; + + // if (data.hasOwnProperty('entryPoint') && data.hasOwnProperty('target')) { + // this.lookAtTarget(data.entryPoint, data.target); + // } + // else{ + + // } + } + + } + + this.lookAtTarget = function(entryPoint, target) { + //print('SHOULD LOOK AT TARGET') + var direction = Vec3.normalize(Vec3.subtract(entryPoint, target)); + var pitch = Quat.angleAxis(Math.asin(-direction.y) * 180.0 / Math.PI, { + x: 1, + y: 0, + z: 0 + }); + var yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * 180.0 / Math.PI, { + x: 0, + y: 1, + z: 0 + }); + + MyAvatar.goToLocation(entryPoint, true, yaw); + + MyAvatar.headYaw = 0; + + } + + this.leaveEntity = function(entityID) { + Entities.editEntity(entityID, { + animationURL: animationURL, + animationSettings: '{ "frameIndex": 1, "running": false }' + }); + this.entered = false; + if (this.initTimeout !== null) { + Script.clearTimeout(this.initTimeout); + } + //playSound(); + } + + this.unload = function() { + if (this.initTimeout !== null) { + Script.clearTimeout(this.initTimeout); + } + } + + this.hoverEnterEntity = function(entityID) { + Entities.editEntity(entityID, { + animationURL: animationURL, + animationSettings: '{ "fps": 24, "firstFrame": 1, "lastFrame": 25, "frameIndex": 1, "running": true, "hold": true }' + }); + } + + this.getTotalWait = function() { + var avatars = AvatarList.getAvatarIdentifiers(); + var avatarCount = avatars.length; + var random = Math.random() * 2000; + var totalWait = random * (avatarCount * 2); + + return totalWait + } + + + this.move = function() { + print('jbp im the owner so move it') + + var magnitudeV = self.maxVelocity; + var directionV = { + x: Math.random() - 0.5, + y: Math.random() - 0.5, + z: Math.random() - 0.5 + }; + + //print("POS magnitude is " + magnitudeV + " and direction is " + directionV.x); + Entities.editEntity(self.entityId, { + velocity: Vec3.multiply(magnitudeV, Vec3.normalize(directionV)) + }); + + + + var magnitudeAV = self.maxAngularVelocity; + + var directionAV = { + x: Math.random() - 0.5, + y: Math.random() - 0.5, + z: Math.random() - 0.5 + }; + //print("ROT magnitude is " + magnitudeAV + " and direction is " + directionAV.x); + Entities.editEntity(self.entityId, { + angularVelocity: Vec3.multiply(magnitudeAV, Vec3.normalize(directionAV)) + + }); + + Script.setTimeout(self.move, self.getTotalWait()) + } + +}) \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js b/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js index 0ee5b3bf32..1b4c06caaa 100644 --- a/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js +++ b/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js @@ -7,7 +7,7 @@ var soundMap = [{ y: 15850, z: 15850 }, - volume: 0.1, + volume: 0.03, loop: true } }, { @@ -19,7 +19,7 @@ var soundMap = [{ y: 15950, z: 15950 }, - volume: 0.1, + volume: 0.03, loop: true } }, { @@ -31,7 +31,7 @@ var soundMap = [{ y: 15650, z: 15650 }, - volume: 0.1, + volume: 0.03, loop: true } }, { @@ -43,7 +43,7 @@ var soundMap = [{ y: 15750, z: 15750 }, - volume: 0.1, + volume: 0.03, loop: true } } diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index ca0eb21f21..7d9a49294f 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -5,7 +5,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var version = 1035; +var version = 1039; var cellLayout; var baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/"; @@ -120,7 +120,7 @@ var scenes = [{ location: locations.cellLayout[1], baseURL: baseLocation }), - script: "zoom.js?" + version, + script: "zoomAndMoveRandomly.js?" + version, visible: true }], boundary: {