File size: 3,617 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import * as THREE from 'three'
import { FindObjectItem } from './utils/three-utils'
import { LoadFBXFile, LoadGLTFile, LoadObjFile } from './utils/loader'

export let HandObject: THREE.Group | null = null
export let FootObject: THREE.Group | null = null

export const HandModelInfo = {
    meshName: 'shoupolySurface1',
    bonePrefix: 'shoujoint',
}
export const FootModelInfo = {
    meshName: 'FootObject',
    bonePrefix: 'FootBone',
}

export const ExtremitiesMapping: Record<
    string,
    {
        meshName: string
        bonePrefix: string
    }
> = {
    left_hand: HandModelInfo,
    right_hand: HandModelInfo,
    left_foot: FootModelInfo,
    right_foot: FootModelInfo,
}

export function IsMatchBonePrefix(name: string) {
    if (name.startsWith(HandModelInfo.bonePrefix)) return true
    if (name.startsWith(FootModelInfo.bonePrefix)) return true
    return false
}

export async function LoadHand(
    handFBXFileUrl: string,
    onLoading?: (loaded: number) => void
) {
    const fbx = await LoadFBXFile(handFBXFileUrl, onLoading)

    // fbx.scale.multiplyScalar(10)
    const mesh = FindObjectItem<THREE.SkinnedMesh>(fbx, HandModelInfo.meshName)!
    mesh.material = new THREE.MeshPhongMaterial()
    // this.scene.add();
    // const helper = new THREE.SkeletonHelper(mesh.parent!);
    // this.scene.add(helper);

    // console.log(mesh.skeleton.bones)
    mesh.skeleton.bones.forEach((o) => {
        const point = new THREE.Mesh(
            new THREE.SphereGeometry(0.2),
            new THREE.MeshBasicMaterial({
                color: 0xff0000,
                //  vertexColors: true,
                depthTest: false,
                opacity: 1,
                transparent: true,
                // depthWrite: false,
                // toneMapped: false,
                // transparent: true,
            })
        )
        point.name = 'red_point'
        // point.scale.setX(0.2)
        // point.position.copy(o.position)
        o.add(point)
    })

    const mask = new THREE.Mesh(
        new THREE.CylinderGeometry(1, 1, 0.4, 32),
        new THREE.MeshBasicMaterial({ color: 0x000000 })
    )
    mask.name = 'hand_mask'
    mask.visible = false
    mask.rotateZ(Math.PI / 2)
    mesh.skeleton.bones[0].add(mask)

    HandObject = fbx
    return fbx
}

export async function LoadFoot(
    footFBXFileUrl: string,
    onLoading?: (loaded: number) => void
) {
    const fbx = await LoadFBXFile(footFBXFileUrl, onLoading)

    console.log(fbx)
    // fbx.scale.multiplyScalar(0.001)

    const mesh = FindObjectItem<THREE.SkinnedMesh>(fbx, FootModelInfo.meshName)!
    mesh.material = new THREE.MeshPhongMaterial()
    // this.scene.add();
    // const helper = new THREE.SkeletonHelper(mesh.parent!);
    // this.scene.add(helper);

    console.log(mesh.skeleton.bones)
    mesh.skeleton.bones.forEach((o) => {
        if (o.name !== 'FootBone2') return
        const point = new THREE.Mesh(
            new THREE.SphereGeometry(0.1),
            new THREE.MeshBasicMaterial({
                color: 0xff0000,
                depthTest: false,
                opacity: 1,
                transparent: true,
            })
        )

        point.name = 'red_point'
        // point.position.copy(o.position)
        point.translateX(-0.3)
        o.add(point)
    })

    const mask = new THREE.Mesh(
        new THREE.CylinderGeometry(0.35, 0.35, 0.2, 32),
        new THREE.MeshBasicMaterial({ color: 0x000000 })
    )
    mask.scale.setX(0.7)
    mask.name = 'foot_mask'
    mask.visible = false
    mesh.skeleton.bones[0].add(mask)

    FootObject = fbx
    return fbx
}