Example #1
0
        private void validateInput()
        {
            byte   unk6, anisotropy;
            ushort textureIndex, unkC;
            uint   flags, unk10;
            bool   unk6Valid, anisotropyValid, textureIndexValid, unkCValid, flagsValid, unk10Valid;

            flagsValid        = FlagHelper.parseHexToInt32(this.flagsTextBox.Text, out flags, "Flags is not a valid 4 byte hex value");
            textureIndexValid = FlagHelper.parseHexToShort(this.textureIndexTextBox.Text, out textureIndex, "Texture Index is not a valid 2 byte hex value");
            unk6Valid         = FlagHelper.parseHexToByte(this.unknown6TextBox.Text, out unk6, "Unknown 6 is not a valid 1 byte hex value");
            anisotropyValid   = FlagHelper.parseHexToByte(this.anistropyTextBox.Text, out anisotropy, "Anisotropy is not a valid 1 byte hex value");
            unkCValid         = FlagHelper.parseHexToShort(this.unknownCTextBox.Text, out unkC, "Unknown C is not a valid 2 byte hex value");
            unk10Valid        = FlagHelper.parseHexToInt32(this.unknown10TextBox.Text, out unk10, "Unknown 10 is not a valid 4 byte hex value");

            foreach (GcmfMaterial material in materials)
            {
                if (flagsValid)
                {
                    material.Flags = flags;
                }
                if (textureIndexValid)
                {
                    material.TextureIdx = textureIndex;
                }
                if (unk6Valid)
                {
                    material.Unk6 = unk6;
                }
                if (anisotropyValid)
                {
                    material.AnisotropyLevel = anisotropy;
                }
                if (unkCValid)
                {
                    material.UnkC = unkC;
                }
                if (unk10Valid)
                {
                    material.Unk10 = unk10;
                }
            }
        }
