-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
604 additions
and
47 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
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,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Grasshopper.Kernel; | ||
using Grasshopper.Kernel.Types; | ||
using Rhino.Geometry; | ||
|
||
namespace GHva3c | ||
{ | ||
/// <summary> | ||
/// Contains utility functions to be called from GH component classes | ||
/// </summary> | ||
public class _Utilities | ||
{ | ||
/// <summary> | ||
/// Returns a string representation of a hex color given a GH_Colour object | ||
/// </summary> | ||
/// <param name="ghColor">the grasshopper color to convert</param> | ||
/// <returns>a hex color string</returns> | ||
public static string hexColor(GH_Colour ghColor) | ||
{ | ||
string hexStr = "0x" + ghColor.Value.R.ToString("X2") + | ||
ghColor.Value.G.ToString("X2") + | ||
ghColor.Value.B.ToString("X2"); | ||
|
||
return hexStr; | ||
} | ||
} | ||
|
||
|
||
//below are a number of Catcher classes which are used to deserialize JSON objects | ||
//mostly called from the va3c_CompileScene component | ||
|
||
|
||
public class va3cGeometryCatcher | ||
{ | ||
public string uuid; | ||
public string type; | ||
public object data; | ||
} | ||
|
||
public class va3cMaterialCatcher | ||
{ | ||
public string uuid; | ||
public string type; | ||
public string color; | ||
public string ambient; | ||
public string emissive; | ||
public string specular; | ||
public double shininess; | ||
public double opacity; | ||
public bool transparent; | ||
public bool wireframe; | ||
public int side; | ||
} | ||
|
||
public class va3cAttributesCatcher | ||
{ | ||
public object userData; | ||
} | ||
|
||
public class va3cLineCatcher | ||
{ | ||
public string uuid; | ||
public string type; | ||
public object data; | ||
} | ||
|
||
public class va3cLineBasicMaterialCatcher | ||
{ | ||
public string uuid; | ||
public string type; | ||
public string color; | ||
public double linewidth; | ||
public double opacity; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Dynamic; | ||
|
||
using Grasshopper.Kernel; | ||
using Grasshopper.Kernel.Types; | ||
using Rhino.Geometry; | ||
|
||
using Newtonsoft.Json; | ||
using GHva3c.Properties; | ||
|
||
namespace GHva3c | ||
{ | ||
public class va3c_LineBasicMaterial : GH_Component | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the va3c_LineBasicMaterial class. | ||
/// </summary> | ||
public va3c_LineBasicMaterial() | ||
: base("va3c_LineBasicMaterial", "va3c_LineBasicMaterial", | ||
"Creates a THREE.js Basic Line Material to use with line geometries", | ||
"va3c", "materials") | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Registers all the input parameters for this component. | ||
/// </summary> | ||
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) | ||
{ | ||
pManager.AddColourParameter("Color", "C", "Material Color", GH_ParamAccess.item); | ||
pManager.AddNumberParameter("LineWeight", "LW", "The thickness, in pixels, of the line material", GH_ParamAccess.item, 1.0); | ||
pManager[1].Optional = true; | ||
} | ||
|
||
/// <summary> | ||
/// Registers all the output parameters for this component. | ||
/// </summary> | ||
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) | ||
{ | ||
pManager.AddTextParameter("Material", "Mat", "Line Material", GH_ParamAccess.item); | ||
} | ||
|
||
/// <summary> | ||
/// This is the method that actually does the work. | ||
/// </summary> | ||
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> | ||
protected override void SolveInstance(IGH_DataAccess DA) | ||
{ | ||
//loacl varaibles | ||
GH_Colour inColor = null; | ||
GH_Number inNumber = new GH_Number(1.0); | ||
|
||
//get user data | ||
if (!DA.GetData(0, ref inColor)) | ||
{ | ||
return; | ||
} | ||
DA.GetData(1, ref inNumber); | ||
|
||
//spin up a JSON material from the inputs | ||
string outJSON = ConstructMaterial(inColor, inNumber); | ||
|
||
//output | ||
DA.SetData(0, outJSON); | ||
|
||
|
||
} | ||
|
||
private string ConstructMaterial(GH_Colour inColor, GH_Number inNumber) | ||
{ | ||
//json object to populate | ||
dynamic jason = new ExpandoObject(); | ||
|
||
//JSON properties | ||
jason.uuid = Guid.NewGuid(); | ||
jason.type = "LineBasicMaterial"; | ||
jason.color = _Utilities.hexColor(inColor); | ||
jason.linewidth = inNumber.Value; | ||
jason.opacity = 1; | ||
|
||
|
||
return JsonConvert.SerializeObject(jason); | ||
} | ||
|
||
/// <summary> | ||
/// Provides an Icon for the component. | ||
/// </summary> | ||
protected override System.Drawing.Bitmap Icon | ||
{ | ||
get | ||
{ | ||
//You can add image files to your project resources and access them like this: | ||
// return Resources.IconForThisComponent; | ||
return null; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the unique ID for this component. Do not change this ID after release. | ||
/// </summary> | ||
public override Guid ComponentGuid | ||
{ | ||
get { return new Guid("{dc90f883-fc2f-4f0b-955b-b276fda72c70}"); } | ||
} | ||
} | ||
} |
Oops, something went wrong.