Create dynamic selection tag for voronoi fracture polygon index
-
So... I have a little problem, I have made a grid of objects made with Voronoi Fracture, and I'm trying to assign a material to each individual polygon from the fracture object. I can't see a way to assign a material based on the number index of a cloner/fracture object/voronoi object or create a list of selection tag on the voronoi fracture...
I wish that the index number could be a variable that we could use as a selection or tag! If anyone has an idea of how to tackle this issue, I would love to hear you out, this is what I have so far:import c4d def main(): # Get the active object, which should be a Voronoi Fracture object fracture_obj = doc.GetActiveObject() # Check if the object is a Voronoi Fracture object if fracture_obj is None or not fracture_obj.CheckType(c4d.Ofracture): raise RuntimeError("Please select a Voronoi Fracture object.") # Access the children of the Voronoi Fracture object (these are the fractured pieces) fracture_pieces = fracture_obj.GetChildren() # Ensure there are fracture pieces if not fracture_pieces: raise RuntimeError("No fracture pieces found. Please ensure the Voronoi Fracture is applied to an object.") # Loop through each fracture piece for i, piece in enumerate(fracture_pieces): # Create a unique polygon selection tag for each piece selection_tag = piece.MakeTag(c4d.Tpolygonselection) selection_tag.SetName(f"Piece_{i}_Selection") # Select all polygons of this fracture piece poly_selection = c4d.BaseSelect() poly_count = piece.GetPolygonCount() for poly_index in range(poly_count): poly_selection.Select(poly_index) # Assign the selection to the tag selection_tag.SetBaseSelect(poly_selection) # Refresh the scene to apply the changes c4d.EventAdd() # Execute the script if __name__ == '__main__':```
-
I actually found something that would help me A LOT but I can't find it anywhere online! what I described is what is possible with this python script:
CV-Parametric Selection Tag for Cinema 4D from Cineversity! I tried to find it but it's impossible to get my hand on it! can someone help please!
-
Hi @filsdegraphiste,
Welcome to the Maxon developers forum and its community, it is great to have you with us!Getting Started
Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.
- Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
- Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
- Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.
It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: Asking Questions.
About your First Question
Generally speaking what you're trying to do is not possible out of the box. There're many unknowns one needs to fix to make the workflow smooth (how do you define a list of materials to assign to fractures? what do you do if there's not enough materials? how do you distinguish between outside/inside polygons? etc..).
If you really want to achieve this, you can try using Python Generator to manually clone voronoi fracture cache (GetCache()), access its cached polygon objects and assign materials to them (related thread on material assignment topic). Please note, if you decide going this way that this is a very tricky route and there're many places that things can work not in a way you expect them to work, e.g. if you use cloners inside voronois fracture, or splines, or deformers... Also note that python generator is slow, so any scene larger than "a simple voronoi fracture with 20 points of a cube" will lead to significant performance slow downs.
With that's said, I leave below a very draft and dirty python generator script that just shows the concept.
You could likely achieve similar results with way less efficiency drops with our C++ API, so I suggest considering this option.
Cheers,
IliaThe scene to test the concept:
voronoi_mat_assignment.c4d
Please note, it's a very draft script, which lacks a lot of necessary checks, so you need to click "Force Update" button on Python Generator object, to actually see the result.The screenshot of the scene:
The screenshot of how simple Voronoi Fracture cache looks like:
The script in the python generator object:
import c4d from typing import Iterator doc: c4d.documents.BaseDocument # The document the object `op` is contained in. op: c4d.BaseObject # The Python generator object holding this code. hh: "PyCapsule" # A HierarchyHelp object, only defined when main is executed. def main() -> c4d.BaseObject: vorOrig = op.GetDown() vor = vorOrig.GetCache(hh).GetClone() fractures: list[c4d.BaseObject] = vor.GetChildren() curMaterial = None for fracOp in fractures: if curMaterial is None: curMaterial = doc.GetFirstMaterial() tag = fracOp.MakeTag(c4d.Ttexture) tag[c4d.TEXTURETAG_MATERIAL] = curMaterial curMaterial = curMaterial.GetNext() return vor
-
Hello @i_mazlov!
Thank you so much for your fast and thoughtful answer, I'm sorry if I didn't post to the right place or in the right form. I'm going to read the rules of the forum more.
I'm more a designer than a developer but I understand the solution path you provided to me and I truly appreciate it! Do you know anything about the CV-parametric selection tag from Cineversity? -
Hi @filsdegraphiste,
The links under the youtube video from Donnovan have been broken after updating Cineversity. I've contacted the Web team, they are working on it. As of today it looks like the links have been fixed (e.g. here is the link to the CV-Parametric selection tag tutorial on the Cineversity portal). However, it also looks like the project files are still broken. It might take the Web team some time to recover them completely.
The CV Toolbox in turn is available on downloads page under "Cineversity Legacy Downloads" section.
Cheers,
Ilia