diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-12-20 21:24:20 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-12-20 21:24:20 +0400 |
commit | 921b2ee2d44ed87363198d7bfa89bb7116b0818b (patch) | |
tree | 3e04fd777b5c32f4814357ff9d18289ee072c962 /source/blender | |
parent | 1dc74acc123721d366e3628663ed029db5761e4d (diff) | |
parent | 738fdc7b6f43c3e1e838bd4239b36340fa4c2e0f (diff) |
Merging r42723 through r42769 from trunk into soc-2011-tomato
Diffstat (limited to 'source/blender')
42 files changed, 941 insertions, 687 deletions
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index 84f8995b480..23073a2d8eb 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -65,6 +65,11 @@ typedef enum { * unless it's a mesh and can be exploded -> curve can also emit particles */ eModifierTypeType_DeformOrConstruct, + + /* Like eModifierTypeType_Nonconstructive, but does not affect the geometry + * of the object, rather some of its CustomData layers. + * E.g. UVProject and WeightVG modifiers. */ + eModifierTypeType_NonGeometrical, } ModifierTypeType; typedef enum { @@ -311,6 +316,7 @@ int modifier_supportsMapping(struct ModifierData *md); int modifier_couldBeCage(struct Scene *scene, struct ModifierData *md); int modifier_isCorrectableDeformed(struct ModifierData *md); int modifier_sameTopology(ModifierData *md); +int modifier_nonGeometrical(ModifierData *md); int modifier_isEnabled(struct Scene *scene, struct ModifierData *md, int required_mode); void modifier_setError(struct ModifierData *md, const char *format, ...) #ifdef __GNUC__ diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 378e5872791..6234308048b 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -305,8 +305,6 @@ void ntreeSwitchID(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sc void ntreeMakeLocal(struct bNodeTree *ntree); int ntreeHasType(struct bNodeTree *ntree, int type); -void ntreeSocketUseFlags(struct bNodeTree *ntree); - void ntreeUpdateTree(struct bNodeTree *ntree); /* XXX Currently each tree update call does call to ntreeVerifyNodes too. * Some day this should be replaced by a decent depsgraph automatism! diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h index 52fa52a5899..7f321abf48e 100644 --- a/source/blender/blenkernel/BKE_texture.h +++ b/source/blender/blenkernel/BKE_texture.h @@ -67,7 +67,7 @@ void free_plugin_tex(struct PluginTex *pit); void init_colorband(struct ColorBand *coba, int rangetype); struct ColorBand *add_colorband(int rangetype); -int do_colorband(struct ColorBand *coba, float in, float out[4]); +int do_colorband(const struct ColorBand *coba, float in, float out[4]); void colorband_table_RGBA(struct ColorBand *coba, float **array, int *size); int vergcband(const void *a1, const void *a2); struct CBData *colorband_element_add(struct ColorBand *coba, float position); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 3bc2ee61e7b..d0ef517e2ae 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -642,7 +642,7 @@ enum { CALC_WP_AUTO_NORMALIZE= (1<<1) }; -void weightpaint_color(unsigned char r_col[4], ColorBand *coba, const float input) +static void weightpaint_color(unsigned char r_col[4], ColorBand *coba, const float input) { float colf[4]; @@ -669,10 +669,10 @@ static void calc_weightpaint_vert_color( if ((selected > 1) && (draw_flag & CALC_WP_MULTIPAINT)) { int was_a_nonzero= FALSE; - int i; + unsigned int i; MDeformWeight *dw= dv->dw; - for (i = dv->totweight; i > 0; i--, dw++) { + for (i = dv->totweight; i != 0; i--, dw++) { /* in multipaint, get the average if auto normalize is inactive * get the sum if it is active */ if (dw->def_nr < defbase_tot) { @@ -717,46 +717,65 @@ void vDM_ColorBand_store(ColorBand *coba) stored_cb= coba; } -static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag) +/* return an array of vertex weight colors, caller must free. + * + * note that we could save some memory and allocate RGB only but then we'd need to + * re-arrange the colors when copying to the face since MCol has odd ordering, + * so leave this as is - campbell */ +static unsigned char *calc_weightpaint_vert_array(Object *ob, int const draw_flag, ColorBand *coba) { Mesh *me = ob->data; - ColorBand *coba= stored_cb; /* warning, not a local var */ - - unsigned char *wtcol = MEM_mallocN (sizeof (unsigned char) * me->totface*4*4, "weightmap"); + unsigned char *wtcol_v = MEM_mallocN (sizeof(unsigned char) * me->totvert * 4, "weightmap_v"); if (me->dvert) { - MDeformVert *dvert= me->dvert; - MFace *mf = me->mface; + unsigned char *wc = wtcol_v; + MDeformVert *dv= me->dvert; + unsigned int i; + /* varisbles for multipaint */ const int defbase_tot = BLI_countlist(&ob->defbase); const int defbase_act = ob->actdef-1; char *dg_flags = MEM_mallocN(defbase_tot * sizeof(char), __func__); const int selected = get_selected_defgroups(ob, dg_flags, defbase_tot); /* const int unselected = defbase_tot - selected; */ /* UNUSED */ - int i; - - memset(wtcol, 0x55, sizeof (unsigned char) * me->totface*4*4); - for (i=0; i<me->totface; i++, mf++) { - unsigned int fidx= mf->v4 ? 3:2; - do { - calc_weightpaint_vert_color(&wtcol[(i*4 + fidx)*4], - &dvert[*(&mf->v1 + fidx)], coba, - defbase_tot, defbase_act, - dg_flags, selected, draw_flag); - } while (fidx--); + for (i = me->totvert; i != 0; i--, wc += 4, dv++) { + calc_weightpaint_vert_color(wc, dv, coba, defbase_tot, defbase_act, dg_flags, selected, draw_flag); } MEM_freeN(dg_flags); } else { - /* no weights, fill in zero */ int col_i; weightpaint_color((unsigned char *)&col_i, coba, 0.0f); - fill_vn_i((int *)wtcol, me->totface*4, col_i); + fill_vn_i((int *)wtcol_v, me->totvert, col_i); + } + + return wtcol_v; +} + +static void add_weight_mcol_dm(Object *ob, DerivedMesh *dm, int const draw_flag) +{ + ColorBand *coba= stored_cb; /* warning, not a local var */ + + Mesh *me = ob->data; + unsigned char *wtcol_v = calc_weightpaint_vert_array(ob, draw_flag, coba); + unsigned char *wtcol_f = MEM_mallocN (sizeof(unsigned char) * me->totface*4*4, "weightmap_f"); + + MFace *mf = me->mface; + int i; + + for (i=0; i<me->totface; i++, mf++) { + unsigned int fidx= mf->v4 ? 3:2; + do { + copy_v4_v4_char((char *)&wtcol_f[(4 * i + fidx) * 4], + (char *)&wtcol_v[4 * (*(&mf->v1 + fidx))]); + } while (fidx--); } - CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol, dm->numFaceData); + MEM_freeN(wtcol_v); + + CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol_f, dm->numFaceData); } /* new value for useDeform -1 (hack for the gameengine): diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index f09be8c34ad..5a389019519 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -239,7 +239,14 @@ int modifier_couldBeCage(struct Scene *scene, ModifierData *md) int modifier_sameTopology(ModifierData *md) { ModifierTypeInfo *mti = modifierType_getInfo(md->type); - return ( mti->type == eModifierTypeType_OnlyDeform || mti->type == eModifierTypeType_Nonconstructive); + return ELEM3(mti->type, eModifierTypeType_OnlyDeform, eModifierTypeType_Nonconstructive, + eModifierTypeType_NonGeometrical); +} + +int modifier_nonGeometrical(ModifierData *md) +{ + ModifierTypeInfo *mti = modifierType_getInfo(md->type); + return (mti->type == eModifierTypeType_NonGeometrical); } void modifier_setError(ModifierData *md, const char *format, ...) diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index cc49e8465b9..ce1dd429794 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1325,32 +1325,6 @@ void nodeSetActive(bNodeTree *ntree, bNode *node) node->flag |= NODE_ACTIVE_TEXTURE; } -/* use flags are not persistent yet, groups might need different tagging, so we do it each time - when we need to get this info */ -void ntreeSocketUseFlags(bNodeTree *ntree) -{ - bNode *node; - bNodeSocket *sock; - bNodeLink *link; - - /* clear flags */ - for(node= ntree->nodes.first; node; node= node->next) { - for(sock= node->inputs.first; sock; sock= sock->next) - sock->flag &= ~SOCK_IN_USE; - for(sock= node->outputs.first; sock; sock= sock->next) - sock->flag &= ~SOCK_IN_USE; - } - - /* tag all thats in use */ - for(link= ntree->links.first; link; link= link->next) { - - if(link->fromsock) // FIXME, see below - link->fromsock->flag |= SOCK_IN_USE; - if(link->tosock) // FIXME This can be NULL, when dragging a new link in the UI, should probably copy the node tree for preview render - campbell - link->tosock->flag |= SOCK_IN_USE; - } -} - /* ************** dependency stuff *********** */ /* node is guaranteed to be not checked before */ @@ -1425,16 +1399,27 @@ static void ntree_update_link_pointers(bNodeTree *ntree) /* first clear data */ for(node= ntree->nodes.first; node; node= node->next) { - for(sock= node->inputs.first; sock; sock= sock->next) + for(sock= node->inputs.first; sock; sock= sock->next) { sock->link= NULL; + sock->flag &= ~SOCK_IN_USE; + } + for(sock= node->outputs.first; sock; sock= sock->next) { + sock->flag &= ~SOCK_IN_USE; + } + } + for(sock= ntree->inputs.first; sock; sock= sock->next) { + sock->flag &= ~SOCK_IN_USE; } - /* clear socket links */ - for(sock= ntree->outputs.first; sock; sock= sock->next) + for(sock= ntree->outputs.first; sock; sock= sock->next) { sock->link= NULL; + sock->flag &= ~SOCK_IN_USE; + } for(link= ntree->links.first; link; link= link->next) { - if (link->tosock) - link->tosock->link= link; + link->tosock->link= link; + + link->fromsock->flag |= SOCK_IN_USE; + link->tosock->flag |= SOCK_IN_USE; } } diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 93404dc25fb..7051376a1f4 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -349,9 +349,9 @@ ColorBand *add_colorband(int rangetype) /* ------------------------------------------------------------------------- */ -int do_colorband(ColorBand *coba, float in, float out[4]) +int do_colorband(const ColorBand *coba, float in, float out[4]) { - CBData *cbd1, *cbd2, *cbd0, *cbd3; + const CBData *cbd1, *cbd2, *cbd0, *cbd3; float fac, mfac, t[4]; int a; diff --git a/source/blender/blenlib/BLI_dynstr.h b/source/blender/blenlib/BLI_dynstr.h index e27a315a023..32c4e012d1d 100644 --- a/source/blender/blenlib/BLI_dynstr.h +++ b/source/blender/blenlib/BLI_dynstr.h @@ -100,6 +100,17 @@ int BLI_dynstr_get_len (DynStr *ds); */ char* BLI_dynstr_get_cstring (DynStr *ds); +/** + * Get a DynStr's contents as a c-string. + * <i> The str argument must be allocated to be at + * least the size of BLI_dynstr_get_len(ds) + 1. </i> + * + * @param ds The DynStr of interest. + * @param str The string to fill. + * @return The contents of @a ds as a c-string. + */ +void BLI_dynstr_get_cstring_ex (DynStr *ds, char *str); + /** * Free the DynStr * diff --git a/source/blender/blenlib/intern/BLI_dynstr.c b/source/blender/blenlib/intern/BLI_dynstr.c index 349bc3492e7..ad52de180aa 100644 --- a/source/blender/blenlib/intern/BLI_dynstr.c +++ b/source/blender/blenlib/intern/BLI_dynstr.c @@ -226,11 +226,11 @@ int BLI_dynstr_get_len(DynStr *ds) return ds->curlen; } -char *BLI_dynstr_get_cstring(DynStr *ds) +void BLI_dynstr_get_cstring_ex(DynStr *ds, char *rets) { - char *s, *rets= MEM_mallocN(ds->curlen+1, "dynstr_cstring"); + char *s; DynStrElem *dse; - + for (s= rets, dse= ds->elems; dse; dse= dse->next) { int slen= strlen(dse->str); @@ -239,7 +239,12 @@ char *BLI_dynstr_get_cstring(DynStr *ds) s+= slen; } rets[ds->curlen]= '\0'; - +} + +char *BLI_dynstr_get_cstring(DynStr *ds) +{ + char *rets= MEM_mallocN(ds->curlen+1, "dynstr_cstring"); + BLI_dynstr_get_cstring_ex(ds, rets); return rets; } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index ab362fba143..8c96e4fa377 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -7459,6 +7459,30 @@ void do_versions_image_settings_2_60(Scene *sce) } +/* socket use flags were only temporary before */ +static void do_versions_nodetree_socket_use_flags_2_62(bNodeTree *ntree) +{ + bNode *node; + bNodeSocket *sock; + bNodeLink *link; + + for (node=ntree->nodes.first; node; node=node->next) { + for (sock=node->inputs.first; sock; sock=sock->next) + sock->flag &= ~SOCK_IN_USE; + for (sock=node->outputs.first; sock; sock=sock->next) + sock->flag &= ~SOCK_IN_USE; + } + for (sock=ntree->inputs.first; sock; sock=sock->next) + sock->flag &= ~SOCK_IN_USE; + for (sock=ntree->outputs.first; sock; sock=sock->next) + sock->flag &= ~SOCK_IN_USE; + + for (link=ntree->links.first; link; link=link->next) { + link->fromsock->flag |= SOCK_IN_USE; + link->tosock->flag |= SOCK_IN_USE; + } +} + static void do_versions(FileData *fd, Library *lib, Main *main) { /* WATCH IT!!!: pointers from libdata have not been converted */ @@ -12688,40 +12712,82 @@ static void do_versions(FileData *fd, Library *lib, Main *main) /* put compatibility code here until next subversion bump */ { - MovieClip *clip; - Object *ob; + { + /* update use flags for node sockets (was only temporary before) */ + Scene *sce; + Material *mat; + Tex *tex; + Lamp *lamp; + World *world; + bNodeTree *ntree; - for (clip= main->movieclip.first; clip; clip= clip->id.next) { - MovieTracking *tracking= &clip->tracking; - MovieTrackingObject *tracking_object= tracking->objects.first; + for (sce=main->scene.first; sce; sce=sce->id.next) + if (sce->nodetree) + do_versions_nodetree_socket_use_flags_2_62(sce->nodetree); - if(!tracking->settings.object_distance) - tracking->settings.object_distance= 1.0f; + for (mat=main->mat.first; mat; mat=mat->id.next) + if (mat->nodetree) + do_versions_nodetree_socket_use_flags_2_62(mat->nodetree); + + for (tex=main->tex.first; tex; tex=tex->id.next) + if (tex->nodetree) + do_versions_nodetree_socket_use_flags_2_62(tex->nodetree); - if(tracking->objects.first == NULL) - BKE_tracking_new_object(tracking, "Camera"); + for (lamp=main->lamp.first; lamp; lamp=lamp->id.next) + if (lamp->nodetree) + do_versions_nodetree_socket_use_flags_2_62(lamp->nodetree); - while(tracking_object) { - if(!tracking_object->scale) - tracking_object->scale= 1.0f; + for (world=main->world.first; world; world=world->id.next) + if (world->nodetree) + do_versions_nodetree_socket_use_flags_2_62(world->nodetree); - tracking_object= tracking_object->next; + for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) + do_versions_nodetree_socket_use_flags_2_62(ntree); + } + { + /* Initialize BGE exit key to esc key */ + Scene *scene; + for(scene= main->scene.first; scene; scene= scene->id.next) { + if (!scene->gm.exitkey) + scene->gm.exitkey = 218; // Blender key code for ESC } } + { + MovieClip *clip; + Object *ob; - for (ob= main->object.first; ob; ob= ob->id.next) { - bConstraint *con; - for (con= ob->constraints.first; con; con=con->next) { - bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + for (clip= main->movieclip.first; clip; clip= clip->id.next) { + MovieTracking *tracking= &clip->tracking; + MovieTrackingObject *tracking_object= tracking->objects.first; + + if(!tracking->settings.object_distance) + tracking->settings.object_distance= 1.0f; + + if(tracking->objects.first == NULL) + BKE_tracking_new_object(tracking, "Camera"); + + while(tracking_object) { + if(!tracking_object->scale) + tracking_object->scale= 1.0f; + + tracking_object= tracking_object->next; + } + } + + for (ob= main->object.first; ob; ob= ob->id.next) { + bConstraint *con; + for (con= ob->constraints.first; con; con=con->next) { + bConstraintTypeInfo *cti= constraint_get_typeinfo(con); - if(!cti) - continue; + if(!cti) + continue; - if(cti->type==CONSTRAINT_TYPE_OBJECTSOLVER) { - bObjectSolverConstraint *data= (bObjectSolverConstraint *)con->data; + if(cti->type==CONSTRAINT_TYPE_OBJECTSOLVER) { + bObjectSolverConstraint *data= (bObjectSolverConstraint *)con->data; - if(data->invmat[3][3]==0.0f) - unit_m4(data->invmat); + if(data->invmat[3][3]==0.0f) + unit_m4(data->invmat); + } } } } diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index f75f2921e51..3a69db013c0 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -243,6 +243,19 @@ int ED_mesh_color_add(struct bContext *C, struct Scene *scene, struct Object *ob int ED_mesh_color_remove(struct bContext *C, struct Object *ob, struct Mesh *me); int ED_mesh_color_remove_named(struct bContext *C, struct Object *ob, struct Mesh *me, const char *name); + +/* mirrtopo */ +typedef struct MirrTopoStore_t { + intptr_t *index_lookup; + int prev_vert_tot; + int prev_edge_tot; + int prev_ob_mode; +} MirrTopoStore_t; + +int ED_mesh_mirrtopo_recalc_check(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store); +void ED_mesh_mirrtopo_init(struct Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store); +void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store); + #ifdef __cplusplus } #endif diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index ea45337ddb3..9853c9c049b 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -845,7 +845,7 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob, Modif uiLayoutSetOperatorContext(row, WM_OP_INVOKE_DEFAULT); uiItemEnumO(row, "OBJECT_OT_modifier_apply", IFACE_("Apply"), 0, "apply_as", MODIFIER_APPLY_DATA); - if (modifier_sameTopology(md)) + if (modifier_sameTopology(md) && !modifier_nonGeometrical(md)) uiItemEnumO(row, "OBJECT_OT_modifier_apply", IFACE_("Apply as Shape"), 0, "apply_as", MODIFIER_APPLY_SHAPE); } @@ -853,7 +853,7 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob, Modif uiBlockSetButLock(block, ob && ob->id.lib, ERROR_LIBDATA_MESSAGE); if (!ELEM5(md->type, eModifierType_Fluidsim, eModifierType_Softbody, eModifierType_ParticleSystem, eModifierType_Cloth, eModifierType_Smoke)) - uiItemO(row, TIP_("Copy"), ICON_NONE, "OBJECT_OT_modifier_copy"); + uiItemO(row, IFACE_("Copy"), ICON_NONE, "OBJECT_OT_modifier_copy"); } /* result is the layout block inside the box, that we return so that modifier settings can be drawn */ diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index 02d20e64bc3..95c71488d26 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -815,3 +815,229 @@ int do_paintface_box_select(ViewContext *vc, rcti *rect, int select, int extend) return OPERATOR_FINISHED; } + + +/* ********************* MESH VERTEX MIRR TOPO LOOKUP *************** */ +/* note, this is not the best place for the function to be but moved + * here to for the purpose of syncing with bmesh */ + +typedef int MirrTopoHash_t; + +typedef struct MirrTopoPair_t { + MirrTopoHash_t hash; + int v_index; +} MirrTopoPair_t; + +static int MirrTopo_long_sort(const void *l1, const void *l2) +{ + if ((MirrTopoHash_t)(intptr_t)l1 > (MirrTopoHash_t)(intptr_t)l2 ) return 1; + else if ((MirrTopoHash_t)(intptr_t)l1 < (MirrTopoHash_t)(intptr_t)l2 ) return -1; + return 0; +} + +static int MirrTopo_item_sort(const void *v1, const void *v2) +{ + if (((MirrTopoPair_t *)v1)->hash > ((MirrTopoPair_t *)v2)->hash ) return 1; + else if (((MirrTopoPair_t *)v1)->hash < ((MirrTopoPair_t *)v2)->hash ) return -1; + return 0; +} + +int ED_mesh_mirrtopo_recalc_check(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store) +{ + int totvert; + int totedge; + + if (me->edit_mesh) { + totvert= me->edit_mesh->totvert; + totedge= me->edit_mesh->totedge; + } + else { + totvert= me->totvert; + totedge= me->totedge; + } + + if( (mesh_topo_store->index_lookup==NULL) || + (mesh_topo_store->prev_ob_mode != ob_mode) || + (totvert != mesh_topo_store->prev_vert_tot) || + (totedge != mesh_topo_store->prev_edge_tot)) + { + return TRUE; + } + else { + return FALSE; + } + +} + +void ED_mesh_mirrtopo_init(Mesh *me, const int ob_mode, MirrTopoStore_t *mesh_topo_store) +{ + MEdge *medge; + EditMesh *em= me->edit_mesh; + void **eve_tmp_back= NULL; /* some of the callers are using eve->tmp so restore after */ + + /* editmode*/ + EditEdge *eed; + + int a, last; + int totvert, totedge; + int totUnique= -1, totUniqueOld= -1; + + MirrTopoHash_t *MirrTopoHash = NULL; + MirrTopoHash_t *MirrTopoHash_Prev = NULL; + MirrTopoPair_t *MirrTopoPairs; + + /* reallocate if needed */ + ED_mesh_mirrtopo_free(mesh_topo_store); + + mesh_topo_store->prev_ob_mode= ob_mode; + + if(em) { + EditVert *eve; + totvert= 0; + eve_tmp_back= MEM_callocN( em->totvert * sizeof(void *), "TopoMirr" ); + for(eve= em->verts.first; eve; eve= eve->next) { + eve_tmp_back[totvert]= eve->tmp.p; + eve->tmp.l = totvert++; + } + } + else { + totvert = me->totvert; + } + + MirrTopoHash = MEM_callocN( totvert * sizeof(MirrTopoHash_t), "TopoMirr" ); + + /* Initialize the vert-edge-user counts used to detect unique topology */ + if(em) { + totedge= 0; + + for(eed=em->edges.first; eed; eed= eed->next, totedge++) { + MirrTopoHash[eed->v1->tmp.l]++; + MirrTopoHash[eed->v2->tmp.l]++; + } + } else { + totedge= me->totedge; + + for(a=0, medge=me->medge; a < me->totedge; a++, medge++) { + MirrTopoHash[medge->v1]++; + MirrTopoHash[medge->v2]++; + } + } + + MirrTopoHash_Prev = MEM_dupallocN( MirrTopoHash ); + + totUniqueOld = -1; + while(1) { + /* use the number of edges per vert to give verts unique topology IDs */ + + if(em) { + for(eed=em->edges.first; eed; eed= eed->next) { + MirrTopoHash[eed->v1->tmp.l] += MirrTopoHash_Prev[eed->v2->tmp.l]; + MirrTopoHash[eed->v2->tmp.l] += MirrTopoHash_Prev[eed->v1->tmp.l]; + } + } else { + for(a=0, medge=me->medge; a<me->totedge; a++, medge++) { + /* This can make really big numbers, wrapping around here is fine */ + MirrTopoHash[medge->v1] += MirrTopoHash_Prev[medge->v2]; + MirrTopoHash[medge->v2] += MirrTopoHash_Prev[medge->v1]; + } + } + memcpy(MirrTopoHash_Prev, MirrTopoHash, sizeof(MirrTopoHash_t) * totvert); + + /* sort so we can count unique values */ + qsort(MirrTopoHash_Prev, totvert, sizeof(MirrTopoHash_t), MirrTopo_long_sort); + + totUnique = 1; /* account for skiping the first value */ + for(a=1; a<totvert; a++) { + if (MirrTopoHash_Prev[a-1] != MirrTopoHash_Prev[a]) { + totUnique++; + } + } + + if (totUnique <= totUniqueOld) { + /* Finish searching for unique valus when 1 loop dosnt give a + * higher number of unique values compared to the previous loop */ + break; + } else { + totUniqueOld = totUnique; + } + /* Copy the hash calculated this iter, so we can use them next time */ + memcpy(MirrTopoHash_Prev, MirrTopoHash, sizeof(MirrTopoHash_t) * totvert); + } + + /* restore eve->tmp.* */ + if(eve_tmp_back) { + EditVert *eve; + totvert= 0; + for(eve= em->verts.first; eve; eve= eve->next) { + eve->tmp.p= eve_tmp_back[totvert++]; + } + + MEM_freeN(eve_tmp_back); + eve_tmp_back= NULL; + } + + + /* Hash/Index pairs are needed for sorting to find index pairs */ + MirrTopoPairs= MEM_callocN( sizeof(MirrTopoPair_t) * totvert, "MirrTopoPairs"); + + /* since we are looping through verts, initialize these values here too */ + mesh_topo_store->index_lookup = MEM_mallocN( totvert * sizeof(long), "mesh_topo_lookup" ); + + if(em) { + EM_init_index_arrays(em,1,0,0); + } + + + for(a=0; a<totvert; a++) { + MirrTopoPairs[a].hash= MirrTopoHash[a]; + MirrTopoPairs[a].v_index = a; + + /* initialize lookup */ + mesh_topo_store->index_lookup[a] = -1; + } + + qsort(MirrTopoPairs, totvert, sizeof(MirrTopoPair_t), MirrTopo_item_sort); + + /* Since the loop starts at 2, we must define the last index where the hash's differ */ + last = ((totvert >= 2) && (MirrTopoPairs[0].hash == MirrTopoPairs[1].hash)) ? 0 : 1; + + /* Get the pairs out of the sorted hashes, note, totvert+1 means we can use the previous 2, + * but you cant ever access the last 'a' index of MirrTopoPairs */ + for(a=2; a <= totvert; a++) { + /* printf("I %d %ld %d\n", (a-last), MirrTopoPairs[a ].hash, MirrTopoPairs[a ].vIndex ); */ + if ((a==totvert) || (MirrTopoPairs[a-1].hash != MirrTopoPairs[a].hash)) { + if (a-last==2) { + if(em) { + mesh_topo_store->index_lookup[MirrTopoPairs[a-1].v_index] = (intptr_t)EM_get_vert_for_index(MirrTopoPairs[a-2].v_index); + mesh_topo_store->index_lookup[MirrTopoPairs[a-2].v_index] = (intptr_t)EM_get_vert_for_index(MirrTopoPairs[a-1].v_index); + } else { + mesh_topo_store->index_lookup[MirrTopoPairs[a-1].v_index] = MirrTopoPairs[a-2].v_index; + mesh_topo_store->index_lookup[MirrTopoPairs[a-2].v_index] = MirrTopoPairs[a-1].v_index; + } + } + last= a; + } + } + if(em) { + EM_free_index_arrays(); + } + + MEM_freeN( MirrTopoPairs ); + MirrTopoPairs = NULL; + + MEM_freeN( MirrTopoHash ); + MEM_freeN( MirrTopoHash_Prev ); + + mesh_topo_store->prev_vert_tot = totvert; + mesh_topo_store->prev_edge_tot = totedge; +} + +void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store) +{ + if (mesh_topo_store->index_lookup) { + MEM_freeN(mesh_topo_store->index_lookup); + } + mesh_topo_store->index_lookup = NULL; + mesh_topo_store->prev_vert_tot = -1; + mesh_topo_store->prev_edge_tot = -1; +} diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index dd82f055f14..77daf21affa 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -765,7 +765,7 @@ intptr_t mesh_octree_table(Object *ob, EditMesh *em, float *co, char mode) if(mode=='u') { /* use table */ if(MeshOctree.table==NULL) mesh_octree_table(ob, em, NULL, 's'); - + if(MeshOctree.table) { Mesh *me= ob->data; bt= MeshOctree.table + mesh_octree_get_base_offs(co, MeshOctree.offs, MeshOctree.div); @@ -848,34 +848,7 @@ intptr_t mesh_octree_table(Object *ob, EditMesh *em, float *co, char mode) return 0; } - -/* ********************* MESH VERTEX MIRR TOPO LOOKUP *************** */ - -typedef int MirrTopoHash_t; - -typedef struct MirrTopoPair_t { - MirrTopoHash_t hash; - int vIndex; -} MirrTopoPair_t; - -static int MirrTopo_long_sort(const void *l1, const void *l2) -{ - if ((MirrTopoHash_t)(intptr_t)l1 > (MirrTopoHash_t)(intptr_t)l2 ) return 1; - else if ((MirrTopoHash_t)(intptr_t)l1 < (MirrTopoHash_t)(intptr_t)l2 ) return -1; - return 0; -} - -static int MirrTopo_item_sort(const void *v1, const void *v2) -{ - if (((MirrTopoPair_t *)v1)->hash > ((MirrTopoPair_t *)v2)->hash ) return 1; - else if (((MirrTopoPair_t *)v1)->hash < ((MirrTopoPair_t *)v2)->hash ) return -1; - return 0; -} - -static intptr_t *mesh_topo_lookup = NULL; -static int mesh_topo_lookup_vert_tot = -1; -static int mesh_topo_lookup_edge_tot = -1; -static int mesh_topo_lookup_mode = -1; +MirrTopoStore_t mesh_topo_store= {NULL, -1. -1, -1}; /* mode is 's' start, or 'e' end, or 'u' use */ /* if end, ob can be NULL */ @@ -883,188 +856,15 @@ static int mesh_topo_lookup_mode = -1; int mesh_mirrtopo_table(Object *ob, char mode) { if(mode=='u') { /* use table */ - Mesh *me= ob->data; - if( (mesh_topo_lookup==NULL) || - (mesh_topo_lookup_mode != ob->mode) || - (me->edit_mesh && (me->edit_mesh->totvert != mesh_topo_lookup_vert_tot)) || - (me->edit_mesh && (me->edit_mesh->totedge != mesh_topo_lookup_edge_tot)) || - (me->edit_mesh==NULL && me->totvert != mesh_topo_lookup_vert_tot) || - (me->edit_mesh==NULL && me->totedge != mesh_topo_lookup_edge_tot) - ) { + if (ED_mesh_mirrtopo_recalc_check(ob->data, ob->mode, &mesh_topo_store)) { mesh_mirrtopo_table(ob, 's'); } - } else if(mode=='s') { /* start table */ - Mesh *me= ob->data; - MEdge *medge; - EditMesh *em= me->edit_mesh; - void **eve_tmp_back= NULL; /* some of the callers are using eve->tmp so restore after */ - - - /* editmode*/ - EditEdge *eed; - - int a, last; - int totvert, totedge; - int totUnique= -1, totUniqueOld= -1; - - MirrTopoHash_t *MirrTopoHash = NULL; - MirrTopoHash_t *MirrTopoHash_Prev = NULL; - MirrTopoPair_t *MirrTopoPairs; - mesh_topo_lookup_mode= ob->mode; - - /* reallocate if needed */ - if (mesh_topo_lookup) { - MEM_freeN(mesh_topo_lookup); - mesh_topo_lookup = NULL; - } - - if(em) { - EditVert *eve; - totvert= 0; - eve_tmp_back= MEM_callocN( em->totvert * sizeof(void *), "TopoMirr" ); - for(eve= em->verts.first; eve; eve= eve->next) { - eve_tmp_back[totvert]= eve->tmp.p; - eve->tmp.l = totvert++; - } - } - else { - totvert = me->totvert; - } - - MirrTopoHash = MEM_callocN( totvert * sizeof(MirrTopoHash_t), "TopoMirr" ); - - /* Initialize the vert-edge-user counts used to detect unique topology */ - if(em) { - totedge= 0; - - for(eed=em->edges.first; eed; eed= eed->next, totedge++) { - MirrTopoHash[eed->v1->tmp.l]++; - MirrTopoHash[eed->v2->tmp.l]++; - } - } else { - totedge= me->totedge; - - for(a=0, medge=me->medge; a < me->totedge; a++, medge++) { - MirrTopoHash[medge->v1]++; - MirrTopoHash[medge->v2]++; - } - } - - MirrTopoHash_Prev = MEM_dupallocN( MirrTopoHash ); - - totUniqueOld = -1; - while(1) { - /* use the number of edges per vert to give verts unique topology IDs */ - - if(em) { - for(eed=em->edges.first; eed; eed= eed->next) { - MirrTopoHash[eed->v1->tmp.l] += MirrTopoHash_Prev[eed->v2->tmp.l]; - MirrTopoHash[eed->v2->tmp.l] += MirrTopoHash_Prev[eed->v1->tmp.l]; - } - } else { - for(a=0, medge=me->medge; a<me->totedge; a++, medge++) { - /* This can make really big numbers, wrapping around here is fine */ - MirrTopoHash[medge->v1] += MirrTopoHash_Prev[medge->v2]; - MirrTopoHash[medge->v2] += MirrTopoHash_Prev[medge->v1]; - } - } - memcpy(MirrTopoHash_Prev, MirrTopoHash, sizeof(MirrTopoHash_t) * totvert); - - /* sort so we can count unique values */ - qsort(MirrTopoHash_Prev, totvert, sizeof(MirrTopoHash_t), MirrTopo_long_sort); - - totUnique = 1; /* account for skiping the first value */ - for(a=1; a<totvert; a++) { - if (MirrTopoHash_Prev[a-1] != MirrTopoHash_Prev[a]) { - totUnique++; - } - } - - if (totUnique <= totUniqueOld) { - /* Finish searching for unique valus when 1 loop dosnt give a - * higher number of unique values compared to the previous loop */ - break; - } else { - totUniqueOld = totUnique; - } - /* Copy the hash calculated this iter, so we can use them next time */ - memcpy(MirrTopoHash_Prev, MirrTopoHash, sizeof(MirrTopoHash_t) * totvert); - } - - /* restore eve->tmp.* */ - if(eve_tmp_back) { - EditVert *eve; - totvert= 0; - for(eve= em->verts.first; eve; eve= eve->next) { - eve->tmp.p= eve_tmp_back[totvert++]; - } - - MEM_freeN(eve_tmp_back); - eve_tmp_back= NULL; - } - - - /* Hash/Index pairs are needed for sorting to find index pairs */ - MirrTopoPairs= MEM_callocN( sizeof(MirrTopoPair_t) * totvert, "MirrTopoPairs"); - - /* since we are looping through verts, initialize these values here too */ - mesh_topo_lookup = MEM_mallocN( totvert * sizeof(long), "mesh_topo_lookup" ); - - if(em) { - EM_init_index_arrays(em,1,0,0); - } - - - for(a=0; a<totvert; a++) { - MirrTopoPairs[a].hash= MirrTopoHash[a]; - MirrTopoPairs[a].vIndex = a; - - /* initialize lookup */ - mesh_topo_lookup[a] = -1; - } - - qsort(MirrTopoPairs, totvert, sizeof(MirrTopoPair_t), MirrTopo_item_sort); - - /* Since the loop starts at 2, we must define the last index where the hash's differ */ - last = ((totvert >= 2) && (MirrTopoPairs[0].hash == MirrTopoPairs[1].hash)) ? 0 : 1; - - /* Get the pairs out of the sorted hashes, note, totvert+1 means we can use the previous 2, - * but you cant ever access the last 'a' index of MirrTopoPairs */ - for(a=2; a < totvert+1; a++) { - /* printf("I %d %ld %d\n", (a-last), MirrTopoPairs[a ].hash, MirrTopoPairs[a ].vIndex ); */ - if ((a==totvert) || (MirrTopoPairs[a-1].hash != MirrTopoPairs[a].hash)) { - if (a-last==2) { - if(em) { - mesh_topo_lookup[MirrTopoPairs[a-1].vIndex] = (intptr_t)EM_get_vert_for_index(MirrTopoPairs[a-2].vIndex); - mesh_topo_lookup[MirrTopoPairs[a-2].vIndex] = (intptr_t)EM_get_vert_for_index(MirrTopoPairs[a-1].vIndex); - } else { - mesh_topo_lookup[MirrTopoPairs[a-1].vIndex] = MirrTopoPairs[a-2].vIndex; - mesh_topo_lookup[MirrTopoPairs[a-2].vIndex] = MirrTopoPairs[a-1].vIndex; - } - } - last= a; - } - } - if(em) { - EM_free_index_arrays(); - } - - MEM_freeN( MirrTopoPairs ); - MirrTopoPairs = NULL; - - MEM_freeN( MirrTopoHash ); - MEM_freeN( MirrTopoHash_Prev ); - - mesh_topo_lookup_vert_tot = totvert; - mesh_topo_lookup_edge_tot = totedge; - - } else if(mode=='e') { /* end table */ - if (mesh_topo_lookup) { - MEM_freeN(mesh_topo_lookup); - } - mesh_topo_lookup = NULL; - mesh_topo_lookup_vert_tot= -1; - mesh_topo_lookup_edge_tot= -1; + } + else if(mode=='s') { /* start table */ + ED_mesh_mirrtopo_init(ob->data, ob->mode, &mesh_topo_store); + } + else if(mode=='e') { /* end table */ + ED_mesh_mirrtopo_free(&mesh_topo_store); } return 0; } @@ -1088,7 +888,7 @@ static int mesh_get_x_mirror_vert_topo(Object *ob, int index) if (mesh_mirrtopo_table(ob, 'u')==-1) return -1; - return mesh_topo_lookup[index]; + return mesh_topo_store.index_lookup[index]; } int mesh_get_x_mirror_vert(Object *ob, int index) @@ -1136,7 +936,7 @@ static EditVert *editmesh_get_x_mirror_vert_topo(Object *ob, struct EditMesh *em } } - poinval= mesh_topo_lookup[ index ]; + poinval= mesh_topo_store.index_lookup[index]; if(poinval != -1) return (EditVert *)(poinval); diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 240fb8017f2..913e5893a77 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -452,7 +452,7 @@ static int modifier_apply_shape(ReportList *reports, Scene *scene, Object *ob, M Key *key=me->key; KeyBlock *kb; - if(!modifier_sameTopology(md)) { + if(!modifier_sameTopology(md) || mti->type == eModifierTypeType_NonGeometrical) { BKE_report(reports, RPT_ERROR, "Only deforming modifiers can be applied to Shapes"); return 0; } @@ -500,7 +500,7 @@ static int modifier_apply_obdata(ReportList *reports, Scene *scene, Object *ob, Mesh *me = ob->data; MultiresModifierData *mmd= find_multires_modifier_before(scene, md); - if( me->key) { + if(me->key && mti->type != eModifierTypeType_NonGeometrical) { BKE_report(reports, RPT_ERROR, "Modifier cannot be applied to Mesh with Shape Keys"); return 0; } diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 007a8f7e4d7..1c34df5393a 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -1293,6 +1293,7 @@ static void area_split_exit(bContext *C, wmOperator *op) op->customdata = NULL; } + WM_cursor_restore(CTX_wm_window(C)); WM_event_add_notifier(C, NC_SCREEN|NA_EDITED, NULL); /* this makes sure aligned edges will result in aligned grabbing */ @@ -1491,6 +1492,37 @@ static int area_split_modal(bContext *C, wmOperator *op, wmEvent *event) } } break; + + case MIDDLEMOUSE: + case TABKEY: + if (sd->previewmode==0){ + } + else{ + dir = RNA_enum_get(op->ptr, "direction"); + + if(event->val==KM_PRESS){ + if (sd->sarea){ + sd->sarea->flag &= ~(AREA_FLAG_DRAWSPLIT_H|AREA_FLAG_DRAWSPLIT_V); + ED_area_tag_redraw(sd->sarea); + + if (dir=='v'){ + RNA_enum_set(op->ptr, "direction", 'h'); + sd->sarea->flag |= AREA_FLAG_DRAWSPLIT_H; + + WM_cursor_set(CTX_wm_window(C),CURSOR_X_MOVE); + } + else{ + RNA_enum_set(op->ptr, "direction", 'v'); + sd->sarea->flag |= AREA_FLAG_DRAWSPLIT_V; + + WM_cursor_set(CTX_wm_window(C),CURSOR_Y_MOVE); + } + } + } + } + + break; + case RIGHTMOUSE: /* cancel operation */ case ESCKEY: return area_split_cancel(C, op); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 2d0ad349be8..eb20465a2ab 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -605,9 +605,13 @@ void ED_keymap_paint(wmKeyConfig *keyconf) ed_keymap_paint_brush_size(keymap, "tool_settings.weight_paint.brush.size"); ed_keymap_paint_brush_radial_control(keymap, "weight_paint", 0); - kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */ + kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* face mask toggle */ RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask"); + /* note, conflicts with vertex paint, but this is more useful */ + kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", VKEY, KM_PRESS, 0, 0); /* vert mask toggle */ + RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask_vertex"); + WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0); diff --git a/source/blender/editors/space_node/node_buttons.c b/source/blender/editors/space_node/node_buttons.c index 15e5719be37..1b5f2417384 100644 --- a/source/blender/editors/space_node/node_buttons.c +++ b/source/blender/editors/space_node/node_buttons.c @@ -115,6 +115,9 @@ static void active_node_panel(const bContext *C, Panel *pa) uiItemS(layout); uiItemR(layout, &ptr, "name", 0, NULL, ICON_NODE); uiItemS(layout); + + uiItemO(layout, NULL, 0, "NODE_OT_hide_socket_toggle"); + uiItemS(layout); /* draw this node's settings */ if (node->typeinfo && node->typeinfo->uifuncbut) diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 08e073494bb..7b692f55965 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -351,10 +351,10 @@ static void node_update_hidden(bNode *node) /* calculate minimal radius */ for(nsock= node->inputs.first; nsock; nsock= nsock->next) - if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) + if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (nsock->flag & SOCK_IN_USE)) totin++; for(nsock= node->outputs.first; nsock; nsock= nsock->next) - if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) + if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (nsock->flag & SOCK_IN_USE)) totout++; tot= MAX2(totin, totout); @@ -371,7 +371,7 @@ static void node_update_hidden(bNode *node) rad=drad= (float)M_PI/(1.0f + (float)totout); for(nsock= node->outputs.first; nsock; nsock= nsock->next) { - if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) { + if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (nsock->flag & SOCK_IN_USE)) { nsock->locx= node->totr.xmax - hiddenrad + (float)sin(rad)*hiddenrad; nsock->locy= node->totr.ymin + hiddenrad + (float)cos(rad)*hiddenrad; rad+= drad; @@ -382,7 +382,7 @@ static void node_update_hidden(bNode *node) rad=drad= - (float)M_PI/(1.0f + (float)totin); for(nsock= node->inputs.first; nsock; nsock= nsock->next) { - if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) { + if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (nsock->flag & SOCK_IN_USE)) { nsock->locx= node->totr.xmin + hiddenrad + (float)sin(rad)*hiddenrad; nsock->locy= node->totr.ymin + hiddenrad + (float)cos(rad)*hiddenrad; rad+= drad; @@ -854,12 +854,12 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b /* sockets */ for(sock= node->inputs.first; sock; sock= sock->next) { - if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) + if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (sock->flag & SOCK_IN_USE)) node_socket_circle_draw(snode->nodetree, sock, socket_size); } for(sock= node->outputs.first; sock; sock= sock->next) { - if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) + if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (sock->flag & SOCK_IN_USE)) node_socket_circle_draw(snode->nodetree, sock, socket_size); } diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 16ee32d10a2..566659e0391 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -195,7 +195,6 @@ void TEXT_OT_new(wmOperatorType *ot) ot->description= "Create a new text data block"; /* api callbacks */ - ot->invoke= WM_operator_confirm; ot->exec= text_new_exec; ot->poll= text_new_poll; diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index 6dd362b827f..e0b1741b0d0 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -70,6 +70,25 @@ #include "view3d_intern.h" // own include +/* user data structures for derived mesh callbacks */ +typedef struct drawMeshFaceSelect_userData { + Mesh *me; + EdgeHash *eh; +} drawMeshFaceSelect_userData; + +typedef struct drawEMTFMapped_userData { + EditMesh *em; + short has_mcol; + short has_mtface; + MFace *mf; + MTFace *tf; +} drawEMTFMapped_userData; + +typedef struct drawTFace_userData { + MFace *mf; + MTFace *tf; +} drawTFace_userData; + /**************************** Face Select Mode *******************************/ /* Flags for marked edges */ @@ -121,7 +140,7 @@ static EdgeHash *get_tface_mesh_marked_edge_info(Mesh *me) static int draw_mesh_face_select__setHiddenOpts(void *userData, int index) { - struct { Mesh *me; EdgeHash *eh; } *data = userData; + drawMeshFaceSelect_userData *data = userData; Mesh *me= data->me; MEdge *med = &me->medge[index]; uintptr_t flags = (intptr_t) BLI_edgehash_lookup(data->eh, med->v1, med->v2); @@ -138,7 +157,7 @@ static int draw_mesh_face_select__setHiddenOpts(void *userData, int index) static int draw_mesh_face_select__setSelectOpts(void *userData, int index) { - struct { Mesh *me; EdgeHash *eh; } *data = userData; + drawMeshFaceSelect_userData *data = userData; MEdge *med = &data->me->medge[index]; uintptr_t flags = (intptr_t) BLI_edgehash_lookup(data->eh, med->v1, med->v2); @@ -159,7 +178,7 @@ static int draw_mesh_face_select__drawFaceOptsInv(void *userData, int index) static void draw_mesh_face_select(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm) { - struct { Mesh *me; EdgeHash *eh; } data; + drawMeshFaceSelect_userData data; data.me = me; data.eh = get_tface_mesh_marked_edge_info(me); @@ -513,7 +532,7 @@ static int draw_tface_mapped__set_draw(void *userData, int index) static int draw_em_tf_mapped__set_draw(void *userData, int index) { - struct {EditMesh *em; short has_mcol; short has_mtface; MFace *mf; MTFace *tf;} *data = userData; + drawEMTFMapped_userData *data = userData; EditMesh *em = data->em; EditFace *efa= EM_get_face_for_index(index); MTFace *tface; @@ -631,7 +650,7 @@ static void draw_mesh_text(Scene *scene, Object *ob, int glsl) static int compareDrawOptions(void *userData, int cur_index, int next_index) { - struct { MFace *mf; MTFace *tf; } *data = userData; + drawTFace_userData *data = userData; if(data->mf && data->mf[cur_index].mat_nr != data->mf[next_index].mat_nr) return 0; @@ -644,7 +663,7 @@ static int compareDrawOptions(void *userData, int cur_index, int next_index) static int compareDrawOptionsEm(void *userData, int cur_index, int next_index) { - struct {EditMesh *em; short has_mcol; short has_mtface; MFace *mf; MTFace *tf;} *data= userData; + drawEMTFMapped_userData *data= userData; if(data->mf && data->mf[cur_index].mat_nr != data->mf[next_index].mat_nr) return 0; @@ -669,7 +688,7 @@ void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec glColor4f(1.0f,1.0f,1.0f,1.0f); if(ob->mode & OB_MODE_EDIT) { - struct {EditMesh *em; short has_mcol; short has_mtface; MFace *mf; MTFace *tf;} data; + drawEMTFMapped_userData data; data.em= me->edit_mesh; data.has_mcol= CustomData_has_layer(&me->edit_mesh->fdata, CD_MCOL); @@ -693,7 +712,7 @@ void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec dm->drawFacesTex(dm, draw_tface__set_draw_legacy, NULL, NULL); } else { - struct { MFace *mf; MTFace *tf; } userData; + drawTFace_userData userData; if(!CustomData_has_layer(&dm->faceData,CD_TEXTURE_MCOL)) add_tface_color_layer(dm); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index e3e551d67ee..7827569bd30 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -118,6 +118,48 @@ typedef enum eWireDrawMode { OBDRAW_WIRE_ON_DEPTH= 2 } eWireDrawMode; +/* user data structures for derived mesh callbacks */ +typedef struct foreachScreenVert_userData { + void (*func)(void *userData, EditVert *eve, int x, int y, int index); + void *userData; + ViewContext vc; + eV3DClipTest clipVerts; +} foreachScreenVert_userData; + +typedef struct foreachScreenEdge_userData { + void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); + void *userData; + ViewContext vc; + eV3DClipTest clipVerts; +} foreachScreenEdge_userData; + +typedef struct foreachScreenFace_userData { + void (*func)(void *userData, EditFace *efa, int x, int y, int index); + void *userData; + ViewContext vc; +} foreachScreenFace_userData; + +typedef struct drawDMVerts_userData { + int sel; + EditVert *eve_act; +} drawDMVerts_userData; + +typedef struct drawDMEdgesSel_userData { + unsigned char *baseCol, *selCol, *actCol; + EditEdge *eed_act; +} drawDMEdgesSel_userData; + +typedef struct drawDMFacesSel_userData { + unsigned char *cols[3]; + EditFace *efa_act; + int *orig_index; +} drawDMFacesSel_userData; + +typedef struct bbsObmodeMeshVerts_userData { + void *offset; + MVert *mvert; +} bbsObmodeMeshVerts_userData; + static void draw_bounding_volume(Scene *scene, Object *ob, char type); static void drawcube_size(float size); @@ -1944,9 +1986,7 @@ static void drawlattice(Scene *scene, View3D *v3d, Object *ob) * use the object matrix in the useual way */ static void mesh_foreachScreenVert__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { - struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); - void *userData; ViewContext vc; eV3DClipTest clipVerts; } *data = userData; - + foreachScreenVert_userData *data = userData; EditVert *eve = EM_get_vert_for_index(index); if (eve->h==0) { @@ -1968,9 +2008,7 @@ void mesh_foreachScreenVert( void (*func)(void *userData, EditVert *eve, int x, int y, int index), void *userData, eV3DClipTest clipVerts) { - struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); - void *userData; ViewContext vc; eV3DClipTest clipVerts; } data; - + foreachScreenVert_userData data; DerivedMesh *dm = editmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH); data.vc= *vc; @@ -2024,8 +2062,7 @@ static int is_co_in_region(ARegion *ar, const short co[2]) } static void mesh_foreachScreenEdge__mapFunc(void *userData, int index, float *v0co, float *v1co) { - struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); - void *userData; ViewContext vc; eV3DClipTest clipVerts; } *data = userData; + foreachScreenEdge_userData *data = userData; EditEdge *eed = EM_get_edge_for_index(index); short s[2][2]; @@ -2056,8 +2093,7 @@ void mesh_foreachScreenEdge( void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, eV3DClipTest clipVerts) { - struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); - void *userData; ViewContext vc; eV3DClipTest clipVerts; } data; + foreachScreenEdge_userData data; DerivedMesh *dm = editmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH); data.vc= *vc; @@ -2077,7 +2113,7 @@ void mesh_foreachScreenEdge( static void mesh_foreachScreenFace__mapFunc(void *userData, int index, float *cent, float *UNUSED(no)) { - struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; ViewContext vc; } *data = userData; + foreachScreenFace_userData *data = userData; EditFace *efa = EM_get_face_for_index(index); short s[2]; @@ -2095,7 +2131,7 @@ void mesh_foreachScreenFace( void (*func)(void *userData, EditFace *efa, int x, int y, int index), void *userData) { - struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; ViewContext vc; } data; + foreachScreenFace_userData data; DerivedMesh *dm = editmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH); data.vc= *vc; @@ -2240,7 +2276,7 @@ static void draw_dm_vert_normals(Scene *scene, DerivedMesh *dm) /* Draw verts with color set based on selection */ static void draw_dm_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { - struct { int sel; EditVert *eve_act; } * data = userData; + drawDMVerts_userData * data = userData; EditVert *eve = EM_get_vert_for_index(index); if (eve->h==0 && (eve->f&SELECT)==data->sel) { @@ -2267,7 +2303,7 @@ static void draw_dm_verts__mapFunc(void *userData, int index, float *co, float * static void draw_dm_verts(DerivedMesh *dm, int sel, EditVert *eve_act) { - struct { int sel; EditVert *eve_act; } data; + drawDMVerts_userData data; data.sel = sel; data.eve_act = eve_act; @@ -2281,7 +2317,7 @@ static int draw_dm_edges_sel__setDrawOptions(void *userData, int index) { EditEdge *eed = EM_get_edge_for_index(index); //unsigned char **cols = userData, *col; - struct { unsigned char *baseCol, *selCol, *actCol; EditEdge *eed_act; } * data = userData; + drawDMEdgesSel_userData * data = userData; unsigned char *col; if (eed->h==0) { @@ -2305,7 +2341,7 @@ static int draw_dm_edges_sel__setDrawOptions(void *userData, int index) } static void draw_dm_edges_sel(DerivedMesh *dm, unsigned char *baseCol, unsigned char *selCol, unsigned char *actCol, EditEdge *eed_act) { - struct { unsigned char *baseCol, *selCol, *actCol; EditEdge *eed_act; } data; + drawDMEdgesSel_userData data; data.baseCol = baseCol; data.selCol = selCol; @@ -2379,7 +2415,7 @@ static void draw_dm_edges_sharp(DerivedMesh *dm) * return 2 for the active face so it renders with stipple enabled */ static int draw_dm_faces_sel__setDrawOptions(void *userData, int index, int *UNUSED(drawSmooth_r)) { - struct { unsigned char *cols[3]; EditFace *efa_act; int *orig_index; } * data = userData; + drawDMFacesSel_userData * data = userData; EditFace *efa = EM_get_face_for_index(index); unsigned char *col; @@ -2399,7 +2435,7 @@ static int draw_dm_faces_sel__setDrawOptions(void *userData, int index, int *UNU static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int next_index) { - struct { unsigned char *cols[3]; EditFace *efa_act; int *orig_index; } *data = userData; + drawDMFacesSel_userData *data = userData; EditFace *efa; EditFace *next_efa; unsigned char *col, *next_col; @@ -2428,7 +2464,7 @@ static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int /* also draws the active face */ static void draw_dm_faces_sel(DerivedMesh *dm, unsigned char *baseCol, unsigned char *selCol, unsigned char *actCol, EditFace *efa_act) { - struct { unsigned char *cols[3]; EditFace *efa_act; int *orig_index; } data; + drawDMFacesSel_userData data; data.cols[0] = baseCol; data.cols[1] = selCol; data.cols[2] = actCol; @@ -6879,7 +6915,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) { - struct {void* offset; MVert *mvert;} *data = userData; + bbsObmodeMeshVerts_userData *data = userData; MVert *mv = &data->mvert[index]; int offset = (intptr_t) data->offset; @@ -6891,7 +6927,7 @@ static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, float *co, static void bbs_obmode_mesh_verts(Object *ob, DerivedMesh *dm, int offset) { - struct {void* offset; struct MVert *mvert;} data; + bbsObmodeMeshVerts_userData data; Mesh *me = ob->data; MVert *mvert = me->mvert; data.mvert = mvert; diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 1b849754db8..345e78d70c9 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -576,7 +576,7 @@ typedef struct GameData { short mode, matmode; short occlusionRes; /* resolution of occlusion Z buffer in pixel */ short physicsEngine; - short pad[2]; + short exitkey, pad; short ticrate, maxlogicstep, physubstep, maxphystep; short obstacleSimulation, pad1; float levelHeight; diff --git a/source/blender/makesdna/DNA_world_types.h b/source/blender/makesdna/DNA_world_types.h index 1e8a4574120..149393b6723 100644 --- a/source/blender/makesdna/DNA_world_types.h +++ b/source/blender/makesdna/DNA_world_types.h @@ -181,6 +181,7 @@ typedef struct World { #define TEXCO_ANGMAP 64 #define TEXCO_H_SPHEREMAP 256 #define TEXCO_H_TUBEMAP 1024 +#define TEXCO_EQUIRECTMAP 2048 /* mapto */ #define WOMAP_BLEND 1 diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index a682c329444..9638bba3e80 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -1213,6 +1213,13 @@ static void rna_GameSettings_auto_start_set(PointerRNA *UNUSED(ptr), int value) G.fileflags &= ~G_FILE_AUTOPLAY; } +static void rna_GameSettings_exit_key_set(PointerRNA *ptr, int value) +{ + GameData *gm = (GameData*)ptr->data; + + if(ISKEYBOARD(value)) + gm->exitkey=value; +} static TimeMarker *rna_TimeLine_add(Scene *scene, const char name[]) { @@ -2103,6 +2110,13 @@ static void rna_def_scene_game_data(BlenderRNA *brna) RNA_def_property_range(prop, 8, 32); RNA_def_property_ui_text(prop, "Bits", "Display bit depth of full screen display"); RNA_def_property_update(prop, NC_SCENE, NULL); + + prop= RNA_def_property(srna, "exit_key", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "exitkey"); + RNA_def_property_enum_items(prop, event_type_items); + RNA_def_property_enum_funcs(prop, NULL, "rna_GameSettings_exit_key_set", NULL); + RNA_def_property_ui_text(prop, "Exit Key", "Sets the key that exits the Game Engine"); + RNA_def_property_update(prop, NC_SCENE, NULL); // Do we need it here ? (since we already have it in World prop= RNA_def_property(srna, "frequency", PROP_INT, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_world.c b/source/blender/makesrna/intern/rna_world.c index 840498249ea..087716adbe3 100644 --- a/source/blender/makesrna/intern/rna_world.c +++ b/source/blender/makesrna/intern/rna_world.c @@ -143,6 +143,7 @@ static void rna_def_world_mtex(BlenderRNA *brna) {TEXCO_GLOB, "GLOBAL", 0, "Global", "Use global coordinates for the texture coordinates (interior mist)"}, {TEXCO_ANGMAP, "ANGMAP", 0, "AngMap", "Use 360 degree angular coordinates, e.g. for spherical light probes"}, {TEXCO_H_SPHEREMAP, "SPHERE", 0, "Sphere", "For 360 degree panorama sky, spherical mapped, only top half"}, + {TEXCO_EQUIRECTMAP, "EQUIRECT", 0, "Equirectangular", "For 360 degree panorama sky, equirectangular mapping"}, {TEXCO_H_TUBEMAP, "TUBE", 0, "Tube", "For 360 degree panorama sky, cylindrical mapped, only top half"}, {TEXCO_OBJECT, "OBJECT", 0, "Object", "Use linked object's coordinates for texture coordinates"}, {0, NULL, 0, NULL, NULL}}; diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index 3146d1c9d5d..38c2073b6a5 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.c +++ b/source/blender/modifiers/intern/MOD_uvproject.c @@ -290,7 +290,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, project_from_camera(tface->uv[0], coords[mf->v1], projectors[0].uci); project_from_camera(tface->uv[1], coords[mf->v2], projectors[0].uci); project_from_camera(tface->uv[2], coords[mf->v3], projectors[0].uci); - if(mf->v3) + if(mf->v4) project_from_camera(tface->uv[3], coords[mf->v4], projectors[0].uci); } else { @@ -343,7 +343,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, project_from_camera(tface->uv[0], coords[mf->v1], best_projector->uci); project_from_camera(tface->uv[1], coords[mf->v2], best_projector->uci); project_from_camera(tface->uv[2], coords[mf->v3], best_projector->uci); - if(mf->v3) + if(mf->v4) project_from_camera(tface->uv[3], coords[mf->v4], best_projector->uci); } else { @@ -407,7 +407,7 @@ ModifierTypeInfo modifierType_UVProject = { /* name */ "UVProject", /* structName */ "UVProjectModifierData", /* structSize */ sizeof(UVProjectModifierData), - /* type */ eModifierTypeType_Nonconstructive, + /* type */ eModifierTypeType_NonGeometrical, /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsMapping | eModifierTypeFlag_SupportsEditmode diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c index 24d80fe847c..bdd7ab7486b 100644 --- a/source/blender/modifiers/intern/MOD_weightvgedit.c +++ b/source/blender/modifiers/intern/MOD_weightvgedit.c @@ -177,10 +177,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der int UNUSED(useRenderParams), int UNUSED(isFinalCalc)) { WeightVGEditModifierData *wmd = (WeightVGEditModifierData*) md; - DerivedMesh *dm = derivedData, *ret = NULL; -#if 0 - Mesh *ob_m = NULL; -#endif + DerivedMesh *dm = derivedData; MDeformVert *dvert = NULL; MDeformWeight **dw = NULL; float *org_w; /* Array original weights. */ @@ -188,7 +185,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der int numVerts; int defgrp_idx; int i; - char rel_ret = 0; /* Boolean, whether we have to release ret dm or not, when not using it! */ /* Flags. */ int do_add = (wmd->edit_flags & MOD_WVG_EDIT_ADD2VG) != 0; int do_rem = (wmd->edit_flags & MOD_WVG_EDIT_REMFVG) != 0; @@ -207,49 +203,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der if (defgrp_idx < 0) return dm; - /* XXX All this to avoid copying dm when not needed... However, it nearly doubles compute - * time! See scene 5 of the WeighVG test file... - */ -#if 0 - /* Get actual dverts (ie vertex group data). */ - dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); - /* If no dverts, return unmodified data... */ - if (dvert == NULL) - return dm; - - /* Get org mesh, only to test whether affected cdata layer has already been copied - * somewhere up in the modifiers stack. - */ - ob_m = get_mesh(ob); - if (ob_m == NULL) - return dm; - - /* Create a copy of our dmesh, only if our affected cdata layer is the same as org mesh. */ - if (dvert == CustomData_get_layer(&ob_m->vdata, CD_MDEFORMVERT)) { - /* XXX Seems to create problems with weightpaint mode??? - * I'm missing something here, I guess... - */ -// DM_set_only_copy(dm, CD_MASK_MDEFORMVERT); /* Only copy defgroup layer. */ - ret = CDDM_copy(dm); - dvert = ret->getVertDataArray(ret, CD_MDEFORMVERT); - if (dvert == NULL) { - ret->release(ret); - return dm; - } - rel_ret = 1; - } - else - ret = dm; -#else - ret = CDDM_copy(dm); - rel_ret = 1; - dvert = ret->getVertDataArray(ret, CD_MDEFORMVERT); - if (dvert == NULL) { - if (rel_ret) - ret->release(ret); - return dm; - } -#endif + dvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MDEFORMVERT, numVerts); /* Get org weights, assuming 0.0 for vertices not in given vgroup. */ org_w = MEM_mallocN(sizeof(float) * numVerts, "WeightVGEdit Modifier, org_w"); @@ -271,7 +225,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der } /* Do masking. */ - weightvg_do_mask(numVerts, NULL, org_w, new_w, ob, ret, wmd->mask_constant, + weightvg_do_mask(numVerts, NULL, org_w, new_w, ob, dm, wmd->mask_constant, wmd->mask_defgrp_name, wmd->mask_texture, wmd->mask_tex_use_channel, wmd->mask_tex_mapping, wmd->mask_tex_map_obj, wmd->mask_tex_uvlayer_name); @@ -285,7 +239,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der MEM_freeN(dw); /* Return the vgroup-modified mesh. */ - return ret; + return dm; } static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob, @@ -300,7 +254,7 @@ ModifierTypeInfo modifierType_WeightVGEdit = { /* name */ "VertexWeightEdit", /* structName */ "WeightVGEditModifierData", /* structSize */ sizeof(WeightVGEditModifierData), - /* type */ eModifierTypeType_Nonconstructive, + /* type */ eModifierTypeType_NonGeometrical, /* flags */ eModifierTypeFlag_AcceptsMesh /* |eModifierTypeFlag_SupportsMapping*/ |eModifierTypeFlag_SupportsEditmode, diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c index 221deeef1a6..17316d891da 100644 --- a/source/blender/modifiers/intern/MOD_weightvgmix.c +++ b/source/blender/modifiers/intern/MOD_weightvgmix.c @@ -219,10 +219,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der int UNUSED(useRenderParams), int UNUSED(isFinalCalc)) { WeightVGMixModifierData *wmd = (WeightVGMixModifierData*) md; - DerivedMesh *dm = derivedData, *ret = NULL; -#if 0 - Mesh *ob_m = NULL; -#endif + DerivedMesh *dm = derivedData; MDeformVert *dvert = NULL; MDeformWeight **dw1, **tdw1, **dw2, **tdw2; int numVerts; @@ -232,7 +229,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der int *tidx, *indices = NULL; int numIdx = 0; int i; - char rel_ret = 0; /* Boolean, whether we have to release ret dm or not, when not using it! */ /* Get number of verts. */ numVerts = dm->getNumVerts(dm); @@ -254,49 +250,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der return dm; } - /* XXX All this to avoid copying dm when not needed... However, it nearly doubles compute - * time! See scene 5 of the WeighVG test file... - */ -#if 0 - /* Get actual dverts (ie vertex group data). */ - dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); - /* If no dverts, return unmodified data... */ - if (dvert == NULL) - return dm; - - /* Get org mesh, only to test whether affected cdata layer has already been copied - * somewhere up in the modifiers stack. - */ - ob_m = get_mesh(ob); - if (ob_m == NULL) - return dm; - - /* Create a copy of our dmesh, only if our affected cdata layer is the same as org mesh. */ - if (dvert == CustomData_get_layer(&ob_m->vdata, CD_MDEFORMVERT)) { - /* XXX Seems to create problems with weightpaint mode??? - * I'm missing something here, I guess... - */ -// DM_set_only_copy(dm, CD_MASK_MDEFORMVERT); /* Only copy defgroup layer. */ - ret = CDDM_copy(dm); - dvert = ret->getVertDataArray(ret, CD_MDEFORMVERT); - if (dvert == NULL) { - ret->release(ret); - return dm; - } - rel_ret = 1; - } - else - ret = dm; -#else - ret = CDDM_copy(dm); - rel_ret = 1; - dvert = ret->getVertDataArray(ret, CD_MDEFORMVERT); - if (dvert == NULL) { - if (rel_ret) - ret->release(ret); - return dm; - } -#endif + dvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MDEFORMVERT, numVerts); /* Find out which vertices to work on. */ tidx = MEM_mallocN(sizeof(int) * numVerts, "WeightVGMix Modifier, tidx"); @@ -364,8 +318,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der MEM_freeN(tdw1); MEM_freeN(tdw2); MEM_freeN(tidx); - if (rel_ret) - ret->release(ret); return dm; } if (numIdx != -1) { @@ -400,7 +352,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der } /* Do masking. */ - weightvg_do_mask(numIdx, indices, org_w, new_w, ob, ret, wmd->mask_constant, + weightvg_do_mask(numIdx, indices, org_w, new_w, ob, dm, wmd->mask_constant, wmd->mask_defgrp_name, wmd->mask_texture, wmd->mask_tex_use_channel, wmd->mask_tex_mapping, wmd->mask_tex_map_obj, wmd->mask_tex_uvlayer_name); @@ -419,7 +371,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der MEM_freeN(indices); /* Return the vgroup-modified mesh. */ - return ret; + return dm; } static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob, @@ -434,7 +386,7 @@ ModifierTypeInfo modifierType_WeightVGMix = { /* name */ "VertexWeightMix", /* structName */ "WeightVGMixModifierData", /* structSize */ sizeof(WeightVGMixModifierData), - /* type */ eModifierTypeType_Nonconstructive, + /* type */ eModifierTypeType_NonGeometrical, /* flags */ eModifierTypeFlag_AcceptsMesh /* |eModifierTypeFlag_SupportsMapping*/ |eModifierTypeFlag_SupportsEditmode, diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index af180b8a688..f67fd907d02 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -28,11 +28,17 @@ * \ingroup modifiers */ +#define DO_PROFILE 0 + #include "BLI_editVert.h" #include "BLI_math.h" #include "BLI_string.h" #include "BLI_utildefines.h" +#if DO_PROFILE + #include "PIL_time.h" +#endif + #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" @@ -334,10 +340,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der int UNUSED(useRenderParams), int UNUSED(isFinalCalc)) { WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData*) md; - DerivedMesh *dm = derivedData, *ret = NULL; -#if 0 - Mesh *ob_m = NULL; -#endif + DerivedMesh *dm = derivedData; MDeformVert *dvert = NULL; MDeformWeight **dw, **tdw; int numVerts; @@ -350,7 +353,10 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der int *tidx, *indices = NULL; int numIdx = 0; int i; - char rel_ret = 0; /* Boolean, whether we have to release ret dm or not, when not using it! */ + +#if DO_PROFILE + TIMEIT_START(perf) +#endif /* Get number of verts. */ numVerts = dm->getNumVerts(dm); @@ -371,49 +377,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der if (defgrp_idx < 0) return dm; - /* XXX All this to avoid copying dm when not needed... However, it nearly doubles compute - * time! See scene 5 of the WeighVG test file... - */ -#if 0 - /* Get actual dverts (ie vertex group data). */ - dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); - /* If no dverts, return unmodified data... */ - if (dvert == NULL) - return dm; - - /* Get org mesh, only to test whether affected cdata layer has already been copied - * somewhere up in the modifiers stack. - */ - ob_m = get_mesh(ob); - if (ob_m == NULL) - return dm; - - /* Create a copy of our dmesh, only if our affected cdata layer is the same as org mesh. */ - if (dvert == CustomData_get_layer(&ob_m->vdata, CD_MDEFORMVERT)) { - /* XXX Seems to create problems with weightpaint mode??? - * I'm missing something here, I guess... - */ -// DM_set_only_copy(dm, CD_MASK_MDEFORMVERT); /* Only copy defgroup layer. */ - ret = CDDM_copy(dm); - dvert = ret->getVertDataArray(ret, CD_MDEFORMVERT); - if (dvert == NULL) { - ret->release(ret); - return dm; - } - rel_ret = 1; - } - else - ret = dm; -#else - ret = CDDM_copy(dm); - rel_ret = 1; - dvert = ret->getVertDataArray(ret, CD_MDEFORMVERT); - if (dvert == NULL) { - if (rel_ret) - ret->release(ret); - return dm; - } -#endif + dvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MDEFORMVERT, numVerts); /* Find out which vertices to work on (all vertices in vgroup), and get their relevant weight. */ @@ -433,8 +397,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der MEM_freeN(tidx); MEM_freeN(tw); MEM_freeN(tdw); - if (rel_ret) - ret->release(ret); return dm; } indices = MEM_mallocN(sizeof(int) * numIdx, "WeightVGProximity Modifier, indices"); @@ -455,7 +417,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der */ float (*tv_cos)[3] = MEM_mallocN(sizeof(float[3]) * numVerts, "WeightVGProximity Modifier, tv_cos"); v_cos = MEM_mallocN(sizeof(float[3]) * numIdx, "WeightVGProximity Modifier, v_cos"); - ret->getVertCos(ret, tv_cos); + dm->getVertCos(dm, tv_cos); for (i = 0; i < numIdx; i++) copy_v3_v3(v_cos[i], tv_cos[indices[i]]); MEM_freeN(tv_cos); @@ -524,7 +486,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der do_map(new_w, numIdx, wmd->min_dist, wmd->max_dist, wmd->falloff_type); /* Do masking. */ - weightvg_do_mask(numIdx, indices, org_w, new_w, ob, ret, wmd->mask_constant, + weightvg_do_mask(numIdx, indices, org_w, new_w, ob, dm, wmd->mask_constant, wmd->mask_defgrp_name, wmd->mask_texture, wmd->mask_tex_use_channel, wmd->mask_tex_mapping, wmd->mask_tex_map_obj, wmd->mask_tex_uvlayer_name); @@ -538,8 +500,12 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der MEM_freeN(indices); MEM_freeN(v_cos); +#if DO_PROFILE + TIMEIT_END(perf) +#endif + /* Return the vgroup-modified mesh. */ - return ret; + return dm; } static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob, @@ -554,7 +520,7 @@ ModifierTypeInfo modifierType_WeightVGProximity = { /* name */ "VertexWeightProximity", /* structName */ "WeightVGProximityModifierData", /* structSize */ sizeof(WeightVGProximityModifierData), - /* type */ eModifierTypeType_Nonconstructive, + /* type */ eModifierTypeType_NonGeometrical, /* flags */ eModifierTypeFlag_AcceptsMesh /* |eModifierTypeFlag_SupportsMapping*/ |eModifierTypeFlag_SupportsEditmode, diff --git a/source/blender/nodes/shader/node_shader_util.c b/source/blender/nodes/shader/node_shader_util.c index 87585c35e6a..8b8afc3d846 100644 --- a/source/blender/nodes/shader/node_shader_util.c +++ b/source/blender/nodes/shader/node_shader_util.c @@ -134,8 +134,6 @@ void ntreeShaderGetTexcoMode(bNodeTree *ntree, int r_mode, short *texco, int *mo bNodeSocket *sock; int a; - ntreeSocketUseFlags(ntree); - for(node= ntree->nodes.first; node; node= node->next) { if(node->type==SH_NODE_TEXTURE) { if((r_mode & R_OSA) && node->id) { diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 69a5fb39b67..ded0f2f768c 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -642,7 +642,7 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop) if (len==16) { if (is_thick) { ret= Matrix_CreatePyObject(NULL, 4, 4, Py_NEW, NULL); - RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->contigPtr); + RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->matrix); } else { PyObject *mat_cb= Matrix_CreatePyObject_cb(ret, 4,4, mathutils_rna_matrix_cb_index, FALSE); @@ -653,7 +653,7 @@ PyObject *pyrna_math_object_from_array(PointerRNA *ptr, PropertyRNA *prop) else if (len==9) { if (is_thick) { ret= Matrix_CreatePyObject(NULL, 3, 3, Py_NEW, NULL); - RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->contigPtr); + RNA_property_float_get_array(ptr, prop, ((MatrixObject *)ret)->matrix); } else { PyObject *mat_cb= Matrix_CreatePyObject_cb(ret, 3,3, mathutils_rna_matrix_cb_index, FALSE); diff --git a/source/blender/python/mathutils/mathutils.c b/source/blender/python/mathutils/mathutils.c index 5587028d812..1dfd7c574dd 100644 --- a/source/blender/python/mathutils/mathutils.c +++ b/source/blender/python/mathutils/mathutils.c @@ -35,6 +35,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_dynstr.h" PyDoc_STRVAR(M_Mathutils_doc, "This module provides access to matrices, eulers, quaternions and vectors." @@ -211,7 +212,7 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) { return -1; } - else if (((MatrixObject *)value)->col_size < 3 || ((MatrixObject *)value)->row_size < 3) { + else if (((MatrixObject *)value)->num_row < 3 || ((MatrixObject *)value)->num_col < 3) { PyErr_Format(PyExc_ValueError, "%.200s: matrix must have minimum 3x3 dimensions", error_prefix); @@ -267,6 +268,18 @@ int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps) return 1; } +/* dynstr as python string utility funcions, frees 'ds'! */ +PyObject *mathutils_dynstr_to_py(struct DynStr *ds) +{ + const int ds_len = BLI_dynstr_get_len(ds); /* space for \0 */ + char *ds_buf = PyMem_Malloc(ds_len + 1); + PyObject *ret; + BLI_dynstr_get_cstring_ex(ds, ds_buf); + BLI_dynstr_free(ds); + ret = PyUnicode_FromStringAndSize(ds_buf, ds_len); + PyMem_Free(ds_buf); + return ret; +} /* Mathutils Callbacks */ diff --git a/source/blender/python/mathutils/mathutils.h b/source/blender/python/mathutils/mathutils.h index cd3548b9b82..2454e953949 100644 --- a/source/blender/python/mathutils/mathutils.h +++ b/source/blender/python/mathutils/mathutils.h @@ -37,6 +37,8 @@ /* Can cast different mathutils types to this, use for generic funcs */ +struct DynStr; + extern char BaseMathObject_Wrapped_doc[]; extern char BaseMathObject_Owner_doc[]; @@ -120,4 +122,7 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error int column_vector_multiplication(float rvec[4], VectorObject *vec, MatrixObject *mat); +/* dynstr as python string utility funcions */ +PyObject *mathutils_dynstr_to_py(struct DynStr *ds); + #endif /* MATHUTILS_H */ diff --git a/source/blender/python/mathutils/mathutils_Color.c b/source/blender/python/mathutils/mathutils_Color.c index e46dda7560f..e0a0deb9a0e 100644 --- a/source/blender/python/mathutils/mathutils_Color.c +++ b/source/blender/python/mathutils/mathutils_Color.c @@ -32,6 +32,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_dynstr.h" #define COLOR_SIZE 3 @@ -125,6 +126,21 @@ static PyObject *Color_repr(ColorObject * self) return ret; } +static PyObject *Color_str(ColorObject * self) +{ + DynStr *ds; + + if (BaseMath_ReadCallback(self) == -1) + return NULL; + + ds= BLI_dynstr_new(); + + BLI_dynstr_appendf(ds, "<Color (r=%.4f, g=%.4f, b=%.4f)>", + self->col[0], self->col[1], self->col[2]); + + return mathutils_dynstr_to_py(ds); /* frees ds */ +} + //------------------------tp_richcmpr //returns -1 execption, 0 false, 1 true static PyObject* Color_richcmpr(PyObject *a, PyObject *b, int op) @@ -789,7 +805,7 @@ PyTypeObject color_Type = { &Color_AsMapping, //tp_as_mapping NULL, //tp_hash NULL, //tp_call - NULL, //tp_str + (reprfunc) Color_str, //tp_str NULL, //tp_getattro NULL, //tp_setattro NULL, //tp_as_buffer diff --git a/source/blender/python/mathutils/mathutils_Euler.c b/source/blender/python/mathutils/mathutils_Euler.c index f44c0b82a2d..443e77c3798 100644 --- a/source/blender/python/mathutils/mathutils_Euler.c +++ b/source/blender/python/mathutils/mathutils_Euler.c @@ -36,6 +36,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_dynstr.h" #define EULER_SIZE 3 @@ -317,6 +318,21 @@ static PyObject *Euler_repr(EulerObject * self) return ret; } +static PyObject *Euler_str(EulerObject * self) +{ + DynStr *ds; + + if (BaseMath_ReadCallback(self) == -1) + return NULL; + + ds= BLI_dynstr_new(); + + BLI_dynstr_appendf(ds, "<Euler (x=%.4f, y=%.4f, z=%.4f), order='%s'>", + self->eul[0], self->eul[1], self->eul[2], euler_order_str(self)); + + return mathutils_dynstr_to_py(ds); /* frees ds */ +} + static PyObject* Euler_richcmpr(PyObject *a, PyObject *b, int op) { PyObject *res; @@ -635,7 +651,7 @@ PyTypeObject euler_Type = { &Euler_AsMapping, //tp_as_mapping NULL, //tp_hash NULL, //tp_call - NULL, //tp_str + (reprfunc) Euler_str, //tp_str NULL, //tp_getattro NULL, //tp_setattro NULL, //tp_as_buffer diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index 44799bb7943..59aad37f746 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -35,6 +35,8 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_string.h" +#include "BLI_dynstr.h" static PyObject *Matrix_copy(MatrixObject *self); static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *value); @@ -49,56 +51,56 @@ static int mathutils_matrix_vector_check(BaseMathObject *bmo) return BaseMath_ReadCallback(self); } -static int mathutils_matrix_vector_get(BaseMathObject *bmo, int subtype) +static int mathutils_matrix_vector_get(BaseMathObject *bmo, int col) { MatrixObject *self= (MatrixObject *)bmo->cb_user; - int index; + int row; if (BaseMath_ReadCallback(self) == -1) return -1; - for (index=0; index < self->col_size; index++) { - bmo->data[index] = MATRIX_ITEM(self, subtype, index); + for (row=0; row < self->num_row; row++) { + bmo->data[row] = MATRIX_ITEM(self, row, col); } return 0; } -static int mathutils_matrix_vector_set(BaseMathObject *bmo, int subtype) +static int mathutils_matrix_vector_set(BaseMathObject *bmo, int col) { MatrixObject *self= (MatrixObject *)bmo->cb_user; - int index; + int row; if (BaseMath_ReadCallback(self) == -1) return -1; - for (index=0; index < self->col_size; index++) { - MATRIX_ITEM(self, subtype, index) = bmo->data[index]; + for (row=0; row < self->num_row; row++) { + MATRIX_ITEM(self, row, col) = bmo->data[row]; } (void)BaseMath_WriteCallback(self); return 0; } -static int mathutils_matrix_vector_get_index(BaseMathObject *bmo, int subtype, int index) +static int mathutils_matrix_vector_get_index(BaseMathObject *bmo, int col, int row) { MatrixObject *self= (MatrixObject *)bmo->cb_user; if (BaseMath_ReadCallback(self) == -1) return -1; - bmo->data[index]= MATRIX_ITEM(self, subtype, index); + bmo->data[row]= MATRIX_ITEM(self, row, col); return 0; } -static int mathutils_matrix_vector_set_index(BaseMathObject *bmo, int subtype, int index) +static int mathutils_matrix_vector_set_index(BaseMathObject *bmo, int col, int row) { MatrixObject *self= (MatrixObject *)bmo->cb_user; if (BaseMath_ReadCallback(self) == -1) return -1; - MATRIX_ITEM(self, subtype, index) = bmo->data[index]; + MATRIX_ITEM(self, row, col) = bmo->data[row]; (void)BaseMath_WriteCallback(self); return 0; @@ -133,16 +135,16 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyObject *arg= PyTuple_GET_ITEM(args, 0); /* -1 is an error, size checks will accunt for this */ - const unsigned short row_size= PySequence_Size(arg); + const unsigned short num_col= PySequence_Size(arg); - if (row_size >= 2 && row_size <= 4) { + if (num_col >= 2 && num_col <= 4) { PyObject *item= PySequence_GetItem(arg, 0); - const unsigned short col_size= PySequence_Size(item); + const unsigned short num_row= PySequence_Size(item); Py_XDECREF(item); - if (col_size >= 2 && col_size <= 4) { + if (num_row >= 2 && num_row <= 4) { /* sane row & col size, new matrix and assign as slice */ - PyObject *matrix= Matrix_CreatePyObject(NULL, row_size, col_size, Py_NEW, type); + PyObject *matrix= Matrix_CreatePyObject(NULL, num_col, num_row, Py_NEW, type); if (Matrix_ass_slice((MatrixObject *)matrix, 0, INT_MAX, arg) == 0) { return matrix; } @@ -622,25 +624,25 @@ static PyObject *C_Matrix_Shear(PyObject *cls, PyObject *args) void matrix_as_3x3(float mat[3][3], MatrixObject *self) { - copy_v3_v3(mat[0], MATRIX_ROW_PTR(self, 0)); - copy_v3_v3(mat[1], MATRIX_ROW_PTR(self, 1)); - copy_v3_v3(mat[2], MATRIX_ROW_PTR(self, 2)); + copy_v3_v3(mat[0], MATRIX_COL_PTR(self, 0)); + copy_v3_v3(mat[1], MATRIX_COL_PTR(self, 1)); + copy_v3_v3(mat[2], MATRIX_COL_PTR(self, 2)); } /* assumes rowsize == colsize is checked and the read callback has run */ static float matrix_determinant_internal(MatrixObject *self) { - if (self->row_size == 2) { + if (self->num_col == 2) { return determinant_m2(MATRIX_ITEM(self, 0, 0), MATRIX_ITEM(self, 0, 1), MATRIX_ITEM(self, 1, 0), MATRIX_ITEM(self, 1, 1)); } - else if (self->row_size == 3) { + else if (self->num_col == 3) { return determinant_m3(MATRIX_ITEM(self, 0, 0), MATRIX_ITEM(self, 0, 1), MATRIX_ITEM(self, 0, 2), MATRIX_ITEM(self, 1, 0), MATRIX_ITEM(self, 1, 1), MATRIX_ITEM(self, 1, 2), MATRIX_ITEM(self, 2, 0), MATRIX_ITEM(self, 2, 1), MATRIX_ITEM(self, 2, 2)); } else { - return determinant_m4((float (*)[4])self->contigPtr); + return determinant_m4((float (*)[4])self->matrix); } } @@ -662,17 +664,17 @@ static PyObject *Matrix_to_quaternion(MatrixObject *self) return NULL; /*must be 3-4 cols, 3-4 rows, square matrix*/ - if ((self->col_size < 3) || (self->row_size < 3) || (self->col_size != self->row_size)) { + if ((self->num_row < 3) || (self->num_col < 3) || (self->num_row != self->num_col)) { PyErr_SetString(PyExc_ValueError, "Matrix.to_quat(): " "inappropriate matrix size - expects 3x3 or 4x4 matrix"); return NULL; } - if (self->col_size == 3) { - mat3_to_quat(quat, (float (*)[3])self->contigPtr); + if (self->num_row == 3) { + mat3_to_quat(quat, (float (*)[3])self->matrix); } else { - mat4_to_quat(quat, (float (*)[4])self->contigPtr); + mat4_to_quat(quat, (float (*)[4])self->matrix); } return Quaternion_CreatePyObject(quat, Py_NEW, NULL); @@ -719,11 +721,11 @@ static PyObject *Matrix_to_euler(MatrixObject *self, PyObject *args) } /*must be 3-4 cols, 3-4 rows, square matrix*/ - if (self->col_size ==3 && self->row_size ==3) { - mat= (float (*)[3])self->contigPtr; + if (self->num_row ==3 && self->num_col ==3) { + mat= (float (*)[3])self->matrix; } - else if (self->col_size ==4 && self->row_size ==4) { - copy_m3_m4(tmat, (float (*)[4])self->contigPtr); + else if (self->num_row ==4 && self->num_col ==4) { + copy_m3_m4(tmat, (float (*)[4])self->matrix); mat= tmat; } else { @@ -774,8 +776,8 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self) return NULL; } - self->contigPtr = PyMem_Realloc(self->contigPtr, (sizeof(float) * 16)); - if (self->contigPtr == NULL) { + self->matrix = PyMem_Realloc(self->matrix, (sizeof(float) * 16)); + if (self->matrix == NULL) { PyErr_SetString(PyExc_MemoryError, "Matrix.resize_4x4(): " "problem allocating pointer space"); @@ -783,31 +785,31 @@ static PyObject *Matrix_resize_4x4(MatrixObject *self) } /*move data to new spot in array + clean*/ - for (blank_rows = (4 - self->row_size); blank_rows > 0; blank_rows--) { + for (blank_rows = (4 - self->num_col); blank_rows > 0; blank_rows--) { for (x = 0; x < 4; x++) { - index = (4 * (self->row_size + (blank_rows - 1))) + x; + index = (4 * (self->num_col + (blank_rows - 1))) + x; if (index == 10 || index == 15) { - self->contigPtr[index] = 1.0f; + self->matrix[index] = 1.0f; } else { - self->contigPtr[index] = 0.0f; + self->matrix[index] = 0.0f; } } } - for (x = 1; x <= self->row_size; x++) { - first_row_elem = (self->col_size * (self->row_size - x)); - curr_pos = (first_row_elem + (self->col_size -1)); - new_pos = (4 * (self->row_size - x)) + (curr_pos - first_row_elem); - for (blank_columns = (4 - self->col_size); blank_columns > 0; blank_columns--) { - self->contigPtr[new_pos + blank_columns] = 0.0f; + for (x = 1; x <= self->num_col; x++) { + first_row_elem = (self->num_row * (self->num_col - x)); + curr_pos = (first_row_elem + (self->num_row -1)); + new_pos = (4 * (self->num_col - x)) + (curr_pos - first_row_elem); + for (blank_columns = (4 - self->num_row); blank_columns > 0; blank_columns--) { + self->matrix[new_pos + blank_columns] = 0.0f; } for ( ; curr_pos >= first_row_elem; curr_pos--) { - self->contigPtr[new_pos] = self->contigPtr[curr_pos]; + self->matrix[new_pos] = self->matrix[curr_pos]; new_pos--; } } - self->row_size = 4; - self->col_size = 4; + self->num_col = 4; + self->num_row = 4; Py_RETURN_NONE; } @@ -825,12 +827,12 @@ static PyObject *Matrix_to_4x4(MatrixObject *self) if (BaseMath_ReadCallback(self) == -1) return NULL; - if (self->col_size==4 && self->row_size==4) { - return Matrix_CreatePyObject(self->contigPtr, 4, 4, Py_NEW, Py_TYPE(self)); + if (self->num_row==4 && self->num_col==4) { + return Matrix_CreatePyObject(self->matrix, 4, 4, Py_NEW, Py_TYPE(self)); } - else if (self->col_size==3 && self->row_size==3) { + else if (self->num_row==3 && self->num_col==3) { float mat[4][4]; - copy_m4_m3(mat, (float (*)[3])self->contigPtr); + copy_m4_m3(mat, (float (*)[3])self->matrix); return Matrix_CreatePyObject((float *)mat, 4, 4, Py_NEW, Py_TYPE(self)); } /* TODO, 2x2 matrix */ @@ -856,7 +858,7 @@ static PyObject *Matrix_to_3x3(MatrixObject *self) if (BaseMath_ReadCallback(self) == -1) return NULL; - if ((self->col_size < 3) || (self->row_size < 3)) { + if ((self->num_row < 3) || (self->num_col < 3)) { PyErr_SetString(PyExc_TypeError, "Matrix.to_3x3(): inappropriate matrix size"); return NULL; @@ -880,14 +882,14 @@ static PyObject *Matrix_to_translation(MatrixObject *self) if (BaseMath_ReadCallback(self) == -1) return NULL; - if ((self->col_size < 3) || self->row_size < 4) { + if ((self->num_row < 3) || self->num_col < 4) { PyErr_SetString(PyExc_TypeError, "Matrix.to_translation(): " "inappropriate matrix size"); return NULL; } - return Vector_CreatePyObject(MATRIX_ROW_PTR(self, 3), 3, Py_NEW, NULL); + return Vector_CreatePyObject(MATRIX_COL_PTR(self, 3), 3, Py_NEW, NULL); } PyDoc_STRVAR(Matrix_to_scale_doc, @@ -910,7 +912,7 @@ static PyObject *Matrix_to_scale(MatrixObject *self) return NULL; /*must be 3-4 cols, 3-4 rows, square matrix*/ - if ((self->col_size < 3) || (self->row_size < 3)) { + if ((self->num_row < 3) || (self->num_col < 3)) { PyErr_SetString(PyExc_TypeError, "Matrix.to_scale(): " "inappropriate matrix size, 3x3 minimum size"); @@ -948,7 +950,7 @@ static PyObject *Matrix_invert(MatrixObject *self) if (BaseMath_ReadCallback(self) == -1) return NULL; - if (self->row_size != self->col_size) { + if (self->num_col != self->num_row) { PyErr_SetString(PyExc_TypeError, "Matrix.invert(ed): " "only square matrices are supported"); @@ -960,26 +962,26 @@ static PyObject *Matrix_invert(MatrixObject *self) if (det != 0) { /*calculate the classical adjoint*/ - if (self->row_size == 2) { + if (self->num_col == 2) { mat[0] = MATRIX_ITEM(self, 1, 1); mat[1] = -MATRIX_ITEM(self, 0, 1); mat[2] = -MATRIX_ITEM(self, 1, 0); mat[3] = MATRIX_ITEM(self, 0, 0); } - else if (self->row_size == 3) { - adjoint_m3_m3((float (*)[3]) mat,(float (*)[3])self->contigPtr); + else if (self->num_col == 3) { + adjoint_m3_m3((float (*)[3]) mat,(float (*)[3])self->matrix); } - else if (self->row_size == 4) { - adjoint_m4_m4((float (*)[4]) mat, (float (*)[4])self->contigPtr); + else if (self->num_col == 4) { + adjoint_m4_m4((float (*)[4]) mat, (float (*)[4])self->matrix); } /*divide by determinate*/ - for (x = 0; x < (self->row_size * self->col_size); x++) { + for (x = 0; x < (self->num_col * self->num_row); x++) { mat[x] /= det; } /*set values*/ - for (x = 0; x < self->row_size; x++) { - for (y = 0; y < self->col_size; y++) { - MATRIX_ITEM(self, x, y) = mat[z]; + for (x = 0; x < self->num_col; x++) { + for (y = 0; y < self->num_row; y++) { + MATRIX_ITEM(self, y, x) = mat[z]; z++; } } @@ -1032,7 +1034,7 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value) if (mathutils_any_to_rotmat(other_rmat, value, "matrix.rotate(value)") == -1) return NULL; - if (self->col_size != 3 || self->row_size != 3) { + if (self->num_row != 3 || self->num_col != 3) { PyErr_SetString(PyExc_TypeError, "Matrix.rotate(): " "must have 3x3 dimensions"); @@ -1042,7 +1044,7 @@ static PyObject *Matrix_rotate(MatrixObject *self, PyObject *value) matrix_as_3x3(self_rmat, self); mul_m3_m3m3(rmat, other_rmat, self_rmat); - copy_m3_m3((float (*)[3])(self->contigPtr), rmat); + copy_m3_m3((float (*)[3])(self->matrix), rmat); (void)BaseMath_WriteCallback(self); Py_RETURN_NONE; @@ -1065,7 +1067,7 @@ static PyObject *Matrix_decompose(MatrixObject *self) float quat[4]; float size[3]; - if (self->col_size != 4 || self->row_size != 4) { + if (self->num_row != 4 || self->num_col != 4) { PyErr_SetString(PyExc_TypeError, "Matrix.decompose(): " "inappropriate matrix size - expects 4x4 matrix"); @@ -1075,7 +1077,7 @@ static PyObject *Matrix_decompose(MatrixObject *self) if (BaseMath_ReadCallback(self) == -1) return NULL; - mat4_to_loc_rot_size(loc, rot, size, (float (*)[4])self->contigPtr); + mat4_to_loc_rot_size(loc, rot, size, (float (*)[4])self->matrix); mat3_to_quat(quat, rot); ret= PyTuple_New(3); @@ -1108,7 +1110,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "O!f:lerp", &matrix_Type, &mat2, &fac)) return NULL; - if (self->row_size != mat2->row_size || self->col_size != mat2->col_size) { + if (self->num_col != mat2->num_col || self->num_row != mat2->num_row) { PyErr_SetString(PyExc_ValueError, "Matrix.lerp(): " "expects both matrix objects of the same dimensions"); @@ -1119,11 +1121,11 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args) return NULL; /* TODO, different sized matrix */ - if (self->row_size==4 && self->col_size==4) { - blend_m4_m4m4((float (*)[4])mat, (float (*)[4])self->contigPtr, (float (*)[4])mat2->contigPtr, fac); + if (self->num_col==4 && self->num_row==4) { + blend_m4_m4m4((float (*)[4])mat, (float (*)[4])self->matrix, (float (*)[4])mat2->matrix, fac); } - else if (self->row_size==3 && self->col_size==3) { - blend_m3_m3m3((float (*)[3])mat, (float (*)[3])self->contigPtr, (float (*)[3])mat2->contigPtr, fac); + else if (self->num_col==3 && self->num_row==3) { + blend_m3_m3m3((float (*)[3])mat, (float (*)[3])self->matrix, (float (*)[3])mat2->matrix, fac); } else { PyErr_SetString(PyExc_ValueError, @@ -1132,7 +1134,7 @@ static PyObject *Matrix_lerp(MatrixObject *self, PyObject *args) return NULL; } - return Matrix_CreatePyObject(mat, self->row_size, self->col_size, Py_NEW, Py_TYPE(self)); + return Matrix_CreatePyObject(mat, self->num_col, self->num_row, Py_NEW, Py_TYPE(self)); } /*---------------------------matrix.determinant() ----------------*/ @@ -1151,7 +1153,7 @@ static PyObject *Matrix_determinant(MatrixObject *self) if (BaseMath_ReadCallback(self) == -1) return NULL; - if (self->row_size != self->col_size) { + if (self->num_col != self->num_row) { PyErr_SetString(PyExc_TypeError, "Matrix.determinant(): " "only square matrices are supported"); @@ -1173,23 +1175,23 @@ static PyObject *Matrix_transpose(MatrixObject *self) if (BaseMath_ReadCallback(self) == -1) return NULL; - if (self->row_size != self->col_size) { + if (self->num_col != self->num_row) { PyErr_SetString(PyExc_TypeError, "Matrix.transpose(d): " "only square matrices are supported"); return NULL; } - if (self->row_size == 2) { + if (self->num_col == 2) { const float t = MATRIX_ITEM(self, 1, 0); MATRIX_ITEM(self, 1, 0) = MATRIX_ITEM(self, 0, 1); MATRIX_ITEM(self, 0, 1) = t; } - else if (self->row_size == 3) { - transpose_m3((float (*)[3])self->contigPtr); + else if (self->num_col == 3) { + transpose_m3((float (*)[3])self->matrix); } else { - transpose_m4((float (*)[4])self->contigPtr); + transpose_m4((float (*)[4])self->matrix); } (void)BaseMath_WriteCallback(self); @@ -1220,7 +1222,7 @@ PyDoc_STRVAR(Matrix_zero_doc, ); static PyObject *Matrix_zero(MatrixObject *self) { - fill_vn_fl(self->contigPtr, self->row_size * self->col_size, 0.0f); + fill_vn_fl(self->matrix, self->num_col * self->num_row, 0.0f); if (BaseMath_WriteCallback(self) == -1) return NULL; @@ -1243,24 +1245,24 @@ static PyObject *Matrix_identity(MatrixObject *self) if (BaseMath_ReadCallback(self) == -1) return NULL; - if (self->row_size != self->col_size) { + if (self->num_col != self->num_row) { PyErr_SetString(PyExc_TypeError, "Matrix.identity(): " "only square matrices are supported"); return NULL; } - if (self->row_size == 2) { + if (self->num_col == 2) { MATRIX_ITEM(self, 0, 0) = 1.0f; MATRIX_ITEM(self, 0, 1) = 0.0f; MATRIX_ITEM(self, 1, 0) = 0.0f; MATRIX_ITEM(self, 1, 1) = 1.0f; } - else if (self->row_size == 3) { - unit_m3((float (*)[3])self->contigPtr); + else if (self->num_col == 3) { + unit_m3((float (*)[3])self->matrix); } else { - unit_m4((float (*)[4])self->contigPtr); + unit_m4((float (*)[4])self->matrix); } if (BaseMath_WriteCallback(self) == -1) @@ -1283,26 +1285,26 @@ static PyObject *Matrix_copy(MatrixObject *self) if (BaseMath_ReadCallback(self) == -1) return NULL; - return Matrix_CreatePyObject((float (*))self->contigPtr, self->row_size, self->col_size, Py_NEW, Py_TYPE(self)); + return Matrix_CreatePyObject((float (*))self->matrix, self->num_col, self->num_row, Py_NEW, Py_TYPE(self)); } /*----------------------------print object (internal)-------------*/ /*print the object to screen*/ static PyObject *Matrix_repr(MatrixObject *self) { - int x, y; + int col, row; PyObject *rows[MATRIX_MAX_DIM]= {NULL}; if (BaseMath_ReadCallback(self) == -1) return NULL; - for (x = 0; x < self->row_size; x++) { - rows[x]= PyTuple_New(self->col_size); - for (y = 0; y < self->col_size; y++) { - PyTuple_SET_ITEM(rows[x], y, PyFloat_FromDouble(MATRIX_ITEM(self, x, y))); + for (col = 0; col < self->num_col; col++) { + rows[col]= PyTuple_New(self->num_row); + for (row = 0; row < self->num_row; row++) { + PyTuple_SET_ITEM(rows[col], row, PyFloat_FromDouble(MATRIX_ITEM(self, row, col))); } } - switch (self->row_size) { + switch (self->num_col) { case 2: return PyUnicode_FromFormat("Matrix((%R,\n" " %R))", rows[0], rows[1]); @@ -1320,6 +1322,42 @@ static PyObject *Matrix_repr(MatrixObject *self) return NULL; } +static PyObject* Matrix_str(MatrixObject *self) +{ + DynStr *ds; + + int maxsize[MATRIX_MAX_DIM]; + int row, col; + + char dummy_buf[1]; + + if (BaseMath_ReadCallback(self) == -1) + return NULL; + + ds= BLI_dynstr_new(); + + /* First determine the maximum width for each column */ + for (col = 0; col < self->num_col; col++) { + maxsize[col]= 0; + for (row = 0; row < self->num_row; row++) { + int size= BLI_snprintf(dummy_buf, sizeof(dummy_buf), "%.4f", MATRIX_ITEM(self, row, col)); + maxsize[col]= MAX2(maxsize[col], size); + } + } + + /* Now write the unicode string to be printed */ + BLI_dynstr_appendf(ds, "<Matrix %dx%d (", self->num_row, self->num_col); + for (row = 0; row < self->num_row; row++) { + for (col = 0; col < self->num_col; col++) { + BLI_dynstr_appendf(ds, col ? ", %*.4f" : "%*.4f", maxsize[col], MATRIX_ITEM(self, row, col)); + } + BLI_dynstr_append(ds, row + 1 != self->num_row ? ")\n " : ")"); + } + BLI_dynstr_append(ds, ">"); + + return mathutils_dynstr_to_py(ds); /* frees ds */ +} + static PyObject* Matrix_richcmpr(PyObject *a, PyObject *b, int op) { PyObject *res; @@ -1332,9 +1370,9 @@ static PyObject* Matrix_richcmpr(PyObject *a, PyObject *b, int op) if (BaseMath_ReadCallback(matA) == -1 || BaseMath_ReadCallback(matB) == -1) return NULL; - ok= ( (matA->col_size == matB->col_size) && - (matA->row_size == matB->row_size) && - EXPP_VectorsAreEqual(matA->contigPtr, matB->contigPtr, (matA->row_size * matA->col_size), 1) + ok= ( (matA->num_row == matB->num_row) && + (matA->num_col == matB->num_col) && + EXPP_VectorsAreEqual(matA->matrix, matB->matrix, (matA->num_col * matA->num_row), 1) ) ? 0 : -1; } @@ -1364,7 +1402,7 @@ static PyObject* Matrix_richcmpr(PyObject *a, PyObject *b, int op) sequence length*/ static int Matrix_len(MatrixObject *self) { - return (self->row_size); + return (self->num_col); } /*----------------------------object[]--------------------------- sequence accessor (get) @@ -1374,13 +1412,13 @@ static PyObject *Matrix_item(MatrixObject *self, int i) if (BaseMath_ReadCallback(self) == -1) return NULL; - if (i < 0 || i >= self->row_size) { + if (i < 0 || i >= self->num_col) { PyErr_SetString(PyExc_IndexError, "matrix[attribute]: " "array index out of range"); return NULL; } - return Vector_CreatePyObject_cb((PyObject *)self, self->col_size, mathutils_matrix_vector_cb_index, i); + return Vector_CreatePyObject_cb((PyObject *)self, self->num_row, mathutils_matrix_vector_cb_index, i); } /*----------------------------object[]------------------------- sequence accessor (set) */ @@ -1391,17 +1429,17 @@ static int Matrix_ass_item(MatrixObject *self, int i, PyObject *value) if (BaseMath_ReadCallback(self) == -1) return -1; - if (i >= self->row_size || i < 0) { + if (i >= self->num_col || i < 0) { PyErr_SetString(PyExc_IndexError, "matrix[attribute] = x: bad column"); return -1; } - if (mathutils_array_parse(vec, self->col_size, self->col_size, value, "matrix[i] = value assignment") < 0) { + if (mathutils_array_parse(vec, self->num_row, self->num_row, value, "matrix[i] = value assignment") < 0) { return -1; } - memcpy(MATRIX_ROW_PTR(self, i), vec, self->col_size * sizeof(float)); + memcpy(MATRIX_COL_PTR(self, i), vec, self->num_row * sizeof(float)); (void)BaseMath_WriteCallback(self); return 0; @@ -1418,14 +1456,14 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end) if (BaseMath_ReadCallback(self) == -1) return NULL; - CLAMP(begin, 0, self->row_size); - CLAMP(end, 0, self->row_size); + CLAMP(begin, 0, self->num_col); + CLAMP(end, 0, self->num_col); begin= MIN2(begin, end); tuple= PyTuple_New(end - begin); for (count= begin; count < end; count++) { PyTuple_SET_ITEM(tuple, count - begin, - Vector_CreatePyObject_cb((PyObject *)self, self->col_size, mathutils_matrix_vector_cb_index, count)); + Vector_CreatePyObject_cb((PyObject *)self, self->num_row, mathutils_matrix_vector_cb_index, count)); } @@ -1440,8 +1478,8 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va if (BaseMath_ReadCallback(self) == -1) return -1; - CLAMP(begin, 0, self->row_size); - CLAMP(end, 0, self->row_size); + CLAMP(begin, 0, self->num_col); + CLAMP(end, 0, self->num_col); begin = MIN2(begin, end); /* non list/tuple cases */ @@ -1467,7 +1505,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va /*parse each sub sequence*/ PyObject *item= PySequence_Fast_GET_ITEM(value_fast, i); - if (mathutils_array_parse(&mat[i * self->col_size], self->col_size, self->col_size, item, + if (mathutils_array_parse(&mat[i * self->num_row], self->num_row, self->num_row, item, "matrix[begin:end] = value assignment") < 0) { return -1; @@ -1477,7 +1515,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va Py_DECREF(value_fast); /*parsed well - now set in matrix*/ - memcpy(self->contigPtr + (begin * self->col_size), mat, sizeof(float) * (size * self->col_size)); + memcpy(self->matrix + (begin * self->num_row), mat, sizeof(float) * (size * self->num_row)); (void)BaseMath_WriteCallback(self); return 0; @@ -1504,16 +1542,16 @@ static PyObject *Matrix_add(PyObject *m1, PyObject *m2) if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1) return NULL; - if (mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size) { + if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) { PyErr_SetString(PyExc_TypeError, "Matrix addition: " "matrices must have the same dimensions for this operation"); return NULL; } - add_vn_vnvn(mat, mat1->contigPtr, mat2->contigPtr, mat1->row_size * mat1->col_size); + add_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row); - return Matrix_CreatePyObject(mat, mat1->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1)); + return Matrix_CreatePyObject(mat, mat1->num_col, mat1->num_row, Py_NEW, Py_TYPE(mat1)); } /*------------------------obj - obj------------------------------ subtraction*/ @@ -1537,24 +1575,24 @@ static PyObject *Matrix_sub(PyObject *m1, PyObject *m2) if (BaseMath_ReadCallback(mat1) == -1 || BaseMath_ReadCallback(mat2) == -1) return NULL; - if (mat1->row_size != mat2->row_size || mat1->col_size != mat2->col_size) { + if (mat1->num_col != mat2->num_col || mat1->num_row != mat2->num_row) { PyErr_SetString(PyExc_TypeError, "Matrix addition: " "matrices must have the same dimensions for this operation"); return NULL; } - sub_vn_vnvn(mat, mat1->contigPtr, mat2->contigPtr, mat1->row_size * mat1->col_size); + sub_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row); - return Matrix_CreatePyObject(mat, mat1->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1)); + return Matrix_CreatePyObject(mat, mat1->num_col, mat1->num_row, Py_NEW, Py_TYPE(mat1)); } /*------------------------obj * obj------------------------------ mulplication*/ static PyObject *matrix_mul_float(MatrixObject *mat, const float scalar) { float tmat[16]; - mul_vn_vn_fl(tmat, mat->contigPtr, mat->row_size * mat->col_size, scalar); - return Matrix_CreatePyObject(tmat, mat->row_size, mat->col_size, Py_NEW, Py_TYPE(mat)); + mul_vn_vn_fl(tmat, mat->matrix, mat->num_col * mat->num_row, scalar); + return Matrix_CreatePyObject(tmat, mat->num_col, mat->num_row, Py_NEW, Py_TYPE(mat)); } static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) @@ -1581,19 +1619,19 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}; double dot = 0.0f; - int x, y, z; + int col, row, item; - for (x = 0; x < mat2->row_size; x++) { - for (y = 0; y < mat1->col_size; y++) { - for (z = 0; z < mat1->row_size; z++) { - dot += MATRIX_ITEM(mat1, z, y) * MATRIX_ITEM(mat2, x, z); + for (col = 0; col < mat2->num_col; col++) { + for (row = 0; row < mat1->num_row; row++) { + for (item = 0; item < mat1->num_col; item++) { + dot += MATRIX_ITEM(mat1, row, item) * MATRIX_ITEM(mat2, item, col); } - mat[((x * mat1->col_size) + y)] = (float)dot; + mat[((col * mat1->num_row) + row)] = (float)dot; dot = 0.0f; } } - return Matrix_CreatePyObject(mat, mat2->row_size, mat1->col_size, Py_NEW, Py_TYPE(mat1)); + return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_NEW, Py_TYPE(mat1)); } else if (mat2) { /*FLOAT/INT * MATRIX */ @@ -1660,13 +1698,13 @@ static PyObject *Matrix_subscript(MatrixObject* self, PyObject* item) if (i == -1 && PyErr_Occurred()) return NULL; if (i < 0) - i += self->row_size; + i += self->num_col; return Matrix_item(self, i); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx((void *)item, self->row_size, &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx((void *)item, self->num_col, &start, &stop, &step, &slicelength) < 0) return NULL; if (slicelength <= 0) { @@ -1696,13 +1734,13 @@ static int Matrix_ass_subscript(MatrixObject* self, PyObject* item, PyObject* va if (i == -1 && PyErr_Occurred()) return -1; if (i < 0) - i += self->row_size; + i += self->num_col; return Matrix_ass_item(self, i, value); } else if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; - if (PySlice_GetIndicesEx((void *)item, self->row_size, &start, &stop, &step, &slicelength) < 0) + if (PySlice_GetIndicesEx((void *)item, self->num_col, &start, &stop, &step, &slicelength) < 0) return -1; if (step == 1) @@ -1767,12 +1805,12 @@ static PyNumberMethods Matrix_NumMethods = { static PyObject *Matrix_getRowSize(MatrixObject *self, void *UNUSED(closure)) { - return PyLong_FromLong((long) self->row_size); + return PyLong_FromLong((long) self->num_col); } static PyObject *Matrix_getColSize(MatrixObject *self, void *UNUSED(closure)) { - return PyLong_FromLong((long) self->col_size); + return PyLong_FromLong((long) self->num_row); } static PyObject *Matrix_median_scale_get(MatrixObject *self, void *UNUSED(closure)) @@ -1783,7 +1821,7 @@ static PyObject *Matrix_median_scale_get(MatrixObject *self, void *UNUSED(closur return NULL; /*must be 3-4 cols, 3-4 rows, square matrix*/ - if ((self->col_size < 3) || (self->row_size < 3)) { + if ((self->num_row < 3) || (self->num_col < 3)) { PyErr_SetString(PyExc_AttributeError, "Matrix.median_scale: " "inappropriate matrix size, 3x3 minimum"); @@ -1801,10 +1839,10 @@ static PyObject *Matrix_is_negative_get(MatrixObject *self, void *UNUSED(closure return NULL; /*must be 3-4 cols, 3-4 rows, square matrix*/ - if (self->col_size == 4 && self->row_size == 4) - return PyBool_FromLong(is_negative_m4((float (*)[4])self->contigPtr)); - else if (self->col_size == 3 && self->row_size == 3) - return PyBool_FromLong(is_negative_m3((float (*)[3])self->contigPtr)); + if (self->num_row == 4 && self->num_col == 4) + return PyBool_FromLong(is_negative_m4((float (*)[4])self->matrix)); + else if (self->num_row == 3 && self->num_col == 3) + return PyBool_FromLong(is_negative_m3((float (*)[3])self->matrix)); else { PyErr_SetString(PyExc_AttributeError, "Matrix.is_negative: " @@ -1819,10 +1857,10 @@ static PyObject *Matrix_is_orthogonal_get(MatrixObject *self, void *UNUSED(closu return NULL; /*must be 3-4 cols, 3-4 rows, square matrix*/ - if (self->col_size == 4 && self->row_size == 4) - return PyBool_FromLong(is_orthogonal_m4((float (*)[4])self->contigPtr)); - else if (self->col_size == 3 && self->row_size == 3) - return PyBool_FromLong(is_orthogonal_m3((float (*)[3])self->contigPtr)); + if (self->num_row == 4 && self->num_col == 4) + return PyBool_FromLong(is_orthogonal_m4((float (*)[4])self->matrix)); + else if (self->num_row == 3 && self->num_col == 3) + return PyBool_FromLong(is_orthogonal_m3((float (*)[3])self->matrix)); else { PyErr_SetString(PyExc_AttributeError, "Matrix.is_orthogonal: " @@ -1906,7 +1944,7 @@ PyTypeObject matrix_Type = { &Matrix_AsMapping, /*tp_as_mapping*/ NULL, /*tp_hash*/ NULL, /*tp_call*/ - NULL, /*tp_str*/ + (reprfunc) Matrix_str, /*tp_str*/ NULL, /*tp_getattro*/ NULL, /*tp_setattro*/ NULL, /*tp_as_buffer*/ @@ -1944,37 +1982,37 @@ PyTypeObject matrix_Type = { * pass Py_NEW - if vector is not a WRAPPER and managed by PYTHON * (i.e. it must be created here with PyMEM_malloc()) */ PyObject *Matrix_CreatePyObject(float *mat, - const unsigned short row_size, const unsigned short col_size, + const unsigned short num_col, const unsigned short num_row, int type, PyTypeObject *base_type) { MatrixObject *self; /* matrix objects can be any 2-4row x 2-4col matrix */ - if (row_size < 2 || row_size > 4 || col_size < 2 || col_size > 4) { + if (num_col < 2 || num_col > 4 || num_row < 2 || num_row > 4) { PyErr_SetString(PyExc_RuntimeError, "Matrix(): " "row and column sizes must be between 2 and 4"); return NULL; } - self= base_type ? (MatrixObject *)base_type->tp_alloc(base_type, 0) : - (MatrixObject *)PyObject_GC_New(MatrixObject, &matrix_Type); + self= base_type ? (MatrixObject *)base_type->tp_alloc(base_type, 0) : + (MatrixObject *)PyObject_GC_New(MatrixObject, &matrix_Type); if (self) { - self->row_size = row_size; - self->col_size = col_size; + self->num_col = num_col; + self->num_row = num_row; /* init callbacks as NULL */ self->cb_user= NULL; self->cb_type= self->cb_subtype= 0; if (type == Py_WRAP) { - self->contigPtr = mat; + self->matrix = mat; self->wrapped = Py_WRAP; } else if (type == Py_NEW) { - self->contigPtr = PyMem_Malloc(row_size * col_size * sizeof(float)); - if (self->contigPtr == NULL) { /*allocation failure*/ + self->matrix = PyMem_Malloc(num_col * num_row * sizeof(float)); + if (self->matrix == NULL) { /*allocation failure*/ PyErr_SetString(PyExc_MemoryError, "Matrix(): " "problem allocating pointer space"); @@ -1982,16 +2020,16 @@ PyObject *Matrix_CreatePyObject(float *mat, } if (mat) { /*if a float array passed*/ - memcpy(self->contigPtr, mat, row_size * col_size * sizeof(float)); + memcpy(self->matrix, mat, num_col * num_row * sizeof(float)); } - else if (row_size == col_size) { + else if (num_col == num_row) { /* or if no arguments are passed return identity matrix for square matrices */ PyObject *ret_dummy= Matrix_identity(self); Py_DECREF(ret_dummy); } else { /* otherwise zero everything */ - memset(self->contigPtr, 0, row_size * col_size * sizeof(float)); + memset(self->matrix, 0, num_col * num_row * sizeof(float)); } self->wrapped = Py_NEW; } diff --git a/source/blender/python/mathutils/mathutils_Matrix.h b/source/blender/python/mathutils/mathutils_Matrix.h index 95768febca0..91a276b648e 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.h +++ b/source/blender/python/mathutils/mathutils_Matrix.h @@ -41,22 +41,22 @@ extern PyTypeObject matrix_Type; /* matrix[row][col] == MATRIX_ITEM_INDEX(matrix, row, col) */ #ifdef DEBUG -# define MATRIX_ITEM_ASSERT(_mat, _row, _col) (BLI_assert(_row < (_mat)->row_size && _col < (_mat)->col_size)) +# define MATRIX_ITEM_ASSERT(_mat, _row, _col) (BLI_assert(_row < (_mat)->num_row && _col < (_mat)->num_col)) #else # define MATRIX_ITEM_ASSERT(_mat, _row, _col) (void)0 #endif -#define MATRIX_ITEM_INDEX(_mat, _row, _col) (MATRIX_ITEM_ASSERT(_mat, _row, _col),(((_mat)->col_size * (_row)) + (_col))) -#define MATRIX_ITEM_PTR( _mat, _row, _col) ((_mat)->contigPtr + MATRIX_ITEM_INDEX(_mat, _row, _col)) -#define MATRIX_ITEM( _mat, _row, _col) ((_mat)->contigPtr [MATRIX_ITEM_INDEX(_mat, _row, _col)]) +#define MATRIX_ITEM_INDEX(_mat, _row, _col) (MATRIX_ITEM_ASSERT(_mat, _row, _col),(((_mat)->num_row * (_col)) + (_row))) +#define MATRIX_ITEM_PTR( _mat, _row, _col) ((_mat)->matrix + MATRIX_ITEM_INDEX(_mat, _row, _col)) +#define MATRIX_ITEM( _mat, _row, _col) ((_mat)->matrix [MATRIX_ITEM_INDEX(_mat, _row, _col)]) -#define MATRIX_ROW_INDEX(_mat, _row) (MATRIX_ITEM_INDEX(_mat, _row, 0)) -#define MATRIX_ROW_PTR( _mat, _row) ((_mat)->contigPtr + MATRIX_ROW_INDEX(_mat, _row)) +#define MATRIX_COL_INDEX(_mat, _col) (MATRIX_ITEM_INDEX(_mat, 0, _col)) +#define MATRIX_COL_PTR( _mat, _col) ((_mat)->matrix + MATRIX_COL_INDEX(_mat, _col)) typedef struct { - BASE_MATH_MEMBERS(contigPtr); - unsigned short row_size; - unsigned short col_size; + BASE_MATH_MEMBERS(matrix); + unsigned short num_col; + unsigned short num_row; } MatrixObject; /* struct data contains a pointer to the actual data that the @@ -66,9 +66,9 @@ typedef struct { /* prototypes */ PyObject *Matrix_CreatePyObject(float *mat, - const unsigned short row_size, const unsigned short col_size, + const unsigned short num_col, const unsigned short num_row, int type, PyTypeObject *base_type); -PyObject *Matrix_CreatePyObject_cb(PyObject *user, int row_size, int col_size, int cb_type, int cb_subtype); +PyObject *Matrix_CreatePyObject_cb(PyObject *user, int num_col, int num_row, int cb_type, int cb_subtype); extern int mathutils_matrix_vector_cb_index; extern struct Mathutils_Callback mathutils_matrix_vector_cb; diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index 7ab9b7b0713..7c339807ee9 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -35,6 +35,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_dynstr.h" #define QUAT_SIZE 4 @@ -493,6 +494,21 @@ static PyObject *Quaternion_repr(QuaternionObject *self) return ret; } +static PyObject *Quaternion_str(QuaternionObject *self) +{ + DynStr *ds; + + if (BaseMath_ReadCallback(self) == -1) + return NULL; + + ds= BLI_dynstr_new(); + + BLI_dynstr_appendf(ds, "<Quaternion (w=%.4f, x=%.4f, y=%.4f, z=%.4f)>", + self->quat[0], self->quat[1], self->quat[2], self->quat[3]); + + return mathutils_dynstr_to_py(ds); /* frees ds */ +} + static PyObject* Quaternion_richcmpr(PyObject *a, PyObject *b, int op) { PyObject *res; @@ -1167,7 +1183,7 @@ PyTypeObject quaternion_Type = { &Quaternion_AsMapping, //tp_as_mapping NULL, //tp_hash NULL, //tp_call - NULL, //tp_str + (reprfunc) Quaternion_str, //tp_str NULL, //tp_getattro NULL, //tp_setattro NULL, //tp_as_buffer diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index aedf60e7191..bd121b6177f 100644 --- a/source/blender/python/mathutils/mathutils_Vector.c +++ b/source/blender/python/mathutils/mathutils_Vector.c @@ -35,6 +35,7 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLI_dynstr.h" #define MAX_DIMENSIONS 4 @@ -1171,6 +1172,29 @@ static PyObject *Vector_repr(VectorObject *self) return ret; } +static PyObject *Vector_str(VectorObject *self) +{ + int i; + + DynStr *ds; + + if (BaseMath_ReadCallback(self) == -1) + return NULL; + + ds= BLI_dynstr_new(); + + BLI_dynstr_append(ds, "<Vector ("); + + for (i = 0; i < self->size; i++) { + BLI_dynstr_appendf(ds, i ? ", %.4f" : "%.4f", self->vec[i]); + } + + BLI_dynstr_append(ds, ")>"); + + return mathutils_dynstr_to_py(ds); /* frees ds */ +} + + /* Sequence Protocol */ /* sequence length len(vector) */ static int Vector_len(VectorObject *self) @@ -1462,14 +1486,14 @@ static PyObject *Vector_isub(PyObject *v1, PyObject *v2) * note: vector/matrix multiplication IS NOT COMMUTATIVE!!!! * note: assume read callbacks have been done first. */ -int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject* vec, MatrixObject * mat) +int column_vector_multiplication(float r_vec[MAX_DIMENSIONS], VectorObject* vec, MatrixObject * mat) { float vec_cpy[MAX_DIMENSIONS]; double dot = 0.0f; - int x, y, z = 0; + int row, col, z = 0; - if (mat->row_size != vec->size) { - if (mat->row_size == 4 && vec->size == 3) { + if (mat->num_col != vec->size) { + if (mat->num_col == 4 && vec->size == 3) { vec_cpy[3] = 1.0f; } else { @@ -1483,13 +1507,13 @@ int column_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject* vec, memcpy(vec_cpy, vec->vec, vec->size * sizeof(float)); - rvec[3] = 1.0f; + r_vec[3] = 1.0f; - for (x = 0; x < mat->col_size; x++) { - for (y = 0; y < mat->row_size; y++) { - dot += (double)(MATRIX_ITEM(mat, y, x) * vec_cpy[y]); + for (row = 0; row < mat->num_row; row++) { + for (col = 0; col < mat->num_col; col++) { + dot += (double)(MATRIX_ITEM(mat, row, col) * vec_cpy[col]); } - rvec[z++] = (float)dot; + r_vec[z++] = (float)dot; dot = 0.0f; } @@ -2589,8 +2613,8 @@ static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *v double dot = 0.0f; int x, y, z= 0, vec_size= vec->size; - if (mat->col_size != vec_size) { - if (mat->col_size == 4 && vec_size != 3) { + if (mat->num_row != vec_size) { + if (mat->num_row == 4 && vec_size != 3) { PyErr_SetString(PyExc_ValueError, "vector * matrix: matrix column size " "and the vector size must be the same"); @@ -2608,9 +2632,9 @@ static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *v rvec[3] = 1.0f; //muliplication - for (x = 0; x < mat->row_size; x++) { - for (y = 0; y < mat->col_size; y++) { - dot += MATRIX_ITEM(mat, x, y) * vec_cpy[y]; + for (x = 0; x < mat->num_col; x++) { + for (y = 0; y < mat->num_row; y++) { + dot += MATRIX_ITEM(mat, y, x) * vec_cpy[y]; } rvec[z++] = (float)dot; dot = 0.0f; @@ -2715,7 +2739,7 @@ PyTypeObject vector_Type = { NULL, /* hashfunc tp_hash; */ NULL, /* ternaryfunc tp_call; */ - NULL, /* reprfunc tp_str; */ + (reprfunc)Vector_str, /* reprfunc tp_str; */ NULL, /* getattrofunc tp_getattro; */ NULL, /* setattrofunc tp_setattro; */ diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index 2b44bad82ab..dc2de5fb450 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -190,6 +190,11 @@ void RE_engine_end_result(RenderEngine *engine, RenderResult *result) if(!result) return; + + result->tilerect.xmin += re->disprect.xmin; + result->tilerect.xmax += re->disprect.xmin; + result->tilerect.ymin += re->disprect.ymin; + result->tilerect.ymax += re->disprect.ymin; /* merge. on break, don't merge in result for preview renders, looks nicer */ if(!(re->test_break(re->tbh) && (re->r.scemode & R_PREVIEWBUTS))) diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index 883684c3483..f9992050052 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -3083,6 +3083,12 @@ void do_sky_tex(const float rco[3], float lo[3], const float dxyview[2], float h continue; } break; + case TEXCO_EQUIRECTMAP: + tempvec[0]= atan2f(lo[0], lo[2]) / (float)M_PI; + tempvec[1]= 1.0f - 2.0f*saacos(lo[1]) / (float)M_PI; + tempvec[2]= 0.0f; + co= tempvec; + break; case TEXCO_OBJECT: if(mtex->object) { copy_v3_v3(tempvec, lo); |