Skip to content
Snippets Groups Projects
Commit 1d452aa2 authored by Christoph-Anton Schwierz's avatar Christoph-Anton Schwierz
Browse files

bunny & ray tracing

parent b961e981
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,6 @@
<script type="module" src="/src/cg/perspectiveDivide.ts"></script>
<script type="module" src="/src/cg/walkToVec.ts"></script>
<script type="module" src="/src/cg/basis.ts"></script-->
<script type="module" src="/src/cg/shear.ts"></script>
<script type="module" src="/src/cg/loadBunnyDemo.ts"></script>
</body>
</html>
import Playground from "./playground";
const pg = new Playground();
const sphere = {
position: [0, .5, -3],
radius: 1.23
}
pg.visCamera(-1);
pg.gridXZ()
const o = [0, 0, 0]
const co = ... // O - C
const step = 1 / 8
for (let yCoord = -1; yCoord <= 1; yCoord += step) {
for (let xCoord = -1; xCoord <= 1; xCoord += step) {
const v = [xCoord, yCoord, -1]
const ov = ... // V - O
pg.visVector(ov)
const a = ... // <---- see equations above
const b = ... // <---- see equations above
const c = ... // <---- see equations above
const discriminant = ... // <---- see equations above
const t1 = (-b + Math.sqrt(discriminant)) / (2 * a)
const t2 = (-b - Math.sqrt(discriminant)) / (2 * a)
if (t1) {
pg.visPoint(vecMultiplyScalar(t1, v),{color:"red"});
}
if (t2) {
pg.visPoint(vecMultiplyScalar(t2, v),{color:"blue"});
}
}
}
\ No newline at end of file
import Playground from "./playground";
import { loadGeoFromUSDA } from "./loader";
// The .usda file imported as raw string
import geo from '../../src/geo.usda?raw';
const data = loadGeoFromUSDA(geo);
const pg = new Playground();
pg.gridXZ();
if (data) {
for (let p of data) {
if (p) {
pg.visPoint(p)
}
}
}
\ No newline at end of file
export function loadGeoFromUSDA(geoRaw: string) {
// Extract vertex position from a .usda file:
// point3f[] points = [(...
// Regex pattern to match the desired array
const pattern = /point3f\[\] points = \[(.*?)\]/;
// Extract the array using the pattern
const match = geoRaw.match(pattern);
if (match) {
// Extract the contents inside the square brackets
const arrayContents = match[1];
// Regex pattern to match each point inside the array contents
const pointPattern = /\(\s*(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)\s*\)/g;
// Match all points in the array contents
const pointMatches = arrayContents.match(pointPattern);
if (!pointMatches) return false;
// Convert matched points to the desired format
const data = pointMatches.map(point => {
// Extract numbers from the matched point
const numbers = point.match(/-?\d+(\.\d+)?/g);
if (!numbers) return false;
// Convert strings to numbers and return as an array
return numbers.map(Number);
});
return data
} else {
return false
}
}
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment