Skip to content

Commit

Permalink
Organized
Browse files Browse the repository at this point in the history
camera controls
viewport
idempotent
  • Loading branch information
lin-ycv committed Sep 14, 2022
1 parent 138bbb5 commit 0d46ae6
Show file tree
Hide file tree
Showing 22 changed files with 890 additions and 252 deletions.
2 changes: 2 additions & 0 deletions AssemblyPriority.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ private void AddWidget(object s, GH_CanvasWidgetListEventArgs e)
LabelWidget.CanvasCreated(c);
e.AddWidget(new WiresWidget());
WiresWidget.CanvasCreated(c);
e.AddWidget(new ViewportWidget());
ViewportWidget.CanvasCreated(c);
}

private void LoadQuickButtons(GH_Canvas canvas)
Expand Down
31 changes: 25 additions & 6 deletions Melanoplus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,23 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="src\WIP_Choke.cs" />
<Compile Include="src\WIP_Viewport.cs" />
<Compile Include="src\WIP_Pipeline.cs" />
<Compile Include="src\Animate.cs" />
<Compile Include="src\CameraSet.cs" />
<Compile Include="src\CameraGet.cs" />
<Compile Include="src\discontinue_AttributeViewer.cs" />
<Compile Include="src\Idempotent.cs" />
<Compile Include="src\LabelWidget.cs" />
<Compile Include="src\ViewportWidget.cs" />
<Compile Include="src\discontinue_Pipeline.cs" />
<Compile Include="src\ColorCanvas.cs" />
<Compile Include="src\Recorder.cs" />
<Compile Include="src\R_HUD.cs" />
<Compile Include="src\CopyWires.cs" />
<Compile Include="src\RhinoHUD.cs" />
<Compile Include="src\WiresWidget.cs" />
<Compile Include="src\GroupName.cs" />
<Compile Include="src\Cluster.cs" />
<Compile Include="src\CleanCanvas.cs" />
<Compile Include="src\Snippet.cs" />
<Compile Include="MelanoplusInfo.cs" />
<Compile Include="src\Label.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -123,6 +127,21 @@
<ItemGroup>
<None Include="Resources\DataHUD.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\idempotent3.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\viewportRhino.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\GetCamera.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\SetCamera.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\GIF.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>Copy "$(TargetPath)" "$(TargetDir)$(ProjectName).gha"
Expand Down
50 changes: 50 additions & 0 deletions Properties/Resources.Designer.cs

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

15 changes: 15 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@
<data name="DataHUD" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\DataHUD.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="GetCamera" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\GetCamera.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="GIF" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\GIF.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="idempotent3" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\idempotent3.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Label" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Label.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand All @@ -145,10 +154,16 @@
<data name="recordON" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\recordON.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="SetCamera" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\SetCamera.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="SnippetBuilder" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\SnippetBuilder.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="unlock" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\unlock.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="viewportRhino" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\viewportRhino.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added Resources/GIF.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/GetCamera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/SetCamera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/idempotent3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/viewportRhino.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions src/Animate.cs
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);
}
}
}
71 changes: 71 additions & 0 deletions src/CameraGet.cs
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);
}
}
}
Loading

0 comments on commit 0d46ae6

Please sign in to comment.