if (typeof Object.assign !== 'function') { // Must be writable: true, enumerable: false, configurable: true Object.defineProperty(Object, "assign", { value: function assign(target, varArgs) { // .length of function is 2 'use strict'; if (target == null) { // TypeError if undefined or null throw new TypeError('Cannot convert undefined or null to object'); } var to = Object(target); for (var index = 1; index < arguments.length; index++) { var nextSource = arguments[index]; if (nextSource != null) { // Skip over if undefined or null for (var nextKey in nextSource) { // Avoid bugs when hasOwnProperty is shadowed if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { to[nextKey] = nextSource[nextKey]; } } } } return to; }, writable: true, configurable: true }); } (function(){ var userData = JSON.stringify({ grabbableKey: { cloneable: false, kinematic: false, grabbable: false } }); // var TWEEN = Script.require('./tween.js'); var DEBUG = true; var KEEP = false; function log(describer, obj) { if (!DEBUG) {return;} if (typeof obj !== "string" || typeof obj !== "number") {obj = JSON.stringify(obj);} print("\n### " + describer + " ::: " + obj ); } // make vector from array function mkVFA(array){ var props = {}; if (array.length === 1){ props.x = array[0]; props.y = array[0]; props.z = array[0]; } else { props.x = array[0]; props.y = array[1]; props.z = array[2]; } return props; } // make Quat from Array function mkQFA(array){ var vec = mkVFA(array); var quat = Quat.fromVec3Degrees(vec); return quat; } // make color from array function mkCFA(array){ var props = {}; if (array.length === 1){ props.red = array[0]; props.green = array[0]; props.blue = array[0]; } else { props.red = array[0]; props.green = array[1]; props.blue = array[2]; } return props; } // make props for box function mkAFV(vector){ var array = []; array[0] = vector.x; array[1] = vector.y; array[2] = vector.z; return array; } var defaultPropObj = { position: mkVFA([0,0,0]), dimensions: mkVFA([1,1,1]), rotation: mkQFA([0,0,0]), registrationPoint: mkVFA([0.5,0.5,0.5]), offset: mkVFA([0,0,0]), color: mkCFA([25,25,25]), lifetime: -1, userData: userData }; // delete any invalid key/value function delUndefined(obj){ var keys = Object.keys(obj); keys.forEach(function(key){ if (!obj[key] || obj[key] === "") {delete obj[key];} }); return obj; } function mkProps(position, dimensions, rotation, registration, offset, color, name){ if (Array.isArray(position)) {position = mkVFA(position);} if (position === "av") {position = MyAvatar.position;} if (Array.isArray(dimensions)) {dimensions = mkVFA(dimensions);} if (Array.isArray(rotation)) {rotation = mkQFA(rotation);} if (Array.isArray(registration)) {registration = mkVFA(registration);} if (Array.isArray(offset)) {offset = mkVFA(offset);} if (Array.isArray(color)) {color = mkCFA(color);} log("!!!position", position); var newProps = { name: name, position: Vec3.sum(position, offset), dimensions: dimensions, rotation: rotation, registrationPoint: registration, color: color, lifetime: -1, userData: userData }; var finalObj = Object.assign({},defaultPropObj, delUndefined(newProps)); // log("finalObj",finalObj); return finalObj; } function mkBox(position, dimensions, rotation, registration, offset, color, name){ var boxProps = { type: "Box", lifetime: -1, userData: userData }; var finalProps = Object.assign({}, boxProps, mkProps(position, dimensions, rotation, registration, offset, color, name)); return Entities.addEntity(finalProps); } function mkBoxProps(props){ position = props[0]; dimensions = props[1]; rotation = props[2]; registration = props[3]; offset = props[4]; color = props[5]; name = props[6]; var boxProps = { type: "Box" // userData: userData2 }; var finalProps = Object.assign({}, boxProps, mkProps(position, dimensions, rotation, registration, offset, color, name)); log("FINAL PROPS!!!!", finalProps); return finalProps; } function mkboxNoShader(position, dimensions, rotation, registration, offset, color, name){ var boxProps = { type: "Box", dynamic: false, collisionless: true, id: parentID, visible: false // userData: userData }; var finalProps = Object.assign({}, boxProps, mkProps(position, dimensions, rotation, registration, offset, color, name)); parentID = Entities.addEntity(finalProps); return parentID; } function mkZone(position, dimensions, rotation, registration, offset, color, name){ var zoneProps = { // parentID: parentID, type: "Zone", name: "zone", keyLight: { ambientIntensity: 5.5, ambientURL: "", color: { blue: 255, green: 255, red: 255 }, direction: { x: 0.3411870300769806, y: -0.9396926164627075, z: -0.023858120664954185 }, intensity: 10 }, stage: { altitude: 0.029999999329447746, automaticHourDay: 0, day: 60, hour: 12, latitude: 37.777000427246094, longitude: 122.40699768066406, sunModelEnabled: 0 }, direction: mkVFA([0,-1,0]), lifetime: -1, userData: userData, script: Script.resolvePath('./zoneReverb.js?' + Date.now()) }; var finalProps = Object.assign({}, zoneProps, mkProps(position, dimensions, rotation, registration, offset, color, name)); return Entities.addEntity(finalProps); } function BoxMakerGroup(){ return { currentIDs: [], name: "", addEntity: function(entityID){ this.currentIDs.push(entityID); }, removeEntity: function(id){ log("in remove entity"); var index = -1; for (var i = 0; i < this.currentIDs.length; i++){ log("this.currentIDs[i]", this.currentIDs[i]); log("id", id); if (this.currentIDs[i] === id) { index = i; break; } } log("index", index); print(index); if (index > -1) { this.currentIDs.splice(index,1); Entities.deleteEntity(id); } }, changeName: function(name){ log("name in change name", name); this.name = name; var zoneProps = this.getZone(); log("zoneProps", zoneProps); var userData = JSON.parse(zoneProps.userData); userData.name = name; Entities.editEntity(zoneProps.id, { userData: JSON.stringify(userData) }); }, deleteAllEntities: function(){ while (this.currentIDs.length > 0){ this.removeEntity(this.currentIDs[0]); } }, getFloor: function(){ return this.getAllProps().filter(function(props){ return props.name === "floor"; })[0].position; }, getZone: function(){ return this.getAllProps().filter(function(props){ log("props.name:", props.name); return props.name === "Zone"; })[0]; }, getProps: function(index, id){ log("in get props"); if (typeof index === "number"){ log("in index get props"); return Entities.getEntityProperties(this.currentIDs[index]); } if (id){ log("in id get props"); return Entities.getEntityProperties(id); } }, getAllProps: function(){ // log("in get all props"); // log("this.curretIds", this.currentIDs); var array = this.currentIDs.map(function(id){ // log("id", id) var props = this.getProps(null,id); // log("props", props) return props; }, this); // log("array", array); return array; }, editProps: function(index, id, props){ // log("editing props"); // log("index", index); // log("id", id); // log("props", props); if (typeof index === "number"){ // log("this.currentIDs[index]", this.currentIDs[index]) // log("props",props); // log("index", index); // log("this.currentIDs", this.currentIDs) // var boxProps = entitiesGroup.getProps(index).rotation; // log("boxPropsPosition", boxProps); Entities.editEntity(this.currentIDs[index], props); // boxProps = entitiesGroup.getProps(index).rotation; // log("boxPropsPosition", boxProps); } if (id){ Entities.editEntity(id, props); } }, makeParent: function(pID){ print("in make Parent"); this.currentIDs.slice(1).forEach(function(id){ print("id", id); Entities.editEntity(id,{ parentID: pID }); }); }, lastId: function(){ return this.currentIDs.length-1; }, spin: function(amount){ var id = this.currentIDs[0]; Entities.editEntity(id, { angularVelocity: {x:amount, y:amount, z: amount} }); }, speed: function(speed){ log("speed", speed); var newSpeed = lerp (0,127,0.0,2.0,speed); var newUserData = JSON.parse(userDataToUse); log("newUserData",newUserData); newUserData.ProceduralEntity.uniforms.speed = newSpeed; props = {userData: JSON.stringify(newUserData)}; // log("props",props); this.currentIDs.forEach(function(id) {Entities.editEntity(id, props);}); // log("newProps", this.getProps(1).userData); }, emit: function(emit){ log("emit", emit); var newEmit = lerp (0,127,0.0,1.0,emit); var newUserData = JSON.parse(userDataToUse); log("newUserData",newUserData); newUserData.ProceduralEntity.uniforms.uEmit = newEmit; props = {userData: JSON.stringify(newUserData)}; // log("props",props); this.currentIDs.forEach(function(id) {Entities.editEntity(id, props);}); // log("newProps", this.getProps(1).userData); }, specular: function(specular){ log("specular", specular); var newSpecular = lerp (0,127,0.0,1.0,specular); var newUserData = JSON.parse(userDataToUse); log("newUserData",newUserData); newUserData.ProceduralEntity.uniforms.speed = newSpecular; props = {userData: JSON.stringify(newUserData)}; // log("props",props); this.currentIDs.forEach(function(id) {Entities.editEntity(id, props);}); // log("newProps", this.getProps(1).userData); }, shine: function(shine){ log("shine", shine); var newShine = lerp (0,127,0.0,255.0,shine); var newUserData = JSON.parse(userDataToUse); log("newUserData",newUserData); newUserData.ProceduralEntity.uniforms.speed = newShine; props = {userData: JSON.stringify(newUserData)}; // log("props",props); this.currentIDs.forEach(function(id) {Entities.editEntity(id, props);}); // log("newProps", this.getProps(1).userData); }, boxLength:1, boxWidth:1, boxHeight:1, boxThickness:1, position: mkVFA([0,0,0]), distanceApart: [0,0,0], length: function(length){ this.boxLength = length; var boxProps = makeNewBoxProps(this.boxLength, this.boxWidth, this.boxHeight,this.boxThickness, this.distanceApart); log("boxProps", boxProps); var propsGroup = makePropsForBox(0,boxProps); log("propsGroup", propsGroup); propsGroup.forEach(function(props,index){ var actuallPropsToSend = mkBoxProps(props); log("props",props); log("actualPropsToSend", actuallPropsToSend); this.editProps(index,null,actuallPropsToSend); },this); }, width: function(width){ this.boxWidth = width; var boxProps = makeNewBoxProps(this.boxLength, this.boxWidth, this.boxHeight,this.boxThickness, this.distanceApart); log("boxProps", boxProps); var propsGroup = makePropsForBox(0,boxProps); log("propsGroup", propsGroup); propsGroup.forEach(function(props,index){ var actuallPropsToSend = mkBoxProps(props); log("props",props); log("actualPropsToSend", actuallPropsToSend); this.editProps(index,null,actuallPropsToSend); },this); }, height: function(height){ this.boxHeight = height; var boxProps = makeNewBoxProps(this.boxLength, this.boxWidth, this.boxHeight,this.boxThickness, this.distanceApart); log("boxProps", boxProps); var propsGroup = makePropsForBox(0,boxProps); log("propsGroup", propsGroup); propsGroup.forEach(function(props,index){ var actuallPropsToSend = mkBoxProps(props); log("props",props); log("actualPropsToSend", actuallPropsToSend); this.editProps(index,null,actuallPropsToSend); },this); }, thickness: function(thickness){ this.boxThickness = thickness; var boxProps = makeNewBoxProps(this.boxLength, this.boxWidth, this.boxHeight,this.boxThickness, this.distanceApart); log("boxProps", boxProps); var propsGroup = makePropsForBox(0,boxProps); log("propsGroup", propsGroup); propsGroup.forEach(function(props,index){ var actuallPropsToSend = mkBoxProps(props); log("props",props); log("actualPropsToSend", actuallPropsToSend); this.editProps(index,null,actuallPropsToSend); },this); }, getPosition: function(normPosition){ return getNormPosition(normPosition, mkAFV(this.position),[this.boxLength, this.boxHeight, this.boxWidth]); }, makeSphere: function(pos, goTo, roomName){ log("roomName in makeSphere", roomName); log("****goTo", goTo); // var posToGet = this.getPosition(pos); var posToGet = pos; log("$$$ posToGet", posToGet); var ent = Entities.addEntity({ type: "Sphere", lifetime: -1, userData: userData, position: posToGet, dimensions: mkVFA([1,1,1]), script: "( function () { return { enterEntity: function () { MyAvatar.position = " + JSON.stringify(goTo) + " ;}}});" }); this.addEntity(ent); var textEnt = Entities.addEntity(textEntityProps(roomName, ent)); this.addEntity(textEnt); } }; } function textEntityProps(text, parentID){ log("text in text entity props", text); var parentPos = Entities.getEntityProperties(parentID, ["position"]).position; log("parentPos", parentPos); var pos = Vec3.sum(parentPos, mkVFA([0,1,0])); log("pos in textEntity Props", pos); var lengthOfChar = 0.07; var lengthOfSign = lengthOfChar * text.length; var props = { type: "Text", text: text, lifetime: -1, userData: userData, dimensions: mkVFA([lengthOfSign,0.5,0.1]), rotation: MyAvatar.orientation, position: pos, parentID: parentID } log("&*&* text props", props); return props; } /* var entitiesGroup = { currentIDs: [], name: "", addEntity: function(entityID){ this.currentIDs.push(entityID); }, removeEntity: function(id){ log("in remove entity"); var index = -1; for (var i = 0; i < this.currentIDs.length; i++){ log("this.currentIDs[i]", this.currentIDs[i]); log("id", id); if (this.currentIDs[i] === id) { index = i; break; } } log("index", index); print(index); if (index > -1) { this.currentIDs.splice(index,1); Entities.deleteEntity(id); } }, changeName: function(name){ this.name = name; } deleteAllEntities: function(){ while (this.currentIDs.length > 0){ this.removeEntity(this.currentIDs[0]); } }, getProps: function(index, id){ log("in get props") if (typeof index == "number"){ log("in index get props"); return Entities.getEntityProperties(this.currentIDs[index]); } if (id){ log("in id get props"); return Entities.getEntityProperties(id); } }, getAllProps: function(){ log("in get all props") log("this.curretIds", this.currentIDs); var array = this.currentIDs.map(function(id){ // log("id", id) var props = this.getProps(null,id); // log("props", props) return props; }, this) log("array", array); return array; }, editProps: function(index, id, props){ // log("editing props"); // log("index", index); // log("id", id); // log("props", props); if (typeof index === "number"){ // log("this.currentIDs[index]", this.currentIDs[index]) // log("props",props); // log("index", index); // log("this.currentIDs", this.currentIDs) // var boxProps = entitiesGroup.getProps(index).rotation; // log("boxPropsPosition", boxProps); Entities.editEntity(this.currentIDs[index], props); // boxProps = entitiesGroup.getProps(index).rotation; // log("boxPropsPosition", boxProps); } if (id){ Entities.editEntity(id, props); } }, makeParent: function(pID){ print("in make Parent"); this.currentIDs.slice(1).forEach(function(id){ print("id", id); Entities.editEntity(id,{ parentID: pID }) }) }, lastId: function(){ return this.currentIDs.length-1; }, spin: function(amount){ var id = this.currentIDs[0]; Entities.editEntity(id, { angularVelocity: {x:amount, y:amount, z: amount} }); }, speed: function(speed){ log("speed", speed); var newSpeed = lerp (0,127,0.0,2.0,speed); var newUserData = JSON.parse(userDataToUse); log("newUserData",newUserData); newUserData.ProceduralEntity.uniforms.speed = newSpeed props = {userData: JSON.stringify(newUserData)}; // log("props",props); this.currentIDs.forEach(function(id) {Entities.editEntity(id, props)}); // log("newProps", this.getProps(1).userData); }, emit: function(emit){ log("emit", emit); var newEmit = lerp (0,127,0.0,1.0,emit); var newUserData = JSON.parse(userDataToUse); log("newUserData",newUserData); newUserData.ProceduralEntity.uniforms.uEmit = newEmit props = {userData: JSON.stringify(newUserData)}; // log("props",props); this.currentIDs.forEach(function(id) {Entities.editEntity(id, props)}); // log("newProps", this.getProps(1).userData); }, specular: function(specular){ log("specular", specular); var newSpecular = lerp (0,127,0.0,1.0,specular); var newUserData = JSON.parse(userDataToUse); log("newUserData",newUserData); newUserData.ProceduralEntity.uniforms.speed = newSpecular props = {userData: JSON.stringify(newUserData)}; // log("props",props); this.currentIDs.forEach(function(id) {Entities.editEntity(id, props)}); // log("newProps", this.getProps(1).userData); }, shine: function(shine){ log("shine", shine); var newShine = lerp (0,127,0.0,255.0,shine); var newUserData = JSON.parse(userDataToUse); log("newUserData",newUserData); newUserData.ProceduralEntity.uniforms.speed = newShine props = {userData: JSON.stringify(newUserData)}; // log("props",props); this.currentIDs.forEach(function(id) {Entities.editEntity(id, props)}); // log("newProps", this.getProps(1).userData); }, boxLength:1, boxWidth:1, boxHeight:1, boxThickness:1, distanceApart: [0,0,0], length: function(length){ this.boxLength = length; var boxProps = makeNewBoxProps(this.boxLength, this.boxWidth, this.boxHeight,this.boxThickness, this.distanceApart); log("boxProps", boxProps) var propsGroup = makePropsForBox(0,boxProps); log("propsGroup", propsGroup); propsGroup.forEach(function(props,index){ var actuallPropsToSend = mkBoxProps(props); log("props",props); log("actualPropsToSend", actuallPropsToSend) this.editProps(index,null,actuallPropsToSend); },this) }, width: function(width){ this.boxWidth = width; var boxProps = makeNewBoxProps(this.boxLength, this.boxWidth, this.boxHeight,this.boxThickness, this.distanceApart); log("boxProps", boxProps) var propsGroup = makePropsForBox(0,boxProps); log("propsGroup", propsGroup); propsGroup.forEach(function(props,index){ var actuallPropsToSend = mkBoxProps(props); log("props",props); log("actualPropsToSend", actuallPropsToSend) this.editProps(index,null,actuallPropsToSend); },this) }, height: function(height){ this.boxHeight = height; var boxProps = makeNewBoxProps(this.boxLength, this.boxWidth, this.boxHeight,this.boxThickness, this.distanceApart); log("boxProps", boxProps) var propsGroup = makePropsForBox(0,boxProps); log("propsGroup", propsGroup); propsGroup.forEach(function(props,index){ var actuallPropsToSend = mkBoxProps(props); log("props",props); log("actualPropsToSend", actuallPropsToSend) this.editProps(index,null,actuallPropsToSend); },this) }, thickness: function(thickness){ this.boxThickness = thickness; var boxProps = makeNewBoxProps(this.boxLength, this.boxWidth, this.boxHeight,this.boxThickness, this.distanceApart); log("boxProps", boxProps) var propsGroup = makePropsForBox(0,boxProps); log("propsGroup", propsGroup); propsGroup.forEach(function(props,index){ var actuallPropsToSend = mkBoxProps(props); log("props",props); log("actualPropsToSend", actuallPropsToSend) this.editProps(index,null,actuallPropsToSend); },this) } }; */ function getNormPosition(normP, realP, dimensions){ // log("!@#") // log("normP", normP); // log("realP", realP); // log("dimensions", dimensions); var xHalfDis = dimensions[0] / 2; var xMinMax = [realP[0] - xHalfDis, realP[0] + xHalfDis]; var yHalfDis = dimensions[1] / 2; var yMinMax = [realP[0] - yHalfDis, realP[0] + yHalfDis]; var zHalfDis = dimensions[2] / 2; var zMinMax = [realP[0] - zHalfDis, realP[0] + zHalfDis]; // log("xMinMax", xMinMax); // log("yMinMax", yMinMax); // log("zMinMax", zMinMax); var unitX = normP[0] * dimensions[0]; var unitY = normP[1] * dimensions[1]; var unitZ = normP[2] * dimensions[2]; // log("unitX", unitX); // log("unitY", unitY); // log("unitZ", unitZ); var newX = xMinMax[0] + unitX; var newY = yMinMax[0] + unitY; var newZ = zMinMax[0] + unitZ; // log("newX", newX); // log("newY", newY); // log("newZ", newZ); var finalPosition = mkVFA([newX, newY, newZ]); // log("finalPosition", finalPosition); return finalPosition; } var boxes = { currentBoxes: [], audioZones: [], addBoxes: function(box, name){ log("((()))") log("name in add boxes", name); box.changeName(name); this.currentBoxes.push(box); }, removeBox: function(idx){ log("boxes:: in remove entity"); // var index = -1; // for (var i = 0; i < this.currentBoxes.length; i++){ // log("this.currentBoxes[i]", this.currentBoxes[i]); // log("id", id); // if (this.currentBoxes[i] === id) { // index = i; // break; // } // } // log("index", index); // print(index); if (idx > -1) { this.currentBoxes[idx].deleteAllEntities(); this.currentBoxes.splice(idx,1); } }, removeAllBoxes: function(){ while (this.currentBoxes.length > 0){ this.removeBox(0); } }, makeSigns: function(){ log("in Make Signs"); for (var i = 0; i < this.currentBoxes.length; i++){ var count = -2; for (var j = 0; j < this.currentBoxes.length; j++){ if (i === j) { log("the same, continuing") continue; } var pos = Vec3.sum(this.currentBoxes[i].position, mkVFA([count,1,3])) // getNormPosition(normPosition, mkAFV(position),[this.boxLength, this.boxHeight, this.boxWidth]); this.currentBoxes[i].makeSphere(pos, this.currentBoxes[j].position, this.currentBoxes[j].name); count+=2; } } }, getAudioZone: function(idx){ var position = this.currentBoxes[idx].position; var length = this.currentBoxes[idx].boxLength; var height = this.currentBoxes[idx].boxHeight; var width = this.currentBoxes[idx].boxWidth; log("position", position); log("length", length); log("height", height); log("width", width); var startx = position.x - length / 2; var endX = position.x + length / 2; var starty = position.y - height / 2; var endy = position.y + height / 2; var startz = position.z - width / 2; var endz = position.z + width / 2; var zone = { startx: startx, endX : endX, starty: starty, endy: endy, startz: startz, endz: endz }; log("ZONE:", zone) return zone; }, getAudioZones: function(){ this.currentBoxes.forEach(function(box, idx){ this.audioZones.push(this.getAudioZone(idx)); }, this) }, printAudioZones: function(){ return JSON.stringify(this.audioZones); } } function changeSpeed(newSpeed){ entitiesGroup.speed(newSpeed); } function changeEmit(newSpeed){ entitiesGroup.emit(newSpeed); } function changeSpecular(newSpeed){ entitiesGroup.specular(newSpeed); } function changeShine(newSpeed){ entitiesGroup.shine(newSpeed); } function changeLength(length){ entitiesGroup.length(length); } function changeWidth(width){ entitiesGroup.width(width); } function changeHeight(height){ entitiesGroup.height(height); } function changeThickness(thickness){ entitiesGroup.thickness(thickness); } function spin(amount){ entitiesGroup.spin(amount); } function multScAr(scalar,array){ log("scalar", scalar); log("array", array); // if (scalar === 0) return [0,0,0]; var newArray = array.map(function(index){ return index * scalar; }); log("new Array", newArray); return newArray; } function addScAr(scalar,array){ log("scalar", scalar); log("array", array); if (scalar === 0) {return [0,0,0];} var newArray = array.map(function(index){ return index + scalar; }); log("new Array", newArray); return newArray; } function howManyTimes(num,functionCallBack, passInProps){ var counter = 0; while (counter < num){ functionCallBack(counter,passInProps); counter++; } } function sumArrays(array1, array2){ // log("array1",array1); // log("array2",array2); var array3 = []; array3[0] = array1[0] + array2[0]; array3[1] = array1[1] + array2[1]; array3[2] = array1[2] + array2[2]; return array3; } function makePropsForBox(currentCounter, props){ var distanceApart = props.distanceApart; var length = props.length; var width = props.width; var height = props.height; var wallThickness = props.wallThickness; var lengthWithOffset = length + wallThickness; var offsetFromCounter = multScAr(currentCounter,distanceApart); var floor =[ "av", [lengthWithOffset, wallThickness/2, width + wallThickness*2], [ 0, 0, 0], [0.5,1.0,0.5], sumArrays([0,-height/2,0],offsetFromCounter), [50, 250, 250], "floor" ]; var ceiling = [ "av", [lengthWithOffset, wallThickness/2, width + wallThickness*2], [ 0, 0, 0], [0.5,0.0,0.5], sumArrays([0,height/2,0],offsetFromCounter), [250, 50, 250], "ceiling" ]; var wall1 = [ "av", // [lengthWithOffset, width, height + width], [length, height, wallThickness], [0, 0, 0], [0.5 ,0.5, 0.0], // sumArrays([0, -length/2, length/2], offsetFromCounter), sumArrays([0, 0, width/2], offsetFromCounter), [250, 0, 90], "wall1" ]; var wall2 = [ "av", [length, height, wallThickness], [0, 0, 0], [0.5 ,0.5, 1.0], sumArrays([0, 0, -width/2], offsetFromCounter), [0, 170, 90], "wall2" ]; var wall3 = [ "av", [wallThickness/2, height, width + wallThickness*2], [0, 0, 0], [0.0 ,0.5, 0.5], sumArrays([ -lengthWithOffset/2, 0, 0], offsetFromCounter), [150, 170, 0], "wall3" ]; var wall4 = [ "av", [wallThickness/2, height, width + wallThickness*2], [0, 0, 0], [1.0 ,0.5, 0.5], sumArrays([ lengthWithOffset/2, 0, 0], offsetFromCounter), [150, 170, 80], "wall4" ]; var zone = [ "av", [length, height, width], [0, 0, 0], [0.5 ,0.5, 0.5], sumArrays([0, 0, 0], offsetFromCounter), [50, 0, 255], "Zone" ]; var propsGroup = [floor, ceiling, wall1, wall2, wall3, wall4, zone]; return propsGroup; } function makeBoxes(currentCounter, props){ var position = props.position; var distanceApart = props.distanceApart; var length = props.length; var width = props.width; var height = props.height; var wallThickness = props.wallThickness; var lengthWithOffset = length + wallThickness; var offsetFromCounter = multScAr(currentCounter,distanceApart); // log("offsetFromCounter", offsetFromCounter) // position, dimensions, rotations, registration, offset, color, name var newBox = new BoxMakerGroup(); log("newBox",newBox); // newBox.addEntity(mkboxNoShader( // position, // [length, height, width], // [0, 0, 0], // [0.5 ,0.5, 0.5], // sumArrays([0, 0, 0], offsetFromCounter), // [50, 0, 255], // // "Parent")); newBox.boxLength = length; newBox.boxWidth = width; newBox.boxHeight = height; newBox.position = position === "av" ? MyAvatar.position : position; newBox.addEntity(mkBox( position, [lengthWithOffset, wallThickness/2, width + wallThickness*2], [ 0, 0, 0], [0.5,1.0,0.5], sumArrays([0,-height/2,0],offsetFromCounter), [50, 250, 250], "floor")); newBox.addEntity(mkBox( position, [lengthWithOffset, wallThickness/2, width + wallThickness*2], [ 0, 0, 0], [0.5,0.0,0.5], sumArrays([0,height/2,0],offsetFromCounter), [250, 50, 250], "ceiling")); newBox.addEntity(mkBox( position, // [lengthWithOffset, width, height + width], [length, height, wallThickness], [0, 0, 0], [0.5 ,0.5, 0.0], // sumArrays([0, -length/2, length/2], offsetFromCounter), sumArrays([0, 0, width/2], offsetFromCounter), [250, 0, 90], "wall1")); newBox.addEntity(mkBox( position, [length, height, wallThickness], [0, 0, 0], [0.5 ,0.5, 1.0], sumArrays([0, 0, -width/2], offsetFromCounter), [0, 170, 90], "wall2")); newBox.addEntity(mkBox( position, [wallThickness/2, height, width + wallThickness*2], [0, 0, 0], [0.0 ,0.5, 0.5], sumArrays([ -lengthWithOffset/2, 0, 0], offsetFromCounter), [150, 170, 0], "wall3")); newBox.addEntity(mkBox( position, [wallThickness/2, height, width + wallThickness*2], [0, 0, 0], [1.0 ,0.5, 0.5], sumArrays([ lengthWithOffset/2, 0, 0], offsetFromCounter), [150, 170, 80], "wall4")); newBox.addEntity(mkZone( position, [length, height, width], [0, 0, 0], [0.5 ,0.5, 0.5], sumArrays([0, 0, 0], offsetFromCounter), [50, 0, 255], "Zone")); // newBox.makeSphere([0.5,0.3,0.7]); return newBox; } var length = 10; var width = 10; var height = 10; var wallThickness = 0.1; var distanceApart = [0.2,0.2,0.4]; var propsToMakeBox = { length: length, width: width, height: height, wallThickness: wallThickness, distanceApart: sumArrays([length,width,height],distanceApart) }; function makeNewBoxProps(length, width, height, wallThickness, distanceApart, position){ log("distanceApart:::::",distanceApart); return { length: length, width: width, height: height, wallThickness: wallThickness, distanceApart: sumArrays([length,width,height],distanceApart), position: position }; } // howManyTimes(1, makeBoxes, propsToMakeBox); // log("@@@myPosition", MyAvatar.position); boxes.addBoxes(makeBoxes(0, makeNewBoxProps(10, 10, 7, 0.5, [0,0,0], "av")), "room1:small"); // log("box 0 floor:", boxes.currentBoxes[0].getFloor()); var vecToAdd = mkVFA([positionFinder(10,22, 3),0,0]); var newPosition = Vec3.sum(MyAvatar.position,vecToAdd); boxes.addBoxes(makeBoxes(0, makeNewBoxProps(22, 22, 15, 0.5, [0,0,0], newPosition)), "room2:med"); // log("box 1 floor:", boxes.currentBoxes[1].getFloor()); var vecToAdd = mkVFA([positionFinder(22,30, 3),0,0]); var newPosition = Vec3.sum(newPosition,vecToAdd); boxes.addBoxes(makeBoxes(0, makeNewBoxProps(30, 30, 18, 0.5, [0,0,0], newPosition)), "room3:large"); // log("box 2 floor:", boxes.currentBoxes[2].getFloor()); var vecToAdd = mkVFA([positionFinder(30,40, 3),0,0]); var newPosition = Vec3.sum(newPosition,vecToAdd); boxes.addBoxes(makeBoxes(0, makeNewBoxProps(40, 40, 27, 0.5, [0,0,0], newPosition)), "room4:yuge"); // log("box 3 floor:", boxes.currentBoxes[3].getFloor()); boxes.makeSigns(); // var newPosition = Vec3.sum(newPosition, mkVFA(positionFinder(8,15),0,0)); // boxes.addBoxes(makeBoxes(0, makeNewBoxProps(20, 20, 20, 0.5, "", newPosition))); // var newPosition = Vec3.sum(newPosition, mkVFA(positionFinder(8,15),0,0)); // boxes.addBoxes(makeBoxes(0, makeNewBoxProps(30, 30, 30, 0.5, "", newPosition))); boxes.getAudioZones(); print(boxes.printAudioZones()); function positionFinder(a, b, gap){ var aHalf = a/2; var bHalf = b/2; var newDistance = aHalf + bHalf + gap; log("&&&new distance", newDistance); return newDistance; } function lerp(InputLow, InputHigh, OutputLow, OutputHigh, Input) { return ((Input - InputLow) / (InputHigh - InputLow)) * (OutputHigh - OutputLow) + OutputLow; } // lerp (0,127,0,360,eventData.velocity); Script.scriptEnding.connect(function(){ if (!KEEP){ boxes.removeAllBoxes(); } }); }());