File size: 2,952 Bytes
6ce4ca6
 
 
 
 
 
 
 
 
 
838a719
6ce4ca6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
838a719
6ce4ca6
 
 
 
 
 
838a719
6ce4ca6
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!-- From https://github.com/brean/urdf-viewer -->

<script lang="ts">
	// The link element describes a rigid body with an inertia, visual features, and collision properties.
	import type IUrdfLink from "../interfaces/IUrdfLink";
	import UrdfVisual from "./UrdfVisual.svelte";
	import { getChildJoints } from "../utils/UrdfParser";
	import UrdfJoint from "./UrdfJoint.svelte";
	import type IUrdfRobot from "../interfaces/IUrdfRobot";
	import { T } from "@threlte/core";
	import Pointcloud from "@/components/3d/misc/Pointcloud.svelte";

	interface Props {
		robot: IUrdfRobot;
		link: IUrdfLink;
		textScale?: number;
		showName?: boolean;
		showVisual?: boolean;
		showCollision?: boolean;
		visualColor?: string;
		visualOpacity?: number;
		collisionOpacity?: number;
		collisionColor?: string;
		jointNames?: boolean;
		joints?: boolean;
		jointColor?: string;
		jointIndicatorColor?: string;
		nameHeight?: number;
		showLine?: boolean;
		opacity?: number;
		isInteractive?: boolean;
	}

	let {
		robot,
		link,
		textScale = 1,
		showName = true,
		showVisual = true,
		showCollision = true,
		visualColor = "#000000",
		visualOpacity = 1,
		collisionOpacity = 1,
		collisionColor = "#000000",
		jointNames = true,
		joints = true,
		jointColor = "#000000",
		jointIndicatorColor = "#000000",
		nameHeight = 0.1,
		showLine = true,
		opacity = 0.7,
		isInteractive = false
	}: Props = $props();

	let showPointCloud = false;
</script>

{@html `<!-- Link ${link.name} -->`}
<!-- {#if showName}
	<Billboard position.x={0} position.y={0} position.z={0}>
		<Text anchorY={-0.2} scale={textScale} text={link.name} characters="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		></Text>
	</Billboard>
{/if} -->

{#if showVisual}
	{#each link.visual as visual}
		<UrdfVisual opacity={visualOpacity} {visual} defaultColor={visualColor} />
	{/each}
{/if}

{#if showCollision}
	{#each link.collision as visual}
		<UrdfVisual opacity={collisionOpacity} {visual} defaultColor={collisionColor} />
	{/each}
{/if}

{#each getChildJoints(robot, link) as joint (joint.name)}
	<UrdfJoint
		{robot}
		{joint}
		{showName}
		{nameHeight}
		{jointColor}
		{jointIndicatorColor}
		{showLine}
		{opacity}
		{isInteractive}
		{showVisual}
		{showCollision}
		{visualOpacity}
		{collisionOpacity}
		{collisionColor}
		{jointNames}
		{joints}
	/>
	{#if joint.type === "fixed" && showPointCloud}
		<T.Group
			position={[joint.origin_xyz[0], joint.origin_xyz[1], joint.origin_xyz[2]]}
			rotation={joint.origin_rpy}
		>
			<T.Group scale={[0.1, 0.1, 0.1]}>
				<T.Mesh scale={[0.1, 0.1, 0.1]}>
					<T.BoxGeometry />
					<T.MeshBasicMaterial color="red" />
				</T.Mesh>
				<Pointcloud
					cameraPositionX={joint.origin_xyz[0]}
					cameraPositionY={joint.origin_xyz[1]}
					cameraPositionZ={joint.origin_xyz[2]}
					cameraRotationX={joint.origin_rpy[0]}
					cameraRotationY={joint.origin_rpy[1]}
					cameraRotationZ={joint.origin_rpy[2]}
				/>
			</T.Group>
		</T.Group>
	{/if}
{/each}