Terek

Hi there!

the subject is my great problem... i doublechecked everything, but cant seem to find any solution... i consulted samples and tutorials, no luck.


what is wrong here what am i missing

the code :

velements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
new VertexElement(0, 24, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
new VertexElement(0, 36, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.BiNormal, 0),
new VertexElement(0, 48, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
VertexElement.VertexDeclarationEnd
};

Mesh mesh = Mesh.FromFile(location, MeshFlags.Managed, device);

Mesh tempmesh = mesh.Clone(MeshFlags.Managed, velements, device);

mesh.Dispose();

mesh = tempmesh;

// mesh.ComputeNormals();

// mesh.ComputeTangent(0, 0, 1, 0, adj);

mesh.ComputeTangentFrame( 0 );


thanks!


Re: Game Technologies: Graphics [c#] Mesh.ComputeTangentFrame throws InvalidDataException

Pieter Germishuys

The only problem that jumps to me is that you might want to move the texture coordinate element after the normal, cause usually you have Position, Normal, TextureCoordinate, Tangent and BiNormal.

I hope this helps.
Take care.




Re: Game Technologies: Graphics [c#] Mesh.ComputeTangentFrame throws InvalidDataException

Terek

thanks, but unfortunately thats not the problem, i was already that desperate to try that... :(

luckily i managed to find a workaround :

if i replace :
mesh.ComputeTangentFrame( 0 );

with :

mesh = Geometry.ComputeTangentFrame(mesh,
(int)DeclarationUsage.TextureCoordinate, 0,
(int)DeclarationUsage.Tangent, 0,
(int)DeclarationUsage.BiNormal, 0,
(int)DeclarationUsage.Normal, 0,
0, null, 0f, 0f, 0f,
out stream);


then it all works out. no stupid exception.
(with the same vertexdeclaration.. )

the only question is: if it works this way, why doesnt it work the other way




Re: Game Technologies: Graphics [c#] Mesh.ComputeTangentFrame throws InvalidDataException

Pieter Germishuys

Mmmm...
I have this sample code, which I used to test and it's working fine in the latest SDK which is December 2006.
Try it out and tell me if it works.
//Setting up the mesh
box = Mesh.FromFile("box.x", MeshFlags.Managed, renderer.Device);

//Compute tangents of the mesh
//Vertex elements that describe the new format of the mesh
VertexElement[] elements = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
new VertexElement(0, 24, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
new VertexElement(0, 36, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
new VertexElement(0, 48, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.BiNormal, 0),
VertexElement.VertexDeclarationEnd,
};
VertexDeclaration decl = new VertexDeclaration(renderer.Device, elements);
Mesh tempMesh = box.Clone(MeshFlags.Managed, elements, renderer.Device);
box.Dispose();
box = tempMesh;

/* Performs tangent frame computations on a mesh. Tangent, binormal, and optionally normal vectors are generated.
* Singularities are handled as required by grouping edges and splitting vertices.
*/
box.ComputeTangentFrame(0);

I hope this helps.
PS: I used a simple .x file I made using Blender.





Re: Game Technologies: Graphics [c#] Mesh.ComputeTangentFrame throws InvalidDataException

Terek

Huh, copypasted it, still doesn't work, still produced the same error.

I already studied the tutorial found on your page, trying to find what does that code work, and not mine...
but then an idea hit me... i tried my code with the .x file from that tutorial, and it worked!

So i think the problem lies within my .x files... i got one of them from reimers.net tutorials, and the other i made myself with 3ds max, and converted with the conv3ds tool from the dx toolkit.

at least now i know the code should work, but then... what can be wrong with my files



ps : im downloading blender right now. :)




Re: Game Technologies: Graphics [c#] Mesh.ComputeTangentFrame throws InvalidDataException

Pieter Germishuys

I would suggest that if you have 3dsmax going to look at Pandasoft's converters, they work extremely well and regularly get updated.

PandaSoft's DirectX Exporter

I hope this helps.
Take care.