Paste Code
Paste Blends
Paste Images
# PSL SNAPSHOT v1.0 - 3Dview Addon - Blender 2.5x
#
# THIS SCRIPT IS LICENSED UNDER GPL,
# please read the license block.
#
# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####



# FOR SOME REASON LIKE ADDON DON'T WORK WELL---------------------------------------------


#bl_info = {
# "name": "PSL_SnapShot",
# "author": "Daniel M. Lara & Jose Molina http://josemolinagarcia.blogspot.com",
# "link": "http://josemolinagarcia.blogspot.com",
# "version": (1, 0),
# "blender": (2, 6, 0),
# "api": 35853,
# "location": "View3D > Nkey Panel > PSL SnapShot",
# "description": "Make SnapShots from Animated Meshes",
# "warning": "",
# "category": "Animation"}
#------------------------------------------------------------------------------------------------------



# import the basic library


bl_info = {
"name": "PSL_SnapShot",
"author": "Daniel M. Lara & Jose Molina http://josemolinagarcia.blogspot.com",
"link": "http://josemolinagarcia.blogspot.com",
"version": (1, 0),
"blender": (2, 6, 0),
"api": 35853,
"location": "View3D > Nkey Panel > PSL SnapShot",
"description": "Make SnapShots from Animated Meshes",
"warning": "",
"category": "Animation"}

# import the basic library
import bpy
import os

prefixpsl = 'PSL_'

snapshotSource = prefixpsl +'snapshotSource'
snapshotInstances = prefixpsl +'snapshotInstances'

nameMaterialSlot = prefixpsl + 'SNAPSHOT_SLOT'
nameMaterialGray = prefixpsl + 'SNAPSHOT_GRAY'
nameMaterialBlack = prefixpsl + 'SNAPSHOT_BLACK'
nameMaterialCustom = prefixpsl + 'SNAPSHOT_CUSTOM'

nameObjectPrefix = prefixpsl + "SNAPSHOT_"
nameEmptyDad = prefixpsl + "SNAPSHOT_DAD"

def initializeMaterials():
#check if exists
try:
materialgray = bpy.data.materials[nameMaterialGray]
except:
#create it
materialgray = bpy.data.materials.new(nameMaterialGray)
materialgray.diffuse_color=[.5,.5,.5]
materialgray.diffuse_intensity = 1.0
materialgray.specular_intensity = .0
materialgray.use_fake_user = True
#check if exists
try:
materialblack = bpy.data.materials[nameMaterialBlack]
except:
#create it
materialblack = materialgray.copy()
materialblack.name = nameMaterialBlack
materialblack.diffuse_color=[0.0,0.0,0.0]
materialblack.use_fake_user = True

try:
materialcustom = bpy.data.materials[nameMaterialCustom]
except:
materialcustom = materialgray.copy()
materialcustom.name = nameMaterialCustom
materialcustom.diffuse_color=[1.0,0.0,0.0]
materialcustom.use_fake_user = True


def initializeSnpashotGroups():
try:
group = bpy.data.groups[snapshotSource]
except:
bpy.data.groups.new(snapshotSource)

try:
group = bpy.data.groups[snapshotInstances]
except:
bpy.data.groups.new(snapshotInstances)


def initializePSLsnapshot():

actual_object = ""
actual_mode = bpy.context.mode
scn = bpy.context.scene

try:
actual_object = context.active_object.name
except:
pass
if bpy.context.mode != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_pattern(pattern="",extend=False)

createEmptyGroup()
initializeSnpashotGroups()
initializeMaterials()


bpy.ops.object.select_pattern(pattern=actual_object,extend=False)
try:
scn.objects.active = scn.objects[actual_object]
bpy.ops.object.mode_set(mode=actual_mode)
except:
pass


def addObjectsToSource(context):
objects_to_add = [obj.name for obj in bpy.context.selected_objects if obj.type == 'MESH']
scn = bpy.context.scene
for name in objects_to_add:
scn.objects.active = scn.objects[name]
bpy.ops.object.group_link(group=snapshotSource)

def createEmptyGroup():
#check if exists
actual_selected = bpy.context.selected_objects[:]
try:
dad = bpy.data.objects[nameEmptyDad]
except:
#create
scn = bpy.context.scene
bpy.ops.object.add(type='EMPTY', view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0))
new_empty = scn.objects.active
new_empty.name = nameEmptyDad
for object in bpy.data.objects:
if object in actual_selected:
object.select = True
else:
object.select = False

class PSL_AddToSourceGroup(bpy.types.Operator):
bl_idname = "object.addtosourcegroup"
bl_label = "Add To Source Group"
bl_description = "Add element to source group"

@classmethod
def poll(cls, context):
sel_objects = bpy.context.selected_objects
if len(sel_objects) == 0 :
return False
all_mesh = True
for object in sel_objects:
if object.type != 'MESH':
all_mesh = False
return all_mesh
return all_mesh

def execute(self, context):
try:
#initializePSLsnapshot()
addObjectsToSource(context)
except:
self.report(type={'ERROR'}, message="Error adding to the source" )
return {'FINISHED'}

class PSL_DeleteFromSourceGroup(bpy.types.Operator):
bl_idname = "object.deletefromsourcegroup"
bl_label = "Delete from Source Group"
bl_description = "Delete element from source group"

@classmethod
def poll(cls, context):
try:
objects = bpy.data.groups[snapshotSource].objects
sel_objects = context.selected_objects
for each_object in objects:
is_there = False
for each_selobject in sel_objects:
if each_selobject == each_object:
is_there = True
return is_there

return is_there
except:
return False
return False
return True#context.active_object is not None

def execute(self, context):
try:
sel_objects = context.selected_objects
source_Group = bpy.data.groups[snapshotSource]
for selobject in sel_objects:
try:
source_Group.objects.unlink(selobject)
except:
raise

except:
self.report(type={'ERROR'}, message="Error removing from source" )
return {'FINISHED'}

def changeGroup (context,object):
scn = context.scene
scn.objects.active = scn.objects[object.name]
try:
bpy.ops.group.objects_remove_active()
except:
pass
bpy.ops.object.group_link(group=snapshotInstances)


def applyMaterial (context, object,materialname):
scn = context.scene
scn.objects.active = scn.objects[object.name]
bpy.ops.object.material_slot_add()
slot = object.material_slots['']
#slot.name = nameMaterialSlot
slot.material = bpy.data.materials[materialname]

def exportImportObj(object):
newObject = None
print("************************** " + object.name)
filename = bpy.data.filepath.split(os.sep)[ len(bpy.data.filepath.split(os.sep))-1:][0]


filepathbas= bpy.data.filepath.replace(filename,"")#'/tmp/'
filepathobj=filepathbas+'psl_snapshot_temp.obj'
filepathmtl=filepathbas+'psl_snapshot_temp.mtl'

#bpy.ops.object.select_pattern(pattern="",extend=False)
bpy.ops.object.select_pattern(pattern=object.name,extend=False)
#scene.objects.active = scene.objects[object.name]

bpy.ops.export_scene.obj(filepath=filepathobj,use_selection=True, use_materials=False)
bpy.ops.import_scene.obj(filepath=filepathobj)

try:
os.remove(filepathobj)
except:
pass
try:
os.remove(filepathmtl)
except:
pass
return newObject




#NEW diplicateObjects in obj
def duplicateObjects(context,material):
objects = bpy.data.groups[snapshotSource].objects
scn = bpy.context.scene
for eachobject in objects:
if eachobject in context.visible_objects:
exportImportObj(eachobject)
newobject = context.selected_objects[0]
newobject.name = eachobject.name
newobject.name = nameObjectPrefix + newobject.name.split(".")[0] + "__"+ str(scn.frame_current)

changeGroup(context,newobject)
#applyMaterial
if material == "GRAY":
applyMaterial (context, newobject,nameMaterialGray)
if material == "BLACK":
applyMaterial (context, newobject,nameMaterialBlack)
if material == "CUSTOM":
applyMaterial (context, newobject,nameMaterialCustom)

#set parent
newobject.parent = bpy.data.objects[nameEmptyDad]

#decimate
decimate = newobject.modifiers.new(name="decimate", type='DECIMATE')
decimate.ratio = scn.psl_decimate_ratio


def generateSnapshot ( self, context):
selected_objects = bpy.context.selected_objects[:]
original_layers = bpy.context.scene.layers[:]
actual_object = ""
actual_mode = context.mode
scn = context.scene
try:
actual_object = context.active_object.name
except:
pass

if context.mode != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')

for i in range(len(bpy.context.scene.layers)):
bpy.context.scene.layers[i] = True

bpy.ops.object.select_pattern(pattern="",extend=False)
bpy.context.scene.objects.active = None
bpy.context.scene.layers = original_layers

material = scn.psl_snapshot_material
duplicateObjects(context,material)


for object in context.scene.objects:
if object in selected_objects:
object.select = True
else:
object.select = False


try:
scn.objects.active = scn.objects[actual_object]
bpy.ops.object.mode_set(mode=actual_mode)
except:
pass




class PSL_MakeSnapshot(bpy.types.Operator):
'''Tooltip'''
bl_idname = "object.make_snapshot"
bl_label = "Make Snapshot"
bl_options = {'REGISTER', 'UNDO'}
bl_description = "Make Snapshot!"

material = bpy.props.StringProperty(name="material", description="Material", default="GRAY")

@classmethod
def poll(cls, context):
try:
objects = bpy.data.groups[snapshotSource].objects
if len(objects) > 0 :
return True
else:
return False
except:
return False
return False

def execute(self, context):

try:
scn = context.scene
if not scn.psl_generate_all:
CleanExistingSnapshot (context)
generateSnapshot ( self, context)
else:
last_frame = False
CleanAllSnapshots ( context )
scn.frame_set(scn.psl_snapshot_start)
generateSnapshot ( self, context)

while (not last_frame) and (scn.frame_current < scn.psl_snapshot_end):
actual_frame = scn.frame_current

bpy.ops.screen.keyframe_jump(next=True)
if actual_frame != scn.frame_current:
generateSnapshot ( self, context)
else:
last_frame = True


if not scn.psl_generate_all and scn.psl_jump_next_frame:
bpy.ops.screen.keyframe_jump(next=True)
except:
self.report(type={'ERROR'}, message="Error making snapshot" )
return {'FINISHED'}



def CleanExistingSnapshot (context):

scn = context.scene
'''
bpy.ops.object.select_pattern(pattern='',extend=False)
bpy.ops.object.select_pattern(pattern='*'+ nameObjectPrefix + '*'+ str(scn.frame_current) +'*',extend=False)
objects = context.selected_objects
'''
objects = []
for object in scn.objects:
if nameObjectPrefix in object.name:
end = object.name.split("__")[len(object.name.split("__"))-1]
if str(scn.frame_current) == end:
objects.append(object)
CleanSnapshots(context, objects)

def CleanAllSnapshots ( context ):
objects = bpy.data.groups[snapshotInstances].objects
CleanSnapshots(context,objects)

def CleanSnapshot (context, object):
bpy.ops.object.select_pattern(pattern="",extend=False)

scn = context.scene
object.hide_select = False
object.select = True

bpy.ops.object.delete()

'''
bpy.ops.object.select_pattern(pattern=object.name,extend=False)
bpy.ops.object.delete()
bpy.ops.object.select_pattern(pattern=object.name,extend=False)
bpy.ops.object.delete()
'''

def CleanSnapshots ( context, objects ):
something_selected = len(bpy.context.selected_objects) > 0

actual_object = ""
actual_mode = context.mode

try:
actual_object = context.active_object.name
except:
pass

if context.mode != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')

bpy.ops.object.select_pattern(pattern="",extend=False)
scn = context.scene
#objects = bpy.data.groups[snapshotInstances].objects
for object in objects:
CleanSnapshot(context, object)


bpy.ops.object.select_pattern(pattern=actual_object,extend=False)

scn = context.scene
try:
scn.objects.active = scn.objects[actual_object]
bpy.ops.object.mode_set(mode=actual_mode)
except:
pass


class PSL_CleanSnapshots(bpy.types.Operator):
'''Tooltip'''
bl_idname = "object.clean_snapshots"
bl_label = "Clean Spanshots"
bl_description = "Delete Current Frame Snapshot"

all = bpy.props.BoolProperty(name="All", description="Delete all snapshots", default=False)

@classmethod
def poll(cls, context):
return True

def execute(self, context):
try:
if (self.all):
objects = bpy.data.groups[snapshotInstances].objects
CleanSnapshots(context,objects)
else:
CleanExistingSnapshot(context)
if context.scene.psl_jump_next_frame:
bpy.ops.screen.keyframe_jump(next=True)

except:
self.report(type={'ERROR'}, message="Error deleting snapshot" )
return {'FINISHED'}


class PSL_SnapshotVisible(bpy.types.Operator):
bl_idname = "object.snapshot_visible"
bl_label = "Enable / Disable Visibility Snapshot"
bl_description = "Show / Hide snapshots"

visible = bpy.props.BoolProperty(name="Visible", description="make visible", default=False)

@classmethod
def poll(cls, context):
return True
def execute(self, context):
try:
objects = bpy.data.groups[snapshotInstances].objects
for object in objects:
object.hide = not self.visible
bpy.types.PSL_SnapshotUI.visible = self.visible
except:
self.report(type={'ERROR'}, message="Error while enabling / disabling visibility of the snapshots" )
return {'FINISHED'}

class PSL_SnapshotRendereable(bpy.types.Operator):
bl_idname = "object.snapshot_renderable"
bl_label = "Enable / Disable Render Snapshot"
bl_description = "Enable / Disable render snapshots"

rendeable = bpy.props.BoolProperty(name="Rendeable", description="make rendeable", default=False)

@classmethod
def poll(cls, context):
return True
def execute(self, context):
try:
objects = bpy.data.groups[snapshotInstances].objects
for object in objects:
object.hide_render = not self.rendeable
bpy.types.PSL_SnapshotUI.rendeable = self.rendeable
except:
self.report(type={'ERROR'}, message="Error while enabling / disabling render of the snapshots" )
return {'FINISHED'}

class PSL_SnapshotSelectable(bpy.types.Operator):
bl_idname = "object.snapshot_selectable"
bl_label = "Select / Deselect snapshot"
bl_description = "Enable / Disable select snapshots"

selectable = bpy.props.BoolProperty(name="Selectable", description="make selectable", default=False)

@classmethod
def poll(cls, context):
return True
def execute(self, context):
try:
objects = bpy.data.groups[snapshotInstances].objects
for object in objects:
object.hide_select = not self.selectable
bpy.types.PSL_SnapshotUI.selectable = self.selectable
except:
self.report(type={'ERROR'}, message="Error while enabling / disabling select of the snapshots" )
return {'FINISHED'}

class PSL_DecimateVisible(bpy.types.Operator):
bl_idname = "object.decimate_visible"
bl_label = "Enable / Disable visibility decimate"
bl_description = "Enable / Disable visibility decimate modifier"

visible = bpy.props.BoolProperty(name="Visible", description="make visible", default=False)

@classmethod
def poll(cls, context):
return True
def execute(self, context):
try:
objects = bpy.data.groups[snapshotInstances].objects
for object in objects:
object.modifiers['decimate'].show_viewport = not self.visible
bpy.types.PSL_SnapshotUI.visible_decimate = self.visible
except:
self.report(type={'ERROR'}, message="Error while enabling / disabling visibility of the decimate" )
return {'FINISHED'}

class PSL_DecimateRendereable(bpy.types.Operator):
bl_idname = "object.decimate_renderable"
bl_label = "Enable / Disable render of decimate"
bl_description = "Enable / Disable render decimate modifier"

rendeable = bpy.props.BoolProperty(name="Rendeable", description="make rendeable", default=False)

@classmethod
def poll(cls, context):
return True
def execute(self, context):
try:
objects = bpy.data.groups[snapshotInstances].objects
for object in objects:
object.modifiers['decimate'].show_render = not self.rendeable
bpy.types.PSL_SnapshotUI.rendeable_decimate = self.rendeable
except:
self.report(type={'ERROR'}, message="Error while enabling / disabling render of the decimate" )
return {'FINISHED'}

class PSL_DecimateUpdate(bpy.types.Operator):
bl_idname = "object.decimate_update"
bl_label = "Update decimate ratio"
bl_description = "Update decimate modifier"
@classmethod
def poll(cls, context):
return True
def execute(self, context):
try:
objects = bpy.data.groups[snapshotInstances].objects
for object in objects:
object.modifiers['decimate'].ratio = context.scene.psl_decimate_ratio
except:
self.report(type={'ERROR'}, message="Error while updating the decimate" )
return {'FINISHED'}

class PSL_RadioButtonMaterial(bpy.types.Operator):
bl_idname = "object.pls_rdbmaterial"
bl_label = "Update radio button material"
bl_description = "Select Material"
material = bpy.props.StringProperty(name="material", description="material", default="BLACK")

@classmethod
def poll(cls, context):
return True
def execute(self, context):
try:
scn = context.scene
scn.psl_snapshot_material = self.material
except:
self.report(type={'ERROR'}, message="Error updating material" )
return {'FINISHED'}

class PSL_Snapshot_Initialize(bpy.types.Operator):
bl_idname = "object.psl_snp_initialize"
bl_label = "Initialize"
bl_description = "Re/Generate all necesary for the addon "

@classmethod
def poll(cls, context):
return True
def execute(self, context):
try:
initializePSLsnapshot()
except:
self.report(type={'ERROR'}, message="Error while initializing the addon" )
return {'FINISHED'}

