Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="objFileStream"></param>
        /// <returns></returns>
        public static HSD_JOBJ GenerateEmblemModel(EmblemModel model)
        {
            List <GX_Vertex> vertexList = new List <GX_Vertex>();

            foreach (var ve in model.f)
            {
                foreach (var i in ve)
                {
                    var x = ((model.v[i - 1][0] - model.xRange.X) / Math.Abs(model.xRange.Y - model.xRange.X)) * model.aspectX;
                    var y = (1 - (model.v[i - 1][2] - model.yRange.X) / Math.Abs(model.xRange.Y - model.yRange.X)) * model.aspectY;

                    vertexList.Add(new GX_Vertex()
                    {
                        POS = new GXVector3(x * 6 - 3, y * 6 - 3, 0)
                    });
                }
            }

            HSD_JOBJ jobj = new HSD_JOBJ();

            jobj.Flags = JOBJ_FLAG.CLASSICAL_SCALING | JOBJ_FLAG.XLU;
            jobj.SX    = 3;
            jobj.SY    = 3;
            jobj.SZ    = 3;
            jobj.TZ    = 67.4f;

            HSD_DOBJ dobj = new HSD_DOBJ();

            dobj.Mobj = new HSD_MOBJ()
            {
                RenderFlags = RENDER_MODE.CONSTANT | RENDER_MODE.NO_ZUPDATE | RENDER_MODE.XLU,
                Material    = new HSD_Material()
                {
                    Alpha         = 0.6f,
                    Shininess     = 50,
                    DiffuseColor  = Color.FromArgb(255, 128, 128, 230),
                    SpecularColor = Color.FromArgb(255, 255, 255, 255),
                    AmbientColor  = Color.FromArgb(255, 128, 128, 128),
                }
            };
            jobj.Dobj = dobj;

            POBJ_Generator pobjGen = new POBJ_Generator();

            GXAttribName[] attrs = new GXAttribName[] { GXAttribName.GX_VA_POS, GXAttribName.GX_VA_NULL };
            dobj.Pobj       = pobjGen.CreatePOBJsFromTriangleList(vertexList, attrs, null);
            dobj.Pobj.Flags = 0;
            pobjGen.SaveChanges();

            return(jobj);
        }
Exemplo n.º 2
0
        public override void FromIOModel(IOModel iomodel)
        {
            //System.Windows.Forms.MessageBox.Show("Importing Model to DAT not supported");

            // use the existing skeleton always
            iomodel.ConvertToSkeleton((SBSkeleton)Skeleton);

            // single bound vertices are stored in inverse transform positions
            iomodel.InvertSingleBinds();

            // dobjs to import to
            var dobjs = GetMeshObjects();

            foreach (SBHsdMesh m in GetMeshObjects())
            {
                m.DOBJ.Pobj = null;
            }

            var attributeGroup       = MakeRiggedAttributes();
            var singleAttributeGroup = MakeSingleAttributes();

            // get a compressor ready
            // the compressor will handle making the compressed attribute buffers
            POBJ_Generator compressor = new POBJ_Generator();

            // import the iomeshes into their respective dobjs
            foreach (var iomesh in iomodel.Meshes)
            {
                int dobjId = -1;
                int.TryParse(iomesh.Name.Replace("DOBJ_", ""), out dobjId);

                SBConsole.WriteLine(iomesh.Name + " imported:" + (dobjId != -1));

                if (dobjId != -1)
                {
                    var dobj = (SBHsdMesh)dobjs[dobjId];
                    dobj.ImportPOBJs(iomesh, (SBSkeleton)Skeleton, compressor, dobj.ParentBone == "JOBJ_0" ? attributeGroup : singleAttributeGroup);
                }
            }

            // finalizes and remakes the buffer
            compressor.SaveChanges();

            // refresh everything
            RefreshRendering();
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="iomodel"></param>
        public override void FromIOModel(IOScene iomodel)
        {
            var model = iomodel.Models[0];

            InvertSingleBinds(model);

            // dobjs to import to
            var dobjs = GetMeshObjects();

            // clear pobjs
            foreach (SBHsdMesh m in GetMeshObjects())
            {
                m.DOBJ.Pobj = null;
            }

            var attributeGroup       = MakeRiggedAttributes();
            var singleAttributeGroup = MakeSingleAttributes();

            // get a compressor ready
            // the compressor will handle making the compressed attribute buffers
            POBJ_Generator compressor = new POBJ_Generator();

            // import the iomeshes into their respective dobjs
            foreach (var iomesh in model.Meshes)
            {
                int dobjId = -1;
                int.TryParse(iomesh.Name.Replace("DOBJ_", ""), out dobjId);

                SBConsole.WriteLine(iomesh.Name + " imported:" + (dobjId != -1));

                if (dobjId != -1)
                {
                    var dobj = (SBHsdMesh)dobjs[dobjId];
                    dobj.ImportPOBJs(iomesh, (SBSkeleton)Skeleton, compressor, dobj.ParentBone == "JOBJ_0" ? attributeGroup : singleAttributeGroup);
                }
            }

            // finalizes and remakes the buffer
            compressor.SaveChanges();

            // refresh everything
            RefreshRendering();
        }
        public static HSD_DOBJ GenerateOutlineMesh(HSD_DOBJ DOBJ)
        {
            var settings = new OutlineSettings();

            using (PropertyDialog d = new PropertyDialog("Outline Settings", settings))
            {
                if (d.ShowDialog() != DialogResult.OK)
                {
                    return(null);
                }
            }

            var pobjGen = new POBJ_Generator();

            pobjGen.UseTriangleStrips = settings.UseStrips;

            var newDOBJ = new HSD_DOBJ();

            newDOBJ.Mobj = new HSD_MOBJ()
            {
                Material = new HSD_Material()
                {
                    AmbientColor  = Color.White,
                    SpecularColor = Color.Black,
                    DiffuseColor  = settings.Color,
                    DIF_A         = 255,
                    SPC_A         = 255,
                    AMB_A         = 255,
                    Shininess     = 50,
                    Alpha         = 1
                },
                RenderFlags = RENDER_MODE.CONSTANT
            };

            foreach (var pobj in DOBJ.Pobj.List)
            {
                var dl = pobj.ToDisplayList();

                var vertices = dl.Vertices;

                GXAttribName[] attrs = new GXAttribName[]
                {
                    GXAttribName.GX_VA_POS,
                    GXAttribName.GX_VA_NULL
                };

                if (pobj.HasAttribute(GXAttribName.GX_VA_PNMTXIDX))
                {
                    attrs = new GXAttribName[]
                    {
                        GXAttribName.GX_VA_PNMTXIDX,
                        GXAttribName.GX_VA_POS,
                        GXAttribName.GX_VA_NULL
                    };
                }

                List <GX_Vertex> newVerties = new List <GX_Vertex>();

                var offset = 0;
                foreach (var prim in dl.Primitives)
                {
                    var verts = vertices.GetRange(offset, prim.Count);
                    offset += prim.Count;

                    switch (prim.PrimitiveType)
                    {
                    case GXPrimitiveType.Quads:
                        verts = TriangleConverter.QuadToList(verts);
                        break;

                    case GXPrimitiveType.TriangleStrip:
                        verts = TriangleConverter.StripToList(verts);
                        break;

                    case GXPrimitiveType.Triangles:
                        break;

                    default:
                        Console.WriteLine(prim.PrimitiveType);
                        break;
                    }

                    newVerties.AddRange(verts);
                }

                // extrude
                for (int i = 0; i < newVerties.Count; i++)
                {
                    var v = newVerties[i];
                    v.POS.X += v.NRM.X * settings.Size;
                    v.POS.Y += v.NRM.Y * settings.Size;
                    v.POS.Z += v.NRM.Z * settings.Size;
                    //v.CLR0.R = settings.Color.R / 255f;
                    //v.CLR0.G = settings.Color.G / 255f;
                    //v.CLR0.B = settings.Color.B / 255f;
                    //v.CLR0.A = settings.Color.A / 255f;
                    newVerties[i] = v;
                }

                // invert faces
                for (int i = 0; i < newVerties.Count; i += 3)
                {
                    var temp = newVerties[i];
                    newVerties[i]     = newVerties[i + 2];
                    newVerties[i + 2] = temp;
                }

                var newpobj = pobjGen.CreatePOBJsFromTriangleList(newVerties, attrs, dl.Envelopes);
                foreach (var p in newpobj.List)
                {
                    p.Flags |= POBJ_FLAG.CULLBACK | POBJ_FLAG.UNKNOWN1;
                }
                if (newDOBJ.Pobj == null)
                {
                    newDOBJ.Pobj = newpobj;
                }
                else
                {
                    newDOBJ.Pobj.Add(newpobj);
                }
            }

            pobjGen.SaveChanges();

            return(newDOBJ);
        }
Exemplo n.º 5
0
        public static void RebuildPOBJs(HSD_JOBJ rootJOBJ)
        {
            var compressor = new POBJ_Generator();

            foreach (var jobj in rootJOBJ.BreathFirstList)
            {
                if (jobj.Dobj != null)
                {
                    foreach (var dobj in jobj.Dobj.List)
                    {
                        if (dobj.Pobj != null)
                        {
                            List <GX_Vertex>  triList = new List <GX_Vertex>();
                            List <HSD_JOBJ[]> bones   = new List <HSD_JOBJ[]>();
                            List <float[]>    weights = new List <float[]>();

                            foreach (var pobj in dobj.Pobj.List)
                            {
                                var dl  = pobj.ToDisplayList();
                                int off = 0;
                                foreach (var pri in dl.Primitives)
                                {
                                    var strip = dl.Vertices.GetRange(off, pri.Count);
                                    if (pri.PrimitiveType == GXPrimitiveType.TriangleStrip)
                                    {
                                        TriangleConverter.StripToList(strip, out strip);
                                    }
                                    if (pri.PrimitiveType == GXPrimitiveType.Quads)
                                    {
                                        TriangleConverter.QuadToList(strip, out strip);
                                    }
                                    off += pri.Count;

                                    //if(pobj.Flags.HasFlag(POBJ_FLAG.ENVELOPE))
                                    {
                                        triList.AddRange(strip);

                                        foreach (var v in strip)
                                        {
                                            if (dl.Envelopes.Count > 0)
                                            {
                                                var        en = dl.Envelopes[v.PNMTXIDX / 3];
                                                HSD_JOBJ[] b  = en.JOBJs;
                                                float[]    w  = en.Weights;
                                                bones.Add(b);
                                                weights.Add(w);
                                            }
                                            else
                                            {
                                                bones.Add(new HSD_JOBJ[0]);
                                                weights.Add(new float[0]);
                                            }
                                        }
                                    }
                                }
                            }

                            dobj.Pobj = compressor.CreatePOBJsFromTriangleList(triList, dobj.Pobj.Attributes.Select(e => e.AttributeName).ToArray(), bones, weights);
                        }
                    }
                }
            }
            compressor.SaveChanges();
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rootJOBJ"></param>
        private static GXVector3 RegenerateIcon(HSD_JOBJ rootJOBJ)
        {
            GXVector3 Min = new GXVector3(float.MaxValue, float.MaxValue, float.MaxValue);
            GXVector3 Max = new GXVector3(float.MinValue, float.MinValue, float.MinValue);

            foreach (var jobj in rootJOBJ.BreathFirstList)
            {
                if (jobj.Dobj != null)
                {
                    foreach (var dobj in jobj.Dobj.List)
                    {
                        if (dobj.Pobj != null)
                        {
                            foreach (var pobj in dobj.Pobj.List)
                            {
                                foreach (var v in pobj.ToDisplayList().Vertices)
                                {
                                    Min.X = Math.Min(Min.X, v.POS.X);
                                    Min.Y = Math.Min(Min.Y, v.POS.Y);
                                    Min.Z = Math.Min(Min.Z, v.POS.Z);
                                    Max.X = Math.Max(Max.X, v.POS.X);
                                    Max.Y = Math.Max(Max.Y, v.POS.Y);
                                    Max.Z = Math.Max(Max.Z, v.POS.Z);
                                }
                            }
                        }
                    }
                }
            }

            var center = new GXVector3((Min.X + Max.X) / 2, (Min.Y + Max.Y) / 2, (Min.Z + Max.Z) / 2);

            var compressor = new POBJ_Generator();

            foreach (var jobj in rootJOBJ.BreathFirstList)
            {
                if (jobj.Dobj != null)
                {
                    foreach (var dobj in jobj.Dobj.List)
                    {
                        if (dobj.Pobj != null)
                        {
                            List <GX_Vertex> triList = new List <GX_Vertex>();

                            foreach (var pobj in dobj.Pobj.List)
                            {
                                var dl  = pobj.ToDisplayList();
                                int off = 0;
                                foreach (var pri in dl.Primitives)
                                {
                                    var strip = dl.Vertices.GetRange(off, pri.Count);

                                    if (pri.PrimitiveType == GXPrimitiveType.TriangleStrip)
                                    {
                                        StripToList(strip, out strip);
                                    }

                                    if (pri.PrimitiveType == GXPrimitiveType.Quads)
                                    {
                                        QuadToList(strip, out strip);
                                    }

                                    off += pri.Count;

                                    for (int i = 0; i < strip.Count; i++)
                                    {
                                        var v = strip[i];

                                        v.POS.X -= center.X;
                                        v.POS.Y -= center.Y;
                                        v.POS.Z -= center.Z;

                                        strip[i] = v;
                                    }

                                    triList.AddRange(strip);
                                }
                            }

                            dobj.Pobj = compressor.CreatePOBJsFromTriangleList(triList, dobj.Pobj.ToGXAttributes().Select(e => e.AttributeName).ToArray(), null, null);
                        }
                    }
                }
            }
            compressor.SaveChanges();

            center.X *= rootJOBJ.SX;
            center.Y *= rootJOBJ.SY;
            center.Z *= rootJOBJ.SZ;

            return(center);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Test for rebuilding pobjs from scratch
        /// </summary>
        /// <param name="path"></param>
        public static void RebuildPOBJs(string path)
        {
            HSDRawFile file = new HSDRawFile(path);

            var rootJOBJ = (HSD_JOBJ)(file.Roots[0].Data);

            var compressor = new POBJ_Generator();

            foreach (var jobj in rootJOBJ.BreathFirstSearch)
            {
                if (jobj.Dobj != null)
                {
                    foreach (var dobj in jobj.Dobj.List)
                    {
                        if (dobj.Pobj != null)
                        {
                            GXAttribName[] attributes = null;
                            if (attributes == null)
                            {
                                attributes = new GXAttribName[dobj.Pobj.Attributes.Length - 1];
                                for (int i = 0; i < attributes.Length; i++)
                                {
                                    attributes[i] = dobj.Pobj.Attributes[i].AttributeName;
                                }
                            }

                            List <GX_Vertex>  triList = new List <GX_Vertex>();
                            List <HSD_JOBJ[]> bones   = new List <HSD_JOBJ[]>();
                            List <float[]>    weights = new List <float[]>();

                            foreach (var pobj in dobj.Pobj.List)
                            {
                                var dl  = pobj.ToDisplayList();
                                int off = 0;
                                foreach (var pri in dl.Primitives)
                                {
                                    var strip = dl.Vertices.GetRange(off, pri.Count);
                                    if (pri.PrimitiveType == GXPrimitiveType.TriangleStrip)
                                    {
                                        TriangleConverter.StripToList(strip, out strip);
                                    }
                                    if (pri.PrimitiveType == GXPrimitiveType.Quads)
                                    {
                                        TriangleConverter.QuadToList(strip, out strip);
                                    }
                                    off += pri.Count;

                                    //if(pobj.Flags.HasFlag(POBJ_FLAG.ENVELOPE))
                                    {
                                        triList.AddRange(strip);

                                        foreach (var v in strip)
                                        {
                                            if (dl.Envelopes.Count > 0)
                                            {
                                                var        en = dl.Envelopes[v.PNMTXIDX / 3];
                                                HSD_JOBJ[] b  = en.JOBJs;
                                                float[]    w  = en.Weights;
                                                bones.Add(b);
                                                weights.Add(w);
                                            }
                                            else
                                            {
                                                bones.Add(new HSD_JOBJ[0]);
                                                weights.Add(new float[0]);
                                            }
                                        }
                                    }
                                }
                            }

                            dobj.Pobj = compressor.CreatePOBJsFromTriangleList(triList, attributes, bones, weights);


                            /*List<GX_Vertex> triList = new List<GX_Vertex>();
                             * foreach (var pobj in dobj.Pobj.List)
                             * {
                             *  var dl = pobj.DisplayList;
                             *  var newPrimGroup = new List<GX_PrimitiveGroup>();
                             *  int offset = 0;
                             *  foreach (var g in dl.Primitives)
                             *  {
                             *      GX_Vertex[] strip = new GX_Vertex[g.Count];
                             *      for (int i = 0; i < g.Count; i++)
                             *          strip[i] = dl.Vertices[offset + i];
                             *      newPrimGroup.Add(compressor.Compress(g.PrimitiveType, strip, pobj.Attributes));
                             *      offset += g.Count;
                             *  }
                             *  dl.Primitives = newPrimGroup;
                             *  pobj.DisplayList = dl;
                             * }*/
                        }
                    }
                }
            }
            compressor.SaveChanges();
            file.Save(path + "_rebuilt.dat");
        }