   plane mesh structure
  Hello everyone,I'm having some troubles creating a simple plane structure, i dont seem to get the way the vertices are arranged, shouldnt this be right?//hVertex(x,y,z,nx,ny,nz,u,v)v[0] = hVertex ( 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );v[1] = hVertex ( 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );v[2] = hVertex ( 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );v[3] = hVertex ( 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );v[4] = hVertex ( 0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );v[5] = hVertex ( 1.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );v[6] = hVertex ( 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );v[7] = hVertex ( 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );v[8] = hVertex ( 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );i[0] = 0; i[1] = 1; i[2] = 3;i[3] = 1; i[4] = 3; i[5] = 4;i[6] = 1; i[7] = 2; i[8] = 4;i[9] = 2; i[10] = 4; i[11] = 5;i[12] = 3; i[13] = 4; i[14] = 6;i[15] = 4; i[16] = 6; i[17] = 7;i[18] = 4; i[19] = 5; i[20] = 7;i[21] = 5; i[22] = 7; i[23] = 8;Thanks for your time-Hassanofftopic: shouldnt  show the image in the current thread?P.S: if i want the vertex to point upwards, it's normal's xyz should be 0,1,0?   
Quote:I'm having some troubles creating a simple plane structure, i dont seem to get the way the vertices are arranged, shouldnt this be right?*** Source Snippet Removed ***I didn't proof all your mesh data, but depending on how you have culling set up, the problem may be related to winding order. (For example, the last two triangles in your mesh are wound in opposite directions.)Quote:offtopic: shouldnt  show the image in the current thread?GDNet doesn't currently support UBB code, but you can use HTML instead.Quote:P.S: if i want the vertex to point upwards, it's normal's xyz should be 0,1,0?The normal should be perpendicular to the surface. It looks like in your example that would be (0,0,1).   ;  i dont know what you mean, it all seems right to me:-x, y-0.0, 0.0===0.5, 0.0===1.0, 0.0||-----------||-----------||||-----------||-----------||||-----------||-----------||||-----------||-----------||0.0, 0.5===0.5, 0.5===1.0, 0.5||-----------||-----------||||-----------||-----------||||-----------||-----------||||-----------||-----------||0.0, 1.0===0.5, 1.0===1.0, 1.0t1:0.0,0.0---0.5,0.0______________|------------/|----------/|--------/|------/|----/|--/|/0.0, 0.5   ;Quote:i dont know what you meanWhich part are you referring to?   ;Quote:Original post by jykQuote:i dont know what you meanWhich part are you referring to?Quote:Original post by jykthe problem may be related to winding order. (For example, the last two triangles in your mesh are wound in opposite directions.);  See here, in the section titled 'Winding Order of Vertices'.   ;Quote:Original post by jykSee here, in the section titled 'Winding Order of Vertices'.yeah but what's wrong with mine? it seems fine, if you mean the second triangles of a quad ( t2, t4, t6 and t8 ), reversing them yo become clockwise doesnt help:i[0] = 0; i[1] = 1; i[2] = 3; //t1i[3] = 4; i[4] = 3; i[5] = 1; //t2i[6] = 1; i[7] = 2; i[8] = 4; //t3i[9] = 5; i[10] = 4; i[11] = 2; //t4i[12] = 3; i[13] = 4; i[14] = 6; //t5i[15] = 7; i[16] = 6; i[17] = 4; //t6i[18] = 4; i[19] = 5; i[20] = 7; //t7i[21] = 8; i[22] = 7; i[23] = 5; //t8;  Well, you haven't really told us anything about the actual problem you're trying to solve, so it's a little difficult to give feedback at this point.What's the problem exactly? Is the mesh displaying incorrectly? Are you just not seeing anything? There are a million ways to get something to render incorrectly, many of which don't have anything to do with how your mesh data is arranged, so without more info we can really only guess as to what's wrong.   ;  the mesh data is incorrect, i get an exception whenever i use the mesh ( e.g. DrawSubset(), OptimizeInPlace(), GenerateAdjacency() )im pretty sure it has something to do with the arrangement of the verts and/or indices, because the code for creating this is the same as creating a cube, which works fine, but with different verts/indices.here's the whole function if you want to see itvoid hxObject::MakePlane ( float size, int xsegments, int zsegments ){scaleFactor = 100;LOD = false;int tris  = ((xsegments+1)*(zsegments+1))*2;int verts = (xsegments+2)*(zsegments+2);if ( FAILED ( D3DXCreateMeshFVF ( tris, verts, D3DXMESH_MANAGED, hVertex::FVF, MainCore->GetDevice(), &baseMesh ) ) ){MainCore->PostError ( this, "MakePlane : Unable to create cube mesh", false );return;}ResetMaterials ( );ClearTexture ( -1 );hVertex* v;if ( FAILED ( baseMesh->LockVertexBuffer ( 0, (void**)&v ) ) ){MainCore->PostError ( this, "MakePlane : Unable to lock the vertex buffer", false );return;}//scaling vertexhVertex vSize ( size/20, size/20, size/20, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f );hVertex vSubt ( 0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f );int vpc = zsegments+2, vpr =xsegments+2;for ( int i = 0; i < vpc; i++ ){for ( int i2 = 0; i2 < vpr; i2++ ){float x, z, _u, _v;x = (1.0f/((float)vpc-1.0f))*i2;z = (1.0f/((float)vpr-1.0f))*i;v[(i*i2)+i2] = ( hVertex ( x, 0.0f, z, 0.0f, 1.0f, 0.0f, x, z ) * vSize ) - vSubt;}}/*v[0] = hVertex ( 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f );v[1] = hVertex ( 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f );v[2] = hVertex ( 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f );v[3] = hVertex ( 0.0f, 0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f );v[4] = hVertex ( 0.5f, 0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f );v[5] = hVertex ( 1.0f, 0.0f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f );v[6] = hVertex ( 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f );v[7] = hVertex ( 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f );v[8] = hVertex ( 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f );*/if ( FAILED ( baseMesh->UnlockVertexBuffer (  ) ) ){MainCore->PostError ( this, "MakePlane : Unable to unlock the vertex buffer", false );return;}WORD *i;if ( FAILED ( baseMesh->LockIndexBuffer ( 0, (void**)&i ) ) ){MainCore->PostError ( this, "MakePlane : Unable to lock the index buffer", false );return;}//indicesint offset = 0;for ( int i1 = 0; i1 < vpc-1; i1++ ){for ( int i2 = 0; i2 < vpr-1; i2++ ){i[(i1*i2)+i2 + 0] = 0   + offset;i[(i1*i2)+i2 + 1] = 1   + offset;i[(i1*i2)+i2 + 2] = vpr + offset;i[(i1*i2)+i2 + 3] = 1   + offset;i[(i1*i2)+i2 + 4] = vpr + offset;i[(i1*i2)+i2 + 5] = vpr + offset + 1;offset++;}offset++;}/*i[0] = 0; i[1] = 1; i[2] = 3;i[3] = 4; i[4] = 3; i[5] = 1;i[6] = 1; i[7] = 2; i[8] = 4;i[9] = 5; i[10] = 4; i[11] = 2;i[12] = 3; i[13] = 4; i[14] = 6;i[15] = 7; i[16] = 6; i[17] = 4;i[18] = 4; i[19] = 5; i[20] = 7;i[21] = 8; i[22] = 7; i[23] = 5;*/if ( FAILED ( baseMesh->UnlockIndexBuffer ( ) ) ){MainCore->PostError ( this, "MakePlane : Unable to unlock the index buffer", false );return;}DWORD* attributeBuffer = 0;if ( FAILED ( baseMesh->LockAttributeBuffer ( 0, &attributeBuffer ) ) ){MainCore->PostError ( this, "MakePlane : failed to lock the attribute buffer", false );goto noAttBuff;}for ( int i = 0; i < baseMesh->GetNumFaces ( ); i++ )attributeBuffer = 0;if ( FAILED ( baseMesh->UnlockAttributeBuffer ( ) ) )MainCore->PostError ( this, "MakePlane : failed to unlock the attribute buffer", false );noAttBuff:vector<DWORD> adjacencyBuffer ( baseMesh->GetNumFaces ( ) * 3 );if ( FAILED ( baseMesh->GenerateAdjacency ( 0.0f, &adjacencyBuffer[0] ) ) )MainCore->PostError ( this, "MakePlane : Unable to generate adjacency", false );adjBuffer = adjacencyBuffer;if ( FAILED ( baseMesh->OptimizeInplace ( D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_COMPACT  | D3DXMESHOPT_VERTEXCACHE, &adjBuffer[0], 0, 0, 0) ) )MainCore->PostError ( this, "MakePlane : Unable to optimize the mesh", false );vaild = true;}//vertex structurestruct hVertex{hVertex(){};hVertex ( float x, float y, float z, float nx, float ny, float nz, float u, float v );    float _x, _y, _z;    float _nx, _ny, _nz;    float _u, _v;hVertex operator+ ( hVertex Vert );hVertex operator- ( hVertex Vert );hVertex operator* ( hVertex Vert );hVertex operator/ ( hVertex Vert );static const DWORD FVF;};hVertex::hVertex ( float x, float y, float z, float nx, float ny, float nz, float u, float v ){_x  = x;  _y  = y;  _z  = z;_nx = nx; _ny = ny; _nz = nz;_u  = u;  _v  = v;}const DWORD hVertex::FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1;note that the two for loops for vertex/index buffers generates the same results as the code in comment blocksalso note that the code in comment blocks only works when passing xsegment and zsegment parameters as 1 : obj->MakePlane ( 20, 1, 1 );[Edited by - Hassanbasil on April 10, 2010 2:44:59 AM];  alright, got it working perfectly now, was swapping 2 indices in the loop, if anyone's interested://vertsint vpc = zsegments+2, vpr =xsegments+2;float uI = 1.0f/(float)(vpc-1);float vI = 1.0f/(float)(vpr-1);float _u = 0.0f, _v = 0.0f;int curVert = 0;for ( int z = 0; z < vpc; z++ ){for ( int x = 0; x < vpr; x++ ){v[curVert++] = ( hVertex ( (float)x/(vpr-1), 0.0f, (float)z/(vpc-1), 0.0f, 0.0f, 0.0f, _u, _v ) - vSubt ) * vSize;_u += uI;}_v += vI;_u = 0;}//indices//indicesint numt = 0;int offset = 0;for ( int t = 0; t < tris/2; t++ ){i[t*6 + 0] = 1   + offset;i[t*6 + 1] = 0   + offset;i[t*6 + 2] = vpr + offset;i[t*6 + 3] = vpr + offset + 1;i[t*6 + 4] = 1   + offset;i[t*6 + 5] = vpr + offset;numt++;offset++;if ( numt == vpr-1 ){offset++;numt = 0;}}