private void ApplyNormalStage() { NPVoxModel voxModel = m_context.MeshOutput.GetVoxModel(); Vector3[] normals = m_context.PreviewMesh.normals; NPVoxNormalProcessor_UserOverride processor = ( NPVoxNormalProcessor_UserOverride )m_context.ViewedProcessor; foreach (NPVoxMeshData vox in m_context.MeshOutput.GetVoxMeshData()) { if (!vox.isHidden) { NPVoxCoord coord = vox.voxCoord; int index = voxModel.GetIndex(coord); if (GetSelection(coord) == SELECTED_TARGET) { processor.m_overrideNormalsRT[vox.voxCoord] = m_normalStage[index]; for (int i = 0; i < vox.numVertices; i++) { normals[vox.vertexIndexOffsetBegin + i] = m_normalStage[index]; } } } } RemoveRedundantOverrides(); UnityEditor.EditorUtility.SetDirty(processor); m_context.PreviewMesh.normals = normals; }
private void RemoveRedundantOverrides() { List <NPVoxCoord> overridesToRemove = new List <NPVoxCoord>(); NPVoxNormalProcessor_UserOverride processor = ( NPVoxNormalProcessor_UserOverride )m_context.ViewedProcessor; NPVoxNormalProcessor previous = m_context.MeshOutput.NormalProcessors.GetPreviousInList(processor); foreach (NPVoxMeshData vox in m_context.MeshOutput.GetVoxMeshData()) { if (!vox.isHidden) { Vector3 normal = Vector3.zero; if (previous != null) { normal = previous.GetOutput()[vox.vertexIndexOffsetBegin]; } if (processor.m_overrideNormalsRT.ContainsKey(vox.voxCoord) && processor.m_overrideNormalsRT[vox.voxCoord] == normal) { overridesToRemove.Add(vox.voxCoord); } } } foreach (NPVoxCoord i in overridesToRemove) { processor.m_overrideNormalsRT.Remove(i); } }
public override object Clone() { NPVoxNormalProcessor_UserOverride clone = ScriptableObject.CreateInstance <NPVoxNormalProcessor_UserOverride>(); foreach (int filter in m_voxelGroupFilter) { clone.m_voxelGroupFilter.Add(filter); } return(clone); }
protected override void DrawSceneInternal(Rect _rect) { if (m_context.ViewedProcessor.IsOutputValid()) { NPVoxNormalProcessor_UserOverride processor = (NPVoxNormalProcessor_UserOverride)m_context.ViewedProcessor; Vector3 voxSize = m_context.MeshOutput.VoxelSize; Vector3 voxExtent = voxSize * 0.5f; Vector3 v1 = new Vector3(voxSize.x, 0, 0); Vector3 v2 = new Vector3(0, voxSize.y, 0); Vector3 v3 = new Vector3(0, 0, voxSize.z); NPVoxMeshData[] voxMeshData = m_context.MeshOutput.GetVoxMeshData(); foreach (NPVoxMeshData vox in voxMeshData) { if (!vox.isHidden) { Vector3 voxPosition = new Vector3(vox.voxelCenter.x, vox.voxelCenter.y, vox.voxelCenter.z); if (m_previewHighlightOverrides && processor.m_overrideNormalsRT.ContainsKey(vox.voxCoord)) { NPipeGL.DrawParallelepiped(voxPosition - voxExtent, v1, v2, v3, new Color(0.5f, 0.0f, 0.0f)); } sbyte selection = GetSelection(vox.voxCoord); if (selection != UNSELECTED) { NPipeGL.DrawParallelepiped(voxPosition - voxExtent, v1, v2, v3, selection == SELECTED_TARGET ? Color.red : Color.green); } if (vox.voxCoord.Equals(m_lastSelected)) { m_lastSelectedData = vox; } } } } }
protected override void OnGUIInternal() { GUIStyle noStretch = new GUIStyle(); noStretch.stretchWidth = false; noStretch.stretchHeight = false; GUILayoutOption widthSmallButton = GUILayout.Width(65); GUILayoutOption widthWideButton = GUILayout.Width(203); GUILayoutOption[] noFill = { GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false) }; GUILayoutOption[] fill = { GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true) }; Color bgColorWarning = new Color(0.8f, 0.3f, 0.3f); Color bgColorTarget = new Color(0.9f, 0.4f, 0.4f); Color bgColorInput = new Color(0.5f, 0.7f, 0.9f); if (m_context.ViewedProcessor.IsOutputValid()) { if (GUILayout.Button(m_previewHighlightOverrides ? "Unhighlight Overrides" : "Highlight Overrides", widthWideButton)) { m_previewHighlightOverrides = !m_previewHighlightOverrides; } GUILayout.Space(8.0f); // Last selected voxel info GUILayout.Space(12.0f); string selectedCoord = "-"; string selectedNormalX = "-"; string selectedNormalY = "-"; string selectedNormalZ = "-"; string selectedVIndex = "-"; if (m_lastSelected.Valid && m_lastSelectedData != null) { selectedCoord = m_lastSelected.X + " " + m_lastSelected.Y + " " + m_lastSelected.Z; selectedVIndex = m_lastSelectedData.vertexIndexOffsetBegin.ToString(); Vector3 normal = m_context.PreviewMesh.normals[m_lastSelectedData.vertexIndexOffsetBegin]; selectedNormalX = normal.x.ToString(); selectedNormalY = normal.y.ToString(); selectedNormalZ = normal.z.ToString(); } int labelWidth = 65, columnWidth = 150, columnSpace = -5; GUILayout.Label("Last Selected:", noFill); NPipeGUILayout.TableRow("Coord:", labelWidth, columnSpace, new NPipeGUILayout.TableColumn(selectedCoord, columnWidth)); NPipeGUILayout.TableRow("v-Index:", labelWidth, columnSpace, new NPipeGUILayout.TableColumn(selectedVIndex, columnWidth)); NPipeGUILayout.TableRow("Normal X:", labelWidth, columnSpace, new NPipeGUILayout.TableColumn(selectedNormalX, columnWidth)); NPipeGUILayout.TableRow("Normal Y:", labelWidth, columnSpace, new NPipeGUILayout.TableColumn(selectedNormalY, columnWidth)); NPipeGUILayout.TableRow("Normal Z:", labelWidth, columnSpace, new NPipeGUILayout.TableColumn(selectedNormalZ, columnWidth)); GUILayout.Space(12.0f); // General selection related controls if (GUILayout.Button("RESET SELECTION (Esc)", widthWideButton)) { ResetSelection(); } // Input field related controls Color currentColor = GUI.backgroundColor; GUI.backgroundColor = bgColorInput; GUILayout.Label("INPUT:", noFill); GUILayout.Space(-3); m_normalField = EditorGUILayout.Vector3Field("", m_normalField, noFill); GUILayout.Space(-3); GUILayout.BeginHorizontal(noStretch, noFill); if (GUILayout.Button("RIGHT", widthSmallButton)) { m_normalField = Vector3.right; } if (GUILayout.Button("UP", widthSmallButton)) { m_normalField = Vector3.up; } if (GUILayout.Button("FWD", widthSmallButton)) { m_normalField = Vector3.forward; } GUILayout.EndHorizontal(); GUILayout.Space(-4); GUILayout.BeginHorizontal(noStretch, noFill); if (GUILayout.Button("LEFT", widthSmallButton)) { m_normalField = Vector3.left; } if (GUILayout.Button("DOWN", widthSmallButton)) { m_normalField = Vector3.down; } if (GUILayout.Button("BACK", widthSmallButton)) { m_normalField = Vector3.back; } GUILayout.EndHorizontal(); GUILayout.Space(-4); GUILayout.BeginHorizontal(noStretch, noFill); if (GUILayout.Button("Normalize", widthWideButton)) { m_normalField = m_normalField.normalized; } GUILayout.EndHorizontal(); GUILayout.Label("APPLY TO INPUT:", noFill); if (GUILayout.Button("Source (Q)", widthWideButton)) { Handle_SourceToInput(); } GUI.backgroundColor = currentColor; // Target selection related controls GUILayout.Space(12.0f); currentColor = GUI.backgroundColor; GUI.backgroundColor = bgColorTarget; GUILayout.Label("APPLY TO TARGET:", noFill); if (GUILayout.Button("Input Field (W)", widthWideButton)) { Handle_InputToTarget(); } if (GUILayout.Button("Source (S)", widthWideButton)) { Handle_SourceToTarget(); } if (GUILayout.Button("Source + Input Field (X)", widthWideButton)) { Handle_SourceInputToTarget(); } GUI.backgroundColor = currentColor; GUILayout.Space(12.0f); // Reset override functions GUILayout.BeginVertical(GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)); GUILayout.EndVertical(); if (GUILayout.Button("RESET SELECTED OVERRIDES", widthWideButton)) { NPVoxNormalProcessor_UserOverride processor = ( NPVoxNormalProcessor_UserOverride )m_context.ViewedProcessor; foreach (NPVoxMeshData vox in m_context.MeshOutput.GetVoxMeshData()) { if (!vox.isHidden) { sbyte selection = GetSelection(vox.voxCoord); if (selection == SELECTED_TARGET) { processor.m_overrideNormalsRT.Remove(vox.voxCoord); } } } ResetSelection(); InitMeshNormals(); } if (GUILayout.Button("RESET ALL OVERRIDES", widthWideButton)) { NPVoxNormalProcessor_UserOverride processor = ( NPVoxNormalProcessor_UserOverride )m_context.ViewedProcessor; processor.m_overrideNormalsRT.Clear(); InitMeshNormals(); } GUILayout.Space(12.0f); } else { Color currentColor = GUI.backgroundColor; GUI.backgroundColor = bgColorWarning; if (GUILayout.Button("Recalculate normals", noFill)) { InitMeshNormals(); } GUI.backgroundColor = currentColor; } }