Skip to content

Commit c7f1f30

Browse files
committed
feat: add Mesh.getVertexPosition()
- add `Mesh.getVertexPosition()` - add doc comment of `SceneUtils.reduceVertices` See: mrdoob/three.js#25049
1 parent eccd730 commit c7f1f30

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

types/three/examples/jsm/utils/SceneUtils.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ export function createMeshesFromMultiMaterialMesh(mesh: Mesh): Group;
1515

1616
export function sortInstancedMesh(mesh: InstancedMesh, compareFn: (a: number, b: number) => number): void;
1717

18+
/**
19+
* Akin to Array.prototype.reduce(), but operating on the vertices of all the visible descendant objects, in world space.
20+
* Additionally, it can operate as a transform-reduce, returning a different type T than the Vector3 input.
21+
* This can be useful for e.g. fitting a viewing frustum to the scene.
22+
*
23+
* @param object - The object to traverse (uses traverseVisible internally).
24+
* @param func - The binary function applied for the reduction.
25+
* Must have the signature: (value: T, vertex: Vector3): T.
26+
* @param initialValue - The value to initialize the reduction with.
27+
* This is required as it also sets the reduction type, which is not required to be Vector3.
28+
*/
1829
export function reduceVertices<TValue>(
1930
object: Object3D,
2031
func: (value: TValue, vertex: Vector3) => TValue,

types/three/src/objects/Mesh.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Raycaster } from './../core/Raycaster';
33
import { Object3D } from './../core/Object3D';
44
import { BufferGeometry } from '../core/BufferGeometry';
55
import { Intersection } from '../core/Raycaster';
6+
import { Vector3 } from '../math/Vector3';
67

78
export class Mesh<
89
TGeometry extends BufferGeometry = BufferGeometry,
@@ -18,5 +19,12 @@ export class Mesh<
1819
type: string;
1920

2021
updateMorphTargets(): void;
22+
23+
/**
24+
* Get the current position of the indicated vertex in local space,
25+
* taking into account the current animation state of both morph targets and skinning.
26+
*/
27+
getVertexPosition(vert: number, target: Vector3): Vector3;
28+
2129
raycast(raycaster: Raycaster, intersects: Intersection[]): void;
2230
}

0 commit comments

Comments
 (0)