@operato/scene-urdf 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +41 -0
- package/assets/images/spinner.png +0 -0
- package/demo/index.html +109 -0
- package/dist/editors/index.d.ts +0 -0
- package/dist/editors/index.js +2 -0
- package/dist/editors/index.js.map +1 -0
- package/dist/elements/drag-n-drop.d.ts +2 -0
- package/dist/elements/drag-n-drop.js +126 -0
- package/dist/elements/drag-n-drop.js.map +1 -0
- package/dist/elements/urdf-controller-element.d.ts +12 -0
- package/dist/elements/urdf-controller-element.js +283 -0
- package/dist/elements/urdf-controller-element.js.map +1 -0
- package/dist/elements/urdf-drag-controls.d.ts +32 -0
- package/dist/elements/urdf-drag-controls.js +185 -0
- package/dist/elements/urdf-drag-controls.js.map +1 -0
- package/dist/elements/urdf-manipulator-element.d.ts +15 -0
- package/dist/elements/urdf-manipulator-element.js +110 -0
- package/dist/elements/urdf-manipulator-element.js.map +1 -0
- package/dist/elements/urdf-viewer-element.d.ts +53 -0
- package/dist/elements/urdf-viewer-element.js +401 -0
- package/dist/elements/urdf-viewer-element.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/index.d.ts +14 -0
- package/dist/templates/index.js +4 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/urdf-controller.d.ts +14 -0
- package/dist/templates/urdf-controller.js +16 -0
- package/dist/templates/urdf-controller.js.map +1 -0
- package/dist/templates/urdf-viewer.d.ts +14 -0
- package/dist/templates/urdf-viewer.js +16 -0
- package/dist/templates/urdf-viewer.js.map +1 -0
- package/dist/urdf-controller.d.ts +27 -0
- package/dist/urdf-controller.js +65 -0
- package/dist/urdf-controller.js.map +1 -0
- package/dist/urdf-viewer.d.ts +50 -0
- package/dist/urdf-viewer.js +198 -0
- package/dist/urdf-viewer.js.map +1 -0
- package/icons/urdf-controller.png +0 -0
- package/icons/urdf-viewer.png +0 -0
- package/package.json +66 -0
- package/src/editors/index.ts +0 -0
- package/src/elements/drag-n-drop.ts +142 -0
- package/src/elements/urdf-controller-element.ts +297 -0
- package/src/elements/urdf-drag-controls.ts +248 -0
- package/src/elements/urdf-manipulator-element.ts +133 -0
- package/src/elements/urdf-viewer-element.ts +495 -0
- package/src/index.ts +2 -0
- package/src/templates/index.ts +4 -0
- package/src/templates/urdf-controller.ts +16 -0
- package/src/templates/urdf-viewer.ts +16 -0
- package/src/urdf-controller.ts +82 -0
- package/src/urdf-viewer.ts +249 -0
- package/things-scene.config.js +7 -0
- package/translations/en.json +16 -0
- package/translations/ko.json +16 -0
- package/translations/ms.json +16 -0
- package/translations/zh.json +16 -0
- package/tsconfig.json +22 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/web-dev-server.config.mjs +27 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Raycaster, Vector3, Scene, Camera, Ray } from 'three';
|
|
2
|
+
import { URDFJoint } from 'urdf-loader';
|
|
3
|
+
export declare class URDFDragControls {
|
|
4
|
+
scene: Scene;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
raycaster: Raycaster;
|
|
7
|
+
initialGrabPoint: Vector3;
|
|
8
|
+
hitDistance: number;
|
|
9
|
+
hovered: any;
|
|
10
|
+
manipulating: any;
|
|
11
|
+
constructor(scene: Scene);
|
|
12
|
+
update(): void;
|
|
13
|
+
updateJoint(joint: URDFJoint, angle: number): void;
|
|
14
|
+
onDragStart(joint: URDFJoint): void;
|
|
15
|
+
onDragEnd(joint: URDFJoint): void;
|
|
16
|
+
onHover(joint: URDFJoint): void;
|
|
17
|
+
onUnhover(joint: URDFJoint): void;
|
|
18
|
+
getRevoluteDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3): number;
|
|
19
|
+
getPrismaticDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3): number;
|
|
20
|
+
moveRay(toRay: Ray): void;
|
|
21
|
+
setGrabbed(grabbed: boolean): void;
|
|
22
|
+
}
|
|
23
|
+
export declare class PointerURDFDragControls extends URDFDragControls {
|
|
24
|
+
camera: Camera;
|
|
25
|
+
domElement: HTMLElement;
|
|
26
|
+
_mouseDown: (e: MouseEvent) => void;
|
|
27
|
+
_mouseMove: (e: MouseEvent) => void;
|
|
28
|
+
_mouseUp: (e: MouseEvent) => void;
|
|
29
|
+
constructor(scene: Scene, camera: Camera, domElement: HTMLElement);
|
|
30
|
+
getRevoluteDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3): number;
|
|
31
|
+
dispose(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { Raycaster, Vector3, Plane, Vector2 } from 'three';
|
|
2
|
+
// Find the nearest parent that is a joint
|
|
3
|
+
function isJoint(j) {
|
|
4
|
+
return j.isURDFJoint && j.jointType !== 'fixed';
|
|
5
|
+
}
|
|
6
|
+
function findNearestJoint(child) {
|
|
7
|
+
let curr = child;
|
|
8
|
+
while (curr) {
|
|
9
|
+
if (isJoint(curr)) {
|
|
10
|
+
return curr;
|
|
11
|
+
}
|
|
12
|
+
curr = curr.parent;
|
|
13
|
+
}
|
|
14
|
+
return curr;
|
|
15
|
+
}
|
|
16
|
+
const prevHitPoint = new Vector3();
|
|
17
|
+
const newHitPoint = new Vector3();
|
|
18
|
+
const pivotPoint = new Vector3();
|
|
19
|
+
const tempVector = new Vector3();
|
|
20
|
+
const tempVector2 = new Vector3();
|
|
21
|
+
const projectedStartPoint = new Vector3();
|
|
22
|
+
const projectedEndPoint = new Vector3();
|
|
23
|
+
const plane = new Plane();
|
|
24
|
+
export class URDFDragControls {
|
|
25
|
+
constructor(scene) {
|
|
26
|
+
this.enabled = true;
|
|
27
|
+
this.scene = scene;
|
|
28
|
+
this.raycaster = new Raycaster();
|
|
29
|
+
this.initialGrabPoint = new Vector3();
|
|
30
|
+
this.hitDistance = -1;
|
|
31
|
+
this.hovered = null;
|
|
32
|
+
this.manipulating = null;
|
|
33
|
+
}
|
|
34
|
+
update() {
|
|
35
|
+
const { raycaster, hovered, manipulating, scene } = this;
|
|
36
|
+
if (manipulating) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
let hoveredJoint = null;
|
|
40
|
+
const intersections = raycaster.intersectObject(scene, true);
|
|
41
|
+
if (intersections.length !== 0) {
|
|
42
|
+
const hit = intersections[0];
|
|
43
|
+
this.hitDistance = hit.distance;
|
|
44
|
+
hoveredJoint = findNearestJoint(hit.object);
|
|
45
|
+
this.initialGrabPoint.copy(hit.point);
|
|
46
|
+
}
|
|
47
|
+
if (hoveredJoint !== hovered) {
|
|
48
|
+
if (hovered) {
|
|
49
|
+
this.onUnhover(hovered);
|
|
50
|
+
}
|
|
51
|
+
this.hovered = hoveredJoint;
|
|
52
|
+
if (hoveredJoint) {
|
|
53
|
+
this.onHover(hoveredJoint);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
updateJoint(joint, angle) {
|
|
58
|
+
joint.setJointValue(angle);
|
|
59
|
+
}
|
|
60
|
+
onDragStart(joint) { }
|
|
61
|
+
onDragEnd(joint) { }
|
|
62
|
+
onHover(joint) { }
|
|
63
|
+
onUnhover(joint) { }
|
|
64
|
+
getRevoluteDelta(joint, startPoint, endPoint) {
|
|
65
|
+
// set up the plane
|
|
66
|
+
tempVector.copy(joint.axis).transformDirection(joint.matrixWorld).normalize();
|
|
67
|
+
pivotPoint.set(0, 0, 0).applyMatrix4(joint.matrixWorld);
|
|
68
|
+
plane.setFromNormalAndCoplanarPoint(tempVector, pivotPoint);
|
|
69
|
+
// project the drag points onto the plane
|
|
70
|
+
plane.projectPoint(startPoint, projectedStartPoint);
|
|
71
|
+
plane.projectPoint(endPoint, projectedEndPoint);
|
|
72
|
+
// get the directions relative to the pivot
|
|
73
|
+
projectedStartPoint.sub(pivotPoint);
|
|
74
|
+
projectedEndPoint.sub(pivotPoint);
|
|
75
|
+
tempVector.crossVectors(projectedStartPoint, projectedEndPoint);
|
|
76
|
+
const direction = Math.sign(tempVector.dot(plane.normal));
|
|
77
|
+
return direction * projectedEndPoint.angleTo(projectedStartPoint);
|
|
78
|
+
}
|
|
79
|
+
getPrismaticDelta(joint, startPoint, endPoint) {
|
|
80
|
+
tempVector.subVectors(endPoint, startPoint);
|
|
81
|
+
plane.normal.copy(joint.axis).transformDirection(joint.parent.matrixWorld).normalize();
|
|
82
|
+
return tempVector.dot(plane.normal);
|
|
83
|
+
}
|
|
84
|
+
moveRay(toRay) {
|
|
85
|
+
const { raycaster, hitDistance, manipulating } = this;
|
|
86
|
+
const { ray } = raycaster;
|
|
87
|
+
if (manipulating) {
|
|
88
|
+
ray.at(hitDistance, prevHitPoint);
|
|
89
|
+
toRay.at(hitDistance, newHitPoint);
|
|
90
|
+
let delta = 0;
|
|
91
|
+
if (manipulating.jointType === 'revolute' || manipulating.jointType === 'continuous') {
|
|
92
|
+
delta = this.getRevoluteDelta(manipulating, prevHitPoint, newHitPoint);
|
|
93
|
+
}
|
|
94
|
+
else if (manipulating.jointType === 'prismatic') {
|
|
95
|
+
delta = this.getPrismaticDelta(manipulating, prevHitPoint, newHitPoint);
|
|
96
|
+
}
|
|
97
|
+
if (delta) {
|
|
98
|
+
this.updateJoint(manipulating, manipulating.angle + delta);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
this.raycaster.ray.copy(toRay);
|
|
102
|
+
this.update();
|
|
103
|
+
}
|
|
104
|
+
setGrabbed(grabbed) {
|
|
105
|
+
const { hovered, manipulating } = this;
|
|
106
|
+
if (grabbed) {
|
|
107
|
+
if (manipulating !== null || hovered === null) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.manipulating = hovered;
|
|
111
|
+
this.onDragStart(hovered);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
if (this.manipulating === null) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this.onDragEnd(this.manipulating);
|
|
118
|
+
this.manipulating = null;
|
|
119
|
+
this.update();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export class PointerURDFDragControls extends URDFDragControls {
|
|
124
|
+
constructor(scene, camera, domElement) {
|
|
125
|
+
super(scene);
|
|
126
|
+
this.camera = camera;
|
|
127
|
+
this.domElement = domElement;
|
|
128
|
+
const raycaster = new Raycaster();
|
|
129
|
+
const mouse = new Vector2();
|
|
130
|
+
function updateMouse(e) {
|
|
131
|
+
mouse.x = (e.offsetX / domElement.offsetWidth) * 2 - 1;
|
|
132
|
+
mouse.y = -(e.offsetY / domElement.offsetHeight) * 2 + 1;
|
|
133
|
+
}
|
|
134
|
+
this._mouseDown = (e) => {
|
|
135
|
+
updateMouse(e);
|
|
136
|
+
raycaster.setFromCamera(mouse, this.camera);
|
|
137
|
+
this.moveRay(raycaster.ray);
|
|
138
|
+
this.setGrabbed(true);
|
|
139
|
+
};
|
|
140
|
+
this._mouseMove = (e) => {
|
|
141
|
+
updateMouse(e);
|
|
142
|
+
raycaster.setFromCamera(mouse, this.camera);
|
|
143
|
+
this.moveRay(raycaster.ray);
|
|
144
|
+
};
|
|
145
|
+
this._mouseUp = (e) => {
|
|
146
|
+
updateMouse(e);
|
|
147
|
+
raycaster.setFromCamera(mouse, this.camera);
|
|
148
|
+
this.moveRay(raycaster.ray);
|
|
149
|
+
this.setGrabbed(false);
|
|
150
|
+
};
|
|
151
|
+
domElement.addEventListener('pointerdown', this._mouseDown);
|
|
152
|
+
domElement.addEventListener('pointermove', this._mouseMove);
|
|
153
|
+
domElement.addEventListener('pointerup', this._mouseUp);
|
|
154
|
+
}
|
|
155
|
+
getRevoluteDelta(joint, startPoint, endPoint) {
|
|
156
|
+
const { camera, initialGrabPoint } = this;
|
|
157
|
+
// set up the plane
|
|
158
|
+
tempVector.copy(joint.axis).transformDirection(joint.matrixWorld).normalize();
|
|
159
|
+
pivotPoint.set(0, 0, 0).applyMatrix4(joint.matrixWorld);
|
|
160
|
+
plane.setFromNormalAndCoplanarPoint(tempVector, pivotPoint);
|
|
161
|
+
tempVector.copy(camera.position).sub(initialGrabPoint).normalize();
|
|
162
|
+
// if looking into the plane of rotation
|
|
163
|
+
if (Math.abs(tempVector.dot(plane.normal)) > 0.3) {
|
|
164
|
+
return super.getRevoluteDelta(joint, startPoint, endPoint);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// get the up direction
|
|
168
|
+
tempVector.set(0, 1, 0).transformDirection(camera.matrixWorld);
|
|
169
|
+
// get points projected onto the plane of rotation
|
|
170
|
+
plane.projectPoint(startPoint, projectedStartPoint);
|
|
171
|
+
plane.projectPoint(endPoint, projectedEndPoint);
|
|
172
|
+
tempVector.set(0, 0, -1).transformDirection(camera.matrixWorld);
|
|
173
|
+
tempVector.cross(plane.normal);
|
|
174
|
+
tempVector2.subVectors(endPoint, startPoint);
|
|
175
|
+
return tempVector.dot(tempVector2);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
dispose() {
|
|
179
|
+
const { domElement } = this;
|
|
180
|
+
domElement.removeEventListener('pointerdown', this._mouseDown);
|
|
181
|
+
domElement.removeEventListener('pointermove', this._mouseMove);
|
|
182
|
+
domElement.removeEventListener('pointerup', this._mouseUp);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=urdf-drag-controls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urdf-drag-controls.js","sourceRoot":"","sources":["../../src/elements/urdf-drag-controls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAgC,MAAM,OAAO,CAAA;AAGxF,0CAA0C;AAC1C,SAAS,OAAO,CAAC,CAAY;IAC3B,OAAO,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,SAAS,KAAK,OAAO,CAAA;AACjD,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAe;IACvC,IAAI,IAAI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CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;YAC/D,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YAC9B,WAAW,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;YAE5C,OAAO,UAAU,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;SACnC;IACH,CAAC;IAED,OAAO;QACL,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAA;QAC3B,UAAU,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;QAC9D,UAAU,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;QAC9D,UAAU,CAAC,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC5D,CAAC;CACF","sourcesContent":["import { Raycaster, Vector3, Plane, Vector2, Scene, Camera, Object3D, Ray } from 'three'\nimport { URDFJoint } from 'urdf-loader'\n\n// Find the nearest parent that is a joint\nfunction isJoint(j: URDFJoint) {\n return j.isURDFJoint && j.jointType !== 'fixed'\n}\n\nfunction findNearestJoint(child: Object3D) {\n let curr: Object3D | null = child\n while (curr) {\n if (isJoint(curr as URDFJoint)) {\n return curr\n }\n\n curr = curr.parent\n }\n\n return curr\n}\n\nconst prevHitPoint = new Vector3()\nconst newHitPoint = new Vector3()\nconst pivotPoint = new Vector3()\nconst tempVector = new Vector3()\nconst tempVector2 = new Vector3()\nconst projectedStartPoint = new Vector3()\nconst projectedEndPoint = new Vector3()\nconst plane = new Plane()\nexport class URDFDragControls {\n scene: Scene\n\n enabled: boolean\n raycaster: Raycaster\n initialGrabPoint: Vector3\n hitDistance: number\n\n hovered: any\n manipulating: any\n\n constructor(scene: Scene) {\n this.enabled = true\n this.scene = scene\n\n this.raycaster = new Raycaster()\n this.initialGrabPoint = new Vector3()\n\n this.hitDistance = -1\n this.hovered = null\n this.manipulating = null\n }\n\n update() {\n const { raycaster, hovered, manipulating, scene } = this\n\n if (manipulating) {\n return\n }\n\n let hoveredJoint = null\n const intersections = raycaster.intersectObject(scene, true)\n if (intersections.length !== 0) {\n const hit = intersections[0]\n this.hitDistance = hit.distance\n hoveredJoint = findNearestJoint(hit.object)\n this.initialGrabPoint.copy(hit.point)\n }\n\n if (hoveredJoint !== hovered) {\n if (hovered) {\n this.onUnhover(hovered)\n }\n\n this.hovered = hoveredJoint\n\n if (hoveredJoint) {\n this.onHover(hoveredJoint as URDFJoint)\n }\n }\n }\n\n updateJoint(joint: URDFJoint, angle: number) {\n joint.setJointValue(angle)\n }\n\n onDragStart(joint: URDFJoint) {}\n\n onDragEnd(joint: URDFJoint) {}\n\n onHover(joint: URDFJoint) {}\n\n onUnhover(joint: URDFJoint) {}\n\n getRevoluteDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3) {\n // set up the plane\n tempVector.copy(joint.axis).transformDirection(joint.matrixWorld).normalize()\n pivotPoint.set(0, 0, 0).applyMatrix4(joint.matrixWorld)\n plane.setFromNormalAndCoplanarPoint(tempVector, pivotPoint)\n\n // project the drag points onto the plane\n plane.projectPoint(startPoint, projectedStartPoint)\n plane.projectPoint(endPoint, projectedEndPoint)\n\n // get the directions relative to the pivot\n projectedStartPoint.sub(pivotPoint)\n projectedEndPoint.sub(pivotPoint)\n\n tempVector.crossVectors(projectedStartPoint, projectedEndPoint)\n\n const direction = Math.sign(tempVector.dot(plane.normal))\n return direction * projectedEndPoint.angleTo(projectedStartPoint)\n }\n\n getPrismaticDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3) {\n tempVector.subVectors(endPoint, startPoint)\n plane.normal.copy(joint.axis).transformDirection(joint.parent!.matrixWorld).normalize()\n\n return tempVector.dot(plane.normal)\n }\n\n moveRay(toRay: Ray) {\n const { raycaster, hitDistance, manipulating } = this\n const { ray } = raycaster\n\n if (manipulating) {\n ray.at(hitDistance, prevHitPoint)\n toRay.at(hitDistance, newHitPoint)\n\n let delta = 0\n if (manipulating.jointType === 'revolute' || manipulating.jointType === 'continuous') {\n delta = this.getRevoluteDelta(manipulating, prevHitPoint, newHitPoint)\n } else if (manipulating.jointType === 'prismatic') {\n delta = this.getPrismaticDelta(manipulating, prevHitPoint, newHitPoint)\n }\n\n if (delta) {\n this.updateJoint(manipulating, manipulating.angle + delta)\n }\n }\n\n this.raycaster.ray.copy(toRay)\n this.update()\n }\n\n setGrabbed(grabbed: boolean) {\n const { hovered, manipulating } = this\n if (grabbed) {\n if (manipulating !== null || hovered === null) {\n return\n }\n\n this.manipulating = hovered\n this.onDragStart(hovered)\n } else {\n if (this.manipulating === null) {\n return\n }\n\n this.onDragEnd(this.manipulating)\n this.manipulating = null\n this.update()\n }\n }\n}\n\nexport class PointerURDFDragControls extends URDFDragControls {\n camera: Camera\n domElement: HTMLElement\n\n _mouseDown: (e: MouseEvent) => void\n _mouseMove: (e: MouseEvent) => void\n _mouseUp: (e: MouseEvent) => void\n\n constructor(scene: Scene, camera: Camera, domElement: HTMLElement) {\n super(scene)\n\n this.camera = camera\n this.domElement = domElement\n\n const raycaster = new Raycaster()\n const mouse = new Vector2()\n\n function updateMouse(e: MouseEvent) {\n mouse.x = (e.offsetX / domElement.offsetWidth) * 2 - 1\n mouse.y = -(e.offsetY / domElement.offsetHeight) * 2 + 1\n }\n\n this._mouseDown = (e: MouseEvent) => {\n updateMouse(e)\n raycaster.setFromCamera(mouse, this.camera)\n this.moveRay(raycaster.ray)\n this.setGrabbed(true)\n }\n\n this._mouseMove = (e: MouseEvent) => {\n updateMouse(e)\n raycaster.setFromCamera(mouse, this.camera)\n this.moveRay(raycaster.ray)\n }\n\n this._mouseUp = (e: MouseEvent) => {\n updateMouse(e)\n raycaster.setFromCamera(mouse, this.camera)\n this.moveRay(raycaster.ray)\n this.setGrabbed(false)\n }\n\n domElement.addEventListener('pointerdown', this._mouseDown)\n domElement.addEventListener('pointermove', this._mouseMove)\n domElement.addEventListener('pointerup', this._mouseUp)\n }\n\n getRevoluteDelta(joint: URDFJoint, startPoint: Vector3, endPoint: Vector3) {\n const { camera, initialGrabPoint } = this\n\n // set up the plane\n tempVector.copy(joint.axis).transformDirection(joint.matrixWorld).normalize()\n pivotPoint.set(0, 0, 0).applyMatrix4(joint.matrixWorld)\n plane.setFromNormalAndCoplanarPoint(tempVector, pivotPoint)\n\n tempVector.copy(camera.position).sub(initialGrabPoint).normalize()\n\n // if looking into the plane of rotation\n if (Math.abs(tempVector.dot(plane.normal)) > 0.3) {\n return super.getRevoluteDelta(joint, startPoint, endPoint)\n } else {\n // get the up direction\n tempVector.set(0, 1, 0).transformDirection(camera.matrixWorld)\n\n // get points projected onto the plane of rotation\n plane.projectPoint(startPoint, projectedStartPoint)\n plane.projectPoint(endPoint, projectedEndPoint)\n\n tempVector.set(0, 0, -1).transformDirection(camera.matrixWorld)\n tempVector.cross(plane.normal)\n tempVector2.subVectors(endPoint, startPoint)\n\n return tempVector.dot(tempVector2)\n }\n }\n\n dispose() {\n const { domElement } = this\n domElement.removeEventListener('pointerdown', this._mouseDown)\n domElement.removeEventListener('pointermove', this._mouseMove)\n domElement.removeEventListener('pointerup', this._mouseUp)\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PointerURDFDragControls } from './urdf-drag-controls';
|
|
2
|
+
import { MeshPhongMaterial } from 'three';
|
|
3
|
+
import URDFViewerElement from './urdf-viewer-element';
|
|
4
|
+
export default class URDFManipulatorElement extends URDFViewerElement {
|
|
5
|
+
static get observedAttributes(): string[];
|
|
6
|
+
highlightMaterial: MeshPhongMaterial;
|
|
7
|
+
dragControls: PointerURDFDragControls;
|
|
8
|
+
get disableDragging(): boolean;
|
|
9
|
+
set disableDragging(val: boolean);
|
|
10
|
+
get highlightColor(): string;
|
|
11
|
+
set highlightColor(val: string);
|
|
12
|
+
constructor();
|
|
13
|
+
disconnectedCallback(): void;
|
|
14
|
+
attributeChangedCallback(attr: string, oldval: any, newval: any): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { customElement } from 'lit/decorators.js';
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
import { PointerURDFDragControls } from './urdf-drag-controls';
|
|
5
|
+
import URDFViewerElement from './urdf-viewer-element';
|
|
6
|
+
// urdf-manipulator element
|
|
7
|
+
// Displays a URDF model that can be manipulated with the mouse
|
|
8
|
+
// Events
|
|
9
|
+
// joint-mouseover: Fired when a joint is hovered over
|
|
10
|
+
// joint-mouseout: Fired when a joint is no longer hovered over
|
|
11
|
+
// manipulate-start: Fires when a joint is manipulated
|
|
12
|
+
// manipulate-end: Fires when a joint is done being manipulated
|
|
13
|
+
let URDFManipulatorElement = class URDFManipulatorElement extends URDFViewerElement {
|
|
14
|
+
static get observedAttributes() {
|
|
15
|
+
return ['highlight-color', ...super.observedAttributes];
|
|
16
|
+
}
|
|
17
|
+
get disableDragging() {
|
|
18
|
+
return this.hasAttribute('disable-dragging');
|
|
19
|
+
}
|
|
20
|
+
set disableDragging(val) {
|
|
21
|
+
val ? this.setAttribute('disable-dragging', String(!!val)) : this.removeAttribute('disable-dragging');
|
|
22
|
+
}
|
|
23
|
+
get highlightColor() {
|
|
24
|
+
return this.getAttribute('highlight-color') || '#FFFFFF';
|
|
25
|
+
}
|
|
26
|
+
set highlightColor(val) {
|
|
27
|
+
val ? this.setAttribute('highlight-color', val) : this.removeAttribute('highlight-color');
|
|
28
|
+
}
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
// The highlight material
|
|
32
|
+
this.highlightMaterial = new THREE.MeshPhongMaterial({
|
|
33
|
+
shininess: 10,
|
|
34
|
+
color: this.highlightColor,
|
|
35
|
+
emissive: this.highlightColor,
|
|
36
|
+
emissiveIntensity: 0.25
|
|
37
|
+
});
|
|
38
|
+
const isJoint = (j) => {
|
|
39
|
+
return j.isURDFJoint && j.jointType !== 'fixed';
|
|
40
|
+
};
|
|
41
|
+
// Highlight the link geometry under a joint
|
|
42
|
+
const highlightLinkGeometry = (m, revert) => {
|
|
43
|
+
const traverse = (c) => {
|
|
44
|
+
// Set or revert the highlight color
|
|
45
|
+
if (c.type === 'Mesh') {
|
|
46
|
+
if (revert) {
|
|
47
|
+
c.material = c.__origMaterial;
|
|
48
|
+
delete c.__origMaterial;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
c.__origMaterial = c.material;
|
|
52
|
+
c.material = this.highlightMaterial;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Look into the children and stop if the next child is
|
|
56
|
+
// another joint
|
|
57
|
+
if (c === m || !isJoint(c)) {
|
|
58
|
+
for (let i = 0; i < c.children.length; i++) {
|
|
59
|
+
traverse(c.children[i]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
traverse(m);
|
|
64
|
+
};
|
|
65
|
+
const el = this.renderer.domElement;
|
|
66
|
+
const dragControls = new PointerURDFDragControls(this.scene, this.camera, el);
|
|
67
|
+
dragControls.onDragStart = joint => {
|
|
68
|
+
this.dispatchEvent(new CustomEvent('manipulate-start', { bubbles: true, cancelable: true, detail: joint.name }));
|
|
69
|
+
this.controls.enabled = false;
|
|
70
|
+
this.redraw();
|
|
71
|
+
};
|
|
72
|
+
dragControls.onDragEnd = joint => {
|
|
73
|
+
this.dispatchEvent(new CustomEvent('manipulate-end', { bubbles: true, cancelable: true, detail: joint.name }));
|
|
74
|
+
this.controls.enabled = true;
|
|
75
|
+
this.redraw();
|
|
76
|
+
};
|
|
77
|
+
dragControls.updateJoint = (joint, angle) => {
|
|
78
|
+
this.setJointValue(joint.name, angle);
|
|
79
|
+
};
|
|
80
|
+
dragControls.onHover = (joint) => {
|
|
81
|
+
highlightLinkGeometry(joint, false);
|
|
82
|
+
this.dispatchEvent(new CustomEvent('joint-mouseover', { bubbles: true, cancelable: true, detail: joint.name }));
|
|
83
|
+
this.redraw();
|
|
84
|
+
};
|
|
85
|
+
dragControls.onUnhover = joint => {
|
|
86
|
+
highlightLinkGeometry(joint, true);
|
|
87
|
+
this.dispatchEvent(new CustomEvent('joint-mouseout', { bubbles: true, cancelable: true, detail: joint.name }));
|
|
88
|
+
this.redraw();
|
|
89
|
+
};
|
|
90
|
+
this.dragControls = dragControls;
|
|
91
|
+
}
|
|
92
|
+
disconnectedCallback() {
|
|
93
|
+
super.disconnectedCallback();
|
|
94
|
+
this.dragControls.dispose();
|
|
95
|
+
}
|
|
96
|
+
attributeChangedCallback(attr, oldval, newval) {
|
|
97
|
+
super.attributeChangedCallback(attr, oldval, newval);
|
|
98
|
+
switch (attr) {
|
|
99
|
+
case 'highlight-color':
|
|
100
|
+
this.highlightMaterial.color.set(this.highlightColor);
|
|
101
|
+
this.highlightMaterial.emissive.set(this.highlightColor);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
URDFManipulatorElement = __decorate([
|
|
107
|
+
customElement('urdf-viewer')
|
|
108
|
+
], URDFManipulatorElement);
|
|
109
|
+
export default URDFManipulatorElement;
|
|
110
|
+
//# sourceMappingURL=urdf-manipulator-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urdf-manipulator-element.js","sourceRoot":"","sources":["../../src/elements/urdf-manipulator-element.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAE9D,OAAO,iBAAiB,MAAM,uBAAuB,CAAA;AAGrD,2BAA2B;AAC3B,+DAA+D;AAE/D,SAAS;AACT,sDAAsD;AACtD,+DAA+D;AAC/D,sDAAsD;AACtD,+DAA+D;AAGhD,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,iBAAiB;IACnE,MAAM,KAAK,kBA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AAC;IAED,wBAAwB,CAAC,IAAY,EAAE,MAAW,EAAE,MAAW;QAC7D,KAAK,CAAC,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;QAEpD,QAAQ,IAAI,EAAE;YACZ,KAAK,iBAAiB;gBACpB,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;gBACrD,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;gBACxD,MAAK;SACR;IACH,CAAC;CACF,CAAA;AAnHoB,sBAAsB;IAD1C,aAAa,CAAC,aAAa,CAAC;GACR,sBAAsB,CAmH1C;eAnHoB,sBAAsB","sourcesContent":["import { customElement } from 'lit/decorators.js'\nimport * as THREE from 'three'\nimport { PointerURDFDragControls } from './urdf-drag-controls'\nimport { Material, MeshPhongMaterial } from 'three'\nimport URDFViewerElement from './urdf-viewer-element'\nimport { URDFJoint } from 'urdf-loader'\n\n// urdf-manipulator element\n// Displays a URDF model that can be manipulated with the mouse\n\n// Events\n// joint-mouseover: Fired when a joint is hovered over\n// joint-mouseout: Fired when a joint is no longer hovered over\n// manipulate-start: Fires when a joint is manipulated\n// manipulate-end: Fires when a joint is done being manipulated\n\n@customElement('urdf-viewer')\nexport default class URDFManipulatorElement extends URDFViewerElement {\n static get observedAttributes() {\n return ['highlight-color', ...super.observedAttributes]\n }\n\n highlightMaterial: MeshPhongMaterial\n dragControls: PointerURDFDragControls\n\n get disableDragging() {\n return this.hasAttribute('disable-dragging')\n }\n\n set disableDragging(val) {\n val ? this.setAttribute('disable-dragging', String(!!val)) : this.removeAttribute('disable-dragging')\n }\n\n get highlightColor() {\n return this.getAttribute('highlight-color') || '#FFFFFF'\n }\n\n set highlightColor(val) {\n val ? this.setAttribute('highlight-color', val) : this.removeAttribute('highlight-color')\n }\n\n constructor() {\n super()\n\n // The highlight material\n this.highlightMaterial = new THREE.MeshPhongMaterial({\n shininess: 10,\n color: this.highlightColor,\n emissive: this.highlightColor,\n emissiveIntensity: 0.25\n })\n\n const isJoint = (j: URDFJoint) => {\n return j.isURDFJoint && j.jointType !== 'fixed'\n }\n\n // Highlight the link geometry under a joint\n const highlightLinkGeometry = (m: THREE.Material, revert: boolean) => {\n const traverse = (c: any) => {\n // Set or revert the highlight color\n if (c.type === 'Mesh') {\n if (revert) {\n c.material = c.__origMaterial\n delete c.__origMaterial\n } else {\n c.__origMaterial = c.material\n c.material = this.highlightMaterial\n }\n }\n\n // Look into the children and stop if the next child is\n // another joint\n if (c === m || !isJoint(c)) {\n for (let i = 0; i < c.children.length; i++) {\n traverse(c.children[i])\n }\n }\n }\n\n traverse(m)\n }\n\n const el = this.renderer.domElement\n\n const dragControls = new PointerURDFDragControls(this.scene, this.camera, el)\n\n dragControls.onDragStart = joint => {\n this.dispatchEvent(new CustomEvent('manipulate-start', { bubbles: true, cancelable: true, detail: joint.name }))\n this.controls.enabled = false\n this.redraw()\n }\n\n dragControls.onDragEnd = joint => {\n this.dispatchEvent(new CustomEvent('manipulate-end', { bubbles: true, cancelable: true, detail: joint.name }))\n this.controls.enabled = true\n this.redraw()\n }\n\n dragControls.updateJoint = (joint, angle) => {\n this.setJointValue(joint.name, angle)\n }\n\n dragControls.onHover = (joint: URDFJoint) => {\n highlightLinkGeometry(joint as any, false)\n this.dispatchEvent(new CustomEvent('joint-mouseover', { bubbles: true, cancelable: true, detail: joint.name }))\n this.redraw()\n }\n\n dragControls.onUnhover = joint => {\n highlightLinkGeometry(joint as any, true)\n this.dispatchEvent(new CustomEvent('joint-mouseout', { bubbles: true, cancelable: true, detail: joint.name }))\n this.redraw()\n }\n\n this.dragControls = dragControls\n }\n\n disconnectedCallback() {\n super.disconnectedCallback()\n this.dragControls.dispose()\n }\n\n attributeChangedCallback(attr: string, oldval: any, newval: any) {\n super.attributeChangedCallback(attr, oldval, newval)\n\n switch (attr) {\n case 'highlight-color':\n this.highlightMaterial.color.set(this.highlightColor)\n this.highlightMaterial.emissive.set(this.highlightColor)\n break\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
|
|
3
|
+
import { URDFRobot } from 'urdf-loader/src/URDFLoader';
|
|
4
|
+
export default class URDFViewerElement extends HTMLElement {
|
|
5
|
+
static get observedAttributes(): string[];
|
|
6
|
+
get package(): string;
|
|
7
|
+
set package(val: string);
|
|
8
|
+
get urdf(): string;
|
|
9
|
+
set urdf(val: string);
|
|
10
|
+
get ignoreLimits(): boolean;
|
|
11
|
+
set ignoreLimits(val: boolean);
|
|
12
|
+
get up(): string;
|
|
13
|
+
set up(val: string);
|
|
14
|
+
get displayShadow(): boolean;
|
|
15
|
+
set displayShadow(val: boolean);
|
|
16
|
+
get ambientColor(): string;
|
|
17
|
+
set ambientColor(val: string);
|
|
18
|
+
get noAutoRecenter(): boolean;
|
|
19
|
+
set noAutoRecenter(val: boolean);
|
|
20
|
+
get jointValues(): any;
|
|
21
|
+
set jointValues(val: any);
|
|
22
|
+
get angles(): any;
|
|
23
|
+
set angles(v: any);
|
|
24
|
+
robot?: URDFRobot;
|
|
25
|
+
controls: OrbitControls;
|
|
26
|
+
scene: THREE.Scene;
|
|
27
|
+
camera: THREE.PerspectiveCamera;
|
|
28
|
+
world: THREE.Object3D;
|
|
29
|
+
renderer: THREE.WebGLRenderer;
|
|
30
|
+
plane: THREE.Mesh;
|
|
31
|
+
directionalLight: THREE.DirectionalLight;
|
|
32
|
+
ambientLight: THREE.HemisphereLight;
|
|
33
|
+
_prevload?: string;
|
|
34
|
+
_requestId: number;
|
|
35
|
+
_dirty: boolean;
|
|
36
|
+
_loadScheduled: boolean;
|
|
37
|
+
loadMeshFunc?: (url: string, manager: THREE.LoadingManager, onLoad: (mesh: THREE.Object3D, err?: Error) => void) => void;
|
|
38
|
+
urlModifierFunc?: (url: string) => string;
|
|
39
|
+
constructor();
|
|
40
|
+
connectedCallback(): void;
|
|
41
|
+
disconnectedCallback(): void;
|
|
42
|
+
attributeChangedCallback(attr: string, oldval: any, newval: any): void;
|
|
43
|
+
updateSize(): void;
|
|
44
|
+
redraw(): void;
|
|
45
|
+
recenter(): void;
|
|
46
|
+
setJointValue(jointName: string, ...values: Number[]): void;
|
|
47
|
+
setJointValues(values: Number[]): void;
|
|
48
|
+
_updateEnvironment(): void;
|
|
49
|
+
_scheduleLoad(): void;
|
|
50
|
+
_loadUrdf(pkg: string, urdf: string): void;
|
|
51
|
+
_setUp(up: string): void;
|
|
52
|
+
_setIgnoreLimits(ignore: boolean, dispatch?: boolean): void;
|
|
53
|
+
}
|