Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        public ImportedEditor(IImported imported)
        {
            Imported = imported;

            if (Imported.MaterialList != null && Imported.MaterialList.Count > 0)
            {
                Materials = new List <WorkspaceMaterial>(Imported.MaterialList.Count);
                foreach (ImportedMaterial mat in Imported.MaterialList)
                {
                    WorkspaceMaterial wsMat = new WorkspaceMaterial(mat);
                    Materials.Add(wsMat);
                }
            }

            if ((Imported.FrameList != null) && (Imported.FrameList.Count > 0))
            {
                Frames = new List <ImportedFrame>();
                foreach (var frame in Imported.FrameList)
                {
                    InitFrames(frame);
                }
            }

            if (Imported.MeshList != null && Imported.MeshList.Count > 0)
            {
                Meshes = new List <WorkspaceMesh>(Imported.MeshList.Count);
                foreach (ImportedMesh mesh in Imported.MeshList)
                {
                    WorkspaceMesh wsMesh = new WorkspaceMesh(mesh);
                    Meshes.Add(wsMesh);
                }
            }

            if (Imported.MorphList != null && Imported.MorphList.Count > 0)
            {
                Morphs = new List <WorkspaceMorph>(Imported.MorphList.Count);
                foreach (ImportedMorph morph in Imported.MorphList)
                {
                    WorkspaceMorph wsMorph = new WorkspaceMorph(morph);
                    Morphs.Add(wsMorph);
                }
            }

            if (Imported.AnimationList != null && Imported.AnimationList.Count > 0)
            {
                Animations = new List <WorkspaceAnimation>(Imported.AnimationList.Count);
                foreach (ImportedAnimation animation in Imported.AnimationList)
                {
                    WorkspaceAnimation wsAnimation = new WorkspaceAnimation(animation);
                    Animations.Add(wsAnimation);
                }
            }
        }
Esempio n. 3
0
        public ImportedEditor(IImported imported)
        {
            Imported = imported;

            if ((Imported.FrameList != null) && (Imported.FrameList.Count > 0))
            {
                Frames = new List<ImportedFrame>();
                foreach (var frame in Imported.FrameList)
                {
                    InitFrames(frame);
                }
            }

            if (Imported.MeshList != null && Imported.MeshList.Count > 0)
            {
                Meshes = new List<WorkspaceMesh>(Imported.MeshList.Count);
                foreach (ImportedMesh mesh in Imported.MeshList)
                {
                    WorkspaceMesh wsMesh = new WorkspaceMesh(mesh);
                    Meshes.Add(wsMesh);
                }
            }

            if (Imported.MorphList != null && Imported.MorphList.Count > 0)
            {
                Morphs = new List<WorkspaceMorph>(Imported.MorphList.Count);
                foreach (ImportedMorph morph in Imported.MorphList)
                {
                    WorkspaceMorph wsMorph = new WorkspaceMorph(morph);
                    Morphs.Add(wsMorph);
                }
            }

            if (Imported.AnimationList != null && Imported.AnimationList.Count > 0)
            {
                Animations = new List<WorkspaceAnimation>(Imported.AnimationList.Count);
                foreach (ImportedAnimation animation in Imported.AnimationList)
                {
                    WorkspaceAnimation wsAnimation = new WorkspaceAnimation(animation);
                    Animations.Add(wsAnimation);
                }
            }
        }
Esempio n. 4
0
 public void ReplaceMorph(WorkspaceMorph morph, string destMorphName, string newName, bool replaceMorphMask, bool replaceNormals, double minSquaredDistance, bool minKeyframes)
 {
     xa.ReplaceMorph(destMorphName, Parser, morph, newName, replaceMorphMask, replaceNormals, (float)minSquaredDistance, minKeyframes);
     Changed = true;
 }
Esempio n. 5
0
        public static void ReplaceMorph(string destMorphName, xaParser parser, WorkspaceMorph wsMorphList, string newMorphName, bool replaceNormals, float minSquaredDistance)
        {
            if (parser.MorphSection == null)
            {
                Report.ReportLog("The .xa file doesn't have a morph section. Skipping these morphs");
                return;
            }

            xaMorphSection morphSection = parser.MorphSection;
            xaMorphIndexSet indices = FindMorphIndexSet(destMorphName, morphSection);
            if (indices == null)
            {
                Report.ReportLog("Couldn't find morph clip " + destMorphName + ". Skipping these morphs");
                return;
            }

            Report.ReportLog("Replacing morphs ...");
            try
            {
                ushort[] meshIndices = indices.MeshIndices;
                ushort[] morphIndices = indices.MorphIndices;
                foreach (ImportedMorphKeyframe wsMorph in wsMorphList.KeyframeList)
                {
                    if (!wsMorphList.isMorphKeyframeEnabled(wsMorph))
                        continue;

                    List<ImportedVertex> vertList = wsMorph.VertexList;
                    xaMorphKeyframe keyframe = FindMorphKeyFrame(wsMorph.Name, morphSection);
                    if (keyframe == null)
                    {
                        keyframe = new xaMorphKeyframe();
                        keyframe.Name = wsMorph.Name;
                        keyframe.PositionList = new List<Vector3>(new Vector3[wsMorph.VertexList.Count]);
                        keyframe.NormalList = new List<Vector3>(new Vector3[wsMorph.VertexList.Count]);
                        for (int i = 0; i < meshIndices.Length; i++)
                        {
                            keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position;
                            keyframe.NormalList[morphIndices[i]] = vertList[meshIndices[i]].Normal;
                        }
                        morphSection.KeyframeList.Add(keyframe);
                    }
                    else
                    {
                        for (int i = 0; i < meshIndices.Length; i++)
                        {
                            Vector3 orgPos = new Vector3(keyframe.PositionList[morphIndices[i]].X, keyframe.PositionList[morphIndices[i]].Y, keyframe.PositionList[morphIndices[i]].Z),
                                newPos = new Vector3(vertList[meshIndices[i]].Position.X, vertList[meshIndices[i]].Position.Y, vertList[meshIndices[i]].Position.Z);
                            if ((orgPos - newPos).LengthSquared() >= minSquaredDistance)
                            {
                                keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position;
                                if (replaceNormals)
                                {
                                    keyframe.NormalList[morphIndices[i]] = vertList[meshIndices[i]].Normal;
                                }
                            }
                        }
                    }

                    string morphNewName = wsMorphList.getMorphKeyframeNewName(wsMorph);
                    if (morphNewName != String.Empty)
                    {
                        for (int i = 0; i < morphSection.ClipList.Count; i++)
                        {
                            xaMorphClip clip = morphSection.ClipList[i];
                            for (int j = 0; j < clip.KeyframeRefList.Count; j++)
                            {
                                xaMorphKeyframeRef keyframeRef = clip.KeyframeRefList[j];
                                if (keyframeRef.Name == wsMorph.Name)
                                    keyframeRef.Name = morphNewName;
                            }
                        }
                        keyframe.Name = morphNewName;
                    }
                }
                if (newMorphName != String.Empty)
                {
                    for (int i = 0; i < morphSection.ClipList.Count; i++)
                    {
                        xaMorphClip clip = morphSection.ClipList[i];
                        if (clip.Name == destMorphName)
                        {
                            clip.Name = newMorphName;
                            break;
                        }
                    }
                    indices.Name = newMorphName;
                }
            }
            catch (Exception ex)
            {
                Report.ReportLog("Error replacing morphs: " + ex.Message);
            }
        }
Esempio n. 6
0
        private void AddList <T>(List <T> list, string rootName, string editorVar)
        {
            if ((list != null) && (list.Count > 0))
            {
                TreeNode root = new TreeNode(rootName);
                root.Checked = true;
                this.treeView.AddChild(root);

                for (int i = 0; i < list.Count; i++)
                {
                    dynamic  item = list[i];
                    TreeNode node = new TreeNode(item is WorkspaceAnimation
                                                ? ((WorkspaceAnimation)item).importedAnimation is ImportedKeyframedAnimation
                                                        ? "Animation" + i : "Animation(Reduced Keys)" + i
                                                : item.Name);
                    node.Checked = true;
                    node.Tag     = new DragSource(editorVar, typeof(T), i);
                    this.treeView.AddChild(root, node);
                    if (item is WorkspaceMesh)
                    {
                        WorkspaceMesh mesh = item;
                        for (int j = 0; j < mesh.SubmeshList.Count; j++)
                        {
                            ImportedSubmesh submesh     = mesh.SubmeshList[j];
                            TreeNode        submeshNode = new TreeNode();
                            submeshNode.Checked          = mesh.isSubmeshEnabled(submesh);
                            submeshNode.Tag              = submesh;
                            submeshNode.ContextMenuStrip = this.contextMenuStripSubmesh;
                            this.treeView.AddChild(node, submeshNode);
                            UpdateSubmeshNode(submeshNode);
                        }
                    }
                    else if (item is WorkspaceMorph)
                    {
                        WorkspaceMorph morph     = item;
                        string         extraInfo = morph.MorphedVertexIndices != null ? " (morphed vertices: " + morph.MorphedVertexIndices.Count : String.Empty;
                        extraInfo += (extraInfo.Length == 0 ? " (" : ", ") + "keyframes: " + morph.KeyframeList.Count + ")";
                        node.Text += extraInfo;
                        for (int j = 0; j < morph.KeyframeList.Count; j++)
                        {
                            ImportedMorphKeyframe keyframe = morph.KeyframeList[j];
                            TreeNode keyframeNode          = new TreeNode();
                            keyframeNode.Checked          = morph.isMorphKeyframeEnabled(keyframe);
                            keyframeNode.Tag              = keyframe;
                            keyframeNode.ContextMenuStrip = this.contextMenuStripMorphKeyframe;
                            this.treeView.AddChild(node, keyframeNode);
                            UpdateMorphKeyframeNode(keyframeNode);
                        }
                    }
                    else if (item is WorkspaceAnimation)
                    {
                        WorkspaceAnimation animation = item;
                        if (animation.importedAnimation is ImportedKeyframedAnimation)
                        {
                            List <ImportedAnimationKeyframedTrack> trackList = ((ImportedKeyframedAnimation)animation.importedAnimation).TrackList;
                            for (int j = 0; j < trackList.Count; j++)
                            {
                                ImportedAnimationKeyframedTrack track = trackList[j];
                                TreeNode trackNode = new TreeNode();
                                trackNode.Checked = animation.isTrackEnabled(track);
                                trackNode.Tag     = track;
                                int numKeyframes = 0;
                                foreach (ImportedAnimationKeyframe keyframe in track.Keyframes)
                                {
                                    if (keyframe != null)
                                    {
                                        numKeyframes++;
                                    }
                                }
                                trackNode.Text = "Track: " + track.Name + ", Keyframes: " + numKeyframes;
                                this.treeView.AddChild(node, trackNode);
                            }
                        }
                        else if (animation.importedAnimation is ImportedSampledAnimation)
                        {
                            List <ImportedAnimationSampledTrack> trackList = ((ImportedSampledAnimation)animation.importedAnimation).TrackList;
                            for (int j = 0; j < trackList.Count; j++)
                            {
                                ImportedAnimationSampledTrack track = trackList[j];
                                TreeNode trackNode = new TreeNode();
                                trackNode.Checked = animation.isTrackEnabled(track);
                                trackNode.Tag     = track;
                                int numScalings = 0;
                                for (int k = 0; k < track.Scalings.Length; k++)
                                {
                                    if (track.Scalings[k] != null)
                                    {
                                        numScalings++;
                                    }
                                }
                                int numRotations = 0;
                                for (int k = 0; k < track.Rotations.Length; k++)
                                {
                                    if (track.Rotations[k] != null)
                                    {
                                        numRotations++;
                                    }
                                }
                                int numTranslations = 0;
                                for (int k = 0; k < track.Translations.Length; k++)
                                {
                                    if (track.Translations[k] != null)
                                    {
                                        numTranslations++;
                                    }
                                }
                                trackNode.Text = "Track: " + track.Name + ", Length: " + track.Scalings.Length + ", Scalings: " + numScalings + ", Rotations: " + numRotations + ", Translations: " + numTranslations;
                                this.treeView.AddChild(node, trackNode);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 7
0
 public void ReplaceMorph(WorkspaceMorph morph, string destMorphName, string newName, bool replaceNormals, double minSquaredDistance)
 {
     xa.ReplaceMorph(destMorphName, Parser, morph, newName, replaceNormals, (float)minSquaredDistance);
 }
Esempio n. 8
0
 public void ReplaceMorph(WorkspaceMorph morph, string destMorphName, string newName, bool replaceMorphMask, bool replaceNormals, double minSquaredDistance, bool minKeyframes)
 {
     xa.ReplaceMorph(destMorphName, Parser, morph, newName, replaceMorphMask, replaceNormals, (float)minSquaredDistance, minKeyframes);
     Changed = true;
 }
Esempio n. 9
0
 public void ReplaceMorph(WorkspaceMorph morph, string destMorphName, bool replaceNormals, double minSquaredDistance)
 {
     Operations.ReplaceMorph(destMorphName, Parser, morph, replaceNormals, (float)minSquaredDistance);
     Changed = true;
 }
Esempio n. 10
0
File: xaOps.cs Progetto: kkdevs/sb3u
        public static void ReplaceMorph(string destMorphName, xaParser parser, WorkspaceMorph wsMorphList, string newMorphName, bool replaceMorphMask, bool replaceNormals, float minSquaredDistance, bool minKeyframes)
        {
            if (parser.MorphSection == null)
            {
                Report.ReportLog("The .xa file doesn't have a morph section. Skipping these morphs");
                return;
            }

            xaMorphSection  morphSection = parser.MorphSection;
            xaMorphIndexSet indices      = FindMorphIndexSet(destMorphName, morphSection);

            if (indices == null)
            {
                Report.ReportLog("Couldn't find morph clip " + destMorphName + ". Skipping these morphs");
                return;
            }
            if (replaceMorphMask && wsMorphList.MorphedVertexIndices != null)
            {
                int             index      = morphSection.IndexSetList.IndexOf(indices);
                xaMorphIndexSet newIndices = new xaMorphIndexSet();
                newIndices.Name = indices.Name;
                int numMorphedVertices = wsMorphList.MorphedVertexIndices.Count;
                newIndices.MeshIndices = new ushort[numMorphedVertices];
                wsMorphList.MorphedVertexIndices.CopyTo(newIndices.MeshIndices);
                newIndices.MorphIndices = new ushort[numMorphedVertices];
                if (minKeyframes)
                {
                    for (ushort i = 0; i < numMorphedVertices; i++)
                    {
                        newIndices.MorphIndices[i] = i;
                    }
                }
                else
                {
                    wsMorphList.MorphedVertexIndices.CopyTo(newIndices.MorphIndices);
                }
                newIndices.Unknown1 = indices.Unknown1;
                morphSection.IndexSetList.RemoveAt(index);
                morphSection.IndexSetList.Insert(index, newIndices);
                indices = newIndices;
            }

            Report.ReportLog("Replacing morphs ...");
            try
            {
                ushort[] meshIndices  = indices.MeshIndices;
                ushort[] morphIndices = indices.MorphIndices;
                foreach (ImportedMorphKeyframe wsMorph in wsMorphList.KeyframeList)
                {
                    if (!wsMorphList.isMorphKeyframeEnabled(wsMorph))
                    {
                        continue;
                    }

                    List <ImportedVertex> vertList = wsMorph.VertexList;
                    xaMorphKeyframe       keyframe = FindMorphKeyFrame(wsMorph.Name, morphSection);
                    if (keyframe == null)
                    {
                        Report.ReportLog("Adding new Keyframe " + wsMorph.Name);
                        keyframe      = new xaMorphKeyframe();
                        keyframe.Name = wsMorph.Name;
                        int numVertices = minKeyframes ? meshIndices.Length : wsMorph.VertexList.Count;
                        keyframe.PositionList = new List <Vector3>(new Vector3[numVertices]);
                        keyframe.NormalList   = new List <Vector3>(new Vector3[numVertices]);
                        for (int i = 0; i < meshIndices.Length; i++)
                        {
                            keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position;
                            keyframe.NormalList[morphIndices[i]]   = vertList[meshIndices[i]].Normal;
                        }
                        morphSection.KeyframeList.Add(keyframe);
                    }
                    else
                    {
                        if (!minKeyframes && keyframe.PositionList.Count != vertList.Count ||
                            minKeyframes && keyframe.PositionList.Count != meshIndices.Length)
                        {
                            Report.ReportLog("Adapting Keyframe " + wsMorph.Name + " to new length.");
                            int       length       = minKeyframes ? meshIndices.Length : vertList.Count;
                            Vector3[] newPositions = new Vector3[length];
                            Vector3[] newNormals   = new Vector3[length];
                            if (!minKeyframes)
                            {
                                for (int i = 0; i < vertList.Count; i++)
                                {
                                    newPositions[i] = vertList[i].Position;
                                    newNormals[i]   = vertList[i].Normal;
                                }
                            }
                            for (int i = 0; i < meshIndices.Length; i++)
                            {
                                newPositions[morphIndices[i]] = vertList[meshIndices[i]].Position;
                                newNormals[morphIndices[i]]   = vertList[meshIndices[i]].Normal;
                            }
                            keyframe.PositionList.Clear();
                            keyframe.NormalList.Clear();
                            keyframe.PositionList.AddRange(newPositions);
                            keyframe.NormalList.AddRange(newNormals);
                        }
                        else
                        {
                            Report.ReportLog("Replacing Keyframe " + wsMorph.Name);
                            for (int i = 0; i < meshIndices.Length; i++)
                            {
                                Vector3 orgPos = new Vector3(keyframe.PositionList[morphIndices[i]].X, keyframe.PositionList[morphIndices[i]].Y, keyframe.PositionList[morphIndices[i]].Z),
                                        newPos = new Vector3(vertList[meshIndices[i]].Position.X, vertList[meshIndices[i]].Position.Y, vertList[meshIndices[i]].Position.Z);
                                if ((orgPos - newPos).LengthSquared() >= minSquaredDistance)
                                {
                                    keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position;
                                    if (replaceNormals)
                                    {
                                        keyframe.NormalList[morphIndices[i]] = vertList[meshIndices[i]].Normal;
                                    }
                                }
                            }
                        }
                    }

                    string morphNewName = wsMorphList.getMorphKeyframeNewName(wsMorph);
                    if (morphNewName != String.Empty)
                    {
                        for (int i = 0; i < morphSection.ClipList.Count; i++)
                        {
                            xaMorphClip clip = morphSection.ClipList[i];
                            for (int j = 0; j < clip.KeyframeRefList.Count; j++)
                            {
                                xaMorphKeyframeRef keyframeRef = clip.KeyframeRefList[j];
                                if (keyframeRef.Name == wsMorph.Name)
                                {
                                    keyframeRef.Name = morphNewName;
                                }
                            }
                        }
                        keyframe.Name = morphNewName;
                    }
                }
                if (newMorphName != String.Empty)
                {
                    for (int i = 0; i < morphSection.ClipList.Count; i++)
                    {
                        xaMorphClip clip = morphSection.ClipList[i];
                        if (clip.Name == destMorphName)
                        {
                            clip.Name = newMorphName;
                            break;
                        }
                    }
                    indices.Name = newMorphName;
                }
            }
            catch (Exception ex)
            {
                Report.ReportLog("Error replacing morphs: " + ex.Message);
            }
        }
Esempio n. 11
0
        private void AddList <T>(List <T> list, string rootName, string editorVar)
        {
            if ((list != null) && (list.Count > 0))
            {
                TreeNode root = new TreeNode(rootName);
                root.Checked = true;
                this.treeView.AddChild(root);

                for (int i = 0; i < list.Count; i++)
                {
                    dynamic  item = list[i];
                    TreeNode node = new TreeNode(item is WorkspaceAnimation ? "Animation" + i : item.Name);
                    node.Checked = true;
                    node.Tag     = new DragSource(editorVar, typeof(T), i);
                    this.treeView.AddChild(root, node);
                    if (item is WorkspaceMesh)
                    {
                        WorkspaceMesh mesh = item;
                        for (int j = 0; j < mesh.SubmeshList.Count; j++)
                        {
                            ImportedSubmesh submesh     = mesh.SubmeshList[j];
                            TreeNode        submeshNode = new TreeNode();
                            submeshNode.Checked          = mesh.isSubmeshEnabled(submesh);
                            submeshNode.Tag              = submesh;
                            submeshNode.ContextMenuStrip = this.contextMenuStripSubmesh;
                            this.treeView.AddChild(node, submeshNode);
                            UpdateSubmeshNode(submeshNode);
                        }
                    }
                    else if (item is WorkspaceMorph)
                    {
                        WorkspaceMorph morph = item;
                        for (int j = 0; j < morph.KeyframeList.Count; j++)
                        {
                            ImportedMorphKeyframe keyframe = morph.KeyframeList[j];
                            TreeNode keyframeNode          = new TreeNode();
                            keyframeNode.Checked          = morph.isMorphKeyframeEnabled(keyframe);
                            keyframeNode.Tag              = keyframe;
                            keyframeNode.ContextMenuStrip = this.contextMenuStripMorphKeyframe;
                            this.treeView.AddChild(node, keyframeNode);
                            UpdateMorphKeyframeNode(keyframeNode);
                        }
                    }
                    else if (item is WorkspaceAnimation)
                    {
                        WorkspaceAnimation animation = item;
                        for (int j = 0; j < animation.TrackList.Count; j++)
                        {
                            ImportedAnimationTrack track = animation.TrackList[j];
                            TreeNode trackNode           = new TreeNode();
                            trackNode.Checked = animation.isTrackEnabled(track);
                            trackNode.Tag     = track;
                            int numKeyframes = 0;
                            foreach (ImportedAnimationKeyframe keyframe in track.Keyframes)
                            {
                                if (keyframe != null)
                                {
                                    numKeyframes++;
                                }
                            }
                            trackNode.Text = "Track: " + track.Name + ", Keyframes: " + numKeyframes;
                            this.treeView.AddChild(node, trackNode);
                        }
                    }
                }
            }
        }
Esempio n. 12
0
        public static void ReplaceMorph(string destMorphName, xaParser parser, WorkspaceMorph wsMorphList, string newMorphName, bool replaceNormals, float minSquaredDistance)
        {
            if (parser.MorphSection == null)
            {
                Report.ReportLog("The .xa file doesn't have a morph section. Skipping these morphs");
                return;
            }

            xaMorphSection  morphSection = parser.MorphSection;
            xaMorphIndexSet indices      = FindMorphIndexSet(destMorphName, morphSection);

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

            Report.ReportLog("Replacing morphs ...");
            try
            {
                ushort[] meshIndices  = indices.MeshIndices;
                ushort[] morphIndices = indices.MorphIndices;
                foreach (ImportedMorphKeyframe wsMorph in wsMorphList.KeyframeList)
                {
                    if (!wsMorphList.isMorphKeyframeEnabled(wsMorph))
                    {
                        continue;
                    }

                    List <ImportedVertex> vertList = wsMorph.VertexList;
                    xaMorphKeyframe       keyframe = FindMorphKeyFrame(wsMorph.Name, morphSection);
                    if (keyframe == null)
                    {
                        keyframe              = new xaMorphKeyframe();
                        keyframe.Name         = wsMorph.Name;
                        keyframe.PositionList = new List <Vector3>(new Vector3[wsMorph.VertexList.Count]);
                        keyframe.NormalList   = new List <Vector3>(new Vector3[wsMorph.VertexList.Count]);
                        for (int i = 0; i < meshIndices.Length; i++)
                        {
                            keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position;
                            keyframe.NormalList[morphIndices[i]]   = vertList[meshIndices[i]].Normal;
                        }
                        morphSection.KeyframeList.Add(keyframe);
                    }
                    else
                    {
                        for (int i = 0; i < meshIndices.Length; i++)
                        {
                            Vector3 orgPos = new Vector3(keyframe.PositionList[morphIndices[i]].X, keyframe.PositionList[morphIndices[i]].Y, keyframe.PositionList[morphIndices[i]].Z),
                                    newPos = new Vector3(vertList[meshIndices[i]].Position.X, vertList[meshIndices[i]].Position.Y, vertList[meshIndices[i]].Position.Z);
                            if ((orgPos - newPos).LengthSquared() >= minSquaredDistance)
                            {
                                keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position;
                                if (replaceNormals)
                                {
                                    keyframe.NormalList[morphIndices[i]] = vertList[meshIndices[i]].Normal;
                                }
                            }
                        }
                    }

                    string morphNewName = wsMorphList.getMorphKeyframeNewName(wsMorph);
                    if (morphNewName != String.Empty)
                    {
                        for (int i = 0; i < morphSection.ClipList.Count; i++)
                        {
                            xaMorphClip clip = morphSection.ClipList[i];
                            for (int j = 0; j < clip.KeyframeRefList.Count; j++)
                            {
                                xaMorphKeyframeRef keyframeRef = clip.KeyframeRefList[j];
                                if (keyframeRef.Name == wsMorph.Name)
                                {
                                    keyframeRef.Name = morphNewName;
                                }
                            }
                        }
                        keyframe.Name = morphNewName;
                    }
                }
                if (newMorphName != String.Empty)
                {
                    for (int i = 0; i < morphSection.ClipList.Count; i++)
                    {
                        xaMorphClip clip = morphSection.ClipList[i];
                        if (clip.Name == destMorphName)
                        {
                            clip.Name = newMorphName;
                            break;
                        }
                    }
                    indices.Name = newMorphName;
                }
            }
            catch (Exception ex)
            {
                Report.ReportLog("Error replacing morphs: " + ex.Message);
            }
        }
Esempio n. 13
0
        public static void ReplaceMorph(string destMorphName, xaParser parser, WorkspaceMorph wsMorphList, string newMorphName, bool replaceMorphMask, bool replaceNormals, float minSquaredDistance, bool minKeyframes)
        {
            if (parser.MorphSection == null)
            {
                Report.ReportLog("The .xa file doesn't have a morph section. Skipping these morphs");
                return;
            }

            xaMorphSection morphSection = parser.MorphSection;
            xaMorphIndexSet indices = FindMorphIndexSet(destMorphName, morphSection);
            if (indices == null)
            {
                Report.ReportLog("Couldn't find morph clip " + destMorphName + ". Skipping these morphs");
                return;
            }
            if (replaceMorphMask && wsMorphList.MorphedVertexIndices != null)
            {
                int index = morphSection.IndexSetList.IndexOf(indices);
                xaMorphIndexSet newIndices = new xaMorphIndexSet();
                newIndices.Name = indices.Name;
                int numMorphedVertices = wsMorphList.MorphedVertexIndices.Count;
                newIndices.MeshIndices = new ushort[numMorphedVertices];
                wsMorphList.MorphedVertexIndices.CopyTo(newIndices.MeshIndices);
                newIndices.MorphIndices = new ushort[numMorphedVertices];
                if (minKeyframes)
                {
                    for (ushort i = 0; i < numMorphedVertices; i++)
                    {
                        newIndices.MorphIndices[i] = i;
                    }
                }
                else
                {
                    wsMorphList.MorphedVertexIndices.CopyTo(newIndices.MorphIndices);
                }
                newIndices.Unknown1 = indices.Unknown1;
                morphSection.IndexSetList.RemoveAt(index);
                morphSection.IndexSetList.Insert(index, newIndices);
                indices = newIndices;
            }

            Report.ReportLog("Replacing morphs ...");
            try
            {
                ushort[] meshIndices = indices.MeshIndices;
                ushort[] morphIndices = indices.MorphIndices;
                foreach (ImportedMorphKeyframe wsMorph in wsMorphList.KeyframeList)
                {
                    if (!wsMorphList.isMorphKeyframeEnabled(wsMorph))
                        continue;

                    List<ImportedVertex> vertList = wsMorph.VertexList;
                    xaMorphKeyframe keyframe = FindMorphKeyFrame(wsMorph.Name, morphSection);
                    if (keyframe == null)
                    {
                        Report.ReportLog("Adding new Keyframe " + wsMorph.Name);
                        keyframe = new xaMorphKeyframe();
                        keyframe.Name = wsMorph.Name;
                        int numVertices = minKeyframes ? meshIndices.Length : wsMorph.VertexList.Count;
                        keyframe.PositionList = new List<Vector3>(new Vector3[numVertices]);
                        keyframe.NormalList = new List<Vector3>(new Vector3[numVertices]);
                        for (int i = 0; i < meshIndices.Length; i++)
                        {
                            keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position;
                            keyframe.NormalList[morphIndices[i]] = vertList[meshIndices[i]].Normal;
                        }
                        morphSection.KeyframeList.Add(keyframe);
                    }
                    else
                    {
                        if (!minKeyframes && keyframe.PositionList.Count != vertList.Count ||
                            minKeyframes && keyframe.PositionList.Count != meshIndices.Length)
                        {
                            Report.ReportLog("Adapting Keyframe " + wsMorph.Name + " to new length.");
                            int length = minKeyframes ? meshIndices.Length : vertList.Count;
                            Vector3[] newPositions = new Vector3[length];
                            Vector3[] newNormals = new Vector3[length];
                            if (!minKeyframes)
                            {
                                for (int i = 0; i < vertList.Count; i++)
                                {
                                    newPositions[i] = vertList[i].Position;
                                    newNormals[i] = vertList[i].Normal;
                                }
                            }
                            for (int i = 0; i < meshIndices.Length; i++)
                            {
                                newPositions[morphIndices[i]] = vertList[meshIndices[i]].Position;
                                newNormals[morphIndices[i]] = vertList[meshIndices[i]].Normal;
                            }
                            keyframe.PositionList.Clear();
                            keyframe.NormalList.Clear();
                            keyframe.PositionList.AddRange(newPositions);
                            keyframe.NormalList.AddRange(newNormals);
                        }
                        else
                        {
                            Report.ReportLog("Replacing Keyframe " + wsMorph.Name);
                            for (int i = 0; i < meshIndices.Length; i++)
                            {
                                Vector3 orgPos = new Vector3(keyframe.PositionList[morphIndices[i]].X, keyframe.PositionList[morphIndices[i]].Y, keyframe.PositionList[morphIndices[i]].Z),
                                    newPos = new Vector3(vertList[meshIndices[i]].Position.X, vertList[meshIndices[i]].Position.Y, vertList[meshIndices[i]].Position.Z);
                                if ((orgPos - newPos).LengthSquared() >= minSquaredDistance)
                                {
                                    keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position;
                                    if (replaceNormals)
                                    {
                                        keyframe.NormalList[morphIndices[i]] = vertList[meshIndices[i]].Normal;
                                    }
                                }
                            }
                        }
                    }

                    string morphNewName = wsMorphList.getMorphKeyframeNewName(wsMorph);
                    if (morphNewName != String.Empty)
                    {
                        for (int i = 0; i < morphSection.ClipList.Count; i++)
                        {
                            xaMorphClip clip = morphSection.ClipList[i];
                            for (int j = 0; j < clip.KeyframeRefList.Count; j++)
                            {
                                xaMorphKeyframeRef keyframeRef = clip.KeyframeRefList[j];
                                if (keyframeRef.Name == wsMorph.Name)
                                    keyframeRef.Name = morphNewName;
                            }
                        }
                        keyframe.Name = morphNewName;
                    }
                }
                if (newMorphName != String.Empty)
                {
                    for (int i = 0; i < morphSection.ClipList.Count; i++)
                    {
                        xaMorphClip clip = morphSection.ClipList[i];
                        if (clip.Name == destMorphName)
                        {
                            clip.Name = newMorphName;
                            break;
                        }
                    }
                    indices.Name = newMorphName;
                }
            }
            catch (Exception ex)
            {
                Report.ReportLog("Error replacing morphs: " + ex.Message);
            }
        }
Esempio n. 14
0
 public void ReplaceMorph(WorkspaceMorph morph, string destMorphName, string newName, bool replaceNormals, double minSquaredDistance)
 {
     xa.ReplaceMorph(destMorphName, Parser, morph, newName, replaceNormals, (float)minSquaredDistance);
 }