BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
BrawlLib.Wii.Models.ModelLinker Class Reference

Public Member Functions

 ModelLinker (MDL0Header *pModel)
 
void RegenerateBoneCache (bool remake=false)
 
void Write (Collada form, ref byte *pGroup, ref byte *pData, bool force)
 
void Finish ()
 

Static Public Member Functions

static ModelLinker Prepare (MDL0Node model)
 

Public Attributes

MDL0HeaderHeader
 
int Version = 9
 
ResourceGroupDefs
 
ResourceGroupBones
 
ResourceGroupVertices
 
ResourceGroupNormals
 
ResourceGroupColors
 
ResourceGroupUVs
 
ResourceGroupMaterials
 
ResourceGroupShaders
 
ResourceGroupObjects
 
ResourceGroupTextures
 
ResourceGroupPalettes
 
ResourceGroupFurVectors
 
ResourceGroupFurLayerCoords
 
MDL0GroupNode[] Groups = new MDL0GroupNode[BankLen]
 
MDL0Node Model
 
int _headerLen
 
int _tableLen
 
int _groupLen
 
int _texLen
 
int _boneLen
 
int _dataLen
 
int _defLen
 
int _assetLen
 
List< MDL0TextureNode_texList
 
List< MDL0TextureNode_pltList
 
int _nodeCount
 
MDL0BoneNode[] BoneCache
 
IMatrixNode[] NodeCache
 
List< VertexCodec_vertices
 
List< VertexCodec_normals
 
List< ColorCodec_colors
 
List< VertexCodec_uvs
 
bool[] _forceDirectAssets = new bool[12]
 

Static Public Attributes

static readonly List< MR >[] IndexBank
 

Constructor & Destructor Documentation

◆ ModelLinker()

BrawlLib.Wii.Models.ModelLinker.ModelLinker ( MDL0Header pModel)
inline
156 {
157 Header = pModel;
158 Version = pModel->_header._version;
159 NodeCache = pModel->Properties == null
160 ? new IMatrixNode[0]
161 : new IMatrixNode[pModel->Properties->_numNodes];
162 BoneCache = new MDL0BoneNode[0];
163
164 bint* offsets = (bint*) ((byte*) pModel + 0x10);
165 if (Version >= 8 && Version <= 11)
166 {
167 List<MR> iList = IndexBank[Version];
168 int groupCount = iList.Count;
169 int offset;
170
171 //Extract resource addresses
172 fixed (ResourceGroup** gList = &Defs)
173 {
174 for (int i = 0; i < groupCount; i++)
175 {
176 if ((offset = offsets[i]) > 0)
177 {
178 gList[(int) iList[i]] = (ResourceGroup*) ((byte*) pModel + offset);
179 }
180 }
181 }
182 }
183 }
Definition: MDL0BoneNode.cs:17
static readonly List< MR >[] IndexBank
Definition: ModelLinker.cs:82
int Version
Definition: ModelLinker.cs:118
ResourceGroup * Defs
Definition: ModelLinker.cs:121
IMatrixNode[] NodeCache
Definition: ModelLinker.cs:142
MDL0Header * Header
Definition: ModelLinker.cs:116
MDL0BoneNode[] BoneCache
Definition: ModelLinker.cs:141
Definition: IMatrixNode.cs:9
Definition: BigEndianTypes.cs:9
bint _version
Definition: BRES.cs:81
BRESCommonHeader _header
Definition: MDL0.cs:19
MDL0Props * Properties
Definition: MDL0.cs:132
bint _numNodes
Definition: MDL0.cs:231
Definition: Common.cs:380

Member Function Documentation

◆ Finish()

void BrawlLib.Wii.Models.ModelLinker.Finish ( )
inline
403 {
404 List<MR> iList = IndexBank[Version];
405 MR resType;
406 bint* pOffset = (bint*) Header + 4;
407 int count = iList.Count, offset;
408
409 fixed (ResourceGroup** pGroup = &Defs)
410 {
411 for (int i = 0; i < count; i++)
412 {
413 resType = iList[i];
414 if ((offset = (int) pGroup[(int) resType]) > 0)
415 {
416 offset -= (int) Header;
417 }
418
419 pOffset[i] = offset;
420 }
421 }
422 }

◆ Prepare()

static ModelLinker BrawlLib.Wii.Models.ModelLinker.Prepare ( MDL0Node  model)
inlinestatic
213 {
214 ModelLinker linker = new ModelLinker
215 {
216 Model = model,
217 Version = model._version
218 };
219
220 //Get flattened bone list and assign it to bone cache
221 linker.RegenerateBoneCache();
222
223 MR resType;
224 int index;
225 List<MR> iList = IndexBank[model._version];
226
227 foreach (MDL0GroupNode group in model.Children)
228 {
229 //If version contains resource type, add it to group list
230 resType = (MR) Enum.Parse(typeof(MR), group.Name);
231 if ((index = iList.IndexOf(resType)) >= 0)
232 {
233 linker.Groups[(int) resType] = group;
234 }
235 }
236
237 return linker;
238 }
int _version
Definition: BRRESNode.cs:1045
Definition: MDL0GroupNode.cs:79
virtual string Name
Definition: ResourceNode.cs:223
List< ResourceNode > Children
Definition: ResourceNode.cs:262
MDL0Node Model
Definition: ModelLinker.cs:137

