int sculpt_get_first_deform_matrices(Scene *scene, Object *ob, float (**deformmats)[3][3], float (**deformcos)[3]) { ModifierData *md; DerivedMesh *dm; int a, numVerts= 0; float (*defmats)[3][3]= NULL, (*deformedVerts)[3]= NULL; MultiresModifierData *mmd= get_multires_modifier(scene, ob, 0); int has_multires = mmd != NULL && mmd->sculptlvl > 0; int numleft= 0; if(has_multires) { *deformmats= NULL; *deformcos= NULL; return numleft; } dm= NULL; md= modifiers_getVirtualModifierList(ob); for(; md; md= md->next) { ModifierTypeInfo *mti= modifierType_getInfo(md->type); if(!modifier_isEnabled(scene, md, eModifierMode_Realtime)) continue; if(mti->type==eModifierTypeType_OnlyDeform) { if(!defmats) { Mesh *me= (Mesh*)ob->data; dm= mesh_create_derived(me, ob, NULL); deformedVerts= mesh_getVertexCos(me, &numVerts); defmats= MEM_callocN(sizeof(*defmats)*numVerts, "defmats"); for(a=0; a<numVerts; a++) unit_m3(defmats[a]); } if(mti->deformMatrices) mti->deformMatrices(md, ob, dm, deformedVerts, defmats, numVerts); else break; } } for(; md; md= md->next) { ModifierTypeInfo *mti= modifierType_getInfo(md->type); if(!modifier_isEnabled(scene, md, eModifierMode_Realtime)) continue; if(mti->type==eModifierTypeType_OnlyDeform) numleft++; } if(dm) dm->release(dm); *deformmats= defmats; *deformcos= deformedVerts; return numleft; }
static int multiresbake_check(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); Object *ob; Mesh *me; MultiresModifierData *mmd; int ok= 1, a; CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) { ob= base->object; if(ob->type != OB_MESH) { BKE_report(op->reports, RPT_ERROR, "Basking of multires data only works with active object which is a mesh"); ok= 0; break; } me= (Mesh*)ob->data; mmd= get_multires_modifier(scene, ob, 0); /* Multi-resolution should be and be last in the stack */ if(ok && mmd) { ModifierData *md; ok= mmd->totlvl>0; for(md = (ModifierData*)mmd->modifier.next; md && ok; md = md->next) { if (modifier_isEnabled(scene, md, eModifierMode_Realtime)) { ok= 0; } } } else ok= 0; if(!ok) { BKE_report(op->reports, RPT_ERROR, "Multires data baking requires multi-resolution object"); break; } if(!me->mtface) { BKE_report(op->reports, RPT_ERROR, "Mesh should be unwrapped before multires data baking"); ok= 0; } else { a= me->totface; while (ok && a--) { Image *ima= me->mtface[a].tpage; if(!ima) { BKE_report(op->reports, RPT_ERROR, "You should have active texture to use multires baker"); ok= 0; } else { ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); if(!ibuf) { BKE_report(op->reports, RPT_ERROR, "Baking should happend to image with image buffer"); ok= 0; } else { if(ibuf->rect==NULL && ibuf->rect_float==NULL) ok= 0; if(ibuf->rect_float && !(ibuf->channels==0 || ibuf->channels==4)) ok= 0; if(!ok) BKE_report(op->reports, RPT_ERROR, "Baking to unsupported image type"); } } } } if(!ok) break; }