Skip to content

Commit

Permalink
build: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dmnsgn committed Sep 5, 2023
1 parent 79cae79 commit a392002
Show file tree
Hide file tree
Showing 40 changed files with 44,899 additions and 14,720 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions examples/unindexed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import random from "pex-random";
import createGUI from "pex-gui";

import { cube } from "primitive-geometry";

import { computeNormals, splitVertices } from "./utils.js";
import splitVertices from "geom-split-vertices";
import computeNormals from "geom-normals";

import basicVert from "./shaders/basic.vert.js";
import basicFrag from "./shaders/basic.frag.js";
Expand Down
60 changes: 0 additions & 60 deletions examples/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { vec3 } from "pex-math";

export const es300Vertex = (shader) => /* glsl */ `#version 300 es
#define attribute in
#define varying out
Expand All @@ -14,61 +12,3 @@ precision highp float;
#define gl_FragColor gl_FragData[0]
out vec4 FragData[${size}];
${shader}`;

export function splitVertices(positions, cells) {
const splitPositions = new Float32Array((positions.length / 2) * 3);

for (let i = 0; i < cells.length; i += 3) {
const face = [cells[i], cells[i + 1], cells[i + 2]];

for (let j = 0; j < face.length; j++) {
splitPositions[(i + j) * 3] = positions[face[j] * 3];
splitPositions[(i + j) * 3 + 1] = positions[face[j] * 3 + 1];
splitPositions[(i + j) * 3 + 2] = positions[face[j] * 3 + 2];
}
}

return {
positions: splitPositions,
cells: new cells.constructor(cells.map((_, i) => i)),
};
}

export function computeNormals(positions, cells) {
const normals = [];

const count = [];
const ab = [0, 0, 0];
const ac = [0, 0, 0];
const n = [0, 0, 0];

for (let fi = 0; fi < cells.length / 3; fi++) {
const f = cells.slice(fi * 3, fi * 3 + 3);
const a = positions.slice(f[0] * 3, f[0] * 3 + 3);
const b = positions.slice(f[1] * 3, f[1] * 3 + 3);
const c = positions.slice(f[2] * 3, f[2] * 3 + 3);

vec3.normalize(vec3.sub(vec3.set(ab, b), a));
vec3.normalize(vec3.sub(vec3.set(ac, c), a));
vec3.normalize(vec3.cross(vec3.set(n, ab), ac));

for (let i = 0; i < f.length; i++) {
if (!normals[f[i]]) {
normals[f[i]] = [0, 0, 0];
}

vec3.add(normals[f[i]], n);
count[f[i]] = count[f[i]] ? 1 : count[f[i]] + 1;
}
}

for (let i = 0; i < normals.length; i++) {
if (normals[i]) {
vec3.normalize(normals[i]);
} else {
normals[i] = [0, 1, 0];
}
}

return Float32Array.from(normals.flat());
}
Loading

0 comments on commit a392002

Please sign in to comment.