Jump to content

Cinema 4D Scripting - How to randomize rendering between multiple objects


puccks

Recommended Posts

Hello, 

 

Basically I want to randomize the renders somehow. 

Let's say I have 10 human bodies modeled, 10 haircuts, 10 types of shirts and so on. I want to render out different random combinations of these objects, without doing it manually. 

 

Do you have any idea how can I do that ? 

 

Thanks! 

Link to comment

Depends on whether you want to have a specific solution for your current setup, or a generalized solution.

 

If your variants are located in a null each (e.g. one null with haircut1, haircut2, haircut3 etc, another null with shirt1, shirt2,...), then you would just go through all these nulls (search by name), select one child randomly (count children, determine one random number in that interval), set this child to visible and all others to invisible. Once you have treated all your options that way, so each of these nulls only has one visible child (one option), you'd simply start a render. You could let the script run overnight to render out a few dozen variants.

 

Your issues will be:

 

1. depending on the number of variants, a combination may repeat. If you want to prevent that, you'd need to save the already-done combinations in a list and compare on each new attempt whether your current combination is already in that list (in that case, skip and don't render).

 

2. The script will need to terminate before you can continue working in C4D, at least in the "simple" solution where you just trigger the render directly. If you have an endless loop in the script, or you want to terminate the script prematurely, you will need to kill the C4D process on the machine. You can program a more sophisticated solution with a dialog and an interrupt mechanism, and start the render on another thread, but that is significantly more work.

 

 

----------
Learn more about Python for C4D scripting:
https://www.patreon.com/cairyn

 

Link to comment
  • 1 month later...
On 9/18/2021 at 6:12 AM, puccks said:

Hello, 

 

Basically I want to randomize the renders somehow. 

Let's say I have 10 human bodies modeled, 10 haircuts, 10 types of shirts and so on. I want to render out different random combinations of these objects, without doing it manually. 

 

Do you have any idea how can I do that ? 

 

Thanks! 

Did you ever end up figuring this out? Would appreciate any info! Thank you

Link to comment
On 9/18/2021 at 9:12 AM, puccks said:

Basically I want to randomize the renders somehow. 

I have a suspicion you don't want to "randomize", but to get all possible unique combinations of those parts.
That is more akin to a "counter" rather than a "randomization"...

This could be done using MoGraph and some mathematically placed keyframes.

Are you making some sort of NFT series? It seems to be quite popular these days...

Link to comment

I have the same question as @puccks. I'm trying to create a 3D NFT project within C4D and want to randomize assets, something like the mekaverse project. Is there an in-depth solution to this? 

 

Essentially I want to create individual elements that fit together in different combinations and have them rendered out as unique characters in each frame so I can batch export it. Also how do I export the name of the nulls in each frame to a JSON to use as metadata? Eg: If the character is made of 4 nulls - black hair, brown eyes and red lips, I would want to write a script to export these traits to a json file.

Link to comment

Reply to all:
There's no "generalized" solution unless there's a definitive "pattern" to what you're trying to make.

Making a randomizer or "counter" to iterate objects that exist in predefined positions/rotations is doable using MoGraph, Python e.t.c., but a very specific set of rules needs to be defined.

Since these are commercial projects, I would advise finding a Technical Artist, or Developer to work with and create your own custom solution.

If you need some references/introductions, I can provide some.

For simplified solutions (like the "Counter" I mentioned), they may become a subject for one of my tutorials in the near future.

Link to comment

Okay, since there seems to be a slight demand for this kind of thing, I'm going to offer a plugin.

 

image.png.a6679c4600f27a64a5382e9e87af556c.png

 

Due to the highly specialized output (setting visibility flags per frame), this will not be el cheapo though. Let's see how serious people are with wanting this.

 

Watch this space for news. (First version will be tested R23/Windows, although this is a Python 3 plugin and should work on any OS and any subsequent C4D version.)

Link to comment
18 minutes ago, gauthamcode said:

I found a helpful plugin in blender that does exactly what we're looking for. It would be awesome if this can be done in C4D. Maybe @Cairynand @MighT

use this as inspiration.

 

Well, I'm not using shapekeys / posemorphs, I just make stuff visible or invisible in a pretty specific way. Now I am not sure whether this really is what you want.

 

I suppose for later I can add a functionality that does not create frame-based visibility combinations but actual models by copying random elements from a repository, but it would still be fairly static.

 

Link to comment

So, I wrote a plugin to create loads of variants from groups of alternative objects:

Collie Variant Generator

 

This is a commercial product and not in the hobbyist category. If you find it too expensive, you may want to use the Blender alternative mentioned above, which is probably also great.

 

Dialog.jpg.76eef83af9d462429a86e277b10a6b87.jpg

 

Here's how it works:

1. Create several groups (nulls) of objects within a parent of some kind. Each group will contain arbitrary alternatives for one scene element, e.g. a character, a background, or a lighting setup.

2. Use the plugin to enter the desired number variants, optionally likelihoods for the alternative objects.

3. The plugin will generate visibility keys (editor and renderer) for a sequence of frames. The combinations will be unique by default (if mathematically possible).

4. You can now render the scene out as single frames (e.g. png format). The plugin has already set the render scope (frames) to the series of generated variants.

5. If you need to document your effort, the plugin can create human-readable files with lists of used objects per frame / in total, or write that to the console, or write a JSON file containing a list of frames with a list each of used indices of the object alternatives.

 

The plugin is not needed for rendering, as all the output information is in the keys, so you can use any render farm.

With enough alternative objects, you can create non-repeating sequences of thousand or more variants. (I tested with up to 50000 frames, but at these numbers C4D itself gets unhappy, and you may not really need that many variants.)

 

1366941343_GumroadTitle.jpg.4f2ad56a568870c364d697e70cd34fd1.jpg

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • LATEST ACTIVITIES

    1. 2

      Nodes Modifier result isn't updated anymore

    2. 10

      CORE 4D Youtube channel

    3. 10

      CORE 4D Youtube channel

    4. 16

      3D world #310

    5. 53

      Looking forward to the next C4D release

×
×
  • Create New...

Copyright Core 4D © 2023 Powered by Invision Community