static void rna_FluidSettings_update_type(Main *bmain, Scene *scene, PointerRNA *ptr) { Object *ob = (Object*)ptr->id.data; FluidsimModifierData *fluidmd; ParticleSystemModifierData *psmd; ParticleSystem *psys; ParticleSettings *part; fluidmd = (FluidsimModifierData*)modifiers_findByType(ob, eModifierType_Fluidsim); fluidmd->fss->flag &= ~OB_FLUIDSIM_REVERSE; /* clear flag */ /* remove fluidsim particle system */ if (fluidmd->fss->type & OB_FLUIDSIM_PARTICLE) { for (psys = ob->particlesystem.first; psys; psys = psys->next) if (psys->part->type == PART_FLUID) break; if (ob->type == OB_MESH && !psys) { /* add particle system */ part = psys_new_settings("ParticleSettings", bmain); psys = MEM_callocN(sizeof(ParticleSystem), "particle_system"); part->type = PART_FLUID; psys->part = part; psys->pointcache = BKE_ptcache_add(&psys->ptcaches); psys->flag |= PSYS_ENABLED; BLI_strncpy(psys->name, "FluidParticles", sizeof(psys->name)); BLI_addtail(&ob->particlesystem,psys); /* add modifier */ psmd = (ParticleSystemModifierData*)modifier_new(eModifierType_ParticleSystem); BLI_strncpy(psmd->modifier.name, "FluidParticleSystem", sizeof(psmd->modifier.name)); psmd->psys = psys; BLI_addtail(&ob->modifiers, psmd); modifier_unique_name(&ob->modifiers, (ModifierData *)psmd); } } else { for (psys = ob->particlesystem.first; psys; psys = psys->next) { if (psys->part->type == PART_FLUID) { /* clear modifier */ psmd = psys_get_modifier(ob, psys); BLI_remlink(&ob->modifiers, psmd); modifier_free((ModifierData *)psmd); /* clear particle system */ BLI_remlink(&ob->particlesystem, psys); psys_free(ob, psys); } } } rna_fluid_update(bmain, scene, ptr); }
int main(int argc, char **argv) { glutInitWindowSize(800, 600); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow("libpsys example: simple"); glutDisplayFunc(disp); glutReshapeFunc(reshape); glutKeyboardFunc(keyb); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(idle); glClearColor(0.05, 0.05, 0.05, 1); if(!(tex = load_texture("pimg.png"))) { fprintf(stderr, "failed to load the texture\n"); return 1; } if(!(ps = psys_create())) { return 1; } if(psys_load_attr(&ps->attr, "simple.psys") == -1) { fprintf(stderr, "failed to load particle system definition\n"); psys_free(ps); return 1; } /*ps->attr.tex = tex; ps->attr.drag = 2; psys_set_value3(&ps->attr.grav, 0, v3_cons(0, -4, 0)); psys_set_anm_rnd(&ps->attr.life, 0, 2, 0); psys_set_value3(&ps->attr.spawn_range, 0, v3_cons(0.3, 0.3, 0.3)); psys_set_anm_rnd3(&ps->attr.dir, 0, v3_cons(0, 0, 0), v3_cons(4, 4, 4)); psys_set_value3(&ps->attr.part_attr.color, 0, v3_cons(1.0, 0.6, 0.4)); psys_set_value3(&ps->attr.part_attr.color, 1000, v3_cons(0.6, 0.3, 1.0)); psys_set_value(&ps->attr.part_attr.alpha, 0, 1); psys_set_value(&ps->attr.part_attr.alpha, 700, 1); psys_set_value(&ps->attr.part_attr.alpha, 1000, 0);*/ assert(glGetError() == GL_NO_ERROR); atexit(cleanup); glutMainLoop(); return 0; }
static int object_modifier_remove(Object *ob, ModifierData *md, int *sort_depsgraph) { ModifierData *obmd; /* It seems on rapid delete it is possible to * get called twice on same modifier, so make * sure it is in list. */ for(obmd=ob->modifiers.first; obmd; obmd=obmd->next) if(obmd==md) break; if(!obmd) return 0; /* special cases */ if(md->type == eModifierType_ParticleSystem) { ParticleSystemModifierData *psmd=(ParticleSystemModifierData*)md; BLI_remlink(&ob->particlesystem, psmd->psys); psys_free(ob, psmd->psys); psmd->psys= NULL; } else if(md->type == eModifierType_Softbody) { if(ob->soft) { sbFree(ob->soft); ob->soft= NULL; ob->softflag= 0; } } else if(md->type == eModifierType_Collision) { if(ob->pd) ob->pd->deflect= 0; *sort_depsgraph = 1; } else if(md->type == eModifierType_Surface) { if(ob->pd && ob->pd->shape == PFIELD_SHAPE_SURFACE) ob->pd->shape = PFIELD_SHAPE_PLANE; *sort_depsgraph = 1; } else if(md->type == eModifierType_Smoke) { ob->dt = OB_TEXTURE; } else if(md->type == eModifierType_Multires) { int ok= 1; Mesh *me= ob->data; ModifierData *tmpmd; /* ensure MDISPS CustomData layer is't used by another multires modifiers */ for(tmpmd= ob->modifiers.first; tmpmd; tmpmd= tmpmd->next) if(tmpmd!=md && tmpmd->type == eModifierType_Multires) { ok= 0; break; } if(ok) { if(me->edit_mesh) { EditMesh *em= me->edit_mesh; /* CustomData_external_remove is used here only to mark layer as non-external for further free-ing, so zero element count looks safer than em->totface */ CustomData_external_remove(&em->fdata, &me->id, CD_MDISPS, 0); EM_free_data_layer(em, &em->fdata, CD_MDISPS); } else { CustomData_external_remove(&me->fdata, &me->id, CD_MDISPS, me->totface); CustomData_free_layer_active(&me->fdata, CD_MDISPS, me->totface); } } } if(ELEM(md->type, eModifierType_Softbody, eModifierType_Cloth) && ob->particlesystem.first == NULL) { ob->mode &= ~OB_MODE_PARTICLE_EDIT; } BLI_remlink(&ob->modifiers, md); modifier_free(md); return 1; }
void BKE_object_handle_data_update(EvaluationContext *eval_ctx, Scene *scene, Object *ob) { ID *data_id = (ID *)ob->data; AnimData *adt = BKE_animdata_from_id(data_id); Key *key; float ctime = BKE_scene_frame_get(scene); if (G.debug & G_DEBUG_DEPSGRAPH) printf("recalcdata %s\n", ob->id.name + 2); /* TODO(sergey): Only used by legacy depsgraph. */ if (adt) { /* evaluate drivers - datalevel */ /* XXX: for mesh types, should we push this to derivedmesh instead? */ BKE_animsys_evaluate_animdata(scene, data_id, adt, ctime, ADT_RECALC_DRIVERS); } /* TODO(sergey): Only used by legacy depsgraph. */ key = BKE_key_from_object(ob); if (key && key->block.first) { if (!(ob->shapeflag & OB_SHAPE_LOCK)) BKE_animsys_evaluate_animdata(scene, &key->id, key->adt, ctime, ADT_RECALC_DRIVERS); } /* includes all keys and modifiers */ switch (ob->type) { case OB_MESH: { BMEditMesh *em = (ob == scene->obedit) ? BKE_editmesh_from_object(ob) : NULL; uint64_t data_mask = scene->customdata_mask | CD_MASK_BAREMESH; #ifdef WITH_FREESTYLE /* make sure Freestyle edge/face marks appear in DM for render (see T40315) */ if (eval_ctx->mode != DAG_EVAL_VIEWPORT) { data_mask |= CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE; } #endif if (em) { makeDerivedMesh(scene, ob, em, data_mask, false); /* was CD_MASK_BAREMESH */ } else { makeDerivedMesh(scene, ob, NULL, data_mask, false); } break; } case OB_ARMATURE: if (ob->id.lib && ob->proxy_from) { if (BKE_pose_copy_result(ob->pose, ob->proxy_from->pose) == false) { printf("Proxy copy error, lib Object: %s proxy Object: %s\n", ob->id.name + 2, ob->proxy_from->id.name + 2); } } else { BKE_pose_where_is(scene, ob); } break; case OB_MBALL: BKE_displist_make_mball(eval_ctx, scene, ob); break; case OB_CURVE: case OB_SURF: case OB_FONT: BKE_displist_make_curveTypes(scene, ob, 0); break; case OB_LATTICE: BKE_lattice_modifiers_calc(scene, ob); break; case OB_EMPTY: if (ob->empty_drawtype == OB_EMPTY_IMAGE && ob->data) if (BKE_image_is_animated(ob->data)) BKE_image_user_check_frame_calc(ob->iuser, (int)ctime, 0); break; } /* related materials */ /* XXX: without depsgraph tagging, this will always need to be run, which will be slow! * However, not doing anything (or trying to hack around this lack) is not an option * anymore, especially due to Cycles [#31834] */ if (ob->totcol) { int a; if (ob->totcol != 0) { BLI_mutex_lock(&material_lock); for (a = 1; a <= ob->totcol; a++) { Material *ma = give_current_material(ob, a); if (ma) { /* recursively update drivers for this material */ material_drivers_update(scene, ma, ctime); } } BLI_mutex_unlock(&material_lock); } } else if (ob->type == OB_LAMP) lamp_drivers_update(scene, ob->data, ctime); /* particles */ if (ob != scene->obedit && ob->particlesystem.first) { ParticleSystem *tpsys, *psys; DerivedMesh *dm; ob->transflag &= ~OB_DUPLIPARTS; psys = ob->particlesystem.first; while (psys) { /* ensure this update always happens even if psys is disabled */ if (psys->recalc & PSYS_RECALC_TYPE) { psys_changed_type(ob, psys); } if (psys_check_enabled(ob, psys)) { /* check use of dupli objects here */ if (psys->part && (psys->part->draw_as == PART_DRAW_REND || eval_ctx->mode == DAG_EVAL_RENDER) && ((psys->part->ren_as == PART_DRAW_OB && psys->part->dup_ob) || (psys->part->ren_as == PART_DRAW_GR && psys->part->dup_group))) { ob->transflag |= OB_DUPLIPARTS; } particle_system_update(scene, ob, psys); psys = psys->next; } else if (psys->flag & PSYS_DELETE) { tpsys = psys->next; BLI_remlink(&ob->particlesystem, psys); psys_free(ob, psys); psys = tpsys; } else psys = psys->next; } if (eval_ctx->mode == DAG_EVAL_RENDER && ob->transflag & OB_DUPLIPARTS) { /* this is to make sure we get render level duplis in groups: * the derivedmesh must be created before init_render_mesh, * since object_duplilist does dupliparticles before that */ CustomDataMask data_mask = CD_MASK_BAREMESH | CD_MASK_MFACE | CD_MASK_MTFACE | CD_MASK_MCOL; dm = mesh_create_derived_render(scene, ob, data_mask); dm->release(dm); for (psys = ob->particlesystem.first; psys; psys = psys->next) psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated; } } /* quick cache removed */ }
void cleanup(void) { psys_free(ps); }
int ED_object_modifier_remove(ReportList *reports, Main *bmain, Scene *scene, Object *ob, ModifierData *md) { ModifierData *obmd; int sort_depsgraph = 0; /* It seems on rapid delete it is possible to * get called twice on same modifier, so make * sure it is in list. */ for(obmd=ob->modifiers.first; obmd; obmd=obmd->next) if(obmd==md) break; if(!obmd) { BKE_reportf(reports, RPT_ERROR, "Modifier '%s' not in object '%s'", ob->id.name, md->name); return 0; } /* special cases */ if(md->type == eModifierType_ParticleSystem) { ParticleSystemModifierData *psmd=(ParticleSystemModifierData*)md; BLI_remlink(&ob->particlesystem, psmd->psys); psys_free(ob, psmd->psys); psmd->psys= NULL; } else if(md->type == eModifierType_Softbody) { if(ob->soft) { sbFree(ob->soft); ob->soft= NULL; ob->softflag= 0; } } else if(md->type == eModifierType_Collision) { if(ob->pd) ob->pd->deflect= 0; sort_depsgraph = 1; } else if(md->type == eModifierType_Surface) { if(ob->pd && ob->pd->shape == PFIELD_SHAPE_SURFACE) ob->pd->shape = PFIELD_SHAPE_PLANE; sort_depsgraph = 1; } else if(md->type == eModifierType_Smoke) { ob->dt = OB_TEXTURE; } else if(md->type == eModifierType_Multires) { int ok= 1; Mesh *me= ob->data; ModifierData *tmpmd; /* ensure MDISPS CustomData layer is't used by another multires modifiers */ for(tmpmd= ob->modifiers.first; tmpmd; tmpmd= tmpmd->next) if(tmpmd!=md && tmpmd->type == eModifierType_Multires) { ok= 0; break; } if(ok) { if(me->edit_mesh) { EditMesh *em= me->edit_mesh; /* CustomData_external_remove is used here only to mark layer as non-external for further free-ing, so zero element count looks safer than em->totface */ CustomData_external_remove(&em->fdata, &me->id, CD_MDISPS, 0); EM_free_data_layer(em, &em->fdata, CD_MDISPS); } else { CustomData_external_remove(&me->fdata, &me->id, CD_MDISPS, me->totface); CustomData_free_layer_active(&me->fdata, CD_MDISPS, me->totface); } } } if(ELEM(md->type, eModifierType_Softbody, eModifierType_Cloth) && ob->particlesystem.first == NULL) { ob->mode &= ~OB_MODE_PARTICLE_EDIT; } BLI_remlink(&ob->modifiers, md); modifier_free(md); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sorting has to be done after the update so that dynamic systems can react properly */ if(sort_depsgraph) DAG_scene_sort(bmain, scene); return 1; }