We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Can’t Animate Light Scale/Size

Home Forums General Questions Can’t Animate Light Scale/Size

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #72215
    meumobbi
    Participant

    It seems Verge3D does recognize any Position or Rotation animation when it comes to lights, but not a Scale animation. I tried animating both Scale and the actual Size parameter in the Object Data Properties in Blender, but neither worked. Is that right? Is there no way to animate changes in a light source’s size?

    #72216
    kdv
    Participant

    What do you expect to get from scaling a light source? It has some sense only for area or spot lights. Point lights and directional lights has no dimensions…

    Puzzles and JS. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of meaning at all.

    #72254
    meumobbi
    Participant

    I’m using area lights representing LED strips built into furniture. For example, when the furniture’s width changes, I need the lenghth of the area light to change accordingly

    #72260
    kdv
    Participant

    Area lights also have no dimensions and it’s useless to scale them (0*20=0). But they have two specific properties: width and height. You can control those properties via JS.
    https://www.soft8soft.com/docs/api/en/lights/RectAreaLight.html

    Puzzles and JS. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of meaning at all.

    #72281
    meumobbi
    Participant

    Right on!

    I think I figured it out with your help. For anyone else that may encounter this problem, here’s the code I used in an Exec Script puzzle that worked for me:

    // Define a function to update LED widths
    function updateLEDWidths() {
    // Access the slider in the parent document
    var sliderValue = parent.document.getElementById(‘your_element_id’).value;

    // Map the slider value ([your range of slider values (e.g. 10 to 20)]) to the LED width ([range of Area Light X values (e.g 0.45 to 0.86)])
    var ledWidth = mapRange(sliderValue, 10, 20, 0.45, 0.86);

    // Update the width of each Area light
    var ledNames = [‘LED 1’, ‘LED 2’, ‘LED 3’, ‘LED 4’];
    ledNames.forEach(function(ledName) {
    // Assuming ‘app’ is your Verge3D app instance accessible in this context
    var led = app.scene.getObjectByName(ledName);
    if (led && led.isRectAreaLight) {
    led.width = ledWidth;
    }
    });
    }

    // Helper function to map a value from one range to another
    function mapRange(value, inMin, inMax, outMin, outMax) {
    return (value – inMin) * (outMax – outMin) / (inMax – inMin) + outMin;
    }

    // Ensure this code runs after the Verge3D app is fully initialized
    // You might need to place this inside a function that’s called after app initialization
    updateLEDWidths();

    // Add an event listener to the slider in the parent document to update LED widths on change
    parent.document.getElementById(your_element_id’).addEventListener(‘input’, updateLEDWidths);

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.