aframe.js 66 KB

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