Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.58 KB | None | 0 0
  1. /*jshint esversion: 6 */
  2. // @ts-check
  3.  
  4. // these four lines fake out TypeScript into thinking that THREE
  5. // has the same type as the T.js module, so things work for type checking
  6. // type inferencing figures out that THREE has the same type as T
  7. // and then I have to use T (not THREE) to avoid the "UMD Module" warning
  8. /** @type typeof import("./THREE/threets/index"); */
  9. let T;
  10. // @ts-ignore
  11. T = THREE;
  12.  
  13. // get things we may need
  14. import { GrWorld } from "./Framework/GrWorld.js";
  15. import { GrObject } from "./Framework/GrObject.js";
  16. import * as InputHelpers from "./Libs/inputHelpers.js";
  17. import * as Helpers from "./Libs/helpers.js";
  18.  
  19. class CubeNObject extends GrObject {
  20. constructor() {
  21. let geometry = new T.Geometry();
  22. geometry.vertices.push(new T.Vector3(1,1,0)); //0
  23. geometry.vertices.push(new T.Vector3( 1,0, 0)); //1
  24. geometry.vertices.push(new T.Vector3( 0,1, 0)); //2
  25. geometry.vertices.push(new T.Vector3( 0,0,0)); //3
  26. geometry.vertices.push(new T.Vector3( 0,1,1)); //4
  27. geometry.vertices.push(new T.Vector3( 0,0,1)); //5
  28. geometry.vertices.push(new T.Vector3( 1,1,1)); //6
  29. geometry.vertices.push(new T.Vector3( 1,0,1)); //7
  30. //
  31. let f1 = new T.Face3(0,1,2);
  32. geometry.faceVertexUvs = [ [] ];
  33. geometry.faces.push(f1);
  34. geometry.faceVertexUvs[0].push([new T.Vector2(0.333,0.333), new T.Vector2(0.333,0), new T.Vector2(0.666,0.333)]);
  35. let f2 = new T.Face3(2,1,3);
  36. geometry.faces.push(f2);
  37. geometry.faceVertexUvs[0].push([new T.Vector2(0.666,0.333), new T.Vector2(0.333,0), new T.Vector2(.666,0)]);
  38. let f3 = new T.Face3(2,3,4);
  39. geometry.faces.push(f3);
  40. geometry.faceVertexUvs[0].push([new T.Vector2(.666,0.333), new T.Vector2(.666,0), new T.Vector2(1,.333)]);
  41. let f4 = new T.Face3(4,3,5);
  42. geometry.faces.push(f4);
  43. geometry.faceVertexUvs[0].push([new T.Vector2(1,.333), new T.Vector2(.666,0), new T.Vector2(1,0)]);
  44. let f5 = new T.Face3(4,5,6);
  45. geometry.faces.push(f5);
  46. geometry.faceVertexUvs[0].push([new T.Vector2(0,0.666), new T.Vector2(0,.333), new T.Vector2(.333,.666)]);
  47. let f6 = new T.Face3(6,5,7);
  48. geometry.faces.push(f6);
  49. geometry.faceVertexUvs[0].push([new T.Vector2(.333,0.666), new T.Vector2(0,.333), new T.Vector2(.333,.333)]);
  50. let f7 = new T.Face3(6,7,0);
  51. geometry.faces.push(f7);
  52. geometry.faceVertexUvs[0].push([new T.Vector2(.333,.666), new T.Vector2(.333,.333), new T.Vector2(.666,.666)]);
  53. let f8 = new T.Face3(0,7,1);
  54. geometry.faces.push(f8);
  55. geometry.faceVertexUvs[0].push([new T.Vector2(.666,.666), new T.Vector2(.333,.333), new T.Vector2(.666,.333)]);
  56. let f9 = new T.Face3(0,2,6);
  57. geometry.faces.push(f9);
  58. geometry.faceVertexUvs[0].push([new T.Vector2(.666,.666), new T.Vector2(.666,.333), new T.Vector2(1,.666)]);
  59. let f10 = new T.Face3(6,2,4);
  60. geometry.faces.push(f10);
  61. geometry.faceVertexUvs[0].push([new T.Vector2(1,0.666), new T.Vector2(.666,.333), new T.Vector2(1,.333)]);
  62. let f11 = new T.Face3(1,7,3);
  63. geometry.faces.push(f11);
  64. geometry.faceVertexUvs[0].push([new T.Vector2(.333,1), new T.Vector2(.666,1), new T.Vector2(.333,.666)]);
  65. let f12 = new T.Face3(3,7,5);
  66. geometry.faces.push(f12);
  67. geometry.faceVertexUvs[0].push([new T.Vector2(.333,.666), new T.Vector2(.666,1), new T.Vector2(.666,.666)]);
  68. geometry.computeFaceNormals();
  69. geometry.uvsNeedUpdate=true;
  70. //
  71. let tl1 = new T.TextureLoader().load("./Texture/brick-1.jpg");
  72. let tl=new T.TextureLoader().load("./Texture/brick.jpg");
  73. let material = new T.MeshStandardMaterial({map:tl1, roughness:0.75});
  74. material.normalMap = tl;
  75. let mesh = new T.Mesh(geometry,material);
  76.  
  77. super("Cube",mesh);
  78. }
  79. }
  80.  
  81. class CubeObject extends GrObject {
  82. constructor() {
  83. let geometry = new T.Geometry();
  84. geometry.vertices.push(new T.Vector3(1,1,0)); //0
  85. geometry.vertices.push(new T.Vector3( 1,0, 0)); //1
  86. geometry.vertices.push(new T.Vector3( 0,1, 0)); //2
  87. geometry.vertices.push(new T.Vector3( 0,0,0)); //3
  88. geometry.vertices.push(new T.Vector3( 0,1,1)); //4
  89. geometry.vertices.push(new T.Vector3( 0,0,1)); //5
  90. geometry.vertices.push(new T.Vector3( 1,1,1)); //6
  91. geometry.vertices.push(new T.Vector3( 1,0,1)); //7
  92. //
  93. let f1 = new T.Face3(0,1,2);
  94. geometry.faceVertexUvs = [ [] ];
  95. geometry.faces.push(f1);
  96. geometry.faceVertexUvs[0].push([new T.Vector2(0.333,0.333), new T.Vector2(0.333,0), new T.Vector2(0.666,0.333)]);
  97. let f2 = new T.Face3(2,1,3);
  98. geometry.faces.push(f2);
  99. geometry.faceVertexUvs[0].push([new T.Vector2(0.666,0.333), new T.Vector2(0.333,0), new T.Vector2(.666,0)]);
  100. let f3 = new T.Face3(2,3,4);
  101. geometry.faces.push(f3);
  102. geometry.faceVertexUvs[0].push([new T.Vector2(.666,0.333), new T.Vector2(.666,0), new T.Vector2(1,.333)]);
  103. let f4 = new T.Face3(4,3,5);
  104. geometry.faces.push(f4);
  105. geometry.faceVertexUvs[0].push([new T.Vector2(1,.333), new T.Vector2(.666,0), new T.Vector2(1,0)]);
  106. let f5 = new T.Face3(4,5,6);
  107. geometry.faces.push(f5);
  108. geometry.faceVertexUvs[0].push([new T.Vector2(0,0.666), new T.Vector2(0,.333), new T.Vector2(.333,.666)]);
  109. let f6 = new T.Face3(6,5,7);
  110. geometry.faces.push(f6);
  111. geometry.faceVertexUvs[0].push([new T.Vector2(.333,0.666), new T.Vector2(0,.333), new T.Vector2(.333,.333)]);
  112. let f7 = new T.Face3(6,7,0);
  113. geometry.faces.push(f7);
  114. geometry.faceVertexUvs[0].push([new T.Vector2(.333,.666), new T.Vector2(.333,.333), new T.Vector2(.666,.666)]);
  115. let f8 = new T.Face3(0,7,1);
  116. geometry.faces.push(f8);
  117. geometry.faceVertexUvs[0].push([new T.Vector2(.666,.666), new T.Vector2(.333,.333), new T.Vector2(.666,.333)]);
  118. let f9 = new T.Face3(0,2,6);
  119. geometry.faces.push(f9);
  120. geometry.faceVertexUvs[0].push([new T.Vector2(.666,.666), new T.Vector2(.666,.333), new T.Vector2(1,.666)]);
  121. let f10 = new T.Face3(6,2,4);
  122. geometry.faces.push(f10);
  123. geometry.faceVertexUvs[0].push([new T.Vector2(1,0.666), new T.Vector2(.666,.333), new T.Vector2(1,.333)]);
  124. let f11 = new T.Face3(1,7,3);
  125. geometry.faces.push(f11);
  126. geometry.faceVertexUvs[0].push([new T.Vector2(.333,1), new T.Vector2(.666,1), new T.Vector2(.333,.666)]);
  127. let f12 = new T.Face3(3,7,5);
  128. geometry.faces.push(f12);
  129. geometry.faceVertexUvs[0].push([new T.Vector2(.333,.666), new T.Vector2(.666,1), new T.Vector2(.666,.666)]);
  130. geometry.computeFaceNormals();
  131. geometry.uvsNeedUpdate=true;
  132. //
  133. let tl1 = new T.TextureLoader().load("./Texture/brick-1.jpg");
  134. let tl=new T.TextureLoader().load("./Texture/brick-2.jpg");
  135. let material = new T.MeshStandardMaterial({map:tl1, roughness:0.75});
  136. material.normalMap = tl;
  137. let mesh = new T.Mesh(geometry,material);
  138.  
  139. super("Cube",mesh);
  140. }
  141. }
  142.  
  143. function shift(grobj,x, boolRotate) {
  144. if(boolRotate) {
  145. grobj.objects[0].translateY(Math.sqrt(2)/2 +.3);
  146. grobj.objects[0].rotation.x = Math.PI/2;
  147.  
  148. }
  149. //grobj.objects[0].rotatateZ(Math.PI/2);
  150. //grobj.objects[0].translateY(2);
  151. grobj.objects[0].translateX(x);
  152. return grobj;
  153. }
  154.  
  155. function test() {
  156. let world = new GrWorld();
  157. let t2 = shift(new CubeNObject(), 0, 0);
  158. world.add(t2);
  159. let t3 = shift(new CubeObject(), -2, 0);
  160. world.add(t3);
  161. world.go();
  162. }
  163. Helpers.onWindowOnload(test);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement