-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
camera controls viewport idempotent
- Loading branch information
Showing
22 changed files
with
890 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using Grasshopper.Kernel; | ||
using Rhino; | ||
using Rhino.Display; | ||
using Rhino.DocObjects; | ||
using Rhino.DocObjects.Tables; | ||
using Rhino.Geometry; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Melanoplus | ||
{ | ||
public class Animate : GH_Component | ||
{ | ||
public override Guid ComponentGuid => new Guid("{8374F785-B678-450F-B264-9B3ED154E6D2}"); | ||
public override GH_Exposure Exposure => GH_Exposure.primary; | ||
protected override Bitmap Icon => Properties.Resources.GIF; | ||
public Animate() : base("Animate Camera", "Animate", | ||
"Animate camera thru a series of named views.", | ||
"Display", "Viewport") | ||
{ } | ||
bool pause = false; | ||
|
||
protected override void RegisterInputParams(GH_InputParamManager pManager) | ||
{ | ||
pManager.AddNumberParameter("Timeline", "Time", "Scrub between 0 and 1 to animate thru the order in named view.", GH_ParamAccess.item); | ||
pManager.AddBooleanParameter("save", null, "Append current view to end of series.", GH_ParamAccess.item); | ||
pManager.AddBooleanParameter("clear", null, "Clear all named view in this series.", GH_ParamAccess.item); | ||
pManager[0].Optional = true; | ||
pManager[1].Optional = true; | ||
pManager[2].Optional = true; | ||
} | ||
|
||
protected override void RegisterOutputParams(GH_OutputParamManager pManager) | ||
{ | ||
} | ||
|
||
protected override void SolveInstance(IGH_DataAccess DA) | ||
{ | ||
if (pause) { pause = false;return; } | ||
RhinoViewport vp = RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport; | ||
double time = -1; | ||
bool save = false, clear = false; | ||
DA.GetData(0, ref time); | ||
DA.GetData(1, ref save); | ||
DA.GetData(2, ref clear); | ||
|
||
NamedViewTable nvt = RhinoDoc.ActiveDoc.NamedViews; | ||
var views = nvt.Where(v => v.Name.StartsWith("melanoplus_")); | ||
int count = nvt.Where(v => v.Name.StartsWith("melanoplus_")).Count(); | ||
if (save) | ||
{ | ||
RhinoDoc.ActiveDoc.NamedViews.Add($"melanoplus_{views.GetHashCode()}", vp.Id); | ||
pause = true; | ||
return; | ||
} | ||
else if (clear && count > 0) | ||
{ | ||
OnPingDocument().ScheduleSolution(5, ClearViews); | ||
return; | ||
} | ||
if (time >= 0 && count > 0) | ||
{ | ||
double progress = (count - 1) * time, remainder = progress % 1.0; | ||
ViewportInfo A = nvt[(int)Math.Floor(progress)].Viewport, B = nvt[(int)Math.Ceiling(progress)].Viewport; | ||
vp.Camera35mmLensLength = ((B.Camera35mmLensLength - A.Camera35mmLensLength) * remainder) + A.Camera35mmLensLength; | ||
Point3d loc = ((B.CameraLocation - A.CameraLocation) * remainder) + A.CameraLocation, tar = ((B.TargetPoint - A.TargetPoint) * remainder) + A.TargetPoint; | ||
Vector3d updir = ((B.CameraUp - A.CameraUp) * remainder) + A.CameraUp; | ||
vp.SetCameraLocations(tar, loc); | ||
vp.CameraUp = updir; | ||
} | ||
} | ||
|
||
private void ClearViews(GH_Document doc) | ||
{ | ||
NamedViewTable nvt = RhinoDoc.ActiveDoc.NamedViews; | ||
var views = nvt.Where(v => v.Name.StartsWith("melanoplus_")); | ||
do | ||
{ | ||
nvt.Delete(views.First().Name); | ||
} while (views.Count() > 0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Grasshopper.GUI.Canvas; | ||
using Grasshopper.GUI; | ||
using Grasshopper.Kernel; | ||
using Grasshopper.Kernel.Attributes; | ||
using Grasshopper.Kernel.Parameters; | ||
using Rhino.Display; | ||
using Rhino.Geometry; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace Melanoplus | ||
{ | ||
public class CameraGet : GH_Component | ||
{ | ||
public override Guid ComponentGuid => new Guid("{80C689F8-9C9F-4CFB-8FAD-DA15578E7460}"); | ||
public override GH_Exposure Exposure => GH_Exposure.primary; | ||
protected override Bitmap Icon => Properties.Resources.GetCamera; | ||
|
||
public CameraGet() : base("Get Camera", "Camera", | ||
"Get Rhino camera properties.", | ||
"Display", "Viewport") { } | ||
protected override void RegisterInputParams(GH_InputParamManager pManager) | ||
{ | ||
pManager.AddGenericParameter("⠀", null, "Something to expire this component", GH_ParamAccess.item); | ||
pManager[0].Optional=true; | ||
} | ||
protected override void RegisterOutputParams(GH_OutputParamManager pManager) | ||
{ | ||
pManager.AddPointParameter("Camera", null, "Get viewport camera location.", GH_ParamAccess.item); | ||
pManager.AddPointParameter("Target", null, "Get camera target point.", GH_ParamAccess.item); | ||
pManager.AddVectorParameter("Up direction", "Up", "Get up direction of camera", GH_ParamAccess.item); | ||
pManager.AddNumberParameter("Lens length", "Lens", "35mm equivalent focal lens", GH_ParamAccess.item); | ||
} | ||
protected override void SolveInstance(IGH_DataAccess DA) | ||
{ | ||
RhinoViewport vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport; | ||
Point3d camera = vp.CameraLocation, target = vp.CameraTarget; | ||
Vector3d up = vp.CameraUp; | ||
double lens = vp.Camera35mmLensLength; | ||
|
||
DA.SetData(0, camera); | ||
DA.SetData(1, target); | ||
DA.SetData(2, up); | ||
DA.SetData(3, lens); | ||
} | ||
public override void CreateAttributes() | ||
{ | ||
m_attributes = new CamGetAttributes(this); | ||
} | ||
} | ||
public class CamGetAttributes : GH_ComponentAttributes | ||
{ | ||
public CamGetAttributes(IGH_Component component) : base(component) | ||
{ | ||
} | ||
public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e) | ||
{ | ||
if (base.Owner is CameraGet comp) | ||
{ | ||
comp.ExpireSolution(true); | ||
return GH_ObjectResponse.Handled; | ||
} | ||
return base.RespondToMouseDoubleClick(sender, e); | ||
} | ||
} | ||
} |
Oops, something went wrong.