|
Makubab
|
 |
« on: August 28, 2008, 10:47:30 PM » |
|
Hi, just wondering how to use Mesh.AddVertex to add the vertices in the same way that Mesh.AddFloorGrid arranges its own. If you add vertices in a line like AddFloorGrid arranges them, it doesn't work out too well. Here's how AddFloorGrid does it: 1,2,3,4,5 6,7,8,9,10
However, AddVertex seems to need it in a triangle manner (I would guess because you are trying to make triangles). But if AddFloorGrid can do it the other way, why not AddVertex? Any help/suggestions would be great, thanks 
|
|
|
|
|
Logged
|
|
|
|
jviper
Community Member

Posts: 1366
Discipline in training
|
 |
« Reply #1 on: August 29, 2008, 06:35:51 PM » |
|
I'm pretty sure the AddFloorGrid function does not add like that.
Try this:
Create a floor grid with AddFloorGrid. Then go into TVInternal objects and take a look at the indexbuffer. Also, loop through your triangles and check the GetTriangle function for each triangle.
|
|
|
|
|
Logged
|
JAbstract.....Don't just imagine, make it happen!
|
|
|
|
Makubab
|
 |
« Reply #2 on: August 30, 2008, 06:48:52 PM » |
|
i do this to check where vertex ID's are: For x = 0 To mesh.GetVertexCount - 1 mesh.GetVertex(x, tmpPos.x, tmpPos.y, tmpPos.z, 0, 0, 0, 0, 0, 0, 0, 0) TVText.TextureFont_DrawBillboardText(x, tmpPos.x, tmpPos.y, tmpPos.z, TVGlobal.RGBA(1, 0, 0, 1)) Next
That basically puts the ID of the vertex over the vertex, and it numbers as I stated in my first post. I did go in and look at the triangle information as you suggested and it confirmed the same, the first triangle (id 0) returned 0, 11, and 1 for it's vertex's (my floor grid is 10x10).
|
|
|
|
|
Logged
|
|
|
|
jviper
Community Member

Posts: 1366
Discipline in training
|
 |
« Reply #3 on: August 30, 2008, 09:43:22 PM » |
|
hmm...wasn't clear in your post. In your post it seemed you were saying that each entry in the indexbuffer matched the index of each element, i.e: 0 = 0, 1 = 1, 2 = 2, 3 = 3, 4 = 4, 5 = 5, 6 = 6, 7 = 7, 8 = 8, 9 = 9........ I was suggesting that this was not the case, and that the entries go more like: 0 = 0, 1 = 11, 2 = 1, 3 = 11, 4 = 1, 5 = 12, 6 = 1, 7 = 12, 8 = 2, 0 = 12, 10 = 2, 11 = 13, 12 = 2, 13 = 13, 14 = 3, 15 = 13, 16 = 3, 17 = 15, 18 = 3, 19 = 14, 20 = 4, 21 = 14, 22 = 4, 23 = 16 ...... It's a bit confusing, and not very trivial, but that's how the indicies are stored.
BUt just curius, what was your AddVertex code?
|
|
|
|
|
Logged
|
JAbstract.....Don't just imagine, make it happen!
|
|
|
|
Makubab
|
 |
« Reply #4 on: August 31, 2008, 12:02:10 AM » |
|
i see what your saying with the vertices IDs and such and that the index might be different then how they were created or some such. Sorry but I don't know how to use InternalObjects to get the IndexBuffer to check however (using VB.NET) but all the methods available in TVInternal return System.IntPtr. Here is my AddVertex code in the attempt to simulate AddFloorGrid: For x = 0 To 10 For z = 0 To 10 mesh.AddVertex(z * 5, 0, x * 5, 0, 0, 0, 0, 0) Next Next
Basically I need to be able to make a floor grid except with more control (by making it myself) but it needs to work like AddFloorGrid, so the vertex ID numbering scheme has to be the same. Thanks for the help so far, btw. 
|
|
|
|
|
Logged
|
|
|
|
jviper
Community Member

