コード例 #1
0
        public MatMeshFloor()
        {
            _DrawMode = PrimitiveTopology.LineList;
            Color = new Color4(0.7f, 0.7f, 0.7f);

            MatVertexDataPNT[] data = new MatVertexDataPNT[404];
            int i = 0;

            for(int x = -50; x <= 50; x++)
            {
                data[i] = new MatVertexDataPNT() { position = new Vector3(x, 0, -50) };
                i++;
                data[i] = new MatVertexDataPNT() { position = new Vector3(x, 0, 50) };
                i++;
                data[i] = new MatVertexDataPNT() { position = new Vector3(-50, 0, x) };
                i++;
                data[i] = new MatVertexDataPNT() { position = new Vector3(50, 0, x) };
                i++;
            }

            InitVertexBuffer(data);
            VertexCount = 404;
        }
コード例 #2
0
        //private static MatVertexDataPNT[] BuildFromTexCoord(List<Indices> indices, List<Vector3> positions, List<Vector3> normals, List<Vector2> texCoords, ref int[] indexBuffer)
        //{
        //    MatVertexDataPNT[] result = new MatVertexDataPNT[texCoords.Count];
        //    int count = 0;
        //    foreach(Indices index in indices)
        //    {
        //        result[index.texCoord] = new MatVertexDataPNT()
        //        {
        //            position = new Vector3(positions[index.position].X, positions[index.position].Y, positions[index.position].Z),
        //            normal = new Vector3(normals[index.normal].X, normals[index.normal].Y, normals[index.normal].Z),
        //            texCoord = new Vector2(texCoords[index.texCoord].X, 1.0f - texCoords[index.texCoord].Y)
        //        };
        //        indexBuffer[count] = index.texCoord;
        //        count++;
        //    }
        //    return result;
        //}
        //private static MatVertexDataPNT[] BuildFromPosition(List<Indices> indices, List<Vector3> positions, List<Vector3> normals, List<Vector2> texCoords, ref int[] indexBuffer)
        //{
        //    MatVertexDataPNT[] result = new MatVertexDataPNT[positions.Count];
        //    int count = 0;
        //    foreach (Indices index in indices)
        //    {
        //        result[index.position] = new MatVertexDataPNT()
        //        {
        //            position = new Vector3(positions[index.position].X, positions[index.position].Y, positions[index.position].Z),
        //            normal = new Vector3(normals[index.normal].X, normals[index.normal].Y, normals[index.normal].Z),
        //            texCoord = new Vector2(texCoords[index.texCoord].X, 1.0f - texCoords[index.texCoord].Y)
        //        };
        //        indexBuffer[count] = index.position;
        //        count++;
        //    }
        //    return result;
        //}
        private static MatVertexDataPNT[] Build(List<Indices> indices, List<Vector3> positions, List<Vector3> normals, List<Vector2> texCoords, ref int[] indexBuffer)
        {
            MatVertexDataPNT[] result = new MatVertexDataPNT[indices.Count];
            int count = 0;

            foreach (Indices index in indices)
            {
                result[count] = new MatVertexDataPNT()
                {
                    position = new Vector3(positions[index.position].X, positions[index.position].Y, positions[index.position].Z),
                    normal = new Vector3(normals[index.normal].X, normals[index.normal].Y, normals[index.normal].Z),
                    texCoord = new Vector2(texCoords[index.texCoord].X, 1.0f - texCoords[index.texCoord].Y)
                };

                indexBuffer[count] = count;
                count++;
            }

            return result;
        }
コード例 #3
0
        protected bool InitVertexBuffer(MatVertexDataPNT[] vertices)
        {
            if (Vertices != vertices) _Vertices = vertices;

            using (DataStream vertexStream = new DataStream(vertices, true, true))
            {
                _VertexBuffer = new SlimDX.Direct3D11.Buffer(
                    Mat3DView.GraphicsDevice,
                    vertexStream,
                    new BufferDescription { SizeInBytes = (int)vertexStream.Length, BindFlags = BindFlags.VertexBuffer }
                    );
            }

            if (VertexBuffer == null) return false;
            else return true;
        }