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

Public Member Functions

void Dispose ()
 
 VertexCodec (Vector3[] vertices, bool removeZ, bool forceFloat)
 
 VertexCodec (Vector3[] vertices, bool removeZ)
 
 VertexCodec (Vector2[] vertices, bool forceFloat)
 
 VertexCodec (Vector2[] vertices)
 
 VertexCodec (Vector3 *sPtr, int count, bool removeZ)
 
 VertexCodec (Vector2 *sPtr, int count)
 
void GetEncoder ()
 
void Write (byte *pOut)
 
void Write (ref byte *pOut, int index)
 
void Write (Vector2[] vertices, byte *pOut)
 
void Write (Vector3[] vertices, byte *pOut)
 
void Write (float *pIn, byte *pOut)
 

Static Public Member Functions

static UnsafeBuffer Decode (MDL0UVData *header)
 
static UnsafeBuffer Decode (VoidPtr data, byte divisor, uint length, WiiVertexComponentType componentType, bool UVs, int isSpecial)
 
static UnsafeBuffer Decode (MDL0VertexData *header)
 
static UnsafeBuffer Decode (MDL0NormalData *header)
 
static Vector3[] ExtractVertices (MDL0VertexData *vertices)
 
static Vector3[] ExtractVertices (MDL0FurPosData *vertices)
 
static Vector3[] ExtractNormals (MDL0NormalData *normals)
 
static Vector2[] ExtractUVs (MDL0UVData *uvs)
 

Public Attributes

Vector2Address
 
Vector3 _min
 
Vector3 _max
 
bool _hasZ
 
WiiVertexComponentType _type
 
int _srcElements
 
int _srcCount
 
int _dstElements
 
int _dstCount
 
int _dstStride
 
int _scale
 
int _dataLen
 

Constructor & Destructor Documentation

◆ VertexCodec() [1/6]

BrawlLib.Wii.Models.VertexCodec.VertexCodec ( Vector3[]  vertices,
bool  removeZ,
bool  forceFloat 
)
inline
50 {
51 _forceFloat = forceFloat;
52 _srcCount = vertices.Length;
53 _srcElements = 3;
54 _handle = GCHandle.Alloc(vertices, GCHandleType.Pinned);
55 _pData = (float*) _handle.AddrOfPinnedObject();
56 Evaluate(removeZ);
57 }
int _srcElements
Definition: VertexCodec.cs:17
int _srcCount
Definition: VertexCodec.cs:17

◆ VertexCodec() [2/6]

BrawlLib.Wii.Models.VertexCodec.VertexCodec ( Vector3[]  vertices,
bool  removeZ 
)
inline
60 {
61 _srcCount = vertices.Length;
62 _srcElements = 3;
63 _handle = GCHandle.Alloc(vertices, GCHandleType.Pinned);
64 _pData = (float*) _handle.AddrOfPinnedObject();
65 Evaluate(removeZ);
66 }

◆ VertexCodec() [3/6]

BrawlLib.Wii.Models.VertexCodec.VertexCodec ( Vector2[]  vertices,
bool  forceFloat 
)
inline
69 {
70 _forceFloat = forceFloat;
71 _srcCount = vertices.Length;
72 _srcElements = 2;
73 _handle = GCHandle.Alloc(vertices, GCHandleType.Pinned);
74 _pData = (float*) _handle.AddrOfPinnedObject();
75 Evaluate(false);
76 }

◆ VertexCodec() [4/6]

BrawlLib.Wii.Models.VertexCodec.VertexCodec ( Vector2[]  vertices)
inline
79 {
80 _srcCount = vertices.Length;
81 _srcElements = 2;
82 _handle = GCHandle.Alloc(vertices, GCHandleType.Pinned);
83 _pData = (float*) _handle.AddrOfPinnedObject();
84 Evaluate(false);
85 }

◆ VertexCodec() [5/6]

BrawlLib.Wii.Models.VertexCodec.VertexCodec ( Vector3 sPtr,
int  count,
bool  removeZ 
)
inline
88 {
89 _srcCount = count;
90 _srcElements = 3;
91 _pData = (float*) sPtr;
92 Evaluate(removeZ);
93 }

◆ VertexCodec() [6/6]

BrawlLib.Wii.Models.VertexCodec.VertexCodec ( Vector2 sPtr,
int  count 
)
inline
96 {
97 _srcCount = count;
98 _srcElements = 2;
99 _pData = (float*) sPtr;
100 Evaluate(false);
101 }

Member Function Documentation

◆ Decode() [1/4]

static UnsafeBuffer BrawlLib.Wii.Models.VertexCodec.Decode ( MDL0NormalData header)
inlinestatic
536 {
537 int count = header->_numVertices;
538 float scale = VQuant.DeQuantTable[header->_divisor]; //Should always be zero?
539 int type = (int) ElementCodec.CodecType.XYZ + header->_type;
540 ElementDecoder decoder = ElementCodec.Decoders[type];
541 UnsafeBuffer buffer;
542
543 if (header->_isNBT != 0)
544 {
545 count *= 3; //Format is the same, just with three Vectors each
546 }
547
548 buffer = new UnsafeBuffer(count * 12);
549
550 byte* pIn = (byte*) header->Data, pOut = (byte*) buffer.Address;
551 for (int i = 0; i < count; i++)
552 {
553 decoder(ref pIn, ref pOut, scale);
554 }
555
556 return buffer;
557 }
Definition: UnsafeBuffer.cs:7
Definition: VQuant.cs:4
static float[] DeQuantTable
Definition: VQuant.cs:5
unsafe delegate void ElementDecoder(ref byte *pIn, ref byte *pOut, float scale)
byte _divisor
Definition: MDL0.cs:773
bint _type
Definition: MDL0.cs:772
bushort _numVertices
Definition: MDL0.cs:775
bint _isNBT
Definition: MDL0.cs:771
VoidPtr Data
Definition: MDL0.cs:788

◆ Decode() [2/4]

static UnsafeBuffer BrawlLib.Wii.Models.VertexCodec.Decode ( MDL0UVData header)
inlinestatic
474 {
475 int count = header->_numEntries;
476 float scale = VQuant.DeQuantTable[header->_divisor];
477 int type = (header->_isST == 0 ? (int) ElementCodec.CodecType.S : (int) ElementCodec.CodecType.ST) +
478 header->_format;
479 ElementDecoder decoder = ElementCodec.Decoders[type];
480 UnsafeBuffer buffer = new UnsafeBuffer(count * 8);
481
482 byte* pIn = (byte*) header->Entries, pOut = (byte*) buffer.Address;
483 for (int i = 0; i < count; i++)
484 {
485 decoder(ref pIn, ref pOut, scale);
486 }
487
488 return buffer;
489 }
bint _format
Definition: MDL0.cs:848
byte _divisor
Definition: MDL0.cs:849
bushort _numEntries
Definition: MDL0.cs:851
bint _isST
Definition: MDL0.cs:847
BVec2 * Entries
Definition: MDL0.cs:867

◆ Decode() [3/4]

static UnsafeBuffer BrawlLib.Wii.Models.VertexCodec.Decode ( MDL0VertexData header)
inlinestatic
518 {
519 int count = header->_numVertices;
520 float scale = VQuant.DeQuantTable[header->_divisor];
521 int type = (header->_isXYZ == 0 ? (int) ElementCodec.CodecType.XY : (int) ElementCodec.CodecType.XYZ) +
522 header->_type;
523 ElementDecoder decoder = ElementCodec.Decoders[type];
524 UnsafeBuffer buffer = new UnsafeBuffer(count * 12);
525
526 byte* pIn = (byte*) header->Data, pOut = (byte*) buffer.Address;
527 for (int i = 0; i < count; i++)
528 {
529 decoder(ref pIn, ref pOut, scale);
530 }
531
532 return buffer;
533 }
byte _divisor
Definition: MDL0.cs:727
VoidPtr Data
Definition: MDL0.cs:746
bint _isXYZ
Definition: MDL0.cs:725
bint _type
Definition: MDL0.cs:726
bushort _numVertices
Definition: MDL0.cs:729

◆ Decode() [4/4]

