2004-08-04 06:16:46 +00:00
|
|
|
#!BPY
|
|
|
|
|
|
|
|
"""
|
2005-10-11 02:32:58 +00:00
|
|
|
Name: 'Bridge Faces/Edge-Loops'
|
|
|
|
Blender: 237
|
2004-08-04 06:16:46 +00:00
|
|
|
Group: 'Mesh'
|
2005-10-11 02:32:58 +00:00
|
|
|
Tooltip: 'Select 2 vert loops, then run this script.'
|
2004-08-04 06:16:46 +00:00
|
|
|
"""
|
|
|
|
|
2005-06-13 17:21:30 +00:00
|
|
|
__author__ = "Campbell Barton AKA Ideasman"
|
|
|
|
__url__ = ["http://members.iinet.net.au/~cpbarton/ideasman/", "blender", "elysiun"]
|
2005-10-11 02:32:58 +00:00
|
|
|
__version__ = "1.0 2004/04/25"
|
2004-11-07 16:31:13 +00:00
|
|
|
|
|
|
|
__bpydoc__ = """\
|
|
|
|
With this script vertex loops can be skinned: faces are created to connect the
|
|
|
|
selected loops of vertices.
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
|
|
|
In mesh Edit mode select the vertices of the loops (closed paths / curves of
|
|
|
|
vertices: circles, for example) that should be skinned, then run this script.
|
2005-10-11 02:32:58 +00:00
|
|
|
A pop-up will provide further options, if the results of a method are not adequate try one of the others.
|
2004-11-07 16:31:13 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2004-08-04 06:16:46 +00:00
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Skin Selected edges 1.0 By Campbell Barton (AKA Ideasman)
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
# ***** END GPL LICENCE BLOCK *****
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Made by Ideasman/Campbell 2005/06/15 - ideasman@linuxmail.org
|
2004-08-04 06:16:46 +00:00
|
|
|
|
|
|
|
import Blender
|
|
|
|
from Blender import *
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
BIG_NUM = 1<<30
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
global CULL_METHOD
|
|
|
|
CULL_METHOD = 0
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2006-07-30 05:48:28 +00:00
|
|
|
def AngleBetweenVecs(a1,a2):
|
|
|
|
try:
|
|
|
|
return Mathutils.AngleBetweenVecs(a1,a2)
|
|
|
|
except:
|
|
|
|
return 180.0
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
class edge:
|
|
|
|
def __init__(self, v1,v2):
|
|
|
|
self.v1 = v1
|
|
|
|
self.v2 = v2
|
2006-07-29 19:32:07 +00:00
|
|
|
co1, co2= v1.co, v2.co
|
|
|
|
self.co1= co1
|
|
|
|
self.co2= co2
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# uv1 uv2 vcol1 vcol2 # Add later
|
2006-07-29 19:32:07 +00:00
|
|
|
self.length = (co1 - co2).length
|
2006-07-18 10:20:43 +00:00
|
|
|
self.removed = 0 # Have we been culled from the eloop
|
|
|
|
self.match = None # The other edge were making a face with
|
2006-07-29 19:32:07 +00:00
|
|
|
|
2006-11-15 21:12:53 +00:00
|
|
|
self.cent= Mathutils.MidpointVecs(co1, co2)
|
2006-07-29 19:32:07 +00:00
|
|
|
self.angle= 0.0
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
class edgeLoop:
|
|
|
|
def __init__(self, loop): # Vert loop
|
|
|
|
# Use next and prev, nextDist, prevDist
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Get Loops centre.
|
2006-07-27 03:15:37 +00:00
|
|
|
fac= len(loop)
|
|
|
|
self.centre= reduce(lambda a,b: a+b.co/fac, loop, Mathutils.Vector())
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
# Convert Vert loop to Edges.
|
|
|
|
self.edges = []
|
|
|
|
vIdx = 0
|
|
|
|
while vIdx < len(loop):
|
|
|
|
self.edges.append( edge(loop[vIdx-1], loop[vIdx]) )
|
|
|
|
vIdx += 1
|
|
|
|
|
|
|
|
# Assign linked list
|
2006-07-10 09:22:07 +00:00
|
|
|
for eIdx in xrange(len(self.edges)-1):
|
2005-10-11 02:32:58 +00:00
|
|
|
self.edges[eIdx].next = self.edges[eIdx+1]
|
|
|
|
self.edges[eIdx].prev = self.edges[eIdx-1]
|
|
|
|
# Now last
|
|
|
|
self.edges[-1].next = self.edges[0]
|
|
|
|
self.edges[-1].prev = self.edges[-2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# GENERATE AN AVERAGE NORMAL FOR THE WHOLE LOOP.
|
|
|
|
self.normal = Mathutils.Vector()
|
|
|
|
for e in self.edges:
|
2006-07-29 19:32:07 +00:00
|
|
|
n = Mathutils.CrossVecs(self.centre-e.co1, self.centre-e.co2)
|
2005-10-11 02:32:58 +00:00
|
|
|
# Do we realy need tot normalize?
|
|
|
|
n.normalize()
|
|
|
|
self.normal += n
|
2006-07-29 19:32:07 +00:00
|
|
|
|
|
|
|
# Generate the angle
|
|
|
|
va= e.cent - e.prev.cent
|
2006-07-30 05:48:28 +00:00
|
|
|
vb= e.next.cent - e.cent
|
2006-07-29 19:32:07 +00:00
|
|
|
|
2006-07-30 05:48:28 +00:00
|
|
|
e.angle= AngleBetweenVecs(va, vb)
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-07-29 19:32:07 +00:00
|
|
|
# Blur the angles
|
|
|
|
#for e in self.edges:
|
|
|
|
# e.angle= (e.angle+e.next.angle)/2
|
|
|
|
|
|
|
|
# Blur the angles
|
|
|
|
#for e in self.edges:
|
|
|
|
# e.angle= (e.angle+e.prev.angle)/2
|
|
|
|
|
|
|
|
self.normal.normalize()
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
# Generate a normal for each edge.
|
|
|
|
for e in self.edges:
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2006-07-29 19:32:07 +00:00
|
|
|
n1 = e.co1
|
|
|
|
n2 = e.co2
|
|
|
|
n3 = e.prev.co1
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
a = n1-n2
|
|
|
|
b = n1-n3
|
|
|
|
normal1 = Mathutils.CrossVecs(a,b)
|
|
|
|
normal1.normalize()
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2006-07-29 19:32:07 +00:00
|
|
|
n1 = e.co2
|
|
|
|
n3 = e.next.co2
|
|
|
|
n2 = e.co1
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
a = n1-n2
|
|
|
|
b = n1-n3
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
normal2 = Mathutils.CrossVecs(a,b)
|
|
|
|
normal2.normalize()
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Reuse normal1 var
|
|
|
|
normal1 += normal1 + normal2
|
|
|
|
normal1.normalize()
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
e.normal = normal1
|
|
|
|
#print e.normal
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def backup(self):
|
|
|
|
# Keep a backup of the edges
|
|
|
|
self.backupEdges = self.edges[:]
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
def restore(self):
|
|
|
|
self.edges = self.backupEdges[:]
|
|
|
|
for e in self.edges:
|
|
|
|
e.removed = 0
|
|
|
|
|
|
|
|
def reverse(self):
|
|
|
|
self.edges.reverse()
|
|
|
|
for e in self.edges:
|
|
|
|
e.normal = -e.normal
|
|
|
|
e.v1, e.v2 = e.v2, e.v1
|
|
|
|
self.normal = -self.normal
|
|
|
|
|
|
|
|
def removeSmallest(self, cullNum, otherLoopLen):
|
2006-07-10 09:22:07 +00:00
|
|
|
'''
|
|
|
|
Removes N Smallest edges and backs up the loop,
|
|
|
|
this is so we can loop between 2 loops as if they are the same length,
|
|
|
|
backing up and restoring incase the loop needs to be skinned with another loop of a different length.
|
|
|
|
'''
|
2005-10-11 02:32:58 +00:00
|
|
|
global CULL_METHOD
|
2006-07-29 19:32:07 +00:00
|
|
|
if CULL_METHOD == 1: # Shortest edge
|
2005-10-11 02:32:58 +00:00
|
|
|
eloopCopy = self.edges[:]
|
2006-07-30 05:48:28 +00:00
|
|
|
eloopCopy.sort(lambda e1, e2: cmp(e1.length, e2.length )) # Length sort, smallest first
|
|
|
|
#eloopCopy.sort(lambda e1, e2: cmp(e1.angle*e1.length, e2.angle*e2.length)) # Length sort, smallest first
|
|
|
|
#eloopCopy.sort(lambda e1, e2: cmp(e1.angle, e2.angle)) # Length sort, smallest first
|
2005-10-11 02:32:58 +00:00
|
|
|
eloopCopy = eloopCopy[:cullNum]
|
|
|
|
for e in eloopCopy:
|
|
|
|
e.removed = 1
|
|
|
|
self.edges.remove( e ) # Remove from own list, still in linked list.
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
else: # CULL METHOD is even
|
|
|
|
|
|
|
|
culled = 0
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2006-07-29 19:32:07 +00:00
|
|
|
step = int(otherLoopLen / float(cullNum)) * 2
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
currentEdge = self.edges[0]
|
|
|
|
while culled < cullNum:
|
|
|
|
|
|
|
|
# Get the shortest face in the next STEP
|
2006-07-29 19:32:07 +00:00
|
|
|
step_count= 0
|
|
|
|
bestAng= 360.0
|
|
|
|
smallestEdge= None
|
|
|
|
while step_count<=step or smallestEdge==None:
|
|
|
|
step_count+=1
|
|
|
|
if not currentEdge.removed:
|
|
|
|
if currentEdge.angle<bestAng:
|
|
|
|
smallestEdge= currentEdge
|
|
|
|
bestAng= currentEdge.angle
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
currentEdge = currentEdge.next
|
|
|
|
|
|
|
|
# In that stepping length we have the smallest edge.remove it
|
|
|
|
smallestEdge.removed = 1
|
|
|
|
self.edges.remove(smallestEdge)
|
|
|
|
|
2006-07-29 19:32:07 +00:00
|
|
|
# Start scanning from the edge we found? - result is over fanning- no good.
|
|
|
|
#currentEdge= smallestEdge.next
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
culled+=1
|
|
|
|
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Returns face edges.
|
|
|
|
# face must have edge data.
|
|
|
|
|
|
|
|
def getSelectedEdges(me, ob):
|
2006-07-10 09:22:07 +00:00
|
|
|
MESH_MODE= Blender.Mesh.Mode()
|
|
|
|
|
|
|
|
if MESH_MODE==Blender.Mesh.SelectModes.EDGE or MESH_MODE==Blender.Mesh.SelectModes.VERTEX:
|
|
|
|
Blender.Mesh.Mode(Blender.Mesh.SelectModes.EDGE)
|
|
|
|
edges= [ ed for ed in me.edges if ed.sel ]
|
|
|
|
Blender.Mesh.Mode(MESH_MODE)
|
|
|
|
return edges
|
|
|
|
|
|
|
|
elif MESH_MODE==Blender.Mesh.SelectModes.FACE:
|
|
|
|
Blender.Mesh.Mode(Blender.Mesh.SelectModes.EDGE)
|
|
|
|
|
|
|
|
def ed_key(ed):
|
|
|
|
i1= ed.v1.index
|
|
|
|
i2= ed.v2.index
|
|
|
|
if i1 > i2:
|
|
|
|
return i2, i1
|
|
|
|
else:
|
|
|
|
return i1, i2
|
|
|
|
|
|
|
|
# value is [edge, face_sel_user_in]
|
2006-11-15 21:12:53 +00:00
|
|
|
'''
|
2006-07-18 10:20:43 +00:00
|
|
|
try: # Python 2.4 only
|
|
|
|
edge_dict= dict((ed_key(ed), [ed, 0]) for ed in me.edges)
|
|
|
|
except:
|
2006-11-15 21:12:53 +00:00
|
|
|
'''
|
|
|
|
# Cant try 2.4 syntax because python 2.3 will complain still
|
|
|
|
edge_dict= dict([(ed_key(ed), [ed, 0]) for ed in me.edges])
|
2006-07-10 09:22:07 +00:00
|
|
|
|
|
|
|
for f in me.faces:
|
|
|
|
if f.sel:
|
2006-07-18 10:20:43 +00:00
|
|
|
fidx= [v.index for v in f]
|
2006-07-10 09:22:07 +00:00
|
|
|
for i in xrange(len(fidx)):
|
|
|
|
i1= fidx[i]
|
|
|
|
i2= fidx[i-1]
|
|
|
|
|
|
|
|
if i1>i2:
|
|
|
|
i1,i2= i2,i1
|
|
|
|
|
|
|
|
# ed_data is a list of 2 ed and face user
|
|
|
|
ed_data= edge_dict[i1,i2]
|
|
|
|
ed_data[1]+=1
|
|
|
|
|
|
|
|
Blender.Mesh.Mode(MESH_MODE)
|
|
|
|
return [ ed_data[0] for ed_data in edge_dict.itervalues() if ed_data[1] == 1 ]
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Like vert loops
|
|
|
|
def getVertLoops(selEdges):
|
2006-07-10 09:22:07 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
mainVertLoops = []
|
|
|
|
while selEdges:
|
|
|
|
e = selEdges.pop()
|
|
|
|
contextVertLoop= [e.v1, e.v2] # start the vert loop
|
|
|
|
|
|
|
|
eIdx = 1 # Get us into the loop. dummy var.
|
|
|
|
|
|
|
|
# if eIdx == 0 then it means we searched and found no matches...
|
|
|
|
# time for a new vert loop,
|
|
|
|
while eIdx:
|
|
|
|
eIdx = len(selEdges)
|
|
|
|
while eIdx:
|
|
|
|
eIdx-=1
|
|
|
|
|
|
|
|
# Check for edge attached at the head of the loop.
|
|
|
|
if contextVertLoop[0] == selEdges[eIdx].v1:
|
|
|
|
contextVertLoop.insert(0, selEdges.pop(eIdx).v2)
|
|
|
|
elif contextVertLoop[0] == selEdges[eIdx].v2:
|
|
|
|
contextVertLoop.insert(0, selEdges.pop(eIdx).v1)
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Chech for edge vert at the tail.
|
|
|
|
elif contextVertLoop[-1] == selEdges[eIdx].v1:
|
|
|
|
contextVertLoop.append(selEdges.pop(eIdx).v2)
|
|
|
|
elif contextVertLoop[-1] == selEdges[eIdx].v2:
|
|
|
|
contextVertLoop.append(selEdges.pop(eIdx).v1)
|
|
|
|
else:
|
|
|
|
# None found? Keep looking
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Once found we.
|
|
|
|
break
|
|
|
|
|
|
|
|
# Is this a loop? if so then its forst and last vert must be teh same.
|
|
|
|
if contextVertLoop[0].index == contextVertLoop[-1].index:
|
|
|
|
contextVertLoop.pop() # remove double vert
|
|
|
|
mainVertLoops.append(contextVertLoop)
|
|
|
|
|
|
|
|
# Build context vert loops
|
|
|
|
return mainVertLoops
|
2004-08-04 06:16:46 +00:00
|
|
|
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
def skin2EdgeLoops(eloop1, eloop2, me, ob, MODE):
|
2006-07-10 09:22:07 +00:00
|
|
|
|
|
|
|
new_faces= [] #
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Make sure e1 loops is bigger then e2
|
|
|
|
if len(eloop1.edges) != len(eloop2.edges):
|
|
|
|
if len(eloop1.edges) < len(eloop2.edges):
|
|
|
|
eloop1, eloop2 = eloop2, eloop1
|
|
|
|
|
|
|
|
eloop1.backup() # were about to cull faces
|
|
|
|
CULL_FACES = len(eloop1.edges) - len(eloop2.edges)
|
|
|
|
eloop1.removeSmallest(CULL_FACES, len(eloop1.edges))
|
|
|
|
else:
|
|
|
|
CULL_FACES = 0
|
|
|
|
# First make sure poly vert loops are in sync with eachother.
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# The vector allong which we are skinning.
|
|
|
|
skinVector = eloop1.centre - eloop2.centre
|
|
|
|
|
|
|
|
loopDist = skinVector.length
|
|
|
|
|
|
|
|
|
|
|
|
# IS THE LOOP FLIPPED, IF SO FLIP BACK.
|
2006-07-30 05:48:28 +00:00
|
|
|
angleBetweenLoopNormals = AngleBetweenVecs(eloop1.normal, eloop2.normal)
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
if angleBetweenLoopNormals > 90:
|
|
|
|
eloop2.reverse()
|
|
|
|
|
2006-07-30 05:48:28 +00:00
|
|
|
DIR= eloop1.centre - eloop2.centre
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
bestEloopDist = BIG_NUM
|
|
|
|
bestOffset = 0
|
|
|
|
# Loop rotation offset to test.1
|
|
|
|
eLoopIdxs = range(len(eloop1.edges))
|
2006-07-10 09:22:07 +00:00
|
|
|
for offset in xrange(len(eloop1.edges)):
|
2005-10-11 02:32:58 +00:00
|
|
|
totEloopDist = 0 # Measure this total distance for thsi loop.
|
|
|
|
|
|
|
|
offsetIndexLs = eLoopIdxs[offset:] + eLoopIdxs[:offset] # Make offset index list
|
|
|
|
|
2006-07-30 05:48:28 +00:00
|
|
|
|
|
|
|
# e1Idx is always from 0uu to N, e2Idx is offset.
|
2005-10-11 02:32:58 +00:00
|
|
|
for e1Idx, e2Idx in enumerate(offsetIndexLs):
|
2006-07-30 05:48:28 +00:00
|
|
|
e1= eloop1.edges[e1Idx]
|
|
|
|
e2= eloop2.edges[e2Idx]
|
2006-07-29 19:32:07 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
|
2006-07-30 05:48:28 +00:00
|
|
|
# Include fan connections in the measurement.
|
|
|
|
OK= True
|
|
|
|
while OK or e1.removed:
|
|
|
|
OK= False
|
|
|
|
|
|
|
|
# Measure the vloop distance ===============
|
|
|
|
diff= ((e1.cent - e2.cent).length) #/ nangle1
|
|
|
|
|
|
|
|
ed_dir= e1.cent-e2.cent
|
|
|
|
a_diff= AngleBetweenVecs(DIR, ed_dir)/18 # 0 t0 18
|
|
|
|
|
2006-11-15 21:12:53 +00:00
|
|
|
totEloopDist += (diff * (1+a_diff)) / (1+loopDist)
|
2006-07-30 05:48:28 +00:00
|
|
|
|
|
|
|
# Premeture break if where no better off
|
|
|
|
if totEloopDist > bestEloopDist:
|
|
|
|
break
|
|
|
|
|
|
|
|
e1=e1.next
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
if totEloopDist < bestEloopDist:
|
|
|
|
bestOffset = offset
|
|
|
|
bestEloopDist = totEloopDist
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Modify V2 LS for Best offset
|
|
|
|
eloop2.edges = eloop2.edges[bestOffset:] + eloop2.edges[:bestOffset]
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-07-10 09:22:07 +00:00
|
|
|
for loopIdx in xrange(len(eloop2.edges)):
|
2005-10-11 02:32:58 +00:00
|
|
|
e1 = eloop1.edges[loopIdx]
|
|
|
|
e2 = eloop2.edges[loopIdx]
|
|
|
|
|
|
|
|
# Remember the pairs for fan filling culled edges.
|
|
|
|
e1.match = e2; e2.match = e1
|
2006-07-10 09:22:07 +00:00
|
|
|
new_faces.append([e1.v1, e1.v2, e2.v2, e2.v1])
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
# FAN FILL MISSING FACES.
|
|
|
|
if CULL_FACES:
|
|
|
|
# Culled edges will be in eloop1.
|
|
|
|
FAN_FILLED_FACES = 0
|
|
|
|
|
|
|
|
contextEdge = eloop1.edges[0] # The larger of teh 2
|
|
|
|
while FAN_FILLED_FACES < CULL_FACES:
|
|
|
|
while contextEdge.next.removed == 0:
|
|
|
|
contextEdge = contextEdge.next
|
|
|
|
|
|
|
|
vertFanPivot = contextEdge.match.v2
|
|
|
|
|
|
|
|
while contextEdge.next.removed == 1:
|
2006-07-10 09:22:07 +00:00
|
|
|
new_faces.append([contextEdge.next.v1, contextEdge.next.v2, vertFanPivot])
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
# Should we use another var?, this will work for now.
|
|
|
|
contextEdge.next.removed = 1
|
|
|
|
|
|
|
|
contextEdge = contextEdge.next
|
|
|
|
FAN_FILLED_FACES += 1
|
|
|
|
|
|
|
|
eloop1.restore() # Add culled back into the list.
|
2006-07-10 09:22:07 +00:00
|
|
|
|
|
|
|
me.faces.extend(new_faces)
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
#if angleBetweenLoopNormals > 90:
|
|
|
|
# eloop2.reverse()
|
2004-08-04 06:16:46 +00:00
|
|
|
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
def main():
|
|
|
|
global CULL_METHOD
|
|
|
|
|
|
|
|
is_editmode = Window.EditMode()
|
|
|
|
if is_editmode: Window.EditMode(0)
|
|
|
|
ob = Scene.GetCurrent().getActiveObject()
|
|
|
|
if ob == None or ob.getType() != 'Mesh':
|
|
|
|
return
|
|
|
|
|
2006-07-10 09:22:07 +00:00
|
|
|
me = ob.getData(mesh=1)
|
2005-10-11 02:32:58 +00:00
|
|
|
|
|
|
|
selEdges = getSelectedEdges(me, ob)
|
|
|
|
vertLoops = getVertLoops(selEdges) # list of lists of edges.
|
|
|
|
|
|
|
|
if len(vertLoops) > 2:
|
|
|
|
choice = Draw.PupMenu('Loft '+str(len(vertLoops))+' edge loops%t|loop|segment')
|
|
|
|
if choice == -1:
|
|
|
|
if is_editmode: Window.EditMode(1)
|
|
|
|
return
|
|
|
|
elif len(vertLoops) < 2:
|
|
|
|
Draw.PupMenu('Error, No Vertloops found%t|if you have a valid selection, go in and out of face edit mode to update the selection state.')
|
|
|
|
if is_editmode: Window.EditMode(1)
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
choice = 2
|
|
|
|
|
|
|
|
|
|
|
|
# The line below checks if any of the vert loops are differenyt in length.
|
|
|
|
if False in [len(v) == len(vertLoops[0]) for v in vertLoops]:
|
2006-07-29 19:32:07 +00:00
|
|
|
CULL_METHOD = Draw.PupMenu('Small to large edge loop distrobution method%t|remove edges evenly|remove smallest edges')
|
2005-10-11 02:32:58 +00:00
|
|
|
if CULL_METHOD == -1:
|
|
|
|
if is_editmode: Window.EditMode(1)
|
|
|
|
return
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
if CULL_METHOD ==1: # RESET CULL_METHOD
|
|
|
|
CULL_METHOD = 0 # shortest
|
|
|
|
else:
|
|
|
|
CULL_METHOD = 1 # even
|
|
|
|
|
|
|
|
|
|
|
|
time1 = sys.time()
|
|
|
|
# Convert to special edge data.
|
|
|
|
edgeLoops = []
|
|
|
|
for vloop in vertLoops:
|
|
|
|
edgeLoops.append(edgeLoop(vloop))
|
2004-08-04 06:16:46 +00:00
|
|
|
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# VERT LOOP ORDERING CODE
|
2006-07-10 09:22:07 +00:00
|
|
|
# "Build a worm" list - grow from Both ends
|
2005-10-11 02:32:58 +00:00
|
|
|
edgeOrderedList = [edgeLoops.pop()]
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Find the closest.
|
|
|
|
bestSoFar = BIG_NUM
|
|
|
|
bestIdxSoFar = None
|
|
|
|
for edLoopIdx, edLoop in enumerate(edgeLoops):
|
|
|
|
l =(edgeOrderedList[-1].centre - edLoop.centre).length
|
|
|
|
if l < bestSoFar:
|
|
|
|
bestIdxSoFar = edLoopIdx
|
|
|
|
bestSoFar = l
|
|
|
|
|
|
|
|
edgeOrderedList.append( edgeLoops.pop(bestIdxSoFar) )
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
# Now we have the 2 closest, append to either end-
|
|
|
|
# Find the closest.
|
|
|
|
while edgeLoops:
|
|
|
|
bestSoFar = BIG_NUM
|
|
|
|
bestIdxSoFar = None
|
|
|
|
first_or_last = 0 # Zero is first
|
|
|
|
for edLoopIdx, edLoop in enumerate(edgeLoops):
|
|
|
|
l1 =(edgeOrderedList[-1].centre - edLoop.centre).length
|
|
|
|
|
|
|
|
if l1 < bestSoFar:
|
|
|
|
bestIdxSoFar = edLoopIdx
|
|
|
|
bestSoFar = l1
|
|
|
|
first_or_last = 1 # last
|
|
|
|
|
|
|
|
l2 =(edgeOrderedList[0].centre - edLoop.centre).length
|
|
|
|
if l2 < bestSoFar:
|
|
|
|
bestIdxSoFar = edLoopIdx
|
|
|
|
bestSoFar = l2
|
|
|
|
first_or_last = 0 # last
|
|
|
|
|
|
|
|
if first_or_last: # add closest Last
|
|
|
|
edgeOrderedList.append( edgeLoops.pop(bestIdxSoFar) )
|
|
|
|
else: # Add closest First
|
|
|
|
edgeOrderedList.insert(0, edgeLoops.pop(bestIdxSoFar) ) # First
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2006-07-10 09:22:07 +00:00
|
|
|
for i in xrange(len(edgeOrderedList)-1):
|
2005-10-11 02:32:58 +00:00
|
|
|
skin2EdgeLoops(edgeOrderedList[i], edgeOrderedList[i+1], me, ob, 0)
|
|
|
|
if choice == 1 and len(edgeOrderedList) > 2: # Loop
|
|
|
|
skin2EdgeLoops(edgeOrderedList[0], edgeOrderedList[-1], me, ob, 0)
|
|
|
|
|
2006-07-10 09:22:07 +00:00
|
|
|
print '\nSkin done in %.4f sec.' % (sys.time()-time1)
|
|
|
|
|
|
|
|
# REMOVE SELECTED FACES.
|
|
|
|
faces= [ f for f in me.faces if f.sel ]
|
2006-07-18 10:20:43 +00:00
|
|
|
|
2006-07-10 09:22:07 +00:00
|
|
|
if faces:
|
|
|
|
me.faces.delete(1, faces)
|
|
|
|
|
2005-10-11 02:32:58 +00:00
|
|
|
if is_editmode: Window.EditMode(1)
|
2004-08-04 06:16:46 +00:00
|
|
|
|
2006-01-29 19:17:53 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|