• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當自強而不息

            網格模型高級技術(2)

            我們在cube_1.x的基礎上添加材質、法線和紋理,構成cube_2.x:

            xof 0302txt 0064
            Header {
            1;
            0;
            1;
            }
            Material RedMaterial {                    //第一塊材料
            1.000000;0.000000;0.000000;1.000000;; // R = 1.0, G = 0.0, B = 0.0
            0.000000;
            0.000000;0.000000;0.000000;;
            0.000000;0.000000;0.000000;;
            	TextureFilename 
            {
            "Tex1.jpg"; //紋理文件名
            }
            }
            Material GreenMaterial {                  //第二塊材料
            0.000000;1.000000;0.000000;1.000000;; // R = 0.0, G = 1.0, B = 0.0
            0.000000;
            0.000000;0.000000;0.000000;;
            0.000000;0.000000;0.000000;;
            	TextureFilename 
            {
            "Tex2.jpg"; //紋理文件名
            }
            }
            Mesh Cube {   //網格
            8; //8個頂點,以下為8個頂點的坐標
            1.000000;1.000000;-1.000000;,
            -1.000000;1.000000;-1.000000;,
            -1.000000;1.000000;1.000000;,
            1.000000;1.000000;1.000000;,
            1.000000;-1.000000;-1.000000;,
            -1.000000;-1.000000;-1.000000;,
            -1.000000;-1.000000;1.000000;,
            1.000000;-1.000000;1.000000;;
            	12;            // 12個面, 以下為每個面三個頂點的索引
            3;0,1,2;,
            3;0,2,3;,
            3;0,4,5;,
            3;0,5,1;,
            3;1,5,6;,
            3;1,6,2;,
            3;2,6,7;,
            3;2,7,3;,
            3;3,7,4;,
            3;3,4,0;,
            3;4,7,6;,
            3;4,6,5;;
            	//網格材質列表
            MeshMaterialList {
            2; //使用材質的數量:2塊材質
            12; //為12個面指定材質
            0, //為前6個面使用第一塊材質
            0,
            0,
            0,
            0,
            0,
            1, //為后面的6個面使用第二塊材質
            1,
            1,
            1,
            1,
            1;;
            		{RedMaterial}       //第一塊材質,引用前面定義的RedMaterial材質
            {GreenMaterial} //第二塊材質,引用前面定義的GreenMaterial材質
            }
            	//頂點法線
            MeshNormals {
            8; //定義8個法線向量
            0.333333;0.666667;-0.666667;,
            -0.816497;0.408248;-0.408248;,
            -0.333333;0.666667;0.666667;,
            0.816497;0.408248;0.408248;,
            0.666667;-0.666667;-0.333333;,
            -0.408248;-0.408248;-0.816497;,
            -0.666667;-0.666667;0.333333;,
            0.408248;-0.408248;0.816497;;
            		12;                   //為12個面的每個頂點指定法線
            3;0,1,2;,
            3;0,2,3;,
            3;0,4,5;,
            3;0,5,1;,
            3;1,5,6;,
            3;1,6,2;,
            3;2,6,7;,
            3;2,7,3;,
            3;3,7,4;,
            3;3,4,0;,
            3;4,7,6;,
            3;4,6,5;;
            }
            	//紋理坐標
            MeshTextureCoords {
            8; //定義8對紋理坐標
            0.000000;1.000000;
            1.000000;1.000000;
            0.000000;1.000000;
            1.000000;1.000000;
            0.000000;0.000000;
            1.000000;0.000000;
            0.000000;0.000000;
            1.000000;0.000000;;
            }
            }
             

            效果圖如下:


             

            可以看到在Mesh模板中嵌套著一個子模板MeshMaterialList,它是Mesh模板的一部分,用來將每個面與材質相關聯,其定義如下:

            Used in a mesh object to specify which material applies to which faces. The nMaterials member specifies how many materials are present, and materials specify which material to apply.

            template MeshMaterialList
            {
            < F6F23F42-7686-11CF-8F52-0040333594A3 >
            DWORD nMaterials;
            DWORD nFaceIndexes;
            array DWORD faceIndexes[nFaceIndexes];
            [Material <3D82AB4D-62DA-11CF-AB39-0020AF71E433>]
            }

            Where:

            • nMaterials - A DWORD. The number of materials.
            • nFaceIndexes - A DWORD. The number of indices.
            • faceIndexes[nFaceIndexes] - An arrray of DWORDs containing the face indices.

            MeshMaterialList是一個受限的模板,它只能包含Material模板,其定義如下:

            Defines a basic material color that can be applied to either a complete mesh or a mesh's individual faces. The power is the specular exponent of the material.

            Note     The ambient color requires an alpha component.

            TextureFilename is an optional data object. If this object is not present, the face is untextured.

            template Material
            {
            < 3D82AB4D-62DA-11CF-AB39-0020AF71E433 >
            ColorRGBA faceColor;
            FLOAT power;
            ColorRGB specularColor;
            ColorRGB emissiveColor;
            [...]
            }

            Where:

            • faceColor - Face color. A ColorRGBA template.
            • power - Material specular color exponent.
            • specularColor - Material specular color. A ColorRGB template.
            • emissiveColor - Material emissive color. A ColorRGB template.

             

            Defines a color object with an alpha component. This is used for the face color in the material template definition.

            template ColorRGBA
            {
            < 35FF44E0-6C7C-11cf-8F52-0040333594A3 >
            float red;
            float green;
            float blue;
            float alpha;
            }

            Defines the basic RGB color object.

            template ColorRGB
            {
            < D3E16E81-7835-11cf-8F52-0040333594A3 >
            float red;
            float green;
            float blue;
            }

            在cube_2.x中,首先定義了兩個材質RedMaterial和GreenMaterial:

            Material RedMaterial {                    //第一塊材料
            1.000000;0.000000;0.000000;1.000000;; // R = 1.0, G = 0.0, B = 0.0
            0.000000;
            0.000000;0.000000;0.000000;;
            0.000000;0.000000;0.000000;;
            	TextureFilename 
            {
            "Tex1.jpg"; //紋理文件名
            }
            }
            Material GreenMaterial {                  //第二塊材料
            0.000000;1.000000;0.000000;1.000000;; // R = 0.0, G = 1.0, B = 0.0
            0.000000;
            0.000000;0.000000;0.000000;;
            0.000000;0.000000;0.000000;;
            	TextureFilename 
            {
            "Tex2.jpg"; //紋理文件名
            }
            }

            在模板MeshMaterialList中則給出了各個面與材質的關聯信息:

            //網格材質列表
            MeshMaterialList {
            2; //使用材質的數量:2塊材質
            12; //為12個面指定材質
            0, //為前6個面使用第一塊材質
            0,
            0,
            0,
            0,
            0,
            1, //為后面的6個面使用第二塊材質
            1,
            1,
            1,
            1,
            1;;
            	{RedMaterial}       //第一塊材質,引用前面定義的RedMaterial材質
            {GreenMaterial} //第二塊材質,引用前面定義的GreenMaterial材質
            }

            其中,{RedMaterial}和{GreenMaterial}是對上面定義的材質模板對象的引用。

            在光照模型運算時需要用到法向量,法向量分為面法向量和頂點法向量。在基于逐頂點計算的光照模型中,需要使用頂點法向量。通常頂點法向量的計算過程是:先將共享該頂點的幾個面的面法向量相加并除以共享該頂點的面的個數,接著歸一化這個結果。模板MeshNormals用來指定法向量:

            Defines normals for a mesh. The first array of vectors is the normal vectors themselves, and the second array is an array of indexes specifying which normals should be applied to a given face. The value of the nFaceNormals member should be equal to the number of faces in a mesh.

            template MeshNormals
            {
            < F6F23F43-7686-11cf-8F52-0040333594A3 >
            DWORD nNormals;
            array Vector normals[nNormals];
            DWORD nFaceNormals;
            array MeshFace faceNormals[nFaceNormals];
            }

            Where:

            • nNormals - Number of normals.
            • array Vector normals[nNormals] - Array of normals.
            • nFaceNormals - Number of face normals.
            • array MeshFace faceNormals[nFaceNormals] - Array of mesh face normals.

            在文件cube_2.x中,法向量的定義以及為面指定法向量的內容如下:

            //頂點法線
            MeshNormals {
            8; //定義8個法線向量
            0.333333;0.666667;-0.666667;,
            -0.816497;0.408248;-0.408248;,
            -0.333333;0.666667;0.666667;,
            0.816497;0.408248;0.408248;,
            0.666667;-0.666667;-0.333333;,
            -0.408248;-0.408248;-0.816497;,
            -0.666667;-0.666667;0.333333;,
            0.408248;-0.408248;0.816497;;
            	12;                   //為12個面的每個頂點指定法線
            3;0,1,2;,
            3;0,2,3;,
            3;0,4,5;,
            3;0,5,1;,
            3;1,5,6;,
            3;1,6,2;,
            3;2,6,7;,
            3;2,7,3;,
            3;3,7,4;,
            3;3,4,0;,
            3;4,7,6;,
            3;4,6,5;;
            }

            模板TextureFilename用于引用紋理,它通常作為Material模板對象的子對象出現,其定義如下:

            Enables you to specify the file name of a texture to apply to a mesh or a face. This template should appear within a material object.

            template TextureFilename 
            {
            < A42790E1-7810-11cf-8F52-0040333594A3 >
            string filename;
            }

            在使用TextureFilename模板時,只需要使用字符串filename指定一個紋理文件名即可,但要將這幅紋理映射到網格模型中,還需要指定紋理坐標:

            Defines a mesh's texture coordinates.

            template MeshTextureCoords
            {
            < F6F23F40-7686-11cf-8F52-0040333594A3 >
            DWORD nTextureCoords;
            array Coords2d textureCoords[nTextureCoords] ;
            }

            Where:

            • nTextureCoords - Number of texture coordinates.
            • array Coords2d textureCoords[nTextureCoords] - Array of 2D texture coordinates.

            Defines a two dimensional vector used to define a mesh's (u, v) texture coordinates.

            template Coords2d
            {
            < F6F23F44-7686-11cf-8F52-0040333594A3 >
            float u;
            float v;
            }
            • u - u coordinate value.
            • v - v coordinate value.

            在cube_2.x中,定義紋理坐標的代碼如下:

            //紋理坐標
            MeshTextureCoords {
            8; //定義8對紋理坐標
            0.000000;1.000000;
            1.000000;1.000000;
            0.000000;1.000000;
            1.000000;1.000000;
            0.000000;0.000000;
            1.000000;0.000000;
            0.000000;0.000000;
            1.000000;0.000000;;
            }

            posted on 2008-05-27 14:49 lovedday 閱讀(1761) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            国产精品99精品久久免费| 久久久久97国产精华液好用吗| 久久久久久综合一区中文字幕| 国内精品久久久久伊人av| 婷婷久久久亚洲欧洲日产国码AV| 97久久婷婷五月综合色d啪蜜芽 | 97久久香蕉国产线看观看| 漂亮人妻被黑人久久精品| 久久亚洲精品成人av无码网站| 国产亚洲婷婷香蕉久久精品| 久久精品一区二区三区AV| 香蕉久久夜色精品升级完成| 久久一日本道色综合久久| 人人狠狠综合久久亚洲婷婷| 色综合久久精品中文字幕首页 | 色99久久久久高潮综合影院| 久久av高潮av无码av喷吹| 国产精品久久婷婷六月丁香| 久久久久久精品久久久久| 国产欧美久久一区二区| 精品久久久久久无码国产| 成人午夜精品无码区久久| 国产亚洲精午夜久久久久久| 人人狠狠综合久久亚洲高清| 亚洲精品久久久www| 国产精品久久久久…| 一本一本久久a久久精品综合麻豆| 久久久久亚洲av无码专区导航| 国产精品日韩深夜福利久久| 伊人久久大香线蕉无码麻豆| 亚洲AV无码久久寂寞少妇| 久久精品国产亚洲AV不卡| 久久国产欧美日韩精品| 色天使久久综合网天天| 久久免费线看线看| 94久久国产乱子伦精品免费| 超级97碰碰碰碰久久久久最新| 精品国产一区二区三区久久蜜臀| 69国产成人综合久久精品| 久久久婷婷五月亚洲97号色| 久久国产视屏|