update to Axiscopy, more error checking. basic functionality the same.

- Dont allow it to apply the matrix twice to a linked-dupe. (Same as Apply Loc/Size/Rot)
- Make sure that the source object is active, not just the first selected object.
- Use Mesh instead of NMesh.
- use mesh.transform(mat) rather then vert by vert vec*mat

Other scripts had pupBlock changes for better layout.
This commit is contained in:
2006-12-15 22:14:33 +00:00
parent 0369f08299
commit 827cce172c
6 changed files with 73 additions and 63 deletions

View File

@@ -2,7 +2,7 @@
""" Registration info for Blender menus: <- these words are ignored
Name: 'Axis Orientation Copy'
Blender: 239
Blender: 242
Group: 'Object'
Tip: 'Copy local axis orientation of active object to all selected meshes (changes mesh data)'
"""
@@ -73,47 +73,54 @@ orientation.
from Blender import *
from Blender import Mathutils
from Blender.Mathutils import *
import BPyMessages
def realusers(data):
users = data.users
if data.fakeUser: users -= 1
return users
def applyTransform(mesh,mat):
for v in mesh.verts:
vec = v.co*mat
v.co[0], v.co[1], v.co[2] = vec[0], vec[1], vec[2]
oblist =Object.GetSelected()
lenob=len(oblist)
error = 0
for o in oblist[1:]:
if o.getType() != "Mesh":
Draw.PupMenu("Error: selected objects must be meshes")
error = 1
if not error:
if lenob<2:
def main():
scn_obs= Scene.GetCurrent().objects
ob_act = scn_obs.active
scn_obs = scn_obs.context
if not ob_act:
BPyMessages.Error_NoActive()
obs = [(ob, ob.getData(mesh=1)) for ob in scn_obs if ob != ob_act]
for ob, me in obs:
if ob.type != 'Mesh':
Draw.PupMenu("Error%t|Selection must be made up of mesh objects only")
return
if realusers(me) != 1:
Draw.PupMenu("Error%t|Meshes must be single user")
return
# remove linked
if len(obs) < 1:
Draw.PupMenu("Error: you must select at least 2 objects")
else :
source=oblist[0]
nsource=source.name
texte="Copy axis orientation from: " + nsource + " ?%t|OK"
result=Draw.PupMenu(texte)
return
result = Draw.PupMenu("Copy axis orientation from: " + ob_act.name + " ?%t|OK")
if result == -1:
return
for ob_target, me_target in obs:
if ob_act.rot != ob_target.rot:
rot_target = ob_target.matrixWorld.rotationPart().toEuler().toMatrix()
rot_source = ob_act.matrixWorld.rotationPart().toEuler().toMatrix()
rot_source_inv = rot_source.copy().invert()
tx_mat = rot_target * rot_source_inv
tx_mat.resize4x4()
me_target.transform(tx_mat)
ob_target.rot=ob_act.rot
for cible in oblist[1:]:
if source.rot!=cible.rot:
rotcible=cible.mat.rotationPart().toEuler().toMatrix()
rotsource=source.mat.rotationPart().toEuler().toMatrix()
rotsourcet = Matrix(rotsource)
rotsourcet.invert()
mat=rotcible*rotsourcet
me=cible.getData()
#ncible=cible.name
#me=NMesh.GetRaw(ncible)
applyTransform(me,mat)
#NMesh.PutRaw(me,ncible)
me.update()
cible.makeDisplayList()
cible.rot=source.rot
if __name__ == '__main__':
main()

View File

@@ -1,6 +1,8 @@
from Blender import Draw, sys
def Error_NoMeshSelected():
Draw.PupMenu('ERROR%t|No mesh objects selected')
def Error_NoActive():
Draw.PupMenu('ERROR%t|No active object')
def Error_NoMeshActive():
Draw.PupMenu('ERROR%t|Active object is not a mesh')
def Error_NoMeshUvSelected():

View File

