Jump to content

  • Log In with Google      Sign In   
  • Create Account

Lattice Deformer (2x2 FFD)


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1 SeanJD   Members   -  Reputation: 112

Like
0Likes
Like

Posted 30 August 2014 - 08:57 AM

Hi,
could anyone help me to understand how to apply a lattice deformation on a 3D object, like the FFD modifier in 3DS max: http://www.3dmax-tutorials.com/FFD__Free_Form_Deformation__Modifier.html ?

I have found this thread, now closed, which is basically asking the same question but hasn't got enough information for me to understand how it's done - http://www.gamedev.net/topic/628822-lattice-deformer/ it mentions 'plug the value into the parametric equations for the deformed lattice' but doesn't explain what the parametric equations are.

From my limited knowledge I thought it would be a case of setting a weighted value between each lattice handle and each vertex in the model that i want to deform, and then using that weight to affect the x,y,z positions of each vertex in the model when deforming the control lattice. But so far my attempts have failed. Could anyone help explain the equations / algorithm needed to apply a 2x2 box/lattice deformation, similar to Max's FFD modifier, or point me in the direction of an article which would explain.

Many thanks

Edited by SeanJD, 30 August 2014 - 09:14 AM.


#2 SeanJD   Members   -  Reputation: 112

Like
0Likes
Like

Posted 30 August 2014 - 10:03 AM

I have been looking into this for days and not come across anything that really explains the concept, but have just come across this paper from siggraph 86 which i think explains it nicely.. http://pages.cpsc.ucalgary.ca/~blob/papers/others/ffd.pdf it uses' tensor product trivariate Bernstein polynomials' to find the vector offset from the original vertex position to that of the deformed lattice. However, before going ahead and writing the code to perform these equations could anyone confirm that this would be an adequate approach to deforming a solid geometry within the control lattice so it moves with the control lattice? I'm just so green to this that I could do with some advice of anyone who has more experience with it. Cheers

#3 osmanb   Crossbones+   -  Reputation: 2076

Like
2Likes
Like

Posted 31 August 2014 - 08:05 AM

Hi! We've recently implemented something similar, so hopefully I can help. That paper looks like it's probably overly complicated for what you want to do - it's designed to handle data in many forms. If you're planning to do something in a vertex shader (or on the CPU) for regular triangle-soup meshes, you can treat the FFD like skinning. Each vertex of the lattice is essentially a bone, with a bind pose (the original lattice), and a skinned pose (wherever you've deformed the lattice to). The important part is figuring out the weights for each vertex. That's actually just based on cubic interpolation across each axis. Assume your lattice is axis-aligned, to simplify things: Normalize your vertex positions so that they're in the range 0 to 1 on each axis of the bind-pose lattice. Now you apply smoothstep (a cubic polynomial) to those positions to get the weights. The weight of each lattice vertex for a particular model vertex is the product of the three directional weights (either the value, or 1 minus the value, depending on which end of the box you're talking about). Basically, every lattice point influences EVERY vertex (except for the extreme case of points on the perimeter of the lattice). This solution also handles the extrapolated deformation that happens with FFD - your cubic polynomial will start returning values outside of [0,1] if your geometry lies outside the original lattice, and those are still your weights. (You can see this effect in 3dsMax, depending on which options you enable on the modifier). I hope that helps - let me know how you make out!



#4 SeanJD   Members   -  Reputation: 112

Like
0Likes
Like

Posted 31 August 2014 - 12:45 PM

Hi Osmanb, thanks for the explanation! I think I was close the first time around then, I have written code which can weight each lattice vertex to each model vertex but just didn't get the weights correct. Also I didn't normalize the vertex positions to be in the range 0->1 . I can do that for sure, but I'm still a little uncertain about getting the weights. I've looked at the smoothstep equation, so do i apply that on each model vertex<->lattice vertex for each direction i.e. calculate the distance between each on each axis? And by product of the three directional weights do you mean the cross product? I'm almost there but just need to get this weighting algorithm right.

Cheers



#5 osmanb   Crossbones+   -  Reputation: 2076

Like
2Likes
Like

Posted 31 August 2014 - 03:27 PM

Sure, I'll see if I can explain it better... (I'm doing this from memory, and I can't really share any code - this was done for my employer). Anyways: Assume that your original lattice has corners at L_000 and L_111 (and all the other corners are at L_001, L_010, etc...). For each vertex, transform them into "lattice space":

 

V_lattice = (V_world - L_000) / (L_111 - L_000)

 

At this point, any vertices that were inside the original lattice will have all three components in [0,1]. Anything outside will be out of that range. You could use those values directly as your weights (see below), but that's not what the FFD does. ... Hmm, actually, I'm not sure what it does in the 2x2 FFD case. For the 3x3 FFD, the weights for each point along one axis are (for example): x^2, 2*x*(1-x), (1-x)^2. For now, you can probably start with the linear weighting (just use the V_lattice from above).

 

To get the full weight for any particular lattice point, you multiply together all three vertex components (or their complement). So the weight for L_111 is (V.x * V.y * V.z). And the weight for L_010 would be ((1-V.x) * V.y * (1-V.z)). 

 

I hope that's some more help - I'm sorry I don't know the exact weighting in the 2x2 case - but if you do the linear version first, you can play with tuning the weights. In any case, the two terms you generate for any particular axis need to sum to one.



#6 SeanJD   Members   -  Reputation: 112

Like
0Likes
Like

Posted 01 September 2014 - 06:57 AM

Great, I think I understand now  though I'm fairly new to 3D dev (I thought smoothstep was a type of dance music wink.png )

I'll give it a try later and let you know how I fare with it.



#7 SeanJD   Members   -  Reputation: 112

Like
1Likes
Like

Posted 02 September 2014 - 08:51 AM

The above solution does indeed work! I set it up as a 2x2 lattice and didn't use the smoothstep weighting (just V.x or (1-V.x) as mentioned for basic weighting) and it works a treat. I'll try ading the smoothstep when I get a chance.

Thanks for the solution Osmanb.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS