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


C# Mesh.ComputeNormals方法代码示例

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


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

示例1: CreateMesh

        protected override BulletMesh CreateMesh(Device device)
        {
            int totalTriangles = this.indices.Length /3;
            int totalVerts = this.vertices.Length;

            Mesh m = new Mesh(device, totalTriangles, totalVerts, MeshFlags.Use32Bit | MeshFlags.SystemMemory, VertexFormat.Position | VertexFormat.Normal);
            SlimDX.DataStream data = m.LockVertexBuffer(LockFlags.None);
            for (int i = 0; i < this.vertices.Length; i++)
            {
                    data.Write(this.vertices[i].X);
                    data.Write(this.vertices[i].Y);
                    data.Write(this.vertices[i].Z);

                    data.Write(0.0f);
                    data.Write(0.0f);
                    data.Write(0.0f);

                    //data.Write(this.texcoords[i]);

            }
            m.UnlockVertexBuffer();

            data = m.LockIndexBuffer(LockFlags.None);
            for (int i = 0; i < this.indices.Length; i++)
            {
                data.Write(this.indices[i]);
            }
            m.UnlockIndexBuffer();
            m.ComputeNormals();
            return null;// new BulletMesh(m);
        }
开发者ID:sunep,项目名称:dx11-vvvv,代码行数:31,代码来源:ConvexHullShapeDefinition.cs

示例2: MeshClass

        /// <summary>
        /// For creating shape objects
        /// </summary>
        /// <param name="type">the name of the object you wish to create</param>
        public MeshClass(MeshType type)
        {
            if (type == MeshType.Cube)
            {
                objectMesh = Mesh.CreateBox(DeviceManager.LocalDevice, 1f, 1f, 1f);

                objectMesh.ComputeNormals();

                objectMesh.Optimize(MeshOptimizeFlags.Compact);

                ApplyColor(Color.White);
            }
            else if (type == MeshType.Triangle)
            {
                var ShapeVertices = new CustomVertex.VertexPositionColor[] {
                    new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, 1f) },
                    new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, 1f) },
                    new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(-1f, 0f, -1f) },
                    new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(1f, 0f, -1f) },
                    new CustomVertex.VertexPositionColor() { Color = Color.White.ToArgb(), Position = new Vector3(0f, 1f, 0f) },
                };

                var ShapeIndices = new short[] {
                    0, 2, 1,    // base
                    1, 2, 3,
                    0, 1, 4,    // sides
                    1, 3, 4,
                    3, 2, 4,
                    2, 0, 4,
                };

                objectMesh = new Mesh(DeviceManager.LocalDevice, ShapeIndices.Length, ShapeVertices.Length, MeshFlags.Managed, VertexFormat.Position | VertexFormat.Diffuse);

                objectMesh.LockVertexBuffer(LockFlags.None).WriteRange<CustomVertex.VertexPositionColor>(ShapeVertices);
                objectMesh.UnlockVertexBuffer();

                objectMesh.LockIndexBuffer(LockFlags.None).WriteRange<short>(ShapeIndices);
                objectMesh.UnlockIndexBuffer();

                Mesh other = objectMesh.Clone(DeviceManager.LocalDevice, MeshFlags.Managed, objectMesh.VertexFormat | VertexFormat.Normal | VertexFormat.Texture2);
                objectMesh.Dispose();
                objectMesh = null;
                other.ComputeNormals();
                objectMesh = other.Clone(DeviceManager.LocalDevice, MeshFlags.Managed, other.VertexFormat);
                other.Dispose();

                objectMesh.Optimize(MeshOptimizeFlags.Compact);
            }

            ObjectPosition = Vector3.Zero;
            ObjectRotate = Vector3.Zero;
            ObjectScale = new Vector3(1, 1, 1);
            world = Matrix.Translation(ObjectPosition);
            Name = type.ToString();
            IsShapeObject = true;
        }
开发者ID:senbeiwabaka,项目名称:Computer-Graphics-Project,代码行数:60,代码来源:MeshClass.cs

