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

Public Member Functions

void SetAssetChanged (int index)
 
PrimitiveManager HardCopy ()
 Returns an identical copy of this manager but as a completely new instance with reallocated buffers. More...
 
Vector3[] GetVertices (bool force)
 Returns vertex positions from each vertex. More...
 
Vector3[] GetNormals (bool force)
 Retrieves normals from raw facedata in a remapped array. More...
 
Vector2[] GetUVs (int index, bool force)
 Retrieves texture coordinates from raw facedata in a remapped array. More...
 
RGBAPixel[] GetColors (int index, bool force)
 Retrieves color values from raw facedata in a remapped array. More...
 
 PrimitiveManager ()
 
 PrimitiveManager (MDL0Object *polygon, AssetStorage assets, IMatrixNode[] nodes, IObject owner)
 
void Dispose ()
 
int GetDisplayListSize ()
 
void GroupPrimitives (bool useStrips, uint cacheSize, uint minStripLen, bool pushCacheHits, bool forceCCW, out int newPointCount, out int newFaceCount)
 Currently should only should be called when importing a model with the collada importer or when internal asset data has changed and needs to be distributed to external arrays More...
 
void SetVertexDescList (short[] indices, List< VertexCodec > vertexCodecs, List< ColorCodec > colorCodecs, params bool[] forceDirect)
 
void WriteVertexDescriptor (out CPVertexFormat vertexFormat, out XFVertexSpecs vertexSpecs)
 This sets up how to read the facepoints that are going to be written. More...
 
void SetFormatList (MDL0ObjectNode polygon, ModelLinker linker)
 
void WriteVertexFormat (MDL0Object *polygon)
 
uint ShiftVtxLo (uint pmidx, uint t76543210midx, uint pos, uint nrm, uint col0, uint col1)
 
uint ShiftVtxHi (uint tex0, uint tex1, uint tex2, uint tex3, uint tex4, uint tex5, uint tex6, uint tex7)
 
uint ShiftXFSpecs (uint host_colors, uint host_normal, uint host_textures)
 
uint ShiftUVATA (uint posCnt, uint posFmt, uint posShft, uint nrmCnt, uint nrmFmt, uint Col0Cnt, uint Col0Fmt, uint Col1Cnt, uint Col1Fmt, uint tex0Cnt, uint tex0Fmt, uint tex0Shft, uint normalIndex3)
 
uint ShiftUVATB (uint tex1Cnt, uint tex1Fmt, uint tex1Shft, uint tex2Cnt, uint tex2Fmt, uint tex2Shft, uint tex3Cnt, uint tex3Fmt, uint tex3Shft, uint tex4Cnt, uint tex4Fmt)
 
uint ShiftUVATC (uint tex4Shft, uint tex5Cnt, uint tex5Fmt, uint tex5Shft, uint tex6Cnt, uint tex6Fmt, uint tex6Shft, uint tex7Cnt, uint tex7Fmt, uint tex7Shft)
 
void Unweight (bool updateAssets)
 
void Weight ()
 
void PrepareStream ()
 
void BindStream ()
 
void DisableTextures ()
 
void ApplyTexture (TexSourceRow source)
 
void RenderMesh ()
 
void PositionsChanged (MDL0ObjectNode obj, bool forceNewNode=false)
 
void NormalsChanged (MDL0ObjectNode obj, bool forceNewNode=false)
 
void ColorsChanged (MDL0ObjectNode obj, int id, bool forceNewNode=false)
 
void UVsChanged (MDL0ObjectNode obj, int id, bool forceNewNode=false)
 

Public Attributes

List< Vertex3_vertices
 
UnsafeBuffer _indices
 
int _pointCount
 
int _faceCount
 
int _renderStride
 
UnsafeBuffer[] _faceData = new UnsafeBuffer[12]
 
bool[] _dirty = new bool[12]
 
UnsafeBuffer _graphicsBuffer
 
bool[] HasTextureMatrix = new bool[8]
 
bool[] UseIdentityTexMtx = new bool[8]
 
bool _remakePrimitives
 
bool _isWeighted
 
int _primitiveSize
 
List< FacepointAttribute_descList
 
List< VertexAttributeFormat_fmtList
 
XFArrayFlags _arrayFlags
 
int _fpStride
 
List< PrimitiveGroup_primGroups = new List<PrimitiveGroup>()
 
int _arrayHandle
 
int _arrayBufferHandle
 
int _elementArrayBufferHandle
 
bool _render = true
 
bool _renderNormals = true
 

Static Public Attributes

static Color DefaultVertColor = Color.FromArgb(0, 128, 0)
 
static Color DefaultNormColor = Color.FromArgb(0, 0, 128)
 
static float NormalLength = 0.5f
 
const float _nodeRadius = 0.05f
 

Properties

bool AssetsChanged [get, set]
 
bool HasTexMtx [get]
 

Constructor & Destructor Documentation

◆ PrimitiveManager() [1/2]

BrawlLib.Modeling.PrimitiveManager.PrimitiveManager ( )
inline
298 {
299 }

◆ PrimitiveManager() [2/2]

BrawlLib.Modeling.PrimitiveManager.PrimitiveManager ( MDL0Object polygon,
AssetStorage  assets,
IMatrixNode[]  nodes,
IObject  owner 
)
inline
366 {
367 _owner = owner;
368
369 byte*[] pAssetList = new byte*[12];
370 byte*[] pFaceBuffers = new byte*[12];
371 int id;
372
373 //This relies on the header being accurate!
374 _indices = new UnsafeBuffer(2 * (_pointCount = polygon->_numVertices));
375 _faceCount = polygon->_numFaces;
376
377 _arrayFlags = polygon->_arrayFlags;
378 for (int i = 0; i < 8; i++)
379 {
381 }
382
383 //Compile decode script by reading the polygon def list
384 //This sets how to read the facepoints
386 desc.SetupMDL0(polygon);
387
388 //Grab asset lists in sequential order.
389 if ((id = polygon->_vertexId) >= 0 && desc.HasData[0] && assets.Assets[0] != null)
390 {
391 pFaceBuffers[0] = (byte*) (_faceData[0] = new UnsafeBuffer(12 * _pointCount)).Address;
392 pAssetList[0] = (byte*) assets.Assets[0][id].Address;
393 }
394
395 if ((id = polygon->_normalId) >= 0 && desc.HasData[1] && assets.Assets[1] != null)
396 {
397 pFaceBuffers[1] = (byte*) (_faceData[1] = new UnsafeBuffer(12 * _pointCount)).Address;
398 pAssetList[1] = (byte*) assets.Assets[1][id].Address;
399 }
400
401 for (int i = 0, x = 2; i < 2; i++, x++)
402 {
403 if ((id = ((bshort*) polygon->_colorIds)[i]) >= 0 && desc.HasData[x] && assets.Assets[2] != null)
404 {
405 pFaceBuffers[x] = (byte*) (_faceData[x] = new UnsafeBuffer(4 * _pointCount)).Address;
406 pAssetList[x] = (byte*) assets.Assets[2][id].Address;
407 }
408 }
409
410 for (int i = 0, x = 4; i < 8; i++, x++)
411 {
412 if ((id = ((bshort*) polygon->_uids)[i]) >= 0 && desc.HasData[x] && assets.Assets[3] != null)
413 {
414 pFaceBuffers[x] = (byte*) (_faceData[x] = new UnsafeBuffer(8 * _pointCount)).Address;
415 pAssetList[x] = (byte*) assets.Assets[3][id].Address;
416 }
417 }
418
419 int triCount = 0, lineCount = 0, pointCount = 0;
420 byte* pData = (byte*) polygon->PrimitiveData;
421
422 fixed (byte** pOut = pFaceBuffers)
423 {
424 fixed (byte** pAssets = pAssetList)
425 {
426 _primGroups = ReadPrimitives(pData, ref desc, pOut, pAssets, nodes, ref triCount, ref lineCount,
427 ref pointCount);
428 }
429 }
430
431 CreateGLPrimitives(triCount, lineCount, pointCount);
432
433 uint p3 = 0, p2 = 0, p1 = 0;
434 ExtractIndices(pData, desc.Stride, ref p3, ref p2, ref p1);
435
436 //Compile merged vertex list
437 _vertices = desc.Finish((Vector3*) pAssetList[0], nodes);
438
439 ushort* pIndex = (ushort*) _indices.Address;
440 for (int x = 0; x < _pointCount; x++, pIndex++)
441 {
442 if (*pIndex >= 0 && *pIndex < _vertices.Count)
443 {
444 _vertices[*pIndex].FaceDataIndices.Add(x);
445 }
446 }
447
448 foreach (Vertex3 v in _vertices)
449 {
450 v.Parent = _owner as IMatrixNodeUser;
451 }
452 }
Definition: UnsafeBuffer.cs:7
VoidPtr Address
Definition: UnsafeBuffer.cs:9
UnsafeBuffer _indices
Definition: PrimitiveManager.cs:49
XFArrayFlags _arrayFlags
Definition: PrimitiveManager.cs:105
List< PrimitiveGroup > _primGroups
Definition: PrimitiveManager.cs:107
int _pointCount
Definition: PrimitiveManager.cs:51
bool[] HasTextureMatrix
Definition: PrimitiveManager.cs:96
List< Vertex3 > _vertices
Definition: PrimitiveManager.cs:48
int _faceCount
Definition: PrimitiveManager.cs:51
UnsafeBuffer[] _faceData
Definition: PrimitiveManager.cs:59
UnsafeBuffer[][] Assets
Definition: AssetStorage.cs:9
Definition: ElementCodec.cs:274
bool[] HasData
Definition: ElementCodec.cs:277
void SetupMDL0(MDL0Object *polygon)
Definition: ElementCodec.cs:378
int Stride
Definition: ElementCodec.cs:275
Definition: MDL0ObjectNode.cs:2304
Definition: Vector3.cs:40
Definition: BigEndianTypes.cs:148
bshort _vertexId
Definition: MDL0.cs:1890
fixed short _colorIds[2]
Definition: MDL0.cs:1892
bint _numVertices
Definition: MDL0.cs:1887
bshort _normalId
Definition: MDL0.cs:1891
fixed short _uids[8]
Definition: MDL0.cs:1893
XFArrayFlags _arrayFlags
Definition: MDL0.cs:1881
bint _numFaces
Definition: MDL0.cs:1888
VoidPtr PrimitiveData
Definition: MDL0.cs:1937
bool GetHasTexMatrix(int index)
Definition: XF.cs:387

