Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Commit

Permalink
Additional Graphics/ cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Mar 30, 2014
1 parent de44018 commit 252b6b9
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 89 deletions.
34 changes: 18 additions & 16 deletions MonoGame.Framework/Graphics/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,39 @@ public class Model
{
#region Public Properties

// Summary:
// Gets a collection of ModelBone objects which describe how each mesh in the
// Meshes collection for this model relates to its parent mesh.
/// <summary>
/// Gets a collection of ModelBone objects which describe how each mesh in the
/// Meshes collection for this model relates to its parent mesh.
/// </summary>
public ModelBoneCollection Bones
{
get;
private set;
}

//
// Summary:
// Gets a collection of ModelMesh objects which compose the model. Each ModelMesh
// in a model may be moved independently and may be composed of multiple materials
// identified as ModelMeshPart objects.
/// <summary>
/// Gets a collection of ModelMesh objects which compose the model. Each ModelMesh
/// in a model may be moved independently and may be composed of multiple materials
/// identified as ModelMeshPart objects.
/// </summary>
public ModelMeshCollection Meshes
{
get;
private set;
}

//
// Summary:
// Gets the root bone for this model.
/// <summary>
/// Gets the root bone for this model.
/// </summary>
public ModelBone Root
{
get;
set;
}

//
// Summary:
// Gets or sets an object identifying this model.
/// <summary>
/// Gets or sets an object identifying this model.
/// </summary>
public object Tag
{
get;
Expand Down Expand Up @@ -139,13 +140,14 @@ public void CopyAbsoluteBoneTransformsTo(Matrix[] destinationBoneTransforms)
ModelBone modelBone = Bones[index1];
if (modelBone.Parent == null)
{
destinationBoneTransforms[index1] = modelBone.transform;
destinationBoneTransforms[index1] = modelBone.Transform;
}
else
{
int index2 = modelBone.Parent.Index;
Matrix modelBoneTransform = modelBone.Transform;
Matrix.Multiply(
ref modelBone.transform,
ref modelBoneTransform,
ref destinationBoneTransforms[index2],
out destinationBoneTransforms[index1]
);
Expand Down
41 changes: 11 additions & 30 deletions MonoGame.Framework/Graphics/ModelBone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ public sealed class ModelBone

public List<ModelMesh> Meshes
{
get
{
return meshes;
}
private set
{
meshes = value;
}
get;
private set;
}

/// <summary>
Expand Down Expand Up @@ -69,16 +63,14 @@ public ModelBone Parent
set;
}

/// <summary>
/// Gets or sets the matrix used to transform this bone relative to its parent
/// bone.
/// </summary>
public Matrix Transform
{
get
{
return this.transform;
}
set
{
this.transform = value;
}
get;
set;
}

/// <summary>
Expand All @@ -92,29 +84,18 @@ public Matrix ModelTransform

#endregion

#region Internal Variables

/// <summary>
/// Gets or sets the matrix used to transform this bone relative to its parent
/// bone.
/// </summary>
internal Matrix transform;

#endregion

#region Private Variables

private List<ModelBone> children = new List<ModelBone>();

private List<ModelMesh> meshes = new List<ModelMesh>();

#endregion

#region Public Constructor

public ModelBone()
{
Children = new ModelBoneCollection(new List<ModelBone>());
Meshes = new List<ModelMesh>();
}

#endregion
Expand All @@ -123,7 +104,7 @@ public ModelBone()

public void AddMesh(ModelMesh mesh)
{
meshes.Add(mesh);
Meshes.Add(mesh);
}

public void AddChild(ModelBone modelBone)
Expand All @@ -134,4 +115,4 @@ public void AddChild(ModelBone modelBone)

#endregion
}
}
}
6 changes: 2 additions & 4 deletions MonoGame.Framework/Graphics/ModelBoneCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#region Using Statements
using System.Collections.Generic;
using System.Collections.ObjectModel;

#endregion

namespace Microsoft.Xna.Framework.Graphics
Expand Down Expand Up @@ -45,8 +44,7 @@ public class ModelBoneCollection : ReadOnlyCollection<ModelBone>

#region Public Constructor

public ModelBoneCollection(IList<ModelBone> list)
: base(list)
public ModelBoneCollection(IList<ModelBone> list) : base(list)
{
}

Expand Down Expand Up @@ -79,4 +77,4 @@ public bool TryGetValue(string boneName, out ModelBone value)