示例3: Model

        /// <summary>
        /// Creates a model out of a single Mesh. TEMP
        /// </summary>
        /// <param name="mesh">Mesh for the given model.</param>
        /// <param name="materials">Materials to apply to mesh</param>
        /// <param name="textures">Textures to apply to mesh</param>
        /// <param name="device">The device to draw to.</param>
        /// <param name="enableSpecular">True if use specular materials</param>
        public Model(Mesh mesh, Material[] materials, Texture[] textures, Vector3 drawRotationOffset, Device device, bool enableSpecular)
        {
            this.drawRotationOffset = drawRotationOffset;
            this.mesh = mesh;
            this.materials = materials;
            this.textures = textures;
            this.enableSpecular = enableSpecular;
            this.models = new List<Model>();

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

            VertexBuffer vertices = mesh.VertexBuffer;
            GraphicsStream stream = vertices.Lock(0, 0, LockFlags.None);
            Vector3 meshcenter;
            this.boundingSphereRadius = Geometry.ComputeBoundingSphere(stream, mesh.NumberVertices, mesh.VertexFormat, out meshcenter);
            vertices.Unlock();
        }
开发者ID:newgrounds,项目名称:Clear-Skies,代码行数:26,代码来源:Model.cs

示例4: Mesh3D

 public Mesh3D(Device device3D, string xFileName,
     Vector3 scal, VertexFormats vertexFormat)
 {
     _device3d = device3D;
     Scal = scal;
     _vertexFormat = vertexFormat;
     string currentDirectory = Application.StartupPath;
     try
     {
         ExtendedMaterial[] materialArray;
         //
         // Check DirectX |*.x file name
         //
         if (!xFileName.EndsWith(".x", true, new System.Globalization.CultureInfo("en-US")))
         {
             throw new Exception(@"Your File is not a DirectX file |*.x" + "\n\rPlease Enter correct FileName.");
         }
         if (!System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + @"\myMeshs\" + xFileName))
         {
             throw new NotFoundException("Given path was not found.");
         }
         Directory.SetCurrentDirectory(Application.StartupPath + @"\myMeshs\");
         mesh = Mesh.FromFile(xFileName, MeshFlags.Managed, device3D, out materialArray);
         //
         // Compute Normals
         //
         if (vertexFormat == CustomVertex.PositionNormalTextured.Format)
         {
             mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device3D);
             mesh.ComputeNormals();
         }
         else if (vertexFormat == CustomVertex.PositionNormalColored.Format)
         {
             mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalColored.Format, device3D);
             mesh.ComputeNormals();
         }
         //
         // set data
         //
         if (materialArray != null && materialArray.Length > 0)
         {
             MeshMaterials = new Material[materialArray.Length];
             MeshTexturs = new Texture[materialArray.Length];
             for (int i = 0; i < materialArray.Length; i++)
             {
                 MeshMaterials[i] = materialArray[i].Material3D;
                 MeshMaterials[i].Ambient = MeshMaterials[i].Diffuse;
                 if (!string.IsNullOrEmpty(materialArray[i].TextureFilename))
                 {
                     MeshTexturs[i] = TextureLoader.FromFile(device3D, materialArray[i].TextureFilename);
                 }
             }
         }
         ComputeRadius();
         optimaize(Math.Max(Math.Max(scal.X, scal.Y), scal.Z));
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message, ex.Source,
             System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
         hasError = true;
     }
     finally
     {
         Directory.SetCurrentDirectory(currentDirectory);
     }
 }
开发者ID:Behzadkhosravifar,项目名称:Room-3D,代码行数:67,代码来源:Mesh3D.cs

示例5: Render

        public void Render(Device device)
        {
            if (!Loaded)
            {
                mesh = Mesh.FromFile(Name, MeshFlags.Managed, 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(device, materialarray[i].TextureFilename);
                        }
                    }
                }
                mesh = mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device);
                mesh.ComputeNormals();

                Loaded = true;
            }
            for (int i = 0; i < meshmaterials.Length; i++)
            {
                device.Material = meshmaterials[i];
                device.SetTexture(0, meshtextures[i]);
                mesh.DrawSubset(i);
            }
            //device.DrawUserPrimitives(PrimitiveType.LineList, 12, vertices);
        }
开发者ID:veggielane,项目名称:orts_old,代码行数:34,代码来源:Shapes.cs

示例6: 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

