-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmerge_anim.js
50 lines (40 loc) · 1.3 KB
/
merge_anim.js
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
const fs = require('fs');
let mesh_path = process.argv[2];
let anim_path = process.argv[3];
let mesh = JSON.parse(fs.readFileSync(mesh_path));
let anim = JSON.parse(fs.readFileSync(anim_path));
let final_mesh = JSON.parse(fs.readFileSync(mesh_path));
anim.buffers.forEach(v => {
final_mesh.buffers.push(v);
});
anim.bufferViews.forEach(v => {
v.buffer += mesh.buffers.length;
final_mesh.bufferViews.push(v);
});
anim.accessors.forEach(v => {
v.bufferView += mesh.bufferViews.length;
final_mesh.accessors.push(v);
});
anim.animations.forEach(v => {
v.samplers = v.samplers.map(e => ({
input: e.input + mesh.accessors.length,
output: e.output + mesh.accessors.length,
interpolation: e.interpolation,
}));
v.channels = v.channels.map(e => {
let targetNode = false;
mesh.nodes.forEach((node, idx) => {
if (!node.hasOwnProperty('name')) return;
if (node.name.toLowerCase() == e.target.extras.toLowerCase()) {
targetNode = idx;
}
});
if (targetNode !== false) {
e.target.node = targetNode;
return e;
}
return false;
}).filter(e => e !== false);
final_mesh.animations.push(v);
});
fs.writeFileSync('./merged.gltf', JSON.stringify(final_mesh));