-
Notifications
You must be signed in to change notification settings - Fork 0
/
devtools.html
287 lines (266 loc) · 8.41 KB
/
devtools.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!DOCTYPE html>
<html lang="en">
<head>
<style>
#tools {
position: absolute;
right: 0px;
top: 0px;
width: 300px;
height: 100%;
background-color: antiquewhite;
text-align: center;
font-family: Arial;
z-index: 10;
}
#blockeditor {
display: none;
position: absolute;
top: 0px;
left: 0;
width: 100vw;
height: 100vh;
}
#scene {
display: block;
position: absolute;
top: 0px;
left: 0;
width: 100vw;
height: 100vh;
}
</style>
<link rel="stylesheet" href="3d/voxel.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Developer tools</h1>
<p>(Yes we know it looks bad)</p>
<button>Report bugs</button>
<p>Code editor</p>
<p onclick="open3d()">3D-editor</p>
<p>Request features</p>
<h1>Developer news</h1>
<p>Nothing here, yet!</p>
<div id="blockeditor" onkeydown="testmove(event)">
<div id="tools">
<h1>Settings</h1>
<span>Select block</span>
<select onclick="changetool()" id="toolselect">
<option value="color">Custom color</option>
<option value="custom">Custom image (not working)</option>
</select>
<br>
<input type="color" id="blockcolor" onchange="changetool()">
<br>
<span>Block size:</span><input type="number" id="bsize">
<br>
<span>Resize all to</span><input type="text" id="resize"> <button onclick="resizeall()">Resize</button>
<br>
<button onclick="document.getElementById('exportarea').value=exportworld()">Export</button><br>
<button onclick="resetworld()">Reset world</button><br>
<button onclick="loadworld()">Load world</button>
<br>
<textarea id="exportarea"></textarea>
<p><strong>Controls: </strong><br>WASD moves (W = forward, A = left, S = backward, D = right)</p>
<p>Drag with your mouse to rotate</p>
<p>LEFT CLICK = place a block</p>
<p>RIGHT CLICK = remove a block</p>
<p>SCROLL = zoom</p>
</div>
<div id="scene"></div>
</div>
<script src="3d/voxelcss.js"></script>
<script src="3d.js"></script>
<script>
var usepath=""
var PI = Math.PI;
var scene = new voxelcss.Scene();
var lightSource = new voxelcss.LightSource(300, 300, 300, 750, 0.5, 1);
var world = new voxelcss.World(scene);
var editor = new voxelcss.Editor(world);
function init(element) {
scene.rotate(-PI / 8, PI / 4, 0);
scene.attach(element);
scene.addLightSource(lightSource);
editor.enableAutoSave();
editor.load();
if (world.getVoxels().length === 0) {
editor.add(new voxelcss.Voxel(0, 0, 0, 100, {
mesh: voxelcss.Meshes.grass
}));
}
}
for (var i=0; i < blocklist.length; i++) {
var newelement=document.createElement("option")
newelement.innerHTML=blocklist[i]
newelement.value=blocklist[i]
document.getElementById("toolselect").appendChild(newelement)
}
document.getElementById("blockcolor").style.display="none"
function changetool() {
document.getElementById("blockcolor").style.display="none"
var select=document.getElementById("toolselect").value
if (select=="color") {
document.getElementById("blockcolor").style.display="inline-block"
editor.setToolMesh(new voxelcss.Mesh(new voxelcss.ColorFace(document.getElementById("blockcolor").value)))
}else{
editor.setToolMesh(getBlock(select))
}
}
function resetworld() {
var voxels=world.getVoxels()
for (var i=0; i < voxels.length; i++) {
var voxel=voxels[i]
world.remove(voxel)
}
editor.add(new voxelcss.Voxel(0, 0, 0, 100, {
mesh: voxelcss.Meshes.grass
}));
}
function testmove(event) {
var key=event.key
var code=event.keyCode
//alert(key)
if (code==32) {
scene.setPanY(scene.getPanY()+100)
}
if (key=="w") {
scene.setPanZ(scene.getPanZ()+100)
}
if (key=="s") {
scene.setPanZ(scene.getPanZ()-100)
}
if (key=="a") {
scene.setPanX(scene.getPanX()+100)
}
if (key=="d") {
scene.setPanX(scene.getPanX()-100)
}
}
function exportworld() {
//blockname,x,y,z,dimesnsion
var voxels=world.getVoxels()
var exportdata=""
for (var i=0; i < voxels.length; i++) {
var voxel=voxels[i]
try {
var blockname=voxel.getMesh().getTop().getSource()
if (blockname.includes("grass")) {
blockname="grass"
}else if (blockname.includes("dirt")) {
blockname="dirt"
}else if (blockname.includes("leaves")) {
blockname="leaves"
}else if (blockname.includes("tree")) {
blockname="wood"
}else if (blockname.includes("sand")) {
blockname="sand"
}else if (blockname.includes("brick")) {
blockname="bricks"
}else if (blockname.includes("btn")) {
blockname="button"
}
} catch {
var blockname="color:"+voxel.getMesh().getTop().getHex()
}
console.log(blockname)
var blockx=voxel.getPositionX()
var blocky=voxel.getPositionY()
var blockz=voxel.getPositionZ()
var blockdimension=voxel.getDimension()
exportdata+=blockname + "," + blockx + "," + blocky + "," + blockz + "," + blockdimension + ";"
}
var voxels=scene.getLightSources()
for (var i=0; i < voxels.length; i++) {
var voxel=voxels[i]
var blockname="lightsource"
var blockx=voxel.getPositionX()
var blocky=voxel.getPositionY()
var blockz=voxel.getPositionZ()
var blockdimension=voxel.getTravelDistance()+"+"+voxel.getBrightness() [0] + "+"+ voxel.getBrightness() [1]
exportdata+=blockname + "," + blockx + "," + blocky + "," + blockz + "," + blockdimension + ";"
}
return exportdata
}
function load3dmodel(data) {
var PI = Math.PI;
var scene = new voxelcss.Scene();
var lightSource = new voxelcss.LightSource(300, 300, 300, 750, 0.3, 1);
var world = new voxelcss.World(scene);
var editor = new voxelcss.Editor(world);
//blockname,x,y,z,dimesnsion
var data1=data.split(";")
for (var i=0; i < data1.length-1; i++) {
var blockname=data1[i].split(",") [0]
var blockx=Number(data1[i].split(",") [1])
var blocky=Number(data1[i].split(",") [2])
var blockz=Number(data1[i].split(",") [3])
var blockdimension=data1[i].split(",") [4]
if (blockname=="lightsource") {
var ls=new voxelcss.LightSource(blockx,blocky,blockz,Number(blockdimension.split("+")[0]),Number(blockdimension.split("+")[1]),Number(blockdimension.split("+")[2]))
scene.addLightSource(ls)
}else{
var blockdimension=Number(blockdimension)
var vface=new voxelcss.ColorFace(0,0,0)
var vblock=new voxelcss.Mesh().setFaces(vface)
if (blockname=="grass") {
var vblock=voxelcss.Meshes.grass
}
if (blockname=="wood") {
var vblock=voxelcss.Meshes.treeTrunk
}
if (blockname=="leaves") {
var vblock=voxelcss.Meshes.treeLeaves
}
if (blockname=="dirt") {
var vblock=voxelcss.Meshes.dirt
}
if (blockname.includes(":")) {
if (blockname.split(":") [0]=="color") {
var vface=new voxelcss.ColorFace(blockname.split(":") [1])
var vblock=new voxelcss.Mesh()
//console.log(vface)
vblock.setFaces(vface)
}
}
console.log([blockx, blocky, blockz, blockdimension])
var voxel=new voxelcss.Voxel(blockx, blocky, blockz, blockdimension)
voxel.setMesh(vblock)
world.add(voxel)
}
}
return world.export()
}
function loadworld() {
var worlddata=prompt("Enter world data:")
loadworld1(worlddata)
}
function loadworld1(worlddata) {
if (worlddata.substring(0,2)=="[{") {
editor.import(worlddata)
}else{
editor.import(load3dmodel(worlddata))
}
world.save()
}
function open3d() {
init(document.getElementById("scene"));
document.getElementById("blockeditor").style.display="block"
}
function resizeall() {
var size = Number(document.getElementById("resize").value)
var voxels=scene.getVoxels();
for (var i=0; i<voxels.length; i++) {
voxels[i].setDimension(Math.floor(voxels[i].getDimension()*size))
voxels[i].setPositionX(voxels[i].getPositionX()*size)
voxels[i].setPositionY(voxels[i].getPositionY()*size)
voxels[i].setPositionZ(voxels[i].getPositionZ()*size)
}
loadworld1(exportworld())
}
</script>
</body>
</html>