Sign in to follow this  

Loading 3D Pre made Models

Recommended Posts

I am learning directx8 in vb6 and i am following a set of tutorials and ive got to the part of loading pre made 3d models and i use this to set my shapes before rendering visual basic code: Dim MeshMaterials() As D3DMATERIAL8 ' Mesh Material data Dim MeshTextures() As Direct3DTexture8 ' Mesh Textures Dim nMaterials As Long 'How may materials/textures we have.... Dim mtrlBuffer As D3DXBuffer '//Holds some useful data for us... Dim I As Long 'Loop variable Dim TextureFile As String 'the texture required '//1. Get the data from the file Set Mesh = D3DX.LoadMeshFromX(App.Path & "\pyramid.x", D3DXMESH_MANAGED, D3DDevice, Nothing, mtrlBuffer, nMaterials) If Mesh Is Nothing Then GoTo BailOut: '//Dont continue if the above call did not work '//2. Allocate the space required for the materials and textures used: ReDim MeshMaterials(nMaterials) As D3DMATERIAL8 ReDim MeshTextures(nMaterials) As Direct3DTexture8 '//3. Now we fill our arrays with the information required For I = 0 To nMaterials - 1 '//Get D3DX to copy the data that we loaded from the file into our structure D3DX.BufferGetMaterial mtrlBuffer, I, MeshMaterials(I) '//Fill in the missing gaps - the Ambient properties MeshMaterials(I).Ambient = MeshMaterials(I).diffuse '//get the name of the texture used for this part of the mesh TextureFile = D3DX.BufferGetTextureName(mtrlBuffer, I) '//Now create the texture If TextureFile <> "" Then 'Dont try to create a texture from an empty string Set MeshTextures(I) = D3DX.CreateTextureFromFileEx(D3DDevice, App.Path & "\" & TextureFile, 128, 128, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_LINEAR, D3DX_FILTER_LINEAR, 0, ByVal 0, ByVal 0) End If Next I but i do not know how to load more than one shape on the screen any help?

Share this post

Link to post
Share on other sites
Same shape of different shape ???

You didnt include the rendering code, so not sure if you want to load additional
shapes and draw one of each or several objects on the same shape....

If several shapes -- define a structure (see the 'Type' keyword for defining types with multiple elements) and then an array of that type.
Put all the variables associated with the shape being loaded into it.

Loop all your shapes and put their data into the array so each shape can be selected using a array index.

Your render code would have a loop itself, except each would draw a different object (you should have a structure Type for this too -- including Position coordinates and Shape index value). You would then have an array of objects (of the new Object Type) whuch you will preload with data to specify what to draw.

You would loop thru all the objects and draw each using the data in the Object array (which references which Shape that Object is to look like).

If you want each object to have its own unique shape, you could merge the two structure Types to simplify.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this