示例#1
0
 public SBHsdVertex(GXVector3 pOS, GXVector3 nRM, GXVector2 uV0, Vector4 bone, Vector4 weight) : this()
 {
     POS    = pOS;
     NRM    = nRM;
     UV0    = uV0;
     Bone   = bone;
     Weight = weight;
 }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="p"></param>
        /// <param name="index"></param>
        /// <param name="pointToIndex"></param>
        /// <param name="points"></param>
        /// <returns></returns>
        private static int GetPointIndex(GXVector3 p, ref Dictionary <GXVector3, int> pointToIndex, ref List <GXVector3> points)
        {
            if (!pointToIndex.ContainsKey(p))
            {
                pointToIndex.Add(p, points.Count);
                points.Add(p);
            }

            return(pointToIndex[p]);
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="group"></param>
        /// <returns></returns>
        public static HSD_JOBJ GenerateModel(SSFGroup group)
        {
            var jobj = new HSD_JOBJ()
            {
                Flags = JOBJ_FLAG.CLASSICAL_SCALING,
                SX    = 1,
                SY    = 1,
                SZ    = 1
            };

            if (group.Lines.Count == 0)
            {
                return(jobj);
            }

            var attributes = new GXAttribName[]
            {
                GXAttribName.GX_VA_POS,
                GXAttribName.GX_VA_NRM,
                GXAttribName.GX_VA_NULL
            };

            var triangleList = new List <GX_Vertex>();

            foreach (var l in group.Lines)
            {
                var v1     = group.Vertices[l.Vertex1];
                var v2     = group.Vertices[l.Vertex2];
                var nrm    = new OpenTK.Vector3(v1.X - v2.X, v1.Y - v2.Y, 0).Normalized();
                var normal = new GXVector3(nrm.Y, -nrm.X, nrm.Z);

                triangleList.Add(new GX_Vertex()
                {
                    POS = new GXVector3(v1.X, v1.Y, 5), NRM = normal
                });
                triangleList.Add(new GX_Vertex()
                {
                    POS = new GXVector3(v1.X, v1.Y, -5), NRM = normal
                });
                triangleList.Add(new GX_Vertex()
                {
                    POS = new GXVector3(v2.X, v2.Y, 5), NRM = normal
                });

                triangleList.Add(new GX_Vertex()
                {
                    POS = new GXVector3(v2.X, v2.Y, -5), NRM = normal
                });
                triangleList.Add(new GX_Vertex()
                {
                    POS = new GXVector3(v2.X, v2.Y, 5), NRM = normal
                });
                triangleList.Add(new GX_Vertex()
                {
                    POS = new GXVector3(v1.X, v1.Y, -5), NRM = normal
                });
            }

            var gen = new HSDRaw.Tools.POBJ_Generator();

            jobj.Dobj = new HSD_DOBJ()
            {
                Mobj = new HSD_MOBJ()
                {
                    RenderFlags = RENDER_MODE.DIFFUSE,
                    Material    = new HSD_Material()
                    {
                        Alpha         = 1,
                        AmbientColor  = System.Drawing.Color.Gray,
                        DiffuseColor  = System.Drawing.Color.Gray,
                        SpecularColor = System.Drawing.Color.White,
                    }
                },
                Pobj = gen.CreatePOBJsFromTriangleList(triangleList, attributes, null)
            };
            gen.SaveChanges();

            Console.WriteLine(gen.CreatePOBJsFromTriangleList(triangleList, attributes, null).Attributes);


            return(jobj);
        }
示例#4
0
 public static Vector3 GLVector3(GXVector3 v)
 {
     return(new Vector3(v.X, v.Y, v.Z));
 }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="table"></param>
        /// <param name="icons"></param>
        /// <returns></returns>
        private static MEX_mexSelectChr GenerateMexSelectChrSymbol(SBM_SelectChrDataTable table, MEX_CSSIcon[] cssIcons)
        {
            // create mexSelectChr struct
            MEX_mexSelectChr mex = new MEX_mexSelectChr();

            // generate icon model
            var icon_joint = HSDAccessor.DeepClone <HSD_JOBJ>(table.MenuModel.Children[2].Child);

            icon_joint.TX   = 0;
            icon_joint.TY   = 0;
            icon_joint.TZ   = 0;
            icon_joint.Next = null;
            var center = RegenerateIcon(icon_joint);

            // generate material_anim_joint
            var icon_matanim_joint = HSDAccessor.DeepClone <HSD_MatAnimJoint>(table.MenuMaterialAnimation.Children[2].Child);

            icon_matanim_joint.Next = null;

            // general base models
            HSD_JOBJ position_joint = new HSD_JOBJ();

            position_joint.Flags = JOBJ_FLAG.CLASSICAL_SCALING | JOBJ_FLAG.ROOT_XLU;
            position_joint.SX    = 1; position_joint.SY = 1; position_joint.SZ = 1;

            HSD_AnimJoint anim_joint = new HSD_AnimJoint();

            HSD_MatAnimJoint matanim_joint = new HSD_MatAnimJoint();

            // create icon data
            var joints   = table.MenuModel.BreathFirstList;
            var matanims = table.MenuAnimation.BreathFirstList;

            foreach (var ico in cssIcons)
            {
                if (joints[ico.JointID].Dobj == null)
                {
                    continue;
                }

                HSD_JOBJ joint = HSDAccessor.DeepClone <HSD_JOBJ>(icon_joint);
                joint.Dobj.Pobj.Attributes      = icon_joint.Dobj.Pobj.Attributes;
                joint.Dobj.Next.Pobj.Attributes = icon_joint.Dobj.Pobj.Attributes;
                joint.Dobj.Next.Mobj.Textures   = HSDAccessor.DeepClone <HSD_TOBJ>(joints[ico.JointID].Dobj.Next.Mobj.Textures);

                var worldPosition = new GXVector3(joints[ico.JointID].TX, joints[ico.JointID].TY, joints[ico.JointID].TZ);

                // get anim
                var anim = matanims[ico.JointID].AOBJ;

                // if it's a clone get parent location
                if (ico.JointID < 15)
                {
                    worldPosition = new GXVector3(joints[ico.JointID - 1].TX, joints[ico.JointID - 1].TY, joints[ico.JointID - 1].TZ);
                    anim          = matanims[ico.JointID - 1].AOBJ;
                }

                // check animation for world position
                if (anim != null)
                {
                    foreach (var v in anim.FObjDesc.List)
                    {
                        System.Diagnostics.Debug.WriteLine(v.JointTrackType);
                        if (v.JointTrackType == JointTrackType.HSD_A_J_TRAX)
                        {
                            var keys = v.GetDecodedKeys();
                            worldPosition.X = keys[keys.Count - 1].Value;
                        }
                    }
                }

                joint.TX = worldPosition.X + center.X;
                joint.TY = worldPosition.Y + center.Y;
                joint.TZ = worldPosition.Z + center.Z;

                position_joint.AddChild(joint);
                anim_joint.AddChild(new HSD_AnimJoint());
                matanim_joint.AddChild(HSDAccessor.DeepClone <HSD_MatAnimJoint>(icon_matanim_joint));
            }

            mex.IconModel        = position_joint;
            mex.IconAnimJoint    = anim_joint;
            mex.IconMatAnimJoint = matanim_joint;
            mex.CSPMatAnim       = HSDAccessor.DeepClone <HSD_MatAnim>(table.MenuMaterialAnimation.Children[6].Child.MaterialAnimation);

            var cspkeys = mex.CSPMatAnim.TextureAnimation.AnimationObject.FObjDesc.GetDecodedKeys();

            foreach (var k in cspkeys)
            {
                if ((k.Frame % 30) >= 19)
                {
                    k.Frame++;
                }
            }

            mex.CSPMatAnim.TextureAnimation.AnimationObject.FObjDesc.SetKeys(cspkeys, (byte)TexTrackType.HSD_A_T_TIMG);
            mex.CSPMatAnim.TextureAnimation.AnimationObject.FObjDesc.Next.SetKeys(cspkeys, (byte)TexTrackType.HSD_A_T_TCLT);

            mex.CSPStride = 30;

            return(mex);
        }
示例#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);
        }