Skip to content

Commit 8291bd9

Browse files
authored
Merge pull request #51 from aras-p/more-edit-tools
Editing: merge, move splats, bake transform when exporting
2 parents 8f5ab54 + 6047c10 commit 8291bd9

31 files changed

+2516
-518
lines changed

package/Editor/GaussianMoveTool.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
using GaussianSplatting.Runtime;
4+
using UnityEditor;
5+
using UnityEditor.EditorTools;
6+
using UnityEngine;
7+
8+
namespace GaussianSplatting.Editor
9+
{
10+
[EditorTool("Gaussian Move Tool", typeof(GaussianSplatRenderer), typeof(GaussianToolContext))]
11+
class GaussianMoveTool : GaussianTool
12+
{
13+
public override void OnToolGUI(EditorWindow window)
14+
{
15+
var gs = GetRenderer();
16+
if (!gs || !CanBeEdited() || !HasSelection())
17+
return;
18+
var tr = gs.transform;
19+
20+
EditorGUI.BeginChangeCheck();
21+
var selCenterLocal = GetSelectionCenterLocal();
22+
var selCenterWorld = tr.TransformPoint(selCenterLocal);
23+
var newPosWorld = Handles.DoPositionHandle(selCenterWorld, Tools.handleRotation);
24+
if (EditorGUI.EndChangeCheck())
25+
{
26+
var newPosLocal = tr.InverseTransformPoint(newPosWorld);
27+
var wasModified = gs.editModified;
28+
gs.EditTranslateSelection(newPosLocal - selCenterLocal);
29+
if (!wasModified)
30+
GaussianSplatRendererEditor.RepaintAll();
31+
Event.current.Use();
32+
}
33+
}
34+
}
35+
}

package/Editor/GaussianMoveTool.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/Editor/GaussianRotateTool.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
using GaussianSplatting.Runtime;
4+
using UnityEditor;
5+
using UnityEditor.EditorTools;
6+
using UnityEngine;
7+
8+
namespace GaussianSplatting.Editor
9+
{
10+
/* not working correctly yet
11+
[EditorTool("Gaussian Rotate Tool", typeof(GaussianSplatRenderer), typeof(GaussianToolContext))]
12+
class GaussianRotateTool : GaussianTool
13+
{
14+
Quaternion m_CurrentRotation = Quaternion.identity;
15+
Vector3 m_FrozenSelCenterLocal = Vector3.zero;
16+
bool m_FreezePivot = false;
17+
18+
public override void OnActivated()
19+
{
20+
m_FreezePivot = false;
21+
}
22+
23+
public override void OnToolGUI(EditorWindow window)
24+
{
25+
var gs = GetRenderer();
26+
if (!gs || !CanBeEdited() || !HasSelection())
27+
return;
28+
var tr = gs.transform;
29+
var evt = Event.current;
30+
31+
var selCenterLocal = GetSelectionCenterLocal();
32+
if (evt.type == EventType.MouseDown)
33+
{
34+
gs.EditStorePosMouseDown();
35+
gs.EditStoreOtherMouseDown();
36+
m_FrozenSelCenterLocal = selCenterLocal;
37+
m_FreezePivot = true;
38+
}
39+
if (evt.type == EventType.MouseUp)
40+
{
41+
m_CurrentRotation = Quaternion.identity;
42+
m_FreezePivot = false;
43+
}
44+
45+
if (m_FreezePivot)
46+
selCenterLocal = m_FrozenSelCenterLocal;
47+
48+
EditorGUI.BeginChangeCheck();
49+
var selCenterWorld = tr.TransformPoint(selCenterLocal);
50+
var newRotation = Handles.DoRotationHandle(m_CurrentRotation, selCenterWorld);
51+
if (EditorGUI.EndChangeCheck())
52+
{
53+
Matrix4x4 localToWorld = gs.transform.localToWorldMatrix;
54+
Matrix4x4 worldToLocal = gs.transform.worldToLocalMatrix;
55+
var wasModified = gs.editModified;
56+
var rotToApply = newRotation;
57+
gs.EditRotateSelection(selCenterLocal, localToWorld, worldToLocal, rotToApply);
58+
m_CurrentRotation = newRotation;
59+
if (!wasModified)
60+
GaussianSplatRendererEditor.RepaintAll();
61+
62+
if(GUIUtility.hotControl == 0)
63+
{
64+
m_CurrentRotation = Tools.handleRotation;
65+
}
66+
}
67+
}
68+
}
69+
*/
70+
}

package/Editor/GaussianRotateTool.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/Editor/GaussianScaleTool.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
using GaussianSplatting.Runtime;
4+
using UnityEditor;
5+
using UnityEditor.EditorTools;
6+
using UnityEngine;
7+
8+
namespace GaussianSplatting.Editor
9+
{
10+
/* // not working correctly yet when the GS itself has scale
11+
[EditorTool("Gaussian Scale Tool", typeof(GaussianSplatRenderer), typeof(GaussianToolContext))]
12+
class GaussianScaleTool : GaussianTool
13+
{
14+
Vector3 m_CurrentScale = Vector3.one;
15+
Vector3 m_FrozenSelCenterLocal = Vector3.zero;
16+
bool m_FreezePivot = false;
17+
18+
public override void OnActivated()
19+
{
20+
m_FreezePivot = false;
21+
}
22+
23+
public override void OnToolGUI(EditorWindow window)
24+
{
25+
var gs = GetRenderer();
26+
if (!gs || !CanBeEdited() || !HasSelection())
27+
return;
28+
var tr = gs.transform;
29+
var evt = Event.current;
30+
31+
var selCenterLocal = GetSelectionCenterLocal();
32+
if (evt.type == EventType.MouseDown)
33+
{
34+
gs.EditStorePosMouseDown();
35+
m_FrozenSelCenterLocal = selCenterLocal;
36+
m_FreezePivot = true;
37+
}
38+
if (evt.type == EventType.MouseUp)
39+
{
40+
m_CurrentScale = Vector3.one;
41+
m_FreezePivot = false;
42+
}
43+
44+
if (m_FreezePivot)
45+
selCenterLocal = m_FrozenSelCenterLocal;
46+
47+
EditorGUI.BeginChangeCheck();
48+
var selCenterWorld = tr.TransformPoint(selCenterLocal);
49+
m_CurrentScale = Handles.DoScaleHandle(m_CurrentScale, selCenterWorld, Tools.handleRotation, HandleUtility.GetHandleSize(selCenterWorld));
50+
if (EditorGUI.EndChangeCheck())
51+
{
52+
Matrix4x4 localToWorld = Matrix4x4.identity;
53+
Matrix4x4 worldToLocal = Matrix4x4.identity;
54+
if (Tools.pivotRotation == PivotRotation.Global)
55+
{
56+
localToWorld = gs.transform.localToWorldMatrix;
57+
worldToLocal = gs.transform.worldToLocalMatrix;
58+
}
59+
var wasModified = gs.editModified;
60+
gs.EditScaleSelection(selCenterLocal, localToWorld, worldToLocal, m_CurrentScale);
61+
if (!wasModified)
62+
GaussianSplatRendererEditor.RepaintAll();
63+
evt.Use();
64+
}
65+
}
66+
}
67+
*/
68+
}

package/Editor/GaussianScaleTool.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)