I need to perform some processing on points of a mesh based on a grayscale map, but I’m currently unable to obtain accurate grayscale values. Can anyone help me? @fraguada @andy @nathanletwory
mesh.3dm (5.7 MB)
meshColor.gh (8.3 KB)
The following code produces correct results when no transform is applied to the texture mapping, but fails to compute the correct color once the texture is repeated, offset, or rotated
private void RunScript(Guid meshId, Guid ptId, ref object A, ref object B)
{
MeshObject mObj = RhinoDoc.ActiveDoc.Objects.FindId(meshId) as MeshObject;
PointObject pObj = RhinoDoc.ActiveDoc.Objects.FindId(ptId) as PointObject;
if (pObj == null) return;
if (mObj == null) return;
int[] channels = mObj.GetTextureChannels();
if (channels.Length == 0)
{
Rhino.RhinoApp.WriteLine("111");
return;
}
Point3d closestPoint = mObj.MeshGeometry.ClosestPoint(pObj.PointGeometry.Location);
TextureMapping mapping = mObj.GetTextureMapping(channels[0]);
Point3d t;
int re = mapping.Evaluate(closestPoint, Vector3d.ZAxis, out t);
if (re == 0)
{
return;
}
RenderTexture renderTexture = mObj.GetRenderMaterial(true).GetTextureFromUsage(RenderMaterial.StandardChildSlots.Diffuse);
TextureEvaluator textureEvaluator = renderTexture.CreateEvaluator(RenderTexture.TextureEvaluatorFlags.Normal);
Color color = textureEvaluator.GetColor(t, Vector3d.ZAxis, Vector3d.ZAxis).AsSystemColor();
A = color;
}