Working on ModelMesh, ModelMeshCollection, ModelMeshPart and ModelMeshPartCollection tests

This commit is contained in:
SND\AstrorEnales_cp 2012-10-21 19:49:04 +00:00 committed by Konstantin Koch
parent 6c488dbca5
commit bb4f7ccf2e
12 changed files with 288 additions and 98 deletions

View File

@ -80,6 +80,8 @@
<Compile Include="Strukturen\Graphics\ModelEffectCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelEffectCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelMeshCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshPartCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelMeshPartCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshPartTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshTest.cs" />
<Compile Include="Strukturen\Graphics\SamplerStateCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\SamplerStateCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\VertexPositionNormalTextureTest.cs" /> <Compile Include="Strukturen\Graphics\VertexPositionNormalTextureTest.cs" />
<Compile Include="Strukturen\Graphics\VertexPositionColorTextureTest.cs" /> <Compile Include="Strukturen\Graphics\VertexPositionColorTextureTest.cs" />

View File

@ -80,6 +80,8 @@
<Compile Include="Strukturen\Graphics\ModelEffectCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelEffectCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelMeshCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshPartCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelMeshPartCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshPartTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshTest.cs" />
<Compile Include="Strukturen\Graphics\SamplerStateCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\SamplerStateCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\VertexPositionNormalTextureTest.cs" /> <Compile Include="Strukturen\Graphics\VertexPositionNormalTextureTest.cs" />
<Compile Include="Strukturen\Graphics\VertexPositionColorTextureTest.cs" /> <Compile Include="Strukturen\Graphics\VertexPositionColorTextureTest.cs" />

View File

@ -81,6 +81,8 @@
<Compile Include="Strukturen\Graphics\ModelEffectCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelEffectCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelMeshCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshPartCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelMeshPartCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshPartTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshTest.cs" />
<Compile Include="Strukturen\Graphics\SamplerStateCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\SamplerStateCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\VertexPositionNormalTextureTest.cs" /> <Compile Include="Strukturen\Graphics\VertexPositionNormalTextureTest.cs" />
<Compile Include="Strukturen\Graphics\VertexPositionColorTextureTest.cs" /> <Compile Include="Strukturen\Graphics\VertexPositionColorTextureTest.cs" />

View File

@ -82,6 +82,8 @@
<Compile Include="Strukturen\Graphics\ModelEffectCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelEffectCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelMeshCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshPartCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\ModelMeshPartCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshPartTest.cs" />
<Compile Include="Strukturen\Graphics\ModelMeshTest.cs" />
<Compile Include="Strukturen\Graphics\SamplerStateCollectionTest.cs" /> <Compile Include="Strukturen\Graphics\SamplerStateCollectionTest.cs" />
<Compile Include="Strukturen\Graphics\VertexPositionNormalTextureTest.cs" /> <Compile Include="Strukturen\Graphics\VertexPositionNormalTextureTest.cs" />
<Compile Include="Strukturen\Graphics\VertexPositionColorTextureTest.cs" /> <Compile Include="Strukturen\Graphics\VertexPositionColorTextureTest.cs" />

View File

