예제 #1
0
        public BinBVHAnimation()
        {
            rotationkeys = 0;
            positionkeys = 0;
            unknown0 = 1;
            unknown1 = 0;
            Priority = 1;
            Length = 0;
            ExpressionName = string.Empty;
            InPoint = 0;
            OutPoint = 0;
            Loop = false;
            EaseInTime = 0;
            EaseOutTime = 0;
            HandPose = 1;
            m_jointCount = 0;
            
            Joints = new binBVHJoint[1];
            Joints[0] = new binBVHJoint();
            Joints[0].Name = "mPelvis";
            Joints[0].Priority = 7;
            Joints[0].positionkeys = new binBVHJointKey[1];
            Joints[0].rotationkeys = new binBVHJointKey[1];
            Random rnd = new Random();

            Joints[0].rotationkeys[0] = new binBVHJointKey();
            Joints[0].rotationkeys[0].time = (0f);
            Joints[0].rotationkeys[0].key_element.X = ((float)rnd.NextDouble() * 2 - 1);
            Joints[0].rotationkeys[0].key_element.Y = ((float)rnd.NextDouble() * 2 - 1);
            Joints[0].rotationkeys[0].key_element.Z = ((float)rnd.NextDouble() * 2 - 1);

            Joints[0].positionkeys[0] = new binBVHJointKey();
            Joints[0].positionkeys[0].time = (0f);
            Joints[0].positionkeys[0].key_element.X = ((float)rnd.NextDouble() * 2 - 1);
            Joints[0].positionkeys[0].key_element.Y = ((float)rnd.NextDouble() * 2 - 1);
            Joints[0].positionkeys[0].key_element.Z = ((float)rnd.NextDouble() * 2 - 1);
            

        }
예제 #2
0
        /// <summary>
        /// Read in a Joint from an animation asset byte array
        /// Variable length Joint fields, yay!
        /// Advances the index
        /// </summary>
        /// <param name="data">animation asset byte array</param>
        /// <param name="i">Byte Offset of the start of the joint</param>
        /// <returns>The Joint data serialized into the binBVHJoint structure</returns>
        private binBVHJoint readJoint(byte[] data, ref int i)
        {
           
            binBVHJointKey[] positions;
            binBVHJointKey[] rotations;

            binBVHJoint pJoint = new binBVHJoint();

            /*
                109
                84
                111
                114
                114
                111
                0 <--- Null terminator
            */

            pJoint.Name = ReadBytesUntilNull(data, ref i); // Joint name

            /* 
                 2 <- Priority Revisited
                 0
                 0
                 0
            */

            /* 
                5 <-- 5 keyframes
                0
                0
                0
                ... 5 Keyframe data blocks
            */

            /* 
                2 <-- 2 keyframes
                0
                0
                0
                ..  2 Keyframe data blocks
            */
            if (!BitConverter.IsLittleEndian)
            {
                pJoint.Priority = Utils.BytesToInt(BinBVHUtil.EndianSwap(data, i, 4)); i += 4; // Joint Priority override?
                rotationkeys = Utils.BytesToInt(BinBVHUtil.EndianSwap(data, i, 4)); i += 4; // How many rotation keyframes
            }
            else
            {
                pJoint.Priority = Utils.BytesToInt(data, i); i += 4; // Joint Priority override?
                rotationkeys = Utils.BytesToInt(data, i); i += 4; // How many rotation keyframes
            }

            // argh! floats into two bytes!..   bad bad bad bad
            // After fighting with it for a while..  -1, to 1 seems to give the best results
            rotations = readKeys(data, ref i, rotationkeys, -1f, 1f);
            for (int iter = 0; iter < rotations.Length; iter++)
            {
                rotations[iter].W = 1f -
                    (rotations[iter].key_element.X + rotations[iter].key_element.Y +
                     rotations[iter].key_element.Z);
            }


            if (!BitConverter.IsLittleEndian)
            {
                positionkeys = Utils.BytesToInt(BinBVHUtil.EndianSwap(data, i, 4)); i += 4; // How many position keyframes
            }
            else
            {
                positionkeys = Utils.BytesToInt(data, i); i += 4; // How many position keyframes
            }

            // Read in position keyframes
            // argh! more floats into two bytes!..  *head desk*
            // After fighting with it for a while..  -5, to 5 seems to give the best results
            positions = readKeys(data, ref i, positionkeys, -5f, 5f);

            pJoint.rotationkeys = rotations;
            pJoint.positionkeys = positions;

            return pJoint;
        }
 public JointMoveSize(binBVHJoint bvhJoint)
 {
     joint   = bvhJoint;
     timeLen = ComputeTime(bvhJoint.rotationkeys) + ComputeTime(bvhJoint.positionkeys);
     posLen  = ComputeMotion(bvhJoint.rotationkeys) + ComputeMotion(bvhJoint.positionkeys);
 }