Triangle Lists
Triangle Lists
Triangle Lists
Triangle Lists
Triangle Lists
Triangle Lists Triangle Lists Triangle Lists Triangle Lists Triangle Lists Triangle Lists Triangle Lists Triangle Lists
Triangle Lists Triangle Lists
Triangle Lists
Go Back  Xtreme Visual Basic Talk > > > > Triangle Lists


Reply
 
Thread Tools Display Modes
  #1  
Old 06-15-2006, 02:21 PM
scruffyduck scruffyduck is offline
Newcomer
 
Join Date: May 2006
Location: UK
Posts: 14
Default Triangle Lists


So the further I dig into this the foggier it gets

I have a list of vertices on the one hand and a list of triangles on the other. The vertex list contains information about the vertex including tu and tv information. The triangle list contains the triangles to be drawn to create the object. There are actually several lists, each follows a change of material or texture which is applied to the triangles.

My first thought was to create a vertex buffer containing the vertex list, but I now think that is wrong and that I should be creating a buffer from the triangle list and using that. I think I need to use a TriangleList primitive since the information I have consists of three pairs of vertex numbers for each triangle. So my current plan is to create a vertex buffer from the vertices referenced for each triangle, in the sequence they are referenced and then render this as a TriangleList primtive.

Am I heading in the right direction?

EDIT Hmm I have dug a bit more into the SDK and it looks like my list of triangles is an index into the list of vertices and I could use the DrawIndexedPrimitives Method?



Thanks
__________________
Jon
www.scruffyduckscenery.co.uk

Last edited by scruffyduck; 06-15-2006 at 02:36 PM.
Reply With Quote
  #2  
Old 06-20-2006, 01:30 PM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Default

Maybe it's just me but what are you up to? If you want to draw some simple shapes and set the vertices yourself you need to use a:
DirectX.Direct3D.VertexBuffer

I'm learning myself atm. but I can still provide you with some code on this part:

Code:
'Variable:
Private D3D_Cube As Direct3D.VertexBuffer

'Creating The Shape:
D3D_Cube = New Direct3D.VertexBuffer(GetType(Direct3D.CustomVertex.PositionTextured), 36, D3D_Device, 0, Direct3D.CustomVertex.PositionTextured.Format, Direct3D.Pool.Default)
Dim D3D_LockCube As Direct3D.CustomVertex.PositionTextured() = CType(D3D_Cube.Lock(0, 0), Direct3D.CustomVertex.PositionTextured())

D3D_LockCube(0) = New Direct3D.CustomVertex.PositionTextured(-1, -1, 1, 0, 1)
D3D_LockCube(1) = New Direct3D.CustomVertex.PositionTextured(-1, 1, 1, 0, 0)
D3D_LockCube(2) = New Direct3D.CustomVertex.PositionTextured(-1, -1, -1, 1, 1)

'Drawing:
D3D_Device.Transform.World = <your DirectX.Matrix here>
D3D_Device.SetStreamSource(0, <your DirectX.Direct3D.VertexBuffer here>, 0)
D3D_Device.VertexFormat = Direct3D.CustomVertex.PositionTextured.Format
D3D_Device.SetTexture(0, <your DirectX.Direct3D.Texture here>)
D3D_Device.DrawPrimitives(Direct3D.PrimitiveType.TriangleList, 0, 6)
I hope that helps.
Reply With Quote
  #3  
Old 06-20-2006, 01:58 PM
scruffyduck scruffyduck is offline
Newcomer
 
Join Date: May 2006
Location: UK
Posts: 14
Default

Thanks - what I have are pre-defined objects in a specific format. When de-compiled they provide the information that I now know is a mesh. What I am doing is taking that information and translating it so that DirectX can use it. I understand the format of the model file and I now understand (I think) what DirectX needs to render it. My current problem is the conversion from one to the other. Since posting this I have gotten a long way towards it.
__________________
Jon
www.scruffyduckscenery.co.uk
Reply With Quote
  #4  
Old 06-20-2006, 02:21 PM
ShadowWolf ShadowWolf is offline
Centurion
 
Join Date: Jan 2006
Location: Finland
Posts: 114
Default

