// tutorialZoneEntityScript.js // // Script Type: Entity // Created by Eric Levin on 1/20/16. // Copyright 2016 High Fidelity, Inc. // // This entity script creates a tutorial demonstrating the use of the vives when a user enters the entity // 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; var viveTutorialZone = function() { _this = this; this.RIGHT_HAND = 1; this.LEFT_HAND = 0; this.RIGHT_VIVE_MODEL_URL = "http://hifi-public.s3.amazonaws.com/viveController/ViveController.fbx"; this.LEFT_VIVE_MODEL_URL = "http://hifi-public.s3.amazonaws.com/viveController/ViveController.fbx"; this.RIGHT_HAND_JOINT_INDEX = MyAvatar.getJointIndex("RightHand"); this.LEFT_HAND_JOINT_INDEX = MyAvatar.getJointIndex("LeftHand"); this.TRIGGER_PLAY_MESSAGE = "PlayBackOnAssignment"; this.TRIGGER_STOP_MESSAGE = "StopPlayBackOnAssignment"; this.TRIGGER_CHANNEL = "viveTutorialChannel"; }; viveTutorialZone.prototype = { enterEntity: function() { this.placeControllersInHand(); Messages.sendMessage(this.TRIGGER_CHANNEL, this.TRIGGER_PLAY_MESSAGE); }, placeControllersInHand: function() { var rotation = Quat.multiply(MyAvatar.getRightPalmRotation(), Quat.fromPitchYawRollDegrees(0, 180, -100)); var position = Vec3.sum(MyAvatar.getRightHandPosition(), Vec3.multiplyQbyV(rotation, { x: 0.13, y: -0.02, z: -0.06 })); this.rightHandviveModel = Entities.addEntity({ type: "Model", name: "Right vive", modelURL: this.RIGHT_VIVE_MODEL_URL, parentID: MyAvatar.sessionUUID, parentJointIndex: this.RIGHT_HAND_JOINT_INDEX, dimensions: { x: 0.24, y: 0.15, z: 0.11 }, rotation: rotation, position: position }); rotation = Quat.multiply(MyAvatar.getLeftPalmRotation(), Quat.fromPitchYawRollDegrees(0, 0, 100)); position = Vec3.sum(MyAvatar.getLeftHandPosition(), Vec3.multiplyQbyV(rotation, { x: 0.11, y: 0.0, z: 0.035 })); this.leftHandviveModel = Entities.addEntity({ type: "Model", name: "Left vive", modelURL: this.LEFT_VIVE_MODEL_URL, dimensions: { x: 0.24, y: 0.15, z: 0.11 }, parentID: MyAvatar.sessionUUID, parentJointIndex: this.LEFT_HAND_JOINT_INDEX, position: position, rotation: rotation }); }, leaveEntity: function() { Messages.sendMessage(this.TRIGGER_CHANNEL, this.TRIGGER_STOP_MESSAGE); this.cleanup(); }, preload: function(entityID) { this.entityID = entityID; }, cleanup: function() { Entities.deleteEntity(this.rightHandviveModel); Entities.deleteEntity(this.leftHandviveModel); }, unload: function() { this.cleanup(); } }; return new viveTutorialZone(); });