Skip to content

Commit

Permalink
Merge pull request #51 from aras-p/more-edit-tools
Browse files Browse the repository at this point in the history
Editing: merge, move splats, bake transform when exporting
  • Loading branch information
aras-p authored Nov 9, 2023
2 parents 8f5ab54 + 6047c10 commit 8291bd9
Show file tree
Hide file tree
Showing 31 changed files with 2,516 additions and 518 deletions.
35 changes: 35 additions & 0 deletions package/Editor/GaussianMoveTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: MIT

using GaussianSplatting.Runtime;
using UnityEditor;
using UnityEditor.EditorTools;
using UnityEngine;

namespace GaussianSplatting.Editor
{
[EditorTool("Gaussian Move Tool", typeof(GaussianSplatRenderer), typeof(GaussianToolContext))]
class GaussianMoveTool : GaussianTool
{
public override void OnToolGUI(EditorWindow window)
{
var gs = GetRenderer();
if (!gs || !CanBeEdited() || !HasSelection())
return;
var tr = gs.transform;

EditorGUI.BeginChangeCheck();
var selCenterLocal = GetSelectionCenterLocal();
var selCenterWorld = tr.TransformPoint(selCenterLocal);
var newPosWorld = Handles.DoPositionHandle(selCenterWorld, Tools.handleRotation);
if (EditorGUI.EndChangeCheck())
{
var newPosLocal = tr.InverseTransformPoint(newPosWorld);
var wasModified = gs.editModified;
gs.EditTranslateSelection(newPosLocal - selCenterLocal);
if (!wasModified)
GaussianSplatRendererEditor.RepaintAll();
Event.current.Use();
}
}
}
}
11 changes: 11 additions & 0 deletions package/Editor/GaussianMoveTool.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions package/Editor/GaussianRotateTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-License-Identifier: MIT

using GaussianSplatting.Runtime;
using UnityEditor;
using UnityEditor.EditorTools;
using UnityEngine;

namespace GaussianSplatting.Editor
{
/* not working correctly yet
[EditorTool("Gaussian Rotate Tool", typeof(GaussianSplatRenderer), typeof(GaussianToolContext))]
class GaussianRotateTool : GaussianTool
{
Quaternion m_CurrentRotation = Quaternion.identity;
Vector3 m_FrozenSelCenterLocal = Vector3.zero;
bool m_FreezePivot = false;
public override void OnActivated()
{
m_FreezePivot = false;
}
public override void OnToolGUI(EditorWindow window)
{
var gs = GetRenderer();
if (!gs || !CanBeEdited() || !HasSelection())
return;
var tr = gs.transform;
var evt = Event.current;
var selCenterLocal = GetSelectionCenterLocal();
if (evt.type == EventType.MouseDown)
{
gs.EditStorePosMouseDown();
gs.EditStoreOtherMouseDown();
m_FrozenSelCenterLocal = selCenterLocal;
m_FreezePivot = true;
}
if (evt.type == EventType.MouseUp)
{
m_CurrentRotation = Quaternion.identity;
m_FreezePivot = false;
}
if (m_FreezePivot)
selCenterLocal = m_FrozenSelCenterLocal;
EditorGUI.BeginChangeCheck();
var selCenterWorld = tr.TransformPoint(selCenterLocal);
var newRotation = Handles.DoRotationHandle(m_CurrentRotation, selCenterWorld);
if (EditorGUI.EndChangeCheck())
{
Matrix4x4 localToWorld = gs.transform.localToWorldMatrix;
Matrix4x4 worldToLocal = gs.transform.worldToLocalMatrix;
var wasModified = gs.editModified;
var rotToApply = newRotation;
gs.EditRotateSelection(selCenterLocal, localToWorld, worldToLocal, rotToApply);
m_CurrentRotation = newRotation;
if (!wasModified)
GaussianSplatRendererEditor.RepaintAll();
if(GUIUtility.hotControl == 0)
{
m_CurrentRotation = Tools.handleRotation;
}
}
}
}
*/
}
3 changes: 3 additions & 0 deletions package/Editor/GaussianRotateTool.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions package/Editor/GaussianScaleTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: MIT

using GaussianSplatting.Runtime;
using UnityEditor;
using UnityEditor.EditorTools;
using UnityEngine;

namespace GaussianSplatting.Editor
{
/* // not working correctly yet when the GS itself has scale
[EditorTool("Gaussian Scale Tool", typeof(GaussianSplatRenderer), typeof(GaussianToolContext))]
class GaussianScaleTool : GaussianTool
{
Vector3 m_CurrentScale = Vector3.one;
Vector3 m_FrozenSelCenterLocal = Vector3.zero;
bool m_FreezePivot = false;
public override void OnActivated()
{
m_FreezePivot = false;
}
public override void OnToolGUI(EditorWindow window)
{
var gs = GetRenderer();
if (!gs || !CanBeEdited() || !HasSelection())
return;
var tr = gs.transform;
var evt = Event.current;
var selCenterLocal = GetSelectionCenterLocal();
if (evt.type == EventType.MouseDown)
{
gs.EditStorePosMouseDown();
m_FrozenSelCenterLocal = selCenterLocal;
m_FreezePivot = true;
}
if (evt.type == EventType.MouseUp)
{
m_CurrentScale = Vector3.one;
m_FreezePivot = false;
}
if (m_FreezePivot)
selCenterLocal = m_FrozenSelCenterLocal;
EditorGUI.BeginChangeCheck();
var selCenterWorld = tr.TransformPoint(selCenterLocal);
m_CurrentScale = Handles.DoScaleHandle(m_CurrentScale, selCenterWorld, Tools.handleRotation, HandleUtility.GetHandleSize(selCenterWorld));
if (EditorGUI.EndChangeCheck())
{
Matrix4x4 localToWorld = Matrix4x4.identity;
Matrix4x4 worldToLocal = Matrix4x4.identity;
if (Tools.pivotRotation == PivotRotation.Global)
{
localToWorld = gs.transform.localToWorldMatrix;
worldToLocal = gs.transform.worldToLocalMatrix;
}
var wasModified = gs.editModified;
gs.EditScaleSelection(selCenterLocal, localToWorld, worldToLocal, m_CurrentScale);
if (!wasModified)
GaussianSplatRendererEditor.RepaintAll();
evt.Use();
}
}
}
*/
}
3 changes: 3 additions & 0 deletions package/Editor/GaussianScaleTool.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8291bd9

Please sign in to comment.