Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/pointcache.c
| Show First 20 Lines • Show All 1,825 Lines • ▼ Show 20 Lines | void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, Object *ob, RigidBodyWorld *rbw) | ||||
| pid->default_step = 1; | pid->default_step = 1; | ||||
| pid->max_step = 1; | pid->max_step = 1; | ||||
| pid->file_type = PTCACHE_FILE_PTCACHE; | pid->file_type = PTCACHE_FILE_PTCACHE; | ||||
| } | } | ||||
| static int ptcache_sim_particle_totpoint(void *state_v, int UNUSED(cfra)) | static int ptcache_sim_particle_totpoint(void *state_v, int UNUSED(cfra)) | ||||
| { | { | ||||
| ParticleSimulationState *state = (ParticleSimulationState *)state_v; | UNUSED_VARS(state_v); | ||||
| return state->tot_particles; | /* All actual data is stored in extra data. | ||||
| * Just don't return 0 so that this data is not skipped. */ | |||||
| return 1; | |||||
| } | } | ||||
| static void ptcache_sim_particle_error(void *UNUSED(state_v), const char *UNUSED(message)) | static void ptcache_sim_particle_error(void *UNUSED(state_v), const char *UNUSED(message)) | ||||
| { | { | ||||
| } | } | ||||
| static int ptcache_sim_particle_write(int index, void *state_v, void **data, int UNUSED(cfra)) | static int ptcache_sim_particle_write(int UNUSED(index), | ||||
| void *UNUSED(state_v), | |||||
| void **UNUSED(data), | |||||
| int UNUSED(cfra)) | |||||
| { | |||||
| return 0; | |||||
| } | |||||
| static void ptcache_sim_particle_read(int UNUSED(index), | |||||
| void *UNUSED(state_v), | |||||
| void **UNUSED(data), | |||||
| float UNUSED(cfra), | |||||
| float *UNUSED(old_data)) | |||||
| { | { | ||||
| ParticleSimulationState *state = (ParticleSimulationState *)state_v; | } | ||||
| const float *positions = (const float *)CustomData_get_layer_named( | static void ptcache_sim_particle_extra_write(void *state_v, PTCacheMem *pm, int UNUSED(cfra)) | ||||
| &state->attributes, CD_LOCATION, "Position"); | { | ||||
| ParticleSimulationState *state = state_v; | |||||
| PTCACHE_DATA_FROM(data, BPHYS_DATA_LOCATION, positions + (index * 3)); | for (int layer_index = 0; layer_index < state->attributes.totlayer; layer_index++) { | ||||
| CustomDataLayer *layer = &state->attributes.layers[layer_index]; | |||||
| BLI_assert(layer->name != NULL); | |||||
| return 1; | PTCacheExtra *extra = MEM_callocN(sizeof(PTCacheExtra), AT); | ||||
| extra->type = BPHYS_EXTRA_CUSTOM_DATA; | |||||
| extra->totdata = state->tot_particles; | |||||
| extra->custom_data_type = layer->type; | |||||
| extra->identifier = BLI_strdup(layer->name); | |||||
| extra->data = MEM_dupallocN(layer->data); /* TODO: Don't use dupalloc. */ | |||||
| BLI_addtail(&pm->extradata, extra); | |||||
| } | |||||
| } | } | ||||
| static void ptcache_sim_particle_read( | |||||
| int index, void *state_v, void **data, float UNUSED(cfra), float *UNUSED(old_data)) | static void ptcache_sim_particle_extra_read(void *state_v, PTCacheMem *pm, float UNUSED(cfra)) | ||||
| { | { | ||||
| ParticleSimulationState *state = (ParticleSimulationState *)state_v; | ParticleSimulationState *state = state_v; | ||||
| CustomData_free(&state->attributes, state->tot_particles); | |||||
| state->tot_particles = 0; | |||||
| LISTBASE_FOREACH (const PTCacheExtra *, extra, &pm->extradata) { | |||||
| BLI_assert(extra->type == BPHYS_EXTRA_CUSTOM_DATA); | |||||
| if (extra->totdata != state->tot_particles) { | |||||
| state->tot_particles = extra->totdata; | |||||
| CustomData_realloc(&state->attributes, extra->totdata); | |||||
| } | |||||
| BLI_assert(index < state->tot_particles); | void *data = MEM_dupallocN(extra->data); /* TODO: Don't use dupalloc. */ | ||||
| float *positions = (float *)CustomData_get_layer_named( | |||||
| &state->attributes, CD_LOCATION, "Position"); | |||||
| PTCACHE_DATA_TO(data, BPHYS_DATA_LOCATION, 0, positions + (index * 3)); | CustomData_add_layer_named(&state->attributes, | ||||
| extra->custom_data_type, | |||||
| CD_ASSIGN, | |||||
| data, | |||||
| extra->totdata, | |||||
| extra->identifier); | |||||
| } | |||||
| } | } | ||||
| void BKE_ptcache_id_from_sim_particles(PTCacheID *pid, ParticleSimulationState *state) | void BKE_ptcache_id_from_sim_particles(PTCacheID *pid, ParticleSimulationState *state) | ||||
| { | { | ||||
| memset(pid, 0, sizeof(PTCacheID)); | memset(pid, 0, sizeof(PTCacheID)); | ||||
| ParticleSimulationState *state_orig; | ParticleSimulationState *state_orig; | ||||
| if (state->head.orig_state != NULL) { | if (state->head.orig_state != NULL) { | ||||
| Show All 11 Lines | void BKE_ptcache_id_from_sim_particles(PTCacheID *pid, ParticleSimulationState *state) | ||||
| pid->totpoint = ptcache_sim_particle_totpoint; | pid->totpoint = ptcache_sim_particle_totpoint; | ||||
| pid->totwrite = ptcache_sim_particle_totpoint; | pid->totwrite = ptcache_sim_particle_totpoint; | ||||
| pid->error = ptcache_sim_particle_error; | pid->error = ptcache_sim_particle_error; | ||||
| pid->write_point = ptcache_sim_particle_write; | pid->write_point = ptcache_sim_particle_write; | ||||
| pid->read_point = ptcache_sim_particle_read; | pid->read_point = ptcache_sim_particle_read; | ||||
| pid->interpolate_point = NULL; | pid->interpolate_point = NULL; | ||||
| pid->write_stream = NULL; | pid->write_extra_data = ptcache_sim_particle_extra_write; | ||||
| pid->read_stream = NULL; | pid->read_extra_data = ptcache_sim_particle_extra_read; | ||||
| pid->write_openvdb_stream = NULL; | |||||
| pid->read_openvdb_stream = NULL; | |||||
| pid->write_extra_data = NULL; | |||||
| pid->read_extra_data = NULL; | |||||
| pid->interpolate_extra_data = NULL; | pid->interpolate_extra_data = NULL; | ||||
| pid->write_header = NULL; | pid->data_types = 1 << BPHYS_DATA_LOCATION; /* Just must not be 0. */ | ||||
| pid->read_header = NULL; | |||||
| pid->data_types = 1 << BPHYS_DATA_LOCATION; | |||||
| pid->info_types = 0; | |||||
| pid->stack_index = 0; | |||||
| pid->default_step = 1; | pid->default_step = 1; | ||||
| pid->max_step = 1; | pid->max_step = 1; | ||||
| pid->file_type = PTCACHE_FILE_PTCACHE; | pid->file_type = PTCACHE_FILE_PTCACHE; | ||||
| } | } | ||||
| /** | /** | ||||
| * \param ob: Optional, may be NULL. | * \param ob: Optional, may be NULL. | ||||
| ▲ Show 20 Lines • Show All 726 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| PTCacheExtra *extra = pm->extradata.first; | PTCacheExtra *extra = pm->extradata.first; | ||||
| if (extra) { | if (extra) { | ||||
| for (; extra; extra = extra->next) { | for (; extra; extra = extra->next) { | ||||
| if (extra->data) { | if (extra->data) { | ||||
| MEM_freeN(extra->data); | MEM_freeN(extra->data); | ||||
| } | } | ||||
| if (extra->identifier) { | |||||
| MEM_freeN(extra->identifier); | |||||
| } | |||||
| } | } | ||||
| BLI_freelistN(&pm->extradata); | BLI_freelistN(&pm->extradata); | ||||
| } | } | ||||
| } | } | ||||
| static void ptcache_mem_clear(PTCacheMem *pm) | static void ptcache_mem_clear(PTCacheMem *pm) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | else { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (!error && pm->extradata.first) { | if (!error && pm->extradata.first) { | ||||
| PTCacheExtra *extra = pm->extradata.first; | PTCacheExtra *extra = pm->extradata.first; | ||||
| for (; extra; extra = extra->next) { | for (; extra; extra = extra->next) { | ||||
| /* This is not yet implemented. */ | |||||
| BLI_assert(extra->type != BPHYS_EXTRA_CUSTOM_DATA); | |||||
| if (extra->data == NULL || extra->totdata == 0) { | if (extra->data == NULL || extra->totdata == 0) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| ptcache_file_write(pf, &extra->type, 1, sizeof(unsigned int)); | ptcache_file_write(pf, &extra->type, 1, sizeof(unsigned int)); | ||||
| ptcache_file_write(pf, &extra->totdata, 1, sizeof(unsigned int)); | ptcache_file_write(pf, &extra->totdata, 1, sizeof(unsigned int)); | ||||
| if (pid->cache->compression) { | if (pid->cache->compression) { | ||||
| ▲ Show 20 Lines • Show All 1,785 Lines • Show Last 20 Lines | |||||