Skip to content

Commit

Permalink
Add set camera component
Browse files Browse the repository at this point in the history
  • Loading branch information
camnewnham committed Oct 30, 2024
1 parent d9b1290 commit 02daccd
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
Binary file added Assets/Icon_SetCamera.3dm
Binary file not shown.
10 changes: 10 additions & 0 deletions Plugin/Properties/Resources.Designer.cs

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

3 changes: 3 additions & 0 deletions Plugin/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="icon_setcamera_24" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon_setcamera_24.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="logo_24" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\logo_24.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
Binary file added Plugin/Resources/icon_setcamera_24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions Plugin/SetCameraComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Grasshopper.Kernel;
using Rhino.Geometry;
using System;

namespace GH_Timeline
{
public class SetCameraComponent : GH_Component
{
public override Guid ComponentGuid => new Guid("EEE94A1F-A762-425C-B564-5F5282580951");
protected override System.Drawing.Bitmap Icon => Properties.Resources.icon_setcamera_24;

public SetCameraComponent()
: base("Set Camera", "Set Camera", "Sets the camera location and target", "Display", "Timeline")
{
}

protected override void RegisterInputParams(GH_InputParamManager pManager)
{
pManager.AddPointParameter("Camera Location", "L", "The location of the camera", GH_ParamAccess.item);
pManager.AddPointParameter("Camera Target", "T", "The target of the camera", GH_ParamAccess.item);
pManager[pManager.AddTextParameter("Viewport", "V", "The name of the viewport. If none, the active viewport will be used", GH_ParamAccess.item)].Optional = true;
}

protected override void RegisterOutputParams(GH_OutputParamManager pManager)
{
}

protected override void SolveInstance(IGH_DataAccess DA)
{
Rhino.Display.RhinoViewport viewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport;
string viewportName = viewport.Name;


if (DA.GetData(2, ref viewportName))
{
Rhino.Display.RhinoView rhView = Rhino.RhinoDoc.ActiveDoc.Views.Find(viewportName, false);
if (rhView == null)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Unable to find viewport {viewportName}");
return;
}

viewport = rhView.ActiveViewport;
}

Point3d camPos = default;
Point3d camTar = default;

DA.GetData(0, ref camPos);
DA.GetData(1, ref camTar);

viewport.SetCameraLocations(camTar, camPos);
}
}
}

0 comments on commit 02daccd

Please sign in to comment.