示例7: toMesh

        /// <summary>
        /// Convierte la pared en un TgcMesh
        /// </summary>
        /// <param name="meshName">Nombre de la malla que se va a crear</param>
        public TgcMesh toMesh(string meshName)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear Mesh
            Mesh d3dMesh = new Mesh(vertices.Length / 3, vertices.Length, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.DiffuseMapVertexElements, d3dDevice);

            //Cargar VertexBuffer
            using (VertexBuffer vb = d3dMesh.VertexBuffer)
            {
                GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                Vector3 ceroNormal = new Vector3(0, 0, 0);
                int whiteColor = Color.White.ToArgb();
                for (int j = 0; j < vertices.Length; j++)
                {
                    TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex v = new TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex();
                    CustomVertex.PositionTextured vWall = vertices[j];

                    //vertices
                    v.Position = vWall.Position;

                    //normals
                    v.Normal = ceroNormal;

                    //texture coordinates diffuseMap
                    v.Tu = vWall.Tu;
                    v.Tv = vWall.Tv;

                    //color
                    v.Color = whiteColor;

                    data.Write(v);
                }
                vb.Unlock();
            }

            //Cargar IndexBuffer en forma plana
            using (IndexBuffer ib = d3dMesh.IndexBuffer)
            {
                short[] indices = new short[vertices.Length];
                for (int j = 0; j < indices.Length; j++)
                {
                    indices[j] = (short)j;
                }
                ib.SetData(indices, 0, LockFlags.None);
            }

            //Calcular normales
            d3dMesh.ComputeNormals();

            //Malla de TGC
            TgcMesh tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.DIFFUSE_MAP);
            tgcMesh.DiffuseMaps = new TgcTexture[] { texture.clone() };
            tgcMesh.Materials = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
            tgcMesh.createBoundingBox();
            tgcMesh.Enabled = true;
            return tgcMesh;
        }
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:62,代码来源:TgcPlaneWall.cs

示例8: RenderSoftBodyTextured

        public void RenderSoftBodyTextured(SoftBody softBody)
        {
            if (!(softBody.UserObject is Array))
                return;

            object[] userObjArr = softBody.UserObject as object[];
            FloatArray vertexBuffer = userObjArr[0] as FloatArray;
            IntArray indexBuffer = userObjArr[1] as IntArray;

            int vertexCount = (vertexBuffer.Count / 8);

            if (vertexCount > 0)
            {
                int faceCount = indexBuffer.Count / 2;

                bool index32 = vertexCount > 65536;

                Mesh mesh = new Mesh(device, faceCount, vertexCount,
                    MeshFlags.SystemMemory | (index32 ? MeshFlags.Use32Bit : 0),
                    VertexFormat.Position | VertexFormat.Normal | VertexFormat.Texture1);

                DataStream indices = mesh.LockIndexBuffer(LockFlags.Discard);
                if (index32)
                {
                    foreach (int i in indexBuffer)
                        indices.Write(i);
                }
                else
                {
                    foreach (int i in indexBuffer)
                        indices.Write((short)i);
                }
                mesh.UnlockIndexBuffer();

                DataStream verts = mesh.LockVertexBuffer(LockFlags.Discard);
                foreach (float f in vertexBuffer)
                    verts.Write(f);
                mesh.UnlockVertexBuffer();

                mesh.ComputeNormals();
                mesh.DrawSubset(0);
                mesh.Dispose();
            }
        }
开发者ID:WebFreak001,项目名称:BulletSharp,代码行数:44,代码来源:MeshFactory.cs

示例9: CreateStaticPlaneShape

        Mesh CreateStaticPlaneShape(StaticPlaneShape shape)
        {
            // Load shader
            if (planeShader == null)
            {
                Assembly assembly = Assembly.GetExecutingAssembly();
                Stream shaderStream = assembly.GetManifestResourceStream("DemoFramework.checker_shader.fx");

                planeShader = Effect.FromStream(device, shaderStream, ShaderFlags.None);
            }


            Vector3[] vertices = new Vector3[4 * 2];

            Mesh mesh = new Mesh(device, 2, 4, MeshFlags.SystemMemory, VertexFormat.Position | VertexFormat.Normal);

            Vector3 planeOrigin = shape.PlaneNormal * shape.PlaneConstant;
            Vector3 vec0, vec1;
            PlaneSpace1(shape.PlaneNormal, out vec0, out vec1);
            float size = 1000;

            Vector3[] verts = new Vector3[4]
                {
                    planeOrigin + vec0*size,
                    planeOrigin - vec0*size,
                    planeOrigin + vec1*size,
                    planeOrigin - vec1*size
                };

            SlimDX.DataStream vertexBuffer = mesh.LockVertexBuffer(LockFlags.Discard);
            vertexBuffer.Write(verts[0]);
            vertexBuffer.Position += 12;
            vertexBuffer.Write(verts[1]);
            vertexBuffer.Position += 12;
            vertexBuffer.Write(verts[2]);
            vertexBuffer.Position += 12;
            vertexBuffer.Write(verts[3]);
            vertexBuffer.Position += 12;
            mesh.UnlockVertexBuffer();

            SlimDX.DataStream indexBuffer = mesh.LockIndexBuffer(LockFlags.Discard);
            indexBuffer.Write((short)1);
            indexBuffer.Write((short)2);
            indexBuffer.Write((short)0);
            indexBuffer.Write((short)1);
            indexBuffer.Write((short)3);
            indexBuffer.Write((short)0);
            mesh.UnlockIndexBuffer();

            mesh.ComputeNormals();

            complexShapes.Add(shape, mesh);

            return mesh;
        }
开发者ID:rhynodegreat,项目名称:BulletSharp,代码行数:55,代码来源:GraphicObjectFactory.cs

示例10: CreateConvexHullShape

        Mesh CreateConvexHullShape(ConvexHullShape shape)
        {
            ShapeHull hull = new ShapeHull(shape);
            hull.BuildHull(shape.Margin);

            UIntArray hullIndices = hull.Indices;
            Vector3Array points = hull.Vertices;


            int vertexCount = hull.NumIndices;
            int faceCount = hull.NumTriangles;

            bool index32 = vertexCount > 65536;

            Mesh mesh = new Mesh(device, faceCount, vertexCount,
                MeshFlags.SystemMemory | (index32 ? MeshFlags.Use32Bit : 0), VertexFormat.Position | VertexFormat.Normal);


            SlimDX.DataStream indices = mesh.LockIndexBuffer(LockFlags.Discard);
            int i;
            if (index32)
            {
                for (i = 0; i < vertexCount; i++)
                    indices.Write(i);
            }
            else
            {
                for (i = 0; i < vertexCount; i++)
                    indices.Write((short)i);
            }
            mesh.UnlockIndexBuffer();

            SlimDX.DataStream verts = mesh.LockVertexBuffer(LockFlags.Discard);
            Vector3 scale = Vector3.Multiply(shape.LocalScaling, 1.0f + shape.Margin);
            for (i = 0; i < vertexCount; i += 3)
            {
                verts.Write(Vector3.Modulate(points[(int)hullIndices[i]], scale));
                verts.Position += 12;
                verts.Write(Vector3.Modulate(points[(int)hullIndices[i+1]], scale));
                verts.Position += 12;
                verts.Write(Vector3.Modulate(points[(int)hullIndices[i+2]], scale));
                verts.Position += 12;
            }
            mesh.UnlockVertexBuffer();

            mesh.ComputeNormals();
            shapes.Add(shape, mesh);

            return mesh;
        }
开发者ID:rhynodegreat,项目名称:BulletSharp,代码行数:50,代码来源:GraphicObjectFactory.cs

示例11: CreateGImpactMeshShape

        Mesh CreateGImpactMeshShape(GImpactMeshShape shape)
        {
            BulletSharp.DataStream verts, indices;
            int numVerts, numFaces;
            PhyScalarType vertsType, indicesType;
            int vertexStride, indexStride;
            shape.MeshInterface.GetLockedReadOnlyVertexIndexData(out verts, out numVerts, out vertsType, out vertexStride,
                out indices, out indexStride, out numFaces, out indicesType);

            bool index32 = numVerts > 65536;

            Mesh mesh = new Mesh(device, numFaces, numVerts,
                MeshFlags.SystemMemory | (index32 ? MeshFlags.Use32Bit : 0), VertexFormat.Position | VertexFormat.Normal);

            SlimDX.DataStream vertexBuffer = mesh.LockVertexBuffer(LockFlags.Discard);
            while (vertexBuffer.Position < vertexBuffer.Length)
            {
                vertexBuffer.Write(verts.Read<Vector3>());
                vertexBuffer.Position += 12;
            }
            mesh.UnlockVertexBuffer();

            SlimDX.DataStream indexBuffer = mesh.LockIndexBuffer(LockFlags.Discard);
            if (index32)
            {
                while (indexBuffer.Position < indexBuffer.Length)
                    indexBuffer.Write(indices.Read<int>());
            }
            else
            {
                while (indexBuffer.Position < indexBuffer.Length)
                    indexBuffer.Write((short)indices.Read<int>());
            }
            mesh.UnlockIndexBuffer();

            mesh.ComputeNormals();
            shapes.Add(shape, mesh);

            return mesh;
        }
开发者ID:rhynodegreat,项目名称:BulletSharp,代码行数:40,代码来源:GraphicObjectFactory.cs

