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:
authorCampbell Barton <ideasman42@gmail.com>2007-01-04 23:44:33 +0300
committerCampbell Barton <ideasman42@gmail.com>2007-01-04 23:44:33 +0300
commitd26d0e288980a10d3f90fb9d945d205bdda7cb77 (patch)
tree5f5a1a0e08478d287d6e185e169031639aef8929 /release
parenteb424ec18d0b937bc720de633b1e2e18b5e15d76 (diff)
Update to JMSs scripts fixed bug 5419.
Optimized 3ds_export.py newstyle classes and fixed an error where objects with no material would fail to export.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/3ds_export.py134
-rw-r--r--release/scripts/tex2uvbaker.py668
-rw-r--r--release/scripts/uvpaint.py52
3 files changed, 435 insertions, 419 deletions
diff --git a/release/scripts/3ds_export.py b/release/scripts/3ds_export.py
index 7911a4b4277..9e5605575f0 100644
--- a/release/scripts/3ds_export.py
+++ b/release/scripts/3ds_export.py
@@ -129,11 +129,10 @@ SZ_SHORT = 2
SZ_INT = 4
SZ_FLOAT = 4
-class _3ds_short:
+class _3ds_short(object):
'''Class representing a short (2-byte integer) for a 3ds file.
*** This looks like an unsigned short H is unsigned from the struct docs - Cam***'''
- value=0
-
+ __slots__ = 'value'
def __init__(self, val=0):
self.value=val
@@ -141,16 +140,14 @@ class _3ds_short:
return SZ_SHORT
def write(self,file):
- data=struct.pack("<H", self.value)
- file.write(data)
+ file.write(struct.pack("<H", self.value))
def __str__(self):
return str(self.value)
-class _3ds_int:
+class _3ds_int(object):
'''Class representing an int (4-byte integer) for a 3ds file.'''
- value=0
-
+ __slots__ = 'value'
def __init__(self, val=0):
self.value=val
@@ -158,16 +155,14 @@ class _3ds_int:
return SZ_INT
def write(self,file):
- data=struct.pack("<I", self.value)
- file.write(data)
+ file.write(struct.pack("<I", self.value))
def __str__(self):
return str(self.value)
-class _3ds_float:
+class _3ds_float(object):
'''Class representing a 4-byte IEEE floating point number for a 3ds file.'''
- value=0.0
-
+ __slots__ = 'value'
def __init__(self, val=0.0):
self.value=val
@@ -175,18 +170,15 @@ class _3ds_float:
return SZ_FLOAT
def write(self,file):
- data=struct.pack("<f", self.value)
- file.write(data)
-
+ file.write(struct.pack("<f", self.value))
def __str__(self):
return str(self.value)
-class _3ds_string:
+class _3ds_string(object):
'''Class representing a zero-terminated string for a 3ds file.'''
- value=""
-
+ __slots__ = 'value'
def __init__(self, val=""):
self.value=val
@@ -195,17 +187,15 @@ class _3ds_string:
def write(self,file):
binary_format = "<%ds" % (len(self.value)+1)
- data=struct.pack(binary_format, self.value)
- file.write(data)
+ file.write(struct.pack(binary_format, self.value))
def __str__(self):
return self.value
-class _3ds_point_3d:
+class _3ds_point_3d(object):
'''Class representing a three-dimensional point for a 3ds file.'''
- x=y=z=0.0
-
+ __slots__ = 'x','y','z'
def __init__(self, point=(0.0,0.0,0.0)):
self.x, self.y, self.z = point
@@ -213,16 +203,14 @@ class _3ds_point_3d:
return 3*SZ_FLOAT
def write(self,file):
- data=struct.pack('<3f', self.x, self.y, self.z)
- file.write(data)
+ file.write(struct.pack('<3f', self.x, self.y, self.z))
def __str__(self):
return '(%f, %f, %f)' % (self.x, self.y, self.z)
-class _3ds_point_4d:
+class _3ds_point_4d(object):
'''Class representing a four-dimensional point for a 3ds file, for instance a quaternion.'''
- x=y=z=w=0.0
-
+ __slots__ = 'x','y','z','w'
def __init__(self, point=(0.0,0.0,0.0,0.0)):
self.x, self.y, self.z, self.w = point
@@ -236,10 +224,9 @@ class _3ds_point_4d:
def __str__(self):
return '(%f, %f, %f, %f)' % (self.x, self.y, self.z, self.w)
-class _3ds_point_uv:
+class _3ds_point_uv(object):
'''Class representing a UV-coordinate for a 3ds file.'''
- uv=(0.0, 0.0)
-
+ __slots__ = 'uv'
def __init__(self, point=(0.0,0.0)):
self.uv = point
@@ -256,10 +243,9 @@ class _3ds_point_uv:
def __str__(self):
return '(%g, %g)' % self.uv
-class _3ds_rgb_color:
+class _3ds_rgb_color(object):
'''Class representing a (24-bit) rgb color for a 3ds file.'''
- r=g=b=0
-
+ __slots__ = 'r','g','b'
def __init__(self, col=(0,0,0)):
self.r, self.g, self.b = col
@@ -267,19 +253,14 @@ class _3ds_rgb_color:
return 3
def write(self,file):
- file.write( struct.pack('<c', chr(int(255*self.r))) )
- file.write( struct.pack('<c', chr(int(255*self.g))) )
- file.write( struct.pack('<c', chr(int(255*self.b))) )
+ file.write( struct.pack('<3c', chr(int(255*self.r)), chr(int(255*self.g)), chr(int(255*self.b)) ) )
def __str__(self):
return '{%f, %f, %f}' % (self.r, self.g, self.b)
-class _3ds_face:
+class _3ds_face(object):
'''Class representing a face for a 3ds file.'''
-
- # vertex index tuple:
- vindex=(0,0,0)
-
+ __slots__ = 'vindex'
def __init__(self, vindex):
self.vindex = vindex
@@ -288,20 +269,17 @@ class _3ds_face:
def write(self,file):
# The last zero is only used by 3d studio
- data=struct.pack("<4H", self.vindex[0],self.vindex[1], self.vindex[2], 0)
- file.write(data)
+ file.write(struct.pack("<4H", self.vindex[0],self.vindex[1], self.vindex[2], 0))
def __str__(self):
return '[%d %d %d]' % (self.vindex[0],self.vindex[1], self.vindex[2])
-class _3ds_array:
+class _3ds_array(object):
'''Class representing an array of variables for a 3ds file.
Consists of a _3ds_short to indicate the number of items, followed by the items themselves.
'''
- values=[]
- size=0
-
+ __slots__ = 'values', 'size'
def __init__(self):
self.values=[]
self.size=SZ_SHORT
@@ -325,12 +303,10 @@ class _3ds_array:
def __str__(self):
return '(%d items)' % len(self.values)
-class _3ds_named_variable:
+class _3ds_named_variable(object):
'''Convenience class for named variables.'''
- name=""
- value=None
-
+ __slots__ = 'value', 'name'
def __init__(self, name, val=None):
self.name=name
self.value=val
@@ -357,21 +333,12 @@ class _3ds_named_variable:
#the chunk class
-class _3ds_chunk:
+class _3ds_chunk(object):
'''Class representing a chunk in a 3ds file.
Chunks contain zero or more variables, followed by zero or more subchunks.
'''
-
- # The chunk ID:
- ID=_3ds_short()
- # The total chunk size (including the size of the chunk ID and chunk size!):
- size=_3ds_int()
- # Variables:
- variables=[]
- # Sub chunks:
- subchunks=[]
-
+ __slots__ = 'ID', 'size', 'variables', 'subchunks'
def __init__(self, id=0):
self.ID=_3ds_short(id)
self.size=_3ds_int(0)
@@ -507,18 +474,12 @@ def make_material_chunk(material, image):
return material_chunk
-class tri_wrapper:
+class tri_wrapper(object):
'''Class representing a triangle.
Used when converting faces to triangles'''
- # vertex indices:
- vertex_index=(0,0,0)
- # material index:
- mat_index=None
- # uv coordinates (used on blender faces that have face-uv)
- faceuvs=None
-
+ __slots__ = 'vertex_index', 'mat', 'image', 'faceuvs', 'offset'
def __init__(self, vindex=(0,0,0), mat=None, image=None, faceuvs=None):
self.vertex_index= vindex
self.mat= mat
@@ -618,9 +579,12 @@ def remove_face_uv(verts, tri_list):
index_list = []
for i,vert in enumerate(verts):
index_list.append(vert_index)
+
+ pt = _3ds_point_3d(vert.co) # reuse, should be ok
+
for ii, uv_3ds in unique_uvs[i].itervalues():
# add a vertex duplicate to the vertex_array for every uv associated with this vertex:
- vert_array.add(_3ds_point_3d(vert.co))
+ vert_array.add(pt)
# add the uv coordinate to the uv array:
uv_array.add(uv_3ds)
vert_index += len(unique_uvs[i])
@@ -639,6 +603,8 @@ def make_faces_chunk(tri_list, mesh, materialDict):
Also adds subchunks assigning materials to all faces.'''
materials = mesh.materials
+ if not materials:
+ mat = None
face_chunk = _3ds_chunk(OBJECT_FACES)
face_list = _3ds_array()
@@ -651,10 +617,9 @@ def make_faces_chunk(tri_list, mesh, materialDict):
face_list.add(_3ds_face(tri.vertex_index))
- # obj_material_faces[tri.mat].add(_3ds_short(i))
-
- mat = materials[tri.mat]
- if mat: mat = mat.name
+ if materials:
+ mat = materials[tri.mat]
+ if mat: mat = mat.name
img = tri.image
@@ -914,10 +879,16 @@ def save_3ds(filename):
# get material/image tuples.
if data.faceUV:
mat_ls = data.materials
+
+ if not mat_ls:
+ mat = mat_name = None
+
for f in data.faces:
- mat = mat_ls[f.mat]
- if mat: mat_name = mat.name
- else: mat_name = None
+ if mat_ls:
+ mat = mat_ls[f.mat]
+ if mat: mat_name = mat.name
+ else: mat_name = None
+ # else there alredy set to none
img = f.image
if img: img_name = img.name
@@ -929,9 +900,6 @@ def save_3ds(filename):
materialDict[mat_name, img_name]
except:
materialDict[mat_name, img_name]= mat, img
-
-
-
else:
for mat in data.materials:
diff --git a/release/scripts/tex2uvbaker.py b/release/scripts/tex2uvbaker.py
index 1ccc22859a4..a54086144f8 100644
--- a/release/scripts/tex2uvbaker.py
+++ b/release/scripts/tex2uvbaker.py
@@ -1,7 +1,7 @@
#!BPY
""" Registration info for Blender menus:
-Name: 'Texture Baker'
+Name: 'UV Texture Baker'
Blender: 239
Group: 'UV'
Tooltip: 'Procedural to uvmapped texture baker'
@@ -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.3.2 2005/12/28"
+__version__ = "0.3.3 2005/09/10"
__bpydoc__ = """\
This script "bakes" Blender procedural materials (including textures): it saves
@@ -28,7 +28,7 @@ a) Enter face mode and define uv coordinates for your mesh;<br>
b) Define its materials and textures ;
c) Run this script and check the console.
-Global variables
+Global variables print
a) FRAME integer, the last frame of the animation, autodocumented .
b) LIMIT integer, 0 or 1, uvcoords may exceed limits 0.0 to 1.0 , this variable
@@ -39,7 +39,7 @@ Notes:<br>
"""
#---------------------------------------------
-# Last release : 0.3.1 , 2005/10/21 , 20h23
+# Last release : 0.3.3 , 2006/09/10 , 15h20
#---------------------------------------------
#---------------------------------------------
# (c) jm soler 07/2004 : 'Procedural Texture Baker'
@@ -49,6 +49,10 @@ Notes:<br>
#
# Released under Blender Artistic Licence
#
+# 0.3.3
+# blender 2.40 update to deal with the object module refactory
+# some probleme with the relatif render directory
+#
# 0.3.2
# blender 2.40 update to deal with the new shape
# key system .
@@ -161,13 +165,13 @@ from Blender import NMesh, Draw, Object, Scene, Camera
# poses a problem when the memory is too much encumbered
#-----------------------------------
try:
- import nt
- os = nt
- os.sep='\\'
+ import nt
+ os = nt
+ os.sep='\\'
except:
- import posix
- os = posix
- os.sep='/'
+ import posix
+ os = posix
+ os.sep='/'
DIRNAME=Blender.Get('filename')
#-----------------------------------
# decoupage de la chaine en fragment
@@ -179,9 +183,9 @@ DIRNAME=Blender.Get('filename')
#-----------------------------------
if DIRNAME.find(os.sep)!=-1:
- k0=DIRNAME.split(os.sep)
+ k0=DIRNAME.split(os.sep)
else:
- k0=DIRNAME.split('/')
+ k0=DIRNAME.split('/')
DIRNAME=DIRNAME.replace(k0[-1],'')
#-----------------------------------
# Last release : 0.2.5 , 2005/05/22 , end
@@ -217,7 +221,24 @@ DEBUG=1
RENDERLAYER=20
SCENELAYERS=[]
-
+BLOCK={'limit': [Blender.Draw.Create(0),""],
+ 'ObjPos' : [Blender.Draw.Create(100.0),""],
+ 'RenderLayer' : [Blender.Draw.Create(20),""],
+ 'DisplayRes' : [Blender.Draw.Create(1024),""],
+ 'ImageName' : [Blender.Draw.Create("uvtext"),""],
+ 'NoReplaceImag' : [Blender.Draw.Create(0),""],
+ 'RemoveMorphMesh' : [Blender.Draw.Create(0),""],
+ 'RemoveShootCamera' : [Blender.Draw.Create(0),""],
+ 'Debug' : [Blender.Draw.Create(0),""]}
+
+block = []
+block.append(("limit",BLOCK['limit'][0],""))
+block.append(("Obj Pos :",BLOCK['ObjPos'][0], 0.0, 1000.0))
+block.append(("Render Layer :",BLOCK['RenderLayer'][0],1, 20))
+block.append(("Display Res :",BLOCK['DisplayRes'][0],16, 4096))
+block.append(("Replace Img Name",BLOCK['NoReplaceImag'][0],""))
+block.append(("Remove Morph Mesh",BLOCK['RemoveMorphMesh'][0],""))
+block.append(("Remove Shoot Camera",BLOCK['RemoveShootCamera'][0],""))
helpmsg = """
Texture Baker:
@@ -236,7 +257,7 @@ Basic instructions:
"""
def GET_newobject (TYPE,NAME):
- """
+ """
# ---------------------------
# Function GET_newobject
#
@@ -246,14 +267,14 @@ def GET_newobject (TYPE,NAME):
# SCENE Blender current scene object
# ---------------------------
Return and object and the current scene
- """
- SCENE = Blender.Scene.getCurrent()
- OBJECT = Blender.Object.New(TYPE,NAME)
- SCENE.link(OBJECT)
- return OBJECT, SCENE
+ """
+ SCENE = Blender.Scene.getCurrent()
+ OBJECT = Blender.Object.New(TYPE,NAME)
+ SCENE.link(OBJECT)
+ return OBJECT, SCENE
def RenameImage(RDIR, MYDIR, FILENAME, name):
- """
+ """
# ---------------------------
# Function RenameImage
#
@@ -265,18 +286,18 @@ def RenameImage(RDIR, MYDIR, FILENAME, name):
# ---------------------------
Rename the file pointed by the string name
recall the function if the file yet exists
- """
- newfname = RDIR + MYDIR + name
- if newfname.find('.png', -4) < 0 : newfname += '.png'
-
- if not Blender.sys.exists(newfname):
- os.rename(FILENAME, newfname)
- else:
- name = Draw.PupStrInput ('ReName Image, please :', name, 32)
- RenameImage(RDIR, MYDIR, FILENAME, name)
+ """
+ newfname = RDIR + MYDIR + name
+ if newfname.find('.png', -4) < 0 : newfname += '.png'
+
+ if not Blender.sys.exists(newfname):
+ os.rename(FILENAME, newfname)
+ else:
+ name = Draw.PupStrInput ('ReName Image, please :', name, 32)
+ RenameImage(RDIR, MYDIR, FILENAME, name)
def SAVE_image (rc, name, FRAME, result):
- """
+ """
# ---------------------------
# Function SAVE_image
#
@@ -285,43 +306,50 @@ def SAVE_image (rc, name, FRAME, result):
# FRAME integer, last numbre of the curent animation
# OUT: nothing
# ---------------------------
- """
- rc.enableExtensions(1)
- MYDIR = ''
- RENDERDIR = rc.getRenderPath().replace('\\','/')
- if RENDERDIR.find('//')==0 :
- print 'filename', Blender.Get('filename'),'/n', Blender.sys.dirname(Blender.Get('filename'))
- RDIR=RENDERDIR.replace('//',DIRNAME)
- else:
- RDIR=RENDERDIR[:]
- if DEBUG : print 'RDIR : ', RDIR
-
- HOMEDIR=Blender.Get('homedir')
- if DEBUG : print 'HOMEDIR', HOMEDIR
- rc.setRenderPath(RENDERDIR + MYDIR)
- if DEBUG : print "Render folder:", RENDERDIR + MYDIR
- IMAGETYPE = Blender.Scene.Render.PNG
- if DEBUG : print 'IMAGETYPE : ',IMAGETYPE
- rc.setImageType(IMAGETYPE)
- NEWFRAME = FRAME
- OLDEFRAME = rc.endFrame()
- OLDSFRAME = rc.startFrame()
- rc.startFrame(NEWFRAME)
- rc.endFrame(NEWFRAME)
- rc.renderAnim()
- if result!=2 :
- 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)
+ """
+ rc.enableExtensions(1)
+ MYDIR = ''
+ RENDERDIR = rc.getRenderPath()
+ if RENDERDIR.find('//')==0 :
+ print 'filename', Blender.Get('filename'),'/n', Blender.sys.dirname(Blender.Get('filename'))
+ RDIR=RENDERDIR.replace('//',DIRNAME)
+ elif len(RENDERDIR)==1 and RENDERDIR.find('/')==0:
+ print 'filename', Blender.Get('filename'),'/n', Blender.sys.dirname(Blender.Get('filename'))
+ RDIR=RENDERDIR.replace('/',DIRNAME)
+ print 'RDIR=',RDIR
+
+ else:
+ RDIR=RENDERDIR[:]
+
+ RDIR = RDIR.replace('\\','/')
+ if DEBUG : print 'RDIR : ', RDIR
+
+ HOMEDIR=Blender.Get('homedir')
+ if DEBUG : print 'HOMEDIR', HOMEDIR
+ rc.setRenderPath(RDIR + MYDIR)
+ if DEBUG : print "Render folder:", RDIR + MYDIR
+ IMAGETYPE = Blender.Scene.Render.PNG
+ if DEBUG : print 'IMAGETYPE : ',IMAGETYPE
+ rc.setImageType(IMAGETYPE)
+ NEWFRAME = FRAME
+ OLDEFRAME = rc.endFrame()
+ OLDSFRAME = rc.startFrame()
+ rc.startFrame(NEWFRAME)
+ rc.endFrame(NEWFRAME)
+ rc.renderAnim()
+ if result==1 :
+ 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(RDIR)
def SHOOT (XYlimit, frame, obj, name, FRAME, result):
- """
+ """
# ---------------------------
# Function SHOOT
#
@@ -334,86 +362,75 @@ def SHOOT (XYlimit, frame, obj, name, FRAME, result):
# OUT: nothing
# ---------------------------
render and save the baked textures picture
- """
- try:
- CAM = Blender.Object.Get('UVCAMERA')
- Cam = CAM.getData()
- SC = Blender.Scene.getCurrent()
- except:
- Cam = Blender.Camera.New()
- Cam.name = 'UVCamera'
- CAM, SC = GET_newobject('Camera','UVCAMERA')
- CAM.link(Cam)
- CAM.setName('UVCAMERA')
- CAM.layers=[RENDERLAYER]
- Cam.lens = 30
- Cam.name = 'UVCamera'
-
- Cam.setType('ortho')
- Cam.setScale(1.0)
-
- CAM.setLocation(obj.getLocation())
- CAM.LocX += XYlimit[2] * 0.500
- CAM.LocY += XYlimit[3] * 0.500
- CAM.LocZ += max (XYlimit[2], XYlimit[3])
- CAM.setEuler (0.0, 0.0, 0.0)
-
- context = SC.getRenderingContext()
- Camold = SC.getCurrentCamera()
- SC.setCurrentCamera(CAM)
-
- OLDy = context.imageSizeY()
- OLDx = context.imageSizeX()
-
- TAILLEIMAGE='TEXTURE OUT RESOLUTION : %t |'
- TAILLEIMAGE+='256 %x1 |'
- TAILLEIMAGE+='512 %x2 |'
- TAILLEIMAGE+='768 %x3 |'
- TAILLEIMAGE+='1024 %x4 |'
- TAILLEIMAGE+='2048 %x5 '
- #TAILLEIMAGE+='| 4096 %x6 '
- tres = Draw.PupMenu(TAILLEIMAGE)
-
- if (tres) == 1: res = 256
- elif (tres) == 2: res = 512
- elif (tres) == 3: res = 768
- elif (tres) == 4: res = 1024
- elif (tres) == 5: res = 2048
- # elif (tres) == 6: res = 4096
- else: res = 512
- #...
-
-
- SCENELAYERS=SC.layers
- SC.layers = [20]
- context.imageSizeY(res)
- context.imageSizeX(res)
- SAVE_image (context, name, FRAME, result)
- context.imageSizeY(OLDy)
- context.imageSizeX(OLDx)
- SC.layers = SCENELAYERS
- if Camold : SC.setCurrentCamera(Camold)
-
- Blender.Set ('curframe', frame)
+ """
+ global BLOCK
+ #----------------------------------------------
+ # Create the object CAM only if it does not
+ # exist already . Get the current scene in the
+ # same time .
+ #----------------------------------------------
+ try:
+ CAM = Blender.Object.Get('UVCAMERA')
+ Cam = CAM.getData()
+ SC = Blender.Scene.getCurrent()
+ except:
+ Cam = Blender.Camera.New()
+ Cam.name = 'UVCamera'
+ CAM, SC = GET_newobject('Camera','UVCAMERA')
+ CAM.link(Cam)
+ CAM.setName('UVCAMERA')
+ CAM.layers=[RENDERLAYER]
+ Cam.lens = 30
+ Cam.name = 'UVCamera'
+ Cam.setType('ortho')
+ Cam.setScale(1.0)
+ CAM.setLocation(obj.getLocation())
+ CAM.LocX += XYlimit[2] * 0.500
+ CAM.LocY += XYlimit[3] * 0.500
+ CAM.LocZ += max (XYlimit[2], XYlimit[3])
+ CAM.RotX=0.0 #setEuler ((0.0, 0.0, 0.0))
+ CAM.RotY=0.0
+ CAM.RotZ=0.0
+ context = SC.getRenderingContext()
+ Camold = SC.getCurrentCamera()
+ SC.setCurrentCamera(CAM)
+ OLDy = context.imageSizeY()
+ OLDx = context.imageSizeX()
+ res=BLOCK['DisplayRes'][0].val
+ SCENELAYERS=SC.layers
+ SC.layers = [20]
+
+ Blender.Window.EditMode(1)
+ Blender.Window.EditMode(0)
+
+ context.imageSizeY(res)
+ context.imageSizeX(res)
+ SAVE_image (context, name, FRAME, result)
+ context.imageSizeY(OLDy)
+ context.imageSizeX(OLDx)
+ SC.layers = SCENELAYERS
+ if Camold : SC.setCurrentCamera(Camold)
+
+ Blender.Set ('curframe', frame)
#-----------------------------------
# release : 0.2.6 , 2005/05/29 , 00h00
#-----------------------------------
def PROV_Shadeless(MATList):
- """
+ """
# ---------------------------
# Function PROV_Shadeless
#
# IN : MATList a list of the mesh's materials
# OUT: SHADEDict a dictionnary of the materials' shadeles value
# ---------------------------
- """
- SHADEDict={}
- for mat in MATList:
- SHADEDict[mat.name]=mat.mode
- mat.mode |= Blender.Material.Modes.SHADELESS
- return SHADEDict
+ """
+ SHADEDict={}
+ for mat in MATList:
+ SHADEDict[mat.name]=mat.mode
+ mat.mode |= Blender.Material.Modes.SHADELESS
+ return SHADEDict
#-----------------------------------
# Last release : 0.2.6 , 2005/05/29 , end
#-----------------------------------
@@ -422,17 +439,17 @@ def PROV_Shadeless(MATList):
# release : 0.2.6 , 2005/05/29 , 00h00
#-----------------------------------
def REST_Shadeless(SHADEDict):
- """
+ """
# ---------------------------
# Function REST_Shadeless
#
# IN : SHADEDict a dictionnary of the materials' shadeles value
# OUT : nothing
# ---------------------------
- """
- for m in SHADEDict.keys():
- mat=Blender.Material.Get(m)
- mat.mode=SHADEDict[m]
+"""
+ for m in SHADEDict.keys():
+ mat=Blender.Material.Get(m)
+ mat.mode=SHADEDict[m]
#-----------------------------------
# release : 0.2.6 , 2005/05/29 , end
#-----------------------------------
@@ -442,7 +459,7 @@ def REST_Shadeless(SHADEDict):
# release : 0.3.2 , 2005/12/28 , 13h00
#-----------------------------------
def Blender240update(MESH2,FRAME):
- """
+ """
# ---------------------------
# Function Blender240update
#
@@ -454,192 +471,213 @@ def Blender240update(MESH2,FRAME):
#
# OUT : nothing
# ---------------------------
- """
- # ---------------------------
- # recuperation des clef de morphing pour ce mesh
- # ---------------------------
- key = MESH2.getKey()
- # ---------------------------
- # recuperation de l'Ipo
- # ---------------------------
- ipo = key.ipo
- # ---------------------------
- # si l'ipo n'existe pas on la cree
- # ---------------------------
- if ipo == None:
- noipo = Blender.Ipo.New("Key","keyipo")
- key.ipo = noipo
- # ---------------------------
- # raccourci de l'expression
- # ---------------------------
- ipo = key.ipo
- # ---------------------------
- # identification de la clef de morphing
- # ---------------------------
- keyidentity = "Key 1"
- # ---------------------------
- # recuperation de la courbe correspondante
- # c'est toujours la courbe 0
- # ---------------------------
- ipocurve = ipo.getCurve(0)
- # ---------------------------
- # si la courbe n'existe pas (normalement, elle n'existe pas mais
- # on gère le risque pour faciliter une eventuelle récupération de
- # cette fonction dans un autre script ou pour les cas , certe peu
- # probable, ou blender viendrait a etre modifie pour les ajouter
- # automatiquement ) on la cree ...
- # ---------------------------
- if ipocurve == None:
- ipocurve = ipo.addCurve(keyidentity)
- # ---------------------------
- # On applique l'attribut d'inetrpolation qui permet d'avoir
- # une ligne droite
- # ---------------------------
- ipocurve.setInterpolation("Linear")
- # ---------------------------
- # On retire tous les sommets qui pourraient se trouver sur la
- # courbe (dans l'état actuel, cette opération est une sécurité
- # superflue ) .
- # ---------------------------
- while len(ipocurve.getPoints()) > 0:
- ipocurve.delBezier(0)
- ipocurve.recalc()
- # ---------------------------
- # On ajouter les sommets necessaires ...
- # ---------------------------
- ipocurve.append((-1,1))
- # ---------------------------
- # ... ce dernire n'est peut-être pas absolument obligatoire .
- # ---------------------------
- ipocurve.append((FRAME+1,1))
+"""
+ # ---------------------------
+ # recuperation des clef de morphing pour ce mesh
+ # ---------------------------
+ key = MESH2.getKey()
+ # ---------------------------
+ # recuperation de l'Ipo
+ # ---------------------------
+ ipo = key.ipo
+ # ---------------------------
+ # si l'ipo n'existe pas on la cree
+ # ---------------------------
+ if ipo == None:
+ noipo = Blender.Ipo.New("Key","keyipo")
+ key.ipo = noipo
+ # ---------------------------
+ # raccourci de l'expression
+ # ---------------------------
+ ipo = key.ipo
+ # ---------------------------
+ # identification de la clef de morphing
+ # ---------------------------
+ keyidentity = "Key 1"
+ # ---------------------------
+ # recuperation de la courbe correspondante
+ # c'est toujours la courbe 0
+ # ---------------------------
+ ipocurve = ipo.getCurve(0)
+ # ---------------------------
+ # si la courbe n'existe pas (normalement, elle n'existe pas mais
+ # on gère le risque pour faciliter une eventuelle récupération de
+ # cette fonction dans un autre script ou pour les cas , certe peu
+ # probable, ou blender viendrait a etre modifie pour les ajouter
+ # automatiquement ) on la cree ...
+ # ---------------------------
+ if ipocurve == None:
+ ipocurve = ipo.addCurve(keyidentity)
+ # ---------------------------
+ # On applique l'attribut d'inetrpolation qui permet d'avoir
+ # une ligne droite
+ # ---------------------------
+ ipocurve.setInterpolation("Linear")
+ # ---------------------------
+ # On retire tous les sommets qui pourraient se trouver sur la
+ # courbe (dans l'état actuel, cette opération est une sécurité
+ # superflue ) .
+ # ---------------------------
+ while len(ipocurve.getPoints()) > 0:
+ ipocurve.delBezier(0)
+ ipocurve.recalc()
+ # ---------------------------
+ # On ajouter les sommets necessaires ...
+ # ---------------------------
+ ipocurve.addBezier((-1,1))
+ # ---------------------------
+ # ... ce dernire n'est peut-être pas absolument obligatoire .
+ # ---------------------------
+ ipocurve.addBezier((FRAME+1,1))
#-----------------------------------
# release : 0.3.2 , 2005/12/28 , end
#-----------------------------------
def Mesh2UVCoord (LIMIT):
- """
+ """
# ---------------------------
# Function Mesh2UVCoord
#
# IN : LIMIT integer, create or not a new framing for uvcoords
# OUT: nothing
# ---------------------------
- """
- global PUTRAW, FRAME, SCENELAYERS
-
- try:
- MESH3D = Object.GetSelected()[0]
- if MESH3D.getType() == 'Mesh':
- MESH = MESH3D.getData()
-
- try:
- NewOBJECT=Blender.Object.Get('UVOBJECT')
- CurSCENE=Blender.Scene.getCurrent()
- except:
- NewOBJECT, CurSCENE = GET_newobject('Mesh','UVOBJECT')
- MESH2 = NewOBJECT.getData()
- MESH2.edges=[]
- 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])
- MESH2.verts.append(v1)
- f1.v.append(MESH2.verts[len(MESH2.verts) - 1])
-
- MESH2.faces.append(f1)
- f1.uv = f.uv[:]
- f1.col = f.col[:]
- f1.smooth = f.smooth
- 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
-
- print XYLIMIT
-
- MESH2.update()
- MESH2.insertKey (FRAME, 'absolute')
- MESH2.update()
-
- #-----------------------------------
- # release : 0.3.2 , 2005/12/28 , 13h00
- #-----------------------------------
- Blender240update(MESH2,FRAME)
- #-----------------------------------
- # release : 0.3.2 , 2005/12/28 , end
- #-----------------------------------
-
- imagename = 'uvtext'
-
- name = "CHANGE IMAGE NAME ? %t | Replace it | No replace | Script help"
- result = Draw.PupMenu(name)
-
- if result == 1:
- imagename = Draw.PupStrInput ('Image Name:', imagename, 32)
-
- if result != 3:
- #-----------------------------------
- # release : 0.2.6 , 2005/05/29 , 00h00
- #-----------------------------------
- SHADEDict=PROV_Shadeless(MESH2.materials)
- #-----------------------------------
- # release : 0.2.6 , 2005/05/29 , end
- #-----------------------------------
-
- if LIMIT :
- SHOOT(XYLIMIT, FRAME, NewOBJECT, imagename, FRAME,result)
- else :
- SHOOT([0.0,0.0,1.0,1.0], FRAME, NewOBJECT, imagename, FRAME, result)
- #-----------------------------------
- # release : 0.2.6, 2005/05/29 , 00h00
- #-----------------------------------
- REST_Shadeless(SHADEDict)
- #-----------------------------------
- # release : 0.2.6 , 2005/05/29 , end
- #-----------------------------------
-
- Blender.Redraw()
-
- else:
- Draw.PupMenu("Ready%t|Please check console for instructions")
- print helpmsg
-
- else:
- name = "Error%t|Active object is not a mesh or has no UV coordinates"
- result = Draw.PupMenu(name)
- print 'problem : no object selected or not mesh'
-
- except:
- name = "Error%t|Active object is not a mesh or has no UV coordinates"
- result = Draw.PupMenu(name)
- print 'problem : no object selected or not mesh'
+ """
+ global PUTRAW, FRAME, SCENELAYERS, BLOCK, block
+ if Object.GetSelected() and Object.GetSelected()[0].getType()=='Mesh':
+
+ retval = Blender.Draw.PupBlock("PupBlock test", block)
+
+ if retval==1 :
+ LIMIT = BLOCK['limit'][0].val
+ imagename = BLOCK['ImageName'][0].val
+ result = BLOCK['NoReplaceImag'][0].val
+
+ MESH3D = Object.GetSelected()[0]
+ [O.select(0) for O in Object.GetSelected()]
+ MESH = MESH3D.getData()
+ if MESH.hasFaceUV():
+ try:
+ NewOBJECT=Blender.Object.Get('UVOBJECT')
+ CurSCENE=Blender.Scene.getCurrent()
+ except:
+ NewOBJECT, CurSCENE = GET_newobject('Mesh','UVOBJECT')
+
+ MESH2 = NewOBJECT.getData()
+ MESH2.edges=[]
+ 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])
+ MESH2.verts.append(v1)
+ f1.v.append(MESH2.verts[len(MESH2.verts) - 1])
+
+ MESH2.faces.append(f1)
+ f1.uv = f.uv[:]
+ f1.col = f.col[:]
+ f1.smooth = f.smooth
+ 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))
+
+ NewOBJECT.RotX=0.0 #setEuler ((0.0, 0.0, 0.0))
+ NewOBJECT.RotY=0.0
+ NewOBJECT.RotZ=0.0
+
+ MESH2.removeAllKeys()
+
+ MESH2.update()
+ MESH2.insertKey (1, 'absolute')
+ MESH2.update()
+
+ NewOBJECT.select(1)
+ NewOBJECT.makeDisplayList()
+
+ 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
+
+ #print XYLIMIT
+
+ MESH2.update()
+ MESH2.insertKey (FRAME, 'absolute')
+ MESH2.update()
+
+
+ #-----------------------------------
+ # release : 0.3.2 , 2005/12/28 , 13h00
+ #-----------------------------------
+ Blender240update(MESH2,FRAME)
+ #-----------------------------------
+ # release : 0.3.2 , 2005/12/28 , end
+ #-----------------------------------
+
+
+
+ #imagename = 'uvtext'
+ #name = "CHANGE IMAGE NAME ? %t | Replace it | No replace | Script help"
+ #result = Draw.PupMenu(name)
+
+ #if result == 1:
+ # imagename = Draw.PupStrInput ('Image Name:', imagename, 32)
+
+ if result != 3:
+ #-----------------------------------
+ # release : 0.2.6 , 2005/05/29 , 00h00
+ #-----------------------------------
+ SHADEDict=PROV_Shadeless(MESH2.materials)
+ #-----------------------------------
+ # release : 0.2.6 , 2005/05/29 , end
+ #-----------------------------------
+
+ if LIMIT :
+ SHOOT(XYLIMIT, FRAME, NewOBJECT, imagename, FRAME,result)
+ else :
+ SHOOT([0.0,0.0,1.0,1.0], FRAME, NewOBJECT, imagename, FRAME, result)
+ #-----------------------------------
+ # release : 0.2.6, 2005/05/29 , 00h00
+ #-----------------------------------
+ REST_Shadeless(SHADEDict)
+ #-----------------------------------
+ # release : 0.2.6 , 2005/05/29 , end
+ #-----------------------------------
+
+ Blender.Redraw()
+
+ else:
+ Draw.PupMenu("Ready%t|Please check console for instructions")
+ print helpmsg
+
+ else:
+ name = "Error%t|Active object is not a mesh or has no UV coordinates"
+ result = Draw.PupMenu(name)
+ print 'problem : Active object is not a mesh or has no UV coordinates'
+ else:
+ name = "Error%t| nothing do . Push << OK >> button ."
+ result = Draw.PupMenu(name)
+ #except:
+ else :
+ name = "Error%t|No Active object or it is not a mesh "
+ result = Draw.PupMenu(name)
+ print 'problem : no object selected or not mesh'
Mesh2UVCoord(LIMIT) \ No newline at end of file
diff --git a/release/scripts/uvpaint.py b/release/scripts/uvpaint.py
index 5ecacf26d57..ac8c8062ceb 100644
--- a/release/scripts/uvpaint.py
+++ b/release/scripts/uvpaint.py
@@ -261,13 +261,17 @@ def transface(f,x,y,u=0.0, v=0.0):
if len(f.v)>=3:
a[0]=int((f.uv[0][0]-LIM[1])*x+u)
a[1]=int((f.uv[0][1]-LIM[3])*y+v)
-
+
if a[0]>xlimit:
xlimit=a[0]
+
+ if f.col :
+ a[2]=f.col[0].r/255.0
+ a[3]=f.col[0].g/255.0
+ a[4]=f.col[0].b/255.0
- a[2]=f.col[0].r/255.0
- a[3]=f.col[0].g/255.0
- a[4]=f.col[0].b/255.0
+ else :
+ a[2],a[3],a[4]=1.0,1.0,1.0
c[0]=int((f.uv[2][0]-LIM[1])*x+u)
c[1]=int((f.uv[2][1]-LIM[3])*y+v)
@@ -275,10 +279,12 @@ def transface(f,x,y,u=0.0, v=0.0):
if c[0]>xlimit:
xlimit=c[0]
- c[2]=f.col[2].r/255.0
- c[3]=f.col[2].g/255.0
- c[4]=f.col[2].b/255.0
-
+ if f.col :
+ c[2]=f.col[2].r/255.0
+ c[3]=f.col[2].g/255.0
+ c[4]=f.col[2].b/255.0
+ else :
+ c[2],c[3],c[4]=1.0,1.0,1.0
b[0]=int((f.uv[1][0]-LIM[1])*x+u)
b[1]=int((f.uv[1][1]-LIM[3])*y+v)
@@ -286,10 +292,12 @@ def transface(f,x,y,u=0.0, v=0.0):
if b[0]>xlimit:
xlimit=b[0]
- b[2]=f.col[1].r/255.0
- b[3]=f.col[1].g/255.0
- b[4]=f.col[1].b/255.0
-
+ if f.col :
+ b[2]=f.col[1].r/255.0
+ b[3]=f.col[1].g/255.0
+ b[4]=f.col[1].b/255.0
+ else :
+ b[2],b[3],b[4]=1.0,1.0,1.0
if len(f.v)==4:
d[0]=int((f.uv[3][0]-LIM[1])*x+u)
@@ -297,14 +305,15 @@ def transface(f,x,y,u=0.0, v=0.0):
if d[0]>xlimit:
xlimit=d[0]
-
- d[2]=f.col[3].r/255.0
- d[3]=f.col[3].g/255.0
- d[4]=f.col[3].b/255.0
+ if f.col :
+ d[2]=f.col[3].r/255.0
+ d[3]=f.col[3].g/255.0
+ d[4]=f.col[3].b/255.0
+ else :
+ d[2],d[3],d[4]=1.0,1.0,1.0
else:
d=0
-
#print a,b,c
return a,b,c,d
@@ -322,8 +331,8 @@ def affiche_mesh(ME,x,y):
global LINE,xlimit,MMENU,XLIMIT,xwin,xlimit,LC
global LIM, EMPTY,TRANSP
if not NOLIM : LIM=[-1.0,1.0,-1.0,1.0]
-
- if ME.getType()=='Mesh':
+
+ if ME.getType()=='Mesh' and ME.getData().hasFaceUV():
me=ME.getData()
if MMENU.val==1:
se=me.faces
@@ -353,7 +362,7 @@ def affiche_mesh(ME,x,y):
Ttriangle(a,c,d)
elif len(f.v)==3:
Ttriangle(a,b,c)
-
+
if LINE.val==1 or EMPTY:
for f in se:
a,b,c,d=transface(f,x,y)
@@ -366,6 +375,7 @@ def affiche_mesh(ME,x,y):
else:
Lcarre([1,1],[1,y-2],[xwin-2,y-2],[xwin-2,1])
+
def write_tgafile(loc2,bitmap,width,height,profondeur):
f=open(loc2,'wb')
@@ -677,4 +687,4 @@ def bevent(evt):
Blender.Redraw()
-Register(draw, event, bevent)
+Register(draw, event, bevent) \ No newline at end of file