Skip to content

Commit 6edfa7c

Browse files
committed
fix: correct sync measures example bug when loading multiple models
1 parent 8c01045 commit 6edfa7c

File tree

4 files changed

+113
-103
lines changed

4 files changed

+113
-103
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,5 @@ node-app
145145

146146
.DS_Store
147147
.claude/
148+
149+
resources/frags/test/

packages/front/src/measurement/AngleMeasurement/example.ts

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -158,41 +158,43 @@ window.onkeydown = (event) => {
158158
const meshes: THREE.Mesh[] = [];
159159

160160
// Add picking meshes (deduplicating geometries to save memory)
161-
const model = fragments.list.values().next().value!;
162-
const idsWithGeometry = await model.getItemsIdsWithGeometry();
163-
const allMeshesData = await model.getItemsGeometry(idsWithGeometry);
164-
165-
const geometries = new Map<number, THREE.BufferGeometry>();
166-
167-
for (const itemId in allMeshesData) {
168-
const meshData = allMeshesData[itemId];
169-
for (const geomData of meshData) {
170-
if (
171-
!geomData.positions ||
172-
!geomData.indices ||
173-
!geomData.transform ||
174-
!geomData.representationId
175-
) {
176-
continue;
161+
for (const [, model] of fragments.list) {
162+
const idsWithGeometry = await model.getItemsIdsWithGeometry();
163+
const allMeshesData = await model.getItemsGeometry(idsWithGeometry);
164+
165+
const geometries = new Map<number, THREE.BufferGeometry>();
166+
167+
for (const itemId in allMeshesData) {
168+
const meshData = allMeshesData[itemId];
169+
for (const geomData of meshData) {
170+
if (
171+
!geomData.positions ||
172+
!geomData.indices ||
173+
!geomData.transform ||
174+
!geomData.representationId
175+
) {
176+
continue;
177+
}
178+
179+
const representationId = geomData.representationId;
180+
if (!geometries.has(representationId)) {
181+
const geometry = new THREE.BufferGeometry();
182+
geometry.setAttribute(
183+
"position",
184+
new THREE.Float32BufferAttribute(geomData.positions, 3),
185+
);
186+
geometry.setIndex(Array.from(geomData.indices));
187+
geometries.set(representationId, geometry);
188+
}
189+
190+
const geometry = geometries.get(representationId)!;
191+
192+
const mesh = new THREE.Mesh(geometry);
193+
mesh.applyMatrix4(geomData.transform);
194+
mesh.applyMatrix4(model.object.matrixWorld);
195+
mesh.updateWorldMatrix(true, true);
196+
meshes.push(mesh);
177197
}
178-
179-
const representationId = geomData.representationId;
180-
if (!geometries.has(representationId)) {
181-
const geometry = new THREE.BufferGeometry();
182-
geometry.setAttribute(
183-
"position",
184-
new THREE.Float32BufferAttribute(geomData.positions, 3),
185-
);
186-
geometry.setIndex(Array.from(geomData.indices));
187-
geometries.set(representationId, geometry);
188-
}
189-
190-
const geometry = geometries.get(representationId)!;
191-
192-
const mesh = new THREE.Mesh(geometry);
193-
mesh.applyMatrix4(geomData.transform);
194-
mesh.updateWorldMatrix(true, true);
195-
meshes.push(mesh);
196198
}
197199
}
198200

packages/front/src/measurement/AreaMeasurement/example.ts

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ fragments.core.models.materials.list.onItemSet.add(({ value: material }) => {
9090
:::
9191
*/
9292

93-
const fragPaths = ["https://thatopen.github.io/engine_components/resources/frags/school_arq.frag"];
93+
const fragPaths = [
94+
"https://thatopen.github.io/engine_components/resources/frags/school_arq.frag",
95+
];
9496
await Promise.all(
9597
fragPaths.map(async (path) => {
9698
const modelId = path.split("/").pop()?.split(".").shift();
@@ -171,41 +173,43 @@ measurer.list.onItemAdded.add((area) => {
171173
const meshes: THREE.Mesh[] = [];
172174

173175
// Add picking meshes (deduplicating geometries to save memory)
174-
const model = fragments.list.values().next().value!;
175-
const idsWithGeometry = await model.getItemsIdsWithGeometry();
176-
const allMeshesData = await model.getItemsGeometry(idsWithGeometry);
177-
178-
const geometries = new Map<number, THREE.BufferGeometry>();
179-
180-
for (const itemId in allMeshesData) {
181-
const meshData = allMeshesData[itemId];
182-
for (const geomData of meshData) {
183-
if (
184-
!geomData.positions ||
185-
!geomData.indices ||
186-
!geomData.transform ||
187-
!geomData.representationId
188-
) {
189-
continue;
176+
for (const [, model] of fragments.list) {
177+
const idsWithGeometry = await model.getItemsIdsWithGeometry();
178+
const allMeshesData = await model.getItemsGeometry(idsWithGeometry);
179+
180+
const geometries = new Map<number, THREE.BufferGeometry>();
181+
182+
for (const itemId in allMeshesData) {
183+
const meshData = allMeshesData[itemId];
184+
for (const geomData of meshData) {
185+
if (
186+
!geomData.positions ||
187+
!geomData.indices ||
188+
!geomData.transform ||
189+
!geomData.representationId
190+
) {
191+
continue;
192+
}
193+
194+
const representationId = geomData.representationId;
195+
if (!geometries.has(representationId)) {
196+
const geometry = new THREE.BufferGeometry();
197+
geometry.setAttribute(
198+
"position",
199+
new THREE.Float32BufferAttribute(geomData.positions, 3),
200+
);
201+
geometry.setIndex(Array.from(geomData.indices));
202+
geometries.set(representationId, geometry);
203+
}
204+
205+
const geometry = geometries.get(representationId)!;
206+
207+
const mesh = new THREE.Mesh(geometry);
208+
mesh.applyMatrix4(geomData.transform);
209+
mesh.applyMatrix4(model.object.matrixWorld);
210+
mesh.updateWorldMatrix(true, true);
211+
meshes.push(mesh);
190212
}
191-
192-
const representationId = geomData.representationId;
193-
if (!geometries.has(representationId)) {
194-
const geometry = new THREE.BufferGeometry();
195-
geometry.setAttribute(
196-
"position",
197-
new THREE.Float32BufferAttribute(geomData.positions, 3),
198-
);
199-
geometry.setIndex(Array.from(geomData.indices));
200-
geometries.set(representationId, geometry);
201-
}
202-
203-
const geometry = geometries.get(representationId)!;
204-
205-
const mesh = new THREE.Mesh(geometry);
206-
mesh.applyMatrix4(geomData.transform);
207-
mesh.updateWorldMatrix(true, true);
208-
meshes.push(mesh);
209213
}
210214
}
211215

packages/front/src/measurement/LengthMeasurement/example.ts

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -206,41 +206,43 @@ const removeComplementaryDimensions = () => {
206206
const meshes: THREE.Mesh[] = [];
207207

208208
// Add picking meshes (deduplicating geometries to save memory)
209-
const model = fragments.list.values().next().value!;
210-
const idsWithGeometry = await model.getItemsIdsWithGeometry();
211-
const allMeshesData = await model.getItemsGeometry(idsWithGeometry);
212-
213-
const geometries = new Map<number, THREE.BufferGeometry>();
214-
215-
for (const itemId in allMeshesData) {
216-
const meshData = allMeshesData[itemId];
217-
for (const geomData of meshData) {
218-
if (
219-
!geomData.positions ||
220-
!geomData.indices ||
221-
!geomData.transform ||
222-
!geomData.representationId
223-
) {
224-
continue;
209+
for (const [, model] of fragments.list) {
210+
const idsWithGeometry = await model.getItemsIdsWithGeometry();
211+
const allMeshesData = await model.getItemsGeometry(idsWithGeometry);
212+
213+
const geometries = new Map<number, THREE.BufferGeometry>();
214+
215+
for (const itemId in allMeshesData) {
216+
const meshData = allMeshesData[itemId];
217+
for (const geomData of meshData) {
218+
if (
219+
!geomData.positions ||
220+
!geomData.indices ||
221+
!geomData.transform ||
222+
!geomData.representationId
223+
) {
224+
continue;
225+
}
226+
227+
const representationId = geomData.representationId;
228+
if (!geometries.has(representationId)) {
229+
const geometry = new THREE.BufferGeometry();
230+
geometry.setAttribute(
231+
"position",
232+
new THREE.Float32BufferAttribute(geomData.positions, 3),
233+
);
234+
geometry.setIndex(Array.from(geomData.indices));
235+
geometries.set(representationId, geometry);
236+
}
237+
238+
const geometry = geometries.get(representationId)!;
239+
240+
const mesh = new THREE.Mesh(geometry);
241+
mesh.applyMatrix4(geomData.transform);
242+
mesh.applyMatrix4(model.object.matrixWorld);
243+
mesh.updateWorldMatrix(true, true);
244+
meshes.push(mesh);
225245
}
226-
227-
const representationId = geomData.representationId;
228-
if (!geometries.has(representationId)) {
229-
const geometry = new THREE.BufferGeometry();
230-
geometry.setAttribute(
231-
"position",
232-
new THREE.Float32BufferAttribute(geomData.positions, 3),
233-
);
234-
geometry.setIndex(Array.from(geomData.indices));
235-
geometries.set(representationId, geometry);
236-
}
237-
238-
const geometry = geometries.get(representationId)!;
239-
240-
const mesh = new THREE.Mesh(geometry);
241-
mesh.applyMatrix4(geomData.transform);
242-
mesh.updateWorldMatrix(true, true);
243-
meshes.push(mesh);
244246
}
245247
}
246248

0 commit comments

Comments
 (0)