diff options
-rw-r--r-- | release/scripts/bpymodules/BPyMathutils.py | 27 | ||||
-rw-r--r-- | release/scripts/bpymodules/BPyMesh.py | 17 | ||||
-rw-r--r-- | release/scripts/mesh_solidify.py | 30 | ||||
-rw-r--r-- | release/scripts/scripttemplate_mesh_edit.py | 12 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_library.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 11 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 1 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_ID.h | 2 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Library.c | 4 | ||||
-rw-r--r-- | source/blender/src/editobject.c | 2 | ||||
-rw-r--r-- | source/blender/src/filesel.c | 23 |
11 files changed, 87 insertions, 44 deletions
diff --git a/release/scripts/bpymodules/BPyMathutils.py b/release/scripts/bpymodules/BPyMathutils.py index ba15a8b8e8d..27736b4169e 100644 --- a/release/scripts/bpymodules/BPyMathutils.py +++ b/release/scripts/bpymodules/BPyMathutils.py @@ -210,3 +210,30 @@ def plane2mat(plane, normalize= False): mat.resize4x4() tmat= Blender.Mathutils.TranslationMatrix(cent) return mat * tmat + + +# Used for mesh_solidify.py and mesh_wire.py + +# returns a length from an angle +# Imaging a 2d space. +# there is a hoz line at Y1 going to inf on both X ends, never moves (LINEA) +# down at Y0 is a unit length line point up at (angle) from X0,Y0 (LINEB) +# This function returns the length of LINEB at the point it would intersect LINEA +# - Use this for working out how long to make the vector - differencing it from surrounding faces, +# import math +from math import pi, sin, cos, sqrt + +def angleToLength(angle): + # Alredy accounted for + if angle < 0.000001: + return 1.0 + + angle = 2*pi*angle/360 + x,y = cos(angle), sin(angle) + # print "YX", x,y + # 0 d is hoz to the right. + # 90d is vert upward. + fac=1/x + x=x*fac + y=y*fac + return sqrt((x*x)+(y*y)) diff --git a/release/scripts/bpymodules/BPyMesh.py b/release/scripts/bpymodules/BPyMesh.py index b28ec58c84d..8cba68f012b 100644 --- a/release/scripts/bpymodules/BPyMesh.py +++ b/release/scripts/bpymodules/BPyMesh.py @@ -1151,6 +1151,23 @@ def pointInsideMesh(ob, pt): return len([None for f in me.faces if ptInFaceXYBounds(f, obSpacePt) if faceIntersect(f)]) % 2 +def faceAngles(f): + Ang= Blender.Mathutils.AngleBetweenVecs + if len(f) == 3: + v1,v2,v3 = [v.co for v in f] + a1= Ang(v2-v1,v3-v1) + a2= Ang(v1-v2,v3-v2) + a3 = 180 - (a1+a2) # a3= Mathutils.AngleBetweenVecs(v2-v3,v1-v3) + return a1,a2,a3 + + else: + v1,v2,v3,v4 = [v.co for v in f] + a1= Ang(v2-v1,v4-v1) + a2= Ang(v1-v2,v3-v2) + a3= Ang(v2-v3,v4-v3) + a4= Ang(v3-v4,v1-v4) + return a1,a2,a3,a4 + # NMesh wrapper Vector= Blender.Mathutils.Vector class NMesh(object): diff --git a/release/scripts/mesh_solidify.py b/release/scripts/mesh_solidify.py index 2e58513845c..91943db7a77 100644 --- a/release/scripts/mesh_solidify.py +++ b/release/scripts/mesh_solidify.py @@ -23,6 +23,8 @@ import BPyMesh import BPyMessages # reload(BPyMessages) +from BPyMathutils import angleToLength + # python 2.3 has no reversed() iterator. this will only work on lists and tuples try: reversed @@ -74,32 +76,6 @@ def copy_facedata_multilayer(me, from_faces, to_faces): Ang= Mathutils.AngleBetweenVecs SMALL_NUM=0.00001 - -# returns a length from an angle -# Imaging a 2d space. -# there is a hoz line at Y1 going to inf on both X ends, never moves (LINEA) -# down at Y0 is a unit length line point up at (angle) from X0,Y0 (LINEB) -# This function returns the length of LINEB at the point it would intersect LINEA -# - Use this for working out how long to make the vector - differencing it from surrounding faces, -# import math -from math import pi, sin, cos, sqrt - -def lengthFromAngle(angle): - ''' # Alredy accounted for - if angle < SMALL_NUM: - return 1.0 - ''' - angle = 2*pi*angle/360 - x,y = cos(angle), sin(angle) - # print "YX", x,y - # 0 d is hoz to the right. - # 90d is vert upward. - fac=1/x - x=x*fac - y=y*fac - return sqrt((x*x)+(y*y)) - - def main(): scn = bpy.scenes.active ob = scn.objects.active @@ -164,7 +140,7 @@ def main(): elif a < SMALL_NUM: length+= 1 else: - length+= lengthFromAngle(a) + length+= angleToLength(a) length= length/len(vertFaces[i]) #print 'LENGTH %.6f' % length diff --git a/release/scripts/scripttemplate_mesh_edit.py b/release/scripts/scripttemplate_mesh_edit.py index 746f11d48ee..27607f2c69c 100644 --- a/release/scripts/scripttemplate_mesh_edit.py +++ b/release/scripts/scripttemplate_mesh_edit.py @@ -6,10 +6,11 @@ Group: 'ScriptTemplate' Tooltip: 'Add a new text for editing a mesh' """ -from Blender import Text, Window +from Blender import Window +import bpy -script_data = ''' -#!BPY +script_data = \ +'''#!BPY """ Name: 'My Mesh Script' Blender: 243 @@ -21,6 +22,7 @@ Tooltip: 'Put some useful info here' from Blender import Scene, Mesh, Window, sys import BPyMessages +import bpy def my_mesh_util(me): # This function runs out of editmode with a mesh @@ -53,7 +55,7 @@ def my_mesh_util(me): def main(): # Gets the current scene, there can be many scenes in 1 blend file. - sce = Scene.GetCurrent() + sce = bpy.scenes.active # Get the active object, there can only ever be 1 # and the active object is always the editmode object. @@ -71,7 +73,7 @@ def main(): if is_editmode: Window.EditMode(1) Window.WaitCursor(1) - me = ob_act.getData(mesh=1) + me = ob_act.getData(mesh=1) # old NMesh api is default t = sys.time() # Run the mesh editing function diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index f73c1b23a8a..064acf12eb5 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -62,7 +62,7 @@ void free_main(struct Main *mainvar); void splitIDname(char *name, char *left, int *nr); void rename_id(struct ID *id, char *name); void test_idbutton(char *name); -void all_local(struct Library *lib); +void all_local(struct Library *lib, int untagged_only); struct ID *find_id(char *type, char *name); void clear_id_newpoins(void); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 803059ee0b4..a5a0c2bead2 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -983,7 +983,7 @@ static void lib_indirect_test_id(ID *id) /* if lib!=NULL, only all from lib local */ -void all_local(Library *lib) +void all_local(Library *lib, int untagged_only) { ListBase *lbarray[MAX_LIBARRAY], tempbase={0, 0}; ID *id, *idn; @@ -997,7 +997,14 @@ void all_local(Library *lib) id->newid= NULL; idn= id->next; /* id is possibly being inserted again */ - if(id->flag & (LIB_EXTERN|LIB_INDIRECT|LIB_NEW)) { + /* The check on the second line (LIB_APPEND_TAG) is done so its + * possible to tag data you dont want to be made local, used for + * appending data, so any libdata alredy linked wont become local + * (very nasty to discover all your links are lost after appending) + * */ + if(id->flag & (LIB_EXTERN|LIB_INDIRECT|LIB_NEW) && + (untagged_only==0 || !(id->flag & LIB_APPEND_TAG))) + { if(lib==NULL || id->lib==lib) { id->flag &= ~(LIB_EXTERN|LIB_INDIRECT|LIB_NEW); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 6ef6f18caee..41199d243f9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -7480,7 +7480,6 @@ void BLO_library_append(SpaceFile *sfile, char *dir, int idcode) } } } - DAG_scene_sort(G.scene); } /* ************* READ LIBRARY ************** */ diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h index 080d2861a19..ce03bdc5e84 100644 --- a/source/blender/makesdna/DNA_ID.h +++ b/source/blender/makesdna/DNA_ID.h @@ -215,6 +215,8 @@ typedef struct Library { #define LIB_FAKEUSER 512 /* free test flag */ #define LIB_DOIT 1024 +/* */ +#define LIB_APPEND_TAG 2048 #ifdef __cplusplus } diff --git a/source/blender/python/api2_2x/Library.c b/source/blender/python/api2_2x/Library.c index daccf31489e..dd7cf18cb3d 100644 --- a/source/blender/python/api2_2x/Library.c +++ b/source/blender/python/api2_2x/Library.c @@ -416,7 +416,7 @@ static PyObject *M_Library_Update( PyObject * self ) break; lib = lib->id.next; } - all_local( lib ); + all_local( lib, 0 ); } Py_INCREF( Py_None ); @@ -620,7 +620,7 @@ PyObject *LibraryData_importLibData( BPy_LibraryData *self, char *name, for( lib = G.main->library.first; lib; lib = lib->id.next ) if( strcmp( longFilename, lib->name ) == 0 ) { if( mode != FILE_LINK ) { - all_local( lib ); + all_local( lib, 0 ); lib = NULL; } break; diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c index 6e1bbe61039..0a1f29c0d48 100644 --- a/source/blender/src/editobject.c +++ b/source/blender/src/editobject.c @@ -4449,7 +4449,7 @@ void make_local(int mode) if(G.scene->id.lib) return; if(mode==3) { - all_local(NULL); /* NULL is all libs */ + all_local(NULL, 0); /* NULL is all libs */ allqueue(REDRAWALL, 0); return; } diff --git a/source/blender/src/filesel.c b/source/blender/src/filesel.c index d2ac3115c0f..d8f1b732e19 100644 --- a/source/blender/src/filesel.c +++ b/source/blender/src/filesel.c @@ -2395,8 +2395,20 @@ static void do_library_append(SpaceFile *sfile) Object *ob; int idcode = groupname_to_code(group); + if((sfile->flag & FILE_LINK)==0) { + /* tag everything, all untagged data can be made local */ + ID *id; + ListBase *lbarray[MAX_LIBARRAY]; + int a; + + a= set_listbasepointers(G.main, lbarray); + while(a--) { + for(id= lbarray[a]->first; id; id= id->next) id->flag |= LIB_APPEND_TAG; + } + } + BLO_library_append(sfile, dir, idcode); - + /* DISPLISTS? */ ob= G.main->object.first; while(ob) { @@ -2413,14 +2425,15 @@ static void do_library_append(SpaceFile *sfile) lib= lib->id.next; } - if(lib) { - if((sfile->flag & FILE_LINK)==0) - all_local(lib); + /* make local */ + if(lib && (sfile->flag & FILE_LINK)==0) { + all_local(lib, 1); } + DAG_scene_sort(G.scene); + /* in sfile->dir is the whole lib name */ BLI_strncpy(G.lib, sfile->dir, sizeof(G.lib) ); - } } |