Skip to content

Commit b665ef2

Browse files
committed
Add zelview support
1 parent 73d8c00 commit b665ef2

13 files changed

Lines changed: 3952 additions & 45 deletions

File tree

.vscode/launch.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "0.1.0",
3+
"configurations": [
4+
{
5+
"name": "Launch index.html",
6+
"type": "chrome",
7+
"request": "launch",
8+
"url": "http://localhost:8000/index.html",
9+
"webRoot": "${workspaceRoot}",
10+
"sourceMaps": true
11+
}
12+
]
13+
}

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Place your settings in this file to overwrite default and user settings.
22
{
33
"files.exclude": {
4-
"**/*.js.map": true,
5-
"**/*.js": true
4+
"**/*.js.map": true
65
}
76
}

build/main.js

Lines changed: 1860 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import { Viewer, Scene, SceneDesc, SceneGroup } from 'viewer';
33
import * as SM64DS from 'sm64ds/scenes';
4+
import * as ZELVIEW from 'zelview/scenes';
45

56
export class Main {
67
viewer:Viewer;
@@ -15,6 +16,7 @@ export class Main {
1516

1617
// The "plugin" part of this.
1718
this.groups.push(SM64DS.sceneGroup);
19+
this.groups.push(ZELVIEW.sceneGroup);
1820

1921
this.makeUI();
2022
}

src/sm64ds/render.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import * as LZ77 from 'lz77';
55
import * as Viewer from 'viewer';
66
import * as NITRO_BMD from './nitro_bmd';
77
import * as NITRO_GX from './nitro_gx';
8+
import { fetch } from 'util';
89

9-
var DL_VERT_SHADER_SOURCE = `
10+
const DL_VERT_SHADER_SOURCE = `
1011
precision mediump float;
1112
uniform mat4 u_modelView;
1213
uniform mat4 u_localMatrix;
@@ -25,7 +26,7 @@ var DL_VERT_SHADER_SOURCE = `
2526
}
2627
`;
2728

28-
var DL_FRAG_SHADER_SOURCE = `
29+
const DL_FRAG_SHADER_SOURCE = `
2930
precision mediump float;
3031
varying vec2 v_uv;
3132
varying vec4 v_color;
@@ -61,8 +62,8 @@ class NITRO_Program extends Viewer.Program {
6162
}
6263

6364
// 3 pos + 4 color + 2 uv
64-
var VERTEX_SIZE = 9;
65-
var VERTEX_BYTES = VERTEX_SIZE * Float32Array.BYTES_PER_ELEMENT;
65+
const VERTEX_SIZE = 9;
66+
const VERTEX_BYTES = VERTEX_SIZE * Float32Array.BYTES_PER_ELEMENT;
6667

6768
enum RenderPass {
6869
OPAQUE = 0x01,
@@ -95,7 +96,6 @@ class Texture implements Viewer.Texture {
9596
}
9697

9798
class Scene implements Viewer.Scene {
98-
path:string;
9999
textures:Viewer.Texture[];
100100
modelFuncs:Function[];
101101
program:NITRO_Program;
@@ -199,7 +199,11 @@ class Scene implements Viewer.Scene {
199199
const localMatrix = window.mat4.create();
200200
const bmd = this.bmd;
201201

202-
window.mat4.scale(localMatrix, localMatrix, [bmd.scaleFactor, bmd.scaleFactor, bmd.scaleFactor]);
202+
// Local fudge factor so that all the models in the viewer "line up".
203+
const localScaleFactor = 100;
204+
const scaleFactor = bmd.scaleFactor * localScaleFactor;
205+
206+
window.mat4.scale(localMatrix, localMatrix, [scaleFactor, scaleFactor, scaleFactor]);
203207
const batches = bmdm.batches.map((batch) => this.translateBatch(gl, batch));
204208
return (pass:RenderPass) => {
205209
gl.uniformMatrix4fv(this.program.localMatrixLocation, false, localMatrix);
@@ -229,22 +233,6 @@ class Scene implements Viewer.Scene {
229233
}
230234
}
231235

232-
function fetch(path):PromiseLike<ArrayBuffer> {
233-
var request = new XMLHttpRequest();
234-
request.open("GET", path, true);
235-
request.responseType = "arraybuffer";
236-
request.send();
237-
238-
return new window.Promise((resolve, reject) => {
239-
request.onload = () => {
240-
resolve(request.response);
241-
};
242-
request.onerror = () => {
243-
reject();
244-
};
245-
});
246-
}
247-
248236
export class SceneDesc implements Viewer.SceneDesc {
249237
name:string;
250238
path:string;

src/sm64ds/scenes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const sceneDescs:SceneDesc[] = [
5353
'water_city_all.bmd',
5454
'water_land_all.bmd',
5555
].map((filename:string):SceneDesc => {
56-
const path = 'data/sm64ds/' + filename;
56+
const path = `data/sm64ds/${filename}`;
5757
return new SceneDesc(filename, path);
5858
});
5959

src/util.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
export function fetch(path):PromiseLike<ArrayBuffer> {
3+
var request = new XMLHttpRequest();
4+
request.open("GET", path, true);
5+
request.responseType = "arraybuffer";
6+
request.send();
7+
8+
return new window.Promise((resolve, reject) => {
9+
request.onload = () => {
10+
resolve(request.response);
11+
};
12+
request.onerror = () => {
13+
reject();
14+
};
15+
});
16+
}

src/viewer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function compileShader(gl:WebGLRenderingContext, str:string, type:number) {
1919

2020
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
2121
console.error(gl.getShaderInfoLog(shader));
22-
return null;
22+
throw new Error();
2323
}
2424

2525
return shader;
@@ -56,6 +56,7 @@ export class Program {
5656
}
5757

5858
export class RenderState {
59+
gl:WebGLRenderingContext;
5960
viewport:Viewport;
6061
currentProgram:Program = null;
6162

@@ -64,6 +65,7 @@ export class RenderState {
6465

6566
constructor(viewport:Viewport) {
6667
this.viewport = viewport;
68+
this.gl = this.viewport.gl;
6769

6870
this.projection = window.mat4.create();
6971
window.mat4.perspective(this.projection, Math.PI / 4, viewport.canvas.width / viewport.canvas.height, 0.2, 50000);
@@ -185,7 +187,7 @@ export class Viewer {
185187
var dt = nt - t;
186188
t = nt;
187189

188-
var mult = .1;
190+
var mult = 10;
189191
if (keysDown[SHIFT])
190192
mult *= 5;
191193
mult *= (dt / 16.0);

0 commit comments

Comments
 (0)