Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › toWorldVec Error when Scale is 0

  • toWorldVec Error when Scale is 0

    Posted by Erin Prysiazny on December 28, 2018 at 12:58 pm

    Hey,

    I’m having trouble understanding toWorldVec. I’m trying to use it so that I can convert a layer’s scale to world space so that no matter how many parents that layer has, the expression uses the scale amount that takes into account the parents’ scales as well.

    When either the layer scale or any of the parent scales are 0, I get this error:

    layer to world matrix isn’t invertible in fromWorld

    Is the problem just that toWorldVec doesn’t like scales to be 0?

    thisScale = transform.scale;
    thisScaleParent = thisLayer.toWorldVec(transform.scale);

    scaleFactor = 100/thisScale[0];
    scaleFactorParent = thisScaleParent[0]/100;

    scaleFactor = scaleFactor * scaleFactorParent;

    value*scaleFactor;

    Erin Prysiazny replied 7 years, 8 months ago 3 Members · 6 Replies
  • 6 Replies
  • Kalleheikki Kannisto

    December 28, 2018 at 7:58 pm

    Probably a divide by zero issue. How about you force the scale to be a very small number instead of zero with Math.max()?

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Erin Prysiazny

    December 29, 2018 at 3:11 pm

    Would I still be able to convert the layer’s scale to world space using Math.max?

    I tried it like this and it still said that it didn’t like that I was trying to convert 0 to world space:

    thisScaleParent = Math.max(thisLayer.toWorldVec(transform.scale))

  • Kalleheikki Kannisto

    December 29, 2018 at 5:42 pm

    Math.max needs a second input to get the desired result, you could try:
    thisScaleParent = Math.max(thisLayer.toWorldVec(transform.scale),.0001)

    Kalleheikki Kannisto
    Senior Graphic Designer

  • Erin Prysiazny

    January 4, 2019 at 12:08 pm

    I tried this out and I still get this error:

    layer to world matrix isn’t invertible in fromWorld

    I don’t really know much about the world conversion expressions so I don’t totally understand why it doesn’t work. Anyone have any resources on these kinds of expressions?

  • Dan Ebberts

    January 4, 2019 at 5:31 pm

    I don’t think I’d use layer space transforms for this (although I’m not sure exactly what your objective is). Something like this might work:


    L = thisLayer;
    s = transform.scale.value;
    while (L.hasParent){
    L = L.parent;
    for (i = 0; i < s.length; i++) s[i] *= L.transform.scale.value[i]/100;
    }
    s

    Dan

  • Erin Prysiazny

    January 8, 2019 at 3:47 am

    Thanks Dan! This works great ☺

    My end goal was to put this on the stroke width of a layer and have the stroke width maintain the same value while also accounting for how much the scale of its parents and itself affect it.

    I had it working with toWorldVec aside from when the scale was 0, but this works in all scenarios and makes more sense. Thanks!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy