-
Notifications
You must be signed in to change notification settings - Fork 3
/
QuakeWebTools.html
150 lines (127 loc) · 4.86 KB
/
QuakeWebTools.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
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Quake Web Tools</title>
<link rel="stylesheet" href="QuakeWebTools/css/style.css">
<!--lib-->
<script src="QuakeWebTools/scripts/lib/stats.min.js"></script>
<script src="QuakeWebTools/scripts/lib/DataStream.js"></script>
<script src="QuakeWebTools/scripts/lib/three.js"></script>
<script src="QuakeWebTools/scripts/lib/orbitcontrols.js"></script>
<script src="QuakeWebTools/scripts/lib/firstpersoncontrols.js"></script>
<!--util-->
<script src="QuakeWebTools/scripts/util/filemanager.js"></script>
<script src="QuakeWebTools/scripts/util/fileutil.js"></script>
<script src="QuakeWebTools/scripts/util/imageutil.js"></script>
<!--types-->
<script src="QuakeWebTools/scripts/types/pak.js"></script>
<script src="QuakeWebTools/scripts/types/wad.js"></script>
<script src="QuakeWebTools/scripts/types/pal.js"></script>
<script src="QuakeWebTools/scripts/types/lmp.js"></script>
<script src="QuakeWebTools/scripts/types/spr.js"></script>
<script src="QuakeWebTools/scripts/types/bsp.js"></script>
<script src="QuakeWebTools/scripts/types/mdl.js"></script>
<!--application-->
<script src="QuakeWebTools/scripts/quakewebtools.js"></script>
</head>
<body onload="app_init()" style="width: 540px">
<article>
<div id="holder" class="filedrop" style="min-height: 100px">
<h1 style="font-size: 2em">DROP FILES HERE</h1>
<p>Drag Quake file format files (pak, wad, bsp, lmp, spr, mdl, map,
pal) into this area to load their content in your browser.</p>
<div id="file-content" class="" style="border:0">
</div>
</div>
<p id="status">File API and FileReader API not supported</p>
</article>
</body>
</html>
<!-- TODO: Clean up this mess and put it in a better location -->
<script>
// stats
if (0) {
var stats = new Stats();
stats.setMode(1); // 0: fps, 1: ms
// Align top-left
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '0px';
stats.domElement.style.top = '0px';
document.body.appendChild( stats.domElement );
QuakeWebTools.STATS = stats;
}
var holder = document.getElementById('holder');
var state = document.getElementById('status');
if (typeof window.FileReader === 'undefined') {
state.className = 'fail';
} else {
state.parentNode.removeChild(state);
}
holder.ondragover = function () { this.className = 'filedrop-hover'; return false; };
holder.ondragleave = function () { this.className = 'filedrop'; return false; };
holder.ondragend = holder.ondragleave;
holder.ondrop = function (e) {
this.className = 'filedrop';
e.preventDefault();
var file = e.dataTransfer.files[0];
var reader = new FileReader();
reader.onload = function (event) {
var QWT = QuakeWebTools;
var G = QWT.GLOBAL;
var file_entry = G.FILEMANAGER.addFile(file.name, event.target.result);
var filename = file_entry.path;
var arraybuffer = file_entry.data;
// will need a proper system to deal with these for multiple viewers
if (QWT.ANIMATION_ID != null) {
console.log("stopping animationFrame " + QWT.ANIMATION_ID);
cancelAnimationFrame(QWT.ANIMATION_ID);
QWT.ANIMATION_ID = null;
}
document.getElementById("file-content").innerHTML = "";
switch (file_entry.type) {
case "pak":
var pak = file_entry.obj;
viewPAK(pak);
break;
case "wad":
var wad = file_entry.obj;
QWT.ImageUtil.generateHTMLPreview({image_infos: wad.directory, arraybuffer: wad.ab},
QWT.DEFAULT_PALETTE, "file-content");
break;
case "bsp":
var bsp = file_entry.obj;
QWT.ANIMATION_ID = viewBSP(bsp);
QWT.ImageUtil.generateHTMLPreview({image_infos: bsp.miptex_directory, arraybuffer: bsp.ab},
QWT.DEFAULT_PALETTE, "file-content");
break;
case "spr":
var spr = file_entry.obj;
var image_datas = spr.getImageData();
QWT.ImageUtil.generateHTMLPreview({image_datas: image_datas},
QWT.DEFAULT_PALETTE, "file-content");
break;
case "lmp":
var image_datas = [QWT.ImageUtil.getImageData(filename, arraybuffer)];
QWT.ImageUtil.generateHTMLPreview({image_datas: image_datas},
QWT.DEFAULT_PALETTE, "file-content");
break;
case "pal":
var image_datas = [QWT.ImageUtil.getImageData(filename, arraybuffer)];
QWT.ImageUtil.generateHTMLPreview({image_datas: image_datas},
QWT.DEFAULT_PALETTE, "file-content");
break;
case "mdl":
var mdl = file_entry.obj;
QWT.ANIMATION_ID = viewMDL(mdl);
QWT.ImageUtil.generateHTMLPreview({image_datas:mdl.skins}, QWT.DEFAULT_PALETTE, "file-content");
break;
default:
var msg = "File type not supported (" + file_entry.type + ")";
alert(msg);
}
};
reader.readAsArrayBuffer(file);
return false;
};
</script>