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-08-01 07:06:24 +0400
committerWillian Padovani Germano <wpgermano@gmail.com>2005-08-01 07:06:24 +0400
commitf6ff9ec608df550b10fa94ddc1f9cd010e5a8e8a (patch)
treefd02b9d052242ec962d8e5943c960ed79e3803f4 /release
parent3f9d13c119af83762baf7f526cfccfa412972525 (diff)
Scripts updated:
- Jean-Michel Soler: 1) paths import -- ai module; 2) tex2uvbaker; - Campbell Barton: obj exporter. BPython: - Campbell also provided a patch (+docs) to add shader data access to Blender.Material. Again, thanks guys and sorry for the long delay.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/bpymodules/ai2obj.py8
-rw-r--r--release/scripts/obj_export.py67
-rw-r--r--release/scripts/tex2uvbaker.py100
3 files changed, 108 insertions, 67 deletions
diff --git a/release/scripts/bpymodules/ai2obj.py b/release/scripts/bpymodules/ai2obj.py
index 410cbe0405a..47c2dcbd57e 100644
--- a/release/scripts/bpymodules/ai2obj.py
+++ b/release/scripts/bpymodules/ai2obj.py
@@ -316,6 +316,8 @@ def ligne_fermee(l,n0,CP):
del courbes.ITEM[n0].beziers_knot[0]
return courbes,n0,CP
+def passe(l,n0,CP):
+ return courbes,n0,CP
Actions= { "C" : courbe_vers_c,
"c" : courbe_vers_c,
@@ -326,12 +328,14 @@ Actions= { "C" : courbe_vers_c,
"m" : mouvement_vers,
"l" : ligne_tracee_l,
"L" : ligne_tracee_l,
-
+ "F" : passe,
"f" : ligne_fermee,
+ "B" : passe,
"b" : ligne_fermee,
+ "S" : passe,
"s" : ligne_fermee,
-
"N" : ligne_fermee,
+ "n" : passe,
}
TAGcourbe=Actions.keys()
diff --git a/release/scripts/obj_export.py b/release/scripts/obj_export.py
index 8c52c28967e..205a280f878 100644
--- a/release/scripts/obj_export.py
+++ b/release/scripts/obj_export.py
@@ -21,7 +21,7 @@ Run this script from "File->Export" menu to export all meshes.
# --------------------------------------------------------------------------
-# OBJ Export v0.9 by Campbell Barton (AKA Ideasman)
+# OBJ Export v0.9b by Campbell Barton (AKA Ideasman)
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
@@ -63,6 +63,7 @@ def save_mtl(filename):
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('Ni %.6f\n' % mat.getIOR()) # Refraction index
file.write('d %.6f\n' % mat.getAlpha()) # Alpha (obj uses 'd' for dissolve)
# illum, 0 to disable lightng, 2 is normal.
@@ -80,7 +81,7 @@ def save_obj(filename):
save_mtl(mtlfilename)
file = open(filename, "w")
-
+
# Write Header
file.write('# Blender OBJ File: %s\n' % (Get('filename')))
file.write('# www.blender.org\n')
@@ -91,6 +92,8 @@ def save_obj(filename):
# Initialize totals, these are updated each object
totverts = totuvco = 0
+ globalUVCoords = {}
+
# Get all meshs
for ob in scn.getChildren():
if ob.getType() != 'Mesh':
@@ -100,7 +103,14 @@ def save_obj(filename):
if not m.faces: # Make sure there is somthing to write
continue #dont bother with this mesh.
-
+
+ faces = [ f for f in m.faces if len(f) > 2 ]
+ materials = m.materials
+
+ # Sort by Material so we dont over context switch in the obj file.
+ if len(materials) > 1:
+ faces.sort(lambda a,b: cmp(a.mat, b.mat))
+
# Set the default mat
currentMatName = NULL_MAT
currentImgName = NULL_IMG
@@ -112,24 +122,27 @@ def save_obj(filename):
file.write('v %.6f %.6f %.6f\n' % tuple(v.co))
# UV
- for f in m.faces:
- for uvIdx in range(len(f.v)):
- if f.uv:
- file.write('vt %.6f %.6f 0.0\n' % f.uv[uvIdx])
- else:
- file.write('vt 0.0 0.0 0.0\n')
-
+ if m.hasFaceUV():
+ for f in faces:
+ for uv in f.uv:
+ uvKey = '%.6f %.6f' % uv
+ try:
+ dummy = globalUVCoords[uvKey]
+ except KeyError:
+ totuvco +=1 # 1 based index.
+ globalUVCoords[uvKey] = totuvco
+ file.write('vt %s 0.0\n' % uvKey)
+
# NORMAL
- for f in m.faces:
- for v in f.v:
- file.write('vn %.6f %.6f %.6f\n' % tuple(v.no))
+ for v in m.verts:
+ file.write('vn %.6f %.6f %.6f\n' % tuple(v.no))
uvIdx = 0
- for f in m.faces:
+ for f in faces:
# Check material and change if needed.
- if len(m.materials) > f.mat:
- if currentMatName != m.materials[f.mat].getName():
- currentMatName = m.materials[f.mat].getName()
+ if len(materials) > 0:
+ if currentMatName != materials[f.mat].getName():
+ currentMatName = materials[f.mat].getName()
file.write('usemtl %s\n' % (currentMatName))
elif currentMatName != NULL_MAT:
@@ -146,19 +159,23 @@ def save_obj(filename):
elif currentImgName != NULL_IMG: # Not using an image so set to NULL_IMG
currentImgName = NULL_IMG
- # Set a new image for all following faces
+ # Set a ne w image for all following faces
file.write( 'usemap %s\n' % currentImgName) # No splitting needed.
-
- file.write('f ')
- for v in f.v:
- file.write( '%s/%s/%s ' % (v.index + totverts+1, uvIdx+totuvco+1, uvIdx+totuvco+1))
-
- uvIdx+=1
+
+ file.write('f')
+ if m.hasFaceUV():
+ for vi, v in enumerate(f.v):
+ uvIdx = globalUVCoords[ '%.6f %.6f' % f.uv[vi] ]
+ i = v.index + totverts + 1
+ file.write( ' %d/%d/%d' % (i, uvIdx, i)) # vert, uv, normal
+
+ else: # No UV's
+ for v in f.v:
+ file.write( ' %d' % (v.index + totverts+1))
file.write('\n')
# Make the indicies global rather then per mesh
totverts += len(m.verts)
- totuvco += uvIdx
file.close()
print "obj export time: %.2f" % (sys.time() - time1)
diff --git a/release/scripts/tex2uvbaker.py b/release/scripts/tex2uvbaker.py
index 326f852d53d..0d0f4dfe065 100644
--- a/release/scripts/tex2uvbaker.py
+++ b/release/scripts/tex2uvbaker.py
@@ -11,7 +11,7 @@ __author__ = "Jean-Michel Soler (jms)"
__url__ = ("blender", "elysiun",
"Official Page, http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_mesh3d2uv2d_en.htm",
"Communicate problems and errors, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender")
-__version__ = "0.2.6 2005/5/29"
+__version__ = "0.2.8 2005/7/20"
__bpydoc__ = """\
Texture Baker "bakes" Blender procedural materials (including textures): it saves them as 2d uv-mapped images.
@@ -37,7 +37,7 @@ Notes:<br>
"""
#---------------------------------------------
-# Last release : 0.2.6 , 2005/05/29 , 22h00
+# Last release : 0.2.8 , 2005/07/20 , 17h10
#---------------------------------------------
#---------------------------------------------
# (c) jm soler 07/2004 : 'Procedural Texture Baker'
@@ -47,6 +47,26 @@ Notes:<br>
#
# Released under Blender Artistic Licence
#
+# 0.2.8
+# -- added the forgotten image property in face
+# data. a little longer but better.
+# ( a remove double in the resulting mesh may be
+# useful .)
+# -- the data.update() function problem is
+# corrected too
+# -- no more layers problem . CAM and MESH are
+# localised in layer 20 . This layer is
+# the active one for the image rendering .
+# -- mesh creation is cleaner, loop in double was
+# removed and the abskey is set in frame 1
+# only . This solves an other deform problem .
+# -- if user does not want an autosaved image,
+# the "no replace" option leaves the render
+# window on the screen
+#
+# 0.2.7
+# -- minor correction on line 147: "!=-1" added
+#
# 0.2.6
# -- Creation of LAMP object is removed and replaced
# by the use of the shadeless option in material object
@@ -142,7 +162,7 @@ DIRNAME=Blender.Get('filename')
# the file name from the path name
#-----------------------------------
-if DIRNAME.find(os.sep):
+if DIRNAME.find(os.sep)!=-1:
k0=DIRNAME.split(os.sep)
else:
k0=DIRNAME.split('/')
@@ -178,6 +198,8 @@ LIMIT=0
XYLIMIT = [0.0, 0.0,1.0,1.0]
OBJPOS = 100.0
DEBUG=1
+RENDERLAYER=20
+SCENELAYERS=[]
helpmsg = """
Texture Baker:
@@ -234,7 +256,7 @@ def RenameImage(RDIR, MYDIR, FILENAME, name):
name = Draw.PupStrInput ('ReName Image, please :', name, 32)
RenameImage(RDIR, MYDIR, FILENAME, name)
-def SAVE_image (rc, name, FRAME):
+def SAVE_image (rc, name, FRAME, result):
"""
# ---------------------------
# Function SAVE_image
@@ -268,26 +290,25 @@ def SAVE_image (rc, name, FRAME):
rc.startFrame(NEWFRAME)
rc.endFrame(NEWFRAME)
rc.renderAnim()
- Blender.Scene.Render.CloseRenderWindow()
-
- FILENAME = "%04d" % NEWFRAME
- FILENAME = FILENAME.replace (' ', '0')
- FILENAME = RDIR + MYDIR + FILENAME + '.png'
-
- RenameImage(RDIR, MYDIR, FILENAME, name)
-
+ if result!=2 and not KEEPRENDERWINDOW:
+ Blender.Scene.Render.CloseRenderWindow()
+ FILENAME = "%04d" % NEWFRAME
+ FILENAME = FILENAME.replace (' ', '0')
+ FILENAME = RDIR + MYDIR + FILENAME + '.png'
+ RenameImage(RDIR, MYDIR, FILENAME, name)
+
rc.endFrame(OLDEFRAME)
rc.startFrame(OLDSFRAME)
rc.setRenderPath(RENDERDIR)
-def SHOOT (XYlimit, frame, obj, name, FRAME):
+def SHOOT (XYlimit, frame, obj, name, FRAME, result):
"""
# ---------------------------
# Function SHOOT
#
# IN : XYlimit list of 4 floats, smallest and biggest
# uvcoords
-# frame cureente frame
+# frame current frame
# obj for object location
# name image name
# FRAME the last animation's frame
@@ -305,6 +326,7 @@ def SHOOT (XYlimit, frame, obj, name, FRAME):
CAM, SC = GET_newobject('Camera','UVCAMERA')
CAM.link(Cam)
CAM.setName('UVCAMERA')
+ CAM.layers=[RENDERLAYER]
Cam.lens = 30
Cam.name = 'UVCamera'
@@ -333,13 +355,15 @@ def SHOOT (XYlimit, frame, obj, name, FRAME):
elif (tres) == 5: res = 2048
else: res = 512
+ SCENELAYERS=SC.layers
+ SC.layers = [20]
context.imageSizeY(res)
context.imageSizeX(res)
- SAVE_image (context, name, FRAME)
+ SAVE_image (context, name, FRAME, result)
context.imageSizeY(OLDy)
context.imageSizeX(OLDx)
-
- if Camold :SC.setCurrentCamera(Camold)
+ SC.layers = SCENELAYERS
+ if Camold : SC.setCurrentCamera(Camold)
Blender.Set ('curframe', frame)
@@ -393,6 +417,8 @@ def Mesh2UVCoord (LIMIT):
# OUT: nothing
# ---------------------------
"""
+ global PUTRAW, FRAME, SCENELAYERS
+
try:
MESH3D = Object.GetSelected()[0]
if MESH3D.getType() == 'Mesh':
@@ -401,18 +427,21 @@ def Mesh2UVCoord (LIMIT):
try:
NewOBJECT=Blender.Object.Get('UVOBJECT')
CurSCENE=Blender.Scene.getCurrent()
- MESH2 = NewOBJECT.getData()
-
except:
NewOBJECT, CurSCENE = GET_newobject('Mesh','UVOBJECT')
- MESH2 = Blender.NMesh.GetRaw()
+ MESH2 = NewOBJECT.getData()
+ NewOBJECT.layers=[RENDERLAYER]
MESH2.faces=[]
for f in MESH.faces:
f1 = Blender.NMesh.Face()
-
for v in f.v:
- v1 = Blender.NMesh.Vert (v.co[0], v.co[1], v.co[2])
+ v1 = Blender.NMesh.Vert (0.0, 0.0, 0.0)
+ for n in [0,1]:
+ v1.co[n] = f.uv[f.v.index(v)][n]
+ exec "if v1.co[%s] > XYLIMIT[%s]: XYLIMIT[%s] = v1.co[%s]" % (n, n+2, n+2, n)
+ exec "if v1.co[%s] < XYLIMIT[%s]: XYLIMIT[%s] = v1.co[%s]" % (n, n, n, n)
+ v1.co[2] = 0.0
MESH2.verts.append(v1)
f1.v.append(MESH2.verts[len(MESH2.verts) - 1])
@@ -423,32 +452,23 @@ def Mesh2UVCoord (LIMIT):
f1.mode = f.mode
f1.flag = f.flag
f1.mat = f.mat
+ #-----------------------------------
+ # release : 0.2.8 , 2005/07/19 , end
+ #-----------------------------------
+ try:
+ f1.image=f.image
+ except :
+ pass
MESH2.materials = MESH.materials[:]
-
NewOBJECT.setLocation (OBJPOS, OBJPOS, 0.0)
NewOBJECT.setEuler (0.0, 0.0, 0.0)
MESH2.removeAllKeys()
-
MESH2.update()
MESH2.insertKey (1, 'absolute')
MESH2.update()
- for f in MESH2.faces:
- for v in f.v:
- for n in [0,1]:
- v.co[n] = f.uv[f.v.index(v)][n]
- exec "if v.co[%s] > XYLIMIT[%s]: XYLIMIT[%s] = v.co[%s]" % (n, n+2, n+2, n)
- exec "if v.co[%s] < XYLIMIT[%s]: XYLIMIT[%s] = v.co[%s]" % (n, n, n, n)
- v.co[2] = 0.0
-
- if DEBUG: print XYLIMIT
-
- MESH2.update()
- MESH2.insertKey (FRAME, 'absolute')
- MESH2.update()
-
imagename = 'uvtext'
name = "CHANGE IMAGE NAME ? %t | Replace it | No replacing | Script help"
@@ -467,9 +487,9 @@ def Mesh2UVCoord (LIMIT):
#-----------------------------------
if LIMIT :
- SHOOT(XYLIMIT, FRAME, NewOBJECT, imagename, FRAME)
+ SHOOT(XYLIMIT, FRAME, NewOBJECT, imagename, FRAME,result)
else :
- SHOOT([0.0,0.0,1.0,1.0], FRAME, NewOBJECT, imagename, FRAME)
+ SHOOT([0.0,0.0,1.0,1.0], FRAME, NewOBJECT, imagename, FRAME, result)
#-----------------------------------
# release : 0.2.6, 2005/05/29 , 00h00
#-----------------------------------