#endregion
}
}
}
12 changes: 5 additions & 7 deletions MonoGame.Framework/Graphics/ModelEffectCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ public sealed class ModelEffectCollection : ReadOnlyCollection<Effect>
{
#region Public Constructor

public ModelEffectCollection(IList<Effect> list)
: base(list)
public ModelEffectCollection(IList<Effect> list) : base(list)
{
}

#endregion

#region Internal Constructor

internal ModelEffectCollection()
: base(new List<Effect>())
internal ModelEffectCollection() : base(new List<Effect>())
{
}

Expand All @@ -46,14 +44,14 @@ internal ModelEffectCollection()
/// </summary>
public new ModelEffectCollection.Enumerator GetEnumerator()
{
return new ModelEffectCollection.Enumerator((List<Effect>)Items);
return new ModelEffectCollection.Enumerator((List<Effect>) Items);
}

#endregion

#region Internal Methods

//ModelMeshPart needs to be able to add to ModelMesh's effects list
// ModelMeshPart needs to be able to add to ModelMesh's effects list
internal void Add(Effect item)
{
Items.Add(item);
Expand Down Expand Up @@ -132,4 +130,4 @@ void IEnumerator.Reset()

#endregion
}
}
}
3 changes: 2 additions & 1 deletion MonoGame.Framework/Graphics/ModelMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public ModelMesh(GraphicsDevice graphicsDevice, List<ModelMeshPart> parts)
/// <summary>
/// Draws all of the ModelMeshPart objects in this mesh, using their current
/// Effect settings.
/// </summary>
public void Draw()
{
foreach (ModelMeshPart part in MeshParts)
Expand Down Expand Up @@ -138,4 +139,4 @@ public void Draw()

#endregion
}
}
}
7 changes: 3 additions & 4 deletions MonoGame.Framework/Graphics/ModelMeshCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed class ModelMeshCollection : ReadOnlyCollection<ModelMesh>
/// Retrieves a ModelMesh from the collection, given the name of the mesh.
/// </summary>
/// <param name="meshName">
/// The name of the mesh to retrieve.
/// The name of the mesh to retrieve.
/// </param>
public ModelMesh this[string meshName]
{
Expand All @@ -45,8 +45,7 @@ public sealed class ModelMeshCollection : ReadOnlyCollection<ModelMesh>

#region Internal Constructor

internal ModelMeshCollection(IList<ModelMesh> list)
: base(list)
internal ModelMeshCollection(IList<ModelMesh> list) : base(list)
{
}

Expand Down Expand Up @@ -85,4 +84,4 @@ public bool TryGetValue(string meshName, out ModelMesh value)

#endregion
}
}
}
20 changes: 10 additions & 10 deletions MonoGame.Framework/Graphics/ModelMeshPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ public Effect Effect
{
get
{
return _effect;
return INTERNAL_effect;
}
set
{
if (value == _effect)
if (value == INTERNAL_effect)
{
return;
}

if (_effect != null)
if (INTERNAL_effect != null)
{
// First check to see any other parts are also using this effect.
bool removeEffect = true;
foreach (ModelMeshPart part in parent.MeshParts)
{
if (part != this && part._effect == _effect)
if (part != this && part.INTERNAL_effect == INTERNAL_effect)
{
removeEffect = false;
break;
Expand All @@ -41,12 +41,12 @@ public Effect Effect

if (removeEffect)
{
parent.Effects.Remove(_effect);
parent.Effects.Remove(INTERNAL_effect);
}
}

// Set the new effect.
_effect = value;
INTERNAL_effect = value;
parent.Effects.Add(value);
}
}
Expand Down Expand Up @@ -141,9 +141,9 @@ internal int EffectIndex
#region Private Variables

/// <summary>
/// Gets or sets the material Effect for this mesh part. Reference page contains
/// code sample.
private Effect _effect;
/// Gets or sets the material Effect for this mesh part.
/// </summary>
private Effect INTERNAL_effect;

#endregion

Expand All @@ -153,4 +153,4 @@ internal int EffectIndex

#endregion
}
}
}
5 changes: 2 additions & 3 deletions MonoGame.Framework/Graphics/ModelMeshPartCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ namespace Microsoft.Xna.Framework.Graphics
{
public sealed class ModelMeshPartCollection : ReadOnlyCollection<ModelMeshPart>
{
public ModelMeshPartCollection(IList<ModelMeshPart> list)
: base(list)
public ModelMeshPartCollection(IList<ModelMeshPart> list) : base(list)
{
}
}
}
}
3 changes: 2 additions & 1 deletion MonoGame.Framework/Graphics/SpriteBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Microsoft.Xna.Framework.Graphics
{
// TODO: Rewrite from scratch using DynamicVertexBuffer/DynamicIndexBuffer. -flibit
public class SpriteBatch : GraphicsResource
{
#region Private Variables
Expand Down Expand Up @@ -731,7 +732,7 @@ void Setup()
_spritePass.Apply();

/* If the user supplied a custom effect then apply
* it now to override the sprite effect.
* it now to override the sprite effect.
*/
if (_effect != null)
{
Expand Down
20 changes: 9 additions & 11 deletions MonoGame.Framework/Graphics/SpriteBatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ namespace Microsoft.Xna.Framework.Graphics
/// </summary>
internal class SpriteBatcher
{
/*
* Note that this class is fundamental to high performance for SpriteBatch games. Please exercise
/* Note that this class is fundamental to high performance for SpriteBatch games. Please exercise
* caution when making changes to this class.
*/

Expand Down Expand Up @@ -206,15 +205,14 @@ private void EnsureArrayCapacity(int numBatchItems)
}
for (int i = start; i < numBatchItems; i += 1)
{
/*
* TL TR
* 0----1 0,1,2,3 = index offsets for vertex indices
* | /| TL,TR,BL,BR are vertex references in SpriteBatchItem.
* | / |
* | / |
* |/ |
* 2----3
* BL BR
/* TL TR
* 0----1 0,1,2,3 = index offsets for vertex indices
* | /| TL,TR,BL,BR are vertex references in SpriteBatchItem.
* | / |
* | / |
* |/ |
* 2----3
* BL BR
*/
// Triangle 1
newIndex[i * 6 + 0] = (short)(i * 4);
Expand Down
Loading

0 comments on commit 252b6b9

Please sign in to comment.