-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathoverlay.ts
More file actions
101 lines (87 loc) · 2.34 KB
/
overlay.ts
File metadata and controls
101 lines (87 loc) · 2.34 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import * as THREE from 'three';
import { get3DOrbitCamera } from '../editor/areas/model/utils/orbitCamera';
import Renderer from '../../renderer';
import AnimState from '../../model/anim/AnimState';
import { loadModel } from '../../model';
import { loadInventoryModel } from '../../model/inventory';
const envInfo = {
skyColor: [0, 0, 0]
};
const ambience = {
lightingAlpha: 309,
lightingBeta: 2500
};
const createOverlayScene = (rval = -1) => {
const camera = get3DOrbitCamera(0.3, rval);
const scene = {
camera,
threeScene: new THREE.Scene()
};
scene.threeScene.add(camera.controlNode);
return scene;
};
const createOverlayClock = () => {
return new THREE.Clock(false);
};
const createOverlayCanvas = (className: string) => {
const canvas = document.createElement('canvas');
canvas.tabIndex = 0;
canvas.className = className;
return canvas;
};
const createOverlayRenderer = (canvas: any, type: string) => {
return new Renderer(canvas, type, { alpha: true });
};
const loadSceneModel = async (sce, b, bodyIndex, anims) => {
const m = await loadModel(
b,
bodyIndex,
0,
anims,
envInfo,
ambience
);
if (sce &&
sce.threeScene &&
sce.threeScene.children &&
sce.threeScene.children.length > 1) {
sce.threeScene.remove(sce.threeScene.children[1]);
}
sce.threeScene.add(m.mesh);
return m;
};
const loadSceneInventoryModel = async (sce, invId) => {
const m = await loadInventoryModel(
{},
invId,
envInfo,
ambience
);
if (sce &&
sce.threeScene &&
sce.threeScene.children &&
sce.threeScene.children.length > 1) {
sce.threeScene.remove(sce.threeScene.children[1]);
}
sce.threeScene.add(m.mesh);
return m;
};
const updateAnimModel = (m, animState: AnimState, entityIdx, animIdx, time) => {
animState.update(time, entityIdx, animIdx);
const q = new THREE.Quaternion();
const angle = animState.rotation.y * time.delta;
q.setFromAxisAngle(
new THREE.Vector3(0, 1, 0),
angle
);
m.mesh.quaternion.multiply(q);
};
export {
createOverlayScene,
createOverlayClock,
createOverlayCanvas,
createOverlayRenderer,
loadSceneModel,
updateAnimModel,
loadSceneInventoryModel,
};