-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRemoveFacesOfTexture_CmdLine.bio2s
More file actions
221 lines (176 loc) · 4.85 KB
/
RemoveFacesOfTexture_CmdLine.bio2s
File metadata and controls
221 lines (176 loc) · 4.85 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "std\lodNames.inc"
console=openStandardIO;
//example usage
//O2Script.exe -a O2Scripts\RemoveFacesOfTexture_CmdLine.bio2s p:\test\name.p3d path\textureOrMaterialName.paa/rvmat
//Library methods
//==================
/*
_deleteFace =
{
_faceIndex = _x;
_texture = getTexture (_currentLOD face _faceIndex);
if (_texture == TextureToRemove) then
{
_faceSel = newSelection _currentLOD;
_faceSel selectFace _x;
// _faceSel selectFaces (getSelectedFaces _sel);
deleteSelected _faceSel;
};
};
*/
_removeIsolatedPoints =
{
private["_currentLOD","_usedPoints","_isolatedPoints","_face","_verts","_sel"];
_currentLOD = _this;
//find all "used" (in faces) points
_usedPoints = [];
_isolatedPoints = [];
_currentLOD forEachFace [{true},
{
_faceIndex = _x;
_face = _currentLOD face _faceIndex;
_verts = getVertices _face;
{
if (!(_x in _usedPoints)) then {_usedPoints set [count _usedPoints,_x]};
} forEach _verts;
}];
_currentLOD forEachPoint [{!(_x in _usedPoints)},
{
_isolatedPoints set [count _isolatedPoints,_x];
}];
//_currentLOD callRuntime "isolatedpts";
_sel = newSelection _currentLOD;
_sel selectPoints _isolatedPoints;
deleteSelected _sel;
};
_selectByFaceIndices =
{
private ["_currentLOD","_faceIndices","_sel","_return"];
_currentLOD = _this @ 0;
_facesIndices = _this @ 1;
_sel = newSelection _currentLOD;
_sel selectFaces _facesIndices;
_return = selectPointsFromFaces _sel;
_return
};
_getTexOrMatName =
{
private["_currentLOD","_faceIndex","_isMat","_return"];
_currentLOD = _this @ 0;
_faceIndex = _this @ 1;
_isMat = _this @ 2;
_return = "";
if (_isMat) then
{
_return = getMaterial (_currentLOD face _faceIndex)
}
else
{
_return = getTexture (_currentLOD face _faceIndex)
};
_return
};
_getProxyFaces =
{
private ["_currentLOD","_faces","_face","_selections","_proxySel"];
_currentLOD = _this;
_faces = [];
_selections = (getSelections _currentLOD);
{
if (_x @ [0,6]=="proxy:") then
{
_proxySel = _currentLOD loadSelection _x;
_face = (getSelectedFaces _proxySel) @ 0;
_faces set [count _faces,_face];
};
} forEach _selections;
_faces
};
_faceIndicesByTexture =
{
private["_currentLOD","_texName","_faceIndices"];
_currentLOD = _this @ 0;
_texName = _this @ 1;
_texIsMat = _this @ 2;
if (logging) then {console<<"_currentLOD: "<<str _currentLOD<<eoln;};
if (logging) then {console<<"_texName: "<<_texName<<eoln;};
if (logging) then {console<<"_texIsMat: "<<str _texIsMat<<eoln;};
_proxyFaces = _currentLOD call _getProxyFaces;
if (logging) then {console<<"_proxyFaces: "<<str _proxyFaces<<eoln;};
_faceIndices = [];
_currentLOD forEachFace
[
{
if (logging) then {console<<"_x: "<<str _x<<eoln;};
if (logging) then {console<<"_texOrMat: "<<([_currentLOD,_x,_texIsMat] call _getTexOrMatName)<<eoln;};
if (logging) then {console<<"found?: "<<str (([_currentLOD,_x,_texIsMat] call _getTexOrMatName) == _texName)<<eoln;};
([_currentLOD,_x,_texIsMat] call _getTexOrMatName) == _texName
},
{
if (!(_x in _proxyFaces)) then
{
_faceIndices set [count _faceIndices,_x];
};
}
];
if (logging) then {console<<"_faceIndices: "<<str _faceIndices<<eoln;};
_faceIndices
};
_selectionByTexture =
{
private["_currentLOD","_texName","_texIsMat","_faceIndices","_sel"];
_currentLOD = _this @ 0;
_texName = _this @ 1;
_texIsMat = _this @ 2;
_faceIndices = [_currentLOD,_texName,_texIsMat] call _faceIndicesByTexture;
_sel = [_currentLOD,_faceIndices] call _selectByFaceIndices;
_sel
};
_removeFaces =
{
private["_currentLOD","_sel","_faceSel","_selectedFaces"];
_currentLOD = _this @ 0;
_sel = _this @ 1;
//create new selection with just faces
_faceSel = newSelection _currentLOD;
_selectedFaces = getSelectedFaces _sel;
_faceSel selectFaces _selectedFaces;
deleteSelected _faceSel;
};
_optimizeByTex =
{
private["_currentLOD","_texName","_texIsMat","_sel"];
_currentLOD = _this @ 0;
_texName = _this @ 1;
_texIsMat = _this @ 2;
_sel = [_currentLOD,_texName,_texIsMat] call _selectionByTexture;
[_currentLOD,_sel] call _removeFaces;
};
// main
_sourcePath = this @ 0;
_targetPath = _sourcePath;
_textureOrMaterialToRemove = this @ 1;
_p3d = newLODObject;
_p3d loadP3D _sourcePath;
_LODs = getObjects _p3d;
_resolutions = getResolutions _p3d;
logging = false;
//logging = true;
if (logging) then {console<<"_sourcePath: "<<_sourcePath<<eoln;};
for "_i" from 0 to ((count _p3d) - 1) do
{
private["_currentLOD","_currentResolution"];
_currentLOD = _LODs @ _i;
_currentResolution = _resolutions @ _i;
// _currentLOD forEachFace [{true},_deleteFace];
// if (IS_LOD_RESOLUTION(_currentResolution)) then
// {
// halt;
[_currentLOD,_textureOrMaterialToRemove,false] call _optimizeByTex;
[_currentLOD,_textureOrMaterialToRemove,true] call _optimizeByTex;
_currentLOD call _removeIsolatedPoints;
// };
};
// revert
//if (true) exitWith {-1};
save (_p3d as _targetPath);