56 lines
2.1 KiB
JavaScript
56 lines
2.1 KiB
JavaScript
// 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 = "http://hifi-content.s3.amazonaws.com/caitlyn/production/bowlingAlley/bpins4.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");
|
|
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));
|
|
Audio.playSound(ringSound, {
|
|
position: jointLocInWorld,
|
|
volume: 0.5
|
|
});
|
|
|
|
print("LOOKING FOR OLD PINS TO DELETE");
|
|
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) {}
|
|
});
|
|
|
|
// Script.setTimeout(function(){},2555);
|
|
print("ADDING NEW PINS");
|
|
Clipboard.importEntities(IMPORT_URL);
|
|
Clipboard.pasteEntities(jointLocInWorld);
|
|
print("COMPLETE");
|
|
}
|
|
});
|