Creating subsets from a loop, always crashes after the first one
GeoHaz7 opened this issue · 2 comments
GeoHaz7 commented
so im trying to create subsets based on a loop of models that i have, unfortunately it always creates the first one then it crashes, with error :
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'mesh')
const createSubsetsFromArray = async () => {
await Promise.all(
props.models.map(async (model) => {
const { ifcApi } = props;
ifcApi.IFC.selector.unpickIfcItems();
ifcApi.IFC.selector.unHighlightIfcItems();
try {
const subset = ifcApi.IFC.loader.ifcManager.createSubset({
modelID: model.modelID,
ids: Array.from(new Set(model.geometry.attributes.expressID.array)),
applyBVH: true,
scene: model.parent,
removePrevious: true,
customID: 'full-model-subset' + model.modelID,
});
return subset; // Add a return statement here to return the subset
} catch (error) {
console.error(`Error creating subset for model ${model.modelID}: ${error}`);
return null; // Return null if an error occurs
}
})
);
};
joselazcanor commented
I'm not very experimented with promises, but: What if you try to set an "await" in the const subset?
const subset = await ifcApi.IFC.loader.ifcManager.createSubset
agviegas commented
I also suspect that you are you are skipping the await of a promise. Have you tried something simpler?
const subsets = [];
for(const model of models) {
const subset = await ifcApi.IFC.loader.ifcManager.createSubset({ ... });
subsets.push(subset);
}
Alternatively, you can also use the dev tools and, if it fails, see where it fails. Cheers!