@@ -524,20 +524,22 @@ def write_ui(filename):
# Get USER Options
pup_block = [\
('Mesh Options...'),\
('Context...'),\
('Selection Only', EXPORT_SEL_ONLY, 'Only export objects in visible selection. Else export whole scene.'),\
('All Scenes', EXPORT_ALL_SCENES, 'Each scene as a seperate OBJ file.'),\
('Animation', EXPORT_ANIMATION, 'Each frame as a numbered OBJ file.'),\
('Object Prefs...'),\
('Apply Modifiers', EXPORT_APPLY_MODIFIERS, 'Use transformed mesh data from each object. May break vert order for morph targets.'),\
('Rotate X90', EXPORT_ROTX90 , 'Rotate on export so Blenders UP is translated into OBJs UP'),\
('Triangulate', EXPORT_TRI, 'Triangulate quadsModifiers.'),\
(''),\
('Extra Data...'),\
('Edges', EXPORT_EDGES, 'Edges not connected to faces.'),\
('Normals', EXPORT_NORMALS, 'Export vertex normal data (Ignored on import).'),\
('High Quality Normals', EXPORT_NORMALS_HQ, 'Calculate high quality normals for rendering.'),\
('UVs', EXPORT_UV, 'Export texface UV coords.'),\
('Materials', EXPORT_MTL, 'Write a separate MTL file with the OBJ.'),\
('Context...'),\
('Selection Only', EXPORT_SEL_ONLY, 'Only export objects in visible selection. Else export whole scene.'),\
('All Scenes', EXPORT_ALL_SCENES, 'Each scene as a seperate OBJ file.'),\
('Animation', EXPORT_ANIMATION, 'Each frame as a numbered OBJ file.'),\
('Copy Images', EXPORT_COPY_IMAGES, 'Copy image files to the export directory, never overwrite.'),\
('Triangulate', EXPORT_TRI, 'Triangulate quads.'),\
('Grouping...'),\
('Objects', EXPORT_BLEN_OBS, 'Export blender objects as "OBJ objects".'),\
('Object Groups', EXPORT_GROUP_BY_OB, 'Export blender objects as "OBJ Groups".'),\
@@ -601,7 +603,7 @@ def write_ui(filename):
Blender.Set('curframe', frame)
if EXPORT_SEL_ONLY:
export_objects = scn.objects.selected #Blender.Object.GetSelected() # Export Context
export_objects = scn.objects.context
else:
export_objects = scn.objects # scn.getChildren()

View File

@@ -734,7 +734,6 @@ def load_obj_ui(filepath, BATCH_LOAD= False):
('Split by Groups', SPLIT_GROUPS, 'Import OBJ Groups into Blender Objects'),\
('Split by Material', SPLIT_MATERIALS, 'Import each material into a seperate mesh (Avoids > 16 per mesh error)'),\
('Clamp Scale:', CLAMP_SIZE, 0.0, 1000.0, 'Clamp the size to this maximum (Zero to Disable)'),\
'',\
('Image Search', IMAGE_SEARCH, 'Search subdirs for any assosiated images (Warning, may be slow)'),\
]

View File

@@ -71,7 +71,6 @@ def main():
pup_block = [\
('Poly Reduce:', PREF_REDUX, 0.05, 0.95, 'Scale the meshes poly count by this value.'),\
'',\
('Boundry Weight:', PREF_BOUNDRY_WEIGHT, 0.0, 20.0, 'Weight boundry verts by this scale, 0.0 for no boundry weighting.'),\
('Area Weight:', PREF_FACE_AREA_WEIGHT, 0.0, 20.0, 'Collapse edges effecting lower area faces first.'),\
('Triangulate', PREF_FACE_TRIANGULATE, 'Convert quads to tris before reduction, for more choices of edges to collapse.'),\
@@ -79,17 +78,17 @@ def main():
('VGroup Weighting', VGROUP_INF_ENABLE, 'Use a vertex group to influence the reduction, higher weights for higher quality '),\
('vgroup name: ', VGROUP_INF_REDUX, 0, 32, 'The name of the vertex group to use for the weight map'),\
('vgroup mult: ', VGROUP_INF_WEIGHT, 0.0, 100.0, 'How much to make the weight effect the reduction'),\
('Other Selected Obs', PREF_OTHER_SEL_OBS, 'reduce other selected objects.'),\
'',\
'',\
'',\
('UV Coords', PREF_DO_UV, 'Interpolate UV Coords.'),\
('Vert Colors', PREF_DO_VCOL, 'Interpolate Vertex Colors'),\
('Vert Weights', PREF_DO_WEIGHTS, 'Interpolate Vertex Weights'),\
('Remove Doubles', PREF_REM_DOUBLES, 'Remove doubles before reducing to avoid boundry tearing.'),\
'',\
('Other Selected Obs', PREF_OTHER_SEL_OBS, 'reduce other selected objects.'),\
]
if not Draw.PupBlock("X Mirror mesh tool", pup_block):
if not Draw.PupBlock("Poly Reducer", pup_block):
return
PREF_REDUX= PREF_REDUX.val

