Hi @johntravolski,
thank you for reaching out to us. Please remember that we need the user's coding environment, os and Cinema 4D version attached as tags to questions in order to answer them in the best way possible. I have added a Python tag to your posting, please add the missing information. I also moved your posting into the Development forum. You can learn more about the forum's tagging feature and general support procedures in the Forum Guidelines.
About your question:
What you are trying to do can be and should be done with a Python generator object, since such tasks are its main use case. Cinema 4D does however not provide an auto-triangulation routine in the Python generator, like you might be used to from the various plotting environments out there, e.g. matplotlib
or Mathematica/Wolfram
. The Python generator is not a plotting tool, but a pruned version of an ObjectData
plugin, allowing you to build arbitrary shapes (at the cost of not having an automesher like provide by matplotlib.mplot3d
for example). Cinema does also not support complex numbers as point coordinates, since its vector space is exclusively R³
- at least for polygon objects. You can however use Python's complex
module if you want to deal with complex numbers and then map these into R³
.
Below you will find the code for your example and also a file with a Python generator in it, running that code.
Cheers,
Ferdinand
the file:
wedge_shape_generator.c4d
the code:
import c4d
# Your vertex data expressed as c4d.Vector instances.
VERTEX_DATA = [
c4d.Vector(1, 1, 1), c4d.Vector(1, 1, -1),
c4d.Vector(0, 0, 1), c4d.Vector(0, 0, -1),
c4d.Vector(-1, 1, 1), c4d.Vector(-1, 1, -1),
]
SCALE = 100.
def main():
"""
"""
# Create a polygon object node setup for 6 vertices and 2 polygons.
node = c4d.PolygonObject(pcnt=6, vcnt=2)
# Your data is rather small, so we have to scale it a bit up.
points = [p * SCALE for p in VERTEX_DATA]
# Set all points.
node.SetAllPoints(points)
# Now we have to create the polygons which are represented by CPolygon in
# Cinema 4D. Cinema has no rectangular auto-mesher which will
# automatically triangulate a point cloud provided in a certain way, like
# for example provided by matplotlib in Python, Mathematica/Wolfram or
# similar math packages.
# In this case we could iterate in a convenient fashion over our data
# due to its regular nature. I will doe it however manually for clarity.
# The first polygon: CPolygon references point indices in its attributes
# a, b, c and d. In Cinema all non-gons are represented by CPolygon,
# including triangles, which just repeat their third index in d.
#
# We index our vertices here. The a bit odd index order is caused by
# how you did provide your data. Polygons are organized ccw for forward-
# facing normals in Cinema, read more about it here [1].
cpoly = c4d.CPolygon(0, 1, 3, 2)
# Then we add the first polygon to our mesh.
node.SetPolygon(0, cpoly)
# Now we do the same with the second polygon. We have to reindex the
# vertices 2 and 3 here, since they are shared by both polygons.
cpoly = c4d.CPolygon(2, 3, 5, 4)
node.SetPolygon(1, cpoly)
# And we are done and can return our little wedge shape.
return node
# Links
# [1] https://developers.maxon.net/docs/Cinema4DPythonSDK/html/manuals/3d_concept/modeling/polygon_object.html#polygon-object