Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

VBSmiles

.an8 >> .3ds >> .x loading mesh problem.

This topic is 5317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

VB6/dx8.1 I am having a problem I cant seem to figure out. First, I am using anim8or. Nice little prog and can convert to 3ds. From there I am able to convert to .x file, and that seems to work.Well kind of. When I load an .x using vb6 I am able to see the color but alot darker,almost black, as if the lights are not working.If I increase the lighting/alpha, and other options, the model shows up brighter,but as if the mesh does not have normals or something. However, When I use the help utility meshviwer, it shows fine.Also, if I load an older .x or convert the 3ds that I retrieved with a sample then load it, everything works. I can also convert my anim8or file to x using crossroads I can see the mesh nicely but then the color is stripped.This is not what I want. Is there something special going on that I am unable to figure out. I want the colors and to be presented much as the meshviewer displays it. I originally posted this in the beginners section but noone has responded. Its as if noone ever uses anim8or and relies solely on autocad or 3d studio max, or has never had the problem.I have had. Yet I have seen many postings of people using anim8or and appearently without the problem. For reference much of my code has been based on lesson08 from directx4vb. Sure hope someone can help

Share this post


Link to post
Share on other sites
Advertisement
Could you possibly post some code of your loading and rendering functions (also, the renderstates you set would be good, too)? It would help out a lot.

If the DirectX utility meshviewer (that comes with the SDK) views it correctly, then the mesh itself is fine. It would be a problem with your code.


Dustin Franklin
Mircrosoft DirectX MVP

Share this post


Link to post
Share on other sites
Don''t know if this is too much but posted most of it anyway
Also crossing fingers that it uses bbcode

Public Function Initialise() As Boolean
On Error GoTo ErrHandler:
Dim DispMode As D3DDISPLAYMODE ''//Describes our Display Mode
Dim D3DWindow As D3DPRESENT_PARAMETERS ''//Describes our Viewport
Set dX = New DirectX8 ''//Create our Master Object
Set D3D = dX.Direct3DCreate() ''//Make our Master Object create the Direct3D Interface
Set D3DX = New D3DX8 ''//Create our helper library...
''############ windowed ###################
D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, DispMode ''//Retrieve the current display Mode
D3DWindow.Windowed = 1 ''//Tell it we''re using Windowed Mode
D3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC ''//We''ll refresh when the monitor does
D3DWindow.SwapEffect = D3DSWAPEFFECT_FLIP
D3DWindow.BackBufferCount = 1 ''//1 backbuffer only
D3DWindow.BackBufferFormat = DispMode.Format ''What we specified earlier
D3DWindow.BackBufferWidth = DispMode.Width
D3DWindow.BackBufferHeight = DispMode.Height
D3DWindow.hDeviceWindow = DXViewer.hWnd
D3DWindow.EnableAutoDepthStencil = 1
If D3D.CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, DispMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16) = D3D_OK Then
D3DWindow.AutoDepthStencilFormat = D3DFMT_D16 ''//16 bit Z-Buffer
Else
''We could now check for different modes available...
End If
Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, DXViewer.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, _
D3DWindow)
D3DDevice.SetRenderState D3DRS_LIGHTING, 1
D3DDevice.SetRenderState D3DRS_ZENABLE, 1
''RGB(55,55,55)&H202020
D3DDevice.SetRenderState D3DRS_AMBIENT, )&H202020 ''The ambient value is a hex-RRGGBB code
D3DDevice.SetTextureStageState 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR
D3DDevice.SetTextureStageState 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR
fnt.Name = "Verdana"
fnt.Size = 12
Set MainFontDesc = fnt
Set MainFont = D3DX.CreateFont(D3DDevice, MainFontDesc.hFont)
If InitialiseGeometry() = False Then GoTo ErrHandler:
Initialise = True
Exit Function
ErrHandler:
Debug.Print "Error Number Returned: " & Err.Number
Initialise = False
End Function




Public Sub Render()
''//1. We need to clear the render device before we can draw anything
'' This must always happen before you start rendering stuff...
D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET Or D3DCLEAR_ZBUFFER, RGB(150, 100, 100), 1#, 0 ''//Clear the screen black

D3DDevice.BeginScene
''All rendering calls go between these two lines
For I = 0 To nMaterials - 1
''//Setup the renderer for this part of the mesh
D3DDevice.SetMaterial MeshMaterials(I)
note that this is commented out because there is no texture being loaded.
'' D3DDevice.SetTexture 0, MeshTextures(I)
''//Draw the current part of the mesh
Mesh.DrawSubset I
Next I


D3DDevice.EndScene

D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
End Sub




Private Function InitialiseGeometry() As Boolean


On Error GoTo BailOut: ''//Setup our Error handler
''//0. Any variables required
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 & "\lesson08.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
Mesh.GetNumVertices
InitialiseGeometry = True
Exit Function
BailOut:
Debug.Print "Error occured in InitGeometryEx() Code"
InitialiseGeometry = False
End Function




Private Sub Form_Load()

Dim matTemp As D3DMATRIX ''//To hold temporary stuff...

