aframeComponent.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  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 components model driver
  8. define(["module", "vwf/model", "vwf/utility"], function (module, model, utility) {
  9. var self;
  10. // vwf/model/example/scene.js is a demonstration of a scene manager.
  11. return model.load(module, {
  12. // == Module Definition ====================================================================
  13. // -- pipeline -----------------------------------------------------------------------------
  14. // pipeline: [ log ], // vwf <=> log <=> scene
  15. // -- initialize ---------------------------------------------------------------------------
  16. initialize: function () {
  17. self = this;
  18. this.state = {
  19. nodes: {},
  20. scenes: {},
  21. prototypes: {},
  22. createLocalNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  23. childSource, childType, childIndex, childName, callback) {
  24. return {
  25. "parentID": nodeID,
  26. "ID": childID,
  27. "extendsID": childExtendsID,
  28. "implementsIDs": childImplementsIDs,
  29. "source": childSource,
  30. "type": childType,
  31. "name": childName,
  32. "prototypes": undefined,
  33. "aframeObj": undefined,
  34. "componentName": undefined
  35. };
  36. },
  37. isComponentClass: function (prototypes, classID) {
  38. if (prototypes) {
  39. for (var i = 0; i < prototypes.length; i++) {
  40. if (prototypes[i] === classID) {
  41. //console.info( "prototypes[ i ]: " + prototypes[ i ] );
  42. return true;
  43. }
  44. }
  45. }
  46. return false;
  47. },
  48. isComponentNode: function (prototypes) {
  49. var found = false;
  50. if (prototypes) {
  51. for (var i = 0; i < prototypes.length && !found; i++) {
  52. found = (prototypes[i] === "http://vwf.example.com/aframe/componentNode.vwf");
  53. }
  54. }
  55. return found;
  56. }
  57. };
  58. this.state.kernel = this.kernel.kernel.kernel;
  59. this.aframeComponentDef = {
  60. 'A-MATERIAL': [
  61. "alphaTest",
  62. "depthTest",
  63. "flatShading",
  64. "npot",
  65. "offset",
  66. "opacity",
  67. "remain",
  68. "repeat",
  69. "shader",
  70. "side",
  71. "transparent",
  72. "vertexColors",
  73. "visible",
  74. "ambient-occlusion-map",
  75. "ambient-occlusion-map-intensity",
  76. "ambient-occlusion-texture-offset",
  77. "ambient-occlusion-texture-repeat",
  78. "color",
  79. "displacement-bias",
  80. "displacement-map",
  81. "displacement-scale",
  82. "displacement-texture-offset",
  83. "displacement-texture-repeat",
  84. "emissive",
  85. "emissiveIntensity",
  86. "height",
  87. "envMap",
  88. "fog",
  89. "metalness",
  90. "normal-map",
  91. "normal-scale",
  92. "normal-texture-offset",
  93. "normal-texture-repeat",
  94. "roughness",
  95. "sphericalEnvMap",
  96. "width",
  97. "wireframe",
  98. "wireframe-linewidth",
  99. "src"],
  100. 'A-SOUND': [
  101. "autoplay", "distanceModel", "loop", "maxDistance", "on", "poolSize", "refDistance",
  102. "rolloffFactor", "src", "volume"
  103. ],
  104. 'aabb-collider':[
  105. "collideNonVisible", "debug", "enabled", "objects", "interval"
  106. ]
  107. }
  108. //this.state.kernel = this.kernel.kernel.kernel;
  109. },
  110. // == Model API ============================================================================
  111. // -- creatingNode -------------------------------------------------------------------------
  112. creatingNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  113. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  114. // If the parent nodeID is 0, this node is attached directly to the root and is therefore either
  115. // the scene or a prototype. In either of those cases, save the uri of the new node
  116. var childURI = (nodeID === 0 ? childIndex : undefined);
  117. var appID = this.kernel.application();
  118. // If the node being created is a prototype, construct it and add it to the array of prototypes,
  119. // and then return
  120. var prototypeID = utility.ifPrototypeGetId(appID, this.state.prototypes, nodeID, childID);
  121. if (prototypeID !== undefined) {
  122. this.state.prototypes[prototypeID] = {
  123. parentID: nodeID,
  124. ID: childID,
  125. extendsID: childExtendsID,
  126. implementsID: childImplementsIDs,
  127. source: childSource,
  128. type: childType,
  129. name: childName
  130. };
  131. return;
  132. }
  133. var protos = getPrototypes(this.kernel, childExtendsID);
  134. //var kernel = this.kernel.kernel.kernel;
  135. var node;
  136. if (this.state.isComponentNode(protos)) {
  137. // Create the local copy of the node properties
  138. if (this.state.nodes[childID] === undefined) {
  139. this.state.nodes[childID] = this.state.createLocalNode(nodeID, childID, childExtendsID, childImplementsIDs,
  140. childSource, childType, childIndex, childName, callback);
  141. }
  142. node = this.state.nodes[childID];
  143. node.prototypes = protos;
  144. //node.aframeObj = createAFrameObject(node);
  145. node.aframeObj = setAFrameObject(node);
  146. // addNodeToHierarchy(node);
  147. //notifyDriverOfPrototypeAndBehaviorProps();
  148. }
  149. },
  150. // -- initializingNode -------------------------------------------------------------------------
  151. // initializingNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
  152. // childSource, childType, childIndex, childName ) {
  153. // },
  154. // -- deletingNode -------------------------------------------------------------------------
  155. deletingNode: function (nodeID) {
  156. if (this.state.nodes[nodeID] !== undefined) {
  157. var node = this.state.nodes[nodeID];
  158. if (node.aframeObj.compName !== undefined) {
  159. // removes and destroys object
  160. node.aframeObj.el.removeAttribute(node.aframeObj.compName);
  161. node.aframeObj = undefined;
  162. }
  163. delete this.state.nodes[nodeID];
  164. }
  165. },
  166. // -- initializingProperty -----------------------------------------------------------------
  167. initializingProperty: function (nodeID, propertyName, propertyValue) {
  168. var value = undefined;
  169. var node = this.state.nodes[nodeID];
  170. if (node !== undefined) {
  171. value = this.settingProperty(nodeID, propertyName, propertyValue);
  172. }
  173. return value;
  174. },
  175. // -- creatingProperty ---------------------------------------------------------------------
  176. creatingProperty: function (nodeID, propertyName, propertyValue) {
  177. return this.initializingProperty(nodeID, propertyName, propertyValue);
  178. },
  179. // -- settingProperty ----------------------------------------------------------------------
  180. settingProperty: function (nodeID, propertyName, propertyValue) {
  181. var node = this.state.nodes[nodeID];
  182. var value = undefined;
  183. if (node && node.aframeObj && utility.validObject(propertyValue)) {
  184. var aframeObject = node.aframeObj;
  185. if (isComponentNodeDefinition(node.prototypes)) {
  186. value = propertyValue;
  187. switch (propertyName) {
  188. default:
  189. value = undefined;
  190. break;
  191. }
  192. }
  193. if (value === undefined && isComponentDefinition(node.prototypes)) {
  194. value = propertyValue;
  195. switch (propertyName) {
  196. case "compName":
  197. break;
  198. default:
  199. value = undefined;
  200. break;
  201. }
  202. }
  203. if (value === undefined && isAViewOffsetCameraDefinition(node.prototypes)) {
  204. if (aframeObject.el.getAttribute(aframeObject.compName)) {
  205. value = propertyValue;
  206. let parentNodeAF = aframeObject.el;
  207. // let defs = ['fullWidth', 'fullHeight', 'xoffset', 'yoffset'];
  208. // defs.forEach(element => {
  209. // element == propertyName ? parentNodeAF.setAttribute('viewoffset', element, propertyValue) :
  210. // value = undefined;
  211. // })
  212. switch (propertyName) {
  213. case "fullWidth":
  214. parentNodeAF.setAttribute('viewoffset', 'fullWidth', propertyValue);
  215. break;
  216. case "fullHeight":
  217. parentNodeAF.setAttribute('viewoffset', 'fullHeight', propertyValue);
  218. break;
  219. case "yoffset":
  220. parentNodeAF.setAttribute('viewoffset', 'yoffset', propertyValue);
  221. break;
  222. case "xoffset":
  223. parentNodeAF.setAttribute('viewoffset', 'xoffset', propertyValue);
  224. break;
  225. case "subcamWidth":
  226. parentNodeAF.setAttribute('viewoffset', 'width', propertyValue);
  227. break;
  228. case "subcamHeight":
  229. parentNodeAF.setAttribute('viewoffset', 'height', propertyValue);
  230. break;
  231. default:
  232. value = undefined;
  233. break;
  234. }
  235. }
  236. }
  237. // if (value === undefined && isARayCasterListenerDefinition(node.prototypes)) {
  238. // if (aframeObject.el.getAttribute(aframeObject.compName)) {
  239. // value = propertyValue;
  240. // let parentNodeAF = aframeObject.el;
  241. // switch (propertyName) {
  242. // default:
  243. // value = undefined;
  244. // break;
  245. // }
  246. // }
  247. // }
  248. if (value === undefined && isAShadowDefinition(node.prototypes)) {
  249. if (aframeObject.el.getAttribute(aframeObject.compName)) {
  250. value = propertyValue;
  251. let parentNodeAF = aframeObject.el;
  252. switch (propertyName) {
  253. case "cast":
  254. parentNodeAF.setAttribute('shadow', 'cast', propertyValue);
  255. break;
  256. case "receive":
  257. parentNodeAF.setAttribute('shadow', 'receive', propertyValue);
  258. break;
  259. default:
  260. value = undefined;
  261. break;
  262. }
  263. }
  264. }
  265. if (value === undefined && isAMaterialDefinition(node.prototypes)) {
  266. if (aframeObject.el.getAttribute(aframeObject.compName)) {
  267. value = propertyValue;
  268. let parentNodeAF = aframeObject.el;
  269. //let defs = ['color', 'transparent', 'opacity', 'side'];
  270. self.aframeComponentDef['A-MATERIAL'].forEach(element => {
  271. element == propertyName ? parentNodeAF.setAttribute('material', element, propertyValue) :
  272. value = undefined;
  273. })
  274. }
  275. }
  276. if (value === undefined && isASoundDefinition(node.prototypes)) {
  277. if (aframeObject.el.getAttribute(aframeObject.compName)) {
  278. value = propertyValue;
  279. let parentNodeAF = aframeObject.el;
  280. //let defs = ['color', 'transparent', 'opacity', 'side'];
  281. self.aframeComponentDef['A-SOUND'].forEach(element => {
  282. element == propertyName ? parentNodeAF.setAttribute('sound', element, propertyValue) :
  283. value = undefined;
  284. })
  285. }
  286. }
  287. if (value === undefined && isAAabbColliderDefinition(node.prototypes)) {
  288. if (aframeObject.el.getAttribute(aframeObject.compName)) {
  289. value = propertyValue;
  290. let parentNodeAF = aframeObject.el;
  291. //let defs = ['color', 'transparent', 'opacity', 'side'];
  292. self.aframeComponentDef['aabb-collider'].forEach(element => {
  293. element == propertyName ? parentNodeAF.setAttribute('aabb-collider', element, propertyValue) :
  294. value = undefined;
  295. })
  296. }
  297. }
  298. if (value === undefined && isAFogDefinition(node.prototypes)) {
  299. if (aframeObject.el.getAttribute(aframeObject.compName)) {
  300. value = propertyValue;
  301. let parentNodeAF = aframeObject.el;
  302. let defs = ['fogType', 'fogColor', 'density', 'near', 'far'];
  303. defs.forEach(element => {
  304. if (element == propertyName) {
  305. switch (element) {
  306. case 'fogType':
  307. parentNodeAF.setAttribute('fog', 'type', propertyValue);
  308. break;
  309. case 'fogColor':
  310. parentNodeAF.setAttribute('fog', 'color', propertyValue);
  311. break;
  312. default:
  313. value = parentNodeAF.setAttribute('fog', element, propertyValue);
  314. break;
  315. }
  316. } else {
  317. value = undefined
  318. }
  319. // element == propertyName ? parentNodeAF.setAttribute('fog', element, propertyValue) :
  320. // value = undefined;
  321. })
  322. }
  323. }
  324. if (value === undefined && isARayCasterDefinition(node.prototypes)) {
  325. if (aframeObject.el.getAttribute(aframeObject.compName)) {
  326. value = propertyValue;
  327. let parentNodeAF = aframeObject.el;
  328. let defs = ['direction', 'far', 'interval', 'near', 'objects', 'origin', 'recursive', 'showLine', 'useWorldCoordinates'];
  329. defs.forEach(element => {
  330. element == propertyName ? parentNodeAF.setAttribute('raycaster', element, propertyValue) :
  331. value = undefined;
  332. })
  333. }
  334. }
  335. if (value === undefined && isALinePathDefinition(node.prototypes)) {
  336. if (aframeObject.el.getAttribute(aframeObject.compName)) {
  337. value = propertyValue;
  338. let parentNodeAF = aframeObject.el;
  339. switch (propertyName) {
  340. case "color":
  341. parentNodeAF.setAttribute(aframeObject.compName, 'color', propertyValue);
  342. break;
  343. case "path":
  344. parentNodeAF.setAttribute(aframeObject.compName, 'path', propertyValue);
  345. break;
  346. case "width":
  347. parentNodeAF.setAttribute(aframeObject.compName, 'width', propertyValue);
  348. break;
  349. default:
  350. value = undefined;
  351. break;
  352. }
  353. }
  354. }
  355. //isALineDefinition(node.prototypes)
  356. //if (value === undefined && node.componentName == 'line') { //isALineDefinition( node.prototypes )
  357. if (node.extendsID == "http://vwf.example.com/aframe/lineComponent.vwf") {
  358. if (value === undefined && aframeObject.el.getAttribute(aframeObject.compName)) {
  359. value = propertyValue;
  360. //let parentNodeAF = self.state.kernel.find(node.parentID);
  361. // aframeObject.el.setAttribute('line', 'color')
  362. let parentNodeAF = aframeObject.el;
  363. switch (propertyName) {
  364. case "start":
  365. parentNodeAF.setAttribute(aframeObject.compName, { start: propertyValue });
  366. break;
  367. case "end":
  368. parentNodeAF.setAttribute(aframeObject.compName, { end: propertyValue });
  369. break;
  370. case "color":
  371. parentNodeAF.setAttribute(aframeObject.compName, 'color', propertyValue);
  372. break;
  373. case "opacity":
  374. parentNodeAF.setAttribute(aframeObject.compName, 'opacity', propertyValue);
  375. break;
  376. case "visible":
  377. parentNodeAF.setAttribute(aframeObject.compName, 'visible', propertyValue);
  378. break;
  379. default:
  380. value = undefined;
  381. break;
  382. }
  383. }
  384. }
  385. if (value === undefined && isAAnimMixerDefinition(node.prototypes)) {
  386. if (aframeObject.el.getAttribute(aframeObject.compName)) {
  387. value = propertyValue;
  388. let parentNodeAF = aframeObject.el;
  389. switch (propertyName) {
  390. case "clip":
  391. parentNodeAF.setAttribute(aframeObject.compName, 'clip', propertyValue);
  392. break;
  393. case "duration":
  394. parentNodeAF.setAttribute(aframeObject.compName, 'duration', propertyValue);
  395. break;
  396. case "crossFadeDuration":
  397. parentNodeAF.setAttribute(aframeObject.compName, 'crossFadeDuration', propertyValue);
  398. break;
  399. case "loop":
  400. parentNodeAF.setAttribute(aframeObject.compName, 'loop', propertyValue);
  401. break;
  402. case "repetitions":
  403. parentNodeAF.setAttribute(aframeObject.compName, 'repetitions', propertyValue);
  404. break;
  405. default:
  406. value = undefined;
  407. break;
  408. }
  409. }
  410. }
  411. if (value === undefined && isAInterpolationDefinition(node.prototypes)) {
  412. if (aframeObject.el.getAttribute(aframeObject.compName)) {
  413. value = propertyValue;
  414. let parentNodeAF = aframeObject.el;
  415. switch (propertyName) {
  416. case "enabled":
  417. parentNodeAF.setAttribute(aframeObject.compName, 'enabled', propertyValue);
  418. break;
  419. case "deltaPos":
  420. parentNodeAF.setAttribute(aframeObject.compName, 'deltaPos', propertyValue);
  421. break;
  422. case "deltaRot":
  423. parentNodeAF.setAttribute(aframeObject.compName, 'deltaRot', propertyValue);
  424. break;
  425. case "deltaScale":
  426. parentNodeAF.setAttribute(aframeObject.compName, 'deltaScale', propertyValue);
  427. break;
  428. default:
  429. value = undefined;
  430. break;
  431. }
  432. }
  433. }
  434. if (value === undefined && isAGizmoDefinition(node.prototypes)) {
  435. if (aframeObject.el.getAttribute(aframeObject.compName)) {
  436. value = propertyValue;
  437. let parentNodeAF = aframeObject.el;
  438. switch (propertyName) {
  439. case "mode":
  440. parentNodeAF.setAttribute(aframeObject.compName, 'mode', propertyValue);
  441. break;
  442. default:
  443. value = undefined;
  444. break;
  445. }
  446. }
  447. }
  448. }
  449. return value;
  450. },
  451. // -- gettingProperty ----------------------------------------------------------------------
  452. gettingProperty: function (nodeID, propertyName, propertyValue) {
  453. var node = this.state.nodes[nodeID];
  454. var value = undefined;
  455. if (node && node.aframeObj) {
  456. var aframeObject = node.aframeObj;
  457. if (isComponentNodeDefinition(node.prototypes)) {
  458. switch (propertyName) {
  459. }
  460. }
  461. if (value === undefined && isComponentDefinition(node.prototypes)) {
  462. switch (propertyName) {
  463. case "compName":
  464. break;
  465. }
  466. }
  467. // isALineDefinition( node.prototypes ) aframeObject.compName == compName
  468. if (value === undefined && isARayCasterDefinition(node.prototypes)) {
  469. value = propertyValue;
  470. let parentNodeAF = aframeObject.el;
  471. let defs = ['direction', 'far', 'interval', 'near', 'objects', 'origin', 'recursive', 'showLine', 'useWorldCoordinates'];
  472. defs.forEach(element => {
  473. if (element == propertyName) {
  474. let val = parentNodeAF.getAttribute('raycaster').element;
  475. value = AFRAME.utils.coordinates.isCoordinates(val) ? AFRAME.utils.coordinates.stringify(val) : val
  476. }
  477. })
  478. }
  479. // if (value === undefined && isARayCasterListenerDefinition(node.prototypes)) {
  480. // value = propertyValue;
  481. // let parentNodeAF = aframeObject.el;
  482. // switch (propertyName) {
  483. // default:
  484. // value = undefined;
  485. // break;
  486. // }
  487. // }
  488. if (value === undefined && isAFogDefinition(node.prototypes)) {
  489. value = propertyValue;
  490. let parentNodeAF = aframeObject.el;
  491. let defs = ['fogType', 'color', 'density', 'near', 'far'];
  492. defs.forEach(element => {
  493. if (element == propertyName) {
  494. switch (element) {
  495. case 'fogType':
  496. value = parentNodeAF.getAttribute('fog').type;
  497. break;
  498. case 'fogColor':
  499. value = parentNodeAF.getAttribute('fog').color;
  500. break;
  501. default:
  502. value = parentNodeAF.getAttribute('fog').element;
  503. break;
  504. }
  505. }
  506. })
  507. }
  508. if (value === undefined && isAShadowDefinition(node.prototypes)) {
  509. value = propertyValue;
  510. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  511. let parentNodeAF = aframeObject.el;
  512. switch (propertyName) {
  513. case "cast":
  514. value = parentNodeAF.getAttribute(aframeObject.compName).cast;
  515. break;
  516. case "receive":
  517. value = parentNodeAF.getAttribute(aframeObject.compName).receive;
  518. break;
  519. }
  520. }
  521. if (value === undefined && isALineDefinition(node.prototypes)) {
  522. value = propertyValue;
  523. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  524. let parentNodeAF = aframeObject.el;
  525. switch (propertyName) {
  526. case "start":
  527. value = AFRAME.utils.coordinates.stringify(parentNodeAF.getAttribute(aframeObject.compName).start);
  528. break;
  529. case "end":
  530. value = AFRAME.utils.coordinates.stringify(parentNodeAF.getAttribute(aframeObject.compName).end);
  531. break;
  532. case "color":
  533. value = parentNodeAF.getAttribute(aframeObject.compName).color;
  534. break;
  535. case "opacity":
  536. value = parentNodeAF.getAttribute(aframeObject.compName).opacity;
  537. break;
  538. case "visible":
  539. value = parentNodeAF.getAttribute(aframeObject.compName).visible;
  540. break;
  541. }
  542. }
  543. if (value === undefined && isAAnimMixerDefinition(node.prototypes)) {
  544. value = propertyValue;
  545. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  546. let parentNodeAF = aframeObject.el;
  547. switch (propertyName) {
  548. case "clip":
  549. value = parentNodeAF.getAttribute(aframeObject.compName).clip;
  550. break;
  551. case "duration":
  552. value = parentNodeAF.getAttribute(aframeObject.compName).duration;
  553. break;
  554. case "crossFadeDuration":
  555. value = parentNodeAF.getAttribute(aframeObject.compName).crossFadeDuration;
  556. break;
  557. case "loop":
  558. value = parentNodeAF.getAttribute(aframeObject.compName).loop;
  559. break;
  560. case "repetitions":
  561. value = parentNodeAF.getAttribute(aframeObject.compName).repetitions;
  562. break;
  563. }
  564. }
  565. if (value === undefined && isAMaterialDefinition(node.prototypes)) {
  566. value = propertyValue;
  567. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  568. let parentNodeAF = aframeObject.el;
  569. self.aframeComponentDef['A-MATERIAL'].forEach(element => {
  570. if (element == propertyName) {
  571. value = parentNodeAF.getAttribute('material').element;
  572. }
  573. })
  574. }
  575. if (value === undefined && isASoundDefinition(node.prototypes)) {
  576. value = propertyValue;
  577. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  578. let parentNodeAF = aframeObject.el;
  579. self.aframeComponentDef['A-SOUND'].forEach(element => {
  580. if (element == propertyName) {
  581. value = parentNodeAF.getAttribute('sound').element;
  582. }
  583. })
  584. }
  585. if (value === undefined && isAAabbColliderDefinition(node.prototypes)) {
  586. value = propertyValue;
  587. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  588. let parentNodeAF = aframeObject.el;
  589. self.aframeComponentDef['aabb-collider'].forEach(element => {
  590. if (element == propertyName) {
  591. value = parentNodeAF.getAttribute('aabb-collider').element;
  592. }
  593. })
  594. }
  595. if (value === undefined && isALinePathDefinition(node.prototypes)) {
  596. value = propertyValue;
  597. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  598. let parentNodeAF = aframeObject.el;
  599. switch (propertyName) {
  600. case "color":
  601. value = parentNodeAF.getAttribute(aframeObject.compName).color;
  602. break;
  603. case "path":
  604. value = parentNodeAF.getAttribute(aframeObject.compName).path;
  605. break;
  606. case "width":
  607. value = parentNodeAF.getAttribute(aframeObject.compName).width;
  608. break;
  609. }
  610. }
  611. if (value === undefined && isAViewOffsetCameraDefinition(node.prototypes)) {
  612. value = propertyValue;
  613. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  614. let parentNodeAF = aframeObject.el;
  615. switch (propertyName) {
  616. case "fullWidth":
  617. value = parentNodeAF.getAttribute(aframeObject.compName).fullWidth;
  618. break;
  619. case "fullHeight":
  620. value = parentNodeAF.getAttribute(aframeObject.compName).fullHeight;
  621. break;
  622. case "subcamWidth":
  623. value = parentNodeAF.getAttribute(aframeObject.compName).width;
  624. break;
  625. case "subcamHeight":
  626. value = parentNodeAF.getAttribute(aframeObject.compName).height;
  627. break;
  628. case "xoffset":
  629. value = parentNodeAF.getAttribute(aframeObject.compName).xoffset;
  630. break;
  631. case "yoffset":
  632. value = parentNodeAF.getAttribute(aframeObject.compName).yoffset;
  633. break;
  634. }
  635. }
  636. if (value === undefined && isAInterpolationDefinition(node.prototypes)) {
  637. value = propertyValue;
  638. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  639. let parentNodeAF = aframeObject.el;
  640. switch (propertyName) {
  641. case "enabled":
  642. value = parentNodeAF.getAttribute(aframeObject.compName).enabled;
  643. break;
  644. case "deltaPos":
  645. value = parentNodeAF.getAttribute(aframeObject.compName).deltaPos;
  646. break;
  647. case "deltaRot":
  648. value = parentNodeAF.getAttribute(aframeObject.compName).deltaRot;
  649. break;
  650. case "deltaScale":
  651. value = parentNodeAF.getAttribute(aframeObject.compName).deltaScale;
  652. break;
  653. }
  654. }
  655. if (value === undefined && isAGizmoDefinition(node.prototypes)) {
  656. value = propertyValue;
  657. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  658. let parentNodeAF = aframeObject.el;
  659. switch (propertyName) {
  660. case "mode":
  661. value = parentNodeAF.getAttribute(aframeObject.compName).mode;
  662. break;
  663. }
  664. }
  665. }
  666. if (value !== undefined) {
  667. propertyValue = value;
  668. }
  669. return value;
  670. }
  671. });
  672. function getPrototypes(kernel, extendsID) {
  673. var prototypes = [];
  674. var id = extendsID;
  675. while (id !== undefined) {
  676. prototypes.push(id);
  677. id = kernel.prototype(id);
  678. }
  679. return prototypes;
  680. }
  681. function isAAnimMixerDefinition(prototypes) {
  682. var found = false;
  683. if (prototypes) {
  684. for (var i = 0; i < prototypes.length && !found; i++) {
  685. found = (prototypes[i] == "http://vwf.example.com/aframe/anim-mixer-component.vwf");
  686. }
  687. }
  688. return found;
  689. }
  690. function isAInterpolationDefinition(prototypes) {
  691. var found = false;
  692. if (prototypes) {
  693. for (var i = 0; i < prototypes.length && !found; i++) {
  694. found = (prototypes[i] == "http://vwf.example.com/aframe/interpolation-component.vwf");
  695. }
  696. }
  697. return found;
  698. }
  699. function isALinePathDefinition(prototypes) {
  700. var found = false;
  701. if (prototypes) {
  702. for (var i = 0; i < prototypes.length && !found; i++) {
  703. found = (prototypes[i] == "http://vwf.example.com/aframe/linepath.vwf");
  704. }
  705. }
  706. return found;
  707. }
  708. function isAMaterialDefinition(prototypes) {
  709. var found = false;
  710. if (prototypes) {
  711. for (var i = 0; i < prototypes.length && !found; i++) {
  712. found = (prototypes[i] == "http://vwf.example.com/aframe/aMaterialComponent.vwf");
  713. }
  714. }
  715. return found;
  716. }
  717. function isASoundDefinition(prototypes) {
  718. var found = false;
  719. if (prototypes) {
  720. for (var i = 0; i < prototypes.length && !found; i++) {
  721. found = (prototypes[i] == "http://vwf.example.com/aframe/a-sound-component.vwf");
  722. }
  723. }
  724. return found;
  725. }
  726. function isAViewOffsetCameraDefinition(prototypes) {
  727. var found = false;
  728. if (prototypes) {
  729. for (var i = 0; i < prototypes.length && !found; i++) {
  730. found = (prototypes[i] == "http://vwf.example.com/aframe/viewOffsetCamera-component.vwf");
  731. }
  732. }
  733. return found;
  734. }
  735. function isAGizmoDefinition(prototypes) {
  736. var found = false;
  737. if (prototypes) {
  738. for (var i = 0; i < prototypes.length && !found; i++) {
  739. found = (prototypes[i] == "http://vwf.example.com/aframe/gizmoComponent.vwf");
  740. }
  741. }
  742. return found;
  743. }
  744. function isAFogDefinition(prototypes) {
  745. var found = false;
  746. if (prototypes) {
  747. for (var i = 0; i < prototypes.length && !found; i++) {
  748. found = (prototypes[i] == "http://vwf.example.com/aframe/aSceneFogComponent.vwf");
  749. }
  750. }
  751. return found;
  752. }
  753. function isAShadowDefinition(prototypes) {
  754. var found = false;
  755. if (prototypes) {
  756. for (var i = 0; i < prototypes.length && !found; i++) {
  757. found = (prototypes[i] == "http://vwf.example.com/aframe/shadowComponent.vwf");
  758. }
  759. }
  760. return found;
  761. }
  762. function isAAabbColliderDefinition(prototypes) {
  763. var found = false;
  764. if (prototypes) {
  765. for (var i = 0; i < prototypes.length && !found; i++) {
  766. found = (prototypes[i] == "http://vwf.example.com/aframe/aabb-collider-component.vwf");
  767. }
  768. }
  769. return found;
  770. }
  771. function isARayCasterDefinition(prototypes) {
  772. var found = false;
  773. if (prototypes) {
  774. for (var i = 0; i < prototypes.length && !found; i++) {
  775. found = (prototypes[i] == "http://vwf.example.com/aframe/raycasterComponent.vwf");
  776. }
  777. }
  778. return found;
  779. }
  780. function isARayCasterListenerDefinition(prototypes) {
  781. var found = false;
  782. if (prototypes) {
  783. for (var i = 0; i < prototypes.length && !found; i++) {
  784. found = (prototypes[i] == "http://vwf.example.com/aframe/app-raycaster-listener-component.vwf");
  785. }
  786. }
  787. return found;
  788. }
  789. function isAAabbColliderListenerDefinition(prototypes) {
  790. var found = false;
  791. if (prototypes) {
  792. for (var i = 0; i < prototypes.length && !found; i++) {
  793. found = (prototypes[i] == "http://vwf.example.com/aframe/app-aabb-collider-listener-component.vwf");
  794. }
  795. }
  796. return found;
  797. }
  798. function isALineDefinition(prototypes) {
  799. var found = false;
  800. if (prototypes) {
  801. for (var i = 0; i < prototypes.length && !found; i++) {
  802. found = (prototypes[i] == "http://vwf.example.com/aframe/lineComponent.vwf");
  803. }
  804. }
  805. return found;
  806. }
  807. function isGearVRControlsDefinition(prototypes) {
  808. var found = false;
  809. if (prototypes) {
  810. for (var i = 0; i < prototypes.length && !found; i++) {
  811. found = (prototypes[i] == "http://vwf.example.com/aframe/gearvr-controlsComponent.vwf");
  812. }
  813. }
  814. return found;
  815. }
  816. function isComponentNodeDefinition(prototypes) {
  817. var found = false;
  818. if (prototypes) {
  819. for (var i = 0; i < prototypes.length && !found; i++) {
  820. found = (prototypes[i] == "http://vwf.example.com/aframe/componentNode.vwf");
  821. }
  822. }
  823. return found;
  824. }
  825. function isComponentDefinition(prototypes) {
  826. var found = false;
  827. if (prototypes) {
  828. for (var i = 0; i < prototypes.length && !found; i++) {
  829. found = (prototypes[i] == "http://vwf.example.com/aframe/aentityComponent.vwf");
  830. }
  831. }
  832. return found;
  833. }
  834. function setAFrameObject(node, config) {
  835. var protos = node.prototypes;
  836. var aframeObj = {};
  837. var sceneEl = document.querySelector('a-scene');
  838. aframeObj.id = node.parentID;
  839. // aframeObj.el = sceneEl.children[node.parentID];
  840. aframeObj.el = Array.from(sceneEl.querySelectorAll('*')).filter(item => { return item.id == aframeObj.id })[0];
  841. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/lineComponent.vwf")) {
  842. // aframeObj.id = node.parentID;
  843. // aframeObj.el = sceneEl.children[node.parentID];
  844. if (node.name !== 'line') {
  845. aframeObj.compName = node.name;
  846. } else {
  847. aframeObj.compName = "line";
  848. }
  849. //aframeObj.el.setAttribute(node.type, {});
  850. aframeObj.el.setAttribute(aframeObj.compName, {});
  851. }
  852. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/gizmoComponent.vwf")) {
  853. // aframeObj.el.setAttribute(node.type, {});
  854. aframeObj.compName = "gizmo";
  855. aframeObj.el.setAttribute(aframeObj.compName, {});
  856. }
  857. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/aSceneFogComponent.vwf")) {
  858. // aframeObj.el.setAttribute(node.type, {});
  859. aframeObj = {};
  860. //var sceneEl = document.querySelector('a-scene');
  861. aframeObj.id = node.parentID;
  862. aframeObj.el = document.querySelector('a-scene');
  863. aframeObj.compName = "fog";
  864. aframeObj.el.setAttribute('fog', {});
  865. }
  866. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/raycasterComponent.vwf")) {
  867. // aframeObj.el.setAttribute(node.type, {});
  868. aframeObj.compName = "raycaster";
  869. aframeObj.el.setAttribute(aframeObj.compName, {});
  870. }
  871. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/shadowComponent.vwf")) {
  872. // aframeObj.el.setAttribute(node.type, {});
  873. aframeObj.compName = "shadow";
  874. aframeObj.el.setAttribute(aframeObj.compName, {});
  875. }
  876. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/aabb-collider-component.vwf")) {
  877. // aframeObj.el.setAttribute(node.type, {});
  878. aframeObj.compName = "aabb-collider";
  879. aframeObj.el.setAttribute(aframeObj.compName, {});
  880. }
  881. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/viewOffsetCamera-component.vwf")) {
  882. // aframeObj.el.setAttribute(node.type, {});
  883. aframeObj.compName = "viewoffset";
  884. aframeObj.el.setAttribute(aframeObj.compName, {});
  885. }
  886. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/streamSoundComponent.vwf")) {
  887. // aframeObj.el.setAttribute(node.type, {});
  888. aframeObj.compName = "streamsound";
  889. aframeObj.el.setAttribute(aframeObj.compName, {});
  890. }
  891. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/linepath.vwf")) {
  892. // aframeObj.el.setAttribute(node.type, {});
  893. aframeObj.compName = "linepath";
  894. aframeObj.el.setAttribute(aframeObj.compName, {});
  895. }
  896. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/aMaterialComponent.vwf")) {
  897. // aframeObj.el.setAttribute(node.type, {});
  898. aframeObj.compName = "material";
  899. aframeObj.el.setAttribute(aframeObj.compName, {});
  900. }
  901. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/a-sound-component.vwf")) {
  902. // aframeObj.el.setAttribute(node.type, {});
  903. aframeObj.compName = "sound";
  904. aframeObj.el.setAttribute(aframeObj.compName, {});
  905. }
  906. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/interpolation-component.vwf")) {
  907. // aframeObj.el.setAttribute(node.type, {});
  908. aframeObj.compName = "interpolation";
  909. aframeObj.el.setAttribute(aframeObj.compName, {});
  910. }
  911. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/anim-mixer-component.vwf")) {
  912. // aframeObj.el.setAttribute(node.type, {});
  913. aframeObj.compName = "animation-mixer";
  914. aframeObj.el.setAttribute(aframeObj.compName, {});
  915. }
  916. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/app-envmap-component.vwf")) {
  917. // aframeObj.el.setAttribute(node.type, {});
  918. aframeObj.compName = "envmap";
  919. aframeObj.el.setAttribute(aframeObj.compName, {});
  920. }
  921. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/app-avatarbvh-component.vwf")) {
  922. // aframeObj.el.setAttribute(node.type, {});
  923. aframeObj.compName = "avatarbvh";
  924. aframeObj.el.setAttribute(aframeObj.compName, {});
  925. }
  926. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/app-sun-component.vwf")) {
  927. // aframeObj.el.setAttribute(node.type, {});
  928. aframeObj.compName = "sun";
  929. aframeObj.el.setAttribute('id', "sun");
  930. aframeObj.el.setAttribute(aframeObj.compName, {});
  931. }
  932. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/app-skyshader-component.vwf")) {
  933. // aframeObj.el.setAttribute(node.type, {});
  934. aframeObj.compName = "skyshader";
  935. aframeObj.el.setAttribute(aframeObj.compName, {});
  936. }
  937. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/app-raycaster-listener-component.vwf")) {
  938. // aframeObj.el.setAttribute(node.type, {});
  939. aframeObj.compName = "raycaster-listener";
  940. aframeObj.el.setAttribute(aframeObj.compName, {});
  941. }
  942. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/app-aabb-collider-listener-component.vwf")) {
  943. // aframeObj.el.setAttribute(node.type, {});
  944. aframeObj.compName = "aabb-collider-listener";
  945. aframeObj.el.setAttribute(aframeObj.compName, {});
  946. }
  947. if (self.state.isComponentClass(protos, "http://vwf.example.com/aframe/app-cursor-listener-component.vwf")) {
  948. // aframeObj.el.setAttribute(node.type, {});
  949. aframeObj.compName = "cursor-listener";
  950. aframeObj.el.setAttribute(aframeObj.compName, {});
  951. }
  952. return aframeObj;
  953. }
  954. function addNodeToHierarchy(node) {
  955. if (node.aframeObj) {
  956. if (self.state.nodes[node.parentID] !== undefined) {
  957. var parent = self.state.nodes[node.parentID];
  958. if (parent.aframeObj) {
  959. if (parent.children === undefined) {
  960. parent.children = [];
  961. }
  962. parent.children.push(node.ID);
  963. }
  964. }
  965. }
  966. }
  967. });