-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
164 lines (133 loc) · 4.53 KB
/
app.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* Core Modules */
import { System } from '/src/core/system.js';
import { Scene } from '/src/core/scene.js';
import { Renderer } from '/src/core/renderer.js';
import { Camera } from '/src/core/camera.js';
import { Object } from '/src/core/object.js';
import { Loader } from '/src/core/loader.js';
import { Time } from '/src/time/time.js';
import { Performance } from '/src/time/performance.js';
import { Mouse } from '/src/input/mouse.js';
import { Keyboard } from '/src/input/keyboard.js';
import { Network } from '/src/network/network.js';
/* Editor Modules */
import { Manager } from '/editor/system/manager.js';
import { Handler } from '/editor/system/handler.js';
import { Dnd } from '/editor/system/dnd.js';
import { Hierarchy } from '/editor/windows/hierarchy.js';
import { Properties } from '/editor/windows/properties.js';
import { Project } from '/editor/windows/project.js';
import { Editor } from '/editor/scripting/editor.js'
import { Toolbar } from '/editor/windows/toolbar.js';
import { Graph } from '/editor/blueprint/graph.js';
import { Grid } from '/editor/misc/grid.js';
import { Ruler } from '/editor/misc/ruler.js';
import { Stats } from '/editor/misc/stats.js';
/* Editor Miscellaneous */
import '/editor/misc/tabs.js';
import '/editor/misc/tree.js';
import '/editor/misc/dropdown.js';
import '/editor/misc/select.js';
import '/editor/misc/context-menu.js';
import '/editor/misc/filter.js';
import '/editor/misc/fullscreen.js';
import '/editor/misc/shortcut.js';
import '/editor/misc/play.js';
import '/editor/misc/pause.js';
import '/editor/misc/save.js';
/* Engine initialization */
const host = 'apps.pixelcreator.io';
const port = 443;
const canvas = document.getElementById('wrapper');
const renderer = new Renderer(canvas.clientWidth, canvas.clientHeight, canvas, false, true);
const scene = new Scene('Main Scene');
const camera = new Object('Viewport', 0, 0, canvas.clientWidth, canvas.clientHeight).addComponent(new Camera('#272727'));
/* Editor initialization */
const hierarchy = new Hierarchy('world-list', scene);
const project = new Project('resources-list', scene);
const properties = new Properties('properties-list', scene);
const manager = new Manager(properties); // components manager
const handler = new Handler(scene, camera, renderer, project);
const toolbar = new Toolbar(camera);
const graph = new Graph();
/* Initialization */
async function init() {
// Load plugins
// const plugins = await fetch(`https://${host}/plugins`)
// .then(res => res.json())
// .then(json => json)
// for (const plugin of plugins.names) {
// Loader.import(plugin);
// }
Editor.init();
// Download project resources
let files = await Loader.download(`https://${host}:${port}`);
// console.log(files);
// Connect to main scene
let objects = await Network.init(host, port).connect(scene, true);
// console.log(objects);
// Scene initialization
project.init(files);
scene.init(objects);
renderer.init(scene, camera);
// Start loop
loop();
}
/* Main loop */
async function loop() {
// Analyse des performances
Stats.begin();
// Changement du curseur
Dnd.update();
// Calcul du delta-time
Time.deltaTime = (Time.now() - Time.last) / (1000 / 60);
// Calcul des performances
Performance.update();
// Lancement de la boucle principal
window.requestAnimationFrame(loop);
renderer.render(scene, camera);
// Affichage de la règle
Ruler.active ? Ruler.update(renderer.ctx, Mouse.x, Mouse.y) : false;
// Affichage de la grille
Grid.active ? Grid.draw(renderer.ctx) : false;
// Fin de l'analyse des performances
Stats.end();
Time.last = Time.current;
}
// Initialize on load
window.onload = init;
// Window resized
window.onresize = function() {
Editor.resize();
renderer.resize(canvas.clientWidth, canvas.clientHeight);
// renderer.init(scene, camera);
};
window.onbeforeunload = function(e) {
Network.disconnect();
};
window.onunload = function(e) {
Network.disconnect();
};
// Debug
window.scene = scene;
window.project = project;
window.loader = Loader;
// window.renderer = renderer;
// window.camera = camera;
// window.keyboard = Keyboard;
// window.mouse = Mouse;
// window.system = System;
// window.time = Time;
// window.socket = socket;
export {
renderer as Renderer,
scene as Scene,
camera as Camera,
hierarchy as Hiearchy,
project as Project,
properties as Properties,
manager as Manager,
handler as Handler,
toolbar as Toolbar,
graph as Graph
};