Work with Data in Cinema 4D
Different ways to import and work with CSV files
If you want to visualize data in 3D space, Maxon’s Cinema 4D is more of the immaculate 3D tool. SideFX Houdini was developed for procedural visualization, and is accordingly powerful when dealing with large data sets. And if you want to experience the content interactively in your browser, you can use the JavaScript library Three.js.
Nevertheless, the tool Cinema 4D, which is focused on design and motion graphics, offers some means to import and process data. Sometimes even without any programming knowledge at all. The result is a whole range of visualization possibilities, from classical infographics to experimental. In the following I will show the different techniques for importing and processing CSV files.
The possibilities shown here are:
· Convert values to points
· Create values as keyframes
· Importing values via the XPresso Python Node
· Add values via a script
· Add values via the Python tag
The CSV File
Entity,Code,Year,Annual CO₂ emissions (tonnes )
Afghanistan,AFG,1949,14656
Afghanistan,AFG,1950,84272
Afghanistan,AFG,1951,91600
Afghanistan,AFG,1952,91600
Afghanistan,AFG,1953,106256
Afghanistan,AFG,1954,106256
Afghanistan,AFG,1955,153888
Afghanistan,AFG,1956,183200
Afghanistan,AFG,1957,293120
Above you can see the first ten lines of a CSV (Comma-separated values) file (this was also used for this article). A CSV file usually has a header, the first line of the file. It is the column caption, and each row that follows lists the values. These are, as the name says, separated by commas. To process data in Cinema 4D as well as in any other file, a data set in this or a similar form is necessary.
Convert values to points
The easiest way to insert a CSV file. To do this, you load your data as dots in Cinema 4D. The weak point is here: That there are dots in 3D space, there are only three numbers per line. Text is not accepted.
This result is static and relatively boring so far. But now the MoGraph tools of Cinema 4D can be used to further modify or animate the object. One possibility is to drag the created source into the Point Source of the MoGraph object Voronoi Fracture and “break it open” with the Push Apart Effector:
Create values as keyframes
It is also possible to load the values of the CSV file as keyframes in Cinema 4D. This allows objects to be animated based on data. This is actually for importing MoCap data, but you can import any other data.
Your null object now moves according to the Year column in the CSV file. To further develop this, you can use the XPresso Tag or the MoGraph Tracer:
Importing values via the XPresso Python Node
With just a little bit of Python code, which even a layman can understand and use with copy paste, completely new possibilities open up. Any kind of object can be created, any parameter can be set and any function can be animated, all based on the data read in. Cinema 4D offers a number of ways to implement Python code. To animate and modify existing objects, the Python Node in XPresso is suitable.
As a reminder, this is what the CSV file looks like:
Entity,Code,Year,Annual CO₂ emissions (tonnes )
Afghanistan,AFG,1949,14656
Afghanistan,AFG,1950,84272
Afghanistan,AFG,1951,91600
Adding values via a script
In the Cinema 4D Script Manager, Python scripts can be edited and executed. Unlike the XPresso Python Node, they are only executed once, but you can add objects and set keyframes, for example.
How to add objects with Python is well explained here. For the parameters you can now add the values from the CSV file.
Add values via the Python tag
The Python tag can run with the same code as in the Script Manager. However, the Python tag is executed on every “action” of Cinema 4D. That means as soon as the hierarchy of objects changes, a parameter moves or the next frame is calculated, Cinema 4D executes the script. This can be an advantage if you want to change the parameters of the objects in relation to each other. However, if you want to create objects, they are created anew each time. A workaround is to create the object only if it does not already exist. In addition you have to insert it in the same position.
The commands “InsertUnder” (insert object under a specific other) or “InstertAfter” (insert object after a specific other) are listed here.
Conclusion
The possibilities offered by Cinema 4D for importing data are limited as long as you want to work without code. With code, however, there are actually no more limits. But if this is the best way to visualize data depends on the code. If you are confident in using Cinema 4D, you will quickly achieve success. If you start from the very beginning, you should rather work with SideFX Houdini, Three.js etc. The code for the examples I have put here under GitHub. Also the code and data for the cover picture, which was created with the above mentioned techniques.
If you liked this article you can follow me on instagram at: https://www.instagram.com/la.benzzz/