示例#1
0
文件: odfOps.cs 项目: kkdevs/sb3u
        public static odfMorphProfile FindMorphProfile(String name, odfMorphObject morphObj)
        {
            for (int profileIdx = 0; profileIdx < morphObj.Count; profileIdx++)
            {
                odfMorphProfile profile = morphObj[profileIdx];
                if (profile.Name == name)
                {
                    return(profile);
                }
            }

            return(null);
        }
示例#2
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);
        }
示例#3
0
文件: odaOps.cs 项目: kkdevs/sb3u
        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);
            }
        }