private SSSkeletalMeshMD5[] readMeshes()
        {
            Match[] matches;
            seekEntry("MD5Version", "10");
            seekEntry("commandline", SSMD5Parser._quotedStrRegex);

            matches = seekEntry("numJoints", SSMD5Parser._uintRegex);
            var joints = new SSSkeletalJoint[Convert.ToUInt32(matches[1].Value)];

            matches = seekEntry("numMeshes", SSMD5Parser._uintRegex);
            var meshes = new SSSkeletalMeshMD5[Convert.ToUInt32(matches [1].Value)];

            seekEntry("joints", "{");
            for (int j = 0; j < joints.Length; ++j)
            {
                joints[j]             = readJoint();
                joints [j].jointIndex = j;
            }
            seekEntry("}");
            transformBindPoseToJointLocal(joints);

            for (int m = 0; m < meshes.Length; ++m)
            {
                seekEntry("mesh", "{");
                meshes [m]        = readMesh(joints);
                meshes [m].joints = joints;
                seekEntry("}");

                meshes [m].assetContext = Context;
            }
            return(meshes);
        }
        private SSSkeletalJoint readJoint()
        {
            Match[] matches = seekEntry(
                SSMD5Parser._quotedStrRegex,            // joint name
                SSMD5Parser._intRegex,                  // parent index
                SSMD5Parser._parOpen,
                SSMD5Parser._floatRegex,
                SSMD5Parser._floatRegex,
                SSMD5Parser._floatRegex,
                SSMD5Parser._parClose,                 // position
                SSMD5Parser._parOpen,
                SSMD5Parser._floatRegex,
                SSMD5Parser._floatRegex,
                SSMD5Parser._floatRegex,
                SSMD5Parser._parClose                  // orientation
                );
            SSSkeletalJoint ret = new SSSkeletalJoint();

            ret.name        = matches[0].Captures[0].Value;
            ret.parentIndex = Convert.ToInt32(matches[1].Value);

            ret.bindPoseLocation.position.X = (float)Convert.ToDouble(matches[3].Value);
            ret.bindPoseLocation.position.Y = (float)Convert.ToDouble(matches[4].Value);
            ret.bindPoseLocation.position.Z = (float)Convert.ToDouble(matches[5].Value);

            ret.bindPoseLocation.orientation.X = (float)Convert.ToDouble(matches[8].Value);
            ret.bindPoseLocation.orientation.Y = (float)Convert.ToDouble(matches[9].Value);
            ret.bindPoseLocation.orientation.Z = (float)Convert.ToDouble(matches[10].Value);
            ret.bindPoseLocation.computeQuatW();
            return(ret);
        }
Example #3
0
 public void verifyJoints(SSSkeletalJoint[] joints)
 {
     if (this.numJoints != joints.Length)
     {
         string str = string.Format(
             "Joint number mismatch: {0} in this hierarchy, {1} in other joints",
             this.numJoints, joints.Length);
         Console.WriteLine(str);
         throw new Exception(str);
     }
     for (int j = 0; j < numJoints; ++j)
     {
         SSSkeletalJoint thisJointInfo  = this._joints [j].baseInfo;
         SSSkeletalJoint otherJointInfo = joints [j];
         if (thisJointInfo.name != otherJointInfo.name)
         {
             string str = string.Format(
                 "Joint name mismatch: {0} in this hierarchy, {1} in other joints",
                 thisJointInfo.name, otherJointInfo.name);
             Console.WriteLine(str);
             throw new Exception(str);
         }
         if (thisJointInfo.parentIndex != otherJointInfo.parentIndex)
         {
             string str = string.Format(
                 "Hierarchy parent mismatch for joint \"{0}\": {1} in this hierarchy, {2} in other joints",
                 thisJointInfo.name, thisJointInfo.parentIndex, otherJointInfo.parentIndex);
             Console.WriteLine(str);
             throw new Exception(str);
         }
     }
 }
Example #4
0
        private SSSkeletalJoint readJoint()
        {
            Match[] matches = seekEntry (
                SSMD5Parser._quotedStrRegex, // joint name
                SSMD5Parser._intRegex,  // parent index
                SSMD5Parser._parOpen,
                    SSMD5Parser._floatRegex,
                    SSMD5Parser._floatRegex,
                    SSMD5Parser._floatRegex,
                SSMD5Parser._parClose, // position
                SSMD5Parser._parOpen,
                    SSMD5Parser._floatRegex,
                    SSMD5Parser._floatRegex,
                    SSMD5Parser._floatRegex,
                SSMD5Parser._parClose  // orientation
            );
            SSSkeletalJoint ret = new SSSkeletalJoint();
            ret.name = matches[0].Captures[0].Value;
            ret.parentIndex = Convert.ToInt32(matches[1].Value);

            ret.bindPoseLocation.position.X = (float)Convert.ToDouble(matches[3].Value);
            ret.bindPoseLocation.position.Y = (float)Convert.ToDouble(matches[4].Value);
            ret.bindPoseLocation.position.Z = (float)Convert.ToDouble(matches[5].Value);

            ret.bindPoseLocation.orientation.X = (float)Convert.ToDouble(matches[8].Value);
            ret.bindPoseLocation.orientation.Y = (float)Convert.ToDouble(matches[9].Value);
            ret.bindPoseLocation.orientation.Z = (float)Convert.ToDouble(matches[10].Value);
            ret.bindPoseLocation.computeQuatW();
            return ret;
        }
Example #5
0
 public void verifyAnimation(SSSkeletalAnimation animation)
 {
     if (this.numJoints != animation.numJoints)
     {
         string str = string.Format(
             "Joint number mismatch: {0} in md5mesh, {1} in md5anim",
             this.numJoints, animation.numJoints);
         Console.WriteLine(str);
         throw new Exception(str);
     }
     for (int j = 0; j < numJoints; ++j)
     {
         SSSkeletalJoint thisJointInfo = this._joints [j].baseInfo;
         SSSkeletalJoint animJointInfo = animation.jointHierarchy [j];
         if (thisJointInfo.name != animJointInfo.name)
         {
             string str = string.Format(
                 "Joint name mismatch: {0} in md5mesh, {1} in md5anim",
                 thisJointInfo.name, animJointInfo.name);
             Console.WriteLine(str);
             throw new Exception(str);
         }
         if (thisJointInfo.parentIndex != animJointInfo.parentIndex)
         {
             string str = string.Format(
                 "Hierarchy parent mismatch for joint \"{0}\": {1} in md5mesh, {2} in md5anim",
                 thisJointInfo.name, thisJointInfo.parentIndex, animJointInfo.parentIndex);
             Console.WriteLine(str);
             throw new Exception(str);
         }
     }
 }
Example #6
0
 /// <summary>
 /// Transform bind pose coordinates from mesh global form into joint-local form
 /// </summary>
 private static void transformBindPoseToJointLocal(SSSkeletalJoint[] joints)
 {
     for (int j = joints.Length-1; j > 0; --j) {
         var joint = joints [j];
         var parLoc = joints [joint.parentIndex].bindPoseLocation;
         joint.bindPoseLocation.undoPrecedingTransform (parLoc);
     }
 }
        public SSSkeletalAnimation(int frameRate,
									SSSkeletalJoint[] jointInfo,
									SSSkeletalJointLocation[][] frames,
									SSAABB[] bounds = null)
        {
            _hierarchy = jointInfo;
            _frames = frames;
            _bounds = bounds;
            _frameRate = frameRate;
        }
Example #8
0
        private SSSkeletalAnimationMD5 readAnimation()
        {
            Match[] matches;

            // header
            seekEntry ("MD5Version", "10");
            seekEntry ("commandline", SSMD5Parser._quotedStrRegex);

            matches = seekEntry ("numFrames", SSMD5Parser._uintRegex);
            var numFrames = Convert.ToInt32 (matches [1].Value);

            matches = seekEntry ("numJoints", SSMD5Parser._uintRegex);
            var numJoints = Convert.ToInt32 (matches [1].Value);

            matches = seekEntry ("frameRate", SSMD5Parser._uintRegex);
            var frameRate = Convert.ToInt32 (matches [1].Value);

            matches = seekEntry ("numAnimatedComponents", SSMD5Parser._uintRegex);
            int numAnimatedComponents = Convert.ToInt32 (matches [1].Value);
            var floatComponents = new float[numAnimatedComponents];

            // hierarchy
            seekEntry ("hierarchy", "{");
            var hierarchy = new SSSkeletalJoint[numJoints];
            var flags = new byte[numJoints];
            for (int j = 0; j < numJoints; ++j) {
                hierarchy [j] = readHierarchyEntry (out flags [j]);
            }
            seekEntry ("}");

            // bounds
            seekEntry ("bounds", "{");
            var bounds = new SSAABB[numFrames];
            for (int f = 0; f < numFrames; ++f) {
                bounds [f] = readBounds ();
            }
            seekEntry ("}");

            // base frame
            seekEntry ("baseframe", "{");
            for (int j = 0; j < numJoints; ++j) {
                hierarchy[j].bindPoseLocation = readBaseFrame ();
            }
            seekEntry ("}");

            // frames
            var frames = new SSSkeletalJointLocation[numFrames][];
            for (int f = 0; f < numFrames; ++f) {
                matches = seekEntry ("frame", SSMD5Parser._uintRegex, "{");
                int frameIdx = Convert.ToInt32 (matches [1].Value);
                frames [frameIdx] = readFrameJoints (flags, hierarchy, floatComponents);
                seekEntry ("}");
            }
            return new SSSkeletalAnimationMD5 (frameRate, hierarchy, frames, bounds);
        }
Example #9
0
        private SSSkeletalJointLocation[] readFrameJoints(byte[] jointFlags,
                                                          SSSkeletalJoint[] jointInfos,
                                                          float[] floatComponents)
        {
            seekFloats(floatComponents);
            var thisFrameLocations = new SSSkeletalJointLocation[jointInfos.Length];
            int compIdx            = 0;

            for (int j = 0; j < jointInfos.Length; ++j)
            {
                byte                    flags     = jointFlags[j];
                SSSkeletalJoint         jointInfo = jointInfos [j];
                SSSkeletalJointLocation loc       = jointInfo.bindPoseLocation;
                if ((flags & (byte)LocationFlags.Tx) != 0)
                {
                    loc.position.X = floatComponents [compIdx++];
                }
                if ((flags & (byte)LocationFlags.Ty) != 0)
                {
                    loc.position.Y = floatComponents [compIdx++];
                }
                if ((flags & (byte)LocationFlags.Tz) != 0)
                {
                    loc.position.Z = floatComponents [compIdx++];
                }
                if ((flags & (byte)LocationFlags.Qx) != 0)
                {
                    loc.orientation.X = floatComponents [compIdx++];
                }
                if ((flags & (byte)LocationFlags.Qy) != 0)
                {
                    loc.orientation.Y = floatComponents [compIdx++];
                }
                if ((flags & (byte)LocationFlags.Qz) != 0)
                {
                    loc.orientation.Z = floatComponents [compIdx++];
                }
                loc.computeQuatW();

                                #if false
                if (jointInfo.ParentIndex >= 0)                   // has a parent
                {
                    SSSkeletalJointLocation parentLoc = thisFrameLocations [jointInfo.ParentIndex];
                    loc.Position = parentLoc.Position
                                   + Vector3.Transform(loc.Position, parentLoc.Orientation);
                    loc.Orientation = Quaternion.Multiply(parentLoc.Orientation,
                                                          loc.Orientation);
                    loc.Orientation.Normalize();
                }
                                #endif
                thisFrameLocations[j] = loc;
            }
            return(thisFrameLocations);
        }
 public SSSkeletalHierarchyRuntime(SSSkeletalJoint[] joints)
 {
     _joints = new SSSkeletalJointRuntime[joints.Length];
     for (int j = 0; j < joints.Length; ++j) {
         var jointInput = joints [j];
         _joints [j] = new SSSkeletalJointRuntime(jointInput);
         int parentIdx = jointInput.parentIndex;
         if (parentIdx < 0) {
             _topLevelJoints.Add (j);
         } else {
             _joints [j].parent = _joints [parentIdx];
             _joints [parentIdx].children.Add (_joints[j]);
         }
     }
 }
Example #11
0
        private SSSkeletalJoint readHierarchyEntry(out byte flags)
        {
            Match[] matches = seekEntry(
                SSMD5Parser._quotedStrRegex,           // name
                SSMD5Parser._intRegex,                 // parent index
                SSMD5Parser._uintRegex,                // flags
                SSMD5Parser._uintRegex                 // start index (currently not used)
                );
            SSSkeletalJoint ret = new SSSkeletalJoint();

            ret.name        = matches[0].Value;
            ret.parentIndex = Convert.ToInt32(matches[1].Value);
            flags           = Convert.ToByte(matches[2].Value);
            //m_startIndex = Convert.ToInt32(matches[3].Value);
            return(ret);
        }
