Skip to content
Permalink
Browse files

Add zelview support

  • Loading branch information...
magcius committed Oct 30, 2016
1 parent 73d8c00 commit b665ef2ccff623997f7bfee844ac19cd4a4fa93c
Showing with 3,952 additions and 45 deletions.
  1. +13 −0 .vscode/launch.json
  2. +1 −2 .vscode/settings.json
  3. +1,860 −17 build/main.js
  4. +1 −1 build/main.js.map
  5. +2 −0 src/main.ts
  6. +10 −22 src/sm64ds/render.ts
  7. +1 −1 src/sm64ds/scenes.ts
  8. +16 −0 src/util.ts
  9. +4 −2 src/viewer.ts
  10. +867 −0 src/zelview/f3dex2.ts
  11. +307 −0 src/zelview/render.ts
  12. +452 −0 src/zelview/scenes.ts
  13. +418 −0 src/zelview/zelview0.ts
@@ -0,0 +1,13 @@
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch index.html",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8000/index.html",
"webRoot": "${workspaceRoot}",
"sourceMaps": true
}
]
}
@@ -1,7 +1,6 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"**/*.js.map": true,
"**/*.js": true
"**/*.js.map": true
}
}

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,6 +1,7 @@

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

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

// The "plugin" part of this.
this.groups.push(SM64DS.sceneGroup);
this.groups.push(ZELVIEW.sceneGroup);

this.makeUI();
}
@@ -5,8 +5,9 @@ import * as LZ77 from 'lz77';
import * as Viewer from 'viewer';
import * as NITRO_BMD from './nitro_bmd';
import * as NITRO_GX from './nitro_gx';
import { fetch } from 'util';

var DL_VERT_SHADER_SOURCE = `
const DL_VERT_SHADER_SOURCE = `
precision mediump float;
uniform mat4 u_modelView;
uniform mat4 u_localMatrix;
@@ -25,7 +26,7 @@ var DL_VERT_SHADER_SOURCE = `
}
`;

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

// 3 pos + 4 color + 2 uv
var VERTEX_SIZE = 9;
var VERTEX_BYTES = VERTEX_SIZE * Float32Array.BYTES_PER_ELEMENT;
const VERTEX_SIZE = 9;
const VERTEX_BYTES = VERTEX_SIZE * Float32Array.BYTES_PER_ELEMENT;

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

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

window.mat4.scale(localMatrix, localMatrix, [bmd.scaleFactor, bmd.scaleFactor, bmd.scaleFactor]);
// Local fudge factor so that all the models in the viewer "line up".
const localScaleFactor = 100;
const scaleFactor = bmd.scaleFactor * localScaleFactor;

window.mat4.scale(localMatrix, localMatrix, [scaleFactor, scaleFactor, scaleFactor]);
const batches = bmdm.batches.map((batch) => this.translateBatch(gl, batch));
return (pass:RenderPass) => {
gl.uniformMatrix4fv(this.program.localMatrixLocation, false, localMatrix);
@@ -229,22 +233,6 @@ class Scene implements Viewer.Scene {
}
}

function fetch(path):PromiseLike<ArrayBuffer> {
var request = new XMLHttpRequest();
request.open("GET", path, true);
request.responseType = "arraybuffer";
request.send();

return new window.Promise((resolve, reject) => {
request.onload = () => {
resolve(request.response);
};
request.onerror = () => {
reject();
};
});
}

export class SceneDesc implements Viewer.SceneDesc {
name:string;
path:string;
@@ -53,7 +53,7 @@ const sceneDescs:SceneDesc[] = [
'water_city_all.bmd',
'water_land_all.bmd',
].map((filename:string):SceneDesc => {
const path = 'data/sm64ds/' + filename;
const path = `data/sm64ds/${filename}`;
return new SceneDesc(filename, path);
});

@@ -0,0 +1,16 @@

export function fetch(path):PromiseLike<ArrayBuffer> {
var request = new XMLHttpRequest();
request.open("GET", path, true);
request.responseType = "arraybuffer";
request.send();

return new window.Promise((resolve, reject) => {
request.onload = () => {
resolve(request.response);
};
request.onerror = () => {
reject();
};
});
}
@@ -19,7 +19,7 @@ function compileShader(gl:WebGLRenderingContext, str:string, type:number) {

if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
console.error(gl.getShaderInfoLog(shader));
return null;
throw new Error();
}

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

export class RenderState {
gl:WebGLRenderingContext;
viewport:Viewport;
currentProgram:Program = null;

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

constructor(viewport:Viewport) {
this.viewport = viewport;
this.gl = this.viewport.gl;

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

var mult = .1;
var mult = 10;
if (keysDown[SHIFT])
mult *= 5;
mult *= (dt / 16.0);
Oops, something went wrong.

0 comments on commit b665ef2

Please sign in to comment.
You can’t perform that action at this time.