Exemplo n.º 1
0
        /// <summary>
        /// Build immutable parts from a submodel.
        /// </summary>
        /// <param name="submodel"></param>
        public Kkdf2MdlxParser(Mdlx.SubModel submodel)
        {
            immultableMeshList = submodel.DmaChains
                                 .Select(x => new ImmutableMesh(x))
                                 .ToList();

            immutableExportedMesh = PreProcessVerticesAndBuildModel();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Build intial T-pose matrices.
        /// </summary>
        public static Matrix[] BuildTPoseMatrices(Mdlx.SubModel model, Matrix initialMatrix)
        {
            var boneList = model.Bones.ToArray();
            var matrices = new Matrix[boneList.Length];

            {
                var absTranslationList = new Vector3[matrices.Length];
                var absRotationList    = new Quaternion[matrices.Length];
                for (int x = 0; x < matrices.Length; x++)
                {
                    Quaternion absRotation;
                    Vector3    absTranslation;
                    var        oneBone = boneList[x];
                    var        parent  = oneBone.Parent;
                    if (parent < 0)
                    {
                        absRotation    = Quaternion.Identity;
                        absTranslation = Vector3.Zero;
                    }
                    else
                    {
                        absRotation    = absRotationList[parent];
                        absTranslation = absTranslationList[parent];
                    }

                    var localTranslation = Vector3.TransformCoordinate(new Vector3(oneBone.TranslationX, oneBone.TranslationY, oneBone.TranslationZ), Matrix.RotationQuaternion(absRotation));
                    absTranslationList[x] = absTranslation + localTranslation;

                    var localRotation = Quaternion.Identity;
                    if (oneBone.RotationX != 0)
                    {
                        localRotation *= (Quaternion.RotationAxis(new Vector3(1, 0, 0), oneBone.RotationX));
                    }
                    if (oneBone.RotationY != 0)
                    {
                        localRotation *= (Quaternion.RotationAxis(new Vector3(0, 1, 0), oneBone.RotationY));
                    }
                    if (oneBone.RotationZ != 0)
                    {
                        localRotation *= (Quaternion.RotationAxis(new Vector3(0, 0, 1), oneBone.RotationZ));
                    }
                    absRotationList[x] = localRotation * absRotation;
                }
                for (int x = 0; x < matrices.Length; x++)
                {
                    var absMatrix = initialMatrix;
                    absMatrix  *= Matrix.RotationQuaternion(absRotationList[x]);
                    absMatrix  *= Matrix.Translation(absTranslationList[x]);
                    matrices[x] = absMatrix;
                }
            }

            return(matrices);
        }
Exemplo n.º 3
0
        private static Matrix4x4[] BuildTPoseMatrices(Mdlx.SubModel model, Matrix4x4 initialMatrix)
        {
            var boneList = model.Bones.ToArray();
            var matrices = new Matrix4x4[boneList.Length];

            {
                var absTranslationList = new Vector3[matrices.Length];
                var absRotationList    = new Quaternion[matrices.Length];
                for (int x = 0; x < matrices.Length; x++)
                {
                    Quaternion absRotation;
                    Vector3    absTranslation;
                    var        oneBone = boneList[x];
                    var        parent  = oneBone.Parent;
                    if (parent < 0)
                    {
                        absRotation    = Quaternion.Identity;
                        absTranslation = Vector3.Zero;
                    }
                    else
                    {
                        absRotation    = absRotationList[parent];
                        absTranslation = absTranslationList[parent];
                    }

                    var localTranslation = Vector3.Transform(new Vector3(oneBone.TranslationX, oneBone.TranslationY, oneBone.TranslationZ), Matrix4x4.CreateFromQuaternion(absRotation));
                    absTranslationList[x] = absTranslation + localTranslation;

                    var localRotation = Quaternion.Identity;
                    if (oneBone.RotationZ != 0)
                    {
                        localRotation *= (Quaternion.CreateFromAxisAngle(Vector3.UnitZ, oneBone.RotationZ));
                    }
                    if (oneBone.RotationY != 0)
                    {
                        localRotation *= (Quaternion.CreateFromAxisAngle(Vector3.UnitY, oneBone.RotationY));
                    }
                    if (oneBone.RotationX != 0)
                    {
                        localRotation *= (Quaternion.CreateFromAxisAngle(Vector3.UnitX, oneBone.RotationX));
                    }
                    absRotationList[x] = absRotation * localRotation;
                }
                for (int x = 0; x < matrices.Length; x++)
                {
                    var absMatrix = initialMatrix;
                    absMatrix  *= Matrix4x4.CreateFromQuaternion(absRotationList[x]);
                    absMatrix  *= Matrix4x4.CreateTranslation(absTranslationList[x]);
                    matrices[x] = absMatrix;
                }
            }

            return(matrices);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Build immutable parts from a submodel.
        /// </summary>
        /// <param name="submodel"></param>
        public Kkdf2MdlxParser(Mdlx.SubModel submodel)
        {
            immultableMeshList = new List <ImmutableMesh>();
            foreach (Mdlx.DmaVif dmaVif in submodel.DmaChains.SelectMany(dmaChain => dmaChain.DmaVifs))
            {
                const int tops = 0x40, top2 = 0x220;

                var unpacker = new VifUnpacker(dmaVif.VifPacket)
                {
                    Vif1_Tops = tops
                };
                unpacker.Run();

                var mesh = VU1Simulation.Run(unpacker.Memory, tops, top2, dmaVif.TextureIndex, dmaVif.Alaxi);
                immultableMeshList.Add(mesh);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Build immutable parts from a submodel.
        /// </summary>
        /// <param name="submodel"></param>
        public Kkdf2MdlxParser(Mdlx.SubModel submodel)
        {
            immultableMeshList = new List <ImmutableMesh>();
            foreach (Mdlx.DmaChain dmaChain in submodel.DmaChains)
            {
                foreach (Mdlx.DmaVif dmaVif in dmaChain.DmaVifs)
                {
                    const int tops = 0x40;

                    var unpacker = new VifUnpacker(dmaVif.VifPacket)
                    {
                        Vif1_Tops = tops
                    };
                    unpacker.Run();

                    var mesh = VU1Simulation.Run(unpacker.Memory, tops, dmaVif.TextureIndex, dmaVif.Alaxi);
                    mesh.isOpaque = (dmaChain.Unk00 & 1) == 0;
                    immultableMeshList.Add(mesh);
                }
            }
        }
Exemplo n.º 6
0
 public SubModel_Control(Mdlx.SubModel subModel)
 {
     InitializeComponent();
     DataContext = subModel;
 }
Exemplo n.º 7
0
 public SubModel_VM(Mdlx.SubModel subModel)
 {
     this.subModel = subModel;
 }