aframeComponent.js 44 KB

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