2006-07-29 07:14:11 +00:00
|
|
|
#!BPY
|
|
|
|
"""
|
|
|
|
Name: 'Bake Wire Image from UVs'
|
|
|
|
Blender: 242
|
|
|
|
Group: 'Image'
|
|
|
|
Tooltip: 'Generate an image from the selected mesh objects UV coords and materials'
|
|
|
|
"""
|
|
|
|
__author__= ['Campbell Barton']
|
|
|
|
__url__= ('blender', 'elysiun', 'http://www.gametutorials.com')
|
|
|
|
__version__= '0.1'
|
|
|
|
__bpydoc__= '''\
|
2006-07-31 15:22:20 +00:00
|
|
|
Bake Wire Image from UVs
|
2006-07-29 07:14:11 +00:00
|
|
|
|
2006-07-31 15:22:20 +00:00
|
|
|
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.
|
2006-07-29 07:14:11 +00:00
|
|
|
|
|
|
|
Make sure your UV Coordinates do not overlap.
|
|
|
|
LSCM Unwrapper or archimap unwrapper work well to automaticaly do this.
|
|
|
|
'''
|
|
|
|
|
|
|
|
import Blender
|
|
|
|
import BPyRender
|
|
|
|
#reload(BPyRender)
|
|
|
|
import BPyMessages
|
|
|
|
Vector= Blender.Mathutils.Vector
|
|
|
|
Create= Blender.Draw.Create
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
# Create the variables.
|
|
|
|
# Filename without path or extension.
|
|
|
|
# Big LC, gets all unique mesh objects from the selection that have UV coords.
|
|
|
|
me_s= dict([\
|
|
|
|
(ob.getData(name_only=1), ob.getData(mesh=1))\
|
|
|
|
for ob in Blender.Object.GetSelected()\
|
|
|
|
if ob.getType()=='Mesh' if ob.getData(mesh=1).faceUV]).values()
|
|
|
|
|
|
|
|
if not me_s:
|
|
|
|
BPyMessages.Error_NoMeshUvSelected()
|
|
|
|
return
|
|
|
|
|
2006-07-31 15:22:20 +00:00
|
|
|
newpath= Blender.Get('filename').split('/')[-1].split('\\')[-1].replace('.blend', '_wire.png')
|
2006-07-29 07:14:11 +00:00
|
|
|
PREF_IMAGE_PATH = Create('//%s_wire' % newpath)
|
|
|
|
PREF_IMAGE_SIZE = Create(512)
|
|
|
|
PREF_IMAGE_WIRE_INVERT = Create(0)
|
|
|
|
PREF_IMAGE_WIRE_UNDERLAY = Create(1)
|
|
|
|
PREF_IMAGE_SMOOTH= Create(1)
|
|
|
|
|
|
|
|
PREF_SEL_FACES_ONLY= Create(0)
|
|
|
|
|
|
|
|
pup_block = [\
|
2006-07-31 15:22:20 +00:00
|
|
|
###'Image Path: (no ext)',\
|
|
|
|
###('', PREF_IMAGE_PATH, 3, 100, 'Path to new Image. "//" for curent blend dir.'),\
|
|
|
|
###'Image Options',
|
2006-07-29 07:14:11 +00:00
|
|
|
('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.'),\
|
|
|
|
('Smooth lines', PREF_IMAGE_SMOOTH, 'Render smooth lines.'),\
|
|
|
|
'',\
|
|
|
|
('Selected Faces only', PREF_SEL_FACES_ONLY, 'Only bake from selected faces.'),\
|
|
|
|
]
|
|
|
|
|
|
|
|
if not Blender.Draw.PupBlock('Wire Bake', pup_block):
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
# Defaults for VCol, user cant change
|
|
|
|
PREF_IMAGE_WIRE= True # of course we need this one
|
|
|
|
|
|
|
|
PREF_USE_IMAGE= False
|
|
|
|
|
|
|
|
PREF_IMAGE_BLEED= 0
|
|
|
|
|
|
|
|
PREF_USE_VCOL= False
|
|
|
|
PREF_USE_MATCOL= False
|
|
|
|
PREF_USE_NORMAL= False
|
2006-07-31 15:22:20 +00:00
|
|
|
PREF_USE_TEXTURE= False
|
2006-07-29 07:14:11 +00:00
|
|
|
|
2006-07-31 15:22:20 +00:00
|
|
|
def file_sel(PREF_IMAGE_PATH):
|
2006-09-25 19:35:43 +00:00
|
|
|
|
|
|
|
if not (BPyMessages.Warning_SaveOver(PREF_IMAGE_PATH) and \
|
|
|
|
BPyMessages.Warning_SaveOver(PREF_IMAGE_PATH+'.png')):
|
|
|
|
return
|
|
|
|
|
|
|
|
image = BPyRender.vcol2image(me_s,\
|
2006-07-31 15:22:20 +00:00
|
|
|
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)
|
|
|
|
|
2006-09-25 19:35:43 +00:00
|
|
|
if image:
|
|
|
|
image.makeCurrent()
|
|
|
|
|
2006-07-31 15:22:20 +00:00
|
|
|
Blender.Window.RedrawAll()
|
2006-07-29 07:14:11 +00:00
|
|
|
|
2006-07-31 15:22:20 +00:00
|
|
|
Blender.Window.FileSelector(file_sel, 'SAVE PNG', newpath)
|
2006-07-29 07:14:11 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|