Git Product home page Git Product logo

Comments (11)

walbourn avatar walbourn commented on May 16, 2024

I assume you mean the island.sdkmesh from the legacy DirectX SDK. It contains only a single mesh(based off using sdkmeshdump.cpp)

SDKMESH C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Samples\Media\IslandScene\island.sdkmesh
    Version 101, LittleEndian
    1 meshes, 1 VBs, 1 IBs, 2 subsets, 1 frames, 2 materials
    VB #0 - 55530 vertices, 32 stride
        "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0
        "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12
        "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24
    IB #0 - 55530 indices (18510 faces) IT_32BIT
          1:    0, 1, 2
          2:    3, 4, 5
          3:    6, 7, 8
          4:    9, 10, 11
          5:    12, 13, 14
     ...
      18506:    55515, 55516, 55517
      18507:    55518, 55519, 55520
      18508:    55521, 55522, 55523
      18509:    55524, 55525, 55526
      18510:    55527, 55528, 55529
    Meshes
     Mesh #0 ''
        1 VBs [ 0 ], 0 IB, 2 subsets, 0 bones
        Subsets (2):
         Subset 0 ''
             material 0, TriangleList, start 0, count 20640
         Subset 1 ''
             material 1, TriangleList, start 0, count 34890
    Materials
     Material 0 ''
         Diffuse: 'grass_turf_v2_tex.dds'
         A: (0.000000, 0.000000, 0.000000, 1.000000)
         D: (0.223529, 0.682353, 0.000000, 1.000000)
         S: (0.000000, 0.000000, 0.000000, 1.000000) ^3.200000
         E: (0.000000, 0.000000, 0.000000, 1.000000)
     Material 1 ''
         Diffuse: 'island_v1_tex.dds'
         A: (0.000000, 0.000000, 0.000000, 1.000000)
         D: (0.662745, 0.541176, 0.380392, 1.000000)
         S: (0.000000, 0.000000, 0.000000, 1.000000) ^3.200000
         E: (0.000000, 0.000000, 0.000000, 1.000000)
    Frames
     Frame 0 ''
         Mesh 0 ('')

I see it has two mesh parts, and I don't see any specific reason why it wouldn't work. Let me try it out.

from directxtk.

omml avatar omml commented on May 16, 2024

Hello, sorry, I meant 2 subsets. Regards

from directxtk.

walbourn avatar walbourn commented on May 16, 2024

Model is rendering both parts fine. The issue is that the way the model is modeled, the first model part must be drawn after the second model part because they sit immediately on top of one another. The only sorting built-into the generic Model::Draw is to draw the non-alpha materials first, then draw the alpha material ones.

To render island.sdkmesh, you need to not use the generic Model::Draw and draw the individual parts in the 'correct' order for that particular model. See ModelMeshPart for how to draw the individual pieces.

from directxtk.

omml avatar omml commented on May 16, 2024

Ok, I'll try that, thanks for your advise.

from directxtk.

walbourn avatar walbourn commented on May 16, 2024

One quick hack for this specific model is to reach into the first ModelMeshPart and set isAlpha to true. This will cause the simple "non-alpha" vs. "alpha" sort to change the draw order.

model->meshes[0]->meshParts[0]->isAlpha = true;

from directxtk.

omml avatar omml commented on May 16, 2024

I tried checking the values of the meshParts members of the mentioned mesh:
for (int i=0; i<2; i++)
{
auto effect = m_model->meshes[0]->meshParts[i]->effect;
auto indexBuffer = m_model->meshes[0]->meshParts[i]->indexBuffer;
auto indexCount = m_model->meshes[0]->meshParts[i]->indexCount;
auto indexFormat = m_model->meshes[0]->meshParts[i]->indexFormat;
auto inputLayout = m_model->meshes[0]->meshParts[i]->inputLayout;
auto isAlpha = m_model->meshes[0]->meshParts[i]->isAlpha;
auto primitiveType = m_model->meshes[0]->meshParts[i]->primitiveType;
auto startIndex = m_model->meshes[0]->meshParts[i]->startIndex;
auto vbDecl = m_model->meshes[0]->meshParts[i]->vbDecl;
auto vertexBuffer = m_model->meshes[0]->meshParts[i]->vertexBuffer;
auto vertexOffset = m_model->meshes[0]->meshParts[i]->vertexOffset;
auto vertexStride = m_model->meshes[0]->meshParts[i]->vertexStride;
}

For the first meshPart I get:
indexCount = 20640
startIndex = 0
isAlpha = false
vertexOffset = 0
vertexStride = 32

For the second one I get:
indexCount = 34890
startIndex = 0
isAlpha = false
vertexOffset = 0
vertexStride = 32

I wonder if I should be getting different values for startIndex, vertexOffset or vertexStride for the second meshPart, or I am doing something wrong?

Thanks

from directxtk.

walbourn avatar walbourn commented on May 16, 2024

I see the problem. That model uses a non-zero vertexStart value for the second subset which is an offset to each index in the IB.

from directxtk.

walbourn avatar walbourn commented on May 16, 2024

Ignore my original comment about isAlpha. I was wrong.

The fix is to add a single line to ModelLoadSDKMESH.cpp:

part->indexCount = static_cast<uint32_t>( subset.IndexCount );
part->startIndex = static_cast<uint32_t>( subset.IndexStart );
part->vertexOffset = static_cast<uint32_t>( subset.VertexStart ); // This was MISSING!
part->vertexStride = static_cast<uint32_t>( vbArray[ mh.VertexBuffers[0] ].StrideBytes );
part->indexFormat = ( ibArray[ mh.IndexBuffer ].IndexType == DXUT::IT_32BIT ) ? DXGI_FORMAT_R32_UINT : DXGI_FORMAT_R16_UINT;
part->primitiveType = primType; 
part->inputLayout = il;
part->indexBuffer = ibs[ mh.IndexBuffer ];
part->vertexBuffer = vbs[ mh.VertexBuffers[0] ];
part->effect = mat.effect;
part->vbDecl = vbDecls[ mh.VertexBuffers[0] ];

Thanks for digging into this one. I also need to add this information to my sdkmeshdump.cpp

from directxtk.

walbourn avatar walbourn commented on May 16, 2024

Fix submitted. Will be included in the next release. Thanks!

c0dcd42

from directxtk.

walbourn avatar walbourn commented on May 16, 2024

BTW, after updating my dump utility, I can see the offset is in use:

             Subset 0 ''
                     material 0, TriangleList
                    index start 0, index count 20640
                    vertex start 0, vertex count 20640
             Subset 1 ''
                     material 1, TriangleList
                    index start 0, index count 34890
                    vertex start 20640, vertex count 34890

The Sample Content Exporter never uses a non-zero VertexStart. It uses IndexStart instead and doesn't currently merge/coalesce VBs/IBs. Therefore the bug was only reproducible with older sdkmesh files produced by legacy exporter tools like the DirectX SDK's .x file converter meshconvert.

from directxtk.

omml avatar omml commented on May 16, 2024

That's great! thanks.

from directxtk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.