aframe.js 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  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] === "proxy/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. //.filter(el=>el !== 'font')
  439. self.aframeDef['A-TEXT'].forEach(element => {
  440. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  441. value = undefined;
  442. })
  443. // if(propertyName == 'font'){
  444. // console.log('Loading font...', element);
  445. // }
  446. }
  447. if (value === undefined && aframeObject.nodeName == "A-SCENE") {
  448. value = propertyValue;
  449. switch (propertyName) {
  450. case "color":
  451. aframeObject.setAttribute('background', { 'color': propertyValue });
  452. break;
  453. case "transparent":
  454. aframeObject.setAttribute('background', { 'transparent': propertyValue });
  455. break;
  456. // case "fog":
  457. // aframeObject.setAttribute('fog', propertyValue);
  458. // break;
  459. case "assets":
  460. initAssets(propertyValue)
  461. break;
  462. default:
  463. value = undefined;
  464. break;
  465. }
  466. }
  467. if (value === undefined && aframeObject.nodeName == "A-BOX") {
  468. value = propertyValue;
  469. self.aframeDef['A-BOX'].forEach(element => {
  470. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  471. value = undefined;
  472. })
  473. }
  474. if (value === undefined && aframeObject.nodeName == "A-LIGHT") {
  475. value = propertyValue;
  476. self.aframeDef['A-LIGHT'].forEach(element => {
  477. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  478. value = undefined;
  479. })
  480. switch (propertyName) {
  481. case "castShadow":
  482. aframeObject.setAttribute('light', 'castShadow', propertyValue);
  483. break;
  484. case "shadowCameraVisible":
  485. aframeObject.setAttribute('light', 'shadowCameraVisible', propertyValue);
  486. break;
  487. default:
  488. value = undefined;
  489. break;
  490. }
  491. }
  492. if (value === undefined && aframeObject.nodeName == "A-GLTF-MODEL") {
  493. value = propertyValue;
  494. switch (propertyName) {
  495. case "src":
  496. aframeObject.setAttribute('src', propertyValue);
  497. break;
  498. default:
  499. value = undefined;
  500. break;
  501. }
  502. }
  503. if (value === undefined && aframeObject.nodeName == "A-COLLADA-MODEL") {
  504. value = propertyValue;
  505. switch (propertyName) {
  506. case "src":
  507. aframeObject.setAttribute('src', propertyValue);
  508. break;
  509. default:
  510. value = undefined;
  511. break;
  512. }
  513. }
  514. if (value === undefined && aframeObject.nodeName == "A-OBJ-MODEL") {
  515. value = propertyValue;
  516. switch (propertyName) {
  517. case "src":
  518. aframeObject.setAttribute('src', propertyValue);
  519. break;
  520. case "mtl":
  521. aframeObject.setAttribute('mtl', propertyValue);
  522. break;
  523. default:
  524. value = undefined;
  525. break;
  526. }
  527. }
  528. if (value === undefined && aframeObject.nodeName == "A-PLANE") {
  529. value = propertyValue;
  530. self.aframeDef['A-PLANE'].forEach(element => {
  531. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  532. value = undefined;
  533. })
  534. }
  535. if (value === undefined && aframeObject.nodeName == "A-SPHERE") {
  536. value = propertyValue;
  537. self.aframeDef['A-SPHERE'].forEach(element => {
  538. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  539. value = undefined;
  540. })
  541. }
  542. if (value === undefined && aframeObject.nodeName == "A-CYLINDER") {
  543. value = propertyValue;
  544. self.aframeDef['A-CYLINDER'].forEach(element => {
  545. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  546. value = undefined;
  547. })
  548. }
  549. if (value === undefined && aframeObject.nodeName == "A-CONE") {
  550. value = propertyValue;
  551. self.aframeDef['A-CONE'].forEach(element => {
  552. element == propertyName ? aframeObject.setAttribute(element, propertyValue) :
  553. value = undefined;
  554. })
  555. }
  556. if (value === undefined && aframeObject.nodeName == "A-ANIMATION") {
  557. value = propertyValue;
  558. switch (propertyName) {
  559. // attribute:
  560. // dur:
  561. // from:
  562. // to:
  563. // repeat:
  564. case "dur":
  565. aframeObject.setAttribute('dur', propertyValue);
  566. break;
  567. case "from":
  568. aframeObject.setAttribute('from', propertyValue);
  569. break;
  570. case "to":
  571. aframeObject.setAttribute('to', propertyValue);
  572. break;
  573. case "repeat":
  574. aframeObject.setAttribute('repeat', propertyValue);
  575. break;
  576. case "attribute":
  577. aframeObject.setAttribute('attribute', propertyValue);
  578. break;
  579. case "begin":
  580. aframeObject.setAttribute('begin', propertyValue);
  581. break;
  582. default:
  583. value = undefined;
  584. break;
  585. }
  586. }
  587. if (value === undefined && aframeObject.nodeName == "A-CAMERA") {
  588. value = propertyValue;
  589. switch (propertyName) {
  590. case "user-height":
  591. aframeObject.setAttribute('user-height', propertyValue);
  592. break;
  593. case "look-controls-enabled":
  594. aframeObject.setAttribute('look-controls-enabled', propertyValue);
  595. break;
  596. case "wasd-controls-enabled":
  597. aframeObject.setAttribute('wasd-controls-enabled', propertyValue);
  598. break;
  599. // case "active":
  600. // aframeObject.setAttribute('camera', 'active', propertyValue);
  601. // break;
  602. default:
  603. value = undefined;
  604. break;
  605. }
  606. }
  607. if (value === undefined && aframeObject.nodeName == "A-SUN-SKY") {
  608. value = propertyValue;
  609. switch (propertyName) {
  610. case "sunPosition":
  611. aframeObject.setAttribute('material', 'sunPosition', propertyValue);
  612. break;
  613. // case "active":
  614. // aframeObject.setAttribute('camera', 'active', propertyValue);
  615. // break;
  616. default:
  617. value = undefined;
  618. break;
  619. }
  620. }
  621. if (value === undefined && aframeObject.nodeName == "A-ANCHOR") {
  622. value = propertyValue;
  623. switch (propertyName) {
  624. case "changeMatrixMode":
  625. aframeObject.setAttribute('arjs-anchor', 'changeMatrixMode', propertyValue);
  626. break;
  627. case 'hit-testing-enabled':
  628. aframeObject.setAttribute('hit-testing-enabled', propertyValue);
  629. break;
  630. case 'preset':
  631. aframeObject.setAttribute('preset', propertyValue);
  632. break;
  633. case 'markerType':
  634. aframeObject.setAttribute('type', propertyValue);
  635. break;
  636. case 'markerValue':
  637. aframeObject.setAttribute('velue', propertyValue);
  638. break;
  639. default:
  640. value = undefined;
  641. break;
  642. }
  643. }
  644. }
  645. return value;
  646. },
  647. // -- gettingProperty ----------------------------------------------------------------------
  648. gettingProperty: function (nodeID, propertyName, propertyValue) {
  649. var node = this.state.nodes[nodeID];
  650. var value = undefined;
  651. if (node && node.aframeObj) {
  652. var aframeObject = node.aframeObj;
  653. if (isNodeDefinition(node.prototypes)) {
  654. switch (propertyName) {
  655. }
  656. }
  657. if (value === undefined && isAEntityDefinition(node.prototypes)) {
  658. switch (propertyName) {
  659. case "position":
  660. // var pos = aframeObject.getAttribute('position');
  661. // if (pos !== undefined) {
  662. // value = pos//[pos.x, pos.y, pos.z]//AFRAME.utils.coordinates.stringify(pos);
  663. // }
  664. if (node.transform.position) {
  665. if (node.transform.storedPositionDirty) {
  666. updateStoredTransformFor(node, 'position');
  667. }
  668. value = goog.vec.Vec3.clone(node.transform.position);
  669. //value = node.transform.position;
  670. }
  671. break;
  672. case "rotation":
  673. if (node.transform.rotation) {
  674. if (node.transform.storedRotationDirty) {
  675. updateStoredTransformFor(node, 'rotation');
  676. }
  677. value = goog.vec.Vec3.clone(node.transform.rotation);
  678. // var rot = aframeObject.getAttribute('rotation');
  679. // if (rot !== undefined) {
  680. // value = rot//AFRAME.utils.coordinates.stringify(rot);
  681. // }
  682. }
  683. break;
  684. case "scale":
  685. if (node.transform.scale) {
  686. if (node.transform.storedScaleDirty) {
  687. updateStoredTransformFor(node, 'scale');
  688. }
  689. value = goog.vec.Vec3.clone(node.transform.scale);
  690. // var scale = aframeObject.getAttribute('scale');
  691. // if (scale !== undefined) {
  692. // value = scale//AFRAME.utils.coordinates.stringify(scale);
  693. // }
  694. }
  695. break;
  696. case "clickable":
  697. value = node.events.clickable;
  698. break;
  699. case "class":
  700. value = aframeObject.classList.toString();
  701. //aframeObject.getAttribute('class');
  702. break;
  703. // case "look-controls-enabled":
  704. // var look = aframeObject.getAttribute('look-controls-enabled');
  705. // if (look !== null && look !== undefined) {
  706. // value = aframeObject.getAttribute('look-controls').enabled;
  707. // }
  708. // break;
  709. // case "wasd-controls":
  710. // var wasd = aframeObject.getAttribute('wasd-controls');
  711. // if (wasd !== null && wasd !== undefined) {
  712. // value = aframeObject.getAttribute('wasd-controls').enabled;
  713. // }
  714. // break;
  715. case "ownedBy":
  716. value = aframeObject.getAttribute('ownedby');
  717. break;
  718. case "visible":
  719. value = aframeObject.getAttribute('visible');
  720. break;
  721. }
  722. }
  723. if (value === undefined && aframeObject.nodeName == "A-ASSET-ITEM") {
  724. switch (propertyName) {
  725. case "itemID":
  726. value = aframeObject.getAttribute('id');
  727. break;
  728. case "itemSrc":
  729. value = aframeObject.getAttribute('src');
  730. break;
  731. }
  732. }
  733. if (value === undefined && aframeObject.nodeName == "IMG") {
  734. switch (propertyName) {
  735. case "itemID":
  736. value = aframeObject.getAttribute('id');
  737. break;
  738. case "itemSrc":
  739. value = aframeObject.getAttribute('src');
  740. break;
  741. case "width":
  742. value = aframeObject.width;
  743. break;
  744. case "height":
  745. value = aframeObject.height;
  746. break;
  747. }
  748. }
  749. if (value === undefined && aframeObject.nodeName == "AUDIO") {
  750. switch (propertyName) {
  751. case "itemID":
  752. value = aframeObject.getAttribute('id');
  753. break;
  754. case "itemSrc":
  755. value = aframeObject.getAttribute('src');
  756. break;
  757. }
  758. }
  759. if (value === undefined && aframeObject.nodeName == "VIDEO") {
  760. switch (propertyName) {
  761. case "itemID":
  762. value = aframeObject.getAttribute('id');
  763. break;
  764. case "itemSrc":
  765. value = aframeObject.getAttribute('src');
  766. break;
  767. case "videoWidth":
  768. value = aframeObject.videoWidth;
  769. break;
  770. case "videoHeight":
  771. value = aframeObject.videoHeight;
  772. break;
  773. }
  774. }
  775. if (value === undefined && aframeObject.nodeName == "A-SCENE") {
  776. switch (propertyName) {
  777. // case "fog":
  778. // value = aframeObject.getAttribute('fog');
  779. // break;
  780. case "assets":
  781. break;
  782. case "color":
  783. if (aframeObject.getAttribute('background')) {
  784. value = aframeObject.getAttribute('background').color;
  785. }
  786. break;
  787. case "transparent":
  788. if (aframeObject.getAttribute('background')) {
  789. value = aframeObject.getAttribute('background').transparent;
  790. }
  791. break;
  792. }
  793. }
  794. if (value === undefined && aframeObject.nodeName == "A-SKY") {
  795. self.aframeDef['A-SKY'].forEach(element => {
  796. if (element == propertyName) {
  797. value = aframeObject.getAttribute(element);
  798. }
  799. })
  800. }
  801. if (value === undefined && aframeObject.nodeName == "A-LIGHT") {
  802. self.aframeDef['A-LIGHT'].forEach(element => {
  803. if (element == propertyName) {
  804. value = aframeObject.getAttribute(element);
  805. }
  806. })
  807. switch (propertyName) {
  808. case "castShadow":
  809. value = aframeObject.getAttribute('light').castShadow;
  810. break;
  811. case "shadowCameraVisible":
  812. value = aframeObject.getAttribute('light').shadowCameraVisible;
  813. break;
  814. }
  815. }
  816. if (value === undefined && aframeObject.nodeName == "A-BOX") {
  817. self.aframeDef['A-BOX'].forEach(element => {
  818. if (element == propertyName) {
  819. value = aframeObject.getAttribute(element);
  820. }
  821. })
  822. }
  823. if (value === undefined && aframeObject.nodeName == "A-PLANE") {
  824. self.aframeDef['A-PLANE'].forEach(element => {
  825. if (element == propertyName) {
  826. value = aframeObject.getAttribute(element);
  827. }
  828. })
  829. }
  830. if (value === undefined && aframeObject.nodeName == "A-SPHERE") {
  831. self.aframeDef['A-SPHERE'].forEach(element => {
  832. if (element == propertyName) {
  833. value = aframeObject.getAttribute(element);
  834. }
  835. })
  836. }
  837. if (value === undefined && aframeObject.nodeName == "A-CYLINDER") {
  838. self.aframeDef['A-CYLINDER'].forEach(element => {
  839. if (element == propertyName) {
  840. value = aframeObject.getAttribute(element);
  841. }
  842. })
  843. }
  844. if (value === undefined && aframeObject.nodeName == "A-CONE") {
  845. self.aframeDef['A-CONE'].forEach(element => {
  846. if (element == propertyName) {
  847. value = aframeObject.getAttribute(element);
  848. }
  849. })
  850. }
  851. if (value === undefined && aframeObject.nodeName == "A-TEXT") {
  852. self.aframeDef['A-TEXT'].forEach(element => {
  853. if (element == propertyName) {
  854. value = aframeObject.getAttribute(element);
  855. }
  856. })
  857. }
  858. if (value === undefined && aframeObject.nodeName == "A-ANIMATION") {
  859. switch (propertyName) {
  860. case "attribute":
  861. value = aframeObject.getAttribute('attribute');
  862. break;
  863. case "dur":
  864. value = aframeObject.getAttribute('dur');
  865. break;
  866. case "from":
  867. value = aframeObject.getAttribute('from');
  868. break;
  869. case "to":
  870. value = aframeObject.getAttribute('to');
  871. break;
  872. case "repeat":
  873. value = aframeObject.getAttribute('repeat');
  874. break;
  875. case "begin":
  876. value = aframeObject.getAttribute('begin');
  877. break;
  878. }
  879. }
  880. if (value === undefined && aframeObject.nodeName == "A-CAMERA") {
  881. switch (propertyName) {
  882. case "user-height":
  883. value = aframeObject.getAttribute('user-height');
  884. break;
  885. case "look-controls-enabled":
  886. value = aframeObject.getAttribute('look-controls-enabled');
  887. break;
  888. case "wasd-controls-enabled":
  889. value = aframeObject.getAttribute('wasd-controls-enabled');
  890. break;
  891. }
  892. // switch (propertyName) {
  893. // case "active":
  894. // value = aframeObject.getAttribute('camera').active;
  895. // break;
  896. // }
  897. }
  898. if (value === undefined && aframeObject.nodeName == "A-SUN-SKY") {
  899. switch (propertyName) {
  900. case "sunPosition":
  901. value = aframeObject.getAttribute('material').sunPosition;
  902. break;
  903. }
  904. // switch (propertyName) {
  905. // case "active":
  906. // value = aframeObject.getAttribute('camera').active;
  907. // break;
  908. // }
  909. }
  910. if (value === undefined && aframeObject.nodeName == "A-COLLADA-MODEL") {
  911. switch (propertyName) {
  912. case "src":
  913. value = aframeObject.getAttribute('src');
  914. break;
  915. }
  916. }
  917. if (value === undefined && aframeObject.nodeName == "A-OBJ-MODEL") {
  918. switch (propertyName) {
  919. case "src":
  920. value = aframeObject.getAttribute('src');
  921. break;
  922. case "mtl":
  923. value = aframeObject.getAttribute('mtl');
  924. break;
  925. }
  926. }
  927. if (value === undefined && aframeObject.nodeName == "A-GLTF-MODEL") {
  928. switch (propertyName) {
  929. case "src":
  930. value = aframeObject.getAttribute('src');
  931. break;
  932. }
  933. }
  934. if (value === undefined && aframeObject.nodeName == "A-ANCHOR") {
  935. switch (propertyName) {
  936. case "changeMatrixMode":
  937. value = aframeObject.getAttribute('arjs-anchor').changeMatrixMode;
  938. break;
  939. case "hit-testing-enabled":
  940. value = aframeObject.getAttribute('hit-testing-enabled');
  941. break;
  942. case "preset":
  943. value = aframeObject.getAttribute('preset');
  944. break;
  945. case 'markerType':
  946. value = aframeObject.getAttribute('type');
  947. break;
  948. case 'markerValue':
  949. value = aframeObject.getAttribute('value');
  950. break;
  951. }
  952. }
  953. }
  954. if (value !== undefined) {
  955. propertyValue = value;
  956. }
  957. return value;
  958. }
  959. });
  960. function createAFrameObject(node, config) {
  961. var protos = node.prototypes;
  962. var aframeObj = undefined;
  963. if (self.state.isAFrameClass(protos, "proxy/aframe/ascene.vwf")) {
  964. aframeObj = document.createElement('a-scene');
  965. let assetsElement = document.createElement('a-assets');
  966. aframeObj.appendChild(assetsElement);
  967. aframeObj.setAttribute('scene-utils', "");
  968. aframeObj.setAttribute('light', 'defaultLightsEnabled', false);
  969. //aframeObj.setAttribute('embedded', {});
  970. //aframeObj.setAttribute('loading-screen', "backgroundColor: black");
  971. self.state.scenes[node.ID] = aframeObj;
  972. //TODO: move from veiw here
  973. //document.body.appendChild(aframeObj);
  974. } else if (self.state.isAFrameClass(protos, "proxy/aframe/a-asset-item.vwf")) {
  975. let assets = document.querySelector('a-assets');
  976. if (assets) {
  977. aframeObj = document.createElement('a-asset-item');
  978. aframeObj.setAttribute('id', "item-" + GUID());
  979. aframeObj.setAttribute('src', "");
  980. aframeObj.setAttribute('crossorigin', "anonymous");
  981. assets.appendChild(aframeObj);
  982. }
  983. } else if (self.state.isAFrameClass(protos, "proxy/aframe/a-asset-image-item.vwf")) {
  984. let assets = document.querySelector('a-assets');
  985. if (assets) {
  986. let elID = "item-" + GUID();
  987. aframeObj = document.createElement('img');
  988. aframeObj.setAttribute('id', elID);
  989. aframeObj.setAttribute('src', "");
  990. aframeObj.setAttribute('crossorigin', "anonymous");
  991. assets.appendChild(aframeObj);
  992. }
  993. } else if (self.state.isAFrameClass(protos, "proxy/aframe/a-asset-audio-item.vwf")) {
  994. let assets = document.querySelector('a-assets');
  995. if (assets) {
  996. aframeObj = document.createElement('audio');
  997. aframeObj.setAttribute('id', "item-" + GUID());
  998. aframeObj.setAttribute('src', "");
  999. aframeObj.setAttribute('crossorigin', "anonymous");
  1000. assets.appendChild(aframeObj);
  1001. }
  1002. } else if (self.state.isAFrameClass(protos, "proxy/aframe/a-asset-video-item.vwf")) {
  1003. let assets = document.querySelector('a-assets');
  1004. if (assets) {
  1005. aframeObj = document.createElement('video');
  1006. aframeObj.setAttribute('id', "item-" + GUID());
  1007. aframeObj.setAttribute('src', "");
  1008. aframeObj.setAttribute('crossorigin', "anonymous");
  1009. aframeObj.setAttribute('autoplay', "");
  1010. aframeObj.setAttribute('loop', true);
  1011. assets.appendChild(aframeObj);
  1012. }
  1013. } else if (self.state.isAFrameClass(protos, "proxy/aframe/asky.vwf")) {
  1014. aframeObj = document.createElement('a-sky');
  1015. } else if (self.state.isAFrameClass(protos, "proxy/aframe/a-arjs-anchor.vwf")) {
  1016. aframeObj = document.createElement('a-anchor');
  1017. } else if (self.state.isAFrameClass(protos, "proxy/aframe/alight.vwf")) {
  1018. aframeObj = document.createElement('a-light');
  1019. } else if (self.state.isAFrameClass(protos, "proxy/aframe/acursor.vwf")) {
  1020. aframeObj = document.createElement('a-cursor');
  1021. } else if (self.state.isAFrameClass(protos, "proxy/aframe/a-sun-sky.vwf")) {
  1022. aframeObj = document.createElement('a-sun-sky');
  1023. } else if (self.state.isAFrameClass(protos, "proxy/aframe/abox.vwf")) {
  1024. aframeObj = document.createElement('a-box');
  1025. } else if (self.state.isAFrameClass(protos, "proxy/aframe/aplane.vwf")) {
  1026. aframeObj = document.createElement('a-plane');
  1027. } else if (self.state.isAFrameClass(protos, "proxy/aframe/acylinder.vwf")) {
  1028. aframeObj = document.createElement('a-cylinder');
  1029. } else if (self.state.isAFrameClass(protos, "proxy/aframe/acone.vwf")) {
  1030. aframeObj = document.createElement('a-cone');
  1031. } else if (self.state.isAFrameClass(protos, "proxy/aframe/atext.vwf")) {
  1032. aframeObj = document.createElement('a-text');
  1033. } else if (self.state.isAFrameClass(protos, "proxy/aframe/acolladamodel.vwf")) {
  1034. aframeObj = document.createElement('a-collada-model');
  1035. } else if (self.state.isAFrameClass(protos, "proxy/aframe/aobjmodel.vwf")) {
  1036. aframeObj = document.createElement('a-obj-model');
  1037. } else if (self.state.isAFrameClass(protos, "proxy/aframe/agltfmodel.vwf")) {
  1038. aframeObj = document.createElement('a-gltf-model');
  1039. } else if (self.state.isAFrameClass(protos, "proxy/aframe/asphere.vwf")) {
  1040. aframeObj = document.createElement('a-sphere');
  1041. } else if (self.state.isAFrameClass(protos, "proxy/aframe/aanimation.vwf")) {
  1042. aframeObj = document.createElement('a-animation');
  1043. } else if (self.state.isAFrameClass(protos, "proxy/aframe/acamera.vwf")) {
  1044. aframeObj = document.createElement('a-camera');
  1045. aframeObj.setAttribute('camera', 'active', false);
  1046. } else if (self.state.isAFrameClass(protos, "proxy/aframe/aentity.vwf")) {
  1047. aframeObj = document.createElement('a-entity');
  1048. }
  1049. if (aframeObj.nodeName !== "A-ASSET-ITEM" &&
  1050. aframeObj.nodeName !== "IMG" &&
  1051. aframeObj.nodeName !== "AUDIO" &&
  1052. aframeObj.nodeName !== "VIDEO"
  1053. ) {
  1054. aframeObj.setAttribute('id', node.ID);
  1055. }
  1056. return aframeObj;
  1057. }
  1058. function addNodeToHierarchy(node) {
  1059. if (node.aframeObj) {
  1060. if (self.state.nodes[node.parentID] !== undefined) {
  1061. var parent = self.state.nodes[node.parentID];
  1062. if (parent.aframeObj) {
  1063. if (parent.children === undefined) {
  1064. parent.children = [];
  1065. }
  1066. parent.children.push(node.ID);
  1067. //console.info( "Adding child: " + childID + " to " + nodeID );
  1068. if (node.aframeObj.nodeName !== "A-ASSET-ITEM" &&
  1069. node.aframeObj.nodeName !== "IMG" &&
  1070. node.aframeObj.nodeName !== "AUDIO" &&
  1071. node.aframeObj.nodeName !== "VIDEO"
  1072. ) {
  1073. parent.aframeObj.appendChild(node.aframeObj);
  1074. }
  1075. }
  1076. }
  1077. if (node.aframeObj.nodeName !== "A-SCENE") {
  1078. node.scene = self.state.scenes[self.kernel.application()];
  1079. }
  1080. }
  1081. }
  1082. function updateStoredTransform(node) {
  1083. if (node && node.aframeObj) {
  1084. // Add a local model-side transform that can stay pure even if the view changes the
  1085. // transform on the threeObject - this already happened in creatingNode for those nodes that
  1086. // didn't need to load a model
  1087. node.transform = {};
  1088. //let pos = node.aframeObj.object3D.position;
  1089. let pos = (new THREE.Vector3()).copy(node.aframeObj.object3D.position);
  1090. node.transform.position = goog.vec.Vec3.createFromValues(pos.x, pos.y, pos.z);
  1091. //node.transform.position = AFRAME.utils.coordinates.stringify(node.aframeObj.object3D.position);
  1092. node.transform.rotation = AFRAME.utils.coordinates.stringify(node.aframeObj.object3D.rotation);
  1093. node.storedTransformDirty = false;
  1094. }
  1095. }
  1096. async function initAssets(propertyValue){
  1097. let assetsEl = document.querySelector('a-assets');
  1098. if (!assetsEl) {
  1099. let newAssetsEl = document.createElement('a-assets');
  1100. aframeObject.appendChild(newAssetsEl);
  1101. }
  1102. var assetsElement = document.querySelector('a-assets');
  1103. if (propertyValue) {
  1104. let path = JSON.parse(localStorage.getItem('lcs_app')).path.public_path;
  1105. let worldName = path.slice(1);
  1106. let dbPath = propertyValue.split(".").join("_");
  1107. let userDB = _LCSDB.user(_LCS_WORLD_USER.pub);
  1108. userDB.get('worlds').get(worldName).get(dbPath).load(function(response) {
  1109. if (response) {
  1110. if (Object.keys(response).length > 0) {
  1111. //console.log(JSON.parse(response));
  1112. let assets = (typeof(response) == 'object') ? response: JSON.parse(response);
  1113. for (var prop in assets) {
  1114. var elm = document.createElement(assets[prop].tag);
  1115. elm.setAttribute('id', prop);
  1116. elm.setAttribute('src', assets[prop].src);
  1117. assetsElement.appendChild(elm);
  1118. }
  1119. }
  1120. }
  1121. });
  1122. // httpGetJson(propertyValue).then(function (response) {
  1123. // console.log(JSON.parse(response));
  1124. // let assets = JSON.parse(response);
  1125. // for (var prop in assets) {
  1126. // var elm = document.createElement(assets[prop].tag);
  1127. // elm.setAttribute('id', prop);
  1128. // elm.setAttribute('src', assets[prop].src);
  1129. // assetsElement.appendChild(elm);
  1130. // }
  1131. // }).catch(function (error) {
  1132. // console.log(error);
  1133. // });
  1134. }
  1135. }
  1136. function updateStoredTransformFor(node, propertyName) {
  1137. if (node && node.aframeObj) {
  1138. // Add a local model-side transform that can stay pure even if the view changes the
  1139. // transform on the threeObject - this already happened in creatingNode for those nodes that
  1140. // didn't need to load a model
  1141. if (!node.transform)
  1142. node.transform = {};
  1143. if (propertyName == 'position') {
  1144. let pos = (new THREE.Vector3()).copy(node.aframeObj.object3D.position);
  1145. node.transform.position = goog.vec.Vec3.createFromValues(pos.x, pos.y, pos.z);
  1146. node.transform.storedPositionDirty = false;
  1147. }
  1148. if (propertyName == 'rotation') {
  1149. // let rot = (new THREE.Vector3()).copy(node.aframeObj.object3D.rotation);
  1150. let rot = node.aframeObj.getAttribute('rotation');
  1151. node.transform.rotation = goog.vec.Vec3.createFromValues(rot.x, rot.y, rot.z);
  1152. node.transform.storedRotationDirty = false;
  1153. }
  1154. if (propertyName == 'scale') {
  1155. let scale = (new THREE.Vector3()).copy(node.aframeObj.object3D.scale);
  1156. node.transform.scale = goog.vec.Vec3.createFromValues(scale.x, scale.y, scale.z);
  1157. node.transform.storedScaleDirty = false;
  1158. }
  1159. //node.transform.position = AFRAME.utils.coordinates.stringify(node.aframeObj.object3D.position);
  1160. // node.transform.rotation = AFRAME.utils.coordinates.stringify(node.aframeObj.object3D.rotation);
  1161. // node.storedTransformDirty = false;
  1162. }
  1163. }
  1164. function getPrototypes(kernel, extendsID) {
  1165. var prototypes = [];
  1166. var id = extendsID;
  1167. while (id !== undefined) {
  1168. prototypes.push(id);
  1169. id = kernel.prototype(id);
  1170. }
  1171. return prototypes;
  1172. }
  1173. function isNodeDefinition(prototypes) {
  1174. var found = false;
  1175. if (prototypes) {
  1176. for (var i = 0; i < prototypes.length && !found; i++) {
  1177. found = (prototypes[i] == "proxy/aframe/node.vwf");
  1178. }
  1179. }
  1180. return found;
  1181. }
  1182. function isAEntityDefinition(prototypes) {
  1183. var found = false;
  1184. if (prototypes) {
  1185. for (var i = 0; i < prototypes.length && !found; i++) {
  1186. found = (prototypes[i] == "proxy/aframe/aentity.vwf");
  1187. }
  1188. }
  1189. return found;
  1190. }
  1191. // Changing this function significantly from the GLGE code
  1192. // Will search hierarchy down until encountering a matching child
  1193. // Will look into nodes that don't match.... this might not be desirable
  1194. function FindChildByName(obj, childName, childType, recursive) {
  1195. var child = undefined;
  1196. if (recursive) {
  1197. // TODO: If the obj itself has the child name, the object will be returned by this function
  1198. // I don't think this this desirable.
  1199. if (nameTest.call(this, obj, childName)) {
  1200. child = obj;
  1201. } else if (obj.children && obj.children.length > 0) {
  1202. for (var i = 0; i < obj.children.length && child === undefined; i++) {
  1203. child = FindChildByName(obj.children[i], childName, childType, true);
  1204. }
  1205. }
  1206. } else {
  1207. if (obj.children) {
  1208. for (var i = 0; i < obj.children.length && child === undefined; i++) {
  1209. if (nameTest.call(this, obj.children[i], childName)) {
  1210. child = obj.children[i];
  1211. }
  1212. }
  1213. }
  1214. }
  1215. return child;
  1216. }
  1217. function nameTest(obj, name) {
  1218. if (obj.name == "") {
  1219. return (obj.parent.name + "Child" == name);
  1220. } else {
  1221. return (obj.name == name || obj.id == name || obj.vwfID == name);
  1222. }
  1223. }
  1224. function httpGet(url) {
  1225. return new Promise(function (resolve, reject) {
  1226. // do the usual Http request
  1227. let request = new XMLHttpRequest();
  1228. request.open('GET', url);
  1229. request.onload = function () {
  1230. if (request.status == 200) {
  1231. resolve(request.response);
  1232. } else {
  1233. reject(Error(request.statusText));
  1234. }
  1235. };
  1236. request.onerror = function () {
  1237. reject(Error('Network Error'));
  1238. };
  1239. request.send();
  1240. });
  1241. }
  1242. async function httpGetJson(url) {
  1243. // check if the URL looks like a JSON file and call httpGet.
  1244. let regex = /\.(json)$/i;
  1245. if (regex.test(url)) {
  1246. // call the async function, wait for the result
  1247. return await httpGet(url);
  1248. } else {
  1249. throw Error('Bad Url Format');
  1250. }
  1251. }
  1252. function GUID() {
  1253. var S4 = function () {
  1254. return Math.floor(
  1255. Math.random() * 0x10000 /* 65536 */
  1256. ).toString(16);
  1257. };
  1258. return (
  1259. S4() + S4() + "-" +
  1260. S4() + "-" +
  1261. S4() + "-" +
  1262. S4() + "-" +
  1263. S4() + S4() + S4()
  1264. );
  1265. }
  1266. });