= removed nendo import/export and tex2uvbaker =

tex2uvbaker is now redundant with buitin functionality so thank you for maintaining this script in the past.  nendo is a marginal format and the scripts are not maintained so removing
This commit is contained in:
Tom Musgrove
2007-01-12 09:08:00 +00:00
parent db77deb311
commit 74291cc503
3 changed files with 0 additions and 1196 deletions

View File

@@ -1,244 +0,0 @@
#!BPY
"""
Name: 'Nendo (.ndo)...'
Blender: 232
Group: 'Export'
Tooltip: 'Export selected mesh to Nendo File Format (*.ndo)'
"""
__author__ = "Anthony D'Agostino (Scorpius)"
__url__ = ("blender", "elysiun",
"Author's homepage, http://www.redrival.com/scorpius")
__version__ = "Part of IOSuite 0.5"
__bpydoc__ = """\
This script exports meshes to Nendo file format.
Nendo is (was) a commercial polygon modeler that has about half of the
features found in Wings. The .ndo file format is a simple, uncompressed,
memory dump of structures that represent the mesh objects, uv coords,
and image textures.
Usage:<br>
Select meshes to be exported and run this script from "File->Export" menu.
Supported:<br>
1. Exports meshes only. Hint: use ALT-C to convert non-mesh objects,
and CTRL-ALT-A if you have "dupliverts" objects.<br>
2. Exports Vertex Colors & Radiosity Solutions.
Missing:<br>
Materials and UV Coordinates info will be ignored.
Known issues:<br>
Exports only well-behaved and topologically correct meshes (i.e,
closed meshes, manifolds, meshes imported from wings, etc). The mesh
cannot have duplicate vertices, missing faces (holes), open edges, etc.<br>
PowerUser Hint: In editmode, if CTRL-ALT-SHIFT-M results in a selection,
then your mesh is not a manifold and most likely will not export.
Notes:<br>
Blender & Wings can read/write ndo files with a maximum of 65,535 edges.
Nendo can read/write ndo files with a maximum of 32,767 edges.<br>
If you have a very large mesh that you want to import into nendo, modify
the 'write_edge_table' function to use a signed integer (i.e., ">h") for the 'len(edge_table)'
field.
"""
# $Id$
#
# +---------------------------------------------------------+
# | Copyright (c) 2001 Anthony D'Agostino |
# | http://www.redrival.com/scorpius |
# | scorpius@netzero.com |
# | September 25, 2001 |
# | Read and write Nendo File Format (*.nendo) |
# +---------------------------------------------------------+
# ***** 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 *****
import Blender, meshtools
import struct, time, sys, os
# ==============================
# === Write Nendo 1.1 Format ===
# ==============================
def write(filename):
start = time.clock()
objects = Blender.Object.GetSelected()
objname = objects[0].name
meshname = objects[0].getData(name_only=1)
mesh = Blender.NMesh.GetRaw(meshname)
if not mesh:
Blender.Draw.PupMenu("Nendo Export Error%t|no active mesh")
return
obj = objects[0]
numedges = len(mesh.verts)+len(mesh.faces)-2
maxedges = (2**16)-1 # Blender & Wings can read more edges
#maxedges = 32767 # Nendo can't
if numedges > maxedges:
message = objname + " can't be exported to Nendo format (too many edges)."
Blender.Draw.PupMenu("Nendo Export Error%t|"+message)
return
edge_table = meshtools.generate_edgetable(mesh)
try:
edge_table = meshtools.generate_edgetable(mesh)
assert len(edge_table) <= maxedges
except:
edge_table = {}
message = "Unable to generate Edge Table for the object named " + meshname
meshtools.print_boxed(message)
Blender.Draw.PupMenu("Edge Table Error%t|"+message)
Blender.Window.DrawProgressBar(1.0, "") # clear progressbar
return
file = open(filename, "wb")
write_header(file)
write_object_flags(file, objname)
write_edge_table(file, edge_table)
write_face_table(file, edge_table)
write_vert_table(file, edge_table, mesh)
write_texture(file)
file.close()
Blender.Window.DrawProgressBar(1.0, "") # clear progressbar
print '\a\r',
end = time.clock()
seconds = " in %.2f %s" % (end-start, "seconds")
message = "Successfully exported " + os.path.basename(filename) + seconds
meshtools.print_boxed(message)
# ====================
# === Write Header ===
# ====================
def write_header(file):
file.write("nendo 1.1")
file.write("\0\0")
file.write("\1") # numobjects
# ==========================
# === Write Object Flags ===
# ==========================
def write_object_flags(file, objname):
file.write("\1") # good flag
file.write(struct.pack(">H", len(objname)))
file.write(objname)
file.write("\1"*4)
data = struct.pack(">18f",0,0,0,1,1,1,1,1,1,1,1,1,0.2,0.2,0.2,1,100,1)
data = "<<<< Nendo Export Script for Blender -- (c) 2004 Anthony D'Agostino >>>>"
file.write(data)
# ========================
# === Write Edge Table ===
# ========================
def write_edge_table(file, edge_table):
"+--------------------------------------+"
"| Wings: Sv Ev | Lf Rf | Lp Ls | Rp Rs |"
"| Nendo: Ev Sv | Lf Rf | Ls Rs | Rp Lp |"
"+--------------------------------------+"
#$print "edge_table"; pprint.pprint(edge_table)
file.write(struct.pack(">H", len(edge_table)))
keys = edge_table.keys()
keys.sort()
for key in keys:
file.write(struct.pack(">2H", key[0], key[1])) # Ev Sv
file.write(struct.pack(">2H", edge_table[key][0], edge_table[key][1])) # Lf Rf
file.write(struct.pack(">2H", edge_table[key][3], edge_table[key][5])) # Ls Rs
file.write(struct.pack(">2H", edge_table[key][4], edge_table[key][2])) # Rp Lp
file.write(struct.pack(">1B", 0)) # Hard flag
try:
r1,g1,b1 = map(lambda x:x*255, edge_table[key][8])
r2,g2,b2 = map(lambda x:x*255, edge_table[key][7])
except:
r1,g1,b1 = map(lambda x:x*255, [0.9,0.8,0.7])
r2,g2,b2 = r1,g1,b1
file.write(struct.pack(">8B", r1,g1,b1,0,r2,g2,b2,0))
# ========================
# === Write Face Table ===
# ========================
def write_face_table(file, edge_table):
face_table = build_face_table(edge_table)
#$print "face_table"; pprint.pprint(face_table)
file.write(struct.pack(">H", len(face_table)))
keys = face_table.keys()
keys.sort()
for key in keys:
file.write(struct.pack(">1H", face_table[key]))
# ========================
# === Write Vert Table ===
# ========================
def write_vert_table(file, edge_table, mesh):
vert_table = build_vert_table(edge_table)
#$print "vert_table"; pprint.pprint(vert_table)
file.write(struct.pack(">H", len(vert_table)))
keys = vert_table.keys()
keys.sort()
for key in keys:
vertex = mesh.verts[key].co
x,y,z = map(lambda x:x*10, vertex) # scale
idx = vert_table[key]
#$print "%i % f % f % f" % (idx, x, y, z)
file.write(struct.pack(">1H3f", idx, x, z, -y))
# =====================
# === Write Texture ===
# =====================
def write_texture(file):
file.write("\0"*5)
# ========================
# === Build Vert Table ===
# ========================
def build_vert_table(edge_table): # For Nendo
vert_table = {}
for key in edge_table.keys():
i = edge_table[key][6]
Sv = key[0]
Ev = key[1]
vert_table[Sv] = i
vert_table[Ev] = i
return vert_table
# ========================
# === Build Face Table ===
# ========================
def build_face_table(edge_table): # For Nendo
face_table = {}
for key in edge_table.keys():
i = edge_table[key][6]
Lf = edge_table[key][0]
Rf = edge_table[key][1]
face_table[Lf] = i
face_table[Rf] = i
return face_table
def fs_callback(filename):
if filename.find('.ndo', -4) <= 0: filename += '.ndo'
write(filename)
Blender.Window.FileSelector(fs_callback, "Export Nendo")

