Ejemplo n.º 1
0
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            billboardVertices = new VertexPositionTexture[maximumaParticles * 6];

            for (int i = 0; i < maximumaParticles * 6;)
            {
                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(1, 1));

                billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 0));
                billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(1, 1));
                billboardVertices[i++] = new VertexPositionTexture(Vector3.Zero, new Vector2(0, 1));
            }


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

            vertexBufferS.SetData(billboardVertices);
            int noVertices  = billboardVertices.Count();
            int noTriangles = noVertices / 3;

            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, 0, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.NORMAL);
            b[0].VertexBuffer    = vertexBufferS;
            b[0].IndexBuffer     = null;
            BatchInformations[0] = b;

            TextureInformations       = new TextureInformation[1][];
            TextureInformations[0]    = new TextureInformation[1];
            TextureInformations[0][0] = new TextureInformation(false, factory, diffuseTextureName, null, null, null);
            TextureInformations[0][0].LoadTexture();
        }
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            VertexPositionTexture[] billboardVertices = new VertexPositionTexture[positions.Count * 6];
            int i = 0;

            foreach (var position in positions)
            {
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 0));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 0));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 1));

                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 0));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 1));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 1));
            }


            VertexBuffer vertexBufferS = factory.CreateVertexBuffer(VertexPositionTexture.VertexDeclaration, billboardVertices.Count(), BufferUsage.WriteOnly);
            vertexBufferS.SetData(billboardVertices);
            int noVertices = billboardVertices.Count();
            int noTriangles = noVertices / 3;

            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, 0, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.NORMAL);
            b[0].VertexBuffer = vertexBufferS;
            b[0].IndexBuffer = null;
            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.º 3
0
        protected override void LoadBatchInfo(GraphicFactory factory, out BatchInformation[][] BatchInformations)
        {
            TreeProfile t = factory.GetAsset <TreeProfile>(profileName);

            if (!String.IsNullOrEmpty(LeaftextureName))
            {
                t.LeafTexture = factory.GetAsset <Texture2D>(LeaftextureName);
            }
            if (!String.IsNullOrEmpty(trunktextureName))
            {
                t.TrunkTexture = factory.GetAsset <Texture2D>(trunktextureName);
            }
            tree = t.GenerateSimpleTree(StaticRandom.RandomInstance);

            BatchInformations = new BatchInformation[2][];
            vertexBufferS     = new VertexBuffer[2];
            indexBufferS      = new IndexBuffer[2];
            indexBufferS[0]   = tree.TrunkMesh.IndexBuffer;
            vertexBufferS[0]  = tree.TrunkMesh.VertexBuffer;
            BatchInformation bi0 = new BatchInformation(0, tree.TrunkMesh.NumberOfVertices, tree.TrunkMesh.NumberOfTriangles, 0, 0, tree.TrunkMesh.Vdeclaration, TreeVertex.SizeInBytes);

            BatchInformations[0]    = new BatchInformation[1];
            BatchInformations[0][0] = bi0;

            indexBufferS[1]  = tree.LeafCloud.Ibuffer;
            vertexBufferS[1] = tree.LeafCloud.Vbuffer;
            BatchInformation bi1 = new BatchInformation(0, tree.LeafCloud.Numleaves * 4, tree.LeafCloud.Numleaves * 2, 0, 0, tree.LeafCloud.Vdeclaration, LeafVertex.SizeInBytes);

            BatchInformations[1]    = new BatchInformation[1];
            BatchInformations[1][0] = bi1;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomModel"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="loader">The loader.</param>
        public CustomModel(GraphicFactory factory, ObjectInformation[] loader)
            : base(factory, loader[0].modelName, false)
        {
            System.Diagnostics.Debug.Assert(loader != null);
            System.Diagnostics.Debug.Assert(loader.Count() != 0);
            BatchInformations    = new BatchInformation[1][];
            BatchInformations[0] = new BatchInformation[loader.Count()];

            TextureInformations    = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[loader.Count()];

            BoundingSphere bs = new BoundingSphere();

            for (int i = 0; i < loader.Count(); i++)
            {
                BatchInformations[0][i]   = loader[i].batchInformation;
                TextureInformations[0][i] = loader[i].textureInformation;

                float   radius;
                Vector3 center;
                ModelBuilderHelper.ExtractModelRadiusAndCenter(BatchInformations[0][i], out radius, out center);
                bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius));
            }
            modelRadius = bs.Radius;
        }
Ejemplo n.º 5
0
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformations)
        {
            VertexPositionTexture[] billboardVertices = new VertexPositionTexture[positions.Count * 6];
            int i = 0;

            foreach (var position in positions)
            {
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 0));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 0));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 1));

                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 0));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(1, 1));
                billboardVertices[i++] = new VertexPositionTexture(position, new Vector2(0, 1));
            }


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

            vertexBufferS.SetData(billboardVertices);
            int noVertices  = billboardVertices.Count();
            int noTriangles = noVertices / 3;

            BatchInformations = new BatchInformation[1][];
            BatchInformation[] b = new BatchInformation[1];
            b[0] = new BatchInformation(0, 0, noTriangles, 0, 0, VertexPositionTexture.VertexDeclaration, VertexPositionTexture.VertexDeclaration.VertexStride, BatchType.NORMAL);
            b[0].VertexBuffer    = vertexBufferS;
            b[0].IndexBuffer     = null;
            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.º 6