@ -1,4 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using ANX.Framework.Graphics;
using NUnit.Framework;
using XNAModelMesh = Microsoft.Xna.Framework.Graphics.ModelMesh;
using XNAModelMeshCollection = Microsoft.Xna.Framework.Graphics.ModelMeshCollection;
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -8,5 +16,73 @@ namespace ANX.Framework.TestCenter.Strukturen.Graphics
{ {
class ModelMeshCollectionTest class ModelMeshCollectionTest
{ {
[Test]
public void Constructor()
{
XNAModelMeshCollection xna;
ModelMeshCollection anx;
CreateCollections(out xna, out anx);
Assert.AreEqual(xna.Count, anx.Count);
}
[Test]
public void AccessorArgumentNull()
{
XNAModelMeshCollection xna;
ModelMeshCollection anx;
CreateCollections(out xna, out anx);
TestDelegate xnaDeleg = delegate { XNAModelMesh xnaMesh = xna[""]; };
TestDelegate anxDeleg = delegate { ModelMesh anxMesh = anx[""]; };
AssertHelper.ConvertEquals(Assert.Throws<ArgumentNullException>(xnaDeleg),
Assert.Throws<ArgumentNullException>(anxDeleg), "AccessorArgumentNull");
}
[Test]
public void AccessorKeyNotFound()
{
XNAModelMeshCollection xna;
ModelMeshCollection anx;
CreateCollections(out xna, out anx);
TestDelegate xnaDeleg = delegate { XNAModelMesh xnaMesh = xna["test"]; };
TestDelegate anxDeleg = delegate { ModelMesh anxMesh = anx["test"]; };
AssertHelper.ConvertEquals(Assert.Throws<KeyNotFoundException>(xnaDeleg),
Assert.Throws<KeyNotFoundException>(anxDeleg), "AccessorKeyNotFound");
}
[Test]
public void Accessor()
{
XNAModelMeshCollection xna;
ModelMeshCollection anx;
CreateCollections(out xna, out anx);
XNAModelMesh xnaMesh = xna["mesh1"];
ModelMesh anxMesh = anx["mesh1"];
Assert.AreEqual(xnaMesh.Name, anxMesh.Name);
Assert.AreEqual(xnaMesh.Tag, anxMesh.Tag);
Assert.AreEqual(xnaMesh.ParentBone, anxMesh.ParentBone);
Assert.AreEqual(xnaMesh.MeshParts.Count, anxMesh.MeshParts.Count);
AssertHelper.ConvertEquals(xnaMesh.BoundingSphere, anxMesh.BoundingSphere, "Accessor");
}
private void CreateCollections(out XNAModelMeshCollection xna, out ModelMeshCollection anx)
{
XNAModelMesh xnaMesh;
ModelMesh anxMesh;
ModelMeshTest.CreateMeshes(out xnaMesh, out anxMesh);
var xnaParameters = new object[] { new[] { xnaMesh } };
xna = (XNAModelMeshCollection)Activator.CreateInstance(typeof(XNAModelMeshCollection),
BindingFlags.NonPublic | BindingFlags.Instance, null, xnaParameters, CultureInfo.InvariantCulture);
var anxParameters = new object[] { new[] { anxMesh } };
anx = (ModelMeshCollection)Activator.CreateInstance(typeof(ModelMeshCollection),
BindingFlags.NonPublic | BindingFlags.Instance, null, anxParameters, CultureInfo.InvariantCulture);
}
} }
} }

View File

@ -1,4 +1,11 @@
using System; using System;
using System.Globalization;
using System.Reflection;
using ANX.Framework.Graphics;
using NUnit.Framework;
using XNAModelMeshPart = Microsoft.Xna.Framework.Graphics.ModelMeshPart;
using XNAModelMeshPartCollection = Microsoft.Xna.Framework.Graphics.ModelMeshPartCollection;
// This file is part of the ANX.Framework created by the // This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license. // "ANX.Framework developer group" and released under the Ms-PL license.
@ -8,5 +15,28 @@ namespace ANX.Framework.TestCenter.Strukturen.Graphics
{ {
class ModelMeshPartCollectionTest class ModelMeshPartCollectionTest
{ {
[Test]
public void Constructor()
{
XNAModelMeshPartCollection xna;
ModelMeshPartCollection anx;
CreateCollections(out xna, out anx);
Assert.AreEqual(xna.Count, anx.Count);
}
private void CreateCollections(out XNAModelMeshPartCollection xna, out ModelMeshPartCollection anx)
{
XNAModelMeshPart xnaMesh;
ModelMeshPart anxMesh;
ModelMeshPartTest.CreateMeshes(out xnaMesh, out anxMesh);
var xnaParameters = new object[] { new[] { xnaMesh } };
xna = (XNAModelMeshPartCollection)Activator.CreateInstance(typeof(XNAModelMeshPartCollection),
BindingFlags.NonPublic | BindingFlags.Instance, null, xnaParameters, CultureInfo.InvariantCulture);
var anxParameters = new object[] { new[] { anxMesh } };
anx = (ModelMeshPartCollection)Activator.CreateInstance(typeof(ModelMeshPartCollection),
BindingFlags.NonPublic | BindingFlags.Instance, null, anxParameters, CultureInfo.InvariantCulture);
}
} }
} }

