aframeComponent.js 64 KB

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