🪖 Moves modelloader to model-utilities

This commit is contained in:
Rune Harlyk
2024-02-22 23:51:53 +01:00
parent 5e789fce38
commit e2291813a5
2 changed files with 3 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
import { LoaderUtils } from "three";
import URDFLoader, { type URDFRobot } from "urdf-loader"
import { XacroLoader } from "xacro-parser"
export const loadModelAsync = async (url:string):Promise<[URDFRobot, string[]]> => {
return new Promise((resolve, reject) => {
const xacroLoader = new XacroLoader();
xacroLoader.load(url, async (xml) => {
const urdfLoader = new URDFLoader();
urdfLoader.workingPath = LoaderUtils.extractUrlBase(url);
try {
const model = urdfLoader.parse(xml);
model.rotation.x = -Math.PI / 2;
model.rotation.z = Math.PI / 2;
model.traverse(c => c.castShadow = true);
model.updateMatrixWorld(true);
model.scale.setScalar(10);
const joints = Object.entries(model.joints)
.filter(joint => joint[1].jointType !== 'fixed')
.map(joint => joint[0])
resolve([model, joints]);
} catch (error) {
reject(error);
}
}, (error) => reject(error));
});
}