-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
85 lines (72 loc) · 2.47 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
83
84
85
import { AssetKey, BlockStates, Entities, Models, OrbitControls, Renderer, SceneInspector, SceneObject, Skins, toRadians } from "minerender";
import { Euler, Object3D, Vector3 } from "three";
const renderContainer = document.getElementById('render-container') as HTMLDivElement;
const inspectorContainer = document.getElementById('inspector-container') as HTMLDivElement;
// create renderer and append it to the DOM
const renderer = new Renderer({
camera: {
near: 1,
far: 2000,
perspective: {
fov: 50
}
},
render: {
stats: true,
fpsLimit: 60,
antialias: false,
renderAlways: true
},
composer: {
enabled: false,
},
debug: {
grid: false,
axes: false
}
});
renderer.appendTo(renderContainer);
// create controls & register events
const controls = new OrbitControls(renderer.camera, renderer.renderer.domElement);
renderer.registerEventDispatcher(controls);
controls.update();
const inspector = new SceneInspector(renderer);
inspector.appendTo(inspectorContainer);
// start the renderer!
renderer.start();
// add some things to the scene
Skins.fromUuidOrUsername("inventivetalent")
.then(skinUrl => renderer.scene.addSkin(skinUrl, {
wireframe: true
}))
.then(skinObject => {
skinObject.setPosition(toBlockPos(0, .5, 0));
const leftArm = skinObject.getGroupByName('leftArm') as Object3D;
leftArm.rotateX(toRadians(170));
leftArm.rotateZ(toRadians(330))
const rightArm = skinObject.getGroupByName('rightArm') as Object3D;
rightArm.rotateX(toRadians(60));
});
for (let x = -1; x < 2; x++) {
for (let z = -1; z < 2; z++) {
BlockStates.get(AssetKey.parse("blockstates", Math.random() > 0.4 ? "stone" : "granite"))
.then(blockState => renderer.scene.addBlock(blockState!, {
wireframe: true,
instanceMeshes: true
}))
.then(blockObject => {
blockObject.setPosition(toBlockPos(x, 0, z));
});
}
}
Models.get(AssetKey.parse("models", "item/diamond_sword"))
.then(model => renderer.scene.addModel(model!, {
wireframe: true,
}))
.then(modelObject => {
modelObject.setPosition(new Vector3(6, 33, -11));
modelObject.setRotation(new Euler(toRadians(14), toRadians(90), 0));
})
function toBlockPos(x: number, y: number, z: number) {
return new Vector3(x, y, z).multiplyScalar(16);
}