예제 #1
0
        public override void GetVertexData(List <VertexPositionNormalTexture> vertices, List <ushort> indices)
        {
            var tempIndices  = new List <ushort>();
            var tempVertices = new List <VertexPositionNormalTexture>();

            for (int i = 0; i < DisplayedObject.SubBodies.Count; i++)
            {
                ModelDisplayObjectBase displayObject = Drawer.GetDisplayObject(DisplayedObject.SubBodies[i]);

                displayObject.GetVertexData(tempVertices, tempIndices);
                for (int j = 0; j < tempIndices.Count; j++)
                {
                    indices.Add((ushort)(tempIndices[j] + vertices.Count));
                }
                for (int j = 0; j < tempVertices.Count; j++)
                {
                    VertexPositionNormalTexture vertex = tempVertices[j];
                    vertex.Position = Vector3.Transform(vertex.Position, DisplayedObject.SubBodyLocalRotations[i]) + DisplayedObject.SubBodyLocalOffsets[i];
                    vertex.Normal   = Vector3.Transform(vertex.Normal, DisplayedObject.SubBodyLocalRotations[i]);
                    vertices.Add(vertex);
                }

                tempVertices.Clear();
                tempIndices.Clear();
            }
        }
예제 #2
0
        /// <summary>
        /// Adds a display object to the batch.
        /// </summary>
        /// <param name="displayObject">Display object to add.</param>
        /// <param name="drawer">Drawer of the batch.</param>
        public bool Add(ModelDisplayObjectBase displayObject, InstancedModelDrawer drawer)
        {
            //In theory, don't need to test for dupliate entries since batch.Add
            //should only be called through a InstancedModelDrawer's add (which checks beforehand).
            if (myDisplayObjects.Count == MaximumObjectsPerBatch ||
                ((indices.Length / 3 + displayObject.GetTriangleCountEstimate()) > MaximumPrimitiveCountPerBatch &&
                 myDisplayObjects.Count > 0))
            {
                return(false);
            }
            myDisplayObjects.Add(displayObject);
            int instanceIndex = myDisplayObjects.Count - 1;

            displayObject.GetVertexData(vertexList, indexList, this, (ushort)vertices.Length, indices.Length, instanceIndex);
            //Add the data to the batch.
            var newVertices = new VertexPositionNormalTexture[vertices.Length + vertexList.Count];

            vertices.CopyTo(newVertices, 0);
            vertexList.CopyTo(newVertices, vertices.Length);
            vertices = newVertices;

            var newIndices = new ushort[indices.Length + indexList.Count];

            indices.CopyTo(newIndices, 0);
            indexList.CopyTo(newIndices, indices.Length);
            indices = newIndices;

            var newInstancingIndices = new float[instancingIndices.Length + vertexList.Count];

            instancingIndices.CopyTo(newInstancingIndices, 0);
            for (int i = instancingIndices.Length; i < newInstancingIndices.Length; i++)
            {
                newInstancingIndices[i] = instanceIndex;
            }
            instancingIndices = newInstancingIndices;

            vertexBuffer = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
            vertexBuffer.SetData(vertices);
            instancingBuffer = new VertexBuffer(graphicsDevice, drawer.instancingVertexDeclaration, instancingIndices.Length, BufferUsage.WriteOnly);
            instancingBuffer.SetData(instancingIndices);
            bindings    = new VertexBufferBinding[] { vertexBuffer, instancingBuffer };
            indexBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indices.Length, BufferUsage.WriteOnly);
            indexBuffer.SetData(indices);

            vertexList.Clear();
            indexList.Clear();
            return(true);
        }
        internal BruteDisplayObjectEntry(BruteModelDrawer drawer, ModelDisplayObjectBase displayObject)
        {
            this.drawer = drawer;
            this.displayObject = displayObject;

            var tempVertices = new List<VertexPositionNormalTexture>();
            var tempIndices = new List<ushort>();
            displayObject.GetVertexData(tempVertices, tempIndices);
            vertices = new VertexPositionNormalTexture[tempVertices.Count];
            indices = new ushort[tempIndices.Count];
            tempVertices.CopyTo(vertices);
            tempIndices.CopyTo(indices);

            vertexBuffer = new VertexBuffer(displayObject.Drawer.Game.GraphicsDevice, typeof (VertexPositionNormalTexture), vertices.Length, BufferUsage.WriteOnly);
            indexBuffer = new IndexBuffer(displayObject.Drawer.Game.GraphicsDevice, IndexElementSize.SixteenBits, indices.Length, BufferUsage.WriteOnly);

            vertexBuffer.SetData(vertices);
            indexBuffer.SetData(indices);
        }