◆ RegenerateBoneCache()

void BrawlLib.Wii.Models.ModelLinker.RegenerateBoneCache ( bool  remake = false)
inline
186 {
187 if (Model?._boneGroup != null)
188 {
189 if (remake)
190 {
192 .Select(x => x as MDL0BoneNode).ToArray();
193 }
194 else
195 {
197 .Select(x => x as MDL0BoneNode).OrderBy(x => x.BoneIndex).ToArray();
198 }
199 }
200 else
201 {
202 BoneCache = new MDL0BoneNode[0];
203 }
204
205 int i = 0;
206 foreach (MDL0BoneNode b in BoneCache)
207 {
208 b._entryIndex = i++;
209 }
210 }
MDL0GroupNode _boneGroup
Definition: MDL0Node.cs:289
ResourceNode[] FindChildrenByType(string path, ResourceType type)
Definition: ResourceNode.cs:1434
ResourceType
Definition: ResourceType.cs:6

◆ Write()

void BrawlLib.Wii.Models.ModelLinker.Write ( Collada  form,
ref byte *  pGroup,
ref byte *  pData,
bool  force 
)
inline
241 {
242 MDL0GroupNode group;
243 ResourceGroup* pGrp;
244 ResourceEntry* pEntry;
245 int len;
246
247 //Write data in the order it appears
248 foreach (MR resType in OrderBank)
249 {
250 if ((@group = Groups[(int) resType]) == null || SpecialRebuildData((int) resType))
251 {
252 continue;
253 }
254
255 if (resType == MR.Bones)
256 {
257 form?.Say("Writing Bones");
258
259 MDL0Bone* pBone = (MDL0Bone*) pData;
260 foreach (MDL0BoneNode e in BoneCache)
261 {
262 len = e._calcSize;
263 e.Rebuild(pData, len, true);
264 pData += len;
265 }
266
267 //Loop through after all bones are written
268 //and set header offsets to related bones
269 foreach (MDL0BoneNode e in BoneCache)
270 {
272 }
273 }
274 else if (resType == MR.Shaders)
275 {
276 MDL0GroupNode mats = Groups[(int) MR.Materials];
277 MDL0Material* mHeader;
278
279 form?.Say("Writing Shaders");
280
281 //Write data without headers
282 foreach (ResourceNode e in group.Children)
283 {
284 if (((MDL0ShaderNode) e)._materials.Count > 0)
285 {
286 len = e._calcSize;
287 e.Rebuild(pData, len, force);
288 pData += len;
289 }
290 }
291
292 //Write one header for each material, using same order.
293 if (mats != null)
294 {
295 foreach (MDL0MaterialNode mat in mats.Children)
296 {
297 mHeader = mat.Header;
298 if (mat._shader != null)
299 {
300 len = (int) mat._shader.Header;
301 mHeader->_shaderOffset = len - (int) mHeader;
302 }
303 else
304 {
305 mHeader->_shaderOffset = 0;
306 }
307 }
308 }
309 }
310 else if (resType == MR.Objects || resType == MR.Materials)
311 {
312 foreach (ResourceNode r in group.Children)
313 {
314 form?.Say("Writing " + resType + " - " + r.Name);
315
316 len = r._calcSize;
317 r.Rebuild(pData, len, true); //Forced to fix object node ids and align materials
318 pData += len;
319 }
320 }
321 else
322 {
323 bool rebuild = true;
324
325 if (Model._isImport)
326 {
327 if (group._name == "Vertices" ||
328 group._name == "Normals" ||
329 group._name == "UVs" ||
330 group._name == "Colors")
331 {
332 rebuild = false; //The data has already been written!
333 }
334 }
335
336 if (rebuild)
337 {
338 foreach (ResourceNode e in group.Children)
339 {
340 //Console.WriteLine("Rebuilding the " + group.Name);
341
342 form?.Say("Writing the " + resType + " - " + e.Name);
343
344 len = e._calcSize;
345 e.Rebuild(pData, len, true); //Forced just in case we need to convert to float.
346 pData += len;
347 }
348 }
349 }
350 }
351
352 //Write relocation offsets in the order of the header
353 fixed (ResourceGroup** pOut = &Defs)
354 {
355 foreach (MR resType in IndexBank[Version])
356 {
357 if ((@group = Groups[(int) resType]) == null || SpecialRebuildData((int) resType))
358 {
359 continue;
360 }
361
362 pOut[(int) resType] = pGrp = (ResourceGroup*) pGroup;
363 pEntry = &pGrp->_first + 1;
364 if (resType == MR.Bones)
365 {
366 *pGrp = new ResourceGroup(BoneCache.Length);
367 foreach (ResourceNode e in BoneCache)
368 {
369 (pEntry++)->_dataOffset = (int) ((byte*) e.WorkingUncompressed.Address - pGroup);
370 }
371 }
372 else if (resType == MR.Shaders)
373 {
374 MDL0GroupNode mats = Groups[(int) MR.Materials];
375
376 if (mats != null)
377 {
378 //Create a material group with the amount of entries
379 *pGrp = new ResourceGroup(mats.Children.Count);
380
381 foreach (MDL0MaterialNode mat in mats.Children)
382 {
383 (pEntry++)->_dataOffset = (int) mat._shader.Header - (int) pGrp;
384 }
385 }
386 }
387 else
388 {
389 *pGrp = new ResourceGroup(group.Children.Count);
390 foreach (ResourceNode e in group.Children)
391 {
392 (pEntry++)->_dataOffset = (int) ((byte*) e.WorkingUncompressed.Address - pGroup);
393 }
394 }
395
396 pGroup += pGrp->_totalSize;
397 }
398 }
399 }
void Say(string text)
Definition: ColladaImportDialog.cs:30
void CalculateOffsets()
Definition: MDL0BoneNode.cs:697
Definition: MDL0MaterialNode.cs:22
bool _isImport
Definition: MDL0Node.cs:47
Definition: MDL0ShaderNode.cs:11
Definition: ResourceNode.cs:129
virtual void Rebuild()
Definition: ResourceNode.cs:987
int _calcSize
Definition: ResourceNode.cs:145
string _name
Definition: ResourceNode.cs:139
DataSource WorkingUncompressed
Definition: ResourceNode.cs:183
MDL0GroupNode[] Groups
Definition: ModelLinker.cs:135
VoidPtr Address
Definition: ResourceNode.cs:31
Definition: MDL0.cs:651
Definition: MDL0.cs:1165
Definition: Common.cs:472
bint _totalSize
Definition: Common.cs:383
ResourceEntry _first
Definition: Common.cs:385

