PDA

View Full Version : simpleMod worldspace coordinates?


ivanisavich
03-27-2012, 11:43 PM
I have a simpleMod plugin that deforms vertices based on the position of a scene node.

All works fine, except I can't seem to work outside of the coordinate system of the mod's gizmo.

For example:


on map i p do
(
p = sceneNode.position + [i,random 0 100,0]
p
)


works, but


on map i p
(
p = sceneNode.position - center + [i,random 0 100,0]
p
)


has no effect, meaning I'm not able to compensate for a non-[0,0,0] position of the modifier's gizmo.

Any ideas?

denisT
03-28-2012, 12:12 AM
i'm sure you have to take into account modifierís context transform (see getModContextTM). every time when i work with modifier's transform i have to remember how it works :). check the Modifier Sub-Object Transform Properties in mxs help. that's usually the start point of my memory refreshing.

ivanisavich
03-28-2012, 12:20 AM
edit: oops, I made a mistake.

Thanks dennis...I'll take a look at that :)

ivanisavich
03-28-2012, 04:47 PM
In case anyone else has this problem, I finally found a solution.

For some reason the getModContextTM doesn't update properly for simpleMod plugins. No matter what my object's pos/rot/scale is, and no matter what the simpleMod's gizmo pos/rot/scale is, the getModContextTM always returns the same, incorrect value (even though it returns proper values for other modifier types).

My solution was to store a weak reference to the object's transform in the simpleMod's parameter block. Then during the map function, I multiply my position data by the inverse transform of the object.

Obviously, that won't account for transformations of the simpleMod gizmo itself, but since my plugin doesn't require the user to modify the gizmo in any way, I just lock all its transform subanims.

One final problem I ran into, is that the transform data I was accessing in the <on map> function wasn't updating in real time. If I move the objects manually it updates, but not if I press the play button. My solution was to set 2 keyframes (one at t(-10000) and one at t(10000)) on the position controller of the simpleMod's gizmo. This forces the simpleMod to update all referenced transforms as well.

denisT
03-28-2012, 06:23 PM
Obviously, that won't account for transformations of the simpleMod gizmo itself, but since my plugin doesn't require the user to modify the gizmo in any way, I just lock all its transform subanims.

how do lock the gizmo transform?
i don't think it's possible... do you just subtract the center position from the point position?

ivanisavich
03-28-2012, 06:29 PM
I use this method to lock the gizmo's transfrom controllers:


for q in 1 to 3 do
(
lockedTracksMan.setLocks true this.gizmo[q] this.gizmo[q].parent this.gizmo[q].index true
)


By the way Denis, do you know of a way to access vertex normals within a simpleMod <on map> function? Obviously the "i" variable gives the vertex index, but when I try to do a <getnormal self i> (where self is a paramblock variable that the object the modifier is applied to is assigned) I get an error saying there's an illegal recursion occurring (even if "self" is a nodeTransformMonitor)

denisT
03-28-2012, 06:43 PM
for q in 1 to 3 do
(
lockedTracksMan.setLocks true this.gizmo[q] this.gizmo[q].parent this.gizmo[q].index true
)


yes. sure. i just remember that the gizmo doesn't have transform controller, but it has position, rotation, and scale. but i forgot that gizmo itself is a subanim. so:

lockedTracksMan.setLocks on this.gizmo this this.gizmo.index on

denisT
03-28-2012, 06:51 PM
By the way Denis, do you know of a way to access vertex normals within a simpleMod <on map> function? Obviously the "i" variable gives the vertex index, but when I try to do a <getnormal self i> (where self is a paramblock variable that the object the modifier is applied to is assigned) I get an error saying there's an illegal recursion occurring (even if "self" is a nodeTransformMonitor)

you can get normal of the node because your modifier itself is responsible for the value.
only thing you can do is snapshot the mesh before map and use its data.
that means you have to use a copy of original TriMesh

ivanisavich
03-28-2012, 06:54 PM
you can get normal of the node because your modifier itself is responsible for the value.
only thing you can do is snapshot the mesh before map and use its data.
that means you have to use a copy of original TriMesh

Where's the best place to do the snapshot? Is there an event that is triggered before the map function that I can do that in?

I've tried various places like within the simple mod <on update> clause, but that doesn't update each frame.

The object I'm modifying is animated over each frame, that's why I need the constant snapshot updates to get the proper normals....

denisT
03-28-2012, 07:00 PM
Where's the best place to do the snapshot? Is there an event that is triggered before the map function that I can do that in?

I've tried various places like within the simple mod <on update> clause, but that doesn't update each frame.

The object I'm modifying is animated over each frame, that's why I need the constant snapshot updates to get the proper normals....

you don't need snapshot... i was wrong. you need a copy of trimesh. after you get a normal (which will be in local space) you have to multiply it on objecttransform...

the question is how to get constant update ... let me think.

denisT
03-28-2012, 07:12 PM
Where's the best place to do the snapshot? Is there an event that is triggered before the map function that I can do that in?

you can store the mesh copy when you attach your modifier using attachtonode handler.
but the mesh might be changed after. hmm...
you can setup when construct on geometry change... update the mesh on its event. but set some flag to ignore changes if you do map operation in your modifier....
but there is another problem

denisT
03-28-2012, 07:13 PM
how do you know that geometry was change before your modifier? hmm again.

ivanisavich
03-28-2012, 07:32 PM
I thought of adding a "Calculate Normals" button to the simpleMod rollout that, when pressed, disabled the map function and caches the normals of the geometry to the paramblock for a specified frame range.

But that's a lot of extra work and annoying for anyone who changes the topology below the simpleMod, or animates the mesh in any way.

denisT
03-28-2012, 07:56 PM
OK. I found it. You can make a copy of triMesh in map function when i == 0 !!! cool!

denisT
03-28-2012, 07:59 PM
now we have to find solution how to do it if necessary. map function calls many times with ZERO index for some reason or other

ivanisavich
03-28-2012, 08:06 PM
OK. I found it. You can make a copy of triMesh in map function when i == 0 !!! cool!

Unfortunately, the docs say that:

The <index> value is 1-based, however the scripted plug-in is called with a <index> value of 0 to signal that this particular map call is being used by the gizmo bounding box drawing code to compute points in the gizmo box to draw. This occurs hit testing is performed on the object the SimpleMod modifier is applied to and the gizmo bounding box is displayed. This will be the case if the object is selected, the Modifier panel is active, and the SimpleMod modifier is selected in the objectís modifier stack.


So i = 0 won't happen necessarily if someone is animating the mesh....only if someone is doing that while the modifier panel is open, and the modifier is selected.

Damn...

denisT
03-28-2012, 08:18 PM
it must be another solution.

denisT
03-29-2012, 06:11 AM
ivanisavich,
could you give more details about what you want to do?
#1 can the modified mesh change its topology in time?
#2 can any parameter of the modifier be animated?
#3 does the modified node have an animated transform?

the task's touched me. i don't like to lose.

ivanisavich
03-29-2012, 04:35 PM
Hey Dennis,

I actually got everything working by adding a "cache normals" button, which stores the normals in a point3Tab over a specified frame range. If the user moves to a frame outside of the cached range, the plugin will just use the closest array value...so if you have a non-animated mesh, you only have to cache the normals for 1 frame.

The plugin moves vertices away from a specific object, in the direction of their normals. Here are two animated .gifs showing how it works:

http://tysonibele.com/Main/Scripts/bubbleDeform_02.gif

http://tysonibele.com/Main/Scripts/bubbleDeform_01.gif

CGTalk Moderation
03-29-2012, 04:35 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.