Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Register
    • Login
    1. Maxon Developers Forum
    2. Tpaxep
    3. Topics
    T
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 7
    • Groups 0

    Topics

    • T

      Reverse direction of multi-segment splines

      Watching Ignoring Scheduled Pinned Locked Moved Cinema 4D SDK windows 2024 python
      6
      0 Votes
      6 Posts
      35 Views
      ferdinandF
      Okay, I think I was a bit overly cautious in my answer here. You gave my a very broad question, or to be precise, you gave me a video and a scene file, and did not really ask a precise question. I understand that asking good questions can be hard, especially with a language barrier. But when I have nothing to go by, I of course assume the worst case possible. The scene you have there is a trivial case, even the best case possible. You have there spline segments which lie in a perfect plane and which have no self intersections. You can treat them just like polygons (in the CG sense, not in the mathematical sense) and simply compute their normal over the first three vertices of each segment. Due to the fundamental property of a polygon - reversing the order of the vertices reverses the normal - you can then easily determine if two segments have opposite or equal winding. But all this starts to fall apart, as soon as you cannot make these assumptions. And I cannot help you to write the code for this, as this is then more than just a few lines. Hope this helps, and that I my answer was now less 'overly cautious'. Cheers, Ferdinand Result [image: 1780950951310-85f415e7-7f45-4c00-9651-b4091ee543e2-image.png] The code correctly identifies that in this six segment spline are four segments of one winding direction (clockwise in this case) and two of the other winding direction. winding_direction.c4d Code """Treats spline segments as polygons and compares their plane normals to find segments with reversed winding order. """ import c4d op: c4d.SplineObject # The currently active object in the scene. def main() -> None: """Called by Cinema 4D when the script is being executed. """ if not isinstance(op, c4d.SplineObject): return c4d.gui.MessageDialog("Please select a spline object.") # Get all points in the spline and organize them into their segments. points: list[c4d.Vector] = op.GetAllPoints() segments: list[list[c4d.Vector]] = [] j: int = 0 for i in [op.GetSegment(i)["cnt"] for i in range(op.GetSegmentCount())]: segments.append(points[j:j+i]) j += i if len(segments) < 2: return c4d.gui.MessageDialog("Please select a spline object with at least 2 segments.") # Now build normal data for the spline segments. This assumes: # # - A spline where all points lie in a single plane, a '2D' spline in 3D space. # - No self intersections in the spline. # - A piecewise linear spline, i.e., what Cinema 4D calls a 'Linear' spline. When we have a # 'Cubic' or 'Bezier' spline, we would have make it linear with 'Current State to Object' # first. # # We build the normal for each segment over its three first vertices. The reason why we are doing # this is because of the fundamental identity of a polygon (in a computer graphics sense), # reversing the order of the vertices of a polygon will reverse the normal. So if we have a # spline with two segments with reversed winding order, they will have antiparallel normals (normals # pointing in opposite directions). segmentNormals: list[c4d.Vector] = [] for segment in segments: if len(segment) < 3: print("Segment has less than 3 points, skipping normal calculation.") continue a, b, c = segment[0], segment[1], segment[2] edge1: c4d.Vector = b - a edge2: c4d.Vector = c - b normal: c4d.Vector = edge1.Cross(edge2).GetNormalized() segmentNormals.append(normal) # Now we just declare one segment as 'ground truth' and check if the other segments have normals # that are parallel or antiparallel to it. When we found a segment with an antiparallel normal, we # know we found a segment with reversed winding order. To check if two normals are parallel or # antiparallel, we just compute their dot product (i.e., spanned angle). When the dot product is # negative, the normals are antiparallel. print(f"Establishing the first segment normal {segmentNormals[0]} as ground truth.") baseNormal: c4d.Vector = segmentNormals[0] for i, normal in enumerate(segmentNormals[1:], start=1): isAntiparallel: bool = baseNormal.Dot(normal) < 0 print(f"Segment {i} normal: {normal} is {'antiparallel' if isAntiparallel else 'parallel'} " f"to the base normal {baseNormal}.") if __name__ == '__main__': main()
    • T

      Best way to hide a child and get best perfomance

      Watching Ignoring Scheduled Pinned Locked Moved Cinema 4D SDK 2025 python windows
      7
      0 Votes
      7 Posts
      461 Views
      T
      Here's my prototype, if you are interested in my goal Right now, everything works as expected, but only with these lines of code. profile = GetCloneSpline(profile_orig) path = GetCloneSpline(path_orig) I'm happy with the current result. So, I'd love to get some additional advice on correctness and optimization. I think your previous answer was comprehensive enough, so I'll try to integrate some of it. But I'd also be very grateful if you could take a look at my plugin and perhaps give me some more specific optimization tips. If that's not too much trouble, of course! @ferdinand @ThomasB Anyway, thanks for your replies and advices!
    • T

      Edge ring selection

      Watching Ignoring Scheduled Pinned Locked Moved Cinema 4D SDK 2024 python windows
      2
      0 Votes
      2 Posts
      691 Views
      M
      Hi @Tpaxep, 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: How to Ask Questions. About your First Question The tool has indeed been updated, but the docs were not. Here is how to call it. Note that you have to pass a polygon index, this is mandatory and it needs to be adjacent to one of the vertex to indicate a direction of the ring selection. Here is your script adapted, to be run on a sphere that was made editable. import c4d from c4d import utils def select_ring_edge(obj, v1Id, v2Id, polyId): bc = c4d.BaseContainer() bc.SetData(c4d.MDATA_RING_SEL_STOP_AT_SELECTIONS, False) bc.SetData(c4d.MDATA_RING_SEL_STOP_AT_NON_QUADS, False) bc.SetData(c4d.MDATA_RING_SEL_STOP_AT_POLES, True) bc.SetData(c4d.MDATA_RING_BOTH_SIDES, False) bc.SetData(c4d.MDATA_RING_SWAP_SIDES, False) bc.SetData(c4d.MDATA_RING_FIRST_VERTEX, v1Id) bc.SetData(c4d.MDATA_RING_SECOND_VERTEX, v2Id) bc.SetData(c4d.MDATA_RING_POLYGON_INDEX, polyId) bc.SetData(c4d.MDATA_RING_SELECTION, c4d.SELECTION_NEW) result = c4d.utils.SendModelingCommand( command=c4d.ID_MODELING_RING_TOOL, list=[obj], mode=c4d.MODELINGCOMMANDMODE_EDGESELECTION, bc=bc, doc=c4d.documents.GetActiveDocument(), flags=c4d.MODELINGCOMMANDFLAGS_NONE ) c4d.EventAdd() return result def main(): doc = c4d.documents.GetActiveDocument() obj = doc.GetActiveObject() if obj is None: c4d.gui.MessageDialog("select obj.") return firstVertex = 346 secondVertex = 347 polygonIndex = 312 result = select_ring_edge(obj, firstVertex, secondVertex, polygonIndex) if result: print("DONE") else: print("ERROR") if __name__ == '__main__': main() Note that the same settings also apply for the ID_MODELING_LOOP_TOOL, just modify RING by LOOP in the constant so MDATA_RING_SEL_STOP_AT_SELECTIONS become MDATA_LOOP_SEL_STOP_AT_SELECTIONS. Cheers, Maxime.