@operato/scene-urdf 10.0.0-beta.1 → 10.0.0-beta.18
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/dist/editors/index.d.ts +6 -0
- package/dist/editors/index.js +7 -1
- package/dist/editors/index.js.map +1 -1
- package/dist/editors/property-editor-urdf-joints.d.ts +54 -0
- package/dist/editors/property-editor-urdf-joints.js +242 -0
- package/dist/editors/property-editor-urdf-joints.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/real-object-urdf.d.ts +75 -0
- package/dist/real-object-urdf.js +284 -0
- package/dist/real-object-urdf.js.map +1 -0
- package/dist/templates/index.d.ts +3 -0
- package/dist/templates/index.js +2 -3
- package/dist/templates/index.js.map +1 -1
- package/dist/templates/{urdf-controller.d.ts → urdf.d.ts} +3 -0
- package/dist/templates/urdf.js +19 -0
- package/dist/templates/urdf.js.map +1 -0
- package/dist/urdf-object.d.ts +264 -0
- package/dist/urdf-object.js +163 -0
- package/dist/urdf-object.js.map +1 -0
- package/icons/urdf.png +0 -0
- package/package.json +5 -4
- package/dist/elements/drag-n-drop.d.ts +0 -2
- package/dist/elements/drag-n-drop.js +0 -126
- package/dist/elements/drag-n-drop.js.map +0 -1
- package/dist/elements/urdf-controller-element.d.ts +0 -12
- package/dist/elements/urdf-controller-element.js +0 -283
- package/dist/elements/urdf-controller-element.js.map +0 -1
- package/dist/elements/urdf-drag-controls.d.ts +0 -32
- package/dist/elements/urdf-drag-controls.js +0 -197
- package/dist/elements/urdf-drag-controls.js.map +0 -1
- package/dist/elements/urdf-manipulator-element.d.ts +0 -15
- package/dist/elements/urdf-manipulator-element.js +0 -112
- package/dist/elements/urdf-manipulator-element.js.map +0 -1
- package/dist/elements/urdf-viewer-element.d.ts +0 -53
- package/dist/elements/urdf-viewer-element.js +0 -414
- package/dist/elements/urdf-viewer-element.js.map +0 -1
- package/dist/templates/urdf-controller.js +0 -16
- package/dist/templates/urdf-controller.js.map +0 -1
- package/dist/templates/urdf-viewer.d.ts +0 -14
- package/dist/templates/urdf-viewer.js +0 -16
- package/dist/templates/urdf-viewer.js.map +0 -1
- package/dist/urdf-controller.d.ts +0 -15
- package/dist/urdf-controller.js +0 -70
- package/dist/urdf-controller.js.map +0 -1
- package/dist/urdf-viewer.d.ts +0 -16
- package/dist/urdf-viewer.js +0 -202
- package/dist/urdf-viewer.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"urdf-controller-element.js","sourceRoot":"","sources":["../../src/elements/urdf-controller-element.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAIjD,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAA;AAC7B,MAAM,OAAO,GAAG,CAAC,GAAG,OAAO,CAAA;AAGZ,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,UAAU;IAC3D,MAAM,CAAC,MAAM,GAAG;QACd,eAAe;QACf,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA6IF;KACF,CAAA;IAE2B,MAAM,CAAyB;IAC/B,KAAK,CAAY;IAE7C,MAAM;QACJ,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE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,CAAC,gBAAgB,EAAE,CAAC,CAAQ,EAAE,EAAE;YACrD,MAAM,CAAC,cAAc,GAAG,sBAAsB,CAAA;QAChD,CAAC,CAAC,CAAA;QAEF,kBAAkB,CAAC,MAAM,EAAE,GAAG,EAAE;YAC9B,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QAC1B,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC,MAAO,CAAC,cAAc,GAAG,GAAG,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,YAAY,EAAE,CAAA;IACjH,CAAC;;AAxI2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qDAAgC;AAC/B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oDAAkB;AApJ1B,qBAAqB;IADzC,aAAa,CAAC,iBAAiB,CAAC;GACZ,qBAAqB,CA4RzC;eA5RoB,qBAAqB","sourcesContent":["import { LitElement, css, html, PropertyValues } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport * as THREE from 'three'\nimport { registerDragEvents } from './drag-n-drop.js'\nimport { ScrollbarStyles } from '@operato/styles'\nimport { URDFRobot } from 'urdf-loader'\nimport URDFManipulatorElement from './urdf-manipulator-element.js'\n\nconst DEG2RAD = Math.PI / 180\nconst RAD2DEG = 1 / DEG2RAD\n\n@customElement('urdf-controller')\nexport default class URDFControllerElement extends LitElement {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n width: 100%;\n margin: 15px 0;\n overflow: hidden;\n user-select: none;\n }\n\n :host > * {\n margin: 5px 0;\n }\n\n input[type='number'] {\n color: white;\n border: none;\n font-weight: 300;\n background: rgba(255, 255, 255, 0.25);\n padding: 1px 2px;\n }\n\n ul {\n list-style: none;\n padding: 0;\n margin: 0;\n }\n\n input[type='range'] {\n -webkit-appearance: none;\n border: none;\n outline: none;\n width: 100%;\n flex: 1;\n height: 16px;\n background-color: transparent;\n }\n input[type='range']::-webkit-slider-runnable-track {\n width: 100%;\n height: 1px;\n background: white;\n border: none;\n border-radius: 5px;\n }\n input[type='range']::-webkit-slider-thumb {\n -webkit-appearance: none;\n border: none;\n height: 10px;\n width: 10px;\n border-radius: 50%;\n background: white;\n margin-top: -5px;\n }\n input[type='range']:focus {\n outline: none;\n }\n input[type='range']:focus::-webkit-slider-runnable-track {\n background: white;\n }\n\n input[type='range']::-moz-range-track {\n width: 100%;\n height: 1px;\n background: white;\n border: none;\n border-radius: 5px;\n }\n input[type='range']::-moz-range-thumb {\n border: none;\n height: 10px;\n width: 10px;\n border-radius: 50%;\n background: white;\n }\n\n input[type='range']:-moz-focusring {\n outline: 1px solid white;\n outline-offset: -1px;\n }\n\n input[type='range']::-ms-track {\n width: 100%;\n height: 1px;\n background: white;\n border-radius: 10px;\n color: transparent;\n border: none;\n outline: none;\n }\n input[type='range']::-ms-thumb {\n height: 10px;\n width: 10px;\n border-radius: 50%;\n background: white;\n border: none;\n outline: none;\n margin-top: 2px;\n }\n\n input:focus {\n outline: none;\n opacity: 1;\n }\n\n /* list of joint sliders */\n ul {\n flex: 1;\n overflow-y: auto;\n }\n\n li {\n font-size: 16px;\n display: flex;\n align-items: center;\n padding: 1px 0;\n\n width: 100%;\n user-select: text;\n\n transition: background 0.25s ease;\n }\n\n li[robot-hovered] {\n background: rgba(255, 255, 255, 0.35);\n }\n\n li:hover {\n background: rgba(255, 255, 255, 0.35);\n }\n\n li span {\n padding: 0 5px;\n max-width: 125px;\n text-overflow: ellipsis;\n overflow: hidden;\n }\n\n li input[type='number'] {\n width: 50px;\n overflow: hidden;\n }\n `\n ]\n\n @property({ type: Object }) viewer?: URDFManipulatorElement\n @property({ type: Object }) robot?: URDFRobot\n\n render() {\n const { joints = {} } = this.robot || {}\n const { ignoreLimits = false } = this.viewer || {}\n const jointsArray = Object.values(joints)\n\n return html`\n <ul>\n ${jointsArray.map(joint => {\n var { jointType, name, angle, limit } = joint\n var degVal: number | string = Number(angle || 0)\n\n if (jointType === 'revolute' || jointType === 'continuous') {\n degVal *= RAD2DEG\n }\n\n if (Math.abs(degVal) > 1) {\n degVal = degVal.toFixed(1)\n } else {\n degVal = degVal.toPrecision(2)\n }\n\n var sliderMin\n var sliderMax\n var inputMin\n var inputMax\n\n if (ignoreLimits || jointType === 'continuous') {\n sliderMin = -6.28\n sliderMax = 6.28\n\n inputMin = -6.28 * RAD2DEG\n inputMax = 6.28 * RAD2DEG\n } else {\n sliderMin = limit.lower\n sliderMax = limit.upper\n\n inputMin = Number(limit.lower) * RAD2DEG\n inputMax = Number(limit.upper) * RAD2DEG\n }\n\n return html`\n <li joint-type=${jointType} joint-name=${name}>\n <span title=${name}>${name}</span>\n <input\n type=\"range\"\n .value=${String(angle)}\n step=\"0.0001\"\n min=${sliderMin}\n max=${sliderMax}\n @input=${(e: Event) => {\n this.viewer?.setJointValue(name, (e.target as any).value)\n }}\n />\n <input\n type=\"number\"\n .value=${degVal}\n step=\"0.0001\"\n min=${inputMin}\n max=${inputMax}\n @change=${(e: Event) => {\n this.viewer?.setJointValue(name, Number((e.target as HTMLInputElement).value) * DEG2RAD)\n }}\n />\n </li>\n `\n })}\n </ul>\n `\n }\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('viewer')) {\n this._setupViewer(this.viewer)\n }\n }\n\n _setupViewer(viewer?: URDFManipulatorElement) {\n if (!viewer) {\n return\n }\n\n this.robot = viewer.robot\n\n viewer.addEventListener('urdf-processed', () => {\n this.robot = viewer.robot\n })\n\n viewer.addEventListener('ignore-limits-change', () => {\n this.requestUpdate()\n })\n\n viewer.addEventListener('angle-change', (e: Event) => {\n this.requestUpdate()\n })\n\n viewer.addEventListener('joint-mouseover', (e: Event) => {\n const j = this.renderRoot.querySelector(`li[joint-name=\"${(e as CustomEvent).detail}\"]`)\n if (j) {\n j.setAttribute('robot-hovered', 'true')\n }\n })\n\n viewer.addEventListener('joint-mouseout', (e: Event) => {\n const j = this.renderRoot.querySelector(`li[joint-name=\"${(e as CustomEvent).detail}\"]`)\n if (j) {\n j.removeAttribute('robot-hovered')\n }\n })\n\n let originalNoAutoRecenter: boolean\n viewer.addEventListener('manipulate-start', (e: Event) => {\n const j = this.renderRoot.querySelector(`li[joint-name=\"${(e as CustomEvent).detail}\"]`)\n if (j) {\n // ??\n j.scrollIntoView({ block: 'nearest' })\n window.scrollTo(0, 0)\n }\n\n originalNoAutoRecenter = viewer.noAutoRecenter\n viewer.noAutoRecenter = true\n })\n\n viewer.addEventListener('manipulate-end', (e: Event) => {\n viewer.noAutoRecenter = originalNoAutoRecenter\n })\n\n registerDragEvents(viewer, () => {\n this.setColor('#263238')\n })\n }\n\n setColor(color: string) {\n this.viewer!.highlightColor = '#' + new THREE.Color(0xffffff).lerp(new THREE.Color(color), 0.35).getHexString()\n }\n}\n"]}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
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
|
-
scene;
|
|
26
|
-
enabled;
|
|
27
|
-
raycaster;
|
|
28
|
-
initialGrabPoint;
|
|
29
|
-
hitDistance;
|
|
30
|
-
hovered;
|
|
31
|
-
manipulating;
|
|
32
|
-
constructor(scene) {
|
|
33
|
-
this.enabled = true;
|
|
34
|
-
this.scene = scene;
|
|
35
|
-
this.raycaster = new Raycaster();
|
|
36
|
-
this.initialGrabPoint = new Vector3();
|
|
37
|
-
this.hitDistance = -1;
|
|
38
|
-
this.hovered = null;
|
|
39
|
-
this.manipulating = null;
|
|
40
|
-
}
|
|
41
|
-
update() {
|
|
42
|
-
const { raycaster, hovered, manipulating, scene } = this;
|
|
43
|
-
if (manipulating) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
let hoveredJoint = null;
|
|
47
|
-
const intersections = raycaster.intersectObject(scene, true);
|
|
48
|
-
if (intersections.length !== 0) {
|
|
49
|
-
const hit = intersections[0];
|
|
50
|
-
this.hitDistance = hit.distance;
|
|
51
|
-
hoveredJoint = findNearestJoint(hit.object);
|
|
52
|
-
this.initialGrabPoint.copy(hit.point);
|
|
53
|
-
}
|
|
54
|
-
if (hoveredJoint !== hovered) {
|
|
55
|
-
if (hovered) {
|
|
56
|
-
this.onUnhover(hovered);
|
|
57
|
-
}
|
|
58
|
-
this.hovered = hoveredJoint;
|
|
59
|
-
if (hoveredJoint) {
|
|
60
|
-
this.onHover(hoveredJoint);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
updateJoint(joint, angle) {
|
|
65
|
-
joint.setJointValue(angle);
|
|
66
|
-
}
|
|
67
|
-
onDragStart(joint) { }
|
|
68
|
-
onDragEnd(joint) { }
|
|
69
|
-
onHover(joint) { }
|
|
70
|
-
onUnhover(joint) { }
|
|
71
|
-
getRevoluteDelta(joint, startPoint, endPoint) {
|
|
72
|
-
// set up the plane
|
|
73
|
-
tempVector.copy(joint.axis).transformDirection(joint.matrixWorld).normalize();
|
|
74
|
-
pivotPoint.set(0, 0, 0).applyMatrix4(joint.matrixWorld);
|
|
75
|
-
plane.setFromNormalAndCoplanarPoint(tempVector, pivotPoint);
|
|
76
|
-
// project the drag points onto the plane
|
|
77
|
-
plane.projectPoint(startPoint, projectedStartPoint);
|
|
78
|
-
plane.projectPoint(endPoint, projectedEndPoint);
|
|
79
|
-
// get the directions relative to the pivot
|
|
80
|
-
projectedStartPoint.sub(pivotPoint);
|
|
81
|
-
projectedEndPoint.sub(pivotPoint);
|
|
82
|
-
tempVector.crossVectors(projectedStartPoint, projectedEndPoint);
|
|
83
|
-
const direction = Math.sign(tempVector.dot(plane.normal));
|
|
84
|
-
return direction * projectedEndPoint.angleTo(projectedStartPoint);
|
|
85
|
-
}
|
|
86
|
-
getPrismaticDelta(joint, startPoint, endPoint) {
|
|
87
|
-
tempVector.subVectors(endPoint, startPoint);
|
|
88
|
-
plane.normal.copy(joint.axis).transformDirection(joint.parent.matrixWorld).normalize();
|
|
89
|
-
return tempVector.dot(plane.normal);
|
|
90
|
-
}
|
|
91
|
-
moveRay(toRay) {
|
|
92
|
-
const { raycaster, hitDistance, manipulating } = this;
|
|
93
|
-
const { ray } = raycaster;
|
|
94
|
-
if (manipulating) {
|
|
95
|
-
ray.at(hitDistance, prevHitPoint);
|
|
96
|
-
toRay.at(hitDistance, newHitPoint);
|
|
97
|
-
let delta = 0;
|
|
98
|
-
if (manipulating.jointType === 'revolute' || manipulating.jointType === 'continuous') {
|
|
99
|
-
delta = this.getRevoluteDelta(manipulating, prevHitPoint, newHitPoint);
|
|
100
|
-
}
|
|
101
|
-
else if (manipulating.jointType === 'prismatic') {
|
|
102
|
-
delta = this.getPrismaticDelta(manipulating, prevHitPoint, newHitPoint);
|
|
103
|
-
}
|
|
104
|
-
if (delta) {
|
|
105
|
-
this.updateJoint(manipulating, manipulating.angle + delta);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
this.raycaster.ray.copy(toRay);
|
|
109
|
-
this.update();
|
|
110
|
-
}
|
|
111
|
-
setGrabbed(grabbed) {
|
|
112
|
-
const { hovered, manipulating } = this;
|
|
113
|
-
if (grabbed) {
|
|
114
|
-
if (manipulating !== null || hovered === null) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
this.manipulating = hovered;
|
|
118
|
-
this.onDragStart(hovered);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
if (this.manipulating === null) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
this.onDragEnd(this.manipulating);
|
|
125
|
-
this.manipulating = null;
|
|
126
|
-
this.update();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
export class PointerURDFDragControls extends URDFDragControls {
|
|
131
|
-
camera;
|
|
132
|
-
domElement;
|
|
133
|
-
_mouseDown;
|
|
134
|
-
_mouseMove;
|
|
135
|
-
_mouseUp;
|
|
136
|
-
constructor(scene, camera, domElement) {
|
|
137
|
-
super(scene);
|
|
138
|
-
this.camera = camera;
|
|
139
|
-
this.domElement = domElement;
|
|
140
|
-
const raycaster = new Raycaster();
|
|
141
|
-
const mouse = new Vector2();
|
|
142
|
-
function updateMouse(e) {
|
|
143
|
-
mouse.x = (e.offsetX / domElement.offsetWidth) * 2 - 1;
|
|
144
|
-
mouse.y = -(e.offsetY / domElement.offsetHeight) * 2 + 1;
|
|
145
|
-
}
|
|
146
|
-
this._mouseDown = (e) => {
|
|
147
|
-
updateMouse(e);
|
|
148
|
-
raycaster.setFromCamera(mouse, this.camera);
|
|
149
|
-
this.moveRay(raycaster.ray);
|
|
150
|
-
this.setGrabbed(true);
|
|
151
|
-
};
|
|
152
|
-
this._mouseMove = (e) => {
|
|
153
|
-
updateMouse(e);
|
|
154
|
-
raycaster.setFromCamera(mouse, this.camera);
|
|
155
|
-
this.moveRay(raycaster.ray);
|
|
156
|
-
};
|
|
157
|
-
this._mouseUp = (e) => {
|
|
158
|
-
updateMouse(e);
|
|
159
|
-
raycaster.setFromCamera(mouse, this.camera);
|
|
160
|
-
this.moveRay(raycaster.ray);
|
|
161
|
-
this.setGrabbed(false);
|
|
162
|
-
};
|
|
163
|
-
domElement.addEventListener('pointerdown', this._mouseDown);
|
|
164
|
-
domElement.addEventListener('pointermove', this._mouseMove);
|
|
165
|
-
domElement.addEventListener('pointerup', this._mouseUp);
|
|
166
|
-
}
|
|
167
|
-
getRevoluteDelta(joint, startPoint, endPoint) {
|
|
168
|
-
const { camera, initialGrabPoint } = this;
|
|
169
|
-
// set up the plane
|
|
170
|
-
tempVector.copy(joint.axis).transformDirection(joint.matrixWorld).normalize();
|
|
171
|
-
pivotPoint.set(0, 0, 0).applyMatrix4(joint.matrixWorld);
|
|
172
|
-
plane.setFromNormalAndCoplanarPoint(tempVector, pivotPoint);
|
|
173
|
-
tempVector.copy(camera.position).sub(initialGrabPoint).normalize();
|
|
174
|
-
// if looking into the plane of rotation
|
|
175
|
-
if (Math.abs(tempVector.dot(plane.normal)) > 0.3) {
|
|
176
|
-
return super.getRevoluteDelta(joint, startPoint, endPoint);
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
// get the up direction
|
|
180
|
-
tempVector.set(0, 1, 0).transformDirection(camera.matrixWorld);
|
|
181
|
-
// get points projected onto the plane of rotation
|
|
182
|
-
plane.projectPoint(startPoint, projectedStartPoint);
|
|
183
|
-
plane.projectPoint(endPoint, projectedEndPoint);
|
|
184
|
-
tempVector.set(0, 0, -1).transformDirection(camera.matrixWorld);
|
|
185
|
-
tempVector.cross(plane.normal);
|
|
186
|
-
tempVector2.subVectors(endPoint, startPoint);
|
|
187
|
-
return tempVector.dot(tempVector2);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
dispose() {
|
|
191
|
-
const { domElement } = this;
|
|
192
|
-
domElement.removeEventListener('pointerdown', this._mouseDown);
|
|
193
|
-
domElement.removeEventListener('pointermove', this._mouseMove);
|
|
194
|
-
domElement.removeEventListener('pointerup', this._mouseUp);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
//# sourceMappingURL=urdf-drag-controls.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"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AAU,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"]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { PointerURDFDragControls } from './urdf-drag-controls.js';
|
|
2
|
-
import { MeshPhongMaterial } from 'three';
|
|
3
|
-
import URDFViewerElement from './urdf-viewer-element.js';
|
|
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
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
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.js';
|
|
5
|
-
import URDFViewerElement from './urdf-viewer-element.js';
|
|
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
|
-
highlightMaterial;
|
|
18
|
-
dragControls;
|
|
19
|
-
get disableDragging() {
|
|
20
|
-
return this.hasAttribute('disable-dragging');
|
|
21
|
-
}
|
|
22
|
-
set disableDragging(val) {
|
|
23
|
-
val ? this.setAttribute('disable-dragging', String(!!val)) : this.removeAttribute('disable-dragging');
|
|
24
|
-
}
|
|
25
|
-
get highlightColor() {
|
|
26
|
-
return this.getAttribute('highlight-color') || '#FFFFFF';
|
|
27
|
-
}
|
|
28
|
-
set highlightColor(val) {
|
|
29
|
-
val ? this.setAttribute('highlight-color', val) : this.removeAttribute('highlight-color');
|
|
30
|
-
}
|
|
31
|
-
constructor() {
|
|
32
|
-
super();
|
|
33
|
-
// The highlight material
|
|
34
|
-
this.highlightMaterial = new THREE.MeshPhongMaterial({
|
|
35
|
-
shininess: 10,
|
|
36
|
-
color: this.highlightColor,
|
|
37
|
-
emissive: this.highlightColor,
|
|
38
|
-
emissiveIntensity: 0.25
|
|
39
|
-
});
|
|
40
|
-
const isJoint = (j) => {
|
|
41
|
-
return j.isURDFJoint && j.jointType !== 'fixed';
|
|
42
|
-
};
|
|
43
|
-
// Highlight the link geometry under a joint
|
|
44
|
-
const highlightLinkGeometry = (m, revert) => {
|
|
45
|
-
const traverse = (c) => {
|
|
46
|
-
// Set or revert the highlight color
|
|
47
|
-
if (c.type === 'Mesh') {
|
|
48
|
-
if (revert) {
|
|
49
|
-
c.material = c.__origMaterial;
|
|
50
|
-
delete c.__origMaterial;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
c.__origMaterial = c.material;
|
|
54
|
-
c.material = this.highlightMaterial;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
// Look into the children and stop if the next child is
|
|
58
|
-
// another joint
|
|
59
|
-
if (c === m || !isJoint(c)) {
|
|
60
|
-
for (let i = 0; i < c.children.length; i++) {
|
|
61
|
-
traverse(c.children[i]);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
traverse(m);
|
|
66
|
-
};
|
|
67
|
-
const el = this.renderer.domElement;
|
|
68
|
-
const dragControls = new PointerURDFDragControls(this.scene, this.camera, el);
|
|
69
|
-
dragControls.onDragStart = joint => {
|
|
70
|
-
this.dispatchEvent(new CustomEvent('manipulate-start', { bubbles: true, cancelable: true, detail: joint.name }));
|
|
71
|
-
this.controls.enabled = false;
|
|
72
|
-
this.redraw();
|
|
73
|
-
};
|
|
74
|
-
dragControls.onDragEnd = joint => {
|
|
75
|
-
this.dispatchEvent(new CustomEvent('manipulate-end', { bubbles: true, cancelable: true, detail: joint.name }));
|
|
76
|
-
this.controls.enabled = true;
|
|
77
|
-
this.redraw();
|
|
78
|
-
};
|
|
79
|
-
dragControls.updateJoint = (joint, angle) => {
|
|
80
|
-
this.setJointValue(joint.name, angle);
|
|
81
|
-
};
|
|
82
|
-
dragControls.onHover = (joint) => {
|
|
83
|
-
highlightLinkGeometry(joint, false);
|
|
84
|
-
this.dispatchEvent(new CustomEvent('joint-mouseover', { bubbles: true, cancelable: true, detail: joint.name }));
|
|
85
|
-
this.redraw();
|
|
86
|
-
};
|
|
87
|
-
dragControls.onUnhover = joint => {
|
|
88
|
-
highlightLinkGeometry(joint, true);
|
|
89
|
-
this.dispatchEvent(new CustomEvent('joint-mouseout', { bubbles: true, cancelable: true, detail: joint.name }));
|
|
90
|
-
this.redraw();
|
|
91
|
-
};
|
|
92
|
-
this.dragControls = dragControls;
|
|
93
|
-
}
|
|
94
|
-
disconnectedCallback() {
|
|
95
|
-
super.disconnectedCallback();
|
|
96
|
-
this.dragControls.dispose();
|
|
97
|
-
}
|
|
98
|
-
attributeChangedCallback(attr, oldval, newval) {
|
|
99
|
-
super.attributeChangedCallback(attr, oldval, newval);
|
|
100
|
-
switch (attr) {
|
|
101
|
-
case 'highlight-color':
|
|
102
|
-
this.highlightMaterial.color.set(this.highlightColor);
|
|
103
|
-
this.highlightMaterial.emissive.set(this.highlightColor);
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
URDFManipulatorElement = __decorate([
|
|
109
|
-
customElement('urdf-viewer')
|
|
110
|
-
], URDFManipulatorElement);
|
|
111
|
-
export default URDFManipulatorElement;
|
|
112
|
-
//# sourceMappingURL=urdf-manipulator-element.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,yBAAyB,CAAA;AAEjE,OAAO,iBAAiB,MAAM,0BAA0B,CAAA;AAGxD,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,kBAAkB;QAC3B,OAAO,CAAC,iBAAiB,EAAE,GAAG,KAAK,CAAC,kBAAkB,CAAC,CAAA;IACzD,CAAC;IAED,iBAAiB,CAAmB;IACpC,YAAY,CAAyB;IAErC,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,eAAe,CAAC,GAAG;QACrB,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,kBAAkB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AQ,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;gBACxD,MAAK;QACT,CAAC;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.js'\nimport { Material, MeshPhongMaterial } from 'three'\nimport URDFViewerElement from './urdf-viewer-element.js'\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"]}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
|
|
3
|
-
import { URDFRobot } from 'urdf-loader/src/URDFLoader.js';
|
|
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
|
-
}
|