The halo vertex.
예제 #1
0
        /// <summary>
        /// The make mesh.
        /// </summary>
        /// <param name="vertices">The vertices.</param>
        /// <param name="Indices">The indices.</param>
        /// <param name="uvs">The uvs.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public Mesh MakeMesh(List <Vector3> vertices, List <short> Indices, List <Vector2> uvs)
        {
            Mesh m = new Mesh(Indices.Count / 3, vertices.Count, MeshFlags.Managed, HaloVertex.FVF, device);

            HaloVertex[] tempv = new HaloVertex[vertices.Count];
            for (int x = 0; x < vertices.Count; x++)
            {
                tempv[x].Position = vertices[x];
                tempv[x].Tu0      = uvs[x].X;
                tempv[x].Tv0      = uvs[x].Y;
            }

            VertexBuffer vb = m.VertexBuffer;

            vb.SetData(tempv, 0, LockFlags.None);
            vb.Unlock();

            IndexBuffer ibx = m.IndexBuffer;

            ibx.SetData(Indices.ToArray(), 0, LockFlags.None);

            return(m);
        }
예제 #2
0
        /// <summary>
        /// The load mesh.
        /// </summary>
        /// <remarks></remarks>
        public void LoadMesh()
        {
            dxcoll = new DirectXCollision(ref device, ref coll);

            for (int mc = 0; mc < coll.Meshes.Count; mc++)
            {
                for (int i = 0; i < coll.Meshes[mc].SurfaceData.Length; i++)
                {
                    // for (int i = 0; i < 1; i++)
                    Mesh m = new Mesh(
                        coll.Meshes[mc].SurfaceData.Length,
                        coll.Meshes[mc].Vertices.Length,
                        MeshFlags.Managed,
                        HaloVertex.FVF,
                        device);
                    VertexBuffer vb = m.VertexBuffer;
                    HaloVertex[] tempv = new HaloVertex[coll.Meshes[mc].Vertices.Length];
                    for (int x = 0; x < coll.Meshes[mc].Vertices.Length; x++)
                    {
                        tempv[x].Position = coll.Meshes[mc].Vertices[x];
                    }

                    vb.SetData(tempv, 0, LockFlags.None);
                    vb.Unlock();

                    short[] b = new short[(coll.Meshes[mc].SurfaceData[i].Vertices.Count - 2) * 3];
                    for (int ii = 0; ii < 3; ii++)
                    {
                        b[ii] = (short)coll.Meshes[mc].SurfaceData[i].Vertices[ii];
                    }

                    for (int ii = 1; ii < coll.Meshes[mc].SurfaceData[i].Vertices.Count - 2; ii++)
                    {
                        b[ii * 3] = b[0];
                        b[ii * 3 + 1] = b[ii * 3 - 1];
                        b[ii * 3 + 2] = (short)coll.Meshes[mc].SurfaceData[i].Vertices[ii + 2];
                    }

                    IndexBuffer ibx = m.IndexBuffer;
                    ibx.SetData(b, 0, LockFlags.None);
                    mList.Add(m);
                }

                normalVertices = new CustomVertex.PositionColored[coll.Meshes[mc].Normals.Length * 2];
                for (int i = 0; i < coll.Meshes[mc].Normals.Length; i++)
                {
                    normalVertices[i * 2 + 0].Color = Color.Yellow.ToArgb();
                    normalVertices[i * 2 + 0].Position =
                        new Vector3(
                            coll.Meshes[mc].Normals[i].X * coll.Meshes[mc].Normals[i].W,
                            coll.Meshes[mc].Normals[i].Y * coll.Meshes[mc].Normals[i].W,
                            coll.Meshes[mc].Normals[i].Z * coll.Meshes[mc].Normals[i].W);
                    normalVertices[i * 2 + 1].Color = Color.White.ToArgb();
                    normalVertices[i * 2 + 1].Position = new Vector3(
                        coll.Meshes[mc].Normals[i].X, coll.Meshes[mc].Normals[i].Y, coll.Meshes[mc].Normals[i].Z);

                    // normalVertices[i * 3 + 2].Position = new Vector4(1, 1, 1, 1.0f);
                    // normalVertices[i * 3 + 2].Color = Color.White.ToArgb();
                }
            }

            Vb = new VertexBuffer(
                typeof(CustomVertex.PositionColored),
                normalVertices.Length,
                device,
                Usage.Dynamic | Usage.WriteOnly,
                CustomVertex.PositionColored.Format,
                Pool.Default);
            Vb.SetData(normalVertices, 0, LockFlags.None);
            device.SetStreamSource(0, Vb, 0);
        }
