Beispiel #1
0
        /// <summary>
        /// Reads the vertex buffer into a more accessable format : <see cref="GXVertex"/>
        /// </summary>
        /// <param name="DisplayList">Display list belonging to given PBOJ</param>
        /// <param name="Polygon"><see cref="HSD_POBJ"/> the the display list belong to</param>
        /// <returns>Array of <see cref="GXVertex"/></returns>
        private static GXVertex[] GetDecodedVertices(GXDisplayList DisplayList, HSD_POBJ Polygon)
        {
            // Create Vertex List
            List <GXVertex> Vertices = new List <GXVertex>();

            // Read through the Display Lists
            foreach (GXPrimitiveGroup pg in DisplayList.Primitives)
            {
                Vertices.AddRange(GetDecodedVertices(pg, Polygon.VertexAttributes));
            }

            return(Vertices.ToArray());
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="triList"></param>
        /// <param name="attrGroup"></param>
        /// <param name="weights"></param>
        public HSD_POBJ CreatePOBJ(List <GXVertex> triList, HSD_AttributeGroup attrGroup, List <HSD_JOBJWeight> weights)
        {
            TriangleConverter.TriangleConverter converter = new TriangleConverter.TriangleConverter(true, 100, 3, true);
            int pointCount, faceCount;

            var groups = converter.GroupPrimitives(triList.ToArray(), out pointCount, out faceCount);

            HSD_POBJ rootPOBJ = null;
            HSD_POBJ prevPOBJ = null;

            foreach (var g in groups)
            {
                var jobjweights = new List <HSD_JOBJWeight>();
                var pmidToNewID = new Dictionary <ushort, ushort>();

                foreach (var n in g._nodes)
                {
                    pmidToNewID.Add(n, (ushort)(jobjweights.Count * 3));
                    jobjweights.Add(weights[n / 3]);
                }

                GXDisplayList newdl = new GXDisplayList();

                foreach (var t in g._triangles)
                {
                    var newVert = new List <GXVertex>();
                    for (int p = 0; p < t.Points.Count; p++)
                    {
                        var point = t.Points[p];
                        point.PMXID = pmidToNewID[point.PMXID];
                        t.Points[p] = point;
                        newVert.Add(point);
                        //Console.WriteLine(t.points[p].PMID + " " + point.PMXID + " " + pmidToNewID[point.PMXID] + " " + jobjweights.Count);
                    }

                    newdl.Primitives.Add(Compress(GXPrimitiveType.Triangles, newVert.ToArray(), attrGroup));
                }
                foreach (var t in g._tristrips)
                {
                    var newVert = new List <GXVertex>();
                    for (int p = 0; p < t.Points.Count; p++)
                    {
                        //Console.WriteLine(t.Points[p].PMXID + " " + g._nodes.Count);
                        var point = t.Points[p];
                        point.PMXID = pmidToNewID[point.PMXID];
                        t.Points[p] = point;
                        newVert.Add(point);
                    }
                    newdl.Primitives.Add(Compress(GXPrimitiveType.TriangleStrip, newVert.ToArray(), attrGroup));
                }

                HSD_PointerArray <HSD_JOBJWeight> bindWeights = new HSD_PointerArray <HSD_JOBJWeight>();
                bindWeights.Elements = jobjweights.ToArray();

                var newpobj = new HSD_POBJ();

                newpobj.Flags             = POBJ_FLAG.ENVELOPE;
                newpobj.BindGroups        = bindWeights;
                newpobj.VertexAttributes  = attrGroup;
                newpobj.DisplayListBuffer = newdl.ToBuffer(attrGroup);

                if (prevPOBJ == null)
                {
                    rootPOBJ = newpobj;
                }
                else
                {
                    prevPOBJ.Next = newpobj;
                }
                prevPOBJ = newpobj;
            }

            return(rootPOBJ);
        }