Example #12
0
        private SSSkeletalMeshMD5 readMesh(SSSkeletalJoint[] joints)
        {
            SSSkeletalMeshMD5 newMesh = new SSSkeletalMeshMD5 ();

            Match[] matches;
            matches = seekEntry("shader", SSMD5Parser._quotedStrRegex);
            newMesh.materialShaderString = matches[1].Value;

            matches = seekEntry ("numverts", SSMD5Parser._uintRegex);
            int numVertices = Convert.ToInt32 (matches [1].Value);
            newMesh.vertices = new SSSkeletalVertex[numVertices];

            for (int v = 0; v < numVertices; ++v) {
                int vertexIndex;
                var vertex = readVertex (out vertexIndex);
                newMesh.vertices [vertexIndex] = vertex;
            }

            matches = seekEntry ("numtris", SSMD5Parser._uintRegex);
            int numTris = Convert.ToUInt16 (matches [1].Value);
            newMesh.triangleIndices = new UInt16[numTris * 3];
            for (int t = 0; t < numTris; ++t) {
                readTriangle (newMesh.triangleIndices);
            }

            matches = seekEntry ("numweights", SSMD5Parser._uintRegex);
            int numWeights = Convert.ToInt32 (matches [1].Value);
            newMesh.weights = new SSSkeletalWeight[numWeights];
            for (int w = 0; w < numWeights; ++w) {
                int weightIdx;
                SSSkeletalWeight weight = readWeight(out weightIdx);
                newMesh.weights [weightIdx] = weight;
            }

            return newMesh;
        }
Example #13
0
        public SSSkeletalAnimationMD5(int frameRate,
									   SSSkeletalJoint[] jointInfo,
									   SSSkeletalJointLocation[][] frames,
									   SSAABB[] bounds)
            : base(frameRate, jointInfo, frames, bounds)
        {
        }
Example #14
0
 private SSSkeletalJoint readHierarchyEntry(out byte flags)
 {
     Match[] matches = seekEntry(
         SSMD5Parser._quotedStrRegex, // name
         SSMD5Parser._intRegex, // parent index
         SSMD5Parser._uintRegex, // flags
         SSMD5Parser._uintRegex // start index (currently not used)
     );
     SSSkeletalJoint ret = new SSSkeletalJoint();
     ret.name = matches[0].Value;
     ret.parentIndex = Convert.ToInt32(matches[1].Value);
     flags = Convert.ToByte(matches[2].Value);
     //m_startIndex = Convert.ToInt32(matches[3].Value);
     return ret;
 }
Example #15
0
        private SSSkeletalJointLocation[] readFrameJoints(byte[] jointFlags,
														  SSSkeletalJoint[] jointInfos,
														  float[] floatComponents)
        {
            seekFloats (floatComponents);
            var thisFrameLocations = new SSSkeletalJointLocation[jointInfos.Length];
            int compIdx = 0;
            for (int j = 0; j < jointInfos.Length; ++j) {
                byte flags = jointFlags[j];
                SSSkeletalJoint jointInfo = jointInfos [j];
                SSSkeletalJointLocation loc = jointInfo.bindPoseLocation;
                if ((flags & (byte)LocationFlags.Tx) != 0) {
                    loc.position.X = floatComponents [compIdx++];
                }
                if ((flags & (byte)LocationFlags.Ty) != 0) {
                    loc.position.Y = floatComponents [compIdx++];
                }
                if ((flags & (byte)LocationFlags.Tz) != 0) {
                    loc.position.Z = floatComponents [compIdx++];
                }
                if ((flags & (byte)LocationFlags.Qx) != 0) {
                    loc.orientation.X = floatComponents [compIdx++];
                }
                if ((flags & (byte)LocationFlags.Qy) != 0) {
                    loc.orientation.Y = floatComponents [compIdx++];
                }
                if ((flags & (byte)LocationFlags.Qz) != 0) {
                    loc.orientation.Z = floatComponents [compIdx++];
                }
                loc.computeQuatW ();

                #if false
                if (jointInfo.ParentIndex >= 0) { // has a parent
                    SSSkeletalJointLocation parentLoc = thisFrameLocations [jointInfo.ParentIndex];
                    loc.Position = parentLoc.Position
                        + Vector3.Transform (loc.Position, parentLoc.Orientation);
                    loc.Orientation = Quaternion.Multiply (parentLoc.Orientation,
                        loc.Orientation);
                    loc.Orientation.Normalize ();
                }
                #endif
                thisFrameLocations[j] = loc;
            }
            return thisFrameLocations;
        }
 public SSSkeletalJointRuntime(SSSkeletalJoint baseInfo)
 {
     _baseInfo = baseInfo;
     currentLocation = _baseInfo.bindPoseLocation;
 }
 public void verifyJoints(SSSkeletalJoint[] joints)
 {
     if (this.numJoints != joints.Length) {
         string str = string.Format (
             "Joint number mismatch: {0} in this hierarchy, {1} in other joints",
             this.numJoints, joints.Length);
         Console.WriteLine (str);
         throw new Exception (str);
     }
     for (int j = 0; j < numJoints; ++j) {
         SSSkeletalJoint thisJointInfo = this._joints [j].baseInfo;
         SSSkeletalJoint otherJointInfo = joints [j];
         if (thisJointInfo.name != otherJointInfo.name) {
             string str = string.Format (
                 "Joint name mismatch: {0} in this hierarchy, {1} in other joints",
                 thisJointInfo.name, otherJointInfo.name);
             Console.WriteLine (str);
             throw new Exception (str);
         }
         if (thisJointInfo.parentIndex != otherJointInfo.parentIndex) {
             string str = string.Format (
                 "Hierarchy parent mismatch for joint \"{0}\": {1} in this hierarchy, {2} in other joints",
                 thisJointInfo.name, thisJointInfo.parentIndex, otherJointInfo.parentIndex);
             Console.WriteLine (str);
             throw new Exception (str);
         }
     }
 }
