Community
Bifrost Forum
Welcome to the Bifrost Forum. This is the place for artists using Bifrost to ask and answer questions, browse popular topics, and share knowledge about creating effects procedurally using Bifrost. You can also visit the Bifrost Community on AREA to download an array of ready-to-use graphs, read Bifrost news and updates, and find the latest tutorials.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Use an implicit sphere as a locator for influence?

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Roland.Reyer
1522 Views, 12 Replies

Use an implicit sphere as a locator for influence?

I'd like to use Maya's *implicit* objects as locators to control the influence of deformers and fields:

- implicitSphere

- implicitCube

- implicitCone

These objects have size attributes (e.g. radius, cone angle) and transformation attributes (a transform node).

 

grafik.png


Unfortunately, I can't just import them into the Bifrost Graph.

How can I use these objects in Bifrost?

How do I calculate e.g. how close a point is to an implicitSphere's center considering the sphere's transformation?

 

Labels (2)
12 REPLIES 12
Message 2 of 13

Isnt the extrude compound using an influence objet?

https://area.autodesk.com/downloads/extrude/#

----------------------------------------------------------------
https://linktr.ee/cg_oglu
Message 3 of 13

No, it is just a location and a dropoff value.

I could wire a locator's position and maybe a scaling value.

 

But for example the implicitCone has a specific shape (same with non uniform scale on all objects).

Even for the moved/rotated/scaled sphere I don't know how to calculate if a point is inside.

 

 

Message 4 of 13

Hi Roland,

 

Right now, there is no built-in way to test whether points are inside something like an implicit sphere. However, it's a fairly straightforward computation in the graph if you know the sphere's radius and world transform. (If you do this computation a lot, it would be helpful to publish a reusable compound for it.)

 

To get inputs like the radius and world transform into the graph, you'll need to connect them individually:

 

  1. At the top level of the graph, create a new port on the input node by connecting something of the appropriate type. You'll find that most parameters in Maya use doubles (or vectors/matrices of doubles, etc.), but you can use floats and they will be converted automatically on input.
  2. In Maya's Node Editor, display both the implicit shape and the Bifrost graph, and connect them. A lot of the ports like radius on the implicit sphere aren't visible by default, so to select them you need to click the big circle at the top of the node and select Other.

bifrost-inputs.png

node-editor-inputs.png

 

I hope that helps,

gray

 

 

 


Grahame Fuller
Learning Content Developer
Message 5 of 13

I've gotten exactly that far.
What's next?

 

Message 6 of 13

Hi Roland,

 

The easiest way is probably to convert the point positions that you are testing into the local coordinates of the sphere, and check their lengths against the radius.

 

  1. Use inverse_matrix to invert the sphere's world matrix. Note that you could have just input the inverse directly from Maya, but maybe you need the uninverted matrix for something else anyway. It's the same amount of computation in the end — it's just a question of whether you are asking Maya or Bifrost to do the maths.
  2. Use vector3_to_vector4 to convert the point positions to 4D vectors with w = 1. This is so that they get transformed as point positions rather than vectors.
  3. Use matrix_multiply to transform the positions. Note that the order is important: matrix first, then the positions.
  4. Use vector4_to_vector3 to convert the results back to ordinary 3D positions.
  5. Use length_squared to get their squared lengths, and compare those to the square of the radius. This can be a bit more efficient than comparing their lengths to the radius directly.
  6. If they are less or equal, then the points are inside the sphere. To do something with those points, you probably want to use the original, untransformed positions rather than those in the sphere's local coordinates.

points-in-radius-local-coordinates.png

 

I hope that helps,

gray


Grahame Fuller
Learning Content Developer
Message 7 of 13

Don't I first have to set the translation for the sphere matrix to zero?

 

Message 8 of 13

You shouldn't need to set the translation of the matrix to zero, assuming that you want to move the sphere and find the points inside it based on its current position, wherever that may be.

 

Maybe I'm misunderstanding what you are trying to do?

 

gray


Grahame Fuller
Learning Content Developer
Message 9 of 13

I thought that when I apply the inverse matrix WITH the translation i would move the point around.

All I want to do is rotate and scale the points position, before I measure its distance to the sphere center, right?


On the other hand... when I apply the inverse matrix WITH the translation then I just measure the points distance to (0,0,0). Is that correct?

 

I can only test it tomorrow (I’m in Germany).

 

Message 10 of 13

