aframeComponent.js 65 KB

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