Member Data Documentation

◆ _assetLen

int BrawlLib.Wii.Models.ModelLinker._assetLen

◆ _boneLen

int BrawlLib.Wii.Models.ModelLinker._boneLen

◆ _colors

List<ColorCodec> BrawlLib.Wii.Models.ModelLinker._colors

◆ _dataLen

int BrawlLib.Wii.Models.ModelLinker._dataLen

◆ _defLen

int BrawlLib.Wii.Models.ModelLinker._defLen

◆ _forceDirectAssets

bool [] BrawlLib.Wii.Models.ModelLinker._forceDirectAssets = new bool[12]

◆ _groupLen

int BrawlLib.Wii.Models.ModelLinker._groupLen

◆ _headerLen

int BrawlLib.Wii.Models.ModelLinker._headerLen

◆ _nodeCount

int BrawlLib.Wii.Models.ModelLinker._nodeCount

◆ _normals

List<VertexCodec> BrawlLib.Wii.Models.ModelLinker._normals

◆ _pltList

List<MDL0TextureNode> BrawlLib.Wii.Models.ModelLinker._pltList

◆ _tableLen

int BrawlLib.Wii.Models.ModelLinker._tableLen

◆ _texLen

int BrawlLib.Wii.Models.ModelLinker._texLen

◆ _texList

List<MDL0TextureNode> BrawlLib.Wii.Models.ModelLinker._texList

◆ _uvs

List<VertexCodec> BrawlLib.Wii.Models.ModelLinker._uvs

◆ _vertices

List<VertexCodec> BrawlLib.Wii.Models.ModelLinker._vertices

◆ BoneCache

MDL0BoneNode [] BrawlLib.Wii.Models.ModelLinker.BoneCache

◆ Bones

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.Bones

◆ Colors

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.Colors

◆ Defs

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.Defs

◆ FurLayerCoords

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.FurLayerCoords

◆ FurVectors

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.FurVectors

◆ Groups

MDL0GroupNode [] BrawlLib.Wii.Models.ModelLinker.Groups = new MDL0GroupNode[BankLen]

◆ Header

MDL0Header* BrawlLib.Wii.Models.ModelLinker.Header

◆ IndexBank

readonly List<MR> [] BrawlLib.Wii.Models.ModelLinker.IndexBank
static

◆ Materials

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.Materials

◆ Model

MDL0Node BrawlLib.Wii.Models.ModelLinker.Model

◆ NodeCache

IMatrixNode [] BrawlLib.Wii.Models.ModelLinker.NodeCache

◆ Normals

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.Normals

◆ Objects

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.Objects

◆ Palettes

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.Palettes

◆ Shaders

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.Shaders

◆ Textures

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.Textures

◆ UVs

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.UVs

◆ Version

int BrawlLib.Wii.Models.ModelLinker.Version = 9

◆ Vertices

ResourceGroup* BrawlLib.Wii.Models.ModelLinker.Vertices

The documentation for this class was generated from the following file: