File size: 653 Bytes
ea35075
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import * as THREE from 'three'
import { Object3D } from 'three'

export function FindObjectItem<T extends THREE.Object3D>(
    object: THREE.Object3D,
    name: string
): T | null {
    //console.log(object);
    let result = null
    object.traverse((child) => {
        //console.log("child", child);
        if (child.name == name) {
            result = child
        }
    })
    return result
}

export function GetWorldPosition(o: Object3D) {
    const pos = new THREE.Vector3()
    o.getWorldPosition(pos)
    return pos
}

export function GetLocalPosition(obj: Object3D, postion: THREE.Vector3) {
    return obj.worldToLocal(postion.clone())
}