aframeComponent.js 50 KB

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