xna 4 contenet type reader problem

Started by
2 comments, last by Saeed Masoumi 11 years, 8 months ago
Hello everyone.I wrote code from XNA 3.0 Game Programming Recipes - "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):

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;
}
}
}

custom model processor (just will crawl through the whole model structure, generate a trinagle object)

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;
}
}
}

custom content type writer:

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;
}
}
}


and last one is custom content type reader:

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;
}
}
}

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.
Advertisement
Any suggestion!?
I found this and this im going to review them maybe i can solve this problem.
thanks again.
Nope.not working yet...
please someone help me!!!
Problem solved.just look at here.

This topic is closed to new replies.

Advertisement