Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*jshint esversion: 6 */
- // @ts-check
- // these four lines fake out TypeScript into thinking that THREE
- // has the same type as the T.js module, so things work for type checking
- // type inferencing figures out that THREE has the same type as T
- // and then I have to use T (not THREE) to avoid the "UMD Module" warning
- /** @type typeof import("./THREE/threets/index"); */
- let T;
- // @ts-ignore
- T = THREE;
- // get things we may need
- import { GrWorld } from "./Framework/GrWorld.js";
- import { GrObject } from "./Framework/GrObject.js";
- import * as InputHelpers from "./Libs/inputHelpers.js";
- import * as Helpers from "./Libs/helpers.js";
- class DiceObject extends GrObject {
- constructor() {
- let geometry = new T.Geometry();
- //all triangles + size
- geometry.vertices.push(new T.Vector3( .8,.8,0));
- geometry.vertices.push(new T.Vector3( .8,0, 0));
- geometry.vertices.push(new T.Vector3( 0,.8, 0));
- geometry.vertices.push(new T.Vector3( 0,0,0));
- geometry.vertices.push(new T.Vector3( 0,.8,.8));
- geometry.vertices.push(new T.Vector3( 0,0,.8));
- geometry.vertices.push(new T.Vector3( .8,.8,.8));
- geometry.vertices.push(new T.Vector3( .8,0,.8));
- let face1 = new T.Face3(0,1,2);
- geometry.faceVertexUvs = [ [] ];
- geometry.faces.push(face1);
- geometry.faceVertexUvs[0].push([new T.Vector2((1/3),(1/3)), new T.Vector2((1/3),0), new T.Vector2((2/3),(1/3))]);
- let face2 = new T.Face3(2,1,3);
- geometry.faces.push(face2);
- geometry.faceVertexUvs[0].push([new T.Vector2((2/3),(1/3)), new T.Vector2((1/3),0), new T.Vector2(.66,0)]);
- let face3 = new T.Face3(2,3,4);
- geometry.faces.push(face3);
- geometry.faceVertexUvs[0].push([new T.Vector2(.66,(1/3)), new T.Vector2(.66,0), new T.Vector2(1,.33)]);
- let face4 = new T.Face3(4,3,5);
- geometry.faces.push(face4);
- geometry.faceVertexUvs[0].push([new T.Vector2(1,.33), new T.Vector2(.66,0), new T.Vector2(1,0)]);
- let face5 = new T.Face3(4,5,6);
- geometry.faces.push(face5);
- geometry.faceVertexUvs[0].push([new T.Vector2(0,(2/3)), new T.Vector2(0,.33), new T.Vector2(.33,.66)]);
- let face6 = new T.Face3(6,5,7);
- geometry.faces.push(face6);
- geometry.faceVertexUvs[0].push([new T.Vector2(.33,(2/3)), new T.Vector2(0,.33), new T.Vector2(.33,.33)]);
- let face7 = new T.Face3(6,7,0);
- geometry.faces.push(face7);
- geometry.faceVertexUvs[0].push([new T.Vector2(.33,.66), new T.Vector2(.33,.33), new T.Vector2(.66,.66)]);
- let face8 = new T.Face3(0,7,1);
- geometry.faces.push(face8);
- geometry.faceVertexUvs[0].push([new T.Vector2(.66,.66), new T.Vector2(.33,.33), new T.Vector2(.66,.33)]);
- let face9 = new T.Face3(0,2,6);
- geometry.faces.push(face9);
- geometry.faceVertexUvs[0].push([new T.Vector2(.66,.66), new T.Vector2(.66,.33), new T.Vector2(1,.66)]);
- let face10 = new T.Face3(6,2,4);
- geometry.faces.push(face10);
- geometry.faceVertexUvs[0].push([new T.Vector2(1,.66), new T.Vector2(.66,.33), new T.Vector2(1,.33)]);
- let face11 = new T.Face3(1,7,3);
- geometry.faces.push(face11);
- geometry.faceVertexUvs[0].push([new T.Vector2(.33,1), new T.Vector2(.66,1), new T.Vector2(.33,.66)]);
- let face12 = new T.Face3(3, 7, 5);
- geometry.faces.push(face12);
- geometry.faceVertexUvs[0].push([new T.Vector2(.33,.66), new T.Vector2(.66,1), new T.Vector2(.66,.66)]);
- geometry.computeFaceNormals(); geometry.uvsNeedUpdate=true;
- let tempL;
- var loader = new T.CubeTextureLoader();
- loader.setPath( './Textures' );
- var textureCube = loader.load( [
- 'dice_texture.png',
- 'dice_texture.png',
- 'dice_texture.png',
- 'dice_texture.png',
- 'dice_texture.png',
- 'dice_texture.png'
- ] );
- var mat = new T.MeshBasicMaterial( { color: 0xffffff, envMap: textureCube } );
- // let dice =new T.TextureLoader().load("./Texture/dice_texture.png");
- let mesh = new T.Mesh(geometry,mat);
- super("Dice1",mesh);
- }
- }
- function test() {
- let world = new GrWorld();
- let dice = new DiceObject();
- world.add(dice);
- world.scene.background = new T.CubeTextureLoader()
- .setPath("./Texture/")
- .load( [
- 'dice_texture.png',
- 'dice_texture.png',
- 'dice_texture.png',
- 'dice_texture.png',
- 'dice_texture.png',
- 'dice_texture.png'
- ]);
- world.go();
- var directionalLight = new T.DirectionalLight( "white", 2 );
- world.scene.add( directionalLight );
- function animate()
- {
- // move in a circle
- let theta = performance.now() / 1000;
- let x = 2 * Math.cos(theta);
- let z = 2 * Math.sin(theta);
- directionalLight.position.x = x;
- directionalLight.position.z = z;
- requestAnimationFrame(animate);
- }
- animate();
- }
- Helpers.onWindowOnload(test);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement