コード例 #1
0
ファイル: LevelEditor.cs プロジェクト: Fireborn/Gamedev
        public void ComputeShadowMesh(Vector3 lightWorldPosition)
        {
            List <VertexBuffer> vertexBuffers;
            List <IndexBuffer>  indexBuffers;

            _gameWorld.GetRenderables(out vertexBuffers, out indexBuffers);

            for (int i = 0; i < vertexBuffers.Count; ++i)
            {
                _shadowMeshIndices.Clear();
                _shadowVertices.Clear();
                _shadowIndices.Clear();

                VertexPositionNormalTexture[] vertexData = new VertexPositionNormalTexture[vertexBuffers[i].VertexCount];
                vertexBuffers[i].GetData <VertexPositionNormalTexture>(vertexData);

                UInt32[] vertexIndices = new UInt32[indexBuffers[i].IndexCount];
                indexBuffers[i].GetData <UInt32>(vertexIndices);

                foreach (VertexPositionNormalTexture vertex in vertexData)
                {
                    _shadowVertices.Add(vertex.Position);
                }

                foreach (UInt32 index in vertexIndices)
                {
                    _shadowIndices.Add(index);
                }

                Shadows.CreateShadowVolumeMesh(vertexData.ToList(), _shadowIndices, Vector3.Zero - lightWorldPosition, ref _shadowMeshIndices, ref _shadowMeshVertices);
                IndexBuffer shadowIndexBuffer = new IndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, _shadowMeshIndices.Count, BufferUsage.None);
                shadowIndexBuffer.SetData(_shadowMeshIndices.ToArray());
                _shadowIndexList.Add(shadowIndexBuffer);

                List <VertexPositionColor> shadowVertices = new List <VertexPositionColor>();
                foreach (Vector3 vertexPos in _shadowMeshVertices)
                {
                    shadowVertices.Add(new VertexPositionColor(vertexPos, Color.White));
                }

                VertexBuffer shadowVertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), shadowVertices.Count, BufferUsage.None);
                shadowVertexBuffer.SetData(shadowVertices.ToArray());
                _shadowVertexBufferList.Add(shadowVertexBuffer);
            }
        }