Skip to content

Commit

Permalink
Moved over to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
ameliemaia committed Mar 2, 2017
1 parent 68b9b24 commit 2ed634e
Show file tree
Hide file tree
Showing 110 changed files with 1,782 additions and 1,395 deletions.
18 changes: 0 additions & 18 deletions .babelrc
Expand Up @@ -2,23 +2,5 @@
"presets": [
"es2015",
"stage-0"
],
"plugins": [
["module-resolver", {
"root": ["./src"],
"alias": {
"controls": "./controls",
"core": "./core",
"extras": "./extras",
"geometry": "./geometry",
"helpers": "./helpers",
"lights": "./lights",
"loaders": "./loaders",
"materials": "./materials",
"math": "./math",
"shaders": "./shaders",
"utils": "./utils"
}
}]
]
}
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

5 changes: 3 additions & 2 deletions .gitignore
Expand Up @@ -4,5 +4,6 @@ npm-debug.log
.eslintcache
*.js.map
lib
/examples/js/*.js
/examples/*.html

examples/js/*.js
examples/*.html
1 change: 1 addition & 0 deletions examples/files.json
Expand Up @@ -18,6 +18,7 @@
"texture",
"texturecube",
"texturevideo",
"transformfeedback",
"vive",
"webglcontext"
]
Expand Down
9 changes: 6 additions & 3 deletions examples/src/js/fullscreen/index.js
Expand Up @@ -3,11 +3,12 @@ import {
Renderer,
Scene,
OrthographicCamera,
PerspectiveCamera,
Mesh,
Shader,
PlaneGeometry,
} from 'index';
import { guiController } from '../gui';
} from '../../../../src/index';
const { guiController } = require('../gui')();

// Renderer
const renderer = new Renderer({
Expand All @@ -21,10 +22,12 @@ document.body.appendChild(renderer.canvas);
const scene = new Scene();

// Camera
// const camera = new PerspectiveCamera();
const camera = new OrthographicCamera();
camera.position.set(0, 0, 1);
camera.lookAt();

const geometry = new PlaneGeometry(1, 1);
const geometry = new PlaneGeometry(2, 2);
const material = new Shader({
name: 'Plane',
hookFragmentEnd: GL.webgl2 ?
Expand Down
25 changes: 15 additions & 10 deletions examples/src/js/gui.js
Expand Up @@ -4,17 +4,22 @@ import queryString from 'query-string';
const gui = new dat.GUI();
// dat.GUI.toggleHide();

const options = ['webgl2', 'webgl'];
module.exports = function (modes) {
const options = modes !== undefined ? modes : ['webgl2', 'webgl'];

const queries = queryString.parse(location.search);
const queries = queryString.parse(location.search);

export const guiController = {
context: queries.context || options[0],
};
const guiController = {
context: queries.context || options[0],
};

gui.add(guiController, 'context', options).onChange(val => {
const url = `${window.location.pathname}?context=${val}`;
window.location.href = url;
});
gui.add(guiController, 'context', options).onChange(val => {
const url = `${window.location.pathname}?context=${val}`;
window.location.href = url;
});

export default gui;
return {
gui,
guiController,
};
}
14 changes: 3 additions & 11 deletions examples/src/js/hdr/index.js
Expand Up @@ -10,10 +10,8 @@ import {
OrbitControls,
AxisHelper,
Texture,
} from 'index';
import gui, {
guiController
} from '../gui';
} from '../../../../src/index';
const { gui, guiController } = require('../gui')(['webgl2']);

// Renderer
const renderer = new Renderer({
Expand All @@ -35,17 +33,11 @@ camera.position.set(10, 5, 10);
camera.lookAt();

// Objects
let colors = [];
colors = colors.concat([1, 0, 0]);
colors = colors.concat([0, 1, 0]);
colors = colors.concat([0, 0, 1]);
colors = colors.concat([1, 1, 0]);

const texture0 = new Texture({
src: '/assets/textures/cube/pisa-hdr/nx.hdr',
});

const geometry = new PlaneGeometry(1, 1, colors);
const geometry = new PlaneGeometry(1, 1);
const material = new Shader({
name: 'Plane',
hookFragmentPre: `
Expand Down
14 changes: 2 additions & 12 deletions examples/src/js/hdrcube/index.js
Expand Up @@ -3,20 +3,14 @@ import {
Renderer,
Scene,
PerspectiveCamera,
// AxisHelper,
// GridHelper,
OrbitControls,
SphereGeometry,
Shader,
Mesh,
TextureCube,
ShaderChunks,
// BoxGeometry,
BoxGeometry,
} from 'index';
import gui, {
guiController
} from '../gui';
} from '../../../../src/index';
const { gui, guiController } = require('../gui')(['webgl2']);

// Renderer
const renderer = new Renderer({
Expand All @@ -39,10 +33,6 @@ camera.lookAt();

// Helpers
const controls = new OrbitControls(camera, renderer.canvas);
// const grid = new GridHelper(10);
// scene.add(grid);
// const axis = new AxisHelper(1);
// scene.add(axis);
controls.update();

const environmentMap = new TextureCube({
Expand Down
23 changes: 3 additions & 20 deletions examples/src/js/instancing/index.js
Expand Up @@ -6,21 +6,17 @@ import {
Mesh,
Shader,
BoxGeometry,
GridHelper,
OrbitControls,
AxisHelper,
Color,
DirectionalLight,
ShaderChunks,
Lights,
} from 'index';
} from '../../../../src/index';
import {
Sierpinski,
jerusalem,
} from '../fractal';
import gui, {
guiController
} from '../gui';
const { gui, guiController } = require('../gui')();

// Renderer
const renderer = new Renderer({
Expand All @@ -39,19 +35,12 @@ const camera = new PerspectiveCamera({
far: 500,
});

const s = 2;
camera.position.set(20 * s, 5 * s, 20 * s);
camera.position.set(0, 0, 50);
camera.lookAt();

// Helpers
const controls = new OrbitControls(camera, renderer.canvas);

// const grid = new GridHelper(10);
// scene.add(grid);

// const axis = new AxisHelper(1);
// scene.add(axis);

controls.update();

// Content
Expand Down Expand Up @@ -154,12 +143,6 @@ scene.add(mesh);

gui.add(mesh.shader.uniforms.uFogDensity, 'value', 0, 0.1);

const grid = new GridHelper(10);
scene.add(grid);

const axis = new AxisHelper(1);
scene.add(axis);

function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
Expand Down
6 changes: 2 additions & 4 deletions examples/src/js/memory/index.js
Expand Up @@ -8,10 +8,8 @@ import {
BoxGeometry,
OrbitControls,
Texture,
} from 'index';
import {
guiController
} from '../gui';
} from '../../../../src/index';
const { guiController } = require('../gui')();

// Renderer
const renderer = new Renderer({
Expand Down
6 changes: 2 additions & 4 deletions examples/src/js/obj/index.js
Expand Up @@ -10,10 +10,8 @@ import {
Lights,
Color,
PointLight,
} from 'index';
import {
guiController
} from '../gui';
} from '../../../../src/index';
const { guiController } = require('../gui')();

// Renderer
const renderer = new Renderer({
Expand Down
6 changes: 2 additions & 4 deletions examples/src/js/pbr/index.js
Expand Up @@ -17,10 +17,8 @@ import {
// BoxGeometry,
Lights,
DirectionalLight,
} from 'index';
import gui, {
guiController
} from '../gui';
} from '../../../../src/index';
const { gui, guiController } = require('../gui')(['webgl2']);
import { hookFragmentPre, hookFragmentMain } from './shader.glsl';

// Renderer
Expand Down
2 changes: 1 addition & 1 deletion examples/src/js/pbr/shader.glsl.js
@@ -1,4 +1,4 @@
import { ShaderChunks } from 'index';
import { ShaderChunks } from '../../../../src/index';

export const hookFragmentPre = `
in vec3 vReflect;
Expand Down
6 changes: 2 additions & 4 deletions examples/src/js/pointlights/index.js
Expand Up @@ -11,10 +11,8 @@ import {
PointLight,
Color,
Lights,
} from 'index';
import {
guiController
} from '../gui';
} from '../../../../src/index';
const { guiController } = require('../gui')();

// Renderer
const renderer = new Renderer({
Expand Down
21 changes: 13 additions & 8 deletions examples/src/js/points/index.js
Expand Up @@ -11,10 +11,8 @@ import {
Mesh,
Shader,
Constants,
} from 'index';
import {
guiController
} from '../gui';
} from '../../../../src/index';
const { guiController } = require('../gui')();

// Renderer
const renderer = new Renderer({
Expand Down Expand Up @@ -46,9 +44,9 @@ const axis = new AxisHelper(1);
scene.add(axis);

// Objects
const TOTAL_POINTS = 1000;
const TOTAL_POINTS = 200;
const bufferVertices = new Float32Array(TOTAL_POINTS * 3);
const range = 10;
const range = 3;

let i3 = 0;
for (let i = 0; i < TOTAL_POINTS; i += 1) {
Expand All @@ -61,20 +59,27 @@ for (let i = 0; i < TOTAL_POINTS; i += 1) {
const geometry = new Geometry(bufferVertices);

const hookVertexEndEs300 = `
vec4 mvPosition = uProjectionView.viewMatrix * uModelMatrix * vec4(aVertexPosition + transformed, 1.0);
vec4 mvPosition = uProjectionView.projectionMatrix * uProjectionView.viewMatrix * uModelMatrix * vec4(aVertexPosition + transformed, 1.0);
gl_PointSize = uSize * (100.0 / length(mvPosition.xyz));
`;

const hookVertexEndEs100 = `
vec4 mvPosition = uViewMatrix * uModelMatrix * vec4(aVertexPosition + transformed, 1.0);
vec4 mvPosition = uProjectionMatrix * uViewMatrix * uModelMatrix * vec4(aVertexPosition + transformed, 1.0);
gl_PointSize = uSize * (100.0 / length(mvPosition.xyz));
`;

const hookFragmentEndEs300 = `
if(length(gl_PointCoord - 0.5) > 0.5) {
discard;
}
outputColor = vec4(1.0);
`;

const hookFragmentEndEs100 = `
if(length(gl_PointCoord - 0.5) > 0.5) {
discard;
}
gl_FragColor = vec4(1.0);
`;

Expand Down
6 changes: 2 additions & 4 deletions examples/src/js/raycast/index.js
Expand Up @@ -15,13 +15,11 @@ import {
SphereGeometry,
BoxGeometry,
Lights,
} from 'index';
} from '../../../../src/index';
import {
vec2,
} from 'gl-matrix';
import {
guiController,
} from '../gui';
const { guiController } = require('../gui')();

// Renderer
const renderer = new Renderer({
Expand Down
8 changes: 3 additions & 5 deletions examples/src/js/rendertarget/index.js
Expand Up @@ -12,10 +12,8 @@ import {
PlaneGeometry,
OrthographicCamera,
ShaderChunks,
} from 'index';
import {
guiController
} from '../gui';
} from '../../../../src/index';
const { guiController } = require('../gui')();

// Renderer
const renderer = new Renderer({
Expand Down Expand Up @@ -103,7 +101,7 @@ const material = new Shader({
`,
});

const plane = new Mesh(new PlaneGeometry(1, 1), material);
const plane = new Mesh(new PlaneGeometry(2, 2), material);
scene2.add(plane);

function resize() {
Expand Down

0 comments on commit 2ed634e

Please sign in to comment.