Me.Show ''//Make sure our window is visible
dist = 150
SpinUp = 77
UpVect = 1
bRunning = Initialise()
Debug.Print "Device Creation Return Code : ", bRunning ''So you can see what happens...

Do While bRunning
''//Reset our world matrix
''//1. The World Matrix
D3DXMatrixIdentity matWorld
D3DXMatrixIdentity matTemp
D3DXMatrixRotationYawPitchRoll matTemp, RotateZ * (pi / 180), RotateY * (pi / 180), RotateX * (pi / 180)
D3DXMatrixMultiply matWorld, matWorld, matTemp
D3DDevice.SetTransform D3DTS_WORLD, matWorld ''commit this matrix to the device

''still buggy... must find another way...
If SpinUp > 0 Then
UpVect = 1
Else
UpVect = -1
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''//2. The View Matrix
D3DXMatrixIdentity matView
D3DXMatrixLookAtLH matView, MakeVector(CalcX, CalcY, CalcZ), MakeVector(0, 0, 0), MakeVector(0, UpVect, 0)
D3DDevice.SetTransform D3DTS_VIEW, matView

''//3. The projection Matrix
D3DXMatrixIdentity matProj
D3DXMatrixPerspectiveFovLH matProj, pi / 4, 1, 0.1, 500
D3DDevice.SetTransform D3DTS_PROJECTION, matProj
D3DDevice.SetTransform D3DTS_WORLD, matWorld
''//Work out which light should be on...
D3DDevice.LightEnable 0, 0 ''Turn them all off
D3DDevice.LightEnable 1, 0
D3DDevice.LightEnable 2, 0

D3DDevice.LightEnable CurrentActiveLight, 1 ''Then turn on the correct one
Render ''//Update the frame...
'' //Frame rate calculations
If GetTickCount() - FPS_LastCheck >= 1000 Then
FPS_Current = FPS_Count
FPS_Count = 0 ''reset the counter
FPS_LastCheck = GetTickCount()
End If
FPS_Count = FPS_Count + 1
DoEvents ''//Allow windows time to think; otherwise you''ll get into a really tight (and bad) loop...
Loop ''//Begin the next frame...
On Error Resume Next
Set D3DDevice = Nothing
Set D3D = Nothing
Set dX = Nothing
Debug.Print "All Objects Destroyed"
''//Final termination:
Unload Me
End
End Sub

Share this post


Link to post
Share on other sites
forgot the light setup... although I played around with them .

Private Function SetupLights() As Boolean
On Error GoTo BailOut:

Dim Mtrl As D3DMATERIAL8, Col As D3DCOLORVALUE
Dim col2 As D3DCOLORVALUE
col2.a = 0.2: col2.r = 0.2: col2.b = 0.2: col2.g = 0.2
Col.a = 0.02: Col.r = 1: Col.g = 1: Col.b = 1
Mtrl.Ambient = Col
Mtrl.diffuse = Col
''Mtrl.emissive.a =
Mtrl.emissive.r = 1
Mtrl.emissive.g = 1
Mtrl.emissive.b = 1
D3DDevice.SetMaterial Mtrl


Lights(0).Type = D3DLIGHT_DIRECTIONAL

Lights(0).diffuse.r = 1
Lights(0).diffuse.g = 1
Lights(0).diffuse.b = 1
Lights(0).Direction = MakeVector(0, -1, 0)
D3DDevice.SetLight 0, Lights(0)

Lights(1).Type = D3DLIGHT_POINT
Lights(1).Position = MakeVector(5, 0, 2)
Lights(1).diffuse.b = 1
Lights(1).Range = 100
Lights(1).Attenuation1 = 0.05 ''Set the Linear Attenuation to 0.05

D3DDevice.SetLight 1, Lights(1)

Lights(2).Type = D3DLIGHT_SPOT
Lights(2).Position = MakeVector(-4, 0, 0)
Lights(2).Range = 100
Lights(2).Direction = MakeVector(1, 0, 0) ''Along the X axis
Lights(2).theta = 30 * Rad ''Inner Cone
Lights(2).Phi = 50 * Rad ''Outer Cone
Lights(2).diffuse.g = 1
Lights(2).Attenuation1 = 0.05

D3DDevice.SetLight 2, Lights(2)


SetupLights = True
Exit Function

BailOut:
Debug.Print "Error occured in the SetupLights() code"
SetupLights = False
End Function

Share this post


Link to post
Share on other sites
Ok folks, I''ve fixed my problem! And it was much easier then anyone could have imagined.

Of course after spending the last 2 days and all last night looking for information!

Anyway. This is what I did. I figured maybe I could just open meshview and look at the properties of the mesh. And while I happened to be there I sudenly wondered if there was a converter there i could use ( pretty tired by then ).

Anyway I noticed that I could save a mesh and a couple different ways.The thought came to me that .... ok
sence Im able to view it here , maybe it will save it differently..Yeah right, Im thinking, that just sounded to silly,but went ahead and did it anyway. To my amazement it did just that and can view the mesh perfectly now. :-D

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!