Running Automatic UV for all objects
-
Hello everyone!
I'm making a Python script that applies Automatic UV algorithm for each object in the scene. This algorithm is used for making UVs for lightmaps for hundreds of objects for game engines. It means that I have two UVWs on each object: one for a texture and one for a lightmap.
The problem is that I don't know how to run "Automatic UV" algorithm with "Packed" mode for the object, I haven't found how to do this in the documentation.import c4d def main(): doc = c4d.documents.GetActiveDocument() objects = doc.GetObjects() #getting all objects for obj in objects: tags = obj.GetTags() #getting all tags lightmapTagIndex = 0 i = 0 for tag in tags: #finding tag with "Lightmap" name to avoid modifying UV tag for texture if str(tag.GetName()) == "Lightmap": lightmapTagIndex = i break i += 1 doc.SetActiveObject(obj, c4d.SELECTION_NEW) #selecting our object doc.SetActiveTag(tags[lightmapTagIndex], c4d.SELECTION_NEW) #selecting Lightmap tag #Pseudo Code: obj.RunAutimaticUV(mode.Packed) c4d.EventAdd() if __name__=='__main__': main()
I'm referencing to this Cinema4D's function:
Thank you for your help. -
@BineeMan here is my unwrap script, but I didn't find how to change to cubic or angle mode, there seems not a symbol in the .h file.
import c4d MCOMMAND_AUTOMATICUV = 1053624 def unwrap(node: c4d.BaseObject): doc = node.GetDocument() if isinstance(node, c4d.PolygonObject) and node.GetTag(c4d.Tuvw) is not None: pass elif isinstance(node, c4d.PolygonObject) and node.GetTag(c4d.Tuvw) is None: doc.AddUndo(c4d.UNDOTYPE_CHANGE, node) settings = c4d.BaseContainer() settings[c4d.MDATA_AUTOMATICUV_TAGINDEX] = 0 settings[c4d.MDATA_AUTOMATICUV_FORCESEAMS] = False settings[c4d.MDATA_AUTOMATICUV_OVERLAPMIRRORED] = False settings[c4d.MDATA_AUTOMATICUV_OVERLAPIDENTICAL] = False settings[c4d.MDATA_AUTOMATICUV_SPACING] = 0.01 settings[c4d.MDATA_AUTOMATICUV_USENORMALS] = True settings[c4d.MDATA_AUTOMATICUV_SPACINGASPECT] = 1.0 c4d.utils.SendModelingCommand(command = MCOMMAND_AUTOMATICUV, list=[node], mode=c4d.MODELINGCOMMANDMODE_POLYGONSELECTION, bc=settings, doc=doc) def do_it(): doc = c4d.documents.GetActiveDocument() for node in doc.GetActiveObjects(0): unwrap(node) c4d.EventAdd() if __name__ == '__main__': do_it()
-
Hi @BineeMan sorry for the late reply I was pretty busy Friday and thanks @Dunhou for demonstrating how
Packed
Auto UV work.
For Cubic and Angle you need to use c4d.modules.bodypaint.CallUVComman as demonstrated in the call_uv_command_ example.So for the
Angle
automatic UV you need to use the command IDc4d.UVCOMMAND_OPTIMALMAPPING
with the next parameters:- c4d.OPTIMALMAPPING_PRESERVEORIENTATION # Preserve Orientation
- c4d.OPTIMALMAPPING_STRETCHTOFIT # Stretch to Fit
- c4d.OPTIMALMAPPING_DISTORTION # Maximu, Distortion
- c4d.OPTIMALMAPPING_RELAXCOUNT # Relaxation Steps
- c4d.OPTIMALMAPPING_SPACING # Spacing
And for the
Cubic
automatic UV you need to use the command IDc4d.UVCOMMAND_OPTIMALCUBICMAPPING
with the next parameters:- c4d.OPTIMALMAPPING_PRESERVEORIENTATION # Preserve Orientation
- c4d.OPTIMALMAPPING_STRETCHTOFIT # Stretch to Fit
- c4d.OPTIMALMAPPING_TWOD # 2D
- c4d.OPTIMALMAPPING_AREAFAK # Maximum Area Factor
- c4d.OPTIMALMAPPING_RELAXCOUNT # Relaxation Steps
- c4d.OPTIMALMAPPING_SPACING # Spacing
Cheers,
Maxime. -