Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - d4l1

Pages: [1]
1
Hi!

I'm working on a Python Tag that I apply on a Null object in the scene, which then works as some kind of Material Switcher that stores multiple Materials that I can change through the selected Index. (instead of using Take Manager, or some other Layered Material stuff). I thought this could be helpful, because the Null object can be placed on top of the Outliner and it would be recognizable that there is something going on in that scene when it is reopened some months later. And because it is a nice thing to do these days, the code was 'mostly' written by ChatGPT - even though there were some inputs from my side. The script should replace materials in the applied Material Tags everywhere in the scene. It can't replace whole Material Tags, because there are some references from the top-most layer with Selection Tags. And these tags better stay where they are, which means I only want the linked Material to change. Now - this works fine and does its job, when the scene isn't rendering. If i keyframe the Index and let the frames render, the material won't change at all. It also doesnt work with Live Preview Rendering. And I believe it is because(!) I'm changing only the linked material and not the whole Material Tag. But it does work with the default C4D Render and RedShift. And that circumstances give me hope that I may be only missing some command that refreshes the Render Process - because it does change in Corona if I apply a Layered Material and change the Amount of Blending (even though I'm sure it isn't nearly the same process I was talking about before :) ).

Maybe someone else has some idea? Below is the script that sits in a Python Tag on a Null.

Edit: Forgot to add a scene with the existing Changer. There is some additional User Data stuff that needs to be recreated. And I called it Switcher instead of Changer. Both sound reasonable.

Code: [Select]
import c4d

def get_all_objects_iterative(doc):
    """
    Collects and returns a list of all objects in the document.
    """
    result = []
    op = doc.GetFirstObject()
    while op:
        result.append(op)
        op = op.GetNext()
    i = 0
    while i < len(result):
        current = result[i]
        child = current.GetDown()
        while child:
            result.append(child)
            child = child.GetNext()
        i += 1
    return result

# Global variable to store the last active index.
global g_lastActiveIndex
if 'g_lastActiveIndex' not in globals():
    g_lastActiveIndex = None

def main():
    # Get the active document.
    doc = c4d.documents.GetActiveDocument()
    if not doc:
        print("No active document found.")
        return

    # New boolean user data to enable/disable the script (ID 12).
    # When false, the script will exit immediately, allowing you to make changes without swapping.
    enabled = op[c4d.ID_USERDATA, 12]
    if not enabled:
        print("Script disabled via user data parameter. No processing will be done.")
        return

    # Retrieve materials from custom user data.
    # IDs: 1 = material0, 2 = material1, ..., 10 = material9.
    mat0 = op[c4d.ID_USERDATA, 1]
    mat1 = op[c4d.ID_USERDATA, 2]
    mat2 = op[c4d.ID_USERDATA, 3]
    mat3 = op[c4d.ID_USERDATA, 4]
    mat4 = op[c4d.ID_USERDATA, 5]
    mat5 = op[c4d.ID_USERDATA, 6]
    mat6 = op[c4d.ID_USERDATA, 7]
    mat7 = op[c4d.ID_USERDATA, 8]
    mat8 = op[c4d.ID_USERDATA, 9]
    mat9 = op[c4d.ID_USERDATA, 10]

    # Active Index: keyframeable integer from 0 to 9 (ID 11).
    activeIndex = op[c4d.ID_USERDATA, 11]
    print("Current active index (new selection):", activeIndex)

    # Build list of material options.
    matOptions = [mat0, mat1, mat2, mat3, mat4, mat5, mat6, mat7, mat8, mat9]

    # Validate activeIndex.
    if activeIndex < 0 or activeIndex >= len(matOptions):
        activeIndex = 0

    # Get the new material from the active index.
    newMat = matOptions[activeIndex]
    if newMat and newMat.CheckType(c4d.Ttexture):
        new_material_ref = newMat.GetMaterial()
    else:
        new_material_ref = newMat
    print("New material reference (active):", new_material_ref)

    # Use a global variable to know the previous selection.
    global g_lastActiveIndex
    if g_lastActiveIndex is None:
        g_lastActiveIndex = activeIndex
        print("Initializing g_lastActiveIndex to", activeIndex)
        return  # Nothing to swap on first run.

    print("Previous active index (g_lastActiveIndex):", g_lastActiveIndex)

    if activeIndex == g_lastActiveIndex:
        print("Active index has not changed. Nothing to swap.")
        return

    # Get the previous material reference based on the previous active index.
    oldMat = matOptions[g_lastActiveIndex]
    if oldMat and oldMat.CheckType(c4d.Ttexture):
        old_material_ref = oldMat.GetMaterial()
    else:
        old_material_ref = oldMat
    print("Old material reference (previous active):", old_material_ref)

    if new_material_ref is None:
        print("New material reference is None. Aborting swap.")
        return

    # Get all objects from the scene.
    objects = get_all_objects_iterative(doc)
    objectCount = len(objects)
    print("Total objects scanned:", objectCount)

    swapCount = 0
    # Iterate over the list of objects.
    for obj in objects:
        for tag in obj.GetTags():
            if tag.CheckType(c4d.Ttexture):
                currentMat = tag.GetMaterial()
                # Compare by pointer equality OR by comparing material names.
                if (currentMat == old_material_ref) or \
                   (currentMat and old_material_ref and currentMat.GetName() == old_material_ref.GetName()):
                    print("Swapping on object:", obj.GetName(),
                          "Tag:", tag.GetName(),
                          "\n  from:", old_material_ref,
                          "\n  to:", new_material_ref)
                    tag.SetMaterial(new_material_ref)
                    swapCount += 1

    print("Finished swapping. Total tags swapped:", swapCount)
    # Update the global variable with the new active index.
    g_lastActiveIndex = activeIndex
    c4d.EventAdd()

