Hi all,
I am looking for a way to implement a laplacian deformation for meshes like the cgal-library offers it.
Unless I don’t want to do too much math by myself I hope there is a way this can be done Rhino.
What I want to do:
- Select all vertices which should be part of the deformation (region of interest)
- Inside the region of interest select fixed vertices for which you already know the final position
- provide the final position for the fixed vertices (for instance as a collection of Point3d)
- deform the region of interest by moving the fixed vertices to the final position and let the others follow as smooth as possible
For self-explaining pictures see the link I provided.
One idea is to use the SpaceMorhp for that. I allready read this blogpost, but can not figure out where the points in SpaceMorph.MorphPoint(point) are coming from.
They seem to be connected to the mesh-vertices, but I dont know how. In the following code example every vertex in the mesh seems to be called twice.
I also don’t know what to do with a point for which I dont know the final position.
import Rhino
class TestMorph(Rhino.Geometry.SpaceMorph):
def __init__(self):
self.num_pt_call = 0
def MorphPoint(self, point):
self.num_pt_call += 1
print "MorpPoint called with: %s" % point
return point
def create_mesh():
mesh = Rhino.Geometry.Mesh()
mesh.Vertices.Add(0.0, 0.0, 0.0) # 0
mesh.Vertices.Add(1.0, 0.0, 0.0) # 1
mesh.Vertices.Add(1.0, 1.0, 0.0) # 2
mesh.Vertices.Add(0.0, 1.0, 0.0) # 3
mesh.Faces.AddFace(0, 1, 2)
mesh.Faces.AddFace(2, 3, 0)
mesh.Normals.ComputeNormals()
mesh.Compact()
return mesh
mesh = create_mesh()
tm = TestMorph()
tm.Morph(mesh)
print "called MorphPoint %s times" % tm.num_pt_call
# should print:
# MorpPoint called with: 0,0,0.0009765625
# MorpPoint called with: 1,0,0.0009765625
# MorpPoint called with: 1,1,0.0009765625
# MorpPoint called with: 0,1,0.0009765625
# MorpPoint called with: 0,0,0
# MorpPoint called with: 1,0,0
# MorpPoint called with: 1,1,0
# MorpPoint called with: 0,1,0
# called MorphPoint 8 times
Has anyone an idea for the Laplacian deformation?
Or can someone explain which points are given to the SpaceMorph.MorphPoint(…) method?
What to do with points for which I want Rhino to calculated the most “smooth” position?
Best
Raik