diff options
Diffstat (limited to 'source/blender/src/buttons_object.c')
-rw-r--r-- | source/blender/src/buttons_object.c | 415 |
1 files changed, 414 insertions, 1 deletions
diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c index 7ed33998dc6..b6d7d4afd5c 100644 --- a/source/blender/src/buttons_object.c +++ b/source/blender/src/buttons_object.c @@ -47,6 +47,7 @@ #include "DNA_scene_types.h" #include "BKE_action.h" +#include "BKE_cloth.h" #include "BKE_global.h" #include "BKE_main.h" #include "BKE_library.h" @@ -89,6 +90,7 @@ #include "DNA_action_types.h" #include "DNA_armature_types.h" #include "DNA_camera_types.h" +#include "DNA_cloth_types.h" #include "DNA_constraint_types.h" #include "DNA_curve_types.h" #include "DNA_effect_types.h" @@ -2351,6 +2353,78 @@ void do_object_panels(unsigned short event) if(ob->ipo) ob->ipo->showkey= (ob->ipoflag & OB_DRAWKEY)?1:0; allqueue(REDRAWVIEW3D, 0); break; + case B_CLOTH_CLEARCACHEALL: + { + ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth); + if(clmd) + { + // do nothing in editmode + if(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_EDITMODE) + break; + + /* force freeing because user wants */ + clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE; + + /*user wants to free all, so free whole cloth, this helps to start sim at later frame */ + clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_RESET; + + CFRA= 1; + update_for_newframe_muted(); + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + cloth_clear_cache(ob, clmd, 0); + allqueue(REDRAWBUTSOBJECT, 0); + allqueue(REDRAWVIEW3D, 0); + } + } + break; + case B_CLOTH_CLEARCACHEFRAME: + { + ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth); + if(clmd) + { + // do nothing in editmode + if(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_EDITMODE) + break; + + /* force freeing because user wants */ + clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_CCACHE_FFREE; + + cloth_clear_cache(ob, clmd, MAX2(0.0,G.scene->r.cfra)); + // MAX2(1.0,G.scene->r.cfra + 1.0) + allqueue(REDRAWBUTSOBJECT, 0); + } + } + break; + case B_CLOTH_CHANGEPREROLL: + { + ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth); + if(clmd) + { + // do nothing in editmode + if(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_EDITMODE) + break; + + CFRA= 1; + update_for_newframe_muted(); + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + allqueue(REDRAWBUTSOBJECT, 0); + allqueue(REDRAWVIEW3D, 0); + } + } + break; + case B_CLOTH_RENEW: + { + ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth); + + if(clmd) + { + clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_RESET; + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + allqueue(REDRAWBUTSOBJECT, 0); + allqueue(REDRAWVIEW3D, 0); + } + } + break; default: if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) { @@ -3168,10 +3242,34 @@ static void field_testTexture(char *name, ID **idpp) } *idpp = 0; } + +/* Panel for collision */ +static void object_collision__enabletoggle ( void *ob_v, void *arg2 ) +{ + Object *ob = ob_v; + ModifierData *md = modifiers_findByType ( ob, eModifierType_Collision ); + + if ( !md ) + { + md = modifier_new ( eModifierType_Collision ); + BLI_addhead ( &ob->modifiers, md ); + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + allqueue(REDRAWBUTSEDIT, 0); + allqueue(REDRAWVIEW3D, 0); + } + else + { + BLI_remlink ( &ob->modifiers, md ); + modifier_free ( md ); + allqueue(REDRAWBUTSEDIT, 0); + } +} + /* Panels for particle interaction settings */ static void object_panel_deflection(Object *ob) { uiBlock *block; + uiBut *but; block= uiNewBlock(&curarea->uiblocks, "object_panel_deflection", UI_EMBOSS, UI_HELV, curarea->win); if(uiNewPanel(curarea, block, "Deflection", "Physics", 0, 0, 318, 204)==0) return; @@ -3191,7 +3289,9 @@ static void object_panel_deflection(Object *ob) if(ob->pd && ob->type==OB_MESH) { PartDeflect *pd= ob->pd; - uiDefButBitS(block, TOG, 1, B_REDR, "Deflection",160,160,150,20, &pd->deflect, 0, 0, 0, 0, "Deflects particles based on collision"); + but = uiDefButBitS(block, TOG, 1, B_REDR, "Deflection",160,160,150,20, &pd->deflect, 0, 0, 0, 0, "Deflects particles based on collision"); + uiButSetFunc(but, object_collision__enabletoggle, ob, NULL); + if(pd->deflect) { uiDefBut(block, LABEL, 0, "Particles", 160,140,75,20, NULL, 0.0, 0, 0, 0, ""); uiDefButBitS(block, TOG, PDEFLE_KILL_PART, B_DIFF, "Kill",235,140,75,20, &pd->flag, 0, 0, 0, 0, "Kill collided particles"); @@ -4961,6 +5061,316 @@ errMessage: #endif // DISABLE_ELBEEM } +/* Panel for cloth */ +static void object_cloth__enabletoggle(void *ob_v, void *arg2) +{ + Object *ob = ob_v; + ModifierData *md = modifiers_findByType(ob, eModifierType_Cloth); + + if (!md) { + md = modifier_new(eModifierType_Cloth); + BLI_addhead(&ob->modifiers, md); + + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + allqueue(REDRAWBUTSEDIT, 0); + allqueue(REDRAWVIEW3D, 0); + } + else { + Object *ob = ob_v; + ModifierData *md = modifiers_findByType(ob, eModifierType_Cloth); + + if (!md) + return; + + BLI_remlink(&ob->modifiers, md); + + modifier_free(md); + + BIF_undo_push("Del modifier"); + + ob->softflag |= OB_SB_RESET; + allqueue(REDRAWBUTSEDIT, 0); + allqueue(REDRAWVIEW3D, 0); + allqueue(REDRAWIMAGE, 0); + allqueue(REDRAWOOPS, 0); + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + object_handle_update(ob); + countall(); + } +} + + +static void object_panel_cloth(Object *ob) +{ + uiBlock *block; + uiBut *but; + static int val, val2; + ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth); + + block= uiNewBlock(&curarea->uiblocks, "object_cloth", UI_EMBOSS, UI_HELV, curarea->win); + if(uiNewPanel(curarea, block, "Cloth ", "Physics", 640, 0, 318, 204)==0) return; + uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE); + + val = (clmd ? 1:0); + + but = uiDefButI(block, TOG, REDRAWBUTSOBJECT, "Cloth", 10,200,130,20, &val, 0, 0, 0, 0, "Sets object to become cloth"); + + uiButSetFunc(but, object_cloth__enabletoggle, ob, NULL); + uiDefBut(block, LABEL, 0, "",10,10,300,0, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/ + + if(clmd) + { + int defCount; + char *clvg1, *clvg2; + char clmvg [] = "Vertex Groups%t|"; + + val2=0; + + /* GENERAL STUFF */ + uiClearButLock(); + uiBlockBeginAlign(block); + uiDefButF(block, NUM, B_CLOTH_RENEW, "StructStiff:", 10,170,150,20, &clmd->sim_parms->structural, 1.0, 10000.0, 100, 0, "Overall stiffness of structure"); + uiDefButF(block, NUM, B_CLOTH_RENEW, "BendStiff:", 160,170,150,20, &clmd->sim_parms->bending, 0.0, 10000.0, 1000, 0, "Wrinkle coefficient (higher = less smaller but more big wrinkles)"); + uiDefButI(block, NUM, B_CLOTH_RENEW, "Quality:", 10,150,150,20, &clmd->sim_parms->stepsPerFrame, 4.0, 100.0, 5, 0, "Quality of the simulation (higher=better=slower)"); + + uiDefButF(block, NUM, B_CLOTH_RENEW, "Spring Damp:", 160,150,150,20, &clmd->sim_parms->Cdis, 0.0, 10.0, 10, 0, "Spring damping"); + uiDefButF(block, NUM, B_DIFF, "Air Damp:", 10,130,150,20, &clmd->sim_parms->Cvi, 0.0, 10.0, 10, 0, "Air has normaly some thickness which slows falling things down"); + + uiDefBut(block, LABEL, 0, "Gravity:", 10,100,60,20, NULL, 0.0, 0, 0, 0, ""); + + uiDefButF(block, NUM, B_CLOTH_RENEW, "X:", 70,100,80,20, &clmd->sim_parms->gravity[0], -100.0, 100.0, 10, 0, "Apply gravitation to point movement"); + uiDefButF(block, NUM, B_CLOTH_RENEW, "Y:", 150,100,80,20, &clmd->sim_parms->gravity[1], -100.0, 100.0, 10, 0, "Apply gravitation to point movement"); + uiDefButF(block, NUM, B_CLOTH_RENEW, "Z:", 230,100,80,20, &clmd->sim_parms->gravity[2], -100.0, 100.0, 10, 0, "Apply gravitation to point movement"); + uiBlockEndAlign(block); + + /* GOAL STUFF */ + uiBlockBeginAlign(block); + + + uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_GOAL, B_CLOTH_RENEW, "Pinning of cloth", 10,70,150,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "Define forces for vertices to stick to animated position"); + + if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) && (BLI_countlist (&ob->defbase) > 0)) + { + if(ob->type==OB_MESH) + { + + defCount = sizeof (clmvg); + clvg1 = get_vertexgroup_menustr (ob); + clvg2 = MEM_callocN (strlen (clvg1) + 1 + defCount, "clothVgMS"); + if (! clvg2) { + printf ("draw_modifier: error allocating memory for cloth vertex group menu string.\n"); + return; + } + defCount = BLI_countlist (&ob->defbase); + if (defCount == 0) + { + clmd->sim_parms->vgroup_mass = 0; + } + else + { + if(!clmd->sim_parms->vgroup_mass) + clmd->sim_parms->vgroup_mass = 1; + else if(clmd->sim_parms->vgroup_mass > defCount) + clmd->sim_parms->vgroup_mass = defCount; + } + + sprintf (clvg2, "%s%s", clmvg, clvg1); + + uiDefButS(block, MENU, B_CLOTH_RENEW, clvg2, 160,70,150,20, &clmd->sim_parms->vgroup_mass, 0, defCount, 0, 0, "Browses available vertex groups"); + MEM_freeN (clvg1); + MEM_freeN (clvg2); + } + + uiDefButF(block, NUM, B_CLOTH_RENEW, "Pin Stiff:", 10,50,150,20, &clmd->sim_parms->goalspring, 0.0, 500.0, 10, 0, "Pin (vertex target position) spring stiffness"); + uiDefBut(block, LABEL, 0, " ", 160,50,150,20, NULL, 0.0, 0, 0, 0, ""); + /* + // nobody is changing these ones anyway + uiDefButF(block, NUM, B_CLOTH_RENEW, "G Damp:", 160,50,150,20, &clmd->sim_parms->goalfrict , 0.0, 50.0, 10, 0, "Goal (vertex target position) friction"); + uiDefButF(block, NUM, B_CLOTH_RENEW, "G Min:", 10,30,150,20, &clmd->sim_parms->mingoal, 0.0, 1.0, 10, 0, "Goal minimum, vertex group weights are scaled to match this range"); + uiDefButF(block, NUM, B_CLOTH_RENEW, "G Max:", 160,30,150,20, &clmd->sim_parms->maxgoal, 0.0, 1.0, 10, 0, "Goal maximum, vertex group weights are scaled to match this range"); + */ + } + else if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) + { + uiDefBut(block, LABEL, 0, " ", 160,70,150,20, NULL, 0.0, 0, 0, 0, ""); + uiDefBut(block, LABEL, 0, "No vertex group for pinning available.", 10,50,300,20, NULL, 0.0, 0, 0, 0, ""); + } + + uiBlockEndAlign(block); + + /* + // no tearing supported anymore since modifier stack restrictions + uiBlockBeginAlign(block); + uiDefButBitI(block, TOG, CSIMSETT_FLAG_TEARING_ENABLED, B_EFFECT_DEP, "Tearing", 10,0,150,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "Sets object to become a cloth collision object"); + + if (clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED) + { + uiDefButI(block, NUM, B_DIFF, "Max extent:", 160,0,150,20, &clmd->sim_parms->maxspringlen, 1.0, 1000.0, 10, 0, "Maximum extension before spring gets cut"); + } + + uiBlockEndAlign(block); + */ + } + + uiBlockEndAlign(block); + + uiBlockEndAlign(block); +} + +static void object_panel_cloth_II(Object *ob) +{ + uiBlock *block; + ClothModifierData *clmd = NULL; + + block= uiNewBlock(&curarea->uiblocks, "object_cloth_II", UI_EMBOSS, UI_HELV, curarea->win); + uiNewPanelTabbed("Cloth ", "Physics"); + if(uiNewPanel(curarea, block, "Cloth Cache/Collisions", "Physics", 651, 0, 318, 204)==0) return; + + uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE); + + clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth); + + if(clmd) + { + uiDefButI(block, NUM, B_CLOTH_RENEW, "First Frame:",10,160,150,20, &clmd->sim_parms->firstframe, 0, MAXFRAME, 1, 0, "Frame on which the simulation starts"); + uiDefButI(block, NUM, B_CLOTH_RENEW, "Last Frame:",160,160,150,20, &clmd->sim_parms->lastframe, 0, MAXFRAME, 1, 0, "Frame on which the simulation stops"); + + uiDefBut(block, LABEL, 0, "",10,140,300,20, NULL, 0.0, 0, 0, 0, ""); + + if (!G.relbase_valid) + { + uiDefBut(block, LABEL, 0, "Cache deactivated until file is saved.", 10,120,300,20, NULL, 0.0, 0, 0, 0, ""); + uiDefBut(block, LABEL, 0, " ", 10,100,300,40, NULL, 0.0, 0, 0, 0, ""); + } + else + { + uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT, REDRAWVIEW3D, "Protect Cache & Enable Cache Editing", 10,120,300,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "Protect cache from automatic freeing when scene changed. This also enabled the cache beeing edited in editmode."); + + uiDefBut(block, LABEL, 0, "Clear cache:", 10,100,90,20, NULL, 0.0, 0, 0, 0, ""); + uiDefBut(block, BUT, B_CLOTH_CLEARCACHEALL, "All", 100, 100,100,20, NULL, 0.0, 0.0, 10, 0, "Free ALL cloth cache without preroll"); + uiDefBut(block, BUT, B_CLOTH_CLEARCACHEFRAME, "From next frame", 200, 100,110,20, NULL, 0.0, 0.0, 10, 0, "Free cloth cache starting from next frame"); + uiDefBut(block, LABEL, 0, " ", 10,80,300,20, NULL, 0.0, 0, 0, 0, ""); + } + + /* + TODO: implement this again in cloth! + if(length>1) // B_CLOTH_CHANGEPREROLL + uiDefButI(block, NUM, B_CLOTH_CHANGEPREROLL, "Preroll:", 10,80,145,20, &clmd->sim_parms->preroll, 0, length-1, 1, 0, "Simulation starts on this frame"); + else + uiDefBut(block, LABEL, 0, " ", 10,80,145,20, NULL, 0.0, 0, 0, 0, ""); + */ + + uiDefButBitI(block, TOG, CLOTH_COLLSETTINGS_FLAG_ENABLED, B_CLOTH_RENEW, "Enable collisions", 10,60,150,20, &clmd->coll_parms->flags, 0, 0, 0, 0, "Enable collisions with this object"); + if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED) + { + uiDefButF(block, NUM, REDRAWBUTSOBJECT, "Min Distance:", 160,60,150,20, &clmd->coll_parms->epsilon, 0.001f, 1.0, 0.01f, 0, "Minimum distance between collision objects before collision response takes in, can be changed for each frame"); + uiDefButS(block, NUM, REDRAWBUTSOBJECT, "Collision Quality:", 10,40,150,20, &clmd->coll_parms->loop_count, 1.0, 100.0, 1.0, 0, "How many collision iterations should be done. (higher = better = slower), can be changed for each frame"); + uiDefButF(block, NUM, REDRAWBUTSOBJECT, "Friction:", 160,40,150,20, &clmd->coll_parms->friction, 1.0, 100.0, 1.0, 0, "Friction force if a collision happened"); + } + else + uiDefBut(block, LABEL, 0, "",160,60,150,20, NULL, 0.0, 0, 0, 0, ""); + } + + uiBlockEndAlign(block); + +} + +static void object_panel_cloth_III(Object *ob) +{ + uiBlock *block; + ClothModifierData *clmd = NULL; + + block= uiNewBlock(&curarea->uiblocks, "object_cloth_III", UI_EMBOSS, UI_HELV, curarea->win); + uiNewPanelTabbed("Cloth ", "Physics"); + if(uiNewPanel(curarea, block, "Cloth Advanced", "Physics", 651, 0, 318, 204)==0) return; + + uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE); + + clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth); + + if(clmd) + { + int defCount; + char *clvg1, *clvg2; + char clmvg [] = "Vertex Groups%t|None%x0|"; + char clmvg2 [] = "Vertex Groups%t|None%x0|"; + + uiDefButI(block, NUM, B_DIFF, "Autoprotect Cache From:",10,160,300,20, &clmd->sim_parms->autoprotect, 0.0, MAXFRAME + 1, 1, 0, "Frame on which the simulation gets cache protection enabled automatically (To prevent accidently cleaning it)."); + + uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_SCALING, B_CLOTH_RENEW, "Enable stiffness scaling",10,130,300,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "If enabled, stiffness can be scaled along a weight painted vertex group."); + + if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING)&& (BLI_countlist (&ob->defbase) > 0)) + { + uiDefBut(block, LABEL, 0, "StructStiff VGroup:",10,110,150,20, NULL, 0.0, 0, 0, 0, ""); + uiDefBut(block, LABEL, 0, "BendStiff VGroup:",160,110,150,20, NULL, 0.0, 0, 0, 0, ""); + + defCount = sizeof (clmvg); + clvg1 = get_vertexgroup_menustr (ob); + clvg2 = MEM_callocN (strlen (clvg1) + 1 + defCount, "clothVgST"); + if (! clvg2) { + printf ("draw_modifier: error allocating memory for cloth vertex group menu string.\n"); + return; + } + defCount = BLI_countlist (&ob->defbase); + if (defCount == 0) + { + clmd->sim_parms->vgroup_struct = 0; + } + else + { + if(clmd->sim_parms->vgroup_struct > defCount) + clmd->sim_parms->vgroup_struct = 0; + } + + sprintf (clvg2, "%s%s", clmvg, clvg1); + + uiDefButS(block, MENU, B_CLOTH_RENEW, clvg2, 10,90,150,20, &clmd->sim_parms->vgroup_struct, 0, defCount, 0, 0, "Browses available vertex groups"); + MEM_freeN (clvg1); + MEM_freeN (clvg2); + + defCount = sizeof (clmvg); + clvg1 = get_vertexgroup_menustr (ob); + clvg2 = MEM_callocN (strlen (clvg1) + 1 + defCount, "clothVgBD"); + if (! clvg2) { + printf ("draw_modifier: error allocating memory for cloth vertex group menu string.\n"); + return; + } + defCount = BLI_countlist (&ob->defbase); + if (defCount == 0) + { + clmd->sim_parms->vgroup_bend = 0; + } + else + { + if(clmd->sim_parms->vgroup_bend > defCount) + clmd->sim_parms->vgroup_bend = 0; + } + + sprintf (clvg2, "%s%s", clmvg2, clvg1); + + uiDefButS(block, MENU, B_CLOTH_RENEW, clvg2, 160,90,150,20, &clmd->sim_parms->vgroup_bend, 0, defCount, 0, 0, "Browses available vertex groups"); + MEM_freeN (clvg1); + MEM_freeN (clvg2); + + uiDefButF(block, NUM, B_CLOTH_RENEW, "StructStiff Max:",10,70,150,20, &clmd->sim_parms->max_struct, clmd->sim_parms->structural, 10000.0, 0.01f, 0, "Maximum structural stiffness value"); + + uiDefButF(block, NUM, B_CLOTH_RENEW, "BendStiff Max:",160,70,150,20, &clmd->sim_parms->max_bend, clmd->sim_parms->bending, 10000.0, 0.01f, 0, "Maximum bending stiffness value"); + + } + else if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING) + { + uiDefBut(block, LABEL, 0, " ", 10,110,300,20, NULL, 0.0, 0, 0, 0, ""); + uiDefBut(block, LABEL, 0, "No vertex group for pinning available.", 10,90,300,20, NULL, 0.0, 0, 0, 0, ""); + } + + + + } + + uiBlockEndAlign(block); + +} + void object_panels() { Object *ob; @@ -4990,6 +5400,9 @@ void physics_panels() object_softbodies(ob); object_softbodies_collision(ob); object_softbodies_solver(ob); + object_panel_cloth(ob); + object_panel_cloth_II(ob); + object_panel_cloth_III(ob); object_panel_fluidsim(ob); } } |