Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillian Padovani Germano <wpgermano@gmail.com>2005-06-13 21:21:30 +0400
committerWillian Padovani Germano <wpgermano@gmail.com>2005-06-13 21:21:30 +0400
commitde567cd0cc5532d3a6aa521328230239fa082810 (patch)
treea9018da510f981c7b9b4f163bb8dcf472c6ed7c2
parente5b527c629c2b6cc44944cc4b27f21c81d7ab4fb (diff)
Scripts:
- Campbell Barton updated his obj exporter and skin (bridge/skin/loft) scripts. Thanks.
-rw-r--r--release/scripts/obj_export.py53
-rw-r--r--release/scripts/skin.py138
2 files changed, 91 insertions, 100 deletions
diff --git a/release/scripts/obj_export.py b/release/scripts/obj_export.py
index b6ef15a47e3..8c52c28967e 100644
--- a/release/scripts/obj_export.py
+++ b/release/scripts/obj_export.py
@@ -2,7 +2,7 @@
"""
Name: 'Wavefront (.obj)...'
-Blender: 237
+Blender: 232
Group: 'Export'
Tooltip: 'Save a Wavefront OBJ File'
"""
@@ -56,37 +56,20 @@ NULL_IMG = '(null)' # from docs at http://astronomy.swin.edu.au/~pbourke/geomfor
def save_mtl(filename):
file = open(filename, "w")
+ file.write('# Blender MTL File: %s\n' % (Get('filename')))
for mat in Material.Get():
-
file.write('newmtl %s\n' % (mat.getName())) # Define a new material
-
- # Hardness, convert blenders 1-511 to MTL's
- file.write('Ns %s\n' % ((mat.getHardness()-1) * 1.9607843137254901 ) )
-
- col = mat.getRGBCol()
- # Diffuse
- file.write('Kd %s %s %s\n' % (col[0], col[1], col[2]))
-
- col = mat.getMirCol()
- # Ambient, uses mirror colour,
- file.write('Ka %s %s %s\n' % (col[0], col[1], col[2]))
-
- col = mat.getSpecCol()
- # Specular
- file.write('Ks %s %s %s\n' % (col[0],col[1], col[2]))
-
- # Alpha (dissolve)
- file.write('d %s\n' % (mat.getAlpha()))
+ file.write('Ns %s\n' % ((mat.getHardness()-1) * 1.9607843137254901 ) ) # Hardness, convert blenders 1-511 to MTL's
+ file.write('Kd %.6f %.6f %.6f\n' % tuple(mat.getRGBCol())) # Diffuse
+ file.write('Ka %.6f %.6f %.6f\n' % tuple(mat.getMirCol())) # Ambient, uses mirror colour,
+ file.write('Ks %.6f %.6f %.6f\n' % tuple(mat.getSpecCol())) # Specular
+ file.write('d %.6f\n' % mat.getAlpha()) # Alpha (obj uses 'd' for dissolve)
# illum, 0 to disable lightng, 2 is normal.
if mat.getMode() & Material.Modes['SHADELESS']:
- file.write('illum 0\n') # ignore lighting
+ file.write('illum 0\n\n') # ignore lighting
else:
- file.write('illum 2\n') # light normaly
-
- # End OF Mat
- file.write('\n') # new line
-
+ file.write('illum 2\n\n') # light normaly
file.close()
def save_obj(filename):
@@ -126,24 +109,20 @@ def save_obj(filename):
# Vert
for v in m.verts:
- file.write('v %s %s %s\n' % (v.co.x, v.co.y, v.co.z))
+ file.write('v %.6f %.6f %.6f\n' % tuple(v.co))
# UV
for f in m.faces:
- ''' # Export edges?
- if len(f.v) < 3:
- continue
- '''
for uvIdx in range(len(f.v)):
if f.uv:
- file.write('vt %s %s 0.0\n' % (f.uv[uvIdx][0], f.uv[uvIdx][1]))
+ file.write('vt %.6f %.6f 0.0\n' % f.uv[uvIdx])
else:
file.write('vt 0.0 0.0 0.0\n')
# NORMAL
- for f1 in m.faces:
- for v in f1.v:
- file.write('vn %s %s %s\n' % (v.no.x, v.no.y, v.no.z))
+ for f in m.faces:
+ for v in f.v:
+ file.write('vn %.6f %.6f %.6f\n' % tuple(v.no))
uvIdx = 0
for f in m.faces:
@@ -172,7 +151,7 @@ def save_obj(filename):
file.write('f ')
for v in f.v:
- file.write( '%s/%s/%s ' % (m.verts.index(v) + totverts+1, uvIdx+totuvco+1, uvIdx+totuvco+1))
+ file.write( '%s/%s/%s ' % (v.index + totverts+1, uvIdx+totuvco+1, uvIdx+totuvco+1))
uvIdx+=1
file.write('\n')
@@ -181,6 +160,6 @@ def save_obj(filename):
totverts += len(m.verts)
totuvco += uvIdx
file.close()
- print "obj export time: ", sys.time() - time1
+ print "obj export time: %.2f" % (sys.time() - time1)
Window.FileSelector(save_obj, 'Export Wavefront OBJ', newFName('obj'))
diff --git a/release/scripts/skin.py b/release/scripts/skin.py
index 7bc97e37f64..d3d1d034db7 100644
--- a/release/scripts/skin.py
+++ b/release/scripts/skin.py
@@ -1,19 +1,15 @@
#!BPY
"""
-Name: 'Skin Two Vert-loops / Loft Multiple'
+Name: 'Bridge/Skin/Loft'
Blender: 234
Group: 'Mesh'
-Submenu: 'Loft-loop - shortest edge method' A1
-Submenu: 'Loft-loop - even method' A2
-Submenu: 'Loft-segment - shortest edge' B1
-Submenu: 'Loft-segment - even method' B2
Tooltip: 'Select 2 or more vert loops, then run this script'
"""
-__author__ = "Campbell Barton"
-__url__ = ["blender", "elysiun"]
-__version__ = "1.0 2004/04/25"
+__author__ = "Campbell Barton AKA Ideasman"
+__url__ = ["http://members.iinet.net.au/~cpbarton/ideasman/", "blender", "elysiun"]
+__version__ = "1.1 2005/06/13"
__bpydoc__ = """\
With this script vertex loops can be skinned: faces are created to connect the
@@ -23,7 +19,11 @@ 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.
-A pop-up will provide further options, if the results of a method are not adequate try one of the others.
+A pop-up will provide further options.
+
+Notes:
+
+If the results of a method chosen from the pop-up are not adequate, undo and try one of the others.
"""
@@ -59,7 +59,23 @@ import Blender
from Blender import *
import math
from math import *
-arg = __script__['arg']
+
+
+choice = Draw.PupMenu(\
+'Loft-loop - shortest edge method|\
+Loft-loop - even method|\
+Loft-segment - shortest edge|\
+Loft-segment - even method')
+
+if choice == 1:
+ arg='A1'
+elif choice == 2:
+ arg='A2'
+elif choice == 3:
+ arg='B1'
+elif choice == 4:
+ arg='B2'
+
#================#
@@ -80,7 +96,7 @@ def clamp(max, number):
# List func that takes the last item and adds it to the front #
#=============================================================#
def listRotate(ls):
- return [ls[-1]] + ls[:-1]
+ ls.append(ls.pop(0))
#=================================================================#
# Recieve a list of locs: [x,y,z] and return the average location #
@@ -134,22 +150,26 @@ def selVertBetween2Faces(face1, face2):
# Measure the total distance between all the edges in #
# 2 vertex loops #
#=======================================================#
-def measureVloop(mesh, v1loop, v2loop, surplusFaces):
+def measureVloop(mesh, v1loop, v2loop, surplusFaces, bestSoFar):
totalDist = 0
# Rotate the vertloops to cycle through each pair.
# of faces to compate the distance between the 2 poins
for ii in range(len(v1loop)):
if ii not in surplusFaces:
- V1 = selVertBetween2Faces(mesh.faces[v1loop[0]], mesh.faces[v1loop[1]])
- V2 = selVertBetween2Faces(mesh.faces[v2loop[0]], mesh.faces[v2loop[1]])
+ # Clamp
+ v2clampii = ii
+ while v2clampii >= len(v2loop):
+ v2clampii -= len(v2loop)
+ print v2clampii
- P1 = (V1[0],V1[1],V1[2])
- P2 = (V2[0],V2[1],V2[2])
-
- totalDist += measure(P1,P2)
- v1loop = listRotate(v1loop)
- v2loop = listRotate(v2loop)
+ V1 = selVertBetween2Faces(mesh.faces[v1loop[ii-1]], mesh.faces[v1loop[ii]])
+ V2 = selVertBetween2Faces(mesh.faces[v2loop[v2clampii-1]], mesh.faces[v2loop[v2clampii]])
+
+ totalDist += measure(V1, V2)
+ # Bail out early if not an improvement on previously measured.
+ if bestSoFar != None and totalDist > bestSoFar:
+ return totalDist
#selVertBetween2Faces(mesh.faces[v2loop[0]], mesh.faces[v2loop[1]])
return totalDist
@@ -192,7 +212,7 @@ def skinVertLoops(mesh, v1loop, v2loop):
# Work out if the vert loops are equel or not, if not remove the extra faces from the larger
surplusFaces = []
- tempv1loop = eval(str(v1loop)) # strip faces off this one, use it to keep track of which we have taken faces from.
+ tempv1loop = v1loop[:] # strip faces off this one, use it to keep track of which we have taken faces from.
if len(v1loop) > len(v2loop):
# Even face method.
@@ -231,20 +251,20 @@ def skinVertLoops(mesh, v1loop, v2loop):
# Copy old faces properties
face.v.append( selVertBetween2Faces(\
- mesh.faces[v1loop[clamp(lenVloop, fIdx)]],\
- mesh.faces[v1loop[clamp(lenVloop, fIdx+1)]]) )
+ mesh.faces[v1loop[clamp(lenVloop, fIdx)]],\
+ mesh.faces[v1loop[clamp(lenVloop, fIdx+1)]]) )
face.v.append( selVertBetween2Faces(\
- mesh.faces[v1loop[clamp(lenVloop, fIdx+1)]],\
- mesh.faces[v1loop[clamp(lenVloop, fIdx+2)]]) )
+ mesh.faces[v1loop[clamp(lenVloop, fIdx+1)]],\
+ mesh.faces[v1loop[clamp(lenVloop, fIdx+2)]]) )
#face.v.append( selVertBetween2Faces(\
#mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, (fIdx - offset +1 ))]],\
#mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, (fIdx - offset + 2))]]) )
face.v.append( selVertBetween2Faces(\
- mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, (fIdx - offset))]],\
- mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, fIdx - offset + 1)]]) )
+ mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, (fIdx - offset))]],\
+ mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, fIdx - offset + 1)]]) )
mesh.faces.append(face)
@@ -256,20 +276,20 @@ def skinVertLoops(mesh, v1loop, v2loop):
# Draw a normal quad between the 2 edges/faces
face.v.append( selVertBetween2Faces(\
- mesh.faces[v1loop[clamp(lenVloop, fIdx)]],\
- mesh.faces[v1loop[clamp(lenVloop, fIdx+1)]]) )
+ mesh.faces[v1loop[clamp(lenVloop, fIdx)]],\
+ mesh.faces[v1loop[clamp(lenVloop, fIdx+1)]]) )
face.v.append( selVertBetween2Faces(\
- mesh.faces[v1loop[clamp(lenVloop, fIdx+1)]],\
- mesh.faces[v1loop[clamp(lenVloop, fIdx+2)]]) )
+ mesh.faces[v1loop[clamp(lenVloop, fIdx+1)]],\
+ mesh.faces[v1loop[clamp(lenVloop, fIdx+2)]]) )
face.v.append( selVertBetween2Faces(\
- mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, (fIdx - offset +1 ))]],\
- mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, (fIdx - offset + 2))]]) )
+ mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, (fIdx - offset +1 ))]],\
+ mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, (fIdx - offset + 2))]]) )
face.v.append( selVertBetween2Faces(\
- mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, (fIdx - offset))]],\
- mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, fIdx - offset + 1)]]) )
+ mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, (fIdx - offset))]],\
+ mesh.faces[v2loop[clamp(lenVloop - lenSupFaces, fIdx - offset + 1)]]) )
mesh.faces.append(face)
@@ -348,24 +368,19 @@ def optimizeLoopOrded(mesh, v1loop, v2loop):
for ii in range(len(v1loop)):
# Loop twice , Once for the forward test, and another for the revearsed
- for iii in [0, 0]:
- dist = measureVloop(mesh, v1loop, v2loop)
+ for iii in [None, None]:
+ dist = measureVloop(mesh, v1loop, v2loop, bestSoFar)
# Initialize the Best distance recorded
- if bestSoFar == None:
+ if bestSoFar == None or dist < bestSoFar:
bestSoFar = dist
- bestv2Loop = eval(str(v2loop))
-
- elif dist < bestSoFar: # Update the info if a better vloop rotation is found.
- bestSoFar = dist
- bestv2Loop = eval(str(v2loop))
+ bestv2Loop = v2loop[:]
# We might have got the vert loop backwards, try the other way
v2loop.reverse()
- v2loop = listRotate(v2loop)
+ listRotate(v2loop)
return bestv2Loop
-
#================================================================#
# Now we work out the optimum order to 'skin' the 2 vert loops #
# by measuring the total distance of all edges created, #
@@ -381,28 +396,22 @@ def optimizeLoopOrdedShortEdge(mesh, v1loop, v2loop, surplusFaces):
for ii in range(len(v2loop)):
# Loop twice , Once for the forward test, and another for the revearsed
- for iii in [0, 0]:
- dist = measureVloop(mesh, v1loop, v2loop, surplusFaces)
+ for iii in [None, None]:
+ dist = measureVloop(mesh, v1loop, v2loop, surplusFaces, bestSoFar)
print 'dist', dist
# Initialize the Best distance recorded
- if bestSoFar == None:
+ if bestSoFar == None or dist < bestSoFar:
bestSoFar = dist
- bestv2Loop = eval(str(v2loop))
+ bestv2Loop = v2loop[:]
- elif dist < bestSoFar: # Update the info if a better vloop rotation is found.
- bestSoFar = dist
- bestv2Loop = eval(str(v2loop))
# We might have got the vert loop backwards, try the other way
v2loop.reverse()
- v2loop = listRotate(v2loop)
+ #v2loop = listRotate(v2loop)
+ listRotate(v2loop)
print 'best so far ', bestSoFar
return bestv2Loop
-
-
-
-
#==============================#
# Find our vert loop list #
@@ -511,12 +520,10 @@ def reorderCircularVLoops(mesh, allVLoops):
bestSoFar = 0
while vLoopIdx < len(reorderedVLoopLocs):
-
# Skin back to the start if needs be, becuase this is a crcular loft
toSkin2 = vLoopIdx + 1
if toSkin2 == len(reorderedVLoopLocs):
toSkin2 = 0
-
newDist = measure( reorderedVLoopLocs[vLoopIdx], reorderedVLoopLocs[toSkin2] )
@@ -534,7 +541,9 @@ if is_editmode: Window.EditMode(0)
# Get a mesh and raise errors if we cant
mesh = None
-if len(Object.GetSelected()) > 0:
+if choice == -1:
+ pass
+elif len(Object.GetSelected()) > 0:
if Object.GetSelected()[0].getType() == 'Mesh':
mesh = Object.GetSelected()[0].getData()
else:
@@ -542,8 +551,9 @@ if len(Object.GetSelected()) > 0:
else:
error('no mesh object selected')
-
+time1 = sys.time()
if mesh != None:
+ Window.WaitCursor(1)
allVLoops = getAllVertLoops(mesh)
# Re order the vert loops
@@ -559,7 +569,7 @@ if mesh != None:
toSkin2 = vloopIdx + 1
if toSkin2 == len(allVLoops):
toSkin2 = 0
-
+
# Circular loft or not?
if arg[0] == 'B': # B for open
if vloopIdx != vLoopIdxNotToSkin:
@@ -569,6 +579,8 @@ if mesh != None:
vloopIdx +=1
- mesh.update()
+ mesh.update(1,(mesh.edges != []),0)
if is_editmode: Window.EditMode(1)
+Window.WaitCursor(0)
+print "skinning time: %.2f" % (sys.time() - time1)