283 lines
9.4 KiB
JavaScript
283 lines
9.4 KiB
JavaScript
"use strict";
|
|
/*jslint vars:true, plusplus:true, forin:true*/
|
|
/*global Tablet, Script, */
|
|
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
|
|
//
|
|
// pizzaSpawner.js
|
|
//
|
|
// Created by Zach Fox on 2017-06-07
|
|
// Copyright 2017 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 () { // BEGIN LOCAL_SCOPE
|
|
|
|
numPizzas = 0;
|
|
function inFrontOf(distance, offset) {
|
|
var sumToReturn = Vec3.sum(MyAvatar.position,
|
|
Vec3.multiply(distance, Quat.getForward(MyAvatar.orientation)))
|
|
return Vec3.sum(sumToReturn, Vec3.sum(offset, JSON.parse('{"x":0.0,"y":' + (0.75+0.125*numPizzas) +',"z":0.0}')));
|
|
}
|
|
|
|
var table = false;
|
|
function spawnTable() {
|
|
table = Entities.addEntity({
|
|
type: 'Box',
|
|
dimensions: { x: 0.5, y: 1.85, z: 0.5 },
|
|
"gravity": {
|
|
"x": 0,
|
|
"y": -25,
|
|
"z": 0
|
|
},
|
|
dynamic: true,
|
|
color: { red: 150, green: 150, blue: 150 },
|
|
name: 'PizzaTable',
|
|
position: inFrontOf(2, JSON.parse('{"x":0.0,"y":-1.0,"z":0.0}')),
|
|
});
|
|
}
|
|
|
|
pizzaPies = [];
|
|
function spawnPizzaPie() {
|
|
pizzaPies.push(Entities.addEntity({
|
|
"clientOnly": 0,
|
|
"collisionsWillMove": 1,
|
|
"dimensions": {
|
|
"x": 0.57292401790618896,
|
|
"y": 0.045,
|
|
"z": 0.59015458822250366
|
|
},
|
|
"dynamic": 1,
|
|
"gravity": {
|
|
"x": 0,
|
|
"y": -5,
|
|
"z": 0
|
|
},
|
|
"modelURL": "http://hifi-content.s3.amazonaws.com/alan/dev/pizza.fbx",
|
|
"position": inFrontOf(2, JSON.parse('{"x":0.0,"y":0.0,"z":0.0}')),
|
|
"queryAACube": {
|
|
"scale": 0.8257560133934021,
|
|
"x": -0.41287800669670105,
|
|
"y": -0.36988845467567444,
|
|
"z": -0.41287800669670105
|
|
},
|
|
"restitution": 0,
|
|
"rotation": {
|
|
"w": 0.999603271484375,
|
|
"x": 0.011062741279602051,
|
|
"y": 0.025650382041931152,
|
|
"z": -0.0001678466796875
|
|
},
|
|
"script": "https://s3-us-west-1.amazonaws.com/hifi-content/zfox/scripts/Edible.js?2",
|
|
"shapeType": "box",
|
|
"type": "Model",
|
|
"userData": "{\"grabbableKey\":{\"grabbable\":true}}",
|
|
"friction": 0.8
|
|
}));
|
|
}
|
|
|
|
pizzaSteams = [];
|
|
function spawnPizzaSteam() {
|
|
pizzaSteams.push(Entities.addEntity({
|
|
"accelerationSpread": {
|
|
"x": 0,
|
|
"y": 1,
|
|
"z": 0.5
|
|
},
|
|
"alpha": 0.0099999997764825821,
|
|
"alphaFinish": 0.0099999997764825821,
|
|
"alphaStart": 0.0099999997764825821,
|
|
"clientOnly": 0,
|
|
"color": {
|
|
"blue": 200,
|
|
"green": 200,
|
|
"red": 200
|
|
},
|
|
"colorFinish": {
|
|
"blue": 200,
|
|
"green": 200,
|
|
"red": 200
|
|
},
|
|
"colorStart": {
|
|
"blue": 200,
|
|
"green": 200,
|
|
"red": 200
|
|
},
|
|
"dimensions": {
|
|
"x": 1.4300000667572021,
|
|
"y": 1.4300000667572021,
|
|
"z": 1.4300000667572021
|
|
},
|
|
"emitAcceleration": {
|
|
"x": -0.5,
|
|
"y": 0,
|
|
"z": -0.5
|
|
},
|
|
"emitOrientation": {
|
|
"w": 0.70699995756149292,
|
|
"x": -0.7072136402130127,
|
|
"y": -1.5258869098033756e-05,
|
|
"z": -1.5258869098033756e-05
|
|
},
|
|
"emitRate": 12,
|
|
"emitSpeed": 0.10000000149011612,
|
|
"lifespan": 1,
|
|
"lifetime": 3600,
|
|
"maxParticles": 6210,
|
|
"name": "Pizza Steam",
|
|
"parentID": pizzaPies[numPizzas-1].id,
|
|
"particleRadius": 0.38999998569488525,
|
|
"position": inFrontOf(2, JSON.parse('{"x":0.0,"y":0.0,"z":0.0}')),
|
|
"queryAACube": {
|
|
"scale": 2.4768328666687012,
|
|
"x": -68.603317260742188,
|
|
"y": -1.2696535587310791,
|
|
"z": -220.0611572265625
|
|
},
|
|
"radiusFinish": 0.38999998569488525,
|
|
"radiusStart": 0.38999998569488525,
|
|
"rotation": {
|
|
"w": 0.9996337890625,
|
|
"x": -0.026321828365325928,
|
|
"y": -1.52587890625e-05,
|
|
"z": 1.52587890625e-05
|
|
},
|
|
"speedSpread": 0,
|
|
"textures": "https://content.highfidelity.com/DomainContent/production/Particles/wispy-smoke.png",
|
|
"type": "ParticleEffect",
|
|
"userData": "{\"grabbableKey\":{\"grabbable\":true}}",
|
|
"friction": 0.8
|
|
}));
|
|
}
|
|
|
|
pizzaBoxBottoms = [];
|
|
function spawnPizzaBoxBottom() {
|
|
pizzaBoxBottoms.push(Entities.addEntity({
|
|
"clientOnly": 0,
|
|
"collisionsWillMove": 1,
|
|
"compoundShapeURL": "http://hifi-content.s3.amazonaws.com/alan/dev/Pizza-Box-Bottom.obj?1",
|
|
"dimensions": {
|
|
"x": 0.64875650405883789,
|
|
"y": 0.050600022077560425,
|
|
"z": 0.64339995384216309
|
|
},
|
|
"dynamic": 1,
|
|
"gravity": {
|
|
"x": 0,
|
|
"y": -5,
|
|
"z": 0
|
|
},
|
|
"lifetime": 3600,
|
|
"modelURL": "http://hifi-content.s3.amazonaws.com/alan/dev/Pizza-Box-Bottom.fbx?4",
|
|
"position": inFrontOf(2, JSON.parse('{"x":0.0,"y":-0.02,"z":0.0}')),
|
|
"queryAACube": {
|
|
"scale": 0.91510045528411865,
|
|
"x": -0.44828051328659058,
|
|
"y": -0.45755022764205933,
|
|
"z": -0.44494646787643433
|
|
},
|
|
"restitution": 0,
|
|
"rotation": {
|
|
"w": 0.78228425979614258,
|
|
"x": -0.0001068115234375,
|
|
"y": -0.62291908264160156,
|
|
"z": -4.57763671875e-05
|
|
},
|
|
"shapeType": "compound",
|
|
"type": "Model",
|
|
"userData": "{\"grabbableKey\":{\"grabbable\":true,\"kinematic\":false}}",
|
|
"friction": 0.8
|
|
}));
|
|
}
|
|
|
|
pizzaBoxTops = [];
|
|
function spawnPizzaBoxTop() {
|
|
pizzaBoxTops.push(Entities.addEntity({
|
|
"clientOnly": 0,
|
|
"collisionsWillMove": 1,
|
|
"compoundShapeURL": "http://hifi-content.s3.amazonaws.com/alan/dev/Pizza-Box-Top.obj?1",
|
|
"dimensions": {
|
|
"x": 0.68389636278152466,
|
|
"y": 0.052187561988830566,
|
|
"z": 0.74948406219482422
|
|
},
|
|
"dynamic": 1,
|
|
"gravity": {
|
|
"x": 0,
|
|
"y": -5,
|
|
"z": 0
|
|
},
|
|
"lifetime": 3600,
|
|
"modelURL": "http://hifi-content.s3.amazonaws.com/alan/dev/Pizza-Box-Top.fbx?3",
|
|
"position": inFrontOf(2, JSON.parse('{"x":0.0,"y":0.02,"z":0.0}')),
|
|
"queryAACube": {
|
|
"scale": 1.0159547328948975,
|
|
"x": -0.47995460033416748,
|
|
"y": -0.43442463874816895,
|
|
"z": -0.47474372386932373
|
|
},
|
|
"restitution": 0,
|
|
"rotation": {
|
|
"w": 0.77904939651489258,
|
|
"x": 0,
|
|
"y": -0.62676429748535156,
|
|
"z": 0
|
|
},
|
|
"shapeType": "compound",
|
|
"type": "Model",
|
|
"userData": "{\"grabbableKey\":{\"grabbable\":true,\"kinematic\":false}}",
|
|
"friction": 0.8
|
|
}));
|
|
}
|
|
|
|
function spawnPizza() {
|
|
numPizzas++;
|
|
if (numPizzas === 1) {
|
|
spawnTable();
|
|
}
|
|
spawnPizzaPie();
|
|
spawnPizzaSteam();
|
|
spawnPizzaBoxBottom();
|
|
spawnPizzaBoxTop();
|
|
}
|
|
|
|
var pizzaButton;
|
|
var buttonName = "PIZZA";
|
|
var tablet = null;
|
|
function startup() {
|
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
|
pizzaButton = tablet.addButton({
|
|
text: buttonName
|
|
});
|
|
pizzaButton.clicked.connect(spawnPizza);
|
|
}
|
|
|
|
function shutdown() {
|
|
pizzaButton.clicked.disconnect(spawnPizza);
|
|
tablet.removeButton(pizzaButton);
|
|
if (table) {
|
|
Entities.deleteEntity(table);
|
|
}
|
|
pizzaBoxTops.forEach(function (entity) {
|
|
Entities.deleteEntity(entity);
|
|
});
|
|
pizzaBoxBottoms.forEach(function (entity) {
|
|
Entities.deleteEntity(entity);
|
|
});
|
|
pizzaSteams.forEach(function (entity) {
|
|
Entities.deleteEntity(entity);
|
|
});
|
|
pizzaPies.forEach(function (entity) {
|
|
Entities.deleteEntity(entity);
|
|
});
|
|
numPizzas = 0;
|
|
}
|
|
|
|
//
|
|
// These functions will be called when the script is loaded.
|
|
//
|
|
startup();
|
|
Script.scriptEnding.connect(shutdown);
|
|
|
|
}()); // END LOCAL_SCOPE
|