示例12: createMeshes

        private void createMeshes()
        {
            //Crear Teapot
            teapotMesh = Mesh.Teapot(d3dDevice);
            teapotMesh.ComputeNormals();

            //Cargar cara
            faceMesh = Mesh.FromFile(GuiController.Instance.ExamplesMediaDir + "ModelosX" + "\\" + "Cara.x", MeshFlags.Managed, d3dDevice);
            faceMesh.ComputeNormals();

            //El vertex buffer con la linea que apunta a la direccion de la luz.
            lightVectorVB = new CustomVertex.PositionColored[2];

            //Obtener los vertices para obtener las normales de la tetera.
            CustomVertex.PositionNormal[] verts = (CustomVertex.PositionNormal[])
                                                    teapotMesh.VertexBuffer.Lock(0,
                                                        typeof(CustomVertex.PositionNormal),
                                                        LockFlags.None,
                                                        teapotMesh.NumberVertices);

            //El vertex buffer que tiene las lineas de las normales de la tetera;
            teapotMeshNormalsVB = new CustomVertex.PositionColored[verts.Length * 2];

            for (int i = 0; i < verts.Length; i++)
            {
                //El origen del vector normal esta en la posicion del vertice.
                teapotMeshNormalsVB[i * 2].Position = verts[i].Position;

                //El extremo del vector normal es la posicion mas la normal en si misma. Se escala para que se mas proporcionada.
                teapotMeshNormalsVB[i * 2 + 1].Position = verts[i].Position + Vector3.Scale(verts[i].Normal, 1 / 10f);
                teapotMeshNormalsVB[i * 2].Color = teapotMeshNormalsVB[i * 2 + 1].Color = Color.Yellow.ToArgb();
            }

            //Libero el vertex buffer.
            teapotMesh.VertexBuffer.Unlock();

             //Creo el mesh que representa el foco de luz.
            lightBulb = Mesh.Sphere(d3dDevice, 0.5f, 10, 10);
        }
开发者ID:JesusHerrera,项目名称:tgc-viewer,代码行数:39,代码来源:Lighting.cs

示例13: CreateConeLimit

        public static Mesh CreateConeLimit(Microsoft.DirectX.Direct3D.Device d3dDevice, float fltHalfAngle, float fltHeight, int iSides)
        {
            Mesh mesh;
            AttributeRange ar = new AttributeRange();

            float fltRotAmnt = Geometry.DegreeToRadian(360.0f/iSides);

            //create indices
            short[] aryIndices = new short[iSides * 3];

            //create vertices
            CustomVertex.PositionNormal[] aryVerts = new CustomVertex.PositionNormal[iSides + 1];

            //create mesh with desired vertex format and desired size
            mesh = new Mesh(aryIndices.Length/3, aryVerts.Length, MeshFlags.SystemMemory, CustomVertex.PositionNormal.Format, d3dDevice);

            //caclulate the bottom radius vertices
            Vector3 v3Current = new Vector3(0, 0,0);
            aryVerts[0].Position = v3Current;

            v3Current.Z = fltHeight;
            v3Current.TransformCoordinate(Matrix.RotationX(fltHalfAngle));

            aryVerts[1].Position = v3Current;

            for(int i=2; i<iSides + 1; i++)
            {
                v3Current.TransformCoordinate(Matrix.RotationZ(fltRotAmnt));
                aryVerts[i].Position = v3Current;
            }

            //calculate the indices
            int j =0;
            for(int i=0; i<aryIndices.Length; i+=3)
            {
                //get first triangle
                aryIndices[i] = (short)(0);
                aryIndices[i+1] = (short)(j + 2);
                aryIndices[i+2] = (short)(j + 1);

                if(i == aryIndices.Length - 3)
                {
                    aryIndices[i] =	(short)(0);
                    aryIndices[i+1] = (short)(1);
                    aryIndices[i+2] = (short)(j + 1);

                    /*	TODO:  Remove when done
                    Debug.WriteLine("\nj = " + j.ToString());
                    Debug.WriteLine(aryIndices[i]);
                    Debug.WriteLine(aryIndices[i+1]);
                    Debug.WriteLine(aryIndices[i+2]);
                    Debug.WriteLine(aryIndices[i+3]);
                    Debug.WriteLine(aryIndices[i+4]);
                    Debug.WriteLine(aryIndices[i+5]);
                    */
                }
                j++;
            }

            //			aryIndices[0] = 0;
            //			aryIndices[1] = 2;
            //			aryIndices[2] = 1;
            //			aryIndices[3] = 0;
            //			aryIndices[4] = 3;
            //			aryIndices[5] = 2;
            //			aryIndices[6] = 0;
            //			aryIndices[7] = 4;
            //			aryIndices[8] = 3;
            //			aryIndices[9] = 0;
            //			aryIndices[10] = 1;
            //			aryIndices[11] = 4;

            ar.AttributeId = 0;
            ar.FaceStart = 0;
            ar.FaceCount = aryIndices.Length/3;
            ar.VertexStart = 0;
            ar.VertexCount = aryVerts.Length;

            //set the mesh
            mesh.VertexBuffer.SetData(aryVerts, 0, LockFlags.None);
            mesh.IndexBuffer.SetData(aryIndices, 0, LockFlags.None);
            mesh.SetAttributeTable(new AttributeRange[]{ar});

            mesh.ComputeNormals();

            return (mesh);
        }