View File

@@ -46,6 +46,7 @@ from Blender import *
global renameCount
renameCount = 0
obsel = Scene.GetCurrent().objects.context
def setDataNameWrapper(ob, newname):
if ob.getData(name_only=1) == newname:
@@ -64,7 +65,7 @@ def main():
def renameLinkedDataFromObject():
# Result 1, we want to rename data
for ob in Object.GetSelected():
for ob in obsel:
if ob.name == ob.getData(name_only=1):
return # Alredy the same name, dont bother.
@@ -88,7 +89,7 @@ def main():
NEW_NAME_STRING= NEW_NAME_STRING.val
Window.WaitCursor(1)
for ob in Object.GetSelected():
for ob in obsel:
if ob.name != NEW_NAME_STRING:
ob.name = NEW_NAME_STRING
renameCount+=1
@@ -115,7 +116,7 @@ def main():
WITH_STRING = WITH_STRING.val
Window.WaitCursor(1)
for ob in Object.GetSelected():
for ob in obsel:
newname = ob.name.replace(REPLACE_STRING, WITH_STRING)
if ob.name != newname:
ob.name = newname
@@ -140,7 +141,7 @@ def main():
PREFIX_STRING = PREFIX_STRING.val
Window.WaitCursor(1)
for ob in Object.GetSelected():
for ob in obsel:
ob.name = PREFIX_STRING + ob.name
renameCount+=1 # we knows these are different.
return RENAME_LINKED.val
@@ -162,7 +163,7 @@ def main():
SUFFIX_STRING = SUFFIX_STRING.val
Window.WaitCursor(1)
for ob in Object.GetSelected():
for ob in obsel:
ob.name = ob.name + SUFFIX_STRING
renameCount+=1 # we knows these are different.
return RENAME_LINKED.val
@@ -183,7 +184,7 @@ def main():
Window.WaitCursor(1)
TRUNCATE_START = TRUNCATE_START.val
for ob in Object.GetSelected():
for ob in obsel:
newname = ob.name[TRUNCATE_START: ]
ob.name = newname
renameCount+=1
@@ -206,7 +207,7 @@ def main():
Window.WaitCursor(1)
TRUNCATE_END = TRUNCATE_END.val
for ob in Object.GetSelected():
for ob in obsel:
newname = ob.name[: -TRUNCATE_END]
ob.name = newname
renameCount+=1
@@ -217,7 +218,7 @@ def main():
global renameCount
Window.WaitCursor(1)
for ob in Object.GetSelected():
for ob in obsel:
newname = ob.getData(name_only=1)
if newname != None and ob.name != newname:
ob.name = newname
@@ -228,7 +229,7 @@ def main():
global renameCount
Window.WaitCursor(1)
for ob in Object.GetSelected():
for ob in obsel:
group= ob.DupGroup
if group != None:
newname= group.name
@@ -241,7 +242,7 @@ def main():
global renameCount
Window.WaitCursor(1)
for ob in Object.GetSelected():
for ob in obsel:
if setDataNameWrapper(ob, ob.name):
renameCount+=1
return 0