Skip to content

Commit

Permalink
feat: add descriptions to example.json files and complete coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhouston committed Jul 6, 2020
1 parent 4dc51e6 commit f99e8fe
Show file tree
Hide file tree
Showing 21 changed files with 147 additions and 33 deletions.
64 changes: 45 additions & 19 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import process from "process";
program
.name("build")
.option("-r, --rootDir <dirpath>", "the root of the source directory tree")
.option("-s, --sourceDir <dirpath>", "the typescript source directory tree")
.option("-g, --glob <glob>", "the search within the source directory")
.option("-o, --outDir <dirpath>", "the root of the output directory tree")
.option("-m, --minify", "minify the code")
Expand Down Expand Up @@ -44,40 +45,65 @@ async function transpile() {
return asyncCommandLine(`yarn tgt ${program.minify ? "--minify" : ""}`);
}

function fileSize( filePath) {
return fs.statSync(filePath).size;
}

async function main() {
await transpile();
const globRegex = `${program.rootDir}/${program.glob}`;
glob(globRegex, {}, function (er, sourceFileNames) {
sourceFileNames.forEach(async (sourceFileName) => {
const sourceDirectory = path.dirname(sourceFileName);
const outputDirectory = sourceDirectory.replace(program.rootDir, program.outDir);
glob(globRegex, {}, function (er, inputFileNames) {
inputFileNames.forEach(async (inputFileName) => {
const inputDirectory = path.dirname(inputFileName);
const outputDirectory = inputDirectory.replace(program.rootDir, program.outDir);
const sourceDirectory = inputDirectory.replace(program.rootDir, program.sourceDir);

const extension = path.extname(inputFileName);
const baseName = path.basename(inputFileName, extension);
const bundledFileName = `${outputDirectory}/${baseName}.rollup${extension}`;
const minifiedFileName = `${outputDirectory}/${baseName}${extension}`;


const sourceExtension = path.extname(sourceFileName);
const sourceBaseName = path.basename(sourceFileName, sourceExtension);
const bundledFileName = `${outputDirectory}/${sourceBaseName}.rollup${sourceExtension}`;
const minifiedFileName = `${outputDirectory}/${sourceBaseName}${sourceExtension}`;
//const outputFileName = `${outputDirectory}/${sourceBaseName}.${sourceExtension}`;
if (!fs.existsSync(outputDirectory)) {
makeDir.sync(outputDirectory);
}
await bundle(sourceFileName, bundledFileName);
sourceFileName = bundledFileName;
if (program.minify) {
await minify(sourceFileName, minifiedFileName);
fs.unlinkSync(sourceFileName);
sourceFileName = minifiedFileName;
await bundle(inputFileName, bundledFileName);
const bundledFileSize = fileSize( bundledFileName);
inputFileName = bundledFileName;
let minifiedFileSize = undefined;
if (program.minify) {
await minify(inputFileName, minifiedFileName);
fs.unlinkSync(inputFileName);
inputFileName = minifiedFileName;
minifiedFileSize = fileSize( minifiedFileName);
} else {
fs.renameSync(sourceFileName, minifiedFileName);
fs.renameSync(inputFileName, minifiedFileName);
}

const compressedFileName = sourceFileName + ".br";
const compressedFileName = inputFileName + ".br";
if (fs.existsSync(compressedFileName)) {
fs.unlinkSync(sourceFileName + ".br");
fs.unlinkSync(compressedFileName);
}

let compressedFileSize = undefined;
if (program.compress) {
await compress(sourceFileName);
await compress(inputFileName);
compressedFileSize = fileSize( inputFileName + '.br');
}

const sourceJson = './' + path.join( sourceDirectory, 'example.json');
if( fs.existsSync( sourceJson ) ) {
const outputJson = path.join( './' + outputDirectory, 'example.json');
const json = JSON.parse( fs.readFileSync( sourceJson ) );
json.bundleSize = bundledFileSize;
if( minifiedFileSize !== undefined ) {
json.minifiedSize = minifiedFileSize;
}
if( compressedFileSize ) {
json.compressedFileSize = compressedFileSize;
}
fs.writeFileSync( outputJson, JSON.stringify( json ) );
}
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"scripts": {
"build": "tgt & tsc",
"build-examples": "node --experimental-modules build.mjs -g **/index.js -r ./dist -o ./www -m -c -v 0",
"build-examples": "node --experimental-modules build.mjs -g **/index.js -s ./lib -r ./dist -o ./www -m -c -v 0",
"dev": "npm run watch & npm start",
"lint": "eslint ./src/",
"start": "es-dev-server --node-resolve --watch",
Expand Down
2 changes: 1 addition & 1 deletion src/examples/brdfs/01_lambert/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"slug": "brdf_lambertian",
"en": {
"name": "Lambertian Diffuse BRDF",
"description": "",
"description": "A test of the Lambertian diffuse BRDF in isolation.",
"keywords": [ "brdf", "lambert", "lambertian", "diffuse" ]
}
}
2 changes: 1 addition & 1 deletion src/examples/brdfs/02_specular/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"slug": "brdf_specular_ggx",
"en": {
"name": "GGX Specular BRDF",
"description": "",
"description": "A test of the GGX specular BRDF layered on top of the Lambertian diffuse BRDF.",
"keywords": [ "brdf", "specular", "ggx", "reflection" ]
}
}
2 changes: 1 addition & 1 deletion src/examples/brdfs/03_specularAnisotropic/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"slug": "brdf_specular_ggx_anisotropic",
"en": {
"name": "GGX Specular Anisotropic BRDF",
"description": "",
"description": "A test of the GGX specular BRDF modified via a bend normal to simulate anisotropy layered on top of the Lambertian diffuse BRDF. Anisotropy is specified via a flow map.",
"keywords": [ "brdf", "specular", "ggx", "reflection", "anisotropic" ]
}
}
4 changes: 2 additions & 2 deletions src/examples/brdfs/04_normals/example.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"slug": "microgeometry_normals",
"slug": "normal_map_microgeometry",
"en": {
"name": "Normal Map Microgeometry",
"description": "",
"description": "A normal map is used to simulate microgeometry that is not represented in the mesh. This is a smooth sphere where the normal map adds the golf ball dimples.",
"keywords": [ "microgeometry", "normal", "map", "perturbation", "mapping" ]
}
}
6 changes: 3 additions & 3 deletions src/examples/brdfs/05_bump/example.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"slug": "microgeometry_bump",
"slug": "height_map_microgeometry",
"en": {
"name": "Bump Map Microgeometry",
"description": "",
"name": "Height Map Microgeometry",
"description": "A height map is used to simulate microgeometry that is not represented in the mesh. When the height map only affects lighting, but not geometry, it is called bump mapping. This is a box sphere where the height map adds the brick shapes.",
"keywords": [ "microgeometry", "bump", "map", "perturbation", "mapping" ]
}
}
2 changes: 1 addition & 1 deletion src/examples/brdfs/06_clearcoat/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"slug": "brdf_clear_coat_specular",
"en": {
"name": "Clear Coat Specular BRDF",
"description": "",
"description": "A test of a clear coat GGX specular lobe BRDF with separate a distinct normal map layered on top of a standard GGX specular BRDF.",
"keywords": [ "brdf", "specular", "clearcoat", "reflection" ]
}
}
2 changes: 1 addition & 1 deletion src/examples/brdfs/07_sheen/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"slug": "brdf_sheen",
"en": {
"name": "Sheen BRDF",
"description": "",
"description": "A test of a Charlie-based Sheen BRDF. Sheen is useful rendering realistic cloth.",
"keywords": [ "brdf", "sheen", "fabric", "cloth" ]
}
}
6 changes: 3 additions & 3 deletions src/examples/brdfs/08_displacement/example.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"slug": "microgeometry_displacement",
"slug": "height_map_microgeometry_displacement",
"en": {
"name": "Displacement Map Microgeometry",
"description": "",
"name": "Height Map-based Displacement",
"description": "A height map is used to displace the positions of the mesh in the normal direction in an animated fashion. A normal map is also blended in and out in time to simulation a morphing effect.",
"keywords": [ "microgeometry", "displacement", "map", "perturbation", "mapping" ]
}
}
8 changes: 8 additions & 0 deletions src/examples/gettingstarted/01_triangle/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slug": "getting_started_drawing_geometry",
"en": {
"name": "Getting Started - Drawing Geometry",
"description": "A bare-bones test of drawing geometry directly.",
"keywords": [ "basics", "geometry", "direct" ]
}
}
8 changes: 8 additions & 0 deletions src/examples/gettingstarted/02_animatedUniforms/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slug": "getting_started_animated_uniforms",
"en": {
"name": "Getting Started - Animated Uniforms",
"description": "A simple test of animated uniforms.",
"keywords": [ "basics", "uniforms", "direct" ]
}
}
8 changes: 8 additions & 0 deletions src/examples/gettingstarted/03_texturedPlane/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slug": "getting_started_textured_plane",
"en": {
"name": "Getting Started - Textures",
"description": "A simple test of rendering a texture.",
"keywords": [ "basics", "textures", "direct" ]
}
}
8 changes: 8 additions & 0 deletions src/examples/gettingstarted/04_lambertCube/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slug": "getting_started_cube_diffuse",
"en": {
"name": "Getting Started - Cube Diffuse",
"description": "A bare-bones test of lighting a cube geometry directly.",
"keywords": [ "basics", "geometry", "cube", "direct", "diffuse" ]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slug": "getting_started_cubemap_texture",
"en": {
"name": "Getting Started - Cube Map Texture",
"description": "A bare-bones test of loading and rendering with a cubemap texture directly.",
"keywords": [ "basics", "geometry", "cubemap", "direct", "reflection" ]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slug": "getting_started_interleaved_geometry",
"en": {
"name": "Getting Started - Interleaved Geometry",
"description": "A test of interleaving and rendering arbitrary geometry. Interleaved geometry can be more efficient for GPUs to render because all data for one vertex is collocated.",
"keywords": [ "basics", "geometry", "interleaved", "direct" ]
}
}
8 changes: 8 additions & 0 deletions src/examples/gettingstarted/07_metallicRoughness/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slug": "getting_started_cubemap_lod_roughness",
"en": {
"name": "Getting Started - Cube Map LOD Roughness",
"description": "A test of explicitly setting the cube map LOD to simulate reflections with varying surface roughness. Requires the ext_shader_texture_lod extension.",
"keywords": [ "basics", "geometry", "reflections", "cubemap" ]
}
}
8 changes: 8 additions & 0 deletions src/examples/gettingstarted/08_orthographic/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slug": "getting_started_orthographic",
"en": {
"name": "Getting Started - Orthographic Camera",
"description": "A test of using an orthographic camera to render.",
"keywords": [ "basics", "camera", "orthographic" ]
}
}
8 changes: 8 additions & 0 deletions src/examples/gettingstarted/09_hdr/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slug": "getting_started_hdr",
"en": {
"name": "Getting Started - High Dynamic Range Rendering",
"description": "Loading Radiance HDR (encoded as RGBE) and then storing it in RGBD format. The RGBD data is decoded to linear for rendering and then sRGB corrected when written to the output.",
"keywords": [ "basics", "hrd", "sRGB", "RGBE", "RGBD" ]
}
}
8 changes: 8 additions & 0 deletions src/examples/gettingstarted/10_renderToTexture/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slug": "getting_started_render_to_render",
"en": {
"name": "Getting Started - Render to Texture",
"description": "A simple test of rendering to a texture, and then using that texture as an albedo map on another geometry and writing that to screen.",
"keywords": [ "basics", "render-to-texture", "framebuffer" ]
}
}
8 changes: 8 additions & 0 deletions src/examples/gettingstarted/11_depthTexture/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"slug": "getting_started_depth_texture",
"en": {
"name": "Getting Started - Depth Texture",
"description": "A simple test of rendering to a depth texture framebuffer attachment and then accessing that texture (as an albedo map on geometry which is then rendered to screen.)",
"keywords": [ "basics", "render-to-texture", "depth-texture", "framebuffer" ]
}
}

0 comments on commit f99e8fe

Please sign in to comment.