예제 #4
0
        internal BruteDisplayObjectEntry(BruteModelDrawer drawer, ModelDisplayObjectBase displayObject)
        {
            this.drawer        = drawer;
            this.displayObject = displayObject;

            var tempVertices = new List <VertexPositionNormalTexture>();
            var tempIndices  = new List <ushort>();

            displayObject.GetVertexData(tempVertices, tempIndices);
            vertices = new VertexPositionNormalTexture[tempVertices.Count];
            indices  = new ushort[tempIndices.Count];
            tempVertices.CopyTo(vertices);
            tempIndices.CopyTo(indices);

            vertexBuffer = new VertexBuffer(displayObject.Drawer.Game.GraphicsDevice, typeof(VertexPositionNormalTexture), vertices.Length, BufferUsage.WriteOnly);
            indexBuffer  = new IndexBuffer(displayObject.Drawer.Game.GraphicsDevice, IndexElementSize.SixteenBits, indices.Length, BufferUsage.WriteOnly);

            vertexBuffer.SetData(vertices);
            indexBuffer.SetData(indices);
        }
예제 #5
0
        /// <summary>
        /// Adds a display object to the batch.
        /// </summary>
        /// <param name="displayObject">Display object to add.</param>
        /// <param name="drawer">Drawer of the batch.</param>
        public bool Add(ModelDisplayObjectBase displayObject, InstancedModelDrawer drawer)
        {
            //In theory, don't need to test for dupliate entries since batch.Add
            //should only be called through a InstancedModelDrawer's add (which checks beforehand).
            if (displayObjects.Count == MaximumObjectsPerBatch ||
                ((indices.Length / 3 + displayObject.GetTriangleCountEstimate()) > MaximumPrimitiveCountPerBatch &&
                 displayObjects.Count > 0))
                return false;
            displayObjects.Add(displayObject);
            int instanceIndex = displayObjects.Count - 1;
            displayObject.GetVertexData(vertexList, indexList, this, (ushort) vertices.Length, indices.Length, instanceIndex);
            //Add the data to the batch.
            var newVertices = new VertexPositionNormalTexture[vertices.Length + vertexList.Count];
            vertices.CopyTo(newVertices, 0);
            vertexList.CopyTo(newVertices, vertices.Length);
            vertices = newVertices;

            var newIndices = new ushort[indices.Length + indexList.Count];
            indices.CopyTo(newIndices, 0);
            indexList.CopyTo(newIndices, indices.Length);
            indices = newIndices;

            var newInstancingIndices = new float[instancingIndices.Length + vertexList.Count];
            instancingIndices.CopyTo(newInstancingIndices, 0);
            for (int i = instancingIndices.Length; i < newInstancingIndices.Length; i++)
                newInstancingIndices[i] = instanceIndex;
            instancingIndices = newInstancingIndices;

            vertexBuffer = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
            vertexBuffer.SetData(vertices);
            instancingBuffer = new VertexBuffer(graphicsDevice, drawer.instancingVertexDeclaration, instancingIndices.Length, BufferUsage.WriteOnly);
            instancingBuffer.SetData(instancingIndices);
            bindings = new VertexBufferBinding[] { vertexBuffer, instancingBuffer };
            indexBuffer = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, indices.Length, BufferUsage.WriteOnly);
            indexBuffer.SetData(indices);

            vertexList.Clear();
            indexList.Clear();
            return true;
        }