SHARE
TWEET

Untitled

a guest Apr 21st, 2019 70 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 DiceObject extends GrObject {
  20.     constructor() {
  21.        
  22.         let geometry = new T.Geometry();
  23.        
  24.         //all triangles + size
  25.         geometry.vertices.push(new T.Vector3( .8,.8,0));
  26.         geometry.vertices.push(new T.Vector3( .8,0, 0));
  27.        
  28.         geometry.vertices.push(new T.Vector3( 0,.8, 0));
  29.         geometry.vertices.push(new T.Vector3( 0,0,0));
  30.        
  31.         geometry.vertices.push(new T.Vector3( 0,.8,.8));
  32.         geometry.vertices.push(new T.Vector3( 0,0,.8));
  33.        
  34.         geometry.vertices.push(new T.Vector3( .8,.8,.8));
  35.         geometry.vertices.push(new T.Vector3( .8,0,.8));
  36.        
  37.         let face1 = new T.Face3(0,1,2);
  38.         geometry.faceVertexUvs = [ [] ];
  39.         geometry.faces.push(face1);
  40.         geometry.faceVertexUvs[0].push([new T.Vector2((1/3),(1/3)), new T.Vector2((1/3),0), new T.Vector2((2/3),(1/3))]);
  41.         let face2 = new T.Face3(2,1,3);
  42.         geometry.faces.push(face2);
  43.         geometry.faceVertexUvs[0].push([new T.Vector2((2/3),(1/3)), new T.Vector2((1/3),0), new T.Vector2(.66,0)]);
  44.         let face3 = new T.Face3(2,3,4);
  45.         geometry.faces.push(face3);
  46.         geometry.faceVertexUvs[0].push([new T.Vector2(.66,(1/3)), new T.Vector2(.66,0), new T.Vector2(1,.33)]);
  47.         let face4 = new T.Face3(4,3,5);
  48.         geometry.faces.push(face4);
  49.         geometry.faceVertexUvs[0].push([new T.Vector2(1,.33), new T.Vector2(.66,0), new T.Vector2(1,0)]);
  50.         let face5 = new T.Face3(4,5,6);
  51.         geometry.faces.push(face5);
  52.         geometry.faceVertexUvs[0].push([new T.Vector2(0,(2/3)), new T.Vector2(0,.33), new T.Vector2(.33,.66)]);
  53.         let face6 = new T.Face3(6,5,7);
  54.         geometry.faces.push(face6);
  55.         geometry.faceVertexUvs[0].push([new T.Vector2(.33,(2/3)), new T.Vector2(0,.33), new T.Vector2(.33,.33)]);
  56.         let face7 = new T.Face3(6,7,0);
  57.         geometry.faces.push(face7);
  58.         geometry.faceVertexUvs[0].push([new T.Vector2(.33,.66), new T.Vector2(.33,.33), new T.Vector2(.66,.66)]);
  59.         let face8 = new T.Face3(0,7,1);
  60.         geometry.faces.push(face8);
  61.         geometry.faceVertexUvs[0].push([new T.Vector2(.66,.66), new T.Vector2(.33,.33), new T.Vector2(.66,.33)]);
  62.         let face9 = new T.Face3(0,2,6);
  63.         geometry.faces.push(face9);
  64.         geometry.faceVertexUvs[0].push([new T.Vector2(.66,.66), new T.Vector2(.66,.33), new T.Vector2(1,.66)]);
  65.         let face10 = new T.Face3(6,2,4);
  66.         geometry.faces.push(face10);
  67.         geometry.faceVertexUvs[0].push([new T.Vector2(1,.66), new T.Vector2(.66,.33), new T.Vector2(1,.33)]);
  68.         let face11 = new T.Face3(1,7,3);
  69.         geometry.faces.push(face11);
  70.         geometry.faceVertexUvs[0].push([new T.Vector2(.33,1), new T.Vector2(.66,1), new T.Vector2(.33,.66)]);
  71.         let face12 = new T.Face3(3, 7, 5);
  72.         geometry.faces.push(face12);
  73.         geometry.faceVertexUvs[0].push([new T.Vector2(.33,.66), new T.Vector2(.66,1), new T.Vector2(.66,.66)]);
  74.         geometry.computeFaceNormals(); geometry.uvsNeedUpdate=true;
  75.        
  76.         let tempL;
  77.  
  78.  
  79.  
  80.         var loader = new T.CubeTextureLoader();
  81.         loader.setPath( './Textures' );
  82.         var textureCube = loader.load( [
  83.             'dice_texture.png',
  84.         'dice_texture.png',
  85.         'dice_texture.png',
  86.         'dice_texture.png',
  87.         'dice_texture.png',
  88.         'dice_texture.png'
  89.         ] );
  90.  
  91.         var mat = new T.MeshBasicMaterial( { color: 0xffffff, envMap: textureCube } );
  92.      
  93. //        let dice =new T.TextureLoader().load("./Texture/dice_texture.png");
  94.         let mesh = new T.Mesh(geometry,mat);
  95.         super("Dice1",mesh);
  96.     }
  97. }
  98.  
  99.  
  100. function test() {
  101.  
  102.     let world = new GrWorld();
  103.  
  104.     let dice = new DiceObject();
  105.     world.add(dice);
  106.  
  107.     world.scene.background = new T.CubeTextureLoader()
  108.     .setPath("./Texture/")
  109.     .load( [
  110.         'dice_texture.png',
  111.         'dice_texture.png',
  112.         'dice_texture.png',
  113.         'dice_texture.png',
  114.         'dice_texture.png',
  115.         'dice_texture.png'
  116.        
  117.     ]);
  118.  
  119.     world.go();
  120.  
  121.  
  122.     var directionalLight = new T.DirectionalLight( "white", 2 );
  123.     world.scene.add( directionalLight );
  124.  
  125.     function animate()
  126.     {
  127.         // move in a circle
  128.         let theta = performance.now() / 1000;
  129.         let x = 2 * Math.cos(theta);
  130.         let z = 2 * Math.sin(theta);
  131.         directionalLight.position.x = x;
  132.         directionalLight.position.z = z;
  133.         requestAnimationFrame(animate);
  134.     }
  135.     animate();
  136. }
  137. 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