예제 #3
0
        /// <summary>
        /// The make mesh.
        /// </summary>
        /// <param name="vertices">The vertices.</param>
        /// <param name="Indices">The indices.</param>
        /// <param name="uvs">The uvs.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public Mesh MakeMesh(List<Vector3> vertices, List<short> Indices, List<Vector2> uvs)
        {
            Mesh m = new Mesh(Indices.Count / 3, vertices.Count, MeshFlags.Managed, HaloVertex.FVF, device);
            HaloVertex[] tempv = new HaloVertex[vertices.Count];
            for (int x = 0; x < vertices.Count; x++)
            {
                tempv[x].Position = vertices[x];
                tempv[x].Tu0 = uvs[x].X;
                tempv[x].Tv0 = uvs[x].Y;
            }

            VertexBuffer vb = m.VertexBuffer;
            vb.SetData(tempv, 0, LockFlags.None);
            vb.Unlock();

            IndexBuffer ibx = m.IndexBuffer;
            ibx.SetData(Indices.ToArray(), 0, LockFlags.None);

            return m;
        }
예제 #4
0
        /// <summary>
        /// The make mesh.
        /// </summary>
        /// <param name="pm">The pm.</param>
        /// <param name="chunknumber">The chunknumber.</param>
        /// <param name="device">The device.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Mesh MakeMesh(ref ParsedModel pm, int chunknumber, ref Device device)
        {
            short[] indices;
            int[]   facecount = new int[pm.RawDataMetaChunks[chunknumber].SubMeshInfo.Length];
            int[]   facestart = new int[pm.RawDataMetaChunks[chunknumber].SubMeshInfo.Length];
            if (pm.RawDataMetaChunks[chunknumber].FaceCount * 3 != pm.RawDataMetaChunks[chunknumber].Indices.Length)
            {
                short[] tempindicesx = new short[pm.RawDataMetaChunks[chunknumber].FaceCount * 3];
                int     tempc        = 0;
                for (int x = 0; x < pm.RawDataMetaChunks[chunknumber].SubMeshInfo.Length; x++)
                {
                    short[] tempindices = DecompressIndices(
                        pm.RawDataMetaChunks[chunknumber].Indices,
                        pm.RawDataMetaChunks[chunknumber].SubMeshInfo[x].IndiceStart,
                        pm.RawDataMetaChunks[chunknumber].SubMeshInfo[x].IndiceCount);
                    Array.ConstrainedCopy(tempindices, 0, tempindicesx, tempc, tempindices.Length);

                    facecount[x] = tempindices.Length / 3;
                    facestart[x] = tempc;
                    tempc       += tempindices.Length;
                }

                indices = new short[tempindicesx.Length];
                Array.Copy(tempindicesx, indices, tempindicesx.Length);
            }
            else
            {
                indices = pm.RawDataMetaChunks[chunknumber].Indices;
                for (int x = 0; x < pm.RawDataMetaChunks[chunknumber].SubMeshInfo.Length; x++)
                {
                    facecount[x] = pm.RawDataMetaChunks[chunknumber].SubMeshInfo[x].IndiceCount / 3;
                    facestart[x] = pm.RawDataMetaChunks[chunknumber].SubMeshInfo[x].IndiceStart / 3;
                }
            }

            Mesh m = new Mesh(
                indices.Length / 3,
                pm.RawDataMetaChunks[chunknumber].Vertices.Count,
                MeshFlags.Managed,
                HaloVertex.FVF,
                device);
            VertexBuffer vb = m.VertexBuffer;

            HaloVertex[] tempv = new HaloVertex[pm.RawDataMetaChunks[chunknumber].Vertices.Count];
            for (int x = 0; x < pm.RawDataMetaChunks[chunknumber].Vertices.Count; x++)
            {
                tempv[x].Position = pm.RawDataMetaChunks[chunknumber].Vertices[x];
                tempv[x].Normal   = pm.RawDataMetaChunks[chunknumber].Normals[x];
                tempv[x].Tu0      = pm.RawDataMetaChunks[chunknumber].UVs[x].X;
                tempv[x].Tv0      = pm.RawDataMetaChunks[chunknumber].UVs[x].Y;
            }

            vb.SetData(tempv, 0, LockFlags.None);
            vb.Unlock();

            IndexBuffer ibx = m.IndexBuffer;

            ibx.SetData(indices, 0, LockFlags.None);

            return(m);
        }
