Last active
August 29, 2015 14:05
-
-
Save Eterea/98fb6bedf12cdc5931b9 to your computer and use it in GitHub Desktop.
This Modo script will divide an edge on a mesh slicing it evenly to arrive as closer as possible to a "balanced" uniform mesh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python | |
#-------------------------------------------------------------------------------------- | |
# NAME: etr_sliceToSquares.py | |
# VERS: 1.1 | |
# DATE: August 11, 2013 | |
# | |
# MADE: Cristobal Vila, etereaestudios.com | |
# | |
# USES: This script will divide an edge on a mesh (like a vertical edge in a cylinder) | |
# slicing it evenly to arrive as closer as possible to a "balanced" uniform mesh, | |
# like if it would be created using near to squared polygons in both axes. | |
#-------------------------------------------------------------------------------------- | |
# Calculate Length for Selected Edge and Store it in a Set | |
myEdge_ID = lx.evalN('query layerservice edges ? selected') | |
myEdge_LEN = lx.eval('query layerservice edge.length ? %s' % myEdge_ID) | |
lx.eval('select.editSet tempSetA add') | |
# Define Function to Slice | |
def sliceFunction(slice_N): | |
lx.eval('tool.set poly.loopSlice on') | |
lx.eval('tool.attr poly.loopSlice count %s' % slice_N) | |
lx.eval('tool.attr poly.loopSlice mode uniform') | |
lx.eval('tool.attr poly.loopSlice select 0') | |
lx.eval('tool.attr poly.loopSlice depth 0.0') | |
lx.eval('tool.setAttr poly.loopSlice edit move') | |
lx.eval('tool.doApply') | |
lx.eval('tool.attr poly.loopSlice select false') | |
lx.eval('tool.set poly.loopSlice off 0') | |
# Create an individual Loop Slice transversal to our selected Edge | |
sliceFunction(1) | |
# Calculate and Store Total Lenght for that Transversal Loop of Edges | |
transEdges_N = lx.eval('query layerservice edge.N ? selected') | |
transTotal_LEN = sum(lx.eval('query layerservice edge.length ? %s' % edge) | |
for edge in lx.evalN('query layerservice edges ? selected')) | |
# Remove the Transversal Loop of Edges and recover original Edge Selection. Delete Set. | |
lx.eval('remove') | |
lx.eval('select.useSet tempSetA select') | |
lx.eval('!!select.deleteSet tempSetA') | |
# Calculate Average size for each edge on Transversal Loop | |
transAvge_LEN = transTotal_LEN / transEdges_N | |
# Calculate needed Slice Divisions: we divide our Original Edge Length | |
# by Average Length for each edge on Transversal Loop | |
sliceDivisions = myEdge_LEN / transAvge_LEN | |
# Stop script execution if value for sliceDivisions is too small | |
if sliceDivisions < 1.5: | |
sys.exit() | |
# Calculate final number for Divisions, considering decimal part | |
decimalPart = sliceDivisions - int(sliceDivisions) | |
if decimalPart < 0.5: | |
sliceDivisions = sliceDivisions - 1 | |
# Execute final Slice Divisions | |
sliceFunction(sliceDivisions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment