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

Public Member Functions

IMatrixNode GetMatrixNode ()
 
Matrix GetMatrix ()
 
Matrix GetInvMatrix ()
 
List< BoneWeightGetBoneWeights ()
 
IBoneNode[] GetBones ()
 
float[] GetWeightValues ()
 
int IndexOfBone (IBoneNode b)
 
BoneWeight WeightForBone (IBoneNode b)
 
void ChangeInfluence (IMatrixNode newMatrixNode)
 
void DeferUpdateAssets ()
 
 Vertex3 ()
 
 Vertex3 (Vector3 position)
 
 Vertex3 (Vector3 position, IMatrixNode influence)
 
void Weight ()
 
void Unweight (bool updateVertexSets=true)
 
void SetPosition (MDL0VertexNode node, Vector3 pos)
 
void SetPosition ()
 
void Morph (Vector3 dest, float percent)
 
Color GetWeightColor (IBoneNode targetBone)
 
bool Equals (Vertex3 v)
 
void DeferUpdateAssets ()
 

Public Attributes

Vector3 _position
 
Vector3 _weightedPosition
 
List< int > FaceDataIndices = new List<int>()
 
List< FacepointFacepoints = new List<Facepoint>()
 
Color HighlightColor = Color.Transparent
 

Properties

IMatrixNodeUser Parent [get, set]
 
string Influence [get]
 
IMatrixNode MatrixNode [get, set]
 
Vector3 WeightedPosition [get, set]
 
Vector3 Position [get, set]
 
bool Selected [get, set]
 
- Properties inherited from BrawlLib.SSBB.ResourceNodes.IMatrixNodeUser
IMatrixNode MatrixNode [get, set]
 

Constructor & Destructor Documentation

◆ Vertex3() [1/3]

BrawlLib.Modeling.Vertex3.Vertex3 ( )
inline
241 {
242 }

◆ Vertex3() [2/3]

BrawlLib.Modeling.Vertex3.Vertex3 ( Vector3  position)
inline
245 {
246 Position = position;
247 }
Vector3 Position
Definition: Vertex.cs:235

◆ Vertex3() [3/3]

BrawlLib.Modeling.Vertex3.Vertex3 ( Vector3  position,
IMatrixNode  influence 
)
inline
250 {
251 Position = position;
252 MatrixNode = influence;
253 }
IMatrixNode MatrixNode
Definition: Vertex.cs:195

Member Function Documentation

◆ ChangeInfluence()

void BrawlLib.Modeling.Vertex3.ChangeInfluence ( IMatrixNode  newMatrixNode)
inline
109 {
110 if (_parent == null)
111 {
112 return;
113 }
114
115 IMatrixNode oldMatrixNode = GetMatrixNode();
116 if (newMatrixNode is IBoneNode && (oldMatrixNode is Influence || oldMatrixNode == null))
117 {
118 //Move to local
119 Matrix inv = ((IBoneNode) newMatrixNode).InverseBindMatrix;
120
121 _position *= inv;
122 UpdateNormals(Matrix.Identity, inv);
123
124 if (_updateAssets)
125 {
126 SetPosition();
127 SetNormals();
128 }
129 }
130 else if ((newMatrixNode is Influence || newMatrixNode == null) && oldMatrixNode is IBoneNode)
131 {
132 //Move to world
133 Matrix m = ((IBoneNode) oldMatrixNode).BindMatrix;
134
135 _position *= m;
136 UpdateNormals(m, Matrix.Identity);
137
138 if (_updateAssets)
139 {
140 SetPosition();
141 SetNormals();
142 }
143 }
144 else if (newMatrixNode is IBoneNode && oldMatrixNode is IBoneNode)
145 {
146 //Update local position
147 Matrix m = ((IBoneNode) oldMatrixNode).BindMatrix;
148 Matrix inv = ((IBoneNode) newMatrixNode).InverseBindMatrix;
149
150 _position *= m;
151 _position *= inv;
152 UpdateNormals(m, inv);
153
154 if (_updateAssets)
155 {
156 SetPosition();
157 SetNormals();
158 }
159 }
160
161 _updateAssets = true;
162
163 //If both are null or an influence, they're already in world position
164 }
Vector3 _position
Definition: Vertex.cs:14
void SetPosition()
Definition: Vertex.cs:316
IMatrixNode GetMatrixNode()
Definition: Vertex.cs:37
Definition: InfluenceManager.cs:96
Definition: Matrix.cs:14
static readonly Matrix Identity
Definition: Matrix.cs:15

◆ DeferUpdateAssets()

void BrawlLib.Modeling.Vertex3.DeferUpdateAssets ( )
inline

Implements BrawlLib.SSBB.ResourceNodes.IMatrixNodeUser.

189 {
190 _updateAssets = false;
191 }

◆ Equals()

bool BrawlLib.Modeling.Vertex3.Equals ( Vertex3  v)
inline
380 {
381 if (ReferenceEquals(this, v))
382 {
383 return true;
384 }
385
386 return Position == v.Position && _matrixNode == v._matrixNode;
387 }

◆ GetBones()

IBoneNode[] BrawlLib.Modeling.Vertex3.GetBones ( )
inline
75 {
76 List<BoneWeight> b = GetBoneWeights();
77 return b?.Select(x => x.Bone).ToArray();
78 }
List< BoneWeight > GetBoneWeights()
Definition: Vertex.cs:69

◆ GetBoneWeights()

List< BoneWeight > BrawlLib.Modeling.Vertex3.GetBoneWeights ( )
inline
70 {
71 return MatrixNode == null ? _parent.MatrixNode.Weights : MatrixNode.Weights;
72 }
List< BoneWeight > Weights
Definition: IMatrixNode.cs:15

◆ GetInvMatrix()

Matrix BrawlLib.Modeling.Vertex3.GetInvMatrix ( )
inline
59 {
60 IMatrixNode node = GetMatrixNode();
61 if (node != null)
62 {
63 return node.InverseMatrix;
64 }
65
66 return Matrix.Identity;
67 }

◆ GetMatrix()

Matrix BrawlLib.Modeling.Vertex3.GetMatrix ( )
inline
48 {
49 IMatrixNode node = GetMatrixNode();
50 if (node != null)
51 {
52 return node.Matrix;
53 }
54
55 return Matrix.Identity;
56 }

◆ GetMatrixNode()

IMatrixNode BrawlLib.Modeling.Vertex3.GetMatrixNode ( )
inline
38 {
39 if (_parent?.MatrixNode != null)
40 {
41 return _parent.MatrixNode;
42 }
43
44 return MatrixNode;
45 }
IMatrixNode MatrixNode
Definition: MDL0ObjectNode.cs:2309

◆ GetWeightColor()

Color BrawlLib.Modeling.Vertex3.GetWeightColor ( IBoneNode  targetBone)
inline
340 {
341 float weight = -1.0f;
342 if (_matrixNode == null || targetBone == null)
343 {
344 return Color.Transparent;
345 }
346
347 if (_matrixNode is MDL0BoneNode mNode)
348 {
349 if (mNode == targetBone)
350 {
351 weight = 1.0f;
352 }
353 else
354 {
355 return Color.Transparent;
356 }
357 }
358 else
359 {
360 foreach (BoneWeight b in ((Influence) _matrixNode).Weights)
361 {
362 if (b.Bone == targetBone)
363 {
364 weight = b.Weight;
365 break;
366 }
367 }
368 }
369
370 if (weight < 0.0f || weight > 1.0f)
371 {
372 return Color.Transparent;
373 }
374
375 int r = ((int) (weight * 255.0f)).Clamp(0, 0xFF);
376 return Color.FromArgb(r, 0, 0xFF - r);
377 }
Definition: MDL0BoneNode.cs:17
Definition: InfluenceManager.cs:381
IBoneNode Bone
Definition: InfluenceManager.cs:387
float Weight
Definition: InfluenceManager.cs:388

◆ GetWeightValues()

float[] BrawlLib.Modeling.Vertex3.GetWeightValues ( )
inline
81 {
82 List<BoneWeight> b = GetBoneWeights();
83 return b?.Select(x => x.Weight).ToArray();
84 }

◆ IndexOfBone()

int BrawlLib.Modeling.Vertex3.IndexOfBone ( IBoneNode  b)
inline
87 {
88 return Array.IndexOf(GetBones(), b);
89 }
IBoneNode[] GetBones()
Definition: Vertex.cs:74

◆ Morph()

void BrawlLib.Modeling.Vertex3.Morph ( Vector3  dest,
float  percent 
)
inline
335 {
336 _weightedPosition.Lerp(dest, percent);
337 }
Vector3 _weightedPosition
Definition: Vertex.cs:15
static Vector3 Lerp(Vector3 v1, Vector3 v2, float median)
Definition: Vector3.cs:410

◆ SetPosition() [1/2]

void BrawlLib.Modeling.Vertex3.SetPosition ( )
inline
317 {
318 MDL0VertexNode node = ((MDL0ObjectNode) _parent)?._vertexNode;
319
320 if (node == null || Facepoints.Count < 1 || node.Vertices.Length <= Facepoints[0]._vertexIndex)
321 {
322 return;
323 }
324
325 node.Vertices[Facepoints[0]._vertexIndex] = Position;
326 node.ForceRebuild = true;
327 if (node.Format == WiiVertexComponentType.Float)
328 {
329 node.ForceFloat = true;
330 }
331 }
List< Facepoint > Facepoints
Definition: Vertex.cs:35
Definition: MDL0ObjectNode.cs:21
Definition: MDL0VertexNode.cs:11
Vector3[] Vertices
Definition: MDL0VertexNode.cs:55
WiiVertexComponentType Format
Definition: MDL0VertexNode.cs:20
WiiVertexComponentType
Definition: Enum.cs:4

◆ SetPosition() [2/2]

