-
Notifications
You must be signed in to change notification settings - Fork 1
/
gfxva.html
607 lines (571 loc) · 27.1 KB
/
gfxva.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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
<html>
<head>
<title>Travellers Tales PSX level gfx viewer by @Juanmv94</title>
<style>
body { margin: 0; font-family: Arial;}
canvas { width: 100%; height: 100% }
center {position:absolute;display: table; height: 100%; width: 100%; color: white;}
h1 {display: table-cell; vertical-align: middle;}
div {position: fixed; margin: 4px; right:0; text-align:right}
</style>
</head>
<body>
<center id="progresscontainer"><h1 id="progress">Loading SaveState file</h1></center>
<div style="bottom:0; font-family: monospace; color: white;">
W,A,S,D: move<br/>
←,↑,→,↓,Q,E: turn<br/>
Left click: toggle mouse look<br/>
</div>
<script src="three.min.js"></script>
<script src="FlyControls.js"></script>
<script>
var urlvars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
urlvars[key] = value;
});
var games = {
"blsc": {"clut": addtopos(0x800E2518),"bkgd": 3072, "bkgx": 256, "bkgy": parseInt(urlvars["bkgy"]),"thumbsp": 0, "getgfxo": getgfxots2},
"ts2": {"clut": addtopos(0x800CD200),"bkgd": 3072, "bkgx": 192, "bkgy":128,"thumbsp": 4, "getgfxo": getgfxots2},
"ts2demo": {"clut": addtopos(0x800BCCE0),"bkgd": 3072, "bkgx": 192, "bkgy":128,"thumbsp": 4, "getgfxo": getgfxots2},
"ts2proto": {"clut": addtopos(0x800B58A8),"bkgd": 3072, "bkgx": 192, "bkgy":128,"thumbsp": 4, "getgfxo": getgfxots2},
"bugs": {"clutpag": addtopos(0x800910B0),"bkgd": 1280, "clutpal": addtopos(0x800A7DD8),"bkgx": parseInt(urlvars["bkgx"]), "bkgy": parseInt(urlvars["bkgy"]),"thumbsp": 0, "getgfxo": getgfxobugs},
"bugsdemo": {"clutpag": addtopos(0x80094740),"bkgd": 1536, "clutpal": addtopos(0x800a6be8),"bkgx": parseInt(urlvars["bkgx"]), "bkgy": parseInt(urlvars["bkgy"]),"thumbsp": 0, "getgfxo": getgfxobugs},
"wl": {"clut": addtopos(0x800AAAB8),"bkgd": 3072, "bkgx": 1, "bkgy": 1,"thumbsp": 0, "getgfxo": getgfxots2},
"tsr": {"clut": addtopos(0x800DA610),"bkgd": 3072, "bkgx": 1, "bkgy": 1,"thumbsp": 4, "getgfxo": getgfxots2},
"mrm": {"clut": addtopos(0x800DFF00),"bkgd": 3072, "bkgx": 1, "bkgy": 1,"thumbsp": 4, "getgfxo": getgfxots2}
};
var mult=urlvars["mult"]||0.0035;
var arrayBuffer;
var oReq = new XMLHttpRequest();
var progresstring=document.getElementById("progress");
oReq.open("GET", "SSTATES/"+urlvars["file"], true);
oReq.responseType = "arraybuffer";
oReq.onload = function (oEvent) {
if ((oReq.readyState != 4) || (oReq.status != 200)) {
progresstring.innerText="Failed to load "+urlvars["file"];
return;
}
arrayBuffer = oReq.response; // Note: not oReq.responseText
if (arrayBuffer) {
array8u = new Uint8Array(arrayBuffer.slice(2));
array16 = new Int16Array(arrayBuffer.slice(2));
array16u = new Uint16Array(arrayBuffer.slice(2));
array32 = new Int32Array(arrayBuffer.slice(2));
array32u = new Uint32Array(arrayBuffer.slice(2));
vram = new Uint16Array(arrayBuffer.slice(2048*1254+991,2048*1254+991+(2048*256)));
setTimeout(loaded,50); //we show loading 100%
}
};
oReq.onprogress = function(pe) {
if (pe.lengthComputable) progresstring.innerText="Loading SaveState file: "+Math.floor(pe.loaded/pe.total*100)+"%";
}
oReq.send(null);
function postopsxe(pos) {
return (pos+11056360).toString(16);
}
function psxetopos(psxe) {
return psxe-11056360;
}
function postoadd(add) {
return (add+2147483208).toString(16);
}
function addtopos(add) {
return add-2147483208;
}
var scene = new THREE.Scene();
scene.background = new THREE.Color(0x7777ff);
var camera = new THREE.PerspectiveCamera( 50, window.innerWidth/window.innerHeight, 0.1, 10000 );
var light = new THREE.HemisphereLight( 0xffffff, 0xc0c0c0, 0.95 );
light.position.set( 0.5, 0.5, 0.5 );
scene.add( light );
var renderer = new THREE.WebGLRenderer({antialias: false});
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
function onDocumentMouseDown( event )
{
if (event.button!=0) {
}
var raycaster = new THREE.Raycaster(), mouse = new THREE.Vector2(), intersects;
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = - (event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
intersects = raycaster.intersectObjects(scene.children, true);
if (intersects.length > 0){
var obj=intersects[0].object;
if (obj.parent.ba) console.log(obj.parent.ba);
else if (obj.parent.parent) console.log(obj.parent.parent.ba);
} else {
}
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function colorcurve(c) { //RGB color intensity in PSX is not linear! in the range 0-31 the middle is about 8 (nopsx documentation)
return Math.sin(c/31*Math.PI/2)*255;
}
function getBackgroundTexture() { //Gets the background level texture (pal8 256color)
const bkgd=games[urlvars["game"]].bkgd*4;
const x=games[urlvars["game"]].bkgx,y=games[urlvars["game"]].bkgy;
const multx=3,uy=144,dy=160;
var imarray = new Uint8Array(x*(y+uy+dy)*4*multx*2);
var imarrp=0;
for (let i=0;i<y;i++) //Each line
for (let my=0;my<=((i==0)?uy:(i==(y-1))?dy:0);my++) //repeat first and last line (uy,dy)
for (let mx=0;mx<multx;mx++) { //Times x-repeating (normal+mirrored)
var bkgpl=bkgd+8192*4*i;
for (let j=0;j<x;j++) for (let k=0;k<4;k++) imarray[imarrp++]=textureba[bkgpl++];
bkgpl-=4;
for (let j=0;j<x;j++) {for (let k=0;k<4;k++) imarray[imarrp++]=textureba[bkgpl++]; bkgpl-=8;}
}
return new THREE.DataTexture( imarray, x*multx*2, y+uy+dy, THREE.RGBAFormat );
}
function getPalTextures() { //Gets the pal4 16color level textures
function getpal(x,y) { //returns palette for each pal4 texture pixel
if (n<games[urlvars["game"]].thumbsp) {
if (y<32 && (x%64)<8) return palspage[Math.floor(y/8)*4+Math.floor(x%64/2)];
if (y<64 && (x%64)<16) return palspage[Math.floor(y/16)*4+Math.floor(x%64/4)];
if (y<128 && (x%64)<32) return palspage[Math.floor(y/32)*4+Math.floor(x%64/8)];
}
return palspage[Math.floor(y/64)*4+Math.floor(x%64/16)];
}
//const pals16=768+193*1024;
textureba = new Uint8Array(8192*256*4);
var palspage,vrampage;
var lut=games[urlvars["game"]].clut, lutpal, lutpag;
if (!lut) { //BL has PAL LUT and VRAM page at two diferent addresses
lutpal=games[urlvars["game"]].clutpal; lutpag=games[urlvars["game"]].clutpag;
}
for (var n=0;n<32;n++) {
vrampage=array16u[(lut||lutpag)>>1]&0x7F;
var pal8=array16u[(lut||lutpag)>>1]&0x80;
if (vrampage>15) {if (lut) lut+=16; else {lutpag+=2; lutpal+=2} continue;}
var palp=array16u[(lutpal||(lut+2))>>1]*16;
if (!pal8) {
palspage=new Array(16);
for (var j=0;j<16;j++) {
var pal=new Array(16);
for (var i=0;i<16;i++) {
var color=vram[palp++];
if (!color) pal[i]=[0,0,0,10];
else pal[i]=[colorcurve(color&31),colorcurve((color>>5)&31),colorcurve((color>>10)&31),255];
}
palspage[j]=pal;
}
for (let y=0;y<256;y++) {
var imarrp=n*1024+8192*4*y;
var vrp=vrampage*64+1024*y;
for (let x=0;x<64;x++) {
var pal=getpal(x,y);
var c1=vram[vrp]&15,c2=(vram[vrp]>>4)&15,c3=(vram[vrp]>>8)&15,c4=(vram[vrp]>>12)&15;
for (let i=0;i<4;i++) textureba[imarrp++]=pal[c1][i];
for (let i=0;i<4;i++) textureba[imarrp++]=pal[c2][i];
for (let i=0;i<4;i++) textureba[imarrp++]=pal[c3][i];
for (let i=0;i<4;i++) textureba[imarrp++]=pal[c4][i];
vrp++;
}
}
} else {
var pal=new Array(256);
for (var i=0;i<256;i++) {
var color=vram[palp++];
if (!color) pal[i]=[0,0,0,10];
else pal[i]=[colorcurve(color&31),colorcurve((color>>5)&31),colorcurve((color>>10)&31),255];
}
for (let y=0;y<256;y++) {
var imarrp=n*1024+8192*4*y;
var vrp=vrampage*64+1024*y;
for (let x=0;x<128;x++) {
var c1=vram[vrp]&255,c2=(vram[vrp]>>8)&255;
for (let i=0;i<4;i++) textureba[imarrp++]=pal[c1][i];
for (let i=0;i<4;i++) textureba[imarrp++]=pal[c2][i];
vrp++;
}
}
}
if (lut) lut+=16; else {lutpag+=2; lutpal+=2}
}
return new THREE.DataTexture( textureba, 8192, 256, THREE.RGBAFormat );
}
var texture,textureba,materialtex,materialtexst,materialtexsta,materialtexsts,sprites=[],
materialbasic=new THREE.MeshPhongMaterial({ color:0xFFFFFF, flatShading: true, side: (urlvars["ds"]=="y")?THREE.DoubleSide:THREE.FrontSide, vertexColors: THREE.FaceColors}), materialbasicst=new THREE.MeshPhongMaterial({ color:0xFFFFFF, flatShading: true, side: (urlvars["ds"]=="y")?THREE.DoubleSide:THREE.FrontSide, vertexColors: THREE.FaceColors, opacity: 0.5, transparent: true, depthWrite: false}),
materialbasicsta=new THREE.MeshPhongMaterial({ color:0xFFFFFF, flatShading: true, side: (urlvars["ds"]=="y")?THREE.DoubleSide:THREE.FrontSide, vertexColors: THREE.FaceColors, opacity: 1, blending: THREE.AdditiveBlending, transparent: true, depthWrite: false}),
materialbasicsts=new THREE.MeshPhongMaterial({ color:0xFFFFFF, flatShading: true, side: (urlvars["ds"]=="y")?THREE.DoubleSide:THREE.FrontSide, vertexColors: THREE.FaceColors, opacity: 1, blending: THREE.SubtractiveBlending, transparent: true, depthWrite: false});
function getscenario(pos) { //Returns the full level scenario
var group = new THREE.Group();
for (let i=0;i<parseInt(urlvars["gfxcount"]);i++) {
var elsize=(array8u[pos+23]==0x80)?24:32;
if (elsize==32 && array8u[pos+elsize-1]!=0x80) {
console.log("no more scenario elements from index "+i);
break;
}
var gfxo=games[urlvars["game"]].getgfxo(addtopos(array32u[pos+elsize-4>>2]));
if (gfxo==null) {
console.log("Error loading object "+postopsxe(addtopos(array32u[pos+elsize-4>>2]))+" at sceneobj "+postopsxe(pos));
pos+=elsize;
continue;
}
gfxo.ba=postopsxe(pos)+"("+postopsxe(addtopos(array32u[pos+elsize-4>>2]))+") -> "+[...array8u.slice(pos,pos+elsize)].map(x=>x.toString(16)).join(' '); //debug
gfxo.position.x=array32[pos>>2]*mult;
gfxo.position.y=array32[(pos+4)>>2]*mult;
gfxo.position.z=array32[(pos+8)>>2]*mult;
gfxo.rotation.x=array16[(pos+12)>>1]/2048*Math.PI;
gfxo.rotation.y=array16[(pos+14)>>1]/2048*Math.PI;
gfxo.rotation.z=array16[(pos+16)>>1]/2048*Math.PI;
if (elsize==32) {
if (array16u[(pos+18)>>1]|array16u[(pos+20)>>1]|array16u[(pos+22)>>1]) {
gfxo.scale.x=mult*array16[(pos+18)>>1]/4096;
gfxo.scale.y=mult*array16[(pos+20)>>1]/4096;
gfxo.scale.z=mult*array16[(pos+22)>>1]/4096;
} else {
gfxo.scale.x=mult; gfxo.scale.y=mult; gfxo.scale.z=mult;
console.log("scenario element at "+postopsxe(pos)+" is hidden");
}
} else {
gfxo.scale.x=mult; gfxo.scale.y=mult; gfxo.scale.z=mult;
}
group.add(gfxo);
pos+=elsize;
}
console.log("End reading scene objects at 0x"+postopsxe(pos));
return group;
}
function getgfxobugs(pos) {
var npoints=Math.abs(array32[pos>>2]);
var specialmat=(array32[pos>>2]<0); //Maybe reflective? not implemented
if (gfxoissprite(pos) && !specialmat) return getsprite(pos);
if (npoints>4096) {
console.log("object points too long! 0x"+postopsxe(pos));
return null;
}
if (array32u[(pos>>2)+npoints*3+1]==1) {
console.log("sprite scene object not implemented! 0x"+postopsxe(pos)); //ex: bugs lvl1 sceneobj 0xbf3ad8 (wall at finish)
return null;
}
pos+=4;
var points=new Array(npoints);
for (let i=0; i<npoints; i++) {
var point={};
point.x=array16[pos>>1]; pos+=2;
point.y=array16[pos>>1]; pos+=2;
point.z=array16[pos>>1]; pos+=2;
point.padding=array16[pos>>1]; pos+=2;
point.color=new THREE.Color(Math.sin(array8u[pos]/255*Math.PI/2),Math.sin(array8u[pos+1]/255*Math.PI/2),Math.sin(array8u[pos+2]/255*Math.PI/2)); pos+=3;
point.flag=array8u[pos++];
points[i]=point;
}
//console.log(points);
if (specialmat) pos+=(npoints)*6+(npoints%2)*2; //special mat data skip
var facestex=[],facesuntex=[];
while (array16u[pos>>1]!=0xFFFF) {
var flags=array8u[pos++];
var textmap=array8u[pos++];
var n=array16u[pos>>1]&0xFF;
if (array8u[pos+1]>=0xF0) {
console.log("object faces unknown val at 0x"+postopsxe(pos)+". "+(facestex.length+facesuntex.length)+" faces were read.");
return null;
}
pos+=2;
if (flags&16) for (let i=0; i<n; i++) { //untextured
var face={};
face.flags=flags;
face.textmap=textmap;
face.p1=array16u[pos>>1]/12; pos+=2;
face.p2=array16u[pos>>1]/12; pos+=2;
face.p3=array16u[pos>>1]/12; pos+=2;
if (!(flags&1)) {face.p4=array16u[pos>>1]/12; pos+=2;} //triangles
facesuntex.push(face);
} else for (let i=0; i<n; i++) { //textured
var face={};
face.flags=flags;
face.textmap=textmap;
face.p1=array16u[pos>>1]/12; pos+=2;
face.p2=array16u[pos>>1]/12; pos+=2;
face.p3=array16u[pos>>1]/12; pos+=2;
if (!(flags&1)) {face.p4=array16u[pos>>1]/12; pos+=2;} //triangles
if (!(flags&1)) {face.p1x=array8u[pos++]; face.p1y=array8u[pos++]; }
face.p2x=array8u[pos++]; face.p2y=array8u[pos++];
face.p3x=array8u[pos++]; face.p3y=array8u[pos++];
face.p4x=array8u[pos++]; face.p4y=array8u[pos++];
facestex.push(face);
}
}
//console.log(facestex); console.log(facesuntex);
return processVertexAndFaces(points,facestex,facesuntex,specialmat);
}
function getgfxots2(pos) {
var npoints=Math.abs(array32[pos>>2]);
var specialmat=(array32[pos>>2]<0); //Maybe reflective? not implemented
if (npoints>255) {
console.log("object points too long! 0x"+postopsxe(pos));
return null;
}
if (gfxoissprite(pos) && !specialmat) return getsprite(pos);
pos+=4;
var points=new Array(npoints);
function psxrgb(color) { //returns the THREE color from a 16bit point color
return new THREE.Color(Math.sin(((color>>10)&31)/62*Math.PI),Math.sin(((color>>5)&31)/62*Math.PI),Math.sin((color&31)/62*Math.PI));
}
for (let i=0; i<npoints; i++) {
var point={};
point.x=array16[pos>>1]; pos+=2;
point.y=array16[pos>>1]; pos+=2;
point.z=array16[pos>>1]; pos+=2;
point.color=psxrgb(array16[pos>>1]); pos+=2;
points[i]=point;
}
//console.log(points);
if (specialmat) pos+=(npoints+1)*4; //special mat data skip
var facestex=[],facesuntex=[];
while (array16u[pos>>1]!=0xFFFF) {
var flags=array8u[pos++];
var textmap=array8u[pos++];
var n=array16u[pos>>1]&0xFF;
if (array8u[pos+1]>=0xF0) {
console.log("object faces unknown val at 0x"+postopsxe(pos)+". "+(facestex.length+facesuntex.length)+" faces were read.");
return null;
}
pos+=2;
if (flags&16) for (let i=0; i<n; i++) { //untextured
var face={};
face.flags=flags;
face.textmap=textmap;
face.p1=array8u[pos++];
face.p2=array8u[pos++];
face.p3=array8u[pos++];
face.p4=array8u[pos++];
facesuntex.push(face);
} else for (let i=0; i<n; i++) { //textured
var face={};
face.flags=flags;
face.textmap=textmap;
face.p1=array8u[pos++];
face.p2=array8u[pos++];
face.p3=array8u[pos++];
face.p4=array8u[pos++];
face.p1x=array8u[pos++]; face.p1y=array8u[pos++];
face.p2x=array8u[pos++]; face.p2y=array8u[pos++];
face.p3x=array8u[pos++]; face.p3y=array8u[pos++];
face.p4x=array8u[pos++]; face.p4y=array8u[pos++];
facestex.push(face);
}
}
//console.log(facestex); console.log(facesuntex);
return processVertexAndFaces(points,facestex,facesuntex,specialmat);
}
function gfxoissprite(pos) {
const maxspp=4;
var nsprites=array32u[pos>>2];
pos+=12*nsprites+4;
for (let i=0;i<nsprites;i++) {
var count=array32u[pos>>2];
if (count==0 || count>maxspp) return false;
pos+=4+count*44;
}
return true;
}
function getsprite(pos) {
var nsprites=array32[pos>>2];
pos+=4;
var sobjs=new THREE.Group();
var sprs=new Array(nsprites);
for (let i=0;i<nsprites;i++) {sprs[i]={x:array32[pos>>2], y:array32[(pos>>2)+1], z:array32[(pos>>2)+2]};pos+=12;}
for (let i=0;i<nsprites;i++) {
var count=array32[pos>>2];
pos+=4;
for (let j=0;j<count;j++) {
var face={p1:0, p2:1, p3:2 ,p4:3};
var vertex=[{},{},{},{}];
vertex[0].x=array16[pos>>1]; pos+=2; vertex[0].y=array16[pos>>1]; pos+=2; vertex[0].z=0;
vertex[1].x=array16[pos>>1]; pos+=2; vertex[1].y=array16[pos>>1]; pos+=2; vertex[1].z=0;
vertex[2].x=array16[pos>>1]; pos+=2; vertex[2].y=array16[pos>>1]; pos+=2; vertex[2].z=0;
vertex[3].x=array16[pos>>1]; pos+=2; vertex[3].y=array16[pos>>1]; pos+=2; vertex[3].z=0;
face.pad=array16[pos>>1]; pos+=2;
face.textmap=array16[pos>>1]&0x1F; face.flags=array16[pos>>1]&0xE0|0x02; pos+=2;
face.p1x=array8u[pos++]; face.p1y=array8u[pos++];
face.p2x=array8u[pos++]; face.p2y=array8u[pos++];
face.p3x=array8u[pos++]; face.p3y=array8u[pos++];
face.p4x=array8u[pos++]; face.p4y=array8u[pos++];
vertex[0].color=new THREE.Color(Math.sin(array8u[pos]/255*Math.PI/2),Math.sin(array8u[pos+1]/255*Math.PI/2),Math.sin(array8u[pos+2]/255*Math.PI/2)); pos+=4;
vertex[1].color=new THREE.Color(Math.sin(array8u[pos]/255*Math.PI/2),Math.sin(array8u[pos+1]/255*Math.PI/2),Math.sin(array8u[pos+2]/255*Math.PI/2)); pos+=4;
vertex[2].color=new THREE.Color(Math.sin(array8u[pos]/255*Math.PI/2),Math.sin(array8u[pos+1]/255*Math.PI/2),Math.sin(array8u[pos+2]/255*Math.PI/2)); pos+=4;
vertex[3].color=new THREE.Color(Math.sin(array8u[pos]/255*Math.PI/2),Math.sin(array8u[pos+1]/255*Math.PI/2),Math.sin(array8u[pos+2]/255*Math.PI/2)); pos+=4;
var o=processVertexAndFaces(vertex,[face],[],false);
o.position.x=sprs[i].x; o.position.y=sprs[i].y; o.position.z=sprs[i].z;
sobjs.add(o);
}
}
sprites.push(sobjs);
return sobjs;
}
function processVertexAndFaces(points,facestex,facesuntex,specialmat) { //Same processing for TS2, BLSC, and Bugs
var geometrytex = new THREE.Geometry(), geometryuntex = new THREE.Geometry(), geometrytexst = new THREE.Geometry(), geometryuntexst = new THREE.Geometry(), geometrytexsta = new THREE.Geometry(), geometryuntexsta = new THREE.Geometry(), geometrytexsts = new THREE.Geometry(), geometryuntexsts = new THREE.Geometry();
points.forEach(p=>{
var v=new THREE.Vector3(p.x,p.y,p.z);
geometrytex.vertices.push(v); geometryuntex.vertices.push(v); geometrytexst.vertices.push(v); geometryuntexst.vertices.push(v); geometrytexsta.vertices.push(v); geometryuntexsta.vertices.push(v); geometrytexsts.vertices.push(v); geometryuntexsts.vertices.push(v);
});
facestex.forEach(f=>{
var geom=(((f.flags&0x20)&&(f.flags&0x40))||specialmat)?geometrytex:(f.flags&0x40)?geometrytexsts:(f.flags&0x20)?geometrytexsta:geometrytexst;
if (f.flags&0x01) { //triangles
var face=new THREE.Face3(f.p1,f.p2,f.p3);
face.vertexColors[0] = points[f.p1].color; face.vertexColors[1] = points[f.p2].color; face.vertexColors[2] = points[f.p3].color;
geom.faces.push(face);
geom.faceVertexUvs[0].push([
new THREE.Vector2(f.p2x/8192+(f.textmap&0x1F)*0.03125, 1-f.p2y/256-((f.p2y==f.p4y && f.p2y==f.p3y)?(1/256):0)),
new THREE.Vector2(f.p3x/8192+(f.textmap&0x1F)*0.03125, 1-f.p3y/256),
new THREE.Vector2(f.p4x/8192+(f.textmap&0x1F)*0.03125, 1-f.p4y/256)
]);
if (f.flags&0x02 && (urlvars["ds"]!="y")) { //doubleside
var face=new THREE.Face3(f.p3,f.p2,f.p1);
face.vertexColors[0] = points[f.p3].color; face.vertexColors[1] = points[f.p2].color; face.vertexColors[2] = points[f.p1].color;
geom.faces.push(face);
geom.faceVertexUvs[0].push([
new THREE.Vector2(f.p4x/8192+(f.textmap&0x1F)*0.03125, 1-f.p4y/256),
new THREE.Vector2(f.p3x/8192+(f.textmap&0x1F)*0.03125, 1-f.p3y/256),
new THREE.Vector2(f.p2x/8192+(f.textmap&0x1F)*0.03125, 1-f.p2y/256-((f.p2y==f.p4y && f.p2y==f.p3y)?(1/256):0))
]);
}
}
else { //quads
var face=new THREE.Face3(f.p4,f.p2,f.p3);
face.vertexColors[0] = points[f.p4].color; face.vertexColors[1] = points[f.p2].color; face.vertexColors[2] = points[f.p3].color;
geom.faces.push(face);
geom.faceVertexUvs[0].push([
new THREE.Vector2(f.p4x/8192+(f.textmap&0x1F)*0.03125, 1-f.p4y/256),
new THREE.Vector2(f.p2x/8192+(f.textmap&0x1F)*0.03125, 1-f.p2y/256-((f.p2y==f.p4y && f.p2y==f.p3y)?(1/256):0)),
new THREE.Vector2(f.p3x/8192+(f.textmap&0x1F)*0.03125, 1-f.p3y/256)
]);
face=new THREE.Face3(f.p4,f.p1,f.p2);
face.vertexColors[0] = points[f.p4].color; face.vertexColors[1] = points[f.p1].color; face.vertexColors[2] = points[f.p2].color;
geom.faces.push(face);
geom.faceVertexUvs[0].push([
new THREE.Vector2(f.p4x/8192+(f.textmap&0x1F)*0.03125, 1-f.p4y/256),
new THREE.Vector2(f.p1x/8192+(f.textmap&0x1F)*0.03125, 1-f.p1y/256),
new THREE.Vector2(f.p2x/8192+(f.textmap&0x1F)*0.03125, 1-f.p2y/256-((f.p2y==f.p4y && f.p2y==f.p3y)?(1/256):0))
]);
if (f.flags&0x02 && (urlvars["ds"]!="y")) { //doubleside
var face=new THREE.Face3(f.p3,f.p2,f.p4);
face.vertexColors[0] = points[f.p3].color; face.vertexColors[1] = points[f.p2].color; face.vertexColors[2] = points[f.p4].color;
geom.faces.push(face);
geom.faceVertexUvs[0].push([
new THREE.Vector2(f.p3x/8192+(f.textmap&0x1F)*0.03125, 1-f.p3y/256),
new THREE.Vector2(f.p2x/8192+(f.textmap&0x1F)*0.03125, 1-f.p2y/256-((f.p2y==f.p4y && f.p2y==f.p3y)?(1/256):0)),
new THREE.Vector2(f.p4x/8192+(f.textmap&0x1F)*0.03125, 1-f.p4y/256)
]);
face=new THREE.Face3(f.p2,f.p1,f.p4);
face.vertexColors[0] = points[f.p2].color; face.vertexColors[1] = points[f.p1].color; face.vertexColors[2] = points[f.p4].color;
geom.faces.push(face);
geom.faceVertexUvs[0].push([
new THREE.Vector2(f.p2x/8192+(f.textmap&0x1F)*0.03125, 1-f.p2y/256-((f.p2y==f.p4y && f.p2y==f.p3y)?(1/256):0)),
new THREE.Vector2(f.p1x/8192+(f.textmap&0x1F)*0.03125, 1-f.p1y/256),
new THREE.Vector2(f.p4x/8192+(f.textmap&0x1F)*0.03125, 1-f.p4y/256)
]);
}
}
});
facesuntex.forEach(f=>{
var geom=(((f.flags&0x20)&&(f.flags&0x40))||specialmat)?geometryuntex:(f.flags&0x40)?geometryuntexsts:(f.flags&0x20)?geometryuntexsta:geometryuntexst;
var face=new THREE.Face3(f.p1,f.p2,f.p3);
face.vertexColors[0] = points[f.p1].color; face.vertexColors[1] = points[f.p2].color; face.vertexColors[2] = points[f.p3].color;
geom.faces.push(face);
if (!(f.flags&0x01)) { //quads
face=new THREE.Face3(f.p1,f.p3,f.p4);
face.vertexColors[0] = points[f.p1].color; face.vertexColors[1] = points[f.p3].color; face.vertexColors[2] = points[f.p4].color;
geom.faces.push(face);
}
if (f.flags&0x02 && (urlvars["ds"]!="y")) { //doubleside
var face=new THREE.Face3(f.p3,f.p2,f.p1);
face.vertexColors[0] = points[f.p3].color; face.vertexColors[1] = points[f.p2].color; face.vertexColors[2] = points[f.p1].color;
geom.faces.push(face);
if (!(f.flags&0x01)) { //quads
face=new THREE.Face3(f.p4,f.p3,f.p1);
face.vertexColors[0] = points[f.p4].color; face.vertexColors[1] = points[f.p3].color; face.vertexColors[2] = points[f.p1].color;
geom.faces.push(face);
}
}
});
//geometrytex.computeFaceNormals();
//geometrytex.computeVertexNormals();
var group=new THREE.Group();
group.add(new THREE.Mesh( geometrytex, materialtex));
group.add(new THREE.Mesh( geometryuntex, materialbasic));
group.add(new THREE.Mesh( geometrytexst, materialtexst));
group.add(new THREE.Mesh( geometryuntexst, materialbasicst));
group.add(new THREE.Mesh( geometrytexsta, materialtexsta));
group.add(new THREE.Mesh( geometryuntexsta, materialbasicsta));
group.add(new THREE.Mesh( geometrytexsts, materialtexsts));
group.add(new THREE.Mesh( geometryuntexsts, materialbasicsts));
return group;
}
function loaded() {
document.getElementById("progresscontainer").style.display="none";
window.addEventListener( 'resize', onWindowResize, false );
texture = getPalTextures();
texture.flipY=true; texture.flipX=true;
//texture.magFilter=THREE.LinearFilter;
texture.needsUpdate=true;
materialtex=new THREE.MeshBasicMaterial({
side: (urlvars["ds"]=="y")?THREE.DoubleSide:THREE.FrontSide, map: texture,
wireframe: false, alphaTest:0.5,
vertexColors: THREE.FaceColors
});
materialtexst=new THREE.MeshBasicMaterial({
side: (urlvars["ds"]=="y")?THREE.DoubleSide:THREE.FrontSide, map: texture,
wireframe: false, transparent:true,
vertexColors: THREE.FaceColors, opacity: 0.5, depthWrite: false
});
materialtexsta=new THREE.MeshBasicMaterial({
side: (urlvars["ds"]=="y")?THREE.DoubleSide:THREE.FrontSide, map: texture,
wireframe: false, transparent:true,
vertexColors: THREE.FaceColors, opacity: 1, blending: THREE.AdditiveBlending, depthWrite: false
});
materialtexsts=new THREE.MeshBasicMaterial({
side: (urlvars["ds"]=="y")?THREE.DoubleSide:THREE.FrontSide, map: texture,
wireframe: false, transparent:true,
vertexColors: THREE.FaceColors, opacity: 1, blending: THREE.SubtractiveBlending, depthWrite: false
});
//scene.background=texture; //Debug palette
var bgMesh=null;
var bkgtex=getBackgroundTexture();
bkgtex.needsUpdate=true;
const shader = THREE.ShaderLib.equirect;
const material = new THREE.ShaderMaterial({
fragmentShader: shader.fragmentShader,
vertexShader: shader.vertexShader,
uniforms: shader.uniforms,
depthWrite: false,
side: THREE.BackSide,
});
material.uniforms.tEquirect.value = bkgtex;
const plane = new THREE.BoxBufferGeometry(10000, 10000, 10000);
bgMesh = new THREE.Mesh(plane, material);
scene.add(bgMesh);
//scene.background=bkgtex;
//var model=getgfxots2(psxetopos(0x00B6AB84));
var model=getscenario(psxetopos(parseInt(urlvars["gfxpointer"])));
scene.add(model);
document.addEventListener( 'mousedown', onDocumentMouseDown, false );
camera.position.x=0; camera.position.y=-15; camera.position.z=0;
camera.rotation.x=0.5; camera.rotation.y=-1; camera.rotation.z=3.5;
var controls = new THREE.FlyControls( camera, renderer.domElement );
var t=performance.now();
var animate = function () {
requestAnimationFrame( animate );
var newt=performance.now();
controls.update(newt-t);
t=newt;
bgMesh.position.copy(camera.position);
sprites.forEach(g=>g.children.forEach(s=>{
var d=[s.parent.position.x-camera.position.x,s.parent.position.z-camera.position.z];
var angle=Math.atan(d[0]/d[1]);
if (d[1]>0) angle+=Math.PI;
s.rotation.y=angle-s.parent.rotation.y;
}));
renderer.render( scene, camera );
};
animate();
}
</script>
</body>
</html>