当前位置: 首页>>代码示例>>C#>>正文


C# Mesh.GenerateAdjacency方法代码示例

本文整理汇总了C#中Mesh.GenerateAdjacency方法的典型用法代码示例。如果您正苦于以下问题:C# Mesh.GenerateAdjacency方法的具体用法?C# Mesh.GenerateAdjacency怎么用?C# Mesh.GenerateAdjacency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mesh的用法示例。


在下文中一共展示了Mesh.GenerateAdjacency方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: buildMesh

        /// <summary>
        /// Copies over the vertex and index buffers and calls the function within
        /// the model class to build a Mesh class.
        /// </summary>
        private void buildMesh()
        {
            VertexElement[] vElements = new VertexElement[]
            {
               new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
               new VertexElement(0, 12, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0),
                new VertexElement(0, 20, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0),
               new VertexElement(0, 32, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Tangent, 0),
               VertexElement.VertexDeclarationEnd
            };

            // Creates a new mesh
            try
            {
                mesh = new Mesh(faceList.Count, vertexInfo.Count, MeshFlags.Managed | MeshFlags.Use32Bit, vElements, device);

                mesh.SetVertexBufferData(vertexInfo.ToArray(), LockFlags.None);
                mesh.SetIndexBufferData(faceList.ToArray(), LockFlags.None);
            }
            catch(DirectXException)
            {
                MessageBox.Show("A problem occured with the model", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                faceList.Clear();
                vertexInfo.Clear();
                vertexList.Clear();
                mesh = new Mesh(1, 1, MeshFlags.Managed, vElements, device);
                return;
            }

            // Try loop to generate normals (if needed), tangents and binormals.
            try
            {
                // Generates a list of adjacent faces used for generating normals.
                int[] adjacency = new int[mesh.NumberFaces * 3];
                mesh.GenerateAdjacency(0, adjacency);

                if(!hasNormals)
                    mesh.ComputeNormals(adjacency);

                TangentBuilder.CalculateTangents(mesh);
            }
            catch (DirectXException dxe)
            {
                Console.WriteLine(dxe);
            }
        }
开发者ID:TheKeg,项目名称:Polyviewer,代码行数:50,代码来源:ObjectLoader.cs

示例2: CreateMesh

        private Mesh CreateMesh(aiMesh aiMesh, out Vector3 min, out Vector3 max)
        {
            var numFaces = (int) aiMesh.mNumFaces;
            var numVertices = (int) aiMesh.mNumVertices;

            var dxMesh = new Mesh(numFaces, numVertices, MeshFlags.Managed | MeshFlags.Use32Bit,
                CustomVertex.PositionNormalTextured.Format, device);

            var aiPositions = aiMesh.mVertices;
            var aiNormals = aiMesh.mNormals;
            var aiTextureCoordsAll = aiMesh.mTextureCoords;
            var aiTextureCoords = (aiTextureCoordsAll!=null) ? aiTextureCoordsAll[0] : null;
            var dxVertices = new CustomVertex.PositionNormalTextured[numVertices];
            for (int i = 0; i < numVertices; ++i) {
                dxVertices[i].Position = aiPositions[i].ToVector3();
                if (aiNormals != null) {
                    dxVertices[i].Normal = aiNormals[i].ToVector3();
                }
                if (aiTextureCoords != null) {
                    var uv = aiTextureCoords[i];
                    dxVertices[i].Tu = uv.x;
                    dxVertices[i].Tv = uv.y;
                }
            }
            dxMesh.VertexBuffer.SetData(dxVertices, 0, LockFlags.None);

            var aiFaces = aiMesh.mFaces;
            var dxIndices = new uint[numFaces * 3];
            for (int i = 0; i < numFaces; ++i) {
                var aiFace = aiFaces[i];
                var aiIndices = aiFace.mIndices;
                for (int j = 0; j < 3; ++j) {
                    dxIndices[i * 3 + j] = aiIndices[j];
                }
            }
            dxMesh.IndexBuffer.SetData(dxIndices, 0, LockFlags.None);

            var dxAttributes = dxMesh.LockAttributeBufferArray(LockFlags.None);
            // TODO: Set face material index for attributes
            dxMesh.UnlockAttributeBuffer(dxAttributes);

            var adjacency = new int[numFaces * 3];
            dxMesh.GenerateAdjacency(0.0f, adjacency);
            dxMesh.OptimizeInPlace(MeshFlags.OptimizeAttributeSort, adjacency);

            Geometry.ComputeBoundingBox(dxVertices, CustomVertex.PositionNormalTextured.StrideSize, out min, out max);

            return dxMesh;
        }
开发者ID:henrikno,项目名称:assimp,代码行数:49,代码来源:AssimpView.cs

示例3: BasicSetup

        private unsafe void BasicSetup(byte[] data, string tex0)
        {
            LoadReturn lr=Load(data, data.Length);
            if(lr.Subsets<=0) throw new ApplicationException("Failed to load nif");
            subsets=new Subset[lr.Subsets];
            radius=lr.maxsize;
            loadLog=new string(lr.log);
            if(lr.FailedSubsets>0) System.Windows.Forms.MessageBox.Show(""+lr.FailedSubsets+" could not be rendered", "Warning");

            string texFileName;
            for(uint i=0;i<subsets.Length;i++) {
                //Get basic info
                GetInfo(i, out subsets[i].info);
                GetMaterial(i, out subsets[i].mat);
                GetTransform(i, out subsets[i].transform);
                if(i==0&&tex0!=null) texFileName=tex0;
                else if(subsets[i].info.containsTexture) {
                    sbyte* charPtr;
                    GetTex(i, out charPtr);
                    texFileName=new string(charPtr);
                } else texFileName=null;

                //sanity check
                //if(!subsets[i].info.containsTexCoords) throw new ApplicationException("Vertex texture coords are missing from subset "+i);
                //if(!subsets[i].info.containsNormals) throw new ApplicationException("Vertex normals are missing from subset "+i);
                //if(texFileName==null) throw new ApplicationException("No texture name was specified in subset "+i);

                //Load textures
                if(texFileName!=null) {
                    System.IO.Stream stream=BSAArchive.GetTexture(texFileName);
                    if(stream!=null) {
                        subsets[i].colorMap=TextureLoader.FromStream(device, stream);
                        SurfaceDescription desc=subsets[i].colorMap.GetLevelDescription(0);
                        subsets[i].data.cWidth=desc.Width;
                        subsets[i].data.cHeight=desc.Height;
                        subsets[i].data.cformat=desc.Format;
                        subsets[i].data.path=texFileName;
                    } else throw new ApplicationException("Could not load texture for subset "+i);
                    stream=BSAArchive.GetGlowTexture(texFileName);
                    if(stream!=null) {
                        subsets[i].glowMap=TextureLoader.FromStream(device, stream);
                        SurfaceDescription desc=subsets[i].glowMap.GetLevelDescription(0);
                        subsets[i].data.gWidth=desc.Width;
                        subsets[i].data.gHeight=desc.Height;
                        subsets[i].data.gformat=desc.Format;
                    } else subsets[i].data.gWidth=-1;
                    stream=BSAArchive.GetNormalTexture(texFileName);
                    if(stream!=null) {
                        subsets[i].normalMap=TextureLoader.FromStream(device, stream);
                        SurfaceDescription desc=subsets[i].normalMap.GetLevelDescription(0);
                        subsets[i].data.nWidth=desc.Width;
                        subsets[i].data.nHeight=desc.Height;
                        subsets[i].data.nformat=desc.Format;
                    } else subsets[i].data.nWidth=-1;
                } else {
                    subsets[i].colorMap=null;
                    subsets[i].data.cWidth=-1;
                    subsets[i].data.gWidth=-1;
                    subsets[i].data.nWidth=-1;
                }

                //Get vertex information
                VertexElement[] decl=new VertexElement[7];
                decl[0]=new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0);
                decl[1]=new VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Tangent, 0);
                decl[2]=new VertexElement(0, 24, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.BiNormal, 0);
                decl[3]=new VertexElement(0, 36, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0);
                decl[4]=new VertexElement(0, 48, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0);
                decl[5]=new VertexElement(0, 56, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Color, 0);
                decl[6]=VertexElement.VertexDeclarationEnd;
                subsets[i].vDecl=new VertexDeclaration(device, decl);

                if(subsets[i].info.containsTangentBinormal) {
                    Mesh m=new Mesh(subsets[i].info.iCount/3, subsets[i].info.vCount, MeshFlags.SystemMemory, decl, device);

                    subsets[i].vBuffer=new VertexBuffer(typeof(ConvertedVertex), subsets[i].info.vCount, device, Usage.WriteOnly, VertexFormats.None, Pool.Managed);
                    //ConvertedVertex[] cv=(ConvertedVertex[])subsets[i].vBuffer.Lock(0, LockFlags.None);
                    ConvertedVertex[] cv=(ConvertedVertex[])m.LockVertexBuffer(typeof(ConvertedVertex), LockFlags.None, subsets[i].info.vCount);
                    fixed(ConvertedVertex* cvPtr = cv) {
                        GetVerticies(i, cvPtr);
                    }
                    m.UnlockVertexBuffer();
                    //subsets[i].vBuffer.Unlock();

                    //Indicies
                    subsets[i].iBuffer=new IndexBuffer(typeof(ushort), subsets[i].info.iCount, device, Usage.WriteOnly, Pool.Managed);
                    //ushort[] indicies=(ushort[])subsets[i].iBuffer.Lock(0, LockFlags.None);
                    ushort[] indicies=(ushort[])m.LockIndexBuffer(typeof(ushort), LockFlags.None, subsets[i].info.iCount);
                    fixed(ushort* iPtr = indicies) {
                        GetIndicies(i, iPtr);
                    }
                    //subsets[i].iBuffer.Unlock();
                    m.UnlockIndexBuffer();
                    subsets[i].numTris=subsets[i].info.iCount/3;

                    int[] adj=new int[subsets[i].info.iCount];
                    m.GenerateAdjacency(0.01f, adj);
                    m.ComputeTangent(0, 0, 0, 1, adj);

                    //m.ComputeTangentFrame(TangentOptions.CalculateNormals|TangentOptions.GenerateInPlace);
//.........这里部分代码省略.........
开发者ID:BioBrainX,项目名称:fomm,代码行数:101,代码来源:NifFile.cs

示例4: OnCreateDevice

        /// <summary>Called when the device has been created</summary>
        public static void OnCreateDevice(Device device)
        {
            // Store the device
            DirectionWidget.device = device;

            // Read the effect file
            string path = "UI\\DXUTShared.fx";

            // If this fails, there should be debug output as to 
            // why the .fx file failed to compile (assuming you have dbmon running).
            // If you do not, you can turn on unmanaged debugging for this project.
            effect = Effect.FromFile(device, path, null, null, ShaderFlags.NotCloneable, null);

            // Load the mesh with D3DX and get back a Mesh.  For this
            // sample we'll ignore the X file's embedded materials since we know 
            // exactly the model we're loading.  See the mesh samples such as
            // "OptimizedMesh" for a more generic mesh loading example.
            path = "UI\\arrow.x";
            mesh = Mesh.FromFile(path, MeshFlags.Managed, device);

            // Optimize the mesh for this graphics card's vertex cache 
            // so when rendering the mesh's triangle list the vertices will 
            // cache hit more often so it won't have to re-execute the vertex shader 
            // on those vertices so it will improve perf.     
            int[] adj = new int[mesh.NumberFaces * 3];
            mesh.GenerateAdjacency(1e-6f, adj);
            mesh.OptimizeInPlace(MeshFlags.OptimizeVertexCache, adj);
        }
开发者ID:IntegralLee,项目名称:fomm,代码行数:29,代码来源:dxmutmisc.cs

示例5: LoadMesh

        // loads the heightMap into the vertex and index buffer
        private void LoadMesh()
        {
            if (mesh != null)
                mesh.Dispose();

            mesh = new Mesh(heightMap.IndicesCount / 3, heightMap.VerticesCount,
                0, CustomVertex.PositionNormalTextured.Format, device);

            mesh.VertexBuffer.SetData(heightMap.Vertices, 0, LockFlags.None);
            mesh.IndexBuffer.SetData(heightMap.Indices, 0, LockFlags.None);
            int[] adjacency = new int[mesh.NumberFaces * 3];

            mesh.GenerateAdjacency(0.01F, adjacency);
            mesh.OptimizeInPlace(MeshFlags.OptimizeVertexCache, adjacency);
        }
开发者ID:TrentSterling,项目名称:TerrainGenerator,代码行数:16,代码来源:TerrainForm.cs

示例6: BuildGridGeometry

        void BuildGridGeometry()
        {
            Vector3[] globalverts, gridverts;
            int[] globalindices, gridindices, gridindices2;

            float dx = 10.0f;
            float dz = 10.0f;

            // Generate global grid
            GenTriGrid(inputImageHeight, inputImageWidth, dx, dz, new Vector3(0.0f, -1000f, 0f), out globalverts, out globalindices);

            // Number of sub-grids
            int nGridsY = GetGoodAverage(inputImageHeight);
            int nGridsX = GetGoodAverage(inputImageWidth);

            // Subgrid size
            int GridW = inputImageWidth / nGridsX;
            int GridD = inputImageHeight / nGridsY;

            int gridNumVerts = (GridW+1) * (GridD+1);
            int gridNumTris = (GridD ) * (GridW ) * 2;

            // Generate subgrid indices
            GenTriGrid(GridD+1, GridW+1, dx, dz, new Vector3(0.0f, -5000f, 0f), out gridverts, out gridindices);
            GenTriGrid(GridD, GridW, dx, dz, new Vector3(0.0f, -5000f, 0f), out gridverts, out gridindices2);

            // Define some often used variables
            bool overflowX = false, overflowY = false;
            float w = (GridW*nGridsX) * dx;
            float d = (GridD * nGridsY) * dz;
            Vector3 normal = new Vector3(0f, 1f, 0f);
            Mesh mesh;
            VertexPositionNormalTextured[] vertexData = new VertexPositionNormalTextured[gridNumVerts];
            int subgridX, subgridY, globalIndex, gridIndex;

            // foreach subgrid
            for (int gridX = 0; gridX < nGridsX; gridX++)
            {
                for (int gridY = 0; gridY < nGridsY; gridY++)
                {
                    overflowY = false;
                    overflowX = false;
                    mesh = new Mesh(Renderer.Instance.device, gridNumTris, gridNumVerts, MeshFlags.Use32Bit, VertexPositionNormalTextured.Format);

                    // Check for overflow
                    if ((gridX+1) * (GridW + 1) > inputImageWidth)
                        overflowX = true;
                    else if ((gridY+1) * (GridD + 1) > inputImageHeight)
                        overflowY = true;
                    if (overflowY || overflowX)
                    {
                    }
                    else
                    {
                        for (int subD = 0; subD < GridD + 1; ++subD)
                        {
                            for (int subW = 0; subW < GridW + 1; ++subW)
                            {
                                subgridX = gridX * GridW + subW;
                                subgridY = gridY * GridD + subD;
                                globalIndex = (subgridY * inputImageHeight) + subgridX;
                                gridIndex = (subD * (GridD + 1)) + subW;

                                vertexData[gridIndex].Position = globalverts[globalIndex];
                                //vertexData[gridIndex].Y += GetHeightFromImage(subgridY, subgridX) * scale;
                                vertexData[gridIndex].Position.Y += SampleHeightMap3x3(subgridY, subgridX) * scale;
                                vertexData[gridIndex].Normal = normal;
                                vertexData[gridIndex].TextureCoordinate = new Vector2((vertexData[gridIndex].Position.X + (0.5f * w)) / w, (vertexData[gridIndex].Position.Z - (0.5f * d)) / -d);
                            }
                        }

                        DataStream gs = mesh.LockVertexBuffer(LockFlags.None);
                        gs.WriteRange<VertexPositionNormalTextured>(vertexData);
                        gs.Seek(0, SeekOrigin.Begin);
                        // Todo: Fix AABB and frustrum culling
                        Vector3 min, max;
                        //Geometry.ComputeBoundingBox(gs, gridNumVerts, VertexPositionNormalTextured.Format, out min, out max);
                        mesh.UnlockVertexBuffer();

                        //int[] meshIndices = new int[gridNumTris * 3];
                        DataStream ds = mesh.LockAttributeBuffer(LockFlags.None);
                        for (int i = 0; i < gridNumTris; ++i)
                        {
                            ds.Write<int>(0);
                        }
                        mesh.UnlockAttributeBuffer();

                        //meshIndices = ;
                        gs = mesh.LockIndexBuffer(LockFlags.None);
                        gs.WriteRange<int>(gridindices);
                        mesh.UnlockIndexBuffer();

                        //gs = mesh.LockAttributeBuffer(LockFlags.None);
                        //gs.Write(meshAttr);

                        mesh.ComputeNormals();
                        int[] adj = new int[mesh.FaceCount * 3];
                        mesh.GenerateAdjacency(float.Epsilon);
                        //mesh.OptimizeInPlace(MeshFlags.OptimizeAttributeSort | MeshFlags.OptimizeVertexCache | MeshFlags.OptimizeCompact, adj);
                        Mesh newmesh = mesh.Clone(Renderer.Instance.device, MeshFlags.Managed, VertexPosTexNormalTanBitan.Elements);
//.........这里部分代码省略.........
开发者ID:maesse,项目名称:CubeHags,代码行数:101,代码来源:HeightMap.cs

示例7: LoadMesh

        // 메쉬를 불러오는 함수
        private void LoadMesh(string filenameWithPath, ref Mesh mesh, ref Material[] meshmaterials, ref Texture[] meshtextures)
        {
            ExtendedMaterial[] materialarray;
            mesh = Mesh.FromFile(filenameWithPath, MeshFlags.Managed, m_device, out materialarray);

            if ((materialarray != null) && (materialarray.Length > 0))
            {
                meshmaterials = new Material[materialarray.Length];
                meshtextures = new Texture[materialarray.Length];

                for (int i = 0; i < materialarray.Length; i++)
                {
                    meshmaterials[i] = materialarray[i].Material3D;
                    meshmaterials[i].Ambient = meshmaterials[i].Diffuse;

                    if ((materialarray[i].TextureFilename != null) && (materialarray[i].TextureFilename != string.Empty))
                    {
                        meshtextures[i] = TextureLoader.FromFile(m_device, Class.Renderer.FOLDER_PATH + materialarray[i].TextureFilename);
                    }
                }
            }

            mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, m_device);
            mesh.ComputeNormals();

               int[] adjacency = new int[mesh.NumberFaces * 3];
            mesh.GenerateAdjacency(0.01F, adjacency);
            mesh.OptimizeInPlace(MeshFlags.OptimizeVertexCache, adjacency);
        }
开发者ID:NHNNEXT,项目名称:2014-01-HUDIGAME-skyLab,代码行数:30,代码来源:GameObject.cs

示例8: createMovementGizmo


//.........这里部分代码省略.........
                indices[i * eachILength + 11] = (short)(i * eachVLength + 5);

                indices[i * eachILength + 12] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 13] = (short)(i * eachVLength + 5);
                indices[i * eachILength + 14] = (short)(i * eachVLength + 6);

                indices[i * eachILength + 15] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 16] = (short)(i * eachVLength + 6);
                indices[i * eachILength + 17] = (short)(i * eachVLength + 7);

                indices[i * eachILength + 18] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 19] = (short)(i * eachVLength + 7);
                indices[i * eachILength + 20] = (short)(i * eachVLength + 8);

                indices[i * eachILength + 21] = (short)(i * eachVLength + 0);
                indices[i * eachILength + 22] = (short)(i * eachVLength + 8);
                indices[i * eachILength + 23] = (short)(i * eachVLength + 1);
            }

            for (int i = 3; i < 6; i++)
            {
                // Shaft
                indices[i * eachILength + 0] = (short)((i - 3) * eachVLength + 9);
                indices[i * eachILength + 1] = (short)((i - 3) * eachVLength + 13);
                indices[i * eachILength + 2] = (short)((i - 3) * eachVLength + 10);
                indices[i * eachILength + 3] = (short)((i - 3) * eachVLength + 10);
                indices[i * eachILength + 4] = (short)((i - 3) * eachVLength + 13);
                indices[i * eachILength + 5] = (short)((i - 3) * eachVLength + 14);

                indices[i * eachILength + 6] = (short)((i - 3) * eachVLength + 10);
                indices[i * eachILength + 7] = (short)((i - 3) * eachVLength + 14);
                indices[i * eachILength + 8] = (short)((i - 3) * eachVLength + 11);
                indices[i * eachILength + 9] = (short)((i - 3) * eachVLength + 11);
                indices[i * eachILength + 10] = (short)((i - 3) * eachVLength + 14);
                indices[i * eachILength + 11] = (short)((i - 3) * eachVLength + 15);

                indices[i * eachILength + 12] = (short)((i - 3) * eachVLength + 11);
                indices[i * eachILength + 13] = (short)((i - 3) * eachVLength + 15);
                indices[i * eachILength + 14] = (short)((i - 3) * eachVLength + 12);
                indices[i * eachILength + 15] = (short)((i - 3) * eachVLength + 12);
                indices[i * eachILength + 16] = (short)((i - 3) * eachVLength + 15);
                indices[i * eachILength + 17] = (short)((i - 3) * eachVLength + 16);

                indices[i * eachILength + 18] = (short)((i - 3) * eachVLength + 12);
                indices[i * eachILength + 19] = (short)((i - 3) * eachVLength + 16);
                indices[i * eachILength + 20] = (short)((i - 3) * eachVLength + 13);
                indices[i * eachILength + 21] = (short)((i - 3) * eachVLength + 12);
                indices[i * eachILength + 22] = (short)((i - 3) * eachVLength + 13);
                indices[i * eachILength + 23] = (short)((i - 3) * eachVLength + 9);
            }

            // Squares
            indices[6 * eachILength + 0] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 1] = (short)(3 * eachVLength + 1);
            indices[6 * eachILength + 2] = (short)(3 * eachVLength + 4);
            indices[6 * eachILength + 3] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 4] = (short)(3 * eachVLength + 2);
            indices[6 * eachILength + 5] = (short)(3 * eachVLength + 4);

            indices[6 * eachILength + 6] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 7] = (short)(3 * eachVLength + 2);
            indices[6 * eachILength + 8] = (short)(3 * eachVLength + 6);
            indices[6 * eachILength + 9] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 10] = (short)(3 * eachVLength + 3);
            indices[6 * eachILength + 11] = (short)(3 * eachVLength + 6);

            indices[6 * eachILength + 12] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 13] = (short)(3 * eachVLength + 3);
            indices[6 * eachILength + 14] = (short)(3 * eachVLength + 5);
            indices[6 * eachILength + 15] = (short)(3 * eachVLength + 0);
            indices[6 * eachILength + 16] = (short)(3 * eachVLength + 1);
            indices[6 * eachILength + 17] = (short)(3 * eachVLength + 5);

            m.SetIndexBufferData(indices, LockFlags.None);

            #endregion

            int[] attr = m.LockAttributeBufferArray(LockFlags.Discard);
            int step = eachILength / 3; // 1 face = 3 indices
            for (int i = 0; i < step; i++)
            {
                attr[step * 0 + i] = 0;
                attr[step * 1 + i] = 1;
                attr[step * 2 + i] = 2;
                attr[step * 3 + i] = 3;
                attr[step * 4 + i] = 4;
                attr[step * 5 + i] = 5;
            }

            for (int i = step * 6; i < attr.Length; i++)
            {
                attr[i] = 6 + (i - step * 6) / 2;
            }

            m.UnlockAttributeBuffer(attr);
            int[] adj = new int[m.NumberFaces * 3];
            m.GenerateAdjacency(0.001f, adj);
            m.OptimizeInPlace(MeshFlags.OptimizeVertexCache, adj);
            this.gizmo = m;
        }
