@@ -47,38 +47,6 @@ export function setupIO(io: WebIO) {
47
47
return io . registerExtensions ( [ EXTManifold ] ) ;
48
48
}
49
49
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
-
82
50
/**
83
51
* Read an input mesh into Manifold-compatible data structures, whether it
84
52
* contains the EXT_manifold extension or not.
@@ -167,14 +135,8 @@ export function readMesh(mesh: Mesh, attributes: Attribute[] = []):
167
135
if ( attributeIn === attributeOut ) {
168
136
foundAttribute [ idx ] = true ;
169
137
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 ] ) ;
178
140
}
179
141
}
180
142
} ) ;
@@ -428,3 +390,35 @@ export async function loadTexture(texture: Texture, uri: string) {
428
390
texture . setMimeType ( blob . type ) ;
429
391
texture . setImage ( new Uint8Array ( await blob . arrayBuffer ( ) ) ) ;
430
392
}
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
+ }
0 commit comments