static UnsafeBuffer BrawlLib.Wii.Models.VertexCodec.Decode ( VoidPtr  data,
byte  divisor,
uint  length,
WiiVertexComponentType  componentType,
bool  UVs,
int  isSpecial 
)
inlinestatic
493 {
494 float scale = VQuant.DeQuantTable[divisor];
495 int type = isSpecial * 5 + (UVs ? 0 : 10) + (int) componentType;
496 ElementDecoder decoder = ElementCodec.Decoders[type];
497
498 int bytesPerVal = (UVs ? isSpecial + 1 : isSpecial + 2) * (componentType < WiiVertexComponentType.UInt16
499 ? 1
500 : componentType < WiiVertexComponentType.Float
501 ? 2
502 : 4);
503
504 int count = (int) (length / bytesPerVal);
505
506 UnsafeBuffer buffer = new UnsafeBuffer(count * (UVs ? 8 : 12));
507
508 byte* pIn = (byte*) data, pOut = (byte*) buffer.Address;
509 for (int i = 0; i < count; i++)
510 {
511 decoder(ref pIn, ref pOut, scale);
512 }
513
514 return buffer;
515 }
VoidPtr Address
Definition: UnsafeBuffer.cs:9
WiiVertexComponentType
Definition: Enum.cs:4

◆ Dispose()

void BrawlLib.Wii.Models.VertexCodec.Dispose ( )
inline
38 {
39 if (_handle.IsAllocated)
40 {
41 _handle.Free();
42 }
43
44 _pData = null;
45 }

◆ ExtractNormals()

static Vector3[] BrawlLib.Wii.Models.VertexCodec.ExtractNormals ( MDL0NormalData normals)
inlinestatic
586 {
587 return ExtractVertices(normals->Data, normals->_numVertices, true, normals->Type, 1 << normals->_divisor);
588 }
static Vector3[] ExtractVertices(MDL0VertexData *vertices)
Definition: VertexCodec.cs:563
WiiVertexComponentType Type
Definition: MDL0.cs:790

◆ ExtractUVs()

static Vector2[] BrawlLib.Wii.Models.VertexCodec.ExtractUVs ( MDL0UVData uvs)
inlinestatic
591 {
592 return ExtractPoints(uvs->Entries, uvs->_numEntries, uvs->Type, 1 << uvs->_divisor);
593 }
WiiVertexComponentType Type
Definition: MDL0.cs:869

◆ ExtractVertices() [1/2]

static Vector3[] BrawlLib.Wii.Models.VertexCodec.ExtractVertices ( MDL0FurPosData vertices)
inlinestatic
575 {
576 if (vertices != null)
577 {
578 return ExtractVertices(vertices->Data, vertices->_numVertices, vertices->_isXYZ != 0, vertices->Type,
579 1 << vertices->_divisor);
580 }
581
582 return null;
583 }
WiiVertexComponentType Type
Definition: MDL0.cs:946
VoidPtr Data
Definition: MDL0.cs:944
bshort _numVertices
Definition: MDL0.cs:927
byte _divisor
Definition: MDL0.cs:925
bint _isXYZ
Definition: MDL0.cs:923

◆ ExtractVertices() [2/2]

static Vector3[] BrawlLib.Wii.Models.VertexCodec.ExtractVertices ( MDL0VertexData vertices)
inlinestatic
564 {
565 if (vertices != null)
566 {
567 return ExtractVertices(vertices->Data, vertices->_numVertices, vertices->_isXYZ != 0, vertices->Type,
568 1 << vertices->_divisor);
569 }
570
571 return null;
572 }
WiiVertexComponentType Type
Definition: MDL0.cs:752

◆ GetEncoder()

void BrawlLib.Wii.Models.VertexCodec.GetEncoder ( )
inline
352 {
353 switch (_type)
354 {
355 case WiiVertexComponentType.Int8:
356 case WiiVertexComponentType.UInt8:
357 _enc = _byteEncoder;
358 break;
359 case WiiVertexComponentType.Int16:
360 case WiiVertexComponentType.UInt16:
361 _enc = _shortEncoder;
362 break;
363 default:
364 _enc = _floatEncoder;
365 break;
366 }
367 }
WiiVertexComponentType _type
Definition: VertexCodec.cs:15

◆ Write() [1/5]

void BrawlLib.Wii.Models.VertexCodec.Write ( byte *  pOut)
inline
370 {
371 try
372 {
373 int[] imp = _remap._impTable;
374
375 //Copy elements using encoder
376 float* pTemp = _pData;
377 for (int i = 0; i < _dstCount; i++)
378 {
379 if (imp != null)
380 {
381 pTemp = &_pData[imp[i] * _srcElements];
382 }
383
384 for (int x = 0; x < _srcElements; x++, pTemp++)
385 {
386 if (x < _dstElements)
387 {
388 _enc(*pTemp * _quantScale, ref pOut);
389 }
390 }
391 }
392
393 //Zero remaining
394 for (int i = _dataLen; (i & 0x1F) != 0; i++)
395 {
396 *pOut++ = 0;
397 }
398 }
399 finally
400 {
401 Dispose();
402 }
403 }
void Dispose()
Definition: VertexCodec.cs:37
int _dstElements
Definition: VertexCodec.cs:18
int _dstCount
Definition: VertexCodec.cs:18
int _dataLen
Definition: VertexCodec.cs:21

◆ Write() [2/5]

void BrawlLib.Wii.Models.VertexCodec.Write ( float *  pIn,
byte *  pOut 
)
inline
442 {
443 int[] imp = _remap._impTable;
444 byte* pCeil = pOut + _dataLen.Align(0x20);
445
446 //Copy elements using encoder
447 float* pTemp = pIn;
448 for (int i = 0; i < _dstCount; i++)
449 {
450 if (imp != null)
451 {
452 pTemp = &pIn[imp[i] * _srcElements];
453 }
454
455 for (int x = 0; x < _srcElements; x++, pTemp++)
456 {
457 if (x < _dstElements)
458 {
459 _enc(*pTemp * _quantScale, ref pOut);
460 }
461 }
462 }
463
464 //Zero remaining
465 while (pOut < pCeil)
466 {
467 *pOut++ = 0;
468 }
469 }

◆ Write() [3/5]

void BrawlLib.Wii.Models.VertexCodec.Write ( ref byte *  pOut,
int  index 
)
inline
406 {
407 int[] imp = _remap._impTable;
408
409 //Copy element using encoder
410 float* pTemp = _pData;
411 if (imp != null)
412 {
413 pTemp = &_pData[imp[index] * _srcElements];
414 }
415
416 for (int x = 0; x < _srcElements; x++, pTemp++)
417 {
418 if (x < _dstElements)
419 {
420 _enc(*pTemp * _quantScale, ref pOut);
421 }
422 }
423 }

◆ Write() [4/5]

void BrawlLib.Wii.Models.VertexCodec.Write ( Vector2[]  vertices,
byte *  pOut 
)
inline
426 {
427 fixed (Vector2* p = vertices)
428 {
429 Write((float*) p, pOut);
430 }
431 }
void Write(byte *pOut)
Definition: VertexCodec.cs:369
Definition: Vector2.cs:10

◆ Write() [5/5]

void BrawlLib.Wii.Models.VertexCodec.Write ( Vector3[]  vertices,
byte *  pOut 
)
inline
434 {
435 fixed (Vector3* p = vertices)
436 {
437 Write((float*) p, pOut);
438 }
439 }
Definition: Vector3.cs:40

Member Data Documentation

◆ _dataLen

int BrawlLib.Wii.Models.VertexCodec._dataLen

◆ _dstCount

int BrawlLib.Wii.Models.VertexCodec._dstCount

◆ _dstElements

int BrawlLib.Wii.Models.VertexCodec._dstElements

◆ _dstStride

int BrawlLib.Wii.Models.VertexCodec._dstStride

◆ _hasZ

bool BrawlLib.Wii.Models.VertexCodec._hasZ

◆ _max

Vector3 BrawlLib.Wii.Models.VertexCodec._max

◆ _min

Vector3 BrawlLib.Wii.Models.VertexCodec._min

◆ _scale

int BrawlLib.Wii.Models.VertexCodec._scale

◆ _srcCount

int BrawlLib.Wii.Models.VertexCodec._srcCount

◆ _srcElements

int BrawlLib.Wii.Models.VertexCodec._srcElements

◆ _type

WiiVertexComponentType BrawlLib.Wii.Models.VertexCodec._type

◆ Address

Vector2* BrawlLib.Wii.Models.VertexCodec.Address

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