-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddonMaker.bio2s
217 lines (198 loc) · 5.86 KB
/
addonMaker.bio2s
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
/*
Script name:
Addon Maker
Command line:
Variant 1) none - dialog will shown to ask parameters
Variant 2) text or filename - dialog will shown to ask parameters, text will be used to fill first line in dialog
Variant 3) Object - dialog will shown to ask parameters, object name will be used to fill first line in dialog
Variant 4) Array - in form [source,sourceBase,target,targetBase], no dialog, use parameters in array
Note: Variant 3) is useful for running in O2 directly
Variant 4) is useful for o2script -a
Description:
Addon Maker creates a copy of source P3D file to target P3D file and also copy all
referenced files (textures, materials, etc) to target location.
*/
#include "std/paramFile.inc"
scopeName "Base";
if (this in ["options"]) then {messageBox ["No options available",0]; breakOut "Base";};
console=openStandardIO;
ResourceList=+[];
CanCopyResource={ //_this=src
private ["_src","_i","_found"];
_found=false;
_src=_this;
for "_i" from 0 to (count ResourceList-1) do
{
if (ResourceList select _i==_src) then
{
_found=true;
_i=nil;
};
};
if (!_found) then
{
ResourceList set [count ResourceList,_src];
};
!_found
};
this call
{
sourceModel="";
sourceBasePath="x:\";
targetModel="";
targetBasePath="p:\";
switch (typename this) do
{
case "STRING": {sourceModel=this;};
case "LODObject": {sourceModel=nameOf this;};
case "ARRAY":
{
sourceModel=this @ 0;
sourceBasePath=this @ 1;
targetModel=this @ 2;
targetBasePath=this @ 3;
};
};
private "_res";
if (targetModel=="") then
{
_res=dialogBox [250,150,"Addon Maker",
["label",180,10,"Source P3D",0],["break"],
["textline",180,15,"sourceModel",0],
["browse-button",50,15,"P3D files|*.p3d|All files|*.*|",false,"Select source P3D"],["break"],
["label",180,10,"Source Base Path",0],["break"],
["textline",180,15,"sourceBasePath",0],["break"],
["label",180,10,"Target P3D",0],["break"],
["textline",180,15,"targetModel",0],
["browse-button",50,15,"P3D files|*.p3d|All files|*.*|",true,"Select target P3D"],["break"],
["label",180,10,"Target Base Path",0],["break"],
["textline",180,15,"targetBasePath",0],["break"],
["submit",90,20,1,"Create"],
["cancel-button",85,20]
];
}
else
{
_res=1;
};
if (_res!=1) then {breakTo "Base";};
_srcPathInfo=splitPath sourceModel;
_trgPathInfo=splitPath targetModel;
_dataPath=(_trgPathInfo select 0)+(_trgPathInfo select 1)+"data";
_trgOff=[0,count targetBasePath] select (targetBasePath==(targetModel @ [0,count targetBasePath]));
p3d=newLODObject;
console<<"Loading P3D: "<<sourceModel<<eoln;
_res=p3d loadP3D sourceModel;
if (!_res) then
{
console<<"Unable to load p3d "<<sourceModel<<eoln;
getLine console;
};
if (!_res) exitWith {};
createFolder _dataPath;
_dataPath=_dataPath+"\";
{
console << "Relocating data..."<<eoln;
private "_mesh";
_mesh=_x;
{
if (_x!="") then
{
private ["_src","_trg","_pth"];
_src=sourceBasePath+_x;
_pth=splitPath _src;
_trg=_dataPath+(_pth select 2)+(_pth select 3);
if (_src call CanCopyResource) then
{
console<<"Copying texture: "<<(_pth select 2)<<(_pth select 3)<<eoln;
_src copyFileTo _trg;
};
};
} forEach (_mesh callRuntime "texlist");
{
if (_x!="") then
{
private ["_src","_trg","_pth"];
_src=sourceBasePath+_x;
_pth=splitPath _src;
_trg=_dataPath+(_pth select 2)+(_pth select 3);
if (_src call CanCopyResource) then
{
console<<"Copying material: "<<(_pth select 2)<<(_pth select 3)<<eoln;
private ["_pfile","_input","_output","_process"];
_input=openFile [_src,1];
_output=openFile [_trg,2];
if (isnil("_input")) then {console<<"Error openning source:"<<_src<<eoln;};
if (isnil("_output")) then {console<<"Error openning target:"<<_trg<<eoln;};
if (isnil("_output") || isnil("_input")) exitWith {};
_pfile=_input call paramFileRead;
if (isnil("_pfile")) then
{
console<<"Param file parser error near:"<<getLine _input<<eoln;
}
else
{
_process=
{
switch (true) do
{
case ((_x select 1)=="class"):{ _process forEach (_x select 2);};
case ((_x select 0)=="texture"):
{
if ((_x select 2)!="") then
{
private "_xs";
_xs=_x select 2;
if (_xs @ 0!="#") then
{
private ["_src","_trg","_pth"];
_src=sourceBasePath+_xs;
_pth=splitPath _src;
_trg=_dataPath+(_pth select 2)+(_pth select 3);
if (_src call CanCopyResource) then
{
console<<"...Copying texture: "<<(_pth select 2)<<(_pth select 3)<<eoln;
_src copyFileTo _trg;
};
_trg=_trg @ [_trgOff];
_x set [2,_trg];
};
};
};
};
};
_process forEach _pfile;
[_output,_pfile] call paramFileWrite;
if (!_output) then {console<<"Unable to save rvmat file: "<<_trg<<eoln;}
};
};
};
} forEach (_mesh callRuntime "matlist");
console << "Rebuilding references..."<<eoln;
private "_reloc";
_reloc={
if (_this!="") then
{
private ["_src","_pth"];
_src=sourceBasePath+_this;
_pth=splitPath _src;
_this=(_dataPath+(_pth select 2)+(_pth select 3)) @ [_trgOff];
};
_this
};
_mesh forEachFace [{true},
{
_this face _x setTexture(getTexture(_this face _x) call _reloc);
_this face _x setMaterial(getMaterial(_this face _x) call _reloc);
}];
}
forEach getObjects p3d;
console << "Saving..."<<eoln;
_res=save (p3d as targetModel);
if (!_res) then
{
console<<"Unable to save p3d "<<targetModel<<eoln;
getLine console;
};
if (!_res) exitWith {};
};