.an8 >> .3ds >> .x loading mesh problem.
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
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
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
Don''t know if this is too much but posted most of it anyway
Also crossing fingers that it uses bbcode
Also crossing fingers that it uses bbcode
Public Function Initialise() As BooleanOn Error GoTo ErrHandler:Dim DispMode As D3DDISPLAYMODE ''//Describes our Display ModeDim D3DWindow As D3DPRESENT_PARAMETERS ''//Describes our ViewportSet dX = New DirectX8 ''//Create our Master ObjectSet D3D = dX.Direct3DCreate() ''//Make our Master Object create the Direct3D InterfaceSet D3DX = New D3DX8 ''//Create our helper library... ''############ windowed ###################D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, DispMode ''//Retrieve the current display ModeD3DWindow.Windowed = 1 ''//Tell it we''re using Windowed ModeD3DWindow.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC ''//We''ll refresh when the monitor doesD3DWindow.SwapEffect = D3DSWAPEFFECT_FLIPD3DWindow.BackBufferCount = 1 ''//1 backbuffer onlyD3DWindow.BackBufferFormat = DispMode.Format ''What we specified earlierD3DWindow.BackBufferWidth = DispMode.WidthD3DWindow.BackBufferHeight = DispMode.HeightD3DWindow.hDeviceWindow = DXViewer.hWndD3DWindow.EnableAutoDepthStencil = 1If D3D.CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, DispMode.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16) = D3D_OK Then D3DWindow.AutoDepthStencilFormat = D3DFMT_D16 ''//16 bit Z-BufferElse ''We could now check for different modes available...End IfSet D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, DXViewer.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, _ D3DWindow)D3DDevice.SetRenderState D3DRS_LIGHTING, 1D3DDevice.SetRenderState D3DRS_ZENABLE, 1''RGB(55,55,55)&H202020D3DDevice.SetRenderState D3DRS_AMBIENT, )&H202020 ''The ambient value is a hex-RRGGBB codeD3DDevice.SetTextureStageState 0, D3DTSS_MAGFILTER, D3DTEXF_LINEARD3DDevice.SetTextureStageState 0, D3DTSS_MINFILTER, D3DTEXF_LINEARfnt.Name = "Verdana"fnt.Size = 12Set MainFontDesc = fntSet MainFont = D3DX.CreateFont(D3DDevice, MainFontDesc.hFont)If InitialiseGeometry() = False Then GoTo ErrHandler:Initialise = TrueExit FunctionErrHandler:Debug.Print "Error Number Returned: " & Err.NumberInitialise = FalseEnd 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 blackD3DDevice.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 INext ID3DDevice.EndSceneD3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0End 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 IMesh.GetNumVerticesInitialiseGeometry = TrueExit FunctionBailOut:Debug.Print "Error occured in InitGeometryEx() Code"InitialiseGeometry = FalseEnd Function
Private Sub Form_Load()Dim matTemp As D3DMATRIX ''//To hold temporary stuff...Me.Show ''//Make sure our window is visibledist = 150SpinUp = 77UpVect = 1bRunning = Initialise()Debug.Print "Device Creation Return Code : ", bRunning ''So you can see what happens...Do While bRunning ''//Reset our world matrix ''//1. The World MatrixD3DXMatrixIdentity matWorldD3DXMatrixIdentity matTemp D3DXMatrixRotationYawPitchRoll matTemp, RotateZ * (pi / 180), RotateY * (pi / 180), RotateX * (pi / 180) D3DXMatrixMultiply matWorld, matWorld, matTempD3DDevice.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 MatrixD3DXMatrixIdentity matViewD3DXMatrixLookAtLH matView, MakeVector(CalcX, CalcY, CalcZ), MakeVector(0, 0, 0), MakeVector(0, UpVect, 0)D3DDevice.SetTransform D3DTS_VIEW, matView''//3. The projection MatrixD3DXMatrixIdentity matProjD3DXMatrixPerspectiveFovLH matProj, pi / 4, 1, 0.1, 500D3DDevice.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 = NothingSet D3D = NothingSet dX = NothingDebug.Print "All Objects Destroyed"''//Final termination:Unload MeEndEnd Sub
forgot the light setup... although I played around with them .
Private Function SetupLights() As BooleanOn Error GoTo BailOut:Dim Mtrl As D3DMATERIAL8, Col As D3DCOLORVALUEDim col2 As D3DCOLORVALUEcol2.a = 0.2: col2.r = 0.2: col2.b = 0.2: col2.g = 0.2Col.a = 0.02: Col.r = 1: Col.g = 1: Col.b = 1Mtrl.Ambient = ColMtrl.diffuse = Col''Mtrl.emissive.a =Mtrl.emissive.r = 1Mtrl.emissive.g = 1Mtrl.emissive.b = 1D3DDevice.SetMaterial MtrlLights(0).Type = D3DLIGHT_DIRECTIONALLights(0).diffuse.r = 1Lights(0).diffuse.g = 1Lights(0).diffuse.b = 1Lights(0).Direction = MakeVector(0, -1, 0)D3DDevice.SetLight 0, Lights(0)Lights(1).Type = D3DLIGHT_POINTLights(1).Position = MakeVector(5, 0, 2)Lights(1).diffuse.b = 1Lights(1).Range = 100Lights(1).Attenuation1 = 0.05 ''Set the Linear Attenuation to 0.05D3DDevice.SetLight 1, Lights(1)Lights(2).Type = D3DLIGHT_SPOTLights(2).Position = MakeVector(-4, 0, 0)Lights(2).Range = 100Lights(2).Direction = MakeVector(1, 0, 0) ''Along the X axisLights(2).theta = 30 * Rad ''Inner ConeLights(2).Phi = 50 * Rad ''Outer ConeLights(2).diffuse.g = 1Lights(2).Attenuation1 = 0.05D3DDevice.SetLight 2, Lights(2)SetupLights = TrueExit FunctionBailOut:Debug.Print "Error occured in the SetupLights() code"SetupLights = FalseEnd Function
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement