private void createSlaveAnimationFromPreview(NPVoxAnimation animation, NPVoxIModelFactory inputModelFactory) { var path = NPipelineUtils.GetCreateScriptableObjectAssetPath <NPVoxAnimation>(AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GetAssetPath(inputModelFactory as Object)).name + "_" + animation.name); if (path.Length != 0) { NPVoxAnimation slaveAnimation = NPipelineUtils.CreatePipeContainer <NPVoxAnimation>(path); foreach (NPVoxFrame sourceFrame in animation.Frames) { NPVoxFrame targetFrame = slaveAnimation.AppendFrame(); NPVoxSocketAttachment attachment = sourceFrame.GetPreviewAttachmentForFactory(inputModelFactory); if (attachment == null) { Debug.LogWarning("no attachment found for the given model factory"); continue; } targetFrame.Source = inputModelFactory; NPVoxModelSocketCombiner combiner = NPVoxModelSocketCombiner.CreateInstance <NPVoxModelSocketCombiner>(); if (!sourceFrame.PreOutput) { sourceFrame.FixStuff(); } combiner.Target = sourceFrame.PreOutput; combiner.InputSocketName = attachment.sourceSocketName; combiner.TargetSocketName = attachment.targetSocketName; targetFrame.AppendTransformer(combiner); } Selection.objects = new Object[] { slaveAnimation }; } }
private void createSlaveAnimation(NPVoxAnimation animation, string targetSocket, NPVoxIModelFactory inputModelFactory, string inputSocket) { var path = NPipelineUtils.GetCreateScriptableObjectAssetPath <NPVoxAnimation>(AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GetAssetPath(inputModelFactory as Object)).name + "_" + targetSocket + "_" + animation.name); if (path.Length != 0) { NPVoxAnimation slaveAnimation = NPipelineUtils.CreatePipeContainer <NPVoxAnimation>(path); foreach (NPVoxFrame sourceFrame in animation.Frames) { NPVoxFrame targetFrame = slaveAnimation.AppendFrame(); targetFrame.Source = inputModelFactory; NPVoxModelSocketCombiner combiner = NPVoxModelSocketCombiner.CreateInstance <NPVoxModelSocketCombiner>(); if (!sourceFrame.PreOutput) { sourceFrame.FixStuff(); } combiner.Target = sourceFrame.PreOutput; combiner.InputSocketName = inputSocket; combiner.TargetSocketName = targetSocket; targetFrame.AppendTransformer(combiner); } Selection.objects = new Object[] { slaveAnimation }; } }
public static string DrawSocketSelector(string label, string previousValue, NPVoxIModelFactory modelFactory) { if (modelFactory == null) { return(previousValue); } NPVoxModel inputModel = modelFactory.GetProduct(); string[] socketNames = inputModel.SocketNames; if (inputModel) { GUILayout.BeginHorizontal(); GUILayout.Label(label); if (socketNames.Length > 0) { int previousSelected = NPipeArrayUtil.GetElementIndex(socketNames, previousValue); int newSelected = GUILayout.SelectionGrid(previousSelected, socketNames, 4); GUILayout.EndHorizontal(); if (newSelected < 0) { newSelected = 0; } return(socketNames[newSelected]); } else { GUILayout.Label("-no sockets-"); GUILayout.EndHorizontal(); } } return(previousValue); }
override public bool DrawInspector(NPipeEditFlags flags) { bool changed = base.DrawInspector(flags); NPVoxIModelFactory modelFactory = Input as NPVoxIModelFactory; if (modelFactory != null) { string[] socketNames = modelFactory.GetProduct().SocketNames; if (socketNames == null || socketNames.Length == 0) { GUILayout.Label("No Socket"); } else { string newSocketName = NPipeGUILayout.Toolbar(socketNames, socketNames, SocketName); if (SocketName != newSocketName) { SocketName = newSocketName; changed = true; } } } if (changed && (string.IsNullOrEmpty(InstanceName) || InstanceName.StartsWith("SocketT "))) { InstanceName = "SocketT " + SocketName; } return(changed); }
public void SetFrameModel(int frameIndex, NPVoxIModelFactory source) { Undo.RecordObject(animation, "change model"); NPVoxFrame frame = GetFrameAt(frameIndex); frame.Source = source; EditorUtility.SetDirty(Animation); InvalidateOutputMeshes(); }
public void MaximizeAffectedArea() { // affected area picker NPVoxIModelFactory modelFactory = SelectedFrame.Source; if (modelFactory != null) { ChangeAffectedBox(modelFactory.GetProduct().BoundingBox); } }
// =================================================================================================== // Tools // =================================================================================================== public void MaximizeAffectedArea() { // affected area picker NPVoxIModelFactory modelFactory = Input as NPVoxIModelFactory; if (modelFactory != null) { ChangeAffectedArea(modelFactory.GetProduct().BoundingBox); } }
public string[] GetSourceSocketsForTargetSocket(string targetSocketName) { NPVoxIModelFactory modelFactory = GetPreviewModelFactoryForTargetSocket(targetSocketName); if (modelFactory != null) { NPVoxModel model = modelFactory.GetProduct(); return(model.SocketNames); } return(null); }
public NPVoxIMeshFactory GetSocketPreviewMeshFactoryForCurrentFrame(string targetSocketName) { NPVoxSocketAttachment p = SelectedFrame.GetPreviewAttachmentForTargetSocket(targetSocketName); if (this.selectedFrameIndex < 0 || p == null) { return(null); } NPVoxIModelFactory modelFactory = GetPreviewModelFactoryForTargetSocket(targetSocketName); string inputSocketName = p.sourceSocketName; if (p.outputMeshFactory == null) { NPVoxIMeshFactory meshFactory = GetPreviewFactoryForTargetSocket(targetSocketName); if (meshFactory == null) { return(null); } NPVoxModelSocketCombiner combiner = NPVoxModelCombiner.CreateInstance <NPVoxModelSocketCombiner>(); combiner.Input = modelFactory; combiner.InputSocketName = inputSocketName; combiner.TargetSocketName = targetSocketName; combiner.ResolveConflictMethod = NPVoxModelTransformationUtil.ResolveConflictMethodType.FILL_GAPS; combiner.Target = (UnityEngine.Object)SelectedFrame.PreOutput.Input; combiner.StorageMode = NPipeStorageMode.MEMORY; NPVoxMeshOutput previewFactory = (NPVoxMeshOutput)meshFactory.Clone(); previewFactory.StorageMode = NPipeStorageMode.MEMORY; previewFactory.Input = combiner; p.outputMeshFactory = previewFactory; } else { NPVoxModelSocketCombiner combiner = ((NPVoxModelSocketCombiner)((NPVoxMeshOutput)p.outputMeshFactory).Input); // check if something changed in the meanwhipe if (combiner.Target != TotalModelFactory as UnityEngine.Object || combiner.InputSocketName != inputSocketName) { p.outputMeshFactory.Invalidate(); combiner.Target = (UnityEngine.Object)TotalModelFactory; combiner.InputSocketName = inputSocketName; combiner.Invalidate(); } } return(p.outputMeshFactory); }
override public Vector3 GetPivot() { NPVoxIModelFactory modelFactory = (Input as NPVoxIModelFactory); if (modelFactory != null) { NPVoxSocket socket = modelFactory.GetProduct().GetSocketByName(SocketName); return(this.PivotOffset + NPVoxCoordUtil.ToVector(socket.Anchor)); } else { return(Vector3.zero); } }
override public void SetPivot(Vector3 pivot) { NPVoxIModelFactory modelFactory = (Input as NPVoxIModelFactory); if (modelFactory != null) { NPVoxSocket socket = modelFactory.GetProduct().GetSocketByName(SocketName); this.PivotOffset = pivot - NPVoxCoordUtil.ToVector(socket.Anchor); } else { this.PivotOffset = Vector3.zero; } }
override public Quaternion GetRotation() { if (Absolute) { NPVoxIModelFactory modelFactory = (Input as NPVoxIModelFactory); if (modelFactory != null && quaternionReadFromSocketName != SocketName) { quaternionReadFromSocketName = SocketName; NPVoxSocket socket = modelFactory.GetProduct().GetSocketByName(SocketName); Matrix = Matrix4x4.TRS(GetTranslation(), Quaternion.Euler(socket.EulerAngles), Vector3.one); } } return(Matrix4x4Util.GetRotation(Matrix)); }
public NPVoxSocketAttachment GetPreviewAttachmentForFactory(NPVoxIModelFactory factory) { if (previewAttachments == null) { previewAttachments = new NPVoxSocketAttachment[] {} } ; foreach (NPVoxSocketAttachment previewSocket in previewAttachments) { if (previewSocket.meshFactory != null && previewSocket.meshFactory.Input == factory) { return(previewSocket); } } return(null); }
private void DrawSockets(bool isEditing) { NPVoxIModelFactory modelFactory = viewModel.EditorModelFactory; if (!viewModel.DrawSockets) { return; } if (modelFactory != null) { NPVoxModel model = modelFactory.GetProduct(); NPVoxToUnity npVoxToUnity = new NPVoxToUnity(model, viewModel.Animation.MeshFactory.VoxelSize); if (model) { foreach (NPVoxSocket socket in model.Sockets) { Vector3 anchorPos = npVoxToUnity.ToUnityPosition(socket.Anchor); Quaternion rotation = Quaternion.Euler(socket.EulerAngles); Vector3 anchorRight = npVoxToUnity.ToUnityDirection(rotation * Vector3.right); Vector3 anchorUp = npVoxToUnity.ToUnityDirection(rotation * Vector3.up); Vector3 anchorForward = npVoxToUnity.ToUnityDirection(rotation * Vector3.forward); Vector3 position = Vector3.zero; float size = 2.5f; if (!isEditing) { Handles.color = new Color(0.5f, 1.0f, 0.1f, 0.5f); Handles.CubeCap(0, position + anchorPos, rotation, 0.125f); size = 10.0f; } Handles.color = Color.red; Handles.DrawLine(position + anchorPos, position + anchorPos + anchorRight * size); Handles.color = Color.green; Handles.DrawLine(position + anchorPos, position + anchorPos + anchorUp * size); Handles.color = Color.blue; Handles.DrawLine(position + anchorPos, position + anchorPos + anchorForward * size); } } } }
private void DrawModelSelection() { if (viewModel.SelectedFrame == null) { return; } viewModel.SelectedFrame.Duration = EditorGUILayout.FloatField("Duration", viewModel.SelectedFrame.Duration); GUILayout.BeginHorizontal(); // GUILayout.Label("Frame " + ( viewModel.SelectedFrameIndex + 1 ) + " : "); // NPVoxModelPipeBase modelFactory = (NPVoxModelPipeBase)EditorGUILayout.ObjectField(viewModel.SelectedFrame.Source, typeof(NPVoxModelPipeBase), false); NPVoxIModelFactory modelFactory = (NPVoxIModelFactory)NPipelineUtils.DrawSourceSelector <NPVoxIModelFactory>("Source", viewModel.SelectedFrame.Source); if (modelFactory != viewModel.SelectedFrame.Source) { viewModel.SetFrameModel(viewModel.SelectedFrameIndex, modelFactory); } GUILayout.EndHorizontal(); }
public override void OnInspectorGUI() { GUIStyle boldStyle = new GUIStyle(); boldStyle.fontStyle = FontStyle.Bold; NPVoxAnimation animation = (NPVoxAnimation)target; GUILayout.Label("NPVox Animation: " + animation.name); GUILayout.Label("Tools:"); GUILayout.BeginHorizontal(); if (GUILayout.Button("Invalidate & Reimport All")) { NPipelineUtils.InvalidateAndReimportAll(animation); } if (GUILayout.Button("Invalidate & Reimport All Deep")) { NPipelineUtils.InvalidateAndReimportAllDeep(animation); } GUILayout.EndHorizontal(); if (GUILayout.Button("Edit Animation")) { OpenAnimationScene(animation); } if (animation.Frames != null && animation.Frames.Length > 0 && animation.Frames[0].Source != null) { NPVoxModel model = animation.Frames[0].Source.GetProduct(); if (model != null && model.SocketNames.Length > 0) { EditorGUILayout.BeginHorizontal(); selectedTargetSocket = NPipeGUILayout.Popup(model.SocketNames, model.SocketNames, selectedTargetSocket, true); selectedModelFactory = NPipelineUtils.DrawSourceSelector <NPVoxIModelFactory>("Input:", selectedModelFactory); if (selectedModelFactory != null && selectedModelFactory.GetProduct()) { selectedInputSocket = NPipeGUILayout.Popup(selectedModelFactory.GetProduct().SocketNames, selectedModelFactory.GetProduct().SocketNames, selectedInputSocket, true); } if (GUILayout.Button("Create Slave Animation") && selectedModelFactory != null) { createSlaveAnimation(animation, selectedTargetSocket, selectedModelFactory, selectedInputSocket); } if (GUILayout.Button("Create Slave Animation From Preview") && selectedModelFactory != null) { createSlaveAnimationFromPreview(animation, selectedModelFactory); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.Space(); EditorGUILayout.Space(); GUILayout.Label("Animation Default Settings", boldStyle); DrawDefaultInspector(); EditorGUILayout.Space(); EditorGUILayout.Space(); // Mesh Output Settings GUILayout.Label("Mesh Output Settings", boldStyle); if (animation.MeshFactory.DrawInspector(~NPipeEditFlags.TOOLS & ~NPipeEditFlags.INPUT)) { // Cascade to all frames foreach (NPVoxFrame frame in animation.Frames) { frame.Output.BloodColorIndex = animation.MeshFactory.BloodColorIndex; frame.Output.Cutout = animation.MeshFactory.Cutout; frame.Output.Loop = animation.MeshFactory.Loop; frame.Output.NormalMode = animation.MeshFactory.NormalMode; frame.Output.NormalVariance = animation.MeshFactory.NormalVariance; frame.Output.NormalVarianceSeed = animation.MeshFactory.NormalVarianceSeed; frame.Output.VoxelSize = animation.MeshFactory.VoxelSize; frame.Output.StorageMode = animation.MeshFactory.StorageMode; frame.Output.MinVertexGroups = animation.MeshFactory.MinVertexGroups; frame.Output.NormalModePerVoxelGroup = animation.MeshFactory.NormalModePerVoxelGroup; } } // Destroy unconnected things NPipeIImportable[] importables = NPipelineUtils.GetImportables(AssetDatabase.GetAssetPath(animation)); foreach (NPipeIImportable importable in importables) { NPipeIImportable prev = NPipelineUtils.FindPreviousOfType <NPVoxIModelFactory>(importable); if ((importable as NPVoxMeshOutput) != animation.MeshFactory && (prev == null || prev == importable)) { Debug.LogWarning("Destroying orphaning importable: " + importable); if (importable is NPipeIComposite) { ((NPipeIComposite)importable).Input = null; } importable.Destroy(); // destroy the product Undo.DestroyObjectImmediate((UnityEngine.Object)importable); } } }
public bool IsSkeletonTransformerAppendable() { NPVoxIModelFactory factory = EditorModelFactory as NPVoxIModelFactory; return(factory != null && (factory.GetProduct() is NPVoxBoneModel)); }