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 CubeNObject extends GrObject {
- constructor() {
- let geometry = new T.Geometry();
- geometry.vertices.push(new T.Vector3(1,1,0)); //0
- geometry.vertices.push(new T.Vector3( 1,0, 0)); //1
- geometry.vertices.push(new T.Vector3( 0,1, 0)); //2
- geometry.vertices.push(new T.Vector3( 0,0,0)); //3
- geometry.vertices.push(new T.Vector3( 0,1,1)); //4
- geometry.vertices.push(new T.Vector3( 0,0,1)); //5
- geometry.vertices.push(new T.Vector3( 1,1,1)); //6
- geometry.vertices.push(new T.Vector3( 1,0,1)); //7
- //
- let f1 = new T.Face3(0,1,2);
- geometry.faceVertexUvs = [ [] ];
- geometry.faces.push(f1);
- geometry.faceVertexUvs[0].push([new T.Vector2(0.333,0.333), new T.Vector2(0.333,0), new T.Vector2(0.666,0.333)]);
- let f2 = new T.Face3(2,1,3);
- geometry.faces.push(f2);
- geometry.faceVertexUvs[0].push([new T.Vector2(0.666,0.333), new T.Vector2(0.333,0), new T.Vector2(.666,0)]);
- let f3 = new T.Face3(2,3,4);
- geometry.faces.push(f3);
- geometry.faceVertexUvs[0].push([new T.Vector2(.666,0.333), new T.Vector2(.666,0), new T.Vector2(1,.333)]);
- let f4 = new T.Face3(4,3,5);
- geometry.faces.push(f4);
- geometry.faceVertexUvs[0].push([new T.Vector2(1,.333), new T.Vector2(.666,0), new T.Vector2(1,0)]);
- let f5 = new T.Face3(4,5,6);
- geometry.faces.push(f5);
- geometry.faceVertexUvs[0].push([new T.Vector2(0,0.666), new T.Vector2(0,.333), new T.Vector2(.333,.666)]);
- let f6 = new T.Face3(6,5,7);
- geometry.faces.push(f6);
- geometry.faceVertexUvs[0].push([new T.Vector2(.333,0.666), new T.Vector2(0,.333), new T.Vector2(.333,.333)]);
- let f7 = new T.Face3(6,7,0);
- geometry.faces.push(f7);
- geometry.faceVertexUvs[0].push([new T.Vector2(.333,.666), new T.Vector2(.333,.333), new T.Vector2(.666,.666)]);
- let f8 = new T.Face3(0,7,1);
- geometry.faces.push(f8);
- geometry.faceVertexUvs[0].push([new T.Vector2(.666,.666), new T.Vector2(.333,.333), new T.Vector2(.666,.333)]);
- let f9 = new T.Face3(0,2,6);
- geometry.faces.push(f9);
- geometry.faceVertexUvs[0].push([new T.Vector2(.666,.666), new T.Vector2(.666,.333), new T.Vector2(1,.666)]);
- let f10 = new T.Face3(6,2,4);
- geometry.faces.push(f10);
- geometry.faceVertexUvs[0].push([new T.Vector2(1,0.666), new T.Vector2(.666,.333), new T.Vector2(1,.333)]);
- let f11 = new T.Face3(1,7,3);
- geometry.faces.push(f11);
- geometry.faceVertexUvs[0].push([new T.Vector2(.333,1), new T.Vector2(.666,1), new T.Vector2(.333,.666)]);
- let f12 = new T.Face3(3,7,5);
- geometry.faces.push(f12);
- geometry.faceVertexUvs[0].push([new T.Vector2(.333,.666), new T.Vector2(.666,1), new T.Vector2(.666,.666)]);
- geometry.computeFaceNormals();
- geometry.uvsNeedUpdate=true;
- //
- let tl1 = new T.TextureLoader().load("./Texture/brick-1.jpg");
- let tl=new T.TextureLoader().load("./Texture/brick.jpg");
- let material = new T.MeshStandardMaterial({map:tl1, roughness:0.75});
- material.normalMap = tl;
- let mesh = new T.Mesh(geometry,material);
- super("Cube",mesh);
- }
- }
- class CubeObject extends GrObject {
- constructor() {
- let geometry = new T.Geometry();
- geometry.vertices.push(new T.Vector3(1,1,0)); //0
- geometry.vertices.push(new T.Vector3( 1,0, 0)); //1
- geometry.vertices.push(new T.Vector3( 0,1, 0)); //2
- geometry.vertices.push(new T.Vector3( 0,0,0)); //3
- geometry.vertices.push(new T.Vector3( 0,1,1)); //4
- geometry.vertices.push(new T.Vector3( 0,0,1)); //5
- geometry.vertices.push(new T.Vector3( 1,1,1)); //6
- geometry.vertices.push(new T.Vector3( 1,0,1)); //7
- //
- let f1 = new T.Face3(0,1,2);
- geometry.faceVertexUvs = [ [] ];
- geometry.faces.push(f1);
- geometry.faceVertexUvs[0].push([new T.Vector2(0.333,0.333), new T.Vector2(0.333,0), new T.Vector2(0.666,0.333)]);
- let f2 = new T.Face3(2,1,3);
- geometry.faces.push(f2);
- geometry.faceVertexUvs[0].push([new T.Vector2(0.666,0.333), new T.Vector2(0.333,0), new T.Vector2(.666,0)]);
- let f3 = new T.Face3(2,3,4);
- geometry.faces.push(f3);
- geometry.faceVertexUvs[0].push([new T.Vector2(.666,0.333), new T.Vector2(.666,0), new T.Vector2(1,.333)]);
- let f4 = new T.Face3(4,3,5);
- geometry.faces.push(f4);
- geometry.faceVertexUvs[0].push([new T.Vector2(1,.333), new T.Vector2(.666,0), new T.Vector2(1,0)]);
- let f5 = new T.Face3(4,5,6);
- geometry.faces.push(f5);
- geometry.faceVertexUvs[0].push([new T.Vector2(0,0.666), new T.Vector2(0,.333), new T.Vector2(.333,.666)]);
- let f6 = new T.Face3(6,5,7);
- geometry.faces.push(f6);
- geometry.faceVertexUvs[0].push([new T.Vector2(.333,0.666), new T.Vector2(0,.333), new T.Vector2(.333,.333)]);
- let f7 = new T.Face3(6,7,0);
- geometry.faces.push(f7);
- geometry.faceVertexUvs[0].push([new T.Vector2(.333,.666), new T.Vector2(.333,.333), new T.Vector2(.666,.666)]);
- let f8 = new T.Face3(0,7,1);
- geometry.faces.push(f8);
- geometry.faceVertexUvs[0].push([new T.Vector2(.666,.666), new T.Vector2(.333,.333), new T.Vector2(.666,.333)]);
- let f9 = new T.Face3(0,2,6);
- geometry.faces.push(f9);
- geometry.faceVertexUvs[0].push([new T.Vector2(.666,.666), new T.Vector2(.666,.333), new T.Vector2(1,.666)]);
- let f10 = new T.Face3(6,2,4);
- geometry.faces.push(f10);
- geometry.faceVertexUvs[0].push([new T.Vector2(1,0.666), new T.Vector2(.666,.333), new T.Vector2(1,.333)]);
- let f11 = new T.Face3(1,7,3);
- geometry.faces.push(f11);
- geometry.faceVertexUvs[0].push([new T.Vector2(.333,1), new T.Vector2(.666,1), new T.Vector2(.333,.666)]);
- let f12 = new T.Face3(3,7,5);
- geometry.faces.push(f12);
- geometry.faceVertexUvs[0].push([new T.Vector2(.333,.666), new T.Vector2(.666,1), new T.Vector2(.666,.666)]);
- geometry.computeFaceNormals();
- geometry.uvsNeedUpdate=true;
- //
- let tl1 = new T.TextureLoader().load("./Texture/brick-1.jpg");
- let tl=new T.TextureLoader().load("./Texture/brick-2.jpg");
- let material = new T.MeshStandardMaterial({map:tl1, roughness:0.75});
- material.normalMap = tl;
- let mesh = new T.Mesh(geometry,material);
- super("Cube",mesh);
- }
- }
- function shift(grobj,x, boolRotate) {
- if(boolRotate) {
- grobj.objects[0].translateY(Math.sqrt(2)/2 +.3);
- grobj.objects[0].rotation.x = Math.PI/2;
- }
- //grobj.objects[0].rotatateZ(Math.PI/2);
- //grobj.objects[0].translateY(2);
- grobj.objects[0].translateX(x);
- return grobj;
- }
- function test() {
- let world = new GrWorld();
- let t2 = shift(new CubeNObject(), 0, 0);
- world.add(t2);
- let t3 = shift(new CubeObject(), -2, 0);
- world.add(t3);
- world.go();
- }
- Helpers.onWindowOnload(test);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement