Пример #1
0
        public static odfMorphObject FindMorphObject(String name, odfMorphSection morphSection)
        {
            for (int morphObjIdx = 0; morphObjIdx < morphSection.Count; morphObjIdx++)
            {
                odfMorphObject morphObj = morphSection[morphObjIdx];
                if (morphObj.Name == name)
                {
                    return(morphObj);
                }
            }

            return(null);
        }
Пример #2
0
        public static void ReplaceMorph(string destMorphName, odfParser parser, WorkspaceMorph wsMorphList, string newMorphName, bool replaceNormals, float minSquaredDistance)
        {
            odfMorphSection morphSection = parser.MorphSection;

            if (morphSection == null)
            {
                Report.ReportLog("The .odf file doesn't have a morph section. Skipping these morphs");
                return;
            }

            odfMorphObject morphObj = odf.FindMorphObject(destMorphName, morphSection);

            if (morphObj == null)
            {
                Report.ReportLog("Couldn't find morph object " + destMorphName + ". Skipping these morphs");
                return;
            }

            Report.ReportLog("Replacing morphs ...");
            try
            {
                ushort[] meshIndices = morphObj.MeshIndices;
                foreach (ImportedMorphKeyframe wsMorph in wsMorphList.KeyframeList)
                {
                    if (!wsMorphList.isMorphKeyframeEnabled(wsMorph))
                    {
                        continue;
                    }
                    odfMorphProfile profile = odf.FindMorphProfile(wsMorph.Name, morphObj);
                    if (profile == null)
                    {
                        Report.ReportLog("Warning: Couldn't find morph profile " + wsMorph.Name + ". Skipping this morph");
                        continue;
                    }

                    List <ImportedVertex> vertList = wsMorph.VertexList;
                    for (int i = 0; i < meshIndices.Length; i++)
                    {
                        Vector3 orgPos = new Vector3(profile.VertexList[i].Position.X, profile.VertexList[i].Position.Y, profile.VertexList[i].Position.Z),
                                newPos = new Vector3(vertList[meshIndices[i]].Position.X, vertList[meshIndices[i]].Position.Y, vertList[meshIndices[i]].Position.Z);
                        if ((orgPos - newPos).LengthSquared() >= minSquaredDistance)
                        {
                            profile.VertexList[i].Position = vertList[meshIndices[i]].Position;
                        }
                        if (replaceNormals)
                        {
                            profile.VertexList[i].Normal = vertList[meshIndices[i]].Normal;
                        }
                    }

                    string morphNewName = wsMorphList.getMorphKeyframeNewName(wsMorph);
                    if (morphNewName != String.Empty)
                    {
                        profile.Name = new ObjectName(morphNewName, null);
                    }
                }
                if (newMorphName != String.Empty)
                {
                    morphObj.Name = new ObjectName(newMorphName, null);
                }
            }
            catch (Exception ex)
            {
                Utility.ReportException(ex);
            }
        }
Пример #3
0
        private bool loadMORP(BinaryReader reader, odfFileSection fileSec)
        {
            ObjectName      name            = new ObjectName(reader.ReadBytes(64));
            ObjectID        id              = new ObjectID(reader.ReadBytes(4));
            int             numMorphObjects = reader.ReadInt32();
            odfMorphSection morpSection     = new odfMorphSection(id, numMorphObjects);

            morpSection.Name = name;
            for (int morphObjIdx = 0; morphObjIdx < numMorphObjects; morphObjIdx++)
            {
                id = new ObjectID(reader.ReadBytes(4));
                byte[]         alwaysZero       = reader.ReadBytes(16);
                int            numSelectorInfos = reader.ReadInt32();
                int            numProfiles      = reader.ReadInt32();
                odfMorphObject morphObj         = new odfMorphObject(id, numSelectorInfos, numProfiles);
                morphObj.AlwaysZero16 = alwaysZero;
                morphObj.Name         = new ObjectName(reader.ReadBytes(64));

                morphObj.NumIndices     = reader.ReadInt32();
                morphObj.MeshIndices    = reader.ReadUInt16Array(morphObj.NumIndices);
                morphObj.UnknownIndices = reader.ReadInt32Array(morphObj.NumIndices);

                for (int idx = 0; idx < numProfiles; idx++)
                {
                    odfMorphProfile profile = new odfMorphProfile();
                    profile.VertexList = ParseVertexList(reader, morphObj.NumIndices);
                    profile.Name       = new ObjectName(reader.ReadBytes(64));

                    morphObj.AddChild(profile);
                }

                List <odfMorphSelector> selectorList = new List <odfMorphSelector>(numSelectorInfos);
                for (int idx = 0; idx < numSelectorInfos; idx++)
                {
                    odfMorphSelector selectorInfo = new odfMorphSelector();
                    selectorInfo.Threshold    = reader.ReadInt32();
                    selectorInfo.ProfileIndex = reader.ReadInt32();

                    selectorList.Add(selectorInfo);
                }
                morphObj.SelectorList = selectorList;

                morphObj.ClipType = reader.ReadInt32();
                if (morphObj.ClipType > 0)
                {
                    int numClipInfos             = reader.ReadInt32();
                    List <odfMorphClip> clipList = new List <odfMorphClip>(numClipInfos);
                    for (int idx = 0; idx < numClipInfos; idx++)
                    {
                        odfMorphClip clipInfo = new odfMorphClip();
                        clipInfo.StartIndex = reader.ReadInt32();
                        clipInfo.EndIndex   = reader.ReadInt32();
                        clipInfo.Unknown    = reader.ReadInt32();

                        clipList.Add(clipInfo);
                    }
                    morphObj.MorphClipList = clipList;
                }

                morphObj.MinusOne = reader.ReadInt32();
                morphObj.FrameId  = new ObjectID(reader.ReadBytes(4));

                morpSection.AddChild(morphObj);
            }

            fileSec.Section = morpSection;
            MorphSection    = morpSection;
            return(true);
        }
Пример #4
0
Файл: Mqo.cs Проект: kkdevs/sb3u
            private void Export(DirectoryInfo dir)
            {
                try
                {
                    odfMorphSection morphSection = parser.MorphSection;
                    ushort[]        meshIndices  = morphObj.MeshIndices;

                    odfSubmesh meshObjBase = odf.FindMeshObject(morphObj.SubmeshId, parser.MeshSection);
                    colorVertex = new bool[meshObjBase.VertexList.Count];
                    for (int i = 0; i < meshIndices.Length; i++)
                    {
                        colorVertex[meshIndices[i]] = true;
                    }

                    vertLists = new List <List <ImportedVertex> >(morphObj.Count);
                    for (int i = 0; i < morphObj.Count; i++)
                    {
                        if (skipUnusedProfiles)
                        {
                            bool skip = true;
                            for (int j = 0; j < morphObj.SelectorList.Count; j++)
                            {
                                if (morphObj.SelectorList[j].ProfileIndex == i)
                                {
                                    skip = false;
                                    break;
                                }
                            }
                            if (skip)
                            {
                                continue;
                            }
                        }

                        List <ImportedVertex> vertList = odf.ImportedVertexListUnskinned(meshObjBase.VertexList);
                        vertLists.Add(vertList);

                        for (int j = 0; j < meshIndices.Length; j++)
                        {
                            ImportedVertex vert = vertList[meshIndices[j]];
                            vert.Position = morphObj[i].VertexList[j].Position;
                        }
                    }

                    faceList = odf.ImportedFaceList(meshObjBase.FaceList);
                    string      dest = Utility.GetDestFile(dir, meshObjBase.Parent.Name + "-" + morphObj.Name + "-", ".morph.mqo");
                    odfMaterial mat  = odf.FindMaterialInfo(meshObjBase.MaterialId, parser.MaterialSection);
                    Export(dest, mat, odf.FindTextureInfo(meshObjBase.TextureIds[0], parser.TextureSection));
                    foreach (odfTexture tex in usedTextures)
                    {
                        String texFilePath = Path.GetDirectoryName(parser.ODFPath) + @"\" + tex.TextureFile;
                        try
                        {
                            odfTextureFile odfTex = new odfTextureFile(tex.Name, texFilePath);
                            odf.ExportTexture(odfTex, dir.FullName + @"\" + tex.TextureFile);
                        }
                        catch (Exception ex)
                        {
                            Utility.ReportException(ex);
                        }
                    }
                    Report.ReportLog("Finished exporting morph to " + dest);
                }
                catch (Exception ex)
                {
                    Report.ReportLog("Error exporting morph: " + ex.Message);
                }
            }