class PSL_SnapshotUI(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_label = "PSL SnapShot"

material = bpy.props.BoolProperty(name="gray_material", description="gray_material", default=False)
selectable = bpy.props.BoolProperty(name="Selectable", description="make selectable", default=False)
rendeable = bpy.props.BoolProperty(name="Rendeable", description="make rendeable", default=False)
visible = bpy.props.BoolProperty(name="Visible", description="make visible", default=False)

rendeable_decimate = bpy.props.BoolProperty(name="Rendeable Decimate", description="make rendeable", default=False)
visible_decimate = bpy.props.BoolProperty(name="Visible Decimate", description="make visible", default=False)

def draw(self, context):
layout = self.layout
scn = bpy.context.scene
regenerar = False
try:
m1 = bpy.data.materials[nameMaterialBlack]
m2 = bpy.data.materials[nameMaterialGray]
m3 = bpy.data.materials[nameMaterialCustom]
except:
regenerar = True

if not regenerar:
#OBJ operators
colobjs = layout.column()
colobjs.label(text="Objs to Snapshot:")
operator = colobjs.operator("object.addtosourcegroup",text="Add to List",icon='EXPORT')
operator = colobjs.operator("object.deletefromsourcegroup",text="Delete from List",icon='X')
colobjs.label(text="")


#snapshot Operator

colsnapshot = layout.row(align=True)
colsnapshot.label(text="Snapshots") #, icon='GROUP')

if self.visible :
operator = colsnapshot.operator("object.snapshot_visible",text="",icon='RESTRICT_VIEW_OFF')
operator.visible=False
else:
operator = colsnapshot.operator("object.snapshot_visible",text="",icon='RESTRICT_VIEW_ON')
operator.visible=True

if self.selectable:
operator = colsnapshot.operator("object.snapshot_selectable",text="",icon='RESTRICT_SELECT_OFF')
operator.selectable=False
else:
operator = colsnapshot.operator("object.snapshot_selectable",text="",icon='RESTRICT_SELECT_ON')
operator.selectable=True

if self.rendeable :
operator = colsnapshot.operator("object.snapshot_renderable",text="",icon='RESTRICT_RENDER_OFF')
operator.rendeable=False
else:
operator = colsnapshot.operator("object.snapshot_renderable",text="",icon='RESTRICT_RENDER_ON')
operator.rendeable=True

colbuttonsnpshot = layout.row(align=True)
colbuttonsnpshot.scale_y = 2
colbuttonsnpshot.prop ( scn,"psl_jump_next_frame", icon='FF',text="")
operator = colbuttonsnpshot.operator("object.make_snapshot",text="Make snapshot",icon='NONE')
operator = colbuttonsnpshot.operator("object.clean_snapshots",text="",icon='X')
operator.all = False


layout.separator()

colgekeyscheck = layout.column()
colgekeyscheck.prop ( scn, "psl_generate_all")#, icon ='SCRIPTPLUGINS')
colgekeys = layout.row(align=True)
colgekeys.enabled = scn.psl_generate_all
colgekeys.prop ( scn,"psl_snapshot_start")
colgekeys.prop ( scn,"psl_snapshot_end")



col = layout.row()

boxcolors = col.box()


if scn.psl_snapshot_material == 'BLACK':
row = boxcolors.row()
col1 = row.column()
operator = col1.operator("object.pls_rdbmaterial",text="Color1",icon='RADIOBUT_ON',emboss=False)
operator.material = "BLACK"
col1.active = True
col2 = row.column()
col2.prop ( bpy.data.materials[nameMaterialBlack],"diffuse_color",text ="", icon_only=True)
col2.enabled = True

row = boxcolors.row()
col1 = row.column()
operator = col1.operator("object.pls_rdbmaterial",text="Color2",icon='RADIOBUT_OFF',emboss=False)
operator.material = "GRAY"
col1.active = False
col2 = row.column()
col2.prop ( bpy.data.materials[nameMaterialGray],"diffuse_color",text ="", icon_only=True)
col2.enabled = True

row = boxcolors.row()
col1 = row.column()
operator = col1.operator("object.pls_rdbmaterial",text="Color3",icon='RADIOBUT_OFF',emboss=False)
operator.material = "CUSTOM"
col1.active = False
col2 = row.column()
col2.prop ( bpy.data.materials[nameMaterialCustom],"diffuse_color",text ="", icon_only=True)
col2.enabled = True

if scn.psl_snapshot_material == 'GRAY':
row = boxcolors.row()
col1 = row.column()
operator = col1.operator("object.pls_rdbmaterial",text="Color1",icon='RADIOBUT_OFF',emboss=False)
operator.material = "BLACK"
col1.active = False
col2 = row.column()
col2.prop ( bpy.data.materials[nameMaterialBlack],"diffuse_color",text ="", icon_only=True)
col2.enabled = True

row = boxcolors.row()
col1 = row.column()
operator = col1.operator("object.pls_rdbmaterial",text="Color2",icon='RADIOBUT_ON',emboss=False)
operator.material = "GRAY"
col1.active = True
col2 = row.column()
col2.prop ( bpy.data.materials[nameMaterialGray],"diffuse_color",text ="", icon_only=True)
col2.enabled = True

row = boxcolors.row()
col1 = row.column()
operator = col1.operator("object.pls_rdbmaterial",text="Color3",icon='RADIOBUT_OFF',emboss=False)
operator.material = "CUSTOM"
col1.active = False
col2 = row.column()
col2.prop ( bpy.data.materials[nameMaterialCustom],"diffuse_color",text ="", icon_only=True)
col2.enabled = True
if scn.psl_snapshot_material == 'CUSTOM':
row = boxcolors.row()
col1 = row.column()
operator = col1.operator("object.pls_rdbmaterial",text="Color1",icon='RADIOBUT_OFF',emboss=False)
operator.material = "BLACK"
col1.active = False
col2 = row.column()
col2.prop ( bpy.data.materials[nameMaterialBlack],"diffuse_color",text ="", icon_only=True)
col2.enabled = True

row = boxcolors.row()
col1 = row.column()
operator = col1.operator("object.pls_rdbmaterial",text="Color2",icon='RADIOBUT_OFF',emboss=False)
operator.material = "GRAY"
col1.active = False
col2 = row.column()
col2.prop ( bpy.data.materials[nameMaterialGray],"diffuse_color",text ="", icon_only=True)
col2.enabled = True

row = boxcolors.row()
col1 = row.column()
operator = col1.operator("object.pls_rdbmaterial",text="Color3",icon='RADIOBUT_ON',emboss=False)
operator.material = "CUSTOM"
col1.active = True
col2 = row.column()
col2.prop ( bpy.data.materials[nameMaterialCustom],"diffuse_color",text ="", icon_only=True)
col2.enabled = True





layout.separator()

rowcleansnapshot = layout.row(align=False)
rowcleansnapshot.label(text="Optimize Snapshot Meshes:") #, icon='GROUP')

type_vis = True
coldecimate = layout.row(align=True)
coldecimate.prop(scn,"psl_decimate_ratio")
operator =coldecimate.operator("object.decimate_update",text="",icon='FILE_REFRESH',emboss=type_vis)

coldecimate.separator()

if self.visible_decimate :
operator = coldecimate.operator("object.decimate_visible",text="",icon='RESTRICT_VIEW_ON',emboss=type_vis)
operator.visible=False
else:
operator = coldecimate.operator("object.decimate_visible",text="",icon='RESTRICT_VIEW_OFF',emboss=type_vis)
operator.visible=True


if self.rendeable_decimate :
operator = coldecimate.operator("object.decimate_renderable",text="",icon='RESTRICT_RENDER_OFF',emboss=type_vis)
operator.rendeable=False
else:
#col = col.box()
operator = coldecimate.operator("object.decimate_renderable",text="",icon='RESTRICT_RENDER_ON',emboss=type_vis)
operator.rendeable=True

layout.separator()

rowcleanall = layout.row(align=True)

rowcleanall.scale_y = 1
operator = rowcleanall.operator("object.clean_snapshots",text="Clean All Snapshots",icon='CANCEL')
operator.all = True

# if there aren't elements in source
num_objects = len(bpy.data.groups[snapshotSource].objects)
if num_objects == 0 :
#col.enabled = False
colsnapshot.enabled = False
boxcolors.enabled = False
colbuttonsnpshot.enabled = False
colgekeyscheck.enabled = False
colgekeys.enabled = False
coldecimate.enabled = False
rowcleanall.enabled = False
rowcleansnapshot.enabled = False


else:
colobjs = layout.column()
#colobjs.label(text="Objs to Snapshot:")
operator = colobjs.operator("object.psl_snp_initialize",text="Initialize",icon='EXPORT')


def register():
# Define properties for the draw setting.

bpy.types.Scene.psl_generate_all = bpy.props.BoolProperty(
name="Do it in all keyframes",
description="Generate Snapshots in all Keyframes from start to end",
default=0)
bpy.types.Scene.psl_snapshot_start = bpy.props.IntProperty(
name="Start",
description="From frame snapshot",
default=0)
bpy.types.Scene.psl_snapshot_end = bpy.props.IntProperty(
name="End",
description="To end snapshot",
default=150)

bpy.types.Scene.psl_jump_next_frame = bpy.props.BoolProperty(
name="Jump next key-frame",
description="When on jump to next key-frame after make snapshot",
default=0)

bpy.types.Scene.psl_decimate_ratio = bpy.props.FloatProperty(
name="Decimate Ratio",
description="Value of the decimate modifier",
max=1,
min=0,
default=1.0)

bpy.types.Scene.psl_decimate_renderable = bpy.props.BoolProperty(
name="Render decimate",
description="Enable / disable renderable decimate",
default=1)
bpy.types.Scene.psl_decimate_visibility = bpy.props.BoolProperty(
name="Render visualize",
description="Enable / disable visibility decimate",
default=1)

bpy.types.Scene.psl_snapshot_material = bpy.props.StringProperty(
name="Snapshot Material",
description="Enable / disable visibility decimate",
default="BLACK")

bpy.utils.register_class(PSL_AddToSourceGroup)
bpy.utils.register_class(PSL_DeleteFromSourceGroup)
bpy.utils.register_class(PSL_MakeSnapshot)
bpy.utils.register_class(PSL_CleanSnapshots)
bpy.utils.register_class(PSL_SnapshotRendereable)
bpy.utils.register_class(PSL_SnapshotSelectable)
bpy.utils.register_class(PSL_SnapshotUI)
bpy.utils.register_class(PSL_SnapshotVisible)

bpy.utils.register_class(PSL_RadioButtonMaterial)

bpy.utils.register_class(PSL_DecimateVisible)
bpy.utils.register_class(PSL_DecimateRendereable)
bpy.utils.register_class(PSL_DecimateUpdate)

bpy.utils.register_class(PSL_Snapshot_Initialize)

#,initializePSLsnapshot()


def unregister():
bpy.utils.unregister_class(PSL_AddToSourceGroup)
bpy.utils.unregister_class(PSL_DeleteFromSourceGroup)
bpy.utils.unregister_class(PSL_MakeSnapshot)
bpy.utils.unregister_class(PSL_CleanSnapshots)
bpy.utils.unregister_class(PSL_SnapshotRendereable)
bpy.utils.unregister_class(PSL_SnapshotSelectable)
bpy.utils.unregister_class(PSL_SnapshotUI)
bpy.utils.unregister_class(PSL_SnapshotVisible)

bpy.utils.unregister_class(PSL_RadioButtonMaterial)

bpy.utils.unregister_class(PSL_DecimateVisible)
bpy.utils.unregister_class(PSL_DecimateRendereable)
bpy.utils.unregister_class(PSL_DecimateUpdate)

bpy.utils.unregister_class(PSL_Snapshot_Initialize)

del bpy.types.Scene.psl_generate_all
del bpy.types.Scene.psl_snapshot_start
del bpy.types.Scene.psl_snapshot_end
del bpy.types.Scene.psl_jump_next_frame
del bpy.types.Scene.psl_decimate_ratio
del bpy.types.Scene.psl_decimate_renderable
del bpy.types.Scene.psl_decimate_visibility
del bpy.types.Scene.psl_snapshot_material


if __name__ == "__main__":
register()
  1. # PSL SNAPSHOT v1.0 - 3Dview Addon - Blender 2.5x
  2. #
  3. # THIS SCRIPT IS LICENSED UNDER GPL,
  4. # please read the license block.
  5. #
  6. # ##### BEGIN GPL LICENSE BLOCK #####
  7. #
  8. #  This program is free software; you can redistribute it and/or
  9. #  modify it under the terms of the GNU General Public License
  10. #  as published by the Free Software Foundation; either version 2
  11. #  of the License, or (at your option) any later version.
  12. #
  13. #  This program is distributed in the hope that it will be useful,
  14. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #  GNU General Public License for more details.
  17. #
  18. #  You should have received a copy of the GNU General Public License
  19. #  along with this program; if not, write to the Free Software Foundation,
  20. #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  21. #
  22. # ##### END GPL LICENSE BLOCK #####
  23.  
  24.  
  25.  
  26. # FOR SOME REASON LIKE ADDON DON'T WORK WELL---------------------------------------------
  27.  
  28.  
  29. #bl_info = {
  30. #    "name": "PSL_SnapShot",
  31. #    "author": "Daniel M. Lara & Jose Molina   http://josemolinagarcia.blogspot.com",
  32. #    "link": "http://josemolinagarcia.blogspot.com",
  33. #    "version": (1, 0),
  34. #   "blender": (2, 6, 0),
  35. #    "api": 35853,
  36. #    "location": "View3D > Nkey Panel > PSL SnapShot",
  37. #    "description": "Make SnapShots from Animated Meshes",
  38. #   "warning": "",
  39.  #   "category": "Animation"}
  40. #------------------------------------------------------------------------------------------------------
  41.  
  42.  
  43.  
  44. # import the basic library
  45.  
  46.  
  47. bl_info = {
  48.     "name": "PSL_SnapShot",
  49.     "author": "Daniel M. Lara & Jose Molina   http://josemolinagarcia.blogspot.com",
  50.     "link": "http://josemolinagarcia.blogspot.com",
  51.     "version": (1, 0),
  52.     "blender": (2, 6, 0),
  53.     "api": 35853,
  54.     "location": "View3D > Nkey Panel > PSL SnapShot",
  55.     "description": "Make SnapShots from Animated Meshes",
  56.     "warning": "",
  57.     "category": "Animation"}
  58.  
  59. # import the basic library
  60. import bpy
  61. import os
  62.  
  63. prefixpsl = 'PSL_'
  64.  
  65. snapshotSource = prefixpsl +'snapshotSource'
  66. snapshotInstances = prefixpsl +'snapshotInstances'
  67.  
  68. nameMaterialSlot   = prefixpsl + 'SNAPSHOT_SLOT'
  69. nameMaterialGray   = prefixpsl + 'SNAPSHOT_GRAY'
  70. nameMaterialBlack  = prefixpsl + 'SNAPSHOT_BLACK'
  71. nameMaterialCustom = prefixpsl + 'SNAPSHOT_CUSTOM'
  72.  
  73. nameObjectPrefix = prefixpsl + "SNAPSHOT_"
  74. nameEmptyDad = prefixpsl + "SNAPSHOT_DAD"
  75.  
  76. def initializeMaterials():
  77.     #check if exists
  78.     try:
  79.         materialgray = bpy.data.materials[nameMaterialGray]
  80.     except:
  81.         #create it
  82.         materialgray = bpy.data.materials.new(nameMaterialGray)
  83.         materialgray.diffuse_color=[.5,.5,.5]
  84.         materialgray.diffuse_intensity = 1.0
  85.         materialgray.specular_intensity = .0
  86.         materialgray.use_fake_user = True
  87.     #check if exists
  88.     try:    
  89.         materialblack = bpy.data.materials[nameMaterialBlack]
  90.     except:  
  91.         #create it      
  92.         materialblack = materialgray.copy()
  93.         materialblack.name = nameMaterialBlack
  94.         materialblack.diffuse_color=[0.0,0.0,0.0]
  95.         materialblack.use_fake_user = True
  96.    
  97.     try:
  98.         materialcustom = bpy.data.materials[nameMaterialCustom]
  99.     except:
  100.         materialcustom = materialgray.copy()
  101.         materialcustom.name = nameMaterialCustom
  102.         materialcustom.diffuse_color=[1.0,0.0,0.0]
  103.         materialcustom.use_fake_user = True
  104.        
  105.  
  106. def initializeSnpashotGroups():
  107.     try:
  108.         group = bpy.data.groups[snapshotSource]                
  109.     except:
  110.         bpy.data.groups.new(snapshotSource)
  111.    
  112.     try:
  113.         group = bpy.data.groups[snapshotInstances]                
  114.     except:
  115.         bpy.data.groups.new(snapshotInstances)
  116.  
  117.  
  118. def initializePSLsnapshot():
  119.  
  120.     actual_object = ""        
  121.     actual_mode = bpy.context.mode
  122.     scn = bpy.context.scene
  123.    
  124.     try:
  125.         actual_object =  context.active_object.name            
  126.     except:
  127.         pass    
  128.     if bpy.context.mode != 'OBJECT':
  129.          bpy.ops.object.mode_set(mode='OBJECT')        
  130.     bpy.ops.object.select_pattern(pattern="",extend=False)
  131.    
  132.     createEmptyGroup()
  133.     initializeSnpashotGroups()  
  134.     initializeMaterials()
  135.  
  136.    
  137.     bpy.ops.object.select_pattern(pattern=actual_object,extend=False)            
  138.     try:    
  139.         scn.objects.active = scn.objects[actual_object]    
  140.         bpy.ops.object.mode_set(mode=actual_mode)      
  141.     except:
  142.         pass
  143.      
  144.        
  145. def addObjectsToSource(context):
  146.     objects_to_add = [obj.name for obj in bpy.context.selected_objects if obj.type == 'MESH']  
  147.     scn = bpy.context.scene  
  148.     for name in objects_to_add:  
  149.         scn.objects.active = scn.objects[name]  
  150.         bpy.ops.object.group_link(group=snapshotSource)
  151.  
  152. def createEmptyGroup():
  153.     #check if exists
  154.     actual_selected = bpy.context.selected_objects[:]
  155.     try:
  156.         dad = bpy.data.objects[nameEmptyDad]
  157.     except:            
  158.         #create
  159.         scn = bpy.context.scene
  160.         bpy.ops.object.add(type='EMPTY', view_align=False, enter_editmode=False, location=(0, 0, 0), rotation=(0, 0, 0))
  161.         new_empty = scn.objects.active
  162.         new_empty.name = nameEmptyDad
  163.     for object in bpy.data.objects:
  164.         if object in actual_selected:
  165.             object.select = True
  166.         else:
  167.             object.select = False
  168.            
  169. class PSL_AddToSourceGroup(bpy.types.Operator):
  170.     bl_idname = "object.addtosourcegroup"
  171.     bl_label = "Add To Source Group"
  172.     bl_description = "Add element to source group"
  173.  
  174.     @classmethod
  175.     def poll(cls, context):
  176.         sel_objects = bpy.context.selected_objects
  177.         if len(sel_objects) == 0 :
  178.             return False
  179.         all_mesh = True
  180.         for object in sel_objects:
  181.             if  object.type != 'MESH':
  182.                 all_mesh = False
  183.                 return all_mesh
  184.         return all_mesh
  185.  
  186.     def execute(self, context):
  187.         try:
  188.             #initializePSLsnapshot()    
  189.             addObjectsToSource(context)                    
  190.         except:
  191.             self.report(type={'ERROR'}, message="Error adding to the source" )
  192.         return {'FINISHED'}
  193.    
  194. class PSL_DeleteFromSourceGroup(bpy.types.Operator):
  195.     bl_idname = "object.deletefromsourcegroup"
  196.     bl_label = "Delete from Source Group"
  197.     bl_description = "Delete element from source group"
  198.  
  199.     @classmethod
  200.     def poll(cls, context):
  201.         try:
  202.             objects = bpy.data.groups[snapshotSource].objects
  203.             sel_objects = context.selected_objects            
  204.             for each_object in objects:
  205.                 is_there = False
  206.                 for each_selobject in sel_objects:
  207.                     if each_selobject == each_object:
  208.                         is_there = True
  209.                         return is_there
  210.                    
  211.             return is_there
  212.         except:
  213.             return False
  214.         return False
  215.         return True#context.active_object is not None
  216.  
  217.     def execute(self, context):
  218.         try:
  219.             sel_objects = context.selected_objects
  220.             source_Group = bpy.data.groups[snapshotSource]
  221.             for selobject in sel_objects:
  222.                 try:
  223.                    source_Group.objects.unlink(selobject)
  224.                 except:
  225.                     raise
  226.            
  227.         except:
  228.             self.report(type={'ERROR'}, message="Error removing from source" )
  229.         return {'FINISHED'}
  230.  
  231. def changeGroup (context,object):    
  232.     scn = context.scene  
  233.     scn.objects.active = scn.objects[object.name]  
  234.     try:
  235.         bpy.ops.group.objects_remove_active()
  236.     except:
  237.         pass
  238.     bpy.ops.object.group_link(group=snapshotInstances)
  239.  
  240.  
  241. def applyMaterial (context, object,materialname):
  242.     scn = context.scene
  243.     scn.objects.active = scn.objects[object.name]
  244.     bpy.ops.object.material_slot_add()
  245.     slot = object.material_slots['']
  246.     #slot.name = nameMaterialSlot
  247.     slot.material = bpy.data.materials[materialname]
  248.  
  249. def exportImportObj(object):
  250.     newObject = None
  251.     print("************************** " + object.name)
  252.     filename = bpy.data.filepath.split(os.sep)[ len(bpy.data.filepath.split(os.sep))-1:][0]
  253.    
  254.    
  255.     filepathbas= bpy.data.filepath.replace(filename,"")#'/tmp/'
  256.     filepathobj=filepathbas+'psl_snapshot_temp.obj'
  257.     filepathmtl=filepathbas+'psl_snapshot_temp.mtl'
  258.    
  259.     #bpy.ops.object.select_pattern(pattern="",extend=False)
  260.     bpy.ops.object.select_pattern(pattern=object.name,extend=False)
  261.     #scene.objects.active = scene.objects[object.name]
  262.  
  263.     bpy.ops.export_scene.obj(filepath=filepathobj,use_selection=True, use_materials=False)
  264.     bpy.ops.import_scene.obj(filepath=filepathobj)
  265.    
  266.     try:
  267.         os.remove(filepathobj)
  268.     except:
  269.         pass
  270.     try:
  271.         os.remove(filepathmtl)
  272.     except:
  273.         pass
  274.     return newObject
  275.  
  276.  
  277.    
  278.  
  279. #NEW diplicateObjects in obj
  280. def duplicateObjects(context,material):
  281.     objects = bpy.data.groups[snapshotSource].objects
  282.     scn = bpy.context.scene  
  283.     for eachobject in objects:
  284.         if eachobject in context.visible_objects:
  285.             exportImportObj(eachobject)
  286.             newobject = context.selected_objects[0]
  287.             newobject.name = eachobject.name
  288.             newobject.name = nameObjectPrefix + newobject.name.split(".")[0] + "__"+ str(scn.frame_current)
  289.            
  290.             changeGroup(context,newobject)
  291.             #applyMaterial
  292.             if material == "GRAY":
  293.                 applyMaterial (context, newobject,nameMaterialGray)
  294.             if material == "BLACK":
  295.                 applyMaterial (context, newobject,nameMaterialBlack)
  296.             if material == "CUSTOM":
  297.                 applyMaterial (context, newobject,nameMaterialCustom)    
  298.    
  299.             #set parent
  300.             newobject.parent = bpy.data.objects[nameEmptyDad]
  301.            
  302.             #decimate
  303.             decimate = newobject.modifiers.new(name="decimate", type='DECIMATE')
  304.             decimate.ratio = scn.psl_decimate_ratio
  305.  
  306.  
  307. def generateSnapshot ( self, context):
  308.     selected_objects = bpy.context.selected_objects[:]
  309.     original_layers = bpy.context.scene.layers[:]
  310.     actual_object = ""        
  311.     actual_mode = context.mode
  312.     scn = context.scene  
  313.     try:
  314.         actual_object =  context.active_object.name            
  315.     except:
  316.         pass
  317.    
  318.     if context.mode != 'OBJECT':
  319.          bpy.ops.object.mode_set(mode='OBJECT')
  320.        
  321.     for i in range(len(bpy.context.scene.layers)):
  322.         bpy.context.scene.layers[i] = True
  323.    
  324.     bpy.ops.object.select_pattern(pattern="",extend=False)
  325.     bpy.context.scene.objects.active = None
  326.     bpy.context.scene.layers = original_layers
  327.    
  328.     material = scn.psl_snapshot_material
  329.     duplicateObjects(context,material)
  330.  
  331.        
  332.     for object in context.scene.objects:
  333.         if object in selected_objects:
  334.             object.select = True
  335.         else:
  336.             object.select = False
  337.    
  338.        
  339.     try:  
  340.         scn.objects.active = scn.objects[actual_object]  
  341.         bpy.ops.object.mode_set(mode=actual_mode)      
  342.     except:
  343.         pass
  344.      
  345.  
  346.  
  347.          
  348. class PSL_MakeSnapshot(bpy.types.Operator):
  349.     '''Tooltip'''
  350.     bl_idname = "object.make_snapshot"
  351.     bl_label = "Make Snapshot"
  352.     bl_options = {'REGISTER', 'UNDO'}
  353.     bl_description = "Make Snapshot!"
  354.        
  355.     material = bpy.props.StringProperty(name="material", description="Material", default="GRAY")
  356.  
  357.     @classmethod
  358.     def poll(cls, context):
  359.         try:
  360.             objects = bpy.data.groups[snapshotSource].objects
  361.             if len(objects) > 0 :
  362.                 return True
  363.             else:
  364.                 return False
  365.         except:
  366.             return False
  367.         return False
  368.  
  369.     def execute(self, context):
  370.        
  371.         try:
  372.             scn = context.scene
  373.             if not scn.psl_generate_all:            
  374.                 CleanExistingSnapshot (context)
  375.                 generateSnapshot ( self, context)
  376.             else:        
  377.                 last_frame = False    
  378.                 CleanAllSnapshots ( context )
  379.                 scn.frame_set(scn.psl_snapshot_start)
  380.                 generateSnapshot ( self, context)
  381.                
  382.                 while (not last_frame) and (scn.frame_current < scn.psl_snapshot_end):
  383.                     actual_frame = scn.frame_current
  384.                    
  385.                     bpy.ops.screen.keyframe_jump(next=True)
  386.                     if actual_frame != scn.frame_current:
  387.                         generateSnapshot ( self, context)
  388.                     else:
  389.                         last_frame = True
  390.    
  391.            
  392.             if not scn.psl_generate_all and scn.psl_jump_next_frame:
  393.                 bpy.ops.screen.keyframe_jump(next=True)  
  394.         except:
  395.             self.report(type={'ERROR'}, message="Error making snapshot" )
  396.         return {'FINISHED'}
  397.  
  398.  
  399.  
  400. def CleanExistingSnapshot (context):
  401.    
  402.     scn = context.scene
  403.     '''
  404.     bpy.ops.object.select_pattern(pattern='',extend=False)
  405.     bpy.ops.object.select_pattern(pattern='*'+ nameObjectPrefix + '*'+ str(scn.frame_current) +'*',extend=False)
  406.     objects = context.selected_objects
  407.     '''
  408.     objects = []
  409.     for object in scn.objects:
  410.         if nameObjectPrefix in object.name:
  411.             end = object.name.split("__")[len(object.name.split("__"))-1]
  412.             if  str(scn.frame_current) == end:
  413.                 objects.append(object)
  414.     CleanSnapshots(context, objects)
  415.  
  416. def CleanAllSnapshots ( context ):
  417.     objects = bpy.data.groups[snapshotInstances].objects
  418.     CleanSnapshots(context,objects)    
  419.  
  420. def CleanSnapshot (context, object):
  421.     bpy.ops.object.select_pattern(pattern="",extend=False)
  422.    
  423.     scn = context.scene  
  424.     object.hide_select = False
  425.     object.select = True
  426.    
  427.     bpy.ops.object.delete()
  428.    
  429.     '''
  430.     bpy.ops.object.select_pattern(pattern=object.name,extend=False)
  431.     bpy.ops.object.delete()
  432.     bpy.ops.object.select_pattern(pattern=object.name,extend=False)
  433.     bpy.ops.object.delete()
  434.     '''
  435.  
  436. def CleanSnapshots ( context, objects ):
  437.     something_selected = len(bpy.context.selected_objects) > 0
  438.    
  439.     actual_object = ""        
  440.     actual_mode =  context.mode
  441.    
  442.     try:
  443.         actual_object =  context.active_object.name            
  444.     except:
  445.         pass
  446.    
  447.     if context.mode != 'OBJECT':
  448.          bpy.ops.object.mode_set(mode='OBJECT')
  449.          
  450.     bpy.ops.object.select_pattern(pattern="",extend=False)
  451.     scn = context.scene  
  452.     #objects = bpy.data.groups[snapshotInstances].objects
  453.     for object in objects:
  454.         CleanSnapshot(context, object)
  455.  
  456.    
  457.     bpy.ops.object.select_pattern(pattern=actual_object,extend=False)
  458.    
  459.     scn = context.scene    
  460.     try:    
  461.         scn.objects.active = scn.objects[actual_object]    
  462.         bpy.ops.object.mode_set(mode=actual_mode)      
  463.     except:
  464.         pass
  465.        
  466.        
  467. class PSL_CleanSnapshots(bpy.types.Operator):
  468.     '''Tooltip'''
  469.     bl_idname = "object.clean_snapshots"
  470.     bl_label = "Clean Spanshots"
  471.     bl_description = "Delete Current Frame Snapshot"
  472.    
  473.     all = bpy.props.BoolProperty(name="All", description="Delete all snapshots", default=False)
  474.    
  475.     @classmethod
  476.     def poll(cls, context):
  477.         return True
  478.  
  479.     def execute(self, context):
  480.         try:
  481.             if (self.all):        
  482.                 objects = bpy.data.groups[snapshotInstances].objects
  483.                 CleanSnapshots(context,objects)
  484.             else:
  485.                 CleanExistingSnapshot(context)
  486.                 if context.scene.psl_jump_next_frame:
  487.                     bpy.ops.screen.keyframe_jump(next=True)
  488.        
  489.         except:
  490.             self.report(type={'ERROR'}, message="Error deleting snapshot" )          
  491.         return {'FINISHED'}
  492.    
  493.  
  494. class PSL_SnapshotVisible(bpy.types.Operator):
  495.     bl_idname = "object.snapshot_visible"
  496.     bl_label = "Enable / Disable Visibility Snapshot"
  497.     bl_description = "Show / Hide snapshots"
  498.        
  499.     visible = bpy.props.BoolProperty(name="Visible", description="make visible", default=False)
  500.    
  501.     @classmethod
  502.     def poll(cls, context):
  503.         return True
  504.     def execute(self, context):
  505.         try:
  506.             objects = bpy.data.groups[snapshotInstances].objects
  507.             for object in objects:            
  508.                 object.hide = not self.visible      
  509.             bpy.types.PSL_SnapshotUI.visible = self.visible
  510.         except:
  511.             self.report(type={'ERROR'}, message="Error while enabling / disabling visibility of the snapshots" )  
  512.         return {'FINISHED'}
  513.  
  514. class PSL_SnapshotRendereable(bpy.types.Operator):
  515.     bl_idname = "object.snapshot_renderable"
  516.     bl_label = "Enable / Disable Render Snapshot"
  517.     bl_description = "Enable / Disable render snapshots"
  518.    
  519.     rendeable = bpy.props.BoolProperty(name="Rendeable", description="make rendeable", default=False)
  520.    
  521.     @classmethod
  522.     def poll(cls, context):
  523.         return True
  524.     def execute(self, context):
  525.         try:
  526.             objects = bpy.data.groups[snapshotInstances].objects
  527.             for object in objects:
  528.                 object.hide_render = not self.rendeable
  529.             bpy.types.PSL_SnapshotUI.rendeable = self.rendeable  
  530.         except:
  531.             self.report(type={'ERROR'}, message="Error while enabling / disabling render of the snapshots" )                
  532.         return {'FINISHED'}
  533.  
  534. class PSL_SnapshotSelectable(bpy.types.Operator):
  535.     bl_idname = "object.snapshot_selectable"
  536.     bl_label = "Select / Deselect snapshot"
  537.     bl_description = "Enable / Disable select snapshots"
  538.    
  539.     selectable = bpy.props.BoolProperty(name="Selectable", description="make selectable", default=False)
  540.    
  541.     @classmethod
  542.     def poll(cls, context):
  543.         return True
  544.     def execute(self, context):
  545.         try:
  546.             objects = bpy.data.groups[snapshotInstances].objects
  547.             for object in objects:            
  548.                 object.hide_select = not self.selectable      
  549.             bpy.types.PSL_SnapshotUI.selectable = self.selectable
  550.         except:
  551.             self.report(type={'ERROR'}, message="Error while enabling / disabling select of the snapshots" )  
  552.         return {'FINISHED'}    
  553.  
  554. class PSL_DecimateVisible(bpy.types.Operator):
  555.     bl_idname = "object.decimate_visible"
  556.     bl_label = "Enable / Disable visibility decimate"
  557.     bl_description = "Enable / Disable visibility decimate modifier"
  558.        
  559.     visible = bpy.props.BoolProperty(name="Visible", description="make visible", default=False)
  560.    
  561.     @classmethod
  562.     def poll(cls, context):
  563.         return True
  564.     def execute(self, context):
  565.         try:
  566.             objects = bpy.data.groups[snapshotInstances].objects
  567.             for object in objects:            
  568.                 object.modifiers['decimate'].show_viewport = not self.visible
  569.             bpy.types.PSL_SnapshotUI.visible_decimate = self.visible
  570.         except:
  571.             self.report(type={'ERROR'}, message="Error while enabling / disabling visibility of the decimate" )  
  572.         return {'FINISHED'}
  573.  
  574. class PSL_DecimateRendereable(bpy.types.Operator):
  575.     bl_idname = "object.decimate_renderable"
  576.     bl_label = "Enable / Disable render of decimate"
  577.     bl_description = "Enable / Disable render decimate modifier"
  578.        
  579.     rendeable = bpy.props.BoolProperty(name="Rendeable", description="make rendeable", default=False)
  580.    
  581.     @classmethod
  582.     def poll(cls, context):
  583.         return True
  584.     def execute(self, context):
  585.         try:
  586.             objects = bpy.data.groups[snapshotInstances].objects
  587.             for object in objects:
  588.                 object.modifiers['decimate'].show_render = not self.rendeable
  589.             bpy.types.PSL_SnapshotUI.rendeable_decimate = self.rendeable    
  590.         except:
  591.             self.report(type={'ERROR'}, message="Error while enabling / disabling render of the decimate" )                
  592.         return {'FINISHED'}
  593.  
  594. class PSL_DecimateUpdate(bpy.types.Operator):
  595.     bl_idname = "object.decimate_update"
  596.     bl_label = "Update decimate ratio"    
  597.     bl_description = "Update decimate modifier"  
  598.     @classmethod
  599.     def poll(cls, context):
  600.         return True
  601.     def execute(self, context):
  602.         try:
  603.             objects = bpy.data.groups[snapshotInstances].objects
  604.             for object in objects:
  605.                 object.modifiers['decimate'].ratio = context.scene.psl_decimate_ratio
  606.         except:
  607.             self.report(type={'ERROR'}, message="Error while updating the decimate" )
  608.         return {'FINISHED'}
  609.  
  610. class PSL_RadioButtonMaterial(bpy.types.Operator):
  611.     bl_idname = "object.pls_rdbmaterial"
  612.     bl_label = "Update radio button material"    
  613.     bl_description = "Select Material"    
  614.     material   = bpy.props.StringProperty(name="material", description="material", default="BLACK")
  615.    
  616.     @classmethod
  617.     def poll(cls, context):
  618.         return True
  619.     def execute(self, context):  
  620.         try:      
  621.             scn = context.scene
  622.             scn.psl_snapshot_material = self.material
  623.         except:
  624.             self.report(type={'ERROR'}, message="Error updating material" )
  625.         return {'FINISHED'}
  626.  
  627. class PSL_Snapshot_Initialize(bpy.types.Operator):
  628.     bl_idname = "object.psl_snp_initialize"
  629.     bl_label = "Initialize"    
  630.     bl_description = "Re/Generate all necesary for the addon "
  631.    
  632.     @classmethod
  633.     def poll(cls, context):
  634.         return True
  635.     def execute(self, context):  
  636.         try:      
  637.             initializePSLsnapshot()
  638.         except:
  639.             self.report(type={'ERROR'}, message="Error while initializing the addon" )
  640.         return {'FINISHED'}
  641.        
  642. class PSL_SnapshotUI(bpy.types.Panel):
  643.     bl_space_type = 'VIEW_3D'
  644.     bl_region_type = 'UI'
  645.     bl_label = "PSL SnapShot"
  646.  
  647.     material   = bpy.props.BoolProperty(name="gray_material", description="gray_material", default=False)
  648.     selectable = bpy.props.BoolProperty(name="Selectable", description="make selectable", default=False)
  649.     rendeable  = bpy.props.BoolProperty(name="Rendeable", description="make rendeable", default=False)
  650.     visible    = bpy.props.BoolProperty(name="Visible", description="make visible", default=False)
  651.  
  652.     rendeable_decimate  = bpy.props.BoolProperty(name="Rendeable Decimate", description="make rendeable", default=False)
  653.     visible_decimate    = bpy.props.BoolProperty(name="Visible Decimate", description="make visible", default=False)
  654.  
  655.     def draw(self, context):
  656.         layout = self.layout        
  657.         scn = bpy.context.scene  
  658.         regenerar = False
  659.         try:
  660.             m1 =  bpy.data.materials[nameMaterialBlack]
  661.             m2 =  bpy.data.materials[nameMaterialGray]
  662.             m3 =  bpy.data.materials[nameMaterialCustom]
  663.         except:
  664.             regenerar = True
  665.        
  666.         if not regenerar:
  667.             #OBJ operators
  668.             colobjs = layout.column()
  669.             colobjs.label(text="Objs to Snapshot:")
  670.             operator = colobjs.operator("object.addtosourcegroup",text="Add to List",icon='EXPORT')      
  671.             operator = colobjs.operator("object.deletefromsourcegroup",text="Delete from List",icon='X')  
  672.             colobjs.label(text="")
  673.                
  674.            
  675.             #snapshot Operator
  676.            
  677.             colsnapshot = layout.row(align=True)
  678.             colsnapshot.label(text="Snapshots") #, icon='GROUP')
  679.  
  680.             if self.visible :
  681.                 operator = colsnapshot.operator("object.snapshot_visible",text="",icon='RESTRICT_VIEW_OFF')
  682.                 operator.visible=False
  683.             else:
  684.                 operator = colsnapshot.operator("object.snapshot_visible",text="",icon='RESTRICT_VIEW_ON')
  685.                 operator.visible=True
  686.  
  687.             if self.selectable:
  688.                 operator = colsnapshot.operator("object.snapshot_selectable",text="",icon='RESTRICT_SELECT_OFF')
  689.                 operator.selectable=False
  690.             else:
  691.                 operator = colsnapshot.operator("object.snapshot_selectable",text="",icon='RESTRICT_SELECT_ON')
  692.                 operator.selectable=True
  693.                  
  694.             if self.rendeable :
  695.                 operator = colsnapshot.operator("object.snapshot_renderable",text="",icon='RESTRICT_RENDER_OFF')
  696.                 operator.rendeable=False
  697.             else:
  698.                 operator = colsnapshot.operator("object.snapshot_renderable",text="",icon='RESTRICT_RENDER_ON')
  699.                 operator.rendeable=True
  700.                
  701.             colbuttonsnpshot = layout.row(align=True)  
  702.             colbuttonsnpshot.scale_y = 2
  703.             colbuttonsnpshot.prop ( scn,"psl_jump_next_frame", icon='FF',text="")
  704.             operator = colbuttonsnpshot.operator("object.make_snapshot",text="Make snapshot",icon='NONE')
  705.             operator = colbuttonsnpshot.operator("object.clean_snapshots",text="",icon='X')  
  706.             operator.all = False
  707.            
  708.            
  709.             layout.separator()
  710.            
  711.             colgekeyscheck = layout.column()
  712.             colgekeyscheck.prop ( scn, "psl_generate_all")#, icon ='SCRIPTPLUGINS')
  713.             colgekeys = layout.row(align=True)
  714.             colgekeys.enabled = scn.psl_generate_all
  715.             colgekeys.prop ( scn,"psl_snapshot_start")
  716.             colgekeys.prop ( scn,"psl_snapshot_end")
  717.            
  718.      
  719.  
  720.             col = layout.row()    
  721.          
  722.             boxcolors = col.box()
  723.            
  724.  
  725.             if scn.psl_snapshot_material == 'BLACK':
  726.                 row = boxcolors.row()
  727.                 col1 = row.column()
  728.                 operator = col1.operator("object.pls_rdbmaterial",text="Color1",icon='RADIOBUT_ON',emboss=False)
  729.                 operator.material = "BLACK"  
  730.                 col1.active = True
  731.                 col2 = row.column()
  732.                 col2.prop ( bpy.data.materials[nameMaterialBlack],"diffuse_color",text ="", icon_only=True)  
  733.                 col2.enabled = True
  734.  
  735.                 row = boxcolors.row()
  736.                 col1 = row.column()
  737.                 operator = col1.operator("object.pls_rdbmaterial",text="Color2",icon='RADIOBUT_OFF',emboss=False)
  738.                 operator.material = "GRAY"  
  739.                 col1.active = False
  740.                 col2 = row.column()
  741.                 col2.prop ( bpy.data.materials[nameMaterialGray],"diffuse_color",text ="", icon_only=True)  
  742.                 col2.enabled = True
  743.                
  744.                 row = boxcolors.row()
  745.                 col1 = row.column()
  746.                 operator = col1.operator("object.pls_rdbmaterial",text="Color3",icon='RADIOBUT_OFF',emboss=False)
  747.                 operator.material = "CUSTOM"  
  748.                 col1.active = False
  749.                 col2 = row.column()
  750.                 col2.prop ( bpy.data.materials[nameMaterialCustom],"diffuse_color",text ="", icon_only=True)  
  751.                 col2.enabled = True
  752.                      
  753.             if scn.psl_snapshot_material == 'GRAY':
  754.                 row = boxcolors.row()
  755.                 col1 = row.column()
  756.                 operator = col1.operator("object.pls_rdbmaterial",text="Color1",icon='RADIOBUT_OFF',emboss=False)
  757.                 operator.material = "BLACK"  
  758.                 col1.active = False
  759.                 col2 = row.column()
  760.                 col2.prop ( bpy.data.materials[nameMaterialBlack],"diffuse_color",text ="", icon_only=True)  
  761.                 col2.enabled = True
  762.                
  763.                 row = boxcolors.row()
  764.                 col1 = row.column()
  765.                 operator = col1.operator("object.pls_rdbmaterial",text="Color2",icon='RADIOBUT_ON',emboss=False)
  766.                 operator.material = "GRAY"  
  767.                 col1.active = True
  768.                 col2 = row.column()
  769.                 col2.prop ( bpy.data.materials[nameMaterialGray],"diffuse_color",text ="", icon_only=True)  
  770.                 col2.enabled = True
  771.                
  772.                 row = boxcolors.row()
  773.                 col1 = row.column()
  774.                 operator = col1.operator("object.pls_rdbmaterial",text="Color3",icon='RADIOBUT_OFF',emboss=False)
  775.                 operator.material = "CUSTOM"  
  776.                 col1.active = False
  777.                 col2 = row.column()
  778.                 col2.prop ( bpy.data.materials[nameMaterialCustom],"diffuse_color",text ="", icon_only=True)  
  779.                 col2.enabled = True          
  780.             if scn.psl_snapshot_material == 'CUSTOM':
  781.                 row = boxcolors.row()
  782.                 col1 = row.column()
  783.                 operator = col1.operator("object.pls_rdbmaterial",text="Color1",icon='RADIOBUT_OFF',emboss=False)
  784.                 operator.material = "BLACK"  
  785.                 col1.active = False
  786.                 col2 = row.column()
  787.                 col2.prop ( bpy.data.materials[nameMaterialBlack],"diffuse_color",text ="", icon_only=True)  
  788.                 col2.enabled = True
  789.                
  790.                 row = boxcolors.row()
  791.                 col1 = row.column()
  792.                 operator = col1.operator("object.pls_rdbmaterial",text="Color2",icon='RADIOBUT_OFF',emboss=False)
  793.                 operator.material = "GRAY"  
  794.                 col1.active = False
  795.                 col2 = row.column()
  796.                 col2.prop ( bpy.data.materials[nameMaterialGray],"diffuse_color",text ="", icon_only=True)  
  797.                 col2.enabled = True
  798.                
  799.                 row = boxcolors.row()
  800.                 col1 = row.column()
  801.                 operator = col1.operator("object.pls_rdbmaterial",text="Color3",icon='RADIOBUT_ON',emboss=False)
  802.                 operator.material = "CUSTOM"  
  803.                 col1.active = True
  804.                 col2 = row.column()
  805.                 col2.prop ( bpy.data.materials[nameMaterialCustom],"diffuse_color",text ="", icon_only=True)  
  806.                 col2.enabled = True
  807.                
  808.            
  809.            
  810.            
  811.          
  812.             layout.separator()
  813.            
  814.             rowcleansnapshot = layout.row(align=False)
  815.             rowcleansnapshot.label(text="Optimize Snapshot Meshes:") #, icon='GROUP')
  816.  
  817.             type_vis = True
  818.             coldecimate = layout.row(align=True)
  819.             coldecimate.prop(scn,"psl_decimate_ratio")
  820.             operator =coldecimate.operator("object.decimate_update",text="",icon='FILE_REFRESH',emboss=type_vis)  
  821.            
  822.             coldecimate.separator()
  823.            
  824.             if self.visible_decimate :
  825.                 operator = coldecimate.operator("object.decimate_visible",text="",icon='RESTRICT_VIEW_ON',emboss=type_vis)
  826.                 operator.visible=False
  827.             else:            
  828.                 operator = coldecimate.operator("object.decimate_visible",text="",icon='RESTRICT_VIEW_OFF',emboss=type_vis)
  829.                 operator.visible=True          
  830.            
  831.                  
  832.             if self.rendeable_decimate :
  833.                 operator = coldecimate.operator("object.decimate_renderable",text="",icon='RESTRICT_RENDER_OFF',emboss=type_vis)
  834.                 operator.rendeable=False
  835.             else:
  836.                 #col = col.box()
  837.                 operator = coldecimate.operator("object.decimate_renderable",text="",icon='RESTRICT_RENDER_ON',emboss=type_vis)
  838.                 operator.rendeable=True
  839.            
  840.             layout.separator()
  841.            
  842.             rowcleanall = layout.row(align=True)
  843.            
  844.             rowcleanall.scale_y = 1
  845.             operator = rowcleanall.operator("object.clean_snapshots",text="Clean All Snapshots",icon='CANCEL')  
  846.             operator.all = True
  847.            
  848.             # if there aren't elements in source
  849.             num_objects = len(bpy.data.groups[snapshotSource].objects)
  850.             if num_objects == 0 :
  851.                 #col.enabled = False
  852.                 colsnapshot.enabled = False
  853.                 boxcolors.enabled = False
  854.                 colbuttonsnpshot.enabled = False
  855.                 colgekeyscheck.enabled = False
  856.                 colgekeys.enabled = False
  857.                 coldecimate.enabled = False
  858.                 rowcleanall.enabled = False
  859.                 rowcleansnapshot.enabled = False
  860.                
  861.                
  862.         else:
  863.             colobjs = layout.column()
  864.             #colobjs.label(text="Objs to Snapshot:")
  865.             operator = colobjs.operator("object.psl_snp_initialize",text="Initialize",icon='EXPORT')
  866.  
  867.        
  868. def register():
  869.     # Define properties for the draw setting.
  870.    
  871.     bpy.types.Scene.psl_generate_all = bpy.props.BoolProperty(
  872.         name="Do it in all keyframes",
  873.         description="Generate Snapshots in all Keyframes from start to end",
  874.         default=0)
  875.     bpy.types.Scene.psl_snapshot_start = bpy.props.IntProperty(
  876.         name="Start",
  877.         description="From frame snapshot",
  878.         default=0)    
  879.     bpy.types.Scene.psl_snapshot_end = bpy.props.IntProperty(
  880.         name="End",
  881.         description="To end snapshot",
  882.         default=150)
  883.            
  884.     bpy.types.Scene.psl_jump_next_frame = bpy.props.BoolProperty(
  885.         name="Jump next key-frame",
  886.         description="When on jump to next key-frame after make snapshot",
  887.         default=0)
  888.  
  889.     bpy.types.Scene.psl_decimate_ratio = bpy.props.FloatProperty(
  890.         name="Decimate Ratio",
  891.         description="Value of the decimate modifier",
  892.         max=1,
  893.         min=0,
  894.         default=1.0)  
  895.    
  896.     bpy.types.Scene.psl_decimate_renderable = bpy.props.BoolProperty(
  897.         name="Render decimate",
  898.         description="Enable / disable renderable decimate",
  899.         default=1)      
  900.     bpy.types.Scene.psl_decimate_visibility = bpy.props.BoolProperty(
  901.         name="Render visualize",
  902.         description="Enable / disable visibility decimate",
  903.         default=1)
  904.    
  905.     bpy.types.Scene.psl_snapshot_material = bpy.props.StringProperty(
  906.         name="Snapshot Material",
  907.         description="Enable / disable visibility decimate",
  908.         default="BLACK")
  909.        
  910.     bpy.utils.register_class(PSL_AddToSourceGroup)
  911.     bpy.utils.register_class(PSL_DeleteFromSourceGroup)
  912.     bpy.utils.register_class(PSL_MakeSnapshot)
  913.     bpy.utils.register_class(PSL_CleanSnapshots)
  914.     bpy.utils.register_class(PSL_SnapshotRendereable)
  915.     bpy.utils.register_class(PSL_SnapshotSelectable)    
  916.     bpy.utils.register_class(PSL_SnapshotUI)
  917.     bpy.utils.register_class(PSL_SnapshotVisible)
  918.    
  919.     bpy.utils.register_class(PSL_RadioButtonMaterial)
  920.  
  921.     bpy.utils.register_class(PSL_DecimateVisible)
  922.     bpy.utils.register_class(PSL_DecimateRendereable)  
  923.     bpy.utils.register_class(PSL_DecimateUpdate)
  924.    
  925.     bpy.utils.register_class(PSL_Snapshot_Initialize)
  926.    
  927.     #,initializePSLsnapshot()
  928.  
  929.  
  930. def unregister():
  931.     bpy.utils.unregister_class(PSL_AddToSourceGroup)
  932.     bpy.utils.unregister_class(PSL_DeleteFromSourceGroup)
  933.     bpy.utils.unregister_class(PSL_MakeSnapshot)
  934.     bpy.utils.unregister_class(PSL_CleanSnapshots)
  935.     bpy.utils.unregister_class(PSL_SnapshotRendereable)
  936.     bpy.utils.unregister_class(PSL_SnapshotSelectable)  
  937.     bpy.utils.unregister_class(PSL_SnapshotUI)
  938.     bpy.utils.unregister_class(PSL_SnapshotVisible)
  939.    
  940.     bpy.utils.unregister_class(PSL_RadioButtonMaterial)
  941.  
  942.     bpy.utils.unregister_class(PSL_DecimateVisible)
  943.     bpy.utils.unregister_class(PSL_DecimateRendereable)        
  944.     bpy.utils.unregister_class(PSL_DecimateUpdate)  
  945.    
  946.     bpy.utils.unregister_class(PSL_Snapshot_Initialize)
  947.    
  948.     del bpy.types.Scene.psl_generate_all
  949.     del bpy.types.Scene.psl_snapshot_start
  950.     del bpy.types.Scene.psl_snapshot_end
  951.     del bpy.types.Scene.psl_jump_next_frame
  952.     del bpy.types.Scene.psl_decimate_ratio
  953.     del bpy.types.Scene.psl_decimate_renderable
  954.     del bpy.types.Scene.psl_decimate_visibility    
  955.     del bpy.types.Scene.psl_snapshot_material
  956.    
  957.  
  958. if __name__ == "__main__":    
  959.     register()
go to heaven