Hi everyone,
I am wondering how I can deform a mesh (which has no volume) with another mesh of the same type but different shapes. The script/command should ‘raise’ the original mesh. (The whole thing is similar to the flow on surface tool but with meshes)
Has this been done before by anyone? I am thankful for any ideas.
Cheers
Benjamin
Depending on the two meshes, it would be pretty straightforward to script/Grasshopper an algorithm that iterates all the vertices of mesh A and projects them to their closest point on Mesh B. A more advanced solution might be to pull mesh A onto mesh B using Kangaroo (which would enable things like constraining edge lengths, face angles/areas etc.).
I’m wondering if you couldn’t drape both meshes and then use FlowAlongSrf with the meshes as the objects to transform and the two draped surfaces as base and target for the transformation.
As you can’t snap to objects when draping (unfortunately), you might need to drape a bit larger than you need in both cases, trim both drapes with the same rectangle, then use ShrinkTrimmedSrfToEdge to get them to have the same extents…
–Mitch
Or, along similar lines, Patch both meshes with the same settings. Orientation will be tricky though, depending… might need a starting surface.
@Benjamin4, An example file would be useful…
-Pascal
Hey @pascal, @Helvetosaur and @AndersDeleuran,
here is an example. I am trying to deform Mesh 1 with Mesh 2.
Thanks for any help and your comments! I will definitely try out your suggestions.
@Benjamin4 I have been working on a remeshing plugin for Rhinoceros 3d called Gopher. It is still work in progress, but it will remesh and project a mesh onto another mesh. This took might be just what you are looking for. I have added a WIP rhp to my site:
The command you will want to run is GopherRemeshProject, the defaults should work well with what you are looking to do.
@mnewberg: Awesome thank you! Is there any Python binding to include it into a script?
Cheers
Benjamin
I wasn’t considering any Python binding when I wrote this, but I also didn’t do anything to restrict using this code from PythonScript (or other). Here is a sample script using this plugin:
from Rhino.Commands import *
from Rhino.Input.Custom import *
from Rhino.DocObjects import *
from scriptcontext import doc
import clr
clr.AddReference("Gopher.rhp")
import Gopher
def RunCommand():
gm = GetObject()
gm.SetCommandPrompt("Select mesh")
gm.GeometryFilter = ObjectType.Mesh
gm.Get()
if gm.CommandResult() != Result.Success:
return gm.CommandResult()
mesh = gm.Object(0).Mesh()
if mesh == None:
return Result.Failure
gmt = GetObject()
gmt.EnablePreSelect(False, True)
gmt.SetCommandPrompt("Select mesh Target")
gmt.GeometryFilter = ObjectType.Mesh
gmt.Get()
if gmt.CommandResult() != Result.Success:
return gmt.CommandResult()
meshTarget = gmt.Object(0).Mesh()
if meshTarget == None:
return Result.Failure;
d3Mesh = Gopher.GopherUtil.ConvertToD3Mesh(mesh)
d3MeshTarget = Gopher.GopherUtil.ConvertToD3Mesh(meshTarget)
newMesh = Gopher.GopherUtil.RemeshMesh(d3Mesh, 1, 3, 30, 0.5, 10, d3MeshTarget, 0.5, 30)
rhinoMesh = Gopher.GopherUtil.ConvertToRhinoMesh(newMesh)
doc.Objects.Add(rhinoMesh)
doc.Views.Redraw()
return Result.Success
if __name__ == "__main__":
RunCommand()
Not specific to this thread, but because this is the hit that comes up when you’re trying to figure out how to use Gopher in Python, here’s how I did it in Grasshopper. This is the complete script for a tiny Python component that takes a mesh, runs Gopher Remesh on it with hardcoded parms, and outputs the result.
import rhinoscriptsyntax as rs
import clr
clr.AddReferenceByName("Gopher")
import Gopher
def main(m):
print "hi Gopher"
gmesh = Gopher.GopherUtil.ConvertToD3Mesh(rs.coercemesh(m))
#mesh, minEdge, maxEdge, constraintAngle, smoothSpeed, smoothPasses, constrainedLines
a = Gopher.GopherUtil.RemeshMesh(gmesh,.1,.2,30,.5,20)
return Gopher.GopherUtil.ConvertToRhinoMesh(a)
#end main
a = main(m)
Differences from the above: clr.AddReference() didn’t work, had to use AddReferenceByName (or FileAndPath works). And you have to coerce the mesh from guid to Rhino geometry. Other than that, ezpz.