Member Function Documentation

◆ ApplyTexture()

void BrawlLib.Modeling.PrimitiveManager.ApplyTexture ( TexSourceRow  source)
inline
2153 {
2154 int texId = source >= TexSourceRow.TexCoord0 ? source - TexSourceRow.TexCoord0 : -1 - (int) source;
2155 texId = texId < 0 ? 0 : texId;
2156
2157 if (texId >= 0 && _faceData[texId + 4] != null)
2158 {
2159 byte* pData = (byte*) _graphicsBuffer.Address;
2160 for (int i = 0; i < texId + 4; i++)
2161 {
2162 if (_faceData[i] != null)
2163 {
2164 if (i < 2)
2165 {
2166 pData += 12;
2167 }
2168 else if (i < 4)
2169 {
2170 pData += 4;
2171 }
2172 else
2173 {
2174 pData += 8;
2175 }
2176 }
2177 }
2178
2179 GL.EnableClientState(ArrayCap.TextureCoordArray);
2180 GL.TexCoordPointer(2, TexCoordPointerType.Float, _renderStride, (IntPtr) pData);
2181 }
2182 }
int _renderStride
Definition: PrimitiveManager.cs:51
UnsafeBuffer _graphicsBuffer
Definition: PrimitiveManager.cs:76

◆ BindStream()

void BrawlLib.Modeling.PrimitiveManager.BindStream ( )
inline
2093 {
2094 byte* pData = (byte*) _graphicsBuffer.Address;
2095 for (int i = 0; i < 12; i++)
2096 {
2097 if (_faceData[i] != null)
2098 {
2099 switch (i)
2100 {
2101 case 0:
2102 GL.EnableClientState(ArrayCap.VertexArray);
2103 GL.VertexPointer(3, VertexPointerType.Float, _renderStride, (IntPtr) pData);
2104 pData += 12;
2105 break;
2106 case 1:
2107 GL.EnableClientState(ArrayCap.NormalArray);
2108 GL.NormalPointer(NormalPointerType.Float, _renderStride, (IntPtr) pData);
2109 pData += 12;
2110 break;
2111 case 2:
2112 GL.EnableClientState(ArrayCap.ColorArray);
2113 GL.ColorPointer(4, ColorPointerType.UnsignedByte, _renderStride, (IntPtr) pData);
2114 pData += 4;
2115 break;
2116 case 3:
2117 GL.EnableClientState(ArrayCap.SecondaryColorArray);
2118 GL.SecondaryColorPointer(4, ColorPointerType.UnsignedByte, _renderStride, (IntPtr) pData);
2119 pData += 4;
2120 break;
2121 default:
2122 pData += 8;
2123 break;
2124 }
2125 }
2126 }
2127 }

◆ ColorsChanged()

void BrawlLib.Modeling.PrimitiveManager.ColorsChanged ( MDL0ObjectNode  obj,
int  id,
bool  forceNewNode = false 
)
inline
2427 {
2428 id = id.Clamp(0, 1);
2429
2430 if (obj == null || _faceData[id + 2] == null)
2431 {
2432 return;
2433 }
2434
2435 SetAssetChanged(id + 2);
2436 obj._forceRebuild = true;
2438
2439 MDL0ColorNode node;
2440 if (obj._colorSet[id] != null)
2441 {
2442 if (obj._colorSet[id]._objects.Count == 1 && !forceNewNode)
2443 {
2444 node = obj._colorSet[id];
2445 }
2446 else
2447 {
2448 node = new MDL0ColorNode();
2449 obj.Model.ColorGroup.AddChild(node);
2450 node.Name = node.FindName("Regenerated");
2451 if (obj._colorSet[id]._objects.Contains(obj))
2452 {
2453 obj._colorSet[id]._objects.Remove(obj);
2454 }
2455
2456 obj._colorSet[id] = node;
2457 obj._colorSet[id]._objects.Add(obj);
2458 obj._elementIndices[id + 2] = (short) obj._colorSet[id].Index;
2459 }
2460 }
2461 else
2462 {
2463 node = new MDL0ColorNode();
2464 MDL0Node m = obj.Model;
2465 if (m.ColorGroup == null)
2466 {
2468 m.LinkGroup(g);
2469 g.Parent = m;
2470 }
2471
2472 m.ColorGroup.AddChild(node);
2473 node.Name = node.FindName("Regenerated");
2474 obj._colorSet[id] = node;
2475 obj._colorSet[id]._objects.Add(obj);
2476 obj._elementIndices[id + 2] = (short) obj._colorSet[id].Index;
2477 }
2478
2479 node.Colors = GetColors(id, true);
2480 RGBAPixel* pData = (RGBAPixel*) _faceData[id + 2].Address;
2481 foreach (Vertex3 v in _vertices)
2482 {
2483 for (int i = 0; i < v.FaceDataIndices.Count; i++)
2484 {
2485 v.Facepoints[i]._colorIndices[id] = Array.IndexOf(node.Colors, pData[v.FaceDataIndices[i]]);
2486 }
2487 }
2488 }
void SetAssetChanged(int index)
Definition: PrimitiveManager.cs:63
RGBAPixel[] GetColors(int index, bool force)
Retrieves color values from raw facedata in a remapped array.
Definition: PrimitiveManager.cs:266
Definition: MDL0ColorNode.cs:12
RGBAPixel[] Colors
Definition: MDL0ColorNode.cs:30
List< MDL0ObjectNode > _objects
Definition: MDL0ColorNode.cs:17
MDL0Node Model
Definition: MDL0GroupNode.cs:28
Definition: MDL0GroupNode.cs:79
Definition: MDL0Node.cs:24
ResourceNode ColorGroup
Definition: MDL0Node.cs:324
void LinkGroup(MDL0GroupNode group)
Definition: MDL0Node.cs:2088
MDL0ColorNode[] _colorSet
Definition: MDL0ObjectNode.cs:330
override void SignalPropertyChange()
Definition: MDL0ObjectNode.cs:1707
unsafe string FindName(string name)
Definition: ResourceNode.cs:1578
int Index
Definition: ResourceNode.cs:301
virtual void AddChild(ResourceNode child)
Definition: ResourceNode.cs:757
MDLResourceType
Definition: ModelLinker.cs:15
Definition: PixelTypes.cs:327

◆ DisableTextures()

void BrawlLib.Modeling.PrimitiveManager.DisableTextures ( )
inline
2147 {
2148 GL.DisableClientState(ArrayCap.TextureCoordArray);
2149 GL.Disable(EnableCap.Texture2D);
2150 }

◆ Dispose()

void BrawlLib.Modeling.PrimitiveManager.Dispose ( )
inline
460 {
461 if (_graphicsBuffer != null)
462 {
464 _graphicsBuffer = null;
465 }
466
467 if (_faceData != null)
468 {
469 for (int i = 0; i < _faceData.Length; i++)
470 {
471 if (_faceData[i] != null)
472 {
473 _faceData[i].Dispose();
474 _faceData[i] = null;
475 }
476 }
477
478 _faceData = null;
479 }
480
481 if (_indices != null)
482 {
484 _indices = null;
485 }
486 }
int Length
Definition: UnsafeBuffer.cs:14
void Dispose()
Definition: UnsafeBuffer.cs:32

◆ GetColors()

RGBAPixel[] BrawlLib.Modeling.PrimitiveManager.GetColors ( int  index,
bool  force 
)
inline

Retrieves color values from raw facedata in a remapped array.

Parameters
indexThe color set to retrieve. Values 0 - 1
forceIf not forced, will return values created by a previous call (if there was one).
Returns
267 {
268 index = index.Clamp(0, 1);
269
270 if (_colors[index] != null && _colors[index].Length != 0 && !force)
271 {
272 return _colors[index];
273 }
274
275 HashSet<RGBAPixel> list = new HashSet<RGBAPixel>();
276 if (_faceData[index + 2] != null)
277 {
278 RGBAPixel* pIn = (RGBAPixel*) _faceData[index + 2].Address;
279 for (int i = 0; i < _pointCount; i++)
280 {
281 list.Add(*pIn++);
282 }
283 }
284
285 _colors[index] = new RGBAPixel[list.Count];
286 list.CopyTo(_colors[index]);
287
288 return _colors[index];
289 }

◆ GetDisplayListSize()

int BrawlLib.Modeling.PrimitiveManager.GetDisplayListSize ( )
inline
774 {
775 _primitiveSize = 0;
776
777 foreach (PrimitiveGroup g in _primGroups)
778 {
780 {
781 if (g._tristrips.Count != 0)
782 {
783 foreach (PointTriangleStrip strip in g._tristrips)
784 {
785 _primitiveSize += 3 + strip._points.Count * _fpStride;
786 }
787 }
788
789 if (g._triangles.Count != 0)
790 {
791 _primitiveSize += 3 + g._triangles.Count * 3 * _fpStride;
792 }
793
794 if (g._linestrips.Count != 0)
795 {
796 foreach (PointLineStrip strip in g._linestrips)
797 {
798 _primitiveSize += 3 + strip._points.Count * _fpStride;
799 }
800 }
801
802 if (g._lines.Count != 0)
803 {
804 _primitiveSize += 3 + g._lines.Count * 2 * _fpStride;
805 }
806 }
807 else
808 {
809 g.RegroupNodes();
810 for (int i = 0; i < g._headers.Count; i++)
811 {
812 _primitiveSize += 3 + g._facePoints[i].Count * _fpStride;
813 }
814 }
815
816 if (g._nodes.Count == 1 && g._nodes[0] == 0xFFFF)
817 {
818 _isWeighted = false;
819 }
820
821 if (_isWeighted)
822 {
823 _primitiveSize += 5 * g._nodes.Count * (HasTexMtx ? 3 : 2); //Add total matrices size
824 }
825 }
826
827 return _primitiveSize;
828 }
bool HasTexMtx
Definition: PrimitiveManager.cs:81
bool _remakePrimitives
Definition: PrimitiveManager.cs:100
int _primitiveSize
Definition: PrimitiveManager.cs:102
bool _isWeighted
Definition: PrimitiveManager.cs:101
int _fpStride
Definition: PrimitiveManager.cs:106

◆ GetNormals()

Vector3[] BrawlLib.Modeling.PrimitiveManager.GetNormals ( bool  force)
inline

Retrieves normals from raw facedata in a remapped array.

Parameters
forceIf not forced, will return values created by a previous call (if there was one).
Returns
203 {
204 if (_rawNormals != null && _rawNormals.Length != 0 && !force)
205 {
206 return _rawNormals;
207 }
208
209 HashSet<Vector3> list = new HashSet<Vector3>();
210 if (_faceData[1] != null)
211 {
212 Vector3* pIn = (Vector3*) _faceData[1].Address;
213 for (int i = 0; i < _pointCount; i++)
214 {
215 list.Add(*pIn++);
216 }
217 }
218
219 _rawNormals = new Vector3[list.Count];
220 list.CopyTo(_rawNormals);
221
222 return _rawNormals;
223 }

◆ GetUVs()

Vector2[] BrawlLib.Modeling.PrimitiveManager.GetUVs ( int  index,
bool  force 
)
inline

Retrieves texture coordinates from raw facedata in a remapped array.

Parameters
indexThe UV set to retrieve. Values 0 - 7
forceIf not forced, will return values created by a previous call (if there was one).
Returns
234 {
235 index = index.Clamp(0, 7);
236
237 if (_uvs[index] != null && _uvs[index].Length != 0 && !force)
238 {
239 return _uvs[index];
240 }
241
242 HashSet<Vector2> list = new HashSet<Vector2>();
243 if (_faceData[index + 4] != null)
244 {
245 Vector2* pIn = (Vector2*) _faceData[index + 4].Address;
246 for (int i = 0; i < _pointCount; i++)
247 {
248 list.Add(*pIn++);
249 }
250 }
251
252 _uvs[index] = new Vector2[list.Count];
253 list.CopyTo(_uvs[index]);
254
255 return _uvs[index];
256 }
Definition: Vector2.cs:10

◆ GetVertices()

Vector3[] BrawlLib.Modeling.PrimitiveManager.GetVertices ( bool  force)
inline

Returns vertex positions from each vertex.

Parameters
forceIf not forced, will return values created by a previous call (if there was one).
Returns
179 {
180 if (_rawVertices != null && _rawVertices.Length != 0 && !force)
181 {
182 return _rawVertices;
183 }
184
185 int i = 0;
186 _rawVertices = new Vector3[_vertices.Count];
187 foreach (Vertex3 v in _vertices)
188 {
189 _rawVertices[i++] = v.Position;
190 }
191
192 return _rawVertices;
193 }

◆ GroupPrimitives()

void BrawlLib.Modeling.PrimitiveManager.GroupPrimitives ( bool  useStrips,
uint  cacheSize,
uint  minStripLen,
bool  pushCacheHits,
bool  forceCCW,
out int  newPointCount,
out int  newFaceCount 
)
inline

Currently should only should be called when importing a model with the collada importer or when internal asset data has changed and needs to be distributed to external arrays

842 {
843 TriangleConverter converter = new TriangleConverter(useStrips, cacheSize, minStripLen, pushCacheHits);
844
845 _primGroups = new List<PrimitiveGroup>();
846 newPointCount = 0;
847 newFaceCount = 0;
848
849 //Merge vertices and assets into facepoints
850 Facepoint[] facepoints = MergeInternalFaceData();
851 if (_triangles != null)
852 {
853 Facepoint[] points = new Facepoint[_triangles._indices.Length];
854 uint[] indices = _triangles._indices;
855
856 //Indices are written in reverse for each triangle,
857 //so they need to be set to a triangle in reverse if not CCW
858 for (int t = 0; t < _triangles._indices.Length; t++)
859 {
860 uint index = indices[t];
861 int pointIndex = forceCCW ? t : t - t % 3 + (2 - t % 3);
862 if (pointIndex < points.Length)
863 {
864 if (index >= facepoints.Length)
865 {
866 points[pointIndex] = new Facepoint();
867 }
868 else
869 {
870 points[pointIndex] = facepoints[index];
871 }
872 }
873 }
874
875 _primGroups.AddRange(converter.GroupPrimitives(points, out newPointCount, out newFaceCount));
876 }
877
878 if (_lines != null)
879 {
880 //TODO: combine into linestrips (not as urgent as tristrips was)
881
882 Facepoint[] points = new Facepoint[_lines._indices.Length];
883 uint[] indices = _lines._indices;
884 for (int t = 0; t < indices.Length; t++)
885 {
886 points[t] = facepoints[indices[t]];
887 }
888
889 List<PrimitiveGroup> groups = new List<PrimitiveGroup>();
890
891 for (int i = 0; i < points.Length; i += 2)
892 {
893 PointLine line = new PointLine(points[i], points[i + 1]);
894
895 bool added = false;
896 foreach (PrimitiveGroup g in groups)
897 {
898 if (added = g.TryAdd(line))
899 {
900 break;
901 }
902 }
903
904 if (!added)
905 {
906 PrimitiveGroup g = new PrimitiveGroup();
907 g.TryAdd(line);
908 groups.Add(g);
909 }
910 }
911
912 _primGroups.AddRange(groups);
913 }
914
915 if (_points != null)
916 {
917 Facepoint[] points = new Facepoint[_points._indices.Length];
918 uint[] indices = _points._indices;
919 for (int t = 0; t < indices.Length; t++)
920 {
921 points[t] = facepoints[indices[t]];
922 }
923
924 List<PrimitiveGroup> groups = new List<PrimitiveGroup>();
925
926 for (int i = 0; i < points.Length; i++)
927 {
928 FPoint p = new FPoint(points[i]);
929
930 bool added = false;
931 foreach (PrimitiveGroup g in groups)
932 {
933 if (added = g.TryAdd(p))
934 {
935 break;
936 }
937 }
938
939 if (!added)
940 {
941 PrimitiveGroup g = new PrimitiveGroup();
942 g.TryAdd(p);
943 groups.Add(g);
944 }
945 }
946
947 _primGroups.AddRange(groups);
948 }
949 }
uint[] _indices
Definition: PrimitiveManager.cs:2558
List< PrimitiveGroup > GroupPrimitives(Facepoint[] points, out int pointCount, out int faceCount)
Definition: TriangleConverter.cs:24

◆ HardCopy()

PrimitiveManager BrawlLib.Modeling.PrimitiveManager.HardCopy ( )
inline

Returns an identical copy of this manager but as a completely new instance with reallocated buffers.

120 {
122 {
127 _faceData = new UnsafeBuffer[12],
128 _triangles = _triangles == null
129 ? null
130 : new GLPrimitive(_triangles._indices.Length, BeginMode.Triangles),
131 _lines = _lines == null ? null : new GLPrimitive(_lines._indices.Length, BeginMode.Lines),
132 _points = _points == null ? null : new GLPrimitive(_points._indices.Length, BeginMode.Points),
133 _dirty = new bool[] {true, true, true, true, true, true, true, true, true, true, true, true},
135 };
136 Memory.Move(p._indices.Address, _indices.Address, (uint) _indices.Length);
137 for (int i = 0; i < 12; i++)
138 {
139 UnsafeBuffer b = _faceData[i];
140 if (b == null)
141 {
142 continue;
143 }
144
145 p._faceData[i] = new UnsafeBuffer(b.Length);
146 Memory.Move(p._faceData[i].Address, b.Address, (uint) b.Length);
147 }
148
149 if (p._triangles != null)
150 {
151 _triangles._indices.CopyTo(p._triangles._indices, 0);
152 }
153
154 if (p._lines != null)
155 {
156 _lines._indices.CopyTo(p._lines._indices, 0);
157 }
158
159 if (p._points != null)
160 {
161 _points._indices.CopyTo(p._points._indices, 0);
162 }
163
164 p.HasTextureMatrix = new bool[8];
165 HasTextureMatrix.CopyTo(p.HasTextureMatrix, 0);
166 return p;
167 }
Definition: Memory.cs:8
static void Move(VoidPtr dst, VoidPtr src, uint size)
Definition: Memory.cs:9
bool[] _dirty
Definition: PrimitiveManager.cs:60
PrimitiveManager()
Definition: PrimitiveManager.cs:297

◆ NormalsChanged()

void BrawlLib.Modeling.PrimitiveManager.NormalsChanged ( MDL0ObjectNode  obj,
bool  forceNewNode = false 
)
inline
2357 {
2358 if (obj == null || obj.Deleting || _faceData[1] == null)
2359 {
2360 return;
2361 }
2362
2363 SetAssetChanged(1);
2364 obj._forceRebuild = true;
2366
2367 MDL0NormalNode node;
2368 if (obj._normalNode != null)
2369 {
2370 if (obj._normalNode._objects.Count == 1 && !forceNewNode)
2371 {
2372 node = obj._normalNode;
2373 }
2374 else
2375 {
2376 node = new MDL0NormalNode();
2377 MDL0Node m = obj.Model;
2378 if (m.NormalGroup == null)
2379 {
2381 m.LinkGroup(g);
2382 g.Parent = m;
2383 }
2384
2385 m.NormalGroup.AddChild(node);
2386 node.Name = node.FindName("Regenerated");
2387 if (obj._normalNode._objects.Contains(obj))
2388 {
2389 obj._normalNode._objects.Remove(obj);
2390 }
2391
2392 obj._normalNode = node;
2393 obj._normalNode._objects.Add(obj);
2394 obj._elementIndices[1] = (short) obj._normalNode.Index;
2395 }
2396 }
2397 else
2398 {
2399 node = new MDL0NormalNode();
2400 MDL0Node m = obj.Model;
2401 if (m.NormalGroup == null)
2402 {
2404 m.LinkGroup(g);
2405 g.Parent = m;
2406 }
2407
2408 m.NormalGroup.AddChild(node);
2409 node.Name = node.FindName("Regenerated");
2410 obj._normalNode = node;
2411 obj._normalNode._objects.Add(obj);
2412 obj._elementIndices[1] = (short) obj._normalNode.Index;
2413 }
2414
2415 node.Normals = GetNormals(true);
2416 Vector3* pData = (Vector3*) _faceData[1].Address;
2417 foreach (Vertex3 v in _vertices)
2418 {
2419 for (int i = 0; i < v.FaceDataIndices.Count; i++)
2420 {
2421 v.Facepoints[i]._normalIndex = Array.IndexOf(node.Normals, pData[v.FaceDataIndices[i]]);
2422 }
2423 }
2424 }
Vector3[] GetNormals(bool force)
Retrieves normals from raw facedata in a remapped array.
Definition: PrimitiveManager.cs:202
ResourceNode NormalGroup
Definition: MDL0Node.cs:322
Definition: MDL0NormalNode.cs:10
List< MDL0ObjectNode > _objects
Definition: MDL0NormalNode.cs:16
Vector3[] Normals
Definition: MDL0NormalNode.cs:61
bool Deleting
Definition: MDL0ObjectNode.cs:1865
MDL0NormalNode _normalNode
Definition: MDL0ObjectNode.cs:217

◆ PositionsChanged()

void BrawlLib.Modeling.PrimitiveManager.PositionsChanged ( MDL0ObjectNode  obj,
bool  forceNewNode = false 
)
inline
2284 {
2285 if (obj == null || obj.Deleting || _vertices == null)
2286 {
2287 return;
2288 }
2289
2290 SetAssetChanged(0);
2291 obj._forceRebuild = true;
2293
2294 MDL0VertexNode node;
2295 if (obj._vertexNode != null)
2296 {
2297 if (obj._vertexNode._objects.Count == 1 && !forceNewNode)
2298 {
2299 node = obj._vertexNode;
2300 }
2301 else
2302 {
2303 node = new MDL0VertexNode();
2304 MDL0Node m = obj.Model;
2305 if (m.VertexGroup == null)
2306 {
2308 m.LinkGroup(g);
2309 g.Parent = m;
2310 }
2311
2312 m.VertexGroup.AddChild(node);
2313 node.Name = node.FindName("Regenerated");
2314 if (obj._vertexNode._objects.Contains(obj))
2315 {
2316 obj._vertexNode._objects.Remove(obj);
2317 }
2318
2319 obj._vertexNode = node;
2320 obj._vertexNode._objects.Add(obj);
2321 obj._elementIndices[0] = (short) obj._vertexNode.Index;
2322 }
2323 }
2324 else
2325 {
2326 node = new MDL0VertexNode();
2327 MDL0Node m = obj.Model;
2328 if (m.VertexGroup == null)
2329 {
2331 m.LinkGroup(g);
2332 g.Parent = m;
2333 }
2334
2335 m.VertexGroup.AddChild(node);
2336 node.Name = node.FindName("Regenerated");
2337 obj._vertexNode = node;
2338 obj._vertexNode._objects.Add(obj);
2339 obj._elementIndices[0] = (short) obj._vertexNode.Index;
2340 }
2341
2342 node.Vertices = GetVertices(true);
2343 int x = 0;
2344 foreach (Vertex3 v in _vertices)
2345 {
2346 foreach (Facepoint f in v.Facepoints)
2347 {
2348 f._vertexIndex = x;
2349 f._vertex = v;
2350 }
2351
2352 x++;
2353 }
2354 }
Vector3[] GetVertices(bool force)
Returns vertex positions from each vertex.
Definition: PrimitiveManager.cs:178
ResourceNode VertexGroup
Definition: MDL0Node.cs:321
MDL0VertexNode _vertexNode
Definition: MDL0ObjectNode.cs:216
Definition: MDL0VertexNode.cs:11
List< MDL0ObjectNode > _objects
Definition: MDL0VertexNode.cs:15

◆ PrepareStream()

void BrawlLib.Modeling.PrimitiveManager.PrepareStream ( )
inline
2061 {
2062 CalcStride();
2063 int bufferSize = _renderStride * _pointCount;
2064
2065 //Dispose of buffer if size doesn't match
2066 if (_graphicsBuffer != null && _graphicsBuffer.Length != bufferSize)
2067 {
2069 _graphicsBuffer = null;
2070 }
2071
2072 //Create data buffer
2073 if (_graphicsBuffer == null)
2074 {
2075 _graphicsBuffer = new UnsafeBuffer(bufferSize);
2076 for (int i = 0; i < 12; i++)
2077 {
2078 _dirty[i] = true;
2079 }
2080 }
2081
2082 //Update streams before binding
2083 for (int i = 0; i < 12; i++)
2084 {
2085 if (_dirty[i])
2086 {
2087 UpdateStream(i);
2088 }
2089 }
2090 }

◆ RenderMesh()

void BrawlLib.Modeling.PrimitiveManager.RenderMesh ( )
inline
2185 {
2186 _triangles?.Render();
2187
2188 _lines?.Render();
2189
2190 _points?.Render();
2191 }
void Render()
Definition: PrimitiveManager.cs:2566

◆ SetAssetChanged()

void BrawlLib.Modeling.PrimitiveManager.SetAssetChanged ( int  index)
inline
64 {
65 //Signal that facepoints need to be reindexed with a new asset array
66 _changed[index] = true;
67
68 //Update render buffer
69 _dirty[index] = true;
70 }

◆ SetFormatList()

void BrawlLib.Modeling.PrimitiveManager.SetFormatList ( MDL0ObjectNode  polygon,
ModelLinker  linker 
)
inline
1455 {
1456 _fmtList = new List<VertexAttributeFormat>();
1457 VertexCodec vert = null;
1458 ColorCodec col = null;
1459
1460 for (int i = 0; i < 12; i++)
1461 {
1462 if (polygon._manager._faceData[i] != null)
1463 {
1464 switch (i)
1465 {
1466 case 0: //Positions
1467 if (linker._vertices != null && linker._vertices.Count != 0 &&
1468 polygon._elementIndices[0] != -1)
1469 {
1470 if ((vert = linker._vertices[polygon._elementIndices[0]]) != null)
1471 {
1473 GXAttribute.Position,
1474 (GXCompType) vert._type,
1475 (GXCompCnt) (vert._hasZ ? 1 : 0),
1476 (byte) vert._scale));
1477 }
1478 }
1479
1480 break;
1481 case 1: //Normals
1482 vert = null;
1483 if (linker._normals != null && linker._normals.Count != 0 &&
1484 polygon._elementIndices[1] != -1)
1485 {
1486 if ((vert = linker._normals[polygon._elementIndices[1]]) != null)
1487 {
1489 GXAttribute.Normal,
1490 (GXCompType) vert._type,
1491 GXCompCnt.NrmXYZ,
1492 (byte) vert._scale));
1493 }
1494 }
1495
1496 break;
1497 case 2: //Color 1
1498 case 3: //Color 2
1499 col = null;
1500 if (linker._colors != null && linker._colors.Count != 0 &&
1501 polygon._elementIndices[i] != -1 &&
1502 (col = linker._colors[polygon._elementIndices[i]]) != null)
1503 {
1505 (GXAttribute) ((int) GXAttribute.Color0 + (i - 2)),
1506 (GXCompType) col._outType,
1507 (GXCompCnt) (col._hasAlpha ? 1 : 0),
1508 0));
1509 }
1510
1511 break;
1512 case 4: //Tex 1
1513 case 5: //Tex 2
1514 case 6: //Tex 3
1515 case 7: //Tex 4
1516 case 8: //Tex 5
1517 case 9: //Tex 6
1518 case 10: //Tex 7
1519 case 11: //Tex 8
1520 vert = null;
1521 if (linker._uvs != null && linker._uvs.Count != 0 && polygon._elementIndices[i] != -1)
1522 {
1523 if ((vert = linker._uvs[polygon._elementIndices[i]]) != null)
1524 {
1526 (GXAttribute) ((int) GXAttribute.Tex0 + (i - 4)),
1527 (GXCompType) vert._type,
1528 GXCompCnt.TexST,
1529 (byte) vert._scale));
1530 }
1531 }
1532
1533 break;
1534 }
1535 }
1536 }
1537 }
List< VertexAttributeFormat > _fmtList
Definition: PrimitiveManager.cs:104
PrimitiveManager _manager
Definition: MDL0ObjectNode.cs:710
Definition: ColorCodec.cs:13
bool _hasAlpha
Definition: ColorCodec.cs:142
WiiColorComponentType _outType
Definition: ColorCodec.cs:141
List< ColorCodec > _colors
Definition: ModelLinker.cs:146
List< VertexCodec > _uvs
Definition: ModelLinker.cs:147
List< VertexCodec > _vertices
Definition: ModelLinker.cs:144
List< VertexCodec > _normals
Definition: ModelLinker.cs:145
Definition: VertexCodec.cs:9
bool _hasZ
Definition: VertexCodec.cs:14
int _scale
Definition: VertexCodec.cs:20
WiiVertexComponentType _type
Definition: VertexCodec.cs:15
GXCompCnt
Definition: CP.cs:375
GXCompType
Definition: CP.cs:388
GXAttribute
Definition: XF.cs:480

◆ SetVertexDescList()

void BrawlLib.Modeling.PrimitiveManager.SetVertexDescList ( short[]  indices,
List< VertexCodec vertexCodecs,
List< ColorCodec colorCodecs,
params bool[]  forceDirect 
)
inline
1223 {
1224 //Everything is set in the order the facepoint is written!
1225
1226 //Create new command list
1227 _descList = new List<FacepointAttribute>();
1228 _fpStride = 0;
1229 XFDataFormat fmt;
1230 _arrayFlags = new XFArrayFlags {_data = 0};
1231
1232 if (_isWeighted)
1233 {
1234 _descList.Add(new FacepointAttribute(GXAttribute.PosNrmMtxId, XFDataFormat.Direct));
1235 _fpStride++;
1236 _arrayFlags.HasPosMatrix = true;
1237
1238 //There are no texture matrices without a position/normal matrix also
1239 for (int i = 0; i < 8; i++)
1240 {
1241 if (HasTextureMatrix[i])
1242 {
1243 _descList.Add(new FacepointAttribute((GXAttribute) (i + 1), XFDataFormat.Direct));
1244 _fpStride++;
1246 }
1247 }
1248 }
1249
1250 if (indices[0] > -1 && _faceData[0] != null) //Positions
1251 {
1252 _arrayFlags.HasPositions = true;
1253 fmt = forceDirect != null && forceDirect.Length > 0 && forceDirect[0]
1254 ? XFDataFormat.Direct
1255 : (XFDataFormat) (GetVertices(false).Length > byte.MaxValue ? 3 : 2);
1256 _descList.Add(new FacepointAttribute(GXAttribute.Position, fmt));
1257
1258 //if (fmt == XFDataFormat.Direct)
1259 //{
1260 // _fpStride += linker._vertices[indices[0]]._dstStride;
1261 //}
1262 //else
1263 _fpStride += (int) fmt - 1;
1264 }
1265
1266 if (indices[1] > -1 && _faceData[1] != null) //Normals
1267 {
1268 _arrayFlags.HasNormals = true;
1269 fmt = forceDirect != null && forceDirect.Length > 1 && forceDirect[1]
1270 ? XFDataFormat.Direct
1271 : (XFDataFormat) (GetNormals(false).Length > byte.MaxValue ? 3 : 2);
1272 _descList.Add(new FacepointAttribute(GXAttribute.Normal, fmt));
1273
1274 //if (fmt == XFDataFormat.Direct)
1275 //{
1276 // _fpStride += linker._normals[indices[1]]._dstStride;
1277 //}
1278 //else
1279 _fpStride += (int) fmt - 1;
1280 }
1281
1282 for (int i = 2; i < 4; i++)
1283 {
1284 if (indices[i] > -1 && _faceData[i] != null) //Colors
1285 {
1286 _arrayFlags.SetHasColor(i - 2, true);
1287
1288 fmt = forceDirect != null && forceDirect.Length > i && forceDirect[i]
1289 ? XFDataFormat.Direct
1290 : (XFDataFormat) (GetColors(i - 2, false).Length > byte.MaxValue ? 3 : 2);
1291
1292 _descList.Add(new FacepointAttribute((GXAttribute) (i + 9), fmt));
1293
1294 //if (fmt == XFDataFormat.Direct)
1295 //{
1296 // _fpStride += linker._colors[indices[i]]._dstStride;
1297 //}
1298 //else
1299 _fpStride += (int) fmt - 1;
1300 }
1301 }
1302
1303 for (int i = 4; i < 12; i++)
1304 {
1305 if (indices[i] > -1 && _faceData[i] != null) //UVs
1306 {
1307 _arrayFlags.SetHasUVs(i - 4, true);
1308 fmt = forceDirect != null && forceDirect.Length > i && forceDirect[i]
1309 ? XFDataFormat.Direct
1310 : (XFDataFormat) (GetUVs(i - 4, false).Length > byte.MaxValue ? 3 : 2);
1311 _descList.Add(new FacepointAttribute((GXAttribute) (i + 9), fmt));
1312
1313 //if (fmt == XFDataFormat.Direct)
1314 //{
1315 // _fpStride += linker._uvs[indices[i]]._dstStride;
1316 //}
1317 //else
1318 _fpStride += (int) fmt - 1;
1319 }
1320 }
1321 }
Vector2[] GetUVs(int index, bool force)
Retrieves texture coordinates from raw facedata in a remapped array.
Definition: PrimitiveManager.cs:233
List< FacepointAttribute > _descList
Definition: PrimitiveManager.cs:103
XFDataFormat
Definition: XF.cs:459
void SetHasTexMatrix(int index, bool exists)
Definition: XF.cs:392
void SetHasColor(int index, bool exists)
Definition: XF.cs:402
void SetHasUVs(int index, bool exists)
Definition: XF.cs:412

◆ ShiftUVATA()

uint BrawlLib.Modeling.PrimitiveManager.ShiftUVATA ( uint  posCnt,
uint  posFmt,
uint  posShft,
uint  nrmCnt,
uint  nrmFmt,
uint  Col0Cnt,
uint  Col0Fmt,
uint  Col1Cnt,
uint  Col1Fmt,
uint  tex0Cnt,
uint  tex0Fmt,
uint  tex0Shft,
uint  normalIndex3 
)
inline
1708 {
1709 return (posCnt << 0) |
1710 (posFmt << 1) |
1711 (posShft << 4) |
1712 (nrmCnt << 9) |
1713 (nrmFmt << 10) |
1714 (Col0Cnt << 13) |
1715 (Col0Fmt << 14) |
1716 (Col1Cnt << 17) |
1717 (Col1Fmt << 18) |
1718 (tex0Cnt << 21) |
1719 (tex0Fmt << 22) |
1720 (tex0Shft << 25) |
1721 ((uint) 1 << 30) | //Should always be 1
1722 (normalIndex3 << 31);
1723 }

◆ ShiftUVATB()

uint BrawlLib.Modeling.PrimitiveManager.ShiftUVATB ( uint  tex1Cnt,
uint  tex1Fmt,
uint  tex1Shft,
uint  tex2Cnt,
uint  tex2Fmt,
uint  tex2Shft,
uint  tex3Cnt,
uint  tex3Fmt,
uint  tex3Shft,
uint  tex4Cnt,
uint  tex4Fmt 
)
inline
1728 {
1729 return (tex1Cnt << 0) |
1730 (tex1Fmt << 1) |
1731 (tex1Shft << 4) |
1732 (tex2Cnt << 9) |
1733 (tex2Fmt << 10) |
1734 (tex2Shft << 13) |
1735 (tex3Cnt << 18) |
1736 (tex3Fmt << 19) |
1737 (tex3Shft << 22) |
1738 (tex4Cnt << 27) |
1739 (tex4Fmt << 28) |
1740 ((uint) 1 << 31); //Should always be 1
1741 }

◆ ShiftUVATC()

uint BrawlLib.Modeling.PrimitiveManager.ShiftUVATC ( uint  tex4Shft,
uint  tex5Cnt,
uint  tex5Fmt,
uint  tex5Shft,
uint  tex6Cnt,
uint  tex6Fmt,
uint  tex6Shft,
uint  tex7Cnt,
uint  tex7Fmt,
uint  tex7Shft 
)
inline
1746 {
1747 return (tex4Shft << 0) |
1748 (tex5Cnt << 5) |
1749 (tex5Fmt << 6) |
1750 (tex5Shft << 9) |
1751 (tex6Cnt << 14) |
1752 (tex6Fmt << 15) |
1753 (tex6Shft << 18) |
1754 (tex7Cnt << 23) |
1755 (tex7Fmt << 24) |
1756 (tex7Shft << 27);
1757 }

◆ ShiftVtxHi()

uint BrawlLib.Modeling.PrimitiveManager.ShiftVtxHi ( uint  tex0,
uint  tex1,
uint  tex2,
uint  tex3,
uint  tex4,
uint  tex5,
uint  tex6,
uint  tex7 
)
inline
1685 {
1686 return (tex0 << 0) |
1687 (tex1 << 2) |
1688 (tex2 << 4) |
1689 (tex3 << 6) |
1690 (tex4 << 8) |
1691 (tex5 << 10) |
1692 (tex6 << 12) |
1693 (tex7 << 14);
1694 }

◆ ShiftVtxLo()

uint BrawlLib.Modeling.PrimitiveManager.ShiftVtxLo ( uint  pmidx,
uint  t76543210midx,
uint  pos,
uint  nrm,
uint  col0,
uint  col1 
)
inline
1674 {
1675 return (pmidx << 0) |
1676 (t76543210midx << 1) |
1677 (pos << 9) |
1678 (nrm << 11) |
1679 (col0 << 13) |
1680 (col1 << 15);
1681 }

◆ ShiftXFSpecs()

uint BrawlLib.Modeling.PrimitiveManager.ShiftXFSpecs ( uint  host_colors,
uint  host_normal,
uint  host_textures 
)
inline
1698 {
1699 return (host_colors << 0) |
1700 (host_normal << 2) |
1701 (host_textures << 4);
1702 }

◆ Unweight()

void BrawlLib.Modeling.PrimitiveManager.Unweight ( bool  updateAssets)
inline
1958 {
1959 if (_vertices != null)
1960 {
1961 foreach (Vertex3 v in _vertices)
1962 {
1963 v.Unweight(updateAssets);
1964 }
1965 }
1966 }

◆ UVsChanged()

void BrawlLib.Modeling.PrimitiveManager.UVsChanged ( MDL0ObjectNode  obj,
int  id,
bool  forceNewNode = false 
)
inline
2491 {
2492 id = id.Clamp(0, 7);
2493
2494 if (obj == null || _faceData[id + 4] == null)
2495 {
2496 return;
2497 }
2498
2499 SetAssetChanged(id + 4);
2500 obj._forceRebuild = true;
2502
2503 MDL0UVNode node;
2504 if (obj._uvSet[id] != null)
2505 {
2506 if (obj._uvSet[id]._objects.Count == 1 && !forceNewNode)
2507 {
2508 node = obj._uvSet[id];
2509 }
2510 else
2511 {
2512 node = new MDL0UVNode();
2513 obj.Model.UVGroup.AddChild(node);
2514 node.Name = node.FindName("Regenerated");
2515 if (obj._uvSet[id]._objects.Contains(obj))
2516 {
2517 obj._uvSet[id]._objects.Remove(obj);
2518 }
2519
2520 obj._uvSet[id] = node;
2521 obj._uvSet[id]._objects.Add(obj);
2522 obj._elementIndices[id + 4] = (short) obj._uvSet[id].Index;
2523 }
2524 }
2525 else
2526 {
2527 node = new MDL0UVNode();
2528 MDL0Node m = obj.Model;
2529 if (m.UVGroup == null)
2530 {
2532 m.LinkGroup(g);
2533 g.Parent = m;
2534 }
2535
2536 m.UVGroup.AddChild(node);
2537 node.Name = node.FindName("Regenerated");
2538 obj._uvSet[id] = node;
2539 obj._uvSet[id]._objects.Add(obj);
2540 obj._elementIndices[id + 4] = (short) obj._uvSet[id].Index;
2541 }
2542
2543 node.Points = GetUVs(id, true);
2544 Vector2* pData = (Vector2*) _faceData[id + 4].Address;
2545 foreach (Vertex3 v in _vertices)
2546 {
2547 for (int i = 0; i < v.FaceDataIndices.Count; i++)
2548 {
2549 v.Facepoints[i]._UVIndices[id] = Array.IndexOf(node.Points, pData[v.FaceDataIndices[i]]);
2550 }
2551 }
2552 }
ResourceNode UVGroup
Definition: MDL0Node.cs:323
MDL0UVNode[] _uvSet
Definition: MDL0ObjectNode.cs:419
Definition: MDL0UVNode.cs:10
List< MDL0ObjectNode > _objects
Definition: MDL0UVNode.cs:14
Vector2[] Points
Definition: MDL0UVNode.cs:55

◆ Weight()

