Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_convert_particle.c
| Show All 30 Lines | |||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_particle.h" | #include "BKE_particle.h" | ||||
| #include "BKE_pointcache.h" | #include "BKE_pointcache.h" | ||||
| #include "ED_particle.h" | #include "ED_particle.h" | ||||
| #include "transform.h" | #include "transform.h" | ||||
| #include "transform_convert.h" | #include "transform_convert.h" | ||||
| #include "transform_data.h" | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Particle Edit Transform Creation | /** \name Particle Edit Transform Creation | ||||
| * | * | ||||
| * \{ */ | * \{ */ | ||||
| void createTransParticleVerts(bContext *C, TransInfo *t) | void createTransParticleVerts(bContext *C, TransInfo *t) | ||||
| { | { | ||||
| FOREACH_TRANS_DATA_CONTAINER (t, tc) { | FOREACH_TRANS_DATA_CONTAINER (t, tc) { | ||||
| TransDataExtension *tx = NULL; | |||||
| TransData *td = NULL; | |||||
| TransDataExtension *tx; | |||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| ParticleEditSettings *pset = PE_settings(t->scene); | ParticleEditSettings *pset = PE_settings(t->scene); | ||||
| PTCacheEdit *edit = PE_get_current(t->depsgraph, t->scene, ob); | PTCacheEdit *edit = PE_get_current(t->depsgraph, t->scene, ob); | ||||
| ParticleSystem *psys = NULL; | ParticleSystem *psys = NULL; | ||||
| PTCacheEditPoint *point; | PTCacheEditPoint *point; | ||||
| PTCacheEditKey *key; | PTCacheEditKey *key; | ||||
| float mat[4][4]; | float mat[4][4]; | ||||
| int i, k, transformparticle; | int i, k, transformparticle; | ||||
| Show All 30 Lines | for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) { | ||||
| } | } | ||||
| } | } | ||||
| /* note: in prop mode we need at least 1 selected */ | /* note: in prop mode we need at least 1 selected */ | ||||
| if (hasselected == 0) { | if (hasselected == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| tc->data_len = count; | TransData *td; | ||||
| td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Particle Mode)"); | |||||
| if (t->mode == TFM_BAKE_TIME) { | if (t->mode == TFM_BAKE_TIME) { | ||||
| tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), | td = tc->data = transform_data_alloc(tc->data_len, TD_ALL_COMP); | ||||
| "Particle_TransExtension"); | tx = &td->ext[0]; | ||||
| } | } | ||||
| else { | else { | ||||
| tx = tc->data_ext = NULL; | td = tc->data = transform_data_alloc(tc->data_len, TD_BASIC_COMP); | ||||
| } | } | ||||
| unit_m4(mat); | unit_m4(mat); | ||||
| invert_m4_m4(ob->imat, ob->obmat); | invert_m4_m4(ob->imat, ob->obmat); | ||||
| int tdi = 0; | |||||
| for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) { | for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) { | ||||
| TransData *head, *tail; | int head, tail; | ||||
| head = tail = td; | head = tail = tdi; | ||||
| if (!(point->flag & PEP_TRANSFORM)) { | if (!(point->flag & PEP_TRANSFORM)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { | if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { | ||||
| ParticleSystemModifierData *psmd_eval = edit->psmd_eval; | ParticleSystemModifierData *psmd_eval = edit->psmd_eval; | ||||
| psys_mat_hair_to_global( | psys_mat_hair_to_global( | ||||
| ob, psmd_eval->mesh_final, psys->part->from, psys->particles + i, mat); | ob, psmd_eval->mesh_final, psys->part->from, psys->particles + i, mat); | ||||
| } | } | ||||
| for (k = 0, key = point->keys; k < point->totkey; k++, key++) { | for (k = 0, key = point->keys; k < point->totkey; k++, key++) { | ||||
| if (key->flag & PEK_USE_WCO) { | if (key->flag & PEK_USE_WCO) { | ||||
| copy_v3_v3(key->world_co, key->co); | copy_v3_v3(key->world_co, key->co); | ||||
| mul_m4_v3(mat, key->world_co); | mul_m4_v3(mat, key->world_co); | ||||
| td->loc = key->world_co; | td->basic[tdi].loc = key->world_co; | ||||
| } | } | ||||
| else { | else { | ||||
| td->loc = key->co; | td->basic[tdi].loc = key->co; | ||||
| } | } | ||||
| copy_v3_v3(td->iloc, td->loc); | copy_v3_v3(td->basic[tdi].iloc, td->basic[tdi].loc); | ||||
| copy_v3_v3(td->center, td->loc); | copy_v3_v3(td->center[tdi], td->basic[tdi].loc); | ||||
| if (key->flag & PEK_SELECT) { | if (key->flag & PEK_SELECT) { | ||||
| td->flag |= TD_SELECTED; | td->basic[tdi].flag |= TD_SELECTED; | ||||
| } | } | ||||
| else if (!is_prop_edit) { | else if (!is_prop_edit) { | ||||
| td->flag |= TD_SKIP; | td->basic[tdi].flag |= TD_SKIP; | ||||
| } | } | ||||
| unit_m3(td->mtx); | unit_m3(td->space[tdi].mtx); | ||||
| unit_m3(td->smtx); | unit_m3(td->space[tdi].smtx); | ||||
| /* don't allow moving roots */ | /* don't allow moving roots */ | ||||
| if (k == 0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR))) { | if (k == 0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR))) { | ||||
| td->protectflag |= OB_LOCK_LOC; | td->object[tdi].protectflag |= OB_LOCK_LOC; | ||||
| } | } | ||||
| td->ob = ob; | td->object[tdi].ob = ob; | ||||
| td->ext = tx; | |||||
| if (t->mode == TFM_BAKE_TIME) { | if (t->mode == TFM_BAKE_TIME) { | ||||
| td->val = key->time; | td->special[tdi].val = key->time; | ||||
| td->ival = *(key->time); | td->special[tdi].ival = *(key->time); | ||||
| /* abuse size and quat for min/max values */ | /* abuse size and quat for min/max values */ | ||||
| td->flag |= TD_NO_EXT; | td->basic[tdi].flag |= TD_NO_EXT; | ||||
| if (k == 0) { | if (k == 0) { | ||||
| tx->size = NULL; | tx->size = NULL; | ||||
| } | } | ||||
| else { | else { | ||||
| tx->size = (key - 1)->time; | tx->size = (key - 1)->time; | ||||
| } | } | ||||
| if (k == point->totkey - 1) { | if (k == point->totkey - 1) { | ||||
| tx->quat = NULL; | tx->quat = NULL; | ||||
| } | } | ||||
| else { | else { | ||||
| tx->quat = (key + 1)->time; | tx->quat = (key + 1)->time; | ||||
| } | } | ||||
| } | } | ||||
| td++; | tdi++; | ||||
| tail++; | |||||
| if (tx) { | if (tx) { | ||||
| tx++; | tx++; | ||||
| } | } | ||||
| tail++; | |||||
| } | } | ||||
| if (is_prop_edit && head != tail) { | if (is_prop_edit && head != tail) { | ||||
| calc_distanceCurveVerts(head, tail - 1); | calc_distanceCurveVerts(td, head, tail - 1); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Node Transform Creation | /** \name Node Transform Creation | ||||
| * | * | ||||
| * \{ */ | * \{ */ | ||||
| void flushTransParticles(TransInfo *t) | void flushTransParticles(TransInfo *t) | ||||
| { | { | ||||
| FOREACH_TRANS_DATA_CONTAINER (t, tc) { | FOREACH_TRANS_DATA_CONTAINER (t, tc) { | ||||
| Scene *scene = t->scene; | Scene *scene = t->scene; | ||||
| ViewLayer *view_layer = t->view_layer; | ViewLayer *view_layer = t->view_layer; | ||||
| Object *ob = OBACT(view_layer); | Object *ob = OBACT(view_layer); | ||||
| PTCacheEdit *edit = PE_get_current(t->depsgraph, scene, ob); | PTCacheEdit *edit = PE_get_current(t->depsgraph, scene, ob); | ||||
| ParticleSystem *psys = edit->psys; | ParticleSystem *psys = edit->psys; | ||||
| PTCacheEditPoint *point; | PTCacheEditPoint *point; | ||||
| PTCacheEditKey *key; | PTCacheEditKey *key; | ||||
| TransData *td; | |||||
| float mat[4][4], imat[4][4], co[3]; | float mat[4][4], imat[4][4], co[3]; | ||||
| int i, k; | int i, k; | ||||
| const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; | const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0; | ||||
| /* we do transform in world space, so flush world space position | /* we do transform in world space, so flush world space position | ||||
| * back to particle local space (only for hair particles) */ | * back to particle local space (only for hair particles) */ | ||||
| td = tc->data; | |||||
| for (i = 0, point = edit->points; i < edit->totpoint; i++, point++, td++) { | for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) { | ||||
| if (!(point->flag & PEP_TRANSFORM)) { | if (!(point->flag & PEP_TRANSFORM)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { | if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) { | ||||
| ParticleSystemModifierData *psmd_eval = edit->psmd_eval; | ParticleSystemModifierData *psmd_eval = edit->psmd_eval; | ||||
| psys_mat_hair_to_global( | psys_mat_hair_to_global( | ||||
| ob, psmd_eval->mesh_final, psys->part->from, psys->particles + i, mat); | ob, psmd_eval->mesh_final, psys->part->from, psys->particles + i, mat); | ||||
| Show All 25 Lines | |||||