Sign in to follow this  
Saeed Masoumi

xna 4 contenet type reader problem

Recommended Posts

Saeed Masoumi    110
Hello everyone.I wrote code from [i]XNA 3.0 Game Programming Recipes [/i]- "4-15. Gain Direct Access to Vertex Position Data
by Defining a Custom TypeWriter and TypeReader" in xna 3.1 and its totally worked for me.but now im using same way to write that code in xna 4 but its not working for me.i have problem in my custom content type reader , somewhere over the net i found answer that told i must have diffrent assemply for my content type reader but i still have same problem this is my code (have same assemlies):
Triangle class (custom content type):
[CODE]
using Microsoft.Xna.Framework;
namespace MyModelProcessor
{
public class Triangle
{
private Vector3[] _Vertices;

public Vector3[] Vertices
{
get { return _Vertices; }
}
public Vector3 Vertex1
{
get { return this._Vertices[0]; }
}
public Vector3 Vertex2
{
get { return this._Vertices[1]; }
}
public Vector3 Vertex3
{
get { return this._Vertices[2]; }
}
public Triangle(Vector3 Vertex1, Vector3 Vertex2, Vector3 Vertex3)
{
this._Vertices = new Vector3[3];
this._Vertices[0] = Vertex1;
this._Vertices[1] = Vertex2;
this._Vertices[2] = Vertex3;
}
}
}
[/CODE]
custom model processor (just will crawl through the whole model structure, generate a trinagle object)
[CODE]
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
namespace MyModelProcessor
{
[ContentProcessor(DisplayName = "MyModelProcessor")]
public class MyModelProcessor : ModelProcessor
{
public override ModelContent Process(NodeContent input, ContentProcessorContext context)
{
ModelContent UsualModel = base.Process(input, context);
List<Triangle> Triangles = new List<Triangle>(0);
Triangles = AddTrianglesToList(input, Triangles);
UsualModel.Tag = Triangles.ToArray();
return UsualModel;
}
private List<Triangle> AddTrianglesToList(NodeContent Node, List<Triangle> TrianglesList)
{
MeshContent Mesh = Node as MeshContent;
if (Mesh != null)
{
Matrix AbsTransform = Mesh.AbsoluteTransform;
foreach (GeometryContent Geo in Mesh.Geometry)
{
int trinagles = Geo.Indices.Count / 3;
for (int currentTriangle = 0; currentTriangle < trinagles; currentTriangle++)
{
int index0 = Geo.Indices[currentTriangle * 3 + 0];
int index1 = Geo.Indices[currentTriangle * 3 + 1];
int index2 = Geo.Indices[currentTriangle * 3 + 2];
Vector3 v0 = Geo.Vertices.Positions[index0];
Vector3 v1 = Geo.Vertices.Positions[index1];
Vector3 v2 = Geo.Vertices.Positions[index2];
Vector3 transv0 = Vector3.Transform(v0, AbsTransform);
Vector3 transv1 = Vector3.Transform(v1, AbsTransform);
Vector3 transv2 = Vector3.Transform(v2, AbsTransform);
Triangle newTriangle = new Triangle(transv0, transv1, transv2);
TrianglesList.Add(newTriangle);
}
}
}
foreach (NodeContent child in Node.Children)
{
TrianglesList = AddTrianglesToList(child, TrianglesList);
}
return TrianglesList;
}
}
}
[/CODE]
custom content type writer:
[CODE]
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Microsoft.Xna.Framework.Content.Pipeline;
namespace MyModelProcessor
{
[ContentTypeWriter]
class TriangleTypeWriter : ContentTypeWriter<Triangle>
{
protected override void Write(ContentWriter output, Triangle value)
{
output.WriteObject<Vector3>(value.Vertex1);
output.WriteObject<Vector3>(value.Vertex2);
output.WriteObject<Vector3>(value.Vertex3);
}
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return typeof(TriangleTypeReader).AssemblyQualifiedName;
}
}
}

[/CODE]
and last one is custom content type reader:
[CODE]
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
namespace MyModelProcessor
{
class TriangleTypeReader : ContentTypeReader<Triangle>
{
protected override Triangle Read(ContentReader input, Triangle existingInstance)
{
Vector3 Vertex1 = input.ReadObject<Vector3>();
Vector3 Vertex2 = input.ReadObject<Vector3>();
Vector3 Vertex3 = input.ReadObject<Vector3>();
Triangle newTriangle = new Triangle(Vertex1, Vertex2, Vertex3);
return newTriangle;
}
}
}
[/CODE]
but when i choose "MyModelProcessor" as content processor for my model (for exapmle "cube.fxb") i get this error:

Error loading "cube". Cannot find ContentTypeReader Microsoft.Xna.Framework.Content.ArrayReader`1[[MyModelProcessor.Triangle, MyModelProcessor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].

can someone show me how can i fix this problem?thanks a lot.

Share this post


Link to post
Share on other sites
Saeed Masoumi    110
Any suggestion!?
I found [url="http://blogs.msdn.com/b/shawnhar/archive/2008/11/24/content-pipeline-assemblies.aspx"]this[/url] and [url="http://create.msdn.com/en-US/education/catalog/sample/custom_model_class"]this[/url] im going to review them maybe i can solve this problem.
thanks again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this