5
$\begingroup$

Sometimes you want to get an object's Loc/Rot/Scale in the material for fancy vector stuff or controlling procedural textures. This is usually done by creating a bunch of Values driven by the appropriate parameters. I am wondering if it is possible to do it using 2 Empty objects and comparing their coordinates.

Object Texture Coords give us the location of an object. If we have one object that moves and another that doesn't, the difference tells us the relative position of the object, like a Local Space movement. That part is simple. But how can we figure out rotation and scale? I don't understand vector math enough to figure it out. Is it possible? How could it be done?

$\endgroup$
8
  • $\begingroup$ I do not understand if you were simply trying to get the location, rotation, and scale of the object itself, or as relative to another object. $\endgroup$
    – TheLabCat
    Feb 24, 2021 at 18:13
  • $\begingroup$ Get it for one object, by getting the offset from another object. $\endgroup$
    – Ascalon
    Feb 24, 2021 at 19:32
  • $\begingroup$ Why not just use the objects global location? $\endgroup$
    – TheLabCat
    Feb 24, 2021 at 19:33
  • $\begingroup$ Is there a way to get its Global Location? I guess the Object Coords gives that, but not rot or scale. What I'm really after there is something like Local Loc/Rot/Scale. I want the change in each from the base position. $\endgroup$
    – Ascalon
    Feb 24, 2021 at 20:22
  • $\begingroup$ I don’t think this is possible, but you might try object based texture coordinates as an input. $\endgroup$
    – TheLabCat
    Feb 24, 2021 at 20:23

1 Answer 1

3
$\begingroup$

You can get effective access to the shaded object's entire transformation matrix by using the Vector Transform node to find what the Object space's bases, (its [1,0,0], [0,1,0] and [0,0,1]) become, when they are measured in World coordinates.

Location:

(We know we can already get this from the Object Info node, but just for completeness...) Set a Vector Transform node to 'Point', from: 'Object' to: 'World'. Enter [0,0,0] as the point to be transformed, and you have the location of the shaded object in the World.

Scale:

enter image description here

These arrows point along the Y of their Object's spaces, and the objects have been scaled in Y, by between 1 and 2.5 . By transforming the Object-space vector [0,1,0] to World space, and taking its length, you get how much the object has been scaled in Y. Here, the scales are mapped to colors. Of course, you can do the same in X and Z, and, if you like, encode all 3 scales, XYZ -> RGB.

Rotation:

Well, by taking the Object -> World transforms of [1,0,0], [0,1,0], and [0,0,1], we have the columns of the object's transformation matrix. We know the orientation of all the object axes. But how those orientations are expressed as rotations is another question. If you wanted to express the orientation as Euler rotations, you're into this territory. Even if you fix the order of rotations, (e.g. X, then Y, then Z), there is still no unique set that will arrive at the object's orientation. So even if you make a node-group to make the Matrix to Euler conversion, and find a set of rotations that take you to the orientation, they won't necessarily be the rotations shown in the object's transform panel.

enter image description here

However, you can still do some useful things. This tree, for example, gets the angle of the projection of the object's Y axis down onto the World XY plane, around Z. The angle comes out of the Arctan 2 node between -pi and pi. The other nodes just map that range to 0..1.

Although you can get the location of a shading-point as measured in another object's coordinates, that doesn't tell you anything about the scale or orientation of the other object's space, you still need something like drivers there, unless something comes up in Geometry Nodes? And I don't think you can deduce the absolute dimensions of your own, shaded object, unless you cheat by knowing the location of the object's origin in the object's Generated texture space, which always measures 0-1 along the sides of the object's bounding box, oriented with the object axes.

$\endgroup$
1
  • $\begingroup$ Oh... just remembered. Check our @Rich Sedman's excellent discussion of the Vector Transform node here $\endgroup$
    – Robin Betts
    Feb 25, 2021 at 9:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .