generated from InventivetalentDev/minerender-demo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
82 lines (67 loc) · 1.99 KB
/
index.ts
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
import {Renderer, SceneInspector, SkinObject, Skins, OrbitControls} from "minerender";
import {Intersection, Vector3} from "three";
console.log("hi");
const renderer = new Renderer({
camera: {
near: 1,
far: 2000,
position: [-50, 40, -50],
lookingAt: [0, 10, 0]
},
render: {
stats: true,
fpsLimit: 60,
antialias: false,
renderAlways: true
},
composer: {
enabled: false
},
debug: {
grid: false,
axes: true
}
});
// document.body.appendChild(renderer.renderer.domElement);
window["renderer"] = renderer;
renderer.appendTo(document.body);
const sceneInspector = new SceneInspector(renderer);
sceneInspector.appendTo(document.getElementById('inspector'));
let skinObject: SkinObject;
renderer.scene.addSkin().then(skinObject_ => {
skinObject = skinObject_;
window["skin"] = skinObject_;
setSkin("inventivetalent");
// dummy intersection
const intersection: Intersection = {
object: skinObject_,
distance: 0,
point: new Vector3(),
instanceId: skinObject_.isInstanced ? skinObject_.instanceCounter : undefined
}
sceneInspector.selectObject(skinObject_, intersection)
});
function setSkin(skin: string) {
console.log("setting skin to", skin);
if (skin.startsWith("http")) {
skinObject.setSkinTexture(skin)
} else {
Skins.fromUuidOrUsername(skin).then(skin => {
console.log(skin);
if (typeof skin !== "undefined") {
skinObject.setSkinTexture(skin)
}
})
}
}
window["setSkin"] = setSkin;
const skinInput = document.getElementById("skin-input") as HTMLInputElement;
skinInput.addEventListener("change", () => {
setSkin(skinInput.value);
})
const controls = new OrbitControls(renderer.camera, renderer.renderer.domElement);
controls.target.setY(10);
renderer.registerEventDispatcher(controls);
controls.update();
//TODO: autostart option, maybe
renderer.start();