开发者ID:nolenfelten,项目名称:Blam_BSP,代码行数:101,代码来源:Gizmo.cs

示例9: GenerateMesh

        /// <summary>
        /// Generates a mesh from the parsed 
        /// information of the file
        /// </summary>
        private void GenerateMesh(Device d3dDevice)
        {
            if(m_alNormals.Count == 0)
                throw new System.Exception("No normals were found for this mesh.");

            if(m_intNumFaces == 0)
                throw new System.Exception("No faces were found for this mesh.");

            if(m_intNumVerts == 0)
                throw new System.Exception("No vertices were found for this mesh.");

            //create a mesh with Poisiton, Normal, and Texture info.  Even if it doesn't contain TextCoords
            m_d3dMesh = new Mesh(m_intNumFaces, m_intNumVerts, MeshFlags.Managed, CustomVertex.PositionNormalTextured.Format, d3dDevice);

            //index array
            short[] aryIndices = new short[m_alVertFormat.Count];
            CustomVertex.PositionNormalTextured[] aryVerts = new CustomVertex.PositionNormalTextured[m_intNumVerts];

            Vector3 v, t, n;
            CustomVertex.PositionNormalTextured cvVert;

            //loop through each face and apply the format
            for(int i=0; i<m_intNumFaces * 3; i++)
            {
                //parse the vertex information
                string[] aryVertInfo = (string[])m_alVertFormat[i];

                //first one is vertex index
                short index = short.Parse(aryVertInfo[0]);

                //OBJ format starts at 1 not 0
                index--;

                //set the index arry
                aryIndices[i] = index;
                v = (Vector3)m_alVertices[index];

                t = new Vector3(0,0,0);
                //parse the texture coords
                if( aryVertInfo.Length == 3)
                {
                    index = short.Parse(aryVertInfo[1]);
                    index--;

                    //set the texture coordinate
                    t = (Vector3)m_alTextCoords[index];

                    index = short.Parse(aryVertInfo[2]);
                    index--;

                    //set the normal
                    n = (Vector3)m_alNormals[index];
                }
                else
                {
                    index = short.Parse(aryVertInfo[1]);
                    index--;

                    //set the normal
                    n = (Vector3)m_alNormals[index];
                }

                cvVert = aryVerts[aryIndices[i]];

                cvVert.Position = v;

                cvVert.Normal = n;

                cvVert.Tu = t.X;
                cvVert.Tv = t.Y;

                aryVerts[aryIndices[i]] = cvVert;

            }//end for loop

            m_d3dMesh.VertexBuffer.SetData(aryVerts,0, LockFlags.None);
            m_d3dMesh.IndexBuffer.SetData(aryIndices,0,LockFlags.None);

            AttributeRange ar = new AttributeRange();
            ar.AttributeId = 0;
            ar.FaceCount = m_intNumFaces;
            ar.FaceStart = 0;
            ar.VertexCount = m_intNumVerts;
            ar.VertexStart = 0;

            m_d3dMesh.SetAttributeTable(new AttributeRange[] {ar});

            int[] adj = new int[m_intNumFaces * 3];
            m_d3dMesh.GenerateAdjacency(0.01f, adj);
            m_d3dMesh.OptimizeInPlace(MeshFlags.OptimizeVertexCache | MeshFlags.OptimizeIgnoreVerts, adj);
            m_d3dMesh.ComputeNormals();

            m_bLoaded = true;
        }
开发者ID:NeuroRoboticTech,项目名称:AnimatLabVersion1,代码行数:98,代码来源:OBJLoader.cs


注:本文中的Mesh.GenerateAdjacency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。