Rotating object faces around itself using geometry nodes
I'm trying to rotate an objects faces around itself.
See torus animation for rotation example:
When I try and do it with a "complex" object this happens.
See attached blend file:
The approach I'm going to demonstrate is the simplest I can think of, but it relies entirely on the assumption that the rotation will be around the initial "core" (central circle) of the torus, in other words, the assumption is that you're not going to significantly change the torus before performing the rotation (like moving all the points to some random position). Otherwise, the method won't give the correct result. Steps:
Triangulate
node for the whole object:
No other changes in the Create object
frame. Of course, you can instead just Triangulate
the top and bottom faces, or you can find a way to create the correct topology inside your torus constructor. It's up to you.
The input parameters are the ones you used when creating the torus. The basic idea here is to rotate each vertex around the "core" of the torus. You rotate each vertex around the point (Center
) that is the closest point to this vertex from the "core" of the torus, the Axis
is the tangent to the "core" of the torus at the vertex. Halve
is just Devide
the value by 2, I just renamed it for convenience.
I can write more explanation for each part of the logic if needed, but this is just math.
Now the downside of the algorithm: as I said, if you significantly change the entire torus, the rotation will no longer happen around its "core". Other algorithms will have to find a new circle (or even "ellipse") to rotate around using iterative algorithms. This is difficult and requires internet searching, and will most likely be a rather slow algorithm.
Note: You might realize that if you simply scale the torus by some value before rotating, the algorithm I showed won't give the right result. This is obvious since the central circle will be scaled, while my algorithm doesn't take any transformations into account. If you use two assumptions: the torus core is still a circle, and it is also parallel to the XY plane, then a more complex, but in this case improved algorithm for finding such a central circle for deformed torus can be provided. But I don't provide it since I have no idea if it will actually be useful. You might also rotate the torus, which would break this method as well.
First of all allow me some pedantism, because it's the key to understand the problem here: you're not rotating faces around themselves in your GIF. A face rotated around self wouldn't move the face's center, and in most cases (like in a torus) would require to split the face away from the rest of the geometry (if the rest isn't supposed to get deformed, which is the case when you want to rotate all faces).
So what you're doing in the GIF is rotating vertices around a common center, this "common center" being the average position of the group, and in a torus those vertices are grouped by belonging to the same cross-section loop, same inner circle of the torus.
In a torus, you can use index logic (index modulo major segments) to calculate group ID. Even if indices are shuffled you can restore them by e.g. removing non-horizontal edges, converting to curve, capturing spline index, converting to points, on original geometry sampling the captured spline index by proximity and using it in sorting as group index, plus Gradient Texture: Radial as weight to sort points.
Problem is, it's extremely hard to create a generalized algorithm finding the right spot to rotate around. For example if you found some kind of localized center of mass, it still probably wouldn't work they way you want, because extruded parts wouldn't move around the original torus "spine". You could maybe take the inner loop of faces, discriminating by e.g. normal pointing towards center, then for each vertex find the distance to such nearest face, then discard 20% or so biggest values to ignore extrusions in the calculation, calculate a weighted average, and once you know what kind of a distance from the inner face loop is the virtual "spine", you can rotate all vertices around that spine.
I don't show this, however, because there's another problem: your topology - the n-gon top and bottom - doesn't allow for twisting this torus, as the n-gon would no longer be co-planar and you would get ugly artifacts.
Curve Circle
instead, replace the points withCubes
and then rotate them byIndex
. The rotation will occur around their center, resulting in the "close" result you showed in the animation. Perhaps then you can merge the vertices by distance. $\endgroup$the Torus was just demonstrating the rotation as an animation
. The object is what I included in the static images and the blend file.. (Note: the object isn't all cubes
) $\endgroup$