Ejemplo n.º 1
0
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            List <VertexPositionNormalTexture> vertexList = new List <VertexPositionNormalTexture>();

#if WINDOWS_PHONE || REACH
            ////gambi shortcut
            List <int> indexList2 = new List <int>();
            GetVertexData(vertexList, indexList2, terrainObject);
            List <short> indexList = new List <short>();
            foreach (var item in indexList2)
            {
                indexList.Add((short)item);
            }
            indexList2.Clear();
#else
            List <int> indexList = new List <int>();
            GetVertexData(vertexList, indexList, terrainObject);
#endif
            modelRadius = (terrainObject.BoundingBox.Value.Max - terrainObject.BoundingBox.Value.Max).Length() / 2;

            var newVertices = new VertexPositionNormalTexture[vertexList.Count];
            vertexList.CopyTo(newVertices);

#if WINDOWS_PHONE || REACH
            var newIndices = new short[indexList.Count];
#else
            var newIndices = new int[indexList.Count];
#endif

            indexList.CopyTo(newIndices);

            VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionNormalTexture.VertexDeclaration, newVertices.Count(), BufferUsage.WriteOnly);
            vertexBufferS.SetData(newVertices);
#if WINDOWS_PHONE || REACH
            IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.SixteenBits, newIndices.Count(), BufferUsage.WriteOnly);
#else
            IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, newIndices.Count(), BufferUsage.WriteOnly);
#endif
            indexBufferS.SetData(newIndices);

            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, newVertices.Count(), newIndices.Count() / 3, 0, 0, VertexPositionNormalTexture.VertexDeclaration, VertexPositionNormalTexture.VertexDeclaration.VertexStride);
            b[0].VertexBuffer             = vertexBufferS;
            b[0].IndexBuffer              = indexBufferS;
            b[0].ModelLocalTransformation = Matrix.Identity;
            BatchInformations[0]          = b;

            TextureInformations       = new TextureInformation[1][];
            TextureInformations[0]    = new TextureInformation[1];
            TextureInformations[0][0] = new TextureInformation(isInternal, factory, null, null, null, null);
            TextureInformations[0][0].LoadTexture();
        }
Ejemplo n.º 2
0
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            List<VertexPositionNormalTexture> vertexList = new List<VertexPositionNormalTexture>();
#if WINDOWS_PHONE || REACH
            ////gambi shortcut
            List<int> indexList2 = new List<int>();
            GetVertexData(vertexList, indexList2, terrainObject);
            List<short> indexList = new List<short>();
            foreach (var item in indexList2)
            {
                indexList.Add( (short) item);
            }
            indexList2.Clear();
#else
            List<int> indexList = new List<int>();
            GetVertexData(vertexList, indexList, terrainObject);
#endif
            modelRadius = (terrainObject.BoundingBox.Value.Max - terrainObject.BoundingBox.Value.Max).Length() / 2;

            var newVertices = new VertexPositionNormalTexture[vertexList.Count];
            vertexList.CopyTo(newVertices);

#if WINDOWS_PHONE|| REACH
            var newIndices = new short[indexList.Count];
#else
            var newIndices = new int[indexList.Count];
#endif
            
            indexList.CopyTo(newIndices);

            VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionNormalTexture.VertexDeclaration, newVertices.Count(), BufferUsage.WriteOnly);
            vertexBufferS.SetData(newVertices);
#if WINDOWS_PHONE || REACH
            IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.SixteenBits,newIndices.Count(),BufferUsage.WriteOnly);
#else
            IndexBuffer indexBufferS = factory.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, newIndices.Count(), BufferUsage.WriteOnly);
#endif
            indexBufferS.SetData(newIndices);
            
            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, newVertices.Count(), newIndices.Count() / 3, 0, 0, VertexPositionNormalTexture.VertexDeclaration,VertexPositionNormalTexture.VertexDeclaration.VertexStride);
            b[0].VertexBuffer = vertexBufferS;
            b[0].IndexBuffer = indexBufferS;
            b[0].ModelLocalTransformation = Matrix.Identity;
            BatchInformations[0] = b;

            TextureInformations = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[1];
            TextureInformations[0][0] = new TextureInformation(isInternal, factory, null, null, null, null);
            TextureInformations[0][0].LoadTexture();
        }
Ejemplo n.º 3
0
        /// <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();
        }
        /// <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();
        }
Ejemplo n.º 5
0
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            Vector3 myPosition = new Vector3(basePosition.X - (myWidth / 2), basePosition.Y, basePosition.Z - (myHeight / 2));

            Vector3[] pos = new Vector3[myWidth * myHeight];
            // Vertices
            VertexMultitextured[] myVertices = new VertexMultitextured[myWidth * myHeight];

            for (int x = 0; x < myWidth; x++)
            {
                for (int y = 0; y < myHeight; y++)
                {
                    myVertices[x + y * myWidth].Position = new Vector3(y, 0, x);
                    pos[x + y * myWidth] = new Vector3(y, 0, x);
                    myVertices[x + y * myWidth].Normal = new Vector3(0, -1, 0);
                    myVertices[x + y * myWidth].TextureCoordinate.X = (float)x / 30.0f;
                    myVertices[x + y * myWidth].TextureCoordinate.Y = (float)y / 30.0f;
                }
            }

            modelRadius = BoundingSphere.CreateFromPoints(pos).Radius;

            // Calc Tangent and Bi Normals.
            for (int x = 0; x < myWidth; x++)
            {
                for (int y = 0; y < myHeight; y++)
                {
                    // Tangent Data.
                    if (x != 0 && x < myWidth - 1)
                    {
                        myVertices[x + y * myWidth].Tangent = myVertices[x - 1 + y * myWidth].Position - myVertices[x + 1 + y * myWidth].Position;
                    }
                    else
                    if (x == 0)
                    {
                        myVertices[x + y * myWidth].Tangent = myVertices[x + y * myWidth].Position - myVertices[x + 1 + y * myWidth].Position;
                    }
                    else
                    {
                        myVertices[x + y * myWidth].Tangent = myVertices[x - 1 + y * myWidth].Position - myVertices[x + y * myWidth].Position;
                    }

                    // Bi Normal Data.
                    if (y != 0 && y < myHeight - 1)
                    {
                        myVertices[x + y * myWidth].BiNormal = myVertices[x + (y - 1) * myWidth].Position - myVertices[x + (y + 1) * myWidth].Position;
                    }
                    else
                    if (y == 0)
                    {
                        myVertices[x + y * myWidth].BiNormal = myVertices[x + y * myWidth].Position - myVertices[x + (y + 1) * myWidth].Position;
                    }
                    else
                    {
                        myVertices[x + y * myWidth].BiNormal = myVertices[x + (y - 1) * myWidth].Position - myVertices[x + y * myWidth].Position;
                    }
                }
            }


            VertexDeclaration vd = new VertexDeclaration(VertexMultitextured.SizeInBytes, VertexMultitextured.VertexElements);
            VertexBuffer      vb = factory.CreateVertexBuffer(vd, myWidth * myHeight, BufferUsage.WriteOnly);

            vb.SetData(myVertices);

            short[] terrainIndices = new short[(myWidth - 1) * (myHeight - 1) * 6];
            for (short x = 0; x < myWidth - 1; x++)
            {
                for (short y = 0; y < myHeight - 1; y++)
                {
                    terrainIndices[(x + y * (myWidth - 1)) * 6]     = (short)((x + 1) + (y + 1) * myWidth);
                    terrainIndices[(x + y * (myWidth - 1)) * 6 + 1] = (short)((x + 1) + y * myWidth);
                    terrainIndices[(x + y * (myWidth - 1)) * 6 + 2] = (short)(x + y * myWidth);

                    terrainIndices[(x + y * (myWidth - 1)) * 6 + 3] = (short)((x + 1) + (y + 1) * myWidth);
                    terrainIndices[(x + y * (myWidth - 1)) * 6 + 4] = (short)(x + y * myWidth);
                    terrainIndices[(x + y * (myWidth - 1)) * 6 + 5] = (short)(x + (y + 1) * myWidth);
                }
            }

            IndexBuffer ib = factory.CreateIndexBuffer(IndexElementSize.SixteenBits, (myWidth - 1) * (myHeight - 1) * 6, BufferUsage.WriteOnly);

            ib.SetData(terrainIndices);

            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, myVertices.Count(), terrainIndices.Count() / 3, 0, 0, vd, VertexMultitextured.SizeInBytes);
            b[0].VertexBuffer    = vb;
            b[0].IndexBuffer     = ib;
            BatchInformations[0] = b;

            TextureInformations       = new TextureInformation[1][];
            TextureInformations[0]    = new TextureInformation[1];
            TextureInformations[0][0] = new TextureInformation(isInternal, factory, null, null, null, null);
            TextureInformations[0][0].LoadTexture();
        }
Ejemplo n.º 6
0
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            Vector3 myPosition = new Vector3(basePosition.X - (myWidth / 2), basePosition.Y, basePosition.Z - (myHeight / 2));
            
            Vector3[] pos = new Vector3[myWidth * myHeight];
            // Vertices
            VertexMultitextured[] myVertices = new VertexMultitextured[myWidth * myHeight];

            for (int x = 0; x < myWidth; x++)
                for (int y = 0; y < myHeight; y++)
                {
                    myVertices[x + y * myWidth].Position = new Vector3(y, 0, x);
                    pos[x + y * myWidth] = new Vector3(y, 0, x); 
                    myVertices[x + y * myWidth].Normal = new Vector3(0, -1, 0);
                    myVertices[x + y * myWidth].TextureCoordinate.X = (float)x / 30.0f;
                    myVertices[x + y * myWidth].TextureCoordinate.Y = (float)y / 30.0f;                    
                }

            modelRadius = BoundingSphere.CreateFromPoints(pos).Radius;            

            // Calc Tangent and Bi Normals.
            for (int x = 0; x < myWidth; x++)
                for (int y = 0; y < myHeight; y++)
                {
                    // Tangent Data.
                    if (x != 0 && x < myWidth - 1)
                        myVertices[x + y * myWidth].Tangent = myVertices[x - 1 + y * myWidth].Position - myVertices[x + 1 + y * myWidth].Position;
                    else
                        if (x == 0)
                            myVertices[x + y * myWidth].Tangent = myVertices[x + y * myWidth].Position - myVertices[x + 1 + y * myWidth].Position;
                        else
                            myVertices[x + y * myWidth].Tangent = myVertices[x - 1 + y * myWidth].Position - myVertices[x + y * myWidth].Position;

                    // Bi Normal Data.
                    if (y != 0 && y < myHeight - 1)
                        myVertices[x + y * myWidth].BiNormal = myVertices[x + (y - 1) * myWidth].Position - myVertices[x + (y + 1) * myWidth].Position;
                    else
                        if (y == 0)
                            myVertices[x + y * myWidth].BiNormal = myVertices[x + y * myWidth].Position - myVertices[x + (y + 1) * myWidth].Position;
                        else
                            myVertices[x + y * myWidth].BiNormal = myVertices[x + (y - 1) * myWidth].Position - myVertices[x + y * myWidth].Position;
            }


            VertexDeclaration vd = new VertexDeclaration(VertexMultitextured.SizeInBytes,VertexMultitextured.VertexElements);
            VertexBuffer vb = factory.CreateVertexBuffer(vd, myWidth * myHeight, BufferUsage.WriteOnly);
            vb.SetData(myVertices);

            short[] terrainIndices = new short[(myWidth - 1) * (myHeight - 1) * 6];
            for (short x = 0; x < myWidth - 1; x++)
            {
                for (short y = 0; y < myHeight - 1; y++)
                {
                    terrainIndices[(x + y * (myWidth - 1)) * 6] = (short)((x + 1) + (y + 1) * myWidth);
                    terrainIndices[(x + y * (myWidth - 1)) * 6 + 1] = (short)((x + 1) + y * myWidth);
                    terrainIndices[(x + y * (myWidth - 1)) * 6 + 2] = (short)(x + y * myWidth);

                    terrainIndices[(x + y * (myWidth - 1)) * 6 + 3] = (short)((x + 1) + (y + 1) * myWidth);
                    terrainIndices[(x + y * (myWidth - 1)) * 6 + 4] = (short)(x + y * myWidth);
                    terrainIndices[(x + y * (myWidth - 1)) * 6 + 5] = (short)(x + (y + 1) * myWidth);
                }
            }

            IndexBuffer ib = factory.CreateIndexBuffer(IndexElementSize.SixteenBits, (myWidth - 1) * (myHeight - 1) * 6, BufferUsage.WriteOnly);
            ib.SetData(terrainIndices);

            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0,myVertices.Count(),terrainIndices.Count() /3,0,0,vd,VertexMultitextured.SizeInBytes);
            b[0].VertexBuffer = vb;
            b[0].IndexBuffer = ib;
            BatchInformations[0] = b;

            TextureInformations = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[1];
            TextureInformations[0][0] = new TextureInformation(isInternal, factory, null, null, null, null);
            TextureInformations[0][0].LoadTexture();
        }
        /// <summary>
        /// Merges some indexedbatchinformation objects.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="GraphicFactory">The graphic factory.</param>
        /// <param name="IndexElementSize">Size of the index element.</param>
        /// <param name="ExtraBatchInformation">The extra batch information.</param>
        public static void MergeIndexedBatchInformation <T>(GraphicFactory GraphicFactory, IndexElementSize IndexElementSize, params BatchInformation[] ExtraBatchInformation)
            where T : struct, IVertexType
        {
            CheckBatchInformationsConsistency <T>(ExtraBatchInformation);
            int NumVerts   = 0;
            int NumIndexes = 0;

            for (int i = 0; i < ExtraBatchInformation.Count(); i++)
            {
                NumVerts   += ExtraBatchInformation[i].VertexBuffer.VertexCount;
                NumIndexes += ExtraBatchInformation[i].IndexBuffer.IndexCount;
            }

            //complete
            int[]             completeindex     = new int[NumVerts];
            T[]               completevertex    = new T[NumIndexes];
            VertexDeclaration VertexDeclaration = ExtraBatchInformation[0].VertexDeclaration;


            //mandatory
            int[] indexbuffer = new int[ExtraBatchInformation[0].IndexBuffer.IndexCount];
            switch (IndexElementSize)
            {
            case IndexElementSize.SixteenBits:
                short[] tempindex = new short[ExtraBatchInformation[0].IndexBuffer.IndexCount];
                ExtraBatchInformation[0].IndexBuffer.GetData <short>(tempindex);
                for (int i = 0; i < tempindex.Count(); i++)
                {
                    indexbuffer[i] = tempindex[i];
                }
                break;

            case IndexElementSize.ThirtyTwoBits:
                ExtraBatchInformation[0].IndexBuffer.GetData <int>(indexbuffer);
                break;

            default:
                break;
            }

            //mandatory
            T[] vertexBuffer = new T[ExtraBatchInformation[0].VertexBuffer.VertexCount];
            ExtraBatchInformation[0].VertexBuffer.GetData <T>(vertexBuffer);

            ExtraBatchInformation[0].VertexBuffer.Dispose();
            ExtraBatchInformation[0].IndexBuffer.Dispose();

            int VertexOffset = 0;
            int IndexOffset  = 0;

            for (int i = 1; i < ExtraBatchInformation.Count(); i++)
            {
                //extra vertex
                T[] ExtravertexBuffer = new T[ExtraBatchInformation[i].VertexBuffer.VertexCount];
                ExtraBatchInformation[i].VertexBuffer.GetData <T>(vertexBuffer);

                //extra index
                int[] ExtraindexBuffer = new int[ExtraBatchInformation[i].IndexBuffer.IndexCount];
                switch (IndexElementSize)
                {
                case IndexElementSize.SixteenBits:
                    short[] tempindex = new short[ExtraBatchInformation[0].IndexBuffer.IndexCount];
                    ExtraBatchInformation[0].IndexBuffer.GetData <short>(tempindex);
                    for (int q = 0; q < ExtraindexBuffer.Count(); q++)
                    {
                        ExtraindexBuffer[q] = tempindex[q];
                    }
                    break;

                case IndexElementSize.ThirtyTwoBits:
                    ExtraBatchInformation[i].IndexBuffer.GetData <int>(ExtraindexBuffer);
                    break;

                default:
                    break;
                }


                for (int v = 0; v < ExtraBatchInformation[i].VertexBuffer.VertexCount; v++)
                {
                    completevertex[VertexOffset + v] = ExtravertexBuffer[v];
                }

                for (int j = 0; j < ExtraBatchInformation[i].IndexBuffer.IndexCount; j++)
                {
                    completeindex[IndexOffset + i] = ExtraindexBuffer[j] + VertexOffset;
                }

                ExtraBatchInformation[i].VertexBuffer.Dispose();
                ExtraBatchInformation[i].IndexBuffer.Dispose();
                ExtraBatchInformation[i].StartIndex  = IndexOffset;
                ExtraBatchInformation[i].StartVertex = VertexOffset;
                VertexOffset += ExtravertexBuffer.Count();
                IndexOffset  += ExtraindexBuffer.Count();
            }

            IndexBuffer  IndexBuffer  = GraphicFactory.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, NumIndexes, BufferUsage.None);
            VertexBuffer VertexBuffer = GraphicFactory.CreateVertexBuffer(VertexDeclaration, NumIndexes, BufferUsage.None);

            for (int i = 0; i < ExtraBatchInformation.Count(); i++)
            {
                ExtraBatchInformation[i].IndexBuffer  = IndexBuffer;
                ExtraBatchInformation[i].VertexBuffer = VertexBuffer;
            }
        }
Ejemplo n.º 8
0
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformation)
        {
            int vertCount  = vertices.Count();
            int indexCount = 0;

            if (indices != null)
            {
                indexCount = indices.Count();
            }
            int noVertices  = vertCount;
            int noTriangles = 0;

            if (indices != null)
            {
                noTriangles = indexCount / 3;
            }
            else
            {
                noTriangles = vertCount / 3;
            }

            VertexBuffer vertexBufferS;
            IndexBuffer  IndexBufferS = null;

            if (isDynamic)
            {
                vertexBufferS = factory.CreateDynamicVertexBuffer(vertices[0].VertexDeclaration, (int)(vertCount * dynamicMultiplier), BufferUsage);
                if (indices != null)
                {
                    IndexBufferS = factory.CreateDynamicIndexBuffer(IndexElementSize.ThirtyTwoBits, (int)(indexCount * dynamicMultiplier), BufferUsage);
                }
            }
            else
            {
                vertexBufferS = factory.CreateVertexBuffer(vertices[0].VertexDeclaration, vertCount, BufferUsage);
                if (indices != null)
                {
                    IndexBufferS = factory.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, indexCount, BufferUsage);
                }
            }

            vertexBufferS.SetData <T>(vertices);
            if (indices != null)
            {
                IndexBufferS.SetData <int>(indices);
            }

            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, vertCount, noTriangles, 0, 0, vertices[0].VertexDeclaration, vertices[0].VertexDeclaration.VertexStride,
                                        indices != null ? BatchType.INDEXED : BatchType.NORMAL);
            b[0].ModelLocalTransformation = transformation;
            b[0].VertexBuffer             = vertexBufferS;
            if (indices != null)
            {
                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();
            TextureInformation = TextureInformations;

            if (!isDynamic)
            {
                vertices = null;
                indices  = null;
            }
        }