View File

@@ -1,269 +0,0 @@
#!BPY
"""
Name: 'Nendo (.ndo)...'
Blender: 232
Group: 'Import'
Tooltip: 'Import Nendo Object File Format (.ndo)'
"""
__author__ = "Anthony D'Agostino (Scorpius)"
__url__ = ("blender", "elysiun",
"Author's homepage, http://www.redrival.com/scorpius")
__version__ = "Part of IOSuite 0.5"
__bpydoc__ = """\
This script imports Nendo files to Blender.
Nendo is (was) a commercial polygon modeler that has about half of the
features found in Wings. The .ndo file format is a simple, uncompressed,
memory dump of structures that represent the mesh objects, uv coords,
and image textures.
Usage:<br>
Execute this script from the "File->Import" menu and choose a Nendo file
to open.
Supported:<br>
Meshes only.
Missing:<br>
Materials, UV Coordinates, and Vertex Color info will be ignored.
Known issues:<br>
Triangulation of convex polygons works fine, and uses a very simple
fanning algorithm. Convex polygons (i.e., shaped like the letter "U")
require a different algorithm, and will be triagulated incorrectly.
Notes:<br>
Last tested with Wings 3D 0.98.25 & Nendo 1.1.6. Some models cannot be
imported due to the fact that Nendo erroneously creates doubled back
edges during the course of modeling.
"""
# $Id$
#
# +---------------------------------------------------------+
# | Copyright (c) 2001 Anthony D'Agostino |
# | http://www.redrival.com/scorpius |
# | scorpius@netzero.com |
# | September 25, 2001 |
# | Read and write Nendo File Format (*.nendo) |
# +---------------------------------------------------------+
# ***** 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 *****
import Blender, meshtools
try:
import struct, os
except:
struct= None
# =============================
# === Read Nendo 1.x Format ===
# =============================
def read(filename):
start = Blender.sys.time()
scn= Blender.Scene.GetCurrent()
for obj in scn.objects:
obj.sel= 0
file = open(filename, "rb")
version, numobjs = read_header(file)
for object in xrange(numobjs):
good, = struct.unpack(">B", file.read(1))
if not good: continue # an empty object
objname = read_object_flags(file)
edge_table = read_edge_table(file, version)
face_table = read_face_table(file)
vert_table = read_vert_table(file)
uv = read_uv(file)
verts = make_verts(vert_table)
faces = make_faces(edge_table)
meshtools.create_mesh(verts, faces, objname)
Blender.Window.DrawProgressBar(1.0, "Done") # clear progressbar
file.close()
end = Blender.sys.time()
seconds = " in %.2f %s" % (end-start, "seconds")
message = "Successfully imported " + filename.split(Blender.sys.sep)[-1] + seconds
message += " (%s)" % version.title()
meshtools.print_boxed(message)
# =======================
# === Read The Header ===
# =======================
def read_header(file):
version, = struct.unpack(">9s", file.read(9))
misc, = struct.unpack(">H", file.read(2))
numobjs, = struct.unpack(">B", file.read(1))
if (version != "nendo 1.0") and (version != "nendo 1.1"):
meshtools.print_boxed(file.name, "is not a Nendo file")
return
return version, numobjs
# =========================
# === Read Object Flags ===
# =========================
def read_object_flags(file):
namelen, = struct.unpack(">H", file.read(2))
objname = file.read(namelen)
visible, = struct.unpack(">B", file.read(1))
sensity, = struct.unpack(">B", file.read(1))
other, = struct.unpack(">H", file.read(2)) # or 2 more flags?
misc = struct.unpack(">18f", file.read(72))
return objname
# =======================
# === Read Edge Table ===
# =======================
def read_edge_table(file, version):
numedges, = struct.unpack(">H", file.read(2))
edge_table = {}
for i in xrange(numedges):
if not i%100 and meshtools.show_progress:
Blender.Window.DrawProgressBar(float(i)/numedges, "Reading Edge Table")
edge = struct.unpack(">8H", file.read(16))
if version == "nendo 1.1":
hard, = struct.unpack(">B", file.read(1)) # edge hardness flag
color = struct.unpack(">8B", file.read(8))
edge_table[i] = edge
return edge_table
# =======================
# === Read Face Table ===
# =======================
def read_face_table(file):
numfaces, = struct.unpack(">H", file.read(2))
face_table = {}
for i in xrange(numfaces):
if not i%100 and meshtools.show_progress:
Blender.Window.DrawProgressBar(float(i)/numfaces, "Reading Face Table")
face_table[i] = struct.unpack(">H", file.read(2))[0]
return face_table
# =======================
# === Read Vert Table ===
# =======================
def read_vert_table(file):
numverts, = struct.unpack(">H", file.read(2))
vert_table = []
for i in xrange(numverts):
if not i%100 and meshtools.show_progress:
Blender.Window.DrawProgressBar(float(i)/numverts, "Reading Vertex Table")
w, x, y, z = struct.unpack(">H3f", file.read(14))
vert_table.append((w,(x, y, z)))
return vert_table
# ====================
# === Read Texture ===
# ====================
def read_uv(file):
numuvs, = struct.unpack(">H", file.read(2))
uvlist = struct.unpack(">"+`numuvs`+"H", file.read(numuvs*2))
numfacesT, = struct.unpack(">H", file.read(2))
facesT = struct.unpack(">"+`numfacesT`+"H", file.read(numfacesT*2))
textureflag, = struct.unpack(">B", file.read(1))
if textureflag:
xres, yres = struct.unpack(">2H", file.read(4))
print "%ix%i" % (xres, yres)
pixel = 0
while pixel < (xres*yres):
if not pixel%100 and meshtools.show_progress:
Blender.Window.DrawProgressBar(float(pixel)/xres*yres, "Reading Texture")
count, = struct.unpack(">B", file.read(1))
rgb = file.read(3)
pixel = pixel+count
return numuvs
# ==================
# === Make Verts ===
# ==================
def make_verts(vert_table):
matrix = [ # Rotate 90*x and Scale 0.1
[0.1, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.1, 0.0],
[0.0,-0.1, 0.0, 0.0],
[0.0, 0.0, 0.0, 1.0]]
verts = []
for i in xrange(len(vert_table)):
vertex = vert_table[i][1]
vertex = meshtools.apply_transform(vertex, matrix)
verts.append(vertex)
return verts
# =======================
# === Make Face Table ===
# =======================
def make_face_table(edge_table): # For Nendo
face_table = {}
for i in xrange(len(edge_table)):
Lf = edge_table[i][2]
Rf = edge_table[i][3]
face_table[Lf] = face_table[Rf] = i
return face_table
# =======================
# === Make Vert Table ===
# =======================
def make_vert_table(edge_table): # For Nendo
vert_table = {}
for i in xrange(len(edge_table)):
Sv = edge_table[i][1]
Ev = edge_table[i][0]
vert_table[Sv] = vert_table[Ev]= i
return vert_table
# ==================
# === Make Faces ===
# ==================
def make_faces(edge_table): # For Nendo
face_table = make_face_table(edge_table)
faces=[]
#for i in range(len(face_table)):
for i in face_table.iterkeys(): # avoids a whole class of errors
face_verts = []
current_edge = face_table[i]
while(1):
if i == edge_table[current_edge][3]:
next_edge = edge_table[current_edge][5] # Right successor edge
next_vert = edge_table[current_edge][1]
else:
next_edge = edge_table[current_edge][4] # Left successor edge
next_vert = edge_table[current_edge][0]
face_verts.append(next_vert)
current_edge = next_edge
if current_edge == face_table[i]: break
face_verts.reverse() # Flip all face normals
faces.append(face_verts)
return faces
def main():
if not struct:
Blender.Draw.PupMenu('This importer requires a full python install')
return
Blender.Window.FileSelector(read, 'Import Nendo', '*.ndo')
if __name__=='__main__':
main()

