// CameraFlasher.js // 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 _this = this; var IMPORT_URL_PINSET = "http://hifi-content.s3.amazonaws.com/caitlyn/production/bowlingAlley/bpins4.svo.json"; var IMPORT_URL_BALL = "http://hifi-content.s3.amazonaws.com/caitlyn/production/bowlingAlley/bowlingBall.svo.json"; var soundURL ='http://hifi-production.s3.amazonaws.com/tutorials/soundMaker/bell.wav'; var ringSound; this.preload = function(entityID) { print("preload("+entityID+")"); _this.entityID = entityID; ringSound = SoundCache.getSound(soundURL); } this.startNearTrigger = function(entityID, mouseEvent) { print("START BOWLING RESET TRIGGER"); // Reset pins var bowlingAlley = Entities.getEntityProperties(this.entityID, ['parentID']).parentID; // get the bowling alley's parent ID var entProperties = Entities.getEntityProperties(bowlingAlley);//, ["position", "rotation"]);//, "position").position;//Entities.getEntityProperties(this); var jointNames = Entities.getJointNames(bowlingAlley); print("Joint Names "+jointNames); var jointIndex = Entities.getJointIndex(bowlingAlley, "pinLocatorJoint"); print("JOINT INDEX IS "+jointIndex); var jointLocInObjectFrame = Entities.getAbsoluteJointTranslationInObjectFrame(bowlingAlley, jointIndex); var jointLocInWorld = Vec3.sum(entProperties.position, Vec3.multiplyQbyV(entProperties.rotation, jointLocInObjectFrame)); print("LOCATION IS "+JSON.stringify(jointLocInWorld)); Entities.findEntities(MyAvatar.position, 1000).forEach(function(entity){ try{ var userData = JSON.parse(Entities.getEntityProperties(entity, ['userData']).userData); if (userData.isBowlingPin) { print("Found one, deleting it: " + entity); Entities.deleteEntity(entity); } } catch(e) {} }); print("ADDING NEW PINS"); Clipboard.importEntities(IMPORT_URL_PINSET); Clipboard.pasteEntities(jointLocInWorld); print("PINS ADDED"); // Add new ball jointIndex = Entities.getJointIndex(bowlingAlley, "ballLocatorJoint"); print("BALL JOINT INDEX IS "+jointIndex); jointLocInObjectFrame = Entities.getAbsoluteJointTranslationInObjectFrame(bowlingAlley, jointIndex); jointLocInWorld = Vec3.sum(entProperties.position, Vec3.multiplyQbyV(entProperties.rotation, jointLocInObjectFrame)); print("LOCATION IS "+JSON.stringify(jointLocInWorld)); Clipboard.importEntities(IMPORT_URL_BALL); Clipboard.pasteEntities(jointLocInWorld); print("BALL ADDED"); // Completion sound Audio.playSound(ringSound, { position: jointLocInWorld, volume: 0.5 }); } });