SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 CubeObject 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("./Textures/pengy.png");
  72.         let tl=new T.TextureLoader().load("./Texture/pengy.png");
  73.         let material = new T.MeshStandardMaterial({map:tl1, roughness:0.75});
  74.         material.bumpMap = tl;
  75.         let mesh = new T.Mesh(geometry,material);
  76.  
  77.         super("Cube",mesh);
  78.     }
  79. }
  80.  
  81. function shift(grobj,x, boolRotate) {
  82.     if(boolRotate) {
  83.         grobj.objects[0].translateY(Math.sqrt(2)/2 +.3);
  84.         grobj.objects[0].rotation.x = Math.PI/2;
  85.        
  86.     }
  87.     grobj.objects[0].translateX(x);
  88.     return grobj;
  89. }
  90.  
  91. function spinY(obj, speed=1) {
  92.     obj.advance = function(delta,timeOfDay) {
  93.         obj.objects.forEach(obj => obj.rotateY(speed*delta/1000*Math.PI));
  94.     };
  95.     return obj;
  96. }
  97.  
  98. function test() {
  99.     let world = new GrWorld();
  100.     world.go();
  101.     let cube = shift(new CubeObject(), 0, 0);
  102.     world.add(cube);
  103.     spinY(cube)
  104.     setupButtons();
  105.    
  106.     let scene = new T.Scene();
  107.     let wid = 700;
  108.     let ht  = 500;
  109.     let main_camera = new T.PerspectiveCamera(45, wid/ht, 0.1, 2000);
  110.     main_camera.position.set(0, 4, 6);
  111.     main_camera.rotation.set(-0.5, 0, 0);
  112.     let active_camera = main_camera;
  113.     let gpSize = 10;
  114.     let lookfrom = new T.Vector3(gpSize/2,gpSize,gpSize*2);
  115.     this.camera.position.copy(lookfrom);
  116.    
  117.  
  118.     let camera_1 = new T.PerspectiveCamera(60, 700/500, 1, 100);
  119.     camera_1.position.set(0,0,0);
  120.     camera_1.rotation.set(-1, 0, 0);
  121.    
  122.     // world.add(camera_1)
  123.  
  124.     function animate()
  125.     {
  126.         world.renderer.render(scene, active_camera);
  127.         requestAnimationFrame(animate);
  128.     }
  129.     animate()
  130.  
  131.     function setupButtons()
  132.     {
  133.         document.getElementById("main_cam").onclick = function()
  134.         {
  135.             active_camera = main_camera;
  136.             world.renderer.render(world.scene, active_camera);
  137.         };
  138.         document.getElementById("cam_1").onclick = function()
  139.         {
  140.             active_camera = camera_1;
  141.             world.renderer.render(world.scene, active_camera);
  142.         };
  143.     }
  144. }
  145. Helpers.onWindowOnload(test);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top