I trimmed a textured mesh with an arbitrary curve using a Python script and the texturing in the trimmed mesh perfectly matches the appearance of the original mesh right up to the boundary if I go to the Materials tab and turn on self-illumination. How do I do turn on self-illumination in the Python script?
Trimmed, textured mesh with self-illumination manually turned-on:
I leveraged your last three material lines in my Python script and now it is working fine.
from scriptcontext import doc
# Make sure self-illumination is turned on or else the trimmed mesh will be dark.
material = doc.Materials[source_mat]
material.DisableLighting = True
material.CommitChanges()
for material in sc.doc.RenderMaterials:
material.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
material.SetParameter(âdisable-lightingâ, True)
material.EndChange()
Combining your code with @andy s code youâd have something like this:
# Make sure self-illumination is turned on or else the trimmed mesh will be dark.
mat = doc.Materials[source_mat]
material = mat.RenderMaterial
material.BeginChange(Rhino.Render.RenderContent.ChangeContexts.Program)
material.SetParameter(âdisable-lightingâ, True)
material.EndChange()
Have you tested this? It does not work for my case. The check box in front of Self-illumination under Advanced Options of the Materials tab does not turn on. So I am just using:
obj.Attributes.MaterialIndex = source_mat
obj.Attributes.MaterialSource = ObjectMaterialSource.MaterialFromObject
obj.CommitChanges()
# Make sure self-illumination is turned on or else trimmed mesh will be dark.
mat = doc.Materials[obj.Attributes.MaterialIndex] # Does not work if source_mat is used here.
mat.DisableLighting = True
mat.CommitChanges()
and left out the lines you suggested:
material = mat.RenderMaterial
material.BeginChange(Render.RenderContent.ChangeContexts.Program)
material.SetParameter('disable-lighting', True)
material.EndChange()
Yes I have tested this. The following script I used:
import scriptcontext as sc
import Rhino.Render as Render
for m in sc.doc.Materials:
rm = m.RenderMaterial
rm.BeginChange(Render.RenderContent.ChangeContexts.Program)
rm.SetParameter('disable-lighting', True)
rm.EndChange()
Your material is a very old-style material. You can see that in the material editor: you canât change its type. I donât know (yet?) how to get it converted programmatically, but you can do the following:
create an empty custom material
select old material
right-click on texture and choose copy
select new material
right-click on empty color texture slot anf select Paste as Instance
assign new material to you object
note that the old material disappears, that is normal.
obj.Attributes.MaterialIndex = source_mat
obj.Attributes.MaterialSource = ObjectMaterialSource.MaterialFromObject
obj.CommitChanges()
# Make sure self-illumination is turned on or else trimmed mesh will be dark.
mat = doc.Materials[obj.Attributes.MaterialIndex] # Does not work if source_mat is used here.
mat.DisableLighting = True
mat.CommitChanges()
I will try not to get distracted by the fact that the self-illumination checkbox is not checked. Manually checking and unchecking the Self-illumination box does toggle self-illumination for this mesh/material combination.
The Agisoft Photoscan program is generating the material. Maybe you could drop them a note about a better way to do the material.
The challenge with my discussing this with Agisoft is that I do not know what they should change about their material. The material is actually a jpg file on which they put u,v coordinates that are referenced by the texture coordinates in the OBJ file. Here is an example:
This work I am doing deals with 3D models generated by photogrammetry of 100âs of photos taken by a drone. From the model one can extract many interesting quantitative results: elevation maps, contour maps, tree count, tree heights, tree canopy diameter, tree volume, estimated tree yield, cut and fill of piles (like rocks, sand, construction materials).
I found that there are 4 choices when exporting to an OBJ file in Photoscan:
JPEG, PNG, TIFF and EXR.
Currently I am using JPEG.
Would PGN or TIFF or EXR work better with Rhino 6 for controlling the material self-illumination?