Example #18
0
 public SSSkeletalJointRuntime(SSSkeletalJoint baseInfo)
 {
     _baseInfo       = baseInfo;
     currentLocation = _baseInfo.bindPoseLocation;
 }
Example #19
0
        private SSSkeletalAnimationMD5 readAnimation()
        {
            Match[] matches;

            // header
            seekEntry("MD5Version", "10");
            seekEntry("commandline", SSMD5Parser._quotedStrRegex);

            matches = seekEntry("numFrames", SSMD5Parser._uintRegex);
            var numFrames = Convert.ToInt32(matches [1].Value);

            matches = seekEntry("numJoints", SSMD5Parser._uintRegex);
            var numJoints = Convert.ToInt32(matches [1].Value);

            matches = seekEntry("frameRate", SSMD5Parser._uintRegex);
            var frameRate = Convert.ToInt32(matches [1].Value);

            matches = seekEntry("numAnimatedComponents", SSMD5Parser._uintRegex);
            int numAnimatedComponents = Convert.ToInt32(matches [1].Value);
            var floatComponents       = new float[numAnimatedComponents];

            // hierarchy
            seekEntry("hierarchy", "{");
            var hierarchy = new SSSkeletalJoint[numJoints];
            var flags     = new byte[numJoints];

            for (int j = 0; j < numJoints; ++j)
            {
                hierarchy [j] = readHierarchyEntry(out flags [j]);
            }
            seekEntry("}");

            // bounds
            seekEntry("bounds", "{");
            var bounds = new SSAABB[numFrames];

            for (int f = 0; f < numFrames; ++f)
            {
                bounds [f] = readBounds();
            }
            seekEntry("}");

            // base frame
            seekEntry("baseframe", "{");
            for (int j = 0; j < numJoints; ++j)
            {
                hierarchy[j].bindPoseLocation = readBaseFrame();
            }
            seekEntry("}");

            // frames
            var frames = new SSSkeletalJointLocation[numFrames][];

            for (int f = 0; f < numFrames; ++f)
            {
                matches = seekEntry("frame", SSMD5Parser._uintRegex, "{");
                int frameIdx = Convert.ToInt32(matches [1].Value);
                frames [frameIdx] = readFrameJoints(flags, hierarchy, floatComponents);
                seekEntry("}");
            }
            return(new SSSkeletalAnimationMD5(frameRate, hierarchy, frames, bounds));
        }
Example #20
0
        private SSSkeletalMeshMD5[] readMeshes()
        {
            Match[] matches;
            seekEntry ("MD5Version", "10");
            seekEntry ("commandline", SSMD5Parser._quotedStrRegex);

            matches = seekEntry ("numJoints", SSMD5Parser._uintRegex);
            var joints = new SSSkeletalJoint[Convert.ToUInt32(matches[1].Value)];

            matches = seekEntry ( "numMeshes", SSMD5Parser._uintRegex);
            var meshes = new SSSkeletalMeshMD5[Convert.ToUInt32 (matches [1].Value)];

            seekEntry ("joints", "{");
            for (int j = 0; j < joints.Length; ++j) {
                joints[j] = readJoint();
                joints [j].jointIndex = j;
            }
            seekEntry ("}");
            transformBindPoseToJointLocal (joints);

            for (int m = 0; m < meshes.Length; ++m) {
                seekEntry ("mesh", "{");
                meshes [m] = readMesh (joints);
                meshes [m].joints = joints;
                seekEntry ("}");

                meshes [m].assetContext = Context;
            }
            return meshes;
        }