void BrawlLib.Modeling.PrimitiveManager.Weight ( )
inline
1969 {
1970 //Weight vertices
1971 if (_vertices != null)
1972 {
1973 foreach (Vertex3 v in _vertices)
1974 {
1975 v.Weight();
1976 }
1977 }
1978
1979 //Update graphics buffer with weighted data on next render
1980 _dirty[0] = true;
1981 _dirty[1] = true;
1982 }

◆ WriteVertexDescriptor()

void BrawlLib.Modeling.PrimitiveManager.WriteVertexDescriptor ( out CPVertexFormat  vertexFormat,
out XFVertexSpecs  vertexSpecs 
)
inline

This sets up how to read the facepoints that are going to be written.

1329 {
1330 XFNormalFormat nrmFmt = XFNormalFormat.None;
1331 int numColors = 0;
1332 int numUVs = 0;
1333
1334 uint posNrmMtxId = 0;
1335 uint texMtxIdMask = 0;
1336 uint pos = 0;
1337 uint nrm = 0;
1338 uint col0 = 0;
1339 uint col1 = 0;
1340 uint tex0 = 0;
1341 uint tex1 = 0;
1342 uint tex2 = 0;
1343 uint tex3 = 0;
1344 uint tex4 = 0;
1345 uint tex5 = 0;
1346 uint tex6 = 0;
1347 uint tex7 = 0;
1348
1349 foreach (FacepointAttribute attrPtr in _descList)
1350 {
1351 switch (attrPtr._attr)
1352 {
1353 case GXAttribute.PosNrmMtxId:
1354 posNrmMtxId = (uint) attrPtr._type;
1355 break;
1356
1357 case GXAttribute.Tex0MtxId:
1358 texMtxIdMask = (uint) (texMtxIdMask & ~1) | ((uint) attrPtr._type << 0);
1359 break;
1360 case GXAttribute.Tex1MtxId:
1361 texMtxIdMask = (uint) (texMtxIdMask & ~2) | ((uint) attrPtr._type << 1);
1362 break;
1363 case GXAttribute.Tex2MtxId:
1364 texMtxIdMask = (uint) (texMtxIdMask & ~4) | ((uint) attrPtr._type << 2);
1365 break;
1366 case GXAttribute.Tex3MtxId:
1367 texMtxIdMask = (uint) (texMtxIdMask & ~8) | ((uint) attrPtr._type << 3);
1368 break;
1369 case GXAttribute.Tex4MtxId:
1370 texMtxIdMask = (uint) (texMtxIdMask & ~16) | ((uint) attrPtr._type << 4);
1371 break;
1372 case GXAttribute.Tex5MtxId:
1373 texMtxIdMask = (uint) (texMtxIdMask & ~32) | ((uint) attrPtr._type << 5);
1374 break;
1375 case GXAttribute.Tex6MtxId:
1376 texMtxIdMask = (uint) (texMtxIdMask & ~64) | ((uint) attrPtr._type << 6);
1377 break;
1378 case GXAttribute.Tex7MtxId:
1379 texMtxIdMask = (uint) (texMtxIdMask & ~128) | ((uint) attrPtr._type << 7);
1380 break;
1381
1382 case GXAttribute.Position:
1383 pos = (uint) attrPtr._type;
1384 break;
1385
1386 case GXAttribute.Normal:
1387 if (attrPtr._type != XFDataFormat.None)
1388 {
1389 nrm = (uint) attrPtr._type;
1390 nrmFmt = XFNormalFormat.XYZ;
1391 }
1392
1393 break;
1394
1395 case GXAttribute.NBT:
1396 if (attrPtr._type != XFDataFormat.None)
1397 {
1398 nrm = (uint) attrPtr._type;
1399 nrmFmt = XFNormalFormat.NBT;
1400 }
1401
1402 break;
1403
1404 case GXAttribute.Color0:
1405 col0 = (uint) attrPtr._type;
1406 numColors += col0 != 0 ? 1 : 0;
1407 break;
1408 case GXAttribute.Color1:
1409 col1 = (uint) attrPtr._type;
1410 numColors += col1 != 0 ? 1 : 0;
1411 break;
1412
1413 case GXAttribute.Tex0:
1414 tex0 = (uint) attrPtr._type;
1415 numUVs += tex0 != 0 ? 1 : 0;
1416 break;
1417 case GXAttribute.Tex1:
1418 tex1 = (uint) attrPtr._type;
1419 numUVs += tex1 != 0 ? 1 : 0;
1420 break;
1421 case GXAttribute.Tex2:
1422 tex2 = (uint) attrPtr._type;
1423 numUVs += tex2 != 0 ? 1 : 0;
1424 break;
1425 case GXAttribute.Tex3:
1426 tex3 = (uint) attrPtr._type;
1427 numUVs += tex3 != 0 ? 1 : 0;
1428 break;
1429 case GXAttribute.Tex4:
1430 tex4 = (uint) attrPtr._type;
1431 numUVs += tex4 != 0 ? 1 : 0;
1432 break;
1433 case GXAttribute.Tex5:
1434 tex5 = (uint) attrPtr._type;
1435 numUVs += tex5 != 0 ? 1 : 0;
1436 break;
1437 case GXAttribute.Tex6:
1438 tex6 = (uint) attrPtr._type;
1439 numUVs += tex6 != 0 ? 1 : 0;
1440 break;
1441 case GXAttribute.Tex7:
1442 tex7 = (uint) attrPtr._type;
1443 numUVs += tex7 != 0 ? 1 : 0;
1444 break;
1445 }
1446 }
1447
1448 vertexSpecs = new XFVertexSpecs(numColors, numUVs, nrmFmt);
1449 vertexFormat = new CPVertexFormat(
1450 ShiftVtxLo(posNrmMtxId, texMtxIdMask, pos, nrm, col0, col1),
1451 ShiftVtxHi(tex0, tex1, tex2, tex3, tex4, tex5, tex6, tex7));
1452 }
uint ShiftVtxLo(uint pmidx, uint t76543210midx, uint pos, uint nrm, uint col0, uint col1)
Definition: PrimitiveManager.cs:1673
uint ShiftVtxHi(uint tex0, uint tex1, uint tex2, uint tex3, uint tex4, uint tex5, uint tex6, uint tex7)
Definition: PrimitiveManager.cs:1684
XFNormalFormat
Definition: XF.cs:289
XFDataFormat _type
Definition: XF.cs:476
GXAttribute _attr
Definition: XF.cs:475

◆ WriteVertexFormat()

