How to add material in plugin?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/11/2012 at 09:05, xxxxxxxx wrote:
It's always the seemingly smallest of problems that have me stumped as I learn Python. Par for the course?
I've been doing pretty well making object plugins, but now that I'm trying to add material to my objects I'm having problems. Within GetVirtualObjects I create my objects and parent them under (parented to) a null which is returned at the end. I add a material tag and assign a material, but since I can't parent the material to my main object null, I have to add it to the scene (doc.InsertMaterial(Mat)). When I update the scene with a slider or a changing value the material gets updated and copied into the scene, which results in many copies.
I understand that the way that programs work is that the nodes are constantly being recreated when they receive new data, which is why this is happening. There is probably something that I'm missing such as catching a Message sent and only getting the latest material node, but I haven't figured out how to do this yet. I'll be glad to share my code if it is needed. Help anyone?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/11/2012 at 09:33, xxxxxxxx wrote:
Check if your material with a specific name is already in the MM and only create it
if it's not there. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/11/2012 at 10:19, xxxxxxxx wrote:
Thanks for the reply. I did try this with the following code (towards the bottom) :
def __init__(self) : self.SetOptimizeCache(True) def Init(self, op) : self.InitAttr(op, int, [11001]) op[11001]= 100 return True def GetVirtualObjects(self, op, hierarchyhelp) : doc = c4d.documents.GetActiveDocument() myData = op.GetDataInstance() baseNull = c4d.BaseObject(c4d.Onull) skyI = c4d.BaseObject(c4d.Osky) txtTagI = skyI.MakeTag(c4d.Ttexture) skyI.InsertUnder(baseNull) lMat = c4d.BaseMaterial(5703) lMat[c4d.ID_BASELIST_NAME] = "Light Mat" txtLink = myData.GetData(11000) if txtLink != None: # -- Lighting Material bsbit = c4d.BaseList2D(c4d.Xbitmap) #create a bitmap baseshader bsbit[c4d.BITMAPSHADER_FILENAME] = txtLink bsLum = c4d.BaseList2D(c4d.Xfilter)#Create a filter baseshader lMat[c4d.MATERIAL_LUMINANCE_SHADER] = bsLum bsLum[c4d.SLA_FILTER_TEXTURE] = bsbit lMat[c4d.MATERIAL_LUMINANCE_TEXTUREMIXING] = 3 lMat[c4d.MATERIAL_LUMINANCE_BRIGHTNESS] = myBrightness lMat.InsertShader(bsLum)#insert the shaders under the shader that uses it bsLum.InsertShader(bsbit)#insert the shaders under the shader that uses it lMat.Message(c4d.MSG_UPDATE)#update lMat.Update(True, True) lMat[c4d.MATERIAL_USE_LUMINANCE] = 1 lMat[c4d.MATERIAL_USE_COLOR] = 0 lMat[c4d.MATERIAL_USE_SPECULAR] = 0 txtTagI[c4d.TEXTURETAG_MATERIAL] = lMat matList = doc.GetMaterials() for i in range(len(matList)) : if matList[i].GetName() == "Light Mat": x = 1 try: if x != 1: doc.InsertMaterial(lMat) except: doc.InsertMaterial(lMat) return baseNull
This did work, but then my material tag didn't connect to the material. I think this is because the material is still being created in cache and the tag is looking for the latest updated material, not the original one created in the scene. Does that make sense?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/11/2012 at 11:42, xxxxxxxx wrote:
You need to do all your settings on an existing material.
First check if the material is there. If not, create it.
Insert it in the texture tag.
Then do the settings on the material.You might need to run the the SetOptimize(False) instead of True
and run a CheckDirty() function before you plugin class to control
the cacheing.Cheers
Lennart -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/11/2012 at 14:07, xxxxxxxx wrote:
Thanks Lennart. I guess I need to learn about money laundering...I mean CheckDirty() Cache functions. Your post: (GetContour() refress or uncache? How) is informative. If you have any other suggested locations to learn more about dealing with cache and CheckDirty(), please let me know. I'm reading up on the little that I see on it in the SDK now.