View File

@@ -1,683 +0,0 @@
#!BPY
""" Registration info for Blender menus:
Name: 'UV Texture Baker'
Blender: 239
Group: 'UV'
Tooltip: 'Procedural to uvmapped texture baker'
"""
__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.3 2005/09/10"
__bpydoc__ = """\
This script "bakes" Blender procedural materials (including textures): it saves
them as 2d uv-mapped images.
This script saves an uv texture layout of the chosen mesh, that can be used as
an uv map for it. It is a way to export procedurals from Blender as normal
image textures that can be edited with a 2d image manipulation program or used
with the mesh in games and other 3d applications.
Usage:
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 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
obliges the script to do a complete framing of the uvcoord .
Notes:<br>
This script was based on a suggestion by Martin (Theeth) Poirier;<br>
"""
#---------------------------------------------
# Last release : 0.3.3 , 2006/09/10 , 15h20
#---------------------------------------------
#---------------------------------------------
# (c) jm soler 07/2004 : 'Procedural Texture Baker'
# Based on a Martin 'Theeth' Poirier's really
# good idea : makes a rvk mesh with uv coords
# of the original mesh.
#
# 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 .
#
# 0.3.1
# stupid bug correction
#
# 0.3.0
# TAILLEIMAGE variable
#
# 0.2.9
# -- little probleme with the KEEPRENDERWINDOW variable .
# removed . script seems to works correctly now .
#
# 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
#
# -- helpmsg corrected : the aim of the script
# is to bake any type of textures so we have not
# to mapinput its textures on UV .
#
# --'pers' camera was replaced by an 'ortho' one.
#
# 0.2.5
# -- if a image file with the same name exits the
# system returns an error
#
# 0.2.4
# -- a LIMIT variable is added to unlock the uvcoords
# autoframing
#
#
# 0.2.3 :
# Great thanks for Apollux who sees a lot of these
# problems
#
# --Everytime you run the script a new set
# of objects is created. File size and memory
# consumption can go pretty high if you are
# not aware of that .
# Now it ONLY creates 3 objects: a flattened
# mesh, a camera and a lamp.
# --all the 3 objects was placed on layer 1, but if
# that layer was not visible while you used the script
# all you will get a is an empty render.
# Now the layer is tst and activated befor the shoot
# --The flattened mesh was really flattend only after
# frame 100 (if you playbacked the animation, you can
# actually see the mesh becoming flat on the first 100
# frames). No more.
# -- When the script is run, it changes temporary to
# the new cammera, set the render output to a square
# (i.e. 1024 x 1024 or else), does the render, and then
# resets the render output and the active camera to the
# original one. But if no original camera was found
# this produce an error.
#
# 0.2.2 :
# if the uv mesh objet exists it used,
# no creation of a new one. As the lamp and
# the camera
# 0.2.1 :
# This script automaticaly frame and shoot the
# new uv mesh . The image file is saved ine the
# /render folder.
#
#---------------------------------------------
# On user-friendly side :
#---------------------------------------------
#- Tadje Vobovnik adds the Select Image Size Menu
#
#---------------------------------------------
# Official Page :
# http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_mesh3d2uv2d_en.htm
# For problems and errors:
# http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
#---------------------------------------------
import Blender
from Blender import NMesh, Draw, Object, Scene, Camera
#-----------------------------------
# Last release : 0.2.5 , 2005/05/22 , 20h00
#-----------------------------------
# la fonction Blender.sys.dirname pose un
# probleme lorsque la memoire est trop encombree
# ---
# It seems that the Blender.sys.dirname function
# poses a problem when the memory is too much encumbered
#-----------------------------------
try:
import nt
os = nt
os.sep='\\'
except:
import posix
os = posix
os.sep='/'
DIRNAME=Blender.Get('filename')
#-----------------------------------
# decoupage de la chaine en fragment
# de fa<66>on a isoler le nom du fichier
# du repertoire
# ---
# split string in fragments to isolate
# the file name from the path name
#-----------------------------------
if DIRNAME.find(os.sep)!=-1:
k0=DIRNAME.split(os.sep)
else:
k0=DIRNAME.split('/')
DIRNAME=DIRNAME.replace(k0[-1],'')
#-----------------------------------
# Last release : 0.2.5 , 2005/05/22 , end
#-----------------------------------
#-----------------------------------
# Last release : 0.2.4 , 2005/05/22 , 15h00
#-----------------------------------
FRAME = Blender.Get('endframe')
#-----------------------------------
# Last release : 0.2.4 , 2005/05/22 , end
#-----------------------------------
#-----------------------------------
# Last release : 0.2.4 , 2005/05/18 , 11h00
#
# Si LIMIT == 0 le script n'essaye pas de realiser
# un nouveau cadrage pour que l'image presente toute les
# coordonn<6E>es uv.
# ---
# if LIMIT == 0 the script do not try to make
# a new framing with all the uvcoord in only one
# shoot...
#-----------------------------------
LIMIT=0
#-----------------------------------
# Last release : 0.2.4 , 2005/05/18 , END
#-----------------------------------
XYLIMIT = [0.0, 0.0,1.0,1.0]
OBJPOS = 100.0
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:
This script saves an uv texture layout of the chosen mesh, that can be used as
an uv map for it. It is a way to export procedural textures from Blender as
normal image textures that can be edited with a 2d image manipulation program
or used with the mesh in games and other 3d applications.
Basic instructions:
- Enter face mode and define uv coordinates for your mesh (do not forget to
choose a development shape);
- Define its materials and textures ;
- Run this script and check the console.
"""
def GET_newobject (TYPE,NAME):
"""
# ---------------------------
# Function GET_newobject
#
# IN : TYPE string , object type ('Mesh','Empty',...)
# NAME string , name object
# OUT: OBJECT Blender objetc described in teh string TYPE
# 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
def RenameImage(RDIR, MYDIR, FILENAME, name):
"""
# ---------------------------
# Function RenameImage
#
# IN : RDIR string , current render directory
# MYDIR string , new render dir for this shoot
# FILENAME string , last rendered image filename
# name string , new name for this image
# OUT: nothing
# ---------------------------
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)
def SAVE_image (rc, name, FRAME, result):
"""
# ---------------------------
# Function SAVE_image
#
# IN : rc current render context object
# name string , image name
# FRAME integer, last numbre of the curent animation
# OUT: nothing
# ---------------------------
"""
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
#
# IN : XYlimit list of 4 floats, smallest and biggest
# uvcoords
# frame current frame
# obj for object location
# name image name
# FRAME the last animation's frame
# OUT: nothing
# ---------------------------
render and save the baked textures picture
"""
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
#-----------------------------------
# Last release : 0.2.6 , 2005/05/29 , end
#-----------------------------------
#-----------------------------------
# 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]
#-----------------------------------
# release : 0.2.6 , 2005/05/29 , end
#-----------------------------------
#-----------------------------------
# release : 0.3.2 , 2005/12/28 , 13h00
#-----------------------------------
def Blender240update(MESH2,FRAME):
"""
# ---------------------------
# Function Blender240update
#
# IN : MESH2 a mesh data bloc
# FRAME , the animation frame limit
#
# ADD : an ipo curve to the shape key
# named "Key 1"
#
# 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<75>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'<27>tat actuel, cette op<6F>ration est une s<>curit<69>
# 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-<2D>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, 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)