-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgallery.html
572 lines (523 loc) · 18.7 KB
/
gallery.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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
<html><head>
<title>GLGE</title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<style>
body{background-color: #000;color: #fff;font-family:arial}
</style>
</head><body>
<div>
<div style="width:900px;margin:auto;position:relative" id="container">
<canvas id="canvas" width="900" height="550"></canvas>
<div id="loading">
<div style="position:absolute; left: 150px; top: 100px; background-color: #000;
opacity: 0.8;height: 350px; width: 600px;
border-radius: 5px; -moz-border-radius5px;-webkit-border-radius:5px;border: 1px solid #fff;">
<div align="center" style="position:relative; top: 132px">
<h1>LOADING...</h1>
</div>
</div>
</div>
<div id="framerate" style="position:absolute; left: 762px; top: 7px; background-color: #000;
opacity: 0.3;height: 30px; width: 130px; border-radius: 5px; -moz-border-radius5px;-webkit-border-radius:5px;border: 1px solid #fff;">
<div id="debug" style="padding: 5px"></div>
</div>
<div style="padding: 5px;position:absolute; left: 20px; top: 474px;
background-color: #000; opacity: 0.3;height: 59px; width: 105px; border-radius: 5px;
-moz-border-radius:5px;-webkit-border-radius:5px;border: 1px solid #fff;">
<button onMouseDown='movementButton("fwd")' onMouseUp='movementButtonUp("fwd")' onMouseOut='movementButtonUp("fwd")' style="position:absolute;left:40;top:3">/\</button>
<button onMouseDown='movementButton("back")' onMouseUp='movementButtonUp("back")' onMouseOut='movementButtonUp("back")' style="position:absolute;left:40;top:40">\/</button>
<button onMouseDown='movementButton("left")' onMouseUp='movementButtonUp("left")' onMouseOut='movementButtonUp("left")' style="position:absolute;left:5;top:20"><</button>
<button onMouseDown='movementButton("right")' onMouseUp='movementButtonUp("right")' onMouseOut='movementButtonUp("right")' style="position:absolute;left:75;top:20">></button>
</div>
<div align="center">
<button onclick = 'addPicture(document.getElementById("input_tex1").value)'>new image:</button>
<input type="text" id="input_tex1" size="50" value="images/jais_test512x512.jpg"/><br>
</div>
<div align="center">
<form Name="input_editmode">
<div id="editInfo" align="center">LOADING..LOADING..LOADING..LOADING..LOADING</div>
<input type="radio" Name="R" onClick = 'editMode("safe")' />safe
<input type="radio" Name="R" onClick = 'editMode("move")'Checked="true" />move
<input type="radio" Name="R" onClick = 'editMode("resize")'/>resize
<input type="radio" Name="R" onClick = 'editMode("annotate")'/>annotate
<input type="radio" Name="R" onClick = 'editMode("delete")'/>delete
</form>
<!--
<form Name="input_dragmode">
<div id="editInfo" align="center"></div>
<input type="radio" Name="R" />safe
<input type="radio" Name="R" Checked="true" />move
<input type="radio" Name="R" />rotX
<input type="radio" Name="R" />rotY
<input type="radio" Name="R" />rotZ
</form>
-->
</div>
<div id="galleryAnnotate" style="padding: 5px" align="center">
</div>
<!--
<div style="padding: 5px;position:absolute; left: 145px; top: 510px;
background-color: #000; opacity: 0.5;height: 22px; width: 595px; border-radius: 5px;
-moz-border-radius:5px;-webkit-border-radius:5px;border: 1px solid #fff;"
id="galleryInfo" style="padding: 5px" align="center">
-->
<div style="padding: 5px; position:absolute; left: 125px; top: 510px;
height: 22px; width: 650px"
id="galleryInfo" style="padding: 5px" align="center">
</div>
<div id="save" style="position:absolute; left: 10px; top: 550px;">
<button onclick = 'saveGallery()'>save</button>
</div>
<div id="load" style="position:absolute; right: 10px; top: 550px;">
<button onclick = 'loadGallery()'>load</button>
</div>
<div id="saveLoadGallery" align="center"></div>
</div>
</div>
<script type="text/javascript" src="checkGL.js"></script>
<script type="text/javascript" src="pdebug.js"></script>
<script type="text/javascript" src="externals/GLGE/glge_math.js"></script>
<script type="text/javascript" src="externals/GLGE/glge.js"></script>
<script type="text/javascript" src="externals/GLGE/glge_input.js"></script>
<script type="text/javascript" src="externals/GLGE/glge_collada.js"></script>
<script type="text/javascript" src="ray_tri.js"></script>
<script type="text/javascript" src="kata.js"></script>
<script type="text/javascript">
doc = new GLGE.Document();
setMaterialAll = function(obj, mat) {
var obs = KJS.gameScene.getObjectsById(obj.getRef())
for (var i in obs) {
obs[i].setMaterial(mat)
}
}
// function to safely set material and save original for highlighting (hover/select)
setHighlightMaterial = function(obj, material){
if (material != obj.highlightMaterial) {
if (material == null) {
// obj.setMaterial(obj.originalMaterial)
setMaterialAll(obj, obj.originalMaterial)
}
else {
if (obj.highlightMaterial == null) {
obj.originalMaterial = obj.getMaterial()
}
// obj.setMaterial(material)
setMaterialAll(obj, material)
}
obj.highlightMaterial = material
}
}
niceArray = function (v, places) {
r = []
for (i in v) {
r.push(v[i].toFixed(places))
}
return r
}
positionOnWall = function(obj, x, y){ // pass no x,y means use present mouse location
var placeIndex = KJS.getNearestObject(g_dragOns,x,y)
if (placeIndex) {
var place = placeIndex[0]
var over = g_dragOns[placeIndex[1]]
var norm = new GLGE.Vec(placeIndex[2])
// if we're on a floor or ceiling FIXME: we should still rotate so the picture orients to the camera
if (Math.abs(norm.e(3)) > 0.8) {
obj.setLocX(place[0])
obj.setLocY(place[1])
obj.setLocZ(place[2]+0.1*norm.e(3))
if (obj.id.slice(0,11)=="galleryPix_")
obj.setRotX(Math.PI * -0.5 * -norm.e(3)) /// dbm -- remove for michelangelo; leave in for pix
obj.setRotY(0)
obj.setRotZ(0)
// pdebug("dragWallUpdate: " + obj.id + " over: " + over + " place: " + niceArray(place, 2), 9)
}
// if we're on a wall
else {
var nx = norm.cross([0, -1, 0])
var angZ = norm.angle([0, -1, 0])
if (nx.e(3) > 0)
angZ = -angZ /// assuming approximately vertical
// pdebug("dragWallUpdate: " + obj.id + " over: " + over + " place: " +
// niceArray(place, 2) + " ang: " + angZ.toFixed(2) +" norm: " + niceArray(norm.data, 2), 9)
over = scene.getObjectById(over)
obj.setLocX(place[0]+norm.e(1)*0.1)
obj.setLocY(place[1]+norm.e(2)*0.1)
obj.setLocZ(place[2])
obj.setRotX(over.getRotX())
obj.setRotY(over.getRotY())
obj.setRotZ(Math.PI + angZ)
}
}
}
setNote = function() {
var newComment = document.getElementById("input_annotate").value
if (g_picToAnnotate) g_picToAnnotate.galleryInfo = newComment
document.getElementById("galleryInfo").innerHTML = newComment
document.getElementById("galleryAnnotate").innerHTML = ""
}
g_picToAnnotate=null
dragWallStart = function(x, y){
var root = this.getRoot()
root.dragWallStartScale = [root.getScaleX(), root.getScaleY(), root.getScaleZ()]
// annotate
if (document.input_editmode.R[3].checked) {
g_picToAnnotate = root
var html =
'<input type="text" id="input_annotate" size="100" value="type comment here"/><br><button onclick="setNote()" >press here to enter comment</button>'
document.getElementById("galleryAnnotate").innerHTML = html
document.getElementById("galleryInfo").innerHTML = ""
}
// delete
if (document.input_editmode.R[4].checked) {
KJS.gameScene.removeObjectById(root.id)
}
}
dragWallUpdate = function(dx, dy){
var root = this.getRoot()
if (document.input_editmode.R[1].checked) {
positionOnWall(root)
}
else {
if (document.input_editmode.R[2].checked) {
var scale = 1.0 + 0.007 * dx - 0.003 * dy
if (scale<0.1) scale = 0.1
//pdebug("scale: " + dx + " " + scale, 7)
root.setScaleX(root.dragWallStartScale[0] * scale)
root.setScaleY(root.dragWallStartScale[1] * scale)
root.setScaleZ(root.dragWallStartScale[2] * scale)
this.computeBoundingSphere()
}
}
}
// create a new object with same props as old
shallowClone = function (obj) {
o2 = {}
for (i in obj) {
o2[i] = obj[i]
}
return o2
}
pixnum=1
doc.onLoad = function(){
var heightmap = {
image: "images/gallerymap.jpg",
width: 512,
height: 512,
lowX: -256,
upX: 256,
lowY: -256,
upY: 256,
lowZ: -36,
upZ: 46
}
// heightmap=null
scene = KJS.init(heightmap, 19, // # of objects to load -- hacky way to force everything loaded
function(){
onLoadContinue()
})
}
// this occurs when all objects are loaded
onLoadContinue = function () {
scene.setAmbientColor("#999999")
scene.camera.setLocX(-100)
var purple_mat = doc.getElement("purple");
var cyan_mat = doc.getElement("cyan");
scene.hoverable = ["ball"]
scene.selectable = ["ball"]
scene.dragable = ["ball"]
scene.dragWallable = ["ball","david"]
g_dragOns = ["bornh_bldg_07_floor", "bornh_bldg_08_floor", "b7_firedoor_door","bornh_bldg_07_walls_int_01",
"bornh_bldg_07_walls_int_01_sub1","straightstair_smallgallery","straightstair_smallgallery_sub1",
"bornh_bldg_07_walls_int_02","bornh_bldg_08_wall_int_01", "bornh_bldg_08_wall_int_02b",
"bornh_bldg_08_wall_int_02_sub1","bornh_door_gallery_connector_01",
"bornh_bldg_08_wall_int_03","bornh_bldg_07_walls_ext_02_sub1"]
// hover cyan
for (i in scene.hoverable) {
obj = scene.getObjectById(scene.hoverable[i])
if (!obj) continue
obj.makeHoverable(function(){
if (this.highlightMaterial != purple_mat) setHighlightMaterial(this, cyan_mat)
}, function(){
if (this.highlightMaterial != purple_mat) setHighlightMaterial(this, null)
})
obj.highlightMaterial = null
}
// selected are purple
for (i in scene.selectable) {
obj = scene.getObjectById(scene.selectable[i])
if (!obj) break
obj.makeSelectable(function(){
setHighlightMaterial(this, purple_mat)
}, function(){
if (this.highlightMaterial == purple_mat) setHighlightMaterial(this, null)
})
obj.highlightMaterial = null
}
var fix = function(v) {
v = 57.2958*v
while(v>180) v-=360
while(v<-180) v+=360
return v.toFixed(1)
}
var show = function(self) {
pdebug("edit rotate X="+fix(self.getRotX())+" Y="+fix(self.getRotY())+" Z="+fix(self.getRotZ()),4)
}
// drag is modal: move, rotatex, rotatey, rotatez
for (i in scene.dragable) {
obj=scene.getObjectById(scene.dragable[i])
if (!obj) break
obj.makeDragable(function(){
var root = this.getRoot()
root.dragStartLocX = parseFloat(root.getLocX()) /// wtf? strings?
root.dragStartLocY = parseFloat(root.getLocY())
root.dragStartLocZ = parseFloat(root.getLocZ())
root.dragStartRotX = parseFloat(root.getRotX()) /// wtf? strings?
root.dragStartRotY = parseFloat(root.getRotY())
root.dragStartRotZ = parseFloat(root.getRotZ())
pdebug("dragging: " + root.id + " from: " + root.dragStartLocX+" "+root.dragStartLocY+" "+root.dragStartLocZ,3)
}, function(dx, dy){
var root = this.getRoot()
if (document.input_dragmode.R[1].checked) {
var ang = scene.camera.getRotY()
var x = Math.cos(ang - Math.PI)
var y = Math.sin(ang - Math.PI)
// pdebug("x: " + x + "y: " + y + "ang: "+ (parseFloat(ang)-Math.PI),9)
root.setLocX(root.dragStartLocX - dx * x * 0.05)
root.setLocY(root.dragStartLocY - dx * y * 0.05)
root.setLocZ(root.dragStartLocZ - dy * 0.05)
pdebug("edit move X="+root.getLocX().toFixed(3)+" Y="+root.getLocY().toFixed(3)+" Z="+root.getLocZ().toFixed(3),4)
}
if (document.input_dragmode.R[2].checked) {
root.setRotX(root.dragStartRotX + dy*.01)
show(root)
}
if (document.input_dragmode.R[3].checked) {
root.setRotY(root.dragStartRotY + dy*.01)
show(root)
}
if (document.input_dragmode.R[4].checked) {
root.setRotZ(root.dragStartRotZ + dx*.01)
show(root)
}
})
}
// stop dragging my monkey around! (drag on wall & whatever else is under cursor)
for (i in scene.dragWallable) {
var o = scene.getObjectById(scene.dragWallable[i])
o && o.makeDragable(dragWallStart, dragWallUpdate)
}
// turn off loading banner
editMode("move")
document.getElementById("loading").innerHTML = ""
// hardcoded statue stuff until we get things working
// loc_x="-80" loc_y="-44" loc_z="-2.19" animation="#spin" scale="0.17"
// statue comes up black!
var o = KJS.gameScene.getObjectById("david")
o.setMaterial(doc.getElement("white"))
var root = o.getRoot()
root.setScaleX(0.17)
root.setScaleY(0.17)
root.setScaleZ(0.17)
o.computeBoundingSphere()
root.setLocX(-80)
root.setLocY(-44)
root.setLocZ(-2.19)
}
addPicture = function(pic, scale){
if (scale==null) scale = 0.01
var obj = KJS.createObjectAndAddToScene("galleryPix_" + pixnum++, doc.getElement("square"), pic, function (tx) {
obj.txWidth = tx.width
obj.txHeight = tx.height
obj.setScaleX(parseFloat(tx.width) * scale)
obj.setScaleZ(parseFloat(tx.height) * scale)
obj.computeBoundingSphere()
})
obj.gallerySource = pic
obj.galleryInfo = "Image source: " + pic
positionOnWall(obj, 0, 0)
obj.getMaterial().setSpecular(.4)
obj.getMaterial().setEmit(.5)
obj.makeDragable(dragWallStart, dragWallUpdate)
obj.makeHoverable(function(){
this.getMaterial().setEmit(1)
document.getElementById("galleryInfo").innerHTML = this.galleryInfo
}, function(){
this.getMaterial().setEmit(.5)
document.getElementById("galleryInfo").innerHTML = ""
})
// force edit mode to move (protect from delete)
document.input_editmode.R[1].checked = true
editMode("move")
scene.hoverable.push(obj.id)
return obj
}
movementButton = function(b) {
KJS.forceMovement=b
}
movementButtonUp = function(b) {
KJS.forceMovement=null
}
editMode = function(mode) {
var s
switch (mode) {
case "safe": s = "safe mode: imagess cannot be moved or resized"; break
case "move": s = "move mode: click on an object to drag along the wall or floor"; break
case "resize": s = "resize mode: grab object in upper right corner to resize"; break
case "annotate": s = "annotate mode: click on an object to add & edit comments"; break
case "delete": s = "delete mode: click on an object to delete. Careful, no undo!"; break
}
document.getElementById("editInfo").innerHTML = s
}
cookify_goodchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-+"
cookify_tohex = "0123456789abcdef"
cookify = function(s) {
var ret = ""
for (var i=0; i<s.length; i++) {
if (cookify_goodchars.indexOf(s[i])>=0) {
ret += s[i]
}
else {
var n = s[i].charCodeAt()
var lsn = n & 0x0f
var msn = n >> 4
ret += "_" + cookify_tohex[msn] + cookify_tohex[lsn]
}
}
return ret
}
deCookify = function(s) {
var ret = ""
for (var i=0; i<s.length; i++) {
if (cookify_goodchars.indexOf(s[i])>=0) {
ret += s[i]
}
else {
if (s[i] != "_") alert ("bad char in decookify")
i++
var msn = cookify_tohex.indexOf(s[i++])
var lsn = cookify_tohex.indexOf(s[i])
ret += String.fromCharCode((msn<<4) + lsn)
}
}
return ret
}
saveGallery = function() {
document.getElementById("saveLoadGallery").innerHTML =
'<input type="text" id="input_save" size="40" value="enter gallery name here"/><br><button onclick="saveGalleryFinish()" >OK</button><button onclick="saveGalleryCancel()" >CANCEL</button>'
}
saveGalleryFinish = function () {
var fn = document.getElementById("input_save").value
var prec = 3
var s = "|GalleryBegin~<br>"
for (var i in KJS.gameScene.objects) {
var o = KJS.gameScene.objects[i]
if (o.id=="david" || o.id.slice(0,11) == "galleryPix_") {
if (o.gallerySource)
s += "|" + o.gallerySource
else
s += "|" + o.id
s += "," + o.getLocX().toFixed(prec) + "," + o.getLocY().toFixed(prec) + "," + o.getLocZ().toFixed(prec)
s += "," + o.getRotX().toFixed(prec) + "," + o.getRotY().toFixed(prec) + "," + o.getRotZ().toFixed(prec)
if (o.txWidth)
s += "," + o.getScaleX() / o.txWidth
else
s += "," + o.getScaleX()
s += "," + o.galleryInfo
s += "~"
}
}
s += "<br>|GalleryEnd~<br>"
document.cookie = "gallery_" + fn + "=" + cookify(s) + ";expires=Thu, 31-Dec-3020 00:00:00 GMT." // me love you long time
document.getElementById("saveLoadGallery").innerHTML = ""
}
saveGalleryCancel = function() {
document.getElementById("saveLoadGallery").innerHTML = ""
var obs = KJS.gameScene.getObjectsById("david")
}
loadGallery = function() {
document.getElementById("saveLoadGallery").innerHTML =
'<input type="text" id="input_load" size="40" value="enter gallery name here"/><br><button onclick="loadGalleryFinish()" >OK</button><button onclick="saveGalleryCancel()" >CANCEL</button>'
}
loadGalleryFinish = function(load) {
var gal = document.getElementById("input_load").value
var fn = "gallery_" + gal + "="
document.getElementById("saveLoadGallery").innerHTML = ""
// get load data from cookie
var load;
var w = document.cookie.split(";")
for (var i in w) {
var j = w[i].indexOf(fn)
if (j==0 || j==1) {
load = deCookify(w[i].slice(j+fn.length+1))
break
}
}
if (load==null) {
alert ("gallery " + gal + " not found!")
return
}
// delete everything
var delList = []
for (var i=0; i<KJS.gameScene.objects.length; i++) {
var o = KJS.gameScene.objects[i]
if (o.id.slice(0,11) == "galleryPix_") {
delList.push(o.id)
}
}
for (i in delList) {
KJS.gameScene.removeObjectById(delList[i])
}
// load data
var i = load.indexOf("|GalleryBegin~") + 14
while (i < load.indexOf("|GalleryEnd~")) {
if (load[i]=='|') {
var j = i + load.slice(i+1).indexOf('~') + 1
var s = load.slice(i+1,j)
i = j
var w = s.split(',')
if (w[0] == "david") {
pic = scene.getObjectById("david").getRoot()
pic.setLocX(parseFloat(w[1]))
pic.setLocY(parseFloat(w[2]))
pic.setLocZ(parseFloat(w[3]))
pic.setRotX(parseFloat(w[4]))
pic.setRotY(parseFloat(w[5]))
pic.setRotZ(parseFloat(w[6]))
var scale = parseFloat(w[7])
pic.setScaleX(scale)
pic.setScaleY(scale)
pic.setScaleZ(scale)
}
else {
var pic = addPicture(w[0], parseFloat(w[7]))
pic.setLocX(parseFloat(w[1]))
pic.setLocY(parseFloat(w[2]))
pic.setLocZ(parseFloat(w[3]))
pic.setRotX(parseFloat(w[4]))
pic.setRotY(parseFloat(w[5]))
pic.setRotZ(parseFloat(w[6]))
pic.galleryInfo = w[8]
for (var k = 9; k < w.length; k++) {
pic.galleryInfo += w[k]
}
}
}
else {
i++
}
}
}
doc.load("bornholm_level.xml")
</script>
<div id="dbg0"></div>
<div id="dbg1"></div>
<div id="dbg2"></div>
<div id="dbg3"></div>
<div id="dbg4"></div>
<div id="dbg5"></div>
<div id="dbg6"></div>
<div id="dbg7"></div>
<div id="dbg8"></div>
<div id="dbg9"></div>
<div id="dbg"></div>
</body></html>