开发者ID:NeuroRoboticTech,项目名称:AnimatLabVersion1,代码行数:87,代码来源:Util_DX.cs

示例14: InitializeGraphics

        public bool InitializeGraphics()
        {
            //try
            //{
            this.Show();
            this.Focus();
            Application.DoEvents();

            render.CreateDevice(this);
            device = render.device;

            presentParams.Windowed = true; // We don't want to run fullscreen
            presentParams.PresentationInterval = Direct3D.PresentInterval.Default;
            presentParams.FullScreenRefreshRateInHz = Direct3D.PresentParameters.DefaultPresentRate;
            pause = false;

            sphere = Mesh.Sphere(device, 0.15f, 5, 5);
            sphere.ComputeNormals();

            DefaultMaterial = new Material();
            DefaultMaterial.Diffuse = Color.White;
            DefaultMaterial.Ambient = Color.White;
            BlackMaterial  = new Material();
            BlackMaterial.Diffuse = Color.Black;
            BlackMaterial.Ambient = Color.Black;
            BlueMaterial = new Material();
            BlueMaterial.Diffuse = Color.Blue;
            BlueMaterial.Ambient = Color.Blue;
            GreenMaterial = new Material();
            GreenMaterial.Diffuse = Color.GreenYellow;
            GreenMaterial.Ambient = Color.GreenYellow;

            LoadMesh();
            return true;
        }
开发者ID:nolenfelten,项目名称:Blam_BSP,代码行数:35,代码来源:BSPTreeViewer.new.cs

示例15: SetVertexDeclaration

        /// <summary>Updates the mesh to a new vertex declaration</summary>
        public void SetVertexDeclaration(Device device, VertexElement[] decl)
        {
            Mesh tempSystemMesh = null;
            Mesh tempLocalMesh = null;
            VertexElement[] oldDecl = null;
            using(systemMemoryMesh)
            {
                using (localMemoryMesh)
                {
                    // Clone the meshes
                    if (systemMemoryMesh != null)
                    {
                        oldDecl = systemMemoryMesh.Declaration;
                        tempSystemMesh = systemMemoryMesh.Clone(systemMemoryMesh.Options.Value,
                            decl, device);
                    }
                    if (localMemoryMesh != null)
                    {
                        tempLocalMesh = localMemoryMesh.Clone(localMemoryMesh.Options.Value,
                            decl, device);
                    }
                }
            }

            // Store the new meshes
            systemMemoryMesh = tempSystemMesh;
            localMemoryMesh = tempLocalMesh;

            bool hadNormal = false;
            // Check if the old declaration contains a normal.
            for(int i = 0; i < oldDecl.Length; i++)
            {
                if (oldDecl[i].DeclarationUsage == DeclarationUsage.Normal)
                {
                    hadNormal = true;
                    break;
                }
            }
            // Check to see if the new declaration has a normal
            bool hasNormalNow = false;
            for(int i = 0; i < decl.Length; i++)
            {
                if (decl[i].DeclarationUsage == DeclarationUsage.Normal)
                {
                    hasNormalNow = true;
                    break;
                }
            }

            // Compute normals if they are being requested and the old mesh didn't have them
            if ( !hadNormal && hasNormalNow )
            {
                if (systemMemoryMesh != null)
                    systemMemoryMesh.ComputeNormals();
                if (localMemoryMesh != null)
                    localMemoryMesh.ComputeNormals();
            }
        }
开发者ID:JeremiahZhang,项目名称:AKA,代码行数:59,代码来源:dxmutmesh.cs


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