Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using Rhino;
- using Rhino.Commands;
- using Rhino.Geometry;
- using Rhino.Input;
- using Rhino.Input.Custom;
- namespace MaterialTextureEvaluator
- {
- [System.Runtime.InteropServices.Guid("af615033-e864-4a1e-afc8-463429426672")]
- public class MaterialTextureEvaluatorCommand : Command
- {
- public MaterialTextureEvaluatorCommand()
- {
- // Rhino only creates one instance of each command class defined in a
- // plug-in, so it is safe to store a refence in a static property.
- Instance = this;
- }
- ///<summary>The only instance of this command.</summary>
- public static MaterialTextureEvaluatorCommand Instance
- {
- get; private set;
- }
- ///<returns>The command name as it appears on the Rhino command line.</returns>
- public override string EnglishName
- {
- get { return "MaterialTextureEvaluatorCommand"; }
- }
- protected override Result RunCommand(RhinoDoc doc, RunMode mode)
- {
- int index = doc.Materials.Add();
- Rhino.DocObjects.Material mat = doc.Materials[index];
- mat.SetBitmapTexture("C:\\colgrid.png");
- mat.Name = "Testing";
- mat.DiffuseColor = System.Drawing.Color.Chocolate;
- mat.SpecularColor = System.Drawing.Color.CadetBlue;
- mat.CommitChanges();
- var rm = Rhino.Render.RenderMaterial.CreateBasicMaterial(mat);
- if(rm == null)
- {
- RhinoApp.WriteLine("no rendermaterial");
- return Result.Failure;
- }
- var diffslot = rm.TextureChildSlotName(Rhino.Render.RenderMaterial.StandardChildSlots.Diffuse);
- var rt = rm.FindChild(diffslot) as Rhino.Render.RenderTexture;
- using (var eval = rt.CreateEvaluator())
- {
- var zp = new Vector3d(0.0, 0.0, 0.0);
- for (int y = 0; y < 15; y++)
- {
- for (int x = 0; x < 15; x++)
- {
- var p = new Point3d(x / 15.0, y / 15.0, 0.0); // create a UV coordinate
- var c = eval.GetColor(p, zp, zp);
- if (y < 10 && x < 10) RhinoApp.WriteLine($"{p.X},{p.Y},{p.Z} - {c.R} {c.G} {c.B}");
- }
- }
- }
- return Result.Success;
- }
- }
- }
Add Comment
Please, Sign In to add comment