-
Notifications
You must be signed in to change notification settings - Fork 0
/
assethelper.js
60 lines (49 loc) · 1.5 KB
/
assethelper.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
51
52
53
54
55
56
57
58
59
60
var fs = require('fs');
var path = 'public\\assets\\FertileSoil\\modular_temple\\';
var writePath = 'assets/FertileSoil/modular_temple/';
var commonMaterial = 'Materials_Modular_Temple'
var package = 'modular_temple';
var areaPerEntity = 30;
var gridSize, count;
var grid = [];
var output = [];
fs.readdir(path, function(err, items){
count = 0;
var entities = [];
items.forEach((item, index) => {
if(item.indexOf('.obj')>=0){
entities.push(item.substr(0, item.indexOf('.obj')));
count++;
}
})
gridSize = Math.sqrt(count);
console.log("Total Files: " + count + " (" + gridSize + ")");
entities.forEach(iterate1);
grid.forEach(iterate2);
//console.log(JSON.stringify(output));
fs.writeFile(package + '.json', JSON.stringify(output), 'utf8', () => console.log("done"));
})
var iterate1 = function(name, index){
var row = Math.floor(index/gridSize);
if(!grid[row]){
grid[row] = [];
}
if(!commonMaterial){
commonMaterial = name;
}
grid[row].push({
name,
position: {x: 0, y: 0, z: 0},
scale: {x: 5, y: 5, z: 5},
rotation: {x: 0, y: 0, z: 0},
mesh: writePath + name + ".obj",
material: writePath + commonMaterial + ".mtl"
});
}
var iterate2 = function(entityRow, row){
entityRow.forEach((entity, column) => {
entity.position.x = row * areaPerEntity;
entity.position.z = column * areaPerEntity;
output.push(entity);
});
}