I am using “load” and “OBJloader” from loaders.gl/core and loaders.gl/obj to load a mesh to export it as a const so other module can use it, currently I am using this
export const myMesh = Object.freez({
mesh : load(path_to_obj_file,OBJLoader),
origin: [1.4,0,2.2],
dimensions: [2,2,2],
scale: 1
)}
but then I find out that I can calculate the origin and dimensions from the obj file itself without the need to put them manually (I used to calculate them form meshlab), and I can do it from the load function itself
load(path_to_obj_file,OBJLoader).then((obj)=>{
console.log(obj.schema.metadata.get["boundingBox"]
}
boundingBox would be like that [[-1.4,-1,-2],[0.6,1,-0.2]] (numbers are not accurate at all).
and I can calculate origin and dims from the boundingBox.
my question is, how can I export the const myMesh now? since I have promise, also when we write:
mesh : load(path_to_obj_file,OBJLoader)
could that cause a problem since load returns a promise ? (currently it is working correctly)
I tried:
export const loadMyMesh = load(path_to_obje_file,OBJLoader).then((obj) =>{
const myMesh = Object.freez({
mesh: obj,
origin: calculateOrigin(obj),
dimensions: claculateDim(obj),
scale: 1
});
return myMesh
})
where calculateOrigin and calculateDim are functions used to get the boundingbox and calculate the origin and the dims, but that didn’t work.
so any solution ?