Files
cad-world/frontend/tests/integration/codecs/urdf.integration.spec.ts
T
2026-09-22 10:36:28 +08:00

736 lines
24 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import * as THREE from 'three'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { createDefaultWorkbench, RfsGeomType } from '@/modules'
import { buildImportedPartGraph } from '@/components/part-manager/buildImportedPartGraph'
import {
buildManagedComponentPreview,
buildManagedComponentPreviewFromRfsProject,
} from '@/components/part-manager/buildManagedComponentPreview'
import {
RfsToModelImporter,
UrdfToModelImporter,
buildRfsDocumentFromModel,
} from '@/modules/infrastructure/codecs'
import { ModelToUrdfExporter } from '@/modules/infrastructure/codecs/urdf/model-to-urdf-exporter'
import { resolveAssemblySceneWorldPoses } from '@/modules/application/scene-assembly/assembly-scene-kinematics'
import { partTransformToQuaternion } from '@/modules/application/scene-assembly/part-transform-utils'
import { getWorkbenchGeomQuaternionFromMjcf } from '@/modules/application/simulation/mjcf-geom-basis'
import { expectModelsToBeSemanticallyEqual, readFixture } from '@tests/helpers'
describe('URDF codecs integration', () => {
const readWorkspaceFile = (...segments: string[]): string =>
readFileSync(resolve(process.cwd(), ...segments), 'utf8')
const readWorkspaceBinaryFile = (...segments: string[]): Uint8Array =>
readFileSync(resolve(process.cwd(), ...segments))
const attachRelativePath = (file: File, relativePath: string): File => {
Object.defineProperty(file, 'webkitRelativePath', {
configurable: true,
enumerable: false,
value: relativePath,
})
return file
}
const URDF_TO_SCENE_BASIS = new THREE.Quaternion(
-Math.SQRT1_2,
0,
0,
Math.SQRT1_2,
).normalize()
const urdfRpyToSceneQuaternion = (roll: number, pitch: number, yaw: number): THREE.Quaternion => {
const halfRoll = roll * 0.5
const halfPitch = pitch * 0.5
const halfYaw = yaw * 0.5
const cr = Math.cos(halfRoll)
const sr = Math.sin(halfRoll)
const cp = Math.cos(halfPitch)
const sp = Math.sin(halfPitch)
const cy = Math.cos(halfYaw)
const sy = Math.sin(halfYaw)
const urdfQuaternion = new THREE.Quaternion(
sr * cp * cy - cr * sp * sy,
cr * sp * cy + sr * cp * sy,
cr * cp * sy - sr * sp * cy,
cr * cp * cy + sr * sp * sy,
).normalize()
return URDF_TO_SCENE_BASIS.clone()
.multiply(urdfQuaternion)
.multiply(URDF_TO_SCENE_BASIS.clone().invert())
.normalize()
}
const expectQuaternionEquivalent = (actual: THREE.Quaternion, expected: THREE.Quaternion) => {
expect(Math.abs(actual.normalize().dot(expected.normalize()))).toBeGreaterThan(1 - 1e-6)
}
const toThreeQuaternion = (value: { x: number; y: number; z: number; w: number }): THREE.Quaternion => (
new THREE.Quaternion(value.x, value.y, value.z, value.w).normalize()
)
const collectExpectedVisualQuaternions = (model: {
rootBody: {
children: Array<{
name: string
body: { quat: [number, number, number, number] }
geoms: Array<{ type: number; quat: [number, number, number, number] }>
children: unknown[]
}>
}
}) => {
const result = new Map<string, THREE.Quaternion>()
const walk = (
node: {
name: string
body: { quat: [number, number, number, number] }
geoms: Array<{ type: number; quat: [number, number, number, number] }>
children: unknown[]
},
parentWorldQuaternion: THREE.Quaternion,
) => {
const bodyQuaternion = new THREE.Quaternion(
node.body.quat[1] ?? 0,
node.body.quat[2] ?? 0,
node.body.quat[3] ?? 0,
node.body.quat[0] ?? 1,
).normalize()
const worldQuaternion = parentWorldQuaternion.clone().multiply(bodyQuaternion).normalize()
const meshGeom = node.geoms.find((geom) => geom.type === RfsGeomType.MESH)
if (meshGeom) {
result.set(
node.name,
worldQuaternion
.clone()
.multiply(getWorkbenchGeomQuaternionFromMjcf(meshGeom.type, meshGeom.quat))
.normalize(),
)
}
node.children.forEach((child) => {
walk(child as Parameters<typeof walk>[0], worldQuaternion)
})
}
model.rootBody.children.forEach((child) => {
walk(child, new THREE.Quaternion())
})
return result
}
const collectPreviewVisualQuaternions = (
preview: ReturnType<typeof buildManagedComponentPreview>,
) => {
const worldPoseByInstanceId = collectPreviewWorldPoses(preview)
const result = new Map<string, THREE.Quaternion>()
preview.model.sceneInstances.forEach((instance) => {
const part = preview.sourcePartById[instance.sourceId]
const pose = worldPoseByInstanceId.get(instance.instanceId)
if (!part || !pose) {
return
}
result.set(
part.name,
toThreeQuaternion(pose.rotation)
.multiply(partTransformToQuaternion(part.transform))
.normalize(),
)
})
return result
}
const collectPreviewWorldPoses = (
preview: ReturnType<typeof buildManagedComponentPreview>,
) => resolveAssemblySceneWorldPoses({
instances: preview.model.sceneInstances,
connections: preview.model.sceneConnections,
findPartBySourceId: (sourceId) => preview.sourcePartById[sourceId] ?? null,
jointInitialValues: preview.jointInitialValues,
})
const collectPreviewLinkFrameQuaternions = (
preview: ReturnType<typeof buildManagedComponentPreview>,
) => {
const worldPoseByInstanceId = collectPreviewWorldPoses(preview)
const result = new Map<string, THREE.Quaternion>()
preview.model.sceneInstances.forEach((instance) => {
const part = preview.sourcePartById[instance.sourceId]
const pose = worldPoseByInstanceId.get(instance.instanceId)
if (!part || !pose) {
return
}
result.set(part.name, toThreeQuaternion(pose.rotation))
})
return result
}
const createHipMeshFile = () => new File(
['<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1"></COLLADA>'],
'hip.dae',
{ type: 'model/vnd.collada+xml' },
)
const createA7MeshFiles = () => [
'base_link.STL',
'A1_Link.STL',
'A2_Link.STL',
'A3_Link.STL',
'A4_Link.STL',
'A5_Link.STL',
'A6_Link.STL',
'A7_Link.STL',
'A8_Link.STL',
].map((fileName) => attachRelativePath(
new File(
[readWorkspaceBinaryFile('urdf对比', 'A7_V2.0', 'meshes', fileName)],
fileName,
{ type: 'model/stl' },
),
`meshes/${fileName}`,
))
const getJointBlock = (urdf: string, jointName: string): string => {
const match = urdf.match(new RegExp(`<joint name="${jointName}"[\\s\\S]*?<\\/joint>`))
expect(match?.[0]).toBeTruthy()
return match?.[0] ?? ''
}
const getLimitAttrs = (jointBlock: string) => {
const match = jointBlock.match(/<limit\s+([^/>]+)\/>/)
expect(match?.[1]).toBeTruthy()
const attrs = Object.fromEntries(
Array.from((match?.[1] ?? '').matchAll(/(\w+)="([^"]+)"/g))
.map((item) => [item[1], Number(item[2])]),
)
return attrs
}
it('imports a fixture URDF document', () => {
const model = new UrdfToModelImporter().parseFromText({
urdfText: readFixture('codecs', 'minimal-robot.urdf'),
modelId: 'fixture-urdf',
})
expect(model.name).toBe('fixture_robot')
expect(model.listBodyNodes().length).toBeGreaterThan(1)
})
it('round-trips exported URDF back into the same semantic structure', () => {
const importer = new UrdfToModelImporter()
const sourceModel = importer.parseFromText({
urdfText: readFixture('codecs', 'minimal-robot.urdf'),
modelId: 'fixture-urdf',
})
const exported = new ModelToUrdfExporter().export(sourceModel)
const reparsed = importer.parseFromText({
urdfText: exported,
modelId: sourceModel.id,
modelName: sourceModel.name,
})
expect(exported).toContain('<robot')
expect(exported).toContain('base_to_tool')
expectModelsToBeSemanticallyEqual(reparsed, sourceModel)
})
it('exports edited URDF joints from live model state instead of source metadata', () => {
const sourceModel = new UrdfToModelImporter().parseFromText({
urdfText: `<?xml version="1.0"?>
<robot name="edited_joint_fixture">
<link name="base">
<visual>
<geometry>
<box size="0.1 0.1 0.1" />
</geometry>
</visual>
</link>
<link name="tool">
<visual>
<geometry>
<box size="0.05 0.05 0.05" />
</geometry>
</visual>
</link>
<joint name="base_to_tool" type="revolute">
<parent link="base" />
<child link="tool" />
<origin xyz="0 0 0.1" rpy="0 0 0" />
<axis xyz="0 0 1" />
<limit lower="-1" upper="1" effort="5" velocity="2.5" />
</joint>
</robot>`,
modelId: 'edited-joint-fixture',
})
const toolNode = sourceModel.listBodyNodes().find((node) => node.name === 'tool')
expect(toolNode?.joints[0]).toBeTruthy()
if (!toolNode?.joints[0]) {
return
}
toolNode.body.pos[0] = 0.25
toolNode.body.pos[1] = -0.1
toolNode.body.pos[2] = 0.5
toolNode.joints[0].type = 2
toolNode.joints[0].axis[0] = 1
toolNode.joints[0].axis[1] = 0
toolNode.joints[0].axis[2] = 0
toolNode.joints[0].range[0] = -0.2
toolNode.joints[0].range[1] = 0.4
const exported = new ModelToUrdfExporter().export(sourceModel)
const jointBlock = getJointBlock(exported, 'base_to_tool')
const attrs = getLimitAttrs(jointBlock)
expect(jointBlock).toContain('type="prismatic"')
expect(jointBlock).toContain('<origin xyz="0.25 -0.5000000000000001 -0.10000000000000014"/>')
expect(jointBlock).not.toContain('<origin xyz="0 0 0.1"')
expect(jointBlock).toContain('<axis xyz="1 0 0"/>')
expect(attrs.lower).toBeCloseTo(-0.2)
expect(attrs.upper).toBeCloseTo(0.4)
expect(attrs.velocity).toBeCloseTo(2.5)
})
it('preserves SolidWorks URDF physical, collision, and joint limit metadata on direct export', () => {
const sourceUrdf = readWorkspaceFile('urdf对比', 'A7_V2.0', 'A7_V2.0.urdf')
const sourceModel = new UrdfToModelImporter().parseFromText({
urdfText: sourceUrdf,
modelId: 'a7-solidworks-urdf',
})
const exported = new ModelToUrdfExporter().export(sourceModel, {
includeCollision: true,
meshPathResolver: (meshName) => meshName,
})
expect((exported.match(/<collision>/g) ?? [])).toHaveLength(9)
expect((exported.match(/<inertial>/g) ?? [])).toHaveLength(9)
expect(exported).toContain('ixx="0.00050831"')
expect(exported).toContain('ixy="0.0000041242"')
const expectedLimits = {
A1_Joint: { effort: 80, velocity: 10.47 },
A2_Joint: { effort: 80, velocity: 10.47 },
A3_Joint: { effort: 36, velocity: 9.1 },
A4_Joint: { effort: 36, velocity: 9.1 },
A5_Joint: { effort: 36, velocity: 9.1 },
A6_Joint: { effort: 18, velocity: 7.33 },
A7_Joint: { effort: 18, velocity: 7.33 },
}
Object.entries(expectedLimits).forEach(([jointName, expected]) => {
const attrs = getLimitAttrs(getJointBlock(exported, jointName))
expect(attrs.effort).toBeCloseTo(expected.effort)
expect(attrs.velocity).toBeCloseTo(expected.velocity)
})
const a4Joint = getJointBlock(exported, 'A4_Joint')
expect(a4Joint).toContain('<axis xyz="0 1 0"/>')
expect(a4Joint).not.toContain('1.0559241974565692')
expect(getJointBlock(exported, 'A8_Joint')).toContain('type="fixed"')
})
it('keeps SolidWorks URDF metadata through RFS project preview rebuild', () => {
const sourceUrdf = readWorkspaceFile('urdf对比', 'A7_V2.0', 'A7_V2.0.urdf')
const model = new UrdfToModelImporter().parseFromText({
urdfText: sourceUrdf,
modelId: 'a7-rfs-project-roundtrip',
})
const meshFiles = createA7MeshFiles()
const freshPreview = buildManagedComponentPreview(model, meshFiles)
const rfsText = JSON.stringify(buildRfsDocumentFromModel(freshPreview.model, freshPreview.parts))
const parsedProject = new RfsToModelImporter().parseProjectFromText({ rfsText })
const rebuiltPreview = buildManagedComponentPreviewFromRfsProject(parsedProject, meshFiles)
const a4Part = rebuiltPreview.parts.find((part) => part.name === 'A4_Link')
expect(a4Part?.physical.mass).toBeCloseTo(0.94109)
expect(a4Part?.physical.centerOfMass?.y).toBeCloseTo(0.084098)
expect(a4Part?.physical.centerOfMass?.z).toBeCloseTo(0.00098093)
expect(a4Part?.physical.inertia?.ixy).toBeCloseTo(4.1242e-6)
expect(a4Part?.collisionGeoms).toHaveLength(1)
const a4Joint = rebuiltPreview.parts
.flatMap((part) => part.joints)
.find((joint) => joint.name === 'A4_Joint')
expect(a4Joint?.limits.actuatorfrcrange).toEqual([-36, 36])
expect(a4Joint?.sourceMetadata.urdf?.limit?.velocity).toBeCloseTo(9.1)
expect(a4Joint?.sourceMetadata.urdf?.axis).toEqual([0, 1, 0])
const a8Part = rebuiltPreview.parts.find((part) => part.name === 'A8_Link')
expect(a8Part?.sourceMetadata?.urdf?.inboundJoint?.name).toBe('A8_Joint')
})
it('skips decorative fixed URDF side attachments while keeping distal fixed tips', () => {
const model = new UrdfToModelImporter().parseFromText({
urdfText: `<?xml version="1.0"?>
<robot name="decorative_fixed_fixture">
<link name="trunk">
<visual>
<geometry>
<box size="0.2 0.1 0.1" />
</geometry>
</visual>
</link>
<link name="leg">
<visual>
<geometry>
<box size="0.1 0.1 0.3" />
</geometry>
</visual>
</link>
<link name="rotor">
<visual>
<geometry>
<cylinder radius="0.02" length="0.04" />
</geometry>
</visual>
</link>
<link name="imu_link">
<visual>
<geometry>
<box size="0.01 0.01 0.01" />
</geometry>
</visual>
</link>
<link name="foot">
<visual>
<geometry>
<sphere radius="0.03" />
</geometry>
</visual>
</link>
<joint name="hip_joint" type="revolute">
<parent link="trunk" />
<child link="leg" />
<axis xyz="0 0 1" />
</joint>
<joint name="rotor_joint" type="fixed">
<parent link="trunk" />
<child link="rotor" />
</joint>
<joint name="imu_joint" type="fixed">
<parent link="trunk" />
<child link="imu_link" />
</joint>
<joint name="foot_joint" type="fixed">
<parent link="leg" />
<child link="foot" />
</joint>
</robot>`,
modelId: 'decorative-fixed-fixture',
})
const workbench = createDefaultWorkbench()
const { importedParts, partRecords } = buildImportedPartGraph(workbench, model, [], {
meshLocalFrame: 'urdf',
})
expect(importedParts.map((part) => part.name)).toEqual(['trunk', 'leg', 'foot'])
expect(partRecords.map(({ node }) => node.name)).toEqual(['trunk', 'leg', 'foot'])
})
it('keeps the root frame, skips root-level fixed rotor attachments, and does not reuse the hip mesh', () => {
const model = new UrdfToModelImporter().parseFromText({
urdfText: `<?xml version="1.0"?>
<robot name="root_rotor_fixture">
<link name="base_link" />
<link name="RR_hip">
<visual>
<geometry>
<mesh filename="package://fixture/meshes/RR_hip.dae" />
</geometry>
</visual>
</link>
<link name="RR_hip_rotor">
<collision>
<geometry>
<cylinder radius="0.02" length="0.04" />
</geometry>
</collision>
</link>
<joint name="RR_hip_joint" type="revolute">
<parent link="base_link" />
<child link="RR_hip" />
<axis xyz="1 0 0" />
</joint>
<joint name="RR_hip_rotor_joint" type="fixed">
<parent link="base_link" />
<child link="RR_hip_rotor" />
</joint>
</robot>`,
modelId: 'root-rotor-fixture',
})
const meshFiles = [
attachRelativePath(
new File(
['<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1"></COLLADA>'],
'RR_hip.dae',
{ type: 'model/vnd.collada+xml' },
),
'meshes/RR_hip.dae',
),
]
const workbench = createDefaultWorkbench()
const { importedParts, partRecords } = buildImportedPartGraph(workbench, model, meshFiles, {
meshLocalFrame: 'urdf',
})
expect(importedParts.map((part) => part.name)).toEqual(['base_link (hidden frame)', 'RR_hip'])
expect(partRecords.map(({ node }) => node.name)).toEqual(['base_link', 'RR_hip'])
expect(importedParts.filter((part) => part.meshFileName === 'RR_hip.dae')).toHaveLength(1)
})
it('keeps inertial-only root links in the imported part graph', () => {
const model = new UrdfToModelImporter().parseFromText({
urdfText: `<?xml version="1.0"?>
<robot name="root_inertia_fixture">
<link name="base_link">
<inertial>
<mass value="2" />
<origin xyz="0 0 0.02" rpy="0 0 0" />
<inertia ixx="0.1" ixy="0" ixz="0" iyy="0.1" iyz="0" izz="0.1" />
</inertial>
</link>
<link name="arm">
<visual>
<geometry>
<box size="0.1 0.1 0.2" />
</geometry>
</visual>
</link>
<joint name="base_to_arm" type="revolute">
<parent link="base_link" />
<child link="arm" />
<axis xyz="0 0 1" />
</joint>
</robot>`,
modelId: 'root-inertia-fixture',
})
const workbench = createDefaultWorkbench()
const { importedParts, partRecords } = buildImportedPartGraph(workbench, model, [], {
meshLocalFrame: 'urdf',
})
expect(importedParts.map((part) => part.name)).toEqual(['base_link (hidden frame)', 'arm'])
expect(partRecords.map(({ node }) => node.name)).toEqual(['base_link', 'arm'])
expect(importedParts[0]?.physical.mass).toBeCloseTo(2)
})
it('preserves distinct visual origin rotations for reused hip meshes', () => {
const hipCases = {
fr_hip: [Math.PI, 0, 0],
fl_hip: [0, 0, 0],
rr_hip: [Math.PI, Math.PI, 0],
rl_hip: [0, Math.PI, 0],
} as const
const hipLinks = Object.entries(hipCases).map(([name, rpy], index) => `
<link name="${name}">
<visual>
<origin xyz="0 0 0" rpy="${rpy.join(' ')}" />
<geometry>
<mesh filename="package://fixture/meshes/hip.dae" scale="1 1 1" />
</geometry>
</visual>
</link>
<link name="${name}_foot">
<visual>
<geometry>
<box size="0.01 0.01 0.01" />
</geometry>
</visual>
</link>
<joint name="base_to_${name}" type="fixed">
<parent link="base" />
<child link="${name}" />
<origin xyz="${index * 0.1} 0 0" rpy="0 0 0" />
</joint>
<joint name="${name}_to_foot" type="fixed">
<parent link="${name}" />
<child link="${name}_foot" />
<origin xyz="0 0 -0.1" rpy="0 0 0" />
</joint>`)
const model = new UrdfToModelImporter().parseFromText({
urdfText: `<?xml version="1.0"?>
<robot name="reused_hip_fixture">
<link name="base">
<visual>
<geometry>
<box size="0.01 0.01 0.01" />
</geometry>
</visual>
</link>${hipLinks.join('')}
</robot>`,
modelId: 'reused-hip-fixture',
})
const meshFiles = [createHipMeshFile()]
const workbench = createDefaultWorkbench()
const { importedParts } = buildImportedPartGraph(workbench, model, meshFiles, {
meshLocalFrame: 'urdf',
})
const importedHipParts = Object.fromEntries(
importedParts
.filter((part) => Object.keys(hipCases).includes(part.name))
.map((part) => [part.name, part]),
)
expect(Object.keys(importedHipParts).sort()).toEqual(Object.keys(hipCases).sort())
Object.entries(hipCases).forEach(([name, [roll, pitch, yaw]]) => {
const part = importedHipParts[name]
expect(part?.transform.rotationOrder).toBe('ZYX')
if (!part) {
return
}
const actualQuaternion = partTransformToQuaternion(part.transform)
const expectedQuaternion = urdfRpyToSceneQuaternion(roll, pitch, yaw)
expectQuaternionEquivalent(actualQuaternion, expectedQuaternion)
})
})
it('preserves reused URDF mesh orientations after RFS export and project-preview rebuild', () => {
const hipCases = {
fr_hip: [Math.PI, 0, 0],
fl_hip: [0, 0, 0],
rr_hip: [Math.PI, Math.PI, 0],
rl_hip: [0, Math.PI, 0],
} as const
const hipLinks = Object.entries(hipCases).map(([name, rpy], index) => `
<link name="${name}">
<visual>
<origin xyz="0 0 0" rpy="${rpy.join(' ')}" />
<geometry>
<mesh filename="package://fixture/meshes/hip.dae" scale="1 1 1" />
</geometry>
</visual>
</link>
<joint name="base_to_${name}" type="revolute">
<parent link="base" />
<child link="${name}" />
<origin xyz="${index * 0.1} 0 0" rpy="0 0 0" />
<axis xyz="1 0 0" />
<limit effort="1" lower="-1" upper="1" velocity="1" />
</joint>`)
const model = new UrdfToModelImporter().parseFromText({
urdfText: `<?xml version="1.0"?>
<robot name="reused_hip_preview_fixture">
<link name="base">
<visual>
<geometry>
<box size="0.01 0.01 0.01" />
</geometry>
</visual>
</link>${hipLinks.join('')}
</robot>`,
modelId: 'reused-hip-preview-fixture',
})
const meshFiles = [createHipMeshFile()]
const expectedVisualQuaternions = collectExpectedVisualQuaternions(model)
const freshPreview = buildManagedComponentPreview(model, meshFiles)
const freshVisualQuaternions = collectPreviewVisualQuaternions(freshPreview)
Object.keys(hipCases).forEach((name) => {
expectQuaternionEquivalent(
freshVisualQuaternions.get(name)!,
expectedVisualQuaternions.get(name)!,
)
})
const rfsText = JSON.stringify(buildRfsDocumentFromModel(freshPreview.model, freshPreview.parts))
const parsedProject = new RfsToModelImporter().parseProjectFromText({ rfsText })
const rebuiltPreview = buildManagedComponentPreviewFromRfsProject(parsedProject, meshFiles)
const rebuiltVisualQuaternions = collectPreviewVisualQuaternions(rebuiltPreview)
Object.keys(hipCases).forEach((name) => {
expectQuaternionEquivalent(
rebuiltVisualQuaternions.get(name)!,
expectedVisualQuaternions.get(name)!,
)
})
})
it('keeps child link frames independent from parent visual mesh rotations during preview rebuild', () => {
const expectedLinkQuaternion = new THREE.Quaternion()
const expectedHipVisualQuaternion = urdfRpyToSceneQuaternion(Math.PI, 0, 0)
const model = new UrdfToModelImporter().parseFromText({
urdfText: `<?xml version="1.0"?>
<robot name="visual_origin_child_fixture">
<link name="base">
<visual>
<geometry>
<box size="0.01 0.01 0.01" />
</geometry>
</visual>
</link>
<link name="hip">
<visual>
<origin xyz="0 0 0" rpy="${Math.PI} 0 0" />
<geometry>
<mesh filename="package://fixture/meshes/hip.dae" scale="1 1 1" />
</geometry>
</visual>
</link>
<link name="foot">
<visual>
<geometry>
<box size="0.01 0.01 0.01" />
</geometry>
</visual>
</link>
<joint name="base_to_hip" type="revolute">
<parent link="base" />
<child link="hip" />
<origin xyz="0 0 0" rpy="0 0 0" />
<axis xyz="1 0 0" />
<limit effort="1" lower="-1" upper="1" velocity="1" />
</joint>
<joint name="hip_to_foot" type="fixed">
<parent link="hip" />
<child link="foot" />
<origin xyz="0 0 -0.1" rpy="0 0 0" />
</joint>
</robot>`,
modelId: 'visual-origin-child-fixture',
})
const meshFiles = [createHipMeshFile()]
const freshPreview = buildManagedComponentPreview(model, meshFiles)
const freshLinkQuaternions = collectPreviewLinkFrameQuaternions(freshPreview)
const freshVisualQuaternions = collectPreviewVisualQuaternions(freshPreview)
expectQuaternionEquivalent(freshLinkQuaternions.get('hip')!, expectedLinkQuaternion)
expectQuaternionEquivalent(freshLinkQuaternions.get('foot')!, expectedLinkQuaternion)
expectQuaternionEquivalent(freshVisualQuaternions.get('hip')!, expectedHipVisualQuaternion)
const rfsText = JSON.stringify(buildRfsDocumentFromModel(freshPreview.model, freshPreview.parts))
const parsedProject = new RfsToModelImporter().parseProjectFromText({ rfsText })
const rebuiltPreview = buildManagedComponentPreviewFromRfsProject(parsedProject, meshFiles)
const rebuiltLinkQuaternions = collectPreviewLinkFrameQuaternions(rebuiltPreview)
const rebuiltVisualQuaternions = collectPreviewVisualQuaternions(rebuiltPreview)
expectQuaternionEquivalent(rebuiltLinkQuaternions.get('hip')!, expectedLinkQuaternion)
expectQuaternionEquivalent(rebuiltLinkQuaternions.get('foot')!, expectedLinkQuaternion)
expectQuaternionEquivalent(rebuiltVisualQuaternions.get('hip')!, expectedHipVisualQuaternion)
})
})