-
Notifications
You must be signed in to change notification settings - Fork 8
/
minify.js
40 lines (37 loc) · 1.01 KB
/
minify.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
const gltfPipeline = require('gltf-pipeline')
const fsExtra = require('fs-extra')
var glob = require('glob')
const processGltf = gltfPipeline.processGltf
const gltfToGlb = gltfPipeline.gltfToGlb
const options = {
dracoOptions: {
compressionLevel: 10,
},
}
glob('files/models/**/*.gltf', {}, function (er, files) {
files.forEach((file) => {
try {
const gltf = fsExtra.readJsonSync(file)
processGltf(gltf, options)
.then(function (results) {
fsExtra.writeJsonSync(file, results.gltf)
})
.catch(() => {})
} catch {
//
}
})
})
glob('files/models/barn/model.gltf', {}, function (er, files) {
const allGlbs = files.map((file) => file.split('model.gltf')[0] + 'model.glb')
allGlbs.forEach((glb) => {
if (!fsExtra.existsSync(glb)) {
const gltf = fsExtra.readFileSync(
glb.split('model.glb')[0] + 'model.gltf'
)
gltfToGlb(gltf, options).then(function (results) {
fsExtra.writeFileSync(glb, results.glb)
})
}
})
})