|
@@ -1,6 +1,6 @@
|
1
|
1
|
import * as THREE from "three"
|
2
|
2
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
|
3
|
|
-import { Object3D, Mesh, ShaderMaterial, IcosahedronGeometry, TextureLoader, MeshStandardMaterial, Scene, HemisphereLight, Color, DirectionalLight, Vector3 } from "three";
|
|
3
|
+import { Object3D, Mesh, ShaderMaterial, IcosahedronGeometry, TextureLoader, MeshStandardMaterial, Scene, HemisphereLight, Color, DirectionalLight, Vector3, AmbientLight, PlaneBufferGeometry, MeshPhongMaterial } from "three";
|
4
|
4
|
|
5
|
5
|
import { GameController } from "./controller"
|
6
|
6
|
import { VaringBox } from "./shader_test"
|
|
@@ -27,13 +27,15 @@ export class FooGame {
|
27
|
27
|
constructor() {
|
28
|
28
|
this.camera = new THREE.PerspectiveCamera(this.cam_fov, this.cam_aspect, 1, 1000)
|
29
|
29
|
this.camera.position.x = -1;
|
30
|
|
- this.camera.position.y = 1;
|
|
30
|
+ this.camera.position.y = 2;
|
31
|
31
|
this.camera.position.z = 1;
|
32
|
32
|
|
33
|
33
|
this.scene = new THREE.Scene();
|
34
|
34
|
|
35
|
|
- this.light = new DirectionalLight(new Color(0XFFFFFF), 0.4);
|
|
35
|
+ this.light = new HemisphereLight(new Color(0XFFFFFF), new Color(0x000000), 1);
|
36
|
36
|
this.light.position.set(0, 15, 0);
|
|
37
|
+
|
|
38
|
+ this.scene.add(new AmbientLight(new Color(0xffffff), 1));
|
37
|
39
|
this.scene.add(this.light);
|
38
|
40
|
this.renderer = new THREE.WebGLRenderer();
|
39
|
41
|
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
|
@@ -103,9 +105,11 @@ export class FooGame {
|
103
|
105
|
*/
|
104
|
106
|
loadScene(callback: Function) {
|
105
|
107
|
|
106
|
|
- this.gltfLoader.load("./scenes/foo.gltf", gltf => {
|
|
108
|
+ this.gltfLoader.load("./scenes/campus/Unity2GLTF.gltf", gltf => {
|
|
109
|
+ console.log(gltf);
|
|
110
|
+
|
107
|
111
|
this.scene.add(gltf.scene);
|
108
|
|
- //this.scene.background = new THREE.Color(0xffffff);
|
|
112
|
+ this.scene.background = new THREE.Color('rgb(191,196,234)');
|
109
|
113
|
|
110
|
114
|
callback();
|
111
|
115
|
});
|
|
@@ -115,12 +119,22 @@ export class FooGame {
|
115
|
119
|
let game = new FooGame();
|
116
|
120
|
|
117
|
121
|
game.loadScene(() => {
|
118
|
|
-
|
119
|
|
- let mat = GameUtils.makeRandomObjects(game.scene, 500);
|
|
122
|
+
|
|
123
|
+ /*let mat = GameUtils.makeRandomObjects(game.scene, 500);
|
120
|
124
|
FooGame.setUpdate(game.scene, (obj: Object3D) => {
|
121
|
125
|
mat.uniforms.time.value = performance.now() / 500;
|
122
|
126
|
});
|
|
127
|
+*/
|
123
|
128
|
|
|
129
|
+ let geoGround = new PlaneBufferGeometry(200, 200, 100, 200);
|
|
130
|
+ let matGround = new MeshPhongMaterial({
|
|
131
|
+ color: "rgb(50,50,50)"
|
|
132
|
+ });
|
|
133
|
+
|
|
134
|
+ let ground = new Mesh(geoGround, matGround);
|
|
135
|
+ ground.rotation.x = -Math.PI / 2;
|
|
136
|
+ ground.position.y = -2;
|
|
137
|
+ game.scene.add(ground);
|
124
|
138
|
game.camera.lookAt(new THREE.Vector3(0, 0, 0));
|
125
|
139
|
|
126
|
140
|
|
|
@@ -128,17 +142,12 @@ game.loadScene(() => {
|
128
|
142
|
* 设置天空盒子
|
129
|
143
|
*/
|
130
|
144
|
let skybox = game.findObjectByName("Sphere");
|
131
|
|
- if(skybox instanceof Mesh){
|
132
|
|
- let mesh:Mesh = skybox;
|
133
|
|
- if(mesh.material instanceof MeshStandardMaterial){
|
134
|
|
- let mat:MeshStandardMaterial = mesh.material;
|
|
145
|
+ if (skybox instanceof Mesh) {
|
|
146
|
+ let mesh: Mesh = skybox;
|
|
147
|
+ if (mesh.material instanceof MeshStandardMaterial) {
|
|
148
|
+ let mat: MeshStandardMaterial = mesh.material;
|
135
|
149
|
mat.side = THREE.BackSide;
|
136
|
150
|
}
|
137
|
151
|
}
|
138
|
|
-
|
139
|
|
- console.log(game.camera.matrix);
|
140
|
|
- console.log(new Vector3().setFromMatrixPosition(game.camera.matrix));
|
141
|
|
- console.log(new Vector3().setFromMatrixColumn(game.camera.matrix, 0));
|
142
|
|
-
|
143
|
152
|
})
|
144
|
153
|
|