XNA Game Development Forums
2012/05/21 19:53:23 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: 1 [2]
  Print  
Author Topic: Tranforming a model's vertices  (Read 6880 times)
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #15 on: 2007/07/23 13:30:03 »

The vertex positions you are getting from the buffer will be relative to the mesh's position.
Logged
DoomMarine
Newbie
*
Offline Offline

Posts: 24


View Profile
« Reply #16 on: 2007/07/23 14:34:17 »

the positions im getting i dont transfrom and they still get screwed up, i think i initialize the vertexpositiontexture[] and the short[] arrays wrong, how am i to get the total number of indices and vertices?
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #17 on: 2007/07/23 15:31:08 »

Right I have just had to pay with this, the position of the vert is relative to the position of the mesh, you don't have to translate it it's position is equal to mesh.position + vert.poition.

For example in the code I have just used it in I get the vertext positon like this:
Code:

                for (int side = 0; side < 6; side++)
                {
                    int off = side * 4;
                    Vector3[] thisPos = new Vector3[] { els[off + 0].Position + block.myPosition, els[off + 1].Position + block.myPosition, els[off + 2].Position + block.myPosition, els[off + 3].Position + block.myPosition };
                ... more code ...

So to get at the position of a vert in a given primitive I can use
Code:
    VertPos = thisPos[3];

Which will live me position of the forth vert in the vertex buffer relative to the location of the mesh.
Logged
DoomMarine
Newbie
*
Offline Offline

Posts: 24


View Profile
« Reply #18 on: 2007/07/23 19:33:10 »

i dont think u have understood my question, when i use this code
Code:
VertexPositionTexture[] myverts = new VertexPositionTexture[mesh.VertexBuffer.SizeInBytes / mesh.MeshParts[0].VertexStride];
               
               
                mesh.VertexBuffer.GetData<VertexPositionTexture>(myverts);
                if (mesh.IndexBuffer.IndexElementSize == IndexElementSize.SixteenBits)
                {
                    short[] myinds = new short[mesh.IndexBuffer.SizeInBytes / sizeof(short)];
                    mesh.IndexBuffer.GetData<short>(myinds);
                    for (int i = 0; i < myinds.Length; i += 3)
                    {
                        mylist.Add(ProcessMeshTrianglesShort(myverts, i, myinds));
                    }
                }
               
                if (mesh.IndexBuffer.IndexElementSize == IndexElementSize.ThirtyTwoBits)
                {
                    int[] myinds = new int[mesh.IndexBuffer.SizeInBytes / sizeof(int)];
                    mesh.IndexBuffer.GetData<int>(myinds);
                    for (int i = 0; i < myinds.Length; i += 3)
                    {
                        mylist.Add(ProcessMeshTrianglesInt(myverts, i, myinds));
                    }
                }
i need to find a number for the total number in the arrays to make it like this
Code:
int[] myinds = new int[mesh.IndexBuffer.SizeInBytes / sizeof(int)];

i was wondering i got the correct number to put in each array and which way it was actually supposed to be done
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #19 on: 2007/07/24 01:00:10 »

Yes, it looks like I have totally missed the point!

Why are you using the index buffer??

When getting the vertexbuffer I used this calculation
Code:
                VertexPositionNormalTexture[] els = new VertexPositionNormalTexture[4 * 6];
                block.blockMesh.Meshes[0].VertexBuffer.GetData<VertexPositionNormalTexture>(els);

The object is a simple cube so has 6 sides and each side is made from 4 Verts, so the array size will be 4*6.  It should be the same for the index buffer. I guess you need to know how many primitives are in your mesh to do this. When I have time I will see if I can find out how you can do this. Maybe the new Picking sample on the Creators club could help you?
Logged
DoomMarine
Newbie
*
Offline Offline

Posts: 24


View Profile
« Reply #20 on: 2007/07/24 05:37:50 »

i am currently trying to get each meshpart in the mesh and find the value of its primitive count, adding to the mesh's "totalprimcount" but that number multiplied by 3 or just by itslef doesnt seem to work.

EDIT:
I just remembered that a meshpart also stores a number of vertices for itself and getting each number and adding together seems to work.
« Last Edit: 2007/07/24 05:41:52 by DoomMarine » Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #21 on: 2007/07/24 05:50:49 »

Oh good, so have you solved your issue?
Logged
DoomMarine
Newbie
*
Offline Offline

Posts: 24


View Profile
« Reply #22 on: 2007/07/24 08:53:01 »

no the issue is still there. when i compare the mesh data i tagged to the mesh with the triangles made from the vertex buffer some of the vertices positions dont match up, and i still get the same results as i did before i got rid of the index buffer. I wonder iff there is some sort of offset that needs to be applied to the positions to get the real ones, although in both the mesh data and vertexbuffer data the 1st vertex has the same coordinate.

EDIT: ive also compared the total number of vertices stored in the mesh data to the vertices i got from the vertex buffer and they dont match, so i gettin the total number of vertices doesnt seem to work.

EDIT: i have initialized the vertexposition texture i use in a different way and the total numbers match up but the positions are wrong now and it has nothing to do with the transformation of the vertices.
« Last Edit: 2007/07/24 15:13:58 by DoomMarine » Logged
DoomMarine
Newbie
*
Offline Offline

Posts: 24


View Profile
« Reply #23 on: 2007/07/24 17:43:07 »

ok i found the problem with the vertex buffer data, i need to use the 3rd overload of GetData to get the right results, now i am back to the simple problem of transformation, i can now change the position of the object and rotate it but scaling screws it up. This is without using the meshes parent bone transform though so that may have something to do with it. any help would be appreciated.
Logged
Nemo Krad
Global Moderator
Hero Member
*****
Offline Offline

Posts: 512


I have seen the fnords


View Profile WWW
« Reply #24 on: 2007/07/25 00:56:59 »

Sorry mate, I think this is a little out of my depth at the moment, if I find anything to help I will post it here.
Logged
DoomMarine
Newbie
*
Offline Offline

Posts: 24


View Profile
« Reply #25 on: 2007/08/01 15:46:52 »

ok i think that the problem with the scaling has something to do with the bones of the model. how exactly would u calculate the child bones transform from the parents i assumed it was something like actualTrans = storedTrans * parentTrans but im not sure.
Logged
DoomMarine
Newbie
*
Offline Offline

Posts: 24


View Profile
« Reply #26 on: 2007/08/26 18:07:28 »

ok so i take it no one else can help me out?
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #27 on: 2007/08/27 01:21:00 »

This would depend on the transform type. Translations would be child + parent, scaling would be child * parent, and rotation (since we are using quaternions) would be something like child x parent (that's a cross, as in cross product)
Logged
DoomMarine
Newbie
*
Offline Offline

Posts: 24


View Profile
« Reply #28 on: 2007/08/27 10:41:46 »

so your saying that i should do it manually instead of using vector3.transform?
Logged
DoomMarine
Newbie
*
Offline Offline

Posts: 24


View Profile
« Reply #29 on: 2007/08/28 05:15:34 »

ok i tried to do this only noticing that i have no idea where the bones scaling position and rotations are stored if they are at all, and im not sure thast would help the problem anyways since it is just the scaling of the collision mesh thats the problem
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Tut 6: Model Class Hazy Mind XNA Engine MicahN 2 2258 Last post 2006/11/15 09:43:47
by MicahN
Tutorial 6 :: Getting a Model on Screen Tutorial Discussion mikeschuld 11 5587 Last post 2007/02/18 10:35:28
by Iarus
How To: Render a model with a texture?? Hazy Mind XNA Engine Quinn 6 2324 Last post 2007/01/07 00:33:58
by mikeschuld
Detecting Model Collision...? General Discussion « 1 2 » DaphydTheBard 15 4291 Last post 2007/03/27 01:29:52
by Nemo Krad
I can't see anything on tutorial 4 More Rendering, Vertices and Indexes Hazy Mind 3D Engine moonsvista 5 2906 Last post 2007/03/30 14:37:05
by moonsvista
Model & Shader Problems Hazy Mind XNA Engine Themodem 5 2070 Last post 2007/03/26 11:12:53
by Tiago
Model exporters General Discussion EclipsE 13 3719 Last post 2007/04/26 12:25:03
by EclipsE
Loading a model in runtime? General Discussion XNASorcerer 10 3311 Last post 2007/05/06 21:22:42
by XNASorcerer
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.192 seconds with 18 queries.