void BrawlLib.Modeling.Vertex3.SetPosition ( MDL0VertexNode  node,
Vector3  pos 
)
inline
301 {
302 //if (node == null)
303 // return;
304
305 //node.Vertices[_facepoints[0]._vertexIndex] = pos;
306 //node.ForceRebuild = true;
307 //if (node.Format == WiiVertexComponentType.Float)
308 // node.ForceFloat = true;
309
310 //Have to use this function instead of setting the vertices directly
311 //This is because the vertex set may be used by other objects
312 MDL0ObjectNode obj = _parent as MDL0ObjectNode;
313 obj?.SetEditedVertices();
314 }
void SetEditedVertices(bool forceNewNode=false)
Definition: MDL0ObjectNode.cs:1799

◆ Unweight()

void BrawlLib.Modeling.Vertex3.Unweight ( bool  updateVertexSets = true)
inline
267 {
268 //Unweight overall position
270
271 //Distribute weights for the position across all vertex set influences
272 if (updateVertexSets)
273 {
274 if (_weights != null && _nodes != null)
275 {
276 Vector3 trans = _weightedPosition - _bCenter;
277 for (int i = 0; i < _nodes.Length; i++)
278 {
279 MDL0VertexNode set = _nodes[i];
280 SetPosition(set,
281 GetInvMatrix() * (GetMatrix() * set.Vertices[Facepoints[0]._vertexIndex] + trans));
282 }
283
284 MDL0ObjectNode obj = (MDL0ObjectNode) _parent;
286 GetInvMatrix() * (GetMatrix() * obj._vertexNode.Vertices[Facepoints[0]._vertexIndex] + trans));
287 }
288 else
289 {
290 SetPosition();
291 }
292 }
293 }
Matrix GetMatrix()
Definition: Vertex.cs:47
Vector3 WeightedPosition
Definition: Vertex.cs:222
Matrix GetInvMatrix()
Definition: Vertex.cs:58
MDL0VertexNode _vertexNode
Definition: MDL0ObjectNode.cs:216
Definition: Vector3.cs:40

◆ Weight()

void BrawlLib.Modeling.Vertex3.Weight ( )
inline
258 {
260
261 _weights = null;
262 _nodes = null;
263 }

◆ WeightForBone()

BoneWeight BrawlLib.Modeling.Vertex3.WeightForBone ( IBoneNode  b)
inline
92 {
93 int i = IndexOfBone(b);
94 if (i == -1)
95 {
96 return null;
97 }
98
99 return GetBoneWeights()[i];
100 }
int IndexOfBone(IBoneNode b)
Definition: Vertex.cs:86

Member Data Documentation

◆ _position

Vector3 BrawlLib.Modeling.Vertex3._position

◆ _weightedPosition

Vector3 BrawlLib.Modeling.Vertex3._weightedPosition

◆ FaceDataIndices

List<int> BrawlLib.Modeling.Vertex3.FaceDataIndices = new List<int>()

◆ Facepoints

List<Facepoint> BrawlLib.Modeling.Vertex3.Facepoints = new List<Facepoint>()

◆ HighlightColor

Color BrawlLib.Modeling.Vertex3.HighlightColor = Color.Transparent

Property Documentation

◆ Influence

string BrawlLib.Modeling.Vertex3.Influence
get

◆ MatrixNode

IMatrixNode BrawlLib.Modeling.Vertex3.MatrixNode
getset

Implements BrawlLib.SSBB.ResourceNodes.IMatrixNodeUser.

195 {
196 get => _matrixNode;
197 set
198 {
199 if (_matrixNode == value)
200 {
201 return;
202 }
203
204 ChangeInfluence(value);
205
206 if (_matrixNode != null && _matrixNode.Users.Contains(this))
207 {
208 _matrixNode.Users.Remove(this);
209 }
210
211 if ((_matrixNode = value) != null && !_matrixNode.Users.Contains(this))
212 {
213 _matrixNode.Users.Add(this);
214 }
215 }
216 }
void ChangeInfluence(IMatrixNode newMatrixNode)
Definition: Vertex.cs:108
List< IMatrixNodeUser > Users
Definition: IMatrixNode.cs:10

◆ Parent

IMatrixNodeUser BrawlLib.Modeling.Vertex3.Parent
getset
24 {
25 get => _parent;
26 set => _parent = value;
27 }

◆ Position

Vector3 BrawlLib.Modeling.Vertex3.Position
getset
235 {
236 get => _position;
237 set => _position = value;
238 }

◆ Selected

bool BrawlLib.Modeling.Vertex3.Selected
getset
394 {
395 get => _selected;
396 set
397 {
398 _selected = value;
399 HighlightColor = _selected ? Color.Orange : Color.Transparent;
400 }
401 }
Color HighlightColor
Definition: Vertex.cs:389

◆ WeightedPosition

Vector3 BrawlLib.Modeling.Vertex3.WeightedPosition
getset
222 {
223 get => _weightedPosition;
224 set
225 {
226 _weightedPosition = value;
227 Unweight();
228 }
229 }
void Unweight(bool updateVertexSets=true)
Definition: Vertex.cs:266

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