3
$\begingroup$

Is there a chance to track an object/instance generated inside Geometry Nodes with a camera? Can I provide the coordinates of an animated Object per attribute to an Object Constraint?

This is a small animation made with Geometry Nodes. I want to track one of these objects with a camera. Is this possible?

enter image description here

$\endgroup$
1
  • $\begingroup$ Your link doesn't open for me. You might wanna use blend-exchange.com $\endgroup$
    – Kuboå
    Commented Dec 17, 2022 at 14:50

3 Answers 3

5
$\begingroup$

Since you're re-creating and animating your cube inside your Geometry Nodes and the original is stationary, the Track To constraint on your Camera is not doing anything. On that constraint modifier, there's an option to follow a vertex group as well, maybe we could create a vertex selection out of the animated cubes inside GN and tell the modifier to follow that? Unfortunately, that's not possible unless you apply your GN modifier and destroy its procedurality in the process, since GN cannot create vertex groups, not exactly (for a more detailed explanation as to why not, you can take a look at this answer).

Still, there's a possible workaround for that vertex group idea:

enter image description here

  • Create a new object, a plane for example. Let's name it TARGET. We need only a single vertex, so enter into Edit Mode, select everything, M (Merge) > At Center.
  • That single vertex still selected, create a vertex group out of it (Ctrl+G). Let's name it FOLLOW.
  • In your main Geometry Nodes setup where all the animation is happening, turn the cube you want to follow into an instance, either by ticking the As Instance option on the Object Info node, or by using a Geometry to Instance. Then, using a Store Named Attribute node, capture its Position. I named the attribute LOOKAT.
  • Add a Geometry Nodes modifier to your TARGET object. Get the position information we captured in the main setup into this one via a Sample Index node, and use that to Set Position of our single vertex.
  • Finally, on your Track To constraint of your camera, choose TARGET and FOLLOW as the object and vertex group, respectively.

enter image description here

In summary, your main GN setup will continuously capture your cube's position and write it down as an attribute named LOOKAT. Then your TARGET object's GN setup will take that and use it to move its single vertex to that position. Since we're not creating new geometry in that setup, our vertex group will not be lost, and can be used in our camera's tracking constraint.

Since these movements are all happening in the local space, you might wanna parent your TARGET object to your main GN object in case you'd want to move or rotate them.

Update, answering OP's question in the comments as to how to set this up for an object generated inside the main GN modifier:

  • When you turn a geometry into an instance, the "origin" of the instance will always be created at $[0,0,0]$, so if you do that after moving it with Set Position, its origin will stay there while the mesh moves around. Since the Camera is following the position of the instance, not its mesh, it won't move either. Simply putting Geometry to Instance right after the Icosphere node will prevent this:

enter image description here

  • The other important part here is the Sample Index/Transfer Attribute node. When you use Join Geometry, the merging objects will get their indices according to the order of their noodles from top to bottom. In your case there are three objects going in: Bezier curve, Icosphere, and Cube. Bezier curve is not an instance, so it doesn't get an instance index. In your setup you happened to link the Icosphere below the Cube, so it gets the second index, $1$. Which means you need to tell that to the Sample Index/Transfer Attribute node in your target GN setup:

enter image description here

$\endgroup$
6
  • $\begingroup$ So fantastic. That's it. (Arghh, using Blender 3.3, "Sample Index" not yet existing. Works with the "external" Object and instancing it. Only for clarification: with the geometry created in the main GN setup, this does not work? I tried setting up the icosphere in the same way. <img src="https://blend-exchange.com/embedImage.png?bid=ddAbXDw6" /> $\endgroup$ Commented Dec 18, 2022 at 0:12
  • $\begingroup$ You can use Transfer Attribute instead of Sample Index: blender.stackexchange.com/questions/276087/… Not in front of my PC atm so I'll check your file tomorrow morning if you still have questions about it $\endgroup$
    – Kuboå
    Commented Dec 18, 2022 at 1:11
  • $\begingroup$ @GrisalhoS.K. Wrote an update to the answer explanining what you should do. $\endgroup$
    – Kuboå
    Commented Dec 18, 2022 at 11:37
  • $\begingroup$ Wow! I never realized you went so far into the weeds with this one. Well done, and Yuk :) I deeply hope Everything Nodes is heading in the direction where all this wrangling is no longer necessary. $\endgroup$
    – Robin Betts
    Commented Jan 12, 2023 at 19:40
  • $\begingroup$ @RobinBetts Yeah I hope so! Sometimes I come back to these and even though I took pains to be as detailed as possible it's still hard even for me to follow them. When similar questions pop up and I link these to them I cringe a little bit, imagining them struggling to follow the logic and all the corner cases. There are simpler versions of this setup for ex, but it really depends on the particular job. "If you don't care about the Input geo you can do it this way", "but if you care about it you can do it that way—but only if you don't mind this third thing"... They're all so bespoke. $\endgroup$
    – Kuboå
    Commented Jan 12, 2023 at 19:54
2
$\begingroup$

We want to track, what, the median point of some instanced geometry?I would use a different technique than those so far offered. Let's use another GN object to acquire that median point, shrinkwrap constrain an empty to that GN object, and then track that empty.

enter image description here

GNCube makes a cube using GN; this is our example of geometry that we want to track. InstanceGN then instances that same object, then just moves all of its vertices to their median point. An empty then acquires that median point by shrinkwrapping to the nearest vertex of InstanceGN (where all vertices are at the exact same location, so it doesn't matter which one gets used), and the camera tracks that empty.

It's not technically necessary to realize instances. We could use three transform nodes to scale the instance to 0 at this median point instead. We can of course offset that position (in any particular space we'd like, the only thing transforming InstanceGN will do is to change its space.) If we'd like, we could even specify an attribute input to InstanceGN's modifier to allows us to specify a selection for our median. InstanceGN will read the attribute specified from GNCube:

enter image description here

Here, GN cube is outputting an "att" of 1 for its last two verts and 0 for its other verts, so we're only tracking the median of those two verts instead.

$\endgroup$
1
$\begingroup$

I hope I am not over my head, there is another walk around to realize this track in just one geometry nodes but it's a more complex and it have limitations. The idea is to have groups of vertex within just one vertex. Those vertex will be animated then support the objects as instances.

enter image description here

It work but you can't realize the instances it will break. That being said it's work exactly on the same principles of the Kuboå solution.

$\endgroup$
1
  • $\begingroup$ You're not over your head, it just has its own limitations, like you said. This works because the end result contains only the original geometry as naked mesh—everything else is an instance—so it doesn't touch the vertex groups. Realizing introduces new mesh, which triggers GN to convert the vertex groups into generic attributes, so it breaks. This also means you can't join in any other mesh as well, you have to turn all of them into separate instances, or join them into a single instance at the end, like this: i.imgur.com/iSlI9I6.png $\endgroup$
    – Kuboå
    Commented Dec 18, 2022 at 13:25

You must log in to answer this question.

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