Пример #1
0
        /// <summary>
        /// Update the instancing vertex buffer
        /// </summary>

        private DynamicVertexBuffer UpdateInstanceVB(MeshInstanceGroup instanceGroup)
        {
            // Copy transform data to InstanceData structure
            for (int i = 0; i < instanceGroup.totalVisible; i++)
            {
                instanceGroup.tempTransforms[i] = instanceGroup.visibleInstances[i].Transform;
            }

            // Update vertex buffer
            if (instanceGroup.totalVisible > 0)
            {
                instanceGroup.instanceVB.SetData(instanceGroup.tempTransforms, 0,
                                                 instanceGroup.totalVisible, SetDataOptions.None);
            }

            return(instanceGroup.instanceVB);
        }
Пример #2
0
        /// <summary>
        /// Resize mesh vertex buffer and/or get the bone matrices
        /// </summary>
        public void BuildMeshData(GraphicsDevice graphicsDevice, MeshInstanceGroup instanceGroup)
        {
            int totalInstances = instanceGroup.instances.Count;

#if XNA
            graphicsDevice.SetVertexBuffers(null);
#elif MONOGAME
            graphicsDevice.SetVertexBuffer(null);
#endif
            /// Resize the vertex buffer for instances if needed
            if (instanceGroup.instanceVB == null ||
                totalInstances > instanceGroup.instanceVB.VertexCount)
            {
                instanceGroup.instanceVB = CreateInstanceVB(graphicsDevice, instanceGroup.instances);
            }
            else
            {
                UpdateInstanceVB(instanceGroup);
            }
        }