Example #1
0
        public static void SaveModel(ICLIFlags flags, string path, FindLogic.Combo.ComboInfo info, ulong modelGUID)
        {
            bool convertModels = true;
            bool doRefpose     = false;
            byte lod           = 1;

            if (flags is ExtractFlags extractFlags)
            {
                convertModels = extractFlags.ConvertModels && !extractFlags.Raw;
                doRefpose     = extractFlags.ExtractRefpose;
                lod           = extractFlags.LOD;
                if (extractFlags.SkipModels)
                {
                    return;
                }
            }

            FindLogic.Combo.ModelInfoNew modelInfo = info.Models[modelGUID];
            string modelDirectory = Path.Combine(path, "Models", modelInfo.GetName());

            if (convertModels)
            {
                string modelPath = Path.Combine(modelDirectory, $"{modelInfo.GetNameIndex()}.owmdl");
                CreateDirectoryFromFile(modelPath);

                using (Stream modelStream = OpenFile(modelInfo.GUID)) {
                    teChunkedData chunkedData = new teChunkedData(modelStream);

                    OverwatchModel model = new OverwatchModel(chunkedData, modelInfo.GUID, (sbyte)lod);
                    if (modelInfo.ModelLooks.Count > 0)
                    {
                        FindLogic.Combo.ModelLookInfo modelLookInfo = info.ModelLooks[modelInfo.ModelLooks.First()];
                        model.ModelLookFileName = Path.Combine("ModelLooks",
                                                               modelLookInfo.GetNameIndex() + ".owmat");
                    }
                    using (Stream fileStream = File.OpenWrite(modelPath)) {
                        fileStream.SetLength(0);
                        model.Write(fileStream);
                    }

                    if (doRefpose)
                    {
                        string refposePath = Path.Combine(modelDirectory, modelInfo.GetNameIndex() + ".smd");

                        using (Stream fileStream = File.OpenWrite(refposePath)) {
                            fileStream.SetLength(0);
                            var refpose = new RefPoseSkeleton(chunkedData);
                            refpose.Write(fileStream);
                        }
                    }
                }
            }
            else
            {
                using (Stream modelStream = OpenFile(modelInfo.GUID)) {
                    WriteFile(modelStream, Path.Combine(modelDirectory, modelInfo.GetNameIndex() + ".00C"));
                }
            }

            foreach (ulong modelModelLook in modelInfo.ModelLooks)
            {
                SaveModelLook(flags, modelDirectory, info, modelModelLook);
            }

            foreach (ulong looseMaterial in modelInfo.LooseMaterials)
            {
                SaveMaterial(flags, modelDirectory, info, looseMaterial);
            }

            foreach (ulong modelAnimation in modelInfo.Animations)
            {
                SaveAnimation(flags, modelDirectory, info, modelAnimation, modelGUID);
            }
        }
Example #2
0
        public static void SaveModel(ICLIFlags flags, string path, SaveContext info, ulong modelGUID)
        {
            bool convertModels = true;
            bool doRefpose     = false;
            bool doStu         = false;
            byte lod           = 1;

            if (flags is ExtractFlags extractFlags)
            {
                convertModels = !extractFlags.RawModels && !extractFlags.Raw;
                doRefpose     = extractFlags.ExtractRefpose;
                doStu         = extractFlags.ExtractModelStu;
                lod           = extractFlags.LOD;
                if (extractFlags.SkipModels)
                {
                    return;
                }
            }

            FindLogic.Combo.ModelAsset modelInfo = info.m_info.m_models[modelGUID];
            string modelDirectory = Path.Combine(path, "Models", modelInfo.GetName());

            if (convertModels)
            {
                string modelPath = Path.Combine(modelDirectory, $"{modelInfo.GetNameIndex()}.owmdl");

                using (Stream modelStream = OpenFile(modelInfo.m_GUID)) {
                    if (modelStream == null)
                    {
                        return;
                    }
                    CreateDirectoryFromFile(modelPath);

                    teChunkedData chunkedData = new teChunkedData(modelStream);

                    OverwatchModel model = new OverwatchModel(chunkedData, modelInfo.m_GUID, (sbyte)lod);
                    if (modelInfo.m_modelLooks.Count > 0)
                    {
                        FindLogic.Combo.ModelLookAsset modelLookInfo = info.m_info.m_modelLooks[modelInfo.m_modelLooks.First()];
                        model.ModelLookFileName = Path.Combine("ModelLooks",
                                                               modelLookInfo.GetNameIndex() + ".owmat");
                    }

                    using (Stream fileStream = File.OpenWrite(modelPath)) {
                        fileStream.SetLength(0);
                        model.Write(fileStream);
                    }

                    if (doRefpose)
                    {
                        string refposePath = Path.Combine(modelDirectory, modelInfo.GetNameIndex() + ".smd");

                        using (Stream fileStream = File.OpenWrite(refposePath)) {
                            fileStream.SetLength(0);
                            var refpose = new RefPoseSkeleton(chunkedData);
                            refpose.Write(fileStream);
                        }
                    }

                    if (doStu)
                    {
                        var    stu     = chunkedData.GetChunks <teModelChunk_STU>().Select(x => x.StructuredData).ToArray();
                        string stuPath = Path.Combine(modelDirectory, modelInfo.GetNameIndex() + ".json");
                        JSONTool.OutputJSONAlt(stu, new ListFlags {
                            Output = stuPath
                        }, false);
                    }
                }
            }
            else
            {
                using (Stream modelStream = OpenFile(modelInfo.m_GUID)) {
                    WriteFile(modelStream, Path.Combine(modelDirectory, modelInfo.GetNameIndex() + ".00C"));
                }
            }

            foreach (ulong modelModelLook in modelInfo.m_modelLooks)
            {
                SaveModelLook(flags, modelDirectory, info, modelModelLook);
            }

            foreach (ulong looseMaterial in modelInfo.m_looseMaterials)
            {
                SaveMaterial(flags, modelDirectory, info, looseMaterial);
            }

            foreach (ulong modelAnimation in modelInfo.n_animations)
            {
                SaveAnimation(flags, modelDirectory, info, modelAnimation, modelGUID);
            }
        }