5

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?

Ascalon
  • 6,579
  • 8
  • 55
  • 121

1 Answers1

3

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.

Robin Betts
  • 76,260
  • 8
  • 77
  • 190