Ejemplo n.º 1
0
        /// <summary>
        /// Attaches SKELETON JOBJs to skeleton for rendering and editing
        /// </summary>
        /// <param name="jobj"></param>
        /// <param name="parent"></param>
        private void RecursivlyAddChildren(HSD_JOBJ jobj, SBHsdBone parent)
        {
            /*if (!(jobj.Flags.HasFlag(JOBJ_FLAG.SKELETON) || jobj.Flags.HasFlag(JOBJ_FLAG.SKELETON_ROOT)))
             * {
             *  SBConsole.WriteLine(jobj.Flags.ToString());
             *  return;
             * }*/

            SBHsdBone bone = new SBHsdBone();

            bone.Name = "JOBJ_" + Skeleton.Bones.Length;

            bone.Transform     = OpenTK.Matrix4.Identity;
            bone.Translation   = new OpenTK.Vector3(jobj.TX, jobj.TY, jobj.TZ);
            bone.RotationEuler = new OpenTK.Vector3(jobj.RX, jobj.RY, jobj.RZ);
            bone.Scale         = new OpenTK.Vector3(jobj.SX, jobj.SY, jobj.SZ);
            bone.SetJOBJ(jobj);

            if (parent == null)
            {
                ((SBSkeleton)Skeleton).AddRoot(bone);
            }
            else
            {
                bone.Parent = parent;
            }
            foreach (var child in jobj.Children)
            {
                RecursivlyAddChildren(child, bone);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Refreshes the skeleton to update state of the HSDFile
        /// </summary>
        private void RefreshSkeleton()
        {
            Skeleton = new SBSkeleton();

            Dictionary <HSD_JOBJ, HSD_JOBJ>  childToParent = new Dictionary <HSD_JOBJ, HSD_JOBJ>();
            Dictionary <HSD_JOBJ, SBHsdBone> jobjToBone    = new Dictionary <HSD_JOBJ, SBHsdBone>();

            foreach (var jobj in RootJOBJ.BreathFirstList)
            {
                foreach (var c in jobj.Children)
                {
                    childToParent.Add(c, jobj);
                }

                SBHsdBone bone = new SBHsdBone();
                bone.Name = "JOBJ_" + Skeleton.Bones.Length;

                bone.Transform     = Matrix4.Identity;
                bone.Translation   = new Vector3(jobj.TX, jobj.TY, jobj.TZ);
                bone.RotationEuler = new Vector3(jobj.RX, jobj.RY, jobj.RZ);
                bone.Scale         = new Vector3(jobj.SX, jobj.SY, jobj.SZ);
                bone.SetJOBJ(jobj);

                jobjToBone.Add(jobj, bone);

                if (childToParent.ContainsKey(jobj))
                {
                    bone.Parent = jobjToBone[childToParent[jobj]];
                }
                else
                {
                    ((SBSkeleton)Skeleton).AddRoot(bone);
                }
            }

            //RecursivlyAddChildren(RootJOBJ, null);
        }
Ejemplo n.º 3
0
        private List <IOVertex> ConvertGXDLtoTriangleList(GXPrimitiveType type, List <SBHsdVertex> vertices, SBHsdBone parent)
        {
            var list = new List <IOVertex>();

            foreach (var v in vertices)
            {
                var vertex = new IOVertex()
                {
                    Position    = GXtoGL.GLVector3(v.POS),
                    Normal      = GXtoGL.GLVector3(v.NRM),
                    UV0         = GXtoGL.GLVector2(v.UV0),
                    BoneIndices = v.Bone,
                    BoneWeights = v.Weight,
                };
                if (parent != null)
                {
                    vertex.Position = Vector3.TransformPosition(vertex.Position, parent.WorldTransform);
                    vertex.Normal   = Vector3.TransformNormal(vertex.Normal, parent.WorldTransform);

                    if (vertex.BoneWeights.X == 0)
                    {
                        vertex.BoneWeights.X = 1;
                        vertex.BoneIndices.X = Skeleton.IndexOfBone(parent);
                    }
                }
                if (v.Weight.X == 1)
                {
                    vertex.Position = Vector3.TransformPosition(vertex.Position, Skeleton.Bones[(int)v.Bone.X].WorldTransform);
                    vertex.Normal   = Vector3.TransformNormal(vertex.Normal, Skeleton.Bones[(int)v.Bone.X].WorldTransform);
                }
                list.Add(vertex);
            }

            if (type == GXPrimitiveType.TriangleStrip)
            {
                TriangleConvert.StripToList(list, out list);
            }

            if (type == GXPrimitiveType.Quads)
            {
                TriangleConvert.QuadToList(list, out list);
            }

            return(list);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="vertices"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        private List <IOVertex> ConvertGXDLtoTriangleList(GXPrimitiveType type, List <SBHsdVertex> vertices, SBHsdBone parent)
        {
            var list = new List <IOVertex>();

            foreach (var v in vertices)
            {
                var vertex = new IOVertex()
                {
                    Position = new System.Numerics.Vector3(v.POS.X, v.POS.Y, v.POS.Z),
                    Normal   = new System.Numerics.Vector3(v.NRM.X, v.NRM.Y, v.NRM.Z),
                };
                vertex.SetUV(v.UV0.X, v.UV0.Y, 0);

                for (int i = 0; i < 4; i++)
                {
                    if (v.Weight[i] > 0)
                    {
                        vertex.Envelope.Weights.Add(new IOBoneWeight()
                        {
                            BoneName = "JOBJ_" + (int)v.Bone[i],
                            Weight   = v.Weight[i]
                        });
                    }
                }

                if (parent != null)
                {
                    vertex.Transform(TktoNumeric(parent.WorldTransform));

                    if (vertex.Envelope.Weights.Count == 0)
                    {
                        vertex.Envelope.Weights.Add(new IOBoneWeight()
                        {
                            BoneName = parent.Name,
                            Weight   = 1
                        });
                    }
                }
                if (v.Weight.X == 1)
                {
                    vertex.Transform(TktoNumeric(Skeleton.Bones[(int)v.Bone.X].WorldTransform));
                }
                list.Add(vertex);
            }

            if (type == GXPrimitiveType.TriangleStrip)
            {
                TriangleConvert.StripToList(list, out list);
            }

            if (type == GXPrimitiveType.Quads)
            {
                TriangleConvert.QuadToList(list, out list);
            }

            return(list);
        }