// // itemSpawner.js // // Created by Clement Brisset on 11/16/2016. // Copyright 2015 High Fidelity, Inc. // // This script spawns items for the ping pong table // // 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 ITEM_LIFETIME = 2300; // 30 min. var itemID; this.preload = function(entityID) { itemID = entityID; } this.spawnItem = function () { var properties = Entities.getEntityProperties(itemID, [ "type", "name", "modelURL", "shapeType", "parentID", "position", "rotation", "dimensions", "gravity", "restitution" ]); var parent = Entities.getEntityProperties(properties.parentID, ["position", "rotation"]); var pos = { x: 0.0, y: 0.50, z: properties.name.indexOf("blue") !== -1 ? 1.40 : -1.40, }; pos = Vec3.sum(parent.position, Vec3.multiplyQbyV(parent.rotation, pos)); var userData = "{}"; // Equipped items don't collide // // if (properties.name.indexOf("paddle") !== -1) { // userData = JSON.stringify({ // grabbableKey: { invertSolidWhileHeld: true }, // wearable: { // joints: { // RightHand: [ { x: 0.12, y: 0.16, z: 0.04 }, { x: 0.5, y: 0.5, z: -0.5, w: 0.5 } ], // LeftHand: [ { x: -0.12, y: 0.16, z: 0.04 }, { x: 0.5, y: -0.5, z: 0.5, w: 0.5 } ] // } // } // }); // } print("Spawning a new " + properties.name); Entities.addEntity({ type: properties.type, name: "Spawned " + properties.name, modelURL: properties.modelURL, shapeType: properties.shapeType, position: pos, rotation: properties.rotation, dimensions: properties.dimensions, velocity: { x: 0, y: 0.1, z: 0 }, gravity: properties.gravity, restitution: properties.restitution, lifetime: ITEM_LIFETIME, collisionsWillMove: 1, dynamic: 1, density: 100, userData: userData, }); } this.startNearTrigger = function () { this.spawnItem(); } this.startFarTrigger = function () { this.spawnItem(); } });