From 9bb4920f7a05160025b65eb09effe7016787fef7 Mon Sep 17 00:00:00 2001 From: coolcatcoder Date: Sat, 19 Nov 2022 17:48:56 +0800 Subject: [PATCH] further improvements --- Assets/Scenes/pond_testing.unity | 63 ++++------------- .../Scripts/FlexStuff/IsoSurfaceExtractor.cs | 70 ++++++++++++++++--- 2 files changed, 72 insertions(+), 61 deletions(-) diff --git a/Assets/Scenes/pond_testing.unity b/Assets/Scenes/pond_testing.unity index 8a75a6f..1b28f45 100644 --- a/Assets/Scenes/pond_testing.unity +++ b/Assets/Scenes/pond_testing.unity @@ -922,7 +922,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: CubeHalfSize: 0.5 - DistanceToCount: 0.5 + DistanceToCount: 0.25 IsoSurfaceLevel: 0 DebugCubeIndex: 0 CubeIndexBatchSize: 256 @@ -940,60 +940,21 @@ MonoBehaviour: ChaosOffSet: 0 Experimental: 0 Cells: - - Vert0: 0 - Vert1: 0 - Vert2: 0 - Vert3: 0 - Vert4: 0 - Vert5: 0 - Vert6: 0 - Vert7: 0 - Pos: + - Pos: x: 13 y: -2.25 z: -2 - CubeIndex: 0 - - Vert0: 0 - Vert1: 0 - Vert2: 0 - Vert3: 0 - Vert4: 0 - Vert5: 0 - Vert6: 0 - Vert7: 0 - Pos: - x: 13.5 - y: -2.25 - z: -2 - CubeIndex: 0 - - Vert0: 0 - Vert1: 0 - Vert2: 0 - Vert3: 0 - Vert4: 0 - Vert5: 0 - Vert6: 0 - Vert7: 0 - Pos: - x: 14 - y: -2.25 - z: -2 - CubeIndex: 0 - - Vert0: 0 - Vert1: 0 - Vert2: 0 - Vert3: 0 - Vert4: 0 - Vert5: 0 - Vert6: 0 - Vert7: 0 - Pos: - x: 14.5 - y: -2.25 - z: -2 - CubeIndex: 0 debug: 0 ChaosMultiplier: 0.5 + HandleSize: 0.2 + HandlePosition: + x: 0 + y: 0.75 + z: 0 + DuplicationExtraPosition: + x: 0 + y: 0.5 + z: 0 MeshRenderer: {fileID: 644154722} --- !u!4 &644154720 Transform: @@ -3130,7 +3091,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!199 &1663408938 ParticleSystemRenderer: serializedVersion: 6 diff --git a/Assets/Scripts/FlexStuff/IsoSurfaceExtractor.cs b/Assets/Scripts/FlexStuff/IsoSurfaceExtractor.cs index 0b8dcc2..8db6232 100644 --- a/Assets/Scripts/FlexStuff/IsoSurfaceExtractor.cs +++ b/Assets/Scripts/FlexStuff/IsoSurfaceExtractor.cs @@ -33,6 +33,9 @@ public class IsoSurfaceExtractor : MonoBehaviour public Cell[] Cells; public bool debug = false; public float ChaosMultiplier = 1; + public float HandleSize = 1; + public float3 HandlePosition; + public float3 DuplicationExtraPosition; static readonly int[] edgeTable = { 0x0 , 0x109, 0x203, 0x30a, 0x406, 0x50f, 0x605, 0x70c, @@ -617,16 +620,17 @@ public class IsoSurfaceExtractor : MonoBehaviour [Serializable] public struct Cell { - public int Vert0; - public int Vert1; - public int Vert2; - public int Vert3; - public int Vert4; - public int Vert5; - public int Vert6; - public int Vert7; + [NonSerialized] public int Vert0; + [NonSerialized] public int Vert1; + [NonSerialized] public int Vert2; + [NonSerialized] public int Vert3; + [NonSerialized] public int Vert4; + [NonSerialized] public int Vert5; + [NonSerialized] public int Vert6; + [NonSerialized] public int Vert7; public float3 Pos; - public int CubeIndex; + [NonSerialized] public int CubeIndex; + //remove all NonSerialized attributes if you need to debug these variables! } public MeshFilter MeshRenderer; @@ -1004,4 +1008,50 @@ public unsafe void FullCubesEmptiness() // ContentPosition = EditorGUI.PrefixLabel(position, label); // EditorGUI.PropertyField(ContentPosition, property.FindPropertyRelative("CubeIndex")); // } -//} \ No newline at end of file +//} + +#if UNITY_EDITOR +[CustomEditor(typeof(IsoSurfaceExtractor))] +public class IsoSurfaceExtractorEditor : Editor +{ + public void OnSceneGUI() + { + //Debug.Log("somethingworking?"); + var LO = target as IsoSurfaceExtractor; + SerializedProperty SCells = serializedObject.FindProperty("Cells"); + + Handles.color = Color.blue; + + for(int i = 0; i < SCells.arraySize; i++) + { + float3 CurrentPos = new float3( + SCells.GetArrayElementAtIndex(i).FindPropertyRelative("Pos").FindPropertyRelative("x").floatValue, + SCells.GetArrayElementAtIndex(i).FindPropertyRelative("Pos").FindPropertyRelative("y").floatValue, + SCells.GetArrayElementAtIndex(i).FindPropertyRelative("Pos").FindPropertyRelative("z").floatValue); + CurrentPos = Handles.PositionHandle(CurrentPos, quaternion.identity); + + SCells.GetArrayElementAtIndex(i).FindPropertyRelative("Pos").FindPropertyRelative("x").floatValue = CurrentPos.x; + SCells.GetArrayElementAtIndex(i).FindPropertyRelative("Pos").FindPropertyRelative("y").floatValue = CurrentPos.y; + SCells.GetArrayElementAtIndex(i).FindPropertyRelative("Pos").FindPropertyRelative("z").floatValue = CurrentPos.z; + + var test = Handles.Button(CurrentPos+LO.HandlePosition, quaternion.identity, LO.HandleSize, LO.HandleSize * 2, Handles.SphereHandleCap); + + if (test) + { + Debug.Log("buttonpressed"); + + //SCells.arraySize++; + SCells.InsertArrayElementAtIndex(i); + //SCells.GetArrayElementAtIndex(i+1) = SCells.GetArrayElementAtIndex(i); + //SCells.GetArrayElementAtIndex(i + 1).FindPropertyRelative("Pos").vector3Value = SCells.GetArrayElementAtIndex(i).FindPropertyRelative("Pos").vector3Value; + + SCells.GetArrayElementAtIndex(i + 1).FindPropertyRelative("Pos").FindPropertyRelative("x").floatValue += LO.DuplicationExtraPosition.x; + SCells.GetArrayElementAtIndex(i + 1).FindPropertyRelative("Pos").FindPropertyRelative("y").floatValue += LO.DuplicationExtraPosition.y; + SCells.GetArrayElementAtIndex(i + 1).FindPropertyRelative("Pos").FindPropertyRelative("z").floatValue += LO.DuplicationExtraPosition.z; + } + } + //LinkedObject.Size = Handles.ScaleHandle(LinkedObject.Size, LinkedObject.transform.position, LinkedObject.transform.rotation, HandleUtility.GetHandleSize(LinkedObject.transform.position) * 1.5f); + serializedObject.ApplyModifiedProperties(); + } +} +#endif \ No newline at end of file