0
        protected override void LoadBatchInfo(GraphicFactory factory, out BatchInformation[][] BatchInformations)
        {
            TreeProfile t = factory.GetAsset<TreeProfile>(profileName);
            if (!String.IsNullOrEmpty(LeaftextureName))
            {
                t.LeafTexture = factory.GetAsset<Texture2D>(LeaftextureName);
            }
            if (!String.IsNullOrEmpty(trunktextureName))
            {
                t.TrunkTexture = factory.GetAsset<Texture2D>(trunktextureName);
            }
            tree = t.GenerateSimpleTree(StaticRandom.RandomInstance);

            BatchInformations = new BatchInformation[2][];
            vertexBufferS = new VertexBuffer[2];
            indexBufferS = new IndexBuffer[2];
            indexBufferS[0] = tree.TrunkMesh.IndexBuffer;
            vertexBufferS[0] = tree.TrunkMesh.VertexBuffer;
            BatchInformation bi0 = new BatchInformation(0, tree.TrunkMesh.NumberOfVertices, tree.TrunkMesh.NumberOfTriangles, 0, 0, tree.TrunkMesh.Vdeclaration, TreeVertex.SizeInBytes);
            BatchInformations[0] = new BatchInformation[1];
            BatchInformations[0][0] = bi0;

            indexBufferS[1] = tree.LeafCloud.Ibuffer;
            vertexBufferS[1] = tree.LeafCloud.Vbuffer;
            BatchInformation bi1 = new BatchInformation(0, tree.LeafCloud.Numleaves * 4, tree.LeafCloud.Numleaves * 2, 0, 0, tree.LeafCloud.Vdeclaration, LeafVertex.SizeInBytes);
            BatchInformations[1] = new BatchInformation[1];
            BatchInformations[1][0] = bi1; 
        }
        public void BuildModel()
        {
            added = true;
            int vertCount  = vertices.Count();
            int indexCount = 0;

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

            if (useIndices)
            {
                noTriangles = indexCount / 3;
            }
            else
            {
                noTriangles = vertCount / 3;
            }

            VertexBuffer vertexBufferS;
            IndexBuffer  IndexBufferS = null;

            vertexBufferS = factory.CreateVertexBuffer(vertices[0].VertexDeclaration, vertCount, BufferUsage);
            vertexBufferS.SetData <T>(vertices.ToArray());

            if (useIndices)
            {
                IndexBufferS = factory.CreateIndexBuffer(IndexElementSize.ThirtyTwoBits, indexCount, BufferUsage);
                IndexBufferS.SetData <int>(indices.ToArray());
            }

            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,
                                        useIndices == true ? BatchType.INDEXED : BatchType.NORMAL);
            b[0].ModelLocalTransformation = transformation;
            b[0].VertexBuffer             = vertexBufferS;
            if (useIndices)
            {
                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();
            TextureInformations = TextureInformations;


            vertices = null;
            indices  = null;
        }
Ejemplo n.º 8
0
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformation)
        {
            BatchInformations       = new BatchInformation[1][];
            BatchInformations[0]    = new BatchInformation[1];
            BatchInformations[0][0] = BatchInformation;

            TextureInformation       = new TextureInformation[1][];
            TextureInformation[0]    = new TextureInformation[1];
            TextureInformation[0][0] = new TextureInformation(false, factory, _diffuseName);
            TextureInformation[0][0].LoadTexture();
        }
Ejemplo n.º 9
0
 protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformation)
 {
     model = factory.GetModel(this.Name, isInternal, forceFromDisk);
     ModelBuilderHelper.Extract(factory,out BatchInformations, out TextureInformation,model,_diffuseName,_bumpName,_specularName,_glowName,isInternal);            
     
     BoundingSphere sphere = new BoundingSphere();
     foreach (var item in model.Meshes)
     {
         sphere = BoundingSphere.CreateMerged(sphere, item.BoundingSphere);
     }
     modelRadius = sphere.Radius;         
 }
Ejemplo n.º 10
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.º 11
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.º 12
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>
        /// Extracts the model radius and center.
        /// </summary>
        /// <param name="bi">The bi.</param>
        /// <param name="radius">The radius.</param>
        /// <param name="center">The center.</param>
        public static void ExtractModelRadiusAndCenter(BatchInformation bi, out float radius, out Vector3 center)
        {
            // Read the format of the vertex buffer
            VertexDeclaration declaration = bi.VertexDeclaration;

            VertexElement[] vertexElements = declaration.GetVertexElements();
            // Find the element that holds the position
            VertexElement vertexPosition = new VertexElement();

            foreach (VertexElement vert in vertexElements)
            {
                if (vert.VertexElementUsage == VertexElementUsage.Position &&
                    vert.VertexElementFormat == VertexElementFormat.Vector3)
                {
                    vertexPosition = vert;
                    // There should only be one
                    break;
                }
            }
            // Check the position element found is valid
            if (vertexPosition == null ||
                vertexPosition.VertexElementUsage != VertexElementUsage.Position ||
                vertexPosition.VertexElementFormat != VertexElementFormat.Vector3)
            {
                throw new Exception("Model uses unsupported vertex format!");
            }
            // This where we store the vertices until transformed
            Vector3[] allVertex = new Vector3[bi.NumVertices];
            // Read the vertices from the buffer in to the array
            bi.VertexBuffer.GetData <Vector3>(
                bi.BaseVertex * declaration.VertexStride + vertexPosition.Offset,
                allVertex,
                0,
                bi.NumVertices,
                declaration.VertexStride);
            // Transform them based on the relative bone location and the world if provided
            for (int i = 0; i != allVertex.Length; ++i)
            {
                Vector3.Transform(ref allVertex[i], ref bi.ModelLocalTransformation, out allVertex[i]);
            }
            BoundingSphere bs = BoundingSphere.CreateFromPoints(allVertex);

            radius = bs.Radius;
            center = bs.Center;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomModel"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="modelName">Name of the model.</param>
        /// <param name="meshindex">The meshindex.</param>
        /// <param name="binfo">The binfo.</param>
        /// <param name="diffuse">The diffuse.</param>
        public CustomModel(GraphicFactory factory, String modelName, int meshindex, BatchInformation[] binfo, Texture2D diffuse = null)
            : base(factory, modelName, false)
        {
            System.Diagnostics.Debug.Assert(binfo != null);
            System.Diagnostics.Debug.Assert(binfo.Count() != 0);
            BatchInformations    = new BatchInformation[1][];
            BatchInformations[0] = binfo;

            BoundingSphere bs = new BoundingSphere();

            for (int i = 0; i < binfo.Count(); i++)
            {
                float   radius;
                Vector3 center;
                ModelBuilderHelper.ExtractModelRadiusAndCenter(binfo[i], out radius, out center);
                bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius));
            }
            modelRadius = bs.Radius;

            TextureInformations    = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[binfo.Count()];

            for (int j = 0; j < TextureInformations[0].Count(); j++)
            {
                TextureInformations[0][j] = new TextureInformation(isInternal, factory);
                TextureInformations[0][j].LoadTexture();
                if (diffuse == null)
                {
                    if (model != null)
                    {
                        BasicEffect effect = model.Meshes[meshindex].MeshParts[j].Effect as BasicEffect;
                        if (effect != null)
                        {
                            TextureInformations[0][j].SetTexture(effect.Texture, TextureType.DIFFUSE);
                        }
                    }
                }
                else
                {
                    SetTexture(diffuse, TextureType.DIFFUSE, meshindex, j);
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomModel"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="modelName">Name of the model.</param>
        /// <param name="meshindex">The meshindex.</param>
        /// <param name="binfo">The binfo.</param>
        /// <param name="diffuse">The diffuse.</param>
        public CustomModel(GraphicFactory factory, String modelName, int meshindex, BatchInformation[] binfo, Texture2D diffuse = null)
            : base(factory, modelName,false)
        {
            System.Diagnostics.Debug.Assert(binfo != null);
            System.Diagnostics.Debug.Assert(binfo.Count() != 0);
            BatchInformations = new BatchInformation[1][];
            BatchInformations[0] = binfo;

            BoundingSphere bs = new BoundingSphere();
            for (int i = 0; i < binfo.Count(); i++)
            {
                float radius;
                Vector3 center;
                ModelBuilderHelper.ExtractModelRadiusAndCenter(binfo[i], out radius, out center);
                bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius));
            }
            modelRadius = bs.Radius;

            TextureInformations = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[binfo.Count()];
            
            for (int j = 0; j < TextureInformations[0].Count(); j++)
            {
                TextureInformations[0][j] = new TextureInformation(isInternal, factory);
                TextureInformations[0][j].LoadTexture();
                if (diffuse == null)
                {
                    if (model != null)
                    {
                        BasicEffect effect = model.Meshes[meshindex].MeshParts[j].Effect as BasicEffect;
                        if (effect != null)
                        {
                            TextureInformations[0][j].SetTexture(effect.Texture, TextureType.DIFFUSE);
                        }
                    }
                }
                else
                {
                       SetTexture(diffuse, TextureType.DIFFUSE,meshindex,j);
                }            
            }
        }
        public static void Extract(GraphicFactory factory,out BatchInformation[][] batchInformationS, out TextureInformation[][] textureInformationS, Model model,String diffuseName = null,String bumpName = null,string specularName = null,String glowName = null , bool isinternal = false)
        {            
            batchInformationS = new BatchInformation[model.Meshes.Count][];
            textureInformationS = new TextureInformation[model.Meshes.Count][];
            Matrix[] boneabsolute = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(boneabsolute);

            for (int j = 0; j < model.Meshes.Count; j++)
            {
                ModelMesh mesh = model.Meshes[j];

                BatchInformation[] b = new BatchInformation[mesh.MeshParts.Count];
                TextureInformation[] t = new TextureInformation[mesh.MeshParts.Count];
                for (int i = 0; i < mesh.MeshParts.Count; i++)
                {
                    b[i] = new BatchInformation(mesh.MeshParts[i].VertexOffset, mesh.MeshParts[i].NumVertices, mesh.MeshParts[i].PrimitiveCount, mesh.MeshParts[i].StartIndex, mesh.MeshParts[i].VertexOffset, mesh.MeshParts[i].VertexBuffer.VertexDeclaration, mesh.MeshParts[i].VertexBuffer.VertexDeclaration.VertexStride);
                    b[i].IndexBuffer = mesh.MeshParts[i].IndexBuffer;
                    b[i].VertexBuffer = mesh.MeshParts[i].VertexBuffer;
                    b[i].ModelLocalTransformation = boneabsolute[mesh.ParentBone.Index];
                    t[i] = new TextureInformation(isinternal, factory, diffuseName, bumpName, specularName, glowName);
                    t[i].LoadTexture();

                    if (diffuseName == null)
                    {
                        BasicEffect BasicEffect = mesh.MeshParts[i].Effect as BasicEffect;
                        if (BasicEffect != null)
                        {
                            t[i].SetTexture(BasicEffect.Texture, TextureType.DIFFUSE);
                        }
                        else if (mesh.MeshParts[i].Effect is SkinnedEffect)
                        {
                            t[i].SetTexture((mesh.MeshParts[i].Effect as SkinnedEffect).Texture, TextureType.DIFFUSE);
                        }
                    }                    

                }
                batchInformationS[j] = b;
                textureInformationS[j] = t;
            }
        }
        /// <summary>
        /// Creaters a BATCHInformation from a xna Model
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="batchInformationS">The batch information S.</param>
        public static void Extract(Model model,out BatchInformation[][] batchInformationS)
        {
            batchInformationS = new BatchInformation[model.Meshes.Count][];
            Matrix[] boneabsolute = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(boneabsolute);
                

            for (int j = 0; j < model.Meshes.Count; j++)
            {
                ModelMesh mesh = model.Meshes[j];
                
                BatchInformation[] b = new BatchInformation[mesh.MeshParts.Count];
                for (int i = 0; i < mesh.MeshParts.Count; i++)
                {                 
                    b[i] = new BatchInformation(mesh.MeshParts[i].VertexOffset, mesh.MeshParts[i].NumVertices, mesh.MeshParts[i].PrimitiveCount, mesh.MeshParts[i].StartIndex, mesh.MeshParts[i].VertexOffset , mesh.MeshParts[i].VertexBuffer.VertexDeclaration, mesh.MeshParts[i].VertexBuffer.VertexDeclaration.VertexStride);
                    b[i].IndexBuffer = mesh.MeshParts[i].IndexBuffer;
                    b[i].VertexBuffer = mesh.MeshParts[i].VertexBuffer;
                    b[i].ModelLocalTransformation = boneabsolute[mesh.ParentBone.Index];
                }
                batchInformationS[j] = b;
            }
        }
        /// <summary>
        /// Creaters a BATCHInformation from a xna Model
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="batchInformationS">The batch information S.</param>
        public static void Extract(Model model, out BatchInformation[][] batchInformationS)
        {
            batchInformationS = new BatchInformation[model.Meshes.Count][];
            Matrix[] boneabsolute = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(boneabsolute);


            for (int j = 0; j < model.Meshes.Count; j++)
            {
                ModelMesh mesh = model.Meshes[j];

                BatchInformation[] b = new BatchInformation[mesh.MeshParts.Count];
                for (int i = 0; i < mesh.MeshParts.Count; i++)
                {
                    b[i]                          = new BatchInformation(mesh.MeshParts[i].VertexOffset, mesh.MeshParts[i].NumVertices, mesh.MeshParts[i].PrimitiveCount, mesh.MeshParts[i].StartIndex, mesh.MeshParts[i].VertexOffset, mesh.MeshParts[i].VertexBuffer.VertexDeclaration, mesh.MeshParts[i].VertexBuffer.VertexDeclaration.VertexStride);
                    b[i].IndexBuffer              = mesh.MeshParts[i].IndexBuffer;
                    b[i].VertexBuffer             = mesh.MeshParts[i].VertexBuffer;
                    b[i].ModelLocalTransformation = boneabsolute[mesh.ParentBone.Index];
                }
                batchInformationS[j] = b;
            }
        }
        public static void Extract(GraphicFactory factory, out BatchInformation[][] batchInformationS, out TextureInformation[][] textureInformationS, Model model, String diffuseName = null, String bumpName = null, string specularName = null, String glowName = null, bool isinternal = false)
        {
            batchInformationS   = new BatchInformation[model.Meshes.Count][];
            textureInformationS = new TextureInformation[model.Meshes.Count][];
            Matrix[] boneabsolute = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(boneabsolute);

            for (int j = 0; j < model.Meshes.Count; j++)
            {
                ModelMesh mesh = model.Meshes[j];

                BatchInformation[]   b = new BatchInformation[mesh.MeshParts.Count];
                TextureInformation[] t = new TextureInformation[mesh.MeshParts.Count];
                for (int i = 0; i < mesh.MeshParts.Count; i++)
                {
                    b[i]                          = new BatchInformation(mesh.MeshParts[i].VertexOffset, mesh.MeshParts[i].NumVertices, mesh.MeshParts[i].PrimitiveCount, mesh.MeshParts[i].StartIndex, mesh.MeshParts[i].VertexOffset, mesh.MeshParts[i].VertexBuffer.VertexDeclaration, mesh.MeshParts[i].VertexBuffer.VertexDeclaration.VertexStride);
                    b[i].IndexBuffer              = mesh.MeshParts[i].IndexBuffer;
                    b[i].VertexBuffer             = mesh.MeshParts[i].VertexBuffer;
                    b[i].ModelLocalTransformation = boneabsolute[mesh.ParentBone.Index];
                    t[i]                          = new TextureInformation(isinternal, factory, diffuseName, bumpName, specularName, glowName);
                    t[i].LoadTexture();

                    if (diffuseName == null)
                    {
                        BasicEffect BasicEffect = mesh.MeshParts[i].Effect as BasicEffect;
                        if (BasicEffect != null)
                        {
                            t[i].SetTexture(BasicEffect.Texture, TextureType.DIFFUSE);
                        }
                        else if (mesh.MeshParts[i].Effect is SkinnedEffect)
                        {
                            t[i].SetTexture((mesh.MeshParts[i].Effect as SkinnedEffect).Texture, TextureType.DIFFUSE);
                        }
                    }
                }
                batchInformationS[j]   = b;
                textureInformationS[j] = t;
            }
        }
        /// <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();
        }
        /// <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();
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomModel"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="modelName">Name of the model.</param>
        /// <param name="BatchInformation">The batch information.</param>
        /// <param name="TextureInformation">The texture information.</param>
        /// <param name="meshindex">The meshindex.</param>
        /// <param name="meshpartIndex">Index of the meshpart.</param>
        public CustomModel(GraphicFactory factory, String modelName, BatchInformation BatchInformation, TextureInformation TextureInformation, int meshindex = 0, int meshpartIndex = 0)
            : base(factory, modelName, false)
        {
            System.Diagnostics.Debug.Assert(BatchInformation != null);
            System.Diagnostics.Debug.Assert(TextureInformation != null);

            BatchInformations       = new BatchInformation[1][];
            BatchInformations[0]    = new BatchInformation[1];
            BatchInformations[0][0] = BatchInformation;

            BoundingSphere bs = new BoundingSphere();

            {
                float   radius;
                Vector3 center;
                ModelBuilderHelper.ExtractModelRadiusAndCenter(BatchInformation, out radius, out center);
                bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius));
            }
            modelRadius = bs.Radius;

            TextureInformations       = new TextureInformation[1][];
            TextureInformations[0]    = new TextureInformation[1];
            TextureInformations[0][0] = TextureInformation;

            if (TextureInformation.getTexture(TextureType.DIFFUSE) == null)
            {
                if (model != null)
                {
                    BasicEffect effect = model.Meshes[meshindex].MeshParts[meshpartIndex].Effect as BasicEffect;
                    if (effect != null)
                    {
                        TextureInformations[0][0].SetTexture(effect.Texture, TextureType.DIFFUSE);
                    }
                }
            }
        }
