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


C# GraphicFactory.CreateDynamicVertexBuffer方法代码示例

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


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

示例1: LoadModel

        /// <summary>
        /// Loads the model.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="BatchInformations">The batch informations.</param>
        /// <param name="TextureInformations">The texture informations.</param>
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            VertexPositionTexture[] billboardVertices = new VertexPositionTexture[4];
            int i = 0;
            
            billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 0));
            billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 0));
            billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 1));
            billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 1));

            VertexElement v0 = new VertexElement(0,VertexElementFormat.Vector3,VertexElementUsage.TextureCoordinate,1);
            VertexElement v1 = new VertexElement(sizeof(float) * 3,VertexElementFormat.Vector2,VertexElementUsage.TextureCoordinate,2);

             vd = new VertexDeclaration(v0, v1);

             VertexBuffer InstancedvertexBufferS;
             if (dynamicBufferSize != -1)
             {
                 InstancedvertexBufferS = factory.CreateDynamicVertexBuffer(vd, dynamicBufferSize, BufferUsage.WriteOnly);
             }
             else
             {
                 InstancedvertexBufferS = factory.CreateDynamicVertexBuffer(vd, instances.Count(), BufferUsage.WriteOnly);
             }            
        
            InstancedvertexBufferS.SetData(instances);

            VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, billboardVertices.Count(), BufferUsage.WriteOnly);
            vertexBufferS.SetData(billboardVertices);

            short[] indices = new short[] { 0,2,1,1,2,3};

            IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly);
            indexBufferS.SetData<short>(indices);
            
            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, 4, 2, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride,instances.Count());
            b[0].VertexBuffer = vertexBufferS;
            b[0].IndexBuffer = indexBufferS;
            b[0].InstancedVertexBuffer = InstancedvertexBufferS;
            BatchInformations[0] = b;

            TextureInformations = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[1];
            TextureInformations[0][0] = new TextureInformation(isInternal, factory, diffuseTextureName, null, null, null);
            TextureInformations[0][0].LoadTexture();
        }
开发者ID:brunoduartec,项目名称:port-ploobsengine,代码行数:54,代码来源:InstancedBilboardModel.cs

示例2: ClothModel

        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleModel"/> class.
        /// </summary>
        /// <param name="factory">The graphic factory.</param>
        /// <param name="PhysxPhysicWorld">The physx physic world.</param>
        /// <param name="clothMeshDesc">The cloth mesh desc.</param>
        /// <param name="Points">The points.</param>
        /// <param name="TextCoords">The text coords.</param>
        /// <param name="Indices">The indices.</param>
        /// <param name="diffuseTextureName">Name of the diffuse texture.</param>
        public ClothModel(GraphicFactory factory, PhysxPhysicWorld PhysxPhysicWorld, ClothMeshDescription clothMeshDesc,  
            Vector3[] Points ,
            Vector2[] TextCoords ,
            int[] Indices ,
            String diffuseTextureName = null)
            : base(factory, "Cloth", false)
        {
            this._diffuseName = diffuseTextureName;            

            VerticesNum = Points.Length;
            IndicesNum = Indices.Length;
            
            clothMeshDesc.AllocateVertices<Vector3>(VerticesNum);
            clothMeshDesc.AllocateTriangles<int>(IndicesNum / 3);

            clothMeshDesc.VertexCount = VerticesNum;
            clothMeshDesc.TriangleCount = IndicesNum / 3;

            BatchInformation = new PloobsEngine.Modelo.BatchInformation(0, VerticesNum, IndicesNum / 3, 0, 0,
                VertexPositionNormalTexture.VertexDeclaration, VertexPositionNormalTexture.VertexDeclaration.VertexStride, PrimitiveType.TriangleList);
            BatchInformation.ModelLocalTransformation = XNA.Matrix.Identity;

            vertexPositionNormalTexture = new VertexPositionNormalTexture[VerticesNum];

            BatchInformation.VertexBuffer = factory.CreateDynamicVertexBuffer(VertexPositionNormalTexture.VertexDeclaration, VerticesNum + (int)(1.2 * VerticesNum), BufferUsage.WriteOnly);
            BatchInformation.IndexBuffer = factory.CreateDynamicIndexBuffer(IndexElementSize.ThirtyTwoBits, IndicesNum + (int)(1.2 * IndicesNum), BufferUsage.WriteOnly);

            BatchInformation.IndexBuffer.SetData<int>(Indices);
            clothMeshDesc.VerticesStream.SetData(Points);
            clothMeshDesc.TriangleStream.SetData(Indices);


            XNA.Vector3[] pts = new XNA.Vector3[BatchInformation.NumVertices];
            for (int i = 0; i < BatchInformation.NumVertices; i++)
            {
                vertexPositionNormalTexture[i].TextureCoordinate = TextCoords[i].AsXNA();
                vertexPositionNormalTexture[i].Position = Points[i].AsXNA();
                pts[i] = vertexPositionNormalTexture[i].Position;
            }
                        
            modelRadius = Microsoft.Xna.Framework.BoundingSphere.CreateFromPoints(pts).Radius;
            pts = null;


            // We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed.
            // 32 bits are the default, so this isn't technically needed, but it's good to show in a sample
            clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;
            //clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable);

            // Write the cooked data to memory
            using (var memoryStream = new MemoryStream())
            {
                Cooking.InitializeCooking();
                Cooking.CookClothMesh(clothMeshDesc, memoryStream);
                Cooking.CloseCooking();

                // Need to reset the position of the stream to the beginning
                memoryStream.Position = 0;

                ClothMesh = PhysxPhysicWorld.Core.CreateClothMesh(memoryStream);
            }

            
            LoadModel(factory, out BatchInformations, out TextureInformations);
        }
开发者ID:brunoduartec,项目名称:port-ploobsengine,代码行数:75,代码来源:ClothModel.cs

示例3: LoadModel

        /// <summary>
        /// Loads the model.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="BatchInformations">The batch informations.</param>
        /// <param name="TextureInformations">The texture informations.</param>
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            int vertCount = bilboards.Count() * 4;
            int indexCount = bilboards.Count() * 6;
            int noVertices = vertCount;
            int noTriangles = indexCount / 3;

            VertexBuffer vertexBufferS = factory.CreateDynamicVertexBuffer(VertexPositionTexture.VertexDeclaration, vertCount, BufferUsage.WriteOnly);
            IndexBuffer IndexBufferS = factory.CreateDynamicIndexBuffer(IndexElementSize.SixteenBits, indexCount, BufferUsage.WriteOnly);

            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, vertCount, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.INDEXED);
            b[0].ModelLocalTransformation = Matrix.Identity;
            b[0].VertexBuffer = vertexBufferS;
            b[0].IndexBuffer = IndexBufferS;
            BatchInformations[0] = b;

            TextureInformations = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[1];
            
            TextureInformations[0][0] = new TextureInformation(isInternal, factory, diffuseTextureName, null, null, null);
            TextureInformations[0][0].LoadTexture();
        }
开发者ID:brunoduartec,项目名称:port-ploobsengine,代码行数:30,代码来源:CPUBilboardModel.cs


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