Posts: 1366
Discipline in training
|
 |
« Reply #5 on: August 31, 2008, 12:44:33 AM » |
|
Ah ha. That's what I was afried of. Ok, that would be the wrong way to do it. Basiclally what you've done in that code is add a grid of verticies, but no indicies were defined. But because the AddVertex function does not have any arguments for indicies, each vertex would have to be it's own index. As you know, you need 3 indicies per triangle, and in your code, there is no correlation. So the correction to your code would have to call the AddVertex function 6 times to get two triangles for each square in your grid. This is ofcourse dependent on your mesh format, weither it be triangle strips, triangle lists, points lists, or what not.
NOTE: doing it that way, you will have seams between the triangles. If every triangle always gets 3 different verticies, even if the verticies overlap, your triangles will not be connected. This is perhaps the downside to using this function, unless you play around with the mesh format, and figure out which one works for the method you are using.
The way TV3D does it internally I'll bet, is it uses the index buffer and vertex array directly, then uses SetGeometry. When you define your own index array, you have direct control over how verticies are shared by triangles, therefor no seams. So you define an array of index values which correspond to verticies, then you pass these to the SetGeometry function.
|
|
|
|
|
Logged
|
JAbstract.....Don't just imagine, make it happen!
|
|
|
|
Makubab
|
 |
« Reply #6 on: August 31, 2008, 11:21:53 AM » |
|
alright, I see how TV does it now and I think with a bit of work I'll be able to mimic it. Thanks for the help. 
|
|
|
|
|
Logged
|
|
|
|
jviper
Community Member

Posts: 1366
Discipline in training
|
 |
« Reply #7 on: August 31, 2008, 11:59:52 AM » |
|
Heres some code that should help you along the way: Public Shared Function CreateTVMeshGrid(ByVal PosMin As TV_2DVECTOR, ByVal PosMax As TV_2DVECTOR, ByVal Altitude As Single, ByVal Segs As TV_2DVECTOR, ByVal TexTile As TV_2DVECTOR) As TVMesh Dim Vrt() As TV_SVERTEX Dim Ind() As Integer Dim Mat() As Integer Dim f As Integer : f = 0 Dim Vec As TV_3DVECTOR ReDim Vrt(0 To (CInt(Segs.y + 1) * CInt(Segs.x + 1)) - 1) ReDim Ind(0 To (CInt((Segs.y) * CInt(Segs.x)) * 6) - 1) ReDim Mat(0 To (CInt(Segs.y) * CInt(Segs.x) * 2) - 1) Dim RefTVMesh As TVMesh 'First Loop through the grid of verticies, populating our vertex array For y As Integer = 0 To CInt(Segs.y) For x As Integer = 0 To CInt(Segs.x) 'Calculate the Position of the Vertex Vec.x = PosMin.x + (x / Segs.x) * (PosMax.x - PosMin.x) Vec.z = PosMin.y + (y / Segs.y) * (PosMax.y - PosMin.y) Vec.y = Altitude 'Placing our vertex into the vertex array 'Here is our vertex position. Vrt((y * (CInt(Segs.x + 1))) + x).x = Vec.x Vrt((y * (CInt(Segs.x + 1))) + x).y = Vec.y Vrt((y * (CInt(Segs.x + 1))) + x).z = Vec.z 'Here is our vertex normal. Since this is just a plane, we'll just make all of the normals face upward. Vrt((y * (CInt(Segs.x + 1))) + x).nx = 0 Vrt((y * (CInt(Segs.x + 1))) + x).ny = 1 Vrt((y * (CInt(Segs.x + 1))) + x).nz = 0 'Here is our vertex texture coordinates. Vrt((y * (CInt(Segs.x + 1))) + x).tu = (x / (Segs.x)) * TexTile.x Vrt((y * (CInt(Segs.x + 1))) + x).tv = (y / (Segs.y)) * TexTile.y '/////////////////////////////////////////////////////////////// 'Now, this part of we will populate our index array 'This can be done outside of our vertex loop, but cleverly, it can be done at the same time as the vertex population 'So first we will make sure that the vertex we are looking at is not on the maxima edge 'This is to ensure we don't get an index out of range error when populating our index array. If y <= CInt(Segs.y - 1) Then If x <= CInt(Segs.x - 1) Then 'Now that the check has been done, we populate our index array 6 entries at a time (3 for each triangle in our quad) 'Notice we referenced "s+1" , "s+SegsX" and "s+(SegsY*SegsX) + SegsX" 'This is why it's important we check to make sure we're not working with one of the edge maxima verticies. 'If we excluded this test, we would get an out of range error when we get to the last row. Dim s As Integer : s = (y * CInt(Segs.x + 1)) + x Ind(f) = s Ind(f + 1) = s + CInt(Segs.x + 1) Ind(f + 2) = s + 1 Ind(f + 3) = s + 1 Ind(f + 4) = s + CInt(Segs.x + 1) Ind(f + 5) = s + CInt(Segs.x + 1) + 1 Mat(CInt(f / 3)) = 0 Mat(CInt(f / 3) + 1) = 0 f = f + 6 End If End If Next x Next y 'Now our vertex and index array has been populated. Time to create our TVMesh. RefTVMesh = coreScene.CreateMeshBuilder("TmpMesh_Grid") 'And finally we pass our index array and vertex array to the TVMesh.SetGeometry. RefTVMesh.SetGeometry(Vrt, Ubound(Vrt)+1, Ind, CInt(Ubound(Ind)/3), 1, Mat, False) Return RefTVMesh End Function
|
|
|
|
|
Logged
|
JAbstract.....Don't just imagine, make it happen!
|
|
|
|
SylvainTV
|
 |
« Reply #8 on: September 04, 2008, 01:01:42 PM » |
|
The engine does that internally : for(int z = 0; z <= iNumCellsZ; z++) { for(int x = 0; x <= iNumCellsX; x++) { float xx = (float)x / iNumCellsX; float zz = (float)z / iNumCellsZ; mesh->aData->AddVertex(xx * (fX2 - fX1) + fX1, fAltitude, zz * (fZ2- fZ1) + fZ1,0 ,1,0, xx * fTileU, zz * fTileV, xx,zz, 0xffffffff, false); } }
for(int z = 0; z < iNumCellsZ; z++) { for(int x = 0; x < iNumCellsX; x++) { mesh->aData->AddIndex(iCurrentV + z * (iNumCellsX+1) + x + 0); mesh->aData->AddIndex(iCurrentV + (z+1) * (iNumCellsX+1) + x + 0); mesh->aData->AddIndex(iCurrentV + z * (iNumCellsX+1) + x + 1);
mesh->aData->AddIndex(iCurrentV + z * (iNumCellsX+1) + x + 1); mesh->aData->AddIndex(iCurrentV + (z+1) * (iNumCellsX+1) + x + 0 ); mesh->aData->AddIndex(iCurrentV + (z+1) * (iNumCellsX+1) + x + 1); } } But well you don't have access to AddIndex so you must use SetGeometry/SetGeometryEx.
|
|
|
|
|
Logged
|
|
|
|
jviper
Community Member

Posts: 1366
Discipline in training
|
 |
« Reply #9 on: September 04, 2008, 07:21:37 PM » |
|
hmm....That's DirectX code right? Your saying that the AddIndex does not exists in DirectX?
|
|
|
|
|
Logged
|
JAbstract.....Don't just imagine, make it happen!
|
|
|
|
SylvainTV
|
 |
« Reply #10 on: September 09, 2008, 01:50:52 PM » |
|
Well yes it doesn't exist in Dx either :p but well it was just to show how the grid was generated, you can do the same with setgeometry.
|
|
|
|
|
Logged
|
|
|
|
|