rubik.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. this.initialize = function () {
  2. //console.log(vwf_view.doc.cube.calc());
  3. // if(Object.getPrototypeOf(this).id.includes('ascene.vwf')){
  4. // debugger;
  5. // console.log("Initialize of Scene...", this.id);
  6. // let rubikID = "rubik-" + this.randomHash();
  7. // this.createRubik(rubikID);
  8. // } else {
  9. // console.log("Initialize proto Scene..", this.id);
  10. // }
  11. }
  12. this.createRubik = function (id, robot) {
  13. this.currentCube = id;
  14. let cubeContainer = {
  15. "extends": "proxy/aframe/aentity.vwf",
  16. "properties": {
  17. "displayName": 'container-' + id,
  18. "target": id,
  19. "position": [0,2.7,-7.5]
  20. },
  21. "methods":{
  22. "setupGUI":{
  23. "body": `
  24. this.gui.noRobotButton.init();
  25. this.gui.editCubeButton.init();
  26. this.gui.currentCubeButton.init();
  27. `,
  28. "type": "application/javascript"
  29. }
  30. },
  31. "children": {
  32. "gui": {
  33. "extends": "proxy/aframe/aentity.vwf",
  34. "properties": {
  35. "position": [3,0,0]
  36. },
  37. "children": {
  38. "noRobotButton":{
  39. "extends": "proxy/objects/gui/button.vwf",
  40. "properties": {
  41. "target": id,
  42. "displayName": "noRobotButton",
  43. "position": [-6, -1, 1],
  44. "clickColor": "blue",
  45. "baseColor": "red",
  46. "height": 0.5,
  47. "width": 0.6
  48. }
  49. },
  50. "editCubeButton":{
  51. "extends": "proxy/objects/gui/button.vwf",
  52. "properties": {
  53. "target": id,
  54. "displayName": "editCubeButton",
  55. "position": [-6, 0, 1],
  56. "clickColor": "blue",
  57. "baseColor": "green",
  58. "height": 0.5,
  59. "width": 0.6
  60. }
  61. },
  62. "currentCubeButton":{
  63. "extends": "proxy/objects/gui/button.vwf",
  64. "properties": {
  65. "target": id,
  66. "displayName": "currentCubeButton",
  67. "position": [-6, 1, 1],
  68. "clickColor": "blue",
  69. "baseColor": "white",
  70. "height": 0.8,
  71. "width": 0.8
  72. }
  73. }
  74. // "material": {
  75. // "extends": "proxy/aframe/aMaterialComponent.vwf",
  76. // "type": "component",
  77. // "properties": {
  78. // "color": "white",
  79. // "transparent": true,
  80. // "opacity": 0.5
  81. // }
  82. // }
  83. }
  84. }
  85. }
  86. }
  87. let cube = {
  88. "extends": "cubeModel.vwf",
  89. "properties": {
  90. "cubeID": id,
  91. "displayName": id,
  92. "rotation": [35, -35, 0],
  93. "twistQueue": [],
  94. "twistQueueHistory": []
  95. },
  96. "children": {
  97. "cubelets": {
  98. "extends": "proxy/aframe/aentity.vwf"
  99. },
  100. "gui": {
  101. "extends": "proxy/aframe/aentity.vwf"
  102. },
  103. "interpolation":
  104. {
  105. "extends": "proxy/aframe/interpolation-component.vwf",
  106. "type": "component",
  107. "properties": {
  108. "enabled": true
  109. }
  110. }
  111. }
  112. }
  113. this.children.create('container-' + id, cubeContainer,function (box){
  114. box.children.create(id, cube, function (child) {
  115. child.initializeCubelets();
  116. child.addGUI();
  117. if(robot){
  118. child.robotID = 'robot-' + id;
  119. }
  120. box.setupGUI();
  121. });
  122. // let frame3D = {
  123. // "extends": "proxy/objects/gui/frame3D.vwf",
  124. // "properties": {
  125. // "contentsID": id,
  126. // "position": [0, -2.5, 3]
  127. // }
  128. // }
  129. // box.children.create(id + '-frame3D', frame3D)
  130. } )
  131. if (robot) {
  132. let nodeName = 'robot-' + id;
  133. let cube = {
  134. "extends": "robot.vwf",
  135. "properties": {
  136. "cubeID": id,
  137. "position": [0,0.5,-3],
  138. "visible": false
  139. }
  140. }
  141. this.children.create(nodeName, cube, function (child) {
  142. child.initRobot();
  143. });
  144. }
  145. }
  146. this.doOnRubik = function(command){
  147. let rubik = this.findNode(this.currentCube);
  148. rubik.do(command);
  149. }