-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add multiple canvas sample. Note: AFAICT the stanford dragon was getting flat shading. If that was the intent I can remove the genarateNormals code but I assumed the intent was smooth shading. I do kind of wonder if we should just genearte then once and put them in the data file 😛
- Loading branch information
Showing
8 changed files
with
752 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,44 @@ | ||
import dragonRawData from './stanfordDragonData'; | ||
import { computeSurfaceNormals, computeProjectedPlaneUVs } from './utils'; | ||
import { computeProjectedPlaneUVs, generateNormals } from './utils'; | ||
|
||
export const mesh = { | ||
positions: dragonRawData.positions as [number, number, number][], | ||
triangles: dragonRawData.cells as [number, number, number][], | ||
normals: [] as [number, number, number][], | ||
uvs: [] as [number, number][], | ||
}; | ||
|
||
// Compute surface normals | ||
mesh.normals = computeSurfaceNormals(mesh.positions, mesh.triangles); | ||
const { positions, normals, triangles } = generateNormals( | ||
Math.PI, | ||
dragonRawData.positions as [number, number, number][], | ||
dragonRawData.cells as [number, number, number][] | ||
); | ||
|
||
// Compute some easy uvs for testing | ||
mesh.uvs = computeProjectedPlaneUVs(mesh.positions, 'xy'); | ||
const uvs = computeProjectedPlaneUVs(positions, 'xy'); | ||
|
||
// Push indices for an additional ground plane | ||
mesh.triangles.push( | ||
[mesh.positions.length, mesh.positions.length + 2, mesh.positions.length + 1], | ||
[mesh.positions.length, mesh.positions.length + 1, mesh.positions.length + 3] | ||
triangles.push( | ||
[positions.length, positions.length + 2, positions.length + 1], | ||
[positions.length, positions.length + 1, positions.length + 3] | ||
); | ||
|
||
// Push vertex attributes for an additional ground plane | ||
// prettier-ignore | ||
mesh.positions.push( | ||
positions.push( | ||
[-100, 20, -100], // | ||
[ 100, 20, 100], // | ||
[-100, 20, 100], // | ||
[ 100, 20, -100] | ||
); | ||
mesh.normals.push( | ||
normals.push( | ||
[0, 1, 0], // | ||
[0, 1, 0], // | ||
[0, 1, 0], // | ||
[0, 1, 0] | ||
); | ||
mesh.uvs.push( | ||
uvs.push( | ||
[0, 0], // | ||
[1, 1], // | ||
[0, 1], // | ||
[1, 0] | ||
); | ||
|
||
export const mesh = { | ||
positions, | ||
triangles, | ||
normals, | ||
uvs, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<title>webgpu-samples: multiple canvases</title> | ||
<style> | ||
html, body { | ||
margin: 0; /* remove default margin */ | ||
height: 100%; /* make body fill the browser window */ | ||
} | ||
#outere { | ||
width: 100%; | ||
height: 100%; | ||
display: block; | ||
overflow: auto; | ||
} | ||
.product { | ||
display: inline-block; | ||
padding: 1em; | ||
background: #888; | ||
margin: 1em; | ||
} | ||
.size0>canvas { | ||
width: 200px; | ||
height: 200px; | ||
} | ||
.size1>canvas { | ||
width: 250px; | ||
height: 200px; | ||
} | ||
.size2>canvas { | ||
width: 300px; | ||
height: 200px; | ||
} | ||
.size3>canvas { | ||
width: 100px; | ||
height: 200px; | ||
} | ||
</style> | ||
<script defer src="main.js" type="module"></script> | ||
<script defer type="module" src="../../js/iframe-helper.js"></script> | ||
</head> | ||
<body> | ||
<div id="outer"></div> | ||
</body> | ||
</html> |
Oops, something went wrong.