MeshFlattening: add function to unwrap mesh
This commit is contained in:
@@ -174,7 +174,8 @@ void FaceUnwrapper::findFlatNodes()
|
||||
std::vector<long> fixed_pins; //TODO: INPUT
|
||||
LscmRelax mesh_flattener(this->xyz_nodes.transpose(), this->tris.transpose(), fixed_pins);
|
||||
mesh_flattener.lscm();
|
||||
mesh_flattener.relax(0.9);
|
||||
for (int j=0; j<9; j++)
|
||||
mesh_flattener.relax(0.9);
|
||||
this->ze_nodes = mesh_flattener.flat_vertices.transpose();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,42 +1,58 @@
|
||||
import numpy as np
|
||||
import FreeCADGui as gui
|
||||
import Mesh
|
||||
import FreeCAD as app
|
||||
import flatMesh
|
||||
import Part
|
||||
|
||||
|
||||
import FreeCAD as App
|
||||
import FreeCADGui as gui
|
||||
|
||||
class BaseCommand(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def IsActive(self):
|
||||
if FreeCAD.ActiveDocument is None:
|
||||
if App.ActiveDocument is None:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
class CreateFlatMesh(BaseCommand):
|
||||
"""create an involute gear"""
|
||||
"""create flat wires from a meshed face"""
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap': 'not_yet.svg', 'MenuText': 'unwrap mesh', 'ToolTip': 'find a flat representation of a mesh'}
|
||||
return {'MenuText': 'Unwrap Mesh', 'ToolTip': 'find a flat representation of a mesh'}
|
||||
|
||||
def Activated(self):
|
||||
obj = Gui.Selection.getSelection()[0] # obj must be a Mesh (Mesh-Design->Meshes->Create-Mesh)
|
||||
import numpy as np
|
||||
import flatmesh
|
||||
import Part
|
||||
obj = gui.Selection.getSelection()[0] # obj must be a Mesh (Mesh-Design->Meshes->Create-Mesh)
|
||||
mesh = Mesh.Mesh(obj.Mesh) # copy of the mesh to set new vertices later on
|
||||
points = np.array([[i.x, i.y, i.z] for i in obj.Mesh.Points])
|
||||
faces = np.array([list(i) for i in obj.Mesh.Topology[1]])
|
||||
flattener = flatMesh.FaceUnwrapper(points, faces)
|
||||
print(faces)
|
||||
flattener = flatmesh.FaceUnwrapper(points, faces)
|
||||
flattener.findFlatNodes()
|
||||
boundaries = flattener.getFlatBoundaryNodes()
|
||||
wires = []
|
||||
for edge in boundaries:
|
||||
pi = Part.makePolygon([app.Vector(*node) for node in edge])
|
||||
wires.append(pi)
|
||||
Part.show(Part.Wire(wires))
|
||||
pi = Part.makePolygon([App.Vector(*node) for node in edge])
|
||||
Part.show(Part.Wire(pi))
|
||||
|
||||
def IsActive(self):
|
||||
assert(super(CreateFlatMesh, self).IsActive())
|
||||
assert(isinstance(gui.Selection.getSelection()[0].Mesh, Mesh.Mesh))
|
||||
return True
|
||||
|
||||
def initialize():
|
||||
Gui.addCommand('CreateFlatMesh', CreateFlatMesh())
|
||||
return ["CreateFlatMesh"]
|
||||
class CreateFlatFace(BaseCommand):
|
||||
"""create a flat face from a single face
|
||||
only full faces are supported right now"""
|
||||
|
||||
def GetResources(self):
|
||||
return {'MenuText': 'Unwrap Face', 'ToolTip': 'find a flat representation of a mesh'}
|
||||
|
||||
def IsActive(self):
|
||||
assert(super(CreateFlatMesh, self).IsActive())
|
||||
assert(isinstance(gui.Selection.getSelection()[0], Part.Face))
|
||||
return True
|
||||
|
||||
|
||||
|
||||
gui.addCommand('CreateFlatMesh', CreateFlatMesh())
|
||||
|
||||
Reference in New Issue
Block a user