aframe.js 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. "use strict";
  2. /*
  3. The MIT License (MIT)
  4. Copyright (c) 2014-2018 Nikolai Suslov and the Krestianstvo.org project contributors. (https://github.com/NikolaySuslov/livecodingspace/blob/master/LICENSE.md)
  5. Virtual World Framework Apache 2.0 license (https://github.com/NikolaySuslov/livecodingspace/blob/master/licenses/LICENSE_VWF.md)
  6. */
  7. // VWF & A-Frame model driver
  8. define(["module", "vwf/model", "vwf/utility"], function (module, model, utility) {
  9. var self;
  10. return model.load(module, {
  11. // == Module Definition ====================================================================
  12. // -- initialize ---------------------------------------------------------------------------
  13. initialize: function () {
  14. self = this;
  15. this.state = {
  16. nodes: {},
  17. scenes: {},
  18. prototypes: {},
  19. createLocalNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  20. childSource, childType, childIndex, childName, callback) {
  21. return {
  22. "parentID": nodeID,
  23. "ID": childID,
  24. "extendsID": childExtendsID,
  25. "implementsIDs": childImplementsIDs,
  26. "source": childSource,
  27. "type": childType,
  28. "name": childName,
  29. "prototypes": undefined,
  30. "aframeObj": undefined,
  31. "scene": undefined,
  32. "componentName": undefined,
  33. "events": {
  34. "clickable": false
  35. }
  36. };
  37. },
  38. isAFrameClass: function (prototypes, classID) {
  39. if (prototypes) {
  40. for (var i = 0; i < prototypes.length; i++) {
  41. if (prototypes[i] === classID) {
  42. //console.info( "prototypes[ i ]: " + prototypes[ i ] );
  43. return true;
  44. }
  45. }
  46. }
  47. return false;
  48. },
  49. isAFrameComponent: function (prototypes) {
  50. var found = false;
  51. if (prototypes) {
  52. for (var i = 0; i < prototypes.length && !found; i++) {
  53. found = (prototypes[i] === "http://vwf.example.com/aframe/node.vwf");
  54. }
  55. }
  56. return found;
  57. },
  58. setAFrameProperty: function (propertyName, propertyValue, aframeObject) {
  59. //console.log(propertyValue);
  60. if (propertyValue.hasOwnProperty('x')) {
  61. aframeObject.setAttribute(propertyName, propertyValue)
  62. } else
  63. if (Array.isArray(propertyValue)) {
  64. aframeObject.setAttribute(propertyName, { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] })
  65. } else if (typeof propertyValue === 'string') {
  66. propertyValue.includes(',') ? aframeObject.setAttribute(propertyName, AFRAME.utils.coordinates.parse(propertyValue.split(',').join(' '))) : aframeObject.setAttribute(propertyName, AFRAME.utils.coordinates.parse(propertyValue))
  67. //aframeObject.setAttribute(propertyName, AFRAME.utils.coordinates.parse(propertyValue))
  68. } else if (propertyValue.hasOwnProperty('0')) {
  69. aframeObject.setAttribute(propertyName, { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] })
  70. }
  71. },
  72. setFromValue: function (propertyValue) {
  73. var value = goog.vec.Vec3.create();
  74. if (propertyValue.hasOwnProperty('x')) {
  75. value = goog.vec.Vec3.createFromValues(propertyValue.x, propertyValue.y, propertyValue.z)
  76. }
  77. else if (Array.isArray(propertyValue) || propertyValue instanceof Float32Array) {
  78. value = goog.vec.Vec3.createFromArray(propertyValue);
  79. }
  80. else if (typeof propertyValue === 'string') {
  81. let val = propertyValue.includes(',') ? AFRAME.utils.coordinates.parse(propertyValue.split(',').join(' ')) : AFRAME.utils.coordinates.parse(propertyValue);
  82. value = goog.vec.Vec3.createFromValues(val.x, val.y, val.z)
  83. // let val = AFRAME.utils.coordinates.parse(propertyValue);
  84. // value = goog.vec.Vec3.createFromValues(val.x, val.y, val.z)
  85. } else if (propertyValue.hasOwnProperty('0')) {
  86. value = goog.vec.Vec3.createFromValues(propertyValue[0], propertyValue[1], propertyValue[2])
  87. }
  88. return value
  89. }
  90. };
  91. this.state.kernel = this.kernel.kernel.kernel;
  92. this.aframeDef = {
  93. 'A-BOX': [
  94. 'depth', 'height', 'segments-depth',
  95. 'segments-height', 'segments-width',
  96. 'width'],
  97. 'A-SPHERE': [
  98. 'phi-length', 'phi-start', 'radius',
  99. 'segments-depth',
  100. 'segments-height', 'segments-width',
  101. 'theta-length', 'theta-start'
  102. ],
  103. 'A-CYLINDER': [
  104. 'height', 'radius',
  105. 'open-ended', 'radius-bottom', 'radius-top',
  106. 'segments-height', 'segments-radial',
  107. 'theta-length', 'theta-start'
  108. ],
  109. 'A-CONE': [
  110. 'height',
  111. 'open-ended', 'radius-bottom', 'radius-top',
  112. 'segments-height', 'segments-radial',
  113. 'theta-length', 'theta-start'
  114. ],
  115. 'A-PLANE': [
  116. 'height', 'segments-height', 'segments-width', 'width'
  117. ],
  118. 'A-TEXT': [
  119. 'align', 'alpha-test', 'anchor',
  120. 'baseline', 'color', 'font',
  121. 'font-image', 'height',
  122. 'letter-spacing', 'line-height',
  123. 'opacity', 'shader',
  124. 'side', 'tab-size',
  125. 'transparent', 'value',
  126. 'white-space', 'width',
  127. 'wrap-count', 'wrap-pixels',
  128. 'z-offset', 'negate'
  129. ],
  130. 'A-SKY': [
  131. 'phi-length', 'phi-start', 'radius', 'segments-height',
  132. 'segments-width',
  133. 'theta-length', 'theta-start',
  134. ],
  135. 'A-LIGHT': [
  136. 'angle', 'color', 'decay', 'distance',
  137. 'ground-color', 'intensity', 'penumbra',
  138. 'type', 'target'
  139. ]
  140. }
  141. },
  142. // == Model API ============================================================================
  143. // -- creatingNode -------------------------------------------------------------------------
  144. creatingNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  145. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  146. // If the parent nodeID is 0, this node is attached directly to the root and is therefore either
  147. // the scene or a prototype. In either of those cases, save the uri of the new node
  148. var childURI = (nodeID === 0 ? childIndex : undefined);
  149. var appID = this.kernel.application();
  150. // If the node being created is a prototype, construct it and add it to the array of prototypes,
  151. // and then return
  152. var prototypeID = utility.ifPrototypeGetId(appID, this.state.prototypes, nodeID, childID);
  153. if (prototypeID !== undefined) {
  154. this.state.prototypes[prototypeID] = {
  155. parentID: nodeID,
  156. ID: childID,
  157. extendsID: childExtendsID,
  158. implementsID: childImplementsIDs,
  159. source: childSource,
  160. type: childType,
  161. name: childName
  162. };
  163. return;
  164. }
  165. var protos = getPrototypes(this.kernel, childExtendsID);
  166. //var kernel = this.kernel.kernel.kernel;
  167. var node;
  168. if (this.state.isAFrameComponent(protos)) {
  169. // Create the local copy of the node properties
  170. if (this.state.nodes[childID] === undefined) {
  171. this.state.nodes[childID] = this.state.createLocalNode(nodeID, childID, childExtendsID, childImplementsIDs,
  172. childSource, childType, childIndex, childName, callback);
  173. }
  174. node = this.state.nodes[childID];
  175. node.prototypes = protos;
  176. // if (childType == "component") {
  177. // if (nodeID !== undefined) {
  178. // node.aframeObj = setAFrameObjectComponents(node);
  179. // addNodeToHierarchy(node);
  180. // }
  181. // } else {
  182. node.aframeObj = createAFrameObject(node);
  183. addNodeToHierarchy(node);
  184. if (isAEntityDefinition(node.prototypes)) {
  185. //updateStoredTransform( node );
  186. updateStoredTransformFor(node, 'position');
  187. updateStoredTransformFor(node, 'rotation');
  188. updateStoredTransformFor(node, 'scale');
  189. }
  190. //notifyDriverOfPrototypeAndBehaviorProps();
  191. // }
  192. //addNodeToHierarchy(node);
  193. }
  194. },
  195. // initializingNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
  196. // childSource, childType, childIndex, childName ) {
  197. // var node = this.state.nodes[childID];
  198. // if ( node && childType == "component" ) {
  199. // }
  200. // },
  201. // -- initializingProperty -----------------------------------------------------------------
  202. initializingProperty: function (nodeID, propertyName, propertyValue) {
  203. var value = undefined;
  204. var node = this.state.nodes[nodeID];
  205. if (node !== undefined) {
  206. value = this.settingProperty(nodeID, propertyName, propertyValue);
  207. }
  208. return value;
  209. },
  210. // -- creatingProperty ---------------------------------------------------------------------
  211. creatingProperty: function (nodeID, propertyName, propertyValue) {
  212. return this.initializingProperty(nodeID, propertyName, propertyValue);
  213. },
  214. // -- callingMethod ------------------------------------------------------------------------
  215. callingMethod: function (nodeID, methodName, methodParameters) {
  216. var node = this.state.nodes[nodeID];
  217. if (!node) return;
  218. if (node && node.aframeObj) {
  219. if (methodName == 'lookAt') {
  220. console.log('lookAt: ' + methodParameters[0]);
  221. let target = methodParameters[0];
  222. node.aframeObj.object3D.lookAt(new THREE.Vector3(target.x, target.y, target.z));
  223. let newRotation = node.aframeObj.getAttribute('rotation');
  224. self.kernel.setProperty(nodeID, "rotation", { x: 0, y: newRotation.y, z: 0 });
  225. }
  226. if (methodName == 'worldRotation') {
  227. var worldQuat = new THREE.Quaternion();
  228. node.aframeObj.object3D.getWorldQuaternion(worldQuat);
  229. let angle = (new THREE.Euler()).setFromQuaternion(worldQuat, 'YXZ');
  230. let rotation = (new THREE.Vector3(THREE.Math.radToDeg(angle.x),
  231. THREE.Math.radToDeg(angle.y), THREE.Math.radToDeg(angle.z)));
  232. return rotation
  233. }
  234. if (methodName == 'worldPosition') {
  235. var position = new THREE.Vector3();
  236. node.aframeObj.object3D.getWorldPosition(position);
  237. return position
  238. }
  239. }
  240. },
  241. // -- deletingNode -------------------------------------------------------------------------
  242. //deletingNode: function( nodeID ) {
  243. //},
  244. // -- deletingNode -------------------------------------------------------------------------
  245. deletingNode: function (nodeID) {
  246. if (nodeID) {
  247. var childNode = this.state.nodes[nodeID];
  248. if (!childNode) return;
  249. if (childNode !== undefined) {
  250. if (childNode.children) {
  251. for (var i = 0; i < childNode.children.length; i++) {
  252. this.deletingNode(childNode.children[i]);
  253. }
  254. }
  255. if (childNode.aframeObj !== undefined) {
  256. // removes and destroys object
  257. childNode.aframeObj.parentNode.removeChild(childNode.aframeObj);
  258. childNode.aframeObj.destroy();
  259. childNode.aframeObj = undefined;
  260. }
  261. delete this.state.nodes[nodeID];
  262. }
  263. }
  264. },
  265. // -- settingProperty ----------------------------------------------------------------------
  266. settingProperty: function (nodeID, propertyName, propertyValue) {
  267. var node = this.state.nodes[nodeID];
  268. var value = undefined;
  269. // if (node.componentName == 'line') {
  270. // console.log(node.aframeObj);
  271. // }
  272. if (node && node.aframeObj && utility.validObject(propertyValue)) {
  273. var aframeObject = node.aframeObj;
  274. if (isNodeDefinition(node.prototypes)) {
  275. // 'id' will be set to the nodeID
  276. value = propertyValue;
  277. switch (propertyName) {
  278. default:
  279. value = undefined;
  280. break;
  281. }
  282. }
  283. if (value === undefined && isAEntityDefinition(node.prototypes)) {
  284. value = propertyValue;
  285. switch (propertyName) {
  286. case "position":
  287. var position = this.state.setFromValue(propertyValue || []); //goog.vec.Vec3.createFromArray( propertyValue || [] );
  288. node.transform.position = goog.vec.Vec3.clone(position);
  289. //value = propertyValue;
  290. node.transform.storedPositionDirty = true;
  291. //setTransformsDirty( threeObject );
  292. //this.state.setAFrameProperty('position', propertyValue, aframeObject);
  293. break;
  294. case "rotation":
  295. var rotation = this.state.setFromValue(propertyValue || []); //goog.vec.Vec3.createFromArray( propertyValue || [] );
  296. node.transform.rotation = goog.vec.Vec3.clone(rotation);
  297. //value = propertyValue;
  298. node.transform.storedRotationDirty = true;
  299. //this.state.setAFrameProperty('rotation', propertyValue, aframeObject);
  300. break;
  301. case "scale":
  302. var scale = this.state.setFromValue(propertyValue || []); //goog.vec.Vec3.createFromArray( propertyValue || [] );
  303. node.transform.scale = goog.vec.Vec3.clone(scale);
  304. //value = propertyValue;
  305. node.transform.storedScaleDirty = true;
  306. //setTransformsDirty( threeObject );
  307. //this.state.setAFrameProperty('position', propertyValue, aframeObject);
  308. //this.state.setAFrameProperty('scale', propertyValue, aframeObject);
  309. break;
  310. case "animationTimeUpdated":
  311. if (node.transform) {
  312. node.transform.storedPositionDirty = true;
  313. node.transform.storedRotationDirty = true;
  314. node.transform.storedScaleDirty = true;
  315. }
  316. break;
  317. case "clickable":
  318. if (propertyValue) {
  319. aframeObject.setAttribute('class', 'intersectable');
  320. } else {
  321. aframeObject.setAttribute('class', 'nonintersectable');
  322. }
  323. node.events.clickable = propertyValue;
  324. break;
  325. case "class":
  326. var newClasses = [];
  327. if (propertyValue.includes(',')){
  328. newClasses = propertyValue.split(',');
  329. } else {
  330. newClasses = propertyValue.split(' ')
  331. }
  332. // let newClasses = propertyValue.split(','); //trim()
  333. aframeObject.setAttribute('class',"");
  334. newClasses.forEach(el=>{
  335. aframeObject.classList.add(el.trim());
  336. })
  337. break;
  338. case "ownedBy":
  339. aframeObject.setAttribute('ownedby', propertyValue);
  340. break;
  341. case "visible":
  342. aframeObject.setAttribute('visible', propertyValue);
  343. break;
  344. // case "clickable":
  345. // console.log("set clickable!");
  346. // value = propertyValue;
  347. // break;
  348. // case "clickable":
  349. // if (propertyValue) {
  350. // aframeObject.addEventListener('click', function (evt) {
  351. // console.log("click!");
  352. // vwf_view.kernel.fireEvent(node.ID, "clickEvent",evt.detail.cursorEl.id);
  353. // });
  354. // }
  355. // break;
  356. // case "look-controls-enabled":
  357. // aframeObject.setAttribute('look-controls', 'enabled', propertyValue);
  358. // break;
  359. case "wasd-controls":
  360. aframeObject.setAttribute('wasd-controls', 'enabled', propertyValue);
  361. break;
  362. default:
  363. value = undefined;
  364. break;
  365. }
  366. }
  367. if (value === undefined && aframeObject.nodeName == "A-ASSET-ITEM") {
  368. value = propertyValue;
  369. switch (propertyName) {
  370. case "itemID":
  371. aframeObject.setAttribute('id', propertyValue);
  372. break;
  373. case "itemSrc":
  374. aframeObject.setAttribute('src', propertyValue);
  375. break;
  376. default:
  377. value = undefined;
  378. break;
  379. }
  380. }
  381. if (value === undefined && aframeObject.nodeName == "IMG") {
  382. value = propertyValue;
  383. switch (propertyName) {
  384. case "itemID":
  385. aframeObject.setAttribute('id', propertyValue);
  386. break;
  387. case "itemSrc":
  388. aframeObject.setAttribute('src', propertyValue);
  389. break;
  390. // case "width":
  391. // aframeObject.width = propertyValue;
  392. // break;
  393. // case "height":
  394. // aframeObject.height = propertyValue;
  395. // break;
  396. default:
  397. value = undefined;
  398. break;
  399. }
  400. }
  401. if (value === undefined && aframeObject.nodeName == "AUDIO") {
  402. value = propertyValue;
  403. switch (propertyName) {
  404. case "itemID":
  405. aframeObject.setAttribute('id', propertyValue);
  406. break;
  407. case "itemSrc":
  408. aframeObject.setAttribute('src', propertyValue);
  409. break;
  410. default:
  411. value = undefined;
  412. break;
  413. }
  414. }
  415. if (value === undefined && aframeObject.nodeName == "VIDEO") {
  416. value = propertyValue;
  417. switch (propertyName) {
  418. case "itemID":
  419. aframeObject.setAttribute('id', propertyValue);
  420. break;
  421. case "itemSrc":
  422. aframeObject.setAttribute('src', propertyValue);
  423. break;
  424. default:
  425. value = undefined;
  426. break;
  427. }
  428. }
  429. if (value === undefined && aframeObject.nodeName == "A-SKY") {
  430. value = propertyValue;
  431. self.aframeDef['A-SKY'].forEach(element => {
  432. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  433. value = undefined;
  434. })
  435. }
  436. if (value === undefined && aframeObject.nodeName == "A-TEXT") {
  437. value = propertyValue;
  438. self.aframeDef['A-TEXT'].forEach(element => {
  439. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  440. value = undefined;
  441. })
  442. }
  443. if (value === undefined && aframeObject.nodeName == "A-SCENE") {
  444. value = propertyValue;
  445. switch (propertyName) {
  446. case "color":
  447. aframeObject.setAttribute('background', { 'color': propertyValue });
  448. break;
  449. case "transparent":
  450. aframeObject.setAttribute('background', { 'transparent': propertyValue });
  451. break;
  452. // case "fog":
  453. // aframeObject.setAttribute('fog', propertyValue);
  454. // break;
  455. case "assets":
  456. let assetsEl = document.querySelector('a-assets');
  457. if (!assetsEl) {
  458. let newAssetsEl = document.createElement('a-assets');
  459. aframeObject.appendChild(newAssetsEl);
  460. }
  461. var assetsElement = document.querySelector('a-assets');
  462. if (propertyValue) {
  463. let path = JSON.parse(localStorage.getItem('lcs_app')).path.public_path;
  464. let worldName = path.slice(1);
  465. let dbPath = propertyValue.split(".").join("_");
  466. let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
  467. userDB.get('worlds').get(worldName).get(dbPath).get('file').once(function(response) {
  468. if (response) {
  469. if (Object.keys(response).length > 0) {
  470. //console.log(JSON.parse(response));
  471. let assets = (typeof(response) == 'object') ? response: JSON.parse(response);
  472. for (var prop in assets) {
  473. var elm = document.createElement(assets[prop].tag);
  474. elm.setAttribute('id', prop);
  475. elm.setAttribute('src', assets[prop].src);
  476. assetsElement.appendChild(elm);
  477. }
  478. }
  479. }
  480. });
  481. // httpGetJson(propertyValue).then(function (response) {
  482. // console.log(JSON.parse(response));
  483. // let assets = JSON.parse(response);
  484. // for (var prop in assets) {
  485. // var elm = document.createElement(assets[prop].tag);
  486. // elm.setAttribute('id', prop);
  487. // elm.setAttribute('src', assets[prop].src);
  488. // assetsElement.appendChild(elm);
  489. // }
  490. // }).catch(function (error) {
  491. // console.log(error);
  492. // });
  493. }
  494. break;
  495. default:
  496. value = undefined;
  497. break;
  498. }
  499. }
  500. if (value === undefined && aframeObject.nodeName == "A-BOX") {
  501. value = propertyValue;
  502. self.aframeDef['A-BOX'].forEach(element => {
  503. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  504. value = undefined;
  505. })
  506. }
  507. if (value === undefined && aframeObject.nodeName == "A-LIGHT") {
  508. value = propertyValue;
  509. self.aframeDef['A-LIGHT'].forEach(element => {
  510. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  511. value = undefined;
  512. })
  513. switch (propertyName) {
  514. case "castShadow":
  515. aframeObject.setAttribute('light', 'castShadow', propertyValue);
  516. break;
  517. case "shadowCameraVisible":
  518. aframeObject.setAttribute('light', 'shadowCameraVisible', propertyValue);
  519. break;
  520. default:
  521. value = undefined;
  522. break;
  523. }
  524. }
  525. if (value === undefined && aframeObject.nodeName == "A-GLTF-MODEL") {
  526. value = propertyValue;
  527. switch (propertyName) {
  528. case "src":
  529. aframeObject.setAttribute('src', propertyValue);
  530. break;
  531. default:
  532. value = undefined;
  533. break;
  534. }
  535. }
  536. if (value === undefined && aframeObject.nodeName == "A-COLLADA-MODEL") {
  537. value = propertyValue;
  538. switch (propertyName) {
  539. case "src":
  540. aframeObject.setAttribute('src', propertyValue);
  541. break;
  542. default:
  543. value = undefined;
  544. break;
  545. }
  546. }
  547. if (value === undefined && aframeObject.nodeName == "A-OBJ-MODEL") {
  548. value = propertyValue;
  549. switch (propertyName) {
  550. case "src":
  551. aframeObject.setAttribute('src', propertyValue);
  552. break;
  553. case "mtl":
  554. aframeObject.setAttribute('mtl', propertyValue);
  555. break;
  556. default:
  557. value = undefined;
  558. break;
  559. }
  560. }
  561. if (value === undefined && aframeObject.nodeName == "A-PLANE") {
  562. value = propertyValue;
  563. self.aframeDef['A-PLANE'].forEach(element => {
  564. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  565. value = undefined;
  566. })
  567. }
  568. if (value === undefined && aframeObject.nodeName == "A-SPHERE") {
  569. value = propertyValue;
  570. self.aframeDef['A-SPHERE'].forEach(element => {
  571. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  572. value = undefined;
  573. })
  574. }
  575. if (value === undefined && aframeObject.nodeName == "A-CYLINDER") {
  576. value = propertyValue;
  577. self.aframeDef['A-CYLINDER'].forEach(element => {
  578. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  579. value = undefined;
  580. })
  581. }
  582. if (value === undefined && aframeObject.nodeName == "A-CONE") {
  583. value = propertyValue;
  584. self.aframeDef['A-CONE'].forEach(element => {
  585. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  586. value = undefined;
  587. })
  588. }
  589. if (value === undefined && aframeObject.nodeName == "A-ANIMATION") {
  590. value = propertyValue;
  591. switch (propertyName) {
  592. // attribute:
  593. // dur:
  594. // from:
  595. // to:
  596. // repeat:
  597. case "dur":
  598. aframeObject.setAttribute('dur', propertyValue);
  599. break;
  600. case "from":
  601. aframeObject.setAttribute('from', propertyValue);
  602. break;
  603. case "to":
  604. aframeObject.setAttribute('to', propertyValue);
  605. break;
  606. case "repeat":
  607. aframeObject.setAttribute('repeat', propertyValue);
  608. break;
  609. case "attribute":
  610. aframeObject.setAttribute('attribute', propertyValue);
  611. break;
  612. case "begin":
  613. aframeObject.setAttribute('begin', propertyValue);
  614. break;
  615. default:
  616. value = undefined;
  617. break;
  618. }
  619. }
  620. if (value === undefined && aframeObject.nodeName == "A-CAMERA") {
  621. value = propertyValue;
  622. switch (propertyName) {
  623. case "user-height":
  624. aframeObject.setAttribute('user-height', propertyValue);
  625. break;
  626. case "look-controls-enabled":
  627. aframeObject.setAttribute('look-controls-enabled', propertyValue);
  628. break;
  629. case "wasd-controls-enabled":
  630. aframeObject.setAttribute('wasd-controls-enabled', propertyValue);
  631. break;
  632. // case "active":
  633. // aframeObject.setAttribute('camera', 'active', propertyValue);
  634. // break;
  635. default:
  636. value = undefined;
  637. break;
  638. }
  639. }
  640. if (value === undefined && aframeObject.nodeName == "A-SUN-SKY") {
  641. value = propertyValue;
  642. switch (propertyName) {
  643. case "sunPosition":
  644. aframeObject.setAttribute('material', 'sunPosition', propertyValue);
  645. break;
  646. // case "active":
  647. // aframeObject.setAttribute('camera', 'active', propertyValue);
  648. // break;
  649. default:
  650. value = undefined;
  651. break;
  652. }
  653. }
  654. if (value === undefined && aframeObject.nodeName == "A-ANCHOR") {
  655. value = propertyValue;
  656. switch (propertyName) {
  657. case "changeMatrixMode":
  658. aframeObject.setAttribute('arjs-anchor', 'changeMatrixMode', propertyValue);
  659. break;
  660. case 'hit-testing-enabled':
  661. aframeObject.setAttribute('hit-testing-enabled', propertyValue);
  662. break;
  663. case 'preset':
  664. aframeObject.setAttribute('preset', propertyValue);
  665. break;
  666. case 'markerType':
  667. aframeObject.setAttribute('type', propertyValue);
  668. break;
  669. case 'markerValue':
  670. aframeObject.setAttribute('velue', propertyValue);
  671. break;
  672. default:
  673. value = undefined;
  674. break;
  675. }
  676. }
  677. }
  678. return value;
  679. },
  680. // -- gettingProperty ----------------------------------------------------------------------
  681. gettingProperty: function (nodeID, propertyName, propertyValue) {
  682. var node = this.state.nodes[nodeID];
  683. var value = undefined;
  684. if (node && node.aframeObj) {
  685. var aframeObject = node.aframeObj;
  686. if (isNodeDefinition(node.prototypes)) {
  687. switch (propertyName) {
  688. }
  689. }
  690. if (value === undefined && isAEntityDefinition(node.prototypes)) {
  691. switch (propertyName) {
  692. case "position":
  693. // var pos = aframeObject.getAttribute('position');
  694. // if (pos !== undefined) {
  695. // value = pos//[pos.x, pos.y, pos.z]//AFRAME.utils.coordinates.stringify(pos);
  696. // }
  697. if (node.transform.position) {
  698. if (node.transform.storedPositionDirty) {
  699. updateStoredTransformFor(node, 'position');
  700. }
  701. value = goog.vec.Vec3.clone(node.transform.position);
  702. //value = node.transform.position;
  703. }
  704. break;
  705. case "rotation":
  706. if (node.transform.rotation) {
  707. if (node.transform.storedRotationDirty) {
  708. updateStoredTransformFor(node, 'rotation');
  709. }
  710. value = goog.vec.Vec3.clone(node.transform.rotation);
  711. // var rot = aframeObject.getAttribute('rotation');
  712. // if (rot !== undefined) {
  713. // value = rot//AFRAME.utils.coordinates.stringify(rot);
  714. // }
  715. }
  716. break;
  717. case "scale":
  718. if (node.transform.scale) {
  719. if (node.transform.storedScaleDirty) {
  720. updateStoredTransformFor(node, 'scale');
  721. }
  722. value = goog.vec.Vec3.clone(node.transform.scale);
  723. // var scale = aframeObject.getAttribute('scale');
  724. // if (scale !== undefined) {
  725. // value = scale//AFRAME.utils.coordinates.stringify(scale);
  726. // }
  727. }
  728. break;
  729. case "clickable":
  730. value = node.events.clickable;
  731. break;
  732. case "class":
  733. value = aframeObject.classList.toString();
  734. //aframeObject.getAttribute('class');
  735. break;
  736. // case "look-controls-enabled":
  737. // var look = aframeObject.getAttribute('look-controls-enabled');
  738. // if (look !== null && look !== undefined) {
  739. // value = aframeObject.getAttribute('look-controls').enabled;
  740. // }
  741. // break;
  742. // case "wasd-controls":
  743. // var wasd = aframeObject.getAttribute('wasd-controls');
  744. // if (wasd !== null && wasd !== undefined) {
  745. // value = aframeObject.getAttribute('wasd-controls').enabled;
  746. // }
  747. // break;
  748. case "ownedBy":
  749. value = aframeObject.getAttribute('ownedby');
  750. break;
  751. case "visible":
  752. value = aframeObject.getAttribute('visible');
  753. break;
  754. }
  755. }
  756. if (value === undefined && aframeObject.nodeName == "A-ASSET-ITEM") {
  757. switch (propertyName) {
  758. case "itemID":
  759. value = aframeObject.getAttribute('id');
  760. break;
  761. case "itemSrc":
  762. value = aframeObject.getAttribute('src');
  763. break;
  764. }
  765. }
  766. if (value === undefined && aframeObject.nodeName == "IMG") {
  767. switch (propertyName) {
  768. case "itemID":
  769. value = aframeObject.getAttribute('id');
  770. break;
  771. case "itemSrc":
  772. value = aframeObject.getAttribute('src');
  773. break;
  774. case "width":
  775. value = aframeObject.width;
  776. break;
  777. case "height":
  778. value = aframeObject.height;
  779. break;
  780. }
  781. }
  782. if (value === undefined && aframeObject.nodeName == "AUDIO") {
  783. switch (propertyName) {
  784. case "itemID":
  785. value = aframeObject.getAttribute('id');
  786. break;
  787. case "itemSrc":
  788. value = aframeObject.getAttribute('src');
  789. break;
  790. }
  791. }
  792. if (value === undefined && aframeObject.nodeName == "VIDEO") {
  793. switch (propertyName) {
  794. case "itemID":
  795. value = aframeObject.getAttribute('id');
  796. break;
  797. case "itemSrc":
  798. value = aframeObject.getAttribute('src');
  799. break;
  800. case "videoWidth":
  801. value = aframeObject.videoWidth;
  802. break;
  803. case "videoHeight":
  804. value = aframeObject.videoHeight;
  805. break;
  806. }
  807. }
  808. if (value === undefined && aframeObject.nodeName == "A-SCENE") {
  809. switch (propertyName) {
  810. // case "fog":
  811. // value = aframeObject.getAttribute('fog');
  812. // break;
  813. case "color":
  814. if (aframeObject.getAttribute('background')) {
  815. value = aframeObject.getAttribute('background').color;
  816. }
  817. break;
  818. case "transparent":
  819. if (aframeObject.getAttribute('background')) {
  820. value = aframeObject.getAttribute('background').transparent;
  821. }
  822. break;
  823. }
  824. }
  825. if (value === undefined && aframeObject.nodeName == "A-SKY") {
  826. self.aframeDef['A-SKY'].forEach(element => {
  827. if (element == propertyName) {
  828. value = aframeObject.getAttribute(element);
  829. }
  830. })
  831. }
  832. if (value === undefined && aframeObject.nodeName == "A-LIGHT") {
  833. self.aframeDef['A-LIGHT'].forEach(element => {
  834. if (element == propertyName) {
  835. value = aframeObject.getAttribute(element);
  836. }
  837. })
  838. switch (propertyName) {
  839. case "castShadow":
  840. value = aframeObject.getAttribute('light').castShadow;
  841. break;
  842. case "shadowCameraVisible":
  843. value = aframeObject.getAttribute('light').shadowCameraVisible;
  844. break;
  845. }
  846. }
  847. if (value === undefined && aframeObject.nodeName == "A-BOX") {
  848. self.aframeDef['A-BOX'].forEach(element => {
  849. if (element == propertyName) {
  850. value = aframeObject.getAttribute(element);
  851. }
  852. })
  853. }
  854. if (value === undefined && aframeObject.nodeName == "A-PLANE") {
  855. self.aframeDef['A-PLANE'].forEach(element => {
  856. if (element == propertyName) {
  857. value = aframeObject.getAttribute(element);
  858. }
  859. })
  860. }
  861. if (value === undefined && aframeObject.nodeName == "A-SPHERE") {
  862. self.aframeDef['A-SPHERE'].forEach(element => {
  863. if (element == propertyName) {
  864. value = aframeObject.getAttribute(element);
  865. }
  866. })
  867. }
  868. if (value === undefined && aframeObject.nodeName == "A-CYLINDER") {
  869. self.aframeDef['A-CYLINDER'].forEach(element => {
  870. if (element == propertyName) {
  871. value = aframeObject.getAttribute(element);
  872. }
  873. })
  874. }
  875. if (value === undefined && aframeObject.nodeName == "A-CONE") {
  876. self.aframeDef['A-CONE'].forEach(element => {
  877. if (element == propertyName) {
  878. value = aframeObject.getAttribute(element);
  879. }
  880. })
  881. }
  882. if (value === undefined && aframeObject.nodeName == "A-TEXT") {
  883. self.aframeDef['A-TEXT'].forEach(element => {
  884. if (element == propertyName) {
  885. value = aframeObject.getAttribute(element);
  886. }
  887. })
  888. }
  889. if (value === undefined && aframeObject.nodeName == "A-ANIMATION") {
  890. switch (propertyName) {
  891. case "attribute":
  892. value = aframeObject.getAttribute('attribute');
  893. break;
  894. case "dur":
  895. value = aframeObject.getAttribute('dur');
  896. break;
  897. case "from":
  898. value = aframeObject.getAttribute('from');
  899. break;
  900. case "to":
  901. value = aframeObject.getAttribute('to');
  902. break;
  903. case "repeat":
  904. value = aframeObject.getAttribute('repeat');
  905. break;
  906. case "begin":
  907. value = aframeObject.getAttribute('begin');
  908. break;
  909. }
  910. }
  911. if (value === undefined && aframeObject.nodeName == "A-CAMERA") {
  912. switch (propertyName) {
  913. case "user-height":
  914. value = aframeObject.getAttribute('user-height');
  915. break;
  916. case "look-controls-enabled":
  917. value = aframeObject.getAttribute('look-controls-enabled');
  918. break;
  919. case "wasd-controls-enabled":
  920. value = aframeObject.getAttribute('wasd-controls-enabled');
  921. break;
  922. }
  923. // switch (propertyName) {
  924. // case "active":
  925. // value = aframeObject.getAttribute('camera').active;
  926. // break;
  927. // }
  928. }
  929. if (value === undefined && aframeObject.nodeName == "A-SUN-SKY") {
  930. switch (propertyName) {
  931. case "sunPosition":
  932. value = aframeObject.getAttribute('material').sunPosition;
  933. break;
  934. }
  935. // switch (propertyName) {
  936. // case "active":
  937. // value = aframeObject.getAttribute('camera').active;
  938. // break;
  939. // }
  940. }
  941. if (value === undefined && aframeObject.nodeName == "A-COLLADA-MODEL") {
  942. switch (propertyName) {
  943. case "src":
  944. value = aframeObject.getAttribute('src');
  945. break;
  946. }
  947. }
  948. if (value === undefined && aframeObject.nodeName == "A-OBJ-MODEL") {
  949. switch (propertyName) {
  950. case "src":
  951. value = aframeObject.getAttribute('src');
  952. break;
  953. case "mtl":
  954. value = aframeObject.getAttribute('mtl');
  955. break;
  956. }
  957. }
  958. if (value === undefined && aframeObject.nodeName == "A-GLTF-MODEL") {
  959. switch (propertyName) {
  960. case "src":
  961. value = aframeObject.getAttribute('src');
  962. break;
  963. }
  964. }
  965. if (value === undefined && aframeObject.nodeName == "A-ANCHOR") {
  966. switch (propertyName) {
  967. case "changeMatrixMode":
  968. value = aframeObject.getAttribute('arjs-anchor').changeMatrixMode;
  969. break;
  970. case "hit-testing-enabled":
  971. value = aframeObject.getAttribute('hit-testing-enabled');
  972. break;
  973. case "preset":
  974. value = aframeObject.getAttribute('preset');
  975. break;
  976. case 'markerType':
  977. value = aframeObject.getAttribute('type');
  978. break;
  979. case 'markerValue':
  980. value = aframeObject.getAttribute('value');
  981. break;
  982. }
  983. }
  984. }
  985. if (value !== undefined) {
  986. propertyValue = value;
  987. }
  988. return value;
  989. }
  990. });
  991. function createAFrameObject(node, config) {
  992. var protos = node.prototypes;
  993. var aframeObj = undefined;
  994. if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/ascene.vwf")) {
  995. aframeObj = document.createElement('a-scene');
  996. let assetsElement = document.createElement('a-assets');
  997. aframeObj.appendChild(assetsElement);
  998. aframeObj.setAttribute('scene-utils', "");
  999. aframeObj.setAttribute('light', 'defaultLightsEnabled', false);
  1000. //aframeObj.setAttribute('embedded', {});
  1001. //aframeObj.setAttribute('loading-screen', "backgroundColor: black");
  1002. self.state.scenes[node.ID] = aframeObj;
  1003. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/a-asset-item.vwf")) {
  1004. let assets = document.querySelector('a-assets');
  1005. if (assets) {
  1006. aframeObj = document.createElement('a-asset-item');
  1007. aframeObj.setAttribute('id', "item-" + GUID());
  1008. aframeObj.setAttribute('src', "");
  1009. aframeObj.setAttribute('crossorigin', "anonymous");
  1010. assets.appendChild(aframeObj);
  1011. }
  1012. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/a-asset-image-item.vwf")) {
  1013. let assets = document.querySelector('a-assets');
  1014. if (assets) {
  1015. let elID = "item-" + GUID();
  1016. aframeObj = document.createElement('img');
  1017. aframeObj.setAttribute('id', elID);
  1018. aframeObj.setAttribute('src', "");
  1019. aframeObj.setAttribute('crossorigin', "anonymous");
  1020. assets.appendChild(aframeObj);
  1021. }
  1022. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/a-asset-audio-item.vwf")) {
  1023. let assets = document.querySelector('a-assets');
  1024. if (assets) {
  1025. aframeObj = document.createElement('audio');
  1026. aframeObj.setAttribute('id', "item-" + GUID());
  1027. aframeObj.setAttribute('src', "");
  1028. aframeObj.setAttribute('crossorigin', "anonymous");
  1029. assets.appendChild(aframeObj);
  1030. }
  1031. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/a-asset-video-item.vwf")) {
  1032. let assets = document.querySelector('a-assets');
  1033. if (assets) {
  1034. aframeObj = document.createElement('video');
  1035. aframeObj.setAttribute('id', "item-" + GUID());
  1036. aframeObj.setAttribute('src', "");
  1037. aframeObj.setAttribute('crossorigin', "anonymous");
  1038. aframeObj.setAttribute('autoplay', "");
  1039. aframeObj.setAttribute('loop', true);
  1040. assets.appendChild(aframeObj);
  1041. }
  1042. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/asky.vwf")) {
  1043. aframeObj = document.createElement('a-sky');
  1044. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/a-arjs-anchor.vwf")) {
  1045. aframeObj = document.createElement('a-anchor');
  1046. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/alight.vwf")) {
  1047. aframeObj = document.createElement('a-light');
  1048. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/acursor.vwf")) {
  1049. aframeObj = document.createElement('a-cursor');
  1050. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/a-sun-sky.vwf")) {
  1051. aframeObj = document.createElement('a-sun-sky');
  1052. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/abox.vwf")) {
  1053. aframeObj = document.createElement('a-box');
  1054. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/aplane.vwf")) {
  1055. aframeObj = document.createElement('a-plane');
  1056. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/acylinder.vwf")) {
  1057. aframeObj = document.createElement('a-cylinder');
  1058. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/acone.vwf")) {
  1059. aframeObj = document.createElement('a-cone');
  1060. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/atext.vwf")) {
  1061. aframeObj = document.createElement('a-text');
  1062. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/acolladamodel.vwf")) {
  1063. aframeObj = document.createElement('a-collada-model');
  1064. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/aobjmodel.vwf")) {
  1065. aframeObj = document.createElement('a-obj-model');
  1066. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/agltfmodel.vwf")) {
  1067. aframeObj = document.createElement('a-gltf-model');
  1068. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/asphere.vwf")) {
  1069. aframeObj = document.createElement('a-sphere');
  1070. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/aanimation.vwf")) {
  1071. aframeObj = document.createElement('a-animation');
  1072. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/acamera.vwf")) {
  1073. aframeObj = document.createElement('a-camera');
  1074. aframeObj.setAttribute('camera', 'active', false);
  1075. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/aentity.vwf")) {
  1076. aframeObj = document.createElement('a-entity');
  1077. }
  1078. if (aframeObj.nodeName !== "A-ASSET-ITEM" &&
  1079. aframeObj.nodeName !== "IMG" &&
  1080. aframeObj.nodeName !== "AUDIO" &&
  1081. aframeObj.nodeName !== "VIDEO"
  1082. ) {
  1083. aframeObj.setAttribute('id', node.ID);
  1084. }
  1085. return aframeObj;
  1086. }
  1087. function addNodeToHierarchy(node) {
  1088. if (node.aframeObj) {
  1089. if (self.state.nodes[node.parentID] !== undefined) {
  1090. var parent = self.state.nodes[node.parentID];
  1091. if (parent.aframeObj) {
  1092. if (parent.children === undefined) {
  1093. parent.children = [];
  1094. }
  1095. parent.children.push(node.ID);
  1096. //console.info( "Adding child: " + childID + " to " + nodeID );
  1097. if (node.aframeObj.nodeName !== "A-ASSET-ITEM" &&
  1098. node.aframeObj.nodeName !== "IMG" &&
  1099. node.aframeObj.nodeName !== "AUDIO" &&
  1100. node.aframeObj.nodeName !== "VIDEO"
  1101. ) {
  1102. parent.aframeObj.appendChild(node.aframeObj);
  1103. }
  1104. }
  1105. }
  1106. if (node.aframeObj.nodeName !== "A-SCENE") {
  1107. node.scene = self.state.scenes[self.kernel.application()];
  1108. }
  1109. }
  1110. }
  1111. function updateStoredTransform(node) {
  1112. if (node && node.aframeObj) {
  1113. // Add a local model-side transform that can stay pure even if the view changes the
  1114. // transform on the threeObject - this already happened in creatingNode for those nodes that
  1115. // didn't need to load a model
  1116. node.transform = {};
  1117. //let pos = node.aframeObj.object3D.position;
  1118. let pos = (new THREE.Vector3()).copy(node.aframeObj.object3D.position);
  1119. node.transform.position = goog.vec.Vec3.createFromValues(pos.x, pos.y, pos.z);
  1120. //node.transform.position = AFRAME.utils.coordinates.stringify(node.aframeObj.object3D.position);
  1121. node.transform.rotation = AFRAME.utils.coordinates.stringify(node.aframeObj.object3D.rotation);
  1122. node.storedTransformDirty = false;
  1123. }
  1124. }
  1125. function updateStoredTransformFor(node, propertyName) {
  1126. if (node && node.aframeObj) {
  1127. // Add a local model-side transform that can stay pure even if the view changes the
  1128. // transform on the threeObject - this already happened in creatingNode for those nodes that
  1129. // didn't need to load a model
  1130. if (!node.transform)
  1131. node.transform = {};
  1132. if (propertyName == 'position') {
  1133. let pos = (new THREE.Vector3()).copy(node.aframeObj.object3D.position);
  1134. node.transform.position = goog.vec.Vec3.createFromValues(pos.x, pos.y, pos.z);
  1135. node.transform.storedPositionDirty = false;
  1136. }
  1137. if (propertyName == 'rotation') {
  1138. // let rot = (new THREE.Vector3()).copy(node.aframeObj.object3D.rotation);
  1139. let rot = node.aframeObj.getAttribute('rotation');
  1140. node.transform.rotation = goog.vec.Vec3.createFromValues(rot.x, rot.y, rot.z);
  1141. node.transform.storedRotationDirty = false;
  1142. }
  1143. if (propertyName == 'scale') {
  1144. let scale = (new THREE.Vector3()).copy(node.aframeObj.object3D.scale);
  1145. node.transform.scale = goog.vec.Vec3.createFromValues(scale.x, scale.y, scale.z);
  1146. node.transform.storedScaleDirty = false;
  1147. }
  1148. //node.transform.position = AFRAME.utils.coordinates.stringify(node.aframeObj.object3D.position);
  1149. // node.transform.rotation = AFRAME.utils.coordinates.stringify(node.aframeObj.object3D.rotation);
  1150. // node.storedTransformDirty = false;
  1151. }
  1152. }
  1153. function getPrototypes(kernel, extendsID) {
  1154. var prototypes = [];
  1155. var id = extendsID;
  1156. while (id !== undefined) {
  1157. prototypes.push(id);
  1158. id = kernel.prototype(id);
  1159. }
  1160. return prototypes;
  1161. }
  1162. function isNodeDefinition(prototypes) {
  1163. var found = false;
  1164. if (prototypes) {
  1165. for (var i = 0; i < prototypes.length && !found; i++) {
  1166. found = (prototypes[i] == "http://vwf.example.com/aframe/node.vwf");
  1167. }
  1168. }
  1169. return found;
  1170. }
  1171. function isAEntityDefinition(prototypes) {
  1172. var found = false;
  1173. if (prototypes) {
  1174. for (var i = 0; i < prototypes.length && !found; i++) {
  1175. found = (prototypes[i] == "http://vwf.example.com/aframe/aentity.vwf");
  1176. }
  1177. }
  1178. return found;
  1179. }
  1180. // Changing this function significantly from the GLGE code
  1181. // Will search hierarchy down until encountering a matching child
  1182. // Will look into nodes that don't match.... this might not be desirable
  1183. function FindChildByName(obj, childName, childType, recursive) {
  1184. var child = undefined;
  1185. if (recursive) {
  1186. // TODO: If the obj itself has the child name, the object will be returned by this function
  1187. // I don't think this this desirable.
  1188. if (nameTest.call(this, obj, childName)) {
  1189. child = obj;
  1190. } else if (obj.children && obj.children.length > 0) {
  1191. for (var i = 0; i < obj.children.length && child === undefined; i++) {
  1192. child = FindChildByName(obj.children[i], childName, childType, true);
  1193. }
  1194. }
  1195. } else {
  1196. if (obj.children) {
  1197. for (var i = 0; i < obj.children.length && child === undefined; i++) {
  1198. if (nameTest.call(this, obj.children[i], childName)) {
  1199. child = obj.children[i];
  1200. }
  1201. }
  1202. }
  1203. }
  1204. return child;
  1205. }
  1206. function nameTest(obj, name) {
  1207. if (obj.name == "") {
  1208. return (obj.parent.name + "Child" == name);
  1209. } else {
  1210. return (obj.name == name || obj.id == name || obj.vwfID == name);
  1211. }
  1212. }
  1213. function httpGet(url) {
  1214. return new Promise(function (resolve, reject) {
  1215. // do the usual Http request
  1216. let request = new XMLHttpRequest();
  1217. request.open('GET', url);
  1218. request.onload = function () {
  1219. if (request.status == 200) {
  1220. resolve(request.response);
  1221. } else {
  1222. reject(Error(request.statusText));
  1223. }
  1224. };
  1225. request.onerror = function () {
  1226. reject(Error('Network Error'));
  1227. };
  1228. request.send();
  1229. });
  1230. }
  1231. async function httpGetJson(url) {
  1232. // check if the URL looks like a JSON file and call httpGet.
  1233. let regex = /\.(json)$/i;
  1234. if (regex.test(url)) {
  1235. // call the async function, wait for the result
  1236. return await httpGet(url);
  1237. } else {
  1238. throw Error('Bad Url Format');
  1239. }
  1240. }
  1241. function GUID() {
  1242. var S4 = function () {
  1243. return Math.floor(
  1244. Math.random() * 0x10000 /* 65536 */
  1245. ).toString(16);
  1246. };
  1247. return (
  1248. S4() + S4() + "-" +
  1249. S4() + "-" +
  1250. S4() + "-" +
  1251. S4() + "-" +
  1252. S4() + S4() + S4()
  1253. );
  1254. }
  1255. });