public void ProcessInvalidations(bool force = false) { if (force || (invalidationRequestedAt > 0 && EditorApplication.timeSinceStartup - invalidationRequestedAt > 0.1f)) { frame = null; invalidationRequestedAt = 0; if (invalidatedTransformation != null) { if (editorModelFactorySource == invalidatedTransformation as NPVoxIModelFactory) { EditorModelFactory.Invalidate(); } SelectedFrame.InvalidateTransformation(invalidatedTransformation); invalidatedTransformation = null; } if (ModelMarker != null) { ModelMarker.Invalidate(); } PreviewMeshOutput.Invalidate(); invalidatePreviewMeshFactories(); FireOnMeshChange(); } else { if (invalidationRequestedAt > 0) { if (OnCheckForInvalidation != null) { OnCheckForInvalidation(); } } } }
public void InvalidateTransformation(NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> transformer) { if (transformer != null) { InvalidateFromStep(GetTransformerIndex(transformer) + 1); } }
public void MoveTransformer(int index, int deltaIndex) { Undo.RecordObject(animation, "Moving a transformer"); NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> target = GetTransformer(index); NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> swapWith = GetTransformer(index + deltaIndex); if (swapWith == null) { return; } if (Mathf.Abs(deltaIndex) > 1) { Debug.LogError("deltaIndex > 1 not supported yet"); return; } if (index + deltaIndex < 0) { Debug.LogWarning("Cannot move beofre index 0"); return; } if (index + deltaIndex >= transformers.Length) { Debug.LogWarning("Cannot move after end"); return; } ArrayUtility.RemoveAt(ref transformers, index + deltaIndex); ArrayUtility.Insert(ref transformers, index, swapWith); Undo.RecordObject(swapWith, "Moving a transformer"); Undo.RecordObject(target, "Moving a transformer"); if (index + deltaIndex < index) { target.Input = swapWith.Input; swapWith.Input = target; if (Transformers.Length > index + 1) { Undo.RecordObject(Transformers[index + 1], "Moving a transformer"); Transformers[index + 1].Input = swapWith; } } else { swapWith.Input = target.Input; target.Input = swapWith; if (Transformers.Length > index + deltaIndex + 1) { Undo.RecordObject(Transformers[index + deltaIndex + 1], "Moving a transformer"); Transformers[index + deltaIndex + 1].Input = target; } } Undo.RecordObject(preOutput, "Moving a transformer"); preOutput.Input = (NPipeIImportable)transformers[transformers.Length - 1]; InvalidateFromStep(Mathf.Min(index + deltaIndex, index)); }
public void AddTransformer(System.Type type) { Undo.RecordObjects(new Object[] { this, animation }, "Add Misc Transformer "); NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> transformer = UnityEngine.ScriptableObject.CreateInstance(type) as NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel>; int index = SelectedFrame.AddTransformerAt(transformer, selectedTransformationIndex); InvalidateOutputMeshes(); SelectTransformation(index, true); }
public void DuplicateTransformation(int index) { NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> transformer = this.Transformers[index] as NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel>; this.AddTransformation(transformer); int iIndex = this.Transformers.Length - 1; while (iIndex != index + 1) { MoveTransformation(iIndex, -1); iIndex--; } SelectTransformation(iIndex, true); }
public void InvalidateOutputMeshes(NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> transform = null, bool immediateRefresh = false) { if (frame != null && frame != SelectedFrame) { ProcessInvalidations(true); } if (invalidatedTransformation != null && invalidatedTransformation != transform) { ProcessInvalidations(true); } invalidatedTransformation = transform; frame = SelectedFrame; invalidationRequestedAt = invalidationRequestedAt < 1 ? EditorApplication.timeSinceStartup : invalidationRequestedAt; ProcessInvalidations(!DelayedRefreshEnabled || immediateRefresh); }
public void Paste() { if (HasTransformationToPaste()) { NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> transformer = ClipboardContent as NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel>; this.AddTransformation(transformer); } if (HasFrameToPaste()) { NPVoxFrame frame = ClipboardContent as NPVoxFrame; Undo.RecordObjects(new Object[] { this, animation }, "Add frame from clipboard at " + selectedFrameIndex); animation.AddFrameAt(selectedFrameIndex, frame); SelectFrame(selectedFrameIndex, true); } }
public void SelectAnimation(NPVoxAnimation animation) { if (this.animation != animation) { this.animation = animation; DestroyImmediate(previewMeshOutput as UnityEngine.Object); previewMeshOutput = null; DestroyImmediate(editorModelFactory as UnityEngine.Object); editorModelFactory = null; DestroyImmediate(modelMarker); modelMarker = null; cachedMesh = null; SetCurrentTool(Tool.NONE); InvalidateOutputMeshes(); wipePreviewMeshFactories(); SelectFrame(0, true); } }
public int AddTransformerAt(NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> factory, int index) { Undo.RecordObject(animation, "created a new transformer"); if (index == -1 || index >= transformers.Length) { index = transformers.Length; } else { index = index + 1; } factory.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(factory, AssetDatabase.GetAssetPath(animation)); ArrayUtility.Insert(ref transformers, index, factory); // Undo.RecordObject(factory, "created a new transformer"); if (index == 0) { factory.Input = Source; } else { factory.Input = Transformers[index - 1]; } if (index < Transformers.Length - 1) { Undo.RecordObject(Transformers[index + 1], "Moving a transformer"); Transformers[index + 1].Input = factory; } Undo.RegisterCreatedObjectUndo(factory, "created a new transformer"); Undo.RecordObject(preOutput, "created a new transformer"); preOutput.Input = Transformers[transformers.Length - 1]; InvalidateFromStep(transformers.Length); return(index); }
public void DestroyTransformer(int index) { Undo.RecordObject(animation, "Destroying a transformer"); NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> transformer = GetTransformer(index); if (!transformer) { Debug.LogError("Transformer not found"); return; } ArrayUtility.RemoveAt(ref transformers, index); Undo.RecordObject(output, "Destroying a transformer"); if (transformers.Length > 0) { preOutput.Input = Transformers[transformers.Length - 1]; } else { preOutput.Input = Source; } // preOutput.Invalidate(); if (index < Transformers.Length) { Undo.RecordObject(Transformers[index], "Destroying a transformer"); if (index > 0) { Transformers[index].Input = Transformers[index - 1]; } else { Transformers[index].Input = Source; } } transformer.Destroy(); Undo.DestroyObjectImmediate(transformer); InvalidateFromStep(index + 1); }
public void PrependTransformer(NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> factory) { Undo.RecordObject(animation, "created a new transformer"); factory.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(factory, AssetDatabase.GetAssetPath(animation)); ArrayUtility.Insert(ref this.transformers, 0, factory); Undo.RecordObject(factory, "created a new transformer"); Undo.RecordObject(Transformers[1], "created a new transformer"); factory.Input = Source; if (this.transformers.Length > 1) { Transformers[1].Input = factory; } Undo.RegisterCreatedObjectUndo(factory, "created a new transformer"); Undo.RecordObject(output, "created a new transformer"); preOutput.Input = Transformers[transformers.Length - 1]; InvalidateFromStep(0); }
public void AddTransformation(NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> template = null) { Undo.RecordObjects(new Object[] { this, animation }, "Add Transformation "); NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> transformer; if (template != null) { transformer = (NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel>)template.Clone(); } else { transformer = (NPVoxModelTransformer)NPVoxModelTransformer.CreateInstance(typeof(NPVoxModelTransformer)); if (this.CurrentModelFactory != null && ((NPVoxModelTransformer)transformer)) { NPVoxModel model = this.CurrentModelFactory.GetProduct(); UnityEngine.Assertions.Assert.IsNotNull(model); ((NPVoxModelTransformer)transformer).AffectedArea = NPVoxBox.FromCenterSize(model.BoundingBox.RoundedCenter, new NPVoxCoord(3, 3, 3)); } } SelectedFrame.AppendTransformer(transformer); InvalidateOutputMeshes(); SelectTransformation(Transformers.Length - 1, true); this.SetCurrentTool(Tool.AREA); }
public NPVoxFrame DeepCopy(NPVoxAnimation targetAnimation) { NPVoxFrame other = new NPVoxFrame(targetAnimation); other.source = this.source; other.preOutput.Input = other.Source; other.previewAttachments = new NPVoxSocketAttachment[this.previewAttachments.Length]; for (int i = 0; i < other.previewAttachments.Length; i++) { other.previewAttachments[i] = new NPVoxSocketAttachment(); other.previewAttachments[i].meshFactory = this.previewAttachments[i].meshFactory; other.previewAttachments[i].sourceSocketName = this.previewAttachments[i].sourceSocketName; other.previewAttachments[i].targetSocketName = this.previewAttachments[i].targetSocketName; other.previewAttachments[i].visible = this.previewAttachments[i].visible; } foreach (NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> modelFactory in this.transformers) { NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> clonedFactory = (NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel>)modelFactory.Clone(); other.AppendTransformer(clonedFactory); } return(other); }
public int GetTransformerIndex(NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> transformer) { return(ArrayUtility.IndexOf(transformers, transformer)); }
public void AppendTransformer(NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> factory) { AddTransformerAt(factory, -1); }
private void DrawTransformationSelector() { NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel>[] transformers = viewModel.Transformers; if (transformers == null) { return; } GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout); GUIStyle foldoutSelectedStyle = new GUIStyle(foldoutStyle); GUIStyle labelStyle = new GUIStyle(EditorStyles.label); GUIStyle labelSelectedStyle = new GUIStyle(labelStyle); GUIStyle deleteStyle = new GUIStyle(EditorStyles.miniButtonMid); deleteStyle.fixedWidth = 70; foldoutSelectedStyle.fontStyle = FontStyle.Bold; labelSelectedStyle.fontStyle = FontStyle.Bold; for (int i = 0; i < transformers.Length; i++) { NPVoxCompositeProcessorBase <NPVoxIModelFactory, NPVoxModel> transformer = transformers[i]; GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); bool isSelected = i == viewModel.SelectedTransformationIndex; bool somethingSelected = viewModel.SelectedTransformationIndex != -1; bool isSelectedOrLast = isSelected || (!somethingSelected && i == transformers.Length - 1); string name = transformer.GetInstanceName(); if (name == null || name.Length < 1) { name = transformer.GetTypeName(); } GUILayout.Label((i + 1) + (isSelectedOrLast ? "|A" : ""), isSelected ? labelSelectedStyle : labelStyle, GUILayout.Width(30)); if (isSelected != EditorGUILayout.Foldout(isSelected, name, isSelected ? foldoutSelectedStyle : foldoutStyle)) { if (isSelected) { viewModel.SelectTransformation(-1); unfocus(); } else { viewModel.SelectTransformation(i); } } GUILayout.Space(100); if (GUILayout.Button("Delete" + (isSelectedOrLast ? " (" + HOTKEY_DELETE_LAST_TRANSFOMRATION.ToString() + ")" : ""), deleteStyle)) { viewModel.RemoveTransformationAt(i); } else if (GUILayout.Button("Copy", EditorStyles.miniButtonMid)) { viewModel.CopyTransformation(i); } if (isSelected) { if (NPVoxGUILayout.HotkeyButton(new GUIContent("Up", "Move Up"), HOTKEY_MOVE_TRANSFORMATION_UP, false, false, false, EditorStyles.miniButtonMid)) { viewModel.MoveTransformation(i, -1); } if (NPVoxGUILayout.HotkeyButton(new GUIContent("Down", "Move Down"), HOTKEY_MOVE_TRANSFORMATION_DOWN, false, false, false, EditorStyles.miniButtonMid)) { viewModel.MoveTransformation(i, +1); } if (NPVoxGUILayout.HotkeyButton(new GUIContent("Duplicate", "Duplicate"), DUPLICATE_TRANSFORMATION, false, false, false, EditorStyles.miniButtonMid)) { viewModel.DuplicateTransformation(i); } } else { if (GUILayout.Button(new GUIContent("Up", "Move Up"), EditorStyles.miniButtonMid)) { viewModel.MoveTransformation(i, -1); } if (GUILayout.Button(new GUIContent("Down", "Move Down"), EditorStyles.miniButtonRight)) { viewModel.MoveTransformation(i, +1); } } GUILayout.EndHorizontal(); if (isSelected && viewModel.SelectedTransformer != null) { GUILayout.BeginHorizontal(); { EditorGUILayout.Space(); GUILayout.BeginVertical(); { EditorGUILayout.Space(); if (viewModel.SelectedTransformer is NPVoxISceneEditable) { DrawTransformationToolbar(); } { if (viewModel.SelectedTransformer.DrawInspector(~NPipeEditFlags.TOOLS & ~NPipeEditFlags.INPUT & ~NPipeEditFlags.STORAGE_MODE)) { GUI.changed = true; viewModel.SelectedTransformerChanged(); viewModel.RegeneratePreview(); // GUI.changed = true; // TODO: is this still needed? } } EditorGUILayout.Space(); EditorGUILayout.Space(); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } GUILayout.BeginHorizontal(); if (NPVoxGUILayout.HotkeyButton("+ New T", HOTKEY_APPEND_TRANSFORMATION)) { viewModel.AddTransformation(); } if (viewModel.IsSkeletonBuilderAppendable() && GUILayout.Button("+ Skeleton")) { viewModel.AddSkeletonBuilder(); } if (viewModel.IsSkeletonTransformerAppendable() && NPVoxGUILayout.HotkeyButton("+ SkeletonT", HOTKEY_APPEND_BONETRANSFORMATION)) { viewModel.AddSkeletonTransformer(); } if (GUILayout.Button("+ Mirror")) { viewModel.AddMirrorTransformators(); } // if (GUILayout.Button("+ Combiner")) // { // viewModel.AddSocketCombiner(); // } // if (GUILayout.Button("+ SocketT")) // { // viewModel.AddSocketTransformer(); // } List <System.Type> allTypes = new List <System.Type>(NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeAppendableAttribute))); List <string> allLabels = new List <string>(); allLabels.Add("Other ..."); foreach (System.Type factoryType in allTypes) { NPipeAppendableAttribute attr = (NPipeAppendableAttribute)factoryType.GetCustomAttributes(typeof(NPipeAppendableAttribute), true)[0]; if (!attr.sourceType.IsAssignableFrom(typeof(NPVoxIModelFactory))) { continue; } allLabels.Add(attr.name); } int selection = EditorGUILayout.Popup(0, allLabels.ToArray()); if (selection > 0) { viewModel.AddTransformer(allTypes[selection - 1]); } if (viewModel.HasTransformationToPaste() && GUILayout.Button("+ Paste")) { viewModel.Paste(); } GUILayout.EndHorizontal(); }