Example #2
0
        private void validateInput()
        {
            ushort unk10, unk14, unk16, unk18, unk1A;
            uint   renderFlags, unk4, unk8, unkC, unk40;
            uint   layer;
            bool   unk10Valid, unk14Valid, unk16Valid, unk18Valid, unk1AValid, renderFlagsValid, unk4Valid, unk8Valid, unkCValid, unk40Valid, layerValid;
            float  boundingSphereX, boundingSphereY, boundingSphereZ, unk3C, primaryXCoordScale, primaryYCoordScale, secondaryXCoordScale, secondaryYCoordScale;
            bool   boundingSphereXValid, boundingSphereYValid, boundingSphereZValid, unk3CValid, primXValid, primYValid, secXValid, secYValid;

            renderFlagsValid = FlagHelper.parseHexToInt32(this.renderFlagsTextBox.Text, out renderFlags, "Render Flags is not a valid 4 byte hex value");
            layerValid       = FlagHelper.parseHexToInt32(this.layerTextBox.Text, out layer, "Layer is not a valid 4 byte hex value");
            if (layer != 0 && layer != 1)
            {
                throw new InvalidOperationException("Layer is not 0 or 1");
            }
            unk4Valid  = FlagHelper.parseHexToInt32(this.unknown4TextBox.Text, out unk4, "Vertex Shading A 0x04 is not a valid 4 byte hex value");
            unk8Valid  = FlagHelper.parseHexToInt32(this.unknown8TextBox.Text, out unk8, "Vertex Shading B 0x08 is not a valid 4 byte hex value");
            unkCValid  = FlagHelper.parseHexToInt32(this.unknownCTextBox.Text, out unkC, "Specular Tint 0x0C is not a valid 4 byte hex value");
            unk10Valid = FlagHelper.parseHexToShort(this.unknown10TextBox.Text, out unk10, "Transparency 0x10 is not a valid 2 byte hex value");
            unk14Valid = FlagHelper.parseHexToShort(this.unknown14TextBox.Text, out unk14, "Unknown 0x14 is not a valid 2 byte hex value");
            unk16Valid = FlagHelper.parseHexToShort(this.unknown16TextBox.Text, out unk16, "Primary Material Index 0x16 is not a valid 2 byte hex value");
            unk18Valid = FlagHelper.parseHexToShort(this.unknown18TextBox.Text, out unk18, "Secondary Material Index 0x18 is not a valid 2 byte hex value");
            unk1AValid = FlagHelper.parseHexToShort(this.unknown1ATextBox.Text, out unk1A, "Tertiary Material Index 0x1A is not a valid 2 byte hex value");

            byte[] matrixSpecificIds      = new byte[8];
            bool[] matrixSpecificIdsValid = new bool[8];

            matrixSpecificIdsValid[0] = FlagHelper.parseByte(this.matrixId1TextBox.Text, out matrixSpecificIds[0], "Transformation Matrix Specific Id One is not a valid byte value (0-255)");
            matrixSpecificIdsValid[1] = FlagHelper.parseByte(this.matrixId2TextBox.Text, out matrixSpecificIds[1], "Transformation Matrix Specific Id Two is not a valid byte value (0-255)");
            matrixSpecificIdsValid[2] = FlagHelper.parseByte(this.matrixId3TextBox.Text, out matrixSpecificIds[2], "Transformation Matrix Specific Id Three is not a valid byte value (0-255)");
            matrixSpecificIdsValid[3] = FlagHelper.parseByte(this.matrixId4TextBox.Text, out matrixSpecificIds[3], "Transformation Matrix Specific Id Four is not a valid byte value (0-255)");
            matrixSpecificIdsValid[4] = FlagHelper.parseByte(this.matrixId5TextBox.Text, out matrixSpecificIds[4], "Transformation Matrix Specific Id Five is not a valid byte value (0-255)");
            matrixSpecificIdsValid[5] = FlagHelper.parseByte(this.matrixId6TextBox.Text, out matrixSpecificIds[5], "Transformation Matrix Specific Id Six is not a valid byte value (0-255)");
            matrixSpecificIdsValid[6] = FlagHelper.parseByte(this.matrixId7TextBox.Text, out matrixSpecificIds[6], "Transformation Matrix Specific Id Seven is not a valid byte value (0-255)");
            matrixSpecificIdsValid[7] = FlagHelper.parseByte(this.matrixId8TextBox.Text, out matrixSpecificIds[7], "Transformation Matrix Specific Id Eight is not a valid byte value (0-255)");

            boundingSphereXValid = FlagHelper.parseFloat(this.boundingSphereCenterXTextBox.Text, out boundingSphereX, "Bounding Sphere Center X is not a valid float value");
            boundingSphereYValid = FlagHelper.parseFloat(this.boundingSphereCenterYTextBox.Text, out boundingSphereY, "Bounding Sphere Center Y is not a valid float value");
            boundingSphereZValid = FlagHelper.parseFloat(this.boundingSphereCenterZTextBox.Text, out boundingSphereZ, "Bounding Sphere Center Z is not a valid float value");

            unk3CValid = FlagHelper.parseFloat(this.unknown3CTextBox.Text, out unk3C, "Unknown 0x3C is not a valid float value");
            unk40Valid = FlagHelper.parseHexToInt32(this.unknown40TextBox.Text, out unk40, "Unknown 0x40 is not a valid 4 byte hex value");
            primXValid = FlagHelper.parseFloat(this.primaryXCoordScale.Text, out primaryXCoordScale, "Primary X coordinate scale is not a valid float value");
            primYValid = FlagHelper.parseFloat(this.primaryYCoordScale.Text, out primaryYCoordScale, "Primary Y coordinate scale is not a valid float value");
            secXValid  = FlagHelper.parseFloat(this.secondaryXCoordScale.Text, out secondaryXCoordScale, "Secondary X coordinate scale is not a valid float value");
            secYValid  = FlagHelper.parseFloat(this.secondaryYCoordScale.Text, out secondaryYCoordScale, "Secondary Y coordinate scale is not a valid float value");

            foreach (GcmfMesh mesh in meshes)
            {
                if (renderFlagsValid)
                {
                    mesh.RenderFlags = (GcmfMesh.RenderFlag)renderFlags;
                }
                if (layerValid)
                {
                    mesh.Layer = (GcmfMesh.MeshLayer)layer;
                }
                if (unk4Valid)
                {
                    mesh.Unk4 = unk4;
                }
                if (unk8Valid)
                {
                    mesh.Unk8 = unk8;
                }
                if (unkCValid)
                {
                    mesh.UnkC = unkC;
                }
                if (unk10Valid)
                {
                    mesh.Unk10 = unk10;
                }
                if (unk14Valid)
                {
                    mesh.Unk14 = unk14;
                }
                if (unk16Valid)
                {
                    mesh.PrimaryMaterialIdx = unk16;
                }
                if (unk18Valid)
                {
                    mesh.SecondaryMaterialIdx = unk18;
                }
                if (unk1AValid)
                {
                    mesh.TertiaryMaterialIdx = unk1A;
                }
                mesh.calculatedUsedMaterialCount = Convert.ToByte(((unk16 != ushort.MaxValue) ? 1 : 0) +
                                                                  ((unk18 != ushort.MaxValue) ? 1 : 0) +
                                                                  ((unk1A != ushort.MaxValue) ? 1 : 0));

                for (int i = 0; i < matrixSpecificIds.Length; i++)
                {
                    if (matrixSpecificIdsValid[i])
                    {
                        mesh.TransformMatrixSpecificIdxsObj1[i] = matrixSpecificIds[i];
                    }
                }

                float bSphereX, bSphereY, bSphereZ;
                if (boundingSphereXValid)
                {
                    bSphereX = boundingSphereX;
                }
                else
                {
                    bSphereX = mesh.BoundingSphereCenter.X;
                }
                if (boundingSphereYValid)
                {
                    bSphereY = boundingSphereY;
                }
                else
                {
                    bSphereY = mesh.BoundingSphereCenter.Y;
                }
                if (boundingSphereZValid)
                {
                    bSphereZ = boundingSphereZ;
                }
                else
                {
                    bSphereZ = mesh.BoundingSphereCenter.Z;
                }
                mesh.BoundingSphereCenter = new OpenTK.Vector3(bSphereX, bSphereY, bSphereZ);

                if (unk3CValid)
                {
                    mesh.Unk3C = unk3C;
                }
                if (unk40Valid)
                {
                    mesh.Unk40 = unk40;
                }

                if ((primXValid) && (primYValid) && !(primaryXCoordScale == 1 && primaryYCoordScale == 1))
                {
                    OpenTK.Vector2 primaryScaleFactor = new OpenTK.Vector2(primaryXCoordScale, primaryYCoordScale);
                    foreach (GcmfTriangleStrip strip in mesh.Obj1StripsCcw)
                    {
                        foreach (GcmfVertex vert in strip)
                        {
                            vert.PrimaryTexCoord = OpenTK.Vector2.Divide((OpenTK.Vector2)vert.PrimaryTexCoord, primaryScaleFactor);
                        }
                    }

                    foreach (GcmfTriangleStrip strip in mesh.Obj1StripsCw)
                    {
                        foreach (GcmfVertex vert in strip)
                        {
                            vert.PrimaryTexCoord = OpenTK.Vector2.Divide((OpenTK.Vector2)vert.PrimaryTexCoord, primaryScaleFactor);
                        }
                    }
                }

                if ((secXValid) && (secYValid) && !(secondaryXCoordScale == 1 && secondaryYCoordScale == 1))
                {
                    try
                    {
                        OpenTK.Vector2 secondaryScaleFactor = new OpenTK.Vector2(secondaryXCoordScale, secondaryYCoordScale);
                        foreach (GcmfTriangleStrip strip in mesh.Obj1StripsCcw)
                        {
                            foreach (GcmfVertex vert in strip)
                            {
                                vert.SecondaryTexCoord = OpenTK.Vector2.Divide((OpenTK.Vector2)vert.SecondaryTexCoord, secondaryScaleFactor);
                            }
                        }

                        foreach (GcmfTriangleStrip strip in mesh.Obj1StripsCw)
                        {
                            foreach (GcmfVertex vert in strip)
                            {
                                vert.SecondaryTexCoord = OpenTK.Vector2.Divide((OpenTK.Vector2)vert.SecondaryTexCoord, secondaryScaleFactor);
                            }
                        }
                    }

                    catch (InvalidOperationException ex)
                    {
                        MessageBox.Show("This mesh does not have any secondary texture coordinates to scale. No scaling was applied.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }