.dae文件如何存储网格数据

How do .dae Files Store Mesh Data?

本文关键字:存储 网格 数据 文件 何存储 dae      更新时间:2023-10-16

我正在尝试使用 TinyXML 从 .dae 文件读取网格到 DirectX 项目,但我很难理解 .dae 文件如何存储网格数据。

我相信我已经找到了网格数据的存储位置:在标签<library_geometries>内有以下代码:

<library_geometries>
    <geometry id="Tall_bodyShape" name="Tall_bodyShape">
        <mesh>
            <source id="Tall_bodyShape-positions" name="position">
                <float_array id="Tall_bodyShape-positions-array" count="2910"> *** lots of numbers *** </float_array>
                <technique_common>
                    <accessor source="#Tall_bodyShape-positions-array" count="970" stride="3">
                        <param name="X" type="float"/>
                        <param name="Y" type="float"/>
                        <param name="Z" type="float"/>
                    </accessor>
                </technique_common>
            </source>
            <source id="Tall_bodyShape-normals" name="normal">
                <float_array id="Tall_bodyShape-normals-array" count="3948"> *** lots of numbers *** </float_array>
                <technique_common>
                    <accessor source="#Tall_bodyShape-normals-array" count="1316" stride="3">
                        <param name="X" type="float"/>
                        <param name="Y" type="float"/>
                        <param name="Z" type="float"/>
                    </accessor>
                </technique_common>
            </source>
            <source id="Tall_bodyShape-UVChannel_1" name="UVChannel_1">
                <float_array id="Tall_bodyShape-UVChannel_1-array" count="2892"> *** lots of numbers *** </float_array>
                <technique_common>
                    <accessor source="#Tall_bodyShape-UVChannel_1-array" count="1446" stride="2">
                        <param name="S" type="float"/>
                        <param name="T" type="float"/>
                    </accessor>
                </technique_common>
            </source>
            <vertices id="Tall_bodyShape-vertices">
                <input semantic="POSITION" source="#Tall_bodyShape-positions"/>
            </vertices>
            <triangles material="Tall_bodySG" count="1883">
                <input semantic="VERTEX" source="#Tall_bodyShape-vertices" offset="0"/>
                <input semantic="NORMAL" source="#Tall_bodyShape-normals" offset="1"/>
                <input semantic="TEXCOORD" source="#Tall_bodyShape-UVChannel_1" offset="2" set="0"/>
                <p> *** lots of numbers *** </p>
            </triangles>
        </mesh>
        <extra>
            <technique profile="MAYA">
                <double_sided>1</double_sided>
            </technique>
        </extra>
    </geometry>
</library_geometries>

因此,顶点存储在名为 "position"<source>标签中,法线存储在名为 "normal"<source>标签中,<triangles>标签列出哪些 UV 坐标和法线与哪个顶点相关联。

我假设三角形

以"线"或"剥离"方法列出,但它没有说明我尝试哪个和哪个,它们都显示锯齿状的、球状的三角形混乱。

有谁知道我是否遗漏了其他一些网格数据,这些数据在dae的另一部分,或者我可能出错了?如有必要,我可以发布加载网格数据的函数。

编辑:附加说明:我确定.dae文件是正确的和有效的,因为它可以正确加载到PhyreEngine中(我使用的是去年用于大学项目的.dae(。

我意识到这是一个相对古老的问题,但由于它还没有真正得到回答,我将为后人尝试一下。

您是正确的,位置、法线等作为浮点数组存储在<source>元素中。 <p>("基元"(元素将紧接在 <triangles> 元素中列出的三个输入的索引存储在该元素中。 也就是说,前 3 个整数(例如"0 0 0"(指向第一个顶点的相应 VERTEX、NORMAL 和 TEXCOORD (UVChannel( 值。 它位于 <triangles> 元素中表示每组 3 个顶点(9 个索引整数(描述一个新的三角形,因此不会重复使用任何索引。 如果几何设置为使用条带(重用前 2 个顶点(或扇形(重用第一个和前一个顶点(,则父元素将分别称为 <tristrips><trifans>。 第二组 3 个整数(例如"1 1 1"(描述第一个三角形中的第二个顶点,依此类推。

此外,正如@jterrace指出的那样,几何坐标是几何中描述的对象的内部坐标。 要将对象作为一个整体正确放置在场景中,您必须从场景中应用适当的变换(<translate><rotate>等(,如<library_visual_scenes>中所述。

我使用simp来加载网格数据。解释和代码在这里:http://www.youtube.com/watch?v=ClqnhYAYtcYhttp://www.mediafire.com/download/006lk0xomup7laq/assimpLinux.zip