-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.js
64 lines (56 loc) · 1.75 KB
/
models.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {
LoadingManager,
SphereGeometry,
MeshPhongMaterial,
Mesh,
} from "three";
import { GLTFLoader } from "three/loaders/GLTFLoader.js";
import { MTLLoader } from "three/loaders/MTLLoader.js";
import { OBJLoader } from "three/loaders/OBJLoader.js";
export function loadModels() {
const objLoader = createObjloader("models/Materials_Modular_Terrain.mtl");
return Promise.all([
loadGltf("models/character_mage.gltf").then(({ scene }) => scene),
objLoader
.loadObj("models/Hilly_Terrain_Water_Flat.obj")
.then((waterTile) => {
waterTile.position.y = -0.7;
return waterTile;
}),
objLoader
.loadObj("models/Hilly_Terrain_Grass_Floor.obj")
.then((grassTile) => {
grassTile.position.y = -0.2;
return grassTile;
}),
]).then(([mage, grassTile, waterTile]) => ({ mage, grassTile, waterTile }));
}
export function loadGltf(path) {
return new Promise((resolve, reject) => {
const loader = new GLTFLoader();
loader.load(path, resolve, undefined, reject);
});
}
export function createObjloader(materialPath) {
const manager = new LoadingManager();
const materialsPromise = new Promise((resolve, reject) => {
new MTLLoader(manager).load(materialPath, resolve, undefined, reject);
});
return {
loadObj(path) {
return materialsPromise.then(
(materials) =>
new Promise((resolve, reject) => {
new OBJLoader(manager)
.setMaterials(materials)
.load(path, resolve, undefined, reject);
}),
);
},
};
}
export function createFireSpellModel() {
const geometry = new SphereGeometry(0.3, 32, 16);
const material = new MeshPhongMaterial({ color: 0xc00000 });
return new Mesh(geometry, material);
}