Skip to content

Commit 5fe87b2

Browse files
committed
a few fixes and cleanup
1 parent 87374d0 commit 5fe87b2

File tree

4 files changed

+49
-57
lines changed

4 files changed

+49
-57
lines changed

bindings/wasm/examples/gltf-io.ts

+34-40
Original file line numberDiff line numberDiff line change
@@ -47,38 +47,6 @@ export function setupIO(io: WebIO) {
4747
return io.registerExtensions([EXTManifold]);
4848
}
4949

50-
function readPrimitive(
51-
primitive: Primitive, numProp: number, attributes: Attribute[]) {
52-
const position = primitive.getAttribute('POSITION')!;
53-
const numVert = position.getCount();
54-
const vertProperties = [];
55-
let offset = 0;
56-
for (const attribute of attributes) {
57-
const size = attributeDefs[attribute].components;
58-
if (attributeDefs[attribute].type == null) {
59-
offset += size;
60-
continue;
61-
}
62-
const accessor = primitive.getAttribute(attribute);
63-
if (accessor) {
64-
const array = accessor.getArray()!;
65-
for (let i = 0; i < numVert; ++i) {
66-
for (let j = 0; j < size; ++j) {
67-
vertProperties[numProp * i + offset + j] = array[i * size + j];
68-
}
69-
}
70-
} else {
71-
for (let i = 0; i < numVert; ++i) {
72-
for (let j = 0; j < size; ++j) {
73-
vertProperties[numProp * i + offset + j] = 0;
74-
}
75-
}
76-
}
77-
offset += size;
78-
}
79-
return vertProperties;
80-
}
81-
8250
/**
8351
* Read an input mesh into Manifold-compatible data structures, whether it
8452
* contains the EXT_manifold extension or not.
@@ -167,14 +135,8 @@ export function readMesh(mesh: Mesh, attributes: Attribute[] = []):
167135
if (attributeIn === attributeOut) {
168136
foundAttribute[idx] = true;
169137
const accessor = primitive.getAttribute(attributeIn)!;
170-
const array = accessor.getArray()!;
171-
const size = attributeDefs[attributeIn].components;
172-
for (let i = 0; i < numVert; ++i) {
173-
for (let j = 0; j < size; ++j) {
174-
vertPropArray[numProp * i + attributeOffsets[idx] + j] =
175-
array[i * size + j];
176-
}
177-
}
138+
writeProperties(
139+
vertPropArray, accessor, numProp, attributeOffsets[idx]);
178140
}
179141
}
180142
});
@@ -428,3 +390,35 @@ export async function loadTexture(texture: Texture, uri: string) {
428390
texture.setMimeType(blob.type);
429391
texture.setImage(new Uint8Array(await blob.arrayBuffer()));
430392
}
393+
394+
function writeProperties(
395+
vertProperties: number[], accessor: Accessor, numProp: number,
396+
offset: number) {
397+
const array = accessor.getArray()!;
398+
const size = accessor.getElementSize();
399+
const numVert = accessor.getCount();
400+
for (let i = 0; i < numVert; ++i) {
401+
for (let j = 0; j < size; ++j) {
402+
vertProperties[numProp * i + offset + j] = array[i * size + j];
403+
}
404+
}
405+
}
406+
407+
function readPrimitive(
408+
primitive: Primitive, numProp: number, attributes: Attribute[]) {
409+
const vertProperties: number[] = [];
410+
let offset = 0;
411+
for (const attribute of attributes) {
412+
const size = attributeDefs[attribute].components;
413+
if (attributeDefs[attribute].type == null) {
414+
offset += size;
415+
continue;
416+
}
417+
const accessor = primitive.getAttribute(attribute);
418+
if (accessor) {
419+
writeProperties(vertProperties, accessor, numProp, offset);
420+
}
421+
offset += size;
422+
}
423+
return vertProperties;
424+
}

bindings/wasm/examples/public/editor.d.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import {Attribute} from '../gltf-io';
16-
1715
import {Manifold, Mat4, Vec2, Vec3} from './manifold';
1816

1917
declare class GLTFNode {
@@ -27,6 +25,9 @@ declare class GLTFNode {
2725
clone(parent?: GLTFNode): GLTFNode;
2826
}
2927

28+
type Attribute = 'POSITION'|'NORMAL'|'TANGENT'|'TEXCOORD_0'|'TEXCOORD_1'|
29+
'COLOR_0'|'JOINTS_0'|'WEIGHTS_0'|'SKIP_1'|'SKIP_2'|'SKIP_3'|'SKIP_4';
30+
3031
declare class GLTFMaterial {
3132
attributes?: Attribute[];
3233
roughness?: number;

bindings/wasm/examples/public/examples.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,12 @@ export const examples = {
350350

351351
const hole = Manifold.compose(holes);
352352

353-
result = Manifold.difference(
354-
result,
355-
hole,
356-
hole.rotate([90, 0, 0]),
357-
hole.rotate([0, 90, 0]),
358-
);
353+
result = Manifold.difference([
354+
result,
355+
hole,
356+
hole.rotate([90, 0, 0]),
357+
hole.rotate([0, 90, 0]),
358+
]);
359359
return result;
360360
}
361361

bindings/wasm/examples/worker.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -399,18 +399,15 @@ function addMesh(
399399
{vertices, indices: manifoldMesh.triVerts, id: `${nextGlobalID++}`});
400400

401401
for (const [run, id] of manifoldMesh.runOriginalID!.entries()) {
402-
let inMesh = shown.get(id);
403-
let single = false;
404-
if (inMesh == null) {
405-
single = true;
406-
inMesh = singles.get(id);
407-
}
402+
const show = shown.has(id);
403+
const inMesh = show ? shown.get(id) : singles.get(id);
408404
if (inMesh == null) {
409405
continue;
410406
}
411-
if (single) {
412-
id2properties.get(id)!.material = getCachedMaterial(doc, SHOW);
413-
}
407+
408+
id2properties.get(id)!.material = getCachedMaterial(
409+
doc, show ? SHOW : (id2material.get(id) || backupMaterial));
410+
414411
const debugNode = doc.createNode('debug')
415412
.setMesh(writeMesh(doc, inMesh, id2properties))
416413
.setMatrix(manifoldMesh.transform(run));

0 commit comments

Comments
 (0)