Edit: oh, I missunderstood you again... umm, yeah that's tricky, can't help you there I read that above post as: "You have a non-mesh model, and have decompiled it into a mesh, and now you try to get dx to draw it."
Reply With Quote
  #5  
Old 07-11-2006, 06:28 AM
RcSepp RcSepp is offline
Regular
 
Join Date: Oct 2004
Posts: 55
Default

I don't thing you should break your head at that.

First just build some arraylists

Code:
Dim Vertices_array as new Arraylist
Dim Triangles_array as new Arraylist
I don't know from wher you read your data, but mostly it's a file, so:

Code:
Dim sr as new Streamreader("File.xyz")
While sr.peek <> -1

'Add Data like this:
Dim Vertex(3) as Single
Vertex(0) = sr.Readline
Vertex(1) = sr.Readline
Vertex(2) = sr.Readline
Vertex_array.add(Vertex)
.....

End While
sr.close
Now you have all your data in handy arraylists. Let's build the VertexBuffer!

Code:
Dim VertexBuffer as New VertexBuffer(GetType(CustomVertex.PositionTextured), Vertex_array.count, d3dDevice, Usage.None, CustomVertex.PositionTextured.Format, Pool.Default))
        Dim verts() As CustomVertex.PositionTextured= CType(VertexBuffer.Lock(0, 0), CustomVertex.PositionTextured())
        VertexBuffer.Lock(0, Vertex_array.count, LockFlags.None)
        For i As Long = 0 To Vertex_array.count-1 step 3
            verts(i).Position = New Vector3(Vertex_array(Triangle_array(i/3)(0))(0), Vertex_array(Triangle_array(i/3)(0))(1), Vertex_array(Triangle_array(i/3)(0))(2))
            verts(i+1).Position = New Vector3(Vertex_array(Triangle_array(i/3)(1))(0), Vertex_array(Triangle_array(i/3)(0))(1), Vertex_array(Triangle_array(i/3)(0))(2))
            verts(i+2).Position = New Vector3(Vertex_array(Triangle_array(i/3)(2))(0), Vertex_array(Triangle_array(i/3)(2))(1), Vertex_array(Triangle_array(i/3)(2))(2))

            verts(i * 3).Tu = ...
            verts(i * 3).Tv = ...
            verts(i * 3 + 1).Tu = ...
            verts(i * 3 + 1).Tv = ...
            verts(i * 3 + 2).Tu = ...
            verts(i * 3 + 2).Tv = ...
        Next
        VertexBuffer.Unlock() 'Unlock VertexBuffer
        Vertex_Count=Vertex_array.count-1
And to call it:

Code:
            d3dDevice.SetStreamSource(0, VertexBuffer, 0)
            d3dDevice.VertexFormat = CustomVertex.PositionTextured.Format
            d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, Vertex_Count / 3)
Note:
This code is not tested and it should just push you into the right direction.
Reply With Quote
  #6  
Old 07-11-2006, 08:42 PM
Rockoon's Avatar
Rockoon Rockoon is offline
Joseph Koss

* Guru *
 
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,615
Default

You need a list of vertices at a minimum

they can be arranged as a list of triangles (a triangle list)

or even better, unordered raw vertex information is stored in your vertex buffer and then you use an indexed triangle list and (at least in Dx8) DrawIndexedPrimitive(D3DPT_TRIANGLELIST, ...)
Reply With Quote
  #7  
Old 07-11-2006, 11:54 PM
scruffyduck scruffyduck is offline
Newcomer
 
Join Date: May 2006
Location: UK
Posts: 14
Default

Thanks guys - what I actually did in the end was to export the data from the FS object into a mesh file (DirectX .x) and use that to create the 3D object.

There are several changes of material in some of the objects and most of them use multiple textures and also there are other advantages in that I can use the manipulation methods available with the Mesh class. I switched to C# for the job as well since the bulk of tutorial out there are in C# and I found it easier to understand what is going on.
__________________
Jon
www.scruffyduckscenery.co.uk
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Triangle Lists
Triangle Lists
Triangle Lists Triangle Lists
Triangle Lists
Triangle Lists
Triangle Lists Triangle Lists Triangle Lists Triangle Lists Triangle Lists Triangle Lists Triangle Lists
Triangle Lists
Triangle Lists
 
Triangle Lists
Triangle Lists
 
-->