79 lines
2.4 KiB
JavaScript
79 lines
2.4 KiB
JavaScript
//
|
|
// spawnMuter.js
|
|
//
|
|
// Created by Liv Erickson on June 2, 2017
|
|
// Copyright 2017 High Fidelity, Inc.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE of http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
/* eslint indent: ["error", 4, { "outerIIFEBody" : 0}] */
|
|
|
|
|
|
// Watch FBX and Textures
|
|
var WATCH_URL = "https://hifi-content.s3.amazonaws.com/liv/3DModels/watch/NewWatch.fbx";
|
|
var MUTED_TEXTURE = "https://hifi-content.s3.amazonaws.com/liv/3DModels/watch/Muted.png";
|
|
var OPEN_TEXTURE = "https://hifi-content.s3.amazonaws.com/liv/3DModels/watch/Open.png";
|
|
|
|
var WATCH_JOINT_INDEX = MyAvatar.getJointIndex("LeftHandIndex4");
|
|
var _textureData = { "Face": AudioDevice.getMuted() ? MUTED_TEXTURE : OPEN_TEXTURE };
|
|
|
|
|
|
var isCloseEnough = function (a, b, dist) {
|
|
return (Math.abs(a - b) <= dist);
|
|
};
|
|
|
|
// Create the watch entity
|
|
var watchEntity = {
|
|
type: "Model",
|
|
name: "Watch",
|
|
modelURL: WATCH_URL,
|
|
textures: JSON.stringify(_textureData),
|
|
position: MyAvatar.getJointPosition("LeftHandIndex1"),
|
|
rotation: Quat.fromVec3Degrees({ x: -22, y: -30, z: 0 }),
|
|
parentID: MyAvatar.sessionUUID,
|
|
parentJointIndex: WATCH_JOINT_INDEX,
|
|
dimensions: {x:0.05, y: 0.05, z: 0.05},
|
|
shapeType: "Box",
|
|
dynamic: true,
|
|
grabbable: false,
|
|
angularDamping: 1,
|
|
damping: 1
|
|
|
|
};
|
|
|
|
// Create the invisible collider trigger
|
|
var invisibleCollider = {
|
|
type: "Model",
|
|
name: "WatchCollider",
|
|
modelURL: WATCH_URL,
|
|
visible: false,
|
|
parentID: MyAvatar.sessionUUID,
|
|
rotation: Quat.multiply(MyAvatar.orientation, Quat.fromVec3Degrees({ x: 0, y: 0, z: 90 })),
|
|
parentJointIndex: MyAvatar.getJointIndex("RightHandIndex4"),
|
|
position: MyAvatar.getJointPosition("RightHandIndex4"),
|
|
dimensions: {x:0.1, y: 0.1, z: 0.1},
|
|
shapeType: "Box",
|
|
dynamic: true,
|
|
grabbable: false,
|
|
angularDamping: 1,
|
|
damping: 1
|
|
|
|
|
|
};
|
|
|
|
var watchObject = Entities.addEntity(watchEntity, true);
|
|
var watchCollider = Entities.addEntity(invisibleCollider, true);
|
|
|
|
|
|
Script.scriptEnding.connect(function () {
|
|
Entities.deleteEntity(watchObject);
|
|
Entities.deleteEntity(watchCollider);
|
|
});
|
|
|
|
AudioDevice.muteToggled.connect(function () {
|
|
_textureData = { "Face": AudioDevice.getMuted() ? MUTED_TEXTURE : OPEN_TEXTURE };
|
|
Entities.editEntity(watchObject, { textures: JSON.stringify(_textureData) });
|
|
});
|
|
|
|
|