2
Hi, I'm currently working on a Python script in C4D that tries to read out some Corona object properties, in that case the ChaosScatter[c4d.CHAOS_SCATTER_DISTRIBUTE_ON_OBJECTS] list. I'm no pro at writing code, but with the help of ChatGPT I've created some nice little helper for basic C4D stuff, but mostly with built-in objects, Cloner and so on. Does anyone know how I could get the list and / or change the objects inside that list with code? Can't read the data that ChaosScatter[c4d.CHAOS_SCATTER_DISTRIBUTE_ON_OBJECTS] would give me, I believe! (could be totally wrong how I'm trying to do it), but that [c4d...] doesn't give me anything if I simply print it out? Is this some kind of packaged variable that I need to unpack? Iterating over it with a for loop isn't possible and to that point I've no other clue :) Reading the values, and changing them would be the thing I need to achieve.

Thanks in advance and have a nice day!

3
Hi!

I'm using a Distance shader inside the Chaos Scatter - Surface Scattering - Distribution as a mask to control the scattering. After some troubles everything is working right, but it appears to be a problem for the viewport update process, if the objects that are used inside the Distance shader (Distance from ...) are nested / childs of each other, if they are polygon objects (?) Sorry, if that doesn't sound right - I've attached a test scene where it is quite obvious what I meant. If I move the Null (dist_objs), the viewport updates immediately. If I move the first object (dist_obj), it is the same. But moving only the second polygon object (dist_obj_child), nothing happens with the Scatter object. After re-enabling the Scatter it is back to normal. Don't know if this is something relevant or important, but it is something that happens. Even though it doesn't affect the outcome afterall.

Thanks!

(Previous posts in this thread: https://forum.corona-renderer.com/index.php?topic=42393.0)

4
Hi!

I'm experiencing a strange bug with C4D 2024.2 and Corona 11. If I create a Physical Material and define a color, apply that to a default cube and add that cube into the Asset Browser, the material will turn grey after I load the asset out of the Asset Browser again. Does not happen with a Legacy Material. Somehow it felt like a Cinema bug and therefore I've created a bug ticket on their support site as well. But maybe it is something Corona specific? It is really really strange. We're on Windows 10. Attached is a simple test scene where I can reproduce the error.

5
Hi all!

I've a question about the Corona Pattern Edit Mode. If I understand it correctly, selecting 'Only crop box' should only distribute the mesh inside the orange box. Switching to Whole object should distribute the whole pattern mesh, completely ignoring the orange box? Or does the orange box dimensions get distributed but the whole mesh is applied anyway, which would be the outcome I'm hoping for? Because the mesh I'm working has mesh elements that I don't want to cut because of a Multi Shader that is based on the mesh elements. Otherwise the material will switch on the same mesh element. Right now I've to cut the overlapping part to get it tileable, but that comes with the unwanted material switch halfway.

Ok! But to come back at the Edit Mode question: Somehow nothing changes if I switch the mode for my pattern. I've attached a test scene where I somehow believe (or hope), that the blue cylinder should be distributed too if the 'Whole object' mode is enabled?

Thanks in advance for any help or explanation into that direction!

6
Hi,

as mentioned in the topic name, grass assets that have edge trimming active in the Opacity slot are crashing the render right at the start. This is new in 2024.1 and / or Corona 10 (HF2). Unfortunately I can't test it with C4D 2023.2.2 and Corona 10 (HF2), only without the hotfix. About ~ 1 year ago today I'd kind of the same problem with crashes while Edge Trimming is active and I'm not really sure what solved the problem. Did some trail and error to get rid of that crash but I guess it solved itself over time. But now the problem happens with a newer version, still working with 2023.

Could it be a bug or should I wait it out? :)

Thanks for the great work!

7
Hi, hope you all doing fine! :)

I'm working with Chaos Scatter in Corona 9 (C4D 2023) and I try to use the Scatter for some small parts / thin stripes on my ground plane.
Because of the nice stuff the Scatter comes with, including the Include / Exclude with Splines and also the Edge Trimming I somehow hoped that this setup would be enough to scatter the plants, without having to cut out little islands out of my big ground plane to spawn the plants on. But it seems like - internally - Chaos Scatter deploys instances for the whole object which results in crashes if I'm overdoing the Instances / cm². Camera clipping is on, the viewport only shows me preview objects inside my spline but yeah - it crashes. If I use a way smaller ground object everything works fine. :)

Am I missing something there or is it a technical limitation I'm not aware of? For now it works like every other Scatter plugin I've tried - really hoped that I can get rid of that tedious work.

Pages: [1]