private void treeView_AfterCheck(object sender, TreeViewEventArgs e) { if (e.Node.Tag is ImportedSubmesh) { TreeNode submeshNode = e.Node; ImportedSubmesh submesh = (ImportedSubmesh)submeshNode.Tag; TreeNode meshNode = submeshNode.Parent; DragSource dragSrc = (DragSource)meshNode.Tag; var srcEditor = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable]; srcEditor.Meshes[(int)dragSrc.Id].setSubmeshEnabled(submesh, submeshNode.Checked); } else if (e.Node.Tag is ImportedMorphKeyframe) { TreeNode keyframeNode = e.Node; ImportedMorphKeyframe keyframe = (ImportedMorphKeyframe)keyframeNode.Tag; TreeNode morphNode = keyframeNode.Parent; DragSource dragSrc = (DragSource)morphNode.Tag; var srcEditor = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable]; srcEditor.Morphs[(int)dragSrc.Id].setMorphKeyframeEnabled(keyframe, keyframeNode.Checked); } else if (e.Node.Tag is ImportedAnimationTrack) { TreeNode trackNode = e.Node; ImportedAnimationTrack track = (ImportedAnimationTrack)trackNode.Tag; TreeNode animationNode = trackNode.Parent; DragSource dragSrc = (DragSource)animationNode.Tag; var srcEditor = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable]; srcEditor.Animations[(int)dragSrc.Id].setTrackEnabled(track, trackNode.Checked); } }
public string getMorphKeyframeNewName(ImportedMorphKeyframe keyframe) { AdditionalMorphKeyframeOptions options; if (this.MorphKeyframeOptions.TryGetValue(keyframe, out options)) { return(options.NewName != null ? options.NewName : String.Empty); } throw new Exception("Morph keyframe not found"); }
public bool isMorphKeyframeEnabled(ImportedMorphKeyframe keyframe) { AdditionalMorphKeyframeOptions options; if (this.MorphKeyframeOptions.TryGetValue(keyframe, out options)) { return(options.Enabled); } throw new Exception("Morph keyframe not found"); }
private void UpdateMorphKeyframeNode(TreeNode node) { ImportedMorphKeyframe keyframe = (ImportedMorphKeyframe)node.Tag; TreeNode morphNode = node.Parent; DragSource dragSrc = (DragSource)morphNode.Tag; var srcEditor = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable]; string newName = srcEditor.Morphs[(int)dragSrc.Id].getMorphKeyframeNewName(keyframe); node.Text = "Morph: " + keyframe.Name + (newName != String.Empty ? ", Rename to: " + newName : null); }
public void setMorphKeyframeNewName(ImportedMorphKeyframe keyframe, string newName) { AdditionalMorphKeyframeOptions options; if (this.MorphKeyframeOptions.TryGetValue(keyframe, out options)) { options.NewName = newName; return; } throw new Exception("Morph keyframe not found"); }
public void setMorphKeyframeEnabled(ImportedMorphKeyframe keyframe, bool enabled) { AdditionalMorphKeyframeOptions options; if (this.MorphKeyframeOptions.TryGetValue(keyframe, out options)) { options.Enabled = enabled; return; } throw new Exception("Morph keyframe not found"); }
private void contextMenuStripMorphKeyframe_Opening(object sender, CancelEventArgs e) { Point contextLoc = new Point(contextMenuStripMorphKeyframe.Left, contextMenuStripMorphKeyframe.Top); Point relativeLoc = treeView.PointToClient(contextLoc); TreeNode morphKeyframeNode = treeView.GetNodeAt(relativeLoc); ImportedMorphKeyframe keyframe = (ImportedMorphKeyframe)morphKeyframeNode.Tag; TreeNode morphNode = morphKeyframeNode.Parent; DragSource dragSrc = (DragSource)morphNode.Tag; var srcEditor = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable]; string newName = srcEditor.Morphs[(int)dragSrc.Id].getMorphKeyframeNewName(keyframe); toolStripEditTextBoxNewMorphKeyframeName.Text = newName; }
private void toolStripEditTextBoxNewMorphKeyframeName_AfterEditTextChanged(object sender, EventArgs e) { Point contextLoc = new Point(contextMenuStripMorphKeyframe.Left, contextMenuStripMorphKeyframe.Top); Point relativeLoc = treeView.PointToClient(contextLoc); TreeNode morphKeyframeNode = treeView.GetNodeAt(relativeLoc); ImportedMorphKeyframe keyframe = (ImportedMorphKeyframe)morphKeyframeNode.Tag; TreeNode morphNode = morphKeyframeNode.Parent; DragSource dragSrc = (DragSource)morphNode.Tag; var srcEditor = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable]; string newName = toolStripEditTextBoxNewMorphKeyframeName.Text; srcEditor.Morphs[(int)dragSrc.Id].setMorphKeyframeNewName(keyframe, newName != String.Empty ? newName : null); UpdateMorphKeyframeNode(morphKeyframeNode); }
public ImporterMorph(string path) { try { Importer importer = new Importer(path); MorphList = new List <ImportedMorph>(); ImportedMorph morphList = new ImportedMorph(); MorphList.Add(morphList); morphList.KeyframeList = new List <ImportedMorphKeyframe>(importer.MeshList.Count); foreach (ImportedMesh meshList in importer.MeshList) { foreach (ImportedSubmesh submesh in meshList.SubmeshList) { ImportedMorphKeyframe morph = new ImportedMorphKeyframe(); morph.Name = meshList.Name; morph.VertexList = submesh.VertexList; morphList.KeyframeList.Add(morph); } } int startIdx = path.IndexOf('-') + 1; int endIdx = path.LastIndexOf('-'); if (startIdx > endIdx) { int extIdx = path.ToLower().LastIndexOf(".morph.mqo"); for (int i = extIdx - 1; i >= 0; i--) { if (!Char.IsDigit(path[i])) { endIdx = i + 1; break; } } } if ((startIdx > 0) && (endIdx > 0) && (startIdx < endIdx)) { morphList.Name = path.Substring(startIdx, endIdx - startIdx); } if (morphList.Name == String.Empty) { morphList.Name = "(no name)"; } } catch (Exception ex) { Report.ReportLog("Error importing .morphs.mqo: " + ex.Message); } }
public ImporterMorph(string path) { try { Importer importer = new Importer(path); MorphList = new List <ImportedMorph>(); ImportedMorph morphList = new ImportedMorph(); MorphList.Add(morphList); morphList.KeyframeList = new List <ImportedMorphKeyframe>(importer.MeshList.Count); ImportedSubmesh firstVisibleSubmesh = null; string firstVisibleMorph = null; foreach (ImportedMesh meshList in importer.MeshList) { int dotPos = meshList.Name.IndexOf('.'); if (dotPos >= 0 && morphList.Name == null) { morphList.Name = meshList.Name.Substring(0, dotPos); } foreach (ImportedSubmesh submesh in meshList.SubmeshList) { ImportedMorphKeyframe morph = new ImportedMorphKeyframe(); morph.Name = meshList.Name; dotPos = morph.Name.IndexOf('.'); if (dotPos >= 0) { morph.Name = morph.Name.Substring(dotPos + 1); } morph.VertexList = submesh.VertexList; morphList.KeyframeList.Add(morph); if (firstVisibleSubmesh == null && submesh.Visible) { firstVisibleSubmesh = submesh; firstVisibleMorph = meshList.Name; } } } if (firstVisibleMorph == null && importer.MeshList.Count > 0 && importer.MeshList[0].SubmeshList.Count > 0) { firstVisibleSubmesh = importer.MeshList[0].SubmeshList[0]; firstVisibleMorph = importer.MeshList[0].Name; } if (firstVisibleMorph != null) { Report.ReportLog("Building morph mask from " + firstVisibleMorph); morphList.MorphedVertexIndices = new List <ushort>(); List <ImportedVertex> vertList = firstVisibleSubmesh.VertexList; for (ushort i = 0; i < vertList.Count; i++) { if (vertList[i] is ImportedVertexWithColour) { ImportedVertexWithColour vertCol = (ImportedVertexWithColour)vertList[i]; if (vertCol.Colour.Red < 0.1 && vertCol.Colour.Green < 0.1 && vertCol.Colour.Blue > 0.9) { morphList.MorphedVertexIndices.Add(i); } } } } if (morphList.Name == null) { int startIdx = path.IndexOf('-', path.LastIndexOf('\\')) + 1; int endIdx = path.LastIndexOf('-'); if (startIdx > endIdx) { int extIdx = path.ToLower().LastIndexOf(".morph.mqo"); for (int i = extIdx - 1; i >= 0; i--) { if (!Char.IsDigit(path[i])) { endIdx = i + 1; break; } } } if ((startIdx > 0) && (endIdx > 0) && (startIdx < endIdx)) { morphList.Name = path.Substring(startIdx, endIdx - startIdx); } if (morphList.Name == String.Empty) { morphList.Name = "(no name)"; } } } catch (Exception ex) { Report.ReportLog("Error importing .morphs.mqo: " + ex.Message); } }
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); } } } } } }
public void setMorphKeyframeNewName(int morphId, int id, string newName) { ImportedMorphKeyframe keyframe = this.Morphs[morphId].KeyframeList[id]; this.Morphs[morphId].setMorphKeyframeNewName(keyframe, newName); }
public void setMorphKeyframeEnabled(int morphId, int id, bool enabled) { ImportedMorphKeyframe keyframe = this.Morphs[morphId].KeyframeList[id]; this.Morphs[morphId].setMorphKeyframeEnabled(keyframe, enabled); }
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); } } } } }
public ImporterMorph(string path, float vertexScaling) { try { Importer importer = new Importer(path, vertexScaling); MorphList = new List <ImportedMorph>(); ImportedMorph morphList = null; String lastGroup = String.Empty; ImportedSubmesh firstVisibleSubmesh = null; string firstVisibleMorph = null; foreach (ImportedMesh meshList in importer.MeshList) { int dotPos = meshList.Name.IndexOf('.'); string meshName = dotPos >= 0 ? meshList.Name.Substring(0, dotPos) : meshList.Name; int nextDot = dotPos >= 0 ? meshList.Name.IndexOf('.', dotPos + 1) : -1; String group = nextDot >= 0 ? meshList.Name.Substring(dotPos + 1, nextDot - dotPos - 1) : "unknown_blendshape"; if (group != lastGroup) { morphList = new ImportedMorph(); morphList.Name = meshName; morphList.ClipName = group; MorphList.Add(morphList); morphList.KeyframeList = new List <ImportedMorphKeyframe>(importer.MeshList.Count); morphList.Channels = new List <Tuple <float, int, int> >(importer.MeshList.Count); lastGroup = group; } foreach (ImportedSubmesh submesh in meshList.SubmeshList) { morphList.Channels.Add(new Tuple <float, int, int>(0f, morphList.KeyframeList.Count, 1)); ImportedMorphKeyframe morph = new ImportedMorphKeyframe(); morph.Name = meshList.Name; dotPos = morph.Name.LastIndexOf('.'); if (dotPos >= 0) { morph.Name = morph.Name.Substring(dotPos + 1); } morph.VertexList = submesh.VertexList; morph.Weight = 100f; morphList.KeyframeList.Add(morph); if (firstVisibleSubmesh == null && submesh.Visible) { firstVisibleSubmesh = submesh; firstVisibleMorph = meshList.Name; } } } if (firstVisibleMorph == null && importer.MeshList.Count > 0 && importer.MeshList[0].SubmeshList.Count > 0) { firstVisibleSubmesh = importer.MeshList[0].SubmeshList[0]; firstVisibleMorph = importer.MeshList[0].Name; } if (firstVisibleMorph != null) { Report.ReportLog("Building morph mask from " + firstVisibleMorph); morphList.MorphedVertexIndices = new List <ushort>(); List <ImportedVertex> vertList = firstVisibleSubmesh.VertexList; for (ushort i = 0; i < vertList.Count; i++) { if (vertList[i] is ImportedVertexWithColour) { ImportedVertexWithColour vertCol = (ImportedVertexWithColour)vertList[i]; if (vertCol.Colour.Red < 0.1 && vertCol.Colour.Green < 0.1 && vertCol.Colour.Blue > 0.9) { morphList.MorphedVertexIndices.Add(i); } } } } if (morphList.Name == null) { int startIdx = path.IndexOf('-', path.LastIndexOf('\\')) + 1; int endIdx = path.LastIndexOf('-'); if (startIdx > endIdx) { int extIdx = path.ToLower().LastIndexOf(".morph.mqo"); for (int i = extIdx - 1; i >= 0; i--) { if (!Char.IsDigit(path[i])) { endIdx = i + 1; break; } } } if ((startIdx > 0) && (endIdx > 0) && (startIdx < endIdx)) { morphList.Name = path.Substring(startIdx, endIdx - startIdx); } if (morphList.Name == String.Empty) { morphList.Name = "(no name)"; } } } catch (Exception ex) { Report.ReportLog("Error importing .morphs.mqo: " + ex.Message); } }