aframeComponent.js 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554
  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. // -- callingMethod ------------------------------------------------------------------------
  783. callingMethod: function (nodeID, methodName, methodParameters) {
  784. let self = this;
  785. var node = this.state.nodes[nodeID];
  786. if (!node) return;
  787. if (node && node.aframeObj) {
  788. let aframeObject = node.aframeObj;
  789. let parentNodeAF = aframeObject.el;
  790. if(methodName == "getIntersectionPoint") {
  791. //let nodes = vwf.models["/drivers/model/aframe"].model.state.nodes;
  792. let comp = parentNodeAF.components['raycaster'];
  793. let objID = methodParameters[0];
  794. if (comp.intersectedEls.length>0){
  795. //console.log(comp.intersectedEls);
  796. let intersecedObj = comp.intersectedEls[0]; //objID ? nodes[objID] : nodes[comp.intersectedEls[0].id];
  797. let intersection = comp.getIntersection(intersecedObj);
  798. if(intersection)
  799. return intersection.point
  800. }
  801. return undefined
  802. }
  803. }
  804. },
  805. // -- gettingProperty ----------------------------------------------------------------------
  806. gettingProperty: function (nodeID, propertyName, propertyValue) {
  807. let self = this;
  808. var node = this.state.nodes[nodeID];
  809. var value = undefined;
  810. if (node && node.aframeObj) {
  811. var aframeObject = node.aframeObj;
  812. if (self.state.isComponentNodeDefinition(node.prototypes)) {
  813. switch (propertyName) {
  814. }
  815. }
  816. if (value === undefined && self.state.isComponentDefinition(node.prototypes)) {
  817. switch (propertyName) {
  818. case "compName":
  819. break;
  820. }
  821. }
  822. // isALineDefinition( node.prototypes ) aframeObject.compName == compName
  823. if (value === undefined && self.state.isARayCasterDefinition(node.prototypes)) {
  824. value = propertyValue;
  825. let parentNodeAF = aframeObject.el;
  826. let defs = ['direction', 'far', 'interval', 'near', 'objects', 'origin', 'recursive', 'showLine', 'useWorldCoordinates'];
  827. let el = defs.includes(propertyName);
  828. value = el ? parentNodeAF.getAttribute('raycaster')[propertyName] : undefined;
  829. // defs.forEach(element => {
  830. // if (element == propertyName) {
  831. // let val = parentNodeAF.getAttribute('raycaster').element;
  832. // value = AFRAME.utils.coordinates.isCoordinates(val) ? AFRAME.utils.coordinates.stringify(val) : val
  833. // }
  834. // })
  835. }
  836. // if (value === undefined && isARayCasterListenerDefinition(node.prototypes)) {
  837. // value = propertyValue;
  838. // let parentNodeAF = aframeObject.el;
  839. // switch (propertyName) {
  840. // default:
  841. // value = undefined;
  842. // break;
  843. // }
  844. // }
  845. if (value === undefined && self.state.isAFogDefinition(node.prototypes)) {
  846. value = propertyValue;
  847. let parentNodeAF = aframeObject.el;
  848. let defs = ['fogType', 'color', 'density', 'near', 'far'];
  849. defs.forEach(element => {
  850. if (element == propertyName) {
  851. switch (element) {
  852. case 'fogType':
  853. value = parentNodeAF.getAttribute('fog').type;
  854. break;
  855. case 'fogColor':
  856. value = parentNodeAF.getAttribute('fog').color;
  857. break;
  858. default:
  859. value = parentNodeAF.getAttribute('fog').element;
  860. break;
  861. }
  862. }
  863. })
  864. }
  865. if (value === undefined && self.state.isAAabbColliderListenerDefinition(node.prototypes)) {
  866. let parentNodeAF = aframeObject.el;
  867. if(propertyName == "dynamic"){
  868. let attr = parentNodeAF.getAttribute('data-aabb-collider-dynamic');
  869. value = attr ? true : false
  870. }
  871. }
  872. if (value === undefined && self.state.isAShadowDefinition(node.prototypes)) {
  873. value = propertyValue;
  874. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  875. let parentNodeAF = aframeObject.el;
  876. switch (propertyName) {
  877. case "cast":
  878. value = parentNodeAF.getAttribute(aframeObject.compName).cast;
  879. break;
  880. case "receive":
  881. value = parentNodeAF.getAttribute(aframeObject.compName).receive;
  882. break;
  883. }
  884. }
  885. if (value === undefined && self.state.isALineDefinition(node.prototypes)) {
  886. value = propertyValue;
  887. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  888. let parentNodeAF = aframeObject.el;
  889. switch (propertyName) {
  890. case "start":
  891. value = AFRAME.utils.coordinates.stringify(parentNodeAF.getAttribute(aframeObject.compName).start);
  892. break;
  893. case "end":
  894. value = AFRAME.utils.coordinates.stringify(parentNodeAF.getAttribute(aframeObject.compName).end);
  895. break;
  896. case "color":
  897. value = parentNodeAF.getAttribute(aframeObject.compName).color;
  898. break;
  899. case "opacity":
  900. value = parentNodeAF.getAttribute(aframeObject.compName).opacity;
  901. break;
  902. case "visible":
  903. value = parentNodeAF.getAttribute(aframeObject.compName).visible;
  904. break;
  905. }
  906. }
  907. if (value === undefined && self.state.isAAnimMixerDefinition(node.prototypes)) {
  908. value = propertyValue;
  909. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  910. let parentNodeAF = aframeObject.el;
  911. switch (propertyName) {
  912. case "clip":
  913. value = parentNodeAF.getAttribute(aframeObject.compName).clip;
  914. break;
  915. case "duration":
  916. value = parentNodeAF.getAttribute(aframeObject.compName).duration;
  917. break;
  918. case "crossFadeDuration":
  919. value = parentNodeAF.getAttribute(aframeObject.compName).crossFadeDuration;
  920. break;
  921. case "loop":
  922. value = parentNodeAF.getAttribute(aframeObject.compName).loop;
  923. break;
  924. case "repetitions":
  925. value = parentNodeAF.getAttribute(aframeObject.compName).repetitions;
  926. break;
  927. }
  928. }
  929. //A-Frame material
  930. if (value === undefined && self.state.isAMaterialDefinition(node.prototypes)) {
  931. value = propertyValue;
  932. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  933. let parentNodeAF = aframeObject.el;
  934. let schema = Object.keys(AFRAME.components.material.schema).concat(Object.keys(AFRAME.shaders.standard.schema));
  935. let el = schema.includes(propertyName);
  936. value = el ? parentNodeAF.getAttribute('material')[propertyName] : undefined;
  937. switch (propertyName) {
  938. case "src":
  939. value = value !== "" ? ('#' + value.getAttribute('id')) : value;
  940. break;
  941. }
  942. }
  943. if (value === undefined && self.state.isASoundDefinition(node.prototypes)) {
  944. value = propertyValue;
  945. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  946. let parentNodeAF = aframeObject.el;
  947. let el = self.aframeComponentDef['A-SOUND'].includes(propertyName);
  948. value = el ? parentNodeAF.getAttribute('sound')[propertyName] : undefined;
  949. // self.aframeComponentDef['A-SOUND'].forEach(element => {
  950. // if (element == propertyName) {
  951. // value = parentNodeAF.getAttribute('sound').element;
  952. // }
  953. // })
  954. }
  955. if (value === undefined && self.state.isAMirrorDefinition(node.prototypes)) {
  956. value = propertyValue;
  957. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  958. let parentNodeAF = aframeObject.el;
  959. let el = self.aframeComponentDef['mirror'].includes(propertyName);
  960. value = el ? parentNodeAF.getAttribute('mirror')[propertyName] : undefined;
  961. // self.aframeComponentDef['mirror'].forEach(element => {
  962. // if (element == propertyName) {
  963. // value = parentNodeAF.getAttribute('mirror').element;
  964. // }
  965. // })
  966. }
  967. if (value === undefined && self.state.isAAabbColliderDefinition(node.prototypes)) {
  968. value = propertyValue;
  969. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  970. let parentNodeAF = aframeObject.el;
  971. let el = self.aframeComponentDef['aabb-collider'].includes(propertyName);
  972. value = el ? parentNodeAF.getAttribute('aabb-collider')[propertyName] : undefined;
  973. // self.aframeComponentDef['aabb-collider'].forEach(element => {
  974. // if (element == propertyName) {
  975. // value = parentNodeAF.getAttribute('aabb-collider').element;
  976. // }
  977. // })
  978. }
  979. if (value === undefined && self.state.isALinePathDefinition(node.prototypes)) {
  980. value = propertyValue;
  981. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  982. let parentNodeAF = aframeObject.el;
  983. switch (propertyName) {
  984. case "color":
  985. value = parentNodeAF.getAttribute(aframeObject.compName).color;
  986. break;
  987. case "path":
  988. value = parentNodeAF.getAttribute(aframeObject.compName).path;
  989. break;
  990. case "width":
  991. value = parentNodeAF.getAttribute(aframeObject.compName).width;
  992. break;
  993. case "taper":
  994. value = parentNodeAF.getAttribute(aframeObject.compName).taper;
  995. break;
  996. case "transparent":
  997. value = parentNodeAF.getAttribute(aframeObject.compName).transparent;
  998. break;
  999. case "opacity":
  1000. value = parentNodeAF.getAttribute(aframeObject.compName).opacity;
  1001. break;
  1002. }
  1003. }
  1004. if (value === undefined && self.state.isAViewOffsetCameraDefinition(node.prototypes)) {
  1005. value = propertyValue;
  1006. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  1007. let parentNodeAF = aframeObject.el;
  1008. switch (propertyName) {
  1009. case "fullWidth":
  1010. value = parentNodeAF.getAttribute(aframeObject.compName).fullWidth;
  1011. break;
  1012. case "fullHeight":
  1013. value = parentNodeAF.getAttribute(aframeObject.compName).fullHeight;
  1014. break;
  1015. case "subcamWidth":
  1016. value = parentNodeAF.getAttribute(aframeObject.compName).width;
  1017. break;
  1018. case "subcamHeight":
  1019. value = parentNodeAF.getAttribute(aframeObject.compName).height;
  1020. break;
  1021. case "xoffset":
  1022. value = parentNodeAF.getAttribute(aframeObject.compName).xoffset;
  1023. break;
  1024. case "yoffset":
  1025. value = parentNodeAF.getAttribute(aframeObject.compName).yoffset;
  1026. break;
  1027. }
  1028. }
  1029. if (value === undefined && self.state.isAInterpolationDefinition(node.prototypes)) {
  1030. value = propertyValue;
  1031. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  1032. let parentNodeAF = aframeObject.el;
  1033. switch (propertyName) {
  1034. case "enabled":
  1035. value = parentNodeAF.getAttribute(aframeObject.compName).enabled;
  1036. break;
  1037. case "deltaPos":
  1038. value = parentNodeAF.getAttribute(aframeObject.compName).deltaPos;
  1039. break;
  1040. case "deltaRot":
  1041. value = parentNodeAF.getAttribute(aframeObject.compName).deltaRot;
  1042. break;
  1043. case "deltaScale":
  1044. value = parentNodeAF.getAttribute(aframeObject.compName).deltaScale;
  1045. break;
  1046. }
  1047. }
  1048. if (value === undefined && self.state.isAGizmoDefinition(node.prototypes)) {
  1049. value = propertyValue;
  1050. // let parentNodeAF = self.state.nodes[node.parentID].aframeObj;
  1051. let parentNodeAF = aframeObject.el;
  1052. switch (propertyName) {
  1053. case "mode":
  1054. value = parentNodeAF.getAttribute(aframeObject.compName).mode;
  1055. break;
  1056. }
  1057. }
  1058. }
  1059. if (value !== undefined) {
  1060. propertyValue = value;
  1061. }
  1062. return value;
  1063. }
  1064. });
  1065. }
  1066. }
  1067. export {
  1068. AFrameComponentModel as default
  1069. }