【问题标题】:Displaying mesh using DirectX 9 - Mesh differences使用 DirectX 9 显示网格 - 网格差异
【发布时间】:2010-08-10 19:54:23
【问题描述】:

This 是我显示 .x 网格的程序。我能够显示网格tiger.x,但无法显示ball.x。两种网格有什么区别?我应该在代码中处理什么吗?但我可以使用标准网格查看器(例如 DirectX SDK 附带的查看器)查看这两个网格。

谢谢。

【问题讨论】:

    标签: directx mesh


    【解决方案1】:

    但无法显示ball.x。

    问题不清楚。网格是否加载?它是否包含顶点/面?或者它可能会导致应用程序崩溃?还是加载失败?

    这两种网格有什么区别?

    不同之处在于第二个网格 (ball.x) 不包含“模板”。

    即这部分:

    template Header {
     <3D82AB43-62DA-11cf-AB39-0020AF71E433>
     WORD major;
     WORD minor;
     DWORD flags;
    }
    
    template Vector {
     <3D82AB5E-62DA-11cf-AB39-0020AF71E433>
     FLOAT x;
     FLOAT y;
     FLOAT z;
    }
    
    template Coords2d {
     <F6F23F44-7686-11cf-8F52-0040333594A3>
     FLOAT u;
     FLOAT v;
    }
    
    template Matrix4x4 {
     <F6F23F45-7686-11cf-8F52-0040333594A3>
     array FLOAT matrix[16];
    }
    
    template ColorRGBA {
     <35FF44E0-6C7C-11cf-8F52-0040333594A3>
     FLOAT red;
     FLOAT green;
     FLOAT blue;
     FLOAT alpha;
    }
    
    template ColorRGB {
     <D3E16E81-7835-11cf-8F52-0040333594A3>
     FLOAT red;
     FLOAT green;
     FLOAT blue;
    }
    
    template IndexedColor {
     <1630B820-7842-11cf-8F52-0040333594A3>
     DWORD index;
     ColorRGBA indexColor;
    }
    
    template Boolean {
     <4885AE61-78E8-11cf-8F52-0040333594A3>
     WORD truefalse;
    }
    
    template Boolean2d {
     <4885AE63-78E8-11cf-8F52-0040333594A3>
     Boolean u;
     Boolean v;
    }
    
    template MaterialWrap {
     <4885AE60-78E8-11cf-8F52-0040333594A3>
     Boolean u;
     Boolean v;
    }
    
    template TextureFilename {
     <A42790E1-7810-11cf-8F52-0040333594A3>
     STRING filename;
    }
    
    template Material {
     <3D82AB4D-62DA-11cf-AB39-0020AF71E433>
     ColorRGBA faceColor;
     FLOAT power;
     ColorRGB specularColor;
     ColorRGB emissiveColor;
     [...]
    }
    
    template MeshFace {
     <3D82AB5F-62DA-11cf-AB39-0020AF71E433>
     DWORD nFaceVertexIndices;
     array DWORD faceVertexIndices[nFaceVertexIndices];
    }
    
    template MeshFaceWraps {
     <4885AE62-78E8-11cf-8F52-0040333594A3>
     DWORD nFaceWrapValues;
     Boolean2d faceWrapValues;
    }
    
    template MeshTextureCoords {
     <F6F23F40-7686-11cf-8F52-0040333594A3>
     DWORD nTextureCoords;
     array Coords2d textureCoords[nTextureCoords];
    }
    
    template MeshMaterialList {
     <F6F23F42-7686-11cf-8F52-0040333594A3>
     DWORD nMaterials;
     DWORD nFaceIndexes;
     array DWORD faceIndexes[nFaceIndexes];
     [Material]
    }
    
    template MeshNormals {
     <F6F23F43-7686-11cf-8F52-0040333594A3>
     DWORD nNormals;
     array Vector normals[nNormals];
     DWORD nFaceNormals;
     array MeshFace faceNormals[nFaceNormals];
    }
    
    template MeshVertexColors {
     <1630B821-7842-11cf-8F52-0040333594A3>
     DWORD nVertexColors;
     array IndexedColor vertexColors[nVertexColors];
    }
    
    template Mesh {
     <3D82AB44-62DA-11cf-AB39-0020AF71E433>
     DWORD nVertices;
     array Vector vertices[nVertices];
     DWORD nFaces;
     array MeshFace faces[nFaces];
     [...]
    }
    
    template FrameTransformMatrix {
     <F6F23F41-7686-11cf-8F52-0040333594A3>
     Matrix4x4 frameMatrix;
    }
    

    即模板/结构声明。

    另外,在 ball.x 中,mesh 是 Frames 层次结构的一部分。在tiger.x 中不是,它存储在层次结构的顶层。

    我上次直接使用 *.x 文件已经有一段时间了,但据我所知,您需要将所有“非标准”模板的模板包含到文件中。即,如果文件使用的对象的模板未使用 ID3DXFile 或 IDirectXFile 的 RegisterTemplates 方法注册,则如果模板未写在文件开头,则不会加载文件。尝试为 ball.x 中的每个可疑结构添加模板定义,直到找到罪魁祸首。我会从“标题”开始。

    如果问题是因为层次结构,您需要尝试其他加载方法。

    使用标准网格查看器,例如 DirectX SDK 随附的。

    AFAIK,网格查看器附带源代码。阅读源代码,看看它是如何工作的。

    【讨论】:

      【解决方案2】:

      网格除了视图没有任何问题。放大到无法显示图像。我使用以下矩阵投影图像并且能够正确查看网格。

      //Set Projection
      D3DXMATRIXA16 matProj(1.0,0.0,0.0,0.0,
                            0.0,1.0,0.0,0.0,
                            0.0,0.0,1.0,0.0,
                            0.0,0.0,0.0,150.0);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-02-13
        • 1970-01-01
        • 2022-11-19
        • 1970-01-01
        • 2013-01-30
        • 1970-01-01
        • 2023-03-12
        相关资源
        最近更新 更多