diff options
author | Martin Poirier <theeth@yahoo.com> | 2008-08-05 06:27:09 +0400 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2008-08-05 06:27:09 +0400 |
commit | e2380665259eb0f74376ffda2ab791ba8e1bb9ef (patch) | |
tree | ac5134d6f03956f51e4498e828143482d36287fa /source | |
parent | d4b646103a6cae433d58bf7e2f4953f81358835b (diff) | |
parent | 07bc1e56fec864748c160af02659e3fcff317be9 (diff) |
Merging with trunk
15568 - 15963
Diffstat (limited to 'source')
250 files changed, 9488 insertions, 2924 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index f61b300f708..7dc10c53e22 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -437,5 +437,7 @@ void weight_to_rgb(float input, float *fr, float *fg, float *fb); /* determines required DerivedMesh data according to view and edit modes */ CustomDataMask get_viewedit_datamask(); +void DM_add_tangent_layer(DerivedMesh *dm); + #endif diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index f76cdbc64b7..d951c8401e3 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -41,7 +41,7 @@ struct ListBase; struct MemFile; #define BLENDER_VERSION 246 -#define BLENDER_SUBVERSION 0 +#define BLENDER_SUBVERSION 1 #define BLENDER_MINVERSION 245 #define BLENDER_MINSUBVERSION 15 diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 62289d227c7..8c9634cba06 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -175,6 +175,7 @@ typedef struct Global { #define G_WEIGHTPAINT (1 << 15) #define G_TEXTUREPAINT (1 << 16) /* #define G_NOFROZEN (1 << 17) also removed */ +#define G_GREASEPENCIL (1 << 17) #define G_DRAWEDGES (1 << 18) #define G_DRAWCREASES (1 << 19) #define G_DRAWSEAMS (1 << 20) @@ -265,3 +266,4 @@ extern Global G; #endif + diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index 2d7d0e9286f..2274c54ad3b 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -46,6 +46,7 @@ struct ID; typedef union { int i; float f; + double d; char *str; struct ID *id; struct { diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h index 78a8f60caeb..fade0f8cbaa 100644 --- a/source/blender/blenkernel/BKE_texture.h +++ b/source/blender/blenkernel/BKE_texture.h @@ -62,6 +62,7 @@ struct Tex *copy_texture(struct Tex *tex); void make_local_texture(struct Tex *tex); void autotexname(struct Tex *tex); struct Tex *give_current_texture(struct Object *ob, int act); +struct Tex *give_current_world_texture(void); struct TexMapping *add_mapping(void); void init_mapping(struct TexMapping *texmap); diff --git a/source/blender/blenkernel/bad_level_call_stubs/stubs.c b/source/blender/blenkernel/bad_level_call_stubs/stubs.c index c913820205b..3ad11a61de3 100644 --- a/source/blender/blenkernel/bad_level_call_stubs/stubs.c +++ b/source/blender/blenkernel/bad_level_call_stubs/stubs.c @@ -1,4 +1,3 @@ - /** * $Id$ * @@ -355,7 +354,8 @@ TimeMarker *get_frame_marker(int frame){return 0;}; /* editseq.c */ Sequence *get_forground_frame_seq(int frame){return 0;}; -void set_last_seq(Sequence *seq){}; +void clear_last_seq(Sequence *seq){}; + /* modifier.c stub */ void harmonic_coordinates_bind(struct MeshDeformModifierData *mmd, diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 4d3f9143b85..67cf89d5ee2 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -59,6 +59,7 @@ #include "BLI_edgehash.h" #include "BLI_editVert.h" #include "BLI_linklist.h" +#include "BLI_memarena.h" #include "BKE_cdderivedmesh.h" #include "BKE_customdata.h" @@ -2844,6 +2845,127 @@ int editmesh_get_first_deform_matrices(float (**deformmats)[3][3], float (**defo return numleft; } +void DM_add_tangent_layer(DerivedMesh *dm) +{ + /* mesh vars */ + MTFace *mtface, *tf; + MFace *mface, *mf; + MVert *mvert, *v1, *v2, *v3, *v4; + MemArena *arena= NULL; + VertexTangent **vtangents= NULL; + float (*orco)[3]= NULL, (*tangent)[3]; + float *uv1, *uv2, *uv3, *uv4, *vtang; + float fno[3], tang[3], uv[4][2]; + int i, j, len, mf_vi[4], totvert, totface; + + if(CustomData_get_layer_index(&dm->faceData, CD_TANGENT) != -1) + return; + + /* check we have all the needed layers */ + totvert= dm->getNumVerts(dm); + totface= dm->getNumFaces(dm); + + mvert= dm->getVertArray(dm); + mface= dm->getFaceArray(dm); + mtface= dm->getFaceDataArray(dm, CD_MTFACE); + + if(!mtface) { + orco= dm->getVertDataArray(dm, CD_ORCO); + if(!orco) + return; + } + + /* create tangent layer */ + DM_add_face_layer(dm, CD_TANGENT, CD_CALLOC, NULL); + tangent= DM_get_face_data_layer(dm, CD_TANGENT); + + /* allocate some space */ + arena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE); + BLI_memarena_use_calloc(arena); + vtangents= MEM_callocN(sizeof(VertexTangent*)*totvert, "VertexTangent"); + + /* sum tangents at connected vertices */ + for(i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++) { + v1= &mvert[mf->v1]; + v2= &mvert[mf->v2]; + v3= &mvert[mf->v3]; + + if (mf->v4) { + v4= &mvert[mf->v4]; + CalcNormFloat4(v4->co, v3->co, v2->co, v1->co, fno); + } + else { + v4= NULL; + CalcNormFloat(v3->co, v2->co, v1->co, fno); + } + + if(mtface) { + uv1= tf->uv[0]; + uv2= tf->uv[1]; + uv3= tf->uv[2]; + uv4= tf->uv[3]; + } + else { + uv1= uv[0]; uv2= uv[1]; uv3= uv[2]; uv4= uv[3]; + spheremap(orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2], &uv[0][0], &uv[0][1]); + spheremap(orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2], &uv[1][0], &uv[1][1]); + spheremap(orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2], &uv[2][0], &uv[2][1]); + if(v4) + spheremap(orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2], &uv[3][0], &uv[3][1]); + } + + tangent_from_uv(uv1, uv2, uv3, v1->co, v2->co, v3->co, fno, tang); + sum_or_add_vertex_tangent(arena, &vtangents[mf->v1], tang, uv1); + sum_or_add_vertex_tangent(arena, &vtangents[mf->v2], tang, uv2); + sum_or_add_vertex_tangent(arena, &vtangents[mf->v3], tang, uv3); + + if(mf->v4) { + v4= &mvert[mf->v4]; + + tangent_from_uv(uv1, uv3, uv4, v1->co, v3->co, v4->co, fno, tang); + sum_or_add_vertex_tangent(arena, &vtangents[mf->v1], tang, uv1); + sum_or_add_vertex_tangent(arena, &vtangents[mf->v3], tang, uv3); + sum_or_add_vertex_tangent(arena, &vtangents[mf->v4], tang, uv4); + } + } + + /* write tangent to layer */ + for(i=0, tf=mtface, mf=mface; i < totface; mf++, tf++, i++, tangent+=4) { + len= (mf->v4)? 4 : 3; + + if(mtface) { + uv1= tf->uv[0]; + uv2= tf->uv[1]; + uv3= tf->uv[2]; + uv4= tf->uv[3]; + } + else { + uv1= uv[0]; uv2= uv[1]; uv3= uv[2]; uv4= uv[3]; + spheremap(orco[mf->v1][0], orco[mf->v1][1], orco[mf->v1][2], &uv[0][0], &uv[0][1]); + spheremap(orco[mf->v2][0], orco[mf->v2][1], orco[mf->v2][2], &uv[1][0], &uv[1][1]); + spheremap(orco[mf->v3][0], orco[mf->v3][1], orco[mf->v3][2], &uv[2][0], &uv[2][1]); + if(len==4) + spheremap(orco[mf->v4][0], orco[mf->v4][1], orco[mf->v4][2], &uv[3][0], &uv[3][1]); + } + + mf_vi[0]= mf->v1; + mf_vi[1]= mf->v2; + mf_vi[2]= mf->v3; + mf_vi[3]= mf->v4; + + for(j=0; j<len; j++) { + vtang= find_vertex_tangent(vtangents[mf_vi[j]], mtface ? tf->uv[j] : uv[j]); + + VECCOPY(tangent[j], vtang); + Normalize(tangent[j]); + } + } + + BLI_memarena_free(arena); + MEM_freeN(vtangents); +} + + /* ************************* fluidsim bobj file handling **************************** */ #ifndef DISABLE_ELBEEM diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 26c5d186d87..cfcab54058d 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -1291,116 +1291,6 @@ int cloth_collision_moving ( ClothModifierData *clmd, CollisionModifierData *col return 1; } -int cloth_do_selfcollisions(ClothModifierData * clmd) -{ - int ret2 = 0, l; - Cloth *cloth = clmd->clothObject; - - if ( clmd->clothObject->bvhselftree ) - { - for(l = 0; l < clmd->coll_parms->self_loop_count; l++) - { - BVHTreeOverlap *overlap = NULL; - ClothVertex *verts = clmd->clothObject->verts; // needed for openMP - int k; - int ret = 0, result = 0; - - // search for overlapping collision pairs - overlap = BLI_bvhtree_overlap ( cloth->bvhselftree, cloth->bvhselftree, &result ); - -// #pragma omp parallel for private(k, i, j) schedule(static) - for ( k = 0; k < result; k++ ) - { - float temp[3]; - float length = 0; - float mindistance; - int i, j; - - i = overlap[k].indexA; - j = overlap[k].indexB; - - mindistance = clmd->coll_parms->selfepsilon* ( cloth->verts[i].avg_spring_len + cloth->verts[j].avg_spring_len ); - - if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ) - { - if ( ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) - && ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) ) - { - continue; - } - } - - VECSUB ( temp, verts[i].tx, verts[j].tx ); - - if ( ( ABS ( temp[0] ) > mindistance ) || ( ABS ( temp[1] ) > mindistance ) || ( ABS ( temp[2] ) > mindistance ) ) continue; - - // check for adjacent points (i must be smaller j) - if ( BLI_edgehash_haskey ( cloth->edgehash, MIN2(i, j), MAX2(i, j) ) ) - { - continue; - } - - length = Normalize ( temp ); - - if ( length < mindistance ) - { - float correction = mindistance - length; - - if ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) - { - VecMulf ( temp, -correction ); - VECADD ( verts[j].tx, verts[j].tx, temp ); - } - else if ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) - { - VecMulf ( temp, correction ); - VECADD ( verts[i].tx, verts[i].tx, temp ); - } - else - { - VecMulf ( temp, -correction*0.5 ); - VECADD ( verts[j].tx, verts[j].tx, temp ); - - VECSUB ( verts[i].tx, verts[i].tx, temp ); - } - ret = 1; - ret2 += ret; - } - else - { - // check for approximated time collisions - } - } - - if ( overlap ) - MEM_freeN ( overlap ); - - if(!ret) - break; - - } - //////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////// - // SELFCOLLISIONS: update velocities - //////////////////////////////////////////////////////////// - if ( ret2 ) - { - int i; - ClothVertex *verts = clmd->clothObject->verts; // needed for openMP - - for ( i = 0; i < cloth->numverts; i++ ) - { - if ( ! ( verts [i].flags & CLOTH_VERT_FLAG_PINNED ) ) - { - VECSUB ( verts[i].tv, verts[i].tx, verts[i].txold ); - } - } - } - //////////////////////////////////////////////////////////// - } - return ret2; -} // return all collision objects in scene // collision object will exclude self @@ -1437,6 +1327,9 @@ CollisionModifierData **get_collisionobjects(Object *self, int *numcollobj) if(coll_ob == self) continue; + + if( !collmd->bvhtree) + continue; if(numobj >= maxobj) { @@ -1544,7 +1437,7 @@ int cloth_bvh_objcollision ( Object *ob, ClothModifierData * clmd, float step, f { Cloth *cloth=NULL; BVHTree *cloth_bvh=NULL; - long i=0, numfaces = 0, numverts = 0; + int i=0, numfaces = 0, numverts = 0, k, l, j; int rounds = 0; // result counts applied collisions; ic is for debug output; ClothVertex *verts = NULL; int ret = 0, ret2 = 0; @@ -1644,21 +1537,122 @@ int cloth_bvh_objcollision ( Object *ob, ClothModifierData * clmd, float step, f VECADD ( verts[i].tx, verts[i].txold, verts[i].tv ); } //////////////////////////////////////////////////////////// - + //////////////////////////////////////////////////////////// // Test on *simple* selfcollisions //////////////////////////////////////////////////////////// if ( clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF ) { - ret2 += cloth_do_selfcollisions(clmd); + for(l = 0; l < clmd->coll_parms->self_loop_count; l++) + { + // TODO: add coll quality rounds again + BVHTreeOverlap *overlap = NULL; + int result = 0; + + // collisions = 1; + verts = cloth->verts; // needed for openMP + + numfaces = clmd->clothObject->numfaces; + numverts = clmd->clothObject->numverts; + + verts = cloth->verts; + + if ( cloth->bvhselftree ) + { + // search for overlapping collision pairs + overlap = BLI_bvhtree_overlap ( cloth->bvhselftree, cloth->bvhselftree, &result ); + + // #pragma omp parallel for private(k, i, j) schedule(static) + for ( k = 0; k < result; k++ ) + { + float temp[3]; + float length = 0; + float mindistance; + + i = overlap[k].indexA; + j = overlap[k].indexB; + + mindistance = clmd->coll_parms->selfepsilon* ( cloth->verts[i].avg_spring_len + cloth->verts[j].avg_spring_len ); + + if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ) + { + if ( ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) + && ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) ) + { + continue; + } + } + + VECSUB ( temp, verts[i].tx, verts[j].tx ); + + if ( ( ABS ( temp[0] ) > mindistance ) || ( ABS ( temp[1] ) > mindistance ) || ( ABS ( temp[2] ) > mindistance ) ) continue; + + // check for adjacent points (i must be smaller j) + if ( BLI_edgehash_haskey ( cloth->edgehash, MIN2(i, j), MAX2(i, j) ) ) + { + continue; + } + + length = Normalize ( temp ); + + if ( length < mindistance ) + { + float correction = mindistance - length; + + if ( cloth->verts [i].flags & CLOTH_VERT_FLAG_PINNED ) + { + VecMulf ( temp, -correction ); + VECADD ( verts[j].tx, verts[j].tx, temp ); + } + else if ( cloth->verts [j].flags & CLOTH_VERT_FLAG_PINNED ) + { + VecMulf ( temp, correction ); + VECADD ( verts[i].tx, verts[i].tx, temp ); + } + else + { + VecMulf ( temp, -correction*0.5 ); + VECADD ( verts[j].tx, verts[j].tx, temp ); + + VECSUB ( verts[i].tx, verts[i].tx, temp ); + } + ret = 1; + ret2 += ret; + } + else + { + // check for approximated time collisions + } + } + + if ( overlap ) + MEM_freeN ( overlap ); + + } + } + //////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////// + // SELFCOLLISIONS: update velocities + //////////////////////////////////////////////////////////// + if ( ret2 ) + { + for ( i = 0; i < cloth->numverts; i++ ) + { + if ( ! ( verts [i].flags & CLOTH_VERT_FLAG_PINNED ) ) + { + VECSUB ( verts[i].tv, verts[i].tx, verts[i].txold ); + } + } + } + //////////////////////////////////////////////////////////// } - //////////////////////////////////////////////////////////// } while ( ret2 && ( clmd->coll_parms->loop_count>rounds ) ); if(collobjs) - + MEM_freeN(collobjs); + MEM_freeN(collobjs); return MIN2 ( ret, 1 ); } diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 068501780bc..f13fd5f9963 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -558,8 +558,8 @@ static void contarget_get_mesh_mat (Object *ob, char *substring, float mat[][4]) if (dgroup < 0) return; /* get DerivedMesh */ - if (G.obedit && G.editMesh) { - /* we are in editmode, so get a special derived mesh */ + if ((G.obedit == ob) && (G.editMesh)) { + /* target is in editmode, so get a special derived mesh */ dm = CDDM_from_editmesh(G.editMesh, ob->data); } else { diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 501293ecd81..2c1f6bb84c1 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -265,14 +265,34 @@ static void layerSwap_tface(void *data, int *corner_indices) { MTFace *tf = data; float uv[4][2]; + const static short pin_flags[4] = + { TF_PIN1, TF_PIN2, TF_PIN3, TF_PIN4 }; + const static char sel_flags[4] = + { TF_SEL1, TF_SEL2, TF_SEL3, TF_SEL4 }; + short unwrap = tf->unwrap & ~(TF_PIN1 | TF_PIN2 | TF_PIN3 | TF_PIN4); + char flag = tf->flag & ~(TF_SEL1 | TF_SEL2 | TF_SEL3 | TF_SEL4); int j; for(j = 0; j < 4; ++j) { - uv[j][0] = tf->uv[corner_indices[j]][0]; - uv[j][1] = tf->uv[corner_indices[j]][1]; + int source_index = corner_indices[j]; + + uv[j][0] = tf->uv[source_index][0]; + uv[j][1] = tf->uv[source_index][1]; + + // swap pinning flags around + if(tf->unwrap & pin_flags[source_index]) { + unwrap |= pin_flags[j]; + } + + // swap selection flags around + if(tf->flag & sel_flags[source_index]) { + flag |= sel_flags[j]; + } } memcpy(tf->uv, uv, sizeof(tf->uv)); + tf->unwrap = unwrap; + tf->flag = flag; } static void layerDefault_tface(void *data, int count) @@ -532,13 +552,14 @@ const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { {sizeof(float)*3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, {sizeof(MTexPoly), "MTexPoly", 1, "Face Texture", NULL, NULL, NULL, NULL, NULL}, {sizeof(MLoopUV), "MLoopUV", 1, "UV coord", NULL, NULL, layerInterp_mloopuv, NULL, NULL}, - {sizeof(MLoopCol), "MLoopCol", 1, "Col", NULL, NULL, layerInterp_mloopcol, NULL, layerDefault_mloopcol} + {sizeof(MLoopCol), "MLoopCol", 1, "Col", NULL, NULL, layerInterp_mloopcol, NULL, layerDefault_mloopcol}, + {sizeof(float)*3*4, "", 0, NULL, NULL, NULL, NULL, NULL, NULL} }; const char *LAYERTYPENAMES[CD_NUMTYPES] = { "CDMVert", "CDMSticky", "CDMDeformVert", "CDMEdge", "CDMFace", "CDMTFace", "CDMCol", "CDOrigIndex", "CDNormal", "CDFlags","CDMFloatProperty", - "CDMIntProperty","CDMStringProperty", "CDOrigSpace", "CDOrco", "CDMTexPoly", "CDMLoopUV", "CDMloopCol"}; + "CDMIntProperty","CDMStringProperty", "CDOrigSpace", "CDOrco", "CDMTexPoly", "CDMLoopUV", "CDMloopCol", "CDTangent"}; const CustomDataMask CD_MASK_BAREMESH = CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MFACE; @@ -552,7 +573,7 @@ const CustomDataMask CD_MASK_EDITMESH = const CustomDataMask CD_MASK_DERIVEDMESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | - CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORCO; + CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORCO | CD_MASK_TANGENT; const CustomDataMask CD_MASK_BMESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR; const CustomDataMask CD_MASK_FACECORNERS = diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 2ef2f3a1b77..b16f52571f6 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -54,7 +54,8 @@ static char idp_size_table[] = { sizeof(float)*16, /*Matrix type, deprecated*/ 0, /*arrays don't have a fixed size*/ sizeof(ListBase), /*Group type*/ - sizeof(void*) + sizeof(void*), + sizeof(double) }; @@ -365,10 +366,14 @@ IDProperty *IDP_New(int type, IDPropertyTemplate val, char *name) prop = MEM_callocN(sizeof(IDProperty), "IDProperty float"); *(float*)&prop->data.val = val.f; break; + case IDP_DOUBLE: + prop = MEM_callocN(sizeof(IDProperty), "IDProperty float"); + *(double*)&prop->data.val = val.d; + break; case IDP_ARRAY: { - /*for now, we only support float and int arrays*/ - if (val.array.type == IDP_FLOAT || val.array.type == IDP_INT) { + /*for now, we only support float and int and double arrays*/ + if (val.array.type == IDP_FLOAT || val.array.type == IDP_INT || val.array.type == IDP_DOUBLE) { prop = MEM_callocN(sizeof(IDProperty), "IDProperty array"); prop->len = prop->totallen = val.array.len; prop->subtype = val.array.type; @@ -411,6 +416,10 @@ IDProperty *IDP_New(int type, IDPropertyTemplate val, char *name) prop->type = type; strncpy(prop->name, name, MAX_IDPROP_NAME); + + /*security null byte*/ + prop->name[MAX_IDPROP_NAME-1] = 0; + return prop; } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index e8bcae42d5a..54915058bab 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -915,7 +915,10 @@ void lattice_calc_modifiers(Object *ob) mti->deformVerts(md, ob, NULL, vertexCos, numVerts); } - if (vertexCos) { + /* always displist to make this work like derivedmesh */ + if (!vertexCos) vertexCos = lattice_getVertexCos(ob, &numVerts); + + { DispList *dl = MEM_callocN(sizeof(*dl), "lt_dl"); dl->type = DL_VERTS; dl->parts = 1; diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index f13f8ef0298..503654717ae 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -1130,8 +1130,18 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, mface[numFaces].v1 = vert_map[mface[numFaces].v1]; mface[numFaces].v2 = vert_map[mface[numFaces].v2]; mface[numFaces].v3 = vert_map[mface[numFaces].v3]; - if(mface[numFaces].v4) + if(mface[numFaces].v4) { mface[numFaces].v4 = vert_map[mface[numFaces].v4]; + + test_index_face(&mface[numFaces], &result->faceData, + numFaces, 4); + } + else + { + test_index_face(&mface[numFaces], &result->faceData, + numFaces, 3); + } + origindex[numFaces] = ORIGINDEX_NONE; numFaces++; @@ -1221,8 +1231,17 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, mface[numFaces].v1 = vert_map[mface[numFaces].v1]; mface[numFaces].v2 = vert_map[mface[numFaces].v2]; mface[numFaces].v3 = vert_map[mface[numFaces].v3]; - if(mface[numFaces].v4) + if(mface[numFaces].v4) { mface[numFaces].v4 = vert_map[mface[numFaces].v4]; + + test_index_face(&mface[numFaces], &result->faceData, + numFaces, 4); + } + else + { + test_index_face(&mface[numFaces], &result->faceData, + numFaces, 3); + } origindex[numFaces] = ORIGINDEX_NONE; numFaces++; diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 24a3d348ae7..643f90637ad 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -3744,6 +3744,9 @@ int psys_get_particle_state(Object *ob, ParticleSystem *psys, int p, ParticleKey /* TODO: pa_clump vgroup */ do_clump(state,key1,t,part->clumpfac,part->clumppow,1.0); + + if(psys->lattice) + calc_latt_deform(state->co,1.0f); } else{ if (pa) { /* TODO PARTICLE - should this ever be NULL? - Campbell */ diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index f70648965f4..7dca87d5c13 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -2797,7 +2797,10 @@ void do_effectors(int pa_no, ParticleData *pa, ParticleKey *state, Object *ob, P epart= epsys->part; pd= epart->pd; totepart= epsys->totpart; - + + if(totepart <= 0) + continue; + if(pd->forcefield==PFIELD_HARMONIC){ /* every particle is mapped to only one harmonic effector particle */ p= pa_no%epsys->totpart; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 2898dca767c..553107dd264 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -303,7 +303,7 @@ void set_scene_bg(Scene *sce) int flag; // Note: this here is defined in editseq.c (BIF_editseq.h), NOT in blenkernel! - set_last_seq(NULL); + clear_last_seq(); G.scene= sce; diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 9005db1312f..d5b5ab6d63e 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -2053,7 +2053,6 @@ static void softbody_calc_forces(Object *ob, float forcetime, float timenow, int /* check conditions for various options */ do_deflector= query_external_colliders(ob); - do_effector= pdInitEffectors(ob,NULL); do_selfcollision=((ob->softflag & OB_SB_EDGES) && (sb->bspring)&& (ob->softflag & OB_SB_SELF)); do_springcollision=do_deflector && (ob->softflag & OB_SB_EDGES) &&(ob->softflag & OB_SB_EDGECOLL); do_aero=((sb->aeroedge)&& (ob->softflag & OB_SB_EDGES)); @@ -2061,9 +2060,10 @@ static void softbody_calc_forces(Object *ob, float forcetime, float timenow, int iks = 1.0f/(1.0f-sb->inspring)-1.0f ;/* inner spring constants function */ bproot= sb->bpoint; /* need this for proper spring addressing */ - - if (do_springcollision || do_aero) scan_for_ext_spring_forces(ob,timenow); + /* after spring scan because it uses Effoctors too */ + do_effector= pdInitEffectors(ob,NULL); + if (do_deflector) { float defforce[3]; do_deflector = sb_detect_aabb_collisionCached(defforce,ob->lay,ob,timenow); diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 37804bf68ac..ad139220785 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -53,6 +53,7 @@ #include "DNA_world_types.h" #include "DNA_brush_types.h" #include "DNA_node_types.h" +#include "DNA_scene_types.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -731,7 +732,7 @@ Tex *give_current_texture(Object *ob, int act) bNode *node; if(ob==0) return 0; - if(ob->totcol==0) return 0; + if(ob->totcol==0 && !(ob->type==OB_LAMP)) return 0; if(ob->type==OB_LAMP) { la=(Lamp *)ob->data; @@ -775,6 +776,18 @@ Tex *give_current_texture(Object *ob, int act) return tex; } +Tex *give_current_world_texture(void) +{ + MTex *mtex = 0; + Tex *tex = 0; + + if(!(G.scene->world)) return 0; + + mtex= G.scene->world->mtex[(int)(G.scene->world->texact)]; + if(mtex) tex= mtex->tex; + + return tex; +} /* ------------------------------------------------------------------------- */ diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index a97b9ca6672..4ceb9762a7b 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -484,15 +484,14 @@ static char get_largest_axis(float *bv) } } -static void bvh_div_nodes(BVHTree *tree, BVHNode *node, int start, int end, char lastaxis) +static void bvh_div_nodes(BVHTree *tree, BVHNode *node, int start, int end) { - char laxis; int i, tend; BVHNode *tnode; int slice = (end-start+tree->tree_type-1)/tree->tree_type; //division rounded up // Determine which axis to split along - laxis = get_largest_axis(node->bv); + char laxis = get_largest_axis(node->bv); // split nodes along longest axis for (i=0; start < end; start += slice, i++) //i counts the current child @@ -515,7 +514,7 @@ static void bvh_div_nodes(BVHTree *tree, BVHNode *node, int start, int end, char if(tend != end) partition_nth_element(tree->nodes, start, end, tend, laxis); refit_kdop_hull(tree, tnode, start, tend); - bvh_div_nodes(tree, tnode, start, tend, laxis); + bvh_div_nodes(tree, tnode, start, tend); } node->totnode++; } @@ -586,7 +585,7 @@ void BLI_bvhtree_balance(BVHTree *tree) // refit root bvh node refit_kdop_hull(tree, tree->nodes[tree->totleaf], 0, tree->totleaf); // create + balance tree - bvh_div_nodes(tree, tree->nodes[tree->totleaf], 0, tree->totleaf, 0); + bvh_div_nodes(tree, tree->nodes[tree->totleaf], 0, tree->totleaf); // verify_tree(tree); } diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c index 6685e1b6dc5..4cc8e45b1cf 100644 --- a/source/blender/blenlib/intern/arithb.c +++ b/source/blender/blenlib/intern/arithb.c @@ -60,6 +60,7 @@ #define SMALL_NUMBER 1.e-8 #define ABS(x) ((x) < 0 ? -(x) : (x)) #define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } +#define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c) #if defined(WIN32) || defined(__APPLE__) @@ -2547,11 +2548,6 @@ int IsectPQ2Df(float pt[2], float v1[2], float v2[2], float v3[2], float v4[2]) } - - /* copied from Geometry.c - todo - move to arithb.c or some other generic place we can reuse */ -#define SIDE_OF_LINE(pa,pb,pp) ((pa[0]-pp[0])*(pb[1]-pp[1]))-((pb[0]-pp[0])*(pa[1]-pp[1])) -#define POINT_IN_TRI(p0,p1,p2,p3) ((SIDE_OF_LINE(p1,p2,p0)>=0) && (SIDE_OF_LINE(p2,p3,p0)>=0) && (SIDE_OF_LINE(p3,p1,p0)>=0)) - /** * * @param min @@ -3812,12 +3808,50 @@ int RayIntersectsTriangle(float p1[3], float d[3], float v0[3], float v1[3], flo /* Adapted from the paper by Kasper Fauerby */ /* "Improved Collision detection and Response" */ +static int getLowestRoot(float a, float b, float c, float maxR, float* root) +{ + // Check if a solution exists + float determinant = b*b - 4.0f*a*c; + + // If determinant is negative it means no solutions. + if (determinant >= 0.0f) + { + // calculate the two roots: (if determinant == 0 then + // x1==x2 but let’s disregard that slight optimization) + float sqrtD = sqrt(determinant); + float r1 = (-b - sqrtD) / (2.0f*a); + float r2 = (-b + sqrtD) / (2.0f*a); + + // Sort so x1 <= x2 + if (r1 > r2) + SWAP( float, r1, r2); + + // Get lowest root: + if (r1 > 0.0f && r1 < maxR) + { + *root = r1; + return 1; + } + + // It is possible that we want x2 - this can happen + // if x1 < 0 + if (r2 > 0.0f && r2 < maxR) + { + *root = r2; + return 1; + } + } + // No (valid) solutions + return 0; +} + int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, float v0[3], float v1[3], float v2[3], float *lambda, float *ipoint) { float e1[3], e2[3], e3[3], point[3], vel[3], /*dist[3],*/ nor[3], temp[3], bv[3]; - float a, b, c, d, e, x, y, z, t, t0, t1, radius2=radius*radius; + float a, b, c, d, e, x, y, z, radius2=radius*radius; float elen2,edotv,edotbv,nordotv,vel2; - int embedded_in_plane=0, found_by_sweep=0; + float newLambda; + int found_by_sweep=0; VecSubf(e1,v1,v0); VecSubf(e2,v2,v0); @@ -3826,44 +3860,41 @@ int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, f /*---test plane of tri---*/ Crossf(nor,e1,e2); Normalize(nor); + /* flip normal */ if(Inpf(nor,vel)>0.0f) VecMulf(nor,-1.0f); a=Inpf(p1,nor)-Inpf(v0,nor); - nordotv=Inpf(nor,vel); - if ((nordotv > -0.000001) && (nordotv < 0.000001)) { - if(fabs(a)>=1.0f) + if (fabs(nordotv) < 0.000001) + { + if(fabs(a)>=radius) + { return 0; - else{ - embedded_in_plane=1; - t0=0.0f; - t1=1.0f; } } - else{ - t0=(radius-a)/nordotv; - t1=(-radius-a)/nordotv; - /* make t0<t1 */ - if(t0>t1){b=t1; t1=t0; t0=b;} + else + { + float t0=(-a+radius)/nordotv; + float t1=(-a-radius)/nordotv; + + if(t0>t1) + SWAP(float, t0, t1); if(t0>1.0f || t1<0.0f) return 0; /* clamp to [0,1] */ - t0=(t0<0.0f)?0.0f:((t0>1.0f)?1.0:t0); - t1=(t1<0.0f)?0.0f:((t1>1.0f)?1.0:t1); - } + CLAMP(t0, 0.0f, 1.0f); + CLAMP(t1, 0.0f, 1.0f); -/*---test inside of tri---*/ - if(embedded_in_plane==0){ + /*---test inside of tri---*/ /* plane intersection point */ - VecCopyf(point,vel); - VecMulf(point,t0); - VecAddf(point,point,p1); - VecCopyf(temp,nor); - VecMulf(temp,radius); - VecSubf(point,point,temp); + + point[0] = p1[0] + vel[0]*t0 - nor[0]*radius; + point[1] = p1[1] + vel[1]*t0 - nor[1]*radius; + point[2] = p1[2] + vel[2]*t0 - nor[2]*radius; + /* is the point in the tri? */ a=Inpf(e1,e1); @@ -3878,14 +3909,19 @@ int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, f y=e*a-d*b; z=x+y-(a*c-b*b); - if(( ((unsigned int)z)& ~(((unsigned int)x)|((unsigned int)y)) ) & 0x80000000){ + + if( z <= 0.0f && (x >= 0.0f && y >= 0.0f)) + { + //( ((unsigned int)z)& ~(((unsigned int)x)|((unsigned int)y)) ) & 0x80000000){ *lambda=t0; VecCopyf(ipoint,point); return 1; } } + *lambda=1.0f; + /*---test points---*/ a=vel2=Inpf(vel,vel); @@ -3893,73 +3929,42 @@ int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, f VecSubf(temp,p1,v0); b=2.0f*Inpf(vel,temp); c=Inpf(temp,temp)-radius2; - d=b*b-4*a*c; - - if(d>=0.0f){ - if(d==0.0f) - t=-b/2*a; - else{ - z=sqrt(d); - x=(-b-z)*0.5/a; - y=(-b+z)*0.5/a; - t=x<y?x:y; - } - if(t>0.0 && t < *lambda){ - *lambda=t; - VecCopyf(ipoint,v0); - found_by_sweep=1; - } + if(getLowestRoot(a, b, c, *lambda, lambda)) + { + VecCopyf(ipoint,v0); + found_by_sweep=1; } /*v1*/ VecSubf(temp,p1,v1); b=2.0f*Inpf(vel,temp); c=Inpf(temp,temp)-radius2; - d=b*b-4*a*c; - - if(d>=0.0f){ - if(d==0.0f) - t=-b/2*a; - else{ - z=sqrt(d); - x=(-b-z)*0.5/a; - y=(-b+z)*0.5/a; - t=x<y?x:y; - } - if(t>0.0 && t < *lambda){ - *lambda=t; - VecCopyf(ipoint,v1); - found_by_sweep=1; - } + if(getLowestRoot(a, b, c, *lambda, lambda)) + { + VecCopyf(ipoint,v1); + found_by_sweep=1; } + /*v2*/ VecSubf(temp,p1,v2); b=2.0f*Inpf(vel,temp); c=Inpf(temp,temp)-radius2; - d=b*b-4*a*c; - - if(d>=0.0f){ - if(d==0.0f) - t=-b/2*a; - else{ - z=sqrt(d); - x=(-b-z)*0.5/a; - y=(-b+z)*0.5/a; - t=x<y?x:y; - } - if(t>0.0 && t < *lambda){ - *lambda=t; - VecCopyf(ipoint,v2); - found_by_sweep=1; - } + if(getLowestRoot(a, b, c, *lambda, lambda)) + { + VecCopyf(ipoint,v2); + found_by_sweep=1; } /*---test edges---*/ + VecSubf(e3,v2,v1); //wasnt yet calculated + + /*e1*/ VecSubf(bv,v0,p1); + elen2 = Inpf(e1,e1); edotv = Inpf(e1,vel); edotbv = Inpf(e1,bv); @@ -3967,27 +3972,18 @@ int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, f a=elen2*(-Inpf(vel,vel))+edotv*edotv; b=2.0f*(elen2*Inpf(vel,bv)-edotv*edotbv); c=elen2*(radius2-Inpf(bv,bv))+edotbv*edotbv; - d=b*b-4*a*c; - if(d>=0.0f){ - if(d==0.0f) - t=-b/2*a; - else{ - z=sqrt(d); - x=(-b-z)*0.5/a; - y=(-b+z)*0.5/a; - t=x<y?x:y; - } - e=(edotv*t-edotbv)/elen2; + if(getLowestRoot(a, b, c, *lambda, &newLambda)) + { + e=(edotv*newLambda-edotbv)/elen2; - if((e>=0.0f) && (e<=1.0f)){ - if(t>0.0 && t < *lambda){ - *lambda=t; - VecCopyf(ipoint,e1); - VecMulf(ipoint,e); - VecAddf(ipoint,ipoint,v0); - found_by_sweep=1; - } + if(e >= 0.0f && e <= 1.0f) + { + *lambda = newLambda; + VecCopyf(ipoint,e1); + VecMulf(ipoint,e); + VecAddf(ipoint,ipoint,v0); + found_by_sweep=1; } } @@ -4000,32 +3996,27 @@ int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, f a=elen2*(-Inpf(vel,vel))+edotv*edotv; b=2.0f*(elen2*Inpf(vel,bv)-edotv*edotbv); c=elen2*(radius2-Inpf(bv,bv))+edotbv*edotbv; - d=b*b-4*a*c; - if(d>=0.0f){ - if(d==0.0f) - t=-b/2*a; - else{ - z=sqrt(d); - x=(-b-z)*0.5/a; - y=(-b+z)*0.5/a; - t=x<y?x:y; - } - e=(edotv*t-edotbv)/elen2; + if(getLowestRoot(a, b, c, *lambda, &newLambda)) + { + e=(edotv*newLambda-edotbv)/elen2; - if((e>=0.0f) && (e<=1.0f)){ - if(t>0.0 && t < *lambda){ - *lambda=t; - VecCopyf(ipoint,e2); - VecMulf(ipoint,e); - VecAddf(ipoint,ipoint,v0); - found_by_sweep=1; - } + if(e >= 0.0f && e <= 1.0f) + { + *lambda = newLambda; + VecCopyf(ipoint,e2); + VecMulf(ipoint,e); + VecAddf(ipoint,ipoint,v0); + found_by_sweep=1; } } /*e3*/ - VecSubf(e3,v2,v1); + VecSubf(bv,v0,p1); + elen2 = Inpf(e1,e1); + edotv = Inpf(e1,vel); + edotbv = Inpf(e1,bv); + VecSubf(bv,v1,p1); elen2 = Inpf(e3,e3); edotv = Inpf(e3,vel); @@ -4034,30 +4025,22 @@ int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, f a=elen2*(-Inpf(vel,vel))+edotv*edotv; b=2.0f*(elen2*Inpf(vel,bv)-edotv*edotbv); c=elen2*(radius2-Inpf(bv,bv))+edotbv*edotbv; - d=b*b-4*a*c; - if(d>=0.0f){ - if(d==0.0f) - t=-b/2*a; - else{ - z=sqrt(d); - x=(-b-z)*0.5/a; - y=(-b+z)*0.5/a; - t=x<y?x:y; - } - e=(edotv*t-edotbv)/elen2; + if(getLowestRoot(a, b, c, *lambda, &newLambda)) + { + e=(edotv*newLambda-edotbv)/elen2; - if((e>=0.0f) && (e<=1.0f)){ - if(t>0.0 && t < *lambda){ - *lambda=t; - VecCopyf(ipoint,e3); - VecMulf(ipoint,e); - VecAddf(ipoint,ipoint,v1); - found_by_sweep=1; - } + if(e >= 0.0f && e <= 1.0f) + { + *lambda = newLambda; + VecCopyf(ipoint,e3); + VecMulf(ipoint,e); + VecAddf(ipoint,ipoint,v1); + found_by_sweep=1; } } + return found_by_sweep; } int AxialLineIntersectsTriangle(int axis, float p1[3], float p2[3], float v0[3], float v1[3], float v2[3], float *lambda) diff --git a/source/blender/blenlib/intern/boxpack2d.c b/source/blender/blenlib/intern/boxpack2d.c index acd53e5d516..db7bae8a91d 100644 --- a/source/blender/blenlib/intern/boxpack2d.c +++ b/source/blender/blenlib/intern/boxpack2d.c @@ -42,6 +42,8 @@ #define TRF 2 #define TLF 4 #define BRF 8 +#define CORNERFLAGS (BLF|TRF|TLF|BRF) + #define BL 0 #define TR 1 #define TL 2 @@ -159,7 +161,7 @@ void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height) vert->blb = vert->brb = vert->tlb =\ vert->isect_cache[0] = vert->isect_cache[1] =\ vert->isect_cache[2] = vert->isect_cache[3] = NULL; - vert->free = 15 &~ TRF; + vert->free = CORNERFLAGS &~ TRF; vert->trb = box; vert->index = i; i++; box->v[BL] = vert; vert++; @@ -167,7 +169,7 @@ void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height) vert->trb= vert->brb = vert->tlb =\ vert->isect_cache[0] = vert->isect_cache[1] =\ vert->isect_cache[2] = vert->isect_cache[3] = NULL; - vert->free = 15 &~ BLF; + vert->free = CORNERFLAGS &~ BLF; vert->blb = box; vert->index = i; i++; box->v[TR] = vert; vert++; @@ -175,7 +177,7 @@ void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height) vert->trb = vert->blb = vert->tlb =\ vert->isect_cache[0] = vert->isect_cache[1] =\ vert->isect_cache[2] = vert->isect_cache[3] = NULL; - vert->free = 15 &~ BRF; + vert->free = CORNERFLAGS &~ BRF; vert->brb = box; vert->index = i; i++; box->v[TL] = vert; vert++; @@ -183,7 +185,7 @@ void boxPack2D(boxPack *boxarray, int len, float *tot_width, float *tot_height) vert->trb = vert->blb = vert->brb =\ vert->isect_cache[0] = vert->isect_cache[1] =\ vert->isect_cache[2] = vert->isect_cache[3] = NULL; - vert->free = 15 &~ TLF; + vert->free = CORNERFLAGS &~ TLF; vert->tlb = box; vert->index = i; i++; box->v[BR] = vert; vert++; diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index 8b979f9ed23..74f152ac635 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -405,7 +405,7 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) lcode = charcode; } - err = FT_Set_Charmap( face, (FT_CharMap) FT_ENCODING_UNICODE ); + err = FT_Select_Charmap( face, FT_ENCODING_UNICODE ); return vfd; } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 3c629818b2d..ad19cde3c9b 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -69,6 +69,7 @@ #include "DNA_effect_types.h" #include "DNA_fileglobal_types.h" #include "DNA_group_types.h" +#include "DNA_gpencil_types.h" #include "DNA_ipo_types.h" #include "DNA_image_types.h" #include "DNA_key_types.h" @@ -1346,8 +1347,14 @@ void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, void *fd) prop->data.pointer = newdataadr(fd, prop->data.pointer); if (switch_endian) { - for (i=0; i<prop->len; i++) { - SWITCH_INT(((int*)prop->data.pointer)[i]); + if (prop->subtype != IDP_DOUBLE) { + for (i=0; i<prop->len; i++) { + SWITCH_INT(((int*)prop->data.pointer)[i]); + } + } else { + for (i=0; i<prop->len; i++) { + SWITCH_LONGINT(((double*)prop->data.pointer)[i]); + } } } } @@ -1384,6 +1391,24 @@ void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, void *fd) case IDP_ARRAY: IDP_DirectLinkArray(prop, switch_endian, fd); break; + case IDP_DOUBLE: + /*erg, stupid doubles. since I'm storing them + in the same field as int val; val2 in the + IDPropertyData struct, they have to deal with + endianness specifically + + in theory, val and val2 would've already been swapped + if switch_endian is true, so we have to first unswap + them then reswap them as a single 64-bit entity. + */ + + if (switch_endian) { + SWITCH_INT(prop->data.val); + SWITCH_INT(prop->data.val2); + SWITCH_LONGINT(prop->data.val); + } + + break; } } @@ -3698,6 +3723,32 @@ static void lib_link_screen_sequence_ipos(Main *main) /* ************ READ SCREEN ***************** */ +/* relinks grease-pencil data for 3d-view(s) - used for direct_link */ +static void link_gpencil(FileData *fd, bGPdata *gpd) +{ + bGPDlayer *gpl; + bGPDframe *gpf; + bGPDstroke *gps; + + /* relink layers */ + link_list(fd, &gpd->layers); + + for (gpl= gpd->layers.first; gpl; gpl= gpl->next) { + /* relink frames */ + link_list(fd, &gpl->frames); + gpl->actframe= newdataadr(fd, gpl->actframe); + + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + /* relink strokes (and their points) */ + link_list(fd, &gpf->strokes); + + for (gps= gpf->strokes.first; gps; gps= gps->next) { + gps->points= newdataadr(fd, gps->points); + } + } + } +} + /* note: file read without screens option G_FILE_NO_UI; check lib pointers in call below */ static void lib_link_screen(FileData *fd, Main *main) @@ -3709,23 +3760,23 @@ static void lib_link_screen(FileData *fd, Main *main) if(sc->id.flag & LIB_NEEDLINK) { sc->id.us= 1; sc->scene= newlibadr(fd, sc->id.lib, sc->scene); - + sa= sc->areabase.first; while(sa) { SpaceLink *sl; - + sa->full= newlibadr(fd, sc->id.lib, sa->full); - + /* space handler scriptlinks */ lib_link_scriptlink(fd, &sc->id, &sa->scriptlink); - + for (sl= sa->spacedata.first; sl; sl= sl->next) { if(sl->spacetype==SPACE_VIEW3D) { View3D *v3d= (View3D*) sl; - + v3d->camera= newlibadr(fd, sc->id.lib, v3d->camera); v3d->ob_centre= newlibadr(fd, sc->id.lib, v3d->ob_centre); - + if(v3d->bgpic) { v3d->bgpic->ima= newlibadr_us(fd, sc->id.lib, v3d->bgpic->ima); } @@ -4081,6 +4132,10 @@ static void direct_link_screen(FileData *fd, bScreen *sc) v3d->bgpic= newdataadr(fd, v3d->bgpic); if(v3d->bgpic) v3d->bgpic->iuser.ok= 1; + if(v3d->gpd) { + v3d->gpd= newdataadr(fd, v3d->gpd); + link_gpencil(fd, v3d->gpd); + } v3d->localvd= newdataadr(fd, v3d->localvd); v3d->afterdraw.first= v3d->afterdraw.last= NULL; v3d->clipbb= newdataadr(fd, v3d->clipbb); @@ -4115,9 +4170,21 @@ static void direct_link_screen(FileData *fd, bScreen *sc) } else if(sl->spacetype==SPACE_NODE) { SpaceNode *snode= (SpaceNode *)sl; + + if(snode->gpd) { + snode->gpd= newdataadr(fd, snode->gpd); + link_gpencil(fd, snode->gpd); + } snode->nodetree= snode->edittree= NULL; snode->flag |= SNODE_DO_PREVIEW; } + else if(sl->spacetype==SPACE_SEQ) { + SpaceSeq *sseq= (SpaceSeq *)sl; + if(sseq->gpd) { + sseq->gpd= newdataadr(fd, sseq->gpd); + link_gpencil(fd, sseq->gpd); + } + } } sa->v1= newdataadr(fd, sa->v1); @@ -4803,6 +4870,49 @@ void idproperties_fix_group_lengths(ListBase idlist) } } +void alphasort_version_246(FileData *fd, Library *lib, Mesh *me) +{ + Material *ma; + MFace *mf; + MTFace *tf; + int a, b, texalpha; + + /* verify we have a tface layer */ + for(b=0; b<me->fdata.totlayer; b++) + if(me->fdata.layers[b].type == CD_MTFACE) + break; + + if(b == me->fdata.totlayer) + return; + + /* if we do, set alpha sort if the game engine did it before */ + for(a=0, mf=me->mface; a<me->totface; a++, mf++) { + if(mf->mat_nr < me->totcol) { + ma= newlibadr(fd, lib, me->mat[mf->mat_nr]); + texalpha = 0; + + for(b=0; ma && b<MAX_MTEX; b++) + if(ma->mtex && ma->mtex[b] && ma->mtex[b]->mapto & MAP_ALPHA) + texalpha = 1; + } + else { + ma= NULL; + texalpha = 0; + } + + for(b=0; b<me->fdata.totlayer; b++) { + if(me->fdata.layers[b].type == CD_MTFACE) { + tf = ((MTFace*)me->fdata.layers[b].data) + a; + + tf->mode &= ~TF_ALPHASORT; + if(ma && (ma->mode & MA_ZTRA)) + if(ELEM(tf->transp, TF_ALPHA, TF_ADD) || (texalpha && (tf->transp != TF_CLIP))) + tf->mode |= TF_ALPHASORT; + } + } + } +} + static void do_versions(FileData *fd, Library *lib, Main *main) { /* WATCH IT!!!: pointers from libdata have not been converted */ @@ -7647,8 +7757,9 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } /* sun/sky */ - if ((main->versionfile < 246) ){ + if(main->versionfile < 246) { Lamp *la; + for(la=main->lamp.first; la; la= la->id.next) { la->sun_effect_type = 0; la->horizon_brightness = 1.0; @@ -7664,6 +7775,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main) } } + if(main->versionfile <= 246 && main->subversionfile < 1){ + Mesh *me; + + for(me=main->mesh.first; me; me= me->id.next) + alphasort_version_246(fd, lib, me); + } + /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ /* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */ diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index ca91f1dc346..3a70438dd13 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -112,6 +112,7 @@ Important to know is that 'streaming' has been added to files, for Blender Publi #include "DNA_customdata_types.h" #include "DNA_effect_types.h" #include "DNA_group_types.h" +#include "DNA_gpencil_types.h" #include "DNA_image_types.h" #include "DNA_ipo_types.h" #include "DNA_fileglobal_types.h" @@ -532,6 +533,7 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) if(part->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_PA, "ParticleSettings", 1, part); + if (part->id.properties) IDP_WriteProperty(part->id.properties, wd); writestruct(wd, DATA, "PartDeflect", 1, part->pd); } part= part->id.next; @@ -1565,6 +1567,32 @@ static void write_scenes(WriteData *wd, ListBase *scebase) mywrite(wd, MYWRITE_FLUSH, 0); } +static void write_gpencil(WriteData *wd, bGPdata *gpd) +{ + bGPDlayer *gpl; + bGPDframe *gpf; + bGPDstroke *gps; + + /* write gpd data block to file */ + writestruct(wd, DATA, "bGPdata", 1, gpd); + + /* write grease-pencil layers to file */ + for (gpl= gpd->layers.first; gpl; gpl= gpl->next) { + writestruct(wd, DATA, "bGPDlayer", 1, gpl); + + /* write this layer's frames to file */ + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + writestruct(wd, DATA, "bGPDframe", 1, gpf); + + /* write strokes */ + for (gps= gpf->strokes.first; gps; gps= gps->next) { + writestruct(wd, DATA, "bGPDstroke", 1, gps); + writestruct(wd, DATA, "bGPDspoint", gps->totpoints, gps->points); + } + } + } +} + static void write_screens(WriteData *wd, ListBase *scrbase) { bScreen *sc; @@ -1610,11 +1638,12 @@ static void write_screens(WriteData *wd, ListBase *scrbase) sl= sa->spacedata.first; while(sl) { if(sl->spacetype==SPACE_VIEW3D) { - View3D *v3d= (View3D*) sl; + View3D *v3d= (View3D *) sl; writestruct(wd, DATA, "View3D", 1, v3d); if(v3d->bgpic) writestruct(wd, DATA, "BGpic", 1, v3d->bgpic); if(v3d->localvd) writestruct(wd, DATA, "View3D", 1, v3d->localvd); if(v3d->clipbb) writestruct(wd, DATA, "BoundBox", 1, v3d->clipbb); + if(v3d->gpd) write_gpencil(wd, v3d->gpd); } else if(sl->spacetype==SPACE_IPO) { writestruct(wd, DATA, "SpaceIpo", 1, sl); @@ -1626,7 +1655,9 @@ static void write_screens(WriteData *wd, ListBase *scrbase) writestruct(wd, DATA, "SpaceFile", 1, sl); } else if(sl->spacetype==SPACE_SEQ) { + SpaceSeq *sseq= (SpaceSeq *)sl; writestruct(wd, DATA, "SpaceSeq", 1, sl); + if(sseq->gpd) write_gpencil(wd, sseq->gpd); } else if(sl->spacetype==SPACE_OOPS) { SpaceOops *so= (SpaceOops *)sl; @@ -1689,7 +1720,9 @@ static void write_screens(WriteData *wd, ListBase *scrbase) writestruct(wd, DATA, "SpaceTime", 1, sl); } else if(sl->spacetype==SPACE_NODE){ + SpaceNode *snode= (SpaceNode *)sl; writestruct(wd, DATA, "SpaceNode", 1, sl); + if(snode->gpd) write_gpencil(wd, snode->gpd); } sl= sl->next; } @@ -2242,7 +2275,7 @@ static int handle_append_runtime(int handle, char *exename, char **cause_r) { unsigned char buf[1024]; int count, progfd= -1; - if (!runtime) { + if (!BLI_exists(runtime)) { cause= "Unable to find runtime"; goto cleanup; } diff --git a/source/blender/imbuf/intern/anim.c b/source/blender/imbuf/intern/anim.c index 720f5b0f7c8..c0e84b73e47 100644 --- a/source/blender/imbuf/intern/anim.c +++ b/source/blender/imbuf/intern/anim.c @@ -612,6 +612,7 @@ static int startffmpeg(struct anim * anim) { av_free(anim->pFrameRGB); av_free(anim->pFrameDeinterlaced); av_free(anim->pFrame); + anim->pCodecCtx = NULL; return -1; } @@ -639,7 +640,19 @@ static int startffmpeg(struct anim * anim) { PIX_FMT_BGR32, SWS_FAST_BILINEAR | SWS_PRINT_INFO, NULL, NULL, NULL); - + + if (!anim->img_convert_ctx) { + fprintf (stderr, + "Can't transform color space??? Bailing out...\n"); + avcodec_close(anim->pCodecCtx); + av_close_input_file(anim->pFormatCtx); + av_free(anim->pFrameRGB); + av_free(anim->pFrameDeinterlaced); + av_free(anim->pFrame); + anim->pCodecCtx = NULL; + return -1; + } + return (0); } diff --git a/source/blender/include/BDR_drawaction.h b/source/blender/include/BDR_drawaction.h index 91635123cb7..7cb0768e832 100644 --- a/source/blender/include/BDR_drawaction.h +++ b/source/blender/include/BDR_drawaction.h @@ -38,6 +38,7 @@ struct bAction; struct bActionGroup; struct Object; struct ListBase; +struct bGPDlayer; /* ****************************** Base Structs ****************************** */ @@ -82,6 +83,7 @@ void draw_ipo_channel(struct gla2DDrawInfo *di, struct Ipo *ipo, float ypos); void draw_agroup_channel(struct gla2DDrawInfo *di, struct bActionGroup *agrp, float ypos); void draw_action_channel(struct gla2DDrawInfo *di, struct bAction *act, float ypos); void draw_object_channel(struct gla2DDrawInfo *di, struct Object *ob, float ypos); +void draw_gpl_channel(struct gla2DDrawInfo *di, struct bGPDlayer *gpl, float ypos); /* Keydata Generation */ void icu_to_keylist(struct IpoCurve *icu, ListBase *keys, ListBase *blocks, ActKeysInc *aki); @@ -89,6 +91,7 @@ void ipo_to_keylist(struct Ipo *ipo, ListBase *keys, ListBase *blocks, ActKeysIn void agroup_to_keylist(struct bActionGroup *agrp, ListBase *keys, ListBase *blocks, ActKeysInc *aki); void action_to_keylist(struct bAction *act, ListBase *keys, ListBase *blocks, ActKeysInc *aki); void ob_to_keylist(struct Object *ob, ListBase *keys, ListBase *blocks, ActKeysInc *aki); +void gpl_to_keylist(struct bGPDlayer *gpl, ListBase *keys, ListBase *blocks, ActKeysInc *aki); #endif /* BDR_DRAWACTION_H */ diff --git a/source/blender/include/BDR_gpencil.h b/source/blender/include/BDR_gpencil.h new file mode 100644 index 00000000000..eb749cf28ec --- /dev/null +++ b/source/blender/include/BDR_gpencil.h @@ -0,0 +1,83 @@ +/** + * $Id: BDR_gpencil.h 14444 2008-04-16 22:40:48Z aligorith $ + * + * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2008, Blender Foundation + * This is a new part of Blender + * + * Contributor(s): Joshua Leung + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef BDR_GPENCIL_H +#define BDR_GPENCIL_H + +struct ListBase; +struct bScreen; +struct ScrArea; +struct View3D; +struct SpaceNode; +struct SpaceSeq; +struct bGPdata; +struct bGPDlayer; +struct bGPDframe; + +/* ------------- Grease-Pencil Helpers -------------- */ + +/* Temporary 'Stroke Point' data */ +typedef struct tGPspoint { + short x, y; /* x and y coordinates of cursor (in relative to area) */ + float xf, yf; /* same as x and y, but as floats */ + float pressure; /* pressure of tablet at this point */ +} tGPspoint; + +/* ------------ Grease-Pencil API ------------------ */ + +void free_gpencil_strokes(struct bGPDframe *gpf); +void free_gpencil_frames(struct bGPDlayer *gpl); +void free_gpencil_layers(struct ListBase *list); +void free_gpencil_data(struct bGPdata *gpd); + +struct bGPDframe *gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe); +struct bGPDlayer *gpencil_layer_addnew(struct bGPdata *gpd); +struct bGPdata *gpencil_data_addnew(void); + +struct bGPdata *gpencil_data_duplicate(struct bGPdata *gpd); + +struct bGPdata *gpencil_data_getactive(struct ScrArea *sa); +short gpencil_data_setactive(struct ScrArea *sa, struct bGPdata *gpd); + +void gpencil_frame_delete_laststroke(struct bGPDframe *gpf); + +struct bGPDframe *gpencil_layer_getframe(struct bGPDlayer *gpl, int cframe, short addnew); +void gpencil_layer_delframe(struct bGPDlayer *gpl, struct bGPDframe *gpf); +struct bGPDlayer *gpencil_layer_getactive(struct bGPdata *gpd); +void gpencil_layer_setactive(struct bGPdata *gpd, struct bGPDlayer *active); +void gpencil_layer_delactive(struct bGPdata *gpd); + +void gpencil_delete_actframe(struct bGPdata *gpd); +void gpencil_delete_laststroke(struct bGPdata *gpd); + +void gpencil_delete_operation(short mode); +void gpencil_delete_menu(void); + +//short gpencil_paint(short mousebutton); +short gpencil_do_paint(struct ScrArea *sa, short mousebutton); + +#endif /* BDR_GPENCIL_H */ diff --git a/source/blender/include/BIF_drawgpencil.h b/source/blender/include/BIF_drawgpencil.h new file mode 100644 index 00000000000..418446313df --- /dev/null +++ b/source/blender/include/BIF_drawgpencil.h @@ -0,0 +1,44 @@ +/** + * $Id: BIF_drawgpencil.h 14444 2008-04-16 22:40:48Z aligorith $ + * + * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2008, Blender Foundation + * This is a new part of Blender + * + * Contributor(s): Joshua Leung + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef BIF_DRAWGPENCIL_H +#define BIF_DRAWGPENCIL_H + +struct ScrArea; +struct View3D; +struct SpaceNode; +struct SpaceSeq; +struct bGPdata; +struct uiBlock; + +short draw_gpencil_panel(struct uiBlock *block, struct bGPdata *gpd, struct ScrArea *sa); + +void draw_gpencil_2dview(struct ScrArea *sa, short onlyv2d); +void draw_gpencil_3dview(struct ScrArea *sa, short only3d); +void draw_gpencil_oglrender(struct View3D *v3d, int winx, int winy); + +#endif /* BIF_DRAWGPENCIL_H */ diff --git a/source/blender/include/BIF_editaction.h b/source/blender/include/BIF_editaction.h index 7e0f703681b..77c2f19bb9b 100644 --- a/source/blender/include/BIF_editaction.h +++ b/source/blender/include/BIF_editaction.h @@ -48,7 +48,10 @@ enum { ACTTYPE_FILLIPO, ACTTYPE_FILLCON, ACTTYPE_IPO, - ACTTYPE_SHAPEKEY + ACTTYPE_SHAPEKEY, + ACTTYPE_GPDATABLOCK, + ACTTYPE_GPLAYER, + ACTTYPE_SPECIALDATA }; /* Macros for easier/more consistant state testing */ @@ -69,7 +72,12 @@ enum { #define EDITABLE_ICU(icu) ((icu->flag & IPO_PROTECT)==0) #define SEL_ICU(icu) (icu->flag & IPO_SELECT) -#define NLA_ACTION_SCALED (G.saction->pin==0 && OBACT && OBACT->action) +#define EXPANDED_GPD(gpd) (gpd->flag & GP_DATA_EXPAND) + +#define EDITABLE_GPL(gpl) ((gpl->flag & GP_LAYER_LOCKED)==0) +#define SEL_GPL(gpl) ((gpl->flag & GP_LAYER_ACTIVE) || (gpl->flag & GP_LAYER_SELECT)) + +#define NLA_ACTION_SCALED (G.saction->mode==SACTCONT_ACTION && G.saction->pin==0 && OBACT && OBACT->action) #define NLA_IPO_SCALED (OBACT && OBACT->action && G.sipo->pin==0 && G.sipo->actname) /* constants for setting ipo-interpolation type */ @@ -114,6 +122,8 @@ struct BWinEvent; struct Key; struct ListBase; struct TimeMarker; +struct bGPdata; +struct bGPDlayer; /* Key operations */ void transform_action_keys(int mode, int dummy); @@ -176,11 +186,29 @@ void action_add_localmarker(struct bAction *act, int frame); void action_rename_localmarker(struct bAction *act); void action_remove_localmarkers(struct bAction *act); +/* Grease-Pencil Data */ +void gplayer_make_cfra_list(struct bGPDlayer *gpl, ListBase *elems, short onlysel); + +void deselect_gpencil_layers(void *data, short select_mode); + +short is_gplayer_frame_selected(struct bGPDlayer *gpl); +void set_gplayer_frame_selection(struct bGPDlayer *gpl, short mode); +void select_gpencil_frames(struct bGPDlayer *gpl, short select_mode); +void select_gpencil_frame(struct bGPDlayer *gpl, int selx, short select_mode); +void borderselect_gplayer_frames(struct bGPDlayer *gpl, float min, float max, short select_mode); + +void delete_gpencil_layers(void); +void delete_gplayer_frames(struct bGPDlayer *gpl); +void duplicate_gplayer_frames(struct bGPDlayer *gpd); + +void snap_gplayer_frames(struct bGPDlayer *gpl, short mode); +void mirror_gplayer_frames(struct bGPDlayer *gpl, short mode); + /* ShapeKey stuff */ struct Key *get_action_mesh_key(void); int get_nearest_key_num(struct Key *key, short *mval, float *x); -void *get_nearest_act_channel(short mval[], short *ret_type); +void *get_nearest_act_channel(short mval[], short *ret_type, void **owner); /* Action */ struct bActionChannel *get_hilighted_action_channel(struct bAction* action); diff --git a/source/blender/include/BIF_editarmature.h b/source/blender/include/BIF_editarmature.h index c3660f700b3..0776ef2cbaf 100644 --- a/source/blender/include/BIF_editarmature.h +++ b/source/blender/include/BIF_editarmature.h @@ -110,7 +110,8 @@ void mouse_armature(void); void remake_editArmature(void); void selectconnected_armature(void); void selectconnected_posearmature(void); -void select_bone_parent(void); +void armature_select_hierarchy(short direction, short add_to_sel); + void setflag_armature(short mode); void unique_editbone_name (struct ListBase *ebones, char *name); @@ -136,6 +137,7 @@ void transform_armature_mirror_update(void); void hide_selected_armature_bones(void); void hide_unselected_armature_bones(void); void show_all_armature_bones(void); +void set_locks_armature_bones(short lock); #define BONESEL_ROOT 0x10000000 #define BONESEL_TIP 0x20000000 @@ -147,6 +149,10 @@ void show_all_armature_bones(void); /* from autoarmature */ void BIF_retargetArmature(); +/* used in bone_select_hierachy() */ +#define BONE_SELECT_PARENT 0 +#define BONE_SELECT_CHILD 1 + #endif diff --git a/source/blender/include/BIF_editview.h b/source/blender/include/BIF_editview.h index 4ed3d0df367..d2c6c56d01a 100644 --- a/source/blender/include/BIF_editview.h +++ b/source/blender/include/BIF_editview.h @@ -34,9 +34,12 @@ struct Base; struct Object; struct Camera; struct View3D; +struct rcti; void arrows_move_cursor(unsigned short event); +void lasso_select_boundbox(struct rcti *rect, short mcords[][2], short moves); int lasso_inside(short mcords[][2], short moves, short sx, short sy); +int lasso_inside_edge(short mcords[][2], short moves, int x0, int y0, int x1, int y1); void borderselect(void); void circle_select(void); void deselectall(void); diff --git a/source/blender/include/BIF_poseobject.h b/source/blender/include/BIF_poseobject.h index 58c67ff102a..ab96f7ec03e 100644 --- a/source/blender/include/BIF_poseobject.h +++ b/source/blender/include/BIF_poseobject.h @@ -65,6 +65,8 @@ void pose_assign_to_posegroup(short active); void pose_remove_from_posegroups(void); void pgroup_operation_with_menu(void); +void pose_select_hierarchy(short direction, short add_to_sel); + void pose_select_grouped(short nr); void pose_select_grouped_menu(void); diff --git a/source/blender/include/BIF_space.h b/source/blender/include/BIF_space.h index 37be4a9eafc..4b2b8e14bb6 100644 --- a/source/blender/include/BIF_space.h +++ b/source/blender/include/BIF_space.h @@ -53,6 +53,7 @@ struct SpaceOops; #define VIEW3D_HANDLER_PREVIEW 4 #define VIEW3D_HANDLER_MULTIRES 5 #define VIEW3D_HANDLER_TRANSFORM 6 +#define VIEW3D_HANDLER_GREASEPENCIL 7 /* ipo handler codes */ #define IPO_HANDLER_PROPERTIES 20 @@ -73,11 +74,15 @@ struct SpaceOops; #define NLA_HANDLER_PROPERTIES 50 /* sequence handler codes */ -#define SEQ_HANDLER_PROPERTIES 60 +#define SEQ_HANDLER_PROPERTIES 60 +#define SEQ_HANDLER_GREASEPENCIL 61 /* imasel handler codes */ #define IMASEL_HANDLER_IMAGE 70 +/* nodes handler codes */ +#define NODES_HANDLER_GREASEPENCIL 80 + /* theme codes */ #define B_ADD_THEME 3301 #define B_DEL_THEME 3302 @@ -145,3 +150,4 @@ extern void mainwindow_close(void); #endif + diff --git a/source/blender/include/BSE_drawview.h b/source/blender/include/BSE_drawview.h index 83031ff3bad..e6f22a4fb67 100644 --- a/source/blender/include/BSE_drawview.h +++ b/source/blender/include/BSE_drawview.h @@ -76,6 +76,7 @@ void inner_play_anim_loop(int init, int mode); int play_anim(int mode); void make_axis_color(char *col, char *col2, char axis); +char *view3d_get_name(struct View3D *v3d); /* SMOOTHVIEW */ void smooth_view(struct View3D *v3d, float *ofs, float *quat, float *dist, float *lens); diff --git a/source/blender/include/BSE_editaction_types.h b/source/blender/include/BSE_editaction_types.h index c531383accc..be210415973 100644 --- a/source/blender/include/BSE_editaction_types.h +++ b/source/blender/include/BSE_editaction_types.h @@ -38,7 +38,8 @@ typedef enum ALE_KEYTYPE { ALE_NONE = 0, ALE_IPO, ALE_ICU, - ALE_GROUP + ALE_GROUP, + ALE_GPFRAME, } ALE_KEYTYPE; /* This struct defines a structure used for quick access */ @@ -78,7 +79,8 @@ typedef enum ACTFILTER_FLAGS { typedef enum ACTCONT_TYPES { ACTCONT_NONE = 0, ACTCONT_ACTION, - ACTCONT_SHAPEKEY + ACTCONT_SHAPEKEY, + ACTCONT_GPENCIL } ACTCONT_TYPES; #endif diff --git a/source/blender/include/transform.h b/source/blender/include/transform.h index 4e3b80134f9..720b856a149 100644 --- a/source/blender/include/transform.h +++ b/source/blender/include/transform.h @@ -397,6 +397,7 @@ int Align(TransInfo *t, short mval[2]); /*********************** transform_conversions.c ********** */ struct ListBase; +void flushTransGPactionData(TransInfo *t); void flushTransIpoData(TransInfo *t); void flushTransUVs(TransInfo *t); void flushTransParticles(TransInfo *t); diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h index 60050ea010e..3054e038ba2 100644 --- a/source/blender/makesdna/DNA_ID.h +++ b/source/blender/makesdna/DNA_ID.h @@ -46,7 +46,7 @@ struct ID; typedef struct IDPropertyData { void *pointer; ListBase group; - int val, pad; + int val, val2; /*note, we actually fit a double into these two ints*/ } IDPropertyData; typedef struct IDProperty { @@ -77,6 +77,7 @@ typedef struct IDProperty { /*the ID link property type hasn't been implemented yet, this will require some cleanup of blenkernel, most likely.*/ #define IDP_ID 7 +#define IDP_DOUBLE 8 /*add any future new id property types here.*/ diff --git a/source/blender/makesdna/DNA_action_types.h b/source/blender/makesdna/DNA_action_types.h index 18d2a1cb6f3..2e8d95335cc 100644 --- a/source/blender/makesdna/DNA_action_types.h +++ b/source/blender/makesdna/DNA_action_types.h @@ -32,6 +32,7 @@ #include "DNA_listBase.h" #include "DNA_ID.h" +#include "DNA_gpencil_types.h" #include "DNA_view2d_types.h" #include "DNA_userdef_types.h" @@ -183,8 +184,10 @@ typedef struct SpaceAction { View2D v2d; bAction *action; /* the currently active action */ - short flag, autosnap; /* flag: bitmapped settings; autosnap: automatic keyframe snapping mode */ - short pin, actnr, lock; /* pin: keep showing current action; actnr: used for finding chosen action from menu; lock: lock time to other windows */ + + char mode, autosnap; /* mode: editing context; autosnap: automatic keyframe snapping mode */ + short flag, actnr; /* flag: bitmapped settings; */ + short pin, lock; /* pin: keep showing current action; actnr: used for finding chosen action from menu; lock: lock time to other windows */ short actwidth; /* width of the left-hand side name panel (in pixels?) */ float timeslide; /* for Time-Slide transform mode drawing - current frame? */ } SpaceAction; @@ -238,6 +241,18 @@ typedef enum SACTION_FLAG { SACTION_NODRAWGCOLORS = (1<<7) } SACTION_FLAG; +/* SpaceAction Mode Settings */ +typedef enum SACTCONT_MODES { + /* action (default) */ + SACTCONT_ACTION = 0, + /* editing of shapekey's IPO block */ + SACTCONT_SHAPEKEY, + /* editing of gpencil data */ + SACTCONT_GPENCIL, + /* dopesheet (unimplemented... future idea?) */ + SACTCONT_DOPESHEET +} SACTCONTEXT_MODES; + /* SpaceAction AutoSnap Settings (also used by SpaceNLA) */ typedef enum SACTSNAP_MODES { /* no auto-snap */ diff --git a/source/blender/makesdna/DNA_actuator_types.h b/source/blender/makesdna/DNA_actuator_types.h index ac9761f165d..7444ce95f56 100644 --- a/source/blender/makesdna/DNA_actuator_types.h +++ b/source/blender/makesdna/DNA_actuator_types.h @@ -368,9 +368,9 @@ typedef struct FreeCamera { #define ACT_CONST_DIRPX 1 #define ACT_CONST_DIRPY 2 #define ACT_CONST_DIRPZ 4 -#define ACT_CONST_DIRMX 8 -#define ACT_CONST_DIRMY 16 -#define ACT_CONST_DIRMZ 32 +#define ACT_CONST_DIRNX 8 +#define ACT_CONST_DIRNY 16 +#define ACT_CONST_DIRNZ 32 /* constraint type */ #define ACT_CONST_TYPE_LOC 0 diff --git a/source/blender/makesdna/DNA_armature_types.h b/source/blender/makesdna/DNA_armature_types.h index 673855a6932..0648c535353 100644 --- a/source/blender/makesdna/DNA_armature_types.h +++ b/source/blender/makesdna/DNA_armature_types.h @@ -154,7 +154,8 @@ typedef enum eBone_Flag { BONE_NO_SCALE = (1<<15), /* No parent scale */ BONE_HIDDEN_PG = (1<<16), /* hidden bone when drawing PoseChannels (for ghost drawing) */ BONE_DRAWWIRE = (1<<17), /* bone should be drawn as OB_WIRE, regardless of draw-types of view+armature */ - BONE_NO_CYCLICOFFSET = (1<<18) /* when no parent, bone will not get cyclic offset */ + BONE_NO_CYCLICOFFSET = (1<<18), /* when no parent, bone will not get cyclic offset */ + BONE_EDITMODE_LOCKED = (1<<19), /* bone transforms are locked in EditMode */ } eBone_Flag; #endif diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h index 0fe0dace016..fa5b5a75941 100644 --- a/source/blender/makesdna/DNA_constraint_types.h +++ b/source/blender/makesdna/DNA_constraint_types.h @@ -375,11 +375,13 @@ typedef enum B_CONSTRAINT_SPACETYPES { /* for objects (relative to parent/without parent influence), * for bones (along normals of bone, without parent/restpositions) */ - CONSTRAINT_SPACE_LOCAL, + CONSTRAINT_SPACE_LOCAL, /* = 1 */ /* for posechannels - pose space */ - CONSTRAINT_SPACE_POSE, - /* for posechannels - local with parent */ - CONSTRAINT_SPACE_PARLOCAL, + CONSTRAINT_SPACE_POSE, /* = 2 */ + /* for posechannels - local with parent */ + CONSTRAINT_SPACE_PARLOCAL, /* = 3 */ + /* for files from between 2.43-2.46 (should have been parlocal) */ + CONSTRAINT_SPACE_INVALID, /* = 4. do not exchange for anything! */ } B_CONSTRAINT_SPACETYPES; /* bConstraintChannel.flag */ diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h index 72557145270..6c098e220bb 100644 --- a/source/blender/makesdna/DNA_customdata_types.h +++ b/source/blender/makesdna/DNA_customdata_types.h @@ -71,7 +71,8 @@ typedef struct CustomData { #define CD_MTEXPOLY 15 #define CD_MLOOPUV 16 #define CD_MLOOPCOL 17 -#define CD_NUMTYPES 18 +#define CD_TANGENT 18 +#define CD_NUMTYPES 19 /* Bits for CustomDataMask */ #define CD_MASK_MVERT (1 << CD_MVERT) @@ -92,6 +93,7 @@ typedef struct CustomData { #define CD_MASK_MTEXPOLY (1 << CD_MTEXPOLY) #define CD_MASK_MLOOPUV (1 << CD_MLOOPUV) #define CD_MASK_MLOOPCOL (1 << CD_MLOOPCOL) +#define CD_MASK_TANGENT (1 << CD_TANGENT) /* CustomData.flag */ diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h new file mode 100644 index 00000000000..dca4e28688d --- /dev/null +++ b/source/blender/makesdna/DNA_gpencil_types.h @@ -0,0 +1,143 @@ +/** + * $Id: DNA_gpencil_types.h 8768 2006-11-07 00:10:37Z aligorith $ + * + * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2008, Blender Foundation. + * This is a new part of Blender + * + * Contributor(s): Joshua Leung + * + * ***** END GPL LICENSE BLOCK ***** + */ +#ifndef DNA_GPENCIL_TYPES_H +#define DNA_GPENCIL_TYPES_H + +#include "DNA_listBase.h" +#include "DNA_ID.h" + +/* Grease-Pencil Annotations - 'Stroke Point' + * -> Coordinates may either be 2d or 3d depending on settings at the time + * -> Coordinates of point on stroke, in proportions of window size + * (i.e. n/1000). This assumes that the bottom-left corner is (0,0) + */ +typedef struct bGPDspoint { + float x, y, z; /* co-ordinates of point (usually 2d, but can be 3d as well) */ + float pressure; /* pressure of input device (from 0 to 1) at this point */ +} bGPDspoint; + +/* Grease-Pencil Annotations - 'Stroke' + * -> A stroke represents a (simplified version) of the curve + * drawn by the user in one 'mousedown'->'mouseup' operation + */ +typedef struct bGPDstroke { + struct bGPDstroke *next, *prev; + + bGPDspoint *points; /* array of data-points for stroke */ + int totpoints; /* number of data-points in array */ + + short thickness; /* thickness of stroke (currently not used) */ + short flag; /* various settings about this stroke */ +} bGPDstroke; + +/* bGPDstroke->flag */ + /* stroke is in 3d-space */ +#define GP_STROKE_3DSPACE (1<<0) + /* stroke is in 2d-space */ +#define GP_STROKE_2DSPACE (1<<1) + /* stroke is an "eraser" stroke */ +#define GP_STROKE_ERASER (1<<2) + + +/* Grease-Pencil Annotations - 'Frame' + * -> Acts as storage for the 'image' formed by strokes + */ +typedef struct bGPDframe { + struct bGPDframe *next, *prev; + + ListBase strokes; /* list of the simplified 'strokes' that make up the frame's data */ + + int framenum; /* frame number of this frame */ + int flag; /* temp settings */ +} bGPDframe; + +/* bGPDframe->flag */ + /* frame is being painted on */ +#define GP_FRAME_PAINT (1<<0) + /* for editing in Action Editor */ +#define GP_FRAME_SELECT (1<<1) + + +/* Grease-Pencil Annotations - 'Layer' */ +typedef struct bGPDlayer { + struct bGPDlayer *next, *prev; + + ListBase frames; /* list of annotations to display for frames (bGPDframe list) */ + bGPDframe *actframe; /* active frame (should be the frame that is currently being displayed) */ + + int flag; /* settings for layer */ + short thickness; /* current thickness to apply to strokes */ + short gstep; /* max number of frames between active and ghost to show (0=only those on either side) */ + + float color[4]; /* color that should be used to draw all the strokes in this layer */ + + char info[128]; /* optional reference info about this layer (i.e. "director's comments, 12/3") */ +} bGPDlayer; + +/* bGPDlayer->flag */ + /* don't display layer */ +#define GP_LAYER_HIDE (1<<0) + /* protected from further editing */ +#define GP_LAYER_LOCKED (1<<1) + /* layer is 'active' layer being edited */ +#define GP_LAYER_ACTIVE (1<<2) + /* draw points of stroke for debugging purposes */ +#define GP_LAYER_DRAWDEBUG (1<<3) + /* do onionskinning */ +#define GP_LAYER_ONIONSKIN (1<<4) + /* for editing in Action Editor */ +#define GP_LAYER_SELECT (1<<5) + + +/* Grease-Pencil Annotations - 'DataBlock' */ +typedef struct bGPdata { + /* saved Grease-Pencil data */ + ListBase layers; /* bGPDlayers */ + int flag; /* settings for this datablock */ + + /* not-saved stroke buffer data (only used during paint-session) + * - buffer must be initialised before use, but freed after + * whole paint operation is over + */ + short sbuffer_size; /* number of elements currently in cache */ + short sbuffer_sflag; /* flags for stroke that cache represents */ + void *sbuffer; /* stroke buffer (can hold GP_STROKE_BUFFER_MAX) */ +} bGPdata; + +/* bGPdata->flag */ + /* don't allow painting to occur at all */ +#define GP_DATA_LMBPLOCK (1<<0) + /* show debugging info in viewport (i.e. status print) */ +#define GP_DATA_DISPINFO (1<<1) + /* in Action Editor, show as expanded channel */ +#define GP_DATA_EXPAND (1<<2) + /* is the block overriding all clicks? */ +#define GP_DATA_EDITPAINT (1<<3) + /* new strokes are added in viewport space */ +#define GP_DATA_VIEWALIGN (1<<4) + +#endif /* DNA_GPENCIL_TYPES_H */ diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index 6d025839ac8..4e427ed733c 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -228,7 +228,7 @@ typedef struct PartialVisibility { /* mtface->mode */ #define TF_DYNAMIC 1 -#define TF_DEPRECATED 2 +#define TF_ALPHASORT 2 #define TF_TEX 4 #define TF_SHAREDVERT 8 #define TF_LIGHT 16 diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index c4e8cb4925b..85c49a03569 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -466,9 +466,11 @@ extern Object workob; #define OB_LOCK_ROTX 8 #define OB_LOCK_ROTY 16 #define OB_LOCK_ROTZ 32 +#define OB_LOCK_ROT 56 #define OB_LOCK_SCALEX 64 #define OB_LOCK_SCALEY 128 #define OB_LOCK_SCALEZ 256 +#define OB_LOCK_SCALE 448 /* ob->softflag in DNA_object_force.h */ diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h index c0b9a6b9590..7bad8ec3b44 100644 --- a/source/blender/makesdna/DNA_sequence_types.h +++ b/source/blender/makesdna/DNA_sequence_types.h @@ -257,6 +257,7 @@ typedef struct SpeedControlVars { #define SEQ_USE_CROP 131072 #define SEQ_USE_COLOR_BALANCE 262144 #define SEQ_USE_PROXY_CUSTOM_DIR 524288 +#define SEQ_ACTIVE 1048576 #define SEQ_COLOR_BALANCE_INVERSE_GAIN 1 #define SEQ_COLOR_BALANCE_INVERSE_GAMMA 2 diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index bc30a12ff27..a8694dfb7f5 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -50,6 +50,7 @@ struct RenderInfo; struct bNodeTree; struct uiBlock; struct FileList; +struct bGPdata; /** * The base structure all the other spaces @@ -150,6 +151,8 @@ typedef struct SpaceSeq { short zebra; int flag; float zoom; + + struct bGPdata *gpd; /* grease-pencil data */ } SpaceSeq; typedef struct SpaceFile { @@ -339,6 +342,8 @@ typedef struct SpaceNode { float blockscale; struct ScrArea *area; + short blockhandler[8]; + View2D v2d; struct ID *id, *from; /* context, no need to save in file? well... pinning... */ @@ -351,11 +356,13 @@ typedef struct SpaceNode { struct bNodeTree *nodetree, *edittree; int treetype, pad; /* treetype: as same nodetree->type */ + struct bGPdata *gpd; /* grease-pencil data */ } SpaceNode; /* snode->flag */ #define SNODE_DO_PREVIEW 1 #define SNODE_BACKDRAW 2 +#define SNODE_DISPGP 4 typedef struct SpaceImaSel { SpaceLink *next, *prev; @@ -657,6 +664,7 @@ typedef struct SpaceImaSel { #define SEQ_MARKER_TRANS 2 #define SEQ_DRAW_COLOR_SEPERATED 4 #define SEQ_DRAW_SAFE_MARGINS 8 +#define SEQ_DRAW_GPENCIL 16 /* space types, moved from DNA_screen_types.h */ enum { diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index c21d629be83..135272b9ac2 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -40,6 +40,7 @@ struct Base; struct BoundBox; struct RenderInfo; struct RetopoViewData; +struct bGPdata; /* This is needed to not let VC choke on near and far... old * proprietary MS extensions... */ @@ -53,9 +54,12 @@ struct RetopoViewData; #include "DNA_listBase.h" #include "DNA_image_types.h" +/* ******************************** */ + /* The near/far thing is a Win EXCEPTION. Thus, leave near/far in the * code, and patch for windows. */ - + +/* Background Picture in 3D-View */ typedef struct BGpic { struct Image *ima; struct ImageUser iuser; @@ -63,6 +67,9 @@ typedef struct BGpic { short xim, yim; } BGpic; +/* ********************************* */ + +/* 3D ViewPort Struct */ typedef struct View3D { struct SpaceLink *next, *prev; int spacetype; @@ -135,9 +142,10 @@ typedef struct View3D { char ndoffilter; /*filter for 6DOF devices 0 normal, 1 dominant */ void *properties_storage; /* Nkey panel stores stuff here, not in file */ - + struct bGPdata *gpd; /* Grease-Pencil Data (annotation layers) */ } View3D; + /* View3D->flag (short) */ #define V3D_MODE (16+32+64+128+256+512) #define V3D_DISPIMAGE 1 @@ -158,10 +166,12 @@ typedef struct View3D { #define V3D_DRAW_CENTERS 32768 /* View3d->flag2 (short) */ +#define V3D_MODE2 (32) #define V3D_OPP_DIRECTION_NAME 1 #define V3D_FLYMODE 2 #define V3D_DEPRECATED 4 /* V3D_TRANSFORM_SNAP, moved to a scene setting */ #define V3D_SOLID_TEX 8 +#define V3D_DISPGP 16 /* View3D->around */ #define V3D_CENTER 0 @@ -203,3 +213,4 @@ typedef struct View3D { #endif + diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index 83f4e633fa1..3818d66b39c 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -126,6 +126,7 @@ char *includefiles[] = { "DNA_customdata_types.h", "DNA_particle_types.h", "DNA_cloth_types.h", + "DNA_gpencil_types.h", // if you add files here, please add them at the end // of makesdna.c (this file) as well @@ -1147,4 +1148,5 @@ int main(int argc, char ** argv) #include "DNA_customdata_types.h" #include "DNA_particle_types.h" #include "DNA_cloth_types.h" +#include "DNA_gpencil_types.h" /* end of list */ diff --git a/source/blender/nodes/intern/SHD_nodes/SHD_material.c b/source/blender/nodes/intern/SHD_nodes/SHD_material.c index bdceb134c0d..9396410f850 100644 --- a/source/blender/nodes/intern/SHD_nodes/SHD_material.c +++ b/source/blender/nodes/intern/SHD_nodes/SHD_material.c @@ -54,7 +54,6 @@ static bNodeSocketType sh_node_material_ext_in[]= { { SOCK_VALUE, 1, "Refl", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, { SOCK_VECTOR, 1, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f}, { SOCK_RGBA, 1, "Mirror", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { SOCK_RGBA, 1, "AmbCol", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, { SOCK_VALUE, 1, "Ambient", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, { SOCK_VALUE, 1, "Emit", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, { SOCK_VALUE, 1, "SpecTra", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, @@ -117,8 +116,6 @@ static void node_shader_exec_material(void *data, bNode *node, bNodeStack **in, if (node->type == SH_NODE_MATERIAL_EXT) { if(in[MAT_IN_MIR]->hasinput) nodestack_get_vec(&shi->mirr, SOCK_VECTOR, in[MAT_IN_MIR]); - if(in[MAT_IN_AMBCOL]->hasinput) - nodestack_get_vec(&shi->ambr, SOCK_VECTOR, in[MAT_IN_AMBCOL]); if(in[MAT_IN_AMB]->hasinput) nodestack_get_vec(&shi->amb, SOCK_VALUE, in[MAT_IN_AMB]); if(in[MAT_IN_EMIT]->hasinput) diff --git a/source/blender/nodes/intern/SHD_util.c b/source/blender/nodes/intern/SHD_util.c index c9f58fbce49..f673834d2b7 100644 --- a/source/blender/nodes/intern/SHD_util.c +++ b/source/blender/nodes/intern/SHD_util.c @@ -164,7 +164,7 @@ void nodeShaderSynchronizeID(bNode *node, int copyto) case MAT_IN_MIR: VECCOPY(&ma->mirr, sock->ns.vec); break; case MAT_IN_AMB: - VECCOPY(&ma->ambr, sock->ns.vec); break; + ma->amb= sock->ns.vec[0]; break; case MAT_IN_EMIT: ma->emit= sock->ns.vec[0]; break; case MAT_IN_SPECTRA: @@ -188,7 +188,7 @@ void nodeShaderSynchronizeID(bNode *node, int copyto) case MAT_IN_MIR: VECCOPY(sock->ns.vec, &ma->mirr); break; case MAT_IN_AMB: - VECCOPY(sock->ns.vec, &ma->ambr); break; + sock->ns.vec[0]= ma->amb; break; case MAT_IN_EMIT: sock->ns.vec[0]= ma->emit; break; case MAT_IN_SPECTRA: diff --git a/source/blender/nodes/intern/SHD_util.h b/source/blender/nodes/intern/SHD_util.h index f75802b7c15..bdb2bb3707d 100644 --- a/source/blender/nodes/intern/SHD_util.h +++ b/source/blender/nodes/intern/SHD_util.h @@ -117,13 +117,12 @@ typedef struct ShaderCallData { #define MAT_IN_REFL 2 #define MAT_IN_NORMAL 3 #define MAT_IN_MIR 4 -#define MAT_IN_AMBCOL 5 -#define MAT_IN_AMB 6 -#define MAT_IN_EMIT 7 -#define MAT_IN_SPECTRA 8 -#define MAT_IN_RAY_MIRROR 9 -#define MAT_IN_ALPHA 10 -#define MAT_IN_TRANSLUCENCY 11 +#define MAT_IN_AMB 5 +#define MAT_IN_EMIT 6 +#define MAT_IN_SPECTRA 7 +#define MAT_IN_RAY_MIRROR 8 +#define MAT_IN_ALPHA 9 +#define MAT_IN_TRANSLUCENCY 10 /* output socket defines */ #define MAT_OUT_COLOR 0 diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 226657655fa..06e8c564ef0 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -160,7 +160,6 @@ ScriptError g_script_error; * Function prototypes ***************************************************************************/ PyObject *RunPython( Text * text, PyObject * globaldict ); -char *GetName( Text * text ); PyObject *CreateGlobalDictionary( void ); void ReleaseGlobalDictionary( PyObject * dict ); void DoAllScriptsFromList( ListBase * list, short event ); @@ -410,12 +409,14 @@ void BPY_rebuild_syspath( void ) mod = PyImport_ImportModule( "sys" ); if (!mod) { printf("error: could not import python sys module. some modules may not import.\n"); + PyGILState_Release(gilstate); return; } if (!bpy_orig_syspath_List) { /* should never happen */ printf("error refershing python path\n"); Py_DECREF(mod); + PyGILState_Release(gilstate); return; } @@ -649,7 +650,7 @@ int BPY_txt_do_python_Text( struct Text *text ) } /* Create a new script structure and initialize it: */ - script = alloc_libblock( &G.main->script, ID_SCRIPT, GetName( text ) ); + script = alloc_libblock( &G.main->script, ID_SCRIPT, text->id.name+2 ); if( !script ) { printf( "couldn't allocate memory for Script struct!" ); @@ -660,8 +661,7 @@ int BPY_txt_do_python_Text( struct Text *text ) * an error after it will call BPY_Err_Handle below, but the text struct * will have been deallocated already, so we need to copy its name here. */ - BLI_strncpy( textname, GetName( text ), - strlen( GetName( text ) ) + 1 ); + BLI_strncpy( textname, text->id.name+2, 21 ); script->id.us = 1; script->flags = SCRIPT_RUNNING; @@ -2722,8 +2722,7 @@ PyObject *RunPython( Text * text, PyObject * globaldict ) buf = txt_to_buf( text ); text->compiled = - Py_CompileString( buf, GetName( text ), - Py_file_input ); + Py_CompileString( buf, text->id.name+2, Py_file_input ); MEM_freeN( buf ); @@ -2738,15 +2737,6 @@ PyObject *RunPython( Text * text, PyObject * globaldict ) } /***************************************************************************** -* Description: This function returns the value of the name field of the -* given Text struct. -*****************************************************************************/ -char *GetName( Text * text ) -{ - return ( text->id.name + 2 ); -} - -/***************************************************************************** * Description: This function creates a new Python dictionary object. *****************************************************************************/ PyObject *CreateGlobalDictionary( void ) @@ -2807,7 +2797,7 @@ PyObject *importText( char *name ) text = ( Text * ) & ( G.main->text.first ); while( text ) { - if( !strcmp( txtname, GetName( text ) ) ) + if( !strcmp( txtname, text->id.name+2 ) ) break; text = text->id.next; } @@ -2820,8 +2810,7 @@ PyObject *importText( char *name ) if( !text->compiled ) { buf = txt_to_buf( text ); text->compiled = - Py_CompileString( buf, GetName( text ), - Py_file_input ); + Py_CompileString( buf, text->id.name+2, Py_file_input ); MEM_freeN( buf ); if( PyErr_Occurred( ) ) { @@ -2903,7 +2892,7 @@ static PyObject *reimportText( PyObject *module ) /* look up the text object */ text = ( Text * ) & ( G.main->text.first ); while( text ) { - if( !strcmp( txtname, GetName( text ) ) ) + if( !strcmp( txtname, text->id.name+2 ) ) break; text = text->id.next; } @@ -2920,8 +2909,7 @@ static PyObject *reimportText( PyObject *module ) /* compile the buffer */ buf = txt_to_buf( text ); - text->compiled = Py_CompileString( buf, GetName( text ), - Py_file_input ); + text->compiled = Py_CompileString( buf, text->id.name+2, Py_file_input ); MEM_freeN( buf ); /* if compile failed.... return this error */ diff --git a/source/blender/python/api2_2x/Armature.c b/source/blender/python/api2_2x/Armature.c index e9dff098773..0db87c00dd2 100644 --- a/source/blender/python/api2_2x/Armature.c +++ b/source/blender/python/api2_2x/Armature.c @@ -1469,6 +1469,8 @@ PyObject *Armature_Init(void) PyConstant_NewInt("BONE_SELECTED", BONE_SELECTED)); PyModule_AddObject(module, "TIP_SELECTED", PyConstant_NewInt("TIP_SELECTED", BONE_TIPSEL)); + PyModule_AddObject(module, "LOCKED_EDIT", + PyConstant_NewInt("LOCKED_EDIT", BONE_EDITMODE_LOCKED)); PyModule_AddObject(module, "OCTAHEDRON", PyConstant_NewInt("OCTAHEDRON", ARM_OCTA)); diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c index d8385c1d660..420d292cdce 100644 --- a/source/blender/python/api2_2x/Blender.c +++ b/source/blender/python/api2_2x/Blender.c @@ -708,7 +708,7 @@ static PyObject *Blender_Save( PyObject * self, PyObject * args ) "expected filename and optional int (overwrite flag) as arguments" ); for( li = G.main->library.first; li; li = li->id.next ) { - if( BLI_streq( li->name, fname ) ) { + if( li->parent==NULL && BLI_streq( li->name, fname ) ) { return EXPP_ReturnPyObjError( PyExc_AttributeError, "cannot overwrite used library" ); } diff --git a/source/blender/python/api2_2x/Bone.c b/source/blender/python/api2_2x/Bone.c index 84faf416c5f..948eb007803 100644 --- a/source/blender/python/api2_2x/Bone.c +++ b/source/blender/python/api2_2x/Bone.c @@ -368,6 +368,10 @@ static PyObject *EditBone_getOptions(BPy_EditBone *self, void *closure) if (PyList_Append(list, EXPP_GetModuleConstant("Blender.Armature", "TIP_SELECTED")) == -1) goto RuntimeError; + if(self->editbone->flag & BONE_EDITMODE_LOCKED) + if (PyList_Append(list, + EXPP_GetModuleConstant("Blender.Armature", "LOCKED_EDIT")) == -1) + goto RuntimeError; }else{ if(self->flag & BONE_CONNECTED) if (PyList_Append(list, @@ -401,6 +405,10 @@ static PyObject *EditBone_getOptions(BPy_EditBone *self, void *closure) if (PyList_Append(list, EXPP_GetModuleConstant("Blender.Armature", "TIP_SELECTED")) == -1) goto RuntimeError; + if(self->flag & BONE_EDITMODE_LOCKED) + if (PyList_Append(list, + EXPP_GetModuleConstant("Blender.Armature", "LOCKED_EDIT")) == -1) + goto RuntimeError; } return list; @@ -422,7 +430,7 @@ static int EditBone_CheckValidConstant(PyObject *constant) return 0; if (!STREQ3(PyString_AsString(name), "CONNECTED", "HINGE", "NO_DEFORM") && !STREQ3(PyString_AsString(name), "ROOT_SELECTED", "BONE_SELECTED", "TIP_SELECTED") && - !STREQ2(PyString_AsString(name), "MULTIPLY", "HIDDEN_EDIT")) + !STREQ3(PyString_AsString(name), "MULTIPLY", "HIDDEN_EDIT", "LOCKED_EDIT")) return 0; else return 1; diff --git a/source/blender/python/api2_2x/IDProp.c b/source/blender/python/api2_2x/IDProp.c index f60ebf8dee1..4a51619aec4 100644 --- a/source/blender/python/api2_2x/IDProp.c +++ b/source/blender/python/api2_2x/IDProp.c @@ -60,6 +60,8 @@ PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop ) return PyInt_FromLong( (long)prop->data.val ); case IDP_FLOAT: return PyFloat_FromDouble( (double)(*(float*)(&prop->data.val)) ); + case IDP_DOUBLE: + return PyFloat_FromDouble( (*(double*)(&prop->data.val)) ); case IDP_GROUP: /*blegh*/ { @@ -128,7 +130,19 @@ int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject *value) Py_XDECREF(value); break; } - + case IDP_DOUBLE: + { + double dvalue; + if (!PyNumber_Check(value)) + return EXPP_ReturnIntError(PyExc_TypeError, "expected a float!"); + value = PyNumber_Float(value); + if (!value) + return EXPP_ReturnIntError(PyExc_TypeError, "expected a float!"); + dvalue = (float) PyFloat_AsDouble(value); + *(double*)&self->prop->data.val = dvalue; + Py_XDECREF(value); + break; + } default: return EXPP_ReturnIntError(PyExc_AttributeError, "attempt to set read-only attribute!"); } @@ -204,8 +218,8 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje IDPropertyTemplate val = {0}; if (PyFloat_Check(ob)) { - val.f = (float) PyFloat_AsDouble(ob); - prop = IDP_New(IDP_FLOAT, val, name); + val.d = PyFloat_AsDouble(ob); + prop = IDP_New(IDP_DOUBLE, val, name); } else if (PyInt_Check(ob)) { val.i = (int) PyInt_AsLong(ob); prop = IDP_New(IDP_INT, val, name); @@ -223,7 +237,7 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje val.array.len = PySequence_Length(ob); for (i=0; i<val.array.len; i++) { item = PySequence_GetItem(ob, i); - if (PyFloat_Check(item)) val.array.type = IDP_FLOAT; + if (PyFloat_Check(item)) val.array.type = IDP_DOUBLE; else if (!PyInt_Check(item)) return "only floats and ints are allowed in ID property arrays"; Py_XDECREF(item); } @@ -236,7 +250,7 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje ((int*)prop->data.pointer)[i] = (int)PyInt_AsLong(item); } else { item = PyNumber_Float(item); - ((float*)prop->data.pointer)[i] = (float)PyFloat_AsDouble(item); + ((double*)prop->data.pointer)[i] = (float)PyFloat_AsDouble(item); } Py_XDECREF(item); } @@ -334,6 +348,9 @@ PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop) case IDP_FLOAT: return PyFloat_FromDouble(*((float*)&prop->data.val)); break; + case IDP_DOUBLE: + return PyFloat_FromDouble(*((double*)&prop->data.val)); + break; case IDP_INT: return PyInt_FromLong( (long)prop->data.val ); break; @@ -347,12 +364,15 @@ PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop) "PyList_New() failed" ); for (i=0; i<prop->len; i++) { - if (prop->subtype == IDP_FLOAT) + if (prop->subtype == IDP_FLOAT) { PyList_SetItem(seq, i, PyFloat_FromDouble(((float*)prop->data.pointer)[i])); - - else PyList_SetItem(seq, i, - PyInt_FromLong(((int*)prop->data.pointer)[i])); + } else if (prop->subtype == IDP_DOUBLE) { + PyList_SetItem(seq, i, + PyFloat_FromDouble(((double*)prop->data.pointer)[i])); + } else { PyList_SetItem(seq, i, + PyInt_FromLong(((int*)prop->data.pointer)[i])); + } } return seq; } @@ -451,7 +471,7 @@ PyObject *BPy_IDGroup_GetKeys(BPy_IDProperty *self) /*set correct group length*/ self->prop->len = i; - /*free the old list*/ + /*free the list*/ Py_DECREF(seq); /*call self again*/ @@ -688,6 +708,9 @@ PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, int index) case IDP_FLOAT: return PyFloat_FromDouble( (double)(((float*)self->prop->data.pointer)[index])); break; + case IDP_DOUBLE: + return PyFloat_FromDouble( (((double*)self->prop->data.pointer)[index])); + break; case IDP_INT: return PyInt_FromLong( (long)((int*)self->prop->data.pointer)[index] ); break; @@ -700,7 +723,8 @@ int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *val) { int i; float f; - + double d; + if (index < 0 || index >= self->prop->len) return EXPP_ReturnIntError( PyExc_RuntimeError, "index out of range!"); @@ -717,6 +741,17 @@ int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *val) ((float*)self->prop->data.pointer)[index] = f; Py_XDECREF(val); break; + case IDP_DOUBLE: + if (!PyNumber_Check(val)) return EXPP_ReturnIntError( PyExc_TypeError, + "expected a float"); + val = PyNumber_Float(val); + if (!val) return EXPP_ReturnIntError( PyExc_TypeError, + "expected a float"); + + d = (double) PyFloat_AsDouble(val); + ((double*)self->prop->data.pointer)[index] = d; + Py_XDECREF(val); + break; case IDP_INT: if (!PyNumber_Check(val)) return EXPP_ReturnIntError( PyExc_TypeError, "expected an int"); diff --git a/source/blender/python/api2_2x/Library.c b/source/blender/python/api2_2x/Library.c index 799735c2062..468263c4208 100644 --- a/source/blender/python/api2_2x/Library.c +++ b/source/blender/python/api2_2x/Library.c @@ -1135,9 +1135,78 @@ static PyObject *M_Library_Load(PyObject *self, PyObject * args) return (PyObject *)lib; } +static PyObject *M_Library_GetPaths(PyObject *self, PyObject * args) +{ + PyObject *list; + PyObject *name; + int type=0; + Library *lib; + + if( !PyArg_ParseTuple( args, "|i", &type ) || type < 0 || type > 2 ) { + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected an int between 0 and 2." ); + } + + list = PyList_New(0); + + for(lib= G.main->library.first; lib; lib= lib->id.next) { + if (type==0) { + /* any type is ok */ + } else if (type==1 && lib->parent == 0) { + /* only direct linked */ + } else if (type==2 && lib->parent != 0) { + /* only indirect */ + } else { + continue; /* incompatible type */ + } + + name = PyString_FromString(lib->name); + PyList_Append(list, name); + Py_DECREF(name); + } + return list; +} + +static PyObject *M_Library_ReplacePath(PyObject *self, PyObject * args) +{ + char *name_from, *name_to; + Library *lib; + + if( !PyArg_ParseTuple( args, "ss", &name_from, &name_to )) { + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected the name of a library path" ); + } + + for(lib= G.main->library.first; lib; lib= lib->id.next) { + if (strcmp(lib->name, name_from)==0) { + if (lib->parent) { + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "path is indirectly linked, cannot be changed." ); + } + + if (strlen(name_to) > sizeof(lib->name)) { + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "string length too long, cannot set path." ); + } + + strcpy(lib->name, name_to); + Py_RETURN_NONE; + } + } + + return EXPP_ReturnPyObjError( PyExc_ValueError, + "path given does not exist as a library" ); +} + + + static struct PyMethodDef M_Library_methods[] = { {"load", (PyCFunction)M_Library_Load, METH_VARARGS, "(string) - declare a .blend file for use as a library"}, + {"paths", (PyCFunction)M_Library_GetPaths, METH_VARARGS, + "(type) - return a list of library paths, type 0 for all, 1 only direct links, 2 only indirect links"}, + {"replace", (PyCFunction)M_Library_ReplacePath, METH_VARARGS, + "(from, to) - replace the path of an existing, directly linked library."}, {NULL, NULL, 0, NULL} }; diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c index c36213950b0..ccd24a437b5 100644 --- a/source/blender/python/api2_2x/Material.c +++ b/source/blender/python/api2_2x/Material.c @@ -131,11 +131,11 @@ #define EXPP_MAT_RAYMIRRGLOSS_MIN 0.0 #define EXPP_MAT_RAYMIRRGLOSS_MAX 1.0 #define EXPP_MAT_RAYMIRRGLOSSSAMPLES_MIN 0 -#define EXPP_MAT_RAYMIRRGLOSSSAMPLES_MAX 255 +#define EXPP_MAT_RAYMIRRGLOSSSAMPLES_MAX 1024 #define EXPP_MAT_RAYTRANSPGLOSS_MIN 0.0 #define EXPP_MAT_RAYTRANSPGLOSS_MAX 1.0 #define EXPP_MAT_RAYTRANSPGLOSSSAMPLES_MIN 0 -#define EXPP_MAT_RAYTRANSPGLOSSSAMPLES_MAX 255 +#define EXPP_MAT_RAYTRANSPGLOSSSAMPLES_MAX 1024 #define EXPP_MAT_FILTER_MIN 0.0 #define EXPP_MAT_FILTER_MAX 1.0 #define EXPP_MAT_TRANSLUCENCY_MIN 0.0 @@ -738,8 +738,10 @@ static PyMethodDef BPy_Material_methods[] = { "() - Return fresnel power for refractions factor"}, {"getRayTransGloss", ( PyCFunction ) Material_getGlossTrans, METH_NOARGS, "() - Return amount refraction glossiness"}, + {"getRayTransGlossSamples", ( PyCFunction ) Material_getGlossTransSamples, METH_NOARGS, + "() - Return number of sampels for transparent glossiness"}, {"getRayMirrGlossSamples", ( PyCFunction ) Material_getGlossMirrSamples, METH_NOARGS, - "() - Return amount mirror glossiness"}, + "() - Return number of sampels for mirror glossiness"}, {"getFilter", ( PyCFunction ) Material_getFilter, METH_NOARGS, "() - Return the amount of filtering when transparent raytrace is enabled"}, {"getTranslucency", ( PyCFunction ) Material_getTranslucency, METH_NOARGS, @@ -847,8 +849,10 @@ static PyMethodDef BPy_Material_methods[] = { "(f) - Set blend fac for mirror fresnel - [1.0, 5.0]"}, {"setRayTransGloss", ( PyCFunction ) Material_setGlossTrans, METH_VARARGS, "(f) - Set amount refraction glossiness - [0.0, 1.0]"}, + {"setRayTransGlossSamples", ( PyCFunction ) Material_setGlossTransSamples, METH_VARARGS, + "(i) - Set number transparent gloss samples - [1, 1024]"}, {"setRayMirrGlossSamples", ( PyCFunction ) Material_setGlossMirrSamples, METH_VARARGS, - "(f) - Set amount mirror glossiness - [0.0, 1.0]"}, + "(i) - Set number mirror gloss samples - [1, 1024]"}, {"setFilter", ( PyCFunction ) Matr_oldsetFilter, METH_VARARGS, "(f) - Set the amount of filtering when transparent raytrace is enabled"}, {"setTranslucency", ( PyCFunction ) Matr_oldsetTranslucency, METH_VARARGS, diff --git a/source/blender/python/api2_2x/Particle.c b/source/blender/python/api2_2x/Particle.c index 95de9757b87..2c2e724129e 100644 --- a/source/blender/python/api2_2x/Particle.c +++ b/source/blender/python/api2_2x/Particle.c @@ -40,6 +40,7 @@ #include "BKE_material.h" #include "BKE_utildefines.h" #include "BKE_pointcache.h" +#include "BKE_DerivedMesh.h" #include "BIF_editparticle.h" #include "BIF_space.h" #include "blendef.h" @@ -799,22 +800,27 @@ static PyObject *Part_freeEdit( BPy_PartSys * self, PyObject * args ){ Py_RETURN_NONE; } -static PyObject *Part_GetLoc( BPy_PartSys * self, PyObject * args ){ +static PyObject *Part_GetLoc( BPy_PartSys * self, PyObject * args ) +{ ParticleSystem *psys = 0L; Object *ob = 0L; PyObject *partlist,*seglist; - PyObject* loc = 0L; ParticleCacheKey **cache,*path; + PyObject* loc = 0L; ParticleKey state; - float cfra=bsystem_time(ob,(float)CFRA,0.0); + DerivedMesh* dm; + float cfra; int i,j,k; + float vm[4][4],wm[4][4]; int childexists = 0; int all = 0; int id = 0; + cfra = bsystem_time(ob,(float)CFRA,0.0); + if( !PyArg_ParseTuple( args, "|ii", &all,&id ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected one optional integer as argument" ); + "expected two optional integers as arguments" ); psys = self->psys; ob = self->object; @@ -822,88 +828,118 @@ static PyObject *Part_GetLoc( BPy_PartSys * self, PyObject * args ){ if (!ob || !psys) Py_RETURN_NONE; - if (psys->part->type == 2){ - cache=psys->pathcache; + G.rendering = 1; - /* little hack to calculate hair steps in render mode */ - psys->renderdata = (void*)(int)1; + /* Just to create a valid rendering context */ + psys_render_set(ob,psys,vm,wm,0,0,0); - psys_cache_paths(ob, psys, cfra, 1); + dm = mesh_create_derived_render(ob,CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); + dm->release(dm); - psys->renderdata = NULL; + if ( !psys_check_enabled(ob,psys) ){ + G.rendering = 0; + psys_render_restore(ob,psys); + Particle_Recalc(self,1); + Py_RETURN_NONE; + } - partlist = PyList_New( 0 ); - if( !partlist ) - return EXPP_ReturnPyObjError( PyExc_MemoryError, "PyList() failed" ); + partlist = PyList_New( 0 ); + if( !partlist ){ + PyErr_SetString( PyExc_MemoryError, "PyList_New() failed" ); + goto error; + } - for(i = 0; i < psys->totpart; i++){ - path=cache[i]; - seglist = PyList_New( 0 ); - k = path->steps+1; - for( j = 0; j < k ; j++){ - loc = PyTuple_New(3); - - PyTuple_SetItem(loc,0,PyFloat_FromDouble((double)path->co[0])); - PyTuple_SetItem(loc,1,PyFloat_FromDouble((double)path->co[1])); - PyTuple_SetItem(loc,2,PyFloat_FromDouble((double)path->co[2])); - - if ( (PyList_Append(seglist,loc) < 0) ){ - Py_DECREF(seglist); - Py_DECREF(partlist); - Py_XDECREF(loc); - return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "Couldn't append item to PyList" ); + if (psys->part->type == PART_HAIR){ + cache = psys->pathcache; + + if ( ((self->psys->part->draw & PART_DRAW_PARENT) && (self->psys->part->childtype != 0)) || (self->psys->part->childtype == 0) ){ + + for(i = 0; i < psys->totpart; i++){ + seglist = PyList_New( 0 ); + if (!seglist){ + PyErr_SetString( PyExc_MemoryError, + "PyList_New() failed" ); + goto error; + } + + path=cache[i]; + k = path->steps+1; + for( j = 0; j < k ; j++, path++){ + loc = Py_BuildValue("(fff)",(double)path->co[0], + (double)path->co[1], (double)path->co[2]); + + if (!loc){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't build tuple" ); + goto error; + } + + if ( (PyList_Append(seglist,loc) < 0) ){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + goto error; + } + Py_DECREF(loc); /* PyList_Append increfs */ + loc = NULL; } - Py_DECREF(loc); /* PyList_Append increfs */ - path++; - } - if ( PyList_Append(partlist,seglist) < 0 ){ - Py_DECREF(seglist); - Py_DECREF(partlist); - return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "Couldn't append item to PyList" ); + if ( PyList_Append(partlist,seglist) < 0 ){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + goto error; + } + Py_DECREF(seglist); /* PyList_Append increfs */ + seglist = NULL; } - Py_DECREF(seglist); /* PyList_Append increfs */ } cache=psys->childcache; for(i = 0; i < psys->totchild; i++){ - path=cache[i]; seglist = PyList_New( 0 ); - k = path->steps+1; - for( j = 0; j < k ; j++){ - loc = PyTuple_New(3); + if (!seglist){ + PyErr_SetString( PyExc_MemoryError, + "PyList_New() failed" ); + goto error; + } - PyTuple_SetItem(loc,0,PyFloat_FromDouble((double)path->co[0])); - PyTuple_SetItem(loc,1,PyFloat_FromDouble((double)path->co[1])); - PyTuple_SetItem(loc,2,PyFloat_FromDouble((double)path->co[2])); + path=cache[i]; + k = path->steps+1; + for( j = 0; j < k ; j++, path++ ){ + loc = Py_BuildValue("(fff)",(double)path->co[0], + (double)path->co[1], (double)path->co[2]); + + if (!loc){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't build tuple" ); + goto error; + } if ( PyList_Append(seglist,loc) < 0){ - Py_DECREF(partlist); - Py_XDECREF(loc); - return EXPP_ReturnPyObjError( PyExc_RuntimeError, + PyErr_SetString( PyExc_RuntimeError, "Couldn't append item to PyList" ); + goto error; } Py_DECREF(loc);/* PyList_Append increfs */ - path++; + loc = NULL; } if ( PyList_Append(partlist,seglist) < 0){ - Py_DECREF(partlist); - Py_XDECREF(loc); - return EXPP_ReturnPyObjError( PyExc_RuntimeError, + PyErr_SetString( PyExc_RuntimeError, "Couldn't append item to PyList" ); + goto error; } Py_DECREF(seglist); /* PyList_Append increfs */ + seglist = NULL; } - } else { int init; - partlist = PyList_New( 0 ); - if( !partlist ) - return EXPP_ReturnPyObjError( PyExc_MemoryError, "PyList() failed" ); + char *fmt = NULL; + + if(id) + fmt = "(fffi)"; + else + fmt = "(fff)"; if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) childexists = 1; @@ -919,55 +955,67 @@ static PyObject *Part_GetLoc( BPy_PartSys * self, PyObject * args ){ init = 1; if (init){ - if (!id) - loc = PyTuple_New(3); - else - loc = PyTuple_New(4); - PyTuple_SetItem(loc,0,PyFloat_FromDouble((double)state.co[0])); - PyTuple_SetItem(loc,1,PyFloat_FromDouble((double)state.co[1])); - PyTuple_SetItem(loc,2,PyFloat_FromDouble((double)state.co[2])); - if (id) - PyTuple_SetItem(loc,3,PyInt_FromLong(i)); + loc = Py_BuildValue(fmt,(double)state.co[0], + (double)state.co[1], (double)state.co[2],i); + + if (!loc){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't build tuple" ); + goto error; + } if ( PyList_Append(partlist,loc) < 0 ){ - Py_DECREF(partlist); - Py_XDECREF(loc); - return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "Couldn't append item to PyList" ); + PyErr_SetString( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + goto error; } - Py_DECREF(loc);/* PyList_Append increfs */ - } - else { - if ( all ){ - if ( PyList_Append(partlist,Py_None) < 0 ){ - Py_DECREF(partlist); - return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "Couldn't append item to PyList" ); - } - Py_DECREF(Py_None); /* PyList_Append increfs */ + Py_DECREF(loc); + loc = NULL; + } else { + if ( all && PyList_Append(partlist,Py_None) < 0 ){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + goto error; } } } } + + psys_render_restore(ob,psys); + G.rendering = 0; + Particle_Recalc(self,1); return partlist; + +error: + Py_XDECREF(partlist); + Py_XDECREF(seglist); + Py_XDECREF(loc); + psys_render_restore(ob,psys); + G.rendering = 0; + Particle_Recalc(self,1); + return NULL; } -static PyObject *Part_GetRot( BPy_PartSys * self, PyObject * args ){ +static PyObject *Part_GetRot( BPy_PartSys * self, PyObject * args ) +{ ParticleSystem *psys = 0L; Object *ob = 0L; PyObject *partlist = 0L; PyObject* loc = 0L; ParticleKey state; + DerivedMesh* dm; + float vm[4][4],wm[4][4]; int i; int childexists = 0; int all = 0; int id = 0; + char *fmt = NULL; float cfra=bsystem_time(ob,(float)CFRA,0.0); if( !PyArg_ParseTuple( args, "|ii", &all, &id ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected one optional integer as argument" ); + "expected two optional integers as arguments" ); psys = self->psys; ob = self->object; @@ -975,63 +1023,105 @@ static PyObject *Part_GetRot( BPy_PartSys * self, PyObject * args ){ if (!ob || !psys) Py_RETURN_NONE; - if (psys->part->type != 2){ + G.rendering = 1; + + /* Just to create a valid rendering context */ + psys_render_set(ob,psys,vm,wm,0,0,0); + + dm = mesh_create_derived_render(ob,CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); + dm->release(dm); + + if ( !psys_check_enabled(ob,psys) ){ + G.rendering = 0; + psys_render_restore(ob,psys); + Particle_Recalc(self,1); + Py_RETURN_NONE; + } + + if (psys->part->type != PART_HAIR){ partlist = PyList_New( 0 ); + if( !partlist ){ + PyErr_SetString( PyExc_MemoryError, "PyList_New() failed" ); + goto error; + } + if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) childexists = 1; + if(id) + fmt = "(ffffi)"; + else + fmt = "(ffff)"; + for (i = 0; i < psys->totpart + psys->totchild; i++){ if (childexists && (i < psys->totpart)) continue; state.time = cfra; if(psys_get_particle_state(ob,psys,i,&state,0)==0){ - if ( all ){ - PyList_Append(partlist,Py_None); - Py_DECREF(Py_None); /* PyList_Append increfs */ - continue; - } else { - continue; + if ( all && PyList_Append(partlist,Py_None) < 0){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + goto error; + } + } else { + loc = Py_BuildValue(fmt,(double)state.rot[0], (double)state.rot[1], + (double)state.rot[2], (double)state.rot[3], i); + + if (!loc){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't build tuple" ); + goto error; + } + if (PyList_Append(partlist,loc) < 0){ + PyErr_SetString ( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + goto error; } + Py_DECREF(loc); /* PyList_Append increfs */ + loc = NULL; } - if (!id) - loc = PyTuple_New(4); - else - loc = PyTuple_New(5); - PyTuple_SetItem(loc,0,PyFloat_FromDouble((double)state.rot[0])); - PyTuple_SetItem(loc,1,PyFloat_FromDouble((double)state.rot[1])); - PyTuple_SetItem(loc,2,PyFloat_FromDouble((double)state.rot[2])); - PyTuple_SetItem(loc,3,PyFloat_FromDouble((double)state.rot[3])); - if (id) - PyTuple_SetItem(loc,4,PyInt_FromLong(i)); - PyList_Append(partlist,loc); - Py_DECREF(loc); /* PyList_Append increfs */ } + } else { + partlist = EXPP_incr_ret( Py_None ); } + + psys_render_restore(ob,psys); + G.rendering = 0; + Particle_Recalc(self,1); return partlist; + +error: + Py_XDECREF(partlist); + Py_XDECREF(loc); + psys_render_restore(ob,psys); + G.rendering = 0; + Particle_Recalc(self,1); + return NULL; } -static PyObject *Part_GetSize( BPy_PartSys * self, PyObject * args ){ +static PyObject *Part_GetSize( BPy_PartSys * self, PyObject * args ) +{ ParticleKey state; ParticleSystem *psys = 0L; ParticleData *data; Object *ob = 0L; PyObject *partlist,*tuple; - PyObject* siz = 0L; + DerivedMesh* dm; + float vm[4][4],wm[4][4]; float size; int i; int childexists = 0; int all = 0; int id = 0; + char *fmt = NULL; float cfra=bsystem_time(ob,(float)CFRA,0.0); if( !PyArg_ParseTuple( args, "|ii", &all, &id ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected one optional integer as argument" ); - - data = self->psys->particles; + "expected two optional integers as arguments" ); psys = self->psys; ob = self->object; @@ -1039,13 +1129,39 @@ static PyObject *Part_GetSize( BPy_PartSys * self, PyObject * args ){ if (!ob || !psys) Py_RETURN_NONE; - partlist = PyList_New( 0 ); + G.rendering = 1; - if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) - childexists = 1; + /* Just to create a valid rendering context */ + psys_render_set(ob,psys,vm,wm,0,0,0); + + dm = mesh_create_derived_render(ob,CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); + dm->release(dm); + data = self->psys->particles; + + if ( !psys_check_enabled(ob,psys) ){ + psys_render_restore(ob,psys); + G.rendering = 0; + Particle_Recalc(self,1); + Py_RETURN_NONE; + } + + partlist = PyList_New( 0 ); + + if( !partlist ){ + PyErr_SetString( PyExc_MemoryError, "PyList_New() failed" ); + goto error; + } + + if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) + childexists = 1; + + if(id) + fmt = "(fi)"; + else + fmt = "f"; - for (i = 0; i < psys->totpart + psys->totchild; i++, data++){ - if (psys->part->type != 2){ + for (i = 0; i < psys->totpart + psys->totchild; i++, data++){ + if (psys->part->type != PART_HAIR){ if (childexists && (i < psys->totpart)) continue; @@ -1061,43 +1177,61 @@ static PyObject *Part_GetSize( BPy_PartSys * self, PyObject * args ){ ChildParticle *cpa= &psys->child[i-psys->totpart]; size = psys_get_child_size(psys,cpa,cfra,0); } - if (id){ - tuple = PyTuple_New(2); - PyTuple_SetItem(tuple,0,PyFloat_FromDouble((double)size)); - PyTuple_SetItem(tuple,1,PyInt_FromLong(i)); - PyList_Append(partlist,tuple); - Py_DECREF(tuple); - } else { - siz = PyFloat_FromDouble((double)size); - PyList_Append(partlist,siz); - Py_DECREF(siz); + + tuple = Py_BuildValue(fmt,(double)size,i); + + if (!tuple){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't build tuple" ); + goto error; + } + + if (PyList_Append(partlist,tuple) < 0){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + goto error; } + Py_DECREF(tuple); + tuple = NULL; } } + + psys_render_restore(ob,psys); + G.rendering = 0; + Particle_Recalc(self,1); return partlist; + +error: + Py_XDECREF(partlist); + Py_XDECREF(tuple); + psys_render_restore(ob,psys); + G.rendering = 0; + Particle_Recalc(self,1); + return NULL; } -static PyObject *Part_GetAge( BPy_PartSys * self, PyObject * args ){ +static PyObject *Part_GetAge( BPy_PartSys * self, PyObject * args ) +{ ParticleKey state; ParticleSystem *psys = 0L; ParticleData *data; Object *ob = 0L; PyObject *partlist,*tuple; - PyObject* lif = 0L; + DerivedMesh* dm; + float vm[4][4],wm[4][4]; float life; int i; int childexists = 0; int all = 0; int id = 0; + char *fmt = NULL; float cfra=bsystem_time(ob,(float)CFRA,0.0); if( !PyArg_ParseTuple( args, "|ii", &all, &id ) ) return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected one optional integer as argument" ); - - data = self->psys->particles; + "expected two optional integers as arguments" ); psys = self->psys; ob = self->object; @@ -1105,13 +1239,37 @@ static PyObject *Part_GetAge( BPy_PartSys * self, PyObject * args ){ if (!ob || !psys) Py_RETURN_NONE; - partlist = PyList_New( 0 ); + G.rendering = 1; - if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) - childexists = 1; + /* Just to create a valid rendering context */ + psys_render_set(ob,psys,vm,wm,0,0,0); + + dm = mesh_create_derived_render(ob,CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); + dm->release(dm); + data = self->psys->particles; + + if ( !psys_check_enabled(ob,psys) ){ + psys_render_restore(ob,psys); + G.rendering = 0; + Py_RETURN_NONE; + } + + partlist = PyList_New( 0 ); + if( !partlist ){ + PyErr_SetString( PyExc_MemoryError, "PyList_New() failed" ); + goto error; + } + + if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) + childexists = 1; + + if(id) + fmt = "(fi)"; + else + fmt = "f"; - for (i = 0; i < psys->totpart + psys->totchild; i++, data++){ - if (psys->part->type != 2){ + for (i = 0; i < psys->totpart + psys->totchild; i++, data++){ + if (psys->part->type != PART_HAIR){ if (childexists && (i < psys->totpart)) continue; @@ -1128,20 +1286,37 @@ static PyObject *Part_GetAge( BPy_PartSys * self, PyObject * args ){ ChildParticle *cpa= &psys->child[i-psys->totpart]; life = psys_get_child_time(psys,cpa,cfra); } - if (id){ - tuple = PyTuple_New(2); - PyTuple_SetItem(tuple,0,PyFloat_FromDouble((double)life)); - PyTuple_SetItem(tuple,1,PyInt_FromLong(i)); - PyList_Append(partlist,tuple); - Py_DECREF(tuple); - } else { - lif = PyFloat_FromDouble((double)life); - PyList_Append(partlist,lif); - Py_DECREF(lif); + + tuple = Py_BuildValue(fmt,(double)life,i); + + if (!tuple){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't build tuple" ); + goto error; } + + if (PyList_Append(partlist,tuple) < 0){ + PyErr_SetString( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + goto error; + } + Py_DECREF(tuple); + tuple = NULL; } } + + psys_render_restore(ob,psys); + G.rendering = 0; + Particle_Recalc(self,1); return partlist; + +error: + Py_XDECREF(partlist); + Py_XDECREF(tuple); + psys_render_restore(ob,psys); + G.rendering = 0; + Particle_Recalc(self,1); + return NULL; } @@ -1376,11 +1551,8 @@ static int Part_set2d( BPy_PartSys * self, PyObject * args ) { int number; - if( !PyInt_Check( args ) ) { - char errstr[128]; - sprintf ( errstr, "expected int argument" ); - return EXPP_ReturnIntError( PyExc_TypeError, errstr ); - } + if( !PyInt_Check( args ) ) + return EXPP_ReturnIntError( PyExc_TypeError, "expected int argument" ); number = PyInt_AS_LONG( args ); @@ -1526,7 +1698,7 @@ static int Part_setRandEmission( BPy_PartSys * self, PyObject * args ) static PyObject *Part_getRandEmission( BPy_PartSys * self ) { - return PyInt_FromLong( ((long)( self->psys->part->flag & PART_BOIDS_2D )) > 0 ); + return PyInt_FromLong( ((long)( self->psys->part->flag & PART_TRAND )) > 0 ); } static int Part_setParticleDist( BPy_PartSys * self, PyObject * args ) @@ -1546,7 +1718,7 @@ static int Part_setParticleDist( BPy_PartSys * self, PyObject * args ) return EXPP_ReturnIntError( PyExc_TypeError, errstr ); } - self->psys->part->from = number; + self->psys->part->from = (short)number; Particle_RecalcPsys_distr(self,1); @@ -1603,7 +1775,7 @@ static int Part_setDist( BPy_PartSys * self, PyObject * args ) return EXPP_ReturnIntError( PyExc_TypeError, errstr ); } - self->psys->part->distr = number; + self->psys->part->distr = (short)number; Particle_RecalcPsys_distr(self,1); @@ -1731,7 +1903,7 @@ static int Part_setTargetPsys( BPy_PartSys * self, PyObject * args ){ res = EXPP_setIValueRange( args, &self->psys->target_psys, 0, tottpsys, 'h' ); - if((psys=psys_get_current(ob))){ + if( ( psys = psys_get_current(ob) ) ){ if(psys->keyed_ob==ob || psys->target_ob==ob){ if(psys->keyed_ob==ob) psys->keyed_ob=NULL; diff --git a/source/blender/python/api2_2x/doc/Armature.py b/source/blender/python/api2_2x/doc/Armature.py index 68916af6166..9aceb0105e3 100644 --- a/source/blender/python/api2_2x/doc/Armature.py +++ b/source/blender/python/api2_2x/doc/Armature.py @@ -89,6 +89,8 @@ Example:: @type BONE_SELECTED: Constant @var TIP_SELECTED: Tip of the Bone is selected @type TIP_SELECTED: Constant +@var LOCKED_EDIT: Prevents the bone from being transformed in editmode +@type LOCKED_EDIT: Constant @var OCTAHEDRON: Bones drawn as octahedrons @type OCTAHEDRON: Constant @var STICK: Bones drawn as a line @@ -286,6 +288,7 @@ class Bone: - Armature.ROOT_SELECTED: Selection of root ball of bone - Armature.BONE_SELECTED: Selection of bone - Armature.TIP_SELECTED: Selection of tip ball of bone + - Armature.LOCKED_EDIT: Prevents the bone from being transformed in editmode @type options: List of Constants @ivar subdivision: The number of bone subdivisions. @type subdivision: Int diff --git a/source/blender/python/api2_2x/doc/IDProp.py b/source/blender/python/api2_2x/doc/IDProp.py index 0a0df335fa3..01d5136cd70 100644 --- a/source/blender/python/api2_2x/doc/IDProp.py +++ b/source/blender/python/api2_2x/doc/IDProp.py @@ -18,7 +18,9 @@ class IDGroup: Note that for arrays, the array type defaults to int unless a float is found while scanning the template list; if any floats are found, then the whole - array is float. + array is float. Note that double-precision floating point numbers are used for + python-created float ID properties and arrays (though the internal C api does + support single-precision floats, and the python code will read them). You can also delete properties with the del operator. For example: diff --git a/source/blender/python/api2_2x/doc/Ipo.py b/source/blender/python/api2_2x/doc/Ipo.py index c479926ccf3..d1c72f8cb86 100644 --- a/source/blender/python/api2_2x/doc/Ipo.py +++ b/source/blender/python/api2_2x/doc/Ipo.py @@ -250,7 +250,7 @@ class Ipo: OfsZ, SizeX, SizeY, SizeZ, texR, texG, texB, DefVar, Col, Nor, Var, Disp. 3. Object Ipo: LocX, LocY, LocZ, dLocX, dLocY, dLocZ, RotX, RotY, RotZ, - dRotX, dRotY, dRotZ, SizeX, SizeY, SizeZ, dSizeX, dSizeY, dSizeZ, + dRotX, dRotY, dRotZ, ScaleX, ScaleY, ScaleZ, dScaleX, dScaleY, dScaleZ, Layer, Time, ColR, ColG, ColB, ColA, FStreng, FFall, Damping, RDamp, Perm. 4. Lamp Ipo: Energ, R, G, B, Dist, SpoSi, SpoBl, Quad1, Quad2, HaInt. @@ -289,7 +289,7 @@ class Ipo: OfsZ, SizeX, SizeY, SizeZ, texR, texG, texB, DefVar, Col, Nor, Var, Disp. 3. Object Ipo: LocX, LocY, LocZ, dLocX, dLocY, dLocZ, RotX, RotY, RotZ, - dRotX, dRotY, dRotZ, SizeX, SizeY, SizeZ, dSizeX, dSizeY, dSizeZ, + dRotX, dRotY, dRotZ, ScaleX, ScaleY, ScaleZ, dScaleX, dScaleY, dScaleZ, Layer, Time, ColR, ColG, ColB, ColA, FStreng, FFall, Damping, RDamp, Perm. 4. Lamp Ipo: Energ, R, G, B, Dist, SpoSi, SpoBl, Quad1, Quad2, HaInt. diff --git a/source/blender/python/api2_2x/doc/LibData.py b/source/blender/python/api2_2x/doc/LibData.py index 47bd7fdb763..daa6a186531 100644 --- a/source/blender/python/api2_2x/doc/LibData.py +++ b/source/blender/python/api2_2x/doc/LibData.py @@ -27,17 +27,37 @@ Example:: """ def load(filename,relative=False): - """ - Select an existing .blend file for use as a library. Unlike the - Library module, multiple libraries can be defined at the same time. - - @type filename: string - @param filename: The filename of a Blender file. Filenames starting with "//" will be loaded relative to the blend file's location. - @type relative: boolean - @param relative: Convert relative paths to absolute paths (default). Setting this parameter to True will leave paths relative. - @rtype: Library - @return: return a L{Library} object. - """ + """ + Select an existing .blend file for use as a library. Unlike the + Library module, multiple libraries can be defined at the same time. + + @type filename: string + @param filename: The filename of a Blender file. Filenames starting with "//" will be loaded relative to the blend file's location. + @type relative: boolean + @param relative: Convert relative paths to absolute paths (default). Setting this parameter to True will leave paths relative. + @rtype: Library + @return: return a L{Library} object. + """ + +def paths(link=0): + """ + Returns a list of paths used in the current blend file. + + @type link: int + @param link: 0 (default if no args given) for all library paths, 1 for directly linked library paths only, 2 for indirectly linked library paths only. + @rtype: List + @return: return a list of path strings. + """ + +def replace(pathFrom, pathTo): + """ + Replaces an existing directly linked path. + + @type pathFrom: string + @param pathFrom: An existing library path. + @type pathTo: string + @param pathTo: A new library path. + """ class Libraries: """ diff --git a/source/blender/python/api2_2x/doc/Particle.py b/source/blender/python/api2_2x/doc/Particle.py index 192ecd5355b..511ad81b45f 100644 --- a/source/blender/python/api2_2x/doc/Particle.py +++ b/source/blender/python/api2_2x/doc/Particle.py @@ -56,17 +56,17 @@ class Particle: @type type: int @ivar resolutionGrid: The resolution of the particle grid. @type resolutionGrid: int - @ivar startFrame: Frame # to start emitting particles. + @ivar startFrame: Frame number to start emitting particles. @type startFrame: float - @ivar endFrame: Frame # to stop emitting particles. + @ivar endFrame: Frame number to stop emitting particles. @type endFrame: float @ivar editable: Finalize hair to enable editing in particle mode. @type editable: int @ivar amount: The total number of particles. @type amount: int - @ivar multireact: React multiple times ( Paricle.REACTON[ 'NEAR' | 'COLLISION' | 'DEATH' ] ). + @ivar multireact: React multiple times ( Particle.REACTON[ 'NEAR' | 'COLLISION' | 'DEATH' ] ). @type multireact: int - @ivar reactshape: Power of reaction strength dependence on distance to target. + @ivar reactshape: Power of reaction strength, dependent on distance to target. @type reactshape: float @ivar hairSegments: Amount of hair segments. @type hairSegments: int @@ -74,13 +74,13 @@ class Particle: @type lifetime: float @ivar randlife: Give the particle life a random variation. @type randlife: float - @ivar randemission: Give the particle life a random variation + @ivar randemission: Emit particles in random order. @type randemission: int - @ivar particleDistribution: Where to emit particles from Paricle.EMITFROM[ 'PARTICLE' | 'VOLUME' | 'FACES' | 'VERTS' ] ) + @ivar particleDistribution: Where to emit particles from ( Particle.EMITFROM[ 'PARTICLE' | 'VOLUME' | 'FACES' | 'VERTS' ] ) @type particleDistribution: int @ivar evenDistribution: Use even distribution from faces based on face areas or edge lengths. @type evenDistribution: int - @ivar distribution: How to distribute particles on selected element Paricle.DISTRIBUTION[ 'GRID' | 'RANDOM' | 'JITTERED' ] ). + @ivar distribution: How to distribute particles on selected element ( Particle.DISTRIBUTION[ 'GRID' | 'RANDOM' | 'JITTERED' ] ). @type distribution: int @ivar jitterAmount: Amount of jitter applied to the sampling. @type jitterAmount: float @@ -131,237 +131,56 @@ class Particle: Get the particles locations. A list of tuple is returned in particle mode. A list of list of tuple is returned in hair mode. - The tuple is a vector list of 3 or 4 floats in world space (x,y,z, optionnaly the particle's id). + The tuple is a vector of 3 or 4 floats in world space (x,y,z, +optionally the particle's id). @type all: int @param all: if not 0 export all particles (uninitialized (unborn or died)particles exported as None). @type id: int @param id: add the particle id in the end of the vector tuple - @rtype: list of vectors (tuple of 3 floats and optionnaly the id) or list of list of vectors - @return: list of vectors or list of list of vectors (hair mode) + @rtype: list of vectors (tuple of 3 floats and optionally the id) or list of list of vectors + @return: list of vectors or list of list of vectors (hair mode) or None if system is disabled """ def getRot(all=0,id=0): """ - Get the particles rotations as quaternion. + Get the particles' rotations as quaternion. A list of tuple is returned in particle mode. - The tuple is a vector list of 4 or 5 floats (x,y,z,w, optionnaly the id of the particle). + The tuple is vector of 4 or 5 floats (x,y,z,w, optionally the id of the particle). @type all: int - @param all: if not 0 export all particles (uninitialized (unborn or died) particles exported as None). + @param all: if not 0, export all particles (uninitialized (unborn or died) particles exported as None). @type id: int @param id: add the particle id in the return tuple @rtype: list of tuple of 4 or 5 elements (if id is not zero) - @return: list of 4-tuples + @return: list of 4-tuples or None if system is disabled """ def getMat(): """ - Get the particles material. + Get the particles' material. @rtype: Blender Material - @return: The marterial assigned to particles + @return: The material assigned to particles """ def getSize(all=0,id=0): """ - Get the particles size. + Get the particles' size. A list of float or list of tuple (particle's size,particle's id). @type all: int - @param all: if not 0 export all particles (uninitialized (unborn or died) particles exported as None). + @param all: if not 0, export all particles (uninitialized (unborn or died) particles exported as None). @type id: int @param id: add the particle id in the return tuple @rtype: list of floats - @return: list of floats or list of tuples if id is not zero (size,id). + @return: list of floats or list of tuples if id is not zero (size,id) or None if system is disabled. """ def getAge(all=0,id=0): """ - Get the particles age. - A list of float or list of tuple (particle's age,particle's id). + Get the particles' age. + A list of float or list of tuple (particle's age, particle's id). @type all: int - @param all: if not 0 export all particles (uninitialized (unborn or died) particles exported as None). + @param all: if not 0, export all particles (uninitialized (unborn or died) particles exported as None). @type id: int @param id: add the particle id in the return tuple @rtype: list of floats - @return: list of floats or list of tuples if id is not zero (size,id). - """ -# Blender.Object module and the Object PyType object - -""" -The Blender.Particle submodule - - -Particle -======== - -This module provides access to the B{Particle} in Blender. - -@type TYPE: readonly dictionary -@var TYPE: Constant dict used for with L{Particle.TYPE} - - HAIR: set particle system to hair mode. - - REACTOR: set particle system to reactor mode. - - EMITTER: set particle system to emitter mode. -@type DISTRIBUTION: readonly dictionary -@var DISTRIBUTION: Constant dict used for with L{Particle.DISTRIBUTION} - - GRID: set grid distribution. - - RANDOM: set random distribution. - - JITTERED: set jittered distribution. -@type EMITFROM: readonly dictionary -@var EMITFROM: Constant dict used for with L{Particle.EMITFROM} - - VERTS: set particles emit from vertices - - FACES: set particles emit from faces - - VOLUME: set particles emit from volume - - PARTICLE: set particles emit from particles -@type REACTON: readonly dictionary -@var REACTON: Constant dict used for with L{Particle.REACTON} - - NEAR: react on near - - COLLISION: react on collision - - DEATH: react on death -@type DRAWAS: readonly dictionary -@var DRAWAS: Constant dict used for with L{Particle.DRAWAS} - - NONE: Don't draw - - POINT: Draw as point - - CIRCLE: Draw as circles - - CROSS: Draw as crosses - - AXIS: Draw as axis - - LINE: Draw as lines - - PATH: Draw pathes - - OBJECT: Draw object - - GROUP: Draw goup - - BILLBOARD: Draw as billboard -""" - -def Get(name): - """ - Get the particle system of the object "name". - @type name: string - @return: The particle system of the object. - """ -def New(name): - """ - Assign a new particle system to the object "name". - @type name: string - @return: The newly created particle system. - """ - -class Particle: - """ - The Particle object - =================== - This object gives access to paticles data. - - @ivar seed: Set an offset in the random table. - @type seed: int - @ivar type: Type of particle system ( Particle.TYPE[ 'HAIR' | 'REACTOR' | 'EMITTER' ] ). - @type type: int - @ivar resolutionGrid: The resolution of the particle grid. - @type resolutionGrid: int - @ivar startFrame: Frame # to start emitting particles. - @type startFrame: float - @ivar endFrame: Frame # to stop emitting particles. - @type endFrame: float - @ivar editable: Finalize hair to enable editing in particle mode. - @type editable: int - @ivar amount: The total number of particles. - @type amount: int - @ivar multireact: React multiple times ( Paricle.REACTON[ 'NEAR' | 'COLLISION' | 'DEATH' ] ). - @type multireact: int - @ivar reactshape: Power of reaction strength dependence on distance to target. - @type reactshape: float - @ivar hairSegments: Amount of hair segments. - @type hairSegments: int - @ivar lifetime: Specify the life span of the particles. - @type lifetime: float - @ivar randlife: Give the particle life a random variation. - @type randlife: float - @ivar randemission: Give the particle life a random variation - @type randemission: int - @ivar particleDistribution: Where to emit particles from Paricle.EMITFROM[ 'PARTICLE' | 'VOLUME' | 'FACES' | 'VERTS' ] ) - @type particleDistribution: int - @ivar evenDistribution: Use even distribution from faces based on face areas or edge lengths. - @type evenDistribution: int - @ivar distribution: How to distribute particles on selected element Paricle.DISTRIBUTION[ 'GRID' | 'RANDOM' | 'JITTERED' ] ). - @type distribution: int - @ivar jitterAmount: Amount of jitter applied to the sampling. - @type jitterAmount: float - @ivar pf: Emission locations / face (0 = automatic). - @type pf:int - @ivar invert: Invert what is considered object and what is not. - @type invert: int - @ivar targetObject: The object that has the target particle system (empty if same object). - @type targetObject: Blender object - @ivar targetpsys: The target particle system number in the object. - @type targetpsys: int - @ivar 2d: Constrain boids to a surface. - @type 2d: float - @ivar maxvel: Maximum velocity. - @type maxvel: float - @ivar avvel: The usual speed % of max velocity. - @type avvel: float - @ivar latacc: Lateral acceleration % of max velocity - @type latacc: float - @ivar tanacc: Tangential acceleration % of max velocity - @type tanacc: float - @ivar groundz: Default Z value. - @type groundz: float - @ivar object: Constrain boids to object's surface. - @type object: Blender Object - @ivar renderEmitter: Render emitter object. - @type renderEmitter: int - @ivar displayPercentage: Particle display percentage. - @type displayPercentage: int - @ivar hairDisplayStep: How many steps paths are drawn with (power of 2) in visu mode. - @type hairDisplayStep: int - @ivar hairRenderStep: How many steps paths are rendered with (power of 2) in render mode." - @type hairRenderStep: int - @ivar duplicateObject: Get the duplicate object. - @type duplicateObject: Blender Object - @ivar drawAs: Get draw type Particle.DRAWAS([ 'NONE' | 'OBJECT' | 'POINT' | ... ]). - @type drawAs: int - """ - def freeEdit(): - """ - Free edit mode. - @return: None - """ - - def getLoc(all=0,id=0): - """ - Get the particles locations. - A list of tuple is returned in particle mode. - A list of list of tuple is returned in hair mode. - The tuple is a vector list of 3 floats in world space. - @type all: int - @param all: if not 0 export all particles (uninitialized (unborn or died)particles exported as None). - @type id: int - @param id: add the particle id in the end of the vector tuple - @rtype: list of vectors (tuple of 3 floats and optionnaly the id) or list of list of vectors - @return: list of vectors or list of list of vectors (hair mode) - """ - def getRot(all=0,id=0): - """ - Get the particles rotations as quaternion. - A list of tuple is returned in particle mode. - The tuple is a vector list of 4 floats (quaternion). - @type all: int - @param all: if not 0 export all particles (uninitialized (unborn or died) particles exported as None). - @type id: int - @param id: add the particle id in the return tuple - @rtype: list of tuple of 4 or 5 elements (if id is not zero) - @return: list of 4-tuples - """ - def getMat(): - """ - Get the particles material. - @rtype: Blender Material - @return: The marterial assigned to particles - """ - def getSize(all=0,id=0): - """ - Get the particles size. - A list of float. - @type all: int - @param all: if not 0 export all particles (uninitialized (unborn or died) particles exported as None). - @type id: int - @param id: add the particle id in the return tuple - @rtype: list of floats - @return: list of floats or list of tuples if id is not zero (size,id). + @return: list of floats or list of tuples if id is not zero (size,id) or None if system is disabled. """ diff --git a/source/blender/python/api2_2x/doc/Render.py b/source/blender/python/api2_2x/doc/Render.py index 475a4fc5b10..d4dc83e84a0 100644 --- a/source/blender/python/api2_2x/doc/Render.py +++ b/source/blender/python/api2_2x/doc/Render.py @@ -833,9 +833,7 @@ class RenderData: def enableCropping(toggle): """ - Enable/disable exclusion of border rendering from total image. - @type toggle: int - @param toggle: pass 1 for on / 0 for off + Deprecated: see the L{crop} attribute. """ def setImageType(type): diff --git a/source/blender/python/api2_2x/sceneRender.c b/source/blender/python/api2_2x/sceneRender.c index b446af7efd4..22e165cbe9f 100644 --- a/source/blender/python/api2_2x/sceneRender.c +++ b/source/blender/python/api2_2x/sceneRender.c @@ -56,6 +56,7 @@ struct View3D; /* keep me up here */ #include "gen_utils.h" #include "gen_library.h" +#include "../BPY_extern.h" /* for BPY_do_all_scripts() */ #include "Scene.h" #include "Group.h" @@ -469,19 +470,20 @@ PyObject *M_Render_EnableDispWin( PyObject * self ) PyObject *RenderData_Render( BPy_RenderData * self ) { Scene *oldsce; + /* unlock to prevent a deadlock when there are pynodes: */ + PyThreadState *tstate = NULL; if (!G.background) { oldsce = G.scene; set_scene( self->scene ); + tstate = PyEval_SaveThread(); BIF_do_render( 0 ); set_scene( oldsce ); } - else { /* background mode (blender -b file.blend -P script) */ + int slink_flag = 0; Render *re= RE_NewRender(G.scene->id.name); - - int end_frame = G.scene->r.efra; if (G.scene != self->scene) @@ -490,11 +492,25 @@ PyObject *RenderData_Render( BPy_RenderData * self ) G.scene->r.efra = G.scene->r.sfra; + if (G.f & G_DOSCRIPTLINKS) { + BPY_do_all_scripts(SCRIPT_RENDER); + G.f &= ~G_DOSCRIPTLINKS; /* avoid FRAMECHANGED events*/ + slink_flag = 1; + } + + tstate = PyEval_SaveThread(); + RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra); + if (slink_flag) { + G.f |= G_DOSCRIPTLINKS; + BPY_do_all_scripts(SCRIPT_POSTRENDER); + } + G.scene->r.efra = end_frame; } + PyEval_RestoreThread(tstate); Py_RETURN_NONE; } @@ -565,10 +581,13 @@ PyObject *RenderData_SaveRenderedImage ( BPy_RenderData * self, PyObject *args ) PyObject *RenderData_RenderAnim( BPy_RenderData * self ) { Scene *oldsce; - + /* unlock to prevent a deadlock when there are pynodes: */ + PyThreadState *tstate = NULL; + if (!G.background) { oldsce = G.scene; set_scene( self->scene ); + tstate = PyEval_SaveThread(); BIF_do_render( 1 ); set_scene( oldsce ); } @@ -582,9 +601,18 @@ PyObject *RenderData_RenderAnim( BPy_RenderData * self ) if (G.scene->r.sfra > G.scene->r.efra) return EXPP_ReturnPyObjError (PyExc_RuntimeError, "start frame must be less or equal to end frame"); - + + if (G.f & G_DOSCRIPTLINKS) + BPY_do_all_scripts(SCRIPT_RENDER); + + tstate = PyEval_SaveThread(); RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra); + + if (G.f & G_DOSCRIPTLINKS) + BPY_do_all_scripts(SCRIPT_POSTRENDER); } + + PyEval_RestoreThread(tstate); Py_RETURN_NONE; } @@ -985,7 +1013,7 @@ PyObject *RenderData_EnableCropping( void ) /* return M_Render_BitToggleInt( args, R_MOVIECROP, &self->renderContext->mode ); */ - printf("cropping option is now default, obsolete\n"); + printf("obsolete: movie cropping option is now default\n"); Py_RETURN_NONE; } diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index faa7a68f754..e4a5ad67631 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -1865,9 +1865,17 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem num= cpa->num; /* get orco */ - psys_particle_on_emitter(ob, psmd, - (part->childtype == PART_CHILD_FACES)? PART_FROM_FACE: PART_FROM_PARTICLE, - cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,co,nor,0,0,orco,0); + if(part->childtype == PART_CHILD_FACES) { + psys_particle_on_emitter(ob, psmd, + PART_FROM_FACE, cpa->num,DMCACHE_ISCHILD, + cpa->fuv,cpa->foffset,co,nor,0,0,orco,0); + } + else { + ParticleData *par = psys->particles + cpa->parent; + psys_particle_on_emitter(ob, psmd, part->from, + par->num,DMCACHE_ISCHILD,par->fuv, + par->foffset,co,nor,0,0,orco,0); + } if(uvco){ if(part->from!=PART_FROM_PARTICLE && part->childtype==PART_CHILD_FACES){ diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 67be0ce4c00..4520e4c10bb 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -671,8 +671,10 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) RenderPass *zpass; GroupObject *go; LampRen *lar; - - int x, y; + RenderLayer *rlpp[RE_MAX_OSA]; + + int totsample, fullsample, sample; + int x, y,od; short first_lamp; float *zrect; float *rgbrect; @@ -683,7 +685,10 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) fac = 0.5; facm = 1.0 - fac; - + + totsample= get_sample_layers(pa, rl, rlpp); + fullsample= (totsample > 1); + /* check that z pass is enabled */ if(pa->rectz==NULL) return; for(zpass= rl->passes.first; zpass; zpass= zpass->next) @@ -708,9 +713,10 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) zrect = zpass->rect; rgbrect = rl->rectf; + od=0; /* for each x,y and sun lamp*/ for(y=pa->disprect.ymin; y<pa->disprect.ymax; y++) { - for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, zrect++, rgbrect+=4) { + for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, zrect++, od++) { first_lamp = 1; for(go=R.lights.first; go; go= go->next) { @@ -724,7 +730,7 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) } if(lar->sunsky->effect_type & LA_SUN_EFFECT_AP){ - VECCOPY(tmp_rgb, rgbrect); + VECCOPY(tmp_rgb, (float*)(rgbrect+4*od)); shadeAtmPixel(lar->sunsky, tmp_rgb, x, y, *zrect); @@ -743,7 +749,16 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl) /* if at least for one sun lamp aerial perspective was applied*/ if(first_lamp==0) - VECCOPY(rgbrect, rgb); + { + if(fullsample) { + for(sample=0; sample<totsample; sample++) { + VECCOPY((float*)(rlpp[sample]->rectf + od*4), rgb); + } + } + else { + VECCOPY((float*)(rgbrect+4*od), rgb); + } + } } } } diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c index 0928042729a..5b69323667e 100644 --- a/source/blender/render/intern/source/shadeoutput.c +++ b/source/blender/render/intern/source/shadeoutput.c @@ -1379,6 +1379,8 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int } /* specularity */ + shadfac[3]*= phongcorr; /* note, shadfac not allowed to be stored nonlocal */ + if(shadfac[3]>0.0f && shi->spec!=0.0f && !(lar->mode & LA_NO_SPEC) && !(lar->mode & LA_ONLYSHADOW)) { if(!(passflag & (SCE_PASS_COMBINED|SCE_PASS_SPEC))); diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c index 517ae2b76ca..114eb329308 100644 --- a/source/blender/src/buttons_editing.c +++ b/source/blender/src/buttons_editing.c @@ -1931,7 +1931,7 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco uiBlockBeginAlign(block); uiDefButF(block, NUM, B_MODIFIER_RECALC, "Width: ", lx, (cy -= 19), buttonWidth, 19, &bmd->value, - 0.0, 0.5, 5, 2, + 0.0, 0.5, 5, 4, "Bevel value/amount"); /*uiDefButI(block, NUM, B_MODIFIER_RECALC, "Recurs", lx, (cy -= 19), buttonWidth, 19, &bmd->res, @@ -4373,11 +4373,12 @@ static void editing_panel_armature_bones(Object *ob, bArmature *arm) uiDefButF(block, NUM,B_ARM_RECALCDATA, "Weight:", 225, by-19,105, 18, &curBone->weight, 0.0F, 1000.0F, 10.0F, 0.0F, "Bone deformation weight"); /* bone types */ - uiDefButBitI(block, TOG, BONE_HINGE, B_ARM_RECALCDATA, "Hinge", -10,by-38,80,18, &curBone->flag, 1.0, 32.0, 0.0, 0.0, "Don't inherit rotation or scale from parent Bone"); - uiDefButBitI(block, TOG, BONE_NO_SCALE, B_ARM_RECALCDATA, "S", 70,by-38,20,18, &curBone->flag, 1.0, 32.0, 0.0, 0.0, "Don't inherit scale from parent Bone"); - uiDefButBitI(block, TOGN, BONE_NO_DEFORM, B_ARM_RECALCDATA, "Deform", 90, by-38, 80, 18, &curBone->flag, 0.0, 0.0, 0.0, 0.0, "Indicate if Bone deforms geometry"); - uiDefButBitI(block, TOG, BONE_MULT_VG_ENV, B_ARM_RECALCDATA, "Mult", 170,by-38,80,18, &curBone->flag, 1.0, 32.0, 0.0, 0.0, "Multiply Bone Envelope with VertexGroup"); - uiDefButBitI(block, TOG, BONE_HIDDEN_A, REDRAWVIEW3D, "Hide", 250,by-38,80,18, &curBone->flag, 0, 0, 0, 0, "Toggles display of this bone in Edit Mode"); + uiDefButBitI(block, TOG, BONE_HINGE, B_ARM_RECALCDATA, "Hinge", -10,by-38,60,18, &curBone->flag, 1.0, 32.0, 0.0, 0.0, "Don't inherit rotation or scale from parent Bone"); + uiDefButBitI(block, TOG, BONE_NO_SCALE, B_ARM_RECALCDATA, "S", 50,by-38,20,18, &curBone->flag, 1.0, 32.0, 0.0, 0.0, "Don't inherit scale from parent Bone"); + uiDefButBitI(block, TOGN, BONE_NO_DEFORM, B_ARM_RECALCDATA, "Deform", 70, by-38, 80, 18, &curBone->flag, 0.0, 0.0, 0.0, 0.0, "Indicate if Bone deforms geometry"); + uiDefButBitI(block, TOG, BONE_MULT_VG_ENV, B_ARM_RECALCDATA, "Mult", 150,by-38,60,18, &curBone->flag, 1.0, 32.0, 0.0, 0.0, "Multiply Bone Envelope with VertexGroup"); + uiDefButBitI(block, TOG, BONE_HIDDEN_A, REDRAWVIEW3D, "Hide", 210,by-38,60,18, &curBone->flag, 0, 0, 0, 0, "Toggles display of this bone in Edit Mode"); + uiDefButBitI(block, TOG, BONE_EDITMODE_LOCKED, REDRAWVIEW3D, "Lock", 270,by-38,60,18, &curBone->flag, 0, 0, 0, 0, "Prevents this bone from being transformed in Edit Mode"); /* layers */ uiBlockBeginAlign(block); @@ -6263,6 +6264,7 @@ static void editing_panel_mesh_texface(void) uiDefButBitS(block, TOG, TF_BILLBOARD2, B_TFACE_BILLB, "Billboard",660,110,60,19, &tf->mode, 0, 0, 0, 0, "Billboard with Z-axis constraint"); uiDefButBitS(block, TOG, TF_SHADOW, REDRAWVIEW3D, "Shadow", 720,110,60,19, &tf->mode, 0, 0, 0, 0, "Face is used for shadow"); uiDefButBitS(block, TOG, TF_BMFONT, REDRAWVIEW3D, "Text", 780,110,60,19, &tf->mode, 0, 0, 0, 0, "Enable bitmap text on face"); + uiDefButBitS(block, TOG, TF_ALPHASORT, REDRAWVIEW3D, "Sort", 840,110,60,19, &tf->mode, 0, 0, 0, 0, "Enable sorting of faces for correct alpha drawing (slow, use Clip Alpha instead when possible)"); uiBlockBeginAlign(block); uiBlockSetCol(block, TH_BUT_SETTING1); diff --git a/source/blender/src/buttons_logic.c b/source/blender/src/buttons_logic.c index 441d00ffc30..5cf1958678e 100644 --- a/source/blender/src/buttons_logic.c +++ b/source/blender/src/buttons_logic.c @@ -1654,53 +1654,66 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh wval = (width-100)/3; if (oa->type == ACT_OBJECT_NORMAL) { - ysize= 175; - + if ( ob->gameflag & OB_DYNAMIC ) + { + ysize= 175; + } + else + { + ysize= 72; + } + glRects(xco, yco-ysize, xco+width, yco); uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1); - uiDefBut(block, LABEL, 0, "Force", xco, yco-45, 55, 19, NULL, 0, 0, 0, 0, "Sets the force"); - uiDefButF(block, NUM, 0, "", xco+45, yco-45, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+wval, yco-45, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-45, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, ""); - - uiDefBut(block, LABEL, 0, "Torque", xco, yco-64, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque"); - uiDefButF(block, NUM, 0, "", xco+45, yco-64, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+wval, yco-64, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-64, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, ""); + uiDefBut(block, LABEL, 0, "Loc", xco, yco-45, 45, 19, NULL, 0, 0, 0, 0, "Sets the location"); + uiDefButF(block, NUM, 0, "", xco+45, yco-45, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+wval, yco-45, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-45, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, ""); - uiDefBut(block, LABEL, 0, "dLoc", xco, yco-87, 45, 19, NULL, 0, 0, 0, 0, "Sets the dLoc"); - uiDefButF(block, NUM, 0, "", xco+45, yco-87, wval, 19, oa->dloc, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+wval, yco-87, wval, 19, oa->dloc+1, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-87, wval, 19, oa->dloc+2, -10000.0, 10000.0, 10, 0, ""); - - uiDefBut(block, LABEL, 0, "dRot", xco, yco-106, 45, 19, NULL, 0, 0, 0, 0, "Sets the dRot"); - uiDefButF(block, NUM, 0, "", xco+45, yco-106, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+wval, yco-106, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-106, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, ""); + uiDefBut(block, LABEL, 0, "Rot", xco, yco-64, 45, 19, NULL, 0, 0, 0, 0, "Sets the rotation"); + uiDefButF(block, NUM, 0, "", xco+45, yco-64, wval, 19, oa->drot, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+wval, yco-64, wval, 19, oa->drot+1, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-64, wval, 19, oa->drot+2, -10000.0, 10000.0, 10, 0, ""); + + uiDefButBitS(block, TOG, ACT_DLOC_LOCAL, 0, "L", xco+45+3*wval, yco-45, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); + uiDefButBitS(block, TOG, ACT_DROT_LOCAL, 0, "L", xco+45+3*wval, yco-64, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); + + if ( ob->gameflag & OB_DYNAMIC ) + { + uiDefBut(block, LABEL, 0, "Force", xco, yco-87, 55, 19, NULL, 0, 0, 0, 0, "Sets the force"); + uiDefButF(block, NUM, 0, "", xco+45, yco-87, wval, 19, oa->forceloc, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+wval, yco-87, wval, 19, oa->forceloc+1, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-87, wval, 19, oa->forceloc+2, -10000.0, 10000.0, 10, 0, ""); - uiDefBut(block, LABEL, 0, "linV", xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity"); - uiDefButF(block, NUM, 0, "", xco+45, yco-129, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+wval, yco-129, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-129, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, ""); + uiDefBut(block, LABEL, 0, "Torque", xco, yco-106, 55, 19, NULL, 0, 0, 0, 0, "Sets the torque"); + uiDefButF(block, NUM, 0, "", xco+45, yco-106, wval, 19, oa->forcerot, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+wval, yco-106, wval, 19, oa->forcerot+1, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-6106, wval, 19, oa->forcerot+2, -10000.0, 10000.0, 10, 0, ""); + } - uiDefBut(block, LABEL, 0, "angV", xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity"); - uiDefButF(block, NUM, 0, "", xco+45, yco-148, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+wval, yco-148, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, ""); - uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-148, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, ""); + if ( ob->gameflag & OB_DYNAMIC ) + { + uiDefBut(block, LABEL, 0, "LinV", xco, yco-129, 45, 19, NULL, 0, 0, 0, 0, "Sets the linear velocity"); + uiDefButF(block, NUM, 0, "", xco+45, yco-129, wval, 19, oa->linearvelocity, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+wval, yco-129, wval, 19, oa->linearvelocity+1, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-129, wval, 19, oa->linearvelocity+2, -10000.0, 10000.0, 10, 0, ""); - uiDefBut(block, LABEL, 0, "damp", xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Number of frames to reach the target velocity"); - uiDefButS(block, NUM, 0, "", xco+45, yco-171, wval, 19, &oa->damping, 0.0, 1000.0, 100, 0, ""); - - uiDefButBitS(block, TOG, ACT_FORCE_LOCAL, 0, "L", xco+45+3*wval, yco-45, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); - uiDefButBitS(block, TOG, ACT_TORQUE_LOCAL, 0, "L", xco+45+3*wval, yco-64, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); - uiDefButBitS(block, TOG, ACT_DLOC_LOCAL, 0, "L", xco+45+3*wval, yco-87, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); - uiDefButBitS(block, TOG, ACT_DROT_LOCAL, 0, "L", xco+45+3*wval, yco-106, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); - uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L", xco+45+3*wval, yco-129, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); - uiDefButBitS(block, TOG, ACT_ANG_VEL_LOCAL, 0, "L", xco+45+3*wval, yco-148, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); + uiDefBut(block, LABEL, 0, "AngV", xco, yco-148, 45, 19, NULL, 0, 0, 0, 0, "Sets the angular velocity"); + uiDefButF(block, NUM, 0, "", xco+45, yco-148, wval, 19, oa->angularvelocity, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+wval, yco-148, wval, 19, oa->angularvelocity+1, -10000.0, 10000.0, 10, 0, ""); + uiDefButF(block, NUM, 0, "", xco+45+2*wval, yco-148, wval, 19, oa->angularvelocity+2, -10000.0, 10000.0, 10, 0, ""); - uiDefButBitS(block, TOG, ACT_ADD_LIN_VEL, 0, "add",xco+45+3*wval+15, yco-129, 35, 19, &oa->flag, 0.0, 0.0, 0, 0, "Toggles between ADD and SET linV"); + uiDefBut(block, LABEL, 0, "Damp", xco, yco-171, 45, 19, NULL, 0, 0, 0, 0, "Number of frames to reach the target velocity"); + uiDefButS(block, NUM, 0, "", xco+45, yco-171, wval, 19, &oa->damping, 0.0, 1000.0, 100, 0, ""); + + uiDefButBitS(block, TOG, ACT_FORCE_LOCAL, 0, "L", xco+45+3*wval, yco-87, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); + uiDefButBitS(block, TOG, ACT_TORQUE_LOCAL, 0, "L", xco+45+3*wval, yco-106, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); + uiDefButBitS(block, TOG, ACT_LIN_VEL_LOCAL, 0, "L", xco+45+3*wval, yco-129, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); + uiDefButBitS(block, TOG, ACT_ANG_VEL_LOCAL, 0, "L", xco+45+3*wval, yco-148, 15, 19, &oa->flag, 0.0, 0.0, 0, 0, "Local transformation"); + uiDefButBitS(block, TOG, ACT_ADD_LIN_VEL, 0, "add",xco+45+3*wval+15, yco-129, 35, 19, &oa->flag, 0.0, 0.0, 0, 0, "Toggles between ADD and SET linV"); + } } else if (oa->type == ACT_OBJECT_SERVO) { ysize= 172; @@ -2062,7 +2075,7 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh coa->time = 0; uiDefButS(block, MENU, 1, str, xco+10, yco-65, 70, 19, &coa->flag, 0.0, 0.0, 0, 0, ""); - uiDefButS(block, NUM, 0, "Damp:", xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, ""); + uiDefButS(block, NUM, 0, "damp", xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter"); uiDefBut(block, LABEL, 0, "Min", xco+80, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, ""); uiDefBut(block, LABEL, 0, "Max", xco+80+(width-90)/2, yco-45, (width-90)/2, 19, NULL, 0.0, 0.0, 0, 0, ""); @@ -2084,12 +2097,12 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4|-X axis %x8|-Y axis %x16|-Z axis %x32"; uiDefButS(block, MENU, B_REDR, str, xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Set the direction of the ray"); - uiDefButS(block, NUM, 0, "Damp:", xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, ""); + uiDefButS(block, NUM, 0, "damp", xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter"); uiDefBut(block, LABEL, 0, "Range", xco+80, yco-45, (width-115)/2, 19, NULL, 0.0, 0.0, 0, 0, "Set the maximum length of ray"); uiDefButBitS(block, TOG, ACT_CONST_DISTANCE, B_REDR, "Dist", xco+80+(width-115)/2, yco-45, (width-115)/2, 19, &coa->flag, 0.0, 0.0, 0, 0, "Force distance of object to point of impact of ray"); - if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRMX)) fp= coa->minloc; - else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRMY)) fp= coa->minloc+1; + if(coa->mode & (ACT_CONST_DIRPX|ACT_CONST_DIRNX)) fp= coa->minloc; + else if(coa->mode & (ACT_CONST_DIRPY|ACT_CONST_DIRNY)) fp= coa->minloc+1; else fp= coa->minloc+2; uiDefButF(block, NUM, 0, "", xco+80, yco-65, (width-115)/2, 19, fp+3, 0.0, 2000.0, 10, 0, "Maximum length of ray"); @@ -2124,7 +2137,7 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh str= "Direction %t|None %x0|X axis %x1|Y axis %x2|Z axis %x4"; uiDefButS(block, MENU, B_REDR, str, xco+10, yco-65, 70, 19, &coa->mode, 0.0, 0.0, 0, 0, "Select the axis to be aligned along the reference direction"); - uiDefButS(block, NUM, 0, "Damp:", xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, ""); + uiDefButS(block, NUM, 0, "damp", xco+10, yco-45, 70, 19, &coa->damp, 0.0, 100.0, 0, 0, "Damping factor: time constant (in frame) of low pass filter"); uiDefBut(block, LABEL, 0, "X", xco+80, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, ""); uiDefBut(block, LABEL, 0, "Y", xco+80+(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, ""); uiDefBut(block, LABEL, 0, "Z", xco+80+2*(width-115)/3, yco-45, (width-115)/3, 19, NULL, 0.0, 0.0, 0, 0, ""); @@ -2133,7 +2146,9 @@ static short draw_actuatorbuttons(Object *ob, bActuator *act, uiBlock *block, sh uiDefButF(block, NUM, 0, "", xco+80+(width-115)/3, yco-65, (width-115)/3, 19, &coa->maxrot[1], -2000.0, 2000.0, 10, 0, "Y component of reference direction"); uiDefButF(block, NUM, 0, "", xco+80+2*(width-115)/3, yco-65, (width-115)/3, 19, &coa->maxrot[2], -2000.0, 2000.0, 10, 0, "Z component of reference direction"); - uiDefButS(block, NUM, 0, "time", xco+10, yco-84, 70+(width-115)/3, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited"); + uiDefButS(block, NUM, 0, "time", xco+10, yco-84, 70, 19, &(coa->time), 0.0, 1000.0, 0, 0, "Maximum activation time in frame, 0 for unlimited"); + uiDefButF(block, NUM, 0, "min", xco+80, yco-84, (width-115)/2, 19, &(coa->minloc[0]), 0.0, 180.0, 10, 1, "Minimum angle (in degree) to maintain with target direction. No correction is done if angle with target direction is between min and max"); + uiDefButF(block, NUM, 0, "max", xco+80+(width-115)/2, yco-84, (width-115)/2, 19, &(coa->maxloc[0]), 0.0, 180.0, 10, 1, "Maximum angle (in degree) allowed with target direction. No correction is done if angle with target direction is between min and max"); } str= "Constraint Type %t|Location %x0|Distance %x1|Orientation %x2"; but = uiDefButS(block, MENU, B_REDR, str, xco+40, yco-23, (width-80), 19, &coa->type, 0.0, 0.0, 0, 0, ""); diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c index ebe770c89e7..2c7802c3302 100644 --- a/source/blender/src/buttons_object.c +++ b/source/blender/src/buttons_object.c @@ -480,7 +480,7 @@ static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short /* Target-Space */ if (target == 1) { - uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x3|Local with Parent %x4|Local Space %x1", + uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Target Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1", tarx, yco, bwidth, 18, &con->tarspace, 0, 0, 0, 0, "Choose space that target is evaluated in"); } else if (target == 0) { @@ -490,7 +490,7 @@ static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short /* Owner-Space */ if (owner == 1) { - uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Pose Space %x3|Local with Parent %x4|Local Space %x1", + uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Owner Space %t|World Space %x0|Pose Space %x2|Local with Parent %x3|Local Space %x1", ownx, yco, bwidth, 18, &con->ownspace, 0, 0, 0, 0, "Choose space that owner is evaluated in"); } else if (owner == 0) { diff --git a/source/blender/src/buttons_scene.c b/source/blender/src/buttons_scene.c index af90d01fb59..fb6a7636e16 100644 --- a/source/blender/src/buttons_scene.c +++ b/source/blender/src/buttons_scene.c @@ -137,36 +137,42 @@ static void load_new_sample(char *str) /* called from fileselect */ bSample *sample, *newsample; sound = G.buts->lockpoin; + + /* No Sound or Selected the same sample as we alredy have, just ignore */ + if (sound==NULL || str==sound->name) + return; + + if (sizeof(sound->sample->name) < strlen(str)) { + error("Path too long: %s", str); + return; + } + + // save values + sample = sound->sample; + strcpy(name, sound->sample->name); + strcpy(sound->name, str); + sound_set_sample(sound, NULL); + sound_initialize_sample(sound); - if (sound) { - // save values - sample = sound->sample; - strcpy(name, sound->sample->name); - - strcpy(sound->name, str); - sound_set_sample(sound, NULL); - sound_initialize_sample(sound); - - if (sound->sample->type == SAMPLE_INVALID) { - error("Not a valid sample: %s", str); + if (sound->sample->type == SAMPLE_INVALID) { + error("Not a valid sample: %s", str); - newsample = sound->sample; + newsample = sound->sample; - // restore values - strcpy(sound->name, name); - sound_set_sample(sound, sample); + // restore values + strcpy(sound->name, name); + sound_set_sample(sound, sample); - // remove invalid sample + // remove invalid sample - sound_free_sample(newsample); - BLI_remlink(samples, newsample); - MEM_freeN(newsample); - } + sound_free_sample(newsample); + BLI_remlink(samples, newsample); + MEM_freeN(newsample); + return; } - + BIF_undo_push("Load new audio file"); allqueue(REDRAWBUTSSCENE, 0); - } @@ -403,7 +409,7 @@ static void sound_panel_sound(bSound *sound) sample = sound->sample; /* info string */ - if (sound->sample && sound->sample->len) { + if (sound->sample && sound->sample->len && sound->sample->channels && sound->sample->bits) { char *tmp; if (sound->sample->channels == 1) tmp= "Mono"; else if (sound->sample->channels == 2) tmp= "Stereo"; @@ -757,7 +763,16 @@ static void seq_panel_input() } if (last_seq->type == SEQ_IMAGE) { - StripElem * se = give_stripelem(last_seq, CFRA); + int cfra = CFRA; + StripElem * se; + + if(last_seq->startdisp >cfra) { + cfra = last_seq->startdisp; + } else if (last_seq->enddisp <= cfra) { + cfra = last_seq->enddisp - 1; + } + + se = give_stripelem(last_seq, cfra); if (se) { uiDefBut(block, TEX, @@ -1174,18 +1189,18 @@ static void seq_panel_proxy() 130,140,120,19, &last_seq->flag, 0.0, 21.0, 100, 0, "Use a custom directory to store data"); - } - if (last_seq->flag & SEQ_USE_PROXY_CUSTOM_DIR) { - uiDefIconBut(block, BUT, B_SEQ_SEL_PROXY_DIR, - ICON_FILESEL, 10, 120, 20, 20, 0, 0, 0, 0, 0, - "Select the directory/name for " - "the proxy storage"); + if (last_seq->flag & SEQ_USE_PROXY_CUSTOM_DIR) { + uiDefIconBut(block, BUT, B_SEQ_SEL_PROXY_DIR, + ICON_FILESEL, 10, 120, 20, 20, 0, 0, 0, 0, 0, + "Select the directory/name for " + "the proxy storage"); - uiDefBut(block, TEX, - B_SEQ_BUT_RELOAD, "Dir: ", - 30,120,220,20, last_seq->strip->proxy->dir, - 0.0, 160.0, 100, 0, ""); + uiDefBut(block, TEX, + B_SEQ_BUT_RELOAD, "Dir: ", + 30,120,220,20, last_seq->strip->proxy->dir, + 0.0, 160.0, 100, 0, ""); + } } if (last_seq->flag & SEQ_USE_PROXY) { diff --git a/source/blender/src/drawaction.c b/source/blender/src/drawaction.c index 6fe37c1c6e5..0782ccfc7ee 100644 --- a/source/blender/src/drawaction.c +++ b/source/blender/src/drawaction.c @@ -58,6 +58,7 @@ #include "DNA_constraint_types.h" #include "DNA_key_types.h" #include "DNA_userdef_types.h" +#include "DNA_gpencil_types.h" #include "BKE_action.h" #include "BKE_depsgraph.h" @@ -74,6 +75,7 @@ #include "BIF_editnla.h" #include "BIF_interface.h" #include "BIF_interface_icons.h" +#include "BIF_drawgpencil.h" #include "BIF_gl.h" #include "BIF_glutil.h" #include "BIF_resources.h" @@ -83,9 +85,11 @@ #include "BDR_drawaction.h" #include "BDR_editcurve.h" +#include "BDR_gpencil.h" #include "BSE_drawnla.h" #include "BSE_drawipo.h" +#include "BSE_drawview.h" #include "BSE_editaction_types.h" #include "BSE_editipo.h" #include "BSE_time.h" @@ -464,7 +468,7 @@ static void draw_channel_names(void) bActionGroup *grp = NULL; short indent= 0, offset= 0, sel= 0, group=0; int expand= -1, protect = -1, special= -1, mute = -1; - char name[32]; + char name[64]; /* determine what needs to be drawn */ switch (ale->type) { @@ -622,12 +626,112 @@ static void draw_channel_names(void) sprintf(name, "Constraint"); } break; + case ACTTYPE_GPDATABLOCK: /* gpencil datablock */ + { + bGPdata *gpd = (bGPdata *)ale->data; + ScrArea *sa = (ScrArea *)ale->owner; + + indent = 0; + group= 3; + + /* only show expand if there are any channels */ + if (gpd->layers.first) { + if (gpd->flag & GP_DATA_EXPAND) + expand = ICON_TRIA_DOWN; + else + expand = ICON_TRIA_RIGHT; + } + + switch (sa->spacetype) { + case SPACE_VIEW3D: + { + /* this shouldn't cause any overflow... */ + sprintf(name, "3DView: %s", view3d_get_name(sa->spacedata.first)); + special= ICON_VIEW3D; + } + break; + case SPACE_NODE: + { + SpaceNode *snode= sa->spacedata.first; + char treetype[12]; + + if (snode->treetype == 1) + sprintf(treetype, "Composite"); + else + sprintf(treetype, "Material"); + sprintf(name, "Nodes: %s", treetype); + + special= ICON_NODE; + } + break; + case SPACE_SEQ: + { + SpaceSeq *sseq= sa->spacedata.first; + char imgpreview[10]; + + switch (sseq->mainb) { + case 1: sprintf(imgpreview, "Image..."); break; + case 2: sprintf(imgpreview, "Luma..."); break; + case 3: sprintf(imgpreview, "Chroma..."); break; + case 4: sprintf(imgpreview, "Histogram"); break; + + default: sprintf(imgpreview, "Sequence"); break; + } + sprintf(name, "Sequencer: %s", imgpreview); + + special= ICON_SEQUENCE; + } + break; + + default: + { + sprintf(name, "<Unknown GP-Data Source>"); + special= -1; + } + break; + } + } + break; + case ACTTYPE_GPLAYER: /* gpencil layer */ + { + bGPDlayer *gpl = (bGPDlayer *)ale->data; + + indent = 0; + special = -1; + expand = -1; + group = 1; + + if (EDITABLE_GPL(gpl)) + protect = ICON_UNLOCKED; + else + protect = ICON_LOCKED; + + if (gpl->flag & GP_LAYER_HIDE) + mute = ICON_MUTE_IPO_ON; + else + mute = ICON_MUTE_IPO_OFF; + + sel = SEL_GPL(gpl); + BLI_snprintf(name, 32, gpl->info); + } + break; } /* now, start drawing based on this information */ /* draw backing strip behind channel name */ - if (group == 2) { - /* only for group-channels */ + if (group == 3) { + /* only for gp-data channels */ + if (ale->owner == curarea) // fixme... currently useless + BIF_ThemeColorShade(TH_GROUP_ACTIVE, 10); + else + BIF_ThemeColorShade(TH_GROUP, 20); + uiSetRoundBox((expand == ICON_TRIA_DOWN)? (1):(1|8)); + gl_round_box(GL_POLYGON, x, yminc, (float)NAMEWIDTH, ymaxc, 8); + + offset = 0; + } + else if (group == 2) { + /* only for action group channels */ if (ale->flag & AGRP_ACTIVE) BIF_ThemeColorShade(TH_GROUP_ACTIVE, 10); else @@ -673,13 +777,19 @@ static void draw_channel_names(void) offset += 17; } - /* draw special icon indicating type of ipo-blocktype? - * only for expand widgets for Ipo and Constraint Channels - */ - if (special > 0) { - offset = (group) ? 29 : 24; - BIF_icon_draw(x+offset, yminc, special); - offset += 17; + /* draw special icon indicating certain data-types */ + if (special > -1) { + if (group == 3) { + /* for gpdatablock channels */ + BIF_icon_draw(x+offset, yminc, special); + offset += 17; + } + else { + /* for ipo/constraint channels */ + offset = (group) ? 29 : 24; + BIF_icon_draw(x+offset, yminc, special); + offset += 17; + } } /* draw name */ @@ -695,13 +805,13 @@ static void draw_channel_names(void) offset = 0; /* draw protect 'lock' */ - if (protect > 0) { + if (protect > -1) { offset = 16; BIF_icon_draw(NAMEWIDTH-offset, yminc, protect); } /* draw mute 'eye' */ - if (mute > 0) { + if (mute > -1) { offset += 16; BIF_icon_draw(NAMEWIDTH-offset, yminc, mute); } @@ -827,6 +937,12 @@ static void draw_channel_strips(void) sel = SEL_ICU(icu); } break; + case ACTTYPE_GPLAYER: + { + bGPDlayer *gpl = (bGPDlayer *)ale->data; + sel = SEL_GPL(gpl); + } + break; } if (datatype == ACTCONT_ACTION) { @@ -865,6 +981,19 @@ static void draw_channel_strips(void) glColor4ub(col2[0], col2[1], col2[2], 0x44); glRectf(frame1_x, channel_y-CHANNELHEIGHT/2, G.v2d->hor.xmax, channel_y+CHANNELHEIGHT/2); } + else if (datatype == ACTCONT_GPENCIL) { + gla2DDrawTranslatePt(di, G.v2d->cur.xmin, y, &frame1_x, &channel_y); + + /* frames less than one get less saturated background */ + if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22); + else glColor4ub(col2[0], col2[1], col2[2], 0x22); + glRectf(0, channel_y-CHANNELHEIGHT/2, frame1_x, channel_y+CHANNELHEIGHT/2); + + /* frames one and higher get a saturated background */ + if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x44); + else glColor4ub(col2[0], col2[1], col2[2], 0x44); + glRectf(frame1_x, channel_y-CHANNELHEIGHT/2, G.v2d->hor.xmax, channel_y+CHANNELHEIGHT/2); + } } /* Increment the step */ @@ -899,6 +1028,9 @@ static void draw_channel_strips(void) case ALE_ICU: draw_icu_channel(di, ale->key_data, y); break; + case ALE_GPFRAME: + draw_gpl_channel(di, ale->data, y); + break; } } @@ -1075,6 +1207,7 @@ void drawactionspace(ScrArea *sa, void *spacedata) { bAction *act = NULL; Key *key = NULL; + bGPdata *gpd = NULL; void *data; short datatype; @@ -1090,18 +1223,32 @@ void drawactionspace(ScrArea *sa, void *spacedata) /* only try to refresh action that's displayed if not pinned */ if (G.saction->pin==0) { - if (OBACT) - G.saction->action = OBACT->action; - else - G.saction->action= NULL; + /* depends on mode */ + switch (G.saction->mode) { + case SACTCONT_ACTION: + { + if (OBACT) + G.saction->action = OBACT->action; + else + G.saction->action= NULL; + } + break; + } } /* get data */ data = get_action_context(&datatype); - if (datatype == ACTCONT_ACTION) - act = data; - else if (datatype == ACTCONT_SHAPEKEY) - key = data; + switch (datatype) { + case ACTCONT_ACTION: + act = data; + break; + case ACTCONT_SHAPEKEY: + key = data; + break; + case ACTCONT_GPENCIL: + gpd = data; + break; + } /* Lets make sure the width of the left hand of the screen * is set to an appropriate value based on whether sliders @@ -1450,10 +1597,15 @@ static ActKeysInc *init_aki_data() static ActKeysInc aki; /* init data of static struct here */ - if ((curarea->spacetype == SPACE_ACTION) && NLA_ACTION_SCALED) + if ((curarea->spacetype == SPACE_ACTION) && NLA_ACTION_SCALED && + (G.saction->mode == SACTCONT_ACTION)) + { aki.ob= OBACT; + } else if (curarea->spacetype == SPACE_NLA) + { aki.ob= NULL; // FIXME + } else aki.ob= NULL; @@ -1528,6 +1680,16 @@ void draw_action_channel(gla2DDrawInfo *di, bAction *act, float ypos) BLI_freelistN(&keys); } +void draw_gpl_channel(gla2DDrawInfo *di, bGPDlayer *gpl, float ypos) +{ + ListBase keys = {0, 0}; + ActKeysInc *aki = init_aki_data(); + + gpl_to_keylist(gpl, &keys, NULL, aki); + draw_keylist(di, &keys, NULL, ypos); + BLI_freelistN(&keys); +} + /* --------------- Conversion: data -> keyframe list ------------------ */ void ob_to_keylist(Object *ob, ListBase *keys, ListBase *blocks, ActKeysInc *aki) @@ -1674,3 +1836,26 @@ void action_to_keylist(bAction *act, ListBase *keys, ListBase *blocks, ActKeysIn } } +void gpl_to_keylist(bGPDlayer *gpl, ListBase *keys, ListBase *blocks, ActKeysInc *aki) +{ + bGPDframe *gpf; + ActKeyColumn *ak; + + if (gpl && keys) { + /* loop over frames, converting directly to 'keyframes' (should be in order too) */ + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + ak= MEM_callocN(sizeof(ActKeyColumn), "ActKeyColumn"); + BLI_addtail(keys, ak); + + ak->cfra= gpf->framenum; + ak->modified = 1; + ak->handle_type= 0; + + if (gpf->flag & GP_FRAME_SELECT) + ak->sel = SELECT; + else + ak->sel = 0; + } + } +} + diff --git a/source/blender/src/drawgpencil.c b/source/blender/src/drawgpencil.c new file mode 100644 index 00000000000..ee28049e2c0 --- /dev/null +++ b/source/blender/src/drawgpencil.c @@ -0,0 +1,856 @@ +/** + * $Id: drawgpencil.c 14881 2008-05-18 10:41:42Z aligorith $ + * + * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2008, Blender Foundation + * This is a new part of Blender + * + * Contributor(s): Joshua Leung + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stddef.h> +#include <math.h> + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "MEM_guardedalloc.h" + +#include "BMF_Api.h" + +#include "BLI_arithb.h" +#include "BLI_blenlib.h" + +#include "DNA_listBase.h" +#include "DNA_gpencil_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_space_types.h" +#include "DNA_userdef_types.h" +#include "DNA_view3d_types.h" + +#include "BKE_global.h" +#include "BKE_utildefines.h" +#include "BKE_blender.h" + +#include "BIF_gl.h" +#include "BIF_glutil.h" +#include "BIF_butspace.h" +#include "BIF_graphics.h" +#include "BIF_interface.h" +#include "BIF_mywindow.h" +#include "BIF_resources.h" +#include "BIF_space.h" +#include "BIF_screen.h" +#include "BIF_toolbox.h" +#include "BIF_toets.h" + +#include "BDR_gpencil.h" +#include "BIF_drawgpencil.h" + +#include "BSE_drawipo.h" +#include "BSE_headerbuttons.h" +#include "BSE_view.h" + +#include "blendef.h" +#include "butspace.h" + +#include "PIL_time.h" /* sleep */ +#include "mydevice.h" + +/* ************************************************** */ +/* GREASE PENCIL PANEL-UI DRAWING */ + +/* Every space which implements Grease-Pencil functionality should have a panel + * for the settings. All of the space-dependent parts should be coded in the panel + * code for that space, but the rest is all handled by generic panel here. + */ + +/* ------- Callbacks ----------- */ +/* These are just 'dummy wrappers' around gpencil api calls */ + +/* make layer active one after being clicked on */ +void gp_ui_activelayer_cb (void *gpd, void *gpl) +{ + gpencil_layer_setactive(gpd, gpl); + allqueue(REDRAWACTION, 0); +} + +/* rename layer and set active */ +void gp_ui_renamelayer_cb (void *gpd_arg, void *gpl_arg) +{ + bGPdata *gpd= (bGPdata *)gpd_arg; + bGPDlayer *gpl= (bGPDlayer *)gpl_arg; + + BLI_uniquename(&gpd->layers, gpl, "GP_Layer", offsetof(bGPDlayer, info[0]), 128); + gpencil_layer_setactive(gpd, gpl); + allqueue(REDRAWACTION, 0); +} + +/* add a new layer */ +void gp_ui_addlayer_cb (void *gpd, void *dummy) +{ + gpencil_layer_addnew(gpd); + allqueue(REDRAWACTION, 0); +} + +/* delete active layer */ +void gp_ui_dellayer_cb (void *gpd, void *dummy) +{ + gpencil_layer_delactive(gpd); + allqueue(REDRAWACTION, 0); +} + +/* delete last stroke of active layer */ +void gp_ui_delstroke_cb (void *gpd, void *gpl) +{ + bGPDframe *gpf= gpencil_layer_getframe(gpl, CFRA, 0); + + gpencil_layer_setactive(gpd, gpl); + gpencil_frame_delete_laststroke(gpf); +} + +/* delete active frame of active layer */ +void gp_ui_delframe_cb (void *gpd, void *gpl) +{ + bGPDframe *gpf= gpencil_layer_getframe(gpl, CFRA, 0); + + gpencil_layer_setactive(gpd, gpl); + gpencil_layer_delframe(gpl, gpf); + + allqueue(REDRAWACTION, 0); +} + +/* ------- Drawing Code ------- */ + +/* draw the controls for a given layer */ +static void gp_drawui_layer (uiBlock *block, bGPdata *gpd, bGPDlayer *gpl, short *xco, short *yco) +{ + uiBut *but; + short active= (gpl->flag & GP_LAYER_ACTIVE); + short width= 314; + short height; + int rb_col; + + /* unless button has own callback, it adds this callback to button */ + uiBlockSetFunc(block, gp_ui_activelayer_cb, gpd, gpl); + + /* draw header */ + { + uiBlockSetEmboss(block, UI_EMBOSSN); + + /* rounded header */ + if (active) uiBlockSetCol(block, TH_BUT_ACTION); + rb_col= (active)?-20:20; + uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-8, *yco-2, width, 24, NULL, 5.0, 0.0, 15 , rb_col-20, ""); + if (active) uiBlockSetCol(block, TH_AUTO); + + /* lock toggle */ + uiDefIconButBitI(block, ICONTOG, GP_LAYER_LOCKED, B_REDR, ICON_UNLOCKED, *xco-7, *yco-1, 20, 20, &gpl->flag, 0.0, 0.0, 0, 0, "Layer cannot be modified"); + } + + /* when layer is locked or hidden, only draw header */ + if (gpl->flag & (GP_LAYER_LOCKED|GP_LAYER_HIDE)) { + char name[256]; /* gpl->info is 128, but we need space for 'locked/hidden' as well */ + + height= 26; + + /* visibility button (only if hidden but not locked!) */ + if ((gpl->flag & GP_LAYER_HIDE) && !(gpl->flag & GP_LAYER_LOCKED)) + uiDefIconButBitI(block, ICONTOG, GP_LAYER_HIDE, B_REDR, ICON_RESTRICT_VIEW_OFF, *xco+12, *yco-1, 20, 20, &gpl->flag, 0.0, 0.0, 0, 0, "Visibility of layer"); + + /* name */ + if (gpl->flag & GP_LAYER_HIDE) + sprintf(name, "%s (Hidden)", gpl->info); + else + sprintf(name, "%s (Locked)", gpl->info); + uiDefBut(block, LABEL, 1, name, *xco+35, *yco, 240, 20, NULL, 0.0, 0.0, 0, 0, "Short description of what this layer is for (optional)"); + + /* delete button (only if hidden but not locked!) */ + if ((gpl->flag & GP_LAYER_HIDE) & !(gpl->flag & GP_LAYER_LOCKED)) { + but= uiDefIconBut(block, BUT, B_REDR, ICON_X, *xco+(width-30), *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete layer"); + uiButSetFunc(but, gp_ui_dellayer_cb, gpd, NULL); + } + uiBlockSetEmboss(block, UI_EMBOSS); + } + else { + height= 97; + + /* draw rest of header */ + { + /* visibility button */ + uiDefIconButBitI(block, ICONTOG, GP_LAYER_HIDE, B_REDR, ICON_RESTRICT_VIEW_OFF, *xco+12, *yco-1, 20, 20, &gpl->flag, 0.0, 0.0, 0, 0, "Visibility of layer"); + + uiBlockSetEmboss(block, UI_EMBOSS); + + /* name */ + but= uiDefButC(block, TEX, B_REDR, "Info:", *xco+36, *yco, 240, 19, gpl->info, 0, 127, 0, 0, "Short description of what this layer is for (optional)"); + uiButSetFunc(but, gp_ui_renamelayer_cb, gpd, gpl); + + /* delete 'button' */ + uiBlockSetEmboss(block, UI_EMBOSSN); + + but= uiDefIconBut(block, BUT, B_REDR, ICON_X, *xco+(width-30), *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Delete layer"); + uiButSetFunc(but, gp_ui_dellayer_cb, gpd, NULL); + + uiBlockSetEmboss(block, UI_EMBOSS); + } + + /* draw backdrop */ + if (active) uiBlockSetCol(block, TH_BUT_ACTION); + uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-8, *yco-height, width, height-1, NULL, 5.0, 0.0, 12, rb_col, ""); + if (active) uiBlockSetCol(block, TH_AUTO); + + /* draw settings */ + { + /* color */ + uiBlockBeginAlign(block); + uiDefButF(block, COL, B_REDR, "", *xco, *yco-26, 150, 19, gpl->color, 0, 0, 0, 0, "Color to use for all strokes on this Grease Pencil Layer"); + uiDefButF(block, NUMSLI, B_REDR, "Opacity: ", *xco,*yco-45,150,19, &gpl->color[3], 0.3, 1.0, 0, 0, "Visibility of stroke (0.3 to 1.0)"); + uiBlockEndAlign(block); + + /* stroke thickness */ + uiDefButS(block, NUMSLI, B_REDR, "Thickness:", *xco, *yco-75, 150, 20, &gpl->thickness, 1, 10, 0, 0, "Thickness of strokes (in pixels)"); + + /* debugging options */ + if (G.f & G_DEBUG) { + uiDefButBitI(block, TOG, GP_LAYER_DRAWDEBUG, B_REDR, "Show Points", *xco, *yco-95, 150, 20, &gpl->flag, 0, 0, 0, 0, "Show points which form the strokes"); + } + + /* onion-skinning */ + uiBlockBeginAlign(block); + uiDefButBitI(block, TOG, GP_LAYER_ONIONSKIN, B_REDR, "Onion-Skin", *xco+160, *yco-26, 140, 20, &gpl->flag, 0, 0, 0, 0, "Ghost frames on either side of frame"); + uiDefButS(block, NUMSLI, B_REDR, "GStep:", *xco+160, *yco-46, 140, 20, &gpl->gstep, 0, 120, 0, 0, "Max number of frames on either side of active frame to show (0 = just 'first' available sketch on either side)"); + uiBlockEndAlign(block); + + /* options */ + uiBlockBeginAlign(block); + but= uiDefBut(block, BUT, B_REDR, "Del Active Frame", *xco+160, *yco-75, 140, 20, NULL, 0, 0, 0, 0, "Erases the the active frame for this layer (Hotkey = Alt-XKEY/DEL)"); + uiButSetFunc(but, gp_ui_delframe_cb, gpd, gpl); + + but= uiDefBut(block, BUT, B_REDR, "Del Last Stroke", *xco+160, *yco-95, 140, 20, NULL, 0, 0, 0, 0, "Erases the last stroke from the active frame (Hotkey = Alt-XKEY/DEL)"); + uiButSetFunc(but, gp_ui_delstroke_cb, gpd, gpl); + uiBlockEndAlign(block); + } + } + + /* adjust height for new to start */ + (*yco) -= (height + 27); +} + +/* Draw the contents for a grease-pencil panel. This assumes several things: + * - that panel has been created, is 318 x 204. max yco is 225 + * - that a toggle for turning on/off gpencil drawing is 150 x 20, starting from (10,225) + * which is basically the top left-hand corner + * It will return the amount of extra space to extend the panel by + */ +short draw_gpencil_panel (uiBlock *block, bGPdata *gpd, ScrArea *sa) +{ + uiBut *but; + bGPDlayer *gpl; + short xco= 10, yco= 170; + + /* draw gpd settings first */ + { + /* add new layer buttons */ + but= uiDefBut(block, BUT, B_REDR, "Add New Layer", 10,205,150,20, 0, 0, 0, 0, 0, "Adds a new Grease Pencil Layer"); + uiButSetFunc(but, gp_ui_addlayer_cb, gpd, NULL); + + + /* show override lmb-clicks button + painting lock */ + uiBlockBeginAlign(block); + if ((gpd->flag & GP_DATA_EDITPAINT)==0) { + uiDefButBitI(block, TOG, GP_DATA_EDITPAINT, B_REDR, "Draw Mode", 170, 225, 130, 20, &gpd->flag, 0, 0, 0, 0, "Interpret click-drag as new strokes"); + + uiBlockSetCol(block, TH_BUT_SETTING); + uiDefIconButBitI(block, ICONTOG, GP_DATA_LMBPLOCK, B_REDR, ICON_UNLOCKED, 300, 225, 20, 20, &gpd->flag, 0.0, 0.0, 0, 0, "Painting cannot occur with Shift-LMB (when making selections)"); + uiBlockSetCol(block, TH_AUTO); + } + else + uiDefButBitI(block, TOG, GP_DATA_EDITPAINT, B_REDR, "Draw Mode", 170, 225, 150, 20, &gpd->flag, 0, 0, 0, 0, "Interpret click-drag as new strokes"); + uiBlockEndAlign(block); + + /* 'view align' button (naming depends on context) */ + if (sa->spacetype == SPACE_VIEW3D) + uiDefButBitI(block, TOG, GP_DATA_VIEWALIGN, B_REDR, "Sketch in 3D", 170, 205, 150, 20, &gpd->flag, 0, 0, 0, 0, "New strokes are added in 3D-space"); + else if (sa->spacetype != SPACE_SEQ) /* not available for sequencer yet */ + uiDefButBitI(block, TOG, GP_DATA_VIEWALIGN, B_REDR, "Stick to View", 170, 205, 150, 20, &gpd->flag, 0, 0, 0, 0, "New strokes are added on 2d-canvas"); + } + + /* draw for each layer */ + for (gpl= gpd->layers.first; gpl; gpl= gpl->next) { + gp_drawui_layer(block, gpd, gpl, &xco, &yco); + } + + /* return new height if necessary */ + return (yco < 0) ? (204 - yco) : 204; +} + +/* ************************************************** */ +/* GREASE PENCIL DRAWING */ + +/* ----- General Defines ------ */ + +/* flags for sflag */ +enum { + GP_DRAWDATA_NOSTATUS = (1<<0), /* don't draw status info */ + GP_DRAWDATA_ONLY3D = (1<<1), /* only draw 3d-strokes */ + GP_DRAWDATA_ONLYV2D = (1<<2), /* only draw 'canvas' strokes */ +}; + +/* ----- Tool Buffer Drawing ------ */ + +/* draw stroke defined in buffer (simple ogl lines/points for now, as dotted lines) */ +static void gp_draw_stroke_buffer (tGPspoint *points, int totpoints, short thickness, short dflag, short sflag) +{ + tGPspoint *pt; + int i; + + /* error checking */ + if ((points == NULL) || (totpoints <= 0)) + return; + + /* check if buffer can be drawn */ + if (dflag & (GP_DRAWDATA_ONLY3D|GP_DRAWDATA_ONLYV2D)) + return; + + /* if drawing a single point, draw it larger */ + if (totpoints == 1) { + /* draw point */ + glBegin(GL_POINTS); + glVertex2f(points->x, points->y); + glEnd(); + } + else if (sflag & GP_STROKE_ERASER) { + /* draw stroke curve - just standard thickness */ + setlinestyle(4); + glLineWidth(1.0f); + + glBegin(GL_LINE_STRIP); + for (i=0, pt=points; i < totpoints && pt; i++, pt++) { + glVertex2f(pt->x, pt->y); + } + glEnd(); + + setlinestyle(0); + } + else { + float oldpressure = 0.0f; + + /* draw stroke curve */ + setlinestyle(2); + + glBegin(GL_LINE_STRIP); + for (i=0, pt=points; i < totpoints && pt; i++, pt++) { + if (fabs(pt->pressure - oldpressure) > 0.2f) { + glEnd(); + glLineWidth(pt->pressure * thickness); + glBegin(GL_LINE_STRIP); + + glVertex2f(pt->x, pt->y); + + oldpressure = pt->pressure; + } + else + glVertex2f(pt->x, pt->y); + } + glEnd(); + + setlinestyle(0); + } +} + +/* ----- Existing Strokes Drawing (3D and Point) ------ */ + +/* draw a given stroke - just a single dot (only one point) */ +static void gp_draw_stroke_point (bGPDspoint *points, short sflag, int winx, int winy) +{ + /* draw point */ + if (sflag & GP_STROKE_3DSPACE) { + glBegin(GL_POINTS); + glVertex3f(points->x, points->y, points->z); + glEnd(); + } + else if (sflag & GP_STROKE_2DSPACE) { + glBegin(GL_POINTS); + glVertex2f(points->x, points->y); + glEnd(); + } + else { + const float x= (points->x / 1000 * winx); + const float y= (points->y / 1000 * winy); + + glBegin(GL_POINTS); + glVertex2f(x, y); + glEnd(); + } +} + +/* draw a given stroke in 3d (i.e. in 3d-space), using simple ogl lines */ +static void gp_draw_stroke_3d (bGPDspoint *points, int totpoints, short thickness, short dflag, short sflag, short debug, int winx, int winy) +{ + bGPDspoint *pt; + float oldpressure = 0.0f; + int i; + + /* draw stroke curve */ + glBegin(GL_LINE_STRIP); + for (i=0, pt=points; i < totpoints && pt; i++, pt++) { + if (fabs(pt->pressure - oldpressure) > 0.2f) { + glEnd(); + glLineWidth(pt->pressure * thickness); + glBegin(GL_LINE_STRIP); + + glVertex3f(pt->x, pt->y, pt->z); + + oldpressure = pt->pressure; + } + else + glVertex3f(pt->x, pt->y, pt->z); + } + glEnd(); + + /* draw debug points of curve on top? */ + if (debug) { + glBegin(GL_POINTS); + for (i=0, pt=points; i < totpoints && pt; i++, pt++) + glVertex3f(pt->x, pt->y, pt->z); + glEnd(); + } +} + +/* ----- Fancy 2D-Stroke Drawing ------ */ + +/* draw a given stroke in 2d */ +static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness, short dflag, short sflag, short debug, int winx, int winy) +{ + /* if thickness is less than 3, 'smooth' opengl lines look better */ + if ((thickness < 3) || (G.rt==0)) { + bGPDspoint *pt; + int i; + + glBegin(GL_LINE_STRIP); + for (i=0, pt=points; i < totpoints && pt; i++, pt++) { + if (sflag & GP_STROKE_2DSPACE) { + glVertex2f(pt->x, pt->y); + } + else { + const float x= (pt->x / 1000 * winx); + const float y= (pt->y / 1000 * winy); + + glVertex2f(x, y); + } + } + glEnd(); + } + else { /* tesselation code: currently only enabled with rt != 0 */ + bGPDspoint *pt1, *pt2; + float p0[2], p1[2], pm[2]; + int i; + + glShadeModel(GL_FLAT); + glBegin(GL_QUAD_STRIP); + + for (i=0, pt1=points, pt2=points+1; i < (totpoints-1); i++, pt1++, pt2++) { + float s0[2], s1[2]; /* segment 'center' points */ + float t0[2], t1[2]; /* tesselated coordinates */ + float m1[2], m2[2]; /* gradient and normal */ + float pthick, dist; /* thickness at segment point, and length of segment */ + float sminorang; /* minor angle between strokes */ + + /* get x and y coordinates from points */ + if (sflag & GP_STROKE_2DSPACE) { + s0[0]= pt1->x; s0[1]= pt1->y; + s1[0]= pt2->x; s1[1]= pt2->y; + } + else { + s0[0]= (pt1->x / 1000 * winx); + s0[1]= (pt1->y / 1000 * winy); + s1[0]= (pt2->x / 1000 * winx); + s1[1]= (pt2->y / 1000 * winy); + } + + /* calculate gradient and normal - 'angle'=(ny/nx) */ + m1[1]= s1[1] - s0[1]; + m1[0]= s1[0] - s0[0]; + dist = Vec2Lenf(s0, s1); + m2[1]= -(m1[0]) / dist; + m2[0]= m1[1] / dist; + + /* if the first segment, initialise the first segment using segment's normal */ + if (i == 0) { + pthick= (pt1->pressure * thickness); + + // TODO: also draw/do a round end-cap first + + p0[0]= s0[0] - (pthick * m2[0]); + p0[1]= s0[1] - (pthick * m2[1]); + p1[0]= s1[0] + (pthick * m2[0]); + p1[1]= s1[1] + (pthick * m2[1]); + + Vec2Copyf(pm, m1); + } + + /* if the minor angle between the current segment and the previous one is less than 90 degrees */ + if (i) + sminorang= NormalizedVecAngle2_2D(pm, m1); + else + sminorang= 0.0f; + + if ((IS_EQ(sminorang, 0)==0) && (abs(sminorang) < M_PI_2) ) + { + float closep[2]; + + /* recalculate startpoint of segment, where the new start-line: + * - starts a new gl-quad-strip + * - uses the vert of old startpoint closer to our endpoint + * - distance between new startpoints = distance between old startpoints + * - new startpoints occur on same gradient as old segment does (has potential for some 'minor' overlap, but ok) + */ + + /* find the closer vertex, and distance between startpoints */ + if (Vec2Lenf(p0, s1) > Vec2Lenf(p1, s1)) + Vec2Copyf(closep, p1); + else + Vec2Copyf(closep, p0); + + /* determine which side this closer vertex should be on */ + pthick= (pt1->pressure * thickness * 2); + if ( ((closep[0] - s0[0]) > 0) || ((closep[1] - s0[1]) > 0) ) { + /* assumes this is the 'second' point, (i.e. the 'plus' one), so the other is subtracting */ + p0[0]= closep[0] - (pthick * pm[0]); + p0[1]= closep[1] - (pthick * pm[1]); + p1[0]= closep[0]; + p1[1]= closep[1]; + } + else if ( ((closep[0] - s0[0]) < 0) || ((closep[1] - s0[1]) < 0) ) { + /* assumes this is the 'first' point, (i.e. the 'minus' one), so the other is adding */ + p0[0]= closep[0]; + p0[1]= closep[1]; + p1[0]= closep[0] + (pthick * pm[0]); + p1[1]= closep[1] + (pthick * pm[1]); + } + + /* reset gl-states! */ + glEnd(); + glBegin(GL_QUAD_STRIP); + } + + /* do the end of this segment */ + pthick= (pt2->pressure * thickness); + t0[0] = s1[0] - (pthick * m2[0]); + t0[1] = s1[1] - (pthick * m2[1]); + t1[0] = s1[0] + (pthick * m2[0]); + t1[1] = s1[1] + (pthick * m2[1]); + + /* draw this segment */ + glVertex2f(p0[0], p0[1]); + glVertex2f(p1[0], p1[1]); + glVertex2f(t0[0], t0[1]); + glVertex2f(t1[0], t1[1]); + + // TODO: draw end cap if last segment + if (i == totpoints-2) { + + } + + /* store current points for next segment to use */ + Vec2Copyf(p0, t0); + Vec2Copyf(p1, t1); + Vec2Copyf(pm, m1); + } + + glEnd(); + } + + /* draw debug points of curve on top? (original stroke points) */ + if (debug) { + bGPDspoint *pt; + int i; + + glBegin(GL_POINTS); + for (i=0, pt=points; i < totpoints && pt; i++, pt++) { + if (sflag & GP_STROKE_2DSPACE) { + glVertex2f(pt->x, pt->y); + } + else { + const float x= (pt->x / 1000 * winx); + const float y= (pt->y / 1000 * winy); + + glVertex2f(x, y); + } + } + glEnd(); + } +} + +/* ----- General Drawing ------ */ + +/* draw a set of strokes */ +static void gp_draw_strokes (bGPDframe *gpf, int winx, int winy, int dflag, short debug, + short lthick, float color[4]) +{ + bGPDstroke *gps; + + /* set color first (may need to reset it again later too) */ + glColor4f(color[0], color[1], color[2], color[3]); + + for (gps= gpf->strokes.first; gps; gps= gps->next) { + /* check if stroke can be drawn */ + if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE)) + continue; + if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE)) + continue; + if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE)) + continue; + if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE)) + continue; + if ((gps->points == 0) || (gps->totpoints < 1)) + continue; + + /* check which stroke-drawer to use */ + if (gps->totpoints == 1) + gp_draw_stroke_point(gps->points, gps->flag, winx, winy); + else if (dflag & GP_DRAWDATA_ONLY3D) + gp_draw_stroke_3d(gps->points, gps->totpoints, lthick, dflag, gps->flag, debug, winx, winy); + else if (gps->totpoints > 1) + gp_draw_stroke(gps->points, gps->totpoints, lthick, dflag, gps->flag, debug, winx, winy); + } +} + +/* draw grease-pencil datablock */ +static void gp_draw_data (bGPdata *gpd, int winx, int winy, int dflag) +{ + bGPDlayer *gpl, *actlay=NULL; + + /* turn on smooth lines (i.e. anti-aliasing) */ + glEnable(GL_LINE_SMOOTH); + + /* turn on alpha-blending */ + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + + /* loop over layers, drawing them */ + for (gpl= gpd->layers.first; gpl; gpl= gpl->next) { + bGPDframe *gpf; + + short debug = (gpl->flag & GP_LAYER_DRAWDEBUG) ? 1 : 0; + short lthick= gpl->thickness; + float color[4], tcolor[4]; + + /* don't draw layer if hidden */ + if (gpl->flag & GP_LAYER_HIDE) + continue; + + /* if layer is active one, store pointer to it */ + if (gpl->flag & GP_LAYER_ACTIVE) + actlay= gpl; + + /* get frame to draw */ + gpf= gpencil_layer_getframe(gpl, CFRA, 0); + if (gpf == NULL) + continue; + + /* set color, stroke thickness, and point size */ + glLineWidth(lthick); + QUATCOPY(color, gpl->color); // just for copying 4 array elements + QUATCOPY(tcolor, gpl->color); // additional copy of color (for ghosting) + glColor4f(color[0], color[1], color[2], color[3]); + glPointSize(gpl->thickness + 2); + + /* draw 'onionskins' (frame left + right) */ + if (gpl->flag & GP_LAYER_ONIONSKIN) { + /* drawing method - only immediately surrounding (gstep = 0), or within a frame range on either side (gstep > 0)*/ + if (gpl->gstep) { + bGPDframe *gf; + short i; + + /* draw previous frames first */ + for (gf=gpf->prev, i=0; gf; gf=gf->prev, i++) { + /* check if frame is drawable */ + if ((gpf->framenum - gf->framenum) <= gpl->gstep) { + /* alpha decreases with distance from curframe index */ + tcolor[3] = color[3] - (i/gpl->gstep); + gp_draw_strokes(gf, winx, winy, dflag, debug, lthick, tcolor); + } + else + break; + } + + /* now draw next frames */ + for (gf= gpf->next, i=0; gf; gf=gf->next, i++) { + /* check if frame is drawable */ + if ((gf->framenum - gpf->framenum) <= gpl->gstep) { + /* alpha decreases with distance from curframe index */ + tcolor[3] = color[3] - (i/gpl->gstep); + gp_draw_strokes(gf, winx, winy, dflag, debug, lthick, tcolor); + } + else + break; + } + + /* restore alpha */ + glColor4f(color[0], color[1], color[2], color[3]); + } + else { + /* draw the strokes for the ghost frames (at half of the alpha set by user) */ + if (gpf->prev) { + tcolor[3] = (color[3] / 7); + gp_draw_strokes(gpf->prev, winx, winy, dflag, debug, lthick, tcolor); + } + + if (gpf->next) { + tcolor[3] = (color[3] / 4); + gp_draw_strokes(gpf->next, winx, winy, dflag, debug, lthick, tcolor); + } + + /* restore alpha */ + glColor4f(color[0], color[1], color[2], color[3]); + } + } + + /* draw the strokes already in active frame */ + tcolor[3]= color[3]; + gp_draw_strokes(gpf, winx, winy, dflag, debug, lthick, tcolor); + + /* Check if may need to draw the active stroke cache, only if this layer is the active layer + * that is being edited. (Stroke buffer is currently stored in gp-data) + */ + if ((G.f & G_GREASEPENCIL) && (gpl->flag & GP_LAYER_ACTIVE) && + (gpf->flag & GP_FRAME_PAINT)) + { + /* Buffer stroke needs to be drawn with a different linestyle to help differentiate them from normal strokes. */ + gp_draw_stroke_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick, dflag, gpd->sbuffer_sflag); + } + } + + /* turn off alpha blending, then smooth lines */ + glDisable(GL_BLEND); // alpha blending + glDisable(GL_LINE_SMOOTH); // smooth lines + + /* show info for debugging the status of gpencil */ + if ( ((dflag & GP_DRAWDATA_NOSTATUS)==0) && (gpd->flag & GP_DATA_DISPINFO) ) { + char printable[256]; + short xmax; + + /* get text to display */ + if (actlay) { + if (gpd->flag & GP_DATA_EDITPAINT) + BIF_ThemeColor(TH_BONE_POSE); // should be blue-ish + else if (actlay->actframe == NULL) + BIF_ThemeColor(TH_REDALERT); + else if (actlay->actframe->framenum == CFRA) + BIF_ThemeColor(TH_VERTEX_SELECT); // should be yellow + else + BIF_ThemeColor(TH_TEXT_HI); + + if (actlay->actframe) { + sprintf(printable, "GPencil: Layer ('%s'), Frame (%d) %s", + actlay->info, actlay->actframe->framenum, + ((gpd->flag & GP_DATA_EDITPAINT)?", Draw Mode On":"") ); + } + else { + sprintf(printable, "GPencil: Layer ('%s'), Frame <None> %s", + actlay->info, ((gpd->flag & GP_DATA_EDITPAINT)?", Draw Mode On":"") ); + } + } + else { + BIF_ThemeColor(TH_REDALERT); + sprintf(printable, "GPencil: Layer <None>"); + } + xmax= GetButStringLength(printable); + + /* only draw it if view is wide enough (assume padding of 20 is enough for now) */ + if (winx > (xmax + 20)) { + glRasterPos2i(winx-xmax, winy-20); + BMF_DrawString(G.fonts, printable); + } + } + + /* restore initial gl conditions */ + glLineWidth(1.0); + glPointSize(1.0); + glColor4f(0, 0, 0, 1); +} + +/* ----- Grease Pencil Sketches Drawing API ------ */ + +/* draw grease-pencil sketches to specified 2d-view assuming that matrices are already set correctly + * Note: this gets called twice - first time with onlyv2d=1 to draw 'canvas' strokes, second time with onlyv2d=0 for screen-aligned strokes + */ +void draw_gpencil_2dview (ScrArea *sa, short onlyv2d) +{ + bGPdata *gpd; + int dflag = 0; + + /* check that we have grease-pencil stuff to draw */ + if (sa == NULL) return; + gpd= gpencil_data_getactive(sa); + if (gpd == NULL) return; + + /* draw it! */ + if (onlyv2d) dflag |= (GP_DRAWDATA_ONLYV2D|GP_DRAWDATA_NOSTATUS); + gp_draw_data(gpd, sa->winx, sa->winy, dflag); +} + +/* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly + * Note: this gets called twice - first time with only3d=1 to draw 3d-strokes, second time with only3d=0 for screen-aligned strokes + */ +void draw_gpencil_3dview (ScrArea *sa, short only3d) +{ + bGPdata *gpd; + int dflag = 0; + + /* check that we have grease-pencil stuff to draw */ + gpd= gpencil_data_getactive(sa); + if (gpd == NULL) return; + + /* draw it! */ + if (only3d) dflag |= (GP_DRAWDATA_ONLY3D|GP_DRAWDATA_NOSTATUS); + gp_draw_data(gpd, sa->winx, sa->winy, dflag); +} + +/* draw grease-pencil sketches to opengl render window assuming that matrices are already set correctly */ +void draw_gpencil_oglrender (View3D *v3d, int winx, int winy) +{ + bGPdata *gpd; + + /* assume gpencil data comes from v3d */ + if (v3d == NULL) return; + gpd= v3d->gpd; + if (gpd == NULL) return; + + /* pass 1: draw 3d-strokes ------------ > */ + gp_draw_data(gpd, winx, winy, (GP_DRAWDATA_NOSTATUS|GP_DRAWDATA_ONLY3D)); + + /* pass 2: draw 2d-strokes ------------ > */ + /* adjust view matrices */ + myortho2(-0.375, (float)(winx)-0.375, -0.375, (float)(winy)-0.375); + glLoadIdentity(); + + /* draw it! */ + gp_draw_data(gpd, winx, winy, GP_DRAWDATA_NOSTATUS); +} + +/* ************************************************** */ diff --git a/source/blender/src/drawnode.c b/source/blender/src/drawnode.c index 1169062fdd0..853df3bedfc 100644 --- a/source/blender/src/drawnode.c +++ b/source/blender/src/drawnode.c @@ -37,6 +37,7 @@ #include "DNA_action_types.h" #include "DNA_color_types.h" #include "DNA_customdata_types.h" +#include "DNA_gpencil_types.h" #include "DNA_ipo_types.h" #include "DNA_ID.h" #include "DNA_image_types.h" @@ -65,8 +66,11 @@ #include "CMP_node.h" #include "SHD_node.h" +#include "BDR_gpencil.h" + #include "BIF_gl.h" #include "BIF_glutil.h" +#include "BIF_drawgpencil.h" #include "BIF_interface.h" #include "BIF_interface_icons.h" #include "BIF_language.h" @@ -3300,6 +3304,66 @@ static void node_draw_group(ScrArea *sa, SpaceNode *snode, bNode *gnode) } + +static void nodes_panel_gpencil(short cntrl) // NODES_HANDLER_GREASEPENCIL +{ + uiBlock *block; + SpaceNode *snode; + + snode= curarea->spacedata.first; + + block= uiNewBlock(&curarea->uiblocks, "nodes_panel_gpencil", UI_EMBOSS, UI_HELV, curarea->win); + uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl); + uiSetPanelHandler(NODES_HANDLER_GREASEPENCIL); // for close and esc + if (uiNewPanel(curarea, block, "Grease Pencil", "SpaceNode", 100, 30, 318, 204)==0) return; + + /* we can only really draw stuff if there are nodes (otherwise no events are handled */ + if (snode->nodetree == NULL) + return; + + /* allocate memory for gpd if drawing enabled (this must be done first or else we crash) */ + if (snode->flag & SNODE_DISPGP) { + if (snode->gpd == NULL) + gpencil_data_setactive(curarea, gpencil_data_addnew()); + } + + if (snode->flag & SNODE_DISPGP) { + bGPdata *gpd= snode->gpd; + short newheight; + + /* this is a variable height panel, newpanel doesnt force new size on existing panels */ + /* so first we make it default height */ + uiNewPanelHeight(block, 204); + + /* draw button for showing gpencil settings and drawings */ + uiDefButBitS(block, TOG, SNODE_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &snode->flag, 0, 0, 0, 0, "Display freehand annotations overlay over this Node Editor (draw using Shift-LMB)"); + + /* extend the panel if the contents won't fit */ + newheight= draw_gpencil_panel(block, gpd, curarea); + uiNewPanelHeight(block, newheight); + } + else { + uiDefButBitS(block, TOG, SNODE_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &snode->flag, 0, 0, 0, 0, "Display freehand annotations overlay over this Node Editor"); + uiDefBut(block, LABEL, 1, " ", 160, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, ""); + } +} + +static void nodes_blockhandlers(ScrArea *sa) +{ + SpaceNode *snode= sa->spacedata.first; + short a; + + for(a=0; a<SPACE_MAXHANDLER; a+=2) { + /* clear action value for event */ + switch(snode->blockhandler[a]) { + case NODES_HANDLER_GREASEPENCIL: + nodes_panel_gpencil(snode->blockhandler[a+1]); + break; + } + } + uiDrawBlocksPanels(sa, 0); +} + void drawnodespace(ScrArea *sa, void *spacedata) { SpaceNode *snode= sa->spacedata.first; @@ -3354,13 +3418,26 @@ void drawnodespace(ScrArea *sa, void *spacedata) } } + /* draw grease-pencil ('canvas' strokes) */ + if ((snode->flag & SNODE_DISPGP) && (snode->nodetree)) + draw_gpencil_2dview(sa, 1); + /* restore viewport (not needed yet) */ mywinset(sa->win); /* ortho at pixel level curarea */ myortho2(-0.375, sa->winx-0.375, -0.375, sa->winy-0.375); + + /* draw grease-pencil (screen strokes) */ + if ((snode->flag & SNODE_DISPGP) && (snode->nodetree)) + draw_gpencil_2dview(sa, 0); draw_area_emboss(sa); + + /* it is important to end a view in a transform compatible with buttons */ + bwin_scalematrix(sa->win, snode->blockscale, snode->blockscale, snode->blockscale); + nodes_blockhandlers(sa); + curarea->win_swap= WIN_BACK_OK; /* in the end, this is a delayed previewrender test, to allow buttons to be first */ diff --git a/source/blender/src/drawobject.c b/source/blender/src/drawobject.c index 045bf292446..1a469e8b366 100644 --- a/source/blender/src/drawobject.c +++ b/source/blender/src/drawobject.c @@ -1199,7 +1199,12 @@ static void drawlattice(Object *ob) int use_wcol= 0; lt= (ob==G.obedit)?editLatt:ob->data; + + /* now we default make displist, this will modifiers work for non animated case */ + if(ob->disp.first==NULL) + lattice_calc_modifiers(ob); dl= find_displist(&ob->disp, DL_VERTS); + if(ob==G.obedit) { cpack(0x004000); diff --git a/source/blender/src/drawseq.c b/source/blender/src/drawseq.c index e554b91dd52..71a777c9056 100644 --- a/source/blender/src/drawseq.c +++ b/source/blender/src/drawseq.c @@ -43,6 +43,7 @@ #include "IMB_imbuf_types.h" +#include "DNA_gpencil_types.h" #include "DNA_sequence_types.h" #include "DNA_scene_types.h" #include "DNA_screen_types.h" @@ -67,6 +68,9 @@ #include "BIF_space.h" #include "BIF_interface.h" +#include "BIF_drawgpencil.h" +#include "BDR_gpencil.h" + #include "BSE_view.h" #include "BSE_drawipo.h" #include "BSE_sequence.h" @@ -94,10 +98,74 @@ int no_rightbox=0, no_leftbox= 0; static void draw_seq_handle(Sequence *seq, SpaceSeq *sseq, float pixelx, short direction); static void draw_seq_extensions(Sequence *seq, SpaceSeq *sseq); -static void draw_seq_text(Sequence *seq, float x1, float x2, float y1, float y2); +static void draw_seq_text(Sequence *seq, float x1, float x2, float y1, float y2, char *background_col); static void draw_shadedstrip(Sequence *seq, char *col, float x1, float y1, float x2, float y2); static void draw_seq_strip(struct Sequence *seq, struct ScrArea *sa, struct SpaceSeq *sseq, int outline_tint, float pixelx); + +static void seq_panel_gpencil(short cntrl) // SEQ_HANDLER_GREASEPENCIL +{ + uiBlock *block; + SpaceSeq *sseq; + + sseq= curarea->spacedata.first; + + block= uiNewBlock(&curarea->uiblocks, "seq_panel_gpencil", UI_EMBOSS, UI_HELV, curarea->win); + uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl); + uiSetPanelHandler(SEQ_HANDLER_GREASEPENCIL); // for close and esc + if (uiNewPanel(curarea, block, "Grease Pencil", "SpaceSeq", 100, 30, 318, 204)==0) return; + + /* only draw settings if right mode */ + if (sseq->mainb == 0) + return; + + /* allocate memory for gpd if drawing enabled (this must be done first or else we crash) */ + if (sseq->flag & SEQ_DRAW_GPENCIL) { + if (sseq->gpd == NULL) + gpencil_data_setactive(curarea, gpencil_data_addnew()); + } + + if (sseq->flag & SEQ_DRAW_GPENCIL) { + bGPdata *gpd= sseq->gpd; + short newheight; + + /* this is a variable height panel, newpanel doesnt force new size on existing panels */ + /* so first we make it default height */ + uiNewPanelHeight(block, 204); + + /* draw button for showing gpencil settings and drawings */ + uiDefButBitI(block, TOG, SEQ_DRAW_GPENCIL, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &sseq->flag, 0, 0, 0, 0, "Display freehand annotations overlay over this Sequencer View (draw using Shift-LMB)"); + + /* extend the panel if the contents won't fit */ + newheight= draw_gpencil_panel(block, gpd, curarea); + uiNewPanelHeight(block, newheight); + } + else { + uiDefButBitI(block, TOG, SEQ_DRAW_GPENCIL, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &sseq->flag, 0, 0, 0, 0, "Display freehand annotations overlay over this Sequencer View"); + uiDefBut(block, LABEL, 1, " ", 160, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, ""); + } +} + +static void seq_blockhandlers(ScrArea *sa) +{ + SpaceSeq *sseq= sa->spacedata.first; + short a; + + /* warning; blocks need to be freed each time, handlers dont remove (for ipo moved to drawipospace) */ + uiFreeBlocksWin(&sa->uiblocks, sa->win); + + for(a=0; a<SPACE_MAXHANDLER; a+=2) { + switch(sseq->blockhandler[a]) { + case SEQ_HANDLER_GREASEPENCIL: + seq_panel_gpencil(sseq->blockhandler[a+1]); + break; + } + } + uiDrawBlocksPanels(sa, 0); + +} + + static void draw_cfra_seq(void) { glColor3ub(0x30, 0x90, 0x50); @@ -536,7 +604,7 @@ static void draw_seq_extensions(Sequence *seq, SpaceSeq *sseq) } /* draw info text on a sequence strip */ -static void draw_seq_text(Sequence *seq, float x1, float x2, float y1, float y2) +static void draw_seq_text(Sequence *seq, float x1, float x2, float y1, float y2, char *background_col) { float v1[2], v2[2]; int len, size; @@ -602,8 +670,13 @@ static void draw_seq_text(Sequence *seq, float x1, float x2, float y1, float y2) mval[1]= 1; areamouseco_to_ipoco(G.v2d, mval, &x1, &x2); - if(seq->flag & SELECT) cpack(0xFFFFFF); - else cpack(0); + if(seq->flag & SELECT){ + cpack(0xFFFFFF); + }else if ((((int)background_col[0] + (int)background_col[1] + (int)background_col[2]) / 3) < 50){ + cpack(0x505050); /* use lighter text colour for dark background */ + }else{ + cpack(0); + } glRasterPos3f(x1, y1+SEQ_STRIP_OFSBOTTOM, 0.0); BMF_DrawString(G.font, strp); } @@ -672,7 +745,7 @@ so wave file sample drawing precission is zoom adjusted static void draw_seq_strip(Sequence *seq, ScrArea *sa, SpaceSeq *sseq, int outline_tint, float pixelx) { float x1, x2, y1, y2; - char col[3], is_single_image; + char col[3], background_col[3], is_single_image; /* we need to know if this is a single image/color or not for drawing */ is_single_image = (char)check_single_seq(seq); @@ -687,13 +760,14 @@ static void draw_seq_strip(Sequence *seq, ScrArea *sa, SpaceSeq *sseq, int outli /* get the correct color per strip type*/ - get_seq_color3ubv(seq, col); + //get_seq_color3ubv(seq, col); + get_seq_color3ubv(seq, background_col); /* draw the main strip body */ if (is_single_image) /* single image */ - draw_shadedstrip(seq, col, seq_tx_get_final_left(seq, 0), y1, seq_tx_get_final_right(seq, 0), y2); + draw_shadedstrip(seq, background_col, seq_tx_get_final_left(seq, 0), y1, seq_tx_get_final_right(seq, 0), y2); else /* normal operation */ - draw_shadedstrip(seq, col, x1, y1, x2, y2); + draw_shadedstrip(seq, background_col, x1, y1, x2, y2); /* draw additional info and controls */ if (seq->type == SEQ_RAM_SOUND) @@ -746,7 +820,7 @@ static void draw_seq_strip(Sequence *seq, ScrArea *sa, SpaceSeq *sseq, int outli /* nice text here would require changing the view matrix for texture text */ if( (x2-x1) / pixelx > 32) { - draw_seq_text(seq, x1, x2, y1, y2); + draw_seq_text(seq, x1, x2, y1, y2, background_col); } } @@ -907,6 +981,17 @@ static void draw_image_seq(ScrArea *sa) if (free_ibuf) { IMB_freeImBuf(ibuf); } + + /* draw grease-pencil (screen aligned) */ + if (sseq->flag & SEQ_DRAW_GPENCIL) + draw_gpencil_2dview(sa, 0); + + /* ortho at pixel level sa */ + myortho2(-0.375, sa->winx-0.375, -0.375, sa->winy-0.375); + + /* it is important to end a view in a transform compatible with buttons */ + bwin_scalematrix(sa->win, sseq->blockscale, sseq->blockscale, sseq->blockscale); + seq_blockhandlers(sa); sa->win_swap= WIN_BACK_OK; } @@ -1023,24 +1108,6 @@ void seq_viewmove(SpaceSeq *sseq) window_set_cursor(win, oldcursor); } - - -static void seq_blockhandlers(ScrArea *sa) -{ - SpaceSeq *sseq= sa->spacedata.first; - short a; - - /* warning; blocks need to be freed each time, handlers dont remove (for ipo moved to drawipospace) */ - uiFreeBlocksWin(&sa->uiblocks, sa->win); - - for(a=0; a<SPACE_MAXHANDLER; a+=2) { - /* clear action value for event */ - sseq->blockhandler[a+1]= 0; - } - uiDrawBlocksPanels(sa, 0); - -} - void drawprefetchseqspace(ScrArea *sa, void *spacedata) { SpaceSeq *sseq= sa->spacedata.first; diff --git a/source/blender/src/drawview.c b/source/blender/src/drawview.c index 780e7847bfb..65111bccfa9 100644 --- a/source/blender/src/drawview.c +++ b/source/blender/src/drawview.c @@ -61,6 +61,7 @@ #include "DNA_constraint_types.h" #include "DNA_curve_types.h" #include "DNA_group_types.h" +#include "DNA_gpencil_types.h" #include "DNA_image_types.h" #include "DNA_key_types.h" #include "DNA_lattice_types.h" @@ -111,6 +112,7 @@ #include "BIF_butspace.h" #include "BIF_drawimage.h" +#include "BIF_drawgpencil.h" #include "BIF_editgroup.h" #include "BIF_editarmature.h" #include "BIF_editmesh.h" @@ -137,6 +139,7 @@ #include "BDR_editobject.h" #include "BDR_vpaint.h" #include "BDR_sculptmode.h" +#include "BDR_gpencil.h" #include "BSE_drawview.h" #include "BSE_filesel.h" @@ -1501,44 +1504,52 @@ static void draw_view_icon(void) glDisable(GL_BLEND); } -static void draw_viewport_name(ScrArea *sa) +char *view3d_get_name(View3D *v3d) { char *name = NULL; - char *printable = NULL; - switch(G.vd->view) { + switch (v3d->view) { case 1: - if (G.vd->persp == V3D_ORTHO) - name = (G.vd->flag2 & V3D_OPP_DIRECTION_NAME) ? "Back Ortho" : "Front Ortho"; + if (v3d->persp == V3D_ORTHO) + name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Back Ortho" : "Front Ortho"; else - name = (G.vd->flag2 & V3D_OPP_DIRECTION_NAME) ? "Back Persp" : "Front Persp"; + name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Back Persp" : "Front Persp"; break; case 3: - if (G.vd->persp == V3D_ORTHO) - name = (G.vd->flag2 & V3D_OPP_DIRECTION_NAME) ? "Left Ortho" : "Right Ortho"; + if (v3d->persp == V3D_ORTHO) + name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Left Ortho" : "Right Ortho"; else - name = (G.vd->flag2 & V3D_OPP_DIRECTION_NAME) ? "Left Persp" : "Right Persp"; + name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Left Persp" : "Right Persp"; break; case 7: - if (G.vd->persp == V3D_ORTHO) - name = (G.vd->flag2 & V3D_OPP_DIRECTION_NAME) ? "Bottom Ortho" : "Top Ortho"; + if (v3d->persp == V3D_ORTHO) + name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Bottom Ortho" : "Top Ortho"; else - name = (G.vd->flag2 & V3D_OPP_DIRECTION_NAME) ? "Bottom Persp" : "Top Persp"; + name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Bottom Persp" : "Top Persp"; break; default: - if (G.vd->persp==V3D_CAMOB) { - if ((G.vd->camera) && (G.vd->camera->type == OB_CAMERA)) { + if (v3d->persp==V3D_CAMOB) { + if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) { Camera *cam; - cam = G.vd->camera->data; + cam = v3d->camera->data; name = (cam->type != CAM_ORTHO) ? "Camera Persp" : "Camera Ortho"; } else { name = "Object as Camera"; } } else { - name = (G.vd->persp == V3D_ORTHO) ? "User Ortho" : "User Persp"; + name = (v3d->persp == V3D_ORTHO) ? "User Ortho" : "User Persp"; } + break; } + return name; +} + +static void draw_viewport_name(ScrArea *sa) +{ + char *name = view3d_get_name(sa->spacedata.first); + char *printable = NULL; + if (G.vd->localview) { printable = malloc(strlen(name) + strlen(" (Local)_")); /* '_' gives space for '\0' */ strcpy(printable, name); @@ -1986,6 +1997,8 @@ static void v3d_editarmature_buts(uiBlock *block, Object *ob, float lim) tfp->ob_eul[0]= 180.0*ebone->roll/M_PI; uiDefButF(block, NUM, B_ARMATUREPANEL1, "Roll:", 10, 100, 140, 19, tfp->ob_eul, -lim, lim, 1000, 3, ""); + uiDefButBitI(block, TOG, BONE_EDITMODE_LOCKED, REDRAWVIEW3D, "Lock", 160, 100, 140, 19, &(ebone->flag), 0, 0, 0, 0, "Prevents bone from being transformed in edit mode"); + uiBlockBeginAlign(block); uiDefButF(block, NUM, B_ARMATUREPANEL1, "TailRadius:", 10, 150, 140, 19, &ebone->rad_tail, 0, lim, 10, 3, ""); if (ebone->parent && ebone->flag & BONE_CONNECTED ) @@ -2500,7 +2513,7 @@ static void view3d_panel_background(short cntrl) // VIEW3D_HANDLER_BACKGROUND uiSetPanelHandler(VIEW3D_HANDLER_BACKGROUND); // for close and esc if(uiNewPanel(curarea, block, "Background Image", "View3d", 340, 10, 318, 204)==0) return; - if(G.f & G_VERTEXPAINT || G.f & G_WEIGHTPAINT || G.f & G_TEXTUREPAINT) { + if(G.f & G_VERTEXPAINT || G.f & G_WEIGHTPAINT || G.f & G_TEXTUREPAINT || G.f & G_GREASEPENCIL) { uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER); // force old style frontbuffer draw } @@ -2548,7 +2561,7 @@ static void view3d_panel_properties(short cntrl) // VIEW3D_HANDLER_SETTINGS /* to force height */ uiNewPanelHeight(block, 264); - if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT)) { + if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT|G_GREASEPENCIL)) { uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER); // force old style frontbuffer draw } @@ -2622,6 +2635,49 @@ static void view3d_panel_preview(ScrArea *sa, short cntrl) // VIEW3D_HANDLER_PRE } } +static void view3d_panel_gpencil(short cntrl) // VIEW3D_HANDLER_GREASEPENCIL +{ + uiBlock *block; + View3D *vd; + + vd= G.vd; + + block= uiNewBlock(&curarea->uiblocks, "view3d_panel_gpencil", UI_EMBOSS, UI_HELV, curarea->win); + uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl); + uiSetPanelHandler(VIEW3D_HANDLER_GREASEPENCIL); // for close and esc + if (uiNewPanel(curarea, block, "Grease Pencil", "View3d", 100, 30, 318, 204)==0) return; + + if (G.f & (G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT|G_GREASEPENCIL)) { + uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER); // force old style frontbuffer draw + } + + /* allocate memory for gpd if drawing enabled (this must be done first or else we crash) */ + if (vd->flag2 & V3D_DISPGP) { + if (vd->gpd == NULL) + gpencil_data_setactive(curarea, gpencil_data_addnew()); + } + + if (vd->flag2 & V3D_DISPGP) { + bGPdata *gpd= vd->gpd; + short newheight; + + /* this is a variable height panel, newpanel doesnt force new size on existing panels */ + /* so first we make it default height */ + uiNewPanelHeight(block, 204); + + /* draw button for showing gpencil settings and drawings */ + uiDefButBitS(block, TOG, V3D_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &vd->flag2, 0, 0, 0, 0, "Display freehand annotations overlay over this 3D View (draw using Shift-LMB)"); + + /* extend the panel if the contents won't fit */ + newheight= draw_gpencil_panel(block, gpd, curarea); + uiNewPanelHeight(block, newheight); + } + else { + uiDefButBitS(block, TOG, V3D_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &vd->flag2, 0, 0, 0, 0, "Display freehand annotations overlay over this 3D View"); + uiDefBut(block, LABEL, 1, " ", 160, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, ""); + } +} + static void view3d_blockhandlers(ScrArea *sa) { @@ -2636,9 +2692,7 @@ static void view3d_blockhandlers(ScrArea *sa) glDisable(GL_DEPTH_TEST); for(a=0; a<SPACE_MAXHANDLER; a+=2) { - switch(v3d->blockhandler[a]) { - case VIEW3D_HANDLER_PROPERTIES: view3d_panel_properties(v3d->blockhandler[a+1]); break; @@ -2653,7 +2707,10 @@ static void view3d_blockhandlers(ScrArea *sa) break; case VIEW3D_HANDLER_TRANSFORM: view3d_panel_transform_spaces(v3d->blockhandler[a+1]); - break; + break; + case VIEW3D_HANDLER_GREASEPENCIL: + view3d_panel_gpencil(v3d->blockhandler[a+1]); + break; } /* clear action value for event */ v3d->blockhandler[a+1]= 0; @@ -3173,7 +3230,11 @@ void drawview3dspace(ScrArea *sa, void *spacedata) v3d->zbuf= FALSE; glDisable(GL_DEPTH_TEST); } - + + /* draw grease-pencil stuff */ + if (v3d->flag2 & V3D_DISPGP) + draw_gpencil_3dview(sa, 1); + persp(PERSP_WIN); // set ortho /* Draw Sculpt Mode brush */ @@ -3215,6 +3276,11 @@ void drawview3dspace(ScrArea *sa, void *spacedata) if(v3d->persp>1) drawviewborder(); if(v3d->flag2 & V3D_FLYMODE) drawviewborder_flymode(); + + /* draw grease-pencil stuff */ + if (v3d->flag2 & V3D_DISPGP) + draw_gpencil_3dview(sa, 0); + if(!(G.f & G_PLAYANIM)) drawcursor(v3d); if(U.uiflag & USER_SHOW_ROTVIEWICON) draw_view_axis(); @@ -3315,16 +3381,15 @@ void drawview3d_render(struct View3D *v3d, int winx, int winy, float winmat[][4] /* first draw set */ if(G.scene->set) { - for(SETLOOPER(G.scene->set, base)) { if(v3d->lay & base->lay) { if ELEM3(base->object->type, OB_LAMP, OB_CAMERA, OB_LATTICE); else { where_is_object(base->object); - + BIF_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f); draw_object(base, DRAW_CONSTCOLOR|DRAW_SCENESET); - + if(base->object->transflag & OB_DUPLI) { draw_dupli_objects(v3d, base); } @@ -3381,6 +3446,13 @@ void drawview3d_render(struct View3D *v3d, int winx, int winy, float winmat[][4] glDisable(GL_DEPTH_TEST); } + if(v3d->gpd) { + /* draw grease-pencil overlays + * WARNING: view matrices are altered here! + */ + draw_gpencil_oglrender(v3d, winx, winy); + } + G.f &= ~G_SIMULATION; glFlush(); diff --git a/source/blender/src/editaction.c b/source/blender/src/editaction.c index 4cc0e52ce3f..c454715b1df 100644 --- a/source/blender/src/editaction.c +++ b/source/blender/src/editaction.c @@ -52,6 +52,7 @@ #include "DNA_mesh_types.h" #include "DNA_nla_types.h" #include "DNA_lattice_types.h" +#include "DNA_gpencil_types.h" #include "BKE_action.h" #include "BKE_armature.h" @@ -90,6 +91,7 @@ #include "BDR_drawaction.h" #include "BDR_editobject.h" +#include "BDR_gpencil.h" #include "mydevice.h" #include "blendef.h" @@ -296,6 +298,16 @@ bActListElem *make_new_actlistelem (void *data, short datatype, void *owner, sho ale->datatype= ALE_IPO; } break; + case ACTTYPE_GPLAYER: + { + bGPDlayer *gpl= (bGPDlayer *)data; + + ale->flag= gpl->flag; + + ale->key_data= NULL; + ale->datatype= ALE_GPFRAME; + } + break; } } @@ -505,6 +517,49 @@ static void actdata_filter_shapekey (ListBase *act_data, Key *key, int filter_mo } } + +static void actdata_filter_gpencil (ListBase *act_data, bScreen *sc, int filter_mode) +{ + bActListElem *ale; + ScrArea *sa; + bGPdata *gpd; + bGPDlayer *gpl; + + /* check if filtering types are appropriate */ + if ( !(filter_mode & (ACTFILTER_IPOKEYS|ACTFILTER_ONLYICU|ACTFILTER_ACTGROUPED)) ) + { + /* loop over spaces in current screen, finding gpd blocks (could be slow!) */ + for (sa= sc->areabase.first; sa; sa= sa->next) { + /* try to get gp data */ + gpd= gpencil_data_getactive(sa); + if (gpd == NULL) continue; + + /* add gpd as channel too (if for drawing, and it has layers) */ + if ((filter_mode & ACTFILTER_FORDRAWING) && (gpd->layers.first)) { + /* add to list */ + ale= make_new_actlistelem(gpd, ACTTYPE_GPDATABLOCK, sa, ACTTYPE_SPECIALDATA); + if (ale) BLI_addtail(act_data, ale); + } + + /* only add layers if they will be visible (if drawing channels) */ + if ( !(filter_mode & ACTFILTER_VISIBLE) || (EXPANDED_GPD(gpd)) ) { + /* loop over layers as the conditions are acceptable */ + for (gpl= gpd->layers.first; gpl; gpl= gpl->next) { + /* only if selected */ + if (!(filter_mode & ACTFILTER_SEL) || SEL_GPL(gpl)) { + /* only if editable */ + if (!(filter_mode & ACTFILTER_FOREDIT) || EDITABLE_GPL(gpl)) { + /* add to list */ + ale= make_new_actlistelem(gpl, ACTTYPE_GPLAYER, gpd, ACTTYPE_GPDATABLOCK); + if (ale) BLI_addtail(act_data, ale); + } + } + } + } + } + } +} + /* This function filters the active data source to leave only the desired * data types. 'Public' api call. * *act_data: is a pointer to a ListBase, to which the filtered action data @@ -525,6 +580,9 @@ void actdata_filter (ListBase *act_data, int filter_mode, void *data, short data case ACTCONT_SHAPEKEY: actdata_filter_shapekey(act_data, data, filter_mode); break; + case ACTCONT_GPENCIL: + actdata_filter_gpencil(act_data, data, filter_mode); + break; } /* remove any weedy entries */ @@ -599,11 +657,8 @@ int get_nearest_key_num (Key *key, short *mval, float *x) return (num + 1); } -/* this function is used to get a pointer to an action or shapekey - * datablock, thus simplying that process. - */ -/* this function is intended for use */ -void *get_nearest_act_channel (short mval[], short *ret_type) +/* this function finds the channel that mouse is floating over */ +void *get_nearest_act_channel (short mval[], short *ret_type, void **owner) { ListBase act_data = {NULL, NULL}; bActListElem *ale; @@ -614,6 +669,9 @@ void *get_nearest_act_channel (short mval[], short *ret_type) int clickmin, clickmax; float x,y; + /* init 'owner' return val */ + *owner= NULL; + /* determine what type of data we are operating on */ data = get_action_context(&datatype); if (data == NULL) { @@ -641,6 +699,7 @@ void *get_nearest_act_channel (short mval[], short *ret_type) /* found match */ *ret_type= ale->type; data= ale->data; + *owner= ale->owner; BLI_freelistN(&act_data); @@ -743,6 +802,10 @@ static void *get_nearest_action_key (float *selx, short *sel, short *ret_type, b bActionGroup *agrp= (bActionGroup *)ale->data; agroup_to_keylist(agrp, &act_keys, NULL, NULL); } + else if (ale->type == ACTTYPE_GPLAYER) { + bGPDlayer *gpl= (bGPDlayer *)ale->data; + gpl_to_keylist(gpl, &act_keys, NULL, NULL); + } /* loop through keyframes, finding one that was clicked on */ for (ak= act_keys.first; ak; ak= ak->next) { @@ -766,6 +829,10 @@ static void *get_nearest_action_key (float *selx, short *sel, short *ret_type, b data = ale->key_data; *ret_type= ACTTYPE_ICU; } + else if (datatype == ACTCONT_GPENCIL) { + data = ale->data; + *ret_type= ACTTYPE_GPLAYER; + } /* cleanup tempolary lists */ BLI_freelistN(&act_keys); @@ -795,17 +862,40 @@ void *get_action_context (short *datatype) act = (G.saction)? G.saction->action: NULL; key = get_action_mesh_key(); - if (act) { - *datatype= ACTCONT_ACTION; - return act; - } - else if (key) { - *datatype= ACTCONT_SHAPEKEY; - return key; + /* check mode selector */ + if (G.saction) { + switch (G.saction->mode) { + case SACTCONT_ACTION: + *datatype= ACTCONT_ACTION; + return act; + + case SACTCONT_SHAPEKEY: + *datatype= ACTCONT_SHAPEKEY; + return key; + + case SACTCONT_GPENCIL: + *datatype= ACTCONT_GPENCIL; + return G.curscreen; // FIXME: add that dopesheet type thing here! + + default: /* includes SACTCONT_DOPESHEET for now */ + *datatype= ACTCONT_NONE; + return NULL; + } } else { - *datatype= ACTCONT_NONE; - return NULL; + /* resort to guessing based on what is available */ + if (act) { + *datatype= ACTCONT_ACTION; + return act; + } + else if (key) { + *datatype= ACTCONT_SHAPEKEY; + return key; + } + else { + *datatype= ACTCONT_NONE; + return NULL; + } } } @@ -1307,12 +1397,18 @@ void duplicate_action_keys (void) if (data == NULL) return; /* filter data */ - filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS); + if (datatype == ACTCONT_GPENCIL) + filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT); + else + filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS); actdata_filter(&act_data, filter, data, datatype); /* loop through filtered data and duplicate selected keys */ for (ale= act_data.first; ale; ale= ale->next) { - duplicate_ipo_keys((Ipo *)ale->key_data); + if (ale->type == ACTTYPE_GPLAYER) + duplicate_gplayer_frames(ale->data); + else + duplicate_ipo_keys((Ipo *)ale->key_data); } /* free filtered list */ @@ -1398,7 +1494,10 @@ void snap_action_keys(short mode) } /* filter data */ - filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS); + if (datatype == ACTCONT_GPENCIL) + filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT); + else + filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS); actdata_filter(&act_data, filter, data, datatype); /* snap to frame */ @@ -1408,6 +1507,8 @@ void snap_action_keys(short mode) snap_ipo_keys(ale->key_data, mode); actstrip_map_ipo_keys(OBACT, ale->key_data, 1, 1); } + else if (ale->type == ACTTYPE_GPLAYER) + snap_gplayer_frames(ale->data, mode); else snap_ipo_keys(ale->key_data, mode); } @@ -1421,6 +1522,7 @@ void snap_action_keys(short mode) allqueue(REDRAWACTION, 0); allqueue(REDRAWIPO, 0); allqueue(REDRAWNLA, 0); + allqueue(REDRAWVIEW3D, 0); } /* this function is responsible for snapping keyframes to frame-times */ @@ -1456,7 +1558,10 @@ void mirror_action_keys(short mode) } /* filter data */ - filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS); + if (datatype == ACTCONT_GPENCIL) + filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT); + else + filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS); actdata_filter(&act_data, filter, data, datatype); /* mirror */ @@ -1466,6 +1571,8 @@ void mirror_action_keys(short mode) mirror_ipo_keys(ale->key_data, mode); actstrip_map_ipo_keys(OBACT, ale->key_data, 1, 1); } + else if (ale->type == ACTTYPE_GPLAYER) + mirror_gplayer_frames(ale->data, mode); else mirror_ipo_keys(ale->key_data, mode); } @@ -1550,6 +1657,10 @@ void insertkey_action(void) } } } + else { + /* this tool is not supported in this mode */ + return; + } BIF_undo_push("Insert Key"); allspace(REMAKEIPO, 0); @@ -1573,12 +1684,18 @@ void delete_action_keys (void) if (data == NULL) return; /* filter data */ - filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS); + if (datatype == ACTCONT_GPENCIL) + filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT); + else + filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS); actdata_filter(&act_data, filter, data, datatype); /* loop through filtered data and delete selected keys */ for (ale= act_data.first; ale; ale= ale->next) { - delete_ipo_keys((Ipo *)ale->key_data); + if (ale->type == ACTTYPE_GPLAYER) + delete_gplayer_frames((bGPDlayer *)ale->data); + else + delete_ipo_keys((Ipo *)ale->key_data); } /* free filtered list */ @@ -1699,6 +1816,7 @@ void clean_action (void) 0.0000001f, 1.0, 0.001, 0.1, "Clean Threshold"); if (!ok) return; + if (datatype == ACTCONT_GPENCIL) return; /* filter data */ filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_SEL | ACTFILTER_ONLYICU); @@ -1737,6 +1855,7 @@ void sample_action_keys (void) /* sanity checks */ data= get_action_context(&datatype); if (data == NULL) return; + if (datatype == ACTCONT_GPENCIL) return; /* filter data */ filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_ONLYICU); @@ -2096,6 +2215,7 @@ void action_set_ipo_flags (short mode, short event) /* determine what type of data we are operating on */ data = get_action_context(&datatype); if (data == NULL) return; + if (datatype == ACTCONT_GPENCIL) return; /* determine which set of processing we are doing */ switch (mode) { @@ -2194,6 +2314,7 @@ void sethandles_action_keys (int code) /* determine what type of data we are operating on */ data = get_action_context(&datatype); if (data == NULL) return; + if (datatype == ACTCONT_GPENCIL) return; /* filter data */ filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS); @@ -2224,7 +2345,7 @@ static void numbuts_action () void *data; short datatype; - void *act_channel; + void *act_channel, *channel_owner; short chantype; bActionGroup *agrp= NULL; @@ -2232,11 +2353,13 @@ static void numbuts_action () bConstraintChannel *conchan= NULL; IpoCurve *icu= NULL; KeyBlock *kb= NULL; + bGPdata *gpd= NULL; + bGPDlayer *gpl= NULL; short mval[2]; int but=0; - char str[64]; + char str[128]; short expand, protect, mute; float slidermin, slidermax; @@ -2249,7 +2372,7 @@ static void numbuts_action () getmouseco_areawin(mval); if (mval[0] > NAMEWIDTH) return; - act_channel= get_nearest_act_channel(mval, &chantype); + act_channel= get_nearest_act_channel(mval, &chantype, &channel_owner); /* create items for clever-numbut */ if (chantype == ACTTYPE_ACHAN) { @@ -2345,6 +2468,19 @@ static void numbuts_action () add_numbut(but++, TOG|SHO, "Expanded", 0, 24, &expand, "Action Group is Expanded"); add_numbut(but++, TOG|SHO, "Protected", 0, 24, &protect, "Group is Protected"); } + else if (chantype == ACTTYPE_GPLAYER) { + /* Grease-Pencil Layer */ + gpd= (bGPdata *)channel_owner; + gpl= (bGPDlayer *)act_channel; + + strcpy(str, gpl->info); + protect= (gpl->flag & GP_LAYER_LOCKED); + mute = (gpl->flag & GP_LAYER_HIDE); + + add_numbut(but++, TEX, "GP-Layer: ", 0, 128, str, "Name of Grease Pencil Layer"); + add_numbut(but++, TOG|SHO, "Hide", 0, 24, &mute, "Grease Pencil Layer is Visible"); + add_numbut(but++, TOG|SHO, "Protected", 0, 24, &protect, "Grease Pencil Layer is Protected"); + } else { /* nothing under-cursor */ return; @@ -2393,6 +2529,16 @@ static void numbuts_action () if (protect) agrp->flag |= AGRP_PROTECTED; else agrp->flag &= ~AGRP_PROTECTED; } + else if (gpl) { + strcpy(gpl->info, str); + BLI_uniquename(&gpd->layers, gpl, "GP_Layer", offsetof(bGPDlayer, info), 128); + + if (mute) gpl->flag |= GP_LAYER_HIDE; + else gpl->flag &= ~GP_LAYER_HIDE;; + + if (protect) gpl->flag |= GP_LAYER_LOCKED; + else gpl->flag &= ~GP_LAYER_LOCKED; + } allqueue(REDRAWACTION, 0); allspace(REMAKEIPO, 0); @@ -2524,6 +2670,31 @@ void setflag_action_channels (short mode) } } break; + case ACTTYPE_GPLAYER: + { + bGPDlayer *gpl= (bGPDlayer *)ale->data; + + /* 'protect' and 'mute' */ + if (val == 2) { + /* mute */ + if (mode == 2) + gpl->flag &= ~GP_LAYER_HIDE; + else if (mode == 1) + gpl->flag |= GP_LAYER_HIDE; + else + gpl->flag ^= GP_LAYER_HIDE; + } + else if (val == 1) { + /* protected */ + if (mode == 2) + gpl->flag &= ~GP_LAYER_LOCKED; + else if (mode == 1) + gpl->flag |= GP_LAYER_LOCKED; + else + gpl->flag ^= GP_LAYER_LOCKED; + } + } + break; } } BLI_freelistN(&act_data); @@ -2564,7 +2735,7 @@ static void select_action_group (bAction *act, bActionGroup *agrp, int selectmod set_active_actiongroup(act, agrp, select); } -static void hilight_channel(bAction *act, bActionChannel *achan, short select) +static void hilight_channel (bAction *act, bActionChannel *achan, short select) { bActionChannel *curchan; @@ -2637,7 +2808,7 @@ void select_actionchannel_by_name (bAction *act, char *name, int select) /* exported for outliner (ton) */ /* apparently within active object context */ -int select_channel(bAction *act, bActionChannel *achan, int selectmode) +int select_channel (bAction *act, bActionChannel *achan, int selectmode) { /* Select the channel based on the selection mode */ int flag; @@ -2661,9 +2832,9 @@ int select_channel(bAction *act, bActionChannel *achan, int selectmode) return flag; } -static int select_constraint_channel(bAction *act, - bConstraintChannel *conchan, - int selectmode) +static int select_constraint_channel (bAction *act, + bConstraintChannel *conchan, + int selectmode) { /* Select the constraint channel based on the selection mode */ int flag; @@ -2684,7 +2855,7 @@ static int select_constraint_channel(bAction *act, return flag; } -int select_icu_channel(bAction *act, IpoCurve *icu, int selectmode) +int select_icu_channel (bAction *act, IpoCurve *icu, int selectmode) { /* Select the channel based on the selection mode */ int flag; @@ -2704,6 +2875,30 @@ int select_icu_channel(bAction *act, IpoCurve *icu, int selectmode) return flag; } +int select_gplayer_channel (bGPdata *gpd, bGPDlayer *gpl, int selectmode) +{ + /* Select the channel based on the selection mode */ + int flag; + + switch (selectmode) { + case SELECT_ADD: + gpl->flag |= GP_LAYER_SELECT; + break; + case SELECT_SUBTRACT: + gpl->flag &= ~GP_LAYER_SELECT; + break; + case SELECT_INVERT: + gpl->flag ^= GP_LAYER_SELECT; + break; + } + + flag = (gpl->flag & GP_LAYER_SELECT) ? 1 : 0; + if (flag) + gpencil_layer_setactive(gpd, gpl); + + return flag; +} + /* select only the active action-group's action channels */ void select_action_group_channels (bAction *act, bActionGroup *agrp) @@ -2848,6 +3043,8 @@ void deselect_action_channels (short mode) /* based on type */ if (datatype == ACTCONT_ACTION) deselect_actionchannels(data, mode); + else if (datatype == ACTCONT_GPENCIL) + deselect_gpencil_layers(data, mode); // should shapekey channels be allowed to do this? } @@ -2863,24 +3060,40 @@ void deselect_action_keys (short test, short sel) /* determine what type of data we are operating on */ data = get_action_context(&datatype); if (data == NULL) return; - + + /* determine type-based settings */ + if (datatype == ACTCONT_GPENCIL) + filter= (ACTFILTER_VISIBLE); + else + filter= (ACTFILTER_VISIBLE | ACTFILTER_IPOKEYS); + /* filter data */ - filter= (ACTFILTER_VISIBLE | ACTFILTER_IPOKEYS); actdata_filter(&act_data, filter, data, datatype); /* See if we should be selecting or deselecting */ if (test) { for (ale= act_data.first; ale; ale= ale->next) { - if (is_ipo_key_selected(ale->key_data)) { - sel= 0; - break; + if (ale->type == ACTTYPE_GPLAYER) { + if (is_gplayer_frame_selected(ale->data)) { + sel= 0; + break; + } + } + else { + if (is_ipo_key_selected(ale->key_data)) { + sel= 0; + break; + } } } } /* Now set the flags */ for (ale= act_data.first; ale; ale= ale->next) { - set_ipo_key_selection(ale->key_data, sel); + if (ale->type == ACTTYPE_GPLAYER) + set_gplayer_frame_selection(ale->data, sel); + else + set_ipo_key_selection(ale->key_data, sel); } /* Cleanup */ @@ -2908,11 +3121,11 @@ void selectall_action_keys (short mval[], short mode, short select_mode) switch (mode) { case 0: /* all in channel*/ { - void *act_channel; + void *act_channel, *channel_owner; short chantype; /* get channel, and act according to type */ - act_channel= get_nearest_act_channel(mval, &chantype); + act_channel= get_nearest_act_channel(mval, &chantype, &channel_owner); switch (chantype) { case ACTTYPE_GROUP: { @@ -2946,6 +3159,12 @@ void selectall_action_keys (short mval[], short mode, short select_mode) select_icu_bezier_keys(icu, select_mode); } break; + case ACTTYPE_GPLAYER: + { + bGPDlayer *gpl= (bGPDlayer *)act_channel; + select_gpencil_frames(gpl, select_mode); + } + break; } } break; @@ -2971,12 +3190,16 @@ void selectall_action_keys (short mval[], short mode, short select_mode) rectf.xmax = rectf.xmax + 0.5; /* filter data */ - filter= (ACTFILTER_VISIBLE | ACTFILTER_IPOKEYS); + if (datatype == ACTCONT_GPENCIL) + filter= (ACTFILTER_VISIBLE); + else + filter= (ACTFILTER_VISIBLE | ACTFILTER_IPOKEYS); actdata_filter(&act_data, filter, data, datatype); /* Now set the flags */ - for (ale= act_data.first; ale; ale= ale->next) + for (ale= act_data.first; ale; ale= ale->next) { borderselect_ipo_key(ale->key_data, rectf.xmin, rectf.xmax, select_mode); + } /* Cleanup */ BLI_freelistN(&act_data); @@ -3058,19 +3281,23 @@ void selectkeys_leftright (short leftright, short select_mode) } /* filter data */ - filter= (ACTFILTER_VISIBLE | ACTFILTER_IPOKEYS); + if (datatype == ACTCONT_GPENCIL) + filter= (ACTFILTER_VISIBLE); + else + filter= (ACTFILTER_VISIBLE | ACTFILTER_IPOKEYS); actdata_filter(&act_data, filter, data, datatype); /* select keys on the side where most data occurs */ for (ale= act_data.first; ale; ale= ale->next) { - if(NLA_ACTION_SCALED && datatype==ACTCONT_ACTION) { + if (NLA_ACTION_SCALED && datatype==ACTCONT_ACTION) { actstrip_map_ipo_keys(OBACT, ale->key_data, 0, 1); borderselect_ipo_key(ale->key_data, min, max, SELECT_ADD); actstrip_map_ipo_keys(OBACT, ale->key_data, 1, 1); } - else { + else if (ale->type == ACTTYPE_GPLAYER) + borderselect_gplayer_frames(ale->data, min, max, SELECT_ADD); + else borderselect_ipo_key(ale->key_data, min, max, SELECT_ADD); - } } /* Cleanup */ @@ -3108,7 +3335,10 @@ void nextprev_action_keyframe (short dir) return; /* get list of keyframes that can be used (in global-time) */ - filter= (ACTFILTER_VISIBLE | ACTFILTER_IPOKEYS); + if (datatype == ACTCONT_GPENCIL) + filter= (ACTFILTER_VISIBLE); + else + filter= (ACTFILTER_VISIBLE | ACTFILTER_IPOKEYS); actdata_filter(&act_data, filter, data, datatype); for (ale= act_data.first; ale; ale= ale->next) { @@ -3117,6 +3347,8 @@ void nextprev_action_keyframe (short dir) make_cfra_list(ale->key_data, &elems); actstrip_map_ipo_keys(OBACT, ale->key_data, 1, 1); } + else if (ale->type == ACTTYPE_GPLAYER) + gplayer_make_cfra_list(ale->key_data, &elems, 0); else make_cfra_list(ale->key_data, &elems); } @@ -3199,11 +3431,20 @@ void column_select_action_keys (int mode) /* build list of columns */ switch (mode) { case 1: /* list of selected keys */ - filter= (ACTFILTER_VISIBLE | ACTFILTER_IPOKEYS); - actdata_filter(&act_data, filter, data, datatype); - - for (ale= act_data.first; ale; ale= ale->next) - make_sel_cfra_list(ale->key_data, &elems); + if (datatype == ACTCONT_GPENCIL) { + filter= (ACTFILTER_VISIBLE); + actdata_filter(&act_data, filter, data, datatype); + + for (ale= act_data.first; ale; ale= ale->next) + gplayer_make_cfra_list(ale->data, &elems, 1); + } + else { + filter= (ACTFILTER_VISIBLE | ACTFILTER_IPOKEYS); + actdata_filter(&act_data, filter, data, datatype); + + for (ale= act_data.first; ale; ale= ale->next) + make_sel_cfra_list(ale->key_data, &elems); + } BLI_freelistN(&act_data); break; @@ -3231,19 +3472,34 @@ void column_select_action_keys (int mode) /* loop through all of the keys and select additional keyframes * based on the keys found to be selected above */ - filter= (ACTFILTER_VISIBLE | ACTFILTER_ONLYICU); + if (datatype == ACTCONT_GPENCIL) + filter= (ACTFILTER_VISIBLE); + else + filter= (ACTFILTER_VISIBLE | ACTFILTER_ONLYICU); actdata_filter(&act_data, filter, data, datatype); for (ale= act_data.first; ale; ale= ale->next) { for (ce= elems.first; ce; ce= ce->next) { - for (icu= ale->key_data; icu; icu= icu->next) { - BezTriple *bezt; - int verts = 0; + /* select elements with frame number matching cfraelem */ + if (ale->type == ACTTYPE_GPLAYER) { + bGPDlayer *gpl= (bGPDlayer *)ale->data; + bGPDframe *gpf; - for (bezt=icu->bezt; verts<icu->totvert; bezt++, verts++) { - if (bezt) { - if( (int)(ce->cfra) == (int)(bezt->vec[1][0]) ) - bezt->f2 |= 1; + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + if ( (int)ce->cfra == gpf->framenum ) + gpf->flag |= GP_FRAME_SELECT; + } + } + else { + for (icu= ale->key_data; icu; icu= icu->next) { + BezTriple *bezt; + int verts = 0; + + for (bezt=icu->bezt; verts<icu->totvert; bezt++, verts++) { + if (bezt) { + if( (int)(ce->cfra) == (int)(bezt->vec[1][0]) ) + bezt->f2 |= 1; + } } } } @@ -3272,7 +3528,7 @@ void borderselect_actionchannels (void) /* determine what type of data we are operating on */ data = get_action_context(&datatype); if (data == NULL) return; - if (datatype != ACTCONT_ACTION) return; + if (ELEM(datatype, ACTCONT_ACTION, ACTCONT_GPENCIL)==0) return; /* draw and handle the borderselect stuff (ui) and get the select rect */ if ( (val = get_border(&rect, 3)) ) { @@ -3344,6 +3600,16 @@ void borderselect_actionchannels (void) icu->flag &= ~IPO_SELECT; } break; + case ACTTYPE_GPLAYER: /* grease-pencil layer */ + { + bGPDlayer *gpl = (bGPDlayer *)ale->data; + + if (selectmode == SELECT_ADD) + gpl->flag |= GP_LAYER_SELECT; + else + gpl->flag &= ~GP_LAYER_SELECT; + } + break; } /* select action-channel 'owner' */ @@ -3460,6 +3726,9 @@ void borderselect_action (void) borderselect_ipo_key(conchan->ipo, rectf.xmin, rectf.xmax, selectmode); } } + else if (ale->type == ACTTYPE_GPLAYER) { + borderselect_gplayer_frames(ale->data, rectf.xmin, rectf.xmax, selectmode); + } break; case ACTEDIT_BORDERSEL_CHA: /* all in channel(s) */ if (!((ymax < rectf.ymin) || (ymin > rectf.ymax))) { @@ -3481,6 +3750,9 @@ void borderselect_action (void) select_ipo_bezier_keys(conchan->ipo, selectmode); } } + else if (ale->type == ACTTYPE_GPLAYER) { + select_gpencil_frames(ale->data, selectmode); + } } break; default: /* any keyframe inside region defined by region */ @@ -3503,6 +3775,9 @@ void borderselect_action (void) borderselect_ipo_key(conchan->ipo, rectf.xmin, rectf.xmax, selectmode); } } + else if (ale->type == ACTTYPE_GPLAYER) { + borderselect_gplayer_frames(ale->data, rectf.xmin, rectf.xmax, selectmode); + } } } @@ -3533,6 +3808,8 @@ static void mouse_action (int selectmode) bActionChannel *achan= NULL; bConstraintChannel *conchan= NULL; IpoCurve *icu= NULL; + bGPdata *gpd = NULL; + bGPDlayer *gpl = NULL; TimeMarker *marker, *pmarker; void *act_channel; @@ -3543,6 +3820,7 @@ static void mouse_action (int selectmode) data = get_action_context(&datatype); if (data == NULL) return; if (datatype == ACTCONT_ACTION) act= (bAction *)data; + if (datatype == ACTCONT_GPENCIL) gpd= (bGPdata *)data; act_channel= get_nearest_action_key(&selx, &sel, &act_type, &achan); marker= find_nearest_marker(SCE_MARKERS, 1); @@ -3615,6 +3893,9 @@ static void mouse_action (int selectmode) case ACTTYPE_GROUP: agrp= (bActionGroup *)act_channel; break; + case ACTTYPE_GPLAYER: + gpl= (bGPDlayer *)act_channel; + break; default: return; } @@ -3638,6 +3919,13 @@ static void mouse_action (int selectmode) set_active_actiongroup(act, agrp, 1); } } + else if (datatype == ACTCONT_GPENCIL) { + deselect_action_channels(0); + + /* Highlight gpencil layer */ + gpl->flag |= GP_LAYER_SELECT; + gpencil_layer_setactive(gpd, gpl); + } } if (icu) @@ -3654,6 +3942,8 @@ static void mouse_action (int selectmode) select_ipo_key(conchan->ipo, selx, selectmode); } } + else if (gpl) + select_gpencil_frame(gpl, selx, selectmode); std_rmouse_transform(transform_action_keys); @@ -3670,7 +3960,7 @@ static void mouse_action (int selectmode) static void mouse_actionchannels (short mval[]) { bAction *act= G.saction->action; - void *data, *act_channel; + void *data, *act_channel, *channel_owner; short datatype, chantype; /* determine what type of data we are operating on */ @@ -3678,7 +3968,7 @@ static void mouse_actionchannels (short mval[]) if (data == NULL) return; /* get channel to work on */ - act_channel= get_nearest_act_channel(mval, &chantype); + act_channel= get_nearest_act_channel(mval, &chantype, &channel_owner); /* action to take depends on what channel we've got */ switch (chantype) { @@ -3816,6 +4106,39 @@ static void mouse_actionchannels (short mval[]) } } break; + case ACTTYPE_GPDATABLOCK: + { + bGPdata *gpd= (bGPdata *)act_channel; + + /* toggle expand */ + gpd->flag ^= GP_DATA_EXPAND; + } + break; + case ACTTYPE_GPLAYER: + { + bGPdata *gpd= (bGPdata *)channel_owner; + bGPDlayer *gpl= (bGPDlayer *)act_channel; + + if (mval[0] >= (NAMEWIDTH-16)) { + /* toggle lock */ + gpl->flag ^= GP_LAYER_LOCKED; + } + else if (mval[0] >= (NAMEWIDTH-32)) { + /* toggle hide */ + gpl->flag ^= GP_LAYER_HIDE; + } + else { + /* select/deselect */ + if (G.qual & LR_SHIFTKEY) { + select_gplayer_channel(gpd, gpl, SELECT_INVERT); + } + else { + deselect_gpencil_layers(data, 0); + select_gplayer_channel(gpd, gpl, SELECT_INVERT); + } + } + } + break; default: return; } @@ -4482,7 +4805,7 @@ void winqreadactionspace(ScrArea *sa, void *spacedata, BWinEvent *evt) case RIGHTMOUSE: /* Clicking in the channel area */ if ((G.v2d->mask.xmin) && (mval[0] < NAMEWIDTH)) { - if (datatype == ACTCONT_ACTION) { + if (ELEM(datatype, ACTCONT_ACTION, ACTCONT_GPENCIL)) { /* mouse is over action channels */ if (G.qual == LR_CTRLKEY) numbuts_action(); @@ -4832,8 +5155,12 @@ void winqreadactionspace(ScrArea *sa, void *spacedata, BWinEvent *evt) case DELKEY: case XKEY: if (okee("Erase selected")) { - if (mval[0] < NAMEWIDTH) - delete_action_channels(); + if (mval[0] < NAMEWIDTH) { + if (datatype == ACTCONT_ACTION) + delete_action_channels(); + else if (datatype == ACTCONT_GPENCIL) + delete_gpencil_layers(); + } else delete_action_keys(); diff --git a/source/blender/src/editaction_gpencil.c b/source/blender/src/editaction_gpencil.c new file mode 100644 index 00000000000..14269080b1f --- /dev/null +++ b/source/blender/src/editaction_gpencil.c @@ -0,0 +1,548 @@ +/** + * $Id: editaction_gpencil.c 14881 2008-05-18 10:41:42Z aligorith $ + * + * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2008, Blender Foundation + * This is a new part of Blender + * + * Contributor(s): Joshua Leung + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stddef.h> +#include <math.h> + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "MEM_guardedalloc.h" + +#include "BMF_Api.h" + +#include "BLI_arithb.h" +#include "BLI_blenlib.h" + +#include "DNA_listBase.h" +#include "DNA_action_types.h" +#include "DNA_gpencil_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_space_types.h" +#include "DNA_userdef_types.h" +#include "DNA_view3d_types.h" +#include "DNA_view2d_types.h" + +#include "BKE_global.h" +#include "BKE_utildefines.h" +#include "BKE_blender.h" +#include "BKE_ipo.h" + +#include "BIF_gl.h" +#include "BIF_glutil.h" +#include "BIF_butspace.h" +#include "BIF_graphics.h" +#include "BIF_interface.h" +#include "BIF_mywindow.h" +#include "BIF_resources.h" +#include "BIF_space.h" +#include "BIF_screen.h" +#include "BIF_toolbox.h" +#include "BIF_toets.h" + +#include "BIF_editaction.h" +#include "BSE_editaction_types.h" + +#include "BDR_gpencil.h" +#include "BIF_drawgpencil.h" + +#include "BSE_drawipo.h" +#include "BSE_headerbuttons.h" +#include "BSE_time.h" +#include "BSE_view.h" + +#include "blendef.h" +#include "butspace.h" + +#include "PIL_time.h" /* sleep */ +#include "mydevice.h" + +/* ***************************************** */ +/* NOTE ABOUT THIS FILE: + * This file contains code for editing Grease Pencil data in the Action Editor + * as a 'keyframes', so that a user can adjust the timing of Grease Pencil drawings. + * Therefore, this file mostly contains functions for selecting Grease-Pencil frames. + */ +/* ***************************************** */ +/* Generics - Loopers */ + +/* Loops over the gp-frames for a gp-layer, and applies the given callback */ +short gplayer_frames_looper (bGPDlayer *gpl, short (*gpf_cb)(bGPDframe *)) +{ + bGPDframe *gpf; + + /* error checker */ + if (gpl == NULL) + return 0; + + /* do loop */ + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + /* execute callback */ + if (gpf_cb(gpf)) + return 1; + } + + /* nothing to return */ + return 0; +} + +/* ****************************************** */ +/* Data Conversion Tools */ + +/* make a listing all the gp-frames in a layer as cfraelems */ +void gplayer_make_cfra_list (bGPDlayer *gpl, ListBase *elems, short onlysel) +{ + bGPDframe *gpf; + CfraElem *ce; + + /* error checking */ + if (ELEM(NULL, gpl, elems)) + return; + + /* loop through gp-frames, adding */ + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + if ((onlysel == 0) || (gpf->flag & GP_FRAME_SELECT)) { + ce= MEM_callocN(sizeof(CfraElem), "CfraElem"); + + ce->cfra= gpf->framenum; + ce->sel= (gpf->flag & GP_FRAME_SELECT) ? 1 : 0; + + BLI_addtail(elems, ce); + } + } +} + +/* ***************************************** */ +/* Selection Tools */ + +/* check if one of the frames in this layer is selected */ +short is_gplayer_frame_selected (bGPDlayer *gpl) +{ + bGPDframe *gpf; + + /* error checking */ + if (gpl == NULL) + return 0; + + /* stop at the first one found */ + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + if (gpf->flag & GP_FRAME_SELECT) + return 1; + } + + /* not found */ + return 0; +} + +/* helper function - select gp-frame based on SELECT_* mode */ +static void gpframe_select (bGPDframe *gpf, short select_mode) +{ + switch (select_mode) { + case SELECT_ADD: + gpf->flag |= GP_FRAME_SELECT; + break; + case SELECT_SUBTRACT: + gpf->flag &= ~GP_FRAME_SELECT; + break; + case SELECT_INVERT: + gpf->flag ^= GP_FRAME_SELECT; + break; + } +} + +/* set all/none/invert select (like above, but with SELECT_* modes) */ +void select_gpencil_frames (bGPDlayer *gpl, short select_mode) +{ + bGPDframe *gpf; + + /* error checking */ + if (gpl == NULL) + return; + + /* handle according to mode */ + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + gpframe_select(gpf, select_mode); + } +} + +/* set all/none/invert select */ +void set_gplayer_frame_selection (bGPDlayer *gpl, short mode) +{ + /* error checking */ + if (gpl == NULL) + return; + + /* convert mode to select_mode */ + switch (mode) { + case 2: + mode= SELECT_INVERT; + break; + case 1: + mode= SELECT_ADD; + break; + case 0: + mode= SELECT_SUBTRACT; + break; + default: + return; + } + + /* now call the standard function */ + select_gpencil_frames (gpl, mode); +} + +void select_gpencil_frame (bGPDlayer *gpl, int selx, short select_mode) +{ + bGPDframe *gpf; + + /* search through frames for a match */ + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + if (gpf->framenum == selx) + gpframe_select(gpf, select_mode); + } +} + +void borderselect_gplayer_frames (bGPDlayer *gpl, float min, float max, short select_mode) +{ + bGPDframe *gpf; + + /* only select those frames which are in bounds */ + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + if (IN_RANGE(gpf->framenum, min, max)) + gpframe_select(gpf, select_mode); + } +} + + +/* De-selects or inverts the selection of Layers for a grease-pencil block + * mode: 0 = default behaviour (select all), 1 = test if (de)select all, 2 = invert all + */ +void deselect_gpencil_layers (void *data, short mode) +{ + ListBase act_data = {NULL, NULL}; + bActListElem *ale; + int filter, sel=1; + + /* filter data */ + filter= ACTFILTER_VISIBLE; + actdata_filter(&act_data, filter, data, ACTCONT_GPENCIL); + + /* See if we should be selecting or deselecting */ + if (mode == 1) { + for (ale= act_data.first; ale; ale= ale->next) { + if (sel == 0) + break; + + if (ale->flag & GP_LAYER_SELECT) + sel= 0; + } + } + else + sel= 0; + + /* Now set the flags */ + for (ale= act_data.first; ale; ale= ale->next) { + bGPDlayer *gpl= (bGPDlayer *)ale->data; + + if (mode == 2) + gpl->flag ^= GP_LAYER_SELECT; + else if (sel) + gpl->flag |= GP_LAYER_SELECT; + else + gpl->flag &= ~GP_LAYER_SELECT; + + gpl->flag &= ~GP_LAYER_ACTIVE; + } + + /* Cleanup */ + BLI_freelistN(&act_data); +} + +/* ***************************************** */ +/* Frame Editing Tools */ + +void delete_gpencil_layers (void) +{ + ListBase act_data = {NULL, NULL}; + bActListElem *ale, *next; + void *data; + short datatype; + int filter; + + /* determine what type of data we are operating on */ + data = get_action_context(&datatype); + if (data == NULL) return; + if (datatype != ACTCONT_GPENCIL) return; + + /* filter data */ + filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_CHANNELS | ACTFILTER_SEL); + actdata_filter(&act_data, filter, data, datatype); + + /* clean up grease-pencil layers */ + for (ale= act_data.first; ale; ale= next) { + bGPdata *gpd= (bGPdata *)ale->owner; + bGPDlayer *gpl= (bGPDlayer *)ale->data; + next= ale->next; + + /* free layer and its data */ + if (SEL_GPL(gpl)) { + free_gpencil_frames(gpl); + BLI_freelinkN(&gpd->layers, gpl); + } + + /* free temp memory */ + BLI_freelinkN(&act_data, ale); + } + + BIF_undo_push("Delete GPencil Layers"); + allspace(REDRAWVIEW3D, 0); + allqueue(REDRAWACTION, 0); +} + +/* Delete selected frames */ +void delete_gplayer_frames (bGPDlayer *gpl) +{ + bGPDframe *gpf, *gpfn; + + /* error checking */ + if (gpl == NULL) + return; + + /* check for frames to delete */ + for (gpf= gpl->frames.first; gpf; gpf= gpfn) { + gpfn= gpf->next; + + if (gpf->flag & GP_FRAME_SELECT) + gpencil_layer_delframe(gpl, gpf); + } +} + +/* Duplicate selected frames from given gp-layer */ +void duplicate_gplayer_frames (bGPDlayer *gpl) +{ + bGPDframe *gpf, *gpfn; + + /* error checking */ + if (gpl == NULL) + return; + + /* duplicate selected frames */ + for (gpf= gpl->frames.first; gpf; gpf= gpfn) { + gpfn= gpf->next; + + /* duplicate this frame */ + if (gpf->flag & GP_FRAME_SELECT) { + bGPDframe *gpfd; + bGPDstroke *gps; + + /* duplicate frame, and deselect self */ + gpfd= MEM_dupallocN(gpf); + gpf->flag &= ~GP_FRAME_SELECT; + + /* duplicate list of strokes too */ + duplicatelist(&gpfd->strokes, &gpf->strokes); + + /* dupalloc only makes another copy of mem, but doesn't adjust pointers */ + for (gps= gpfd->strokes.first; gps; gps= gps->next) { + gps->points= MEM_dupallocN(gps->points); + } + + BLI_insertlinkafter(&gpl->frames, gpf, gpfd); + } + } +} + +/* -------------------------------------- */ +/* Snap Tools */ + +static short snap_gpf_nearest (bGPDframe *gpf) +{ + if (gpf->flag & GP_FRAME_SELECT) + gpf->framenum= (int)(floor(gpf->framenum+0.5)); + return 0; +} + +static short snap_gpf_nearestsec (bGPDframe *gpf) +{ + float secf = FPS; + if (gpf->flag & GP_FRAME_SELECT) + gpf->framenum= (int)(floor(gpf->framenum/secf + 0.5f) * secf); + return 0; +} + +static short snap_gpf_cframe (bGPDframe *gpf) +{ + if (gpf->flag & GP_FRAME_SELECT) + gpf->framenum= (int)CFRA; + return 0; +} + +static short snap_gpf_nearmarker (bGPDframe *gpf) +{ + if (gpf->flag & GP_FRAME_SELECT) + gpf->framenum= (int)find_nearest_marker_time(gpf->framenum); + return 0; +} + + +/* snap selected frames to ... */ +void snap_gplayer_frames (bGPDlayer *gpl, short mode) +{ + switch (mode) { + case 1: /* snap to nearest frame */ + gplayer_frames_looper(gpl, snap_gpf_nearest); + break; + case 2: /* snap to current frame */ + gplayer_frames_looper(gpl, snap_gpf_cframe); + break; + case 3: /* snap to nearest marker */ + gplayer_frames_looper(gpl, snap_gpf_nearmarker); + break; + case 4: /* snap to nearest second */ + gplayer_frames_looper(gpl, snap_gpf_nearestsec); + break; + default: /* just in case */ + gplayer_frames_looper(gpl, snap_gpf_nearest); + break; + } +} + +/* -------------------------------------- */ +/* Mirror Tools */ + +static short mirror_gpf_cframe (bGPDframe *gpf) +{ + float diff; + + if (gpf->flag & GP_FRAME_SELECT) { + diff= ((float)CFRA - gpf->framenum); + gpf->framenum= ((float)CFRA + diff); + } + + return 0; +} + +static short mirror_gpf_yaxis (bGPDframe *gpf) +{ + float diff; + + if (gpf->flag & GP_FRAME_SELECT) { + diff= (0.0f - gpf->framenum); + gpf->framenum= (0.0f + diff); + } + + return 0; +} + +static short mirror_gpf_xaxis (bGPDframe *gpf) +{ + float diff; + + if (gpf->flag & GP_FRAME_SELECT) { + diff= (0.0f - gpf->framenum); + gpf->framenum= (0.0f + diff); + } + + return 0; +} + +static short mirror_gpf_marker (bGPDframe *gpf) +{ + static TimeMarker *marker; + static short initialised = 0; + float diff; + + /* In order for this mirror function to work without + * any extra arguments being added, we use the case + * of bezt==NULL to denote that we should find the + * marker to mirror over. The static pointer is safe + * to use this way, as it will be set to null after + * each cycle in which this is called. + */ + + if (gpf) { + /* mirroring time */ + if ((gpf->flag & GP_FRAME_SELECT) && (marker)) { + diff= (marker->frame - gpf->framenum); + gpf->framenum= (marker->frame + diff); + } + } + else { + /* initialisation time */ + if (initialised) { + /* reset everything for safety */ + marker = NULL; + initialised = 0; + } + else { + /* try to find a marker */ + for (marker= G.scene->markers.first; marker; marker=marker->next) { + if (marker->flag & SELECT) { + initialised = 1; + break; + } + } + + if (initialised == 0) + marker = NULL; + } + } + + return 0; +} + + +/* mirror selected gp-frames on... */ +void mirror_gplayer_frames (bGPDlayer *gpl, short mode) +{ + switch (mode) { + case 1: /* mirror over current frame */ + gplayer_frames_looper(gpl, mirror_gpf_cframe); + break; + case 2: /* mirror over frame 0 */ + gplayer_frames_looper(gpl, mirror_gpf_yaxis); + break; + case 3: /* mirror over value 0 */ + gplayer_frames_looper(gpl, mirror_gpf_xaxis); + break; + case 4: /* mirror over marker */ + mirror_gpf_marker(NULL); + gplayer_frames_looper(gpl, mirror_gpf_marker); + mirror_gpf_marker(NULL); + break; + default: /* just in case */ + gplayer_frames_looper(gpl, mirror_gpf_yaxis); + break; + } +} + +/* ***************************************** */ diff --git a/source/blender/src/editarmature.c b/source/blender/src/editarmature.c index d2557d9050f..80a01bc5cce 100644 --- a/source/blender/src/editarmature.c +++ b/source/blender/src/editarmature.c @@ -1033,87 +1033,6 @@ static void *get_nearest_bone (short findunsel) return NULL; } -/* used by posemode and editmode */ -void select_bone_parent (void) -{ - Object *ob; - bArmature *arm; - - /* get data */ - if (G.obedit) - ob= G.obedit; - else if (OBACT) - ob= OBACT; - else - return; - arm= (bArmature *)ob->data; - - /* determine which mode armature is in */ - if ((!G.obedit) && (ob->flag & OB_POSEMODE)) { - /* deal with pose channels */ - /* channels are sorted on dependency, so the loop below won't result in a flood-select */ - bPoseChannel *pchan=NULL; - - for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - /* check if bone in original selection */ - if (pchan->bone->flag & BONE_SELECTED) { - bPoseChannel *chanpar= pchan->parent; - - /* check if any parent */ - if ((chanpar) && ((chanpar->bone->flag & BONE_SELECTED)==0)) { - chanpar->bone->flag |= BONE_SELECTED; - select_actionchannel_by_name (ob->action, pchan->name, 1); - } - } - } - } - else if (G.obedit) { - /* deal with editbones */ - EditBone *curbone, *parbone, *parpar; - - /* prevent floods */ - for (curbone= G.edbo.first; curbone; curbone= curbone->next) - curbone->temp= NULL; - - for (curbone= G.edbo.first; curbone; curbone= curbone->next) { - /* check if bone selected */ - if ((curbone->flag & BONE_SELECTED) && curbone->temp==NULL) { - parbone= curbone->parent; - - /* check if any parent */ - if ((parbone) && ((parbone->flag & BONE_SELECTED)==0)) { - /* select the parent bone */ - parbone->flag |= (BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); - - /* check if parent has parent */ - parpar= parbone->parent; - - if ((parpar) && (parbone->flag & BONE_CONNECTED)) { - parpar->flag |= BONE_TIPSEL; - } - /* tag this bone to not flood selection */ - parbone->temp= parbone; - } - } - } - - /* to be sure... */ - for (curbone= G.edbo.first; curbone; curbone= curbone->next) - curbone->temp= NULL; - - } - - /* undo + redraw pushes */ - countall(); // flushes selection! - - allqueue (REDRAWVIEW3D, 0); - allqueue (REDRAWBUTSEDIT, 0); - allqueue(REDRAWBUTSOBJECT, 0); - allqueue(REDRAWOOPS, 0); - - BIF_undo_push("Select Parent"); -} - /* helper for setflag_sel_bone() */ static void bone_setflag (int *bone, int flag, short mode) { @@ -1139,6 +1058,89 @@ static void bone_setflag (int *bone, int flag, short mode) } } +/* Get the first available child of an editbone */ +static EditBone *editbone_get_child(EditBone *pabone, short use_visibility) +{ + Object *ob; + bArmature *arm; + EditBone *curbone, *chbone=NULL; + + if (!G.obedit) return NULL; + else ob= G.obedit; + arm= (bArmature *)ob->data; + + for (curbone= G.edbo.first; curbone; curbone= curbone->next) { + if (curbone->parent == pabone) { + if (use_visibility) { + if ((arm->layer & curbone->layer) && !(pabone->flag & BONE_HIDDEN_A)) + chbone = curbone; + } + else + chbone = curbone; + } + } + + return chbone; +} + +void armature_select_hierarchy(short direction, short add_to_sel) +{ + Object *ob; + bArmature *arm; + EditBone *curbone, *pabone, *chbone; + + if (!G.obedit) return; + else ob= G.obedit; + arm= (bArmature *)ob->data; + + for (curbone= G.edbo.first; curbone; curbone= curbone->next) { + if (arm->layer & curbone->layer) { + if (curbone->flag & (BONE_ACTIVE)) { + if (direction == BONE_SELECT_PARENT) { + if (curbone->parent == NULL) continue; + else pabone = curbone->parent; + + if ((arm->layer & pabone->layer) && !(pabone->flag & BONE_HIDDEN_A)) { + pabone->flag |= (BONE_ACTIVE|BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + if (pabone->parent) pabone->parent->flag |= BONE_TIPSEL; + + if (!add_to_sel) curbone->flag &= ~(BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + curbone->flag &= ~BONE_ACTIVE; + break; + } + + } else { // BONE_SELECT_CHILD + chbone = editbone_get_child(curbone, 1); + if (chbone == NULL) continue; + + if ((arm->layer & chbone->layer) && !(chbone->flag & BONE_HIDDEN_A)) { + chbone->flag |= (BONE_ACTIVE|BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL); + + if (!add_to_sel) { + curbone->flag &= ~(BONE_SELECTED|BONE_ROOTSEL); + if (curbone->parent) curbone->parent->flag &= ~BONE_TIPSEL; + } + curbone->flag &= ~BONE_ACTIVE; + break; + } + } + } + } + } + + countall(); // flushes selection! + + allqueue (REDRAWVIEW3D, 0); + allqueue (REDRAWBUTSEDIT, 0); + allqueue (REDRAWBUTSOBJECT, 0); + allqueue (REDRAWOOPS, 0); + + if (direction==BONE_SELECT_PARENT) + BIF_undo_push("Select edit bone parent"); + if (direction==BONE_SELECT_CHILD) + BIF_undo_push("Select edit bone child"); +} + /* used by posemode and editmode */ void setflag_armature (short mode) { @@ -2709,6 +2711,32 @@ void show_all_armature_bones(void) BIF_undo_push("Reveal Bones"); } +/* Sets editmode transform locks for bones (adds if lock==1, clears otherwise) */ +void set_locks_armature_bones(short lock) +{ + bArmature *arm= G.obedit->data; + EditBone *ebone; + + for (ebone = G.edbo.first; ebone; ebone=ebone->next) { + if (arm->layer & ebone->layer) { + if (ebone->flag & BONE_SELECTED) { + if (lock) + ebone->flag |= BONE_EDITMODE_LOCKED; + else + ebone->flag &= ~BONE_EDITMODE_LOCKED; + } + } + } + countall(); + allqueue(REDRAWVIEW3D, 0); + allqueue(REDRAWBUTSEDIT, 0); + + if (lock) + BIF_undo_push("Lock Bones"); + else + BIF_undo_push("Unlock Bones"); +} + /* check for null, before calling! */ static void bone_connect_to_existing_parent(EditBone *bone) { diff --git a/source/blender/src/editimasel.c b/source/blender/src/editimasel.c index 67e10d771e0..97ddc2e0f1d 100644 --- a/source/blender/src/editimasel.c +++ b/source/blender/src/editimasel.c @@ -1076,6 +1076,12 @@ void winqreadimaselspace(ScrArea *sa, void *spacedata, BWinEvent *evt) toggle_blockhandler(sa, IMASEL_HANDLER_IMAGE, UI_PNL_UNSTOW); scrarea_queue_winredraw(sa); break; + case HKEY: + simasel->flag ^= FILE_HIDE_DOT; + BIF_filelist_free(simasel->files); + do_draw= 1; + do_headdraw= 1; + break; case PKEY: if(G.qual & LR_SHIFTKEY) { extern char bprogname[]; /* usiblender.c */ diff --git a/source/blender/src/editipo.c b/source/blender/src/editipo.c index c5dd41e16d5..63c301658f2 100644 --- a/source/blender/src/editipo.c +++ b/source/blender/src/editipo.c @@ -82,6 +82,7 @@ #include "BKE_group.h" #include "BKE_ipo.h" #include "BKE_key.h" +#include "BKE_main.h" #include "BKE_material.h" #include "BKE_particle.h" #include "BKE_texture.h" @@ -933,6 +934,9 @@ static void make_editipo(void) ob->ipowin= ID_TE; make_texture_editipo(G.sipo); } + else if(G.scene->world && give_current_world_texture()) { + make_texture_editipo(G.sipo); + } } else if(G.sipo->blocktype==ID_CA) { if (ob) { @@ -1120,6 +1124,11 @@ static void get_ipo_context(short blocktype, ID **from, Ipo **ipo, char *actname *from= (ID *)tex; if(tex) *ipo= tex->ipo; } + else if(G.scene->world) { + Tex *tex= give_current_world_texture(); + *from= (ID *)tex; + if(tex) *ipo= tex->ipo; + } } else if(blocktype==ID_MA) { if(ob) { @@ -6002,4 +6011,4 @@ void move_to_frame(void) } } BIF_undo_push("Set frame to selected Ipo vertex"); -} +}
\ No newline at end of file diff --git a/source/blender/src/editmesh.c b/source/blender/src/editmesh.c index 9eef61e11f9..188f7476728 100644 --- a/source/blender/src/editmesh.c +++ b/source/blender/src/editmesh.c @@ -340,8 +340,9 @@ void free_editface(EditFace *efa) #endif EM_remove_selection(efa, EDITFACE); - if (G.editMesh->act_face==efa) - EM_set_actFace(NULL); + if (G.editMesh->act_face==efa) { + EM_set_actFace( G.editMesh->faces.first == efa ? NULL : G.editMesh->faces.first); + } CustomData_em_free_block(&G.editMesh->fdata, &efa->data); if(efa->fast==0) @@ -1059,7 +1060,11 @@ void make_editMesh() EM_hide_reset(); /* sets helper flags which arent saved */ EM_fgon_flags(); - + + if (EM_get_actFace(0)==NULL) { + EM_set_actFace( G.editMesh->faces.first ); /* will use the first face, this is so we alwats have an active face */ + } + /* vertex coordinates change with cache edit, need to recalc */ if(cacheedit) recalc_editnormals(); diff --git a/source/blender/src/editnode.c b/source/blender/src/editnode.c index 4c7334c55e0..98f4f1bb46f 100644 --- a/source/blender/src/editnode.c +++ b/source/blender/src/editnode.c @@ -82,6 +82,7 @@ #include "BLI_storage_types.h" #include "BDR_editobject.h" +#include "BDR_gpencil.h" #include "RE_pipeline.h" #include "IMB_imbuf_types.h" @@ -2305,6 +2306,7 @@ static int node_uiDoBlocks(ScrArea *sa, short event) SpaceNode *snode= sa->spacedata.first; ListBase *lb= &sa->uiblocks; ListBase listb= *lb; + uiBlock *block; bNode *node; rctf rect; void *prev, *next; @@ -2319,13 +2321,36 @@ static int node_uiDoBlocks(ScrArea *sa, short event) return UI_NOTHING; } + /* evil hack: try to do grease-pencil floating panel (like for nodes) */ + block= uiGetBlock("nodes_panel_gpencil", sa); + if (block) { + /* try to process events here... if failed, just carry on */ + /* when there's menus, the prev pointer becomes zero! */ + prev= ((struct Link *)block)->prev; + next= ((struct Link *)block)->next; + ((struct Link *)block)->prev= NULL; + ((struct Link *)block)->next= NULL; + + lb->first= lb->last= block; + retval= uiDoBlocks(lb, event, 1); + + ((struct Link *)block)->prev= prev; + ((struct Link *)block)->next= next; + + *lb= listb; + + /* if something happened, get the heck outta here */ + if (retval != UI_NOTHING) + return retval; + } + + rect.xmin -= 2.0f; rect.ymin -= 2.0f; rect.xmax = rect.xmin + 4.0f; rect.ymax = rect.ymin + 4.0f; for(node= snode->edittree->nodes.first; node; node= node->next) { - uiBlock *block; char str[32]; /* retreive unique block name, see also drawnode.c */ @@ -2369,14 +2394,16 @@ void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt) if(snode->nodetree==NULL) return; if(val) { - - if( node_uiDoBlocks(sa, event)!=UI_NOTHING ) event= 0; - + if( node_uiDoBlocks(sa, event)!=UI_NOTHING ) event= 0; + fromlib= (snode->id && snode->id->lib); switch(event) { case LEFTMOUSE: - if(fromlib) { + if(gpencil_do_paint(sa, L_MOUSE)) { + return; + } + else if(fromlib) { if(node_mouse_groupheader(snode)==0) node_mouse_select(snode, event); } @@ -2394,7 +2421,10 @@ void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt) break; case RIGHTMOUSE: - if(find_indicated_socket(snode, &actnode, &actsock, SOCK_IN)) { + if(gpencil_do_paint(sa, R_MOUSE)) { + return; + } + else if(find_indicated_socket(snode, &actnode, &actsock, SOCK_IN)) { if(actsock->flag & SOCK_SEL) { snode->edittree->selin= NULL; actsock->flag&= ~SOCK_SEL; @@ -2541,8 +2571,13 @@ void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt) break; case DELKEY: case XKEY: - if(fromlib) fromlib= -1; - else node_delete(snode); + if(G.qual==LR_ALTKEY) { + gpencil_delete_menu(); + } + else { + if(fromlib) fromlib= -1; + else node_delete(snode); + } break; } } diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c index 2e5785eaab8..cbf7691754d 100644 --- a/source/blender/src/editobject.c +++ b/source/blender/src/editobject.c @@ -2760,7 +2760,7 @@ void special_editmenu(void) DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA); } else if(G.obedit->type==OB_ARMATURE) { - nr= pupmenu("Specials%t|Subdivide %x1|Subdivide Multi%x2|Flip Left-Right Names%x3|%l|AutoName Left-Right%x4|AutoName Front-Back%x5|AutoName Top-Bottom%x6"); + nr= pupmenu("Specials%t|Subdivide %x1|Subdivide Multi%x2|Flip Left-Right Names%x3|%l|AutoName Left-Right%x4|AutoName Front-Back%x5|AutoName Top-Bottom%x6|%l|Lock%x7|Unlock%x8"); if(nr==1) subdivide_armature(1); if(nr==2) { @@ -2773,6 +2773,10 @@ void special_editmenu(void) else if(ELEM3(nr, 4, 5, 6)) { armature_autoside_names(nr-4); } + else if(nr==7) + set_locks_armature_bones(1); + else if(nr==8) + set_locks_armature_bones(0); } else if(G.obedit->type==OB_LATTICE) { static float weight= 1.0f; @@ -3502,6 +3506,17 @@ void copy_attr(short event) base->object->damping= ob->damping; base->object->rdamping= ob->rdamping; } + else if(event==11) { /* all physical attributes */ + base->object->gameflag = ob->gameflag; + base->object->inertia = ob->inertia; + base->object->formfactor = ob->formfactor; + base->object->damping= ob->damping; + base->object->rdamping= ob->rdamping; + base->object->mass= ob->mass; + if (ob->gameflag & OB_BOUNDS) { + base->object->boundtype = ob->boundtype; + } + } else if(event==17) { /* tex space */ copy_texture_space(base->object, ob); } @@ -3688,7 +3703,7 @@ void copy_attr_menu() * view3d_edit_object_copyattrmenu() and in toolbox.c */ - strcpy(str, "Copy Attributes %t|Location%x1|Rotation%x2|Size%x3|Draw Options%x4|Time Offset%x5|Dupli%x6|%l|Mass%x7|Damping%x8|Properties%x9|Logic Bricks%x10|Protected Transform%x29|%l"); + strcpy(str, "Copy Attributes %t|Location%x1|Rotation%x2|Size%x3|Draw Options%x4|Time Offset%x5|Dupli%x6|%l|Mass%x7|Damping%x8|All Physical Attributes%x11|Properties%x9|Logic Bricks%x10|Protected Transform%x29|%l"); strcat (str, "|Object Constraints%x22"); strcat (str, "|NLA Strips%x26"); @@ -5505,6 +5520,7 @@ void selectlinks(int nr) allqueue(REDRAWDATASELECT, 0); allqueue(REDRAWOOPS, 0); BIF_undo_push("Select linked"); + countall(); } } diff --git a/source/blender/src/editseq.c b/source/blender/src/editseq.c index f9432f8e69a..e9d0b57a166 100644 --- a/source/blender/src/editseq.c +++ b/source/blender/src/editseq.c @@ -122,13 +122,28 @@ Sequence *get_last_seq() if(!_last_seq_init) { Editing *ed; Sequence *seq; + Sequence *l_sel = NULL; + Sequence *l_act = NULL; ed= G.scene->ed; if(!ed) return NULL; - for(seq= ed->seqbasep->first; seq; seq=seq->next) + for(seq= ed->seqbasep->first; seq; seq=seq->next) { + if(seq->flag & SEQ_ACTIVE) + l_act = seq; if(seq->flag & SELECT) - _last_seq= seq; + l_sel = seq; + } + + if (l_act) { + _last_seq = l_act; + } else { + _last_seq = l_sel; + } + + if (_last_seq) { + _last_seq->flag |= SEQ_ACTIVE; + } _last_seq_init = 1; } @@ -138,12 +153,23 @@ Sequence *get_last_seq() void set_last_seq(Sequence *seq) { + if (_last_seq_init && _last_seq) { + _last_seq->flag &= ~SEQ_ACTIVE; + } + _last_seq = seq; _last_seq_init = 1; + + if (_last_seq) { + _last_seq->flag |= SEQ_ACTIVE; + } } -void clear_last_seq(Sequence *seq) +void clear_last_seq() { + if (_last_seq_init && _last_seq) { + _last_seq->flag &= ~SEQ_ACTIVE; + } _last_seq = NULL; _last_seq_init = 0; } @@ -618,6 +644,7 @@ static int seq_is_parent(Sequence *par, Sequence *seq) static int seq_is_predecessor(Sequence *pred, Sequence *seq) { + if (!pred) return 0; if(pred == seq) return 0; else if(seq_is_parent(pred, seq)) return 1; else if(pred->seq1 && seq_is_predecessor(pred->seq1, seq)) return 1; @@ -2261,6 +2288,8 @@ static Sequence *dupli_seq(Sequence *seq) "handled in duplicate!\nExpect a crash" " now...\n"); } + + seqn->flag &= ~SEQ_ACTIVE; return seqn; } diff --git a/source/blender/src/editview.c b/source/blender/src/editview.c index e3ec69975de..a3fcad7885c 100644 --- a/source/blender/src/editview.c +++ b/source/blender/src/editview.c @@ -298,7 +298,7 @@ int lasso_inside(short mcords[][2], short moves, short sx, short sy) } /* edge version for lasso select. we assume boundbox check was done */ -static int lasso_inside_edge(short mcords[][2], short moves, int x0, int y0, int x1, int y1) +int lasso_inside_edge(short mcords[][2], short moves, int x0, int y0, int x1, int y1) { short v1[2], v2[2]; int a; @@ -371,7 +371,7 @@ static void do_lasso_select_objects(short mcords[][2], short moves, short select } } -static void lasso_select_boundbox(rcti *rect, short mcords[][2], short moves) +void lasso_select_boundbox(rcti *rect, short mcords[][2], short moves) { short a; diff --git a/source/blender/src/gpencil.c b/source/blender/src/gpencil.c new file mode 100644 index 00000000000..eef21323a44 --- /dev/null +++ b/source/blender/src/gpencil.c @@ -0,0 +1,1452 @@ +/** + * $Id: gpencil.c 14881 2008-05-18 10:41:42Z aligorith $ + * + * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2008, Blender Foundation + * This is a new part of Blender + * + * Contributor(s): Joshua Leung + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stddef.h> +#include <math.h> + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "MEM_guardedalloc.h" + +#include "BMF_Api.h" + +#include "BLI_arithb.h" +#include "BLI_blenlib.h" + +#include "DNA_listBase.h" +#include "DNA_gpencil_types.h" +#include "DNA_scene_types.h" +#include "DNA_screen_types.h" +#include "DNA_space_types.h" +#include "DNA_userdef_types.h" +#include "DNA_vec_types.h" +#include "DNA_view3d_types.h" + +#include "BKE_global.h" +#include "BKE_utildefines.h" +#include "BKE_blender.h" + +#include "BIF_gl.h" +#include "BIF_glutil.h" +#include "BIF_butspace.h" +#include "BIF_editview.h" +#include "BIF_graphics.h" +#include "BIF_interface.h" +#include "BIF_mywindow.h" +#include "BIF_resources.h" +#include "BIF_space.h" +#include "BIF_screen.h" +#include "BIF_toolbox.h" +#include "BIF_toets.h" + +#include "BDR_gpencil.h" +#include "BIF_drawgpencil.h" + +#include "BSE_drawipo.h" +#include "BSE_headerbuttons.h" +#include "BSE_view.h" + +#include "blendef.h" + +#include "PIL_time.h" /* sleep */ +#include "mydevice.h" + +/* ************************************************** */ +/* GENERAL STUFF */ + +/* --------- Memory Management ------------ */ + +/* Free strokes belonging to a gp-frame */ +void free_gpencil_strokes (bGPDframe *gpf) +{ + bGPDstroke *gps, *gpsn; + + /* error checking */ + if (gpf == NULL) return; + + /* free strokes */ + for (gps= gpf->strokes.first; gps; gps= gpsn) { + gpsn= gps->next; + + /* free stroke memory arrays, then stroke itself */ + MEM_freeN(gps->points); + BLI_freelinkN(&gpf->strokes, gps); + } +} + +/* Free all of a gp-layer's frames */ +void free_gpencil_frames (bGPDlayer *gpl) +{ + bGPDframe *gpf, *gpfn; + + /* error checking */ + if (gpl == NULL) return; + + /* free frames */ + for (gpf= gpl->frames.first; gpf; gpf= gpfn) { + gpfn= gpf->next; + + /* free strokes and their associated memory */ + free_gpencil_strokes(gpf); + BLI_freelinkN(&gpl->frames, gpf); + } +} + +/* Free all of the gp-layers for a viewport (list should be &G.vd->gpd or so) */ +void free_gpencil_layers (ListBase *list) +{ + bGPDlayer *gpl, *gpln; + + /* error checking */ + if (list == NULL) return; + + /* delete layers*/ + for (gpl= list->first; gpl; gpl= gpln) { + gpln= gpl->next; + + /* free layers and their data */ + free_gpencil_frames(gpl); + BLI_freelinkN(list, gpl); + } +} + +/* Free gp-data and all it's related data */ +void free_gpencil_data (bGPdata *gpd) +{ + /* free layers then data itself */ + free_gpencil_layers(&gpd->layers); + MEM_freeN(gpd); +} + +/* -------- Container Creation ---------- */ + +/* add a new gp-frame to the given layer */ +bGPDframe *gpencil_frame_addnew (bGPDlayer *gpl, int cframe) +{ + bGPDframe *gpf, *gf; + short state=0; + + /* error checking */ + if ((gpl == NULL) || (cframe <= 0)) + return NULL; + + /* allocate memory for this frame */ + gpf= MEM_callocN(sizeof(bGPDframe), "bGPDframe"); + gpf->framenum= cframe; + + /* find appropriate place to add frame */ + if (gpl->frames.first) { + for (gf= gpl->frames.first; gf; gf= gf->next) { + /* check if frame matches one that is supposed to be added */ + if (gf->framenum == cframe) { + state= -1; + break; + } + + /* if current frame has already exceeded the frame to add, add before */ + if (gf->framenum > cframe) { + BLI_insertlinkbefore(&gpl->frames, gf, gpf); + state= 1; + break; + } + } + } + + /* check whether frame was added successfully */ + if (state == -1) { + MEM_freeN(gpf); + printf("Error: frame (%d) existed already for this layer \n", cframe); + } + else if (state == 0) { + /* add to end then! */ + BLI_addtail(&gpl->frames, gpf); + } + + /* return frame */ + return gpf; +} + +/* add a new gp-layer and make it the active layer */ +bGPDlayer *gpencil_layer_addnew (bGPdata *gpd) +{ + bGPDlayer *gpl; + + /* check that list is ok */ + if (gpd == NULL) + return NULL; + + /* allocate memory for frame and add to end of list */ + gpl= MEM_callocN(sizeof(bGPDlayer), "bGPDlayer"); + + /* add to datablock */ + BLI_addtail(&gpd->layers, gpl); + + /* set basic settings */ + gpl->color[3]= 1.0f; + gpl->thickness = 1; + + /* auto-name */ + sprintf(gpl->info, "GP_Layer"); + BLI_uniquename(&gpd->layers, gpl, "GP_Layer", offsetof(bGPDlayer, info[0]), 128); + + /* make this one the active one */ + gpencil_layer_setactive(gpd, gpl); + + /* return layer */ + return gpl; +} + +/* add a new gp-datablock */ +bGPdata *gpencil_data_addnew (void) +{ + bGPdata *gpd; + + /* allocate memory for a new block */ + gpd= MEM_callocN(sizeof(bGPdata), "GreasePencilData"); + + /* initial settings */ + /* it is quite useful to be able to see this info, so on by default */ + gpd->flag = GP_DATA_DISPINFO; + + return gpd; +} + +/* -------- Data Duplication ---------- */ + +/* make a copy of a given gpencil datablock */ +bGPdata *gpencil_data_duplicate (bGPdata *src) +{ + bGPdata *dst; + bGPDlayer *gpld, *gpls; + bGPDframe *gpfd, *gpfs; + bGPDstroke *gps; + + /* error checking */ + if (src == NULL) + return NULL; + + /* make a copy of the base-data */ + dst= MEM_dupallocN(src); + + /* copy layers */ + duplicatelist(&dst->layers, &src->layers); + + for (gpld=dst->layers.first, gpls=src->layers.first; gpld && gpls; + gpld=gpld->next, gpls=gpls->next) + { + /* copy frames */ + duplicatelist(&gpld->frames, &gpls->frames); + + for (gpfd=gpld->frames.first, gpfs=gpls->frames.first; gpfd && gpfs; + gpfd=gpfd->next, gpfs=gpfs->next) + { + /* copy strokes */ + duplicatelist(&gpfd->strokes, &gpfs->strokes); + + for (gps= gpfd->strokes.first; gps; gps= gps->next) + { + gps->points= MEM_dupallocN(gps->points); + } + } + } + + /* return new */ + return dst; +} + +/* ----------- GP-Datablock API ------------- */ + +/* get the appropriate bGPdata from the active/given context */ +bGPdata *gpencil_data_getactive (ScrArea *sa) +{ + /* error checking */ + if ((sa == NULL) && (curarea == NULL)) + return NULL; + if (sa == NULL) + sa= curarea; + + /* handle depending on spacetype */ + switch (sa->spacetype) { + case SPACE_VIEW3D: + { + View3D *v3d= sa->spacedata.first; + return v3d->gpd; + } + break; + case SPACE_NODE: + { + SpaceNode *snode= sa->spacedata.first; + return snode->gpd; + } + break; + case SPACE_SEQ: + { + SpaceSeq *sseq= sa->spacedata.first; + + /* only applicable for "Image Preview" mode */ + if (sseq->mainb) + return sseq->gpd; + } + break; + } + + /* nothing found */ + return NULL; +} + +/* set bGPdata for the active/given context, and return success/fail */ +short gpencil_data_setactive (ScrArea *sa, bGPdata *gpd) +{ + /* error checking */ + if ((sa == NULL) && (curarea == NULL)) + return 0; + if (gpd == NULL) + return 0; + if (sa == NULL) + sa= curarea; + + /* handle depending on spacetype */ + // TODO: someday we should have multi-user data, so no need to loose old data + switch (sa->spacetype) { + case SPACE_VIEW3D: + { + View3D *v3d= sa->spacedata.first; + + /* free the existing block */ + if (v3d->gpd) + free_gpencil_data(v3d->gpd); + v3d->gpd= gpd; + + return 1; + } + break; + case SPACE_NODE: + { + SpaceNode *snode= sa->spacedata.first; + + /* free the existing block */ + if (snode->gpd) + free_gpencil_data(snode->gpd); + snode->gpd= gpd; + + /* set special settings */ + gpd->flag |= GP_DATA_VIEWALIGN; + + return 1; + } + break; + case SPACE_SEQ: + { + SpaceSeq *sseq= sa->spacedata.first; + + /* only applicable if right mode */ + if (sseq->mainb) { + /* free the existing block */ + if (sseq->gpd) + free_gpencil_data(sseq->gpd); + sseq->gpd= gpd; + + return 1; + } + } + break; + } + + /* failed to add */ + return 0; +} + +/* -------- GP-Frame API ---------- */ + +/* delete the last stroke of the given frame */ +void gpencil_frame_delete_laststroke (bGPDframe *gpf) +{ + bGPDstroke *gps= (gpf) ? gpf->strokes.last : NULL; + + /* error checking */ + if (ELEM(NULL, gpf, gps)) + return; + + /* free the stroke and its data */ + MEM_freeN(gps->points); + BLI_freelinkN(&gpf->strokes, gps); +} + +/* -------- GP-Layer API ---------- */ + +/* get the appropriate gp-frame from a given layer + * - this sets the layer's actframe var (if allowed to) + * - extension beyond range (if first gp-frame is after all frame in interest and cannot add) + */ +bGPDframe *gpencil_layer_getframe (bGPDlayer *gpl, int cframe, short addnew) +{ + bGPDframe *gpf = NULL; + short found = 0; + + /* error checking */ + if (gpl == NULL) return NULL; + if (cframe <= 0) cframe = 1; + + /* check if there is already an active frame */ + if (gpl->actframe) { + gpf= gpl->actframe; + + /* do not allow any changes to layer's active frame if layer is locked */ + if (gpl->flag & GP_LAYER_LOCKED) + return gpf; + /* do not allow any changes to actframe if frame has painting tag attached to it */ + if (gpf->flag & GP_FRAME_PAINT) + return gpf; + + /* try to find matching frame */ + if (gpf->framenum < cframe) { + for (; gpf; gpf= gpf->next) { + if (gpf->framenum == cframe) { + found= 1; + break; + } + else if ((gpf->next) && (gpf->next->framenum > cframe)) { + found= 1; + break; + } + } + + /* set the appropriate frame */ + if (addnew) { + if ((found) && (gpf->framenum == cframe)) + gpl->actframe= gpf; + else + gpl->actframe= gpencil_frame_addnew(gpl, cframe); + } + else if (found) + gpl->actframe= gpf; + else + gpl->actframe= gpl->frames.last; + } + else { + for (; gpf; gpf= gpf->prev) { + if (gpf->framenum <= cframe) { + found= 1; + break; + } + } + + /* set the appropriate frame */ + if (addnew) { + if ((found) && (gpf->framenum == cframe)) + gpl->actframe= gpf; + else + gpl->actframe= gpencil_frame_addnew(gpl, cframe); + } + else if (found) + gpl->actframe= gpf; + else + gpl->actframe= gpl->frames.first; + } + } + else if (gpl->frames.first) { + /* check which of the ends to start checking from */ + const int first= ((bGPDframe *)(gpl->frames.first))->framenum; + const int last= ((bGPDframe *)(gpl->frames.last))->framenum; + + if (abs(cframe-first) > abs(cframe-last)) { + /* find gp-frame which is less than or equal to cframe */ + for (gpf= gpl->frames.last; gpf; gpf= gpf->prev) { + if (gpf->framenum <= cframe) { + found= 1; + break; + } + } + } + else { + /* find gp-frame which is less than or equal to cframe */ + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + if (gpf->framenum <= cframe) { + found= 1; + break; + } + } + } + + /* set the appropriate frame */ + if (addnew) { + if ((found) && (gpf->framenum == cframe)) + gpl->actframe= gpf; + else + gpl->actframe= gpencil_frame_addnew(gpl, cframe); + } + else if (found) + gpl->actframe= gpf; + else { + /* unresolved errogenous situation! */ + printf("Error: cannot find appropriate gp-frame \n"); + } + } + else { + /* currently no frames (add if allowed to) */ + if (addnew) + gpl->actframe= gpencil_frame_addnew(gpl, cframe); + else { + /* don't do anything... this may be when no frames yet! */ + } + } + + /* return */ + return gpl->actframe; +} + +/* delete the given frame from a layer */ +void gpencil_layer_delframe (bGPDlayer *gpl, bGPDframe *gpf) +{ + /* error checking */ + if (ELEM(NULL, gpl, gpf)) + return; + + /* free the frame and its data */ + free_gpencil_strokes(gpf); + BLI_freelinkN(&gpl->frames, gpf); + gpl->actframe = NULL; +} + +/* get the active gp-layer for editing */ +bGPDlayer *gpencil_layer_getactive (bGPdata *gpd) +{ + bGPDlayer *gpl; + + /* error checking */ + if (ELEM(NULL, gpd, gpd->layers.first)) + return NULL; + + /* loop over layers until found (assume only one active) */ + for (gpl=gpd->layers.first; gpl; gpl=gpl->next) { + if (gpl->flag & GP_LAYER_ACTIVE) + return gpl; + } + + /* no active layer found */ + return NULL; +} + +/* set the active gp-layer */ +void gpencil_layer_setactive (bGPdata *gpd, bGPDlayer *active) +{ + bGPDlayer *gpl; + + /* error checking */ + if (ELEM3(NULL, gpd, gpd->layers.first, active)) + return; + + /* loop over layers deactivating all */ + for (gpl=gpd->layers.first; gpl; gpl=gpl->next) + gpl->flag &= ~GP_LAYER_ACTIVE; + + /* set as active one */ + active->flag |= GP_LAYER_ACTIVE; +} + +/* delete the active gp-layer */ +void gpencil_layer_delactive (bGPdata *gpd) +{ + bGPDlayer *gpl= gpencil_layer_getactive(gpd); + + /* error checking */ + if (ELEM(NULL, gpd, gpl)) + return; + + /* free layer */ + free_gpencil_frames(gpl); + BLI_freelinkN(&gpd->layers, gpl); + +} + +/* ************************************************** */ +/* GREASE-PENCIL EDITING MODE - Tools */ + +/* --------- Data Deletion ---------- */ + +/* delete the last stroke on the active layer */ +void gpencil_delete_laststroke (bGPdata *gpd) +{ + bGPDlayer *gpl= gpencil_layer_getactive(gpd); + bGPDframe *gpf= gpencil_layer_getframe(gpl, CFRA, 0); + + gpencil_frame_delete_laststroke(gpf); +} + +/* delete the active frame */ +void gpencil_delete_actframe (bGPdata *gpd) +{ + bGPDlayer *gpl= gpencil_layer_getactive(gpd); + bGPDframe *gpf= gpencil_layer_getframe(gpl, CFRA, 0); + + gpencil_layer_delframe(gpl, gpf); +} + + + +/* delete various grase-pencil elements + * mode: 1 - last stroke + * 2 - active frame + * 3 - active layer + */ +void gpencil_delete_operation (short mode) +{ + bGPdata *gpd; + + /* get datablock to work on */ + gpd= gpencil_data_getactive(NULL); + if (gpd == NULL) return; + + switch (mode) { + case 1: /* last stroke */ + gpencil_delete_laststroke(gpd); + break; + case 2: /* active frame */ + gpencil_delete_actframe(gpd); + break; + case 3: /* active layer */ + gpencil_layer_delactive(gpd); + break; + } + + /* redraw and undo-push */ + BIF_undo_push("GPencil Delete"); + allqueue(REDRAWVIEW3D, 0); +} + +/* display a menu for deleting different grease-pencil elements */ +void gpencil_delete_menu (void) +{ + bGPdata *gpd= gpencil_data_getactive(NULL); + short mode; + + /* only show menu if it will be relevant */ + if (gpd == NULL) return; + + mode= pupmenu("Grease Pencil Erase...%t|Last Stroke%x1|Active Frame%x2|Active Layer%x3"); + if (mode <= 0) return; + + gpencil_delete_operation(mode); +} + +/* ************************************************** */ +/* GREASE-PENCIL EDITING MODE - Painting */ + +/* ---------- 'Globals' and Defines ----------------- */ + +/* maximum sizes of gp-session buffer */ +#define GP_STROKE_BUFFER_MAX 5000 + +/* Hardcoded sensitivity thresholds... */ +// TODO: one day, these might be added to the UI if it is necessary + /* minimum number of pixels mouse should move before new point created */ +#define MIN_MANHATTEN_PX 3 + /* minimum length of new segment before new point can be added */ +#define MIN_EUCLIDEAN_PX 20 + +/* ------ */ + +/* Temporary 'Stroke' Operation data */ +typedef struct tGPsdata { + ScrArea *sa; /* area where painting originated */ + View2D *v2d; /* needed for GP_STROKE_2DSPACE */ + + bGPdata *gpd; /* gp-datablock layer comes from */ + bGPDlayer *gpl; /* layer we're working on */ + bGPDframe *gpf; /* frame we're working on */ + + short status; /* current status of painting */ + short paintmode; /* mode for painting */ +} tGPsdata; + +/* values for tGPsdata->status */ +enum { + GP_STATUS_NORMAL = 0, /* running normally */ + GP_STATUS_ERROR, /* something wasn't correctly set up */ + GP_STATUS_DONE /* painting done */ +}; + +/* values for tGPsdata->paintmode */ +enum { + GP_PAINTMODE_DRAW = 0, + GP_PAINTMODE_ERASER +}; + +/* Return flags for adding points to stroke buffer */ +enum { + GP_STROKEADD_INVALID = -2, /* error occurred - insufficient info to do so */ + GP_STROKEADD_OVERFLOW = -1, /* error occurred - cannot fit any more points */ + GP_STROKEADD_NORMAL, /* point was successfully added */ + GP_STROKEADD_FULL /* cannot add any more points to buffer */ +}; + +/* ---------- Stroke Editing ------------ */ + +/* clear the session buffers (call this before AND after a paint operation) */ +static void gp_session_validatebuffer (tGPsdata *p) +{ + bGPdata *gpd= p->gpd; + + /* clear memory of buffer (or allocate it if starting a new session) */ + if (gpd->sbuffer) + memset(gpd->sbuffer, 0, sizeof(tGPspoint)*GP_STROKE_BUFFER_MAX); + else + gpd->sbuffer= MEM_callocN(sizeof(tGPspoint)*GP_STROKE_BUFFER_MAX, "gp_session_strokebuffer"); + + /* reset indices */ + gpd->sbuffer_size = 0; + + /* reset flags */ + gpd->sbuffer_sflag= 0; +} + +/* init new painting session */ +static void gp_session_initpaint (tGPsdata *p) +{ + /* clear previous data (note: is on stack) */ + memset(p, 0, sizeof(tGPsdata)); + + /* make sure the active view (at the starting time) is a 3d-view */ + if (curarea == NULL) { + p->status= GP_STATUS_ERROR; + if (G.f & G_DEBUG) + printf("Error: No active view for painting \n"); + return; + } + switch (curarea->spacetype) { + /* supported views first */ + case SPACE_VIEW3D: + { + View3D *v3d= curarea->spacedata.first; + + /* set current area */ + p->sa= curarea; + + /* check that gpencil data is allowed to be drawn */ + if ((v3d->flag2 & V3D_DISPGP)==0) { + p->status= GP_STATUS_ERROR; + if (G.f & G_DEBUG) + printf("Error: In active view, Grease Pencil not shown \n"); + return; + } + } + break; + case SPACE_NODE: + { + SpaceNode *snode= curarea->spacedata.first; + + /* set current area */ + p->sa= curarea; + p->v2d= &snode->v2d; + + /* check that gpencil data is allowed to be drawn */ + if ((snode->flag & SNODE_DISPGP)==0) { + p->status= GP_STATUS_ERROR; + if (G.f & G_DEBUG) + printf("Error: In active view, Grease Pencil not shown \n"); + return; + } + } + break; + case SPACE_SEQ: + { + SpaceSeq *sseq= curarea->spacedata.first; + + /* set current area */ + p->sa= curarea; + p->v2d= &sseq->v2d; + + /* check that gpencil data is allowed to be drawn */ + if (sseq->mainb == 0) { + p->status= GP_STATUS_ERROR; + if (G.f & G_DEBUG) + printf("Error: In active view (sequencer), active mode doesn't support Grease Pencil \n"); + return; + } + if ((sseq->flag & SEQ_DRAW_GPENCIL)==0) { + p->status= GP_STATUS_ERROR; + if (G.f & G_DEBUG) + printf("Error: In active view, Grease Pencil not shown \n"); + return; + } + } + break; + /* unsupported views */ + default: + { + p->status= GP_STATUS_ERROR; + if (G.f & G_DEBUG) + printf("Error: Active view not appropriate for Grease Pencil drawing \n"); + return; + } + break; + } + + /* get gp-data */ + p->gpd= gpencil_data_getactive(p->sa); + if (p->gpd == NULL) { + short ok; + + p->gpd= gpencil_data_addnew(); + ok= gpencil_data_setactive(p->sa, p->gpd); + + /* most of the time, the following check isn't needed */ + if (ok == 0) { + /* free gpencil data as it can't be used */ + free_gpencil_data(p->gpd); + p->gpd= NULL; + p->status= GP_STATUS_ERROR; + if (G.f & G_DEBUG) + printf("Error: Could not assign newly created Grease Pencil data to active area \n"); + return; + } + } + + /* set edit flags */ + G.f |= G_GREASEPENCIL; + + /* clear out buffer (stored in gp-data) in case something contaminated it */ + gp_session_validatebuffer(p); +} + +/* cleanup after a painting session */ +static void gp_session_cleanup (tGPsdata *p) +{ + bGPdata *gpd= p->gpd; + + /* error checking */ + if (gpd == NULL) + return; + + /* free stroke buffer */ + if (gpd->sbuffer) { + MEM_freeN(gpd->sbuffer); + gpd->sbuffer= NULL; + } + + /* clear flags */ + gpd->sbuffer_size= 0; + gpd->sbuffer_sflag= 0; +} + +/* check if the current mouse position is suitable for adding a new point */ +static short gp_stroke_filtermval (tGPsdata *p, short mval[2], short pmval[2]) +{ + short dx= abs(mval[0] - pmval[0]); + short dy= abs(mval[1] - pmval[1]); + + /* check if mouse moved at least certain distance on both axes (best case) */ + if ((dx > MIN_MANHATTEN_PX) && (dy > MIN_MANHATTEN_PX)) + return 1; + + /* check if the distance since the last point is significant enough */ + else if (sqrt(dx*dx + dy*dy) > MIN_EUCLIDEAN_PX) + return 1; + + /* mouse 'didn't move' */ + else + return 0; +} + +/* convert screen-coordinates to buffer-coordinates */ +static void gp_stroke_convertcoords (tGPsdata *p, short mval[], float out[]) +{ + bGPdata *gpd= p->gpd; + + /* in 3d-space - pt->x/y/z are 3 side-by-side floats */ + if (gpd->sbuffer_sflag & GP_STROKE_3DSPACE) { + short mx=mval[0], my=mval[1]; + float *fp= give_cursor(); + float dvec[3]; + + /* method taken from editview.c - mouse_cursor() */ + project_short_noclip(fp, mval); + window_to_3d(dvec, mval[0]-mx, mval[1]-my); + VecSubf(out, fp, dvec); + } + + /* 2d - on 'canvas' (assume that p->v2d is set) */ + else if ((gpd->sbuffer_sflag & GP_STROKE_2DSPACE) && (p->v2d)) { + float x, y; + + areamouseco_to_ipoco(p->v2d, mval, &x, &y); + + out[0]= x; + out[1]= y; + } + + /* 2d - relative to screen (viewport area) */ + else { + out[0] = (float)(mval[0]) / (float)(p->sa->winx) * 1000; + out[1] = (float)(mval[1]) / (float)(p->sa->winy) * 1000; + } +} + +/* add current stroke-point to buffer (returns whether point was successfully added) */ +static short gp_stroke_addpoint (tGPsdata *p, short mval[2], float pressure) +{ + bGPdata *gpd= p->gpd; + tGPspoint *pt; + + /* check if still room in buffer */ + if (gpd->sbuffer_size >= GP_STROKE_BUFFER_MAX) + return GP_STROKEADD_OVERFLOW; + + /* get pointer to destination point */ + pt= ((tGPspoint *)(gpd->sbuffer) + gpd->sbuffer_size); + + /* store settings */ + pt->x= mval[0]; + pt->y= mval[1]; + pt->xf= (float)mval[0]; + pt->yf= (float)mval[0]; + pt->pressure= pressure; + + /* increment counters */ + gpd->sbuffer_size++; + + /* check if another operation can still occur */ + if (gpd->sbuffer_size == GP_STROKE_BUFFER_MAX) + return GP_STROKEADD_FULL; + else + return GP_STROKEADD_NORMAL; +} + +/* make a new stroke from the buffer data */ +static void gp_stroke_newfrombuffer (tGPsdata *p) +{ + bGPdata *gpd= p->gpd; + bGPDstroke *gps; + bGPDspoint *pt; + tGPspoint *ptc; + int i, totelem; + + /* get total number of points to allocate space for */ + totelem = gpd->sbuffer_size; + + /* exit with error if no valid points from this stroke */ + if (totelem == 0) { + if (G.f & G_DEBUG) + printf("Error: No valid points in stroke buffer to convert (tot=%d) \n", gpd->sbuffer_size); + return; + } + + /* allocate memory for a new stroke */ + gps= MEM_callocN(sizeof(bGPDstroke), "gp_stroke"); + + /* allocate enough memory for a continuous array for storage points */ + pt= gps->points= MEM_callocN(sizeof(bGPDspoint)*totelem, "gp_stroke_points"); + + /* copy appropriate settings for stroke */ + gps->totpoints= totelem; + gps->thickness= p->gpl->thickness; + gps->flag= gpd->sbuffer_sflag; + + /* copy points from the buffer to the stroke */ + for (i=0, ptc=gpd->sbuffer; i < gpd->sbuffer_size && ptc; i++, ptc++) { + /* convert screen-coordinates to appropriate coordinates (and store them) */ + gp_stroke_convertcoords(p, &ptc->x, &pt->x); + + /* copy pressure */ + pt->pressure= ptc->pressure; + + pt++; + } + + /* add stroke to frame */ + BLI_addtail(&p->gpf->strokes, gps); +} + +/* --- 'Eraser' for 'Paint' Tool ------ */ +/* User should draw 'circles' around the parts of the sketches they wish to + * delete instead of drawing squiggles over existing lines. This should be + * easier to manage than if it was done otherwise. + */ + +/* convert gp-buffer stroke into mouse-coordinates array */ +static short (*gp_stroke_eraser_2mco (bGPdata *gpd))[2] +{ + tGPspoint *pt; + short (*mcoords)[2]; + int i; + + /* allocate memory for coordinates array */ + mcoords= MEM_mallocN(sizeof(*mcoords)*gpd->sbuffer_size,"gp_buf_mcords"); + + /* copy coordinates */ + for (pt=gpd->sbuffer, i=0; i < gpd->sbuffer_size; i++, pt++) { + mcoords[i][0]= pt->x; + mcoords[i][1]= pt->y; + } + + /* return */ + return mcoords; +} + +/* eraser tool - remove segment from stroke/split stroke (after lasso inside) */ +static short gp_stroke_eraser_splitdel (bGPDframe *gpf, bGPDstroke *gps, int i) +{ + bGPDspoint *pt_tmp= gps->points; + bGPDstroke *gsn = NULL; + + /* if stroke only had two points, get rid of stroke */ + if (gps->totpoints == 2) { + /* free stroke points, then stroke */ + MEM_freeN(pt_tmp); + BLI_freelinkN(&gpf->strokes, gps); + + /* nothing left in stroke, so stop */ + return 1; + } + + /* if last segment, just remove segment from the stroke */ + else if (i == gps->totpoints - 2) { + /* allocate new points array, and assign most of the old stroke there */ + gps->totpoints--; + gps->points= MEM_callocN(sizeof(bGPDspoint)*gps->totpoints, "gp_stroke_points"); + memcpy(gps->points, pt_tmp, sizeof(bGPDspoint)*gps->totpoints); + + /* free temp buffer */ + MEM_freeN(pt_tmp); + + /* nothing left in stroke, so stop */ + return 1; + } + + /* if first segment, just remove segment from the stroke */ + else if (i == 0) { + /* allocate new points array, and assign most of the old stroke there */ + gps->totpoints--; + gps->points= MEM_callocN(sizeof(bGPDspoint)*gps->totpoints, "gp_stroke_points"); + memcpy(gps->points, pt_tmp + 1, sizeof(bGPDspoint)*gps->totpoints); + + /* free temp buffer */ + MEM_freeN(pt_tmp); + + /* no break here, as there might still be stuff to remove in this stroke */ + return 0; + } + + /* segment occurs in 'middle' of stroke, so split */ + else { + /* duplicate stroke, and assign 'later' data to that stroke */ + gsn= MEM_dupallocN(gps); + gsn->prev= gsn->next= NULL; + BLI_insertlinkafter(&gpf->strokes, gps, gsn); + + gsn->totpoints= gps->totpoints - i; + gsn->points= MEM_callocN(sizeof(bGPDspoint)*gsn->totpoints, "gp_stroke_points"); + memcpy(gsn->points, pt_tmp + i, sizeof(bGPDspoint)*gsn->totpoints); + + /* adjust existing stroke */ + gps->totpoints= i; + gps->points= MEM_callocN(sizeof(bGPDspoint)*gps->totpoints, "gp_stroke_points"); + memcpy(gps->points, pt_tmp, sizeof(bGPDspoint)*i); + + /* free temp buffer */ + MEM_freeN(pt_tmp); + + /* nothing left in stroke, so stop */ + return 1; + } +} + +/* eraser tool - evaluation per stroke */ +static void gp_stroke_eraser_dostroke (tGPsdata *p, short mcoords[][2], short moves, rcti *rect, bGPDframe *gpf, bGPDstroke *gps) +{ + bGPDspoint *pt1, *pt2; + short x0=0, y0=0, x1=0, y1=0; + short xyval[2]; + int i; + + if (gps->totpoints == 0) { + /* just free stroke */ + if (gps->points) + MEM_freeN(gps->points); + BLI_freelinkN(&gpf->strokes, gps); + } + else if (gps->totpoints == 1) { + /* get coordinates */ + if (gps->flag & GP_STROKE_3DSPACE) { + // FIXME: this may not be the correct correction + project_short(&gps->points->x, xyval); + x0= xyval[0]; + x1= xyval[1]; + } + else if (gps->flag & GP_STROKE_2DSPACE) { + ipoco_to_areaco_noclip(p->v2d, &gps->points->x, xyval); + x0= xyval[0]; + y0= xyval[1]; + } + else { + x0= (gps->points->x / 1000 * p->sa->winx); + y0= (gps->points->y / 1000 * p->sa->winy); + } + + /* do boundbox check first */ + if (BLI_in_rcti(rect, x0, y0)) { + /* only check if point is inside */ + if (lasso_inside(mcoords, moves, x0, y0)) { + /* free stroke */ + MEM_freeN(gps->points); + BLI_freelinkN(&gpf->strokes, gps); + } + } + } + else { + /* loop over the points in the stroke, checking for intersections + * - an intersection will require the stroke to be split + */ + for (i=0; (i+1) < gps->totpoints; i++) { + /* get points to work with */ + pt1= gps->points + i; + pt2= gps->points + i + 1; + + /* get coordinates */ + if (gps->flag & GP_STROKE_3DSPACE) { + // FIXME: may not be correct correction + project_short(&gps->points->x, xyval); + x0= xyval[0]; + x1= xyval[1]; + } + else if (gps->flag & GP_STROKE_2DSPACE) { + ipoco_to_areaco_noclip(p->v2d, &pt1->x, xyval); + x0= xyval[0]; + y0= xyval[1]; + + ipoco_to_areaco_noclip(p->v2d, &pt2->x, xyval); + x1= xyval[0]; + y1= xyval[1]; + } + else { + x0= (pt1->x / 1000 * p->sa->winx); + y0= (pt1->y / 1000 * p->sa->winy); + x1= (pt2->x / 1000 * p->sa->winx); + y1= (pt2->y / 1000 * p->sa->winy); + } + + /* check that point segment of the boundbox of the eraser stroke */ + if (BLI_in_rcti(rect, x0, y0) || BLI_in_rcti(rect, x1, y1)) { + /* check if point segment of stroke had anything to do with + * eraser region (either within stroke painted, or on its lines) + * - this assumes that linewidth is irrelevant + * - handled using the lasso-select checking code + */ + if (lasso_inside_edge(mcoords, moves, x0, y0, x1, x1)) { + /* if function returns true, break this loop (as no more point to check) */ + if (gp_stroke_eraser_splitdel(gpf, gps, i)) + break; + } + } + } + } +} + +/* -------- */ + +/* erase strokes which fall under the eraser strokes */ +static void gp_stroke_doeraser (tGPsdata *p) +{ + bGPdata *gpd= p->gpd; + bGPDframe *gpf= p->gpf; + bGPDstroke *gps, *gpn; + short (*mcoords)[2]; + rcti rect; + + /* get buffer-stroke coordinates as shorts array, and then get bounding box */ + mcoords= gp_stroke_eraser_2mco(gpd); + lasso_select_boundbox(&rect, mcoords, gpd->sbuffer_size); + + /* loop over strokes, checking segments for intersections */ + for (gps= gpf->strokes.first; gps; gps= gpn) { + gpn= gps->next; + gp_stroke_eraser_dostroke(p, mcoords, gpd->sbuffer_size, &rect, gpf, gps); + } + + /* free mcoords array */ + MEM_freeN(mcoords); +} + +/* ---------- 'Paint' Tool ------------ */ + +/* init new stroke */ +static void gp_paint_initstroke (tGPsdata *p, short paintmode) +{ + /* get active layer (or add a new one if non-existent) */ + p->gpl= gpencil_layer_getactive(p->gpd); + if (p->gpl == NULL) + p->gpl= gpencil_layer_addnew(p->gpd); + if (p->gpl->flag & GP_LAYER_LOCKED) { + p->status= GP_STATUS_ERROR; + if (G.f & G_DEBUG) + printf("Error: Cannot paint on locked layer \n"); + return; + } + + /* get active frame (add a new one if not matching frame) */ + p->gpf= gpencil_layer_getframe(p->gpl, CFRA, 1); + if (p->gpf == NULL) { + p->status= GP_STATUS_ERROR; + if (G.f & G_DEBUG) + printf("Error: No frame created (gpencil_paint_init) \n"); + return; + } + else + p->gpf->flag |= GP_FRAME_PAINT; + + /* set 'eraser' for this stroke if using eraser */ + p->paintmode= paintmode; + if (p->paintmode == GP_PAINTMODE_ERASER) + p->gpd->sbuffer_sflag |= GP_STROKE_ERASER; + + /* check if points will need to be made in view-aligned space */ + if (p->gpd->flag & GP_DATA_VIEWALIGN) { + switch (p->sa->spacetype) { + case SPACE_VIEW3D: + { + float *fp= give_cursor(); + initgrabz(fp[0], fp[1], fp[2]); + + p->gpd->sbuffer_sflag |= GP_STROKE_3DSPACE; + } + break; + case SPACE_NODE: + { + p->gpd->sbuffer_sflag |= GP_STROKE_2DSPACE; + } + break; + case SPACE_SEQ: + { + /* for now, this is not applicable here... */ + } + break; + } + } +} + +/* finish off a stroke (clears buffer, but doesn't finish the paint operation) */ +static void gp_paint_strokeend (tGPsdata *p) +{ + /* check if doing eraser or not */ + if (p->gpd->sbuffer_sflag & GP_STROKE_ERASER) { + /* get rid of relevant sections of strokes */ + gp_stroke_doeraser(p); + } + else { + /* transfer stroke to frame */ + gp_stroke_newfrombuffer(p); + } + + /* clean up buffer now */ + gp_session_validatebuffer(p); +} + +/* finish off stroke painting operation */ +static void gp_paint_cleanup (tGPsdata *p) +{ + /* finish off a stroke */ + gp_paint_strokeend(p); + + /* "unlock" frame */ + p->gpf->flag &= ~GP_FRAME_PAINT; + + /* add undo-push so stroke can be undone */ + /* FIXME: currently disabled, as it's impossible to get this working nice + * as gpenci data is on currently screen-level (which isn't saved to undo files) + */ + //BIF_undo_push("GPencil Stroke"); + + /* force redraw after drawing action */ + force_draw_plus(SPACE_ACTION, 0); +} + +/* -------- */ + +/* main call to paint a new stroke */ +short gpencil_paint (short mousebutton, short paintmode) +{ + tGPsdata p; + short prevmval[2], mval[2]; + float opressure, pressure; + short ok = GP_STROKEADD_NORMAL; + + /* init paint-data */ + gp_session_initpaint(&p); + if (p.status == GP_STATUS_ERROR) { + gp_session_cleanup(&p); + return 0; + } + gp_paint_initstroke(&p, paintmode); + if (p.status == GP_STATUS_ERROR) { + gp_session_cleanup(&p); + return 0; + } + + /* set cursor to indicate drawing */ + setcursor_space(p.sa->spacetype, CURSOR_VPAINT); + + /* init drawing-device settings */ + getmouseco_areawin(mval); + pressure = get_pressure(); + + prevmval[0]= mval[0]; + prevmval[1]= mval[1]; + opressure= pressure; + + /* only allow painting of single 'dots' if: + * - pressure is not excessive (as it can be on some windows tablets) + * - draw-mode for active datablock is turned on + */ + if (!(pressure >= 0.99f) || (p.gpd->flag & GP_DATA_EDITPAINT)) { + gp_stroke_addpoint(&p, mval, pressure); + } + + /* paint loop */ + do { + /* get current user input */ + getmouseco_areawin(mval); + pressure = get_pressure(); + + /* only add current point to buffer if mouse moved (otherwise wait until it does) */ + if (gp_stroke_filtermval(&p, mval, prevmval)) { + /* try to add point */ + ok= gp_stroke_addpoint(&p, mval, pressure); + + /* handle errors while adding point */ + if ((ok == GP_STROKEADD_FULL) || (ok == GP_STROKEADD_OVERFLOW)) { + /* finish off old stroke */ + gp_paint_strokeend(&p); + + /* start a new stroke, starting from previous point */ + gp_stroke_addpoint(&p, prevmval, opressure); + ok= gp_stroke_addpoint(&p, mval, pressure); + } + else if (ok == GP_STROKEADD_INVALID) { + /* the painting operation cannot continue... */ + error("Cannot paint stroke"); + p.status = GP_STATUS_ERROR; + + if (G.f & G_DEBUG) + printf("Error: Grease-Pencil Paint - Add Point Invalid \n"); + break; + } + force_draw(0); + + prevmval[0]= mval[0]; + prevmval[1]= mval[1]; + opressure= pressure; + } + else + BIF_wait_for_statechange(); + + /* do mouse checking at the end, so don't check twice, and potentially + * miss a short tap + */ + } while (get_mbut() & mousebutton); + + /* clear edit flags */ + G.f &= ~G_GREASEPENCIL; + + /* restore cursor to indicate end of drawing */ + setcursor_space(p.sa->spacetype, CURSOR_STD); + + /* check size of buffer before cleanup, to determine if anything happened here */ + if (paintmode == GP_PAINTMODE_ERASER) + ok= (p.gpd->sbuffer_size > 1); + else + ok= p.gpd->sbuffer_size; + + /* cleanup */ + gp_paint_cleanup(&p); + gp_session_cleanup(&p); + + /* done! return if a stroke was successfully added */ + return ok; +} + + +/* All event (loops) handling checking if stroke drawing should be initiated + * should call this function. + */ +short gpencil_do_paint (ScrArea *sa, short mbut) +{ + bGPdata *gpd = gpencil_data_getactive(sa); + short retval= 0; + + /* check if possible to do painting */ + if (gpd == NULL) + return 0; + + /* currently, we will only 'paint' if: + * 1. draw-mode on gpd is set (for accessibility reasons) + * (single 'dots' are only available via this method) + * 2. if shift-modifier is held + lmb -> 'quick paint' + * + * OR + * + * draw eraser stroke if: + * 1. using the eraser on a tablet + * 2. draw-mode on gpd is set (for accessiblity reasons) + * (eraser is mapped to right-mouse) + * 3. Alt + 'select' mouse-button + * i.e. if LMB = select: Alt-LMB + * if RMB = select: Alt-RMB + */ + if (get_activedevice() == 2) { + /* eraser on a tablet - always try to erase strokes */ + retval = gpencil_paint(mbut, GP_PAINTMODE_ERASER); + } + else if (gpd->flag & GP_DATA_EDITPAINT) { + /* try to paint/erase */ + if (mbut == L_MOUSE) + retval = gpencil_paint(mbut, GP_PAINTMODE_DRAW); + else if (mbut == R_MOUSE) + retval = gpencil_paint(mbut, GP_PAINTMODE_ERASER); + } + else if (!(gpd->flag & GP_DATA_LMBPLOCK)) { + /* try to paint/erase as not locked */ + if ((G.qual == LR_SHIFTKEY) && (mbut == L_MOUSE)) { + retval = gpencil_paint(mbut, GP_PAINTMODE_DRAW); + } + else if (G.qual == LR_ALTKEY) { + if ((U.flag & USER_LMOUSESELECT) && (mbut == L_MOUSE)) + retval = gpencil_paint(mbut, GP_PAINTMODE_ERASER); + else if (!(U.flag & USER_LMOUSESELECT) && (mbut == R_MOUSE)) + retval = gpencil_paint(mbut, GP_PAINTMODE_ERASER); + } + } + + /* return result of trying to paint */ + return retval; +} + +/* ************************************************** */ diff --git a/source/blender/src/header_action.c b/source/blender/src/header_action.c index 9c7046c5111..4bb7bb9677e 100644 --- a/source/blender/src/header_action.c +++ b/source/blender/src/header_action.c @@ -50,8 +50,11 @@ #include "DNA_screen_types.h" #include "DNA_space_types.h" +#include "BIF_gl.h" +#include "BIF_glutil.h" #include "BIF_editaction.h" #include "BIF_interface.h" +#include "BIF_language.h" #include "BIF_poseobject.h" #include "BIF_resources.h" #include "BIF_screen.h" @@ -76,6 +79,7 @@ #include "blendef.h" #include "mydevice.h" +/* ------------------------------- */ /* enums declaring constants that are used as menu event codes */ enum { @@ -212,6 +216,16 @@ enum { ACTMENU_MARKERS_LOCALMOVE }; +/* ------------------------------- */ +/* macros for easier state testing (only for use here) */ + +/* test if active action editor is showing any markers */ +#define G_SACTION_HASMARKERS \ + ((G.saction->action && G.saction->action->markers.first) \ + || (G.scene->markers.first)) + +/* ------------------------------- */ + void do_action_buttons(unsigned short event) { Object *ob= OBACT; @@ -398,32 +412,41 @@ static uiBlock *action_viewmenu(void *arg_unused) uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); - uiDefIconTextBut(block, BUTM, 1, (G.saction->flag & SACTION_SLIDERS)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, - "Show Sliders|", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 1, - ACTMENU_VIEW_SLIDERS, ""); - - uiDefIconTextBut(block, BUTM, 1, (G.saction->flag & SACTION_NOHIDE)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, - "Show Hidden Channels|", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 1, - ACTMENU_VIEW_NOHIDE, ""); - - uiDefIconTextBut(block, BUTM, 1, (G.saction->flag & SACTION_NODRAWGCOLORS)?ICON_CHECKBOX_DEHLT:ICON_CHECKBOX_HLT, - "Use Group Colors|", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 1, - ACTMENU_VIEW_GCOLORS, ""); - - // this option may get removed in future - uiDefIconTextBut(block, BUTM, 1, (G.saction->flag & SACTION_HORIZOPTIMISEON)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, - "Cull Out-of-View Keys (Time)|", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 1, - ACTMENU_VIEW_HORIZOPTIMISE, ""); + if (G.saction->mode == SACTCONT_GPENCIL) { + // this option may get removed in future + uiDefIconTextBut(block, BUTM, 1, (G.saction->flag & SACTION_HORIZOPTIMISEON)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, + "Cull Out-of-View Keys (Time)|", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 1, + ACTMENU_VIEW_HORIZOPTIMISE, ""); + } + else { + uiDefIconTextBut(block, BUTM, 1, (G.saction->flag & SACTION_SLIDERS)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, + "Show Sliders|", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 1, + ACTMENU_VIEW_SLIDERS, ""); + + uiDefIconTextBut(block, BUTM, 1, (G.saction->flag & SACTION_NOHIDE)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, + "Show Hidden Channels|", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 1, + ACTMENU_VIEW_NOHIDE, ""); + + uiDefIconTextBut(block, BUTM, 1, (G.saction->flag & SACTION_NODRAWGCOLORS)?ICON_CHECKBOX_DEHLT:ICON_CHECKBOX_HLT, + "Use Group Colors|", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 1, + ACTMENU_VIEW_GCOLORS, ""); + + // this option may get removed in future + uiDefIconTextBut(block, BUTM, 1, (G.saction->flag & SACTION_HORIZOPTIMISEON)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, + "Cull Out-of-View Keys (Time)|", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 1, + ACTMENU_VIEW_HORIZOPTIMISE, ""); + + uiDefIconTextBut(block, BUTM, 1, (G.saction->flag & SACTION_NOTRANSKEYCULL)?ICON_CHECKBOX_DEHLT:ICON_CHECKBOX_HLT, + "AutoMerge Keyframes|", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 1, + ACTMENU_VIEW_TRANSDELDUPS, ""); + } - uiDefIconTextBut(block, BUTM, 1, (G.saction->flag & SACTION_NOTRANSKEYCULL)?ICON_CHECKBOX_DEHLT:ICON_CHECKBOX_HLT, - "AutoMerge Keyframes|", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 1, - ACTMENU_VIEW_TRANSDELDUPS, ""); - uiDefIconTextBut(block, BUTM, 1, (G.v2d->flag & V2D_VIEWLOCK)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, "Lock Time to Other Windows|", 0, yco-=20, @@ -476,7 +499,7 @@ static uiBlock *action_viewmenu(void *arg_unused) menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_VIEW_PREVRANGECLEAR, ""); - if (G.saction->action) { + if ((G.saction->mode == SACTCONT_ACTION) && (G.saction->action)) { uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Preview Range from Action Length|Ctrl Alt P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, @@ -550,13 +573,15 @@ static uiBlock *action_selectmenu_columnmenu(void *arg_unused) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "On Current Frame|Ctrl K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_SEL_COLUMN_CFRA, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, - "On Selected Markers|Shift K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, - ACTMENU_SEL_COLUMN_MARKERSCOLUMN, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, - "Between Selected Markers|Alt K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, - ACTMENU_SEL_COLUMN_MARKERSBETWEEN, ""); + if (G_SACTION_HASMARKERS) { + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, + "On Selected Markers|Shift K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, + ACTMENU_SEL_COLUMN_MARKERSCOLUMN, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, + "Between Selected Markers|Alt K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, + ACTMENU_SEL_COLUMN_MARKERSBETWEEN, ""); + } uiBlockSetDirection(block, UI_RIGHT); uiTextBoundsBlock(block, 60); @@ -659,14 +684,18 @@ static uiBlock *action_selectmenu(void *arg_unused) "Border Select Keys|B", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_SEL_BORDER, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, - "Border Select Channels|B", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 0, - ACTMENU_SEL_BORDERC, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, - "Border Select Markers|Ctrl B", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 0, - ACTMENU_SEL_BORDERM, ""); + if (G_SACTION_HASMARKERS) { + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, + "Border Select Markers|Ctrl B", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 0, + ACTMENU_SEL_BORDERM, ""); + } + if (G.saction->mode != SACTCONT_SHAPEKEY) { + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, + "Border Select Channels|B", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 0, + ACTMENU_SEL_BORDERC, ""); + } uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); @@ -675,14 +704,18 @@ static uiBlock *action_selectmenu(void *arg_unused) "Select/Deselect All Keys|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_SEL_ALL_KEYS, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, - "Select/Deselect All Markers|Ctrl A", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 0, - ACTMENU_SEL_ALL_MARKERS, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, - "Select/Deselect All Channels|A", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 0, - ACTMENU_SEL_ALL_CHAN, ""); + if (G_SACTION_HASMARKERS) { + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, + "Select/Deselect All Markers|Ctrl A", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 0, + ACTMENU_SEL_ALL_MARKERS, ""); + } + if (G.saction->mode != SACTCONT_SHAPEKEY) { + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, + "Select/Deselect All Channels|A", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 0, + ACTMENU_SEL_ALL_CHAN, ""); + } uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); @@ -691,14 +724,18 @@ static uiBlock *action_selectmenu(void *arg_unused) "Inverse Keys|Ctrl I", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_SEL_INVERSE_KEYS, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, - "Inverse Markers|Ctrl Shift I", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 0, - ACTMENU_SEL_INVERSE_MARKERS, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, - "Inverse All Channels|Ctrl I", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 0, - ACTMENU_SEL_INVERSE_CHANNELS, ""); + if (G_SACTION_HASMARKERS) { + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, + "Inverse Markers|Ctrl Shift I", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 0, + ACTMENU_SEL_INVERSE_MARKERS, ""); + } + if (G.saction->mode != SACTCONT_SHAPEKEY) { + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, + "Inverse All Channels|Ctrl I", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 0, + ACTMENU_SEL_INVERSE_CHANNELS, ""); + } uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); @@ -971,6 +1008,40 @@ static uiBlock *action_channelmenu(void *arg_unused) return block; } +/* note: uses do_action_channelmenu too... */ +static uiBlock *action_gplayermenu(void *arg_unused) +{ + uiBlock *block; + short yco= 0, menuwidth=120; + + block= uiNewBlock(&curarea->uiblocks, "action_gplayermenu", + UI_EMBOSSP, UI_HELV, curarea->headwin); + uiBlockSetButmFunc(block, do_action_channelmenu, NULL); + + uiDefIconTextBlockBut(block, action_channelmenu_settingsmenu, + NULL, ICON_RIGHTARROW_THIN, + "Settings", 0, yco-=20, 120, 20, ""); + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, + menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, + "Delete|X", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_DELETE, ""); + + if (curarea->headertype==HEADERTOP) { + uiBlockSetDirection(block, UI_DOWN); + } + else { + uiBlockSetDirection(block, UI_TOP); + uiBlockFlipOrder(block); + } + + uiTextBoundsBlock(block, 50); + + return block; +} + static void do_action_keymenu_transformmenu(void *arg, int event) { switch (event) @@ -1400,6 +1471,51 @@ static uiBlock *action_keymenu(void *arg_unused) return block; } +/* note: uses do_action_keymenu too! */ +static uiBlock *action_framemenu(void *arg_unused) +{ + uiBlock *block; + short yco= 0, menuwidth=120; + + block= uiNewBlock(&curarea->uiblocks, "action_framemenu", + UI_EMBOSSP, UI_HELV, curarea->headwin); + uiBlockSetButmFunc(block, do_action_keymenu, NULL); + + uiDefIconTextBlockBut(block, action_keymenu_transformmenu, + NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 20, ""); + + uiDefIconTextBlockBut(block, action_keymenu_snapmenu, + NULL, ICON_RIGHTARROW_THIN, "Snap", 0, yco-=20, 120, 20, ""); + + uiDefIconTextBlockBut(block, action_keymenu_mirrormenu, + NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, 120, 20, ""); + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, + menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, + "Duplicate|Shift D", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 0, + ACTMENU_KEY_DUPLICATE, ""); + + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, + "Delete|X", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 0, + ACTMENU_KEY_DELETE, ""); + + if(curarea->headertype==HEADERTOP) { + uiBlockSetDirection(block, UI_DOWN); + } + else { + uiBlockSetDirection(block, UI_TOP); + uiBlockFlipOrder(block); + } + + uiTextBoundsBlock(block, 50); + + return block; +} + static void do_action_markermenu(void *arg, int event) { switch(event) @@ -1461,17 +1577,19 @@ static uiBlock *action_markermenu(void *arg_unused) menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_NAME, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move Marker|Ctrl G", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_MOVE, ""); - - uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); - - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Pose Marker|Shift L", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALADD, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Rename Pose Marker|Ctrl Shift L", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALRENAME, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete Pose Marker|Alt L", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALDELETE, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move Pose Marker|Ctrl L", 0, yco-=20, - menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALMOVE, ""); + + if (G.saction->mode == SACTCONT_ACTION) { + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Pose Marker|Shift L", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALADD, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Rename Pose Marker|Ctrl Shift L", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALRENAME, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete Pose Marker|Alt L", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALDELETE, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move Pose Marker|Ctrl L", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALMOVE, ""); + } if(curarea->headertype==HEADERTOP) { uiBlockSetDirection(block, UI_DOWN); @@ -1498,6 +1616,7 @@ void action_buttons(void) return; /* copied from drawactionspace.... */ + // FIXME: do for gpencil too? if (!G.saction->pin) { if (OBACT) G.saction->action = OBACT->action; @@ -1558,68 +1677,95 @@ void action_buttons(void) "Select", xco, -2, xmax-3, 24, ""); xco+= xmax; - if (G.saction->action) { + if ((G.saction->action) && (G.saction->mode==SACTCONT_ACTION)) { xmax= GetButStringLength("Channel"); uiDefPulldownBut(block, action_channelmenu, NULL, "Channel", xco, -2, xmax-3, 24, ""); xco+= xmax; } + else if (G.saction->mode==SACTCONT_GPENCIL) { + xmax= GetButStringLength("Channel"); + uiDefPulldownBut(block, action_gplayermenu, NULL, + "Channel", xco, -2, xmax-3, 24, ""); + xco+= xmax; + } xmax= GetButStringLength("Marker"); uiDefPulldownBut(block, action_markermenu, NULL, "Marker", xco, -2, xmax-3, 24, ""); xco+= xmax; - xmax= GetButStringLength("Key"); - uiDefPulldownBut(block, action_keymenu, NULL, - "Key", xco, -2, xmax-3, 24, ""); - xco+= xmax; + if (G.saction->mode == SACTCONT_GPENCIL) { + xmax= GetButStringLength("Frame"); + uiDefPulldownBut(block, action_framemenu, NULL, + "Frame", xco, -2, xmax-3, 24, ""); + xco+= xmax; + + } + else { + xmax= GetButStringLength("Key"); + uiDefPulldownBut(block, action_keymenu, NULL, + "Key", xco, -2, xmax-3, 24, ""); + xco+= xmax; + } } uiBlockSetEmboss(block, UI_EMBOSS); - /* NAME ETC */ - ob= OBACT; - from = (ID *)ob; - - xco= std_libbuttons(block, xco, 0, B_ACTPIN, &G.saction->pin, - B_ACTIONBROWSE, ID_AC, 0, (ID*)G.saction->action, - from, &(G.saction->actnr), B_ACTALONE, - B_ACTLOCAL, B_ACTIONDELETE, 0, B_KEEPDATA); - - uiClearButLock(); + /* MODE SELECTOR */ + uiDefButC(block, MENU, B_REDR, + "Editor Mode %t|Action Editor %x0|ShapeKey Editor %x1|Grease Pencil %x2", + xco,0,90,YIC, &(G.saction->mode), 0, 1, 0, 0, + "Editing modes for this editor"); - xco += 8; - /* COPY PASTE */ - uiBlockBeginAlign(block); - if (curarea->headertype==HEADERTOP) { - uiDefIconBut(block, BUT, B_ACTCOPYKEYS, ICON_COPYUP, xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Copies the selected keyframes from the selected channel(s) to the buffer"); - uiDefIconBut(block, BUT, B_ACTPASTEKEYS, ICON_PASTEUP, xco+=XIC,0,XIC,YIC, 0, 0, 0, 0, 0, "Pastes the keyframes from the buffer"); - } - else { - uiDefIconBut(block, BUT, B_ACTCOPYKEYS, ICON_COPYDOWN, xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Copies the selected keyframes from the selected channel(s) to the buffer"); - uiDefIconBut(block, BUT, B_ACTPASTEKEYS, ICON_PASTEDOWN, xco+=XIC,0,XIC,YIC, 0, 0, 0, 0, 0, "Pastes the keyframes from the buffer"); - } - uiBlockEndAlign(block); - xco += (XIC + 8); + xco += (90 + 8); - /* draw AUTOSNAP */ - if (G.saction->flag & SACTION_DRAWTIME) { - uiDefButS(block, MENU, B_REDR, - "Auto-Snap Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3", - xco,0,70,YIC, &(G.saction->autosnap), 0, 1, 0, 0, - "Auto-snapping mode for keyframes when transforming"); - } - else { - uiDefButS(block, MENU, B_REDR, - "Auto-Snap Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3", - xco,0,70,YIC, &(G.saction->autosnap), 0, 1, 0, 0, - "Auto-snapping mode for keyframes when transforming"); + /* MODE-DEPENDENT DRAWING */ + if (G.saction->mode != SACTCONT_GPENCIL) { + /* NAME ETC */ + ob= OBACT; + from = (ID *)ob; + + xco= std_libbuttons(block, xco, 0, B_ACTPIN, &G.saction->pin, + B_ACTIONBROWSE, ID_AC, 0, (ID*)G.saction->action, + from, &(G.saction->actnr), B_ACTALONE, + B_ACTLOCAL, B_ACTIONDELETE, 0, B_KEEPDATA); + + uiClearButLock(); + + xco += 8; + + /* COPY PASTE */ + uiBlockBeginAlign(block); + if (curarea->headertype==HEADERTOP) { + uiDefIconBut(block, BUT, B_ACTCOPYKEYS, ICON_COPYUP, xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Copies the selected keyframes from the selected channel(s) to the buffer"); + uiDefIconBut(block, BUT, B_ACTPASTEKEYS, ICON_PASTEUP, xco+=XIC,0,XIC,YIC, 0, 0, 0, 0, 0, "Pastes the keyframes from the buffer"); + } + else { + uiDefIconBut(block, BUT, B_ACTCOPYKEYS, ICON_COPYDOWN, xco,0,XIC,YIC, 0, 0, 0, 0, 0, "Copies the selected keyframes from the selected channel(s) to the buffer"); + uiDefIconBut(block, BUT, B_ACTPASTEKEYS, ICON_PASTEDOWN, xco+=XIC,0,XIC,YIC, 0, 0, 0, 0, 0, "Pastes the keyframes from the buffer"); + } + uiBlockEndAlign(block); + xco += (XIC + 8); + + /* draw AUTOSNAP */ + if (G.saction->flag & SACTION_DRAWTIME) { + uiDefButC(block, MENU, B_REDR, + "Auto-Snap Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3", + xco,0,70,YIC, &(G.saction->autosnap), 0, 1, 0, 0, + "Auto-snapping mode for keyframes when transforming"); + } + else { + uiDefButC(block, MENU, B_REDR, + "Auto-Snap Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3", + xco,0,70,YIC, &(G.saction->autosnap), 0, 1, 0, 0, + "Auto-snapping mode for keyframes when transforming"); + } + + xco += (70 + 8); } - xco += (70 + 8); - /* draw LOCK */ uiDefIconButS(block, ICONTOG, 1, ICON_UNLOCKED, xco, 0, XIC, YIC, &(G.saction->lock), 0, 0, 0, 0, diff --git a/source/blender/src/header_info.c b/source/blender/src/header_info.c index dac7c7bc2c6..a9280d9dd19 100644 --- a/source/blender/src/header_info.c +++ b/source/blender/src/header_info.c @@ -540,6 +540,42 @@ static void check_packAll() } } +#ifdef _WIN32 +static void copy_game_dll(char *dll_filename, char *source_dir, char *dest_dir) +{ + char source_filename[FILE_MAX]; + char dest_filename[FILE_MAX]; + + strcpy( source_filename, source_dir ); + strcat( source_filename, dll_filename ); + + strcpy( dest_filename, dest_dir ); + strcat( dest_filename, dll_filename ); + + if(!BLI_exists(dest_filename)) { + BLI_copy_fileops( source_filename, dest_filename ); + } +} + +static void copy_all_game_dlls(char *str) +{ +#define GAME_DLL_COUNT 7 + char *game_dll_list[GAME_DLL_COUNT]={"gnu_gettext.dll", "libpng.dll", "libtiff.dll", "pthreadVC2.dll", "python25.dll", "SDL.dll", "zlib.dll"}; + + char dest_dir[FILE_MAX]; + char source_dir[FILE_MAX]; + int i; + + strcpy(source_dir, get_install_dir()); + strcat(source_dir, "\\"); + BLI_split_dirfile_basic(str, dest_dir, NULL); + + for (i= 0; i< GAME_DLL_COUNT; i++) { + copy_game_dll(game_dll_list[i], source_dir, dest_dir ); + }; +} +#endif + static int write_runtime(char *str, char *exename) { char *freestr= NULL; @@ -587,7 +623,14 @@ static void write_runtime_check(char *str) #endif write_runtime(str, player); + +#ifdef _WIN32 + // get a list of the .DLLs in the Blender folder and copy all of these to the destination folder if they don't exist + copy_all_game_dlls(str); +#endif } + + /* end keyed functions */ /************************** MAIN MENU *****************************/ @@ -1026,7 +1069,7 @@ static uiBlock *info_externalfiles(void *arg_unused) block= uiNewBlock(&curarea->uiblocks, "info_externalfiles", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin); uiBlockSetButmFunc(block, do_info_externalfiles, NULL); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack into Blend", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Pack into .blend file", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 1, ""); #if 0 uiDefBut(block, BUTM, 1, "Unpack Data to current dir", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 2, "Removes all packed files from the project and saves them to the current directory"); #endif @@ -1036,8 +1079,8 @@ static uiBlock *info_externalfiles(void *arg_unused) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Make all Paths Relative", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 10, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Make all Paths Absolute", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 11, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Report Missing Files", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 12, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Find Missing Files", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 13, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Report Missing Files...", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 12, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Find Missing Files...", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 13, ""); uiBlockSetDirection(block, UI_RIGHT); uiTextBoundsBlock(block, 60); @@ -1078,9 +1121,9 @@ static uiBlock *info_filemenu(void *arg_unused) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Screenshot Subwindow|Ctrl F3", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 24, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Screenshot All|Ctrl Shift F3", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 25, ""); #if GAMEBLENDER == 1 - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Runtime...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 22, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Game As Runtime...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 22, ""); #ifdef _WIN32 - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Dynamic Runtime...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 23, ""); +// uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Save Dynamic Runtime...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 23, ""); #endif #endif uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); diff --git a/source/blender/src/header_ipo.c b/source/blender/src/header_ipo.c index 15caf325ec6..59d542e72ec 100644 --- a/source/blender/src/header_ipo.c +++ b/source/blender/src/header_ipo.c @@ -970,7 +970,7 @@ static char *ipo_modeselect_pup(void) if(ob && ob->type==OB_LAMP) str += sprintf(str,formatstring, "Lamp",ID_LA, ICON_LAMP); - if(ob && give_current_texture(ob, ob->actcol)) + if((ob && give_current_texture(ob, ob->actcol))||(give_current_world_texture())) str += sprintf(str,formatstring, "Texture",ID_TE, ICON_TEXTURE); if(ob){ diff --git a/source/blender/src/header_node.c b/source/blender/src/header_node.c index ec6bbc9044c..4c7b4aa80bc 100644 --- a/source/blender/src/header_node.c +++ b/source/blender/src/header_node.c @@ -110,12 +110,16 @@ static void do_node_viewmenu(void *arg, int event) case 3: /* View all */ snode_home(curarea, snode); break; + case 4: /* Grease Pencil */ + add_blockhandler(curarea, NODES_HANDLER_GREASEPENCIL, UI_PNL_UNSTOW); + break; } allqueue(REDRAWNODE, 0); } static uiBlock *node_viewmenu(void *arg_unused) { + SpaceNode *snode= curarea->spacedata.first; uiBlock *block; short yco= 0, menuwidth=120; @@ -123,6 +127,12 @@ static uiBlock *node_viewmenu(void *arg_unused) UI_EMBOSSP, UI_HELV, curarea->headwin); uiBlockSetButmFunc(block, do_node_viewmenu, NULL); + if (snode->nodetree) { + uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Grease Pencil...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, ""); + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + } + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom In|NumPad +", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Zoom Out|NumPad -", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); diff --git a/source/blender/src/header_seq.c b/source/blender/src/header_seq.c index 393830a61cf..e5a63b9fe45 100644 --- a/source/blender/src/header_seq.c +++ b/source/blender/src/header_seq.c @@ -100,6 +100,9 @@ static void do_seq_viewmenu(void *arg, int event) case 6: /* Draw time/frames */ sseq->flag ^= SEQ_DRAWFRAMES; break; + case 7: /* Grease Pencil */ + add_blockhandler(curarea, SEQ_HANDLER_GREASEPENCIL, UI_PNL_UNSTOW); + break; } } @@ -111,7 +114,15 @@ static uiBlock *seq_viewmenu(void *arg_unused) block= uiNewBlock(&curarea->uiblocks, "seq_viewmenu", UI_EMBOSSP, UI_HELV, curarea->headwin); uiBlockSetButmFunc(block, do_seq_viewmenu, NULL); - + + if (sseq->mainb) { + uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, + "Grease Pencil...", 0, yco-=20, + menuwidth, 19, NULL, 0.0, 0.0, 1, 7, ""); + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + } + if (sseq->mainb == 0) { uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Play Back Animation " diff --git a/source/blender/src/header_view3d.c b/source/blender/src/header_view3d.c index 0f3a46c8a8c..948023bebfb 100644 --- a/source/blender/src/header_view3d.c +++ b/source/blender/src/header_view3d.c @@ -166,9 +166,9 @@ void do_layer_buttons(short event) if(event==-1 && (G.qual & LR_CTRLKEY)) { G.vd->scenelock= !G.vd->scenelock; do_view3d_buttons(B_SCENELOCK); - } else if (event==-1) { + } else if (event<0) { if(G.vd->lay== (1<<20)-1) { - if(G.qual & LR_SHIFTKEY) G.vd->lay= oldlay; + if(event==-2 || G.qual & LR_SHIFTKEY) G.vd->lay= oldlay; } else { oldlay= G.vd->lay; @@ -601,7 +601,13 @@ static void do_view3d_viewmenu(void *arg, int event) break; case 20: /* Transform Space Panel */ add_blockhandler(curarea, VIEW3D_HANDLER_TRANSFORM, UI_PNL_UNSTOW); + break; + case 21: /* Grease Pencil */ + add_blockhandler(curarea, VIEW3D_HANDLER_GREASEPENCIL, UI_PNL_UNSTOW); break; + case 22: /* View all layers */ + do_layer_buttons(-2); + break; } allqueue(REDRAWVIEW3D, 1); } @@ -619,6 +625,7 @@ static uiBlock *view3d_viewmenu(void *arg_unused) uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Render Preview...|Shift P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 18, ""); uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "View Properties...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 16, ""); uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Background Image...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 15, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Grease Pencil...", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 21, ""); uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); @@ -644,6 +651,11 @@ static uiBlock *view3d_viewmenu(void *arg_unused) uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + if(G.vd->lay== (1<<20)-1) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Previous Layers|Shift ~", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 22, ""); + else uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show All Layers| ~", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 22, ""); + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + if(G.vd->localview) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Local View|NumPad /", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, ""); else uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Local View|NumPad /", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 7, ""); if(!G.vd->localview) uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Global View|NumPad /", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 8, ""); @@ -722,6 +734,9 @@ void do_view3d_select_object_typemenu(void *arg, int event) case 10: /* Lamp */ selectall_type(OB_LAMP); break; + case 20: + do_layer_buttons(-2); + break; } allqueue(REDRAWVIEW3D, 0); } @@ -1310,12 +1325,21 @@ static void do_view3d_select_armaturemenu(void *arg, int event) case 2: /* Select/Deselect all */ deselectall_armature(1, 1); break; - case 3: /* Select Parent(s) */ - select_bone_parent(); - break; - case 4: /* Swap Select All */ + case 3: /* Swap Select All */ deselectall_armature(3, 1); break; + case 4: /* Select parent */ + armature_select_hierarchy(BONE_SELECT_PARENT, 0); + break; + case 5: /* Select child */ + armature_select_hierarchy(BONE_SELECT_CHILD, 0); + break; + case 6: /* Extend Select parent */ + armature_select_hierarchy(BONE_SELECT_PARENT, 1); + break; + case 7: /* Extend Select child */ + armature_select_hierarchy(BONE_SELECT_CHILD, 1); + break; } allqueue(REDRAWVIEW3D, 0); } @@ -1333,11 +1357,18 @@ static uiBlock *view3d_select_armaturemenu(void *arg_unused) uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Inverse|Ctrl I", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Swap Select All|Ctrl I", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, ""); + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Parent|[", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Child|]", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, ""); + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Extend Select Parent|Shift [", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Extend Select Child|Shift ]", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Parent(s)|P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, ""); - if(curarea->headertype==HEADERTOP) { uiBlockSetDirection(block, UI_DOWN); } @@ -1364,12 +1395,21 @@ static void do_view3d_select_pose_armaturemenu(void *arg, int event) case 3: /* Select Target(s) of Constraint(s) */ pose_select_constraint_target(); break; - case 4: /* Select Bone's Parent */ - select_bone_parent(); - break; case 5: /* Swap Select All */ deselectall_posearmature(OBACT, 3, 1); break; + case 6: /* Select parent */ + pose_select_hierarchy(BONE_SELECT_PARENT, 0); + break; + case 7: /* Select child */ + pose_select_hierarchy(BONE_SELECT_CHILD, 0); + break; + case 8: /* Extend Select parent */ + pose_select_hierarchy(BONE_SELECT_PARENT, 1); + break; + case 9: /* Extend Select child */ + pose_select_hierarchy(BONE_SELECT_CHILD, 1); + break; } allqueue(REDRAWVIEW3D, 0); } @@ -1389,8 +1429,17 @@ static uiBlock *view3d_select_pose_armaturemenu(void *arg_unused) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select/Deselect All|A", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Swap Select All|Ctrl I", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Constraint Target|W", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, ""); - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Parent(s)|P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, ""); - + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Parent|[", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Select Child|]", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, ""); + + uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Extend Select Parent|Shift [", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Extend Select Child|Shift ]", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, ""); + if(curarea->headertype==HEADERTOP) { uiBlockSetDirection(block, UI_DOWN); } @@ -2192,6 +2241,7 @@ static uiBlock *view3d_edit_object_copyattrmenu(void *arg_unused) uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Mass|Ctrl C, 7", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Damping|Ctrl C, 8", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "All Physical Attributes|Ctrl C, 11", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Properties|Ctrl C, 9", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Logic Bricks|Ctrl C, 10", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Protected Transform |Ctrl C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 29, ""); @@ -2462,8 +2512,11 @@ static void do_view3d_edit_objectmenu(void *arg, int event) case 15: /* Object Panel */ add_blockhandler(curarea, VIEW3D_HANDLER_OBJECT, UI_PNL_UNSTOW); break; + case 16: /* make proxy object*/ + make_proxy(); + break; #ifdef WITH_VERSE - case 16: /* Share Object at Verse server */ + case 17: /* Share Object at Verse server */ if(session_list.first != session_list.last) session = session_menu(); else session = session_list.first; if(session) b_verse_push_object(session, ob); @@ -2488,7 +2541,7 @@ static uiBlock *view3d_edit_objectmenu(void *arg_unused) if (base) ob= base->object; if(ob && (ob->type == OB_MESH) && (!ob->vnode)) { - uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Share at Verse Server", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 16, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Share at Verse Server", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 17, ""); uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); } } @@ -2514,6 +2567,7 @@ static uiBlock *view3d_edit_objectmenu(void *arg_unused) uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Make Proxy|Ctrl Alt P", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 16, ""); uiDefIconTextBlockBut(block, view3d_edit_object_makelinksmenu, NULL, ICON_RIGHTARROW_THIN, "Make Links", 0, yco-=20, 120, 19, ""); uiDefIconTextBlockBut(block, view3d_edit_object_singleusermenu, NULL, ICON_RIGHTARROW_THIN, "Make Single User", 0, yco-=20, 120, 19, ""); uiDefIconTextBlockBut(block, view3d_edit_object_makelocalmenu, NULL, ICON_RIGHTARROW_THIN, "Make Local", 0, yco-=20, 120, 19, ""); diff --git a/source/blender/src/interface.c b/source/blender/src/interface.c index 4fbf92d646e..e7b5b176979 100644 --- a/source/blender/src/interface.c +++ b/source/blender/src/interface.c @@ -532,7 +532,7 @@ static int ui_but_copy_paste(uiBut *but, char mode) /* give butfunc the original text too */ /* feature used for bone renaming, channels, etc */ if(but->func_arg2==NULL) { - strncpy(backstr, but->drawstr, UI_MAX_DRAW_STR); + strncpy(backstr, but->poin, UI_MAX_DRAW_STR); but->func_arg2= backstr; } strncpy(but->poin, but_copypaste_str, but->max); @@ -618,6 +618,9 @@ void uiBoundsBlock(uiBlock *block, int addval) uiBut *bt; int xof; + if(block==NULL) + return; + if(block->buttons.first==NULL) { if(block->panel) { block->minx= 0.0; block->maxx= block->panel->sizex; @@ -5405,7 +5408,9 @@ uiBlock *uiNewBlock(ListBase *lb, char *name, short dt, short font, short win) int getsizex, getsizey; bwin_getsize(win, &getsizex, &getsizey); - block->aspect= 2.0/( (getsizex)*block->winmat[0][0]); + /* TODO - investigate why block->winmat[0][0] is negative + * in the image view when viewRedrawForce is called */ + block->aspect= 2.0/fabs( (getsizex)*block->winmat[0][0]); } uiSetCurFont(block, font); @@ -5646,6 +5651,8 @@ static int ui_auto_themecol(uiBut *but) // (weak!) detect if it is a blockloop if(but->block->dt == UI_EMBOSSP) return TH_MENU_ITEM; return TH_BUT_POPUP; + case ROUNDBOX: + return TH_PANEL; default: return TH_BUT_NEUTRAL; } diff --git a/source/blender/src/interface_draw.c b/source/blender/src/interface_draw.c index e7041e60003..83ae449b989 100644 --- a/source/blender/src/interface_draw.c +++ b/source/blender/src/interface_draw.c @@ -2351,7 +2351,7 @@ static void ui_draw_roundbox(uiBut *but) { glEnable(GL_BLEND); - BIF_ThemeColorShadeAlpha(TH_PANEL, but->a2, but->a2); + BIF_ThemeColorShadeAlpha(but->themecol, but->a2, but->a2); uiSetRoundBox(but->a1); gl_round_box(GL_POLYGON, but->x1, but->y1, but->x2, but->y2, but->min); diff --git a/source/blender/src/meshlaplacian.c b/source/blender/src/meshlaplacian.c index 4d84672185a..60f569ecf0e 100644 --- a/source/blender/src/meshlaplacian.c +++ b/source/blender/src/meshlaplacian.c @@ -1281,9 +1281,9 @@ static int meshdeform_inside_cage(MeshDeformBind *mdb, float *co) outside[1] = co[1] + (mdb->max[1] - mdb->min[1] + 1.0f)*MESHDEFORM_OFFSET[i][1]; outside[2] = co[2] + (mdb->max[2] - mdb->min[2] + 1.0f)*MESHDEFORM_OFFSET[i][2]; + VECCOPY(start, co); VECSUB(dir, outside, start); Normalize(dir); - VECCOPY(start, co); isect = meshdeform_ray_tree_intersect(mdb, start, outside); if(isect && !isect->facing) diff --git a/source/blender/src/outliner.c b/source/blender/src/outliner.c index 683b06aafc4..3f328a0cfb2 100644 --- a/source/blender/src/outliner.c +++ b/source/blender/src/outliner.c @@ -68,6 +68,7 @@ #include "BKE_main.h" #include "BKE_material.h" #include "BKE_modifier.h" +#include "BKE_object.h" #include "BKE_screen.h" #include "BKE_scene.h" #include "BKE_utildefines.h" @@ -698,6 +699,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i for (index=0,md=ob->modifiers.first; md; index++,md=md->next) { TreeElement *te = outliner_add_element(soops, &temod->subtree, ob, temod, TSE_MODIFIER, index); te->name= md->name; + te->directdata = md; if (md->type==eModifierType_Lattice) { outliner_add_element(soops, &te->subtree, ((LatticeModifierData*) md)->object, te, TSE_LINKED_OB, 0); @@ -3523,6 +3525,27 @@ static void restrictbutton_r_lay_cb(void *poin, void *poin2) allqueue(REDRAWBUTSSCENE, 0); } +static void restrictbutton_modifier_cb(void *poin, void *poin2) +{ + Object *ob = (Object *)poin; + + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + object_handle_update(ob); + countall(); + + allqueue(REDRAWOOPS, 0); + allqueue(REDRAWVIEW3D, 0); + allqueue(REDRAWBUTSEDIT, 0); + allqueue(REDRAWBUTSOBJECT, 0); +} + +static void restrictbutton_bone_cb(void *poin, void *poin2) +{ + allqueue(REDRAWOOPS, 0); + allqueue(REDRAWVIEW3D, 0); + allqueue(REDRAWBUTSEDIT, 0); +} + static void namebutton_cb(void *tep, void *oldnamep) { SpaceOops *soops= curarea->spacedata.first; @@ -3631,7 +3654,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, SpaceOops *soops, ListBas uiBut *bt; TreeElement *te; TreeStoreElem *tselem; - Object *ob; + Object *ob = NULL; for(te= lb->first; te; te= te->next) { tselem= TREESTORE(te); @@ -3639,7 +3662,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, SpaceOops *soops, ListBas /* objects have toggle-able restriction flags */ if(tselem->type==0 && te->idcode==ID_OB) { ob = (Object *)tselem->id; - + uiBlockSetEmboss(block, UI_EMBOSSN); bt= uiDefIconButBitS(block, ICONTOG, OB_RESTRICT_VIEW, REDRAWALL, ICON_RESTRICT_VIEW_OFF, (int)soops->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, te->ys, 17, OL_H-1, &(ob->restrictflag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); @@ -3685,6 +3708,40 @@ static void outliner_draw_restrictbuts(uiBlock *block, SpaceOops *soops, ListBas uiBlockSetEmboss(block, UI_EMBOSS); } + else if(tselem->type==TSE_MODIFIER) { + ModifierData *md= (ModifierData *)te->directdata; + ob = (Object *)tselem->id; + + uiBlockSetEmboss(block, UI_EMBOSSN); + bt= uiDefIconButBitI(block, ICONTOGN, eModifierMode_Realtime, REDRAWALL, ICON_RESTRICT_VIEW_OFF, + (int)soops->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, te->ys, 17, OL_H-1, &(md->mode), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); + uiButSetFunc(bt, restrictbutton_modifier_cb, ob, NULL); + uiButSetFlag(bt, UI_NO_HILITE); + + bt= uiDefIconButBitI(block, ICONTOGN, eModifierMode_Render, REDRAWALL, ICON_RESTRICT_RENDER_OFF, + (int)soops->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX, te->ys, 17, OL_H-1, &(md->mode), 0, 0, 0, 0, "Restrict/Allow renderability"); + uiButSetFunc(bt, restrictbutton_modifier_cb, ob, NULL); + uiButSetFlag(bt, UI_NO_HILITE); + } + else if(tselem->type==TSE_POSE_CHANNEL) { + bPoseChannel *pchan= (bPoseChannel *)te->directdata; + Bone *bone = pchan->bone; + + uiBlockSetEmboss(block, UI_EMBOSSN); + bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_P, REDRAWALL, ICON_RESTRICT_VIEW_OFF, + (int)soops->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, te->ys, 17, OL_H-1, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); + uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL); + uiButSetFlag(bt, UI_NO_HILITE); + } + else if(tselem->type==TSE_EBONE) { + EditBone *ebone= (EditBone *)te->directdata; + + uiBlockSetEmboss(block, UI_EMBOSSN); + bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_A, REDRAWALL, ICON_RESTRICT_VIEW_OFF, + (int)soops->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, te->ys, 17, OL_H-1, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View"); + uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL); + uiButSetFlag(bt, UI_NO_HILITE); + } } if((tselem->flag & TSE_CLOSED)==0) outliner_draw_restrictbuts(block, soops, &te->subtree); diff --git a/source/blender/src/poseobject.c b/source/blender/src/poseobject.c index cc08bf53a72..28b8729a247 100644 --- a/source/blender/src/poseobject.c +++ b/source/blender/src/poseobject.c @@ -180,27 +180,26 @@ bPoseChannel *get_active_posechannel (Object *ob) return NULL; } -/* if a selected or active bone is protected, throw error and return 1 */ +/* if a selected or active bone is protected, throw error (oonly if warn==1) and return 1 */ /* only_selected==1 : the active bone is allowed to be protected */ -static int pose_has_protected_selected(Object *ob, int only_selected) +static short pose_has_protected_selected(Object *ob, short only_selected, short warn) { - /* check protection */ - if(ob->proxy) { + if (ob->proxy) { bPoseChannel *pchan; bArmature *arm= ob->data; - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if(pchan->bone && (pchan->bone->layer & arm->layer)) { - if(pchan->bone->layer & arm->layer_protected) { - if(only_selected && (pchan->bone->flag & BONE_ACTIVE)); - else if(pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) + for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + if (pchan->bone && (pchan->bone->layer & arm->layer)) { + if (pchan->bone->layer & arm->layer_protected) { + if (only_selected && (pchan->bone->flag & BONE_ACTIVE)); + else if (pchan->bone->flag & (BONE_ACTIVE|BONE_SELECTED)) break; } } } - if(pchan) { - error("Cannot change Proxy protected bones"); + if (pchan) { + if (warn) error("Cannot change Proxy protected bones"); return 1; } } @@ -480,6 +479,67 @@ void pose_select_constraint_target(void) } +void pose_select_hierarchy(short direction, short add_to_sel) +{ + Object *ob= OBACT; + bArmature *arm= ob->data; + bPoseChannel *pchan; + Bone *curbone, *pabone, *chbone; + + /* paranoia checks */ + if (!ob && !ob->pose) return; + if (ob==G.obedit || (ob->flag & OB_POSEMODE)==0) return; + + for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + curbone= pchan->bone; + + if (arm->layer & curbone->layer) { + if (curbone->flag & (BONE_ACTIVE)) { + if (direction == BONE_SELECT_PARENT) { + + if (pchan->parent == NULL) continue; + else pabone= pchan->parent->bone; + + if ((arm->layer & pabone->layer) && !(pabone->flag & BONE_HIDDEN_P)) { + + if (!add_to_sel) curbone->flag &= ~BONE_SELECTED; + curbone->flag &= ~BONE_ACTIVE; + pabone->flag |= (BONE_ACTIVE|BONE_SELECTED); + + select_actionchannel_by_name (ob->action, pchan->name, 0); + select_actionchannel_by_name (ob->action, pchan->parent->name, 1); + break; + } + } else { // BONE_SELECT_CHILD + + if (pchan->child == NULL) continue; + else chbone = pchan->child->bone; + + if ((arm->layer & chbone->layer) && !(chbone->flag & BONE_HIDDEN_P)) { + + if (!add_to_sel) curbone->flag &= ~BONE_SELECTED; + curbone->flag &= ~BONE_ACTIVE; + chbone->flag |= (BONE_ACTIVE|BONE_SELECTED); + + select_actionchannel_by_name (ob->action, pchan->name, 0); + select_actionchannel_by_name (ob->action, pchan->child->name, 1); + break; + } + } + } + } + } + + allqueue (REDRAWVIEW3D, 0); + allqueue (REDRAWBUTSOBJECT, 0); + allqueue (REDRAWOOPS, 0); + + if (direction==BONE_SELECT_PARENT) + BIF_undo_push("Select pose bone parent"); + if (direction==BONE_SELECT_CHILD) + BIF_undo_push("Select pose bone child"); +} + /* context: active channel */ void pose_special_editmenu(void) { @@ -540,7 +600,7 @@ void pose_clear_IK(void) if(!ob && !ob->pose) return; if(ob==G.obedit || (ob->flag & OB_POSEMODE)==0) return; - if(pose_has_protected_selected(ob, 0)) + if(pose_has_protected_selected(ob, 0, 1)) return; if(okee("Remove IK constraint(s)")==0) return; @@ -581,7 +641,7 @@ void pose_clear_constraints(void) if(!ob && !ob->pose) return; if(ob==G.obedit || (ob->flag & OB_POSEMODE)==0) return; - if(pose_has_protected_selected(ob, 0)) + if(pose_has_protected_selected(ob, 0, 1)) return; if(okee("Remove Constraints")==0) return; @@ -612,38 +672,49 @@ void pose_copy_menu(void) Object *ob= OBACT; bArmature *arm= ob->data; bPoseChannel *pchan, *pchanact; - short nr; + short nr=0; int i=0; /* paranoia checks */ - if(!ob && !ob->pose) return; - if(ob==G.obedit || (ob->flag & OB_POSEMODE)==0) return; + if (ELEM(NULL, ob, ob->pose)) return; + if ((ob==G.obedit) || (ob->flag & OB_POSEMODE)==0) return; /* find active */ - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if(pchan->bone->flag & BONE_ACTIVE) break; + for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + if (pchan->bone->flag & BONE_ACTIVE) + break; } - if(pchan==NULL) return; - - if(pose_has_protected_selected(ob, 1)) - return; - + if (pchan==NULL) return; pchanact= pchan; - i= BLI_countlist(&(pchanact->constraints)); /* if there are 24 or less, allow for the user to select constraints */ - if (i<25) - nr= pupmenu("Copy Pose Attributes %t|Local Location%x1|Local Rotation%x2|Local Size%x3|%l|Visual Location %x9|Visual Rotation%x10|Visual Size%x11|%l|Constraints (All)%x4|Constraints...%x5|%l|Transform Locks%x6|IK Limits%x7|Bone Shape%x8"); - else - nr= pupmenu("Copy Pose Attributes %t|Local Location%x1|Local Rotation%x2|Local Size%x3|%l|Visual Location %x9|Visual Rotation%x10|Visual Size%x11|%l|Constraints (All)%x4|%l|Transform Locks%x6|IK Limits%x7|Bone Shape%x8"); + /* if proxy-protected bones selected, some things (such as locks + displays) shouldn't be changable, + * but for constraints (just add local constraints) + */ + if (pose_has_protected_selected(ob, 1, 0)) { + i= BLI_countlist(&(pchanact->constraints)); /* if there are 24 or less, allow for the user to select constraints */ + if (i < 25) + nr= pupmenu("Copy Pose Attributes %t|Local Location%x1|Local Rotation%x2|Local Size%x3|%l|Visual Location %x9|Visual Rotation%x10|Visual Size%x11|%l|Constraints (All)%x4|Constraints...%x5"); + else + nr= pupmenu("Copy Pose Attributes %t|Local Location%x1|Local Rotation%x2|Local Size%x3|%l|Visual Location %x9|Visual Rotation%x10|Visual Size%x11|%l|Constraints (All)%x4"); + } + else { + i= BLI_countlist(&(pchanact->constraints)); /* if there are 24 or less, allow for the user to select constraints */ + if (i < 25) + nr= pupmenu("Copy Pose Attributes %t|Local Location%x1|Local Rotation%x2|Local Size%x3|%l|Visual Location %x9|Visual Rotation%x10|Visual Size%x11|%l|Constraints (All)%x4|Constraints...%x5|%l|Transform Locks%x6|IK Limits%x7|Bone Shape%x8"); + else + nr= pupmenu("Copy Pose Attributes %t|Local Location%x1|Local Rotation%x2|Local Size%x3|%l|Visual Location %x9|Visual Rotation%x10|Visual Size%x11|%l|Constraints (All)%x4|%l|Transform Locks%x6|IK Limits%x7|Bone Shape%x8"); + } - if(nr==-1) return; - if(nr!=5) { - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if( (arm->layer & pchan->bone->layer) && - (pchan->bone->flag & BONE_SELECTED) && - (pchan!=pchanact) - ) { + if (nr <= 0) + return; + + if (nr != 5) { + for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + if ( (arm->layer & pchan->bone->layer) && + (pchan->bone->flag & BONE_SELECTED) && + (pchan != pchanact) ) + { switch (nr) { case 1: /* Local Location */ VECCOPY(pchan->loc, pchanact->loc); @@ -656,13 +727,26 @@ void pose_copy_menu(void) break; case 4: /* All Constraints */ { - free_constraints(&pchan->constraints); - copy_constraints(&pchan->constraints, &pchanact->constraints); - pchan->constflag = pchanact->constflag; + ListBase tmp_constraints = {NULL, NULL}; - if (ob->pose) { - ob->pose->flag |= POSE_RECALC; + /* copy constraints to tmpbase and apply 'local' tags before + * appending to list of constraints for this channel + */ + copy_constraints(&tmp_constraints, &pchanact->constraints); + if ((ob->proxy) && (pchan->bone->layer & arm->layer_protected)) { + bConstraint *con; + + /* add proxy-local tags */ + for (con= tmp_constraints.first; con; con= con->next) + con->flag |= CONSTRAINT_PROXY_LOCAL; } + addlisttolist(&pchan->constraints, &tmp_constraints); + + /* update flags (need to add here, not just copy) */ + pchan->constflag |= pchanact->constflag; + + if (ob->pose) + ob->pose->flag |= POSE_RECALC; } break; case 6: /* Transform Locks */ @@ -703,12 +787,13 @@ void pose_copy_menu(void) } } } - } else { /* constraints, optional */ + } + else { /* constraints, optional (note: max we can have is 24 constraints) */ bConstraint *con, *con_back; int const_toggle[24]; - ListBase const_copy={0, 0}; + ListBase const_copy = {NULL, NULL}; - duplicatelist (&const_copy, &(pchanact->constraints)); + duplicatelist(&const_copy, &(pchanact->constraints)); /* build the puplist of constraints */ for (con = pchanact->constraints.first, i=0; con; con=con->next, i++){ @@ -723,32 +808,46 @@ void pose_copy_menu(void) /* now build a new listbase from the options selected */ for (i=0, con=const_copy.first; con; i++) { + /* if not selected, free/remove it from the list */ if (!const_toggle[i]) { con_back= con->next; BLI_freelinkN(&const_copy, con); con= con_back; - } else { + } + else con= con->next; - } } /* Copy the temo listbase to the selected posebones */ - for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { - if( (arm->layer & pchan->bone->layer) && - (pchan->bone->flag & BONE_SELECTED) && - (pchan!=pchanact) - ) { - free_constraints(&pchan->constraints); - copy_constraints(&pchan->constraints, &const_copy); - pchan->constflag = pchanact->constflag; + for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { + if ( (arm->layer & pchan->bone->layer) && + (pchan->bone->flag & BONE_SELECTED) && + (pchan!=pchanact) ) + { + ListBase tmp_constraints = {NULL, NULL}; + + /* copy constraints to tmpbase and apply 'local' tags before + * appending to list of constraints for this channel + */ + copy_constraints(&tmp_constraints, &const_copy); + if ((ob->proxy) && (pchan->bone->layer & arm->layer_protected)) { + bConstraint *con; + + /* add proxy-local tags */ + for (con= tmp_constraints.first; con; con= con->next) + con->flag |= CONSTRAINT_PROXY_LOCAL; + } + addlisttolist(&pchan->constraints, &tmp_constraints); + + /* update flags (need to add here, not just copy) */ + pchan->constflag |= pchanact->constflag; } } BLI_freelistN(&const_copy); update_pose_constraint_flags(ob->pose); /* we could work out the flags but its simpler to do this */ - if (ob->pose) { + if (ob->pose) ob->pose->flag |= POSE_RECALC; - } } DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); // and all its relations @@ -808,7 +907,7 @@ void paste_posebuf (int flip) /* // disabled until protected bones in proxies follow the rules everywhere else! - if(pose_has_protected_selected(ob, 1)) + if(pose_has_protected_selected(ob, 1, 1)) return; */ @@ -1249,7 +1348,7 @@ void pose_flip_names(void) if(!ob && !ob->pose) return; if(ob==G.obedit || (ob->flag & OB_POSEMODE)==0) return; - if(pose_has_protected_selected(ob, 0)) + if(pose_has_protected_selected(ob, 0, 1)) return; for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { @@ -1282,7 +1381,7 @@ void pose_autoside_names(short axis) if (ELEM(NULL, ob, ob->pose)) return; if (ob==G.obedit || (ob->flag & OB_POSEMODE)==0) return; - if (pose_has_protected_selected(ob, 0)) + if (pose_has_protected_selected(ob, 0, 1)) return; for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { @@ -1415,7 +1514,7 @@ void pose_movetolayer(void) /* pose-channel layers */ bPoseChannel *pchan; - if (pose_has_protected_selected(ob, 0)) + if (pose_has_protected_selected(ob, 0, 1)) return; for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) { diff --git a/source/blender/src/sequence.c b/source/blender/src/sequence.c index 9426548dc38..7e2ffc3ba63 100644 --- a/source/blender/src/sequence.c +++ b/source/blender/src/sequence.c @@ -1473,8 +1473,8 @@ static void input_preprocess(Sequence * seq, TStripElem* se, int cfra) dy = sy; if (seq->flag & SEQ_USE_TRANSFORM) { - dx = seqrectx; - dy = seqrecty; + dx = G.scene->r.xsch; + dy = G.scene->r.ysch; } if (c.top + c.bottom >= se->ibuf->y || diff --git a/source/blender/src/space.c b/source/blender/src/space.c index 58420604c83..8d86336e12e 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -56,6 +56,7 @@ #include "DNA_armature_types.h" #include "DNA_curve_types.h" #include "DNA_group_types.h" /* used for select_same_group */ +#include "DNA_gpencil_types.h" #include "DNA_image_types.h" #include "DNA_ipo_types.h" #include "DNA_mesh_types.h" @@ -159,6 +160,7 @@ #include "BDR_imagepaint.h" #include "BDR_sculptmode.h" #include "BDR_unwrapper.h" +#include "BDR_gpencil.h" #include "BLO_readfile.h" /* for BLO_blendhandle_close */ @@ -1193,21 +1195,28 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) if(event==UI_BUT_EVENT) do_butspace(val); /* temporal, view3d deserves own queue? */ - /* we consider manipulator a button, defaulting to leftmouse */ + /* - we consider manipulator a button, defaulting to leftmouse + * - grease-pencil also defaults to leftmouse + */ if(event==LEFTMOUSE) { /* run any view3d event handler script links */ - if (event && sa->scriptlink.totscript) + if (event && sa->scriptlink.totscript) { if (BPY_do_spacehandlers(sa, event, SPACEHANDLER_VIEW3D_EVENT)) return; /* return if event was processed (swallowed) by handler(s) */ - + } + + if(gpencil_do_paint(sa, L_MOUSE)) return; if(BIF_do_manipulator(sa)) return; } + else if(event==RIGHTMOUSE) { + if(gpencil_do_paint(sa, R_MOUSE)) return; + } /* swap mouse buttons based on user preference */ if (U.flag & USER_LMOUSESELECT) { /* only swap mouse button for selection, in modes where it is relevant. * painting/sculpting stays on LEFTMOUSE */ - if ( !((G.f & G_SCULPTMODE) || (G.f & G_WEIGHTPAINT) || + if ( !((G.f & G_SCULPTMODE) || (G.f & G_WEIGHTPAINT) || (G.f & G_GREASEPENCIL) || (G.f & G_VERTEXPAINT) || (G.f & G_TEXTUREPAINT) || (G.f & G_PARTICLEEDIT)) || (G.obedit) ) { @@ -1945,7 +1954,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) adduplicate(0, 0); } else if(G.qual==LR_CTRLKEY) { - imagestodisplist(); + imagestodisplist(); // removed } else if((G.qual==0)){ pupval= pupmenu("Draw mode%t|BoundBox %x1|Wire %x2|OpenGL Solid %x3|Shaded Solid %x4|Textured Solid %x5"); @@ -2419,7 +2428,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) else if(G.qual==LR_ALTKEY && G.obedit->type==OB_ARMATURE) clear_bone_parent(); else if((G.qual==0) && (G.obedit->type==OB_ARMATURE)) - select_bone_parent(); + armature_select_hierarchy(BONE_SELECT_PARENT, 1); // 1 = add to selection else if((G.qual==(LR_CTRLKEY|LR_ALTKEY)) && (G.obedit->type==OB_ARMATURE)) separate_armature(); else if((G.qual==0) && G.obedit->type==OB_MESH) @@ -2449,7 +2458,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) start_RBSimulation(); } else if((G.qual==0) && (OBACT) && (OBACT->type==OB_ARMATURE) && (OBACT->flag & OB_POSEMODE)) - select_bone_parent(); + pose_select_hierarchy(BONE_SELECT_PARENT, 1); // 1 = add to selection else if((G.qual==0)) { start_game(); } @@ -2705,6 +2714,8 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) case DELKEY: if(G.qual==0 || G.qual==LR_SHIFTKEY) delete_context_selected(); + if(G.qual==LR_ALTKEY) + gpencil_delete_menu(); break; case YKEY: if((G.qual==0) && (G.obedit)) { @@ -2750,6 +2761,19 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) scrarea_queue_winredraw(curarea); break; + case LEFTBRACKETKEY: + if ((G.obedit) && (G.obedit->type == OB_ARMATURE)) + armature_select_hierarchy(BONE_SELECT_PARENT, (G.qual == LR_SHIFTKEY)); + else if ((ob) && (ob->flag & OB_POSEMODE)) + pose_select_hierarchy(BONE_SELECT_PARENT, (G.qual == LR_SHIFTKEY)); + break; + case RIGHTBRACKETKEY: + if ((G.obedit) && (G.obedit->type == OB_ARMATURE)) + armature_select_hierarchy(BONE_SELECT_CHILD, (G.qual == LR_SHIFTKEY)); + if ((ob) && (ob->flag & OB_POSEMODE)) + pose_select_hierarchy(BONE_SELECT_CHILD, (G.qual == LR_SHIFTKEY)); + break; + case PADSLASHKEY: if(G.qual==0) { if(G.vd->localview) { @@ -4816,6 +4840,14 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt) if(val) { if( uiDoBlocks(&curarea->uiblocks, event, 1)!=UI_NOTHING ) event= 0; + /* grease-pencil defaults to leftmouse */ + if (event == LEFTMOUSE) { + if(gpencil_do_paint(sa, L_MOUSE)) return; + } + else if (event == RIGHTMOUSE) { + if(gpencil_do_paint(sa, R_MOUSE)) return; + } + /* swap mouse buttons based on user preference */ if (U.flag & USER_LMOUSESELECT) { if (event == LEFTMOUSE) { @@ -4829,11 +4861,11 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt) switch(event) { case LEFTMOUSE: - if(sseq->mainb || view2dmove(event)==0) { + if(sseq->mainb==0 && view2dmove(event)==0) { first= 1; set_special_seq_update(1); - + do { getmouseco_areawin(mval); areamouseco_to_ipoco(v2d, mval, &dx, &dy); @@ -5088,6 +5120,10 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt) if((G.qual==0)) del_seq(); } + else if(G.qual==LR_ALTKEY) { + if(sseq->mainb) + gpencil_delete_menu(); + } break; case PAD1: case PAD2: case PAD4: case PAD8: seq_viewzoom(event, (G.qual & LR_SHIFTKEY)==0); @@ -5096,7 +5132,10 @@ static void winqreadseqspace(ScrArea *sa, void *spacedata, BWinEvent *evt) } } - if(doredraw) scrarea_queue_winredraw(curarea); + if(doredraw) { + scrarea_queue_winredraw(curarea); + scrarea_queue_headredraw(curarea); + } } @@ -6241,6 +6280,7 @@ void freespacelist(ScrArea *sa) if(vd->bgpic->ima) vd->bgpic->ima->id.us--; MEM_freeN(vd->bgpic); } + if(vd->gpd) free_gpencil_data(vd->gpd); if(vd->localvd) MEM_freeN(vd->localvd); if(vd->clipbb) MEM_freeN(vd->clipbb); if(vd->depths) { @@ -6284,7 +6324,12 @@ void freespacelist(ScrArea *sa) curvemapping_free(sima->cumap); } else if(sl->spacetype==SPACE_NODE) { -/* SpaceNode *snode= (SpaceNode *)sl; */ + SpaceNode *snode= (SpaceNode *)sl; + if(snode->gpd) free_gpencil_data(snode->gpd); + } + else if(sl->spacetype==SPACE_SEQ) { + SpaceSeq *sseq= (SpaceSeq *)sl; + if(sseq->gpd) free_gpencil_data(sseq->gpd); } } @@ -6314,6 +6359,7 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2) BIF_view3d_previewrender_free(v3d); v3d->depths= NULL; v3d->retopo_view_data= NULL; + v3d->gpd= gpencil_data_duplicate(v3d->gpd); } else if(sl->spacetype==SPACE_OOPS) { SpaceOops *so= (SpaceOops *)sl; @@ -6333,11 +6379,16 @@ void duplicatespacelist(ScrArea *newarea, ListBase *lb1, ListBase *lb2) else if(sl->spacetype==SPACE_NODE) { SpaceNode *snode= (SpaceNode *)sl; snode->nodetree= NULL; + snode->gpd= gpencil_data_duplicate(snode->gpd); } else if(sl->spacetype==SPACE_SCRIPT) { SpaceScript *sc = ( SpaceScript * ) sl; sc->but_refs = NULL; } + else if(sl->spacetype==SPACE_SEQ) { + SpaceSeq *sseq= (SpaceSeq *)sl; + sseq->gpd= gpencil_data_duplicate(sseq->gpd); + } sl= sl->next; } diff --git a/source/blender/src/toolbox.c b/source/blender/src/toolbox.c index 94d38ee1635..8a8d7c8cec7 100644 --- a/source/blender/src/toolbox.c +++ b/source/blender/src/toolbox.c @@ -125,8 +125,6 @@ void asciitoraw(int ch, unsigned short *event, unsigned short *qual) { - if( isalpha(ch)==0 ) return; - if( isupper(ch) ) { *qual= LEFTSHIFTKEY; ch= tolower(ch); @@ -804,7 +802,10 @@ static void tb_do_hotkey(void *arg, int event) case 'd': key= PAGEDOWNKEY; break; } } - else asciitoraw(event, &key, &qual[3]); + else if (isalpha(event)) + asciitoraw(event, &key, &qual[3]); + else if (event == '~') + key = ACCENTGRAVEKEY; for (i=0;i<4;i++) { @@ -1213,6 +1214,8 @@ static TBitem tb_view[]= { { 0, "Ortho/Perspective|NumPad 5", TB_PAD|'5', NULL}, { 0, "Local/Global View|NumPad /", TB_PAD|'/', NULL}, { 0, "SEPR", 0, NULL}, +{ 0, "Show All Layers|Shift ~", TB_SHIFT|'~', NULL}, +{ 0, "SEPR", 0, NULL}, { 0, "Align View", 0, tb_view_alignview}, { 0, "SEPR", 0, NULL}, { 0, "View Selected|NumPad .", TB_PAD|'.', NULL}, diff --git a/source/blender/src/transform_conversions.c b/source/blender/src/transform_conversions.c index 10e49cdd218..8f83434e528 100644 --- a/source/blender/src/transform_conversions.c +++ b/source/blender/src/transform_conversions.c @@ -70,6 +70,7 @@ #include "DNA_vfont_types.h" #include "DNA_constraint_types.h" #include "DNA_listBase.h" +#include "DNA_gpencil_types.h" #include "BKE_action.h" #include "BKE_armature.h" @@ -125,6 +126,7 @@ #include "BDR_drawaction.h" // list of keyframes in action #include "BDR_editobject.h" // reset_slowparents() +#include "BDR_gpencil.h" #include "BDR_unwrapper.h" #include "BLI_arithb.h" @@ -1087,6 +1089,8 @@ static void createTransArmatureVerts(TransInfo *t) VECCOPY (td->center, td->iloc); td->loc= ebo->tail; td->flag= TD_SELECTED; + if (ebo->flag & BONE_EDITMODE_LOCKED) + td->protectflag = OB_LOCK_LOC|OB_LOCK_ROT|OB_LOCK_SCALE; Mat3CpyMat3(td->smtx, smtx); Mat3CpyMat3(td->mtx, mtx); @@ -1102,6 +1106,8 @@ static void createTransArmatureVerts(TransInfo *t) VECCOPY (td->center, td->iloc); td->loc= ebo->head; td->flag= TD_SELECTED; + if (ebo->flag & BONE_EDITMODE_LOCKED) + td->protectflag = OB_LOCK_LOC|OB_LOCK_ROT|OB_LOCK_SCALE; Mat3CpyMat3(td->smtx, smtx); Mat3CpyMat3(td->mtx, mtx); @@ -2474,6 +2480,96 @@ void flushTransIpoData(TransInfo *t) /* ********************* ACTION/NLA EDITOR ****************** */ +/* Called by special_aftertrans_update to make sure selected gp-frames replace + * any other gp-frames which may reside on that frame (that are not selected). + * It also makes sure gp-frames are still stored in chronological order after + * transform. + */ +static void posttrans_gpd_clean (bGPdata *gpd) +{ + bGPDlayer *gpl; + + for (gpl= gpd->layers.first; gpl; gpl= gpl->next) { + ListBase sel_buffer = {NULL, NULL}; + bGPDframe *gpf, *gpfn; + bGPDframe *gfs, *gfsn; + + /* loop 1: loop through and isolate selected gp-frames to buffer + * (these need to be sorted as they are isolated) + */ + for (gpf= gpl->frames.first; gpf; gpf= gpfn) { + gpfn= gpf->next; + + if (gpf->flag & GP_FRAME_SELECT) { + BLI_remlink(&gpl->frames, gpf); + + /* find place to add them in buffer + * - go backwards as most frames will still be in order, + * so doing it this way will be faster + */ + for (gfs= sel_buffer.last; gfs; gfs= gfs->prev) { + /* if current (gpf) occurs after this one in buffer, add! */ + if (gfs->framenum < gpf->framenum) { + BLI_insertlinkafter(&sel_buffer, gfs, gpf); + break; + } + } + if (gfs == NULL) + BLI_addhead(&sel_buffer, gpf); + } + } + + /* error checking: it is unlikely, but may be possible to have none selected */ + if (sel_buffer.first == NULL) + continue; + + /* if all were selected (i.e. gpl->frames is empty), then just transfer sel-buf over */ + if (gpl->frames.first == NULL) { + gpl->frames.first= sel_buffer.first; + gpl->frames.last= sel_buffer.last; + + continue; + } + + /* loop 2: remove duplicates of frames in buffers */ + //gfs= sel_buffer.first; + //gfsn= gfs->next; + + for (gpf= gpl->frames.first; gpf && sel_buffer.first; gpf= gpfn) { + gpfn= gpf->next; + + /* loop through sel_buffer, emptying stuff from front of buffer if ok */ + for (gfs= sel_buffer.first; gfs && gpf; gfs= gfsn) { + gfsn= gfs->next; + + /* if this buffer frame needs to go before current, add it! */ + if (gfs->framenum < gpf->framenum) { + /* transfer buffer frame to frames list (before current) */ + BLI_remlink(&sel_buffer, gfs); + BLI_insertlinkbefore(&gpl->frames, gpf, gfs); + } + /* if this buffer frame is on same frame, replace current with it and stop */ + else if (gfs->framenum == gpf->framenum) { + /* transfer buffer frame to frames list (before current) */ + BLI_remlink(&sel_buffer, gfs); + BLI_insertlinkbefore(&gpl->frames, gpf, gfs); + + /* get rid of current frame */ + gpencil_layer_delframe(gpl, gpf); + } + } + } + + /* if anything is still in buffer, append to end */ + for (gfs= sel_buffer.first; gfs; gfs= gfsn) { + gfsn= gfs->next; + + BLI_remlink(&sel_buffer, gfs); + BLI_addtail(&gpl->frames, gfs); + } + } +} + /* Called by special_aftertrans_update to make sure selected keyframes replace * any other keyframes which may reside on that frame (that is not selected). */ @@ -2698,6 +2794,26 @@ static int count_ipo_keys(Ipo *ipo, char side, float cfra) return count; } +/* fully select selected beztriples, but only include if it's on the right side of cfra */ +static int count_gplayer_frames(bGPDlayer *gpl, char side, float cfra) +{ + bGPDframe *gpf; + int count = 0; + + if (gpl == NULL) + return count; + + /* only include points that occur on the right side of cfra */ + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + if (gpf->flag & GP_FRAME_SELECT) { + if (FrameOnMouseSide(side, gpf->framenum, cfra)) + count++; + } + } + + return count; +} + /* This function assigns the information to transdata */ static void TimeToTransData(TransData *td, float *time, Object *ob) { @@ -2751,9 +2867,68 @@ static TransData *IpoToTransData(TransData *td, Ipo *ipo, Object *ob, char side, return td; } +/* helper struct for gp-frame transforms (only used here) */ +typedef struct tGPFtransdata { + float val; /* where transdata writes transform */ + int *sdata; /* pointer to gpf->framenum */ +} tGPFtransdata; + +/* This function helps flush transdata written to tempdata into the gp-frames */ +void flushTransGPactionData (TransInfo *t) +{ + tGPFtransdata *tfd; + int i; + + /* find the first one to start from */ + if (t->mode == TFM_TIME_SLIDE) + tfd= (tGPFtransdata *)( (float *)(t->customData) + 2 ); + else + tfd= (tGPFtransdata *)(t->customData); + + /* flush data! */ + for (i = 0; i < t->total; i++, tfd++) { + *(tfd->sdata)= (int)floor(tfd->val + 0.5); + } +} + +/* This function advances the address to which td points to, so it must return + * the new address so that the next time new transform data is added, it doesn't + * overwrite the existing ones... i.e. td = GPLayerToTransData(td, ipo, ob, side, cfra); + * + * The 'side' argument is needed for the extend mode. 'B' = both sides, 'R'/'L' mean only data + * on the named side are used. + */ +static int GPLayerToTransData (TransData *td, tGPFtransdata *tfd, bGPDlayer *gpl, short side, float cfra) +{ + bGPDframe *gpf; + int count= 0; + + /* check for select frames on right side of current frame */ + for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { + if (gpf->flag & GP_FRAME_SELECT) { + if (FrameOnMouseSide(side, gpf->framenum, cfra)) { + /* memory is calloc'ed, so that should zero everything nicely for us */ + td->val= &tfd->val; + td->ival= gpf->framenum; + + tfd->val= gpf->framenum; + tfd->sdata= &gpf->framenum; + + /* advance td now */ + td++; + tfd++; + count++; + } + } + } + + return count; +} + static void createTransActionData(TransInfo *t) { TransData *td = NULL; + tGPFtransdata *tfd = NULL; Object *ob= NULL; ListBase act_data = {NULL, NULL}; @@ -2771,7 +2946,10 @@ static void createTransActionData(TransInfo *t) if (data == NULL) return; /* filter data */ - filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS); + if (datatype == ACTCONT_GPENCIL) + filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT); + else + filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_IPOKEYS); actdata_filter(&act_data, filter, data, datatype); /* is the action scaled? if so, the it should belong to the active object */ @@ -2800,8 +2978,12 @@ static void createTransActionData(TransInfo *t) cfra = CFRA; /* loop 1: fully select ipo-keys and count how many BezTriples are selected */ - for (ale= act_data.first; ale; ale= ale->next) - count += count_ipo_keys(ale->key_data, side, cfra); + for (ale= act_data.first; ale; ale= ale->next) { + if (ale->type == ACTTYPE_GPLAYER) + count += count_gplayer_frames(ale->data, side, cfra); + else + count += count_ipo_keys(ale->key_data, side, cfra); + } /* stop if trying to build list if nothing selected */ if (count == 0) { @@ -2812,16 +2994,38 @@ static void createTransActionData(TransInfo *t) /* allocate memory for data */ t->total= count; + t->data= MEM_callocN(t->total*sizeof(TransData), "TransData(Action Editor)"); - if (t->mode == TFM_TIME_SLIDE) + td= t->data; + + if (datatype == ACTCONT_GPENCIL) { + if (t->mode == TFM_TIME_SLIDE) { + t->customData= MEM_callocN((sizeof(float)*2)+(sizeof(tGPFtransdata)*count), "TimeSlide + tGPFtransdata"); + tfd= (tGPFtransdata *)( (float *)(t->customData) + 2 ); + } + else { + t->customData= MEM_callocN(sizeof(tGPFtransdata)*count, "tGPFtransdata"); + tfd= (tGPFtransdata *)(t->customData); + } + } + else if (t->mode == TFM_TIME_SLIDE) t->customData= MEM_callocN(sizeof(float)*2, "TimeSlide Min/Max"); - td= t->data; /* loop 2: build transdata array */ for (ale= act_data.first; ale; ale= ale->next) { - Ipo *ipo= (Ipo *)ale->key_data; - - td= IpoToTransData(td, ipo, ob, side, cfra); + if (ale->type == ACTTYPE_GPLAYER) { + bGPDlayer *gpl= (bGPDlayer *)ale->data; + int i; + + i = GPLayerToTransData(td, tfd, gpl, side, cfra); + td += i; + tfd += i; + } + else { + Ipo *ipo= (Ipo *)ale->key_data; + + td= IpoToTransData(td, ipo, ob, side, cfra); + } } /* check if we're supposed to be setting minx/maxx for TimeSlide */ @@ -3623,7 +3827,7 @@ void special_aftertrans_update(TransInfo *t) } } } - else if (t->spacetype == SPACE_ACTION) { + if (t->spacetype == SPACE_ACTION) { void *data; short datatype; @@ -3673,6 +3877,13 @@ void special_aftertrans_update(TransInfo *t) DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA); } + else if (datatype == ACTCONT_GPENCIL) { + /* remove duplicate frames and also make sure points are in order! */ + if ((cancelled == 0) || (duplicate)) + { + posttrans_gpd_clean(data); + } + } G.saction->flag &= ~SACTION_MOVING; } diff --git a/source/blender/src/transform_generics.c b/source/blender/src/transform_generics.c index 6cb7a34d1bc..c332fd723eb 100644 --- a/source/blender/src/transform_generics.c +++ b/source/blender/src/transform_generics.c @@ -278,6 +278,11 @@ void recalcData(TransInfo *t) data = get_action_context(&context); if (data == NULL) return; + /* always flush data if gpencil context */ + if (context == ACTCONT_GPENCIL) { + flushTransGPactionData(t); + } + if (G.saction->lock) { if (context == ACTCONT_ACTION) { if(ob) { @@ -753,6 +758,10 @@ void postTrans (TransInfo *t) if (G.sima->flag & SI_LIVE_UNWRAP) unwrap_lscm_live_end(t->state == TRANS_CANCEL); } + else if(t->spacetype==SPACE_ACTION) { + if (t->customData) + MEM_freeN(t->customData); + } } void applyTransObjects(TransInfo *t) diff --git a/source/blender/src/transform_manipulator.c b/source/blender/src/transform_manipulator.c index 050360887b4..709879f142b 100644 --- a/source/blender/src/transform_manipulator.c +++ b/source/blender/src/transform_manipulator.c @@ -170,6 +170,13 @@ static void stats_pose(View3D *v3d, bPoseChannel *pchan) } } +/* for editmode*/ +static void stats_editbone(View3D *v3d, EditBone *ebo) +{ + if (ebo->flag & BONE_EDITMODE_LOCKED) + protectflag_to_drawflags(OB_LOCK_LOC|OB_LOCK_ROT|OB_LOCK_SCALE, &v3d->twdrawflag); +} + /* only counts the parent selection, and tags transform flag */ /* bad call... should re-use method from transform_conversion once */ static void count_bone_select(TransInfo *t, bArmature *arm, ListBase *lb, int do_it) @@ -258,6 +265,9 @@ int calc_manipulator_stats(ScrArea *sa) calc_tw_center(ebo->head); totsel++; } + if (ebo->flag & BONE_SELECTED) { + stats_editbone(v3d, ebo); + } } } } diff --git a/source/blender/src/usiblender.c b/source/blender/src/usiblender.c index df2a0863523..18759c1c9e0 100644 --- a/source/blender/src/usiblender.c +++ b/source/blender/src/usiblender.c @@ -885,7 +885,7 @@ void BIF_write_file(char *target) if (G.f & G_DOSCRIPTLINKS) BPY_do_pyscript(&G.scene->id, SCRIPT_ONSAVE); for (li= G.main->library.first; li; li= li->id.next) { - if (BLI_streq(li->name, target)) { + if (li->parent==NULL && BLI_streq(li->name, target)) { error("Cannot overwrite used library"); return; } diff --git a/source/creator/creator.c b/source/creator/creator.c index 9589f1e3e94..e17b0f66977 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -618,8 +618,23 @@ int main(int argc, char **argv) if (G.scene) { if (a < argc) { int frame= MIN2(MAXFRAME, MAX2(1, atoi(argv[a]))); + int slink_flag= 0; Render *re= RE_NewRender(G.scene->id.name); + + if (G.f & G_DOSCRIPTLINKS) { + BPY_do_all_scripts(SCRIPT_RENDER); + /* avoid FRAMECHANGED slink event + * (should only be triggered in anims): */ + G.f &= ~G_DOSCRIPTLINKS; + slink_flag= 1; + } + RE_BlenderAnim(re, G.scene, frame, frame); + + if (slink_flag) { + G.f |= G_DOSCRIPTLINKS; + BPY_do_all_scripts(SCRIPT_POSTRENDER); + } } } else { printf("\nError: no blend loaded. cannot use '-f'.\n"); @@ -628,7 +643,14 @@ int main(int argc, char **argv) case 'a': if (G.scene) { Render *re= RE_NewRender(G.scene->id.name); + + if (G.f & G_DOSCRIPTLINKS) + BPY_do_all_scripts(SCRIPT_RENDER); + RE_BlenderAnim(re, G.scene, G.scene->r.sfra, G.scene->r.efra); + + if (G.f & G_DOSCRIPTLINKS) + BPY_do_all_scripts(SCRIPT_POSTRENDER); } else { printf("\nError: no blend loaded. cannot use '-a'.\n"); } diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp index 5f37de24ed6..1604dfe5cce 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp @@ -101,6 +101,13 @@ int KX_BlenderCanvas::GetHeight( return scrarea_get_win_height(m_area); } +RAS_Rect & +KX_BlenderCanvas:: +GetWindowArea( +){ + return m_area_rect; +} + void KX_BlenderCanvas:: SetViewPort( @@ -112,6 +119,11 @@ SetViewPort( int minx = scrarea_get_win_x(m_area); int miny = scrarea_get_win_y(m_area); + m_area_rect.SetLeft(minx + x1); + m_area_rect.SetBottom(miny + y1); + m_area_rect.SetRight(minx + x2); + m_area_rect.SetTop(miny + y2); + glViewport(minx + x1, miny + y1, vp_width, vp_height); glScissor(minx + x1, miny + y1, vp_width, vp_height); } diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h index b155d39e149..bc202a8558c 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h @@ -117,6 +117,10 @@ public: return m_displayarea; }; + RAS_Rect & + GetWindowArea( + ); + void SetViewPort( int x1, int y1, @@ -159,6 +163,7 @@ public: private: /** Blender area the game engine is running within */ struct ScrArea* m_area; + RAS_Rect m_area_rect; }; #endif // __KX_BLENDERCANVAS diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp index ed6ea7c5f6a..da52be56d1b 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp @@ -170,6 +170,7 @@ void BL_RenderText(int mode,const char* textstr,int textlen,struct MTFace* tface void DisableForText() { if(glIsEnabled(GL_BLEND)) glDisable(GL_BLEND); + if(glIsEnabled(GL_ALPHA_TEST)) glDisable(GL_ALPHA_TEST); if(glIsEnabled(GL_LIGHTING)) { glDisable(GL_LIGHTING); diff --git a/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.cpp b/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.cpp deleted file mode 100644 index d173b1c66d9..00000000000 --- a/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/** - * $Id$ - * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "KX_BlenderPolyMaterial.h" -#include "BKE_mesh.h" - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#if 0 -KX_BlenderPolyMaterial::KX_BlenderPolyMaterial(const STR_String &texname, - bool ba, - const STR_String& matname, - int tile, - int tilexrep, - int tileyrep, - int mode, - bool transparant, - bool zsort, - int lightlayer, - bool bIsTriangle, - void* clientobject, - struct MTFace* tface) - : RAS_IPolyMaterial(texname, - false, - matname, - tile, - tilexrep, - tileyrep, - mode, - transparant, - zsort, - lightlayer, - bIsTriangle, - clientobject), - m_tface(tface) -{ -} - -void KX_BlenderPolyMaterial::Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const -{ - - - if (GetCachingInfo() != cachingInfo) - { - if (!cachingInfo) - { - set_tpage(NULL); - } - cachingInfo = GetCachingInfo(); - - if ((m_drawingmode & 4)&& (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED)) - { - update_realtime_texture((struct MTFace*) m_tface, rasty->GetTime()); - set_tpage(m_tface); - rasty->EnableTextures(true); - } - else - { - set_tpage(NULL); - rasty->EnableTextures(false); - } - - if(m_drawingmode & RAS_IRasterizer::KX_TWOSIDE) - { - rasty->SetCullFace(false); - } - else - { - rasty->SetCullFace(true); - } - - if (m_drawingmode & RAS_IRasterizer::KX_LINES) { - rasty->SetLines(true); - } - else { - rasty->SetLines(false); - } - } - - rasty->SetSpecularity(m_specular[0],m_specular[1],m_specular[2],m_specularity); - rasty->SetShinyness(m_shininess); - rasty->SetDiffuse(m_diffuse[0], m_diffuse[1],m_diffuse[2], 1.0); -} - - -#endif - - diff --git a/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.h b/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.h deleted file mode 100644 index 35823b2125b..00000000000 --- a/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.h +++ /dev/null @@ -1,99 +0,0 @@ -/** - * $Id$ - * - * ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ -#ifndef __KX_BLENDERPOLYMATERIAL -#define __KX_BLENDERPOLYMATERIAL - -#include "RAS_MaterialBucket.h" -#include "RAS_IRasterizer.h" - -struct MTFace; -extern "C" int set_tpage(MTFace* tface); /* Worst hack ever */ - -#if 0 -class KX_BlenderPolyMaterial : public RAS_IPolyMaterial -{ - /** Blender texture face structure. */ - MTFace* m_tface; - -public: - - KX_BlenderPolyMaterial(const STR_String &texname, - bool ba, - const STR_String& matname, - int tile, - int tilexrep, - int tileyrep, - int mode, - bool transparant, - bool zsort, - int lightlayer, - bool bIsTriangle, - void* clientobject, - struct MTFace* tface); - - /** - * Returns the caching information for this material, - * This can be used to speed up the rasterizing process. - * @return The caching information. - */ - virtual TCachingInfo GetCachingInfo(void) const; - - /** - * Activates the material in the (OpenGL) rasterizer. - * On entry, the cachingInfo contains info about the last activated material. - * On exit, the cachingInfo should contain updated info about this material. - * @param rasty The rasterizer in which the material should be active. - * @param cachingInfo The information about the material used to speed up rasterizing. - */ - virtual void Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const; - - /** - * Returns the Blender texture face structure that is used for this material. - * @return The material's texture face. - */ - MTFace* GetMTFace(void) const; -protected: -private: -}; - - -inline MTFace* KX_BlenderPolyMaterial::GetMTFace(void) const -{ - return m_tface; -} - -inline RAS_IPolyMaterial::TCachingInfo KX_BlenderPolyMaterial::GetCachingInfo(void) const -{ - return GetMTFace(); -} - -#endif - -#endif // __KX_BLENDERPOLYMATERIAL - diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp index 220d174d464..e4eff163d5b 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp @@ -40,7 +40,6 @@ // it needs the gameobject and the sumo physics scene for a raycast #include "KX_GameObject.h" -#include "KX_BlenderPolyMaterial.h" #include "KX_PolygonMaterial.h" #include "KX_BlenderMaterial.h" diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 5d6dd694765..2ee8b54a014 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -57,24 +57,12 @@ BL_ActionActuator::~BL_ActionActuator() { - - if (m_pose) { - free_pose_channels(m_pose); - MEM_freeN(m_pose); - m_pose = NULL; - }; - - if (m_userpose){ - free_pose_channels(m_userpose); - MEM_freeN(m_userpose); - m_userpose=NULL; - } - if (m_blendpose) { - free_pose_channels(m_blendpose); - MEM_freeN(m_blendpose); - m_blendpose = NULL; - }; - + if (m_pose) + free_pose(m_pose); + if (m_userpose) + free_pose(m_userpose); + if (m_blendpose) + free_pose(m_blendpose); } void BL_ActionActuator::ProcessReplica(){ diff --git a/source/gameengine/Converter/BL_ArmatureObject.cpp b/source/gameengine/Converter/BL_ArmatureObject.cpp index f73d5b42a01..09f1d9d4d87 100644 --- a/source/gameengine/Converter/BL_ArmatureObject.cpp +++ b/source/gameengine/Converter/BL_ArmatureObject.cpp @@ -82,10 +82,8 @@ void BL_ArmatureObject::ProcessReplica(BL_ArmatureObject *replica) BL_ArmatureObject::~BL_ArmatureObject() { - if (m_mrdPose){ - free_pose_channels(m_mrdPose); - MEM_freeN(m_mrdPose); - } + if (m_mrdPose) + free_pose(m_mrdPose); } /* note, you can only call this for exisiting Armature objects, and not mix it with other Armatures */ @@ -172,12 +170,13 @@ void BL_ArmatureObject::GetMRDPose(bPose **pose) // copy_pose (&m_mrdPose, m_pose, 0); //} - if (!*pose) + if (!*pose) { // must duplicate the constraints too otherwise we have corruption in free_pose_channels() // because it will free the blender constraints. // Ideally, blender should rememeber that the constraints were not copied so that // free_pose_channels() would not free them. copy_pose(pose, m_objArma->pose, 1); + } else extract_pose_from_pose(*pose, m_objArma->pose); diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index f3e22cd297a..f44318120e8 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -136,8 +136,12 @@ #include "BKE_mesh.h" #include "MT_Point3.h" +#include "BLI_arithb.h" + extern "C" { - #include "BKE_customdata.h" +#include "BKE_customdata.h" +#include "BKE_cdderivedmesh.h" +#include "BKE_DerivedMesh.h" } #include "BKE_material.h" /* give_current_material */ @@ -309,7 +313,6 @@ typedef struct MTF_localLayer // ------------------------------------ BL_Material* ConvertMaterial( - Mesh* mesh, Material *mat, MTFace* tface, const char *tfaceName, @@ -323,15 +326,16 @@ BL_Material* ConvertMaterial( //this needs some type of manager BL_Material *material = new BL_Material(); - int numchan = -1; + int numchan = -1, texalpha = 0; bool validmat = (mat!=0); - bool validface = (mesh->mtface && tface); + bool validface = (tface!=0); short type = 0; if( validmat ) type = 1; // material color material->IdMode = DEFAULT_BLENDER; + material->glslmat = (validmat)? glslmat: false; // -------------------------------- if(validmat) { @@ -367,12 +371,13 @@ BL_Material* ConvertMaterial( if(i==0 && facetex ) { Image*tmp = (Image*)(tface->tpage); + if(tmp) { material->img[i] = tmp; material->texname[i] = material->img[i]->id.name; material->flag[i] |= ( tface->transp &TF_ALPHA )?USEALPHA:0; material->flag[i] |= ( tface->transp &TF_ADD )?CALCALPHA:0; - material->ras_mode|= ( tface->transp &(TF_ADD | TF_ALPHA))?TRANSP:0; + if(material->img[i]->flag & IMA_REFLECT) material->mapping[i].mapping |= USEREFL; else @@ -430,6 +435,8 @@ BL_Material* ConvertMaterial( material->flag[i] |= ( mttmp->mapto & MAP_ALPHA )?TEXALPHA:0; material->flag[i] |= ( mttmp->texflag& MTEX_NEGATIVE )?TEXNEG:0; + if(!glslmat && (material->flag[i] & TEXALPHA)) + texalpha = 1; } } else if(mttmp->tex->type == TEX_ENVMAP) { @@ -546,17 +553,7 @@ BL_Material* ConvertMaterial( material->ref = mat->ref; material->amb = mat->amb; - // set alpha testing without z-sorting - if( ( validface && (!(tface->transp &~ TF_CLIP))) && mat->mode & MA_ZTRA) { - // sets the RAS_IPolyMaterial::m_flag |RAS_FORCEALPHA - // this is so we don't have the overhead of the z-sorting code - material->ras_mode|=ALPHA_TEST; - } - else{ - // use regular z-sorting - material->ras_mode |= ((mat->mode & MA_ZTRA) != 0)?ZSORT:0; - } - material->ras_mode |= ((mat->mode & MA_WIRE) != 0)?WIRE:0; + material->ras_mode |= (mat->mode & MA_WIRE)? WIRE: 0; } else { int valid = 0; @@ -574,7 +571,6 @@ BL_Material* ConvertMaterial( material->mapping[0].mapping |= ( (material->img[0]->flag & IMA_REFLECT)!=0 )?USEREFL:0; material->flag[0] |= ( tface->transp &TF_ALPHA )?USEALPHA:0; material->flag[0] |= ( tface->transp &TF_ADD )?CALCALPHA:0; - material->ras_mode|= ( tface->transp & (TF_ADD|TF_ALPHA))?TRANSP:0; valid++; } } @@ -607,10 +603,6 @@ BL_Material* ConvertMaterial( material->ras_mode |= ( (tface->mode & TF_DYNAMIC)!= 0 )?COLLIDER:0; material->transp = tface->transp; - - if(tface->transp&~TF_CLIP) - material->ras_mode |= TRANSP; - material->tile = tface->tile; material->mode = tface->mode; @@ -631,7 +623,16 @@ BL_Material* ConvertMaterial( material->tile = 0; } + // with ztransp enabled, enforce alpha blending mode + if(validmat && (mat->mode & MA_ZTRA) && (material->transp == TF_SOLID)) + material->transp = TF_ALPHA; + // always zsort alpha + add + if((material->transp == TF_ALPHA || material->transp == TF_ADD || texalpha) + && (material->transp != TF_CLIP)) { + material->ras_mode |= ALPHA; + material->ras_mode |= (material->mode & TF_ALPHASORT)? ZSORT: 0; + } // get uv sets if(validmat) @@ -711,132 +712,54 @@ BL_Material* ConvertMaterial( } -static void BL_ComputeTriTangentSpace(const MT_Vector3 &v1, const MT_Vector3 &v2, const MT_Vector3 &v3, - const MT_Vector2 &uv1, const MT_Vector2 &uv2, const MT_Vector2 &uv3, - MFace* mface, MT_Vector3 *tan1, MT_Vector3 *tan2) -{ - MT_Vector3 dx1(v2 - v1), dx2(v3 - v1); - MT_Vector2 duv1(uv2 - uv1), duv2(uv3 - uv1); - - MT_Scalar r = 1.0 / (duv1.x() * duv2.y() - duv2.x() * duv1.y()); - duv1 *= r; - duv2 *= r; - MT_Vector3 sdir(duv2.y() * dx1 - duv1.y() * dx2); - MT_Vector3 tdir(duv1.x() * dx2 - duv2.x() * dx1); - - tan1[mface->v1] += sdir; - tan1[mface->v2] += sdir; - tan1[mface->v3] += sdir; - - tan2[mface->v1] += tdir; - tan2[mface->v2] += tdir; - tan2[mface->v3] += tdir; -} - -static MT_Vector4* BL_ComputeMeshTangentSpace(Mesh* mesh) -{ - MFace* mface = static_cast<MFace*>(mesh->mface); - MTFace* tface = static_cast<MTFace*>(mesh->mtface); - - MT_Vector3 *tan1 = new MT_Vector3[mesh->totvert]; - MT_Vector3 *tan2 = new MT_Vector3[mesh->totvert]; - - int v; - for (v = 0; v < mesh->totvert; v++) - { - tan1[v] = MT_Vector3(0.0, 0.0, 0.0); - tan2[v] = MT_Vector3(0.0, 0.0, 0.0); - } - - for (int p = 0; p < mesh->totface; p++, mface++, tface++) - { - MT_Vector3 v1(mesh->mvert[mface->v1].co), - v2(mesh->mvert[mface->v2].co), - v3(mesh->mvert[mface->v3].co); - - MT_Vector2 uv1(tface->uv[0]), - uv2(tface->uv[1]), - uv3(tface->uv[2]); - - BL_ComputeTriTangentSpace(v1, v2, v3, uv1, uv2, uv3, mface, tan1, tan2); - if (mface->v4) - { - MT_Vector3 v4(mesh->mvert[mface->v4].co); - MT_Vector2 uv4(tface->uv[3]); - - BL_ComputeTriTangentSpace(v1, v3, v4, uv1, uv3, uv4, mface, tan1, tan2); - } - } - - MT_Vector4 *tangent = new MT_Vector4[mesh->totvert]; - for (v = 0; v < mesh->totvert; v++) - { - const MT_Vector3 no(mesh->mvert[v].no[0]/32767.0, - mesh->mvert[v].no[1]/32767.0, - mesh->mvert[v].no[2]/32767.0); - // Gram-Schmidt orthogonalize - MT_Vector3 t(tan1[v] - no.cross(no.cross(tan1[v]))); - if (!MT_fuzzyZero(t)) - t /= t.length(); - - tangent[v].x() = t.x(); - tangent[v].y() = t.y(); - tangent[v].z() = t.z(); - // Calculate handedness - tangent[v].w() = no.dot(tan1[v].cross(tan2[v])) < 0.0 ? -1.0 : 1.0; - } - - delete [] tan1; - delete [] tan2; - - return tangent; -} - RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* rendertools, KX_Scene* scene, KX_BlenderSceneConverter *converter) { RAS_MeshObject *meshobj; - bool skinMesh = false; - + bool skinMesh = false; int lightlayer = blenderobj->lay; - - MFace* mface = static_cast<MFace*>(mesh->mface); - MTFace* tface = static_cast<MTFace*>(mesh->mtface); + + // Get DerivedMesh data + DerivedMesh *dm = CDDM_from_mesh(mesh, blenderobj); + + MVert *mvert = dm->getVertArray(dm); + int totvert = dm->getNumVerts(dm); + + MFace *mface = dm->getFaceArray(dm); + MTFace *tface = static_cast<MTFace*>(dm->getFaceDataArray(dm, CD_MTFACE)); + MCol *mcol = static_cast<MCol*>(dm->getFaceDataArray(dm, CD_MCOL)); + float (*tangent)[3] = NULL; + int totface = dm->getNumFaces(dm); const char *tfaceName = ""; - MCol* mmcol = mesh->mcol; - MT_assert(mface || mesh->totface == 0); + if(tface) { + DM_add_tangent_layer(dm); + tangent = (float(*)[3])dm->getFaceDataArray(dm, CD_TANGENT); + } // Determine if we need to make a skinned mesh - if (mesh->dvert || mesh->key){ + if (mesh->dvert || mesh->key) { meshobj = new BL_SkinMeshObject(mesh, lightlayer); skinMesh = true; } - else { + else meshobj = new RAS_MeshObject(mesh, lightlayer); - } - MT_Vector4 *tangent = 0; - if (tface) - tangent = BL_ComputeMeshTangentSpace(mesh); - // Extract avaiable layers MTF_localLayer *layers = new MTF_localLayer[MAX_MTFACE]; - for (int lay=0; lay<MAX_MTFACE; lay++) - { + for (int lay=0; lay<MAX_MTFACE; lay++) { layers[lay].face = 0; layers[lay].name = ""; } - int validLayers = 0; - for (int i=0; i<mesh->fdata.totlayer; i++) + for (int i=0; i<dm->faceData.totlayer; i++) { - if (mesh->fdata.layers[i].type == CD_MTFACE) + if (dm->faceData.layers[i].type == CD_MTFACE) { assert(validLayers <= 8); - layers[validLayers].face = (MTFace*)mesh->fdata.layers[i].data;; - layers[validLayers].name = mesh->fdata.layers[i].name; + layers[validLayers].face = (MTFace*)(dm->faceData.layers[i].data); + layers[validLayers].name = dm->faceData.layers[i].name; if(tface == layers[validLayers].face) tfaceName = layers[validLayers].name; validLayers++; @@ -844,271 +767,269 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* } meshobj->SetName(mesh->id.name); - meshobj->m_xyz_index_to_vertex_index_mapping.resize(mesh->totvert); - for (int f=0;f<mesh->totface;f++,mface++) + meshobj->m_xyz_index_to_vertex_index_mapping.resize(totvert); + + for (int f=0;f<totface;f++,mface++) { - + Material* ma = 0; bool collider = true; - - // only add valid polygons - if (mface->v3) - { - MT_Point2 uv0(0.0,0.0),uv1(0.0,0.0),uv2(0.0,0.0),uv3(0.0,0.0); - MT_Point2 uv20(0.0,0.0),uv21(0.0,0.0),uv22(0.0,0.0),uv23(0.0,0.0); - // rgb3 is set from the adjoint face in a square - unsigned int rgb0,rgb1,rgb2,rgb3 = 0; - MT_Vector3 no0(mesh->mvert[mface->v1].no[0], mesh->mvert[mface->v1].no[1], mesh->mvert[mface->v1].no[2]), - no1(mesh->mvert[mface->v2].no[0], mesh->mvert[mface->v2].no[1], mesh->mvert[mface->v2].no[2]), - no2(mesh->mvert[mface->v3].no[0], mesh->mvert[mface->v3].no[1], mesh->mvert[mface->v3].no[2]), - no3(0.0, 0.0, 0.0); - MT_Point3 pt0(mesh->mvert[mface->v1].co), - pt1(mesh->mvert[mface->v2].co), - pt2(mesh->mvert[mface->v3].co), - pt3(0.0, 0.0, 0.0); - MT_Vector4 tan0(0.0, 0.0, 0.0, 0.0), - tan1(0.0, 0.0, 0.0, 0.0), - tan2(0.0, 0.0, 0.0, 0.0), - tan3(0.0, 0.0, 0.0, 0.0); - - no0 /= 32767.0; - no1 /= 32767.0; - no2 /= 32767.0; - if (mface->v4) - { - pt3 = MT_Point3(mesh->mvert[mface->v4].co); - no3 = MT_Vector3(mesh->mvert[mface->v4].no[0], mesh->mvert[mface->v4].no[1], mesh->mvert[mface->v4].no[2]); - no3 /= 32767.0; + MT_Point2 uv0(0.0,0.0),uv1(0.0,0.0),uv2(0.0,0.0),uv3(0.0,0.0); + MT_Point2 uv20(0.0,0.0),uv21(0.0,0.0),uv22(0.0,0.0),uv23(0.0,0.0); + unsigned int rgb0,rgb1,rgb2,rgb3 = 0; + + MT_Vector3 no0, no1, no2, no3; + MT_Point3 pt0, pt1, pt2, pt3; + MT_Vector4 tan0, tan1, tan2, tan3; + + /* get coordinates, normals and tangents */ + pt0 = MT_Point3(mvert[mface->v1].co); + pt1 = MT_Point3(mvert[mface->v2].co); + pt2 = MT_Point3(mvert[mface->v3].co); + pt3 = (mface->v4)? MT_Point3(mvert[mface->v4].co): MT_Point3(0.0, 0.0, 0.0); + + if(mface->flag & ME_SMOOTH) { + float n0[3], n1[3], n2[3], n3[3]; + + NormalShortToFloat(n0, mvert[mface->v1].no); + NormalShortToFloat(n1, mvert[mface->v2].no); + NormalShortToFloat(n2, mvert[mface->v3].no); + no0 = n0; + no1 = n1; + no2 = n2; + + if(mface->v4) { + NormalShortToFloat(n3, mvert[mface->v4].no); + no3 = n3; } + else + no3 = MT_Vector3(0.0, 0.0, 0.0); + } + else { + float fno[3]; + + if(mface->v4) + CalcNormFloat4(mvert[mface->v1].co, mvert[mface->v2].co, + mvert[mface->v3].co, mvert[mface->v4].co, fno); + else + CalcNormFloat(mvert[mface->v1].co, mvert[mface->v2].co, + mvert[mface->v3].co, fno); + + no0 = no1 = no2 = no3 = MT_Vector3(fno); + } + + if(tangent) { + tan0 = tangent[f*4 + 0]; + tan1 = tangent[f*4 + 1]; + tan2 = tangent[f*4 + 2]; + + if (mface->v4) + tan3 = tangent[f*4 + 3]; + } + + /* get material */ + ma = give_current_material(blenderobj, mface->mat_nr+1); - if(!(mface->flag & ME_SMOOTH)) - { - MT_Vector3 norm = ((pt1-pt0).cross(pt2-pt0)).safe_normalized(); - norm[0] = ((int) (10*norm[0]))/10.0; - norm[1] = ((int) (10*norm[1]))/10.0; - norm[2] = ((int) (10*norm[2]))/10.0; - no0=no1=no2=no3= norm; - + { + bool polyvisible = true; + RAS_IPolyMaterial* polymat = NULL; + BL_Material *bl_mat = NULL; + + if(converter->GetMaterials()) { + /* do Blender Multitexture and Blender GLSL materials */ + unsigned int rgb[4]; + MT_Point2 uv[4]; + + /* first is the BL_Material */ + bl_mat = ConvertMaterial(ma, tface, tfaceName, mface, mcol, + lightlayer, blenderobj, layers, converter->GetGLSLMaterials()); + + bl_mat->material_index = (int)mface->mat_nr; + + polyvisible = ((bl_mat->ras_mode & POLY_VIS)!=0); + collider = ((bl_mat->ras_mode & COLLIDER)!=0); + + /* vertex colors and uv's were stored in bl_mat temporarily */ + bl_mat->GetConversionRGB(rgb); + rgb0 = rgb[0]; rgb1 = rgb[1]; + rgb2 = rgb[2]; rgb3 = rgb[3]; + + bl_mat->GetConversionUV(uv); + uv0 = uv[0]; uv1 = uv[1]; + uv2 = uv[2]; uv3 = uv[3]; + + bl_mat->GetConversionUV2(uv); + uv20 = uv[0]; uv21 = uv[1]; + uv22 = uv[2]; uv23 = uv[3]; + + /* then the KX_BlenderMaterial */ + polymat = new KX_BlenderMaterial(scene, bl_mat, skinMesh, lightlayer, blenderobj ); } + else { + /* do Texture Face materials */ + Image* bima = (tface)? (Image*)tface->tpage: NULL; + STR_String imastr = (tface)? (bima? (bima)->id.name : "" ) : ""; - { - Material* ma = 0; - bool polyvisible = true; - RAS_IPolyMaterial* polymat = NULL; - BL_Material *bl_mat = NULL; - - if(converter->GetMaterials()) - { - if(mesh->totcol > 1) - ma = mesh->mat[mface->mat_nr]; - else - ma = give_current_material(blenderobj, 1); - - bl_mat = ConvertMaterial(mesh, ma, tface, tfaceName, mface, mmcol, lightlayer, blenderobj, layers, converter->GetGLSLMaterials()); - // set the index were dealing with - bl_mat->material_index = (int)mface->mat_nr; - - polyvisible = ((bl_mat->ras_mode & POLY_VIS)!=0); - collider = ((bl_mat->ras_mode & COLLIDER)!=0); + char transp=0; + short mode=0, tile=0; + int tilexrep=4,tileyrep = 4; + + if (bima) { + tilexrep = bima->xrep; + tileyrep = bima->yrep; + } + + /* get tface properties if available */ + if(tface) { + /* TF_DYNAMIC means the polygon is a collision face */ + collider = ((tface->mode & TF_DYNAMIC) != 0); + transp = tface->transp; + tile = tface->tile; + mode = tface->mode; - polymat = new KX_BlenderMaterial(scene, bl_mat, skinMesh, lightlayer, blenderobj ); + polyvisible = !((mface->flag & ME_HIDE)||(tface->mode & TF_INVISIBLE)); - unsigned int rgb[4]; - bl_mat->GetConversionRGB(rgb); - rgb0 = rgb[0]; rgb1 = rgb[1]; - rgb2 = rgb[2]; rgb3 = rgb[3]; - MT_Point2 uv[4]; - bl_mat->GetConversionUV(uv); - uv0 = uv[0]; uv1 = uv[1]; - uv2 = uv[2]; uv3 = uv[3]; - - bl_mat->GetConversionUV2(uv); - uv20 = uv[0]; uv21 = uv[1]; - uv22 = uv[2]; uv23 = uv[3]; - - if(tangent){ - tan0 = tangent[mface->v1]; - tan1 = tangent[mface->v2]; - tan2 = tangent[mface->v3]; - if (mface->v4) - tan3 = tangent[mface->v4]; - } + uv0 = MT_Point2(tface->uv[0]); + uv1 = MT_Point2(tface->uv[1]); + uv2 = MT_Point2(tface->uv[2]); + + if (mface->v4) + uv3 = MT_Point2(tface->uv[3]); + } + else { + /* no texfaces, set COLLSION true and everything else FALSE */ + mode = default_face_mode; + transp = TF_SOLID; + tile = 0; } - else - { - ma = give_current_material(blenderobj, 1); - Image* bima = ((mesh->mtface && tface) ? (Image*) tface->tpage : NULL); - - STR_String imastr = - ((mesh->mtface && tface) ? - (bima? (bima)->id.name : "" ) : "" ); - - char transp=0; - short mode=0, tile=0; - int tilexrep=4,tileyrep = 4; + /* get vertex colors */ + if (mcol) { + /* we have vertex colors */ + rgb0 = KX_Mcol2uint_new(mcol[0]); + rgb1 = KX_Mcol2uint_new(mcol[1]); + rgb2 = KX_Mcol2uint_new(mcol[2]); - if (bima) - { - tilexrep = bima->xrep; - tileyrep = bima->yrep; - - } + if (mface->v4) + rgb3 = KX_Mcol2uint_new(mcol[3]); + } + else { + /* no vertex colors, take from material, otherwise white */ + unsigned int color = 0xFFFFFFFFL; - if (mesh->mtface && tface) + if (ma) { - // Use texface colors if available - //TF_DYNAMIC means the polygon is a collision face - collider = ((tface->mode & TF_DYNAMIC) != 0); - transp = tface->transp &~ TF_CLIP; - tile = tface->tile; - mode = tface->mode; - - polyvisible = !((mface->flag & ME_HIDE)||(tface->mode & TF_INVISIBLE)); + union + { + unsigned char cp[4]; + unsigned int integer; + } col_converter; - uv0 = MT_Point2(tface->uv[0]); - uv1 = MT_Point2(tface->uv[1]); - uv2 = MT_Point2(tface->uv[2]); - - if (mface->v4) - uv3 = MT_Point2(tface->uv[3]); - } - else - { - // no texfaces, set COLLSION true and everything else FALSE + col_converter.cp[3] = (unsigned char) (ma->r*255.0); + col_converter.cp[2] = (unsigned char) (ma->g*255.0); + col_converter.cp[1] = (unsigned char) (ma->b*255.0); + col_converter.cp[0] = (unsigned char) (ma->alpha*255.0); - mode = default_face_mode; - transp = TF_SOLID; - tile = 0; + color = col_converter.integer; } - if (mmcol) - { - // Use vertex colors - rgb0 = KX_Mcol2uint_new(mmcol[0]); - rgb1 = KX_Mcol2uint_new(mmcol[1]); - rgb2 = KX_Mcol2uint_new(mmcol[2]); - - if (mface->v4) - rgb3 = KX_Mcol2uint_new(mmcol[3]); - } - else { - // no vertex colors: take from material if we have one, - // otherwise set to white - unsigned int color = 0xFFFFFFFFL; + rgb0 = KX_rgbaint2uint_new(color); + rgb1 = KX_rgbaint2uint_new(color); + rgb2 = KX_rgbaint2uint_new(color); + + if (mface->v4) + rgb3 = KX_rgbaint2uint_new(color); + } + + bool istriangle = (mface->v4==0); - if (ma) - { - union - { - unsigned char cp[4]; - unsigned int integer; - } col_converter; - - col_converter.cp[3] = (unsigned char) (ma->r*255.0); - col_converter.cp[2] = (unsigned char) (ma->g*255.0); - col_converter.cp[1] = (unsigned char) (ma->b*255.0); - col_converter.cp[0] = (unsigned char) (ma->alpha*255.0); - - color = col_converter.integer; - } + // only zsort alpha + add + bool alpha = (transp == TF_ALPHA || transp == TF_ADD); + bool zsort = (mode & TF_ALPHASORT)? alpha: 0; + + polymat = new KX_PolygonMaterial(imastr, ma, + tile, tilexrep, tileyrep, + mode, transp, alpha, zsort, lightlayer, istriangle, blenderobj, tface, (unsigned int*)mcol); - rgb0 = KX_rgbaint2uint_new(color); - rgb1 = KX_rgbaint2uint_new(color); - rgb2 = KX_rgbaint2uint_new(color); - - if (mface->v4) - rgb3 = KX_rgbaint2uint_new(color); - } - - bool istriangle = (mface->v4==0); - bool zsort = ma?(ma->mode & MA_ZTRA) != 0:false; - - polymat = new KX_PolygonMaterial(imastr, ma, - tile, tilexrep, tileyrep, - mode, transp, zsort, lightlayer, istriangle, blenderobj, tface, (unsigned int*)mmcol); - - if (ma) - { - polymat->m_specular = MT_Vector3(ma->specr, ma->specg, ma->specb)*ma->spec; - polymat->m_shininess = (float)ma->har/4.0; // 0 < ma->har <= 512 - polymat->m_diffuse = MT_Vector3(ma->r, ma->g, ma->b)*(ma->emit + ma->ref); + if (ma) { + polymat->m_specular = MT_Vector3(ma->specr, ma->specg, ma->specb)*ma->spec; + polymat->m_shininess = (float)ma->har/4.0; // 0 < ma->har <= 512 + polymat->m_diffuse = MT_Vector3(ma->r, ma->g, ma->b)*(ma->emit + ma->ref); + } + else { + polymat->m_specular = MT_Vector3(0.0f,0.0f,0.0f); + polymat->m_shininess = 35.0; + } + } - } else - { - polymat->m_specular = MT_Vector3(0.0f,0.0f,0.0f); - polymat->m_shininess = 35.0; - } + // see if a bucket was reused or a new one was created + // this way only one KX_BlenderMaterial object has to exist per bucket + bool bucketCreated; + RAS_MaterialBucket* bucket = scene->FindBucket(polymat, bucketCreated); + if (bucketCreated) { + // this is needed to free up memory afterwards + converter->RegisterPolyMaterial(polymat); + if(converter->GetMaterials()) { + converter->RegisterBlenderMaterial(bl_mat); } - - // see if a bucket was reused or a new one was created - // this way only one KX_BlenderMaterial object has to exist per bucket - bool bucketCreated; - RAS_MaterialBucket* bucket = scene->FindBucket(polymat, bucketCreated); - if (bucketCreated) { - // this is needed to free up memory afterwards - converter->RegisterPolyMaterial(polymat); - if(converter->GetMaterials()) { - converter->RegisterBlenderMaterial(bl_mat); - } - } else { - // delete the material objects since they are no longer needed - // from now on, use the polygon material from the material bucket - delete polymat; - if(converter->GetMaterials()) { - delete bl_mat; - } - polymat = bucket->GetPolyMaterial(); + } else { + // delete the material objects since they are no longer needed + // from now on, use the polygon material from the material bucket + delete polymat; + if(converter->GetMaterials()) { + delete bl_mat; } - - int nverts = mface->v4?4:3; - int vtxarray = meshobj->FindVertexArray(nverts,polymat); - RAS_Polygon* poly = new RAS_Polygon(bucket,polyvisible,nverts,vtxarray); + polymat = bucket->GetPolyMaterial(); + } + + int nverts = mface->v4?4:3; + int vtxarray = meshobj->FindVertexArray(nverts,polymat); + RAS_Polygon* poly = new RAS_Polygon(bucket,polyvisible,nverts,vtxarray); - bool flat; + bool flat; - if (skinMesh) { - /* If the face is set to solid, all fnors are the same */ - if (mface->flag & ME_SMOOTH) - flat = false; - else - flat = true; - } - else + if (skinMesh) { + /* If the face is set to solid, all fnors are the same */ + if (mface->flag & ME_SMOOTH) flat = false; + else + flat = true; + } + else + flat = false; - poly->SetVertex(0,meshobj->FindOrAddVertex(vtxarray,pt0,uv0,uv20,tan0,rgb0,no0,flat,polymat,mface->v1)); - poly->SetVertex(1,meshobj->FindOrAddVertex(vtxarray,pt1,uv1,uv21,tan1,rgb1,no1,flat,polymat,mface->v2)); - poly->SetVertex(2,meshobj->FindOrAddVertex(vtxarray,pt2,uv2,uv22,tan2,rgb2,no2,flat,polymat,mface->v3)); - if (nverts==4) - poly->SetVertex(3,meshobj->FindOrAddVertex(vtxarray,pt3,uv3,uv23,tan3,rgb3,no3,flat,polymat,mface->v4)); + poly->SetVertex(0,meshobj->FindOrAddVertex(vtxarray,pt0,uv0,uv20,tan0,rgb0,no0,flat,polymat,mface->v1)); + poly->SetVertex(1,meshobj->FindOrAddVertex(vtxarray,pt1,uv1,uv21,tan1,rgb1,no1,flat,polymat,mface->v2)); + poly->SetVertex(2,meshobj->FindOrAddVertex(vtxarray,pt2,uv2,uv22,tan2,rgb2,no2,flat,polymat,mface->v3)); + if (nverts==4) + poly->SetVertex(3,meshobj->FindOrAddVertex(vtxarray,pt3,uv3,uv23,tan3,rgb3,no3,flat,polymat,mface->v4)); - meshobj->AddPolygon(poly); - if (poly->IsCollider()) + meshobj->AddPolygon(poly); + if (poly->IsCollider()) + { + RAS_TriangleIndex idx; + idx.m_index[0] = mface->v1; + idx.m_index[1] = mface->v2; + idx.m_index[2] = mface->v3; + idx.m_collider = collider; + meshobj->m_triangle_indices.push_back(idx); + if (nverts==4) { - RAS_TriangleIndex idx; - idx.m_index[0] = mface->v1; - idx.m_index[1] = mface->v2; - idx.m_index[2] = mface->v3; - idx.m_collider = collider; - meshobj->m_triangle_indices.push_back(idx); - if (nverts==4) - { - idx.m_index[0] = mface->v1; - idx.m_index[1] = mface->v3; - idx.m_index[2] = mface->v4; - idx.m_collider = collider; - meshobj->m_triangle_indices.push_back(idx); - } + idx.m_index[0] = mface->v1; + idx.m_index[1] = mface->v3; + idx.m_index[2] = mface->v4; + idx.m_collider = collider; + meshobj->m_triangle_indices.push_back(idx); } - -// poly->SetVisibleWireframeEdges(mface->edcode); - poly->SetCollider(collider); } + +// poly->SetVisibleWireframeEdges(mface->edcode); + poly->SetCollider(collider); } + if (tface) tface++; - if (mmcol) - mmcol+=4; + if (mcol) + mcol+=4; for (int lay=0; lay<MAX_MTFACE; lay++) { @@ -1127,11 +1048,10 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* (*mit)->GetPolyMaterial()->OnConstruction(); } - if(tangent) - delete [] tangent; - if (layers) delete []layers; + + dm->release(dm); return meshobj; } @@ -1819,7 +1739,7 @@ KX_GameObject* getGameOb(STR_String busc,CListValue* sumolist){ return 0; } -#include "BLI_arithb.h" + // convert blender objects into ketsji gameobjects void BL_ConvertBlenderObjects(struct Main* maggie, const STR_String& scenename, @@ -1847,7 +1767,10 @@ void BL_ConvertBlenderObjects(struct Main* maggie, int aspect_width; int aspect_height; vector<MT_Vector3> inivel,iniang; - + set<Group*> grouplist; // list of groups to be converted + set<Object*> allblobj; // all objects converted + set<Object*> groupobj; // objects from groups (never in active layer) + if (alwaysUseExpandFraming) { frame_type = RAS_FrameSettings::e_frame_extend; aspect_width = canvas->GetWidth(); @@ -1919,6 +1842,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie, for (SETLOOPER(blenderscene, base)) { Object* blenderobject = base->object; + allblobj.insert(blenderobject); + KX_GameObject* gameobj = gameobject_from_blenderobject( base->object, kxscene, @@ -1932,7 +1857,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, if (converter->addInitFromFrame) if (!isInActiveLayer) addobj=false; - + if (gameobj&&addobj) { MT_Point3 posPrev; @@ -1984,10 +1909,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie, gameobj->NodeUpdateGS(0,true); BL_ConvertIpos(blenderobject,gameobj,converter); - // TODO: expand to multiple ipos per mesh - Material *mat = give_current_material(blenderobject, 1); - if(mat) BL_ConvertMaterialIpos(mat, gameobj, converter); - + BL_ConvertMaterialIpos(blenderobject, gameobj, converter); + sumolist->Add(gameobj->AddRef()); BL_ConvertProperties(blenderobject,gameobj,timemgr,kxscene,isInActiveLayer); @@ -2024,8 +1947,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie, // needed for python scripting logicmgr->RegisterGameObjectName(gameobj->GetName(),gameobj); - // needed for dynamic object morphing - logicmgr->RegisterGameObj(gameobj, blenderobject); + // needed for group duplication + logicmgr->RegisterGameObj(blenderobject, gameobj); for (int i = 0; i < gameobj->GetMeshCount(); i++) logicmgr->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), blenderobject); @@ -2046,7 +1969,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, gameobj->NodeUpdateGS(0,true); gameobj->Bucketize(); - + } else { @@ -2054,6 +1977,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie, //at the end of this function if it is not a root object inactivelist->Add(gameobj->AddRef()); } + if (gameobj->IsDupliGroup()) + grouplist.insert(blenderobject->dup_group); if (converter->addInitFromFrame){ gameobj->NodeSetLocalPosition(posPrev); gameobj->NodeSetLocalOrientation(angor); @@ -2073,7 +1998,188 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } - if (blenderscene->camera) { + if (!grouplist.empty()) + { + // now convert the group referenced by dupli group object + // keep track of all groups already converted + set<Group*> allgrouplist = grouplist; + set<Group*> tempglist; + // recurse + while (!grouplist.empty()) + { + set<Group*>::iterator git; + tempglist.clear(); + tempglist.swap(grouplist); + for (git=tempglist.begin(); git!=tempglist.end(); git++) + { + Group* group = *git; + GroupObject* go; + for(go=(GroupObject*)group->gobject.first; go; go=(GroupObject*)go->next) + { + Object* blenderobject = go->ob; + if (converter->FindGameObject(blenderobject) == NULL) + { + allblobj.insert(blenderobject); + groupobj.insert(blenderobject); + KX_GameObject* gameobj = gameobject_from_blenderobject( + blenderobject, + kxscene, + rendertools, + converter, + blenderscene); + + // this code is copied from above except that + // object from groups are never in active layer + bool isInActiveLayer = false; + bool addobj=true; + + if (converter->addInitFromFrame) + if (!isInActiveLayer) + addobj=false; + + if (gameobj&&addobj) + { + MT_Point3 posPrev; + MT_Matrix3x3 angor; + if (converter->addInitFromFrame) + blenderscene->r.cfra=blenderscene->r.sfra; + + MT_Point3 pos = MT_Point3( + blenderobject->loc[0]+blenderobject->dloc[0], + blenderobject->loc[1]+blenderobject->dloc[1], + blenderobject->loc[2]+blenderobject->dloc[2] + ); + MT_Vector3 eulxyz = MT_Vector3( + blenderobject->rot[0], + blenderobject->rot[1], + blenderobject->rot[2] + ); + MT_Vector3 scale = MT_Vector3( + blenderobject->size[0], + blenderobject->size[1], + blenderobject->size[2] + ); + if (converter->addInitFromFrame){//rcruiz + float eulxyzPrev[3]; + blenderscene->r.cfra=blenderscene->r.sfra-1; + update_for_newframe(); + MT_Vector3 tmp=pos-MT_Point3(blenderobject->loc[0]+blenderobject->dloc[0], + blenderobject->loc[1]+blenderobject->dloc[1], + blenderobject->loc[2]+blenderobject->dloc[2] + ); + eulxyzPrev[0]=blenderobject->rot[0]; + eulxyzPrev[1]=blenderobject->rot[1]; + eulxyzPrev[2]=blenderobject->rot[2]; + + double fps = (double) blenderscene->r.frs_sec/ + (double) blenderscene->r.frs_sec_base; + + tmp.scale(fps, fps, fps); + inivel.push_back(tmp); + tmp=eulxyz-eulxyzPrev; + tmp.scale(fps, fps, fps); + iniang.push_back(tmp); + blenderscene->r.cfra=blenderscene->r.sfra; + update_for_newframe(); + } + + gameobj->NodeSetLocalPosition(pos); + gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz)); + gameobj->NodeSetLocalScale(scale); + gameobj->NodeUpdateGS(0,true); + + BL_ConvertIpos(blenderobject,gameobj,converter); + BL_ConvertMaterialIpos(blenderobject,gameobj, converter); + + sumolist->Add(gameobj->AddRef()); + + BL_ConvertProperties(blenderobject,gameobj,timemgr,kxscene,isInActiveLayer); + + + gameobj->SetName(blenderobject->id.name); + + // templist to find Root Parents (object with no parents) + templist->Add(gameobj->AddRef()); + + // update children/parent hierarchy + if ((blenderobject->parent != 0)&&(!converter->addInitFromFrame)) + { + // blender has an additional 'parentinverse' offset in each object + SG_Node* parentinversenode = new SG_Node(NULL,NULL,SG_Callbacks()); + + // define a normal parent relationship for this node. + KX_NormalParentRelation * parent_relation = KX_NormalParentRelation::New(); + parentinversenode->SetParentRelation(parent_relation); + + parentChildLink pclink; + pclink.m_blenderchild = blenderobject; + pclink.m_gamechildnode = parentinversenode; + vec_parent_child.push_back(pclink); + + float* fl = (float*) blenderobject->parentinv; + MT_Transform parinvtrans(fl); + parentinversenode->SetLocalPosition(parinvtrans.getOrigin()); + parentinversenode->SetLocalOrientation(parinvtrans.getBasis()); + + parentinversenode->AddChild(gameobj->GetSGNode()); + } + + // needed for python scripting + logicmgr->RegisterGameObjectName(gameobj->GetName(),gameobj); + + // needed for group duplication + logicmgr->RegisterGameObj(blenderobject, gameobj); + for (int i = 0; i < gameobj->GetMeshCount(); i++) + logicmgr->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), blenderobject); + + converter->RegisterGameObject(gameobj, blenderobject); + // this was put in rapidly, needs to be looked at more closely + // only draw/use objects in active 'blender' layers + + logicbrick_conversionlist->Add(gameobj->AddRef()); + + if (converter->addInitFromFrame){ + posPrev=gameobj->NodeGetWorldPosition(); + angor=gameobj->NodeGetWorldOrientation(); + } + if (isInActiveLayer) + { + objectlist->Add(gameobj->AddRef()); + //tf.Add(gameobj->GetSGNode()); + + gameobj->NodeUpdateGS(0,true); + gameobj->Bucketize(); + + } + else + { + //we must store this object otherwise it will be deleted + //at the end of this function if it is not a root object + inactivelist->Add(gameobj->AddRef()); + + } + if (gameobj->IsDupliGroup()) + { + // check that the group is not already converted + if (allgrouplist.insert(blenderobject->dup_group).second) + grouplist.insert(blenderobject->dup_group); + } + if (converter->addInitFromFrame){ + gameobj->NodeSetLocalPosition(posPrev); + gameobj->NodeSetLocalOrientation(angor); + } + + } + if (gameobj) + gameobj->Release(); + } + } + } + } + } + + // non-camera objects not supported as camera currently + if (blenderscene->camera && blenderscene->camera->type == OB_CAMERA) { KX_Camera *gamecamera= (KX_Camera*) converter->FindGameObject(blenderscene->camera); if(gamecamera) @@ -2081,15 +2187,18 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } // Set up armatures - for(SETLOOPER(blenderscene, base)){ - if (base->object->type==OB_MESH){ - Mesh *me = (Mesh*)base->object->data; + set<Object*>::iterator oit; + for(oit=allblobj.begin(); oit!=allblobj.end(); oit++) + { + Object* blenderobj = *oit; + if (blenderobj->type==OB_MESH){ + Mesh *me = (Mesh*)blenderobj->data; if (me->dvert){ - KX_GameObject *obj = converter->FindGameObject(base->object); + KX_GameObject *obj = converter->FindGameObject(blenderobj); - if (base->object->parent && base->object->parent->type==OB_ARMATURE && base->object->partype==PARSKEL){ - KX_GameObject *par = converter->FindGameObject(base->object->parent); + if (obj && blenderobj->parent && blenderobj->parent->type==OB_ARMATURE && blenderobj->partype==PARSKEL){ + KX_GameObject *par = converter->FindGameObject(blenderobj->parent); if (par) ((BL_SkinDeformer*)(((BL_DeformableGameObject*)obj)->m_pDeformer))->SetArmature((BL_ArmatureObject*) par); } @@ -2174,7 +2283,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie, { meshobj = gameobj->GetMesh(0); } - BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,activeLayerBitInfo,physics_engine,converter,processCompoundChildren); + int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0; + BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,physics_engine,converter,processCompoundChildren); } processCompoundChildren = true; @@ -2189,7 +2299,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie, { meshobj = gameobj->GetMesh(0); } - BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,activeLayerBitInfo,physics_engine,converter,processCompoundChildren); + int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0; + BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,physics_engine,converter,processCompoundChildren); } @@ -2311,29 +2422,32 @@ void BL_ConvertBlenderObjects(struct Main* maggie, { KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i)); struct Object* blenderobj = converter->FindBlenderObject(gameobj); - bool isInActiveLayer = (blenderobj->lay & activeLayerBitInfo)!=0; - BL_ConvertActuators(maggie->name, blenderobj,gameobj,logicmgr,kxscene,ketsjiEngine,executePriority, activeLayerBitInfo,isInActiveLayer,rendertools,converter); + int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0; + bool isInActiveLayer = (blenderobj->lay & layerMask)!=0; + BL_ConvertActuators(maggie->name, blenderobj,gameobj,logicmgr,kxscene,ketsjiEngine,executePriority, layerMask,isInActiveLayer,rendertools,converter); } for ( i=0;i<logicbrick_conversionlist->GetCount();i++) { KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i)); struct Object* blenderobj = converter->FindBlenderObject(gameobj); - bool isInActiveLayer = (blenderobj->lay & activeLayerBitInfo)!=0; - BL_ConvertControllers(blenderobj,gameobj,logicmgr,pythondictionary,executePriority,activeLayerBitInfo,isInActiveLayer,converter); + int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0; + bool isInActiveLayer = (blenderobj->lay & layerMask)!=0; + BL_ConvertControllers(blenderobj,gameobj,logicmgr,pythondictionary,executePriority,layerMask,isInActiveLayer,converter); } for ( i=0;i<logicbrick_conversionlist->GetCount();i++) { KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i)); struct Object* blenderobj = converter->FindBlenderObject(gameobj); - bool isInActiveLayer = (blenderobj->lay & activeLayerBitInfo)!=0; - BL_ConvertSensors(blenderobj,gameobj,logicmgr,kxscene,keydev,executePriority,activeLayerBitInfo,isInActiveLayer,canvas,converter); + int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0; + bool isInActiveLayer = (blenderobj->lay & layerMask)!=0; + BL_ConvertSensors(blenderobj,gameobj,logicmgr,kxscene,keydev,executePriority,layerMask,isInActiveLayer,canvas,converter); + // set the init state to all objects + gameobj->SetInitState((blenderobj->init_state)?blenderobj->init_state:blenderobj->state); } - // apply the initial state to controllers - for ( i=0;i<logicbrick_conversionlist->GetCount();i++) + // apply the initial state to controllers, only on the active objects as this registers the sensors + for ( i=0;i<objectlist->GetCount();i++) { - KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i)); - struct Object* blenderobj = converter->FindBlenderObject(gameobj); - gameobj->SetInitState((blenderobj->init_state)?blenderobj->init_state:blenderobj->state); + KX_GameObject* gameobj = static_cast<KX_GameObject*>(objectlist->GetValue(i)); gameobj->ResetState(); } @@ -2344,5 +2458,19 @@ void BL_ConvertBlenderObjects(struct Main* maggie, // Calculate the scene btree - // too slow - commented out. //kxscene->SetNodeTree(tf.MakeTree()); + + // instantiate dupli group, we will loop trough the object + // that are in active layers. Note that duplicating group + // has the effect of adding objects at the end of objectlist. + // Only loop through the first part of the list. + int objcount = objectlist->GetCount(); + for (i=0;i<objcount;i++) + { + KX_GameObject* gameobj = (KX_GameObject*) objectlist->GetValue(i); + if (gameobj->IsDupliGroup()) + { + kxscene->DupliGroupRecurse(gameobj, 0); + } + } } diff --git a/source/gameengine/Converter/BL_DeformableGameObject.h b/source/gameengine/Converter/BL_DeformableGameObject.h index 57a404ad72b..315ad18c42c 100644 --- a/source/gameengine/Converter/BL_DeformableGameObject.h +++ b/source/gameengine/Converter/BL_DeformableGameObject.h @@ -60,6 +60,7 @@ public: { if (m_pDeformer) m_pDeformer->Relink (map); + KX_GameObject::Relink(map); }; void ProcessReplica(KX_GameObject* replica); diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 41bf565a4d8..7fb5d7ff829 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -442,15 +442,15 @@ PyMethodDef BL_ShapeActionActuator::Methods[] = { {"setProperty", (PyCFunction) BL_ShapeActionActuator::sPySetProperty, METH_VARARGS, SetProperty_doc}, {"setBlendtime", (PyCFunction) BL_ShapeActionActuator::sPySetBlendtime, METH_VARARGS, SetBlendtime_doc}, - {"getAction", (PyCFunction) BL_ShapeActionActuator::sPyGetAction, METH_VARARGS, GetAction_doc}, - {"getStart", (PyCFunction) BL_ShapeActionActuator::sPyGetStart, METH_VARARGS, GetStart_doc}, - {"getEnd", (PyCFunction) BL_ShapeActionActuator::sPyGetEnd, METH_VARARGS, GetEnd_doc}, - {"getBlendin", (PyCFunction) BL_ShapeActionActuator::sPyGetBlendin, METH_VARARGS, GetBlendin_doc}, - {"getPriority", (PyCFunction) BL_ShapeActionActuator::sPyGetPriority, METH_VARARGS, GetPriority_doc}, - {"getFrame", (PyCFunction) BL_ShapeActionActuator::sPyGetFrame, METH_VARARGS, GetFrame_doc}, - {"getProperty", (PyCFunction) BL_ShapeActionActuator::sPyGetProperty, METH_VARARGS, GetProperty_doc}, - {"getType", (PyCFunction) BL_ShapeActionActuator::sPyGetType, METH_VARARGS, GetType_doc}, - {"setType", (PyCFunction) BL_ShapeActionActuator::sPySetType, METH_VARARGS, SetType_doc}, + {"getAction", (PyCFunction) BL_ShapeActionActuator::sPyGetAction, METH_NOARGS, GetAction_doc}, + {"getStart", (PyCFunction) BL_ShapeActionActuator::sPyGetStart, METH_NOARGS, GetStart_doc}, + {"getEnd", (PyCFunction) BL_ShapeActionActuator::sPyGetEnd, METH_NOARGS, GetEnd_doc}, + {"getBlendin", (PyCFunction) BL_ShapeActionActuator::sPyGetBlendin, METH_NOARGS, GetBlendin_doc}, + {"getPriority", (PyCFunction) BL_ShapeActionActuator::sPyGetPriority, METH_NOARGS, GetPriority_doc}, + {"getFrame", (PyCFunction) BL_ShapeActionActuator::sPyGetFrame, METH_NOARGS, GetFrame_doc}, + {"getProperty", (PyCFunction) BL_ShapeActionActuator::sPyGetProperty, METH_NOARGS, GetProperty_doc}, + {"getType", (PyCFunction) BL_ShapeActionActuator::sPyGetType, METH_NOARGS, GetType_doc}, + {"setType", (PyCFunction) BL_ShapeActionActuator::sPySetType, METH_NOARGS, SetType_doc}, {NULL,NULL} //Sentinel }; @@ -463,9 +463,7 @@ char BL_ShapeActionActuator::GetAction_doc[] = "getAction()\n" "\tReturns a string containing the name of the current action.\n"; -PyObject* BL_ShapeActionActuator::PyGetAction(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PyGetAction(PyObject* self) { PyObject *result; if (m_action){ @@ -484,9 +482,7 @@ char BL_ShapeActionActuator::GetProperty_doc[] = "getProperty()\n" "\tReturns the name of the property to be used in FromProp mode.\n"; -PyObject* BL_ShapeActionActuator::PyGetProperty(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PyGetProperty(PyObject* self) { PyObject *result; result = Py_BuildValue("s", (const char *)m_propname); @@ -499,9 +495,7 @@ char BL_ShapeActionActuator::GetFrame_doc[] = "getFrame()\n" "\tReturns the current frame number.\n"; -PyObject* BL_ShapeActionActuator::PyGetFrame(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PyGetFrame(PyObject* self) { PyObject *result; result = Py_BuildValue("f", m_localtime); @@ -514,9 +508,7 @@ char BL_ShapeActionActuator::GetEnd_doc[] = "getEnd()\n" "\tReturns the last frame of the action.\n"; -PyObject* BL_ShapeActionActuator::PyGetEnd(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PyGetEnd(PyObject* self) { PyObject *result; result = Py_BuildValue("f", m_endframe); @@ -529,9 +521,7 @@ char BL_ShapeActionActuator::GetStart_doc[] = "getStart()\n" "\tReturns the starting frame of the action.\n"; -PyObject* BL_ShapeActionActuator::PyGetStart(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PyGetStart(PyObject* self) { PyObject *result; result = Py_BuildValue("f", m_startframe); @@ -545,9 +535,7 @@ char BL_ShapeActionActuator::GetBlendin_doc[] = "\tReturns the number of interpolation animation frames to be\n" "\tgenerated when this actuator is triggered.\n"; -PyObject* BL_ShapeActionActuator::PyGetBlendin(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PyGetBlendin(PyObject* self) { PyObject *result; result = Py_BuildValue("f", m_blendin); @@ -561,9 +549,7 @@ char BL_ShapeActionActuator::GetPriority_doc[] = "\tReturns the priority for this actuator. Actuators with lower\n" "\tPriority numbers will override actuators with higher numbers.\n"; -PyObject* BL_ShapeActionActuator::PyGetPriority(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PyGetPriority(PyObject* self) { PyObject *result; result = Py_BuildValue("i", m_priority); @@ -605,6 +591,7 @@ PyObject* BL_ShapeActionActuator::PySetAction(PyObject* self, } } else { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -627,6 +614,7 @@ PyObject* BL_ShapeActionActuator::PySetStart(PyObject* self, m_startframe = start; } else { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -649,6 +637,7 @@ PyObject* BL_ShapeActionActuator::PySetEnd(PyObject* self, m_endframe = end; } else { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -672,6 +661,7 @@ PyObject* BL_ShapeActionActuator::PySetBlendin(PyObject* self, m_blendin = blendin; } else { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -700,6 +690,7 @@ PyObject* BL_ShapeActionActuator::PySetBlendtime(PyObject* self, m_blendframe = m_blendin; } else { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -724,6 +715,7 @@ PyObject* BL_ShapeActionActuator::PySetPriority(PyObject* self, m_priority = priority; } else { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -750,6 +742,7 @@ PyObject* BL_ShapeActionActuator::PySetFrame(PyObject* self, m_localtime=m_endframe; } else { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -773,6 +766,7 @@ PyObject* BL_ShapeActionActuator::PySetProperty(PyObject* self, m_propname = string; } else { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -784,9 +778,7 @@ PyObject* BL_ShapeActionActuator::PySetProperty(PyObject* self, char BL_ShapeActionActuator::GetType_doc[] = "getType()\n" "\tReturns the operation mode of the actuator.\n"; -PyObject* BL_ShapeActionActuator::PyGetType(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* BL_ShapeActionActuator::PyGetType(PyObject* self) { return Py_BuildValue("h", m_playtype); } @@ -801,6 +793,7 @@ PyObject* BL_ShapeActionActuator::PySetType(PyObject* self, short typeArg; if (!PyArg_ParseTuple(args, "h", &typeArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h index 434a62a1233..10cbe9f1ac3 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.h +++ b/source/gameengine/Converter/BL_ShapeActionActuator.h @@ -1,5 +1,5 @@ /** - * $Id$ + * $Id:BL_ShapeActionActuator.h 15330 2008-06-23 16:37:51Z theeth $ * * ***** BEGIN GPL LICENSE BLOCK ***** * @@ -87,15 +87,15 @@ public: KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetBlendtime); KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetChannel); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,GetAction); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,GetBlendin); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,GetPriority); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,GetStart); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,GetEnd); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,GetFrame); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,GetProperty); + KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetAction); + KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetBlendin); + KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetPriority); + KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetStart); + KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetEnd); + KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetFrame); + KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetProperty); // KX_PYMETHOD(BL_ActionActuator,GetChannel); - KX_PYMETHOD_DOC(BL_ShapeActionActuator,GetType); + KX_PYMETHOD_DOC_NOARGS(BL_ShapeActionActuator,GetType); KX_PYMETHOD_DOC(BL_ShapeActionActuator,SetType); virtual PyObject* _getattr(const STR_String& attr); diff --git a/source/gameengine/Converter/BL_ShapeDeformer.cpp b/source/gameengine/Converter/BL_ShapeDeformer.cpp index f2af0d9294e..d3fbb795b23 100644 --- a/source/gameengine/Converter/BL_ShapeDeformer.cpp +++ b/source/gameengine/Converter/BL_ShapeDeformer.cpp @@ -109,6 +109,13 @@ bool BL_ShapeDeformer::ExecuteShapeDrivers(void) vector<IpoCurve*>::iterator it; void *poin; int type; + // the shape drivers use the bone matrix as input. Must + // update the matrix now + Object* par_arma = m_armobj->GetArmatureObject(); + m_armobj->ApplyPose(); + where_is_pose( par_arma ); + PoseApplied(true); + for (it=m_shapeDrivers.begin(); it!=m_shapeDrivers.end(); it++) { // no need to set a specific time: this curve has a driver IpoCurve *icu = *it; diff --git a/source/gameengine/Converter/BL_SkinDeformer.cpp b/source/gameengine/Converter/BL_SkinDeformer.cpp index d3442fe5298..f96c40c098f 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.cpp +++ b/source/gameengine/Converter/BL_SkinDeformer.cpp @@ -66,7 +66,8 @@ BL_SkinDeformer::BL_SkinDeformer(BL_DeformableGameObject *gameobj, m_armobj(arma), m_lastArmaUpdate(-1), m_defbase(&bmeshobj->defbase), - m_releaseobject(false) + m_releaseobject(false), + m_poseApplied(false) { Mat4CpyMat4(m_obmat, bmeshobj->obmat); }; @@ -98,32 +99,28 @@ BL_SkinDeformer::~BL_SkinDeformer() m_armobj->Release(); } -bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *) +bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *mat) { size_t i, j; - if (!Update()) - // no need to update the cache - return false; + // update the vertex in m_transverts + Update(); - // Update all materials at once, so we can do the above update test - // without ending up with some materials not updated - for(RAS_MaterialBucket::Set::iterator mit = m_pMeshObject->GetFirstMaterial(); - mit != m_pMeshObject->GetLastMaterial(); ++ mit) { - RAS_IPolyMaterial *mat = (*mit)->GetPolyMaterial(); + // The vertex cache can only be updated for this deformer: + // Duplicated objects with more than one ploymaterial (=multiple mesh slot per object) + // share the same mesh (=the same cache). As the rendering is done per polymaterial + // cycling through the objects, the entire mesh cache cannot be updated in one shot. + vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat); - vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat); + // For each array + for (i=0; i<vertexarrays.size(); i++) { + KX_VertexArray& vertexarray = (*vertexarrays[i]); - // For each array - for (i=0; i<vertexarrays.size(); i++) { - KX_VertexArray& vertexarray = (*vertexarrays[i]); - - // For each vertex - // copy the untransformed data from the original mvert - for (j=0; j<vertexarray.size(); j++) { - RAS_TexVert& v = vertexarray[j]; - v.SetXYZ(m_transverts[v.getOrigIndex()]); - } + // For each vertex + // copy the untransformed data from the original mvert + for (j=0; j<vertexarray.size(); j++) { + RAS_TexVert& v = vertexarray[j]; + v.SetXYZ(m_transverts[v.getOrigIndex()]); } } @@ -153,9 +150,11 @@ bool BL_SkinDeformer::Update(void) /* XXX note: where_is_pose() (from BKE_armature.h) calculates all matrices needed to start deforming */ /* but it requires the blender object pointer... */ - Object* par_arma = m_armobj->GetArmatureObject(); - where_is_pose( par_arma ); + if (!PoseApplied()){ + m_armobj->ApplyPose(); + where_is_pose( par_arma ); + } /* store verts locally */ VerifyStorage(); @@ -180,7 +179,8 @@ bool BL_SkinDeformer::Update(void) /* Update the current frame */ m_lastArmaUpdate=m_armobj->GetLastFrame(); - + /* reset for next frame */ + PoseApplied(false); /* indicate that the m_transverts and normals are up to date */ return true; } diff --git a/source/gameengine/Converter/BL_SkinDeformer.h b/source/gameengine/Converter/BL_SkinDeformer.h index f35db8273c4..d3fc5ae2a81 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.h +++ b/source/gameengine/Converter/BL_SkinDeformer.h @@ -81,10 +81,13 @@ public: virtual ~BL_SkinDeformer(); bool Update (void); bool Apply (class RAS_IPolyMaterial *polymat); + bool PoseApplied() + { return m_poseApplied; } + void PoseApplied(bool applied) + { m_poseApplied = applied; } bool PoseUpdated(void) { if (m_armobj && m_lastArmaUpdate!=m_armobj->GetLastFrame()) { - m_armobj->ApplyPose(); return true; } return false; @@ -102,6 +105,7 @@ protected: ListBase* m_defbase; float m_obmat[4][4]; // the reference matrix for skeleton deform bool m_releaseobject; + bool m_poseApplied; }; diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index 1cc1b2e27a3..53ac730d203 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -503,7 +503,7 @@ void BL_ConvertActuators(char* maggiename, case ACT_PROPERTY: { bPropertyActuator* propact = (bPropertyActuator*) bact->data; - CValue* destinationObj = NULL; + SCA_IObject* destinationObj = NULL; /* here the destinationobject is searched. problem with multiple scenes: other scenes @@ -628,6 +628,8 @@ void BL_ConvertActuators(char* maggiename, /* convert settings... degrees in the ui become radians */ /* internally */ if (conact->type == ACT_CONST_TYPE_ORI) { + min = (MT_2_PI * conact->minloc[0])/360.0; + max = (MT_2_PI * conact->maxloc[0])/360.0; switch (conact->mode) { case ACT_CONST_DIRPX: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX; @@ -656,18 +658,18 @@ void BL_ConvertActuators(char* maggiename, min = conact->minloc[2]; max = conact->maxloc[2]; break; - case ACT_CONST_DIRMX: - locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRMX; + case ACT_CONST_DIRNX: + locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX; min = conact->minloc[0]; max = conact->maxloc[0]; break; - case ACT_CONST_DIRMY: - locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRMY; + case ACT_CONST_DIRNY: + locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY; min = conact->minloc[1]; max = conact->maxloc[1]; break; - case ACT_CONST_DIRMZ: - locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRMZ; + case ACT_CONST_DIRNZ: + locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ; min = conact->minloc[2]; max = conact->maxloc[2]; break; diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp index 7c9df688d45..5e433bb821b 100644 --- a/source/gameengine/Converter/KX_ConvertSensors.cpp +++ b/source/gameengine/Converter/KX_ConvertSensors.cpp @@ -733,9 +733,9 @@ void BL_ConvertSensors(struct Object* blenderobject, gameobj->AddSensor(gamesensor); // only register to manager if it's in an active layer - - if (isInActiveLayer) - gamesensor->RegisterToManager(); + // Make registration dynamic: only when sensor is activated + //if (isInActiveLayer) + // gamesensor->RegisterToManager(); for (int i=0;i<sens->totlinks;i++) diff --git a/source/gameengine/Converter/KX_IpoConvert.cpp b/source/gameengine/Converter/KX_IpoConvert.cpp index 75ca59d01e7..7410beecaf4 100644 --- a/source/gameengine/Converter/KX_IpoConvert.cpp +++ b/source/gameengine/Converter/KX_IpoConvert.cpp @@ -36,6 +36,7 @@ #pragma warning (disable:4786) #endif +#include "BKE_material.h" /* give_current_material */ #include "KX_GameObject.h" #include "KX_IpoConvert.h" @@ -68,6 +69,8 @@ #include "SG_Node.h" +#include "STR_HashedString.h" + static BL_InterpolatorList *GetIpoList(struct Ipo *for_ipo, KX_BlenderSceneConverter *converter) { BL_InterpolatorList *ipoList= converter->FindInterpolatorList(for_ipo); @@ -560,16 +563,15 @@ void BL_ConvertWorldIpos(struct World* blenderworld,KX_BlenderSceneConverter *co } } - -void BL_ConvertMaterialIpos( - Material* blendermaterial, +static void ConvertMaterialIpos( + Material* blendermaterial, + dword matname_hash, KX_GameObject* gameobj, KX_BlenderSceneConverter *converter ) { if (blendermaterial->ipo) { - - KX_MaterialIpoController* ipocontr = new KX_MaterialIpoController(); + KX_MaterialIpoController* ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); @@ -596,7 +598,7 @@ void BL_ConvertMaterialIpos( ipo = ipoList->GetScalarInterpolator(MA_COL_R); if (ipo) { if (!ipocontr) { - ipocontr = new KX_MaterialIpoController(); + ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); } @@ -610,7 +612,7 @@ void BL_ConvertMaterialIpos( ipo = ipoList->GetScalarInterpolator(MA_COL_G); if (ipo) { if (!ipocontr) { - ipocontr = new KX_MaterialIpoController(); + ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); } @@ -624,7 +626,7 @@ void BL_ConvertMaterialIpos( ipo = ipoList->GetScalarInterpolator(MA_COL_B); if (ipo) { if (!ipocontr) { - ipocontr = new KX_MaterialIpoController(); + ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); } @@ -638,7 +640,7 @@ void BL_ConvertMaterialIpos( ipo = ipoList->GetScalarInterpolator(MA_ALPHA); if (ipo) { if (!ipocontr) { - ipocontr = new KX_MaterialIpoController(); + ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); } @@ -653,7 +655,7 @@ void BL_ConvertMaterialIpos( ipo = ipoList->GetScalarInterpolator(MA_SPEC_R ); if (ipo) { if (!ipocontr) { - ipocontr = new KX_MaterialIpoController(); + ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); } @@ -667,7 +669,7 @@ void BL_ConvertMaterialIpos( ipo = ipoList->GetScalarInterpolator(MA_SPEC_G); if (ipo) { if (!ipocontr) { - ipocontr = new KX_MaterialIpoController(); + ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); } @@ -681,7 +683,7 @@ void BL_ConvertMaterialIpos( ipo = ipoList->GetScalarInterpolator(MA_SPEC_B); if (ipo) { if (!ipocontr) { - ipocontr = new KX_MaterialIpoController(); + ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); } @@ -696,7 +698,7 @@ void BL_ConvertMaterialIpos( ipo = ipoList->GetScalarInterpolator(MA_HARD); if (ipo) { if (!ipocontr) { - ipocontr = new KX_MaterialIpoController(); + ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); } @@ -710,7 +712,7 @@ void BL_ConvertMaterialIpos( ipo = ipoList->GetScalarInterpolator(MA_SPEC); if (ipo) { if (!ipocontr) { - ipocontr = new KX_MaterialIpoController(); + ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); } @@ -725,7 +727,7 @@ void BL_ConvertMaterialIpos( ipo = ipoList->GetScalarInterpolator(MA_REF); if (ipo) { if (!ipocontr) { - ipocontr = new KX_MaterialIpoController(); + ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); } @@ -739,7 +741,7 @@ void BL_ConvertMaterialIpos( ipo = ipoList->GetScalarInterpolator(MA_EMIT); if (ipo) { if (!ipocontr) { - ipocontr = new KX_MaterialIpoController(); + ipocontr = new KX_MaterialIpoController(matname_hash); gameobj->GetSGNode()->AddSGController(ipocontr); ipocontr->SetObject(gameobj->GetSGNode()); } @@ -752,3 +754,28 @@ void BL_ConvertMaterialIpos( } } +void BL_ConvertMaterialIpos( + struct Object* blenderobject, + KX_GameObject* gameobj, + KX_BlenderSceneConverter *converter + ) +{ + if (blenderobject->totcol==1) + { + Material *mat = give_current_material(blenderobject, 1); + // if there is only one material attached to the mesh then set material_index in BL_ConvertMaterialIpos to NULL + // --> this makes the UpdateMaterialData function in KX_GameObject.cpp use the old hack of using SetObjectColor + // because this yields a better performance as not all the vertex colors need to be edited + if(mat) ConvertMaterialIpos(mat, NULL, gameobj, converter); + } + else + { + for (int material_index=1; material_index <= blenderobject->totcol; material_index++) + { + Material *mat = give_current_material(blenderobject, material_index); + STR_HashedString matname = mat->id.name; + if(mat) ConvertMaterialIpos(mat, matname.hash(), gameobj, converter); + } + } +} + diff --git a/source/gameengine/Converter/KX_IpoConvert.h b/source/gameengine/Converter/KX_IpoConvert.h index afcb1b22821..4ec9bd31062 100644 --- a/source/gameengine/Converter/KX_IpoConvert.h +++ b/source/gameengine/Converter/KX_IpoConvert.h @@ -46,7 +46,7 @@ void BL_ConvertCameraIpos(struct Camera* blendercamera, class KX_GameObject* cameraobj, class KX_BlenderSceneConverter *converter); -void BL_ConvertMaterialIpos(struct Material* blendermaterial, +void BL_ConvertMaterialIpos(struct Object* blenderobject, class KX_GameObject* materialobj, class KX_BlenderSceneConverter *converter); diff --git a/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp b/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp index 28ca1fd673f..9a47c262889 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp @@ -1,5 +1,5 @@ /** - * $Id$ + * $Id:SCA_ActuatorEventManager.cpp 15567 2008-07-14 14:09:36Z theeth $ * ***** BEGIN GPL LICENSE BLOCK ***** * * This program is free software; you can redistribute it and/or @@ -48,19 +48,10 @@ SCA_ActuatorEventManager::~SCA_ActuatorEventManager() } - - -void SCA_ActuatorEventManager::RegisterSensor(SCA_ISensor* sensor) -{ - m_sensors.push_back(sensor); -} - - - void SCA_ActuatorEventManager::NextFrame() { // check for changed actuator - for (vector<SCA_ISensor*>::const_iterator it = m_sensors.begin();!(it==m_sensors.end());it++) + for (set<SCA_ISensor*>::const_iterator it = m_sensors.begin();!(it==m_sensors.end());it++) { (*it)->Activate(m_logicmgr,NULL); } @@ -69,7 +60,7 @@ void SCA_ActuatorEventManager::NextFrame() void SCA_ActuatorEventManager::UpdateFrame() { // update the state of actuator before executing them - for (vector<SCA_ISensor*>::const_iterator it = m_sensors.begin();!(it==m_sensors.end());it++) + for (set<SCA_ISensor*>::const_iterator it = m_sensors.begin();!(it==m_sensors.end());it++) { ((SCA_ActuatorSensor*)(*it))->Update(); } diff --git a/source/gameengine/GameLogic/SCA_ActuatorEventManager.h b/source/gameengine/GameLogic/SCA_ActuatorEventManager.h index b5108764197..6454decfc62 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorEventManager.h +++ b/source/gameengine/GameLogic/SCA_ActuatorEventManager.h @@ -1,5 +1,5 @@ /** - * $Id$ + * $Id:SCA_ActuatorEventManager.h 15567 2008-07-14 14:09:36Z theeth $ * * ***** BEGIN GPL LICENSE BLOCK ***** * @@ -44,7 +44,6 @@ public: virtual ~SCA_ActuatorEventManager(); virtual void NextFrame(); virtual void UpdateFrame(); - virtual void RegisterSensor(SCA_ISensor* sensor); //SCA_LogicManager* GetLogicManager() { return m_logicmgr;} }; diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp index e1c8ef87dd1..8bba37d045a 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp @@ -1,7 +1,7 @@ /** * Actuator sensor * - * $Id$ + * $Id:SCA_ActuatorSensor.cpp 15567 2008-07-14 14:09:36Z theeth $ * * ***** BEGIN GPL LICENSE BLOCK ***** * @@ -149,7 +149,7 @@ PyParentObject SCA_ActuatorSensor::Parents[] = { }; PyMethodDef SCA_ActuatorSensor::Methods[] = { - {"getActuator", (PyCFunction) SCA_ActuatorSensor::sPyGetActuator, METH_VARARGS, GetActuator_doc}, + {"getActuator", (PyCFunction) SCA_ActuatorSensor::sPyGetActuator, METH_NOARGS, GetActuator_doc}, {"setActuator", (PyCFunction) SCA_ActuatorSensor::sPySetActuator, METH_VARARGS, SetActuator_doc}, {NULL,NULL} //Sentinel }; @@ -162,7 +162,7 @@ PyObject* SCA_ActuatorSensor::_getattr(const STR_String& attr) { char SCA_ActuatorSensor::GetActuator_doc[] = "getActuator()\n" "\tReturn the Actuator with which the sensor operates.\n"; -PyObject* SCA_ActuatorSensor::PyGetActuator(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_ActuatorSensor::PyGetActuator(PyObject* self) { return PyString_FromString(m_checkactname); } @@ -180,6 +180,7 @@ PyObject* SCA_ActuatorSensor::PySetActuator(PyObject* self, PyObject* args, PyOb char *actNameArg = NULL; if (!PyArg_ParseTuple(args, "s", &actNameArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.h b/source/gameengine/GameLogic/SCA_ActuatorSensor.h index 6086c5bfce0..568e7158af2 100644 --- a/source/gameengine/GameLogic/SCA_ActuatorSensor.h +++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.h @@ -1,7 +1,7 @@ /** * Actuator sensor * - * $Id$ + * $Id:SCA_ActuatorSensor.h 15567 2008-07-14 14:09:36Z theeth $ * * ***** BEGIN GPL LICENSE BLOCK ***** * @@ -66,7 +66,7 @@ public: /* 3. setProperty */ KX_PYMETHOD_DOC(SCA_ActuatorSensor,SetActuator); /* 4. getProperty */ - KX_PYMETHOD_DOC(SCA_ActuatorSensor,GetActuator); + KX_PYMETHOD_DOC_NOARGS(SCA_ActuatorSensor,GetActuator); }; diff --git a/source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp b/source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp index ab3bc2cc4ee..4cd2dfba994 100644 --- a/source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp +++ b/source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp @@ -51,16 +51,9 @@ SCA_AlwaysEventManager::SCA_AlwaysEventManager(class SCA_LogicManager* logicmgr) void SCA_AlwaysEventManager::NextFrame() { - for (vector<class SCA_ISensor*>::const_iterator i= m_sensors.begin();!(i==m_sensors.end());i++) + for (set<class SCA_ISensor*>::const_iterator i= m_sensors.begin();!(i==m_sensors.end());i++) { - SCA_ISensor* sensor = *i; - sensor->Activate(m_logicmgr, NULL); + (*i)->Activate(m_logicmgr, NULL); } } - - -void SCA_AlwaysEventManager::RegisterSensor(SCA_ISensor* sensor) -{ - m_sensors.push_back(sensor); -} diff --git a/source/gameengine/GameLogic/SCA_AlwaysEventManager.h b/source/gameengine/GameLogic/SCA_AlwaysEventManager.h index 28c71512875..a619eecddd4 100644 --- a/source/gameengine/GameLogic/SCA_AlwaysEventManager.h +++ b/source/gameengine/GameLogic/SCA_AlwaysEventManager.h @@ -39,7 +39,6 @@ class SCA_AlwaysEventManager : public SCA_EventManager public: SCA_AlwaysEventManager(class SCA_LogicManager* logicmgr); virtual void NextFrame(); - virtual void RegisterSensor(SCA_ISensor* sensor); }; diff --git a/source/gameengine/GameLogic/SCA_EventManager.cpp b/source/gameengine/GameLogic/SCA_EventManager.cpp index 0169864a133..e4fd0379597 100644 --- a/source/gameengine/GameLogic/SCA_EventManager.cpp +++ b/source/gameengine/GameLogic/SCA_EventManager.cpp @@ -45,17 +45,14 @@ SCA_EventManager::~SCA_EventManager() { } - +void SCA_EventManager::RegisterSensor(class SCA_ISensor* sensor) +{ + m_sensors.insert(sensor); +} void SCA_EventManager::RemoveSensor(class SCA_ISensor* sensor) { - std::vector<SCA_ISensor*>::iterator i = - std::find(m_sensors.begin(), m_sensors.end(), sensor); - if (!(i == m_sensors.end())) - { - std::swap(*i, m_sensors.back()); - m_sensors.pop_back(); - } + m_sensors.erase(sensor); } void SCA_EventManager::NextFrame(double curtime, double fixedtime) diff --git a/source/gameengine/GameLogic/SCA_EventManager.h b/source/gameengine/GameLogic/SCA_EventManager.h index 9cc1718cd1e..9dbb5a6d24f 100644 --- a/source/gameengine/GameLogic/SCA_EventManager.h +++ b/source/gameengine/GameLogic/SCA_EventManager.h @@ -30,12 +30,14 @@ #define __KX_EVENTMANAGER #include <vector> +#include <set> #include <algorithm> class SCA_EventManager { protected: - std::vector <class SCA_ISensor*> m_sensors; + // use a set to speed-up insertion/removal + std::set <class SCA_ISensor*> m_sensors; public: enum EVENT_MANAGER_TYPE { @@ -61,7 +63,7 @@ public: virtual void NextFrame(); virtual void UpdateFrame(); virtual void EndFrame(); - virtual void RegisterSensor(class SCA_ISensor* sensor)=0; + virtual void RegisterSensor(class SCA_ISensor* sensor); int GetType(); protected: diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index f6efd485adb..e73358bc1e8 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -82,7 +82,10 @@ void SCA_ILogicBrick::ReParent(SCA_IObject* parent) m_gameobj = parent; } - +void SCA_ILogicBrick::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + // nothing to do +} CValue* SCA_ILogicBrick::Calc(VALUE_OPERATOR op, CValue *val) { diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index 80bc6ae3b86..c28711ac0f6 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -32,6 +32,8 @@ #include "Value.h" #include "SCA_IObject.h" #include "BoolValue.h" +#include "GEN_Map.h" +#include "GEN_HashedPtr.h" class SCA_ILogicBrick : public CValue { @@ -59,6 +61,7 @@ public: SCA_IObject* GetParent(); virtual void ReParent(SCA_IObject* parent); + virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); // act as a BoolValue (with value IsPositiveTrigger) virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp index c5bb4a41552..b0f8decee26 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -306,7 +306,7 @@ const MT_Point3& SCA_IObject::ConvertPythonPylist(PyObject* pylist) } #endif -void SCA_IObject::Suspend(void) +void SCA_IObject::Suspend() { if ((!m_ignore_activity_culling) && (!m_suspended)) { @@ -337,12 +337,31 @@ void SCA_IObject::Resume(void) void SCA_IObject::SetState(unsigned int state) { - m_state = state; - // update the status of the controllers + unsigned int tmpstate; SCA_ControllerList::iterator contit; - for (contit = m_controllers.begin(); contit != m_controllers.end(); contit++) + + // we will update the state in two steps: + // 1) set the new state bits that are 1 + // 2) clr the new state bits that are 0 + // This to ensure continuity if a sensor is attached to two states + // that are switching state: no need to deactive and reactive the sensor + + tmpstate = m_state | state; + if (tmpstate != m_state) + { + // update the status of the controllers + for (contit = m_controllers.begin(); contit != m_controllers.end(); contit++) + { + (*contit)->ApplyState(tmpstate); + } + } + m_state = state; + if (m_state != tmpstate) { - (*contit)->ApplyState(m_state); + for (contit = m_controllers.begin(); contit != m_controllers.end(); contit++) + { + (*contit)->ApplyState(m_state); + } } } diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index 68341b57435..2dc49924062 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -41,7 +41,8 @@ void SCA_ISensor::ReParent(SCA_IObject* parent) { SCA_ILogicBrick::ReParent(parent); - m_eventmgr->RegisterSensor(this); + // will be done when the sensor is activated + //m_eventmgr->RegisterSensor(this); this->SetActive(false); } @@ -133,6 +134,7 @@ void SCA_ISensor::DecLink() { { // sensor is detached from all controllers, initialize it so that it // is fresh as at startup when it is reattached again. + UnregisterToManager(); Init(); } } @@ -168,23 +170,23 @@ PyMethodDef SCA_ISensor::Methods[] = { {"isPositive", (PyCFunction) SCA_ISensor::sPyIsPositive, METH_VARARGS, IsPositive_doc}, {"getUsePosPulseMode", (PyCFunction) SCA_ISensor::sPyGetUsePosPulseMode, - METH_VARARGS, GetUsePosPulseMode_doc}, + METH_NOARGS, GetUsePosPulseMode_doc}, {"setUsePosPulseMode", (PyCFunction) SCA_ISensor::sPySetUsePosPulseMode, METH_VARARGS, SetUsePosPulseMode_doc}, {"getFrequency", (PyCFunction) SCA_ISensor::sPyGetFrequency, - METH_VARARGS, GetFrequency_doc}, + METH_NOARGS, GetFrequency_doc}, {"setFrequency", (PyCFunction) SCA_ISensor::sPySetFrequency, METH_VARARGS, SetFrequency_doc}, {"getUseNegPulseMode", (PyCFunction) SCA_ISensor::sPyGetUseNegPulseMode, - METH_VARARGS, GetUseNegPulseMode_doc}, + METH_NOARGS, GetUseNegPulseMode_doc}, {"setUseNegPulseMode", (PyCFunction) SCA_ISensor::sPySetUseNegPulseMode, METH_VARARGS, SetUseNegPulseMode_doc}, {"getInvert", (PyCFunction) SCA_ISensor::sPyGetInvert, - METH_VARARGS, GetInvert_doc}, + METH_NOARGS, GetInvert_doc}, {"setInvert", (PyCFunction) SCA_ISensor::sPySetInvert, METH_VARARGS, SetInvert_doc}, {"getLevel", (PyCFunction) SCA_ISensor::sPyGetLevel, - METH_VARARGS, GetLevel_doc}, + METH_NOARGS, GetLevel_doc}, {"setLevel", (PyCFunction) SCA_ISensor::sPySetLevel, METH_VARARGS, SetLevel_doc}, {NULL,NULL} //Sentinel @@ -203,6 +205,11 @@ void SCA_ISensor::RegisterToManager() m_eventmgr->RegisterSensor(this); } +void SCA_ISensor::UnregisterToManager() +{ + m_eventmgr->RemoveSensor(this); +} + void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr, CValue* event) { @@ -259,7 +266,7 @@ PyObject* SCA_ISensor::PyIsPositive(PyObject* self, PyObject* args, PyObject* kw char SCA_ISensor::GetUsePosPulseMode_doc[] = "getUsePosPulseMode()\n" "\tReturns whether positive pulse mode is active.\n"; -PyObject* SCA_ISensor::PyGetUsePosPulseMode(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_ISensor::PyGetUsePosPulseMode(PyObject* self) { return BoolToPyArg(m_pos_pulsemode); } @@ -286,7 +293,7 @@ PyObject* SCA_ISensor::PySetUsePosPulseMode(PyObject* self, PyObject* args, PyOb char SCA_ISensor::GetFrequency_doc[] = "getFrequency()\n" "\tReturns the frequency of the updates in pulse mode.\n" ; -PyObject* SCA_ISensor::PyGetFrequency(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_ISensor::PyGetFrequency(PyObject* self) { return PyInt_FromLong(m_pulse_frequency); } @@ -321,7 +328,7 @@ PyObject* SCA_ISensor::PySetFrequency(PyObject* self, PyObject* args, PyObject* char SCA_ISensor::GetInvert_doc[] = "getInvert()\n" "\tReturns whether or not pulses from this sensor are inverted.\n" ; -PyObject* SCA_ISensor::PyGetInvert(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_ISensor::PyGetInvert(PyObject* self) { return BoolToPyArg(m_invert); } @@ -342,11 +349,10 @@ char SCA_ISensor::GetLevel_doc[] = "getLevel()\n" "\tReturns whether this sensor is a level detector or a edge detector.\n" "\tIt makes a difference only in case of logic state transition (state actuator).\n" -"\tA level detector will immediately generate a pulse if the condition for the\n" -"\tdetector is met when entering the state. A edge detector will wait for an off-on\n" -"\ttransition to occur.\n" -"\tOnly some sensors implement this feature: keyboard.\n"; -PyObject* SCA_ISensor::PyGetLevel(PyObject* self, PyObject* args, PyObject* kwds) +"\tA level detector will immediately generate a pulse, negative or positive\n" +"\tdepending on the sensor condition, as soon as the state is activated.\n" +"\tA edge detector will wait for a state change before generating a pulse.\n"; +PyObject* SCA_ISensor::PyGetLevel(PyObject* self) { return BoolToPyArg(m_level); } @@ -366,7 +372,7 @@ PyObject* SCA_ISensor::PySetLevel(PyObject* self, PyObject* args, PyObject* kwds char SCA_ISensor::GetUseNegPulseMode_doc[] = "getUseNegPulseMode()\n" "\tReturns whether negative pulse mode is active.\n"; -PyObject* SCA_ISensor::PyGetUseNegPulseMode(PyObject* self, PyObject* args, PyObject* kwds) +PyObject* SCA_ISensor::PyGetUseNegPulseMode(PyObject* self) { return BoolToPyArg(m_neg_pulsemode); } diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index 4ce49e71507..d5dabbce3ee 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -115,6 +115,8 @@ public: void SetLevel(bool lvl); void RegisterToManager(); + void UnregisterToManager(); + virtual float GetNumber(); /** Stop sensing for a while. */ @@ -129,22 +131,22 @@ public: void ClrLink() { m_links = 0; } void IncLink() - { m_links++; } + { if (!m_links++) RegisterToManager(); } void DecLink(); bool IsNoLink() const { return !m_links; } /* Python functions: */ KX_PYMETHOD_DOC(SCA_ISensor,IsPositive); - KX_PYMETHOD_DOC(SCA_ISensor,GetUsePosPulseMode); + KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetUsePosPulseMode); KX_PYMETHOD_DOC(SCA_ISensor,SetUsePosPulseMode); - KX_PYMETHOD_DOC(SCA_ISensor,GetFrequency); + KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetFrequency); KX_PYMETHOD_DOC(SCA_ISensor,SetFrequency); - KX_PYMETHOD_DOC(SCA_ISensor,GetUseNegPulseMode); + KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetUseNegPulseMode); KX_PYMETHOD_DOC(SCA_ISensor,SetUseNegPulseMode); - KX_PYMETHOD_DOC(SCA_ISensor,GetInvert); + KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetInvert); KX_PYMETHOD_DOC(SCA_ISensor,SetInvert); - KX_PYMETHOD_DOC(SCA_ISensor,GetLevel); + KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,GetLevel); KX_PYMETHOD_DOC(SCA_ISensor,SetLevel); }; diff --git a/source/gameengine/GameLogic/SCA_JoystickManager.cpp b/source/gameengine/GameLogic/SCA_JoystickManager.cpp index 7bf2049e56e..8ff28ba0b51 100644 --- a/source/gameengine/GameLogic/SCA_JoystickManager.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickManager.cpp @@ -52,9 +52,10 @@ SCA_JoystickManager::~SCA_JoystickManager() void SCA_JoystickManager::NextFrame(double curtime,double deltatime) { - for (unsigned int i = 0; i < m_sensors.size(); i++) + set<SCA_ISensor*>::iterator it; + for (it = m_sensors.begin(); it != m_sensors.end(); it++) { - SCA_JoystickSensor* joysensor = (SCA_JoystickSensor*) m_sensors[i]; + SCA_JoystickSensor* joysensor = (SCA_JoystickSensor*)(*it); if(!joysensor->IsSuspended()) { m_joystick->HandleEvents(); @@ -64,12 +65,6 @@ void SCA_JoystickManager::NextFrame(double curtime,double deltatime) } -void SCA_JoystickManager::RegisterSensor(SCA_ISensor* sensor) -{ - m_sensors.push_back(sensor); -} - - SCA_Joystick *SCA_JoystickManager::GetJoystickDevice() { /* diff --git a/source/gameengine/GameLogic/SCA_JoystickManager.h b/source/gameengine/GameLogic/SCA_JoystickManager.h index 3c4df64677e..f2bb27965fa 100644 --- a/source/gameengine/GameLogic/SCA_JoystickManager.h +++ b/source/gameengine/GameLogic/SCA_JoystickManager.h @@ -45,7 +45,6 @@ public: SCA_JoystickManager(class SCA_LogicManager* logicmgr); virtual ~SCA_JoystickManager(); virtual void NextFrame(double curtime,double deltatime); - virtual void RegisterSensor(SCA_ISensor* sensor); SCA_Joystick* GetJoystickDevice(void); }; diff --git a/source/gameengine/GameLogic/SCA_KeyboardManager.cpp b/source/gameengine/GameLogic/SCA_KeyboardManager.cpp index 259b06134d7..6a96442b124 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardManager.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardManager.cpp @@ -62,23 +62,14 @@ void SCA_KeyboardManager::NextFrame() { //const SCA_InputEvent& event = GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)=0; // cerr << "SCA_KeyboardManager::NextFrame"<< endl; - for (unsigned int i=0;i<m_sensors.size();i++) + set<SCA_ISensor*>::iterator it; + for (it=m_sensors.begin(); it != m_sensors.end(); it++) { - SCA_KeyboardSensor* keysensor = (SCA_KeyboardSensor*)m_sensors[i]; - keysensor->Activate(m_logicmanager,NULL); + (*it)->Activate(m_logicmanager,NULL); } } - - -void SCA_KeyboardManager::RegisterSensor(SCA_ISensor* keysensor) -{ - m_sensors.push_back(keysensor); -} - - - bool SCA_KeyboardManager::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode) { return false; diff --git a/source/gameengine/GameLogic/SCA_KeyboardManager.h b/source/gameengine/GameLogic/SCA_KeyboardManager.h index b4a50f56025..8f3cc0ab715 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardManager.h +++ b/source/gameengine/GameLogic/SCA_KeyboardManager.h @@ -55,7 +55,6 @@ public: bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode); virtual void NextFrame(); - virtual void RegisterSensor(class SCA_ISensor* sensor); SCA_IInputDevice* GetInputDevice(); }; diff --git a/source/gameengine/GameLogic/SCA_LogicManager.cpp b/source/gameengine/GameLogic/SCA_LogicManager.cpp index f50161cbecb..91e66aea359 100644 --- a/source/gameengine/GameLogic/SCA_LogicManager.cpp +++ b/source/gameengine/GameLogic/SCA_LogicManager.cpp @@ -127,12 +127,17 @@ void SCA_LogicManager::RegisterGameMeshName(const STR_String& gamemeshname, void -void SCA_LogicManager::RegisterGameObj(CValue* gameobj, void* blendobj) +void SCA_LogicManager::RegisterGameObj(void* blendobj, CValue* gameobj) { - m_map_gameobj_to_blendobj.insert(CHashedPtr(gameobj), blendobj); + m_map_blendobj_to_gameobj.insert(CHashedPtr(blendobj), gameobj); } - +void SCA_LogicManager::UnregisterGameObj(void* blendobj, CValue* gameobj) +{ + void **obp = m_map_blendobj_to_gameobj[CHashedPtr(blendobj)]; + if (obp && (CValue*)(*obp) == gameobj) + m_map_blendobj_to_gameobj.remove(CHashedPtr(blendobj)); +} CValue* SCA_LogicManager::GetGameObjectByName(const STR_String& gameobjname) { @@ -146,10 +151,10 @@ CValue* SCA_LogicManager::GetGameObjectByName(const STR_String& gameobjname) } -void* SCA_LogicManager::FindBlendObjByGameObj(CValue* gameobject) +CValue* SCA_LogicManager::FindGameObjByBlendObj(void* blendobj) { - void **obp= m_map_gameobj_to_blendobj[CHashedPtr(gameobject)]; - return obp?*obp:NULL; + void **obp= m_map_blendobj_to_gameobj[CHashedPtr(blendobj)]; + return obp?(CValue*)(*obp):NULL; } @@ -171,12 +176,7 @@ void SCA_LogicManager::RemoveSensor(SCA_ISensor* sensor) (*c)->UnlinkSensor(sensor); } m_sensorcontrollermapje.erase(sensor); - - for (vector<SCA_EventManager*>::const_iterator ie=m_eventmanagers.begin(); - !(ie==m_eventmanagers.end());ie++) - { - (*ie)->RemoveSensor(sensor); - } + sensor->UnregisterToManager(); } void SCA_LogicManager::RemoveController(SCA_IController* controller) diff --git a/source/gameengine/GameLogic/SCA_LogicManager.h b/source/gameengine/GameLogic/SCA_LogicManager.h index 39d8b865977..e0d3d506702 100644 --- a/source/gameengine/GameLogic/SCA_LogicManager.h +++ b/source/gameengine/GameLogic/SCA_LogicManager.h @@ -109,7 +109,7 @@ class SCA_LogicManager GEN_Map<STR_HashedString,void*> m_mapStringToActions; GEN_Map<STR_HashedString,void*> m_map_gamemeshname_to_blendobj; - GEN_Map<CHashedPtr,void*> m_map_gameobj_to_blendobj; + GEN_Map<CHashedPtr,void*> m_map_blendobj_to_gameobj; vector<SmartActuatorPtr> m_removedActuators; public: @@ -152,8 +152,9 @@ public: void RegisterGameMeshName(const STR_String& gamemeshname, void* blendobj); void* FindBlendObjByGameMeshName(const STR_String& gamemeshname); - void RegisterGameObj(CValue* gameobj, void* blendobj); - void* FindBlendObjByGameObj(CValue* gameobj); + void RegisterGameObj(void* blendobj, CValue* gameobj); + void UnregisterGameObj(void* blendobj, CValue* gameobj); + CValue* FindGameObjByBlendObj(void* blendobj); }; #endif //__KX_LOGICMANAGER diff --git a/source/gameengine/GameLogic/SCA_MouseManager.cpp b/source/gameengine/GameLogic/SCA_MouseManager.cpp index b4251d8ab53..ca875dad07c 100644 --- a/source/gameengine/GameLogic/SCA_MouseManager.cpp +++ b/source/gameengine/GameLogic/SCA_MouseManager.cpp @@ -75,9 +75,10 @@ void SCA_MouseManager::NextFrame() { if (m_mousedevice) { - for (unsigned int i = 0; i < m_sensors.size(); i++) + set<SCA_ISensor*>::iterator it; + for (it=m_sensors.begin(); it!=m_sensors.end(); it++) { - SCA_MouseSensor* mousesensor = (SCA_MouseSensor*) m_sensors[i]; + SCA_MouseSensor* mousesensor = (SCA_MouseSensor*)(*it); // (0,0) is the Upper Left corner in our local window // coordinates if (!mousesensor->IsSuspended()) @@ -98,15 +99,6 @@ void SCA_MouseManager::NextFrame() } } - - -void SCA_MouseManager::RegisterSensor(SCA_ISensor* keysensor) -{ - m_sensors.push_back(keysensor); -} - - - bool SCA_MouseManager::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode) { /* We should guard for non-mouse events maybe? A rather silly side */ diff --git a/source/gameengine/GameLogic/SCA_MouseManager.h b/source/gameengine/GameLogic/SCA_MouseManager.h index bc8254486ad..efa4c639ce7 100644 --- a/source/gameengine/GameLogic/SCA_MouseManager.h +++ b/source/gameengine/GameLogic/SCA_MouseManager.h @@ -62,7 +62,6 @@ public: */ bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode); virtual void NextFrame(); - virtual void RegisterSensor(class SCA_ISensor* sensor); SCA_IInputDevice* GetInputDevice(); }; diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp index ebe1cd51863..7062f2cef6a 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp @@ -42,7 +42,7 @@ /* Native functions */ /* ------------------------------------------------------------------------- */ -SCA_PropertyActuator::SCA_PropertyActuator(SCA_IObject* gameobj,CValue* sourceObj,const STR_String& propname,const STR_String& expr,int acttype,PyTypeObject* T ) +SCA_PropertyActuator::SCA_PropertyActuator(SCA_IObject* gameobj,SCA_IObject* sourceObj,const STR_String& propname,const STR_String& expr,int acttype,PyTypeObject* T ) : SCA_IActuator(gameobj,T), m_type(acttype), m_propname(propname), @@ -51,14 +51,14 @@ SCA_PropertyActuator::SCA_PropertyActuator(SCA_IObject* gameobj,CValue* sourceOb { // protect ourselves against someone else deleting the source object // don't protect against ourselves: it would create a dead lock - if (m_sourceObj && m_sourceObj != GetParent()) - m_sourceObj->AddRef(); + if (m_sourceObj) + m_sourceObj->RegisterActuator(this); } SCA_PropertyActuator::~SCA_PropertyActuator() { - if (m_sourceObj && m_sourceObj != GetParent()) - m_sourceObj->Release(); + if (m_sourceObj) + m_sourceObj->UnregisterActuator(this); } bool SCA_PropertyActuator::Update() @@ -185,10 +185,31 @@ void SCA_PropertyActuator::ProcessReplica() // no need to check for self reference like in the constructor: // the replica will always have a different parent if (m_sourceObj) - m_sourceObj->AddRef(); + m_sourceObj->RegisterActuator(this); SCA_IActuator::ProcessReplica(); } +bool SCA_PropertyActuator::UnlinkObject(SCA_IObject* clientobj) +{ + if (clientobj == m_sourceObj) + { + // this object is being deleted, we cannot continue to track it. + m_sourceObj = NULL; + return true; + } + return false; +} + +void SCA_PropertyActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + void **h_obj = (*obj_map)[m_sourceObj]; + if (h_obj) { + if (m_sourceObj) + m_sourceObj->UnregisterActuator(this); + m_sourceObj = (SCA_IObject*)(*h_obj); + m_sourceObj->RegisterActuator(this); + } +} /* ------------------------------------------------------------------------- */ diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.h b/source/gameengine/GameLogic/SCA_PropertyActuator.h index f8305901c51..1e435684572 100644 --- a/source/gameengine/GameLogic/SCA_PropertyActuator.h +++ b/source/gameengine/GameLogic/SCA_PropertyActuator.h @@ -52,7 +52,7 @@ class SCA_PropertyActuator : public SCA_IActuator int m_type; STR_String m_propname; STR_String m_exprtxt; - CValue* m_sourceObj; // for copy property actuator + SCA_IObject* m_sourceObj; // for copy property actuator public: @@ -60,7 +60,7 @@ public: SCA_PropertyActuator( SCA_IObject* gameobj, - CValue* sourceObj, + SCA_IObject* sourceObj, const STR_String& propname, const STR_String& expr, int acttype, @@ -74,7 +74,9 @@ public: GetReplica( ); - void ProcessReplica(); + virtual void ProcessReplica(); + virtual bool UnlinkObject(SCA_IObject* clientobj); + virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); virtual bool Update(); diff --git a/source/gameengine/GameLogic/SCA_PropertyEventManager.cpp b/source/gameengine/GameLogic/SCA_PropertyEventManager.cpp index fc56d101728..e5e3f9cced5 100644 --- a/source/gameengine/GameLogic/SCA_PropertyEventManager.cpp +++ b/source/gameengine/GameLogic/SCA_PropertyEventManager.cpp @@ -47,19 +47,10 @@ SCA_PropertyEventManager::~SCA_PropertyEventManager() } - - -void SCA_PropertyEventManager::RegisterSensor(SCA_ISensor* sensor) -{ - m_sensors.push_back(sensor); -} - - - void SCA_PropertyEventManager::NextFrame() { // check for changed properties - for (vector<SCA_ISensor*>::const_iterator it = m_sensors.begin();!(it==m_sensors.end());it++) + for (set<SCA_ISensor*>::const_iterator it = m_sensors.begin();!(it==m_sensors.end());it++) { (*it)->Activate(m_logicmgr,NULL); } diff --git a/source/gameengine/GameLogic/SCA_PropertyEventManager.h b/source/gameengine/GameLogic/SCA_PropertyEventManager.h index aaa303a52c8..f166065b198 100644 --- a/source/gameengine/GameLogic/SCA_PropertyEventManager.h +++ b/source/gameengine/GameLogic/SCA_PropertyEventManager.h @@ -43,7 +43,6 @@ public: SCA_PropertyEventManager(class SCA_LogicManager* logicmgr); virtual ~SCA_PropertyEventManager(); virtual void NextFrame(); - virtual void RegisterSensor(SCA_ISensor* sensor); //SCA_LogicManager* GetLogicManager() { return m_logicmgr;} }; diff --git a/source/gameengine/GameLogic/SCA_RandomEventManager.cpp b/source/gameengine/GameLogic/SCA_RandomEventManager.cpp index 02020a52a17..156478d866d 100644 --- a/source/gameengine/GameLogic/SCA_RandomEventManager.cpp +++ b/source/gameengine/GameLogic/SCA_RandomEventManager.cpp @@ -50,16 +50,9 @@ SCA_RandomEventManager::SCA_RandomEventManager(class SCA_LogicManager* logicmgr) void SCA_RandomEventManager::NextFrame() { - for (vector<class SCA_ISensor*>::const_iterator i= m_sensors.begin();!(i==m_sensors.end());i++) + for (set<class SCA_ISensor*>::const_iterator i= m_sensors.begin();!(i==m_sensors.end());i++) { - SCA_ISensor *sensor = *i; - sensor->Activate(m_logicmgr, NULL); + (*i)->Activate(m_logicmgr, NULL); } } - - -void SCA_RandomEventManager::RegisterSensor(SCA_ISensor* sensor) -{ - m_sensors.push_back(sensor); -}; diff --git a/source/gameengine/GameLogic/SCA_RandomEventManager.h b/source/gameengine/GameLogic/SCA_RandomEventManager.h index 8c75ef665fa..79138c23c62 100644 --- a/source/gameengine/GameLogic/SCA_RandomEventManager.h +++ b/source/gameengine/GameLogic/SCA_RandomEventManager.h @@ -45,7 +45,6 @@ public: SCA_RandomEventManager(class SCA_LogicManager* logicmgr); virtual void NextFrame(); - virtual void RegisterSensor(SCA_ISensor* sensor); }; #endif //__KX_RANDOMEVENTMGR diff --git a/source/gameengine/GameLogic/SCA_TimeEventManager.cpp b/source/gameengine/GameLogic/SCA_TimeEventManager.cpp index 643f1247a52..b7fadd3d62c 100644 --- a/source/gameengine/GameLogic/SCA_TimeEventManager.cpp +++ b/source/gameengine/GameLogic/SCA_TimeEventManager.cpp @@ -65,6 +65,11 @@ void SCA_TimeEventManager::RegisterSensor(SCA_ISensor* sensor) // not yet } +void SCA_TimeEventManager::RemoveSensor(SCA_ISensor* sensor) +{ + // empty +} + void SCA_TimeEventManager::NextFrame(double curtime, double fixedtime) diff --git a/source/gameengine/GameLogic/SCA_TimeEventManager.h b/source/gameengine/GameLogic/SCA_TimeEventManager.h index 2fd39661a2d..bd57e12eb44 100644 --- a/source/gameengine/GameLogic/SCA_TimeEventManager.h +++ b/source/gameengine/GameLogic/SCA_TimeEventManager.h @@ -45,6 +45,7 @@ public: virtual void NextFrame(double curtime, double fixedtime); virtual void RegisterSensor(class SCA_ISensor* sensor); + virtual void RemoveSensor(class SCA_ISensor* sensor); void AddTimeProperty(CValue* timeval); void RemoveTimeProperty(CValue* timeval); }; diff --git a/source/gameengine/GamePlayer/common/GPC_Canvas.h b/source/gameengine/GamePlayer/common/GPC_Canvas.h index f82166dfa88..87719041f65 100644 --- a/source/gameengine/GamePlayer/common/GPC_Canvas.h +++ b/source/gameengine/GamePlayer/common/GPC_Canvas.h @@ -130,6 +130,12 @@ public: ) { return m_displayarea; }; + + RAS_Rect & + GetWindowArea( + ) { + return m_displayarea; + } void BeginFrame( diff --git a/source/gameengine/GamePlayer/common/windows/GPW_Canvas.h b/source/gameengine/GamePlayer/common/windows/GPW_Canvas.h index bb1abd71505..bf8cb720811 100644 --- a/source/gameengine/GamePlayer/common/windows/GPW_Canvas.h +++ b/source/gameengine/GamePlayer/common/windows/GPW_Canvas.h @@ -36,7 +36,7 @@ #include <iostream> #include <windows.h> -#include <gl/gl.h> +//#include <gl/gl.h> #include "GPC_Canvas.h" diff --git a/source/gameengine/Ketsji/BL_BlenderShader.cpp b/source/gameengine/Ketsji/BL_BlenderShader.cpp index dd45d522b9f..a9a0771936c 100644 --- a/source/gameengine/Ketsji/BL_BlenderShader.cpp +++ b/source/gameengine/Ketsji/BL_BlenderShader.cpp @@ -1,6 +1,10 @@ #include "DNA_customdata_types.h" #include "DNA_material_types.h" +#include "DNA_scene_types.h" + +#include "BKE_global.h" +#include "BKE_main.h" #include "BL_BlenderShader.h" #include "BL_Material.h" @@ -10,30 +14,51 @@ #include "GPU_material.h" #endif +#include "RAS_BucketManager.h" #include "RAS_MeshObject.h" #include "RAS_IRasterizer.h" + + /* this is evil, but we need the scene to create materials with + * lights from the correct scene .. */ +static struct Scene *GetSceneForName(const STR_String& scenename) +{ + Scene *sce; + + for (sce= (Scene*)G.main->scene.first; sce; sce= (Scene*)sce->id.next) + if (scenename == (sce->id.name+2)) + return sce; -const bool BL_BlenderShader::Ok()const + return (Scene*)G.main->scene.first; +} + +bool BL_BlenderShader::Ok() { #ifdef BLENDER_GLSL - return (mGPUMat != 0); + VerifyShader(); + + return (mMat && mMat->gpumaterial); #else return 0; #endif } -BL_BlenderShader::BL_BlenderShader(struct Material *ma, int lightlayer) +BL_BlenderShader::BL_BlenderShader(KX_Scene *scene, struct Material *ma, int lightlayer) : #ifdef BLENDER_GLSL - mGPUMat(0), + mScene(scene), + mMat(ma), + mGPUMat(NULL), #endif mBound(false), mLightLayer(lightlayer) { #ifdef BLENDER_GLSL - if(ma) { - GPU_material_from_blender(ma); - mGPUMat = ma->gpumaterial; + mBlenderScene = GetSceneForName(scene->GetName()); + mBlendMode = GPU_BLEND_SOLID; + + if(mMat) { + GPU_material_from_blender(mBlenderScene, mMat); + mGPUMat = mMat->gpumaterial; } #endif } @@ -41,17 +66,29 @@ BL_BlenderShader::BL_BlenderShader(struct Material *ma, int lightlayer) BL_BlenderShader::~BL_BlenderShader() { #ifdef BLENDER_GLSL - if(mGPUMat) { - GPU_material_unbind(mGPUMat); - mGPUMat = 0; - } + if(mMat && mMat->gpumaterial) + GPU_material_unbind(mMat->gpumaterial); +#endif +} + +bool BL_BlenderShader::VerifyShader() +{ +#ifdef BLENDER_GLSL + if(mMat && !mMat->gpumaterial) + GPU_material_from_blender(mBlenderScene, mMat); + + mGPUMat = mMat->gpumaterial; + + return (mMat && mGPUMat); +#else + return false; #endif } void BL_BlenderShader::SetProg(bool enable) { #ifdef BLENDER_GLSL - if(mGPUMat) { + if(VerifyShader()) { if(enable) { GPU_material_bind(mGPUMat, mLightLayer); mBound = true; @@ -70,7 +107,7 @@ int BL_BlenderShader::GetAttribNum() GPUVertexAttribs attribs; int i, enabled = 0; - if(!mGPUMat) + if(!VerifyShader()) return enabled; GPU_material_vertex_attributes(mGPUMat, &attribs); @@ -96,7 +133,7 @@ void BL_BlenderShader::SetAttribs(RAS_IRasterizer* ras, const BL_Material *mat) ras->SetAttribNum(0); - if(!mGPUMat) + if(!VerifyShader()) return; if(ras->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED) { @@ -142,9 +179,11 @@ void BL_BlenderShader::SetAttribs(RAS_IRasterizer* ras, const BL_Material *mat) void BL_BlenderShader::Update( const KX_MeshSlot & ms, RAS_IRasterizer* rasty ) { #ifdef BLENDER_GLSL - float obmat[4][4], viewmat[4][4], viewinvmat[4][4]; + float obmat[4][4], viewmat[4][4], viewinvmat[4][4], obcol[4]; + + VerifyShader(); - if(!mGPUMat || !mBound) + if(!mGPUMat) // || !mBound) return; MT_Matrix4x4 model; @@ -158,10 +197,22 @@ void BL_BlenderShader::Update( const KX_MeshSlot & ms, RAS_IRasterizer* rasty ) view.invert(); view.getValue((float*)viewinvmat); - GPU_material_bind_uniforms(mGPUMat, obmat, viewmat, viewinvmat); + if(ms.m_bObjectColor) + ms.m_RGBAcolor.getValue((float*)obcol); + else + obcol[0]= obcol[1]= obcol[2]= obcol[3]= 1.0f; + + GPU_material_bind_uniforms(mGPUMat, obmat, viewmat, viewinvmat, obcol); + + mBlendMode = GPU_material_blend_mode(mGPUMat, obcol); #endif } +int BL_BlenderShader::GetBlendMode() +{ + return mBlendMode; +} + bool BL_BlenderShader::Equals(BL_BlenderShader *blshader) { #ifdef BLENDER_GLSL diff --git a/source/gameengine/Ketsji/BL_BlenderShader.h b/source/gameengine/Ketsji/BL_BlenderShader.h index b758d1a9cba..da9765dafa4 100644 --- a/source/gameengine/Ketsji/BL_BlenderShader.h +++ b/source/gameengine/Ketsji/BL_BlenderShader.h @@ -14,7 +14,10 @@ #include "RAS_IPolygonMaterial.h" +#include "KX_Scene.h" + struct Material; +struct Scene; class BL_Material; #define BL_MAX_ATTRIB 16 @@ -27,21 +30,28 @@ class BL_BlenderShader { private: #ifdef BLENDER_GLSL + KX_Scene *mScene; + struct Scene *mBlenderScene; + struct Material *mMat; GPUMaterial *mGPUMat; #endif bool mBound; int mLightLayer; + int mBlendMode; + + bool VerifyShader(); public: - BL_BlenderShader(struct Material *ma, int lightlayer); + BL_BlenderShader(KX_Scene *scene, struct Material *ma, int lightlayer); virtual ~BL_BlenderShader(); - const bool Ok()const; + bool Ok(); void SetProg(bool enable); int GetAttribNum(); void SetAttribs(class RAS_IRasterizer* ras, const BL_Material *mat); void Update(const class KX_MeshSlot & ms, class RAS_IRasterizer* rasty); + int GetBlendMode(); bool Equals(BL_BlenderShader *blshader); }; diff --git a/source/gameengine/Ketsji/BL_Material.h b/source/gameengine/Ketsji/BL_Material.h index 568f7e171de..dcb66ea2579 100644 --- a/source/gameengine/Ketsji/BL_Material.h +++ b/source/gameengine/Ketsji/BL_Material.h @@ -129,8 +129,7 @@ enum BL_flag TEXALPHA=8, // use alpha combiner functions TEXNEG=16, // negate blending HASIPO=32, - USENEGALPHA=64, - ALPHA_TEST=128 + USENEGALPHA=64 }; // BL_Material::ras_mode @@ -139,7 +138,7 @@ enum BL_ras_mode POLY_VIS=1, COLLIDER=2, ZSORT=4, - TRANSP=8, + ALPHA=8, TRIANGLE=16, USE_LIGHT=32, WIRE=64 diff --git a/source/gameengine/Ketsji/BL_Texture.cpp b/source/gameengine/Ketsji/BL_Texture.cpp index f24ef4322f0..f0ef84032f7 100644 --- a/source/gameengine/Ketsji/BL_Texture.cpp +++ b/source/gameengine/Ketsji/BL_Texture.cpp @@ -384,8 +384,6 @@ void BL_Texture::DisableUnit() void BL_Texture::DisableAllTextures() { - glDisable(GL_BLEND); - for(int i=0; i<MAXTEX; i++) { if(GLEW_ARB_multitexture) glActiveTextureARB(GL_TEXTURE0_ARB+i); diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp index 7b5b7fdf78c..eee8e9f6827 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp @@ -55,28 +55,13 @@ KX_NetworkEventManager::~KX_NetworkEventManager() //printf("KX_NetworkEventManager destructor\n"); } -void KX_NetworkEventManager::RegisterSensor(class SCA_ISensor* sensor) -{ - //printf("KX_NetworkEventManager RegisterSensor\n"); - m_sensors.push_back(sensor); -} - -void KX_NetworkEventManager::RemoveSensor(class SCA_ISensor* sensor) -{ - //printf("KX_NetworkEventManager RemoveSensor\n"); - // Network specific RemoveSensor stuff goes here - - // parent - SCA_EventManager::RemoveSensor(sensor); -} - void KX_NetworkEventManager::NextFrame() { // printf("KX_NetworkEventManager::proceed %.2f - %.2f\n", curtime, deltatime); // each frame, the logicmanager will call the network // eventmanager to look for network events, and process it's // 'network' sensors - vector<class SCA_ISensor*>::iterator it; + set<class SCA_ISensor*>::iterator it; for (it = m_sensors.begin(); !(it==m_sensors.end()); it++) { // printf("KX_NetworkEventManager::proceed sensor %.2f\n", curtime); diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h index 0b097ba2ef6..ae88f1d4987 100644 --- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h +++ b/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h @@ -42,9 +42,6 @@ public: class NG_NetworkDeviceInterface *ndi); virtual ~KX_NetworkEventManager (); - virtual void RegisterSensor(class SCA_ISensor* sensor); - virtual void RemoveSensor(class SCA_ISensor* sensor); - virtual void NextFrame(); virtual void EndFrame(); diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 0f445a9f32e..a67e5b26667 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -38,6 +38,7 @@ extern "C" { // ------------------------------------ #define spit(x) std::cout << x << std::endl; +BL_Shader *KX_BlenderMaterial::mLastShader = NULL; BL_BlenderShader *KX_BlenderMaterial::mLastBlenderShader = NULL; //static PyObject *gTextureDict = 0; @@ -58,7 +59,8 @@ KX_BlenderMaterial::KX_BlenderMaterial( data->tilexrep[0], data->tileyrep[0], data->mode, - ((data->ras_mode &TRANSP)!=0), + data->transp, + ((data->ras_mode &ALPHA)!=0), ((data->ras_mode &ZSORT)!=0), lightlayer, ((data->ras_mode &TRIANGLE)!=0), @@ -79,7 +81,6 @@ KX_BlenderMaterial::KX_BlenderMaterial( m_flag |=RAS_BLENDERMAT; m_flag |=(mMaterial->IdMode>=ONETEX)?RAS_MULTITEX:0; m_flag |=(mMaterial->ras_mode & USE_LIGHT)!=0?RAS_MULTILIGHT:0; - m_flag |=(mMaterial->ras_mode &ALPHA_TEST)!=0?RAS_FORCEALPHA:0; // figure max int enabled = mMaterial->num_enabled; @@ -158,12 +159,29 @@ void KX_BlenderMaterial::OnConstruction() mConstructed = true; } +void KX_BlenderMaterial::EndFrame() +{ + if(mLastBlenderShader) { + mLastBlenderShader->SetProg(false); + mLastBlenderShader = NULL; + } + + if(mLastShader) { + mLastShader->SetProg(false); + mLastShader = NULL; + } +} + void KX_BlenderMaterial::OnExit() { if( mShader ) { - //note, the shader here is allocated, per unique material - //and this function is called per face - mShader->SetProg(false); + //note, the shader here is allocated, per unique material + //and this function is called per face + if(mShader == mLastShader) { + mShader->SetProg(false); + mLastShader = NULL; + } + delete mShader; mShader = 0; } @@ -197,13 +215,19 @@ void KX_BlenderMaterial::setShaderData( bool enable, RAS_IRasterizer *ras) int i; if( !enable || !mShader->Ok() ) { // frame cleanup. - mShader->SetProg(false); + if(mShader == mLastShader) { + mShader->SetProg(false); + mLastShader = NULL; + } + + ras->SetBlendingMode(TF_SOLID); BL_Texture::DisableAllTextures(); return; } BL_Texture::DisableAllTextures(); mShader->SetProg(true); + mLastShader = mShader; BL_Texture::ActivateFirst(); @@ -217,9 +241,12 @@ void KX_BlenderMaterial::setShaderData( bool enable, RAS_IRasterizer *ras) } if(!mUserDefBlend) { - setDefaultBlending(); + ras->SetBlendingMode(mMaterial->transp); } else { + ras->SetBlendingMode(TF_SOLID); + ras->SetBlendingMode(-1); // indicates custom mode + // tested to be valid enums glEnable(GL_BLEND); glBlendFunc(mBlendFunc[0], mBlendFunc[1]); @@ -234,11 +261,14 @@ void KX_BlenderMaterial::setBlenderShaderData( bool enable, RAS_IRasterizer *ras mLastBlenderShader->SetProg(false); mLastBlenderShader= NULL; } + + ras->SetBlendingMode(TF_SOLID); BL_Texture::DisableAllTextures(); return; } if(!mBlenderShader->Equals(mLastBlenderShader)) { + ras->SetBlendingMode(mMaterial->transp); BL_Texture::DisableAllTextures(); if(mLastBlenderShader) @@ -251,17 +281,17 @@ void KX_BlenderMaterial::setBlenderShaderData( bool enable, RAS_IRasterizer *ras void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras) { - if(GLEW_ARB_shader_objects && mShader) - mShader->SetProg(false); - BL_Texture::DisableAllTextures(); - if( !enable ) + + if( !enable ) { + ras->SetBlendingMode(TF_SOLID); return; + } BL_Texture::ActivateFirst(); if( mMaterial->IdMode == DEFAULT_BLENDER ) { - setDefaultBlending(); + ras->SetBlendingMode(mMaterial->transp); return; } @@ -271,7 +301,7 @@ void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras) mTextures[0].ActivateTexture(); mTextures[0].setTexEnv(0, true); mTextures[0].SetMapping(mMaterial->mapping[0].mapping); - setDefaultBlending(); + ras->SetBlendingMode(mMaterial->transp); } return; } @@ -294,9 +324,12 @@ void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras) } if(!mUserDefBlend) { - setDefaultBlending(); + ras->SetBlendingMode(mMaterial->transp); } else { + ras->SetBlendingMode(TF_SOLID); + ras->SetBlendingMode(-1); // indicates custom mode + glEnable(GL_BLEND); glBlendFunc(mBlendFunc[0], mBlendFunc[1]); } @@ -356,6 +389,11 @@ KX_BlenderMaterial::ActivateBlenderShaders( { KX_BlenderMaterial *tmp = const_cast<KX_BlenderMaterial*>(this); + if(mLastShader) { + mLastShader->SetProg(false); + mLastShader= NULL; + } + // reset... if(tmp->mMaterial->IsShared()) cachingInfo =0; @@ -402,6 +440,11 @@ KX_BlenderMaterial::ActivateMat( { KX_BlenderMaterial *tmp = const_cast<KX_BlenderMaterial*>(this); + if(mLastShader) { + mLastShader->SetProg(false); + mLastShader= NULL; + } + if(mLastBlenderShader) { mLastBlenderShader->SetProg(false); mLastBlenderShader= NULL; @@ -451,7 +494,10 @@ KX_BlenderMaterial::Activate( return dopass; } else { - mShader->SetProg(false); + if(mShader == mLastShader) { + mShader->SetProg(false); + mLastShader = NULL; + } mPass = 0; dopass = false; return dopass; @@ -499,10 +545,22 @@ bool KX_BlenderMaterial::UsesLighting(RAS_IRasterizer *rasty) const void KX_BlenderMaterial::ActivateMeshSlot(const KX_MeshSlot & ms, RAS_IRasterizer* rasty) const { - if(mShader && GLEW_ARB_shader_objects) + if(mShader && GLEW_ARB_shader_objects) { mShader->Update(ms, rasty); - else if(mBlenderShader && GLEW_ARB_shader_objects) + } + else if(mBlenderShader && GLEW_ARB_shader_objects) { + int blendmode; + mBlenderShader->Update(ms, rasty); + + /* we do blend modes here, because they can change per object + * with the same material due to obcolor */ + blendmode = mBlenderShader->GetBlendMode(); + if((blendmode == TF_SOLID || blendmode == TF_ALPHA) && mMaterial->transp != TF_SOLID) + blendmode = mMaterial->transp; + + rasty->SetBlendingMode(blendmode); + } } void KX_BlenderMaterial::ActivatGLMaterials( RAS_IRasterizer* rasty )const @@ -582,31 +640,6 @@ void KX_BlenderMaterial::ActivateTexGen(RAS_IRasterizer *ras) const ras->EnableTextures(false); } -bool KX_BlenderMaterial::setDefaultBlending() -{ - if( mMaterial->transp &TF_ADD) { - glEnable(GL_BLEND); - glBlendFunc(GL_ONE, GL_ONE); - glDisable ( GL_ALPHA_TEST ); - return true; - } - - if( mMaterial->transp & TF_ALPHA ) { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable ( GL_ALPHA_TEST ); - return true; - } - - if( mMaterial->transp & TF_CLIP ) { - glDisable(GL_BLEND); - glEnable ( GL_ALPHA_TEST ); - glAlphaFunc(GL_GREATER, 0.5f); - return false; - } - return false; -} - void KX_BlenderMaterial::setTexMatrixData(int i) { glMatrixMode(GL_TEXTURE); @@ -831,12 +864,14 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") void KX_BlenderMaterial::SetBlenderGLSLShader(void) { if(!mBlenderShader) - mBlenderShader = new BL_BlenderShader(mMaterial->material, m_lightlayer); + mBlenderShader = new BL_BlenderShader(mScene, mMaterial->material, m_lightlayer); if(!mBlenderShader->Ok()) { delete mBlenderShader; mBlenderShader = 0; } + else + m_flag |= RAS_BLENDERGLSL; } KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getMaterialIndex, "getMaterialIndex()") diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h index bf6d2095e7c..0d7657b8cdb 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.h +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h @@ -90,11 +90,13 @@ public: // -------------------------------- // pre calculate to avoid pops/lag at startup virtual void OnConstruction( ); + + static void EndFrame(); + private: BL_Material* mMaterial; BL_Shader* mShader; BL_BlenderShader* mBlenderShader; - static BL_BlenderShader *mLastBlenderShader; KX_Scene* mScene; BL_Texture mTextures[MAXTEX]; // texture array bool mUserDefBlend; @@ -114,7 +116,6 @@ private: void setBlenderShaderData( bool enable, RAS_IRasterizer *ras); void setShaderData( bool enable, RAS_IRasterizer *ras); - bool setDefaultBlending(); void setObjectMatrixData(int i, RAS_IRasterizer *ras); void setTexMatrixData(int i); @@ -123,6 +124,10 @@ private: // cleanup stuff void OnExit(); + // shader chacing + static BL_BlenderShader *mLastBlenderShader; + static BL_Shader *mLastShader; + mutable int mPass; }; diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp index 70443ced7a9..539eaec4a7b 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -13,11 +13,13 @@ #include "KX_ClientObjectInfo.h" #include "PHY_IPhysicsEnvironment.h" +#include "CcdPhysicsEnvironment.h" KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna) : KX_IPhysicsController(dyna,(PHY_IPhysicsController*)this), -CcdPhysicsController(ci) +CcdPhysicsController(ci), +m_savedCollisionFlags(0) { } @@ -131,9 +133,10 @@ void KX_BulletPhysicsController::getOrientation(MT_Quaternion& orn) CcdPhysicsController::getOrientation(myorn[0],myorn[1],myorn[2],myorn[3]); orn = MT_Quaternion(myorn[0],myorn[1],myorn[2],myorn[3]); } -void KX_BulletPhysicsController::setOrientation(const MT_Quaternion& orn) +void KX_BulletPhysicsController::setOrientation(const MT_Matrix3x3& orn) { - CcdPhysicsController::setOrientation(orn.x(),orn.y(),orn.z(),orn.w()); + btMatrix3x3 btmat(orn[0][0], orn[0][1], orn[0][2], orn[1][0], orn[1][1], orn[1][2], orn[2][0], orn[2][1], orn[2][2]); + CcdPhysicsController::setWorldOrientation(btmat); } void KX_BulletPhysicsController::setPosition(const MT_Point3& pos) { @@ -161,14 +164,37 @@ void KX_BulletPhysicsController::setRigidBody(bool rigid) { } -void KX_BulletPhysicsController::SuspendDynamics() +void KX_BulletPhysicsController::SuspendDynamics(bool ghost) { - GetRigidBody()->setActivationState(DISABLE_SIMULATION); - + btRigidBody *body = GetRigidBody(); + if (body->getActivationState() != DISABLE_SIMULATION) + { + btBroadphaseProxy* handle = body->getBroadphaseHandle(); + m_savedCollisionFlags = body->getCollisionFlags(); + m_savedMass = GetMass(); + m_savedCollisionFilterGroup = handle->m_collisionFilterGroup; + m_savedCollisionFilterMask = handle->m_collisionFilterMask; + body->setActivationState(DISABLE_SIMULATION); + GetPhysicsEnvironment()->updateCcdPhysicsController(this, + 0.0, + btCollisionObject::CF_STATIC_OBJECT|((ghost)?btCollisionObject::CF_NO_CONTACT_RESPONSE:(m_savedCollisionFlags&btCollisionObject::CF_NO_CONTACT_RESPONSE)), + btBroadphaseProxy::StaticFilter, + btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter); + } } + void KX_BulletPhysicsController::RestoreDynamics() { - GetRigidBody()->forceActivationState(ACTIVE_TAG); + btRigidBody *body = GetRigidBody(); + if (body->getActivationState() == DISABLE_SIMULATION) + { + GetPhysicsEnvironment()->updateCcdPhysicsController(this, + m_savedMass, + m_savedCollisionFlags, + m_savedCollisionFilterGroup, + m_savedCollisionFilterMask); + GetRigidBody()->forceActivationState(ACTIVE_TAG); + } } SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode) diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.h b/source/gameengine/Ketsji/KX_BulletPhysicsController.h index 0853755dffa..2efe0474b30 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.h +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.h @@ -7,6 +7,11 @@ class KX_BulletPhysicsController : public KX_IPhysicsController ,public CcdPhysicsController { +private: + int m_savedCollisionFlags; + short int m_savedCollisionFilterGroup; + short int m_savedCollisionFilterMask; + MT_Scalar m_savedMass; public: @@ -30,7 +35,7 @@ public: virtual void SetAngularVelocity(const MT_Vector3& ang_vel,bool local); virtual void SetLinearVelocity(const MT_Vector3& lin_vel,bool local); virtual void getOrientation(MT_Quaternion& orn); - virtual void setOrientation(const MT_Quaternion& orn); + virtual void setOrientation(const MT_Matrix3x3& orn); virtual void setPosition(const MT_Point3& pos); virtual void setScaling(const MT_Vector3& scaling); virtual MT_Scalar GetMass(); @@ -39,7 +44,7 @@ public: virtual void resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ); - virtual void SuspendDynamics(); + virtual void SuspendDynamics(bool ghost); virtual void RestoreDynamics(); virtual SG_Controller* GetReplica(class SG_Node* destnode); diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 27f4870de10..0a97b6f0a2f 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -49,7 +49,7 @@ STR_String KX_CameraActuator::Y_AXIS_STRING = "y"; KX_CameraActuator::KX_CameraActuator( SCA_IObject* gameobj, - CValue *obj, + SCA_IObject *obj, MT_Scalar hght, MT_Scalar minhght, MT_Scalar maxhght, @@ -63,11 +63,14 @@ KX_CameraActuator::KX_CameraActuator( m_maxHeight (maxhght), m_x (xytog) { + if (m_ob) + m_ob->RegisterActuator(this); } KX_CameraActuator::~KX_CameraActuator() { - //nothing to do + if (m_ob) + m_ob->UnregisterActuator(this); } CValue* @@ -81,9 +84,36 @@ GetReplica( return replica; }; +void KX_CameraActuator::ProcessReplica() +{ + if (m_ob) + m_ob->RegisterActuator(this); + SCA_IActuator::ProcessReplica(); +} +bool KX_CameraActuator::UnlinkObject(SCA_IObject* clientobj) +{ + if (clientobj == m_ob) + { + // this object is being deleted, we cannot continue to track it. + m_ob = NULL; + return true; + } + return false; +} +void KX_CameraActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + void **h_obj = (*obj_map)[m_ob]; + if (h_obj) { + if (m_ob) + m_ob->UnregisterActuator(this); + m_ob = (SCA_IObject*)(*h_obj); + m_ob->RegisterActuator(this); + } +} + /* three functions copied from blender arith... don't know if there's an equivalent */ static float Kx_Normalize(float *n) @@ -181,8 +211,14 @@ static void Kx_VecUpMat3(float *vec, float mat[][3], short axis) bool KX_CameraActuator::Update(double curtime, bool frame) { - bool result = true; + /* wondering... is it really neccesary/desirable to suppress negative */ + /* events here? */ + bool bNegativeEvent = IsNegativeEvent(); + RemoveAllEvents(); + if (bNegativeEvent || !m_ob) + return false; + KX_GameObject *obj = (KX_GameObject*) GetParent(); MT_Point3 from = obj->NodeGetWorldPosition(); MT_Matrix3x3 frommat = obj->NodeGetWorldOrientation(); @@ -195,13 +231,6 @@ bool KX_CameraActuator::Update(double curtime, bool frame) float mindistsq, maxdistsq, distsq; float mat[3][3]; - /* wondering... is it really neccesary/desirable to suppress negative */ - /* events here? */ - bool bNegativeEvent = IsNegativeEvent(); - RemoveAllEvents(); - - if (bNegativeEvent) return false; - /* The rules: */ /* CONSTRAINT 1: not implemented */ /* CONSTRAINT 2: can camera see actor? */ @@ -315,7 +344,7 @@ bool KX_CameraActuator::Update(double curtime, bool frame) actormat[2][0]= mat[0][2]; actormat[2][1]= mat[1][2]; actormat[2][2]= mat[2][2]; obj->NodeSetLocalOrientation(actormat); - return result; + return true; } CValue *KX_CameraActuator::findObject(char *obName) @@ -404,7 +433,11 @@ PyObject* KX_CameraActuator::PySetObject(PyObject* self, PyObject* gameobj; if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj)) { - m_ob = (CValue*)gameobj; + if (m_ob) + m_ob->UnregisterActuator(this); + m_ob = (SCA_IObject*)gameobj; + if (m_ob) + m_ob->RegisterActuator(this); Py_Return; } PyErr_Clear(); @@ -412,10 +445,13 @@ PyObject* KX_CameraActuator::PySetObject(PyObject* self, char* objectname; if (PyArg_ParseTuple(args, "s", &objectname)) { - CValue *object = (CValue*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname)); + SCA_IObject *object = (SCA_IObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname)); if(object) { + if (m_ob != NULL) + m_ob->UnregisterActuator(this); m_ob = object; + m_ob->RegisterActuator(this); Py_Return; } } diff --git a/source/gameengine/Ketsji/KX_CameraActuator.h b/source/gameengine/Ketsji/KX_CameraActuator.h index eb007e403ec..488b36922b0 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.h +++ b/source/gameengine/Ketsji/KX_CameraActuator.h @@ -49,7 +49,7 @@ class KX_CameraActuator : public SCA_IActuator Py_Header; private : /** Object that will be tracked. */ - CValue *m_ob; + SCA_IObject *m_ob; /** height (float), */ //const MT_Scalar m_height; @@ -87,7 +87,7 @@ private : SCA_IObject *gameobj, //const CValue *ob, - CValue *ob, + SCA_IObject *ob, MT_Scalar hght, MT_Scalar minhght, MT_Scalar maxhght, @@ -103,6 +103,7 @@ private : /** Methods Inherited from CValue */ CValue* GetReplica(); + virtual void ProcessReplica(); /** Methods inherited from SCA_IActuator */ @@ -110,7 +111,10 @@ private : double curtime, bool frame ); + virtual bool UnlinkObject(SCA_IObject* clientobj); + /** Methods inherited from SCA_ILogicBrick */ + virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index 80288a72485..2401d69d3a3 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -88,11 +88,17 @@ KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj, } else { m_refDirection /= len; } + m_minimumBound = cos(minBound); + m_maximumBound = cos(maxBound); + m_minimumSine = sin(minBound); + m_maximumSine = sin(maxBound); } break; default: m_minimumBound = minBound; m_maximumBound = maxBound; + m_minimumSine = 0.f; + m_maximumSine = 0.f; break; } @@ -153,9 +159,9 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) KX_GameObject *obj = (KX_GameObject*) GetParent(); MT_Point3 position = obj->NodeGetWorldPosition(); MT_Point3 newposition; - MT_Vector3 direction; + MT_Vector3 direction, refDirection; MT_Matrix3x3 rotation = obj->NodeGetWorldOrientation(); - MT_Scalar filter, newdistance; + MT_Scalar filter, newdistance, cosangle; int axis, sign; if (m_posDampTime) { @@ -178,16 +184,52 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) direction[2] = rotation[2][1]; axis = 1; break; - case KX_ACT_CONSTRAINT_ORIZ: + default: direction[0] = rotation[0][2]; direction[1] = rotation[1][2]; direction[2] = rotation[2][2]; axis = 2; break; } - // apply damping on the direction + if ((m_maximumBound < (1.0f-FLT_EPSILON)) || (m_minimumBound < (1.0f-FLT_EPSILON))) { + // reference direction needs to be evaluated + // 1. get the cosine between current direction and target + cosangle = direction.dot(m_refDirection); + if (cosangle >= (m_maximumBound-FLT_EPSILON) && cosangle <= (m_minimumBound+FLT_EPSILON)) { + // no change to do + result = true; + goto CHECK_TIME; + } + // 2. define a new reference direction + // compute local axis with reference direction as X and + // Y in direction X refDirection plane + MT_Vector3 zaxis = m_refDirection.cross(direction); + if (MT_fuzzyZero2(zaxis.length2())) { + // direction and refDirection are identical, + // choose any other direction to define plane + if (direction[0] < 0.9999) + zaxis = m_refDirection.cross(MT_Vector3(1.0,0.0,0.0)); + else + zaxis = m_refDirection.cross(MT_Vector3(0.0,1.0,0.0)); + } + MT_Vector3 yaxis = zaxis.cross(m_refDirection); + yaxis.normalize(); + if (cosangle > m_minimumBound) { + // angle is too close to reference direction, + // choose a new reference that is exactly at minimum angle + refDirection = m_minimumBound * m_refDirection + m_minimumSine * yaxis; + } else { + // angle is too large, choose new reference direction at maximum angle + refDirection = m_maximumBound * m_refDirection + m_maximumSine * yaxis; + } + } else { + refDirection = m_refDirection; + } if (m_posDampTime) { - direction = filter*direction + (1.0-filter)*m_refDirection; + // apply damping on the direction + direction = filter*direction + (1.0-filter)*refDirection; + } else { + direction = refDirection; } obj->AlignAxisToVect(direction, axis); result = true; @@ -195,9 +237,9 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) case KX_ACT_CONSTRAINT_DIRPX: case KX_ACT_CONSTRAINT_DIRPY: case KX_ACT_CONSTRAINT_DIRPZ: - case KX_ACT_CONSTRAINT_DIRMX: - case KX_ACT_CONSTRAINT_DIRMY: - case KX_ACT_CONSTRAINT_DIRMZ: + case KX_ACT_CONSTRAINT_DIRNX: + case KX_ACT_CONSTRAINT_DIRNY: + case KX_ACT_CONSTRAINT_DIRNZ: switch (m_locrot) { case KX_ACT_CONSTRAINT_DIRPX: direction[0] = rotation[0][0]; @@ -220,21 +262,21 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) axis = 2; sign = 1; break; - case KX_ACT_CONSTRAINT_DIRMX: + case KX_ACT_CONSTRAINT_DIRNX: direction[0] = -rotation[0][0]; direction[1] = -rotation[1][0]; direction[2] = -rotation[2][0]; axis = 0; sign = 0; break; - case KX_ACT_CONSTRAINT_DIRMY: + case KX_ACT_CONSTRAINT_DIRNY: direction[0] = -rotation[0][1]; direction[1] = -rotation[1][1]; direction[2] = -rotation[2][1]; axis = 1; sign = 0; break; - case KX_ACT_CONSTRAINT_DIRMZ: + case KX_ACT_CONSTRAINT_DIRNZ: direction[0] = -rotation[0][2]; direction[1] = -rotation[1][2]; direction[2] = -rotation[2][2]; @@ -395,27 +437,27 @@ PyParentObject KX_ConstraintActuator::Parents[] = { PyMethodDef KX_ConstraintActuator::Methods[] = { {"setDamp", (PyCFunction) KX_ConstraintActuator::sPySetDamp, METH_VARARGS, SetDamp_doc}, - {"getDamp", (PyCFunction) KX_ConstraintActuator::sPyGetDamp, METH_VARARGS, GetDamp_doc}, + {"getDamp", (PyCFunction) KX_ConstraintActuator::sPyGetDamp, METH_NOARGS, GetDamp_doc}, {"setRotDamp", (PyCFunction) KX_ConstraintActuator::sPySetRotDamp, METH_VARARGS, SetRotDamp_doc}, - {"getRotDamp", (PyCFunction) KX_ConstraintActuator::sPyGetRotDamp, METH_VARARGS, GetRotDamp_doc}, + {"getRotDamp", (PyCFunction) KX_ConstraintActuator::sPyGetRotDamp, METH_NOARGS, GetRotDamp_doc}, {"setDirection", (PyCFunction) KX_ConstraintActuator::sPySetDirection, METH_VARARGS, SetDirection_doc}, - {"getDirection", (PyCFunction) KX_ConstraintActuator::sPyGetDirection, METH_VARARGS, GetDirection_doc}, + {"getDirection", (PyCFunction) KX_ConstraintActuator::sPyGetDirection, METH_NOARGS, GetDirection_doc}, {"setOption", (PyCFunction) KX_ConstraintActuator::sPySetOption, METH_VARARGS, SetOption_doc}, - {"getOption", (PyCFunction) KX_ConstraintActuator::sPyGetOption, METH_VARARGS, GetOption_doc}, + {"getOption", (PyCFunction) KX_ConstraintActuator::sPyGetOption, METH_NOARGS, GetOption_doc}, {"setTime", (PyCFunction) KX_ConstraintActuator::sPySetTime, METH_VARARGS, SetTime_doc}, - {"getTime", (PyCFunction) KX_ConstraintActuator::sPyGetTime, METH_VARARGS, GetTime_doc}, + {"getTime", (PyCFunction) KX_ConstraintActuator::sPyGetTime, METH_NOARGS, GetTime_doc}, {"setProperty", (PyCFunction) KX_ConstraintActuator::sPySetProperty, METH_VARARGS, SetProperty_doc}, - {"getProperty", (PyCFunction) KX_ConstraintActuator::sPyGetProperty, METH_VARARGS, GetProperty_doc}, + {"getProperty", (PyCFunction) KX_ConstraintActuator::sPyGetProperty, METH_NOARGS, GetProperty_doc}, {"setMin", (PyCFunction) KX_ConstraintActuator::sPySetMin, METH_VARARGS, SetMin_doc}, - {"getMin", (PyCFunction) KX_ConstraintActuator::sPyGetMin, METH_VARARGS, GetMin_doc}, + {"getMin", (PyCFunction) KX_ConstraintActuator::sPyGetMin, METH_NOARGS, GetMin_doc}, {"setDistance", (PyCFunction) KX_ConstraintActuator::sPySetMin, METH_VARARGS, SetDistance_doc}, - {"getDistance", (PyCFunction) KX_ConstraintActuator::sPyGetMin, METH_VARARGS, GetDistance_doc}, + {"getDistance", (PyCFunction) KX_ConstraintActuator::sPyGetMin, METH_NOARGS, GetDistance_doc}, {"setMax", (PyCFunction) KX_ConstraintActuator::sPySetMax, METH_VARARGS, SetMax_doc}, - {"getMax", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_VARARGS, GetMax_doc}, + {"getMax", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_NOARGS, GetMax_doc}, {"setRayLength", (PyCFunction) KX_ConstraintActuator::sPySetMax, METH_VARARGS, SetRayLength_doc}, - {"getRayLength", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_VARARGS, GetRayLength_doc}, + {"getRayLength", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_NOARGS, GetRayLength_doc}, {"setLimit", (PyCFunction) KX_ConstraintActuator::sPySetLimit, METH_VARARGS, SetLimit_doc}, - {"getLimit", (PyCFunction) KX_ConstraintActuator::sPyGetLimit, METH_VARARGS, GetLimit_doc}, + {"getLimit", (PyCFunction) KX_ConstraintActuator::sPyGetLimit, METH_NOARGS, GetLimit_doc}, {NULL,NULL} //Sentinel }; @@ -434,6 +476,7 @@ PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, PyObject* kwds) { int dampArg; if(!PyArg_ParseTuple(args, "i", &dampArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -446,9 +489,7 @@ PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, char KX_ConstraintActuator::GetDamp_doc[] = "getDamp()\n" "\tReturns the damping parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self, - PyObject* args, - PyObject* kwds){ +PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self){ return PyInt_FromLong(m_posDampTime); } @@ -463,6 +504,7 @@ PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, PyObject* kwds) { int dampArg; if(!PyArg_ParseTuple(args, "i", &dampArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -475,9 +517,7 @@ PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, char KX_ConstraintActuator::GetRotDamp_doc[] = "getRotDamp()\n" "\tReturns the damping time for application of the constraint.\n"; -PyObject* KX_ConstraintActuator::PyGetRotDamp(PyObject* self, - PyObject* args, - PyObject* kwds){ +PyObject* KX_ConstraintActuator::PyGetRotDamp(PyObject* self){ return PyInt_FromLong(m_rotDampTime); } @@ -494,6 +534,7 @@ PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, MT_Vector3 dir; if(!PyArg_ParseTuple(args, "(fff)", &x, &y, &z)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } dir[0] = x; @@ -512,9 +553,7 @@ PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, char KX_ConstraintActuator::GetDirection_doc[] = "getDirection()\n" "\tReturns the reference direction of the orientation constraint as a 3-tuple.\n"; -PyObject* KX_ConstraintActuator::PyGetDirection(PyObject* self, - PyObject* args, - PyObject* kwds){ +PyObject* KX_ConstraintActuator::PyGetDirection(PyObject* self){ PyObject *retVal = PyList_New(3); PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_refDirection[0])); @@ -538,6 +577,7 @@ PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, PyObject* kwds) { int option; if(!PyArg_ParseTuple(args, "i", &option)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -549,9 +589,7 @@ PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, char KX_ConstraintActuator::GetOption_doc[] = "getOption()\n" "\tReturns the option parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetOption(PyObject* self, - PyObject* args, - PyObject* kwds){ +PyObject* KX_ConstraintActuator::PyGetOption(PyObject* self){ return PyInt_FromLong(m_option); } @@ -567,6 +605,7 @@ PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, PyObject* kwds) { int t; if(!PyArg_ParseTuple(args, "i", &t)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -580,9 +619,7 @@ PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, char KX_ConstraintActuator::GetTime_doc[] = "getTime()\n" "\tReturns the time parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetTime(PyObject* self, - PyObject* args, - PyObject* kwds){ +PyObject* KX_ConstraintActuator::PyGetTime(PyObject* self){ return PyInt_FromLong(m_activeTime); } @@ -597,6 +634,7 @@ PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, PyObject* kwds) { char *property; if (!PyArg_ParseTuple(args, "s", &property)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } if (property == NULL) { @@ -612,9 +650,7 @@ PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, char KX_ConstraintActuator::GetProperty_doc[] = "getProperty()\n" "\tReturns the property parameter.\n"; -PyObject* KX_ConstraintActuator::PyGetProperty(PyObject* self, - PyObject* args, - PyObject* kwds){ +PyObject* KX_ConstraintActuator::PyGetProperty(PyObject* self){ return PyString_FromString(m_property); } @@ -634,6 +670,7 @@ PyObject* KX_ConstraintActuator::PySetMin(PyObject* self, PyObject* kwds) { float minArg; if(!PyArg_ParseTuple(args, "f", &minArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -659,9 +696,7 @@ char KX_ConstraintActuator::GetMin_doc[] = "getMin()\n" "\tReturns the lower value of the interval to which the value\n" "\tis clipped.\n"; -PyObject* KX_ConstraintActuator::PyGetMin(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PyGetMin(PyObject* self) { return PyFloat_FromDouble(m_minimumBound); } @@ -681,6 +716,7 @@ PyObject* KX_ConstraintActuator::PySetMax(PyObject* self, PyObject* kwds){ float maxArg; if(!PyArg_ParseTuple(args, "f", &maxArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -706,9 +742,7 @@ char KX_ConstraintActuator::GetMax_doc[] = "getMax()\n" "\tReturns the upper value of the interval to which the value\n" "\tis clipped.\n"; -PyObject* KX_ConstraintActuator::PyGetMax(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PyGetMax(PyObject* self) { return PyFloat_FromDouble(m_maximumBound); } @@ -736,6 +770,7 @@ PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, PyObject* kwds) { int locrotArg; if(!PyArg_ParseTuple(args, "i", &locrotArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -747,9 +782,7 @@ PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, char KX_ConstraintActuator::GetLimit_doc[] = "getLimit()\n" "\tReturns the type of constraint.\n"; -PyObject* KX_ConstraintActuator::PyGetLimit(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ConstraintActuator::PyGetLimit(PyObject* self) { return PyInt_FromLong(m_locrot); } diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.h b/source/gameengine/Ketsji/KX_ConstraintActuator.h index 5a1d4d23217..d9f39124cac 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.h +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.h @@ -48,6 +48,10 @@ protected: float m_minimumBound; // max (float) float m_maximumBound; + // sinus of minimum angle + float m_minimumSine; + // sinus of maximum angle + float m_maximumSine; // reference direction MT_Vector3 m_refDirection; // locrotxyz choice (pick one): only one choice allowed at a time! @@ -80,9 +84,9 @@ protected: KX_ACT_CONSTRAINT_DIRPX, KX_ACT_CONSTRAINT_DIRPY, KX_ACT_CONSTRAINT_DIRPZ, - KX_ACT_CONSTRAINT_DIRMX, - KX_ACT_CONSTRAINT_DIRMY, - KX_ACT_CONSTRAINT_DIRMZ, + KX_ACT_CONSTRAINT_DIRNX, + KX_ACT_CONSTRAINT_DIRNY, + KX_ACT_CONSTRAINT_DIRNZ, KX_ACT_CONSTRAINT_ORIX, KX_ACT_CONSTRAINT_ORIY, KX_ACT_CONSTRAINT_ORIZ, @@ -127,27 +131,27 @@ protected: virtual PyObject* _getattr(const STR_String& attr); KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDamp); - KX_PYMETHOD_DOC(KX_ConstraintActuator,GetDamp); + KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDamp); KX_PYMETHOD_DOC(KX_ConstraintActuator,SetRotDamp); - KX_PYMETHOD_DOC(KX_ConstraintActuator,GetRotDamp); + KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetRotDamp); KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDirection); - KX_PYMETHOD_DOC(KX_ConstraintActuator,GetDirection); + KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDirection); KX_PYMETHOD_DOC(KX_ConstraintActuator,SetOption); - KX_PYMETHOD_DOC(KX_ConstraintActuator,GetOption); + KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetOption); KX_PYMETHOD_DOC(KX_ConstraintActuator,SetTime); - KX_PYMETHOD_DOC(KX_ConstraintActuator,GetTime); + KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetTime); KX_PYMETHOD_DOC(KX_ConstraintActuator,SetProperty); - KX_PYMETHOD_DOC(KX_ConstraintActuator,GetProperty); + KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetProperty); KX_PYMETHOD_DOC(KX_ConstraintActuator,SetMin); - KX_PYMETHOD_DOC(KX_ConstraintActuator,GetMin); + KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetMin); static char SetDistance_doc[]; static char GetDistance_doc[]; KX_PYMETHOD_DOC(KX_ConstraintActuator,SetMax); - KX_PYMETHOD_DOC(KX_ConstraintActuator,GetMax); + KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetMax); static char SetRayLength_doc[]; static char GetRayLength_doc[]; KX_PYMETHOD_DOC(KX_ConstraintActuator,SetLimit); - KX_PYMETHOD_DOC(KX_ConstraintActuator,GetLimit); + KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetLimit); }; #endif //__KX_CONSTRAINTACTUATOR diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 2ac4f909077..6fcd3df2afc 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -61,6 +61,8 @@ typedef unsigned long uint_ptr; #include "KX_RayCast.h" #include "KX_PythonInit.h" #include "KX_PyMath.h" +#include "SCA_IActuator.h" +#include "SCA_ISensor.h" // This file defines relationships between parents and children // in the game engine. @@ -75,10 +77,10 @@ KX_GameObject::KX_GameObject( SCA_IObject(T), m_bDyna(false), m_layer(0), + m_pBlenderObject(NULL), m_bSuspendDynamics(false), m_bUseObjectColor(false), m_bIsNegativeScaling(false), - m_pBlenderObject(NULL), m_bVisible(true), m_pPhysicsController1(NULL), m_pPhysicsEnvironment(NULL), @@ -94,12 +96,9 @@ KX_GameObject::KX_GameObject( KX_NormalParentRelation * parent_relation = KX_NormalParentRelation::New(); m_pSGNode->SetParentRelation(parent_relation); - - }; - KX_GameObject::~KX_GameObject() { // is this delete somewhere ? @@ -163,6 +162,7 @@ STR_String KX_GameObject::GetName() void KX_GameObject::SetName(STR_String name) { m_name = name; + }; // Set the name of the value @@ -222,6 +222,10 @@ void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj) RemoveParent(scene); obj->GetSGNode()->AddChild(GetSGNode()); + if (m_pPhysicsController1) + { + m_pPhysicsController1->SuspendDynamics(true); + } // Set us to our new scale, position, and orientation scale1[0] = scale1[0]/scale2[0]; scale1[1] = scale1[1]/scale2[1]; @@ -258,6 +262,10 @@ void KX_GameObject::RemoveParent(KX_Scene *scene) if (!rootlist->SearchValue(this)) // object was not in root list, add it now and increment ref count rootlist->Add(AddRef()); + if (m_pPhysicsController1) + { + m_pPhysicsController1->RestoreDynamics(); + } } } @@ -267,6 +275,7 @@ void KX_GameObject::ProcessReplica(KX_GameObject* replica) replica->m_pSGNode = NULL; replica->m_pClient_info = new KX_ClientObjectInfo(*m_pClient_info); replica->m_pClient_info->m_gameobject = replica; + replica->m_state = 0; } @@ -432,6 +441,7 @@ void KX_GameObject::UpdateIPO(float curframetime, // IPO update void KX_GameObject::UpdateMaterialData( + dword matname_hash, MT_Vector4 rgba, MT_Vector3 specrgb, MT_Scalar hard, @@ -443,16 +453,35 @@ KX_GameObject::UpdateMaterialData( ) { int mesh = 0; + if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0) { RAS_MaterialBucket::Set::iterator mit = m_meshes[mesh]->GetFirstMaterial(); for(; mit != m_meshes[mesh]->GetLastMaterial(); ++mit) { RAS_IPolyMaterial* poly = (*mit)->GetPolyMaterial(); - if(poly->GetFlag() & RAS_BLENDERMAT ) + if(poly->GetFlag() & RAS_BLENDERMAT) { - SetObjectColor(rgba); KX_BlenderMaterial *m = static_cast<KX_BlenderMaterial*>(poly); - m->UpdateIPO(rgba, specrgb,hard,spec,ref,emit, alpha); + + if (matname_hash == NULL) + { + m->UpdateIPO(rgba, specrgb,hard,spec,ref,emit, alpha); + // if mesh has only one material attached to it then use original hack with no need to edit vertices (better performance) + if(!(poly->GetFlag() & RAS_BLENDERGLSL)) + SetObjectColor(rgba); + } + else + { + if (matname_hash == poly->GetMaterialNameHash()) + { + m->UpdateIPO(rgba, specrgb,hard,spec,ref,emit, alpha); + m_meshes[mesh]->SetVertexColor(poly,rgba); + + // no break here, because one blender material can be split into several game engine materials + // (e.g. one uvsphere material is split into one material at poles with ras_mode TRIANGLE and one material for the body + // if here was a break then would miss some vertices if material was split + } + } } } } @@ -714,8 +743,12 @@ MT_Vector3 KX_GameObject::GetAngularVelocity(bool local) void KX_GameObject::NodeSetLocalPosition(const MT_Point3& trans) { - if (m_pPhysicsController1) + if (m_pPhysicsController1 && (!GetSGNode() || !GetSGNode()->GetSGParent())) { + // don't update physic controller if the object is a child: + // 1) the transformation will not be right + // 2) in this case, the physic controller is necessarily a static object + // that is updated from the normal kinematic synchronization m_pPhysicsController1->setPosition(trans); } @@ -727,25 +760,22 @@ void KX_GameObject::NodeSetLocalPosition(const MT_Point3& trans) void KX_GameObject::NodeSetLocalOrientation(const MT_Matrix3x3& rot) { - if (m_pPhysicsController1) + if (m_pPhysicsController1 && (!GetSGNode() || !GetSGNode()->GetSGParent())) { - m_pPhysicsController1->setOrientation(rot.getRotation()); + // see note above + m_pPhysicsController1->setOrientation(rot); } if (GetSGNode()) GetSGNode()->SetLocalOrientation(rot); - else - { - int i; - i=0; - } } void KX_GameObject::NodeSetLocalScale(const MT_Vector3& scale) { - if (m_pPhysicsController1) + if (m_pPhysicsController1 && (!GetSGNode() || !GetSGNode()->GetSGParent())) { + // see note above m_pPhysicsController1->setScaling(scale); } @@ -832,7 +862,7 @@ void KX_GameObject::Resume(void) } } -void KX_GameObject::Suspend(void) +void KX_GameObject::Suspend() { if ((!m_ignore_activity_culling) && (!m_suspended)) { @@ -875,6 +905,8 @@ PyMethodDef KX_GameObject::Methods[] = { {"getParent", (PyCFunction)KX_GameObject::sPyGetParent,METH_NOARGS}, {"setParent", (PyCFunction)KX_GameObject::sPySetParent,METH_O}, {"removeParent", (PyCFunction)KX_GameObject::sPyRemoveParent,METH_NOARGS}, + {"getChildren", (PyCFunction)KX_GameObject::sPyGetChildren,METH_NOARGS}, + {"getChildrenRecursive", (PyCFunction)KX_GameObject::sPyGetChildrenRecursive,METH_NOARGS}, {"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS}, {"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_NOARGS}, {"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS}, @@ -882,6 +914,7 @@ PyMethodDef KX_GameObject::Methods[] = { KX_PYMETHODTABLE(KX_GameObject, rayCastTo), KX_PYMETHODTABLE(KX_GameObject, rayCast), KX_PYMETHODTABLE(KX_GameObject, getDistanceTo), + KX_PYMETHODTABLE(KX_GameObject, getVectTo), {NULL,NULL} //Sentinel }; @@ -1292,20 +1325,58 @@ PyObject* KX_GameObject::PyRemoveParent(PyObject* self) Py_RETURN_NONE; } + +static void walk_children(SG_Node* node, CListValue* list, bool recursive) +{ + NodeList& children = node->GetSGChildren(); + + for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) + { + SG_Node* childnode = (*childit); + CValue* childobj = (CValue*)childnode->GetSGClientObject(); + if (childobj != NULL) // This is a GameObject + { + // add to the list + list->Add(childobj->AddRef()); + } + + // if the childobj is NULL then this may be an inverse parent link + // so a non recursive search should still look down this node. + if (recursive || childobj==NULL) { + walk_children(childnode, list, recursive); + } + } +} + +PyObject* KX_GameObject::PyGetChildren(PyObject* self) +{ + CListValue* list = new CListValue(); + walk_children(m_pSGNode, list, 0); + return list; +} + +PyObject* KX_GameObject::PyGetChildrenRecursive(PyObject* self) +{ + CListValue* list = new CListValue(); + walk_children(m_pSGNode, list, 1); + return list; +} + PyObject* KX_GameObject::PyGetMesh(PyObject* self, PyObject* args, PyObject* kwds) { int mesh = 0; - if (PyArg_ParseTuple(args, "|i", &mesh)) + if (!PyArg_ParseTuple(args, "|i", &mesh)) + return NULL; // python sets a simple error + + if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0) { - if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0) - { - KX_MeshProxy* meshproxy = new KX_MeshProxy(m_meshes[mesh]); - return meshproxy; - } + KX_MeshProxy* meshproxy = new KX_MeshProxy(m_meshes[mesh]); + return meshproxy; } + Py_RETURN_NONE; } @@ -1420,6 +1491,7 @@ PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* self, if (PyVecTo(pyvect, vect)) { AlignAxisToVect(vect,axis,fac); + NodeUpdateGS(0.f,true); Py_RETURN_NONE; } } @@ -1485,6 +1557,54 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getDistanceTo, return NULL; } +KX_PYMETHODDEF_DOC(KX_GameObject, getVectTo, +"getVectTo(other): get vector and the distance to another point/KX_GameObject\n" +"Returns a 3-tuple with (distance,worldVector,localVector)\n") +{ + MT_Point3 toPoint, fromPoint; + MT_Vector3 toDir, locToDir; + MT_Scalar distance; + + PyObject *returnValue; + PyObject *pyother; + + if (!PyVecArgTo(args, toPoint)) + { + PyErr_Clear(); + if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &pyother)) + { + KX_GameObject *other = static_cast<KX_GameObject*>(pyother); + toPoint = other->NodeGetWorldPosition(); + }else + { + PyErr_SetString(PyExc_TypeError, "Expected a 3D Vector or GameObject type"); + return NULL; + } + } + + fromPoint = NodeGetWorldPosition(); + toDir = toPoint-fromPoint; + distance = toDir.length(); + + if (MT_fuzzyZero(distance)) + { + //cout << "getVectTo() Error: Null vector!\n"; + locToDir = toDir = MT_Vector3(0.0,0.0,0.0); + distance = 0.0; + } else { + toDir.normalize(); + locToDir = toDir * NodeGetWorldOrientation(); + } + + returnValue = PyTuple_New(3); + if (returnValue) { // very unlikely to fail, python sets a memory error here. + PyTuple_SET_ITEM(returnValue, 0, PyFloat_FromDouble(distance)); + PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(toDir)); + PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(locToDir)); + } + return returnValue; +} + bool KX_GameObject::RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data) { @@ -1517,8 +1637,9 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo, float dist = 0.0f; char *propName = NULL; - if (!PyArg_ParseTuple(args,"O|fs", &pyarg, &dist, &propName)) - return NULL; + if (!PyArg_ParseTuple(args,"O|fs", &pyarg, &dist, &propName)) { + return NULL; // python sets simple error + } if (!PyVecTo(pyarg, toPoint)) { @@ -1565,11 +1686,11 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo, } KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, -"rayCast(to,from,dist,prop): cast a ray and return tuple (object,hit,normal) of contact point with object within dist that matches prop or None if no hit\n" + "rayCast(to,from,dist,prop): cast a ray and return tuple (object,hit,normal) of contact point with object within dist that matches prop or (None,None,None) tuple if no hit\n" " prop = property name that object must have; can be omitted => detect any object\n" " dist = max distance to look (can be negative => look behind); 0 or omitted => detect up to to\n" " from = 3-tuple or object reference for origin of ray (if object, use center of object)\n" -" Can None or omitted => start from self object center\n" +" Can be None or omitted => start from self object center\n" " to = 3-tuple or object reference for destination of ray (if object, use center of object)\n" "Note: the object on which you call this method matters: the ray will ignore it if it goes through it\n") { @@ -1581,8 +1702,9 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, char *propName = NULL; KX_GameObject *other; - if (!PyArg_ParseTuple(args,"O|Ofs", &pyto, &pyfrom, &dist, &propName)) - return NULL; + if (!PyArg_ParseTuple(args,"O|Ofs", &pyto, &pyfrom, &dist, &propName)) { + return NULL; // Python sets a simple error + } if (!PyVecTo(pyto, toPoint)) { @@ -1640,16 +1762,12 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, if (m_pHitObject) { PyObject* returnValue = PyTuple_New(3); - if (!returnValue) - return NULL; - PyTuple_SET_ITEM(returnValue, 0, m_pHitObject->AddRef()); - PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(resultPoint)); - PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(resultNormal)); + if (returnValue) { // unlikely this would ever fail, if it does python sets an error + PyTuple_SET_ITEM(returnValue, 0, m_pHitObject->AddRef()); + PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(resultPoint)); + PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(resultNormal)); + } return returnValue; - //return Py_BuildValue("(O,(fff),(fff))", - // m_pHitObject->AddRef(), // trick: KX_GameObject are not true Python object, they use a difference reference count system - // resultPoint[0], resultPoint[1], resultPoint[2], - // resultNormal[0], resultNormal[1], resultNormal[2]); } return Py_BuildValue("OOO", Py_None, Py_None, Py_None); //Py_RETURN_NONE; @@ -1660,6 +1778,20 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, * --------------------------------------------------------------------- */ void KX_GameObject::Relink(GEN_Map<GEN_HashedPtr, void*> *map_parameter) { - /* intentionally empty ? */ + // we will relink the sensors and actuators that use object references + // if the object is part of the replicated hierarchy, use the new + // object reference instead + SCA_SensorList& sensorlist = GetSensors(); + SCA_SensorList::iterator sit; + for (sit=sensorlist.begin(); sit != sensorlist.end(); sit++) + { + (*sit)->Relink(map_parameter); + } + SCA_ActuatorList& actuatorlist = GetActuators(); + SCA_ActuatorList::iterator ait; + for (ait=actuatorlist.begin(); ait != actuatorlist.end(); ait++) + { + (*ait)->Relink(map_parameter); + } } diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index ddbf863aa1a..4e435e9ddf4 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -47,6 +47,7 @@ #include "KX_Scene.h" #include "KX_KetsjiEngine.h" /* for m_anim_framerate */ #include "KX_IPhysicsController.h" /* for suspend/resume */ +#include "DNA_object_types.h" #define KX_OB_DYNAMIC 1 @@ -392,6 +393,13 @@ public: m_pBlenderObject = obj; } + bool IsDupliGroup() + { + return (m_pBlenderObject && + (m_pBlenderObject->transflag & OB_DUPLIGROUP) && + m_pBlenderObject->dup_group != NULL) ? true : false; + } + /** * Set the Scene graph node for this game object. * warning - it is your responsibility to make sure @@ -513,6 +521,7 @@ public: */ void UpdateMaterialData( + dword matname_hash, MT_Vector4 rgba, MT_Vector3 specrgb, MT_Scalar hard, @@ -738,6 +747,8 @@ public: KX_PYMETHOD_NOARGS(KX_GameObject,GetParent); KX_PYMETHOD_O(KX_GameObject,SetParent); KX_PYMETHOD_NOARGS(KX_GameObject,RemoveParent); + KX_PYMETHOD_NOARGS(KX_GameObject,GetChildren); + KX_PYMETHOD_NOARGS(KX_GameObject,GetChildrenRecursive); KX_PYMETHOD(KX_GameObject,GetMesh); KX_PYMETHOD_NOARGS(KX_GameObject,GetPhysicsId); KX_PYMETHOD_NOARGS(KX_GameObject,GetPropertyNames); @@ -745,6 +756,7 @@ public: KX_PYMETHOD_DOC(KX_GameObject,rayCastTo); KX_PYMETHOD_DOC(KX_GameObject,rayCast); KX_PYMETHOD_DOC(KX_GameObject,getDistanceTo); + KX_PYMETHOD_DOC(KX_GameObject,getVectTo); private : diff --git a/source/gameengine/Ketsji/KX_IPhysicsController.h b/source/gameengine/Ketsji/KX_IPhysicsController.h index 2ec66a883eb..ecfdb8c4275 100644 --- a/source/gameengine/Ketsji/KX_IPhysicsController.h +++ b/source/gameengine/Ketsji/KX_IPhysicsController.h @@ -71,14 +71,15 @@ public: virtual void resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ) = 0; virtual void getOrientation(MT_Quaternion& orn)=0; - virtual void setOrientation(const MT_Quaternion& orn)=0; + virtual void setOrientation(const MT_Matrix3x3& orn)=0; + //virtual void setOrientation(const MT_Quaternion& orn)=0; virtual void setPosition(const MT_Point3& pos)=0; virtual void setScaling(const MT_Vector3& scaling)=0; virtual MT_Scalar GetMass()=0; virtual MT_Vector3 getReactionForce()=0; virtual void setRigidBody(bool rigid)=0; - virtual void SuspendDynamics()=0; + virtual void SuspendDynamics(bool ghost=false)=0; virtual void RestoreDynamics()=0; virtual SG_Controller* GetReplica(class SG_Node* destnode)=0; diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index b7103f49aee..af3add8a323 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -430,27 +430,27 @@ PyMethodDef KX_IpoActuator::Methods[] = { {"setStart", (PyCFunction) KX_IpoActuator::sPySetStart, METH_VARARGS, SetStart_doc}, {"getStart", (PyCFunction) KX_IpoActuator::sPyGetStart, - METH_VARARGS, GetStart_doc}, + METH_NOARGS, GetStart_doc}, {"setEnd", (PyCFunction) KX_IpoActuator::sPySetEnd, METH_VARARGS, SetEnd_doc}, {"getEnd", (PyCFunction) KX_IpoActuator::sPyGetEnd, - METH_VARARGS, GetEnd_doc}, + METH_NOARGS, GetEnd_doc}, {"setIpoAsForce", (PyCFunction) KX_IpoActuator::sPySetIpoAsForce, METH_VARARGS, SetIpoAsForce_doc}, {"getIpoAsForce", (PyCFunction) KX_IpoActuator::sPyGetIpoAsForce, - METH_VARARGS, GetIpoAsForce_doc}, + METH_NOARGS, GetIpoAsForce_doc}, {"setIpoAdd", (PyCFunction) KX_IpoActuator::sPySetIpoAdd, METH_VARARGS, SetIpoAdd_doc}, {"getIpoAdd", (PyCFunction) KX_IpoActuator::sPyGetIpoAdd, - METH_VARARGS, GetIpoAdd_doc}, + METH_NOARGS, GetIpoAdd_doc}, {"setType", (PyCFunction) KX_IpoActuator::sPySetType, METH_VARARGS, SetType_doc}, {"getType", (PyCFunction) KX_IpoActuator::sPyGetType, - METH_VARARGS, GetType_doc}, + METH_NOARGS, GetType_doc}, {"setForceIpoActsLocal", (PyCFunction) KX_IpoActuator::sPySetForceIpoActsLocal, METH_VARARGS, SetForceIpoActsLocal_doc}, {"getForceIpoActsLocal", (PyCFunction) KX_IpoActuator::sPyGetForceIpoActsLocal, - METH_VARARGS, GetForceIpoActsLocal_doc}, + METH_NOARGS, GetForceIpoActsLocal_doc}, {NULL,NULL} //Sentinel }; @@ -480,6 +480,7 @@ PyObject* KX_IpoActuator::PySet(PyObject* self, int startFrame, stopFrame; if(!PyArg_ParseTuple(args, "siii", &mode, &startFrame, &stopFrame, &forceToggle)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } modenum = string2mode(mode); @@ -515,6 +516,7 @@ PyObject* KX_IpoActuator::PySetProperty(PyObject* self, /* args: property */ char *propertyName; if(!PyArg_ParseTuple(args, "s", &propertyName)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -533,6 +535,7 @@ PyObject* KX_IpoActuator::PySetStart(PyObject* self, PyObject* kwds) { float startArg; if(!PyArg_ParseTuple(args, "f", &startArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -544,9 +547,7 @@ PyObject* KX_IpoActuator::PySetStart(PyObject* self, char KX_IpoActuator::GetStart_doc[] = "getStart()\n" "\tReturns the frame from which the ipo starts playing.\n"; -PyObject* KX_IpoActuator::PyGetStart(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PyGetStart(PyObject* self) { return PyFloat_FromDouble(m_startframe); } @@ -560,6 +561,7 @@ PyObject* KX_IpoActuator::PySetEnd(PyObject* self, PyObject* kwds) { float endArg; if(!PyArg_ParseTuple(args, "f", &endArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -571,9 +573,7 @@ PyObject* KX_IpoActuator::PySetEnd(PyObject* self, char KX_IpoActuator::GetEnd_doc[] = "getEnd()\n" "\tReturns the frame at which the ipo stops playing.\n"; -PyObject* KX_IpoActuator::PyGetEnd(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PyGetEnd(PyObject* self) { return PyFloat_FromDouble(m_endframe); } @@ -588,6 +588,7 @@ PyObject* KX_IpoActuator::PySetIpoAsForce(PyObject* self, int boolArg; if (!PyArg_ParseTuple(args, "i", &boolArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -601,9 +602,7 @@ PyObject* KX_IpoActuator::PySetIpoAsForce(PyObject* self, char KX_IpoActuator::GetIpoAsForce_doc[] = "getIpoAsForce()\n" "\tReturns whether to interpret the ipo as a force rather than a displacement.\n"; -PyObject* KX_IpoActuator::PyGetIpoAsForce(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PyGetIpoAsForce(PyObject* self) { return BoolToPyArg(m_ipo_as_force); } @@ -618,6 +617,7 @@ PyObject* KX_IpoActuator::PySetIpoAdd(PyObject* self, int boolArg; if (!PyArg_ParseTuple(args, "i", &boolArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -631,9 +631,7 @@ PyObject* KX_IpoActuator::PySetIpoAdd(PyObject* self, char KX_IpoActuator::GetIpoAdd_doc[] = "getIpoAsAdd()\n" "\tReturns whether to interpret the ipo as additive rather than absolute.\n"; -PyObject* KX_IpoActuator::PyGetIpoAdd(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PyGetIpoAdd(PyObject* self) { return BoolToPyArg(m_ipo_add); } @@ -648,6 +646,7 @@ PyObject* KX_IpoActuator::PySetType(PyObject* self, int typeArg; if (!PyArg_ParseTuple(args, "i", &typeArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -662,9 +661,7 @@ PyObject* KX_IpoActuator::PySetType(PyObject* self, char KX_IpoActuator::GetType_doc[] = "getType()\n" "\tReturns the operation mode of the actuator.\n"; -PyObject* KX_IpoActuator::PyGetType(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PyGetType(PyObject* self) { return PyInt_FromLong(m_type); } @@ -681,6 +678,7 @@ PyObject* KX_IpoActuator::PySetForceIpoActsLocal(PyObject* self, int boolArg; if (!PyArg_ParseTuple(args, "i", &boolArg)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } @@ -693,9 +691,7 @@ char KX_IpoActuator::GetForceIpoActsLocal_doc[] = "getForceIpoActsLocal()\n" "\tReturn whether to apply the force in the object's local\n" "\tcoordinates rather than the world global coordinates.\n"; -PyObject* KX_IpoActuator::PyGetForceIpoActsLocal(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_IpoActuator::PyGetForceIpoActsLocal(PyObject* self) { return BoolToPyArg(m_ipo_local); } diff --git a/source/gameengine/Ketsji/KX_IpoActuator.h b/source/gameengine/Ketsji/KX_IpoActuator.h index ae554fb0fce..d6f52f8d59d 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.h +++ b/source/gameengine/Ketsji/KX_IpoActuator.h @@ -143,17 +143,17 @@ public: KX_PYMETHOD_DOC(KX_IpoActuator,SetProperty); /* KX_PYMETHOD_DOC(KX_IpoActuator,SetKey2Key); */ KX_PYMETHOD_DOC(KX_IpoActuator,SetStart); - KX_PYMETHOD_DOC(KX_IpoActuator,GetStart); + KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetStart); KX_PYMETHOD_DOC(KX_IpoActuator,SetEnd); - KX_PYMETHOD_DOC(KX_IpoActuator,GetEnd); + KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetEnd); KX_PYMETHOD_DOC(KX_IpoActuator,SetIpoAsForce); - KX_PYMETHOD_DOC(KX_IpoActuator,GetIpoAsForce); + KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetIpoAsForce); KX_PYMETHOD_DOC(KX_IpoActuator,SetIpoAdd); - KX_PYMETHOD_DOC(KX_IpoActuator,GetIpoAdd); + KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetIpoAdd); KX_PYMETHOD_DOC(KX_IpoActuator,SetType); - KX_PYMETHOD_DOC(KX_IpoActuator,GetType); + KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetType); KX_PYMETHOD_DOC(KX_IpoActuator,SetForceIpoActsLocal); - KX_PYMETHOD_DOC(KX_IpoActuator,GetForceIpoActsLocal); + KX_PYMETHOD_DOC_NOARGS(KX_IpoActuator,GetForceIpoActsLocal); }; diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index db099d56b55..1d6cc975ab5 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -118,7 +118,6 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system) m_bInitialized(false), m_activecam(0), m_bFixedTime(false), - m_game2ipo(false), m_firstframe(true), @@ -148,6 +147,8 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system) m_showBackground(false), m_show_debug_properties(false), + m_game2ipo(false), + // Default behavior is to hide the cursor every frame. m_hideCursor(false), diff --git a/source/gameengine/Ketsji/KX_MaterialIpoController.cpp b/source/gameengine/Ketsji/KX_MaterialIpoController.cpp index c0757a32b9c..2ce5d469380 100644 --- a/source/gameengine/Ketsji/KX_MaterialIpoController.cpp +++ b/source/gameengine/Ketsji/KX_MaterialIpoController.cpp @@ -37,6 +37,7 @@ bool KX_MaterialIpoController::Update(double currentTime) //kxgameobj->SetObjectColor(m_rgba); kxgameobj->UpdateMaterialData( + m_matname_hash, m_rgba, m_specrgb, m_hard, diff --git a/source/gameengine/Ketsji/KX_MaterialIpoController.h b/source/gameengine/Ketsji/KX_MaterialIpoController.h index e76ddeefb04..4d2e258bf94 100644 --- a/source/gameengine/Ketsji/KX_MaterialIpoController.h +++ b/source/gameengine/Ketsji/KX_MaterialIpoController.h @@ -7,6 +7,8 @@ #include "SG_Spatial.h" #include "KX_IInterpolator.h" +#include "STR_String.h" //typedef dword + class KX_MaterialIpoController : public SG_Controller { public: @@ -23,10 +25,12 @@ private: bool m_modified; double m_ipotime; + dword m_matname_hash; public: - KX_MaterialIpoController() : + KX_MaterialIpoController(dword matname_hash) : m_modified(true), - m_ipotime(0.0) + m_ipotime(0.0), + m_matname_hash(matname_hash) {} virtual ~KX_MaterialIpoController(); virtual SG_Controller* GetReplica(class SG_Node* destnode); diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index d69871275b9..140dd37f5c6 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -98,6 +98,14 @@ void KX_NearSensor::RegisterSumo(KX_TouchEventManager *touchman) } } +void KX_NearSensor::UnregisterSumo(KX_TouchEventManager* touchman) +{ + if (m_physCtrl) + { + touchman->GetPhysicsEnvironment()->removeSensor(m_physCtrl); + } +} + CValue* KX_NearSensor::GetReplica() { KX_NearSensor* replica = new KX_NearSensor(*this); @@ -135,9 +143,6 @@ CValue* KX_NearSensor::GetReplica() void KX_NearSensor::ReParent(SCA_IObject* parent) { - - SCA_ISensor::ReParent(parent); - m_client_info->m_gameobject = static_cast<KX_GameObject*>(parent); m_client_info->m_sensors.push_back(this); @@ -151,6 +156,7 @@ void KX_NearSensor::ReParent(SCA_IObject* parent) */ ((KX_GameObject*)GetParent())->GetSGNode()->ComputeWorldTransforms(NULL); SynchronizeTransform(); + SCA_ISensor::ReParent(parent); } diff --git a/source/gameengine/Ketsji/KX_NearSensor.h b/source/gameengine/Ketsji/KX_NearSensor.h index c6724caccc3..3f7078ef9fd 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.h +++ b/source/gameengine/Ketsji/KX_NearSensor.h @@ -77,6 +77,7 @@ public: const PHY_CollData * coll_data); virtual bool BroadPhaseFilterCollision(void*obj1,void*obj2); virtual void RegisterSumo(KX_TouchEventManager *touchman); + virtual void UnregisterSumo(KX_TouchEventManager* touchman); virtual PyObject* _getattr(const STR_String& attr); diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp index 9ac0b4d4703..5cd4d089c14 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_ObjectActuator.cpp @@ -304,27 +304,27 @@ PyParentObject KX_ObjectActuator::Parents[] = { }; PyMethodDef KX_ObjectActuator::Methods[] = { - {"getForce", (PyCFunction) KX_ObjectActuator::sPyGetForce, METH_VARARGS}, + {"getForce", (PyCFunction) KX_ObjectActuator::sPyGetForce, METH_NOARGS}, {"setForce", (PyCFunction) KX_ObjectActuator::sPySetForce, METH_VARARGS}, - {"getTorque", (PyCFunction) KX_ObjectActuator::sPyGetTorque, METH_VARARGS}, + {"getTorque", (PyCFunction) KX_ObjectActuator::sPyGetTorque, METH_NOARGS}, {"setTorque", (PyCFunction) KX_ObjectActuator::sPySetTorque, METH_VARARGS}, - {"getDLoc", (PyCFunction) KX_ObjectActuator::sPyGetDLoc, METH_VARARGS}, + {"getDLoc", (PyCFunction) KX_ObjectActuator::sPyGetDLoc, METH_NOARGS}, {"setDLoc", (PyCFunction) KX_ObjectActuator::sPySetDLoc, METH_VARARGS}, - {"getDRot", (PyCFunction) KX_ObjectActuator::sPyGetDRot, METH_VARARGS}, + {"getDRot", (PyCFunction) KX_ObjectActuator::sPyGetDRot, METH_NOARGS}, {"setDRot", (PyCFunction) KX_ObjectActuator::sPySetDRot, METH_VARARGS}, - {"getLinearVelocity", (PyCFunction) KX_ObjectActuator::sPyGetLinearVelocity, METH_VARARGS}, + {"getLinearVelocity", (PyCFunction) KX_ObjectActuator::sPyGetLinearVelocity, METH_NOARGS}, {"setLinearVelocity", (PyCFunction) KX_ObjectActuator::sPySetLinearVelocity, METH_VARARGS}, - {"getAngularVelocity", (PyCFunction) KX_ObjectActuator::sPyGetAngularVelocity, METH_VARARGS}, + {"getAngularVelocity", (PyCFunction) KX_ObjectActuator::sPyGetAngularVelocity, METH_NOARGS}, {"setAngularVelocity", (PyCFunction) KX_ObjectActuator::sPySetAngularVelocity, METH_VARARGS}, {"setDamping", (PyCFunction) KX_ObjectActuator::sPySetDamping, METH_VARARGS}, - {"getDamping", (PyCFunction) KX_ObjectActuator::sPyGetDamping, METH_VARARGS}, + {"getDamping", (PyCFunction) KX_ObjectActuator::sPyGetDamping, METH_NOARGS}, {"setForceLimitX", (PyCFunction) KX_ObjectActuator::sPySetForceLimitX, METH_VARARGS}, - {"getForceLimitX", (PyCFunction) KX_ObjectActuator::sPyGetForceLimitX, METH_VARARGS}, + {"getForceLimitX", (PyCFunction) KX_ObjectActuator::sPyGetForceLimitX, METH_NOARGS}, {"setForceLimitY", (PyCFunction) KX_ObjectActuator::sPySetForceLimitY, METH_VARARGS}, - {"getForceLimitY", (PyCFunction) KX_ObjectActuator::sPyGetForceLimitY, METH_VARARGS}, + {"getForceLimitY", (PyCFunction) KX_ObjectActuator::sPyGetForceLimitY, METH_NOARGS}, {"setForceLimitZ", (PyCFunction) KX_ObjectActuator::sPySetForceLimitZ, METH_VARARGS}, - {"getForceLimitZ", (PyCFunction) KX_ObjectActuator::sPyGetForceLimitZ, METH_VARARGS}, - {"setPID", (PyCFunction) KX_ObjectActuator::sPyGetPID, METH_VARARGS}, + {"getForceLimitZ", (PyCFunction) KX_ObjectActuator::sPyGetForceLimitZ, METH_NOARGS}, + {"setPID", (PyCFunction) KX_ObjectActuator::sPyGetPID, METH_NOARGS}, {"getPID", (PyCFunction) KX_ObjectActuator::sPySetPID, METH_VARARGS}, @@ -340,9 +340,7 @@ PyObject* KX_ObjectActuator::_getattr(const STR_String& attr) { /* Removed! */ /* 2. getForce */ -PyObject* KX_ObjectActuator::PyGetForce(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PyGetForce(PyObject* self) { PyObject *retVal = PyList_New(4); @@ -362,6 +360,7 @@ PyObject* KX_ObjectActuator::PySetForce(PyObject* self, int bToggle = 0; if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } m_force.setValue(vecArg); @@ -371,9 +370,7 @@ PyObject* KX_ObjectActuator::PySetForce(PyObject* self, } /* 4. getTorque */ -PyObject* KX_ObjectActuator::PyGetTorque(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PyGetTorque(PyObject* self) { PyObject *retVal = PyList_New(4); @@ -393,6 +390,7 @@ PyObject* KX_ObjectActuator::PySetTorque(PyObject* self, int bToggle = 0; if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } m_torque.setValue(vecArg); @@ -402,9 +400,7 @@ PyObject* KX_ObjectActuator::PySetTorque(PyObject* self, } /* 6. getDLoc */ -PyObject* KX_ObjectActuator::PyGetDLoc(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PyGetDLoc(PyObject* self) { PyObject *retVal = PyList_New(4); @@ -424,6 +420,7 @@ PyObject* KX_ObjectActuator::PySetDLoc(PyObject* self, int bToggle = 0; if(!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } m_dloc.setValue(vecArg); @@ -433,9 +430,7 @@ PyObject* KX_ObjectActuator::PySetDLoc(PyObject* self, } /* 8. getDRot */ -PyObject* KX_ObjectActuator::PyGetDRot(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PyGetDRot(PyObject* self) { PyObject *retVal = PyList_New(4); @@ -455,6 +450,7 @@ PyObject* KX_ObjectActuator::PySetDRot(PyObject* self, int bToggle = 0; if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } m_drot.setValue(vecArg); @@ -464,9 +460,7 @@ PyObject* KX_ObjectActuator::PySetDRot(PyObject* self, } /* 10. getLinearVelocity */ -PyObject* KX_ObjectActuator::PyGetLinearVelocity(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ObjectActuator::PyGetLinearVelocity(PyObject* self) { PyObject *retVal = PyList_New(4); PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_linear_velocity[0])); @@ -485,6 +479,7 @@ PyObject* KX_ObjectActuator::PySetLinearVelocity(PyObject* self, int bToggle = 0; if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } m_linear_velocity.setValue(vecArg); @@ -495,9 +490,7 @@ PyObject* KX_ObjectActuator::PySetLinearVelocity(PyObject* self, /* 12. getAngularVelocity */ -PyObject* KX_ObjectActuator::PyGetAngularVelocity(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ObjectActuator::PyGetAngularVelocity(PyObject* self) { PyObject *retVal = PyList_New(4); PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_angular_velocity[0])); @@ -515,6 +508,7 @@ PyObject* KX_ObjectActuator::PySetAngularVelocity(PyObject* self, int bToggle = 0; if (!PyArg_ParseTuple(args, "fffi", &vecArg[0], &vecArg[1], &vecArg[2], &bToggle)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } m_angular_velocity.setValue(vecArg); @@ -529,6 +523,7 @@ PyObject* KX_ObjectActuator::PySetDamping(PyObject* self, PyObject* kwds) { int damping = 0; if (!PyArg_ParseTuple(args, "i", &damping) || damping < 0 || damping > 1000) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } m_damping = damping; @@ -536,15 +531,11 @@ PyObject* KX_ObjectActuator::PySetDamping(PyObject* self, } /* 13. getVelocityDamping */ -PyObject* KX_ObjectActuator::PyGetDamping(PyObject* self, - PyObject* args, - PyObject* kwds) { +PyObject* KX_ObjectActuator::PyGetDamping(PyObject* self) { return Py_BuildValue("i",m_damping); } /* 6. getForceLimitX */ -PyObject* KX_ObjectActuator::PyGetForceLimitX(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PyGetForceLimitX(PyObject* self) { PyObject *retVal = PyList_New(3); @@ -562,6 +553,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitX(PyObject* self, float vecArg[2]; int bToggle = 0; if(!PyArg_ParseTuple(args, "ffi", &vecArg[0], &vecArg[1], &bToggle)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } m_drot[0] = vecArg[0]; @@ -571,9 +563,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitX(PyObject* self, } /* 6. getForceLimitY */ -PyObject* KX_ObjectActuator::PyGetForceLimitY(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PyGetForceLimitY(PyObject* self) { PyObject *retVal = PyList_New(3); @@ -591,6 +581,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitY(PyObject* self, float vecArg[2]; int bToggle = 0; if(!PyArg_ParseTuple(args, "ffi", &vecArg[0], &vecArg[1], &bToggle)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } m_drot[1] = vecArg[0]; @@ -600,9 +591,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitY(PyObject* self, } /* 6. getForceLimitZ */ -PyObject* KX_ObjectActuator::PyGetForceLimitZ(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PyGetForceLimitZ(PyObject* self) { PyObject *retVal = PyList_New(3); @@ -620,6 +609,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitZ(PyObject* self, float vecArg[2]; int bToggle = 0; if(!PyArg_ParseTuple(args, "ffi", &vecArg[0], &vecArg[1], &bToggle)) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } m_drot[2] = vecArg[0]; @@ -629,9 +619,7 @@ PyObject* KX_ObjectActuator::PySetForceLimitZ(PyObject* self, } /* 4. getPID */ -PyObject* KX_ObjectActuator::PyGetPID(PyObject* self, - PyObject* args, - PyObject* kwds) +PyObject* KX_ObjectActuator::PyGetPID(PyObject* self) { PyObject *retVal = PyList_New(3); @@ -648,6 +636,7 @@ PyObject* KX_ObjectActuator::PySetPID(PyObject* self, { float vecArg[3]; if (!PyArg_ParseTuple(args, "fff", &vecArg[0], &vecArg[1], &vecArg[2])) { + PyErr_SetString(PyExc_TypeError, "Invalid arguments"); return NULL; } m_torque.setValue(vecArg); diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.h b/source/gameengine/Ketsji/KX_ObjectActuator.h index bb74756551f..aa686f41233 100644 --- a/source/gameengine/Ketsji/KX_ObjectActuator.h +++ b/source/gameengine/Ketsji/KX_ObjectActuator.h @@ -155,27 +155,27 @@ public: virtual PyObject* _getattr(const STR_String& attr); - KX_PYMETHOD(KX_ObjectActuator,GetForce); + KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForce); KX_PYMETHOD(KX_ObjectActuator,SetForce); - KX_PYMETHOD(KX_ObjectActuator,GetTorque); + KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetTorque); KX_PYMETHOD(KX_ObjectActuator,SetTorque); - KX_PYMETHOD(KX_ObjectActuator,GetDLoc); + KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetDLoc); KX_PYMETHOD(KX_ObjectActuator,SetDLoc); - KX_PYMETHOD(KX_ObjectActuator,GetDRot); + KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetDRot); KX_PYMETHOD(KX_ObjectActuator,SetDRot); - KX_PYMETHOD(KX_ObjectActuator,GetLinearVelocity); + KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetLinearVelocity); KX_PYMETHOD(KX_ObjectActuator,SetLinearVelocity); - KX_PYMETHOD(KX_ObjectActuator,GetAngularVelocity); + KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetAngularVelocity); KX_PYMETHOD(KX_ObjectActuator,SetAngularVelocity); KX_PYMETHOD(KX_ObjectActuator,SetDamping); - KX_PYMETHOD(KX_ObjectActuator,GetDamping); - KX_PYMETHOD(KX_ObjectActuator,GetForceLimitX); + KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetDamping); + KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForceLimitX); KX_PYMETHOD(KX_ObjectActuator,SetForceLimitX); - KX_PYMETHOD(KX_ObjectActuator,GetForceLimitY); + KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForceLimitY); KX_PYMETHOD(KX_ObjectActuator,SetForceLimitY); - KX_PYMETHOD(KX_ObjectActuator,GetForceLimitZ); + KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForceLimitZ); KX_PYMETHOD(KX_ObjectActuator,SetForceLimitZ); - KX_PYMETHOD(KX_ObjectActuator,GetPID); + KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetPID); KX_PYMETHOD(KX_ObjectActuator,SetPID); }; diff --git a/source/gameengine/Ketsji/KX_OdePhysicsController.cpp b/source/gameengine/Ketsji/KX_OdePhysicsController.cpp index 4e45ce484e3..05feb11a2bc 100644 --- a/source/gameengine/Ketsji/KX_OdePhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_OdePhysicsController.cpp @@ -133,8 +133,9 @@ void KX_OdePhysicsController::SetLinearVelocity(const MT_Vector3& lin_vel,bool l ODEPhysicsController::SetLinearVelocity(lin_vel[0],lin_vel[1],lin_vel[2],local); } -void KX_OdePhysicsController::setOrientation(const MT_Quaternion& orn) +void KX_OdePhysicsController::setOrientation(const MT_Matrix3x3& rot) { + MT_Quaternion orn = rot.getRotation(); ODEPhysicsController::setOrientation(orn[0],orn[1],orn[2],orn[3]); } @@ -177,7 +178,7 @@ void KX_OdePhysicsController::setRigidBody(bool rigid) } -void KX_OdePhysicsController::SuspendDynamics() +void KX_OdePhysicsController::SuspendDynamics(bool) { ODEPhysicsController::SuspendDynamics(); } diff --git a/source/gameengine/Ketsji/KX_OdePhysicsController.h b/source/gameengine/Ketsji/KX_OdePhysicsController.h index 07a0bee9775..18f9edc6835 100644 --- a/source/gameengine/Ketsji/KX_OdePhysicsController.h +++ b/source/gameengine/Ketsji/KX_OdePhysicsController.h @@ -67,14 +67,14 @@ public: virtual void SetLinearVelocity(const MT_Vector3& lin_vel,bool local); virtual void resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ); virtual void getOrientation(MT_Quaternion& orn); - virtual void setOrientation(const MT_Quaternion& orn); + virtual void setOrientation(const MT_Matrix3x3& orn); virtual void setPosition(const MT_Point3& pos); virtual void setScaling(const MT_Vector3& scaling); virtual MT_Scalar GetMass(); virtual MT_Vector3 getReactionForce(); virtual void setRigidBody(bool rigid); - virtual void SuspendDynamics(); + virtual void SuspendDynamics(bool); virtual void RestoreDynamics(); diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index 8b379bcd44f..fd1b56838e2 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -46,19 +46,22 @@ KX_ParentActuator::KX_ParentActuator(SCA_IObject *gameobj, int mode, - CValue *ob, + SCA_IObject *ob, PyTypeObject* T) : SCA_IActuator(gameobj, T), m_mode(mode), m_ob(ob) { + if (m_ob) + m_ob->RegisterActuator(this); } KX_ParentActuator::~KX_ParentActuator() { - /* intentionally empty */ + if (m_ob) + m_ob->UnregisterActuator(this); } @@ -73,6 +76,36 @@ CValue* KX_ParentActuator::GetReplica() return replica; } +void KX_ParentActuator::ProcessReplica() +{ + if (m_ob) + m_ob->RegisterActuator(this); + SCA_IActuator::ProcessReplica(); +} + + +bool KX_ParentActuator::UnlinkObject(SCA_IObject* clientobj) +{ + if (clientobj == m_ob) + { + // this object is being deleted, we cannot continue to track it. + m_ob = NULL; + return true; + } + return false; +} + +void KX_ParentActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + void **h_obj = (*obj_map)[m_ob]; + if (h_obj) { + if (m_ob) + m_ob->UnregisterActuator(this); + m_ob = (SCA_IObject*)(*h_obj); + m_ob->RegisterActuator(this); + } +} + bool KX_ParentActuator::Update() @@ -87,7 +120,8 @@ bool KX_ParentActuator::Update() KX_Scene *scene = PHY_GetActiveScene(); switch (m_mode) { case KX_PARENT_SET: - obj->SetParent(scene, (KX_GameObject*)m_ob); + if (m_ob) + obj->SetParent(scene, (KX_GameObject*)m_ob); break; case KX_PARENT_REMOVE: obj->RemoveParent(scene); @@ -148,7 +182,11 @@ PyObject* KX_ParentActuator::PySetObject(PyObject* self, PyObject* args, PyObjec PyObject* gameobj; if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj)) { - m_ob = (CValue*)gameobj; + if (m_ob != NULL) + m_ob->UnregisterActuator(this); + m_ob = (SCA_IObject*)gameobj; + if (m_ob) + m_ob->RegisterActuator(this); Py_Return; } PyErr_Clear(); @@ -156,10 +194,13 @@ PyObject* KX_ParentActuator::PySetObject(PyObject* self, PyObject* args, PyObjec char* objectname; if (PyArg_ParseTuple(args, "s", &objectname)) { - CValue *object = (CValue*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname)); + SCA_IObject *object = (SCA_IObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname)); if(object) { + if (m_ob != NULL) + m_ob->UnregisterActuator(this); m_ob = object; + m_ob->RegisterActuator(this); Py_Return; } } diff --git a/source/gameengine/Ketsji/KX_ParentActuator.h b/source/gameengine/Ketsji/KX_ParentActuator.h index 86dcd4e6c12..93b07cd424b 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.h +++ b/source/gameengine/Ketsji/KX_ParentActuator.h @@ -47,7 +47,7 @@ class KX_ParentActuator : public SCA_IActuator int m_mode; /** Object to set as parent */ - CValue *m_ob; + SCA_IObject *m_ob; @@ -62,12 +62,15 @@ class KX_ParentActuator : public SCA_IActuator KX_ParentActuator(class SCA_IObject* gameobj, int mode, - CValue *ob, + SCA_IObject *ob, PyTypeObject* T=&Type); virtual ~KX_ParentActuator(); virtual bool Update(); virtual CValue* GetReplica(); + virtual void ProcessReplica(); + virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); + virtual bool UnlinkObject(SCA_IObject* clientobj); /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp index 93d6d5bb70d..144f74a1a4c 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp @@ -59,7 +59,8 @@ KX_PolygonMaterial::KX_PolygonMaterial(const STR_String &texname, int tilexrep, int tileyrep, int mode, - bool transparant, + int transp, + bool alpha, bool zsort, int lightlayer, bool bIsTriangle, @@ -74,7 +75,8 @@ KX_PolygonMaterial::KX_PolygonMaterial(const STR_String &texname, tilexrep, tileyrep, mode, - transparant, + transp, + alpha, zsort, lightlayer, bIsTriangle, @@ -245,7 +247,7 @@ PyObject* KX_PolygonMaterial::_getattr(const STR_String& attr) if (attr == "drawingmode") return PyInt_FromLong(m_drawingmode); if (attr == "transparent") - return PyInt_FromLong(m_transparant); + return PyInt_FromLong(m_alpha); if (attr == "zsort") return PyInt_FromLong(m_zsort); if (attr == "lightlayer") @@ -312,7 +314,7 @@ int KX_PolygonMaterial::_setattr(const STR_String &attr, PyObject *pyvalue) if (attr == "transparent") { - m_transparant = value; + m_alpha = value; return 0; } diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.h b/source/gameengine/Ketsji/KX_PolygonMaterial.h index 19015494e06..11c8baa8b1f 100644 --- a/source/gameengine/Ketsji/KX_PolygonMaterial.h +++ b/source/gameengine/Ketsji/KX_PolygonMaterial.h @@ -64,7 +64,8 @@ public: int tilexrep, int tileyrep, int mode, - bool transparant, + int transp, + bool alpha, bool zsort, int lightlayer, bool bIsTriangle, diff --git a/source/gameengine/Ketsji/KX_PyMath.h b/source/gameengine/Ketsji/KX_PyMath.h index e1715c9275f..4e383e9b3d4 100644 --- a/source/gameengine/Ketsji/KX_PyMath.h +++ b/source/gameengine/Ketsji/KX_PyMath.h @@ -84,7 +84,10 @@ bool PyMatTo(PyObject* pymat, T& mat) } } else noerror = false; - + + if (noerror==false) + PyErr_SetString(PyExc_TypeError, "could not be converted to a matrix (sequence of sequences)"); + return noerror; } @@ -97,9 +100,13 @@ bool PyVecTo(PyObject* pyval, T& vec) if (PySequence_Check(pyval)) { unsigned int numitems = PySequence_Size(pyval); - if (numitems != Size(vec)) + if (numitems != Size(vec)) { + char err[128]; + sprintf(err, "error setting vector, %d args, should be %d", numitems, Size(vec)); + PyErr_SetString(PyExc_AttributeError, err); return false; - + } + for (unsigned int x = 0; x < numitems; x++) { PyObject *item = PySequence_GetItem(pyval, x); /* new ref */ @@ -107,7 +114,17 @@ bool PyVecTo(PyObject* pyval, T& vec) Py_DECREF(item); } + if (PyErr_Occurred()) { + PyErr_SetString(PyExc_AttributeError, "one or more of the items in the sequence was not a float"); + return false; + } + return true; + } else + { + char err[128]; + sprintf(err, "not a sequence type, expected a sequence of numbers size %d", Size(vec)); + PyErr_SetString(PyExc_AttributeError, err); } return false; diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 61ed8b6a8e4..b66c3e42606 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -756,6 +756,15 @@ PyObject* initGameLogic(KX_Scene* scene) // quick hack to get gravity hook KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX); KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY); KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ); + KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX); + KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY); + KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY); + KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX); + KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY); + KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY); + KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX); + KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY); + KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ); /* 4. Ipo actuator, simple part */ KX_MACRO_addTypesToDict(d, KX_IPOACT_PLAY, KX_IpoActuator::KX_ACT_IPO_PLAY); diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index 987e0b946b2..de4979ac4c9 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -80,10 +80,7 @@ CValue* KX_RadarSensor::GetReplica() { KX_RadarSensor* replica = new KX_RadarSensor(*this); replica->m_colliders = new CListValue(); - replica->m_bCollision = false; - replica->m_bTriggered= false; - replica->m_hitObject = NULL; - replica->m_bLastTriggered = false; + replica->Init(); // this will copy properties and so on... CValue::AddDataToReplica(replica); @@ -92,6 +89,10 @@ CValue* KX_RadarSensor::GetReplica() if (replica->m_physCtrl) { replica->m_physCtrl = replica->m_physCtrl->GetReplica(); + if (replica->m_physCtrl) + { + replica->m_physCtrl->setNewClientInfo(replica->m_client_info); + } } //todo: make sure replication works fine! @@ -175,8 +176,10 @@ void KX_RadarSensor::SynchronizeTransform() if (m_physCtrl) { - m_physCtrl->setPosition(trans.getOrigin().x(),trans.getOrigin().y(),trans.getOrigin().z()); - m_physCtrl->setOrientation(trans.getRotation().x(),trans.getRotation().y(),trans.getRotation().z(),trans.getRotation().w()); + MT_Quaternion orn = trans.getRotation(); + MT_Point3 pos = trans.getOrigin(); + m_physCtrl->setPosition(pos[0],pos[1],pos[2]); + m_physCtrl->setOrientation(orn[0],orn[1],orn[2],orn[3]); m_physCtrl->calcXform(); } diff --git a/source/gameengine/Ketsji/KX_RayEventManager.cpp b/source/gameengine/Ketsji/KX_RayEventManager.cpp index 4101c6b547e..1af29151adf 100644 --- a/source/gameengine/Ketsji/KX_RayEventManager.cpp +++ b/source/gameengine/Ketsji/KX_RayEventManager.cpp @@ -44,14 +44,9 @@ using namespace std; void KX_RayEventManager::NextFrame() { - for (vector<class SCA_ISensor*>::const_iterator i= m_sensors.begin();!(i==m_sensors.end());i++) + for (set<class SCA_ISensor*>::const_iterator i= m_sensors.begin();!(i==m_sensors.end());i++) { - SCA_ISensor *sensor = *i; - sensor->Activate(m_logicmgr, NULL); + (*i)->Activate(m_logicmgr, NULL); } } -void KX_RayEventManager::RegisterSensor(SCA_ISensor* sensor) -{ - m_sensors.push_back(sensor); -}; diff --git a/source/gameengine/Ketsji/KX_RayEventManager.h b/source/gameengine/Ketsji/KX_RayEventManager.h index 3630f9682b9..b816d4d5250 100644 --- a/source/gameengine/Ketsji/KX_RayEventManager.h +++ b/source/gameengine/Ketsji/KX_RayEventManager.h @@ -45,7 +45,6 @@ public: m_logicmgr(logicmgr) {} virtual void NextFrame(); - virtual void RegisterSensor(SCA_ISensor* sensor); }; #endif //__KX_RAYEVENTMGR diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index e5ee4cbddf1..e36891b56f4 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -137,6 +137,17 @@ bool KX_SCA_AddObjectActuator::UnlinkObject(SCA_IObject* clientobj) return false; } +void KX_SCA_AddObjectActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + void **h_obj = (*obj_map)[m_OriginalObject]; + if (h_obj) { + if (m_OriginalObject) + m_OriginalObject->UnregisterActuator(this); + m_OriginalObject = (SCA_IObject*)(*h_obj); + m_OriginalObject->RegisterActuator(this); + } +} + /* ------------------------------------------------------------------------- */ /* Python functions */ diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h index 42123b94a68..1359f39278d 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h @@ -95,6 +95,9 @@ public: virtual bool UnlinkObject(SCA_IObject* clientobj); + virtual void + Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); + virtual bool Update(); diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 065800379d8..2828663c63d 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -37,6 +37,7 @@ #include "MT_assert.h" #include "KX_KetsjiEngine.h" +#include "KX_BlenderMaterial.h" #include "RAS_IPolygonMaterial.h" #include "ListValue.h" #include "SCA_LogicManager.h" @@ -66,6 +67,8 @@ #include "SG_Controller.h" #include "SG_IObject.h" #include "SG_Tree.h" +#include "DNA_group_types.h" +#include "BKE_anim.h" #include "KX_SG_NodeRelationships.h" @@ -90,6 +93,9 @@ void* KX_SceneReplicationFunc(SG_IObject* node,void* gameobj,void* scene) { KX_GameObject* replica = ((KX_Scene*)scene)->AddNodeReplicaObject(node,(KX_GameObject*)gameobj); + if(replica) + replica->Release(); + return (void*)replica; } @@ -114,13 +120,13 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, PyObjectPlus(&KX_Scene::Type), m_keyboardmgr(NULL), m_mousemgr(NULL), + m_sceneConverter(NULL), m_physicsEnvironment(0), m_sceneName(sceneName), m_adi(adi), m_networkDeviceInterface(ndi), m_active_camera(NULL), - m_ueberExecutionPriority(0), - m_sceneConverter(NULL) + m_ueberExecutionPriority(0) { m_suspendedtime = 0.0; m_suspendeddelta = 0.0; @@ -429,6 +435,11 @@ void KX_Scene::RemoveNodeDestructObject(class SG_IObject* node,class CValue* gam KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CValue* gameobj) { + // for group duplication, limit the duplication of the hierarchy to the + // objects that are part of the group. + if (!IsObjectInGroup(gameobj)) + return NULL; + KX_GameObject* orgobj = (KX_GameObject*)gameobj; KX_GameObject* newobj = (KX_GameObject*)orgobj->GetReplica(); m_map_gameobject_to_replica.insert(orgobj, newobj); @@ -506,6 +517,11 @@ KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CVal // hierarchy that's because first ALL bricks must exist in the new // replica of the hierarchy in order to make cross-links work properly // ! +// It is VERY important that the order of sensors and actuators in +// the replicated object is preserved: it is is used to reconnect the logic. +// This method is more robust then using the bricks name in case of complex +// group replication. The replication of logic bricks is done in +// SCA_IObject::ReParentLogic(), make sure it preserves the order of the bricks. void KX_Scene::ReplicateLogic(KX_GameObject* newobj) { // also relink the controller to sensors/actuators @@ -528,37 +544,38 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj) for (vector<SCA_ISensor*>::iterator its = linkedsensors.begin();!(its==linkedsensors.end());its++) { SCA_ISensor* oldsensor = (*its); - STR_String name = oldsensor->GetName(); - //find this name in the list - SCA_ISensor* newsensor = newobj->FindSensor(name); + SCA_IObject* oldsensorobj = oldsensor->GetParent(); + SCA_IObject* newsensorobj = NULL; - if (newsensor) + // the original owner of the sensor has been replicated? + void **h_obj = m_map_gameobject_to_replica[oldsensorobj]; + if (h_obj) + newsensorobj = (SCA_IObject*)(*h_obj); + if (!newsensorobj) { - // relink this newsensor to the controller - m_logicmgr->RegisterToSensor(cont,newsensor); + // no, then the sensor points outside the hierachy, keep it the same + if (m_objectlist->SearchValue(oldsensorobj)) + // only replicate links that points to active objects + m_logicmgr->RegisterToSensor(cont,oldsensor); } else { - // it can be linked somewhere in the hierarchy or... - for (vector<KX_GameObject*>::iterator git = m_logicHierarchicalGameObjects.begin(); - !(git==m_logicHierarchicalGameObjects.end());++git) - { - newsensor = (*git)->FindSensor(name); - if (newsensor) - break; - } + // yes, then the new sensor has the same position + SCA_SensorList& sensorlist = oldsensorobj->GetSensors(); + SCA_SensorList::iterator sit; + SCA_ISensor* newsensor = NULL; + int sensorpos; - if (newsensor) + for (sensorpos=0, sit=sensorlist.begin(); sit!=sensorlist.end(); sit++, sensorpos++) { - // relink this newsensor to the controller somewhere else within this - // hierarchy - m_logicmgr->RegisterToSensor(cont,newsensor); - } - else - { - // must be an external sensor, so... - m_logicmgr->RegisterToSensor(cont,oldsensor); + if ((*sit) == oldsensor) + { + newsensor = newsensorobj->GetSensors().at(sensorpos); + break; + } } + assert(newsensor != NULL); + m_logicmgr->RegisterToSensor(cont,newsensor); } } @@ -566,38 +583,40 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj) for (vector<SCA_IActuator*>::iterator ita = linkedactuators.begin();!(ita==linkedactuators.end());ita++) { SCA_IActuator* oldactuator = (*ita); - STR_String name = oldactuator->GetName(); - //find this name in the list - SCA_IActuator* newactuator = newobj->FindActuator(name); - if (newactuator) + SCA_IObject* oldactuatorobj = oldactuator->GetParent(); + SCA_IObject* newactuatorobj = NULL; + + // the original owner of the sensor has been replicated? + void **h_obj = m_map_gameobject_to_replica[oldactuatorobj]; + if (h_obj) + newactuatorobj = (SCA_IObject*)(*h_obj); + + if (!newactuatorobj) { - // relink this newsensor to the controller - m_logicmgr->RegisterToActuator(cont,newactuator); - newactuator->SetUeberExecutePriority(m_ueberExecutionPriority); + // no, then the sensor points outside the hierachy, keep it the same + if (m_objectlist->SearchValue(oldactuatorobj)) + // only replicate links that points to active objects + m_logicmgr->RegisterToActuator(cont,oldactuator); } else { - // it can be linked somewhere in the hierarchy or... - for (vector<KX_GameObject*>::iterator git = m_logicHierarchicalGameObjects.begin(); - !(git==m_logicHierarchicalGameObjects.end());++git) - { - newactuator= (*git)->FindActuator(name); - if (newactuator) - break; - } + // yes, then the new sensor has the same position + SCA_ActuatorList& actuatorlist = oldactuatorobj->GetActuators(); + SCA_ActuatorList::iterator ait; + SCA_IActuator* newactuator = NULL; + int actuatorpos; - if (newactuator) - { - // relink this actuator to the controller somewhere else within this - // hierarchy - m_logicmgr->RegisterToActuator(cont,newactuator); - newactuator->SetUeberExecutePriority(m_ueberExecutionPriority); - } - else + for (actuatorpos=0, ait=actuatorlist.begin(); ait!=actuatorlist.end(); ait++, actuatorpos++) { - // must be an external actuator, so... - m_logicmgr->RegisterToActuator(cont,oldactuator); + if ((*ait) == oldactuator) + { + newactuator = newactuatorobj->GetActuators().at(actuatorpos); + break; + } } + assert(newactuator != NULL); + m_logicmgr->RegisterToActuator(cont,newactuator); + newactuator->SetUeberExecutePriority(m_ueberExecutionPriority); } } } @@ -605,6 +624,154 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj) newobj->ResetState(); } +void KX_Scene::DupliGroupRecurse(CValue* obj, int level) +{ + KX_GameObject* groupobj = (KX_GameObject*) obj; + KX_GameObject* replica; + KX_GameObject* gameobj; + Object* blgroupobj = groupobj->GetBlenderObject(); + Group* group; + GroupObject *go; + vector<KX_GameObject*> duplilist; + + if (!groupobj->IsDupliGroup() || + level>MAX_DUPLI_RECUR) + return; + + // we will add one group at a time + m_logicHierarchicalGameObjects.clear(); + m_map_gameobject_to_replica.clear(); + m_ueberExecutionPriority++; + // for groups will do something special: + // we will force the creation of objects to those in the group only + // Again, this is match what Blender is doing (it doesn't care of parent relationship) + m_groupGameObjects.clear(); + + group = blgroupobj->dup_group; + for(go=(GroupObject*)group->gobject.first; go; go=(GroupObject*)go->next) + { + Object* blenderobj = go->ob; + if (blgroupobj == blenderobj) + // this check is also in group_duplilist() + continue; + gameobj = (KX_GameObject*)m_logicmgr->FindGameObjByBlendObj(blenderobj); + if (gameobj == NULL) + { + // this object has not been converted!!! + // Should not happen as dupli group are created automatically + continue; + } + if ((blenderobj->lay & group->layer)==0) + { + // object is not visible in the 3D view, will not be instantiated + continue; + } + m_groupGameObjects.insert(gameobj); + } + + set<CValue*>::iterator oit; + for (oit=m_groupGameObjects.begin(); oit != m_groupGameObjects.end(); oit++) + { + gameobj = (KX_GameObject*)(*oit); + + KX_GameObject *parent = gameobj->GetParent(); + if (parent != NULL) + { + parent->Release(); // GetParent() increased the refcount + + // this object is not a top parent. Either it is the child of another + // object in the group and it will be added automatically when the parent + // is added. Or it is the child of an object outside the group and the group + // is inconsistent, skip it anyway + continue; + } + replica = (KX_GameObject*) AddNodeReplicaObject(NULL,gameobj); + // add to 'rootparent' list (this is the list of top hierarchy objects, updated each frame) + m_parentlist->Add(replica->AddRef()); + + // recurse replication into children nodes + NodeList& children = gameobj->GetSGNode()->GetSGChildren(); + + replica->GetSGNode()->ClearSGChildren(); + for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) + { + SG_Node* orgnode = (*childit); + SG_Node* childreplicanode = orgnode->GetSGReplica(); + if (childreplicanode) + replica->GetSGNode()->AddChild(childreplicanode); + } + // don't replicate logic now: we assume that the objects in the group can have + // logic relationship, even outside parent relationship + // In order to match 3D view, the position of groupobj is used as a + // transformation matrix instead of the new position. This means that + // the group reference point is 0,0,0 + + // get the rootnode's scale + MT_Vector3 newscale = groupobj->NodeGetWorldScaling(); + // set the replica's relative scale with the rootnode's scale + replica->NodeSetRelativeScale(newscale); + + MT_Matrix3x3 newori = groupobj->NodeGetWorldOrientation() * gameobj->NodeGetWorldOrientation(); + replica->NodeSetLocalOrientation(newori); + + MT_Point3 newpos = groupobj->NodeGetWorldPosition() + + newscale*(groupobj->NodeGetWorldOrientation() * gameobj->NodeGetWorldPosition()); + replica->NodeSetLocalPosition(newpos); + + if (replica->GetPhysicsController()) + { + // not required, already done in NodeSetLocalOrientation.. + //replica->GetPhysicsController()->setPosition(newpos); + //replica->GetPhysicsController()->setOrientation(newori.getRotation()); + // Scaling has been set relatively hereabove, this does not + // set the scaling of the controller. I don't know why it's just the + // relative scale and not the full scale that has to be put here... + replica->GetPhysicsController()->setScaling(newscale); + } + + replica->GetSGNode()->UpdateWorldData(0); + replica->GetSGNode()->SetBBox(gameobj->GetSGNode()->BBox()); + replica->GetSGNode()->SetRadius(gameobj->GetSGNode()->Radius()); + // done with replica + replica->Release(); + } + + // the logic must be replicated first because we need + // the new logic bricks before relinking + vector<KX_GameObject*>::iterator git; + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + (*git)->ReParentLogic(); + } + + // relink any pointers as necessary, sort of a temporary solution + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + // this will also relink the actuator to objects within the hierarchy + (*git)->Relink(&m_map_gameobject_to_replica); + // add the object in the layer of the parent + (*git)->SetLayer(groupobj->GetLayer()); + } + + // replicate crosslinks etc. between logic bricks + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + ReplicateLogic((*git)); + } + + // now look if object in the hierarchy have dupli group and recurse + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + if ((*git) != groupobj && (*git)->IsDupliGroup()) + // can't instantiate group immediately as it destroys m_logicHierarchicalGameObjects + duplilist.push_back((*git)); + } + + for (git = duplilist.begin(); !(git == duplilist.end()); ++git) + { + DupliGroupRecurse((*git), level+1); + } +} SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, @@ -614,6 +781,7 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, m_logicHierarchicalGameObjects.clear(); m_map_gameobject_to_replica.clear(); + m_groupGameObjects.clear(); // todo: place a timebomb in the object, for temporarily objects :) // lifespan of zero means 'this object lives forever' @@ -647,24 +815,26 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, { SG_Node* orgnode = (*childit); SG_Node* childreplicanode = orgnode->GetSGReplica(); - replica->GetSGNode()->AddChild(childreplicanode); + if (childreplicanode) + replica->GetSGNode()->AddChild(childreplicanode); } - // relink any pointers as necessary, sort of a temporary solution + // now replicate logic vector<KX_GameObject*>::iterator git; for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) { + (*git)->ReParentLogic(); + } + + // relink any pointers as necessary, sort of a temporary solution + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + // this will also relink the actuators in the hierarchy (*git)->Relink(&m_map_gameobject_to_replica); // add the object in the layer of the parent (*git)->SetLayer(parentobj->GetLayer()); } - // now replicate logic - for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) - { - (*git)->ReParentLogic(); - } - // replicate crosslinks etc. between logic bricks for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) { @@ -685,8 +855,9 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, if (replica->GetPhysicsController()) { - replica->GetPhysicsController()->setPosition(newpos); - replica->GetPhysicsController()->setOrientation(newori.getRotation()); + // not needed, already done in NodeSetLocalPosition() + //replica->GetPhysicsController()->setPosition(newpos); + //replica->GetPhysicsController()->setOrientation(newori.getRotation()); replica->GetPhysicsController()->setScaling(newscale); } @@ -697,6 +868,20 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, replica->GetSGNode()->UpdateWorldData(0); replica->GetSGNode()->SetBBox(originalobj->GetSGNode()->BBox()); replica->GetSGNode()->SetRadius(originalobj->GetSGNode()->Radius()); + // check if there are objects with dupligroup in the hierarchy + vector<KX_GameObject*> duplilist; + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + if ((*git)->IsDupliGroup()) + { + // separate list as m_logicHierarchicalGameObjects is also used by DupliGroupRecurse() + duplilist.push_back(*git); + } + } + for (git = duplilist.begin();!(git==duplilist.end());++git) + { + DupliGroupRecurse(*git, 0); + } // don't release replica here because we are returning it, not done with it... return replica; } @@ -743,6 +928,12 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj) int ret; KX_GameObject* newobj = (KX_GameObject*) gameobj; + // keep the blender->game object association up to date + // note that all the replicas of an object will have the same + // blender object, that's why we need to check the game object + // as only the deletion of the original object must be recorded + m_logicmgr->UnregisterGameObj(newobj->GetBlenderObject(), gameobj); + //todo: look at this //GetPhysicsEnvironment()->RemovePhysicsController(gameobj->getPhysicsController()); @@ -801,6 +992,7 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj) //m_active_camera->Release(); m_active_camera = NULL; } + // in case this is a camera m_cameras.remove((KX_Camera*)newobj); @@ -1057,14 +1249,10 @@ void KX_Scene::MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool vi if (visible) { int nummeshes = gameobj->GetMeshCount(); - MT_Transform t( cam->GetWorldToCamera() * gameobj->GetSGNode()->GetWorldTransform()); - + // this adds the vertices to the display list for (int m=0;m<nummeshes;m++) - { - // this adds the vertices to the display list - (gameobj->GetMesh(m))->SchedulePolygons(t, rasty->GetDrawingMode()); - } + (gameobj->GetMesh(m))->SchedulePolygons(rasty->GetDrawingMode()); } gameobj->MarkVisible(visible); } @@ -1121,12 +1309,11 @@ void KX_Scene::MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj,KX_Cam if (vis) { int nummeshes = gameobj->GetMeshCount(); - MT_Transform t(cam->GetWorldToCamera() * gameobj->GetSGNode()->GetWorldTransform()); for (int m=0;m<nummeshes;m++) { // this adds the vertices to the display list - (gameobj->GetMesh(m))->SchedulePolygons(t, rasty->GetDrawingMode()); + (gameobj->GetMesh(m))->SchedulePolygons(rasty->GetDrawingMode()); } // Visibility/ non-visibility are marked // elsewhere now. @@ -1239,7 +1426,7 @@ void KX_Scene::UpdateParents(double curtime) RAS_MaterialBucket* KX_Scene::FindBucket(class RAS_IPolyMaterial* polymat, bool &bucketCreated) { - return m_bucketmanager->RAS_BucketManagerFindBucket(polymat, bucketCreated); + return m_bucketmanager->FindBucket(polymat, bucketCreated); } @@ -1249,10 +1436,9 @@ void KX_Scene::RenderBuckets(const MT_Transform & cameratransform, class RAS_IRenderTools* rendertools) { m_bucketmanager->Renderbuckets(cameratransform,rasty,rendertools); + KX_BlenderMaterial::EndFrame(); } - - void KX_Scene::UpdateObjectActivity(void) { if (m_activity_culling) { diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 28dee1b5893..80a2abe287a 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -216,6 +216,16 @@ protected: */ std::vector<KX_GameObject*> m_logicHierarchicalGameObjects; + /** + * This temporary variable will contain the list of + * object that can be added during group instantiation. + * objects outside this list will not be added (can + * happen with children that are outside the group). + * Used in AddReplicaObject. If the list is empty, it + * means don't care. + */ + std::set<CValue*> m_groupGameObjects; + /** * Pointer to system variable passed in in constructor * only used in constructor so we do not need to keep it @@ -291,6 +301,12 @@ public: * Update all transforms according to the scenegraph. */ void UpdateParents(double curtime); + void DupliGroupRecurse(CValue* gameobj, int level); + bool IsObjectInGroup(CValue* gameobj) + { + return (m_groupGameObjects.empty() || + m_groupGameObjects.find(gameobj) != m_groupGameObjects.end()); + } SCA_IObject* AddReplicaObject(CValue* gameobj, CValue* locationobj, int lifespan=0); diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 8f7cffd506f..d6164dc812a 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -58,13 +58,16 @@ KX_SceneActuator::KX_SceneActuator(SCA_IObject *gameobj, m_KetsjiEngine=ketsjiEngine; m_camera = camera; m_nextSceneName = nextSceneName; + if (m_camera) + m_camera->RegisterActuator(this); } /* End of constructor */ KX_SceneActuator::~KX_SceneActuator() { - // there's nothing to be done here, really.... + if (m_camera) + m_camera->UnregisterActuator(this); } /* end of destructor */ @@ -79,6 +82,34 @@ CValue* KX_SceneActuator::GetReplica() return replica; } +void KX_SceneActuator::ProcessReplica() +{ + if (m_camera) + m_camera->RegisterActuator(this); + SCA_IActuator::ProcessReplica(); +} + +bool KX_SceneActuator::UnlinkObject(SCA_IObject* clientobj) +{ + if (clientobj == (SCA_IObject*)m_camera) + { + // this object is being deleted, we cannot continue to track it. + m_camera = NULL; + return true; + } + return false; +} + +void KX_SceneActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + void **h_obj = (*obj_map)[m_camera]; + if (h_obj) { + if (m_camera) + m_camera->UnregisterActuator(this); + m_camera = (KX_Camera*)(*h_obj); + m_camera->RegisterActuator(this); + } +} bool KX_SceneActuator::Update() @@ -332,7 +363,11 @@ PyObject* KX_SceneActuator::PySetCamera(PyObject* self, PyObject *cam; if (PyArg_ParseTuple(args, "O!", &KX_Camera::Type, &cam)) { + if (m_camera) + m_camera->UnregisterActuator(this); m_camera = (KX_Camera*) cam; + if (m_camera) + m_camera->RegisterActuator(this); Py_Return; } PyErr_Clear(); @@ -345,7 +380,13 @@ PyObject* KX_SceneActuator::PySetCamera(PyObject* self, } KX_Camera *camOb = FindCamera(camName); - if (camOb) m_camera = camOb; + if (camOb) + { + if (m_camera) + m_camera->UnregisterActuator(this); + m_camera = camOb; + m_camera->RegisterActuator(this); + } Py_Return; } diff --git a/source/gameengine/Ketsji/KX_SceneActuator.h b/source/gameengine/Ketsji/KX_SceneActuator.h index cfc79b93f8e..55aaf629d7c 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.h +++ b/source/gameengine/Ketsji/KX_SceneActuator.h @@ -82,6 +82,9 @@ class KX_SceneActuator : public SCA_IActuator virtual ~KX_SceneActuator(); virtual CValue* GetReplica(); + virtual void ProcessReplica(); + virtual bool UnlinkObject(SCA_IObject* clientobj); + virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); virtual bool Update(); diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp index 6ea5461dbaa..4032a795ce3 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp @@ -101,7 +101,7 @@ void KX_SumoPhysicsController::SetSumoTransform(bool nondynaonly) } -void KX_SumoPhysicsController::SuspendDynamics() +void KX_SumoPhysicsController::SuspendDynamics(bool) { SumoPhysicsController::SuspendDynamics(); } @@ -170,8 +170,9 @@ void KX_SumoPhysicsController::setMargin(float collisionMargin) } -void KX_SumoPhysicsController::setOrientation(const MT_Quaternion& orn) +void KX_SumoPhysicsController::setOrientation(const MT_Matrix3x3& rot) { + MT_Quaternion orn = rot.getRotation(); SumoPhysicsController::setOrientation( orn[0],orn[1],orn[2],orn[3]); diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.h b/source/gameengine/Ketsji/KX_SumoPhysicsController.h index 8c061ae4056..1dd930bf3d9 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.h +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.h @@ -76,10 +76,10 @@ public: void resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ); - void SuspendDynamics(); + void SuspendDynamics(bool); void RestoreDynamics(); virtual void getOrientation(MT_Quaternion& orn); - virtual void setOrientation(const MT_Quaternion& orn); + virtual void setOrientation(const MT_Matrix3x3& orn); virtual void setPosition(const MT_Point3& pos); virtual void setScaling(const MT_Vector3& scaling); diff --git a/source/gameengine/Ketsji/KX_TouchEventManager.cpp b/source/gameengine/Ketsji/KX_TouchEventManager.cpp index 423543eef5c..7528fdbbc34 100644 --- a/source/gameengine/Ketsji/KX_TouchEventManager.cpp +++ b/source/gameengine/Ketsji/KX_TouchEventManager.cpp @@ -100,16 +100,24 @@ bool KX_TouchEventManager::newBroadphaseResponse(void *client_data, void KX_TouchEventManager::RegisterSensor(SCA_ISensor* sensor) { KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor); - m_sensors.push_back(touchsensor); + m_sensors.insert(touchsensor); touchsensor->RegisterSumo(this); } +void KX_TouchEventManager::RemoveSensor(SCA_ISensor* sensor) +{ + KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor); + m_sensors.erase(touchsensor); + + touchsensor->UnregisterSumo(this); +} + void KX_TouchEventManager::EndFrame() { - vector<SCA_ISensor*>::iterator it; + set<SCA_ISensor*>::iterator it; for ( it = m_sensors.begin(); !(it==m_sensors.end());it++) { @@ -124,7 +132,7 @@ void KX_TouchEventManager::NextFrame() { if (m_sensors.size() > 0) { - vector<SCA_ISensor*>::iterator it; + set<SCA_ISensor*>::iterator it; for (it = m_sensors.begin();!(it==m_sensors.end());++it) static_cast<KX_TouchSensor*>(*it)->SynchronizeTransform(); @@ -157,20 +165,3 @@ void KX_TouchEventManager::NextFrame() (*it)->Activate(m_logicmgr,NULL); } } - - - -void KX_TouchEventManager::RemoveSensor(class SCA_ISensor* sensor) -{ - std::vector<SCA_ISensor*>::iterator i = - std::find(m_sensors.begin(), m_sensors.end(), sensor); - if (!(i == m_sensors.end())) - { - std::swap(*i, m_sensors.back()); - m_sensors.pop_back(); - } - - // remove the sensor forever :) - SCA_EventManager::RemoveSensor(sensor); -} - diff --git a/source/gameengine/Ketsji/KX_TouchEventManager.h b/source/gameengine/Ketsji/KX_TouchEventManager.h index 20ed6126bd0..cc77bccfc31 100644 --- a/source/gameengine/Ketsji/KX_TouchEventManager.h +++ b/source/gameengine/Ketsji/KX_TouchEventManager.h @@ -71,8 +71,8 @@ public: PHY_IPhysicsEnvironment* physEnv); virtual void NextFrame(); virtual void EndFrame(); - virtual void RemoveSensor(class SCA_ISensor* sensor); virtual void RegisterSensor(SCA_ISensor* sensor); + virtual void RemoveSensor(SCA_ISensor* sensor); SCA_LogicManager* GetLogicManager() { return m_logicmgr;} PHY_IPhysicsEnvironment *GetPhysicsEnvironment() { return m_physEnv; } diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index ce3aa1de2ef..60e1d87d318 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -153,6 +153,14 @@ void KX_TouchSensor::RegisterSumo(KX_TouchEventManager *touchman) } } +void KX_TouchSensor::UnregisterSumo(KX_TouchEventManager* touchman) +{ + if (m_physCtrl) + { + touchman->GetPhysicsEnvironment()->removeCollisionCallback(m_physCtrl); + } +} + bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_CollData* colldata) { // KX_TouchEventManager* toucheventmgr = (KX_TouchEventManager*)m_eventmgr; diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h index 056440ccd6c..b611d296939 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.h +++ b/source/gameengine/Ketsji/KX_TouchSensor.h @@ -76,6 +76,7 @@ public: virtual void ReParent(SCA_IObject* parent); virtual void RegisterSumo(KX_TouchEventManager* touchman); + virtual void UnregisterSumo(KX_TouchEventManager* touchman); // virtual DT_Bool HandleCollision(void* obj1,void* obj2, // const DT_CollData * coll_data); diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 731a610c2eb..f5b463abf02 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -146,19 +146,19 @@ void compatible_eulFast(float *eul, float *oldrot) { float dx, dy, dz; - /* verschillen van ong 360 graden corrigeren */ + /* angular difference of 360 degrees */ dx= eul[0] - oldrot[0]; dy= eul[1] - oldrot[1]; dz= eul[2] - oldrot[2]; - if( fabs(dx) > 5.1) { + if( fabs(dx) > MT_PI) { if(dx > 0.0) eul[0] -= MT_2_PI; else eul[0]+= MT_2_PI; } - if( fabs(dy) > 5.1) { + if( fabs(dy) > MT_PI) { if(dy > 0.0) eul[1] -= MT_2_PI; else eul[1]+= MT_2_PI; } - if( fabs(dz) > 5.1 ) { + if( fabs(dz) > MT_PI ) { if(dz > 0.0) eul[2] -= MT_2_PI; else eul[2]+= MT_2_PI; } } @@ -195,6 +195,8 @@ void KX_TrackToActuator::ProcessReplica() // the replica is tracking the same object => register it if (m_object) m_object->RegisterActuator(this); + if (m_parentobj) + m_parentobj->AddRef(); SCA_IActuator::ProcessReplica(); } @@ -210,6 +212,26 @@ bool KX_TrackToActuator::UnlinkObject(SCA_IObject* clientobj) return false; } +void KX_TrackToActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + void **h_obj = (*obj_map)[m_object]; + if (h_obj) { + if (m_object) + m_object->UnregisterActuator(this); + m_object = (SCA_IObject*)(*h_obj); + m_object->RegisterActuator(this); + } + + void **h_parobj = (*obj_map)[m_parentobj]; + if (h_parobj) { + if (m_parentobj) + m_parentobj->Release(); + m_parentobj= (KX_GameObject*)(*h_parobj); + m_parentobj->AddRef(); + } +} + + bool KX_TrackToActuator::Update(double curtime, bool frame) { bool result = false; diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h index a03aa115baa..1d1cf46d21b 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.h +++ b/source/gameengine/Ketsji/KX_TrackToActuator.h @@ -68,6 +68,7 @@ class KX_TrackToActuator : public SCA_IActuator virtual void ProcessReplica(); virtual bool UnlinkObject(SCA_IObject* clientobj); + virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); virtual bool Update(double curtime, bool frame); /* Python part */ diff --git a/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h b/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h index ec1b7702ffd..7c61902f8e2 100644 --- a/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h +++ b/source/gameengine/Physics/BlOde/OdePhysicsEnvironment.h @@ -65,6 +65,7 @@ public: { } virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl) {} + virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl) {} virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;} virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;} diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index e444c4c73be..5c70b071661 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -337,12 +337,33 @@ void CcdPhysicsController::setOrientation(float quatImag0,float quatImag1,float { m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); } - - m_MotionState->setWorldOrientation(quatImag0,quatImag1,quatImag2,quatReal); + // not required + //m_MotionState->setWorldOrientation(quatImag0,quatImag1,quatImag2,quatReal); btTransform xform = m_body->getCenterOfMassTransform(); xform.setRotation(btQuaternion(quatImag0,quatImag1,quatImag2,quatReal)); m_body->setCenterOfMassTransform(xform); - m_bulletMotionState->setWorldTransform(xform); + // not required + //m_bulletMotionState->setWorldTransform(xform); + } + +} + +void CcdPhysicsController::setWorldOrientation(const btMatrix3x3& orn) +{ + if (m_body) + { + m_body->activate(true); + if (m_body->isStaticObject()) + { + m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); + } + // not required + //m_MotionState->setWorldOrientation(quatImag0,quatImag1,quatImag2,quatReal); + btTransform xform = m_body->getCenterOfMassTransform(); + xform.setBasis(orn); + m_body->setCenterOfMassTransform(xform); + // not required + //m_bulletMotionState->setWorldTransform(xform); } } @@ -356,12 +377,13 @@ void CcdPhysicsController::setPosition(float posX,float posY,float posZ) { m_body->setCollisionFlags(m_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); } - - m_MotionState->setWorldPosition(posX,posY,posZ); + // not required, this function is only used to update the physic controller + //m_MotionState->setWorldPosition(posX,posY,posZ); btTransform xform = m_body->getCenterOfMassTransform(); xform.setOrigin(btVector3(posX,posY,posZ)); m_body->setCenterOfMassTransform(xform); - m_bulletMotionState->setWorldTransform(xform); + // not required + //m_bulletMotionState->setWorldTransform(xform); } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h index 37fa465351f..64f1876e199 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h @@ -106,6 +106,7 @@ class CcdPhysicsController : public PHY_IPhysicsController btRigidBody* m_body; class PHY_IMotionState* m_MotionState; btMotionState* m_bulletMotionState; + friend class CcdPhysicsEnvironment; // needed when updating the controller void* m_newClientInfo; @@ -115,6 +116,9 @@ class CcdPhysicsController : public PHY_IPhysicsController void CreateRigidbody(); + protected: + void setWorldOrientation(const btMatrix3x3& mat); + public: int m_collisionDelay; @@ -194,7 +198,6 @@ class CcdPhysicsController : public PHY_IPhysicsController return m_cci.m_collisionFilterMask; } - virtual void calcXform() {} ; virtual void SetMargin(float margin) {}; virtual float GetMargin() const {return 0.f;}; diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index c9d346e316d..ea14c5430e2 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -368,7 +368,7 @@ void CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl) body->setUserPointer(ctrl); body->setGravity( m_gravity ); - m_controllers.push_back(ctrl); + m_controllers.insert(ctrl); //use explicit group/filter for finer control over collision in bullet => near/radar sensor m_dynamicsWorld->addRigidBody(body, ctrl->GetCollisionFilterGroup(), ctrl->GetCollisionFilterMask()); @@ -434,39 +434,47 @@ void CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl) void CcdPhysicsEnvironment::removeCcdPhysicsController(CcdPhysicsController* ctrl) { - //also remove constraint - - m_dynamicsWorld->removeRigidBody(ctrl->GetRigidBody()); + m_controllers.erase(ctrl); + //remove it from the triggers + m_triggerControllers.erase(ctrl); +} - { - std::vector<CcdPhysicsController*>::iterator i = - std::find(m_controllers.begin(), m_controllers.end(), ctrl); - if (!(i == m_controllers.end())) - { - std::swap(*i, m_controllers.back()); - m_controllers.pop_back(); - } - } +void CcdPhysicsEnvironment::updateCcdPhysicsController(CcdPhysicsController* ctrl, btScalar newMass, int newCollisionFlags, short int newCollisionGroup, short int newCollisionMask) +{ + // this function is used when the collisionning group of a controller is changed + // remove and add the collistioning object + btRigidBody* body = ctrl->GetRigidBody(); + btVector3 inertia; + + m_dynamicsWorld->removeCollisionObject(body); + body->setCollisionFlags(newCollisionFlags); + body->getCollisionShape()->calculateLocalInertia(newMass, inertia); + body->setMassProps(newMass, inertia); + m_dynamicsWorld->addCollisionObject(body, newCollisionGroup, newCollisionMask); + // to avoid nasty interaction, we must update the property of the controller as well + ctrl->m_cci.m_mass = newMass; + ctrl->m_cci.m_collisionFilterGroup = newCollisionGroup; + ctrl->m_cci.m_collisionFilterMask = newCollisionMask; + ctrl->m_cci.m_collisionFlags = newCollisionFlags; +} - //remove it from the triggers +void CcdPhysicsEnvironment::enableCcdPhysicsController(CcdPhysicsController* ctrl) +{ + if (m_controllers.insert(ctrl).second) { - std::vector<CcdPhysicsController*>::iterator i = - std::find(m_triggerControllers.begin(), m_triggerControllers.end(), ctrl); - if (!(i == m_triggerControllers.end())) - { - std::swap(*i, m_triggerControllers.back()); - m_triggerControllers.pop_back(); - } + btRigidBody* body = ctrl->GetRigidBody(); + body->setUserPointer(ctrl); + m_dynamicsWorld->addCollisionObject(body, + ctrl->GetCollisionFilterGroup(), ctrl->GetCollisionFilterMask()); } - - } + void CcdPhysicsEnvironment::beginFrame() { @@ -475,12 +483,12 @@ void CcdPhysicsEnvironment::beginFrame() bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep) { + std::set<CcdPhysicsController*>::iterator it; + int i; - int i,numCtrl = GetNumControllers(); - for (i=0;i<numCtrl;i++) + for (it=m_controllers.begin(); it!=m_controllers.end(); it++) { - CcdPhysicsController* ctrl = GetPhysicsController(i); - ctrl->SynchronizeMotionStates(timeStep); + (*it)->SynchronizeMotionStates(timeStep); } float subStep = timeStep / float(m_numTimeSubSteps); @@ -489,11 +497,9 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep) m_dynamicsWorld->stepSimulation(subStep,0);//perform always a full simulation step } - numCtrl = GetNumControllers(); - for (i=0;i<numCtrl;i++) + for (it=m_controllers.begin(); it!=m_controllers.end(); it++) { - CcdPhysicsController* ctrl = GetPhysicsController(i); - ctrl->SynchronizeMotionStates(timeStep); + (*it)->SynchronizeMotionStates(timeStep); } for (i=0;i<m_wrapperVehicles.size();i++) @@ -820,20 +826,6 @@ CcdPhysicsEnvironment::~CcdPhysicsEnvironment() } -int CcdPhysicsEnvironment::GetNumControllers() -{ - return m_controllers.size(); -} - - -CcdPhysicsController* CcdPhysicsEnvironment::GetPhysicsController( int index) -{ - return m_controllers[index]; -} - - - - void CcdPhysicsEnvironment::setConstraintParam(int constraintId,int param,float value0,float value1) { btTypedConstraint* typedConstraint = getConstraintById(constraintId); @@ -873,12 +865,14 @@ void CcdPhysicsEnvironment::addSensor(PHY_IPhysicsController* ctrl) { CcdPhysicsController* ctrl1 = (CcdPhysicsController* )ctrl; - std::vector<CcdPhysicsController*>::iterator i = - std::find(m_controllers.begin(), m_controllers.end(), ctrl); - if ((i == m_controllers.end())) - { - addCcdPhysicsController(ctrl1); - } + // addSensor() is a "light" function for bullet because it is used + // dynamically when the sensor is activated. Use enableCcdPhysicsController() instead + //if (m_controllers.insert(ctrl1).second) + //{ + // addCcdPhysicsController(ctrl1); + //} + enableCcdPhysicsController(ctrl1); + //Collision filter/mask is now set at the time of the creation of the controller //force collision detection with everything, including static objects (might hurt performance!) //ctrl1->GetRigidBody()->getBroadphaseHandle()->m_collisionFilterMask = btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::SensorTrigger; @@ -891,21 +885,15 @@ void CcdPhysicsEnvironment::addSensor(PHY_IPhysicsController* ctrl) void CcdPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl) { - std::vector<CcdPhysicsController*>::iterator i = - std::find(m_triggerControllers.begin(), m_triggerControllers.end(), ctrl); - if (!(i == m_triggerControllers.end())) - { - std::swap(*i, m_triggerControllers.back()); - m_triggerControllers.pop_back(); - } + m_triggerControllers.erase((CcdPhysicsController*)ctrl); } void CcdPhysicsEnvironment::removeSensor(PHY_IPhysicsController* ctrl) { - removeCollisionCallback(ctrl); - //printf("removeSensor\n"); + removeCcdPhysicsController((CcdPhysicsController*)ctrl); } + void CcdPhysicsEnvironment::addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user) { /* printf("addTouchCallback\n(response class = %i)\n",response_class); @@ -943,10 +931,9 @@ void CcdPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctr CcdPhysicsController* ccdCtrl = static_cast<CcdPhysicsController*>(ctrl); //printf("requestCollisionCallback\n"); - m_triggerControllers.push_back(ccdCtrl); + m_triggerControllers.insert(ccdCtrl); } - void CcdPhysicsEnvironment::CallbackTriggers() { @@ -979,11 +966,10 @@ void CcdPhysicsEnvironment::CallbackTriggers() CcdPhysicsController* ctrl0 = static_cast<CcdPhysicsController*>(obj0->getUserPointer()); CcdPhysicsController* ctrl1 = static_cast<CcdPhysicsController*>(obj1->getUserPointer()); - std::vector<CcdPhysicsController*>::iterator i = - std::find(m_triggerControllers.begin(), m_triggerControllers.end(), ctrl0); + std::set<CcdPhysicsController*>::const_iterator i = m_triggerControllers.find(ctrl0); if (i == m_triggerControllers.end()) { - i = std::find(m_triggerControllers.begin(), m_triggerControllers.end(), ctrl1); + i = m_triggerControllers.find(ctrl1); } if (!(i == m_triggerControllers.end())) @@ -1093,7 +1079,6 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::CreateSphereController(float radi CcdPhysicsController* sphereController = new CcdPhysicsController(cinfo); - return sphereController; } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index 9f14cf6cbef..fd96522037e 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -18,6 +18,7 @@ subject to the following restrictions: #include "PHY_IPhysicsEnvironment.h" #include <vector> +#include <set> class CcdPhysicsController; #include "LinearMath/btVector3.h" #include "LinearMath/btTransform.h" @@ -183,6 +184,15 @@ protected: void removeCcdPhysicsController(CcdPhysicsController* ctrl); + void updateCcdPhysicsController(CcdPhysicsController* ctrl, btScalar newMass, int newCollisionFlags, short int newCollisionGroup, short int newCollisionMask); + + void disableCcdPhysicsController(CcdPhysicsController* ctrl) + { + removeCcdPhysicsController(ctrl); + } + + void enableCcdPhysicsController(CcdPhysicsController* ctrl); + btBroadphaseInterface* getBroadphase(); @@ -200,12 +210,6 @@ protected: } - int GetNumControllers(); - - CcdPhysicsController* GetPhysicsController( int index); - - - const btPersistentManifold* GetManifold(int index) const; @@ -220,9 +224,9 @@ protected: - std::vector<CcdPhysicsController*> m_controllers; + std::set<CcdPhysicsController*> m_controllers; - std::vector<CcdPhysicsController*> m_triggerControllers; + std::set<CcdPhysicsController*> m_triggerControllers; PHY_ResponseCallback m_triggerCallbacks[PHY_NUM_RESPONSE]; void* m_triggerCallbacksUserPtrs[PHY_NUM_RESPONSE]; diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h index f0761618e4e..b5a61f72e4a 100644 --- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h +++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h @@ -80,6 +80,7 @@ public: { } virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl) {} + virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl) {} virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) {return 0;} virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;} diff --git a/source/gameengine/Physics/Sumo/Fuzzics/src/SM_Scene.cpp b/source/gameengine/Physics/Sumo/Fuzzics/src/SM_Scene.cpp index b5bf67b14ea..f0791bbf89f 100644 --- a/source/gameengine/Physics/Sumo/Fuzzics/src/SM_Scene.cpp +++ b/source/gameengine/Physics/Sumo/Fuzzics/src/SM_Scene.cpp @@ -98,12 +98,17 @@ void SM_Scene::addTouchCallback(int response_class, DT_ResponseCallback callback void SM_Scene::addSensor(SM_Object& object) { - object.calcXform(); - m_objectList.push_back(&object); - DT_AddObject(m_scene, object.getObjectHandle()); - DT_SetResponseClass(m_respTable, object.getObjectHandle(), m_ResponseClass[SENSOR_RESPONSE]); - DT_SetResponseClass(m_secondaryRespTable, object.getObjectHandle(), m_secondaryResponseClass[SENSOR_RESPONSE]); - DT_SetResponseClass(m_fixRespTable, object.getObjectHandle(), m_fixResponseClass[SENSOR_RESPONSE]); + T_ObjectList::iterator i = + std::find(m_objectList.begin(), m_objectList.end(), &object); + if (i == m_objectList.end()) + { + object.calcXform(); + m_objectList.push_back(&object); + DT_AddObject(m_scene, object.getObjectHandle()); + DT_SetResponseClass(m_respTable, object.getObjectHandle(), m_ResponseClass[SENSOR_RESPONSE]); + DT_SetResponseClass(m_secondaryRespTable, object.getObjectHandle(), m_secondaryResponseClass [SENSOR_RESPONSE]); + DT_SetResponseClass(m_fixRespTable, object.getObjectHandle(), m_fixResponseClass[SENSOR_RESPONSE]); + } } void SM_Scene::add(SM_Object& object) { diff --git a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp index 16ba45a0be5..65018d2523e 100644 --- a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp @@ -228,6 +228,12 @@ void SumoPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ct m_sumoScene->requestCollisionCallback(*smObject); } } + +void SumoPhysicsEnvironment::removeCollisionCallback(PHY_IPhysicsController* ctrl) +{ + // intentionally empty +} + PHY_IPhysicsController* SumoPhysicsEnvironment::CreateSphereController(float radius,const PHY__Vector3& position) { DT_ShapeHandle shape = DT_NewSphere(0.0); diff --git a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h index ce5cd70e8cc..8b9fb463034 100644 --- a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h +++ b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h @@ -84,6 +84,7 @@ public: virtual void removeSensor(PHY_IPhysicsController* ctrl); virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user); virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl); + virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl); virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position); virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight); diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h index c148210903f..5b275066665 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h @@ -104,6 +104,7 @@ class PHY_IPhysicsEnvironment virtual void removeSensor(PHY_IPhysicsController* ctrl)=0; virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)=0; virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl)=0; + virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl)=0; //These two methods are *solely* used to create controllers for sensor! Don't use for anything else virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) =0; virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight)=0; diff --git a/source/gameengine/PyDoc/BL_ShapeActionActuator.py b/source/gameengine/PyDoc/BL_ShapeActionActuator.py new file mode 100644 index 00000000000..63cce253fa4 --- /dev/null +++ b/source/gameengine/PyDoc/BL_ShapeActionActuator.py @@ -0,0 +1,158 @@ +# $Id$ +# Documentation for BL_ShapeActionActuator +from SCA_IActuator import * + +class BL_ShapeActionActuator(SCA_IActuator): + """ + ShapeAction Actuators apply an shape action to an mesh object. + """ + def setAction(action, reset = True): + """ + Sets the current action. + + @param action: The name of the action to set as the current action. + @type action: string + @param reset: Optional parameter indicating whether to reset the + blend timer or not. A value of 1 indicates that the + timer should be reset. A value of 0 will leave it + unchanged. If reset is not specified, the timer will + be reset. + """ + + def setStart(start): + """ + Specifies the starting frame of the animation. + + @param start: the starting frame of the animation + @type start: float + """ + + def setEnd(end): + """ + Specifies the ending frame of the animation. + + @param end: the ending frame of the animation + @type end: float + """ + def setBlendin(blendin): + """ + Specifies the number of frames of animation to generate + when making transitions between actions. + + @param blendin: the number of frames in transition. + @type blendin: float + """ + + def setPriority(priority): + """ + Sets the priority of this actuator. + + @param priority: Specifies the new priority. Actuators will lower + priority numbers will override actuators with higher + numbers. + @type priority: integer + """ + def setFrame(frame): + """ + Sets the current frame for the animation. + + @param frame: Specifies the new current frame for the animation + @type frame: float + """ + + def setProperty(prop): + """ + Sets the property to be used in FromProp playback mode. + + @param prop: the name of the property to use. + @type prop: string. + """ + + def setBlendtime(blendtime): + """ + Sets the internal frame timer. + + Allows the script to directly modify the internal timer + used when generating transitions between actions. + + @param blendtime: The new time. This parameter must be in the range from 0.0 to 1.0. + @type blendtime: float + """ + + def setType(mode): + """ + Sets the operation mode of the actuator + + @param mode: KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND + @type mode: integer + """ + + def setContinue(cont): + """ + Set the actions continue option True or False. see getContinue. + + @param cont: The continue option. + @type cont: bool + """ + + def getType(): + """ + Returns the operation mode of the actuator + + @rtype: integer + @return: KX_ACTIONACT_PLAY, KX_ACTIONACT_PROPERTY, KX_ACTIONACT_FLIPPER, KX_ACTIONACT_LOOPSTOP, KX_ACTIONACT_LOOPEND + """ + + def getContinue(): + """ + When True, the action will always play from where last left off, otherwise negative events to this actuator will reset it to its start frame. + + @rtype: bool + """ + + def getAction(): + """ + getAction() returns the name of the action associated with this actuator. + + @rtype: string + """ + + def getStart(): + """ + Returns the starting frame of the action. + + @rtype: float + """ + def getEnd(): + """ + Returns the last frame of the action. + + @rtype: float + """ + def getBlendin(): + """ + Returns the number of interpolation animation frames to be generated when this actuator is triggered. + + @rtype: float + """ + def getPriority(): + """ + Returns the priority for this actuator. Actuators with lower Priority numbers will + override actuators with higher numbers. + + @rtype: integer + """ + def getFrame(): + """ + Returns the current frame number. + + @rtype: float + """ + def getProperty(): + """ + Returns the name of the property to be used in FromProp mode. + + @rtype: string + """ + + diff --git a/source/gameengine/PyDoc/KX_ActuatorSensor.py b/source/gameengine/PyDoc/KX_ActuatorSensor.py new file mode 100644 index 00000000000..f9aef86f7f0 --- /dev/null +++ b/source/gameengine/PyDoc/KX_ActuatorSensor.py @@ -0,0 +1,24 @@ +# $Id$ +# Documentation for KX_ActuatorSensor +from SCA_IActuator import * + +class KX_ActuatorSensor(SCA_ISensor): + """ + Actuator sensor detect change in actuator state of the parent object. + It generates a positive pulse if the corresponding actuator is activated + and a negative pulse if the actuator is deactivated. + """ + def getActuator(): + """ + Return the Actuator with which the sensor operates. + + @rtype: string + """ + def setActuator(name): + """ + Sets the Actuator with which to operate. If there is no Actuator + of this name, the function has no effect. + + @param name: actuator name + @type name: string + """ diff --git a/source/gameengine/PyDoc/KX_ConstraintActuator.py b/source/gameengine/PyDoc/KX_ConstraintActuator.py index 9630690e572..b1c6f3c0f4e 100644 --- a/source/gameengine/PyDoc/KX_ConstraintActuator.py +++ b/source/gameengine/PyDoc/KX_ConstraintActuator.py @@ -4,7 +4,7 @@ from SCA_IActuator import * class KX_ConstraintActuator(SCA_IActuator): """ - A constraint actuator limits the position or orientation of an object. + A constraint actuator limits the position, rotation, distance or orientation of an object. """ def setDamp(time): """ @@ -24,7 +24,7 @@ class KX_ConstraintActuator(SCA_IActuator): """ Sets the lower bound of the constraint. - For rotational constraints, lower is specified in degrees. + For rotational and orientation constraints, lower is specified in degrees. @type lower: float """ @@ -32,7 +32,7 @@ class KX_ConstraintActuator(SCA_IActuator): """ Gets the lower bound of the constraint. - For rotational constraints, the lower bound is returned in radians. + For rotational and orientation constraints, the lower bound is returned in radians. @rtype: float """ @@ -40,7 +40,7 @@ class KX_ConstraintActuator(SCA_IActuator): """ Sets the upper bound of the constraint. - For rotational constraints, upper is specified in degrees. + For rotational and orientation constraints, upper is specified in degrees. @type upper: float """ @@ -48,7 +48,7 @@ class KX_ConstraintActuator(SCA_IActuator): """ Gets the upper bound of the constraint. - For rotational constraints, the upper bound is returned in radians. + For rotational and orientation constraints, the upper bound is returned in radians. @rtype: float """ @@ -60,6 +60,9 @@ class KX_ConstraintActuator(SCA_IActuator): @param limit: Position constraints: KX_CONSTRAINTACT_LOCX, KX_CONSTRAINTACT_LOCY, KX_CONSTRAINTACT_LOCZ, Rotation constraints: KX_CONSTRAINTACT_ROTX, KX_CONSTRAINTACT_ROTY or KX_CONSTRAINTACT_ROTZ + Distance contraints: KX_ACT_CONSTRAINT_DIRPX, KX_ACT_CONSTRAINT_DIRPY, KX_ACT_CONSTRAINT_DIRPZ, + KX_ACT_CONSTRAINT_DIRNX, KX_ACT_CONSTRAINT_DIRNY, KX_ACT_CONSTRAINT_DIRNZ, + Orientation constraints: KX_ACT_CONSTRAINT_ORIX, KX_ACT_CONSTRAINT_ORIY, KX_ACT_CONSTRAINT_ORIZ """ def getLimit(): """ @@ -68,5 +71,110 @@ class KX_ConstraintActuator(SCA_IActuator): See module L{GameLogic} for valid constraints. @return: Position constraints: KX_CONSTRAINTACT_LOCX, KX_CONSTRAINTACT_LOCY, KX_CONSTRAINTACT_LOCZ, - Rotation constraints: KX_CONSTRAINTACT_ROTX, KX_CONSTRAINTACT_ROTY or KX_CONSTRAINTACT_ROTZ + Rotation constraints: KX_CONSTRAINTACT_ROTX, KX_CONSTRAINTACT_ROTY, KX_CONSTRAINTACT_ROTZ, + Distance contraints: KX_ACT_CONSTRAINT_DIRPX, KX_ACT_CONSTRAINT_DIRPY, KX_ACT_CONSTRAINT_DIRPZ, + KX_ACT_CONSTRAINT_DIRNX, KX_ACT_CONSTRAINT_DIRNY, KX_ACT_CONSTRAINT_DIRNZ, + Orientation constraints: KX_ACT_CONSTRAINT_ORIX, KX_ACT_CONSTRAINT_ORIY, KX_ACT_CONSTRAINT_ORIZ """ + def setRotDamp(duration): + """ + Sets the time constant of the orientation constraint. + + @param duration: If the duration is negative, it is set to 0. + @type duration: integer + """ + def getRotDamp(): + """ + Returns the damping time for application of the constraint. + + @rtype: integer + """ + def setDirection(vector): + """ + Sets the reference direction in world coordinate for the orientation constraint + + @type vector: 3-tuple + """ + def getDirection(): + """ + Returns the reference direction of the orientation constraint in world coordinate. + + @rtype: 3-tuple + """ + def setOption(option): + """ + Sets several options of the distance constraint. + + @type option: integer + @param option: Binary combination of the following values: + 64 : Activate alignment to surface + 128 : Detect material rather than property + 256 : No deactivation if ray does not hit target + 512 : Activate distance control + """ + def getOption(): + """ + Returns the option parameter. + + @rtype: integer + """ + def setTime(duration): + """ + Sets the activation time of the actuator. + + @type duration: integer + @param duration: The actuator disables itself after this many frame. + If set to 0 or negative, the actuator is not limited in time. + """ + def getTime(): + """ + Returns the time parameter. + + @rtype: integer + """ + def setProperty(property): + """ + Sets the name of the property or material for the ray detection of the distance constraint. + + @type property: string + @param property: If empty, the ray will detect any collisioning object. + """ + def getProperty(): + """ + Returns the property parameter. + + @rtype: string + """ + def setDistance(distance): + """ + Sets the target distance in distance constraint. + + @type distance: float + """ + def getDistance(): + """ + Returns the distance parameter. + + @rtype: float + """ + def setRayLength(length): + """ + Sets the maximum ray length of the distance constraint. + + @type length: float + """ + def getRayLength(): + """ + Returns the length of the ray + + @rtype: float + """ + + + + + + + + + diff --git a/source/gameengine/PyDoc/KX_GameObject.py b/source/gameengine/PyDoc/KX_GameObject.py index 37c188b7f22..a5ba5b1d634 100644 --- a/source/gameengine/PyDoc/KX_GameObject.py +++ b/source/gameengine/PyDoc/KX_GameObject.py @@ -214,6 +214,18 @@ class KX_GameObject: """ Removes this objects parent. """ + def getChildren(): + """ + Return a list of immediate children of this object. + @rtype: list + @return: a list of all this objects children. + """ + def getChildrenRecursive(): + """ + Return a list of children of this object, including all their childrens children. + @rtype: list + @return: a list of all this objects children recursivly. + """ def getMesh(mesh): """ Gets the mesh object for this object. @@ -241,6 +253,16 @@ class KX_GameObject: @type other: L{KX_GameObject} or list [x, y, z] @rtype: float """ + def getVectTo(other): + """ + Returns the vector and the distance to another object or point. + The vector is normalized unless the distance is 0, in which a NULL vector is returned. + + @param other: a point or another L{KX_GameObject} to get the vector and distance to. + @type other: L{KX_GameObject} or list [x, y, z] + @rtype: 3-tuple (float, 3-tuple (x,y,z), 3-tuple (x,y,z)) + @return: (distance, globalVector(3), localVector(3)) + """ def rayCastTo(other,dist,prop): """ Look towards another point/object and find first object hit within dist that matches prop. diff --git a/source/gameengine/PyDoc/KX_IpoActuator.py b/source/gameengine/PyDoc/KX_IpoActuator.py index da8d05ddd5e..1cdab829385 100644 --- a/source/gameengine/PyDoc/KX_IpoActuator.py +++ b/source/gameengine/PyDoc/KX_IpoActuator.py @@ -6,7 +6,7 @@ class KX_IpoActuator(SCA_IActuator): """ IPO actuator activates an animation. """ - def set(mode, startframe, endframe, force): + def set(mode, startframe, endframe, mode): """ Sets the properties of the actuator. @@ -16,8 +16,8 @@ class KX_IpoActuator(SCA_IActuator): @type startframe: integer @param endframe: last frame to use @type endframe: integer - @param force: interpret this ipo as a force - @type force: boolean (KX_TRUE, KX_FALSE) + @param mode: special mode + @type mode: integer (0=normal, 1=interpret location as force, 2=additive) """ def setProperty(property): """ @@ -62,6 +62,19 @@ class KX_IpoActuator(SCA_IActuator): @rtype: boolean """ + def setIpoAdd(add): + """ + Set whether to interpret the ipo as additive rather than absolute. + + @type add: boolean + @param add: KX_TRUE or KX_FALSE + """ + def getIpoAdd(): + """ + Returns whether to interpret the ipo as additive rather than absolute. + + @rtype: boolean + """ def setType(mode): """ Sets the operation mode of the actuator. diff --git a/source/gameengine/PyDoc/KX_ObjectActuator.py b/source/gameengine/PyDoc/KX_ObjectActuator.py index 532c18eea5c..db577d21e6f 100644 --- a/source/gameengine/PyDoc/KX_ObjectActuator.py +++ b/source/gameengine/PyDoc/KX_ObjectActuator.py @@ -6,6 +6,7 @@ class KX_ObjectActuator(SCA_IActuator): """ The object actuator ("Motion Actuator") applies force, torque, displacement, angular displacement, velocity, or angular velocity to an object. + Servo control allows to regulate force to achieve a certain speed target. """ def getForce(): """ @@ -107,15 +108,17 @@ class KX_ObjectActuator(SCA_IActuator): def getLinearVelocity(): """ Returns the linear velocity applied by the actuator. + For the servo control actuator, this is the target speed. @rtype: list [vx, vy, vz, local] @return: A four item list, containing the vector velocity, and whether the velocity is applied in local coordinates (True) or world - coordinates (False) + coordinates (False) """ def setLinearVelocity(vx, vy, vz, local): """ Sets the linear velocity applied by the actuator. + For the servo control actuator, sets the target speed. @type vx: float @param vx: the x component of the velocity vector. @@ -124,8 +127,8 @@ class KX_ObjectActuator(SCA_IActuator): @type vz: float @param vz: the z component of the velocity vector. @type local: boolean - @param local: - False: the velocity vector is applied in world coordinates. - - True: the velocity vector is applied in local coordinates. + @param local: - False: the velocity vector is in world coordinates. + - True: the velocity vector is in local coordinates. """ def getAngularVelocity(): """ @@ -150,5 +153,100 @@ class KX_ObjectActuator(SCA_IActuator): @param local: - False: the velocity vector is applied in world coordinates. - True: the velocity vector is applied in local coordinates. """ + def getDamping(): + """ + Returns the damping parameter of the servo controller. + + @rtype: integer + @return: the time constant of the servo controller in frame unit. + """ + def setDamping(damp): + """ + Sets the damping parameter of the servo controller. + + @type damp: integer + @param damp: the damping parameter in frame unit. + """ + def getForceLimitX(): + """ + Returns the min/max force limit along the X axis used by the servo controller. + + @rtype: list [min, max, enabled] + @return: A three item list, containing the min and max limits of the force as float + and whether the limits are active(true) or inactive(true) + """ + def setForceLimitX(min, max, enable): + """ + Sets the min/max force limit along the X axis and activates or deactivates the limits in the servo controller. + + @type min: float + @param min: the minimum value of the force along the X axis. + @type max: float + @param max: the maximum value of the force along the X axis. + @type enable: boolean + @param enable: - True: the force will be limited to the min/max + - False: the force will not be limited + """ + def getForceLimitY(): + """ + Returns the min/max force limit along the Y axis used by the servo controller. + + @rtype: list [min, max, enabled] + @return: A three item list, containing the min and max limits of the force as float + and whether the limits are active(true) or inactive(true) + """ + def setForceLimitY(min, max, enable): + """ + Sets the min/max force limit along the Y axis and activates or deactivates the limits in the servo controller. + + @type min: float + @param min: the minimum value of the force along the Y axis. + @type max: float + @param max: the maximum value of the force along the Y axis. + @type enable: boolean + @param enable: - True: the force will be limited to the min/max + - False: the force will not be limited + """ + def getForceLimitZ(): + """ + Returns the min/max force limit along the Z axis used by the servo controller. + + @rtype: list [min, max, enabled] + @return: A three item list, containing the min and max limits of the force as float + and whether the limits are active(true) or inactive(true) + """ + def setForceLimitZ(min, max, enable): + """ + Sets the min/max force limit along the Z axis and activates or deactivates the limits in the servo controller. + + @type min: float + @param min: the minimum value of the force along the Z axis. + @type max: float + @param max: the maximum value of the force along the Z axis. + @type enable: boolean + @param enable: - True: the force will be limited to the min/max + - False: the force will not be limited + """ + def getPID(): + """ + Returns the PID coefficient of the servo controller. + + @rtype: list [P, I, D] + @return: A three item list, containing the PID coefficient as floats: + P : proportional coefficient + I : Integral coefficient + D : Derivate coefficient + """ + def setPID(P, I, D): + """ + Sets the PID coefficients of the servo controller. + + @type P: flat + @param P: proportional coefficient + @type I: float + @param I: Integral coefficient + @type D: float + @param D: Derivate coefficient + """ diff --git a/source/gameengine/PyDoc/KX_StateActuator.py b/source/gameengine/PyDoc/KX_StateActuator.py new file mode 100644 index 00000000000..fb6ae5a3621 --- /dev/null +++ b/source/gameengine/PyDoc/KX_StateActuator.py @@ -0,0 +1,26 @@ +# $Id$ +# Documentation for KX_StateActuator +from SCA_IActuator import * + +class KX_StateActuator(SCA_IActuator): + """ + State actuator changes the state mask of parent object. + """ + def setOperation(op): + """ + Set the type of bit operation to be applied on object state mask. + Use setMask() to specify the bits that will be modified. + + @param op: bit operation (0=Copy, 1=Add, 2=Substract, 3=Invert) + @type op: integer + """ + def setMask(mask): + """ + Set the value that defines the bits that will be modified by the operation. + The bits that are 1 in the value will be updated in the object state, + the bits that are 0 are will be left unmodified expect for the Copy operation + which copies the value to the object state. + + @param mask: bits that will be modified + @type mask: integer + """ diff --git a/source/gameengine/PyDoc/SCA_ISensor.py b/source/gameengine/PyDoc/SCA_ISensor.py index b96d8c8c075..0ebc2debb31 100644 --- a/source/gameengine/PyDoc/SCA_ISensor.py +++ b/source/gameengine/PyDoc/SCA_ISensor.py @@ -59,4 +59,22 @@ class SCA_ISensor(SCA_ILogicBrick): @type invert: boolean @param invert: true if activates on negative events; false if activates on positive events. """ + def getLevel(): + """ + Returns whether this sensor is a level detector or a edge detector. + It makes a difference only in case of logic state transition (state actuator). + A level detector will immediately generate a pulse, negative or positive + depending on the sensor condition, as soon as the state is activated. + A edge detector will wait for a state change before generating a pulse. + + @rtype: boolean + @return: true if sensor is level sensitive, false if it is edge sensitive + """ + def setLevel(level): + """ + Set whether to detect level or edge transition when entering a state. + + @param level: Detect level instead of edge? (KX_TRUE, KX_FALSE) + @type level: boolean + """ diff --git a/source/gameengine/Rasterizer/Makefile b/source/gameengine/Rasterizer/Makefile index 1ca3e3b0283..e3b1f274ee5 100644 --- a/source/gameengine/Rasterizer/Makefile +++ b/source/gameengine/Rasterizer/Makefile @@ -41,6 +41,9 @@ CPPFLAGS += -I$(NAN_STRING)/include CPPFLAGS += -I$(NAN_MOTO)/include CPPFLAGS += -I../../kernel/gen_system CPPFLAGS += -I../BlenderRoutines +CPPFLAGS += -I../Expressions + +CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) ifeq ($(OS),darwin) CPPFLAGS += -fpascal-strings diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp index 958fead33ce..ef206332057 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp @@ -43,6 +43,7 @@ #include "STR_String.h" #include "RAS_ICanvas.h" +#include "RAS_Rect.h" #include "RAS_2DFilterManager.h" #include <iostream> @@ -158,7 +159,8 @@ void RAS_2DFilterManager::AnalyseShader(int passindex, vector<STR_String>& propN texflag[passindex] = 0; if(glGetUniformLocationARB(m_filters[passindex], "bgl_DepthTexture") != -1) { - texflag[passindex] |= 0x1; + if(GLEW_ARB_depth_texture) + texflag[passindex] |= 0x1; } if(glGetUniformLocationARB(m_filters[passindex], "bgl_LuminanceTexture") != -1) { @@ -261,7 +263,7 @@ void RAS_2DFilterManager::SetupTextures(bool depth, bool luminance) glGenTextures(1, (GLuint*)&texname[0]); glBindTexture(GL_TEXTURE_2D, texname[0]); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texturewidth, textureheight, 0, GL_RGB, + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texturewidth, textureheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -293,10 +295,13 @@ void RAS_2DFilterManager::SetupTextures(bool depth, bool luminance) } } -void RAS_2DFilterManager::UpdateOffsetMatrix(int width, int height) +void RAS_2DFilterManager::UpdateOffsetMatrix(RAS_ICanvas* canvas) { - canvaswidth = texturewidth = width; - canvasheight = textureheight = height; + RAS_Rect canvas_rect = canvas->GetWindowArea(); + canvaswidth = canvas->GetWidth(); + canvasheight = canvas->GetHeight(); + texturewidth = canvaswidth + canvas_rect.GetLeft(); + textureheight = canvasheight + canvas_rect.GetBottom(); GLint i,j; i = 0; @@ -352,7 +357,7 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) if(canvaswidth != canvas->GetWidth() || canvasheight != canvas->GetHeight()) { - UpdateOffsetMatrix(canvas->GetWidth(), canvas->GetHeight()); + UpdateOffsetMatrix(canvas); SetupTextures(need_depth, need_luminance); } GLuint viewport[4]={0}; @@ -360,19 +365,21 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) if(need_depth){ glActiveTextureARB(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texname[1]); - glCopyTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT, 0,0, texturewidth,textureheight, 0); + glCopyTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT, 0, 0, texturewidth,textureheight, 0); } if(need_luminance){ glActiveTextureARB(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, texname[2]); - glCopyTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE16, 0,0, texturewidth,textureheight, 0); + glCopyTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE16, 0, 0 , texturewidth,textureheight, 0); } glGetIntegerv(GL_VIEWPORT,(GLint *)viewport); - glViewport(0, 0, texturewidth, textureheight); + glViewport(0,0, texturewidth, textureheight); glDisable(GL_DEPTH_TEST); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.h b/source/gameengine/Rasterizer/RAS_2DFilterManager.h index 9d8326b96de..f5998e1f093 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.h +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.h @@ -42,7 +42,7 @@ private: void SetupTextures(bool depth, bool luminance); void FreeTextures(); - void UpdateOffsetMatrix(int width, int height); + void UpdateOffsetMatrix(RAS_ICanvas* canvas); float textureoffsets[18]; float view[4]; diff --git a/source/gameengine/Rasterizer/RAS_BucketManager.cpp b/source/gameengine/Rasterizer/RAS_BucketManager.cpp index b4492ca03a9..82bdce44519 100644 --- a/source/gameengine/Rasterizer/RAS_BucketManager.cpp +++ b/source/gameengine/Rasterizer/RAS_BucketManager.cpp @@ -94,7 +94,6 @@ void RAS_BucketManager::RenderAlphaBuckets( const MT_Scalar cam_origin = cameratrans.getOrigin()[2]; for (bit = m_AlphaBuckets.begin(); bit != m_AlphaBuckets.end(); ++bit) { - (*bit)->ClearScheduledPolygons(); for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) { if ((*mit).m_bVisible) @@ -133,28 +132,15 @@ void RAS_BucketManager::Renderbuckets( rasty->ClearCachingInfo(); RAS_MaterialBucket::StartFrame(); - for (bucket = m_MaterialBuckets.begin(); bucket != m_MaterialBuckets.end(); ++bucket) - { - (*bucket)->ClearScheduledPolygons(); - } for (bucket = m_MaterialBuckets.begin(); bucket != m_MaterialBuckets.end(); ++bucket) - { - RAS_IPolyMaterial *tmp = (*bucket)->GetPolyMaterial(); - if(tmp->IsZSort() || tmp->GetFlag() &RAS_FORCEALPHA ) - rasty->SetAlphaTest(true); - else - rasty->SetAlphaTest(false); - (*bucket)->Render(cameratrans,rasty,rendertools); - } - rasty->SetAlphaTest(false); RenderAlphaBuckets(cameratrans, rasty, rendertools); RAS_MaterialBucket::EndFrame(); } -RAS_MaterialBucket* RAS_BucketManager::RAS_BucketManagerFindBucket(RAS_IPolyMaterial * material, bool &bucketCreated) +RAS_MaterialBucket* RAS_BucketManager::FindBucket(RAS_IPolyMaterial * material, bool &bucketCreated) { bucketCreated = false; BucketList::iterator it; @@ -172,7 +158,7 @@ RAS_MaterialBucket* RAS_BucketManager::RAS_BucketManagerFindBucket(RAS_IPolyMate RAS_MaterialBucket *bucket = new RAS_MaterialBucket(material); bucketCreated = true; - if (bucket->IsTransparant()) + if (bucket->IsAlpha()) m_AlphaBuckets.push_back(bucket); else m_MaterialBuckets.push_back(bucket); @@ -195,3 +181,28 @@ void RAS_BucketManager::RAS_BucketManagerClearAll() m_MaterialBuckets.clear(); m_AlphaBuckets.clear(); } + +void RAS_BucketManager::ReleaseDisplayLists() +{ + BucketList::iterator bit; + RAS_MaterialBucket::T_MeshSlotList::iterator mit; + + for (bit = m_MaterialBuckets.begin(); bit != m_MaterialBuckets.end(); ++bit) { + for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) { + if(mit->m_DisplayList) { + mit->m_DisplayList->Release(); + mit->m_DisplayList = NULL; + } + } + } + + for (bit = m_AlphaBuckets.begin(); bit != m_AlphaBuckets.end(); ++bit) { + for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) { + if(mit->m_DisplayList) { + mit->m_DisplayList->Release(); + mit->m_DisplayList = NULL; + } + } + } +} + diff --git a/source/gameengine/Rasterizer/RAS_BucketManager.h b/source/gameengine/Rasterizer/RAS_BucketManager.h index 010478b1d5b..08b67ed022f 100644 --- a/source/gameengine/Rasterizer/RAS_BucketManager.h +++ b/source/gameengine/Rasterizer/RAS_BucketManager.h @@ -58,8 +58,9 @@ public: RAS_IRasterizer* rasty, class RAS_IRenderTools* rendertools); - RAS_MaterialBucket* RAS_BucketManagerFindBucket(RAS_IPolyMaterial * material, bool &bucketCreated); + RAS_MaterialBucket* FindBucket(RAS_IPolyMaterial * material, bool &bucketCreated); + void ReleaseDisplayLists(); private: void RAS_BucketManagerClearAll(); diff --git a/source/gameengine/Rasterizer/RAS_CameraData.h b/source/gameengine/Rasterizer/RAS_CameraData.h index 0327a3f4763..e3af43fb839 100644 --- a/source/gameengine/Rasterizer/RAS_CameraData.h +++ b/source/gameengine/Rasterizer/RAS_CameraData.h @@ -42,7 +42,7 @@ struct RAS_CameraData int m_viewporttop; float m_focallength; - RAS_CameraData(float lens = 35., float clipstart = 0.1, float clipend = 100., bool perspective = true, + RAS_CameraData(float lens = 35.0, float clipstart = 0.1, float clipend = 5000.0, bool perspective = true, float focallength = 0.0f, bool viewport = false, int viewportleft = 0, int viewportbottom = 0, int viewportright = 0, int viewporttop = 0) : m_lens(lens), diff --git a/source/gameengine/Rasterizer/RAS_ICanvas.h b/source/gameengine/Rasterizer/RAS_ICanvas.h index d799dc9c9bb..f3f817a943d 100644 --- a/source/gameengine/Rasterizer/RAS_ICanvas.h +++ b/source/gameengine/Rasterizer/RAS_ICanvas.h @@ -137,6 +137,14 @@ public: ) = 0; /** + * Used to get canvas area within blender. + */ + virtual + RAS_Rect & + GetWindowArea( + ) = 0; + + /** * Set the visible vieport */ diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp index cb10ba6bf37..4ee06d96603 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp @@ -39,7 +39,8 @@ RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname, int tilexrep, int tileyrep, int mode, - bool transparant, + int transp, + bool alpha, bool zsort, int lightlayer, bool bIsTriangle, @@ -51,7 +52,8 @@ RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname, m_tilexrep(tilexrep), m_tileyrep(tileyrep), m_drawingmode (mode), - m_transparant(transparant), + m_transp(transp), + m_alpha(alpha), m_zsort(zsort), m_lightlayer(lightlayer), m_bIsTriangle(bIsTriangle), @@ -74,6 +76,7 @@ bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const this->m_multimode == lhs.m_multimode && this->m_flag == lhs.m_flag && this->m_drawingmode == lhs.m_drawingmode && + this->m_transp == lhs.m_transp && this->m_lightlayer == lhs.m_lightlayer && this->m_texturename.hash() == lhs.m_texturename.hash() && this->m_materialname.hash() == lhs.m_materialname.hash() @@ -85,7 +88,8 @@ bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const this->m_tile == lhs.m_tile && this->m_tilexrep == lhs.m_tilexrep && this->m_tileyrep == lhs.m_tileyrep && - this->m_transparant == lhs.m_transparant && + this->m_transp == lhs.m_transp && + this->m_alpha == lhs.m_alpha && this->m_zsort == lhs.m_zsort && this->m_drawingmode == lhs.m_drawingmode && this->m_bIsTriangle == lhs.m_bIsTriangle && @@ -109,9 +113,9 @@ int RAS_IPolyMaterial::GetLightLayer() const return m_lightlayer; } -bool RAS_IPolyMaterial::IsTransparant() const +bool RAS_IPolyMaterial::IsAlpha() const { - return m_transparant; + return m_alpha || m_zsort; } bool RAS_IPolyMaterial::IsZSort() const @@ -139,6 +143,11 @@ const STR_String& RAS_IPolyMaterial::GetMaterialName() const return m_materialname; } +dword RAS_IPolyMaterial::GetMaterialNameHash() const +{ + return m_materialname.hash(); +} + const STR_String& RAS_IPolyMaterial::GetTextureName() const { return m_texturename; diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h index d2d1dba99d9..8fc53e6b038 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h @@ -52,7 +52,7 @@ enum MaterialProps RAS_AUTOGEN =128, RAS_NORMAL =256, RAS_DEFMULTI =512, - RAS_FORCEALPHA =1024 + RAS_BLENDERGLSL =1024 }; /** @@ -67,7 +67,8 @@ protected: int m_tile; int m_tilexrep,m_tileyrep; int m_drawingmode; // tface->mode - bool m_transparant; + int m_transp; + bool m_alpha; bool m_zsort; int m_lightlayer; bool m_bIsTriangle; @@ -102,7 +103,8 @@ public: int tilexrep, int tileyrep, int mode, - bool transparant, + int transp, + bool alpha, bool zsort, int lightlayer, bool bIsTriangle, @@ -132,12 +134,13 @@ public: virtual bool Equals(const RAS_IPolyMaterial& lhs) const; bool Less(const RAS_IPolyMaterial& rhs) const; int GetLightLayer() const; - bool IsTransparant() const; + bool IsAlpha() const; bool IsZSort() const; bool UsesTriangles() const; unsigned int hash() const; int GetDrawingMode() const; const STR_String& GetMaterialName() const; + dword GetMaterialNameHash() const; const STR_String& GetTextureName() const; const unsigned int GetFlag() const; diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index d4a9177a85d..9e03212283e 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -372,10 +372,6 @@ public: virtual void SetAmbientColor(float red, float green, float blue)=0; virtual void SetAmbient(float factor)=0; - /** - * Sets alpha testing - */ - virtual void SetAlphaTest(bool enable)=0; /** * Sets a polygon offset. z depth will be: z1 = mult*z0 + add @@ -398,8 +394,10 @@ public: virtual void DisableMotionBlur()=0; virtual float GetMotionBlurValue()=0; - virtual int GetMotionBlurState()=0; - virtual void SetMotionBlurState(int newstate)=0; + virtual int GetMotionBlurState()=0; + virtual void SetMotionBlurState(int newstate)=0; + + virtual void SetBlendingMode(int blendmode)=0; }; #endif //__RAS_IRASTERIZER diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index e295d69e48e..0015b6a251f 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -76,26 +76,11 @@ KX_MeshSlot::~KX_MeshSlot() RAS_MaterialBucket::RAS_MaterialBucket(RAS_IPolyMaterial* mat) :m_bModified(true) { - m_bScheduled=true; m_material = mat; } -void RAS_MaterialBucket::SchedulePolygons(int drawingmode) -{ - m_bScheduled = true; -} - - - -void RAS_MaterialBucket::ClearScheduledPolygons() -{ - m_bScheduled = false; -} - - - RAS_IPolyMaterial* RAS_MaterialBucket::GetPolyMaterial() const { return m_material; @@ -134,9 +119,14 @@ void RAS_MaterialBucket::MarkVisibleMeshSlot(KX_MeshSlot& ms, (*it).m_RGBAcolor= rgbavec; } -bool RAS_MaterialBucket::IsTransparant() const +bool RAS_MaterialBucket::IsAlpha() const +{ + return (m_material->IsAlpha()); +} + +bool RAS_MaterialBucket::IsZSort() const { - return (m_material->IsTransparant()); + return (m_material->IsZSort()); } diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.h b/source/gameengine/Rasterizer/RAS_MaterialBucket.h index 13d8a53714a..4eef889c533 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.h +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.h @@ -125,11 +125,9 @@ public: class RAS_IRasterizer* rasty, class RAS_IRenderTools* rendertools); - void SchedulePolygons(int drawingmode); - void ClearScheduledPolygons(); - RAS_IPolyMaterial* GetPolyMaterial() const; - bool IsTransparant() const; + bool IsAlpha() const; + bool IsZSort() const; static void StartFrame(); static void EndFrame(); @@ -162,7 +160,6 @@ public: private: T_MeshSlotList m_meshSlots; - bool m_bScheduled; bool m_bModified; RAS_IPolyMaterial* m_material; double* m_pOGLMatrix; diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp index 4420f16c56d..af5228e4c35 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp @@ -35,6 +35,8 @@ #include "MT_MinMax.h" #include "MT_Point3.h" +#include <algorithm> + STR_String RAS_MeshObject::s_emptyname = ""; @@ -201,28 +203,35 @@ void RAS_MeshObject::DebugColor(unsigned int abgr) m_debugcolor = abgr; } - +void RAS_MeshObject::SetVertexColor(RAS_IPolyMaterial* mat,MT_Vector4 rgba) +{ + const vecVertexArray & vertexvec = GetVertexCache(mat); + + for (vector<KX_VertexArray*>::const_iterator it = vertexvec.begin(); it != vertexvec.end(); ++it) + { + KX_VertexArray::iterator vit; + for (vit=(*it)->begin(); vit != (*it)->end(); vit++) + { + vit->SetRGBA(rgba); + } + } +} void RAS_MeshObject::SchedulePoly(const KX_VertexIndex& idx, int numverts, RAS_IPolyMaterial* mat) { - //int indexpos = m_IndexArrayCount[idx.m_vtxarray]; - //m_IndexArrayCount[idx.m_vtxarray] = indexpos + 3; - KX_ArrayOptimizer* ao = GetArrayOptimizer(mat); + ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[0]); ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[1]); ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[2]); - if (!mat->UsesTriangles()) //if (!m_bUseTriangles) - { - //m_IndexArrayCount[idx.m_vtxarray] = indexpos+4; + + if (!mat->UsesTriangles()) ao->m_IndexArrayCache1[idx.m_vtxarray]->push_back(idx.m_indexarray[3]); - } } - void RAS_MeshObject::ScheduleWireframePoly(const KX_VertexIndex& idx, int numverts, int edgecode, @@ -409,7 +418,6 @@ void RAS_MeshObject::Bucketize(double* oglmatrix, for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it) { RAS_MaterialBucket* bucket = *it; - bucket->SchedulePolygons(0); // KX_ArrayOptimizer* oa = GetArrayOptimizer(bucket->GetPolyMaterial()); bucket->SetMeshSlot(ms); } @@ -434,7 +442,6 @@ void RAS_MeshObject::MarkVisible(double* oglmatrix, for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it) { RAS_MaterialBucket* bucket = *it; - bucket->SchedulePolygons(0); // KX_ArrayOptimizer* oa = GetArrayOptimizer(bucket->GetPolyMaterial()); bucket->MarkVisibleMeshSlot(ms,visible,useObjectColor,rgbavec); } @@ -453,7 +460,6 @@ void RAS_MeshObject::RemoveFromBuckets(double* oglmatrix, { RAS_MaterialBucket* bucket = *it; // RAS_IPolyMaterial* polymat = bucket->GetPolyMaterial(); - bucket->SchedulePolygons(0); //KX_ArrayOptimizer* oa = GetArrayOptimizer(polymat); bucket->RemoveMeshSlot(ms); } @@ -572,31 +578,36 @@ void RAS_MeshObject::UpdateMaterialList() struct RAS_MeshObject::polygonSlot { - float m_z; - RAS_Polygon *m_poly; - - polygonSlot(float z, RAS_Polygon* poly) : - m_z(z), - m_poly(poly) - {} - /** - * pnorm and pval form the plane equation that the distance from is used to - * sort against. - */ - polygonSlot(const MT_Vector3 &pnorm, const MT_Scalar &pval, RAS_MeshObject *mesh, RAS_Polygon* poly) : - m_poly(poly) + float m_z; + int m_index[4]; + + polygonSlot() {} + + /* pnorm is the normal from the plane equation that the distance from is + * used to sort again. */ + void get(const KX_VertexArray& vertexarray, const KX_IndexArray& indexarray, + int offset, int nvert, const MT_Vector3& pnorm) { - const KX_VertexIndex &base = m_poly->GetIndexBase(); - RAS_TexVert *vert = mesh->GetVertex(base.m_vtxarray, base.m_indexarray[0], poly->GetMaterial()->GetPolyMaterial()); - m_z = MT_dot(pnorm, vert->getLocalXYZ()) + pval; - - for(int i = 1; i < m_poly->VertexCount(); i++) - { - vert = mesh->GetVertex(base.m_vtxarray, base.m_indexarray[i], poly->GetMaterial()->GetPolyMaterial()); - float z = MT_dot(pnorm, vert->getLocalXYZ()) + pval; - m_z += z; + MT_Vector3 center(0, 0, 0); + int i; + + for(i=0; i<nvert; i++) { + m_index[i] = indexarray[offset+i]; + center += vertexarray[m_index[i]].getLocalXYZ(); } - m_z /= m_poly->VertexCount(); + + /* note we don't divide center by the number of vertices, since all + * polygons have the same number of vertices, and that we leave out + * the 4-th component of the plane equation since it is constant. */ + m_z = MT_dot(pnorm, center); + } + + void set(KX_IndexArray& indexarray, int offset, int nvert) + { + int i; + + for(i=0; i<nvert; i++) + indexarray[offset+i] = m_index[i]; } }; @@ -616,100 +627,100 @@ struct RAS_MeshObject::fronttoback } }; - void RAS_MeshObject::SortPolygons(const MT_Transform &transform) { + // Limitations: sorting is quite simple, and handles many + // cases wrong, partially due to polygons being sorted per + // bucket. + // + // a) mixed triangles/quads are sorted wrong + // b) mixed materials are sorted wrong + // c) more than 65k faces are sorted wrong + // d) intersecting objects are sorted wrong + // e) intersecting polygons are sorted wrong + // + // a) can be solved by making all faces either triangles or quads + // if they need to be z-sorted. c) could be solved by allowing + // larger buckets, b) and d) cannot be solved easily if we want + // to avoid excessive state changes while drawing. e) would + // require splitting polygons. + if (!m_zsort) return; - + // Extract camera Z plane... const MT_Vector3 pnorm(transform.getBasis()[2]); - const MT_Scalar pval = transform.getOrigin()[2]; - - unsigned int numpolys = m_Polygons.size(); - std::multiset<polygonSlot, backtofront> alphapolyset; - std::multiset<polygonSlot, fronttoback> solidpolyset; - - for (unsigned int p = 0; p < numpolys; p++) - { - RAS_Polygon* poly = m_Polygons[p]; - if (poly->IsVisible()) - { - if (poly->GetMaterial()->GetPolyMaterial()->IsTransparant()) - { - alphapolyset.insert(polygonSlot(pnorm, pval, this, poly)); - } else { - solidpolyset.insert(polygonSlot(pnorm, pval, this, poly)); - } - } - } - - // Clear current array data. + // unneeded: const MT_Scalar pval = transform.getOrigin()[2]; + for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it) { - vector<KX_IndexArray*> *indexcache = &GetArrayOptimizer((*it)->GetPolyMaterial())->m_IndexArrayCache1; - for (vector<KX_IndexArray*>::iterator iit = indexcache->begin(); iit != indexcache->end(); ++iit) - (*iit)->clear(); - } + if(!(*it)->IsZSort()) + continue; - std::multiset<polygonSlot, fronttoback>::iterator sit = solidpolyset.begin(); - for (; sit != solidpolyset.end(); ++sit) - SchedulePoly((*sit).m_poly->GetVertexIndexBase(), (*sit).m_poly->VertexCount(), (*sit).m_poly->GetMaterial()->GetPolyMaterial()); - - std::multiset<polygonSlot, backtofront>::iterator ait = alphapolyset.begin(); - for (; ait != alphapolyset.end(); ++ait) - SchedulePoly((*ait).m_poly->GetVertexIndexBase(), (*ait).m_poly->VertexCount(), (*ait).m_poly->GetMaterial()->GetPolyMaterial()); + RAS_IPolyMaterial *mat = (*it)->GetPolyMaterial(); + KX_ArrayOptimizer* ao = GetArrayOptimizer(mat); + + vecIndexArrays& indexarrays = ao->m_IndexArrayCache1; + vecVertexArray& vertexarrays = ao->m_VertexArrayCache1; + unsigned int i, j, nvert = (mat->UsesTriangles())? 3: 4; + + for(i=0; i<indexarrays.size(); i++) { + KX_IndexArray& indexarray = *indexarrays[i]; + KX_VertexArray& vertexarray = *vertexarrays[i]; + + unsigned int totpoly = indexarray.size()/nvert; + vector<polygonSlot> slots(totpoly); + + /* get indices and z into temporary array */ + for(j=0; j<totpoly; j++) + slots[j].get(vertexarray, indexarray, j*nvert, nvert, pnorm); + + /* sort (stable_sort might be better, if flickering happens?) */ + std::sort(slots.begin(), slots.end(), backtofront()); + + /* get indices from temporary array again */ + for(j=0; j<totpoly; j++) + slots[j].set(indexarray, j*nvert, nvert); + } + } } -void RAS_MeshObject::SchedulePolygons(const MT_Transform &transform, int drawingmode) +void RAS_MeshObject::SchedulePolygons(int drawingmode) { -// int nummaterials = m_materials.size(); - int i; - if (m_bModified) { - for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it) - { - RAS_MaterialBucket* bucket = *it; + int i, numpolys = m_Polygons.size(); - bucket->SchedulePolygons(drawingmode); - if (bucket->GetPolyMaterial()->IsZSort()) + for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();++it) + if ((*it)->IsZSort()) m_zsort = true; - } - - int numpolys = m_Polygons.size(); - if ((drawingmode > RAS_IRasterizer::KX_BOUNDINGBOX) && - (drawingmode < RAS_IRasterizer::KX_SOLID)) + if (drawingmode == RAS_IRasterizer::KX_WIREFRAME) { for (i=0;i<numpolys;i++) { RAS_Polygon* poly = m_Polygons[i]; if (poly->IsVisible()) - ScheduleWireframePoly(poly->GetVertexIndexBase(),poly->VertexCount(),poly->GetEdgeCode() - ,poly->GetMaterial()->GetPolyMaterial()); + ScheduleWireframePoly(poly->GetVertexIndexBase(),poly->VertexCount(),poly->GetEdgeCode(), + poly->GetMaterial()->GetPolyMaterial()); } m_zsort = false; } else { - if (!m_zsort) + for (i=0;i<numpolys;i++) { - for (i=0;i<numpolys;i++) - { - RAS_Polygon* poly = m_Polygons[i]; - if (poly->IsVisible()) - { - SchedulePoly(poly->GetVertexIndexBase(),poly->VertexCount(),poly->GetMaterial()->GetPolyMaterial()); - } - } + RAS_Polygon* poly = m_Polygons[i]; + if (poly->IsVisible()) + SchedulePoly(poly->GetVertexIndexBase(),poly->VertexCount(), + poly->GetMaterial()->GetPolyMaterial()); } } m_bModified = false; - m_MeshMod = true; } } + diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.h b/source/gameengine/Rasterizer/RAS_MeshObject.h index 0d06748f91f..99806666fa6 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.h +++ b/source/gameengine/Rasterizer/RAS_MeshObject.h @@ -137,6 +137,18 @@ class RAS_MeshObject struct backtofront; struct fronttoback; + void SchedulePoly( + const KX_VertexIndex& idx, + int numverts, + RAS_IPolyMaterial* mat + ); + + void ScheduleWireframePoly( + const KX_VertexIndex& idx, + int numverts, + int edgecode, + RAS_IPolyMaterial* mat + ); protected: enum { BUCKET_MAX_INDICES = 65535 };//2048};//8192}; @@ -189,16 +201,14 @@ public: ); void DebugColor(unsigned int abgr); + void SetVertexColor(RAS_IPolyMaterial* mat,MT_Vector4 rgba); /** * Sorts the polygons by their transformed z values. */ void SortPolygons(const MT_Transform &transform); - void SchedulePolygons( - const MT_Transform &transform, - int drawingmode - ); + void SchedulePolygons(int drawingmode); void ClearArrayData(); @@ -215,19 +225,7 @@ public: int numverts, RAS_IPolyMaterial* polymat ); - - void SchedulePoly( - const KX_VertexIndex& idx, - int numverts, - RAS_IPolyMaterial* mat - ); - void ScheduleWireframePoly( - const KX_VertexIndex& idx, - int numverts, - int edgecode, - RAS_IPolyMaterial* mat - ); // find (and share) or add vertices // for some speedup, only the last 20 added vertices are searched for equality diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index dcc36bf5a39..1dcc6e70934 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -67,6 +67,7 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas) m_motionblurvalue(-1.0), m_texco_num(0), m_attrib_num(0), + m_last_blendmode(0), m_materialCachingInfo(0) { m_viewmatrix.Identity(); @@ -171,6 +172,8 @@ bool RAS_OpenGLRasterizer::Init() m_ambg = 0.0f; m_ambb = 0.0f; + SetBlendingMode(0); + glClearColor(m_redback,m_greenback,m_blueback,m_alphaback); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -189,18 +192,6 @@ void RAS_OpenGLRasterizer::SetAmbientColor(float red, float green, float blue) } -void RAS_OpenGLRasterizer::SetAlphaTest(bool enable) -{ - if (enable) - { - glEnable(GL_ALPHA_TEST); - glAlphaFunc(GL_GREATER, 0.6f); - } - else glDisable(GL_ALPHA_TEST); -} - - - void RAS_OpenGLRasterizer::SetAmbient(float factor) { float ambient[] = { m_ambr*factor, m_ambg*factor, m_ambb*factor, 1.0f }; @@ -353,6 +344,8 @@ bool RAS_OpenGLRasterizer::BeginFrame(int drawingmode, double time) glEnable (GL_CULL_FACE); } + SetBlendingMode(0); + glShadeModel(GL_SMOOTH); m_2DCanvas->BeginFrame(); @@ -1389,3 +1382,34 @@ void RAS_OpenGLRasterizer::DisableMotionBlur() m_motionblur = 0; m_motionblurvalue = -1.0; } + +void RAS_OpenGLRasterizer::SetBlendingMode(int blendmode) +{ + if(blendmode == m_last_blendmode) + return; + + if(blendmode == 0) { + glDisable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + else if(blendmode == 1) { + glBlendFunc(GL_ONE, GL_ONE); + glEnable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + } + else if(blendmode == 2) { + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.0f); + } + else if(blendmode == 4) { + glDisable(GL_BLEND); + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.5f); + } + + m_last_blendmode = blendmode; +} + diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h index 0d54552db05..02056cce446 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h @@ -99,6 +99,7 @@ protected: TexCoGen m_attrib[RAS_MAX_ATTRIB]; int m_texco_num; int m_attrib_num; + int m_last_blendmode; /** Stores the caching information for the last material activated. */ RAS_IPolyMaterial::TCachingInfo m_materialCachingInfo; @@ -142,8 +143,6 @@ public: virtual void SetFocalLength(const float focallength); virtual float GetFocalLength(); - virtual void SetAlphaTest(bool enable); - virtual void SwapBuffers(); virtual void IndexPrimitives( const vecVertexArray& vertexarrays, @@ -282,8 +281,8 @@ public: virtual void EnableMotionBlur(float motionblurvalue); virtual void DisableMotionBlur(); virtual float GetMotionBlurValue(){return m_motionblurvalue;}; - virtual int GetMotionBlurState(){return m_motionblur;}; - virtual void SetMotionBlurState(int newstate) + virtual int GetMotionBlurState(){return m_motionblur;}; + virtual void SetMotionBlurState(int newstate) { if(newstate<0) m_motionblur = 0; @@ -292,6 +291,8 @@ public: else m_motionblur = newstate; }; + + virtual void SetBlendingMode(int blendmode); }; #endif //__RAS_OPENGLRASTERIZER diff --git a/source/gameengine/Rasterizer/RAS_Polygon.cpp b/source/gameengine/Rasterizer/RAS_Polygon.cpp index 852c94def3f..b74cb9cfcac 100644 --- a/source/gameengine/Rasterizer/RAS_Polygon.cpp +++ b/source/gameengine/Rasterizer/RAS_Polygon.cpp @@ -37,24 +37,6 @@ #include "RAS_Polygon.h" -/* -RAS_TexVert* RAS_Polygon::GetVertex(int index) -{ - if (m_bucket) - return m_bucket->GetVertex(m_vertexindexbase.m_vtxarray, m_vertexindexbase.m_indexarray[index]); - else - return NULL; -} -*/ - -/*void RAS_Polygon::Bucketize(double* oglmatrix) -{ - //Transform(trans); - if (m_bucket) - m_bucket->AddPolygon(this,oglmatrix); -} -*/ - RAS_Polygon::RAS_Polygon(RAS_MaterialBucket* bucket, bool visible, int numverts, diff --git a/source/gameengine/SceneGraph/SG_IObject.cpp b/source/gameengine/SceneGraph/SG_IObject.cpp index c347bbc6d9a..d0bdac5c8f0 100644 --- a/source/gameengine/SceneGraph/SG_IObject.cpp +++ b/source/gameengine/SceneGraph/SG_IObject.cpp @@ -104,7 +104,7 @@ SetSGClientObject( } - void + bool SG_IObject:: ActivateReplicationCallback( SG_IObject *replica @@ -112,8 +112,10 @@ ActivateReplicationCallback( if (m_callbacks.m_replicafunc) { // Call client provided replication func - m_callbacks.m_replicafunc(replica,m_SGclientObject,m_SGclientInfo); + if (m_callbacks.m_replicafunc(replica,m_SGclientObject,m_SGclientInfo) == NULL) + return false; } + return true; }; void diff --git a/source/gameengine/SceneGraph/SG_IObject.h b/source/gameengine/SceneGraph/SG_IObject.h index 438ab48c556..7f6bdfbbb1c 100644 --- a/source/gameengine/SceneGraph/SG_IObject.h +++ b/source/gameengine/SceneGraph/SG_IObject.h @@ -202,7 +202,7 @@ public: protected : - void + bool ActivateReplicationCallback( SG_IObject *replica ); diff --git a/source/gameengine/SceneGraph/SG_Node.cpp b/source/gameengine/SceneGraph/SG_Node.cpp index 4e90d7c4653..8de7ac83477 100644 --- a/source/gameengine/SceneGraph/SG_Node.cpp +++ b/source/gameengine/SceneGraph/SG_Node.cpp @@ -68,7 +68,7 @@ SG_Node* SG_Node::GetSGReplica() SG_Node* replica = new SG_Node(*this); if (replica == NULL) return NULL; - ProcessSGReplica(replica); + ProcessSGReplica(&replica); return replica; } @@ -76,25 +76,42 @@ SG_Node* SG_Node::GetSGReplica() void SG_Node:: ProcessSGReplica( - SG_Node* replica + SG_Node** replica ){ // Apply the replication call back function. - ActivateReplicationCallback(replica); + if (!ActivateReplicationCallback(*replica)) + { + delete (*replica); + *replica = NULL; + return; + } // clear the replica node of it's parent. - static_cast<SG_Node*>(replica)->m_SGparent = NULL; + static_cast<SG_Node*>(*replica)->m_SGparent = NULL; if (m_children.begin() != m_children.end()) { // if this node has children, the replica has too, so clear and clone children - replica->ClearSGChildren(); + (*replica)->ClearSGChildren(); NodeList::iterator childit; for (childit = m_children.begin();childit!=m_children.end();++childit) { - replica->AddChild((*childit)->GetSGReplica()); + SG_Node* childnode = (*childit)->GetSGReplica(); + if (childnode) + (*replica)->AddChild(childnode); } } + // Nodes without children and without client object are + // not worth to keep, they will just take up CPU + // This can happen in partial replication of hierarchy + // during group duplication. + if ((*replica)->m_children.empty() && + (*replica)->GetSGClientObject() == NULL) + { + delete (*replica); + *replica = NULL; + } } diff --git a/source/gameengine/SceneGraph/SG_Node.h b/source/gameengine/SceneGraph/SG_Node.h index f86e3046d93..ffaaad861e2 100644 --- a/source/gameengine/SceneGraph/SG_Node.h +++ b/source/gameengine/SceneGraph/SG_Node.h @@ -205,7 +205,7 @@ private: void ProcessSGReplica( - SG_Node* replica + SG_Node** replica ); /** |