forked from movabo/ObjViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·137 lines (119 loc) · 4.33 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title>ObjViewer</title>
<link rel="stylesheet" href="./css/style.css" />
<script src="./js/three.js"></script>
<script src="./js/MTLLoader.js"></script>
<script src="./js/OBJLoader.js"></script>
<script src="./js/PointerLockControls.js"></script>
<script src="./js/ObjViewer.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function(event) {
let byId = (id) => { return document.getElementById(id); },
canvas = byId("renderer"),
start = byId("start"),
overlay = byId("overlay"),
help = byId("help"),
load = byId("load"),
status = byId("status"),
statusbar = byId("statusbar"),
statustext = byId("statustext");
// Initialize ObjViewer
var objViewer = new ObjViewer(THREE, canvas, {
skybox : {
path : './assets/skybox/freezurbern/',
files : [
"divine_ft.png", "divine_bk.png",
"divine_up.png", "divine_dn.png",
"divine_rt.png", "divine_lf.png"
]
},
mtl : {
path : './assets/',
file : "star.mtl"
},
obj : {
path : './assets/',
file : "star.obj"
}
});
// Log the viewer to the console for debugging.
console.log(objViewer);
// Full size of the canvas
objViewer.setSize(window.innerWidth, window.innerHeight);
// Set the flying-speed.
objViewer.floatSpeed = 1040;
// Load when clicking on the load-button
load.addEventListener("click", () => {
// (Down-)Load all files.
objViewer.load();
// Hide button
loader.style.display = "none";
});
// update the loading-bar
objViewer.callbacks.onXhrProgress = (xhr, action) => {
if (xhr.lengthComputable) {
let t = xhr.total,
l = xhr.loaded,
r = Math.round( l / t * 100, 2 ) + "%";
statusbar.style.width = r;
statustext.innerHTML = "Loading (" + action + "): " + r;
}
};
// Show the Start and help when loaded, hide the loading-section
objViewer.callbacks.onLoaded = () => {
status.style.display = "none";
help.style.display = "block";
// Change the start-point for the viewer
objViewer.setPosition(30, 60, 75);
};
// Request the pointer and thus allow the user to move in the canvas
start.addEventListener("click", objViewer.requestPointerLock.bind(objViewer));
// keep full-size on resize
window.addEventListener("resize", () => {
objViewer.setSize(window.innerWidth, window.innerHeight);
});
// Pointer is locked: Hide overlay
objViewer.callbacks.onPointerLock = () => {
overlay.style.display = "none";
// Start the animation
objViewer.animate();
};
// Pointer is unlocked: Show overlay
objViewer.callbacks.onPointerUnlock = () => {
overlay.style.display = "block";
// Stop the animation
objViewer.stopAnimation();
};
});
</script>
</head>
<body>
<h1 class="hidden">ObjViewer</h1>
<p class="hidden">The library to display obj- and mtl-files to display them including a skybox with WebGL and <a href="https://threejs.org/">three.js</a>.</p>
<div id="canvasWrapper">
<canvas width="640px" height="480px" id="renderer"></canvas>
</div>
<div id="overlay">
<div id="loader">
<button id="load" class="button">Load</button><a href="https://github.com/movabo/ObjViewer/">View on GitHub</a>
</div>
<div id="status">
<div id="statusbar"></div>
<div id="statustext"></div>
</div>
<div id="help">
<button id="start">Click to play</button>
(<span class="key">W</span>,
<span class="key">A</span>,
<span class="key">S</span>,
<span class="key">D</span> /
<span class="key">↑</span>,
<span class="key">←</span>,
<span class="key">↓</span>,
<span class="key">↓</span> to move, <span class="key">ESC</span> to exit)
</div>
</div>
</body>
</html>