Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 04:30

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[?] Writing Vertex and Index data to mesh.

Discussion on [?] Writing Vertex and Index data to mesh. within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
sozoku's Avatar
 
elite*gold: 3
Join Date: Dec 2010
Posts: 370
Received Thanks: 974
Post [?] Writing Vertex and Index data to mesh.


Mesh ends up with incorrect/null values. What is wrong/what isnt there?

Really would appreciate some help, getting headaches from filling a ID3DXMesh.


Sozo/Moot.
sozoku is offline  
Old 07/22/2012, 16:15   #2
 
Tyrar's Avatar
 
elite*gold: 0
Join Date: Oct 2008
Posts: 1,637
Received Thanks: 1,119
invalid vertex format?
Tyrar is offline  
Old 07/22/2012, 21:44   #3
 
sozoku's Avatar
 
elite*gold: 3
Join Date: Dec 2010
Posts: 370
Received Thanks: 974
Quote:
Originally Posted by HeavyHacker View Post
invalid vertex format?
Im pretty sure the vertex format isn't the problem as I created the mesh with the same FVF as the vertices being copied.

Edit:
It came up like this, so it maybe a pointer thing when using memcpy.
Quote:
Mesh {
32;
12.619567;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
0.000000;0.000000;0.000000;,
sozoku is offline  
Old 07/23/2012, 16:18   #4
 
elite*gold: 0
Join Date: Jun 2012
Posts: 187
Received Thanks: 58
looks like you are trying to copy data from a dynamic array. dynamic arrays are stored as pointers and their data do not necessarily have to be appended to eachother, meaning each element is stored 'somewhere randomly' in memory and your copy function expects all elements to be at "element1 + sizeof(element) * elementindex". use constant arrays instead.
tnd0 is offline  
Old 07/23/2012, 17:06   #5
 
sozoku's Avatar
 
elite*gold: 3
Join Date: Dec 2010
Posts: 370
Received Thanks: 974
Quote:
Originally Posted by tnd0 View Post
looks like you are trying to copy data from a dynamic array. dynamic arrays are stored as pointers and their data do not necessarily have to be appended to eachother, meaning each element is stored 'somewhere randomly' in memory and your copy function expects all elements to be at "element1 + sizeof(element) * elementindex". use constant arrays instead.
Epvp was down a bit last night so I didn't get to update.

Well I have half solved the problem, quite similar to what you said but then again not much, it was something to do with

This works on an off. So what your saying about it needing it to be constant makes most sense. Thanks for that going to try that now.

Edit: Seems like that I'm short of knowledge to pursue what you advise. :U
Edit2: I'm also seeing that I'm taking account the offset to the start of the stream, which I've fixed. And also relating to what you have said, when locking data, do I need to take into account flags to achieve constant void?
Edit3: So far:


Now for some reason I'm crashing.
Edit4:
Got it to stop crashing by just adding a & before vb. But as I get the mesh, I can help but feel that the vertices are inverted in some way. Maybe relating to the indices.
<-- What is supposed to be a ring.
sozoku is offline  
Old 07/23/2012, 17:52   #6
 
elite*gold: 0
Join Date: Jun 2012
Posts: 187
Received Thanks: 58
show how you fill the Vertex and Index arrays. and stop using screenshots, there's a [ CODE] tag for that.
tnd0 is offline  
Old 07/23/2012, 17:58   #7
 
sozoku's Avatar
 
elite*gold: 3
Join Date: Dec 2010
Posts: 370
Received Thanks: 974
Code:
pDevice->GetFVF(&ppFVF);
				D3DXCreateMeshFVF(primCount,NumVertices,0,ppFVF,pDevice,&mesh); //D3DXMESH_SYSTEMMEM
				pDevice->GetStreamSource(0,&ppStreamData,&poffsetinbytes,&pstride);
				pDevice->GetIndices(&ppIndexData);
				
				ppStreamData->GetDesc(&pDescv);
				mesh->LockVertexBuffer( 0, &VertexPtr );
				ppStreamData->Lock(poffsetinbytes,pDescv.Size, (void**)&Vb,0); //ppStreamData->Lock(poffsetinbytes,pDescv.Size, (void**)Vb,0);
				memcpy( VertexPtr, Vb, (size_t)NumVertices * pstride );
				mesh->UnlockVertexBuffer();
				ppStreamData->Unlock();

				ppIndexData->GetDesc(&pDesc);
				UINT size = (pDesc.Format == D3DFMT_INDEX32) ? sizeof( UINT ) : sizeof( USHORT );
				mesh->LockIndexBuffer( 0, &IndexPtr );
				ppIndexData->Lock(0,pDesc.Size, &Ib,0); //ppIndexData->Lock(0,pDesc.Size,(void**)Ib,0);
				memcpy( IndexPtr, Ib, (size_t)NumVertices * size );
				mesh->UnlockIndexBuffer();
				ppIndexData->Unlock();
Technically, I'm getting vertex and index data from the current stream via a DIP hook and filter... :|
sozoku is offline  
Old 07/23/2012, 19:14   #8
 
elite*gold: 0
Join Date: Jun 2012
Posts: 187
Received Thanks: 58
I was asking how you fill your 'Vb' and 'Ib' var. post more source, i cant help you with that information.
tnd0 is offline  
Old 07/23/2012, 19:26   #9
 
sozoku's Avatar
 
elite*gold: 3
Join Date: Dec 2010
Posts: 370
Received Thanks: 974
Quote:
Originally Posted by tnd0 View Post
I was asking how you fill your 'Vb' and 'Ib' var. post more source, i cant help you with that information.
I dont think you understand. Its getting vb and ib from a drawindexedprimitive call.
sozoku is offline  
Old 07/23/2012, 19:26   #10


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,904
Received Thanks: 25,394
Quote:
Originally Posted by tnd0 View Post
looks like you are trying to copy data from a dynamic array. dynamic arrays are stored as pointers and their data do not necessarily have to be appended to eachother, meaning each element is stored 'somewhere randomly' in memory and your copy function expects all elements to be at "element1 + sizeof(element) * elementindex". use constant arrays instead.
Wat?
MrSm!th is offline  
Thanks
1 User
Old 07/23/2012, 20:04   #11
 
elite*gold: 0
Join Date: Jun 2012
Posts: 187
Received Thanks: 58
Quote:
Originally Posted by MrSm!th View Post
Wat?
Imagine you have 2 arrays, a dynamic and a static one, both arrays of integer.



first line: integer(&SomeStaticArray) = 0x00423EDC
second line: integer(&SomeDynamicArray) = 0x00423EEC
third line: integer(&SomeDynamicArray[0]) = 0x0063C2A8

now imagine you want to copy those data to your GPU memory via memcpy. what does memcopy? you pass 2 pointers, your source and your destination and the length. copying the static array with a pointer to the array is fine because the data are all located there. copying the dynamic array by passing a pointer to it, you will only copy the pointer to the first element and then some zero's if you're lucky, or get an AV else.

thats the difference.

Quote:
I dont think you understand. Its getting vb and ib from a drawindexedprimitive call.
you dont want my help, do ya? the code you posted looks fine as far as one can tell, unless your variables are set up wrong, which I cant tell because I dont see how you fill your buffers. drawindexedprimitve does not fill a buffer, it takes a pointer to a dxstruct which gets passed to the gpu. if you hooked it and grabbed that buffer, it looks like you only grabbed the pointer so you gotta read what that pointer points to.
tnd0 is offline  
Thanks
1 User
Old 07/23/2012, 20:22   #12
 
sozoku's Avatar
 
elite*gold: 3
Join Date: Dec 2010
Posts: 370
Received Thanks: 974
Quote:
Originally Posted by tnd0 View Post
Imagine you have 2 arrays, a dynamic and a static one, both arrays of integer.



first line: integer(&SomeStaticArray) = 0x00423EDC
second line: integer(&SomeDynamicArray) = 0x00423EEC
third line: integer(&SomeDynamicArray[0]) = 0x0063C2A8

now imagine you want to copy those data to your GPU memory via memcpy. what does memcopy? you pass 2 pointers, your source and your destination and the length. copying the static array with a pointer to the array is fine because the data are all located there. copying the dynamic array by passing a pointer to it, you will only copy the pointer to the first element and then some zero's if you're lucky, or get an AV else.

thats the difference.



you dont want my help, do ya? the code you posted looks fine as far as one can tell, unless your variables are set up wrong, which I cant tell because I dont see how you fill your buffers. drawindexedprimitve does not fill a buffer, it takes a pointer to a dxstruct which gets passed to the gpu. if you hooked it and grabbed that buffer, it looks like you only grabbed the pointer so you gotta read what that pointer points to.
" it looks like you only grabbed the pointer so you gotta read what that pointer points to." Seems so.

"you dont want my help, do ya?" Who said that? I just said that I haven't got anything relating to it in my code beyond that point.

In terms of variables :
Code:
D3DINDEXBUFFER_DESC *pIDesc;
D3DVERTEXBUFFER_DESC *pVDesc;
D3DMATERIAL9* pMaterials=NULL; 
LPD3DXBUFFER materialBuffer;
DWORD numMaterials;
ID3DXMesh* mesh;
IDirect3DIndexBuffer9* ppIndexData;
IDirect3DVertexBuffer9* ppStreamData;
LPDIRECT3DVERTEXBUFFER9 m_vb;
LPDIRECT3DINDEXBUFFER9 m_ib;
DWORD meshstride;
DWORD numvert;
DWORD numfaces;
LPVOID *ppbData=NULL;
BYTE* pVertices=NULL;
DWORD ppFVF;
UINT poffsetinbytes; 
UINT pstride;
LPVOID VertexPtr;
LPVOID IndexPtr;
const void *Ib;
const void *Vb;
D3DINDEXBUFFER_DESC pDesc;
D3DVERTEXBUFFER_DESC pDescv;
BOOLEAN record = FALSE;
D3DXMATERIAL mat;
IDirect3DTexture9 *g_texture=NULL;
^^ *some of this is irrelevant as it may be copied from other code lazily or not applicable to the problem.
sozoku is offline  
Old 07/24/2012, 00:37   #13


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,904
Received Thanks: 25,394
What do you mean by "dynamic array"? A linked list?
Because arrays allocated with new or std::vectors are located in a linear order.

edit:

Oh wait, did you mean a double pointer? I mean, a pointer to a pointer or a dynamically allocated two-dimensional array?
Like
Code:
int **ptr = new int*[10];
ptr[0] = new int[10];
Well that would indeed cause problems (even though i wouldn't call that just a "dynamic array", sincen it is actually a two-dimensional array), but I can't imagine how you figured that out of his first code snippet oO
MrSm!th is offline  
Old 07/24/2012, 04:20   #14
 
sozoku's Avatar
 
elite*gold: 3
Join Date: Dec 2010
Posts: 370
Received Thanks: 974

Seems like I found a somewhat similar problem on a Russian article comment. This would explain why very simple meshes work fine but others come out patchy as the proper transformation matrices, vertex shaders and so on haven't been applied. If I'm not mistaken.

Now to see if I can get Processvertices() going on in my code...
sozoku is offline  
Reply


Similar Threads Similar Threads
Unterstüzt AGP 8x Vertex Shader 3.0?
11/08/2011 - Hardware Discussions / Questions - 4 Replies
Frage steht im Titel ;D
[GraKa]Vertex Shader 3.0
01/27/2011 - Technical Support - 12 Replies
Hey, vielleicht könnt ihr mir helfen hoffe ich mal :) also folgendes Problem : Frisch MW2 geladen *FREU* PS: Natürlich die Orginal Version :) und dann will ich es starten und was muss ich da sehen? Error Your Graphiccard does not support vertex shader 3.0! Nun denk ich mir egal neue GraKa Karte kaufen und das wars und dann fiel es mir ein : Meine Grafikkarte ist in mein Motherboard intigriert! Nun meine Frage : Kann ich auch eine andere Grafikkarte anschliessen wenn ich eine habe die...
Vertex Aussortieren
04/05/2009 - General Coding - 0 Replies
Hi, beim d3dx hooking sollte man ja relativ schnell mit vertexen zusammen kommen, was ich jedoch jetzt gern wüsste wäre wie man die vertexe filtert, also herrausfindet welcher jetzt die spielfigur und welcher die wand, die objekte etc. sind, denn daraus läuft es ja hinaus das eben nur manche verändert werden sollen, und nicht alle. Und da es auch schon mal > 1000 geben kann glaube ich kaum das das jemand per hand macht, meine idee wäre es das man das mit farbabstufungen filtern könnte und...



All times are GMT +2. The time now is 04:30.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.