View File

@ -0,0 +1,42 @@
using System;
using System.Globalization;
using System.Reflection;
using ANX.Framework.Graphics;
using NUnit.Framework;
using XNAModelMeshPart = Microsoft.Xna.Framework.Graphics.ModelMeshPart;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.TestCenter.Strukturen.Graphics
{
class ModelMeshPartTest
{
[Test]
public void Constructor()
{
XNAModelMeshPart xna;
ModelMeshPart anx;
CreateMeshes(out xna, out anx);
Assert.AreEqual(xna.StartIndex, anx.StartIndex);
Assert.AreEqual(xna.Tag, anx.Tag);
Assert.AreEqual(xna.VertexOffset, anx.VertexOffset);
Assert.AreEqual(xna.PrimitiveCount, anx.PrimitiveCount);
Assert.AreEqual(xna.NumVertices, anx.NumVertices);
}
public static void CreateMeshes(out XNAModelMeshPart xna, out ModelMeshPart anx)
{
var parameters = new object[] { 4, 64, 0, 20, 777 };
xna = (XNAModelMeshPart)Activator.CreateInstance(typeof(XNAModelMeshPart),
BindingFlags.NonPublic | BindingFlags.Instance, null, parameters, CultureInfo.InvariantCulture);
anx = (ModelMeshPart)Activator.CreateInstance(typeof(ModelMeshPart),
BindingFlags.NonPublic | BindingFlags.Instance, null, parameters, CultureInfo.InvariantCulture);
}
}
}

View File

@ -0,0 +1,60 @@
using System;
using System.Globalization;
using System.Reflection;
using ANX.Framework.Graphics;
using NUnit.Framework;
using XNAModelMesh = Microsoft.Xna.Framework.Graphics.ModelMesh;
using XNAModelMeshPart = Microsoft.Xna.Framework.Graphics.ModelMeshPart;
using XNABoundingSphere = Microsoft.Xna.Framework.BoundingSphere;
using XNAVector3 = Microsoft.Xna.Framework.Vector3;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.TestCenter.Strukturen.Graphics
{
class ModelMeshTest
{
[Test]
public void Constructor()
{
XNAModelMesh xna;
ModelMesh anx;
CreateMeshes(out xna, out anx);
Assert.AreEqual(xna.Name, anx.Name);
Assert.AreEqual(xna.Tag, anx.Tag);
Assert.AreEqual(xna.ParentBone, anx.ParentBone);
Assert.AreEqual(xna.MeshParts.Count, anx.MeshParts.Count);
Assert.AreEqual(xna.Effects.Count, anx.Effects.Count);
AssertHelper.ConvertEquals(xna.BoundingSphere, anx.BoundingSphere, "Constructor");
}
public static void CreateMeshes(out XNAModelMesh xna, out ModelMesh anx)
{
var xnaParameters = new object[]
{
"mesh1",
null,
new XNABoundingSphere(XNAVector3.UnitY, 2f),
new XNAModelMeshPart[0],
17
};
xna = (XNAModelMesh)Activator.CreateInstance(typeof(XNAModelMesh),
BindingFlags.NonPublic | BindingFlags.Instance, null, xnaParameters, CultureInfo.InvariantCulture);
var anxParameters = new object[]
{
"mesh1",
null,
new BoundingSphere(Vector3.UnitY, 2f),
new ModelMeshPart[0],
17
};
anx = (ModelMesh)Activator.CreateInstance(typeof(ModelMesh),
BindingFlags.NonPublic | BindingFlags.Instance, null, anxParameters, CultureInfo.InvariantCulture);
}
}
}

View File

