public Element(string json, va3cElementType type, Material material, Layer layer) { GeometryJson = json; Type = type; Material = material; Layer = layer; }
/// <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) { //System.Drawing.Color inColor = System.Drawing.Color.White; GH_Colour inColor = null; GH_Colour inAmbient = null; GH_Colour inEmissive = null; GH_Colour inSpecular = null; GH_Number inShininess = null; GH_Number inOpacity = null; String outMaterial = null; //if (!DA.GetData(0, ref inColor)) { return; } if (!DA.GetData(0, ref inColor)) { return; } if (inColor == null) { return; } DA.GetData(1, ref inAmbient); DA.GetData(2, ref inEmissive); DA.GetData(3, ref inSpecular); DA.GetData(4, ref inShininess); DA.GetData(5, ref inOpacity); if (inOpacity.Value > 1 || inOpacity.Value < 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The opacity input must be between 0 and 1, and has been defaulted back to 1. Check your 'O' input."); inOpacity.Value = 1.0; } outMaterial = ConstructPhongMaterial(inColor, inAmbient, inEmissive, inSpecular, inShininess.Value, inOpacity.Value); //call json conversion function Material material = new Material(outMaterial, va3cMaterialType.Mesh); DA.SetData(0, material); }
/// <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) { GH_Colour inColor = null; GH_Colour inAmbient = null; GH_Colour inEmissive = null; GH_Number inOpacity = null; GH_Boolean inSmooth = null; String outMaterial = null; if (!DA.GetData(0, ref inColor)) { return; } if (inColor == null) { return; } DA.GetData(1, ref inAmbient); DA.GetData(2, ref inEmissive); DA.GetData(3, ref inOpacity); if (inOpacity.Value > 1 || inOpacity.Value < 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The opacity input must be between 0 and 1, and has been defaulted back to 1. Check your 'O' input."); inOpacity.Value = 1.0; } DA.GetData(4, ref inSmooth); outMaterial = ConstructLambertMaterial(inColor, inAmbient, inEmissive, inOpacity.Value, inSmooth.Value); Material material = new Material(outMaterial, va3cMaterialType.Mesh); DA.SetData(0, material); }
/// <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) { //local varaibles GH_Colour inColor = null; Double inOpacity = 1; string outMaterial = null; //catch inputs and populate local variables if (!DA.GetData(0, ref inColor)) { return; } if (inColor == null) { return; } DA.GetData(1, ref inOpacity); if (inOpacity > 1 || inOpacity < 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The opacity input must be between 0 and 1, and has been defaulted back to 1. Check your 'O' input."); inOpacity = 1.0; } outMaterial = CreateMaterial(inColor, inOpacity); Material material = new Material(outMaterial, va3cMaterialType.Mesh); //set the output - build up a basic material json string DA.SetData(0, material); }
/// <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) { //local varaibles GH_Mesh mesh = null; List<GH_Colour> colors = new List<GH_Colour>(); List<GH_String> attributeNames = new List<GH_String>(); List<GH_String> attributeValues = new List<GH_String>(); Dictionary<string, object> attributesDict = new Dictionary<string, object>(); Layer layer = null; string layerName = "Default"; //catch inputs and populate local variables if (!DA.GetData(0, ref mesh)) { return; } if (mesh == null) { return; } if (!DA.GetDataList(1, colors)) { return; } DA.GetDataList(2, attributeNames); DA.GetDataList(3, attributeValues); if (attributeValues.Count != attributeNames.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please provide equal numbers of attribute names and values."); return; } DA.GetData(4, ref layerName); layer = new Layer(layerName); //populate dictionary int i = 0; foreach (var a in attributeNames) { attributesDict.Add(a.Value, attributeValues[i].Value); i++; } //add the layer name to the attributes dictionary attributesDict.Add("layer", layerName); //create MeshFaceMaterial and assign mesh face material indexes in the attributes dict string meshMaterailJSON = makeMeshFaceMaterialJSON(mesh.Value, attributesDict, colors); //create json from mesh string meshJSON = _Utilities.geoJSON(mesh.Value, attributesDict); Material material = new Material(meshMaterailJSON, va3cMaterialType.Mesh); Element e = new Element(meshJSON, va3cElementType.Mesh, material, layer); DA.SetData(0, e); }
/// <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); Material material = new Material(outJSON, va3cMaterialType.Line); //output DA.SetData(0, material); }