Пример #1
0
        private InteropVertex GetInteropVertex(Vertex v)
        {
            InteropVertex iv = new InteropVertex();

            InteropVector4 dvOne = new InteropVector4();

            dvOne.X = 1;
            dvOne.Y = 1;
            dvOne.Z = 1;
            dvOne.W = 1;

            InteropVector4 dvZero = new InteropVector4();

            dvZero.X = 0;
            dvZero.Y = 0;
            dvZero.W = 0;
            dvZero.W = 0;

            iv.Position     = GetInteropVector4(v.Position, dvZero);
            iv.Normal       = GetInteropVector4(v.Normal, dvZero);
            iv.UV           = GetInteropVector4(v.UV, dvZero);
            iv.BlendWeights = GetInteropVector4(v.BlendWeights, dvZero);
            iv.BlendIndices = v.BlendIndices.GetValueOrDefault(0);
            iv.Color        = GetInteropVector4(v.Color, dvOne);
            iv.Tangent1     = GetInteropVector4(v.Tangent1, dvZero);
            iv.Tangent2     = GetInteropVector4(v.Tangent2, dvZero);

            return(iv);
        }
Пример #2
0
        public InteropMesh(Mesh m)
        {
            Vertices = new InteropVertex[m.Vertices.Length];
            Indices  = new ushort[m.Indices.Length];

            for (int i = 0; i < Vertices.Length; i++)
            {
                Vertices[i] = GetInteropVertex(m.Vertices[i]);
            }

            for (int i = 0; i < Indices.Length; i++)
            {
                Indices[i] = m.Indices[i];
            }

            NumVertexes = m.Vertices.Length;
            NumIndices  = m.Indices.Length;

            BoneListSize = (int)m.Model.Definition.BoneLists[m.Header.BoneListIndex].ActualCount;
            BoneList     = new ushort[BoneListSize];

            // copy actual amount to boneList
            for (int i = 0; i < BoneListSize; i++)
            {
                BoneList[i] = m.Model.Definition.BoneLists[m.Header.BoneListIndex].Bones[i];
            }

            _UnmanagedPtr = Interop.loadMesh(Index,
                                             Vertices, m.Vertices.Length,
                                             Indices, m.Indices.Length,
                                             BoneList, BoneListSize);
        }
Пример #3
0
        /// <summary>
        /// Merges an array of meshes into one InteropMesh. Unused. Does not include BoneList
        /// </summary>
        /// <param name="ma"></param>
        public InteropMesh(Mesh[] ma)
        {
            int numMeshes     = ma.Length;
            int totalVertices = ma.Select(_ => _.Vertices.Length).Sum();
            int totalIndices  = ma.Select(_ => _.Indices.Length).Sum();

            int    vertAccumulator  = 0;
            ushort indexAccumulator = 0;

            Vertices = new InteropVertex[totalVertices];
            Indices  = new ushort[totalIndices];

            for (int i = 0; i < numMeshes; i++)
            {
                int prevVertSum = 0;
                int prevIndSum  = 0;

                // sum previous vertices
                for (int j = 0; j < i; j++)
                {
                    prevVertSum += ma[j].Vertices.Length;
                    prevIndSum  += ma[j].Indices.Length;
                }

                foreach (var t in ma[i].Vertices)
                {
                    Vertices[vertAccumulator] = GetInteropVertex(ma[i].Vertices[vertAccumulator - prevVertSum]);
                    vertAccumulator++;
                }

                foreach (var t in ma[i].Indices)
                {
                    if (i == 0)
                    {
                        Indices[indexAccumulator] = ma[i].Indices[indexAccumulator - prevIndSum];
                        indexAccumulator++;
                    }
                    else
                    {
                        Indices[indexAccumulator] = (ushort)(ma[i].Indices[indexAccumulator - prevIndSum] + prevVertSum);
                        indexAccumulator++;
                    }
                }
            }

//            _UnmanagedPtr = Interop.loadMesh(Index,
//                Vertices, Vertices.Length,
//                Indices, Indices.Length);
        }