Skip to content

Commit

Permalink
further improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
coolcatcoder committed Nov 19, 2022
1 parent 311a1ec commit 9bb4920
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 61 deletions.
63 changes: 12 additions & 51 deletions Assets/Scenes/pond_testing.unity
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
CubeHalfSize: 0.5
DistanceToCount: 0.5
DistanceToCount: 0.25
IsoSurfaceLevel: 0
DebugCubeIndex: 0
CubeIndexBatchSize: 256
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
70 changes: 60 additions & 10 deletions Assets/Scripts/FlexStuff/IsoSurfaceExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1004,4 +1008,50 @@ public unsafe void FullCubesEmptiness()
// ContentPosition = EditorGUI.PrefixLabel(position, label);
// EditorGUI.PropertyField(ContentPosition, property.FindPropertyRelative("CubeIndex"));
// }
//}
//}

#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

0 comments on commit 9bb4920

Please sign in to comment.