File size: 4,629 Bytes
73c6193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// var THREE = require('three');
// THREE.OrbitControls = require('three-orbit-controls')(THREE);
// THREE.GLTFLoader = require('./GLTFLoader.js')(THREE);

import {Viewer, AvatarSystem} from './GLTFAvatarViewer.js';
// import {mergeGLTFAvatar} from './GLTFAvatarMerge.js';
// import {fileSave} from './lib/makeglb.js';

import dat from 'dat.gui';


var viewer = new Viewer();


// viewer.init();
// document.getElementById('container').appendChild(viewer.canvas);






var AvatarControl = function() {
    this.skeleton = 'mixamo';
    this.skin = {
        hair: 'maid',
        clothes: 'maid-dress',

        face: 'saber'
    };

    // skeleton animations
    this.animations = 'null';

    this.mergeAndExport = function() {
        viewer.mergeAndExport();
    };
};


var control = new AvatarControl();

var gui = new dat.GUI();

// var skeletonControl = gui.add(control, 'skeleton', ['mixamo', 'stand-pose']);   // TODO: get repo from avatar system
var skeletonControl = gui.add(control, 'skeleton', Object.keys(AvatarSystem.repo.skeletons));   // TODO: get repo from avatar system
skeletonControl.onChange(function(value) {
    // console.log(value);
    viewer.selectSkeleton(value);
});


var animationFolder = gui.addFolder('animations');
animationFolder.open();

var visibilityFolder = gui.addFolder('visibility-control');
var visibilityToggles = [];
var visibilityValues = {};

// var animationControl; 
var animationToggles = [];
viewer.skeletonUpdateCallback = function(key) {
    // if ( animationControl ) animationFolder.remove(animationControl);
    // animationControl = animationFolder.add(control, 'animations', viewer.skeletonAnimations);

    // animationControl.onChange(function(value) {
    //     if ( viewer.skeletonAnimations.length > 0) {
    //         control.animations = viewer.skeletonAnimations[0];
            
    //         for (var i = 0, len = viewer.skeletonAnimations.length; i < len; i++) {
    //             if (value == viewer.skeletonAnimations[i]) {
    //                 viewer.playAnimation(i);
    //             }
    //         }

    //         animationControl.updateDisplay();
    //     }
        
    // });


    for (var i = 0, len = animationToggles.length; i < len; i++) {
        animationFolder.remove(animationToggles[i]);
    }
    animationToggles = [];
    for (var key in viewer.skeletonActionStates) {
        var toggle = animationFolder.add(viewer.skeletonActionStates, key);
        toggle.onChange((function() {
            var k = key;
            return function(v) {
                viewer.playAnimationMixing(k, v);
            };
        })());
        animationToggles.push(toggle);
    }


    for (var i = 0, len = visibilityToggles.length; i < len; i++) {
        visibilityFolder.remove(visibilityToggles[i]);
    }
    visibilityToggles = [];
    visibilityValues = {};
    // for (var id in viewer.skeletonVisibilityId2Name) {
    for (var id = 1, len = viewer.skeletonVisibilityId2Name.length; id < len; id++) {
        // if (id === 0) continue;

        visibilityValues[id] = true;

        var toggle = visibilityFolder.add(visibilityValues, id).name(id + ' ' + viewer.skeletonVisibilityId2Name[id]);

        toggle.onChange((function() {
            var i = id;
            return function(v) {
                viewer.updateVisibilityValue(i, v);
            };
        })());


        toggle.listen();
        
        visibilityToggles.push(toggle);
    }

};


viewer.skinUpdateCallback = function(type, key) {
    var array = viewer.getVisibilityArray();
    for (var i = 0, len = array.length; i < len; i++) {
        visibilityValues[i] = array[i] === 255 ? true : false;
    }
};




var skinFolder = gui.addFolder('skins');
skinFolder.open();

// skinFolder.add(control.skin, 'hair', Object.keys(AvatarSystem.repo.hair)).onChange(function(value) {
//     viewer.selectSkin('hair', value);
// });
// skinFolder.add(control.skin, 'clothes', Object.keys(AvatarSystem.repo.clothes)).onChange(function(value) {
//     viewer.selectSkin('clothes', value);
// });

function getSelectSkinFunc(cat) {
    var c = cat;
    return function(value) {
        viewer.selectSkin(c, value);
    };
}

for (var cat in control.skin) {
    skinFolder.add(control.skin, cat, Object.keys(AvatarSystem.repo[cat])).onChange(
        getSelectSkinFunc(cat)
    );
}


gui.add(control, 'mergeAndExport');



// viewer.init(document.getElementById('canvas'));
viewer.init();