void BrawlLib.Modeling.PrimitiveManager.WriteVertexFormat ( MDL0Object polygon)
inline
1540 {
1541 //These are default values.
1542
1543 uint posCnt = (int) GXCompCnt.PosXYZ;
1544 uint posType = (int) GXCompType.Float;
1545 uint posFrac = 0;
1546
1547 uint nrmCnt = (int) GXCompCnt.NrmXYZ;
1548 uint nrmType = (int) GXCompType.Float;
1549 uint nrmId3 = 0;
1550
1551 uint c0Cnt = (int) GXCompCnt.ClrRGBA;
1552 uint c0Type = (int) GXCompType.RGBA8;
1553 uint c1Cnt = (int) GXCompCnt.ClrRGBA;
1554 uint c1Type = (int) GXCompType.RGBA8;
1555
1556 uint tx0Cnt = (int) GXCompCnt.TexST;
1557 uint tx0Type = (int) GXCompType.Float;
1558 uint tx0Frac = 0;
1559 uint tx1Cnt = (int) GXCompCnt.TexST;
1560 uint tx1Type = (int) GXCompType.Float;
1561 uint tx1Frac = 0;
1562 uint tx2Cnt = (int) GXCompCnt.TexST;
1563 uint tx2Type = (int) GXCompType.Float;
1564 uint tx2Frac = 0;
1565 uint tx3Cnt = (int) GXCompCnt.TexST;
1566 uint tx3Type = (int) GXCompType.Float;
1567 uint tx3Frac = 0;
1568 uint tx4Cnt = (int) GXCompCnt.TexST;
1569 uint tx4Type = (int) GXCompType.Float;
1570 uint tx4Frac = 0;
1571 uint tx5Cnt = (int) GXCompCnt.TexST;
1572 uint tx5Type = (int) GXCompType.Float;
1573 uint tx5Frac = 0;
1574 uint tx6Cnt = (int) GXCompCnt.TexST;
1575 uint tx6Type = (int) GXCompType.Float;
1576 uint tx6Frac = 0;
1577 uint tx7Cnt = (int) GXCompCnt.TexST;
1578 uint tx7Type = (int) GXCompType.Float;
1579 uint tx7Frac = 0;
1580
1581 if (_fmtList != null)
1582 {
1583 foreach (VertexAttributeFormat list in _fmtList)
1584 {
1585 switch (list._attr)
1586 {
1587 case GXAttribute.Position:
1588 posCnt = (uint) list._cnt;
1589 posType = (uint) list._type;
1590 posFrac = list._frac;
1591 break;
1592 case GXAttribute.Normal:
1593 case GXAttribute.NBT:
1594 nrmType = (uint) list._type;
1595 if (list._cnt == GXCompCnt.NrmNBT3)
1596 {
1597 nrmCnt = (uint) GXCompCnt.NrmNBT;
1598 nrmId3 = 1;
1599 }
1600 else
1601 {
1602 nrmCnt = (uint) list._cnt;
1603 nrmId3 = 0;
1604 }
1605
1606 break;
1607 case GXAttribute.Color0:
1608 c0Cnt = (uint) list._cnt;
1609 c0Type = (uint) list._type;
1610 break;
1611 case GXAttribute.Color1:
1612 c1Cnt = (uint) list._cnt;
1613 c1Type = (uint) list._type;
1614 break;
1615 case GXAttribute.Tex0:
1616 tx0Cnt = (uint) list._cnt;
1617 tx0Type = (uint) list._type;
1618 tx0Frac = list._frac;
1619 break;
1620 case GXAttribute.Tex1:
1621 tx1Cnt = (uint) list._cnt;
1622 tx1Type = (uint) list._type;
1623 tx1Frac = list._frac;
1624 break;
1625 case GXAttribute.Tex2:
1626 tx2Cnt = (uint) list._cnt;
1627 tx2Type = (uint) list._type;
1628 tx2Frac = list._frac;
1629 break;
1630 case GXAttribute.Tex3:
1631 tx3Cnt = (uint) list._cnt;
1632 tx3Type = (uint) list._type;
1633 tx3Frac = list._frac;
1634 break;
1635 case GXAttribute.Tex4:
1636 tx4Cnt = (uint) list._cnt;
1637 tx4Type = (uint) list._type;
1638 tx4Frac = list._frac;
1639 break;
1640 case GXAttribute.Tex5:
1641 tx5Cnt = (uint) list._cnt;
1642 tx5Type = (uint) list._type;
1643 tx5Frac = list._frac;
1644 break;
1645 case GXAttribute.Tex6:
1646 tx6Cnt = (uint) list._cnt;
1647 tx6Type = (uint) list._type;
1648 tx6Frac = list._frac;
1649 break;
1650 case GXAttribute.Tex7:
1651 tx7Cnt = (uint) list._cnt;
1652 tx7Type = (uint) list._type;
1653 tx7Frac = list._frac;
1654 break;
1655 }
1656 }
1657 }
1658
1659 MDL0PolygonDefs* Defs = polygon->DefList;
1660 Defs->UVATA = ShiftUVATA(posCnt, posType, posFrac, nrmCnt, nrmType, c0Cnt, c0Type, c1Cnt, c1Type, tx0Cnt,
1661 tx0Type, tx0Frac, nrmId3);
1662 Defs->UVATB = ShiftUVATB(tx1Cnt, tx1Type, tx1Frac, tx2Cnt, tx2Type, tx2Frac, tx3Cnt, tx3Type, tx3Frac,
1663 tx4Cnt, tx4Type);
1664 Defs->UVATC = ShiftUVATC(tx4Frac, tx5Cnt, tx5Type, tx5Frac, tx6Cnt, tx6Type, tx6Frac, tx7Cnt, tx7Type,
1665 tx7Frac);
1666 }
uint ShiftUVATB(uint tex1Cnt, uint tex1Fmt, uint tex1Shft, uint tex2Cnt, uint tex2Fmt, uint tex2Shft, uint tex3Cnt, uint tex3Fmt, uint tex3Shft, uint tex4Cnt, uint tex4Fmt)
Definition: PrimitiveManager.cs:1726
uint ShiftUVATC(uint tex4Shft, uint tex5Cnt, uint tex5Fmt, uint tex5Shft, uint tex6Cnt, uint tex6Fmt, uint tex6Shft, uint tex7Cnt, uint tex7Fmt, uint tex7Shft)
Definition: PrimitiveManager.cs:1744
uint ShiftUVATA(uint posCnt, uint posFmt, uint posShft, uint nrmCnt, uint nrmFmt, uint Col0Cnt, uint Col0Fmt, uint Col1Cnt, uint Col1Fmt, uint tex0Cnt, uint tex0Fmt, uint tex0Shft, uint normalIndex3)
Definition: PrimitiveManager.cs:1705
MDL0PolygonDefs * DefList
Definition: MDL0.cs:1925
Definition: MDL0.cs:1950
buint UVATC
Definition: MDL0.cs:1972
buint UVATB
Definition: MDL0.cs:1970
buint UVATA
Definition: MDL0.cs:1968
GXCompType _type
Definition: CP.cs:357
GXCompCnt _cnt
Definition: CP.cs:356
GXAttribute _attr
Definition: CP.cs:355

Member Data Documentation

◆ _arrayBufferHandle

int BrawlLib.Modeling.PrimitiveManager._arrayBufferHandle

◆ _arrayFlags

XFArrayFlags BrawlLib.Modeling.PrimitiveManager._arrayFlags

◆ _arrayHandle

int BrawlLib.Modeling.PrimitiveManager._arrayHandle

◆ _descList

List<FacepointAttribute> BrawlLib.Modeling.PrimitiveManager._descList

◆ _dirty

bool [] BrawlLib.Modeling.PrimitiveManager._dirty = new bool[12]

◆ _elementArrayBufferHandle

int BrawlLib.Modeling.PrimitiveManager._elementArrayBufferHandle

◆ _faceCount

int BrawlLib.Modeling.PrimitiveManager._faceCount

◆ _faceData

UnsafeBuffer [] BrawlLib.Modeling.PrimitiveManager._faceData = new UnsafeBuffer[12]

◆ _fmtList

List<VertexAttributeFormat> BrawlLib.Modeling.PrimitiveManager._fmtList

◆ _fpStride

int BrawlLib.Modeling.PrimitiveManager._fpStride

◆ _graphicsBuffer

UnsafeBuffer BrawlLib.Modeling.PrimitiveManager._graphicsBuffer

◆ _indices

UnsafeBuffer BrawlLib.Modeling.PrimitiveManager._indices

◆ _isWeighted

bool BrawlLib.Modeling.PrimitiveManager._isWeighted

◆ _nodeRadius

const float BrawlLib.Modeling.PrimitiveManager._nodeRadius = 0.05f
static

◆ _pointCount

int BrawlLib.Modeling.PrimitiveManager._pointCount

◆ _primGroups

List<PrimitiveGroup> BrawlLib.Modeling.PrimitiveManager._primGroups = new List<PrimitiveGroup>()

◆ _primitiveSize

int BrawlLib.Modeling.PrimitiveManager._primitiveSize

◆ _remakePrimitives

bool BrawlLib.Modeling.PrimitiveManager._remakePrimitives

◆ _render

bool BrawlLib.Modeling.PrimitiveManager._render = true

◆ _renderNormals

bool BrawlLib.Modeling.PrimitiveManager._renderNormals = true

◆ _renderStride

int BrawlLib.Modeling.PrimitiveManager._renderStride

◆ _vertices

List<Vertex3> BrawlLib.Modeling.PrimitiveManager._vertices

◆ DefaultNormColor

Color BrawlLib.Modeling.PrimitiveManager.DefaultNormColor = Color.FromArgb(0, 0, 128)
static

◆ DefaultVertColor

Color BrawlLib.Modeling.PrimitiveManager.DefaultVertColor = Color.FromArgb(0, 128, 0)
static

◆ HasTextureMatrix

bool [] BrawlLib.Modeling.PrimitiveManager.HasTextureMatrix = new bool[8]

◆ NormalLength

float BrawlLib.Modeling.PrimitiveManager.NormalLength = 0.5f
static

◆ UseIdentityTexMtx

bool [] BrawlLib.Modeling.PrimitiveManager.UseIdentityTexMtx = new bool[8]

Property Documentation

◆ AssetsChanged

bool BrawlLib.Modeling.PrimitiveManager.AssetsChanged
getset
24 {
25 get
26 {
27 foreach (bool b in _changed)
28 {
29 if (b)
30 {
31 return true;
32 }
33 }
34
35 return false;
36 }
37 set
38 {
39 for (int i = 0; i < _changed.Length; i++)
40 {
41 _changed[i] = false;
42 }
43 }
44 }

◆ HasTexMtx

bool BrawlLib.Modeling.PrimitiveManager.HasTexMtx
get
81 {
82 get
83 {
84 for (int i = 0; i < 8; i++)
85 {
86 if (HasTextureMatrix[i])
87 {
88 return true;
89 }
90 }
91
92 return false;
93 }
94 }

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