aframeComponent.js 43 KB

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