123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 |
- "use strict";
- define(["module", "vwf/view"], function (module, view) {
- var self;
- return view.load(module, {
-
- initialize: function (options) {
- self = this;
- this.nodes = {};
-
-
-
-
- this.state.appInitialized = false;
- if (options === undefined) { options = {}; }
- if (typeof options == "object") {
- this.rootSelector = options["application-root"];
- }
- else {
- this.rootSelector = options;
- }
- this.gearvr = options.gearvr !== undefined ? options.gearvr : false;
- this.wmrright = options.wmrright !== undefined ? options.wmrright : false;
- this.wmrleft = options.wmrleft !== undefined ? options.wmrleft : false;
- },
- createdNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
- childSource, childType, childIndex, childName, callback /* ( ready ) */) {
- var node = this.state.nodes[childID];
-
-
- if (!node) {
- return;
- }
- if (this.state.scenes[childID]) {
- let scene = this.state.scenes[childID];
-
- document.body.appendChild(scene);
- createAvatarControl(scene);
- createAvatar.call(this, childID);
-
- if (this.gearvr == true) {
- console.log("CREATE GEARVR HERE!!");
- if (AFRAME.utils.device.isGearVR()) {
- let nodeName = 'gearvr-' + self.kernel.moniker();
- createGearVRControls();
- createGearVRController.call(this, childID, nodeName);
- }
- }
- if (this.wmrright == true) {
- console.log("CREATE WMR RIGHT HERE!!");
- if (AFRAME.utils.device.checkHasPositionalTracking()) {
- let nodeName = 'wmrvr-right-' + self.kernel.moniker();
- createWMRVRControls('right');
- createWMRVR.call(this, childID, nodeName);
- }
- }
- if (this.wmrleft == true) {
- console.log("CREATE WMR LEFT HERE!!");
- if (AFRAME.utils.device.checkHasPositionalTracking()) {
- let nodeName = 'wmrvr-left-' + self.kernel.moniker();
- createWMRVRControls('left');
- createWMRVR.call(this, childID, nodeName);
- }
- }
- }
- if (this.state.nodes[childID] && this.state.nodes[childID].aframeObj) {
- this.nodes[childID] = {
- id: childID,
- extends: childExtendsID,
-
-
- };
- }
-
-
-
-
-
-
- },
- initializedNode: function (nodeID, childID) {
- var node = this.state.nodes[childID];
- if (!node) {
- return;
- }
- },
- createdProperty: function (nodeId, propertyName, propertyValue) {
- return this.satProperty(nodeId, propertyName, propertyValue);
- },
- initializedProperty: function (nodeId, propertyName, propertyValue) {
- return this.satProperty(nodeId, propertyName, propertyValue);
- },
- satProperty: function (nodeId, propertyName, propertyValue) {
- var selfs = this;
- var node = this.state.nodes[nodeId];
- if (!(node && node.aframeObj)) {
- return;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- },
- firedEvent: function (nodeID, eventName, eventParameters) {
-
- var avatarName = 'avatar-' + self.kernel.moniker();
- if (eventName == "createAvatar") {
- console.log("!!!!");
- let avatarID = self.kernel.moniker();
- var nodeName = 'avatar-' + avatarID;
- var newNode = {
- "id": avatarName,
- "uri": avatarName,
- "extends": "http://vwf.example.com/aframe/avatar.vwf",
- "properties": {
- "localUrl": '',
- "remoteUrl": '',
- "displayName": randId(),
- "sharing": { audio: true, video: true }
- }
- }
- if (!self.state.nodes[avatarName]) {
- vwf_view.kernel.createChild(nodeID, avatarName, newNode);
- vwf_view.kernel.callMethod(avatarName, "createAvatarBody", []);
-
- }
- }
-
-
-
-
-
-
- },
- ticked: function (vwfTime) {
- updateAvatarPosition();
-
- if (this.gearvr == true) {
- updateHandControllerVR('gearvr-', '#gearvrcontrol');
- }
- if (this.wmrright == true) {
- updateHandControllerVR('wmrvr-right-', '#wmrvrcontrolright');
- }
- if (this.wmrleft == true) {
- updateHandControllerVR('wmrvr-left-', '#wmrvrcontrolleft');
- }
-
-
- },
- calledMethod: function( nodeID, methodName, methodParameters, methodValue ) {
-
- var node = this.state.nodes[nodeID];
- if (!(node && node.aframeObj)) {
- return;
- }
-
- if (this.nodes[nodeID].extends == "http://vwf.example.com/aframe/acamera.vwf"){
- if (methodName == "setCameraToActive"){
- if (methodParameters[0] == vwf.moniker_){
- console.log("set active");
- node.aframeObj.setAttribute('camera', 'active', true)
- }
- }
- }
-
- }
- });
- function compareCoordinates(a, b) {
- return a.x !== b.x || a.y !== b.y || a.z !== b.z
- }
- function updateAvatarPosition() {
- let avatarName = 'avatar-' + self.kernel.moniker();
- var node = self.state.nodes[avatarName];
- if (!node) return;
- if (!node.aframeObj) return;
- let el = document.querySelector('#avatarControl');
- if (el) {
- let position = el.getAttribute('position');
- let rotation = el.getAttribute('rotation');
- let lastRotation = self.nodes[avatarName].selfTickRotation;
- let currentPosition = node.aframeObj.getAttribute('position');
- let currentRotation = node.aframeObj.getAttribute('rotation');
- if (position && rotation && currentPosition && currentRotation && lastRotation) {
- if (compareCoordinates(position, currentPosition) || rotation.y !== lastRotation.y) {
- console.log("not equal!!")
- vwf_view.kernel.callMethod(avatarName, "followAvatarControl", [position, rotation]);
- }
- }
- self.nodes[avatarName].selfTickRotation = Object.assign({}, el.getAttribute('rotation'));
- }
- }
- function updateHandControllerVR(aName, aSelector) {
-
- let avatarName = aName + self.kernel.moniker();
- var node = self.state.nodes[avatarName];
- if (!node) return;
- if (!node.aframeObj) return;
- let el = document.querySelector(aSelector);
- if (el) {
- let position = el.getAttribute('position');
- let rotation = el.getAttribute('rotation');
- let lastRotation = self.nodes[avatarName].selfTickRotation;
- let lastPosition = self.nodes[avatarName].selfTickPosition;
-
-
- if (position && rotation && lastRotation && lastPosition) {
- if (compareCoordinates(position, lastPosition) || compareCoordinates(rotation, lastRotation)) {
- console.log("not equal!!");
- vwf_view.kernel.callMethod(avatarName, "updateVRControl", [position, rotation]);
-
-
- }
- }
- self.nodes[avatarName].selfTickRotation = Object.assign({}, el.getAttribute('rotation'));
- self.nodes[avatarName].selfTickPosition = Object.assign({}, el.getAttribute('position'));
- }
- }
- function createAvatarControl(aScene) {
- let avatarName = 'avatar-' + self.kernel.moniker();
- let controlEl = document.createElement('a-camera');
-
- controlEl.setAttribute('id', 'avatarControl');
- controlEl.setAttribute('wasd-controls-enabled', true);
- controlEl.setAttribute('look-controls-enabled', true);
- controlEl.setAttribute('user-height', 1.6);
- controlEl.setAttribute('gamepad-controls', {'controller': 0});
-
-
-
- controlEl.setAttribute('camera', 'active', true);
-
-
- aScene.appendChild(controlEl);
- let cursorEl = document.createElement('a-cursor');
- cursorEl.setAttribute('id', 'cursor-' + avatarName);
- cursorEl.setAttribute('raycaster', {});
- cursorEl.setAttribute('raycaster', 'objects', '.intersectable');
- cursorEl.setAttribute('raycaster', 'showLine', false);
-
-
- controlEl.appendChild(cursorEl);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- function createWMRVR (nodeID, nodeName) {
- var newNode = {
- "id": nodeName,
- "uri": nodeName,
- "extends": "http://vwf.example.com/aframe/wmrvrcontroller.vwf",
- "properties": {
- }
- }
- if (!self.state.nodes[nodeName]) {
- vwf_view.kernel.createChild(nodeID, nodeName, newNode);
- vwf_view.kernel.callMethod(nodeName, "createController", []);
-
- }
- }
- function createGearVRController(nodeID, nodeName) {
- var newNode = {
- "id": nodeName,
- "uri": nodeName,
- "extends": "http://vwf.example.com/aframe/gearvrcontroller.vwf",
- "properties": {
- }
- }
- if (!self.state.nodes[nodeName]) {
- vwf_view.kernel.createChild(nodeID, nodeName, newNode);
- vwf_view.kernel.callMethod(nodeName, "createController", []);
-
- }
- }
- function createAvatar(nodeID) {
- vwf_view.kernel.fireEvent(nodeID, "createAvatar")
-
-
-
-
-
-
-
-
-
- }
- function randId() {
- return '_' + Math.random().toString(36).substr(2, 9);
- }
- function createGearVRControls() {
- let sceneEl = document.querySelector('a-scene');
- let gearvr = document.createElement('a-entity');
- gearvr.setAttribute('id', 'gearvrcontrol');
- gearvr.setAttribute('gearvr-controls', '');
- gearvr.setAttribute('gearvr-controls', 'hand', 'right');
- gearvr.setAttribute('gearvrcontrol', '');
- sceneEl.appendChild(gearvr);
- }
- function createWMRVRControls(hand) {
- let sceneEl = document.querySelector('a-scene');
- let wmrvr = document.createElement('a-entity');
- wmrvr.setAttribute('id', 'wmrvrcontrol' + hand);
- wmrvr.setAttribute('windows-motion-controls', '');
- wmrvr.setAttribute('windows-motion-controls', 'hand', hand);
- wmrvr.setAttribute('wmrvrcontrol', {'hand': hand});
- sceneEl.appendChild(wmrvr);
- }
- });
|