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.


Messages - d4l1

Pages: [1] 2 3 4
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
Is there some Post Processing Overwriting enabled in the Corona Frame Buffer? We're experiencing some difficulties with the Overwriting and Not-Overwriting of those settings. Especially when the stuff is managed via Key Frames inside the C4D scene. Only since 2025 for us too.

3
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!

4
[C4D] General Discussion / Re: Gaussian Splatting?
« on: 2025-03-06, 14:27:24 »

There is hope! :)

(Time stamp isn't working somehow... 10:50min)

5
[C4D] I need help! / Re: Working with Multiple UVW Channels
« on: 2024-10-17, 08:09:04 »
Can't say it for sure, but I believe it depends on the order of your tags. It is something like: All material tags use the UVW tag on their left. (or on their right?) Can't test it out for myself right now.

6
Don't know if Mac also has Services running. Probably there even is some similar program / app that you could try to search for and / or run?

7
If you're on Windows, you could try to search for 'Start Cosmos Browser' and then execute that program.
The error message suggests, that the service is not running. And this does the trick for me most of the time.


8
Hi!
Hope it is fine if I share our problem with that behavior too. :)

Drag + Drop doesn't always make that link to the original material, but where it happens every time is when I load the material from the Asset Browser more than one time. The attached screenshot shows both materials (ofc, same name and all that, but that shouldn't matter). This really turns to a nightmare if you forget that you already have that material loaded already. To prevent errors, we also use the Corona Node Editor Drag and Drop method.

I tried to reproduce it with a simple, new Physical material and a Color node linked into it. But it seems to work there. Don't know if this is some problem that happens with older materials only?


9
Looks like that problem is fixed now in Corona 12? Made a few test assets and it seems to keep all the material settings.

10
Try to put the object (with the Material / CoronaMultiMap applied) on top of your hierarchy - on the first position in the Outliner / Objects list. Your problem sounds somewhat like we faced a few months ago and this was the solution to that. Really random stuff. Maybe this workaround helps with your situation too. :D We had a Cloner that changed random values ...

Edit: Just saw that your problem is within Max. Sorry! We're working with C4D .. but maybe it works even in another software. :)

11
Since there was a Hotfix to Corona 11 and also the new 2024.4 had some promising new feature, I've installed both and tried out our beloved little bugs. Seems like the bug somehow changed . Now, the color stays after re-loading it from the Asset Browser (most of the time), but the Bump value still is replaced with the full 100%, instead of the previously set value before loading it into the database. Just for a quick update on the topic from my side.

12
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)

13
A fresh setup did the trick. And somehow, if the Distance Shader range has no noise / textures linked, the viewport update is immediate. If there is a noise texture linked, the viewport refreshes after I've disabled and enabled the Scatter. Thanks for your input!

If you can reliably reproduce this behaviour, then consider reporting it as a bug. https://forum.corona-renderer.com/index.php?board=55.0

Tried to reproduce the behaviour in a new scene and will start a bug-thread, but within the C4D section :) It wasn't the noise that caused the bug. It was because of some 'nested' polygon objects that are used for Distance tracing. Thanks!

14
A fresh setup did the trick. And somehow, if the Distance Shader range has no noise / textures linked, the viewport update is immediate. If there is a noise texture linked, the viewport refreshes after I've disabled and enabled the Scatter. Thanks for your input!

15
Just wondering, if there is any chance that the newer versions of C4D 2024 (.4 , since yesterday) would solve the Asset Browser problem somehow?

Pages: [1] 2 3 4