Ejemplo n.º 23
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)
        {
            //code not called !!!
            //Here for future usage.

            model = factory.GetModel(this.Name, isInternal);
            ModelBuilderHelper.Extract(model, out BatchInformations);
            
            BoundingSphere sphere = new BoundingSphere();
            foreach (var item in model.Meshes)
            {
                BoundingSphere.CreateMerged(sphere, item.BoundingSphere);
            }
            modelRadius = sphere.Radius;

            TextureInformations = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[1];
            TextureInformations[0][0] = new TextureInformation(isInternal, factory);
            TextureInformations[0][0].LoadTexture();
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomModel"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="modelName">Name of the model.</param>
        /// <param name="BatchInformation">The batch information.</param>
        /// <param name="TextureInformation">The texture information.</param>
        /// <param name="meshindex">The meshindex.</param>
        /// <param name="meshpartIndex">Index of the meshpart.</param>
        public CustomModel(GraphicFactory factory, String modelName, BatchInformation BatchInformation, TextureInformation TextureInformation, int meshindex = 0, int meshpartIndex = 0)        
            : base(factory, modelName, false)
       {

           System.Diagnostics.Debug.Assert(BatchInformation != null);
           System.Diagnostics.Debug.Assert(TextureInformation != null);

           BatchInformations = new BatchInformation[1][];
           BatchInformations[0] = new BatchInformation[1];
           BatchInformations[0][0] = BatchInformation;
                      
           BoundingSphere bs = new BoundingSphere();           
           {
               float radius;
               Vector3 center;
               ModelBuilderHelper.ExtractModelRadiusAndCenter(BatchInformation, out radius, out center);                
               bs = BoundingSphere.CreateMerged(bs,new BoundingSphere(center,radius));
           }
           modelRadius = bs.Radius;

           TextureInformations = new TextureInformation[1][];
           TextureInformations[0] = new TextureInformation[1];
           TextureInformations[0][0] = TextureInformation;

           if (TextureInformation.getTexture(TextureType.DIFFUSE) == null)
           {
               if (model != null)
               {
                   BasicEffect effect = model.Meshes[meshindex].MeshParts[meshpartIndex].Effect as BasicEffect;
                   if (effect != null)
                   {
                       TextureInformations[0][0].SetTexture(effect.Texture, TextureType.DIFFUSE);
                   }
               }
           }           
       }
Ejemplo n.º 25
0
        protected override void  LoadContent(Engine.GraphicInfo GraphicInfo,GraphicFactory factory)
        {
            base.LoadContent(GraphicInfo, factory);
            effect = factory.GetEffect("skybox",false,true);
            this.factory = factory;
            cubeVertices = new VertexPositionNormalTexture[36];

            Vector3 topLeftFront = new Vector3(-1.0f, 1.0f, 1.0f);
            Vector3 bottomLeftFront = new Vector3(-1.0f, -1.0f, 1.0f);
            Vector3 topRightFront = new Vector3(1.0f, 1.0f, 1.0f);
            Vector3 bottomRightFront = new Vector3(1.0f, -1.0f, 1.0f);
            Vector3 topLeftBack = new Vector3(-1.0f, 1.0f, -1.0f);
            Vector3 topRightBack = new Vector3(1.0f, 1.0f, -1.0f);
            Vector3 bottomLeftBack = new Vector3(-1.0f, -1.0f, -1.0f);
            Vector3 bottomRightBack = new Vector3(1.0f, -1.0f, -1.0f);

            Vector2 textureTopLeft = new Vector2(0.0f, 0.0f);
            Vector2 textureTopRight = new Vector2(1.0f, 0.0f);
            Vector2 textureBottomLeft = new Vector2(0.0f, 1.0f);
            Vector2 textureBottomRight = new Vector2(1.0f, 1.0f);

            Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f);
            Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f);
            Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f);
            Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f);

            // Front face
            cubeVertices[0] =
                new VertexPositionNormalTexture(
                topLeftFront, frontNormal, textureTopLeft);
            cubeVertices[1] =
                new VertexPositionNormalTexture(
                bottomLeftFront, frontNormal, textureBottomLeft);
            cubeVertices[2] =
                new VertexPositionNormalTexture(
                topRightFront, frontNormal, textureTopRight);
            cubeVertices[3] =
                new VertexPositionNormalTexture(
                bottomLeftFront, frontNormal, textureBottomLeft);
            cubeVertices[4] =
                new VertexPositionNormalTexture(
                bottomRightFront, frontNormal, textureBottomRight);
            cubeVertices[5] =
                new VertexPositionNormalTexture(
                topRightFront, frontNormal, textureTopRight);

            // Back face 
            cubeVertices[6] =
                new VertexPositionNormalTexture(
                topLeftBack, backNormal, textureTopRight);
            cubeVertices[7] =
                new VertexPositionNormalTexture(
                topRightBack, backNormal, textureTopLeft);
            cubeVertices[8] =
                new VertexPositionNormalTexture(
                bottomLeftBack, backNormal, textureBottomRight);
            cubeVertices[9] =
                new VertexPositionNormalTexture(
                bottomLeftBack, backNormal, textureBottomRight);
            cubeVertices[10] =
                new VertexPositionNormalTexture(
                topRightBack, backNormal, textureTopLeft);
            cubeVertices[11] =
                new VertexPositionNormalTexture(
                bottomRightBack, backNormal, textureBottomLeft);

            // Top face
            cubeVertices[12] =
                new VertexPositionNormalTexture(
                topLeftFront, topNormal, textureBottomLeft);
            cubeVertices[13] =
                new VertexPositionNormalTexture(
                topRightBack, topNormal, textureTopRight);
            cubeVertices[14] =
                new VertexPositionNormalTexture(
                topLeftBack, topNormal, textureTopLeft);
            cubeVertices[15] =
                new VertexPositionNormalTexture(
                topLeftFront, topNormal, textureBottomLeft);
            cubeVertices[16] =
                new VertexPositionNormalTexture(
                topRightFront, topNormal, textureBottomRight);
            cubeVertices[17] =
                new VertexPositionNormalTexture(
                topRightBack, topNormal, textureTopRight);

            // Bottom face 
            cubeVertices[18] =
                new VertexPositionNormalTexture(
                bottomLeftFront, bottomNormal, textureTopLeft);
            cubeVertices[19] =
                new VertexPositionNormalTexture(
                bottomLeftBack, bottomNormal, textureBottomLeft);
            cubeVertices[20] =
                new VertexPositionNormalTexture(
                bottomRightBack, bottomNormal, textureBottomRight);
            cubeVertices[21] =
                new VertexPositionNormalTexture(
                bottomLeftFront, bottomNormal, textureTopLeft);
            cubeVertices[22] =
                new VertexPositionNormalTexture(
                bottomRightBack, bottomNormal, textureBottomRight);
            cubeVertices[23] =
                new VertexPositionNormalTexture(
                bottomRightFront, bottomNormal, textureTopRight);

            // Left face
            cubeVertices[24] =
                new VertexPositionNormalTexture(
                topLeftFront, leftNormal, textureTopRight);
            cubeVertices[25] =
                new VertexPositionNormalTexture(
                bottomLeftBack, leftNormal, textureBottomLeft);
            cubeVertices[26] =
                new VertexPositionNormalTexture(
                bottomLeftFront, leftNormal, textureBottomRight);
            cubeVertices[27] =
                new VertexPositionNormalTexture(
                topLeftBack, leftNormal, textureTopLeft);
            cubeVertices[28] =
                new VertexPositionNormalTexture(
                bottomLeftBack, leftNormal, textureBottomLeft);
            cubeVertices[29] =
                new VertexPositionNormalTexture(
                topLeftFront, leftNormal, textureTopRight);

            // Right face 
            cubeVertices[30] =
                new VertexPositionNormalTexture(
                topRightFront, rightNormal, textureTopLeft);
            cubeVertices[31] =
                new VertexPositionNormalTexture(
                bottomRightFront, rightNormal, textureBottomLeft);
            cubeVertices[32] =
                new VertexPositionNormalTexture(
                bottomRightBack, rightNormal, textureBottomRight);
            cubeVertices[33] =
                new VertexPositionNormalTexture(
                topRightBack, rightNormal, textureTopRight);
            cubeVertices[34] =
                new VertexPositionNormalTexture(
                topRightFront, rightNormal, textureTopLeft);
            cubeVertices[35] =
                new VertexPositionNormalTexture(
                bottomRightBack, rightNormal, textureBottomRight);

            vertexBuffer = factory.CreateVertexBuffer(VertexPositionNormalTexture.VertexDeclaration,36, BufferUsage.None);
            vertexBuffer.SetData<VertexPositionNormalTexture>(cubeVertices);
            bi = new BatchInformation(0, 36, 23, 0, 0, VertexPositionNormalTexture.VertexDeclaration, VertexPositionNormalTexture.VertexDeclaration.VertexStride, BatchType.NORMAL);
            bi.VertexBuffer = vertexBuffer;            
        }
Ejemplo n.º 26
0
 internal void UpdateBatchInformation(BatchInformation BatchInformation)
 {
     BatchInformation.VertexBuffer = _buffers.VertexBuffer;
     BatchInformation.IndexBuffer = _buffers.IndexBuffer;
     BatchInformation.PrimitiveCount = IndexCount / 3;
     BatchInformation.NumVertices = _vertices.Vertices.Length;
 }
        /// <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();
        }
 public static void Extract(GraphicFactory factory, out BatchInformation[][] batchInformationS, out TextureInformation[][] textureInformationS, string modelName, String diffuseName = null, String bumpName = null, string specularName = null, String glowName = null, bool isinternal = false)
 {
     Model model = factory.GetModel(modelName, isinternal);
     Extract(factory, out batchInformationS, out textureInformationS, model, diffuseName, bumpName, specularName, glowName, isinternal);
 }
 /// <summary>
 /// Extracts the model radius and center.
 /// </summary>
 /// <param name="bi">The bi.</param>
 /// <param name="radius">The radius.</param>
 /// <param name="center">The center.</param>
 public static void ExtractModelRadiusAndCenter(BatchInformation bi, out float radius, out Vector3 center)
 {
     // Read the format of the vertex buffer  
     VertexDeclaration declaration = bi.VertexDeclaration;
     VertexElement[] vertexElements = declaration.GetVertexElements();
     // Find the element that holds the position  
     VertexElement vertexPosition = new VertexElement();
     foreach (VertexElement vert in vertexElements)
     {
         if (vert.VertexElementUsage == VertexElementUsage.Position &&
             vert.VertexElementFormat == VertexElementFormat.Vector3)
         {
             vertexPosition = vert;
             // There should only be one  
             break;
         }
     }
     // Check the position element found is valid  
     if (vertexPosition == null ||
         vertexPosition.VertexElementUsage != VertexElementUsage.Position ||
         vertexPosition.VertexElementFormat != VertexElementFormat.Vector3)
     {
         throw new Exception("Model uses unsupported vertex format!");
     }
     // This where we store the vertices until transformed  
     Vector3[] allVertex = new Vector3[bi.NumVertices];
     // Read the vertices from the buffer in to the array  
         bi.VertexBuffer.GetData<Vector3>(
         bi.BaseVertex * declaration.VertexStride + vertexPosition.Offset,
         allVertex,
         0,
         bi.NumVertices,
         declaration.VertexStride);
     // Transform them based on the relative bone location and the world if provided  
     for (int i = 0; i != allVertex.Length; ++i)
     {
         Vector3.Transform(ref allVertex[i], ref bi.ModelLocalTransformation, out allVertex[i]);
     }
     BoundingSphere bs = BoundingSphere.CreateFromPoints(allVertex);
     radius = bs.Radius;
     center = bs.Center;            
 }  
 /// <summary>
 /// Creates a BatchInformation from a XNA ModelMesh
 /// </summary>
 /// <param name="BonesAbsoluteTransforms">The bones absolute transforms.</param>
 /// <param name="mesh">The mesh.</param>
 /// <param name="batchInformationS">The batch information S.</param>
 public static void Extract(Matrix[] BonesAbsoluteTransforms, ModelMeshPart mesh, out BatchInformation batchInformationS)
 {
     batchInformationS = new BatchInformation(mesh.VertexOffset, mesh.NumVertices, mesh.PrimitiveCount, mesh.StartIndex, mesh.VertexOffset, mesh.VertexBuffer.VertexDeclaration, mesh.VertexBuffer.VertexDeclaration.VertexStride);
     batchInformationS.IndexBuffer = mesh.IndexBuffer;
     batchInformationS.VertexBuffer = mesh.VertexBuffer;                    
 }
Ejemplo n.º 31
0
        protected override void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformation)
        {                        
            BatchInformations = new BatchInformation[1][];
            BatchInformations[0] = new BatchInformation[1];
            BatchInformations[0][0] = BatchInformation;

            TextureInformation = new TextureInformation[1][];
            TextureInformation[0] = new TextureInformation[1];
            TextureInformation[0][0] = new TextureInformation(false,factory,_diffuseName);
            TextureInformation[0][0].LoadTexture();
        }
Ejemplo n.º 32
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.º 33
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomModel"/> class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="loader">The loader.</param>
        public CustomModel(GraphicFactory factory, ObjectInformation[] loader)
            : base(factory, loader[0].modelName, false)
        {
            System.Diagnostics.Debug.Assert(loader!= null);
            System.Diagnostics.Debug.Assert(loader.Count() != 0);
            BatchInformations = new BatchInformation[1][];
            BatchInformations[0] = new BatchInformation[loader.Count()];

            TextureInformations = new TextureInformation[1][];
            TextureInformations[0] = new TextureInformation[loader.Count()];

            BoundingSphere bs = new BoundingSphere();
            for (int i = 0; i < loader.Count(); i++)
            {
                BatchInformations[0][i] = loader[i].batchInformation;
                TextureInformations[0][i] = loader[i].textureInformation;

                float radius;
                Vector3 center;
                ModelBuilderHelper.ExtractModelRadiusAndCenter(BatchInformations[0][i], out radius, out center);
                bs = BoundingSphere.CreateMerged(bs, new BoundingSphere(center, radius));
            }            
            modelRadius = bs.Radius;
        }
 /// <summary>
 /// Creates a BatchInformation from a XNA ModelMesh
 /// </summary>
 /// <param name="BonesAbsoluteTransforms">The bones absolute transforms.</param>
 /// <param name="mesh">The mesh.</param>
 /// <param name="batchInformationS">The batch information S.</param>
 public static void Extract(Matrix[] BonesAbsoluteTransforms, ModelMeshPart mesh, out BatchInformation batchInformationS)
 {
     batchInformationS              = new BatchInformation(mesh.VertexOffset, mesh.NumVertices, mesh.PrimitiveCount, mesh.StartIndex, mesh.VertexOffset, mesh.VertexBuffer.VertexDeclaration, mesh.VertexBuffer.VertexDeclaration.VertexStride);
     batchInformationS.IndexBuffer  = mesh.IndexBuffer;
     batchInformationS.VertexBuffer = mesh.VertexBuffer;
 }
Ejemplo n.º 35
0
 /// <summary>
 /// Loads the batch info, called by the constructor if callLoadContent is true
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="BatchInformations">The batch informations.</param>
 /// <param name="TextureInformation">The texture information.</param>
 protected abstract void LoadModel(GraphicFactory factory, out BatchInformation[][] BatchInformations, out TextureInformation[][] TextureInformation);
Ejemplo n.º 36
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.º 37
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;
            }
        }
Ejemplo n.º 38
0
        private static void ExtractData(ref Vector3[] vert, ref int[] ind, ref Vector2[] tex, IModelo model, XNA.Vector3 scale)
        {
            List <Vector3> vertices  = new List <Vector3>();
            List <Vector2> texcoords = new List <Vector2>();
            List <int>     indices   = new List <int>();

            for (int i = 0; i < model.MeshNumber; i++)
            {
                BatchInformation[] bi = model.GetBatchInformation(i);
                for (int j = 0; j < bi.Length; j++)
                {
                    BatchInformation info = bi[j];
                    int offset            = vertices.Count;
                    Microsoft.Xna.Framework.Vector3[] a = new Microsoft.Xna.Framework.Vector3[info.NumVertices];

                    // Read the format of the vertex buffer
                    VertexDeclaration declaration    = bi[j].VertexBuffer.VertexDeclaration;
                    VertexElement[]   vertexElements = declaration.GetVertexElements();
                    // Find the element that holds the position
                    VertexElement vertexPosition = new VertexElement();
                    foreach (VertexElement elem in vertexElements)
                    {
                        if (elem.VertexElementUsage == VertexElementUsage.Position &&
                            elem.VertexElementFormat == VertexElementFormat.Vector3)
                        {
                            vertexPosition = elem;
                            // There should only be one
                            break;
                        }
                    }
                    // Check the position element found is valid
                    if (vertexPosition == null ||
                        vertexPosition.VertexElementUsage != VertexElementUsage.Position ||
                        vertexPosition.VertexElementFormat != VertexElementFormat.Vector3)
                    {
                        throw new Exception("Model uses unsupported vertex format!");
                    }
                    // This where we store the vertices until transformed
                    // Read the vertices from the buffer in to the array
                    bi[j].VertexBuffer.GetData <Microsoft.Xna.Framework.Vector3>(
                        bi[j].BaseVertex * declaration.VertexStride + vertexPosition.Offset,
                        a,
                        0,
                        bi[j].NumVertices,
                        declaration.VertexStride);

                    for (int k = 0; k != a.Length; ++k)
                    {
                        XNA.Matrix tra = info.ModelLocalTransformation * XNA.Matrix.CreateScale(scale);
                        Microsoft.Xna.Framework.Vector3.Transform(ref a[k], ref tra, out a[k]);
                        vertices.Add(a[k].AsPhysX());
                    }

                    foreach (VertexElement elem in vertexElements)
                    {
                        if (elem.VertexElementUsage == VertexElementUsage.TextureCoordinate &&
                            elem.VertexElementFormat == VertexElementFormat.Vector2)
                        {
                            vertexPosition = elem;
                            // There should only be one
                            break;
                        }
                    }
                    Microsoft.Xna.Framework.Vector2[] b = new Microsoft.Xna.Framework.Vector2[info.NumVertices];
                    // This where we store the vertices until transformed
                    // Read the vertices from the buffer in to the array
                    bi[j].VertexBuffer.GetData <Microsoft.Xna.Framework.Vector2>(
                        bi[j].BaseVertex * declaration.VertexStride + vertexPosition.Offset,
                        b,
                        0,
                        bi[j].NumVertices,
                        declaration.VertexStride);

                    for (int k = 0; k != b.Length; ++k)
                    {
                        texcoords.Add(b[k].AsPhysX());
                    }


                    if (info.IndexBuffer.IndexElementSize != IndexElementSize.SixteenBits)
                    {
                        int[] s = new int[info.PrimitiveCount * 3];
                        info.IndexBuffer.GetData <int>(info.StartIndex * 2, s, 0, info.PrimitiveCount * 3);
                        for (int k = 0; k != info.PrimitiveCount; ++k)
                        {
                            indices.Add(s[k * 3 + 2] + offset);
                            indices.Add(s[k * 3 + 1] + offset);
                            indices.Add(s[k * 3 + 0] + offset);
                        }
                    }
                    else
                    {
                        short[] s = new short[info.PrimitiveCount * 3];
                        info.IndexBuffer.GetData <short>(info.StartIndex * 2, s, 0, info.PrimitiveCount * 3);
                        for (int k = 0; k != info.PrimitiveCount; ++k)
                        {
                            indices.Add(s[k * 3 + 2] + offset);
                            indices.Add(s[k * 3 + 1] + offset);
                            indices.Add(s[k * 3 + 0] + offset);
                        }
                    }
                }
            }

            ind  = indices.ToArray();
            vert = vertices.ToArray();
            tex  = texcoords.ToArray();
        }