Made all the scripts use the file browser for saving images
Added better docscrings Added a texture baker for procedural textures, Its able to make a WYSIWYG image from the texture, by using the texmesh property, so texture coords arnt lost up when flattening the mesh. Use a high res image not to see any seams
This commit is contained in:
@@ -113,7 +113,7 @@ def mesh2uv(me_s, PREF_SEL_FACES_ONLY=False):
|
||||
"mesh" is the new mesh and...
|
||||
"face_list" is the faces that were used to make the mesh,
|
||||
"material_list" is a list of materials used by each face
|
||||
These are in sync with the meshes faces, so you can easerly copy data between them
|
||||
These are in alligned with the meshes faces, so you can easerly copy data between them
|
||||
|
||||
'''
|
||||
render_me= Blender.Mesh.New()
|
||||
@@ -128,7 +128,6 @@ def mesh2uv(me_s, PREF_SEL_FACES_ONLY=False):
|
||||
else:
|
||||
me_faces= me.faces
|
||||
|
||||
# Keep in sync with render_me.faces
|
||||
face_list.extend(me_faces)
|
||||
|
||||
# Dittro
|
||||
@@ -221,6 +220,7 @@ def vcol2image(me_s,\
|
||||
PREF_USE_VCOL,\
|
||||
PREF_USE_MATCOL,\
|
||||
PREF_USE_NORMAL,\
|
||||
PREF_USE_TEXTURE,\
|
||||
PREF_SEL_FACES_ONLY):
|
||||
|
||||
|
||||
@@ -264,14 +264,80 @@ def vcol2image(me_s,\
|
||||
|
||||
elif PREF_USE_MATCOL:
|
||||
uvmesh_apply_matcol(render_me, material_list)
|
||||
|
||||
|
||||
elif PREF_USE_TEXTURE:
|
||||
# if we have more then 16 materials across all the mesh objects were stuffed :/
|
||||
# get unique materials
|
||||
tex_unique_materials= dict([(mat.name, mat) for mat in material_list]).values()[:16] # just incase we have more then 16
|
||||
tex_me= Blender.Mesh.New()
|
||||
|
||||
# Backup the original shadless setting
|
||||
tex_unique_materials_shadeless= [ mat.mode & Blender.Material.Modes.SHADELESS for mat in tex_unique_materials ]
|
||||
|
||||
# Turn shadeless on
|
||||
for mat in tex_unique_materials:
|
||||
mat.mode |= Blender.Material.Modes.SHADELESS
|
||||
|
||||
# Assign materials
|
||||
render_me.materials= tex_unique_materials
|
||||
|
||||
|
||||
|
||||
tex_material_indicies= dict([(mat.name, i) for i, mat in enumerate(tex_unique_materials)])
|
||||
|
||||
tex_me.verts.extend([Vector(0,0,0),]) # dummy
|
||||
tex_me.verts.extend( [ Vector(v.co) for f in face_list for v in f ] )
|
||||
|
||||
# Now add the faces
|
||||
tmp_faces= []
|
||||
vert_offset= 1
|
||||
for f in face_list:
|
||||
tmp_faces.append( [ii+vert_offset for ii in xrange(len(f))] )
|
||||
vert_offset+= len(f)
|
||||
|
||||
tex_me.faces.extend(tmp_faces)
|
||||
|
||||
# Now we have the faces, put materials and normal, uvs into the mesh
|
||||
if len(tex_me.faces) != len(face_list):
|
||||
# Should never happen
|
||||
raise "Error face length mismatch"
|
||||
|
||||
# Copy data to the mesh that could be used as texture coords
|
||||
for i, tex_face in enumerate(tex_me.faces):
|
||||
orig_face= face_list[i]
|
||||
|
||||
# Set the material index
|
||||
try:
|
||||
render_face.mat= tex_material_indicies[ material_list[i].name ]
|
||||
except:
|
||||
# more then 16 materials
|
||||
pass
|
||||
|
||||
|
||||
# set the uvs on the texmesh mesh
|
||||
tex_face.uv= orig_face.uv
|
||||
|
||||
orig_face_v= orig_face.v
|
||||
# Set the normals
|
||||
for j, v in enumerate(tex_face):
|
||||
v.no= orig_face_v[j].no
|
||||
|
||||
# Set the texmesh
|
||||
render_me.texMesh= tex_me
|
||||
# END TEXMESH
|
||||
|
||||
|
||||
# Handel adding objects
|
||||
render_ob= Blender.Object.New('Mesh')
|
||||
render_me.materials= [rnd_mat()]
|
||||
|
||||
render_ob.link(render_me)
|
||||
|
||||
if not PREF_USE_TEXTURE: # textures use the original materials
|
||||
render_me.materials= [rnd_mat()]
|
||||
|
||||
|
||||
obs= [render_ob]
|
||||
|
||||
|
||||
if PREF_IMAGE_WIRE_UNDERLAY:
|
||||
# Make another mesh with the material colors
|
||||
render_me_under, face_list, material_list= mesh2uv(me_s, PREF_SEL_FACES_ONLY)
|
||||
@@ -320,3 +386,12 @@ def vcol2image(me_s,\
|
||||
|
||||
if PREF_IMAGE_WIRE_UNDERLAY:
|
||||
render_me_under.verts= None
|
||||
|
||||
if PREF_USE_TEXTURE:
|
||||
tex_me.verts= None
|
||||
# Restire Shadeless setting
|
||||
for i, mat in enumerate(tex_unique_materials):
|
||||
# we know there all on so turn it off of its not set
|
||||
if not tex_unique_materials_shadeless[i]:
|
||||
mat.mode &= ~Blender.Material.Modes.SHADELESS
|
||||
|
||||
|
||||
@@ -9,12 +9,13 @@ __author__= ['Campbell Barton']
|
||||
__url__= ('blender', 'elysiun', 'http://www.gametutorials.com')
|
||||
__version__= '0.1'
|
||||
__bpydoc__= '''\
|
||||
Bake Vertex Colors to an image
|
||||
Bake Texface Images to 1 image
|
||||
|
||||
This script makes an image from a meshes vertex colors, using the UV coordinates
|
||||
This script makes an image from a meshes texface images, using the UV coordinates
|
||||
to draw the faces into the image.
|
||||
|
||||
This makes it possible to bake radiosity into a texture.
|
||||
This makes it possible to bake many images into 1 texture.
|
||||
|
||||
Make sure your UV Coordinates do not overlap.
|
||||
LSCM Unwrapper or archimap unwrapper work well to automaticaly do this.
|
||||
'''
|
||||
@@ -40,18 +41,16 @@ def main():
|
||||
BPyMessages.Error_NoMeshUvSelected()
|
||||
return
|
||||
|
||||
newpath= Blender.Get('filename').split('/')[-1].split('\\')[-1].replace('.blend', '')
|
||||
PREF_IMAGE_PATH = Create('//%s_img' % newpath)
|
||||
newpath= Blender.Get('filename').split('/')[-1].split('\\')[-1].replace('.blend', '_img.png')
|
||||
###PREF_IMAGE_PATH = Create('//%s_img' % newpath)
|
||||
PREF_IMAGE_SIZE = Create(512)
|
||||
PREF_IMAGE_BLEED = Create(4)
|
||||
PREF_IMAGE_SMOOTH= Create(1)
|
||||
PREF_IMAGE_SMOOTH= Create(0)
|
||||
|
||||
PREF_SEL_FACES_ONLY= Create(0)
|
||||
|
||||
pup_block = [\
|
||||
'Image Path: (no ext)',\
|
||||
('', PREF_IMAGE_PATH, 3, 100, 'Path to new Image. "//" for curent blend dir.'),\
|
||||
'Image Options',
|
||||
###('', PREF_IMAGE_PATH, 3, 100, 'Path to new Image. "//" for curent blend dir.'),\
|
||||
('Pixel Size:', PREF_IMAGE_SIZE, 64, 4096, 'Image Width and Height.'),\
|
||||
('Pixel Bleed:', PREF_IMAGE_BLEED, 0, 64, 'Extend pixels from boundry edges to avoid mipmapping errors on rendering.'),\
|
||||
('Smooth lines', PREF_IMAGE_SMOOTH, 'Render smooth lines.'),\
|
||||
@@ -73,22 +72,27 @@ def main():
|
||||
PREF_USE_VCOL= False
|
||||
PREF_USE_MATCOL= False
|
||||
PREF_USE_NORMAL= False
|
||||
PREF_USE_TEXTURE= False
|
||||
|
||||
BPyRender.vcol2image(me_s,\
|
||||
PREF_IMAGE_PATH.val,\
|
||||
PREF_IMAGE_SIZE.val,\
|
||||
PREF_IMAGE_BLEED.val,\
|
||||
PREF_IMAGE_SMOOTH.val,\
|
||||
PREF_IMAGE_WIRE,\
|
||||
PREF_IMAGE_WIRE_INVERT,\
|
||||
PREF_IMAGE_WIRE_UNDERLAY,\
|
||||
PREF_USE_IMAGE,\
|
||||
PREF_USE_VCOL,\
|
||||
PREF_USE_MATCOL,\
|
||||
PREF_USE_NORMAL,\
|
||||
PREF_SEL_FACES_ONLY.val)
|
||||
def file_sel(PREF_IMAGE_PATH):
|
||||
BPyRender.vcol2image(me_s,\
|
||||
PREF_IMAGE_PATH,\
|
||||
PREF_IMAGE_SIZE.val,\
|
||||
PREF_IMAGE_BLEED.val,\
|
||||
PREF_IMAGE_SMOOTH.val,\
|
||||
PREF_IMAGE_WIRE,\
|
||||
PREF_IMAGE_WIRE_INVERT,\
|
||||
PREF_IMAGE_WIRE_UNDERLAY,\
|
||||
PREF_USE_IMAGE,\
|
||||
PREF_USE_VCOL,\
|
||||
PREF_USE_MATCOL,\
|
||||
PREF_USE_NORMAL,\
|
||||
PREF_USE_TEXTURE,\
|
||||
PREF_SEL_FACES_ONLY.val)
|
||||
|
||||
Blender.Window.RedrawAll()
|
||||
|
||||
Blender.Window.RedrawAll()
|
||||
Blender.Window.FileSelector(file_sel, 'SAVE PNG', newpath)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -9,12 +9,11 @@ __author__= ['Campbell Barton']
|
||||
__url__= ('blender', 'elysiun', 'http://www.gametutorials.com')
|
||||
__version__= '0.1'
|
||||
__bpydoc__= '''\
|
||||
Bake Vertex Colors to an image
|
||||
Bake Vertex Normals to an image
|
||||
|
||||
This script makes an image from a meshes vertex colors, using the UV coordinates
|
||||
This script makes an image from a meshes vertex normals, using the UV coordinates
|
||||
to draw the faces into the image.
|
||||
|
||||
This makes it possible to bake radiosity into a texture.
|
||||
Make sure your UV Coordinates do not overlap.
|
||||
LSCM Unwrapper or archimap unwrapper work well to automaticaly do this.
|
||||
'''
|
||||
@@ -51,18 +50,16 @@ def main():
|
||||
BPyMessages.Error_NoMeshUvSelected()
|
||||
return
|
||||
|
||||
newpath= Blender.Get('filename').split('/')[-1].split('\\')[-1].replace('.blend', '')
|
||||
PREF_IMAGE_PATH = Create('//%s_nor' % newpath)
|
||||
newpath= Blender.Get('filename').split('/')[-1].split('\\')[-1].replace('.blend', '_nor.png')
|
||||
###PREF_IMAGE_PATH = Create('//%s_nor' % newpath)
|
||||
PREF_IMAGE_SIZE = Create(512)
|
||||
PREF_IMAGE_BLEED = Create(4)
|
||||
PREF_IMAGE_SMOOTH= Create(1)
|
||||
PREF_IMAGE_SMOOTH= Create(0)
|
||||
|
||||
PREF_SEL_FACES_ONLY= Create(0)
|
||||
|
||||
pup_block = [\
|
||||
'Image Path: (no ext)',\
|
||||
('', PREF_IMAGE_PATH, 3, 100, 'Path to new Image. "//" for curent blend dir.'),\
|
||||
'Image Options',
|
||||
###('', PREF_IMAGE_PATH, 3, 100, 'Path to new Image. "//" for curent blend dir.'),\
|
||||
('Pixel Size:', PREF_IMAGE_SIZE, 64, 4096, 'Image Width and Height.'),\
|
||||
('Pixel Bleed:', PREF_IMAGE_BLEED, 0, 64, 'Extend pixels from boundry edges to avoid mipmapping errors on rendering.'),\
|
||||
('Smooth lines', PREF_IMAGE_SMOOTH, 'Render smooth lines.'),\
|
||||
@@ -90,28 +87,32 @@ def main():
|
||||
PREF_USE_IMAGE= False
|
||||
PREF_USE_VCOL= False
|
||||
PREF_USE_MATCOL= False
|
||||
PREF_USE_TEXTURE= False
|
||||
|
||||
PREF_USE_NORMAL= True # of course we need this one
|
||||
def file_sel(PREF_IMAGE_PATH):
|
||||
BPyRender.vcol2image(me_s,\
|
||||
PREF_IMAGE_PATH,\
|
||||
PREF_IMAGE_SIZE.val,\
|
||||
PREF_IMAGE_BLEED.val,\
|
||||
PREF_IMAGE_SMOOTH.val,\
|
||||
PREF_IMAGE_WIRE,\
|
||||
PREF_IMAGE_WIRE_INVERT,\
|
||||
PREF_IMAGE_WIRE_UNDERLAY,\
|
||||
PREF_USE_IMAGE,\
|
||||
PREF_USE_VCOL,\
|
||||
PREF_USE_MATCOL,\
|
||||
PREF_USE_NORMAL,\
|
||||
PREF_USE_TEXTURE,\
|
||||
PREF_SEL_FACES_ONLY.val)
|
||||
|
||||
BPyRender.vcol2image(me_s,\
|
||||
PREF_IMAGE_PATH.val,\
|
||||
PREF_IMAGE_SIZE.val,\
|
||||
PREF_IMAGE_BLEED.val,\
|
||||
PREF_IMAGE_SMOOTH.val,\
|
||||
PREF_IMAGE_WIRE,\
|
||||
PREF_IMAGE_WIRE_INVERT,\
|
||||
PREF_IMAGE_WIRE_UNDERLAY,\
|
||||
PREF_USE_IMAGE,\
|
||||
PREF_USE_VCOL,\
|
||||
PREF_USE_MATCOL,\
|
||||
PREF_USE_NORMAL,\
|
||||
PREF_SEL_FACES_ONLY.val)
|
||||
# Restore normals
|
||||
for me in me_s:
|
||||
me.update()
|
||||
|
||||
# Restore normals
|
||||
for me in me_s:
|
||||
me.update()
|
||||
Blender.Window.RedrawAll()
|
||||
|
||||
Blender.Window.RedrawAll()
|
||||
Blender.Window.FileSelector(file_sel, 'SAVE PNG', newpath)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -40,18 +40,16 @@ def main():
|
||||
BPyMessages.Error_NoMeshUvSelected()
|
||||
return
|
||||
|
||||
newpath= Blender.Get('filename').split('/')[-1].split('\\')[-1].replace('.blend', '')
|
||||
PREF_IMAGE_PATH = Create('//%s_vcol' % newpath)
|
||||
newpath= Blender.Get('filename').split('/')[-1].split('\\')[-1].replace('.blend', '_vcol.png')
|
||||
#PREF_IMAGE_PATH = Create('//%s_vcol' % newpath)
|
||||
PREF_IMAGE_SIZE = Create(512)
|
||||
PREF_IMAGE_BLEED = Create(4)
|
||||
PREF_IMAGE_SMOOTH= Create(1)
|
||||
PREF_IMAGE_SMOOTH= Create(0)
|
||||
|
||||
PREF_SEL_FACES_ONLY= Create(0)
|
||||
|
||||
pup_block = [\
|
||||
'Image Path: (no ext)',\
|
||||
('', PREF_IMAGE_PATH, 3, 100, 'Path to new Image. "//" for curent blend dir.'),\
|
||||
'Image Options',
|
||||
###('', PREF_IMAGE_PATH, 3, 100, 'Path to new Image. "//" for curent blend dir.'),\
|
||||
('Pixel Size:', PREF_IMAGE_SIZE, 64, 4096, 'Image Width and Height.'),\
|
||||
('Pixel Bleed:', PREF_IMAGE_BLEED, 0, 64, 'Extend pixels from boundry edges to avoid mipmapping errors on rendering.'),\
|
||||
('Smooth lines', PREF_IMAGE_SMOOTH, 'Render smooth lines.'),\
|
||||
@@ -62,7 +60,6 @@ def main():
|
||||
if not Blender.Draw.PupBlock('VCol to Image', pup_block):
|
||||
return
|
||||
|
||||
|
||||
# Defaults for VCol, user cant change
|
||||
PREF_IMAGE_WIRE= False
|
||||
PREF_IMAGE_WIRE_INVERT= False
|
||||
@@ -73,22 +70,26 @@ def main():
|
||||
|
||||
PREF_USE_MATCOL= False
|
||||
PREF_USE_NORMAL= False
|
||||
PREF_USE_TEXTURE= False
|
||||
|
||||
BPyRender.vcol2image(me_s,\
|
||||
PREF_IMAGE_PATH.val,\
|
||||
PREF_IMAGE_SIZE.val,\
|
||||
PREF_IMAGE_BLEED.val,\
|
||||
PREF_IMAGE_SMOOTH.val,\
|
||||
PREF_IMAGE_WIRE,\
|
||||
PREF_IMAGE_WIRE_INVERT,\
|
||||
PREF_IMAGE_WIRE_UNDERLAY,\
|
||||
PREF_USE_IMAGE,\
|
||||
PREF_USE_VCOL,\
|
||||
PREF_USE_MATCOL,\
|
||||
PREF_USE_NORMAL,\
|
||||
PREF_SEL_FACES_ONLY.val)
|
||||
def file_sel(PREF_IMAGE_PATH):
|
||||
BPyRender.vcol2image(me_s,\
|
||||
PREF_IMAGE_PATH,\
|
||||
PREF_IMAGE_SIZE.val,\
|
||||
PREF_IMAGE_BLEED.val,\
|
||||
PREF_IMAGE_SMOOTH.val,\
|
||||
PREF_IMAGE_WIRE,\
|
||||
PREF_IMAGE_WIRE_INVERT,\
|
||||
PREF_IMAGE_WIRE_UNDERLAY,\
|
||||
PREF_USE_IMAGE,\
|
||||
PREF_USE_VCOL,\
|
||||
PREF_USE_MATCOL,\
|
||||
PREF_USE_NORMAL,\
|
||||
PREF_USE_TEXTURE,\
|
||||
PREF_SEL_FACES_ONLY.val)
|
||||
|
||||
Blender.Window.RedrawAll()
|
||||
|
||||
Blender.Window.RedrawAll()
|
||||
|
||||
Blender.Window.FileSelector(file_sel, 'SAVE PNG', newpath)
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -9,12 +9,12 @@ __author__= ['Campbell Barton']
|
||||
__url__= ('blender', 'elysiun', 'http://www.gametutorials.com')
|
||||
__version__= '0.1'
|
||||
__bpydoc__= '''\
|
||||
Bake Vertex Colors to an image
|
||||
Bake Wire Image from UVs
|
||||
|
||||
This script makes an image from a meshes vertex colors, using the UV coordinates
|
||||
to draw the faces into the image.
|
||||
Write a wireframe image from the UV coords and the the material color
|
||||
|
||||
This is usefull for laying out UV images on an unwrapped mesh.
|
||||
|
||||
This makes it possible to bake radiosity into a texture.
|
||||
Make sure your UV Coordinates do not overlap.
|
||||
LSCM Unwrapper or archimap unwrapper work well to automaticaly do this.
|
||||
'''
|
||||
@@ -40,7 +40,7 @@ def main():
|
||||
BPyMessages.Error_NoMeshUvSelected()
|
||||
return
|
||||
|
||||
newpath= Blender.Get('filename').split('/')[-1].split('\\')[-1].replace('.blend', '')
|
||||
newpath= Blender.Get('filename').split('/')[-1].split('\\')[-1].replace('.blend', '_wire.png')
|
||||
PREF_IMAGE_PATH = Create('//%s_wire' % newpath)
|
||||
PREF_IMAGE_SIZE = Create(512)
|
||||
PREF_IMAGE_WIRE_INVERT = Create(0)
|
||||
@@ -50,9 +50,9 @@ def main():
|
||||
PREF_SEL_FACES_ONLY= Create(0)
|
||||
|
||||
pup_block = [\
|
||||
'Image Path: (no ext)',\
|
||||
('', PREF_IMAGE_PATH, 3, 100, 'Path to new Image. "//" for curent blend dir.'),\
|
||||
'Image Options',
|
||||
###'Image Path: (no ext)',\
|
||||
###('', PREF_IMAGE_PATH, 3, 100, 'Path to new Image. "//" for curent blend dir.'),\
|
||||
###'Image Options',
|
||||
('Pixel Size:', PREF_IMAGE_SIZE, 64, 4096, 'Image Width and Height.'),\
|
||||
('White Wire', PREF_IMAGE_WIRE_INVERT, 'Sets the wire to white (otherwise its black).'),\
|
||||
('Fill Faces', PREF_IMAGE_WIRE_UNDERLAY, 'Fill in faces with material color.'),\
|
||||
@@ -75,22 +75,27 @@ def main():
|
||||
PREF_USE_VCOL= False
|
||||
PREF_USE_MATCOL= False
|
||||
PREF_USE_NORMAL= False
|
||||
PREF_USE_TEXTURE= False
|
||||
|
||||
BPyRender.vcol2image(me_s,\
|
||||
PREF_IMAGE_PATH.val,\
|
||||
PREF_IMAGE_SIZE.val,\
|
||||
PREF_IMAGE_BLEED,\
|
||||
PREF_IMAGE_SMOOTH.val,\
|
||||
PREF_IMAGE_WIRE,\
|
||||
PREF_IMAGE_WIRE_INVERT.val,\
|
||||
PREF_IMAGE_WIRE_UNDERLAY.val,\
|
||||
PREF_USE_IMAGE,\
|
||||
PREF_USE_VCOL,\
|
||||
PREF_USE_MATCOL,\
|
||||
PREF_USE_NORMAL,\
|
||||
PREF_SEL_FACES_ONLY.val)
|
||||
def file_sel(PREF_IMAGE_PATH):
|
||||
BPyRender.vcol2image(me_s,\
|
||||
PREF_IMAGE_PATH,\
|
||||
PREF_IMAGE_SIZE.val,\
|
||||
PREF_IMAGE_BLEED,\
|
||||
PREF_IMAGE_SMOOTH.val,\
|
||||
PREF_IMAGE_WIRE,\
|
||||
PREF_IMAGE_WIRE_INVERT.val,\
|
||||
PREF_IMAGE_WIRE_UNDERLAY.val,\
|
||||
PREF_USE_IMAGE,\
|
||||
PREF_USE_VCOL,\
|
||||
PREF_USE_MATCOL,\
|
||||
PREF_USE_NORMAL,\
|
||||
PREF_USE_TEXTURE,\
|
||||
PREF_SEL_FACES_ONLY.val)
|
||||
|
||||
Blender.Window.RedrawAll()
|
||||
|
||||
Blender.Window.RedrawAll()
|
||||
Blender.Window.FileSelector(file_sel, 'SAVE PNG', newpath)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user