public override void SimulateMaterial(ref Rhino.DocObjects.Material simulatedMaterial, bool forDataOnly) { base.SimulateMaterial(ref simulatedMaterial, forDataOnly); if (Fields.TryGetValue("mat1", out Color4f color)) { simulatedMaterial.DiffuseColor = color.AsSystemColor(); } }
/// <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) { Color Color_Diffuse = Color.Black, Color_Ambient = Color.Black, Color_Emission = Color.Black, Color_Reflection = Color.Black; bool FresnelReflections = false; DA.GetData(0, ref Color_Diffuse); DA.GetData(1, ref Color_Ambient); DA.GetData(2, ref Color_Emission); DA.GetData(3, ref Color_Reflection); double Reflectivity = 0, ReflectionGlossiness = 0, RefractionGlossiness = 0, IoR = 0, Transparency = 0; DA.GetData(4, ref Reflectivity); DA.GetData(5, ref ReflectionGlossiness); DA.GetData(6, ref RefractionGlossiness); DA.GetData(7, ref FresnelReflections); DA.GetData(8, ref IoR); DA.GetData(9, ref Transparency); Reflectivity = Math.Min(Math.Max(Reflectivity, 0), 1); ReflectionGlossiness = Math.Min(Math.Max(ReflectionGlossiness, 0), 1); Transparency = Math.Min(Math.Max(Transparency, 0), 1); Rhino.DocObjects.Material material = new Rhino.DocObjects.Material(); material.FresnelReflections = FresnelReflections; if (FresnelReflections) { material.FresnelIndexOfRefraction = IoR; } else { material.IndexOfRefraction = IoR; } material.DiffuseColor = Color_Diffuse; material.AmbientColor = Color_Ambient; material.EmissionColor = Color_Emission; material.ReflectionColor = Color_Reflection; material.Reflectivity = Reflectivity; material.RefractionGlossiness = RefractionGlossiness; material.ReflectionGlossiness = ReflectionGlossiness; material.Transparency = Transparency; var renderMaterial = Rhino.Render.RenderMaterial.CreateBasicMaterial(material); DA.SetData(0, new GH_Material(renderMaterial)); }
public static Elements.Material ToMaterial(this Rhino.DocObjects.Material mat) { var color = mat.DiffuseColor.ToColor(); color.Alpha = 1.0 - mat.Transparency; var specularFactor = 0.1; var glossinessFactor = mat.Shine / Rhino.DocObjects.Material.MaxShine; var name = mat.Name; return(new Elements.Material(color, specularFactor, glossinessFactor, false, null, true, Guid.NewGuid(), name)); }
/// <summary> /// Constructs a new basic material from a <see cref="Rhino.DocObjects.Material">Material</see>. /// </summary> /// <param name="material">(optional)The material to create the basic material from.</param> /// <returns>A new basic material.</returns> public static RenderMaterial CreateBasicMaterial(Rhino.DocObjects.Material material) { IntPtr pConstSourceMaterial = (material == null ? IntPtr.Zero : material.ConstPointer()); IntPtr pNewMaterial = UnsafeNativeMethods.Rdk_Globals_NewBasicMaterial(pConstSourceMaterial); NativeRenderMaterial newMaterial = RenderContent.FromPointer(pNewMaterial) as NativeRenderMaterial; if (newMaterial != null) { newMaterial.AutoDelete = true; } return(newMaterial); }
/// <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 diffuseColor = System.Drawing.Color.Empty; DA.GetData(0, ref diffuseColor); var material = new Rhino.DocObjects.Material(); material.DiffuseColor = diffuseColor; 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) { Boolean button = false; String name = ""; var material = new Rhino.DocObjects.Material(); DA.GetData(0, ref button); DA.GetData(1, ref name); DA.GetData(2, ref material); if (button == true) { material.Name = name; Rhino.RhinoDoc.ActiveDoc.RenderMaterials.Add(material.RenderMaterial); } }
/// <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) { Color diffuseColor = Color.Empty; Color specularColor = Color.Empty; Color reflectionColor = Color.Empty; double reflectivity = double.NaN; double reflectionGlossiness = double.NaN; bool useFresnelReflection = true; Color transparentColor = Color.Empty; double transparency = double.NaN; double indexOfRefraction = double.NaN; double refractionGlossiness = double.NaN; Color emissionColor = Color.Empty; DA.GetData(0, ref diffuseColor); DA.GetData(1, ref specularColor); DA.GetData(2, ref reflectionColor); DA.GetData(3, ref reflectivity); DA.GetData(4, ref reflectionGlossiness); DA.GetData(5, ref useFresnelReflection); DA.GetData(6, ref transparentColor); DA.GetData(7, ref transparency); DA.GetData(8, ref indexOfRefraction); DA.GetData(9, ref refractionGlossiness); DA.GetData(10, ref emissionColor); var material = new Rhino.DocObjects.Material(); material.DiffuseColor = diffuseColor; material.SpecularColor = specularColor; material.ReflectionColor = reflectionColor; material.Reflectivity = reflectivity; material.ReflectionGlossiness = reflectionGlossiness; material.FresnelReflections = useFresnelReflection; material.TransparentColor = transparentColor; material.Transparency = transparency; material.IndexOfRefraction = indexOfRefraction; material.RefractionGlossiness = refractionGlossiness; material.EmissionColor = emissionColor; DA.SetData(0, material); }
public override void SimulateMaterial(ref Rhino.DocObjects.Material simulatedMaterial, bool forDataOnly) { var boolrc = false; boolrc = HandleTexturedValue(Pbr.BaseColor, Base); simulatedMaterial.DiffuseColor = Base.Value.AsSystemColor(); if (Base.Texture != null && Base.On) { SimulatedTexture simtex = Base.Texture.SimulatedTexture(RenderTexture.TextureGeneration.Allow); simulatedMaterial.SetBitmapTexture(simtex.Texture()); } boolrc = HandleTexturedValue(Pbr.Metallic, Metallic); simulatedMaterial.Reflectivity = Metallic.Value; if (Metallic.Value > 0.5f) { simulatedMaterial.DiffuseColor = System.Drawing.Color.Black; simulatedMaterial.ReflectionColor = Base.Value.AsSystemColor(); } boolrc = HandleTexturedValue(Pbr.Roughness, Roughness); simulatedMaterial.ReflectionGlossiness = 1.0f - Roughness.Value; boolrc = HandleTexturedValue(Pbr.Opacity, Transmission); simulatedMaterial.Transparency = 1.0f - Transmission.Value; if (Transmission.Value > 0.5f) { simulatedMaterial.TransparentColor = Base.Value.AsSystemColor(); } boolrc = HandleTexturedValue(Pbr.OpacityRoughness, TransmissionRoughness); simulatedMaterial.RefractionGlossiness = 1.0f - TransmissionRoughness.Value; boolrc = HandleTexturedValue(Pbr.OpacityIor, Ior); simulatedMaterial.IndexOfRefraction = Ior.Value; boolrc = HandleTexturedValue(Pbr.Bump, Bump); if (Bump.On && Bump.Texture != null) { SimulatedTexture simtex = Bump.Texture.SimulatedTexture(RenderTexture.TextureGeneration.Allow); simulatedMaterial.SetBumpTexture(simtex.Texture()); } }
static void OnSimulateMaterial(int serial_number, IntPtr pSim, int bDataOnly) { try { RenderMaterial material = RenderContent.FromSerialNumber(serial_number) as RenderMaterial; if (material != null && pSim != IntPtr.Zero) { Rhino.DocObjects.Material temp_material = Rhino.DocObjects.Material.NewTemporaryMaterial(pSim); if (temp_material != null) { material.SimulateMaterial(ref temp_material, bDataOnly != 0); temp_material.ReleaseNonConstPointer(); } } } catch (Exception ex) { Rhino.Runtime.HostUtils.ExceptionReport(ex); } }
public static Rhino.Commands.Result AddMaterial(Rhino.RhinoDoc doc) { // materials are stored in the document's material table int index = doc.Materials.Add(); Rhino.DocObjects.Material mat = doc.Materials[index]; mat.DiffuseColor = System.Drawing.Color.Chocolate; mat.SpecularColor = System.Drawing.Color.CadetBlue; mat.CommitChanges(); // set up object attributes to say they use a specific material Rhino.Geometry.Sphere sp = new Rhino.Geometry.Sphere(Rhino.Geometry.Plane.WorldXY, 5); Rhino.DocObjects.ObjectAttributes attr = new Rhino.DocObjects.ObjectAttributes(); attr.MaterialIndex = index; attr.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject; doc.Objects.AddSphere(sp, attr); // add a sphere without the material attributes set sp.Center = new Rhino.Geometry.Point3d(10, 10, 0); doc.Objects.AddSphere(sp); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
protected virtual bool AddRenderMeshToScene(Rhino.DocObjects.RhinoObject obj, Rhino.DocObjects.Material material, Rhino.Geometry.Mesh mesh) { return(true); }
internal Texture(int index, Rhino.DocObjects.Material parent) { m_index = index; m__parent = parent; }
public static void OptToRhino(OptFile opt, string rhinoPath, bool scale) { if (opt == null) { throw new ArgumentNullException("opt"); } string rhinoDirectory = Path.GetDirectoryName(rhinoPath); string rhinoName = Path.GetFileNameWithoutExtension(rhinoPath); var distances = opt.Meshes .SelectMany(t => t.Lods) .Select(t => t.Distance) .Distinct() .OrderByDescending(t => t) .ToArray(); for (int distance = 0; distance < distances.Length; distance++) { using (var file = new Rhino.FileIO.File3dm()) { file.Settings.ModelUnitSystem = Rhino.UnitSystem.Meters; int objectsIndex = 0; List<string> textureNames = new List<string>(); foreach (var mesh in opt.Meshes) { var lod = mesh.Lods.FirstOrDefault(t => t.Distance <= distances[distance]); if (lod == null) { continue; } foreach (var textureName in lod.FaceGroups .Where(t => t.Textures.Count > 0) .Select(t => t.Textures[0])) { if (!textureNames.Contains(textureName)) { textureNames.Add(textureName); } } string meshName = string.Format(CultureInfo.InvariantCulture, "{0}.{1:D3}", mesh.Descriptor.MeshType, objectsIndex); using (var layer = new Rhino.DocObjects.Layer()) { layer.Name = meshName; file.Layers.Add(layer); } foreach (var faceGroup in lod.FaceGroups) { using (var rhinoMesh = new Rhino.Geometry.Mesh()) using (var rhinoAttributes = new Rhino.DocObjects.ObjectAttributes()) { rhinoAttributes.Name = meshName; rhinoAttributes.LayerIndex = objectsIndex; if (faceGroup.Textures.Count > 0) { rhinoAttributes.MaterialIndex = textureNames.IndexOf(faceGroup.Textures[0]); } Action<Vector> addVertex; if (scale) { addVertex = vertex => rhinoMesh.Vertices.Add(vertex.X * OptFile.ScaleFactor, vertex.Y * OptFile.ScaleFactor, vertex.Z * OptFile.ScaleFactor); } else { addVertex = vertex => rhinoMesh.Vertices.Add(vertex.X, vertex.Y, vertex.Z); } Action<TextureCoordinates> addTexCoords = texCoords => rhinoMesh.TextureCoordinates.Add(texCoords.U, -texCoords.V); Action<Vector> addNormal = normal => rhinoMesh.Normals.Add(normal.X, normal.Y, normal.Z); int facesIndex = 0; foreach (var face in faceGroup.Faces) { var verticesIndex = face.VerticesIndex; var texCoordsIndex = face.TextureCoordinatesIndex; var normalsIndex = face.VertexNormalsIndex; addVertex(mesh.Vertices[verticesIndex.A]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.A]); addNormal(mesh.VertexNormals[normalsIndex.A]); facesIndex++; addVertex(mesh.Vertices[verticesIndex.B]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.B]); addNormal(mesh.VertexNormals[normalsIndex.B]); facesIndex++; addVertex(mesh.Vertices[verticesIndex.C]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.C]); addNormal(mesh.VertexNormals[normalsIndex.C]); facesIndex++; if (verticesIndex.D >= 0) { addVertex(mesh.Vertices[verticesIndex.D]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.D]); addNormal(mesh.VertexNormals[normalsIndex.D]); facesIndex++; } if (verticesIndex.D < 0) { rhinoMesh.Faces.AddFace(facesIndex - 1, facesIndex - 2, facesIndex - 3); } else { rhinoMesh.Faces.AddFace(facesIndex - 1, facesIndex - 2, facesIndex - 3, facesIndex - 4); } } rhinoMesh.Compact(); file.Objects.AddMesh(rhinoMesh, rhinoAttributes); } } objectsIndex++; } foreach (var textureName in textureNames) { Texture texture; opt.Textures.TryGetValue(textureName, out texture); using (var material = new Rhino.DocObjects.Material()) { material.Name = textureName; if (texture == null) { material.DiffuseColor = System.Drawing.Color.White; } else { texture.Save(Path.Combine(rhinoDirectory, textureName + ".png")); material.SetBitmapTexture(textureName + ".png"); if (texture.HasAlpha) { texture.SaveAlphaMap(Path.Combine(rhinoDirectory, textureName + "_alpha.png")); material.SetTransparencyTexture(textureName + "_alpha.png"); } } file.Materials.Add(material); } } file.Write(Path.Combine(rhinoDirectory, string.Format(CultureInfo.InvariantCulture, "{0}_{1}.3dm", rhinoName, distance)), 4); } } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { String[] matName = new String[] { "WhiteGold_18ct", "YellowGold_18ct", "RedGold_18ct", "RodiumBlack_18ct", "Silver_925", "Platinum_960", "Ruby", "Emerald", "Saphir", "Paraiba", "Granat", "Amethyst", "Morganite", "Diamond" }; Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings(); settings.VisibleFilter = true; System.Collections.Generic.List <Guid> ids = new System.Collections.Generic.List <Guid>(); List <string> allItems = new List <string>(); List <string> metalItems = new List <string>(); List <string> stoneItems = new List <string>(); List <double> circleStones = new List <double>(); List <int> quantCirclesStones = new List <int>(); foreach (Rhino.DocObjects.RhinoObject rhObj in doc.Objects.GetObjectList(settings)) { var objType = rhObj.ObjectType; Guid objGuid = rhObj.Id; Rhino.DocObjects.ObjRef objref = new Rhino.DocObjects.ObjRef(objGuid); if (objType == Rhino.DocObjects.ObjectType.Curve) { Curve curveRadius = objref.Curve(); Circle circleRadius = new Circle(); var circlefound = curveRadius.TryGetCircle(out circleRadius, doc.ModelAbsoluteTolerance); if (circlefound) { double diamStone = Math.Round(circleRadius.Diameter, 2, MidpointRounding.AwayFromZero); int match = circleStones.IndexOf(diamStone); if (match == -1) { circleStones.Add(diamStone); quantCirclesStones.Add(1); } else { int currVal = quantCirclesStones[match]; quantCirclesStones[match] = currVal + 1; } } } Rhino.DocObjects.Material mat = rhObj.GetMaterial(true); var objMatName = mat.Name; int pos = Array.IndexOf(matName, objMatName); if (pos == -1) { continue; } switch (pos) { //18ctGold case int n when(n < 4): double gold18ct = 0.016; CalMat(doc, gold18ct, objType, objref, metalItems, matName, pos, " g"); break; //Silver case 4: double silver = 0.0105; CalMat(doc, silver, objType, objref, metalItems, matName, pos, " g"); break; //Platinum case 5: double platinum = 0.0203; CalMat(doc, platinum, objType, objref, metalItems, matName, pos, " g"); break; //ColorStones ruby=4g Emerald=2.65g saphr=4g Paraiba=3g Granat=3.9g Amethyst=2.65 Morganite=2.65 case 6: double ruby = 0.02; CalMat(doc, ruby, objType, objref, stoneItems, matName, pos, " ct"); break; case 7: double emerald = 0.0133; CalMat(doc, emerald, objType, objref, stoneItems, matName, pos, " ct"); break; case 8: double saphir = 0.02; CalMat(doc, saphir, objType, objref, stoneItems, matName, pos, " ct"); break; case 9: double paraiba = 0.015; CalMat(doc, paraiba, objType, objref, stoneItems, matName, pos, " ct"); break; case 10: double granat = 0.0195; CalMat(doc, granat, objType, objref, stoneItems, matName, pos, " ct"); break; case 11: double amethyst = 0.0133; CalMat(doc, amethyst, objType, objref, stoneItems, matName, pos, " ct"); break; case 12: double morganite = 0.0133; CalMat(doc, morganite, objType, objref, stoneItems, matName, pos, " ct"); break; //Diamond case 13: double diamond = 0.02; CalMat(doc, diamond, objType, objref, stoneItems, matName, pos, " ct"); break; } } metalItems.Sort(); stoneItems.Sort(); allItems.Add("------Metals(g)/Stones(ct) from solids-------"); for (int i = 0; i < materials.Length; i++) { if (materials[i] == 0) { continue; } allItems.Add(matName[i] + ": " + materials[i]); } /* * allItems.Add("--------------Metals--------------"); * for (int i = 0; i < metalItems.Count; i++) * { * allItems.Add(metalItems[i]); * } * * allItems.Add("--------------Stone---------------"); * for (int i = 0; i < stoneItems.Count; i++) * { * allItems.Add(stoneItems[i]); * } */ allItems.Add("-----------------------------------------------"); allItems.Add(""); allItems.Add("-----------Brillants from circles------------"); double totalCt = 0.0; for (int i = 0; i < circleStones.Count; i++) { double ct; ct = Math.Round((circleStones[i] * circleStones[i] * circleStones[i] * 0.6 * 0.0061), 4, MidpointRounding.AwayFromZero); allItems.Add("Brill: " + quantCirclesStones[i] + " x " + circleStones[i] + " mm " + ct + " ct Total: " + ct * quantCirclesStones[i] + " ct"); totalCt = totalCt + ct * quantCirclesStones[i]; } allItems.Add("Total brillant weight: " + totalCt + " ct"); allItems.Add("-----------------------------------------------"); String clipboardString = ""; foreach (String o in allItems) { clipboardString = clipboardString + o + "\n"; } Clipboard.SetText(clipboardString); if (open > 0) { Dialogs.ShowMessage("At least one object is not closed. Weights might be false.", "Warning!"); } Dialogs.ShowListBox("Report", "This data is copied to your clipboard \n Use Ctrl+V to paste", allItems); materials = new double[14]; open = 0; return(Result.Success); }
public override void SimulateMaterial(ref Rhino.DocObjects.Material simulatedMaterial, bool forDataOnly) { base.SimulateMaterial(ref simulatedMaterial, forDataOnly); simulatedMaterial.DiffuseColor = Color.DeepSkyBlue; }
/// <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) { List <IGH_GeometricGoo> objs = new List <IGH_GeometricGoo>(); DA.GetDataList(0, objs); string layerName = "Default"; object material = null; bool clearL = false; DA.GetData(1, ref layerName); DA.GetData(2, ref material); /*Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes(); * att.LayerIndex = doc.Layers.Find(layerName, true); * att.MaterialIndex = doc.Materials.Find(matName, true);*/ Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes(); //Set material if (material != null) { string matName = ""; DisplayMaterial mat = new DisplayMaterial(); Color col = new Color(); int isName = -1; int materialIndex = -1; try { matName = (material as GH_String).Value; isName = 1; } catch { try { mat = (material as GH_Material).Value; isName = 0; } catch { try { col = (material as GH_Colour).Value; mat = new DisplayMaterial(col); isName = 0; } catch { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Can't identify material object. Please supply render material name, GH material or color."); } } } if (isName == 1) { materialIndex = doc.Materials.Find(matName, true); att.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject; if (materialIndex < 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Couldn't find material by name. If you're sure the material exists in the Rhino Material list, try adding it to one object manually. After that it should work."); } att.MaterialIndex = materialIndex; } else { materialIndex = doc.Materials.Add(); if (materialIndex > -1) { Rhino.DocObjects.Material m = doc.Materials[materialIndex]; m.Name = matName; m.AmbientColor = mat.Ambient; m.DiffuseColor = mat.Diffuse; m.EmissionColor = mat.Emission; //m.ReflectionColor = no equivalent m.SpecularColor = mat.Specular; m.Shine = mat.Shine; m.Transparency = mat.Transparency; //m.TransparentColor = no equivalent m.CommitChanges(); att.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject; att.MaterialIndex = materialIndex; } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Couldn't add material. Try cleaning up your materials."); //This never happened to me. } } } DA.GetData(3, ref att); DA.GetData(4, ref clearL); //Delete objects by GUID doc.Objects.Delete(ids, true); for (int i = 0; i < objs.Count; i++) { GeometryBase gb; Point3d pt; Brep b; if (ids.Count <= i) { ids.Add(Guid.NewGuid()); } att.ObjectId = ids[i]; if (objs[i].CastTo <Point3d>(out pt)) { doc.Objects.AddPoint(pt, att); } else if (objs[i].CastTo <Brep>(out b)) { doc.Objects.AddBrep(b, att); } else if (objs[i].CastTo <GeometryBase>(out gb)) { doc.Objects.Add(gb, att); } else { throw new Exception("Object nr. " + i + " is not bakeable:\n" + objs[i].ToString() + ".\nIf it's a box or a curve, try turning it into a Brep by wiring it through a Brep container component before feeding it to Instant Bake."); } } if (clearL) { foreach (Rhino.DocObjects.RhinoObject o in doc.Objects.FindByLayer(layerName)) { doc.Objects.Delete(o, true); } } if (counter >= 10) { Rhino.RhinoDoc.ActiveDoc.ClearUndoRecords(true); counter = 0; } DA.SetDataList(0, ids); counter++; }
/// <summary> /// This method simulates the selected material in the Rhino viewport. /// </summary> /// <param name="simulation">Set the properties of the input basic material to provide the simulation for this material.</param> /// <param name="isForDataOnly">Called when only asking for a hash - don't write any textures to the disk - /// just provide the filenames they will get.</param> public override void SimulateMaterial(ref Rhino.DocObjects.Material simulation, bool isForDataOnly) { ReadDataFromUI(); //if (IntIOR.FirstParameter > 0) simulation.Transparency = 0.5D; simulation.Transparency = 0.5D; }
public override void SimulateMaterial(ref Rhino.DocObjects.Material simulation, bool isForDataOnly) { ReadDataFromUI(); //TODO simulate conductor como simular oro, cobre... ????? }
static int OnReturnBoolGeneralCallback(int serial_number, int iVirtualFunction, IntPtr pObj, IntPtr pMat, IntPtr pMesh, IntPtr pView, int rectLeft, int rectTop, int rectRight, int rectBottom) { try { RenderPipeline pipe = RenderPipeline.FromSerialNumber(serial_number); if (pipe != null) { switch ((VirtualFunctions)iVirtualFunction) { case VirtualFunctions.StartRendering: return(pipe.OnRenderBegin() ? 1 : 0); case VirtualFunctions.StartRenderingInWindow: { Rhino.Display.RhinoView view = Rhino.Display.RhinoView.FromIntPtr(pView); System.Drawing.Rectangle rect = System.Drawing.Rectangle.FromLTRB(rectLeft, rectTop, rectRight, rectBottom); return(pipe.OnRenderWindowBegin(view, rect) ? 1 : 0); } case VirtualFunctions.StopRendering: pipe.OnRenderEnd(new RenderEndEventArgs()); return(1); case VirtualFunctions.NeedToProcessGeometryTable: return(pipe.NeedToProcessGeometryTable() ? 1 : 0); case VirtualFunctions.NeedToProcessLightTable: return(pipe.NeedToProcessLightTable() ? 1 : 0); case VirtualFunctions.RenderSceneWithNoMeshes: return(pipe.RenderSceneWithNoMeshes() ? 1 : 0); case VirtualFunctions.RenderPreCreateWindow: return(pipe.RenderPreCreateWindow() ? 1:0); case VirtualFunctions.RenderEnterModalLoop: return(pipe.RenderEnterModalLoop() ? 1 : 0); case VirtualFunctions.RenderExitModalLoop: return(pipe.RenderExitModalLoop() ? 1 : 0); case VirtualFunctions.RenderContinueModal: return(pipe.ContinueModal() ? 1 : 0); case VirtualFunctions.IgnoreRhinoObject: { if (pObj != IntPtr.Zero) { Rhino.DocObjects.RhinoObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj); if (obj != null) { return(pipe.IgnoreRhinoObject(obj) ? 1 : 0); } } } return(0); case VirtualFunctions.AddLightToScene: { if (pObj != IntPtr.Zero) { Rhino.DocObjects.LightObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj) as Rhino.DocObjects.LightObject; if (obj != null) { return(pipe.AddLightToScene(obj) ? 1 : 0); } } } return(0); case VirtualFunctions.AddRenderMeshToScene: { if (pObj != IntPtr.Zero && pMat != IntPtr.Zero && pMesh != IntPtr.Zero) { Rhino.DocObjects.RhinoObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj); Rhino.DocObjects.Material mat = Rhino.DocObjects.Material.NewTemporaryMaterial(pMat); //Steve....you need to look at this Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(pMesh, obj); return(pipe.AddRenderMeshToScene(obj, mat, mesh) ? 1:0); } } return(0); } } } catch (Exception ex) { Rhino.Runtime.HostUtils.ExceptionReport(ex); } Debug.Assert(false); return(0); }
/// <summary>Modify material settings.</summary> /// <param name="newSettings">This information is copied.</param> /// <param name="materialIndex"> /// zero based index of material to set. This must be in the range 0 <= layerIndex < MaterialTable.Count. /// </param> /// <param name="quiet">if true, information message boxes pop up when illegal changes are attempted.</param> /// <returns> /// true if successful. false if materialIndex is out of range or the settings attempt /// to lock or hide the current material. /// </returns> public bool Modify(Rhino.DocObjects.Material newSettings, int materialIndex, bool quiet) { IntPtr pConstMaterial = newSettings.ConstPointer(); return(UnsafeNativeMethods.CRhinoMaterialTable_ModifyMaterial(m_doc.m_docId, pConstMaterial, materialIndex, quiet)); }
public static void OptToRhino(OptFile opt, string rhinoPath, bool scale) { if (opt == null) { throw new ArgumentNullException("opt"); } string rhinoDirectory = Path.GetDirectoryName(rhinoPath); string rhinoName = Path.GetFileNameWithoutExtension(rhinoPath); var distances = opt.Meshes .SelectMany(t => t.Lods) .Select(t => t.Distance) .Distinct() .OrderByDescending(t => t) .ToArray(); for (int distance = 0; distance < distances.Length; distance++) { using (var file = new Rhino.FileIO.File3dm()) { file.Settings.ModelUnitSystem = Rhino.UnitSystem.Meters; int objectsIndex = 0; List <string> textureNames = new List <string>(); foreach (var mesh in opt.Meshes) { var lod = mesh.Lods.FirstOrDefault(t => t.Distance <= distances[distance]); if (lod == null) { continue; } foreach (var textureName in lod.FaceGroups .Where(t => t.Textures.Count > 0) .Select(t => t.Textures[0])) { if (!textureNames.Contains(textureName)) { textureNames.Add(textureName); } } string meshName = string.Format(CultureInfo.InvariantCulture, "{0}.{1:D3}", mesh.Descriptor.MeshType, objectsIndex); using (var layer = new Rhino.DocObjects.Layer()) { layer.Name = meshName; file.Layers.Add(layer); } foreach (var faceGroup in lod.FaceGroups) { using (var rhinoMesh = new Rhino.Geometry.Mesh()) using (var rhinoAttributes = new Rhino.DocObjects.ObjectAttributes()) { rhinoAttributes.Name = meshName; rhinoAttributes.LayerIndex = objectsIndex; if (faceGroup.Textures.Count > 0) { rhinoAttributes.MaterialIndex = textureNames.IndexOf(faceGroup.Textures[0]); } Action <Vector> addVertex; if (scale) { addVertex = vertex => rhinoMesh.Vertices.Add(vertex.X * OptFile.ScaleFactor, vertex.Y * OptFile.ScaleFactor, vertex.Z * OptFile.ScaleFactor); } else { addVertex = vertex => rhinoMesh.Vertices.Add(vertex.X, vertex.Y, vertex.Z); } Action <TextureCoordinates> addTexCoords = texCoords => rhinoMesh.TextureCoordinates.Add(texCoords.U, -texCoords.V); Action <Vector> addNormal = normal => rhinoMesh.Normals.Add(normal.X, normal.Y, normal.Z); int facesIndex = 0; foreach (var face in faceGroup.Faces) { var verticesIndex = face.VerticesIndex; var texCoordsIndex = face.TextureCoordinatesIndex; var normalsIndex = face.VertexNormalsIndex; addVertex(mesh.Vertices[verticesIndex.A]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.A]); addNormal(mesh.VertexNormals[normalsIndex.A]); facesIndex++; addVertex(mesh.Vertices[verticesIndex.B]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.B]); addNormal(mesh.VertexNormals[normalsIndex.B]); facesIndex++; addVertex(mesh.Vertices[verticesIndex.C]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.C]); addNormal(mesh.VertexNormals[normalsIndex.C]); facesIndex++; if (verticesIndex.D >= 0) { addVertex(mesh.Vertices[verticesIndex.D]); addTexCoords(mesh.TextureCoordinates[texCoordsIndex.D]); addNormal(mesh.VertexNormals[normalsIndex.D]); facesIndex++; } if (verticesIndex.D < 0) { rhinoMesh.Faces.AddFace(facesIndex - 1, facesIndex - 2, facesIndex - 3); } else { rhinoMesh.Faces.AddFace(facesIndex - 1, facesIndex - 2, facesIndex - 3, facesIndex - 4); } } rhinoMesh.Compact(); file.Objects.AddMesh(rhinoMesh, rhinoAttributes); } } objectsIndex++; } foreach (var textureName in textureNames) { Texture texture; opt.Textures.TryGetValue(textureName, out texture); using (var material = new Rhino.DocObjects.Material()) { material.Name = textureName; if (texture == null) { material.DiffuseColor = System.Drawing.Color.White; } else { texture.Save(Path.Combine(rhinoDirectory, textureName + ".png")); material.SetBitmapTexture(textureName + ".png"); if (texture.HasAlpha) { texture.SaveAlphaMap(Path.Combine(rhinoDirectory, textureName + "_alpha.png")); material.SetTransparencyTexture(textureName + "_alpha.png"); } } file.Materials.Add(material); } } file.Write(Path.Combine(rhinoDirectory, string.Format(CultureInfo.InvariantCulture, "{0}_{1}.3dm", rhinoName, distance)), 4); } } }
public static Rhino.Commands.Result AddTexture(Rhino.RhinoDoc doc) { // Select object to add texture const ObjectType filter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter | Rhino.DocObjects.ObjectType.Mesh; Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object to add texture", false, filter, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.DocObjects.RhinoObject rhino_object = objref.Object(); if (rhino_object == null) { return(Rhino.Commands.Result.Failure); } // Select texture Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog(); fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg"; if (!fd.ShowDialog()) { return(Rhino.Commands.Result.Cancel); } // Verify texture string bitmap_filename = fd.FileName; if (string.IsNullOrEmpty(bitmap_filename) || !System.IO.File.Exists(bitmap_filename)) { return(Rhino.Commands.Result.Nothing); } // Make sure the object has it's material source set to "material_from_object" rhino_object.Attributes.MaterialSource = Rhino.DocObjects.ObjectMaterialSource.MaterialFromObject; // Make sure the object has a material assigned int material_index = rhino_object.Attributes.MaterialIndex; if (material_index < 0) { // Create a new material based on Rhino's default material material_index = doc.Materials.Add(); // Assign the new material (index) to the object. rhino_object.Attributes.MaterialIndex = material_index; } if (material_index >= 0) { Rhino.DocObjects.Material mat = doc.Materials[material_index]; mat.SetBumpTexture(bitmap_filename); mat.CommitChanges(); //Don't forget to update the object, if necessary rhino_object.CommitChanges(); doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } return(Rhino.Commands.Result.Failure); }
/// <summary> /// /// </summary> /// <param name="simulation"></param> /// <param name="isForDataOnly"></param> public override void SimulateMaterial(ref Rhino.DocObjects.Material simulation, bool isForDataOnly) { ReadDataFromUI(); //TODO simulate RoughConductorMaterial }