Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

20.11.2005, 15:33

Textur fehlt bei Model das mit Milkshape exportiert wurde

Hallo,

bin noch blutiger Anfänger und arbeite grad das Buch durch.
Jetzt habe ich versucht mit dem Code:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
    // Das Truckmodell laden

    if(FAILED(hResult = D3DXLoadMeshFromX("truck.x",
                                          D3DXMESH_MANAGED,
                                          g_pD3DDevice,
                                          NULL,
                                          NULL,
                                          NULL,
                                          NULL,
                                          &g_pTruckModel)))
    {
        // Fehler!

        TB_ERROR_DIRECTX("D3DXLoadMeshFromX", hResult, TB_ERROR);
    }

ein Model aus einem x.-Files zu laden, das klappt auch, allerdings wird es ohne Textur angezeigt.
Es ist ganz weiß.
Hier ist der Code zum anzeigen auch noch:

C-/C++-Quelltext

1
2
    // Den Truck zeichnen

    g_pTruckModel->DrawSubset(0);


Also wie gesagt, bin noch Anfänger, ich hab das Model mit Mikshape gemacht, und gehe dann auf Exportieren-> DirectX(JT)..
und da lass ich die Einstellungen wie sie sind.

Weiß jemand wo der Fehler liegt?

CW_Kovok

Alter Hase

Beiträge: 836

Wohnort: nähe Bonn

Beruf: Schüler

  • Private Nachricht senden

2

20.11.2005, 15:38

du musst die textur mit dem model laden schau mal hier(aus den direct x samples):

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
HRESULT InitGeometry()
{
    LPD3DXBUFFER pD3DXMtrlBuffer;

    // Load the mesh from the specified file

    if( FAILED( D3DXLoadMeshFromX( "Tiger.x", D3DXMESH_SYSTEMMEM, 
                                   g_pd3dDevice, NULL, 
                                   &pD3DXMtrlBuffer, NULL, &g_dwNumMaterials, 
                                   &g_pMesh ) ) )
    {
        // If model is not in current folder, try parent folder

        if( FAILED( D3DXLoadMeshFromX( "..\\Tiger.x", D3DXMESH_SYSTEMMEM, 
                                    g_pd3dDevice, NULL, 
                                    &pD3DXMtrlBuffer, NULL, &g_dwNumMaterials, 
                                    &g_pMesh ) ) )
        {
            MessageBox(NULL, "Could not find tiger.x", "Meshes.exe", MB_OK);
            return E_FAIL;
        }
    }

    // We need to extract the material properties and texture names from the 

    // pD3DXMtrlBuffer

    D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
    g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials];
    if( g_pMeshMaterials == NULL )
        return E_OUTOFMEMORY;
    g_pMeshTextures  = new LPDIRECT3DTEXTURE9[g_dwNumMaterials];
    if( g_pMeshTextures == NULL )
        return E_OUTOFMEMORY;

    for( DWORD i=0; i<g_dwNumMaterials; i++ )
    {
        // Copy the material

        g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;

        // Set the ambient color for the material (D3DX does not do this)

        g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;

        g_pMeshTextures[i] = NULL;
        if( d3dxMaterials[i].pTextureFilename != NULL && 
            lstrlen(d3dxMaterials[i].pTextureFilename) > 0 )
        {
            // Create the texture

            if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, 
                                                d3dxMaterials[i].pTextureFilename, 
                                                &g_pMeshTextures[i] ) ) )
            {
                // If texture is not in current folder, try parent folder

                const TCHAR* strPrefix = TEXT("..\\");
                TCHAR strTexture[MAX_PATH];
                StringCchCopy( strTexture, MAX_PATH, strPrefix );
                StringCchCat( strTexture, MAX_PATH, d3dxMaterials[i].pTextureFilename );
                // If texture is not in current folder, try parent folder

                if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, 
                                                    strTexture, 
                                                    &g_pMeshTextures[i] ) ) )
                {
                    MessageBox(NULL, "Could not find texture map", "Meshes.exe", MB_OK);
                }
            }
        }
    }

    // Done with the material buffer

    pD3DXMtrlBuffer->Release();

    return S_OK;
}


und dann zum anzeigen:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
VOID Render()
{
    // Clear the backbuffer and the zbuffer

    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
                         D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
    
    // Begin the scene

    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        // Setup the world, view, and projection matrices

        SetupMatrices();

        // Meshes are divided into subsets, one for each material. Render them in

        // a loop

        for( DWORD i=0; i<g_dwNumMaterials; i++ )
        {
            // Set the material and texture for this subset

            g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
            g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );
        
            // Draw the mesh subset

            g_pMesh->DrawSubset( i );
        }

        // End the scene

        g_pd3dDevice->EndScene();
    }

    // Present the backbuffer contents to the display

    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}


also:

Mesh öffnen, die Materialien mit laden, Texturen laden, und dann pro textur die drawSubset methode aufrufen[/cpp]

3

20.11.2005, 16:18

ok danke für die schnelle antwort, dann werd ich mir den Code mal einverleiben ;p

Werbeanzeige