@woosh/meep-engine 2.118.11 → 2.118.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/meep.cjs +30 -8
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +30 -8
- package/package.json +1 -1
- package/src/core/bvh2/bvh3/BVH.d.ts.map +1 -1
- package/src/core/bvh2/bvh3/BVH.js +13 -8
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +4 -4
- package/src/core/collection/array/typed/array_buffer_copy.js +2 -2
- package/src/core/collection/array/typed/typed_array_copy.d.ts.map +1 -1
- package/src/core/collection/array/typed/typed_array_copy.js +16 -0
- package/src/core/geom/3d/aabb/aabb3_compute_surface_area.js +1 -3
- package/src/engine/graphics/geometry/optimization/VertexCacheOptimizer.d.ts.map +1 -1
- package/src/engine/graphics/geometry/optimization/VertexCacheOptimizer.js +36 -22
package/build/meep.module.js
CHANGED
|
@@ -52062,6 +52062,8 @@ function array_buffer_copy(
|
|
|
52062
52062
|
target, target_offset,
|
|
52063
52063
|
byte_length
|
|
52064
52064
|
) {
|
|
52065
|
+
// assert.ok(source instanceof ArrayBuffer || source instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
|
|
52066
|
+
// assert.ok(target instanceof ArrayBuffer || target instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
|
|
52065
52067
|
|
|
52066
52068
|
/**
|
|
52067
52069
|
* @type {Uint8Array|Uint16Array|Uint32Array}
|
|
@@ -52152,6 +52154,7 @@ const CAPACITY_GROW_MIN_STEP = 64;
|
|
|
52152
52154
|
* @type {number}
|
|
52153
52155
|
*/
|
|
52154
52156
|
const ELEMENT_WORD_COUNT = 10;
|
|
52157
|
+
const ELEMENT_BYTE_COUNT = ELEMENT_WORD_COUNT * 4;
|
|
52155
52158
|
|
|
52156
52159
|
/**
|
|
52157
52160
|
* How many nodes can be stored in the newly constructed tree before allocation needs to take place
|
|
@@ -52189,7 +52192,7 @@ class BVH {
|
|
|
52189
52192
|
* If you intend to modify the data directly - make sure you fully understand the implications of doing so
|
|
52190
52193
|
* @returns {ArrayBuffer}
|
|
52191
52194
|
*/
|
|
52192
|
-
get data_buffer(){
|
|
52195
|
+
get data_buffer() {
|
|
52193
52196
|
return this.__data_buffer;
|
|
52194
52197
|
}
|
|
52195
52198
|
|
|
@@ -52310,19 +52313,23 @@ class BVH {
|
|
|
52310
52313
|
|
|
52311
52314
|
const old_data_uint32 = this.__data_uint32;
|
|
52312
52315
|
|
|
52313
|
-
const new_data_buffer = new ArrayBuffer(new_capacity *
|
|
52316
|
+
const new_data_buffer = new ArrayBuffer(new_capacity * ELEMENT_BYTE_COUNT);
|
|
52314
52317
|
|
|
52315
52318
|
this.__data_buffer = new_data_buffer;
|
|
52316
52319
|
|
|
52317
52320
|
this.__data_float32 = new Float32Array(new_data_buffer);
|
|
52318
52321
|
this.__data_uint32 = new Uint32Array(new_data_buffer);
|
|
52319
52322
|
|
|
52320
|
-
|
|
52321
|
-
|
|
52322
|
-
|
|
52323
|
-
|
|
52324
|
-
|
|
52325
|
-
|
|
52323
|
+
if (this.__size > 0) {
|
|
52324
|
+
|
|
52325
|
+
// copy old data into new buffer
|
|
52326
|
+
array_buffer_copy(
|
|
52327
|
+
old_data_uint32.buffer, old_data_uint32.byteOffset,
|
|
52328
|
+
new_data_buffer, 0,
|
|
52329
|
+
Math.min(this.__size * ELEMENT_BYTE_COUNT, new_data_buffer.byteLength)
|
|
52330
|
+
);
|
|
52331
|
+
|
|
52332
|
+
}
|
|
52326
52333
|
|
|
52327
52334
|
this.__capacity = new_capacity;
|
|
52328
52335
|
}
|
|
@@ -61391,10 +61398,25 @@ function typed_array_copy(source, destination) {
|
|
|
61391
61398
|
const destination_size = destination.length;
|
|
61392
61399
|
|
|
61393
61400
|
if (destination_size >= source.length) {
|
|
61401
|
+
|
|
61394
61402
|
destination.set(source, 0);
|
|
61403
|
+
|
|
61404
|
+
} else if (source.constructor === destination.constructor) {
|
|
61405
|
+
|
|
61406
|
+
// same type
|
|
61407
|
+
array_buffer_copy(
|
|
61408
|
+
source.buffer,
|
|
61409
|
+
source.byteOffset,
|
|
61410
|
+
destination.buffer,
|
|
61411
|
+
destination.byteOffset,
|
|
61412
|
+
Math.min(source.byteLength, destination.byteLength)
|
|
61413
|
+
);
|
|
61414
|
+
|
|
61395
61415
|
} else {
|
|
61416
|
+
|
|
61396
61417
|
// destination is smaller than source, crop source data
|
|
61397
61418
|
array_copy(source, 0, destination, 0, destination_size);
|
|
61419
|
+
|
|
61398
61420
|
}
|
|
61399
61421
|
}
|
|
61400
61422
|
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BVH.d.ts","sourceRoot":"","sources":["../../../../../src/core/bvh2/bvh3/BVH.js"],"names":[],"mappings":"AAQA,8BAA+B;AAC/B,+BAAgC;AAChC,+BAAgC;AAChC,8BAA+B;AAE/B;;;;;GAKG;AACH,+BAFU,MAAM,CAE+B;AAE/C;;;GAGG;AACH,wBAFU,MAAM,CAEoB;AAcpC;;;;;GAKG;AACH,iCAFU,MAAM,CAEqB;
|
|
1
|
+
{"version":3,"file":"BVH.d.ts","sourceRoot":"","sources":["../../../../../src/core/bvh2/bvh3/BVH.js"],"names":[],"mappings":"AAQA,8BAA+B;AAC/B,+BAAgC;AAChC,+BAAgC;AAChC,8BAA+B;AAE/B;;;;;GAKG;AACH,+BAFU,MAAM,CAE+B;AAE/C;;;GAGG;AACH,wBAFU,MAAM,CAEoB;AAcpC;;;;;GAKG;AACH,iCAFU,MAAM,CAEqB;AAiBrC;;;;;;GAMG;AACH;IAEI;;;;OAIG;IACH,sBAA2E;IAE3E;;;;;OAKG;IACH,+BAEC;IAED;;;;OAIG;IACH,uBAAsD;IAEtD;;;;OAIG;IACH,sBAAoD;IAEpD;;;;OAIG;IACH,mBAA8B;IAE9B;;;;OAIG;IACH,eAAW;IAEX;;;;OAIG;IACH,eAAY;IAEZ;;;;OAIG;IACH,uBAAmB;IAEnB;;;;OAIG;IACH,eAAmB;IAUnB;;;OAGG;IACH,sBAEC;IAdD;;;OAGG;IACH,mBAEC;IAkBD;;;OAGG;IACH,+BAMC;IAlBD;;;OAGG;IACH,4BAEC;IAcD,wBAgBC;IAED;;;;OAIG;IACH,uBA6BC;IAED;;OAEG;IACH,aAIC;IAED;;;OAGG;IACH,iBAFa,MAAM,CAqDlB;IAED;;;;OAIG;IACH,iBAFW,MAAM,QAMhB;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,OAAO,CAOnB;IAED;;;;OAIG;IACH,uBAHW,MAAM,GACJ,MAAM,CAKlB;IAED;;;;OAIG;IACH,uBAHW,MAAM,SACN,MAAM,QAOhB;IAED;;;;OAIG;IACH,oBAHW,MAAM,GACJ,MAAM,CAKlB;IAED;;;;OAIG;IACH,sBAHW,MAAM,UACN,MAAM,QAIhB;IAED;;;;OAIG;IACH,oBAHW,MAAM,GACJ,MAAM,CAKlB;IAED;;;;OAIG;IACH,sBAHW,MAAM,UACN,MAAM,QAIhB;IAED;;;;OAIG;IACH,oBAHW,MAAM,GACJ,MAAM,CAKlB;IAED;;;;OAIG;IACH,sBAHW,MAAM,UACN,MAAM,QAIhB;IAGD;;;;OAIG;IACH,oBAHW,MAAM,GACJ,MAAM,CAKlB;IAED;;;;OAIG;IACH,oBAHW,MAAM,UACN,MAAM,QAKhB;IAED;;;;OAIG;IACH,kBAHW,MAAM,UACN,MAAM,EAAE,GAAC,YAAY,QAe/B;IAED;;;;OAIG;IACH,kBAHW,MAAM,QACN,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,QAAM,QAsB1C;IAED;;;;OAIG;IACH,mBAHW,MAAM,QACN,MAAM,EAAE,QAWlB;IAED;;;;;;;;;OASG;IACH,4BARW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAmBhB;IAED;;;;OAIG;IACH,0BAHW,MAAM,GACJ,MAAM,CAoBlB;IAED;;;;;OAKG;IACH,wCAJW,MAAM,WACN,MAAM,GACJ,MAAM,CAoClB;IAED;;;;;OAKG;IACH,oCAJW,MAAM,WACN,MAAM,WACN,MAAM,QAwChB;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACJ,IAAI,CA0GhB;IAED;;;;;OAKG;IACH,wBAqBC;IAED;;;;OAIG;IACH,yBA4BC;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACJ,IAAI,CA6ChB;IAED;;;;;;OAMG;IACH,gBAoMC;IAED;;;OAGG;IACH,oBAIC;IAED;;;;OAIG;IACH,yCA8BC;IAED;;;;;OAKG;IACH,+BAJW,MAAM,EAAE,sBACR,MAAM,GACJ,MAAM,CAWlB;IAED;;;;;OAKG;IACH,0BA6BC;IAED;;;;;OAKG;IACH,cAJW,MAAM,KACN,MAAM,GACJ,OAAO,CAsCnB;CACJ"}
|
|
@@ -44,6 +44,7 @@ const CAPACITY_GROW_MIN_STEP = 64;
|
|
|
44
44
|
* @type {number}
|
|
45
45
|
*/
|
|
46
46
|
export const ELEMENT_WORD_COUNT = 10;
|
|
47
|
+
const ELEMENT_BYTE_COUNT = ELEMENT_WORD_COUNT * 4;
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
50
|
* How many nodes can be stored in the newly constructed tree before allocation needs to take place
|
|
@@ -81,7 +82,7 @@ export class BVH {
|
|
|
81
82
|
* If you intend to modify the data directly - make sure you fully understand the implications of doing so
|
|
82
83
|
* @returns {ArrayBuffer}
|
|
83
84
|
*/
|
|
84
|
-
get data_buffer(){
|
|
85
|
+
get data_buffer() {
|
|
85
86
|
return this.__data_buffer;
|
|
86
87
|
}
|
|
87
88
|
|
|
@@ -203,19 +204,23 @@ export class BVH {
|
|
|
203
204
|
|
|
204
205
|
const old_data_uint32 = this.__data_uint32;
|
|
205
206
|
|
|
206
|
-
const new_data_buffer = new ArrayBuffer(new_capacity *
|
|
207
|
+
const new_data_buffer = new ArrayBuffer(new_capacity * ELEMENT_BYTE_COUNT);
|
|
207
208
|
|
|
208
209
|
this.__data_buffer = new_data_buffer;
|
|
209
210
|
|
|
210
211
|
this.__data_float32 = new Float32Array(new_data_buffer);
|
|
211
212
|
this.__data_uint32 = new Uint32Array(new_data_buffer);
|
|
212
213
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
214
|
+
if (this.__size > 0) {
|
|
215
|
+
|
|
216
|
+
// copy old data into new buffer
|
|
217
|
+
array_buffer_copy(
|
|
218
|
+
old_data_uint32.buffer, old_data_uint32.byteOffset,
|
|
219
|
+
new_data_buffer, 0,
|
|
220
|
+
Math.min(this.__size * ELEMENT_BYTE_COUNT, new_data_buffer.byteLength)
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
}
|
|
219
224
|
|
|
220
225
|
this.__capacity = new_capacity;
|
|
221
226
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assert } from "../../assert.js";
|
|
2
|
-
import { array_copy } from "../../collection/array/array_copy.js";
|
|
3
2
|
import { array_quick_sort_by_lookup_uint } from "../../collection/array/array_quick_sort_by_lookup_uint.js";
|
|
3
|
+
import { typed_array_copy } from "../../collection/array/typed/typed_array_copy.js";
|
|
4
4
|
import { AABB3 } from "../../geom/3d/aabb/AABB3.js";
|
|
5
5
|
import { aabb3_from_v3_array } from "../../geom/3d/aabb/aabb3_from_v3_array.js";
|
|
6
6
|
import { aabb3_compute_from_triangle } from "../../geom/3d/aabb3_compute_from_triangle.js";
|
|
@@ -56,7 +56,6 @@ export function ebvh_build_for_geometry_morton(
|
|
|
56
56
|
bvh.__size = node_total_count;
|
|
57
57
|
|
|
58
58
|
|
|
59
|
-
|
|
60
59
|
// indices of triangles, but sorted by morton codes
|
|
61
60
|
const sorted_triangle_order = new Uint32Array(tri_count);
|
|
62
61
|
|
|
@@ -128,8 +127,9 @@ export function ebvh_build_for_geometry_morton(
|
|
|
128
127
|
|
|
129
128
|
// record newly generated nodes as "unprocessed"
|
|
130
129
|
const unprocessed_nodes = new Uint32Array(tri_count);
|
|
131
|
-
|
|
130
|
+
|
|
131
|
+
typed_array_copy(nodes, unprocessed_nodes);
|
|
132
132
|
|
|
133
133
|
// assign root
|
|
134
|
-
bvh.root = ebvh_build_hierarchy(bvh, unprocessed_nodes, tri_count, nodes, tri_count, quality
|
|
134
|
+
bvh.root = ebvh_build_hierarchy(bvh, unprocessed_nodes, tri_count, nodes, tri_count, quality);
|
|
135
135
|
}
|
|
@@ -18,8 +18,8 @@ export function array_buffer_copy(
|
|
|
18
18
|
assert.isNonNegativeInteger(source_offset, 'source_offset');
|
|
19
19
|
assert.isNonNegativeInteger(target_offset, 'target_offset');
|
|
20
20
|
assert.isNonNegativeInteger(byte_length, 'byte_length');
|
|
21
|
-
assert.ok(source instanceof ArrayBuffer || source instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
|
|
22
|
-
assert.ok(target instanceof ArrayBuffer || target instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
|
|
21
|
+
// assert.ok(source instanceof ArrayBuffer || source instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
|
|
22
|
+
// assert.ok(target instanceof ArrayBuffer || target instanceof SharedArrayBuffer,'source is not an ArrayBuffer');
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @type {Uint8Array|Uint16Array|Uint32Array}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed_array_copy.d.ts","sourceRoot":"","sources":["../../../../../../src/core/collection/array/typed/typed_array_copy.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typed_array_copy.d.ts","sourceRoot":"","sources":["../../../../../../src/core/collection/array/typed/typed_array_copy.js"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,yCAHW,aAAW,YAAY,GAAC,UAAU,GAAC,WAAW,eAC9C,aAAW,YAAY,GAAC,UAAU,GAAC,WAAW,QA0BxD"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { array_copy } from "../array_copy.js";
|
|
2
|
+
import { array_buffer_copy } from "./array_buffer_copy.js";
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -10,9 +11,24 @@ export function typed_array_copy(source, destination) {
|
|
|
10
11
|
const destination_size = destination.length;
|
|
11
12
|
|
|
12
13
|
if (destination_size >= source.length) {
|
|
14
|
+
|
|
13
15
|
destination.set(source, 0);
|
|
16
|
+
|
|
17
|
+
} else if (source.constructor === destination.constructor) {
|
|
18
|
+
|
|
19
|
+
// same type
|
|
20
|
+
array_buffer_copy(
|
|
21
|
+
source.buffer,
|
|
22
|
+
source.byteOffset,
|
|
23
|
+
destination.buffer,
|
|
24
|
+
destination.byteOffset,
|
|
25
|
+
Math.min(source.byteLength, destination.byteLength)
|
|
26
|
+
);
|
|
27
|
+
|
|
14
28
|
} else {
|
|
29
|
+
|
|
15
30
|
// destination is smaller than source, crop source data
|
|
16
31
|
array_copy(source, 0, destination, 0, destination_size);
|
|
32
|
+
|
|
17
33
|
}
|
|
18
34
|
}
|
|
@@ -8,11 +8,9 @@
|
|
|
8
8
|
* @param {number} z1
|
|
9
9
|
* @returns {number}
|
|
10
10
|
*/
|
|
11
|
-
function aabb3_compute_surface_area(x0, y0, z0, x1, y1, z1) {
|
|
11
|
+
export function aabb3_compute_surface_area(x0, y0, z0, x1, y1, z1) {
|
|
12
12
|
const dx = x1 - x0;
|
|
13
13
|
const dy = y1 - y0;
|
|
14
14
|
const dz = z1 - z0;
|
|
15
15
|
return (dy * (dx + dz) + dz * dx) * 2; //2 of each side
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
export { aabb3_compute_surface_area };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VertexCacheOptimizer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/optimization/VertexCacheOptimizer.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"VertexCacheOptimizer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/optimization/VertexCacheOptimizer.js"],"names":[],"mappings":"AA8aA;;;;;;GAMG;AACH,yDALW,MAAM,EAAE,GAAC,WAAW,WACpB,MAAM,EAAE,GAAC,WAAW,eACpB,MAAM,gBACN,MAAM,QAIhB;AAED;;;;;;GAMG;AACH,8DALW,MAAM,EAAE,GAAC,WAAW,WACpB,MAAM,EAAE,GAAC,WAAW,eACpB,MAAM,gBACN,MAAM,QAIhB"}
|
|
@@ -8,10 +8,9 @@ const kCacheSizeMax = 16;
|
|
|
8
8
|
const kValenceMax = 8;
|
|
9
9
|
|
|
10
10
|
class VertexScoreTable {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
11
|
+
|
|
12
|
+
cache = new Float32Array(1 + kCacheSizeMax);
|
|
13
|
+
live = new Float32Array(1 + kValenceMax);
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
*
|
|
@@ -42,11 +41,10 @@ const kVertexScoreTableStrip = VertexScoreTable.from(
|
|
|
42
41
|
);
|
|
43
42
|
|
|
44
43
|
class TriangleAdjacency {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
44
|
+
|
|
45
|
+
counts = new Uint32Array(1);
|
|
46
|
+
offsets = new Uint32Array(1);
|
|
47
|
+
data = new Uint32Array(1);
|
|
50
48
|
|
|
51
49
|
/**
|
|
52
50
|
*
|
|
@@ -76,42 +74,48 @@ function buildTriangleAdjacency(adjacency, indices, index_count, vertex_count) {
|
|
|
76
74
|
// fill triangle counts
|
|
77
75
|
// adjacency.counts.fill(0);// unnecessary, new arrays are already zero-filled
|
|
78
76
|
|
|
77
|
+
const adjacency_counts = adjacency.counts;
|
|
78
|
+
|
|
79
79
|
for (let i = 0; i < index_count; ++i) {
|
|
80
80
|
const index = indices[i];
|
|
81
81
|
|
|
82
82
|
assert.lessThan(index, vertex_count);
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
adjacency_counts[index]++;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// fill offset table
|
|
88
88
|
let offset = 0;
|
|
89
89
|
|
|
90
|
+
const adjacency_offsets = adjacency.offsets;
|
|
91
|
+
|
|
90
92
|
for (let i = 0; i < vertex_count; ++i) {
|
|
91
|
-
|
|
92
|
-
offset +=
|
|
93
|
+
adjacency_offsets[i] = offset;
|
|
94
|
+
offset += adjacency_counts[i];
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
assert.equal(offset, index_count);
|
|
96
98
|
|
|
99
|
+
const adjacency_data = adjacency.data;
|
|
100
|
+
|
|
97
101
|
// fill triangle data
|
|
98
102
|
for (let i = 0; i < face_count; ++i) {
|
|
99
103
|
const i3 = i * 3;
|
|
100
104
|
|
|
101
|
-
const a = indices[i3
|
|
105
|
+
const a = indices[i3];
|
|
102
106
|
const b = indices[i3 + 1];
|
|
103
107
|
const c = indices[i3 + 2];
|
|
104
108
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
adjacency_data[adjacency_offsets[a]++] = i;
|
|
110
|
+
adjacency_data[adjacency_offsets[b]++] = i;
|
|
111
|
+
adjacency_data[adjacency_offsets[c]++] = i;
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
// fix offsets that have been disturbed by the previous pass
|
|
111
115
|
for (let i = 0; i < vertex_count; ++i) {
|
|
112
116
|
// assert(adjacency.offsets[i] >= adjacency.counts[i]);
|
|
113
117
|
|
|
114
|
-
|
|
118
|
+
adjacency_offsets[i] -= adjacency_counts[i];
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
|
|
@@ -236,8 +240,9 @@ function meshopt_optimizeVertexCacheTable(destination, indices, index_count, ver
|
|
|
236
240
|
assert.equal(index_count % 3, 0);
|
|
237
241
|
|
|
238
242
|
// guard for empty meshes
|
|
239
|
-
if (index_count === 0 || vertex_count === 0)
|
|
243
|
+
if (index_count === 0 || vertex_count === 0) {
|
|
240
244
|
return;
|
|
245
|
+
}
|
|
241
246
|
|
|
242
247
|
// support in-place optimization
|
|
243
248
|
if (destination === indices) {
|
|
@@ -273,9 +278,10 @@ function meshopt_optimizeVertexCacheTable(destination, indices, index_count, ver
|
|
|
273
278
|
const triangle_scores = new Float32Array(face_count);
|
|
274
279
|
|
|
275
280
|
for (let i = 0; i < face_count; ++i) {
|
|
281
|
+
|
|
276
282
|
const i3 = i * 3;
|
|
277
283
|
|
|
278
|
-
const a = indices[i3
|
|
284
|
+
const a = indices[i3];
|
|
279
285
|
const b = indices[i3 + 1];
|
|
280
286
|
const c = indices[i3 + 2];
|
|
281
287
|
|
|
@@ -296,16 +302,17 @@ function meshopt_optimizeVertexCacheTable(destination, indices, index_count, ver
|
|
|
296
302
|
|
|
297
303
|
const in_tri_3 = current_triangle * 3;
|
|
298
304
|
|
|
299
|
-
const a = indices[in_tri_3
|
|
305
|
+
const a = indices[in_tri_3];
|
|
300
306
|
const b = indices[in_tri_3 + 1];
|
|
301
307
|
const c = indices[in_tri_3 + 2];
|
|
302
308
|
|
|
303
309
|
// output indices
|
|
304
310
|
const out_tri_3 = output_triangle * 3;
|
|
305
311
|
|
|
306
|
-
destination[out_tri_3
|
|
312
|
+
destination[out_tri_3] = a;
|
|
307
313
|
destination[out_tri_3 + 1] = b;
|
|
308
314
|
destination[out_tri_3 + 2] = c;
|
|
315
|
+
|
|
309
316
|
output_triangle++;
|
|
310
317
|
|
|
311
318
|
// update emitted flags
|
|
@@ -327,8 +334,11 @@ function meshopt_optimizeVertexCacheTable(destination, indices, index_count, ver
|
|
|
327
334
|
}
|
|
328
335
|
}
|
|
329
336
|
|
|
337
|
+
// swap caches
|
|
330
338
|
const cache_temp = cache;
|
|
331
|
-
cache = cache_new
|
|
339
|
+
cache = cache_new;
|
|
340
|
+
cache_new = cache_temp;
|
|
341
|
+
|
|
332
342
|
cache_count = cache_write > cache_size ? cache_size : cache_write;
|
|
333
343
|
|
|
334
344
|
// update live triangle counts
|
|
@@ -346,13 +356,17 @@ function meshopt_optimizeVertexCacheTable(destination, indices, index_count, ver
|
|
|
346
356
|
const neighbours_size = adjacency.counts[index];
|
|
347
357
|
|
|
348
358
|
for (let i = 0; i < neighbours_size; ++i) {
|
|
359
|
+
|
|
349
360
|
const tri = neighbours[i + neighbour_offset];
|
|
350
361
|
|
|
351
362
|
if (tri === current_triangle) {
|
|
363
|
+
|
|
352
364
|
neighbours[neighbour_offset + i] = neighbours[neighbour_offset + neighbours_size - 1];
|
|
353
365
|
adjacency.counts[index]--;
|
|
354
366
|
break;
|
|
367
|
+
|
|
355
368
|
}
|
|
369
|
+
|
|
356
370
|
}
|
|
357
371
|
}
|
|
358
372
|
|