예제 #5
0
        /// <summary>
        /// The make mesh.
        /// </summary>
        /// <param name="pm">The pm.</param>
        /// <param name="chunknumber">The chunknumber.</param>
        /// <param name="device">The device.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static Mesh MakeMesh(ref ParsedModel pm, int chunknumber, ref Device device)
        {
            short[] indices;
            int[] facecount = new int[pm.RawDataMetaChunks[chunknumber].SubMeshInfo.Length];
            int[] facestart = new int[pm.RawDataMetaChunks[chunknumber].SubMeshInfo.Length];
            if (pm.RawDataMetaChunks[chunknumber].FaceCount * 3 != pm.RawDataMetaChunks[chunknumber].Indices.Length)
            {
                short[] tempindicesx = new short[pm.RawDataMetaChunks[chunknumber].FaceCount * 3];
                int tempc = 0;
                for (int x = 0; x < pm.RawDataMetaChunks[chunknumber].SubMeshInfo.Length; x++)
                {
                    short[] tempindices = DecompressIndices(
                        pm.RawDataMetaChunks[chunknumber].Indices,
                        pm.RawDataMetaChunks[chunknumber].SubMeshInfo[x].IndiceStart,
                        pm.RawDataMetaChunks[chunknumber].SubMeshInfo[x].IndiceCount);
                    Array.ConstrainedCopy(tempindices, 0, tempindicesx, tempc, tempindices.Length);

                    facecount[x] = tempindices.Length / 3;
                    facestart[x] = tempc;
                    tempc += tempindices.Length;
                }

                indices = new short[tempindicesx.Length];
                Array.Copy(tempindicesx, indices, tempindicesx.Length);
            }
            else
            {
                indices = pm.RawDataMetaChunks[chunknumber].Indices;
                for (int x = 0; x < pm.RawDataMetaChunks[chunknumber].SubMeshInfo.Length; x++)
                {
                    facecount[x] = pm.RawDataMetaChunks[chunknumber].SubMeshInfo[x].IndiceCount / 3;
                    facestart[x] = pm.RawDataMetaChunks[chunknumber].SubMeshInfo[x].IndiceStart / 3;
                }
            }

            Mesh m = new Mesh(
                indices.Length / 3,
                pm.RawDataMetaChunks[chunknumber].Vertices.Count,
                MeshFlags.Managed,
                HaloVertex.FVF,
                device);
            VertexBuffer vb = m.VertexBuffer;
            HaloVertex[] tempv = new HaloVertex[pm.RawDataMetaChunks[chunknumber].Vertices.Count];
            for (int x = 0; x < pm.RawDataMetaChunks[chunknumber].Vertices.Count; x++)
            {
                tempv[x].Position = pm.RawDataMetaChunks[chunknumber].Vertices[x];
                tempv[x].Normal = pm.RawDataMetaChunks[chunknumber].Normals[x];
                tempv[x].Tu0 = pm.RawDataMetaChunks[chunknumber].UVs[x].X;
                tempv[x].Tv0 = pm.RawDataMetaChunks[chunknumber].UVs[x].Y;
            }

            vb.SetData(tempv, 0, LockFlags.None);
            vb.Unlock();

            IndexBuffer ibx = m.IndexBuffer;
            ibx.SetData(indices, 0, LockFlags.None);

            return m;
        }