What I posted above doesn't actually move anything (unless you use set_point_position with those values). The idea is to convert the point positions from world coordinates so that they are expressed relative to the sphere instead. This is so that you can compare their lengths to the sphere's radius and know whether they are inside or not.

 

If you move the sphere so that it now encloses different points, you need to take that translation into account when converting the points' coordinates. This is why you need to not zero out the sphere's translation.

 

But note that this is just for determining whether the points are inside the sphere and should be deformed or not. What happens next depends on how you want to deform those points.

 

For example, if you want to add an offset to their current positions, you'd start with the original, unconverted, world-space positions of those points. On the other hand, if you want to scale them about the sphere's center, you'd multiply the converted positions by some factor and then convert them back to world space before you set their new values on the geometry. (Converting back to world-space involves turning them back to 4D with w = 1 again, multiplying them matrix-first with the uninverted matrix, and finally turning them back to 3D.)

 

Good luck!

gray


Grahame Fuller
Learning Content Developer
Message 11 of 13

Ok, it workes! 😀

In this example I shrink the surface of the torus along the point normals, but only inside the implicit sphere.

The sphere can be moved, rotated, scaled.

 

grafik.png

 

This is the compound that checks if points are inside the sphere.

It outputs an array of factors for each point on the torus geometry and I can multiply any modification (grow, shrink, noise, etc.) with the factor (see the final graph).

grafik.png

 

How do I find out if a point is inside the moved/rotated/scaled sphere?
I followed @Grahame_Fuller's advice to transform the points with the Inverse Matrix of the sphere and then just measure the distance to the center (= length of the position vector).

The position inside the sphere is then divided by the radius and the result (clamped and fcurved) is the array of factors.

InfluenceSphere1.jpg

 

The final graph for this grow/shrink modification looks like this.

Note that the implicit sphere (createNode implicitSphere) cannot be dragged into the Bifrost Graph directly. You have to create the plugs on the input node and then in the Node Editor connect the sphere's worldMatrix and Radius.

grafik.png

 

grafik.png

 

Piece of cake, right?

 

Message 12 of 13
Roland.Reyer
in reply to: Roland.Reyer

Oh, before I forget it:

 

Here's a MEL script that

  • creates an implicit sphere
  • creates a new input node on the selected bifrostBoard (usually "bifrostGraph1" in the Outliner)
  • creates the plugs "matrix" and "radius" on that new input node
  • connects the implicit sphere's "worldMatrix[0]" and "Radius" to the bifrostBoard (=the input node)
  • creates the influenceSphere_pointFactor compound (needs to be installed in your user compounds)
  • connects the inputNode matrix and radius to the influenceSphere_pointFactor compound

IMPORTANT: the node "bifrostGraph#" needs to be selected in the Outliner when you execute this.

 

Put this on your shelf.

Makes your life easier when you test this stuff 🙂

 

$bifrostBoards = `ls -sl -type "bifrostBoard"`;
if (size($bifrostBoards)) {
    $sphereName = `createNode implicitSphere`;
    $name = `vnnCompound $bifrostBoards[0] "/" -addIONode true`;
    vnnCompound $bifrostBoards[0] "/" -renameNode $name $sphereName;
    vnnNode $bifrostBoards[0] ("/" + $sphereName) -createOutputPort ($sphereName + "Matrix") "Math::float4x4";
    vnnNode $bifrostBoards[0] ("/" + $sphereName) -createOutputPort ($sphereName + "Radius") "float";
    
    connectAttr ($sphereName + ".worldMatrix[0]") ($bifrostBoards[0] + ("." + $sphereName + "Matrix"));
    connectAttr ($sphereName + ".radius") ($bifrostBoards[0] + ("." + $sphereName + "Radius"));
    
    $name = `vnnCompound $bifrostBoards[0] "/" -addNode "BifrostGraph,User::Compounds,influenceSphere_pointFactor"`;
    vnnConnect $bifrostBoards[0] ("." + $sphereName + "Matrix") ("/" + $name[0] + ".matrix");
    vnnConnect $bifrostBoards[0] ("." + $sphereName + "Radius") ("/" + $name[0] + ".radius");

} else warning "No bifrostBoard node selected (e.g. \"bifrostGraph1\")";

 

Message 13 of 13

I'm glad it helped. I like that illustration — it really helps to show how it works.

 

gray


Grahame Fuller
Learning Content Developer

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report