@ -1,7 +1,5 @@
#region Using Statements #region Using Statements
using System; using System;
using System.Collections;
using System.Collections.Generic;
using ANX.Framework.NonXNA.Development; using ANX.Framework.NonXNA.Development;
#endregion // Using Statements #endregion // Using Statements
@ -14,10 +12,10 @@ namespace ANX.Framework.Graphics
{ {
[PercentageComplete(100)] [PercentageComplete(100)]
[Developer("Glatzemann")] [Developer("Glatzemann")]
[TestState(TestStateAttribute.TestState.Untested)] [TestState(TestStateAttribute.TestState.InProgress)]
public sealed class ModelMesh public sealed class ModelMesh
{ {
private BoundingSphere boundingSphere; private readonly BoundingSphere boundingSphere;
public BoundingSphere BoundingSphere public BoundingSphere BoundingSphere
{ {
@ -30,7 +28,7 @@ namespace ANX.Framework.Graphics
public ModelBone ParentBone { get; private set; } public ModelBone ParentBone { get; private set; }
public object Tag { get; set; } public object Tag { get; set; }
public ModelMesh(string name, ModelBone bone, BoundingSphere sphere, ModelMeshPart[] meshParts, Object tag) internal ModelMesh(string name, ModelBone bone, BoundingSphere sphere, ModelMeshPart[] meshParts, Object tag)
{ {
this.Name = name; this.Name = name;
this.ParentBone = bone; this.ParentBone = bone;
@ -42,10 +40,8 @@ namespace ANX.Framework.Graphics
foreach (var item in this.MeshParts) foreach (var item in this.MeshParts)
{ {
item.parentMesh = this; item.parentMesh = this;
if (item.Effect != null && !this.Effects.Contains(item.Effect)) if (item.Effect != null && Effects.Contains(item.Effect) == false)
{ Effects.Add(item.Effect);
this.Effects.Add(item.Effect);
}
} }
} }
@ -56,31 +52,21 @@ namespace ANX.Framework.Graphics
foreach (var item in MeshParts) foreach (var item in MeshParts)
{ {
if (object.ReferenceEquals(item, part)) if (ReferenceEquals(item, part))
{
continue; continue;
}
if (object.ReferenceEquals(item.Effect, oldEffect)) if (ReferenceEquals(item.Effect, oldEffect))
{
oldEffectIsInUse = true; oldEffectIsInUse = true;
}
if (object.ReferenceEquals(item.Effect, newEffect)) if (ReferenceEquals(item.Effect, newEffect))
{
newEffectIsKnown = true; newEffectIsKnown = true;
}
} }
if (oldEffect != null && !oldEffectIsInUse) if (oldEffect != null && !oldEffectIsInUse)
{
Effects.Remove(oldEffect); Effects.Remove(oldEffect);
}
if (newEffect != null && !newEffectIsKnown) if (newEffect != null && !newEffectIsKnown)
{
Effects.Add(newEffect); Effects.Add(newEffect);
}
} }
public void Draw() public void Draw()
@ -94,7 +80,8 @@ namespace ANX.Framework.Graphics
GraphicsDevice graphics = part.VertexBuffer.GraphicsDevice; GraphicsDevice graphics = part.VertexBuffer.GraphicsDevice;
graphics.SetVertexBuffer(part.VertexBuffer, part.VertexOffset); graphics.SetVertexBuffer(part.VertexBuffer, part.VertexOffset);
graphics.Indices = part.IndexBuffer; graphics.Indices = part.IndexBuffer;
graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, part.NumVertices, part.StartIndex, part.PrimitiveCount); graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, part.NumVertices, part.StartIndex,
part.PrimitiveCount);
} }
} }
} }

View File

@ -15,70 +15,29 @@ namespace ANX.Framework.Graphics
{ {
[PercentageComplete(100)] [PercentageComplete(100)]
[Developer("Glatzemann, AstrorEnales")] [Developer("Glatzemann, AstrorEnales")]
[TestState(TestStateAttribute.TestState.InProgress)] [TestState(TestStateAttribute.TestState.Tested)]
public sealed class ModelMeshCollection : ReadOnlyCollection<ModelMesh> public sealed class ModelMeshCollection : ReadOnlyCollection<ModelMesh>
{ {
private readonly ModelMesh[] modelMeshes; private readonly ModelMesh[] modelMeshes;
public ModelMesh this[string meshName]
{
get
{
ModelMesh result;
if (TryGetValue(meshName, out result) == false)
throw new KeyNotFoundException();
return result;
}
}
internal ModelMeshCollection(ModelMesh[] modelMeshes) internal ModelMeshCollection(ModelMesh[] modelMeshes)
: base(modelMeshes) : base(modelMeshes)
{ {
this.modelMeshes = modelMeshes; this.modelMeshes = modelMeshes;
} }
public new Enumerator GetEnumerator()
{
return new Enumerator(this.modelMeshes);
}
public struct Enumerator : IEnumerator<ModelMesh>, IDisposable, IEnumerator
{
private readonly ModelMesh[] wrappedArray;
private int position;
internal Enumerator(ModelMesh[] wrappedArray)
{
this.wrappedArray = wrappedArray;
this.position = -1;
}
public ModelMesh Current
{
get
{
return this.wrappedArray[this.position];
}
}
public bool MoveNext()
{
this.position++;
if (this.position >= this.wrappedArray.Length)
{
this.position = this.wrappedArray.Length;
return false;
}
return true;
}
void IEnumerator.Reset()
{
this.position = -1;
}
public void Dispose()
{
}
object IEnumerator.Current
{
get
{
return this.Current;
}
}
}
public bool TryGetValue(string meshName, out ModelMesh value) public bool TryGetValue(string meshName, out ModelMesh value)
{ {
if (String.IsNullOrEmpty(meshName)) if (String.IsNullOrEmpty(meshName))
@ -98,16 +57,50 @@ namespace ANX.Framework.Graphics
return false; return false;
} }
public ModelMesh this[string meshName] public new Enumerator GetEnumerator()
{ {
get return new Enumerator(this.modelMeshes);
}
public struct Enumerator : IEnumerator<ModelMesh>, IDisposable, IEnumerator
{
private readonly ModelMesh[] wrappedArray;
private int position;
public ModelMesh Current
{ {
ModelMesh result; get { return this.wrappedArray[this.position]; }
if (TryGetValue(meshName, out result) == false) }
object IEnumerator.Current
{
get { return this.Current; }
}
internal Enumerator(ModelMesh[] wrappedArray)
{
this.wrappedArray = wrappedArray;
this.position = -1;
}
public bool MoveNext()
{
this.position++;
if (this.position >= this.wrappedArray.Length)
{ {
throw new KeyNotFoundException(); this.position = this.wrappedArray.Length;
return false;
} }
return result; return true;
}
void IEnumerator.Reset()
{
this.position = -1;
}
public void Dispose()
{
} }
} }
} }

View File

@ -12,7 +12,7 @@ namespace ANX.Framework.Graphics
{ {
[PercentageComplete(100)] [PercentageComplete(100)]
[Developer("Glatzemann")] [Developer("Glatzemann")]
[TestState(TestStateAttribute.TestState.Untested)] [TestState(TestStateAttribute.TestState.InProgress)]
public sealed class ModelMeshPart public sealed class ModelMeshPart
{ {
#region Private #region Private

View File

@ -33,21 +33,15 @@ namespace ANX.Framework.Graphics
private readonly ModelMeshPart[] wrappedArray; private readonly ModelMeshPart[] wrappedArray;
private int position; private int position;
public ModelMeshPart Current public ModelMeshPart Current
{ {
get get { return this.wrappedArray[this.position]; }
{ }
return this.wrappedArray[this.position];
}
}
object IEnumerator.Current object IEnumerator.Current
{ {
get get { return this.Current; }
{ }
return this.Current;
}
}
internal Enumerator(ModelMeshPart[] wrappedArray) internal Enumerator(ModelMeshPart[] wrappedArray)
{ {