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>
        public static GX_Vertex[] GetDecodedVertices(GX_DisplayList DisplayList, HSD_POBJ Polygon)
        {
            // Create Vertex List
            List <GX_Vertex> Vertices = new List <GX_Vertex>();

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

            return(Vertices.ToArray());
        }
Beispiel #2
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>
        public static GX_Shape[] GetShapeSet(GX_DisplayList DisplayList, HSD_POBJ Polygon, int shapeset)
        {
            // Create Vertex List
            List <GX_Shape> Vertices = new List <GX_Shape>();

            // Read through the Display Lists
            foreach (GX_PrimitiveGroup pg in DisplayList.Primitives)
            {
                var v = GetDecodedVertices(pg, DisplayList.Attributes, Polygon, shapeset);

                foreach (var gv in v)
                {
                    Vertices.Add(new GX_Shape()
                    {
                        POS = gv.POS, NRM = gv.NRM
                    });
                }
            }

            return(Vertices.ToArray());
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="triList"></param>
        /// <param name="attrGroup"></param>
        /// <param name="weights"></param>
        public HSD_POBJ CreatePOBJsFromTriangleList(List <GX_Vertex> triList, GXAttribName[] attributes, List <HSD_Envelope> weights)
        {
            TriangleConverter.TriangleConverter converter = new TriangleConverter.TriangleConverter(UseTriangleStrips, 32, 3, true);
            int pointCount, faceCount;

            HSD_JOBJ singleBind = null;

            bool HasPositionNormalMatrix = attributes.Contains(GXAttribName.GX_VA_PNMTXIDX);

            // Optimize single bind

            /*if (weights != null && weights.Count == 1 && weights[0].EnvelopeCount == 1)
             * {
             *  singleBind = weights[0].GetJOBJAt(0);
             *  var al = attributes.ToList();
             *  al.Remove(GXAttribName.GX_VA_PNMTXIDX);
             *  attributes = al.ToArray();
             * }*/

            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_Envelope>();
                var pmidToNewID = new Dictionary <ushort, ushort>();

                if (HasPositionNormalMatrix == true && weights.Count > 0)
                {
                    foreach (var n in g._nodes)
                    {
                        pmidToNewID.Add(n, (ushort)(jobjweights.Count * 3));
                        jobjweights.Add(weights[n / 3]);
                    }
                }

                GX_DisplayList newdl = new GX_DisplayList();

                foreach (var t in g._triangles)
                {
                    var newVert = new List <GX_Vertex>();
                    for (int p = 0; p < t.Points.Count; p++)
                    {
                        var point = t.Points[p];
                        if (HasPositionNormalMatrix)
                        {
                            point.PNMTXIDX   = pmidToNewID[point.PNMTXIDX];
                            point.TEX0MTXIDX = (ushort)(point.PNMTXIDX + 30);
                            point.TEX1MTXIDX = point.TEX0MTXIDX;
                        }
                        t.Points[p] = point;
                        newVert.Add(point);
                    }

                    newdl.Primitives.Add(Compress(GXPrimitiveType.Triangles, newVert.ToArray(), attributes));
                }
                foreach (var t in g._tristrips)
                {
                    var newVert = new List <GX_Vertex>();
                    for (int p = 0; p < t.Points.Count; p++)
                    {
                        var point = t.Points[p];
                        if (HasPositionNormalMatrix)
                        {
                            point.PNMTXIDX   = pmidToNewID[point.PNMTXIDX];
                            point.TEX0MTXIDX = (ushort)(point.PNMTXIDX + 30);
                            point.TEX1MTXIDX = point.TEX0MTXIDX;
                        }
                        t.Points[p] = point;
                        newVert.Add(point);
                    }
                    newdl.Primitives.Add(Compress(GXPrimitiveType.TriangleStrip, newVert.ToArray(), attributes));
                }

                if (singleBind == null)
                {
                    newdl.Envelopes = jobjweights;
                }

                var newpobj = new HSD_POBJ();
                CreatedPOBJs.Add(newpobj);

                if (singleBind != null)
                {
                    newpobj.SingleBoundJOBJ = singleBind;
                }

                pobjToDisplayList.Add(newpobj, newdl);
                pobjToAttributes.Add(newpobj, attributes);

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

            //Console.WriteLine(rootPOBJ.List.Count + " POBJs generated");


            return(rootPOBJ);
        }