Ejemplo n.º 1
0
 private static void AddOneScaleFrame(bool useScaleFrames, AquaMotion.KeyData node, Assimp.Node aiNode = null)
 {
     if (useScaleFrames)
     {
         AquaMotion.MKEY sclKeys = new AquaMotion.MKEY();
         sclKeys.keyType  = 3;
         sclKeys.dataType = 1;
         sclKeys.keyCount = 1;
         if (aiNode == null)
         {
             sclKeys.vector4Keys = new List <Vector4>()
             {
                 new Vector4(1.0f, 1.0f, 1.0f, 0)
             };
         }
         else
         {
             Matrix4x4.Invert(GetMat4FromAssimpMat4(aiNode.Transform), out Matrix4x4 mat4);
             sclKeys.vector4Keys = new List <Vector4>()
             {
                 new Vector4(mat4.M11, mat4.M22, mat4.M33, 0)
             };
         }
         node.keyData.Add(sclKeys);
     }
 }
Ejemplo n.º 2
0
        private static void AddOnePosFrame(AquaMotion.KeyData node, Assimp.Node aiNode, float baseScale)
        {
            AquaMotion.MKEY posKeys = new AquaMotion.MKEY();
            posKeys.keyType  = 1;
            posKeys.dataType = 1;
            posKeys.keyCount = 1;
            var mat4 = GetMat4FromAssimpMat4(aiNode.Transform);

            posKeys.vector4Keys = new List <Vector4>()
            {
                new Vector4(mat4.M14 * baseScale, mat4.M24 * baseScale, mat4.M34 * baseScale, 0)
            };
            node.keyData.Add(posKeys);
        }
Ejemplo n.º 3
0
        private static void AddOneRotFrame(AquaMotion.KeyData node, Assimp.Node aiNode)
        {
            AquaMotion.MKEY rotKeys = new AquaMotion.MKEY();
            rotKeys.keyType  = 2;
            rotKeys.dataType = 3;
            rotKeys.keyCount = 1;
            Matrix4x4.Invert(GetMat4FromAssimpMat4(aiNode.Transform), out Matrix4x4 mat4);
            var quat = Quaternion.CreateFromRotationMatrix(mat4);

            rotKeys.vector4Keys = new List <Vector4>()
            {
                new Vector4(quat.X, quat.Y, quat.Z, quat.W)
            };
            node.keyData.Add(rotKeys);
        }
        public void UpdateToNGSPlayerMotion(AquaMotion motion)
        {
            //Add the nodeTreeFlag if it's there
            AquaMotion.KeyData nodeTree = null;
            if (motion.motionKeys[motion.motionKeys.Count - 1].mseg.nodeName.GetString().Contains("NodeTreeFlag"))
            {
                nodeTree = motion.motionKeys[motion.motionKeys.Count - 1];
            }

            //Remove to the old count
            while (motion.motionKeys.Count > oldRange)
            {
                motion.motionKeys.RemoveAt(motion.motionKeys.Count - 1);
            }

            //Go through and add NGS nodes
            for (int i = oldRange; i < endRange + 1; i++)
            {
                var keySet = new AquaMotion.KeyData();
                keySet.mseg.nodeDataCount = 3;
                keySet.mseg.nodeId        = i;
                keySet.mseg.nodeType      = 2;
                keySet.mseg.nodeName      = AquaCommon.PSO2String.GeneratePSO2String(nodeNames[i]);

                var pos   = new AquaMotion.MKEY();
                var rot   = new AquaMotion.MKEY();
                var scale = new AquaMotion.MKEY();

                //If the key isn't in there, set to the default. Else set based on the old id
                if (!remapDict.ContainsKey(i))
                {
                    // position
                    pos.dataType = 1;
                    pos.keyCount = 1;
                    pos.keyType  = 1;
                    pos.vector4Keys.Add(defaultPos[i]);

                    // rotation
                    rot.dataType = 3;
                    rot.keyCount = 1;
                    rot.keyType  = 2;
                    rot.vector4Keys.Add(new Vector4(defaultRots[i].X, defaultRots[i].Y, defaultRots[i].Z, defaultRots[i].W));

                    // scale
                    scale.dataType = 1;
                    scale.keyCount = 1;
                    scale.keyType  = 3;
                    scale.vector4Keys.Add(new Vector4(1.0f, 1.0f, 1.0f, 0));
                }
                else
                {
                    for (int keyData = 0; keyData < motion.motionKeys[remapDict[i]].keyData.Count; keyData++)
                    {
                        switch (motion.motionKeys[remapDict[i]].keyData[keyData].keyType)
                        {
                        case 1:
                            pos = motion.motionKeys[remapDict[i]].keyData[keyData];
                            if (motion.motionKeys[remapDict[i]].keyData[keyData].vector4Keys.Count > 1)
                            {
                                for (int frameId = 0; frameId < motion.motionKeys[remapDict[i]].keyData[keyData].vector4Keys.Count; frameId++)
                                {
                                    var frame = motion.motionKeys[remapDict[i]].keyData[keyData].vector4Keys[frameId];
                                    frame = frame - defaultPos[remapDict[i]];
                                    motion.motionKeys[remapDict[i]].keyData[keyData].vector4Keys[frameId] = frame + defaultPos[i];
                                }
                            }
                            break;

                        case 2:
                            rot = motion.motionKeys[remapDict[i]].keyData[keyData];

                            //Extract and apply rotation for every frame
                            for (int frameId = 0; frameId < motion.motionKeys[remapDict[i]].keyData[keyData].vector4Keys.Count; frameId++)
                            {
                                var frame = motion.motionKeys[remapDict[i]].keyData[keyData].vector4Keys[frameId];
                                var quat  = new Quaternion(frame.X, frame.Y, frame.Z, frame.W);
                                quat = quat * Quaternion.Inverse(defaultRots[remapDict[i]]);
                                quat = quat * defaultRots[i];

                                motion.motionKeys[remapDict[i]].keyData[keyData].vector4Keys[frameId] = new Vector4(quat.X, quat.Y, quat.Z, quat.W);
                            }
                            break;

                        case 3:
                            scale = motion.motionKeys[remapDict[i]].keyData[keyData];
                            break;
                        }
                    }

                    //Check if anything was left out and set to defaults if so
                    if (pos.keyType == 0)
                    {
                        pos.dataType = 1;
                        pos.keyCount = 1;
                        pos.keyType  = 1;
                        pos.vector4Keys.Add(defaultPos[i]);
                    }
                    if (rot.keyType == 0)
                    {
                        rot.dataType = 3;
                        rot.keyCount = 1;
                        rot.keyType  = 2;
                        rot.vector4Keys.Add(new Vector4(defaultRots[i].X, defaultRots[i].Y, defaultRots[i].Z, defaultRots[i].W));
                    }
                    if (scale.keyType == 0)
                    {
                        scale.dataType = 1;
                        scale.keyCount = 1;
                        scale.keyType  = 3;
                        scale.vector4Keys.Add(new Vector4(1.0f, 1.0f, 1.0f, 0));
                    }
                }

                keySet.keyData.Add(pos);
                keySet.keyData.Add(rot);
                keySet.keyData.Add(scale);

                motion.motionKeys.Add(keySet);
            }

            if (nodeTree != null)
            {
                motion.motionKeys.Add(nodeTree);
            }
            else
            {
                //Generate NodeTreeFlag
                nodeTree = new AquaMotion.KeyData();
                nodeTree.mseg.nodeDataCount = 3;
                nodeTree.mseg.nodeId        = 0;
                nodeTree.mseg.nodeType      = 16;
                nodeTree.mseg.nodeName      = AquaCommon.PSO2String.GeneratePSO2String("__NodeTreeFlag__");

                for (int set = 0; set < 3; set++)
                {
                    var mkey = new AquaMotion.MKEY();
                    mkey.dataType = 5;
                    mkey.keyCount = motion.moHeader.endFrame + 1;
                    mkey.keyType  = 16 + set;
                    for (int key = 0; key < mkey.keyCount; key++)
                    {
                        if (key == 0)
                        {
                            mkey.frameTimings.Add(0x9);
                        }
                        else if (key == mkey.keyCount - 1)
                        {
                            mkey.frameTimings.Add((ushort)((key * 0x10) + 0xA));
                        }
                        else
                        {
                            mkey.frameTimings.Add((ushort)((key * 0x10) + 0x8));
                        }
                        mkey.intKeys.Add(0x31);
                    }
                    nodeTree.keyData.Add(mkey);
                }
            }
            motion.moHeader.nodeCount = motion.motionKeys.Count;
        }