forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup.js
More file actions
88 lines (87 loc) · 3.22 KB
/
Setup.js
File metadata and controls
88 lines (87 loc) · 3.22 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
import * as THREE from "three";
import TWEEN from "@tweenjs/tween.js";
import Stats from "stats-js";
import * as dat from "dat.gui";
import io from "socket.io-client";
import { DistanceBasedFog } from "./DistanceBasedFog.js";
import { UrlParams } from "./UrlParams.js";
import { gpuInfo } from "./gpuInfo.js";
import { World } from "./World/World.js";
import { InventoryBar } from "./InventoryBar.js";
import { Chat } from "./Chat.js";
import { Entities } from "./Entities.js";
import { PlayerInInventory } from "./PlayerInInventory.js";
import { BlockBreak } from "./BlockBreak.js";
import { BlockPlace } from "./BlockPlace.js";
import { EventHandler } from "./EventHandler.js";
function Setup(game, cb) {
game.canvas = document.querySelector("#c");
game.pcanvas = document.querySelector("#c_player");
game.renderer = new THREE.WebGLRenderer({
canvas: game.canvas,
PixelRatio: window.devicePixelRatio,
});
game.renderer.sortObjects = true;
game.scene = new THREE.Scene();
game.camera = new THREE.PerspectiveCamera(game.fov.normal, 2, 0.1, 1000);
game.camera.rotation.order = "YXZ";
game.camera.position.set(26, 26, 26);
game.scene.add(new THREE.AmbientLight(0xffffff));
game.stats = new Stats();
game.drawcalls = game.stats.addPanel(
new Stats.Panel("calls", "#ff8", "#221")
);
game.stats.showPanel(0);
document.body.appendChild(game.stats.dom);
game.distanceBasedFog = new DistanceBasedFog(game);
UrlParams(game, (password) => {
console.warn(gpuInfo());
game.socket = io({
query: {
nick: game.nick,
server: game.server,
port: game.serverPort,
password,
premium: game.premium,
},
});
game.pii = new PlayerInInventory(game);
game.bb = new BlockBreak(game);
game.bp = new BlockPlace(game);
game.world = new World(game);
game.ent = new Entities(game);
game.chat = new Chat(game);
game.inv_bar = new InventoryBar(game);
game.eh = new EventHandler(game);
game.distanceBasedFog.addShaderToMaterial(game.world.material);
var gui = new dat.GUI();
game.params = {
chunkdist: 3,
};
game.distanceBasedFog.farnear.x = (game.params.chunkdist - 1) * 16;
game.distanceBasedFog.farnear.y = game.params.chunkdist * 16;
gui.add(game.world.material, "wireframe").name("Wireframe").listen();
var chunkDist = gui
.add(game.params, "chunkdist", 0, 10, 1)
.name("Render distance")
.listen();
chunkDist.onChange(function (val) {
game.distanceBasedFog.farnear.x = (val - 1) * 16;
game.distanceBasedFog.farnear.y = val * 16;
console.log(val);
});
game.playerImpulse = function () {
var to = {
x: game.playerPos[0],
y: game.playerPos[1] + game.headHeight,
z: game.playerPos[2],
};
new TWEEN.Tween(game.camera.position)
.to(to, 100)
.easing(TWEEN.Easing.Quadratic.Out)
.start();
};
cb();
});
}
export { Setup };