UNPKG

3.26 kBTypeScriptView Raw
1import { Object3D } from "../core/Object3D.js";
2import { ColorRepresentation } from "../math/Color.js";
3import { Vector3 } from "../math/Vector3.js";
4import { Line } from "../objects/Line.js";
5import { Mesh } from "../objects/Mesh.js";
6
7/**
8 * An 3D arrow object for visualizing directions.
9 * @example
10 * ```typescript
11 * const dir = new THREE.Vector3(1, 2, 0);
12 * //normalize the direction vector (convert to vector of length 1)
13 * dir.normalize();
14 * const origin = new THREE.Vector3(0, 0, 0);
15 * const length = 1;
16 * const hex = 0xffff00;
17 * const {@link ArrowHelper} = new THREE.ArrowHelper(dir, origin, length, hex);
18 * scene.add(arrowHelper);
19 * ```
20 * @see Example: {@link https://threejs.org/examples/#webgl_shadowmesh | WebGL / shadowmesh}
21 * @see {@link https://threejs.org/docs/index.html#api/en/helpers/ArrowHelper | Official Documentation}
22 * @see {@link https://github.com/mrdoob/three.js/blob/master/src/helpers/ArrowHelper.js | Source}
23 */
24export class ArrowHelper extends Object3D {
25 /**
26 * Create a new instance of {@link ArrowHelper}
27 * @param dir Direction from origin. Must be a unit vector. Default `new THREE.Vector3(0, 0, 1)`
28 * @param origin Point at which the arrow starts. Default `new THREE.Vector3(0, 0, 0)`
29 * @param length Length of the arrow. Default `1`
30 * @param hex Hexadecimal value to define color. Default `0xffff00`
31 * @param headLength The length of the head of the arrow. Default `0.2 * length`
32 * @param headWidth The width of the head of the arrow. Default `0.2 * headLength`
33 */
34 constructor(
35 dir?: Vector3,
36 origin?: Vector3,
37 length?: number,
38 color?: ColorRepresentation,
39 headLength?: number,
40 headWidth?: number,
41 );
42
43 /**
44 * A Read-only _string_ to check if `this` object type.
45 * @remarks Sub-classes will update this value.
46 * @override
47 * @defaultValue `ArrowHelper`
48 */
49 override readonly type: string | "ArrowHelper";
50
51 /**
52 * Contains the line part of the arrowHelper.
53 */
54 line: Line;
55
56 /**
57 * Contains the cone part of the arrowHelper.
58 */
59 cone: Mesh;
60
61 /**
62 * Sets the color of the arrowHelper.
63 * @param color The desired color.
64 */
65 setColor(color: ColorRepresentation): void;
66
67 /**
68 * @param dir The desired direction. Must be a unit vector.
69 */
70 setDirection(dir: Vector3): void;
71
72 /**
73 * Sets the length of the arrowhelper.
74 * @param length The desired length.
75 * @param headLength The length of the head of the arrow. Default `0.2 * length`
76 * @param headWidth The width of the head of the arrow. Default `0.2 * headLength`
77 */
78 setLength(length: number, headLength?: number, headWidth?: number): void;
79
80 /**
81 * Copy the given object into this object
82 * @remarks Note: event listeners and user-defined callbacks ({@link onAfterRender | .onAfterRender} and {@link onBeforeRender | .onBeforeRender}) are not copied.
83 * @param source
84 */
85 override copy(source: this): this;
86
87 /**
88 * Frees the GPU-related resources allocated by this instance
89 * @remarks
90 * Call this method whenever this instance is no longer used in your app.
91 */
92 dispose(): void;
93}