[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2751] branches/geodesic_domes/ geodesic_domes: Building automatically an object with a shapekey setting!
Peter K.H. Gragert
pkhgragert at gmail.com
Wed Dec 7 18:25:19 CET 2011
Revision: 2751
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2751
Author: pkhg
Date: 2011-12-07 17:25:18 +0000 (Wed, 07 Dec 2011)
Log Message:
-----------
Building automatically an object with a shapekey setting!
You can save two geodesic objects, different only by changing the form (not more vertices!) and create then an object (at the moment two) where
one has gotten the other as shapekey (remove the used one will be added later)
Modified Paths:
--------------
branches/geodesic_domes/geodesic_domes/third_domes_panel.py
Added Paths:
-----------
branches/geodesic_domes/geodesic_domes/add_shape_geodesic.py
Added: branches/geodesic_domes/geodesic_domes/add_shape_geodesic.py
===================================================================
--- branches/geodesic_domes/geodesic_domes/add_shape_geodesic.py (rev 0)
+++ branches/geodesic_domes/geodesic_domes/add_shape_geodesic.py 2011-12-07 17:25:18 UTC (rev 2751)
@@ -0,0 +1,92 @@
+import bpy
+import mathutils
+
+def reset_transform(ob):
+ m = mathutils.Matrix()
+ ob.matrix_local = m
+
+def func_add_corrective_pose_shape_fast(source, target):
+ reset_transform(target)
+ # If target object doesn't have Basis shape key, create it.
+ try:
+ num_keys = len( target.data.shape_keys.key_blocks )
+ except:
+ basis = target.shape_key_add()
+ basis.name = "Basis"
+ target.data.update()
+ key_index = target.active_shape_key_index
+ if key_index == 0:
+ # Insert new shape key
+ new_shapekey = target.shape_key_add()
+ new_shapekey.name = "Shape_" + source.name
+ new_shapekey_name = new_shapekey.name
+ key_index = len(target.data.shape_keys.key_blocks)-1
+ target.active_shape_key_index = key_index
+ # else, the active shape will be used (updated)
+ target.show_only_shape_key = True
+ shape_key_verts = target.data.shape_keys.key_blocks[ key_index ].data
+ try:
+ vgroup = target.active_shape_key.vertex_group
+ target.active_shape_key.vertex_group = ''
+ except:
+ print("blub")
+ pass
+ # copy the local vertex positions to the new shape
+ verts = source.data.vertices
+ for n in range( len(verts)):
+ shape_key_verts[n].co = verts[n].co
+ # go to all armature modifies and unpose the shape
+ for n in target.modifiers:
+ if n.type == 'ARMATURE' and n.show_viewport:
+ #~ print("got one")
+ n.use_bone_envelopes = False
+ n.use_deform_preserve_volume = False
+ n.use_vertex_groups = True
+ armature = n.object
+ unposeMesh( shape_key_verts, target, armature)
+ break
+
+ # set the new shape key value to 1.0, so we see the result instantly
+ target.data.shape_keys.key_blocks[ target.active_shape_key_index].value = 1.0
+ try:
+ target.active_shape_key.vertex_group = vgroup
+ except:
+ #~ print("bluba")
+ pass
+ target.show_only_shape_key = False
+ target.data.update()
+
+class add_corrective_pose_shape_fast(bpy.types.Operator):
+ '''Adds 1st object as shape to 2nd object as pose shape (only 1 armature)'''
+ bl_idname = "object.add_corrective_pose_shape_fast"
+ bl_label = "Add object as corrective shape faster"
+
+ @classmethod
+ def poll(cls, context):
+ return context.active_object != None
+
+ def execute(self, context):
+
+ if len(context.selected_objects) > 2:
+ print("Select source and target objects please")
+ return {'FINISHED'}
+
+ selection = context.selected_objects
+ target = context.active_object
+ if context.active_object == selection[0]:
+ source = selection[1]
+ else:
+ source = selection[0]
+ print(source)
+ print(target)
+ func_add_corrective_pose_shape_fast( source, target)
+ return {'FINISHED'}
+
+def register():
+ bpy.utils.register_module(__name__)
+
+def unregister():
+ bpy.utils.unregister_module(__name__)
+
+if __name__ == "__main__":
+ register()
Modified: branches/geodesic_domes/geodesic_domes/third_domes_panel.py
===================================================================
--- branches/geodesic_domes/geodesic_domes/third_domes_panel.py 2011-12-07 14:02:03 UTC (rev 2750)
+++ branches/geodesic_domes/geodesic_domes/third_domes_panel.py 2011-12-07 17:25:18 UTC (rev 2751)
@@ -1,7 +1,9 @@
import bpy
from geodesic_domes import vefm_259
from geodesic_domes import forms_259
-from geodesic_domes import geodesic_classes_259
+from geodesic_domes import geodesic_classes_259
+from geodesic_domes import add_shape_geodesic
+
from bpy.props import EnumProperty, IntProperty, FloatProperty, StringProperty, BoolProperty
import math
from math import pi
@@ -21,6 +23,10 @@
basegeodesic = None
imported_hubmesh_to_use = None
########global end######
+########FOR SHAPEKEYS###
+bpy.types.Scene.instant_filenames = StringProperty(name = "saved files",\
+ description = "filenames of saved goedesics",\
+ default = "c://tmp//tmp_geodesic0.txt")
def write_object(filename = "c://tmp//tmp_geodesic"):
file = open(filename, "w", encoding="utf8", newline="\n")
fw = file.write
@@ -39,7 +45,36 @@
fw("]\n")
file.close()
+def read_file(filename = "c://tmp//tmp_geodesic0.txt"):
+ file = open(filename, "r", newline="\n")
+ l0 = file.readline()
+ while l0[0] != 'v':
+ l0 = file.readline()
+ verts = []
+ l1 = file.readline()
+ while l1[0] == "(":
+ verts.append(eval(l1)[0])
+ l1 = file.readline()
+ l2 = l1
+ while l2[0] != 'f':
+ l2 = file.readline()
+ faces = []
+ l2 = file.readline()
+ while l2[0] == "(":
+ faces.append(eval(l2)[0])
+ l2 = file.readline()
+ file.close()
+ return(verts,faces)
+def vefm_add_object_direct(verts,faces):
+ from add_utils import AddObjectHelper, add_object_data
+ e = []
+ m = bpy.data.meshes.new(name= "TWEST")
+ m.from_pydata(verts, e, faces )
+ m.validate(verbose = False)
+ add_object_data(bpy.context, m, operator = None)
+
+########EIND FOR SHAPEKEYS######
#PKHG checking objects
def check_contains(cl,name , print_value = True):
dir_class = dir(cl)
@@ -73,7 +108,13 @@
sce = context.scene
layout = self.layout
col = layout.column()
+ col.label("make shapkey object")
+ files = sce.instant_filenames.split(";")
+ for el in files:
+ col.label(el)
+ col.operator(make_shapekey.bl_idname,"make shapkey object") #object.make_shapekey
col.operator(GenerateGeodesicDome.bl_idname,"execute me!")
+
'''
if context.scene.error_message == "":
col.label("No ERROR at this moment")
@@ -712,8 +753,6 @@
mesh = vefm_259.mesh()
vefm_259.finalfill(basegeodesic,mesh) #always! for hexifiy etc. necessarry!!!
vefm_259.vefm_add_object(mesh)
-#PKHG_TEST if self.instant_copy:
-
last_generated_object = context.active_object
last_generated_object.location = (0,0,0)
context.scene.objects.active = last_generated_object
@@ -886,10 +925,16 @@
self.instant_copy = False
print("try to save data")
tmp = self.instant_copy_filename + str(self.instant_copy_counter) + ".txt"
- try:
+ if True:
write_object(tmp)
- message = tmp + " WRITTEN"
- except:
+ filenames = bpy.context.scene.instant_filenames
+ files_names = filenames.split(";")
+#PKHG_DBG_OK
+# print("file_names",files_names)
+ filenames = filenames + ";" + tmp
+ bpy.context.scene.instant_filenames = filenames
+ message = tmp + " WRITTEN"
+ else:
message = tmp + " FAILED"
context.scene.error_message = message
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
@@ -971,7 +1016,33 @@
f.append(target.verts[a.index])
target.faces.append(f)
###error messages test
+class make_shapekey(bpy.types.Operator):
+ bl_idname = "object.make_shapekey"
+ bl_label = "Make Shapkeys"
+
+ @classmethod
+ def poll(self,context):
+ result = False
+ tmp = context.scene.instant_filenames.split(";")
+ if len(tmp) > 1 and tmp[0] != tmp[1]:
+ result = True
+ return result
+
+ def execute(self,context):
+ tmp = context.scene.instant_filenames.split(";")
+ verts1,faces1 = read_file(tmp[-1])
+ vefm_add_object_direct(verts1,faces1)
+ obj = context.active_object
+ obj.select = True
+ verts1,faces1 = read_file(tmp[-2])
+ vefm_add_object_direct(verts1,faces1)
+ objbase = context.active_object
+ objbase.select = True
+ add_shape_geodesic.func_add_corrective_pose_shape_fast(obj,objbase)
+ context.scene.instant_filenames = tmp[0]
+ return {"FINISHED"}
+
class DialogOperator(bpy.types.Operator):
bl_idname = "object.dialog_operator"
bl_label = "INFO"
More information about the Bf-extensions-cvs
mailing list