ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

toWorldVec Error when Scale is 0

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Erin Prysiazny
toWorldVec Error when Scale is 0
on Dec 28, 2018 at 12:58:55 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;


Return to posts index

Kalleheikki Kannisto
Re: toWorldVec Error when Scale is 0
on Dec 28, 2018 at 7:58:17 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


Return to posts index

Erin Prysiazny
Re: toWorldVec Error when Scale is 0
on Dec 29, 2018 at 3:11:25 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))


Return to posts index


Kalleheikki Kannisto
Re: toWorldVec Error when Scale is 0
on Dec 29, 2018 at 5:42:18 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


Return to posts index

Erin Prysiazny
Re: toWorldVec Error when Scale is 0
on Jan 4, 2019 at 12:08:57 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?


Return to posts index

Dan Ebberts
Re: toWorldVec Error when Scale is 0
on Jan 4, 2019 at 5:31:20 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



Return to posts index


Erin Prysiazny
Re: toWorldVec Error when Scale is 0
on Jan 8, 2019 at 3:47: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!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]