Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BKE_cache_library.h « blenkernel « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 88eb7e986c445a22304f83fbed88bb6c25c0d1f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software  Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * The Original Code is Copyright (C) 2015 Blender Foundation.
 * All rights reserved.
 *
 * The Original Code is: all of this file.
 *
 * Contributor(s): Lukas Toenne
 *
 * ***** END GPL LICENSE BLOCK *****
 */

#ifndef __BKE_CACHE_LIBRARY_H__
#define __BKE_CACHE_LIBRARY_H__

/** \file BKE_cache_library.h
 *  \ingroup bke
 */

#include "DNA_cache_library_types.h"

struct ListBase;
struct Main;
struct bContext;
struct DerivedMesh;
struct Group;
struct Object;
struct Scene;
struct EvaluationContext;
struct ParticleSystem;
struct DupliCache;
struct DupliObjectData;
struct CacheModifier;
struct ID;
struct CacheProcessData;
struct BVHTreeFromMesh;
struct Strands;
struct StrandsChildren;
struct StrandsKeyCacheModifier;
struct Key;
struct KeyBlock;

struct ClothModifierData;

struct CacheLibrary *BKE_cache_library_add(struct Main *bmain, const char *name);
struct CacheLibrary *BKE_cache_library_copy(struct CacheLibrary *cachelib);
void BKE_cache_library_free(struct CacheLibrary *cachelib);
void BKE_cache_library_unlink(struct CacheLibrary *cachelib);

const char *BKE_cache_item_name_prefix(int type);
void BKE_cache_item_name(struct Object *ob, int type, int index, char *name);
int BKE_cache_item_name_length(struct Object *ob, int type, int index);
eCacheReadSampleResult BKE_cache_read_result(int ptc_result);

bool BKE_cache_library_validate_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);

/* ========================================================================= */

void BKE_cache_library_get_read_flags(struct CacheLibrary *cachelib, bool use_render, bool for_display, bool *read_strands_motion, bool *read_strands_children);

bool BKE_cache_archive_path_test(struct CacheLibrary *cachelib, const char *path);
void BKE_cache_archive_path_ex(const char *path, struct Library *lib, const char *default_filename, char *result, int max);
void BKE_cache_archive_input_path(struct CacheLibrary *cachelib, char *result, int max);
void BKE_cache_archive_output_path(struct CacheLibrary *cachelib, char *result, int max);

void BKE_cache_library_dag_recalc_tag(struct EvaluationContext *eval_ctx, struct Main *bmain);

/*void BKE_cache_library_filter_duplilist(struct CacheLibrary *cachelib, struct ListBase *duplilist);*/
void BKE_cache_library_tag_used_objects(CacheLibrary *cachelib);

bool BKE_cache_read_dupli_cache(struct CacheLibrary *cachelib, struct DupliCache *dupcache,
                                struct Scene *scene, struct Group *dupgroup, float frame, bool use_render, bool for_display);
bool BKE_cache_read_dupli_object(struct CacheLibrary *cachelib, struct DupliObjectData *data,
                                 struct Scene *scene, struct Object *ob, float frame, bool use_render, bool for_display);

void BKE_cache_process_dupli_cache(struct CacheLibrary *cachelib, struct CacheProcessData *data,
                                   struct Scene *scene, struct Group *dupgroup, float frame_prev, float frame,
                                   bool do_modifiers, bool do_strands_child_deform, bool do_strands_motion);

/* ========================================================================= */

typedef void (*CacheModifier_IDWalkFunc)(void *userdata, struct CacheLibrary *cachelib, struct CacheModifier *md, struct ID **id_ptr);

typedef struct CacheProcessContext {
	struct Main *bmain;
	struct Scene *scene;
	struct CacheLibrary *cachelib;
	struct Group *group;
} CacheProcessContext;

typedef struct CacheProcessData {
	unsigned int lay;
	float mat[4][4];
	struct DupliCache *dupcache;
} CacheProcessData;

typedef enum eCacheProcessFlag {
	eCacheProcessFlag_DoStrands             = (1 << 0),
	eCacheProcessFlag_DoStrandsChildren     = (1 << 1),
} eCacheProcessFlag;

typedef void (*CacheModifier_InitFunc)(struct CacheModifier *md);
typedef void (*CacheModifier_FreeFunc)(struct CacheModifier *md);
typedef void (*CacheModifier_CopyFunc)(struct CacheModifier *md, struct CacheModifier *target);
typedef void (*CacheModifier_ForeachIDLinkFunc)(struct CacheModifier *md, struct CacheLibrary *cachelib,
                                                CacheModifier_IDWalkFunc walk, void *userData);
typedef void (*CacheModifier_ProcessFunc)(struct CacheModifier *md, struct CacheProcessContext *ctx, struct CacheProcessData *data,
                                          int frame, int frame_prev, int process_flag);

typedef struct CacheModifierTypeInfo {
	/* The user visible name for this modifier */
	char name[32];

	/* The DNA struct name for the modifier data type,
	 * used to write the DNA data out.
	 */
	char struct_name[32];

	/* The size of the modifier data type, used by allocation. */
	int struct_size;

	/********************* Non-optional functions *********************/

	/* Copy instance data for this modifier type. Should copy all user
	 * level settings to the target modifier.
	 */
	CacheModifier_CopyFunc copy;

	/* Should call the given walk function with a pointer to each ID
	 * pointer (i.e. each datablock pointer) that the modifier data
	 * stores. This is used for linking on file load and for
	 * unlinking datablocks or forwarding datablock references.
	 *
	 * This function is optional.
	 */
	CacheModifier_ForeachIDLinkFunc foreachIDLink;

	/* Process data and write results to the modifier's output archive */
	CacheModifier_ProcessFunc process;

	/********************* Optional functions *********************/

	/* Initialize new instance data for this modifier type, this function
	 * should set modifier variables to their default values.
	 * 
	 * This function is optional.
	 */
	CacheModifier_InitFunc init;

	/* Free internal modifier data variables, this function should
	 * not free the md variable itself.
	 *
	 * This function is optional.
	 */
	CacheModifier_FreeFunc free;
} CacheModifierTypeInfo;

void BKE_cache_modifier_init(void);

const char *BKE_cache_modifier_type_name(eCacheModifier_Type type);
const char *BKE_cache_modifier_type_struct_name(eCacheModifier_Type type);
int BKE_cache_modifier_type_struct_size(eCacheModifier_Type type);

bool BKE_cache_modifier_unique_name(struct ListBase *modifiers, struct CacheModifier *md);
struct CacheModifier *BKE_cache_modifier_add(struct CacheLibrary *cachelib, const char *name, eCacheModifier_Type type);
void BKE_cache_modifier_remove(struct CacheLibrary *cachelib, struct CacheModifier *md);
void BKE_cache_modifier_clear(struct CacheLibrary *cachelib);
struct CacheModifier *BKE_cache_modifier_copy(struct CacheLibrary *cachelib, struct CacheModifier *md);

void BKE_cache_modifier_foreachIDLink(struct CacheLibrary *cachelib, struct CacheModifier *md, CacheModifier_IDWalkFunc walk, void *userdata);

bool BKE_cache_modifier_find_object(struct DupliCache *dupcache, struct Object *ob, struct DupliObjectData **r_data);
bool BKE_cache_modifier_find_strands(struct DupliCache *dupcache, struct Object *ob, int hair_system, struct DupliObjectData **r_data, struct Strands **r_strands, struct StrandsChildren **r_children, const char **r_name);

struct KeyBlock *BKE_cache_modifier_strands_key_insert_key(struct StrandsKeyCacheModifier *md, struct Strands *strands, const char *name, const bool from_mix);
bool BKE_cache_modifier_strands_key_get(struct Object *ob, struct StrandsKeyCacheModifier **r_skmd, struct DerivedMesh **r_dm, struct Strands **r_strands,
                                        struct DupliObjectData **r_dobdata, const char **r_name, float r_mat[4][4]);
bool BKE_cache_library_uses_key(struct CacheLibrary *cachelib, struct Key *key);

/* ========================================================================= */

typedef struct CacheEffectorInstance {
	struct CacheEffectorInstance *next, *prev;
	
	float mat[4][4];
	float imat[4][4];
	// TODO add linear/angular velocity if necessary
} CacheEffectorInstance;

typedef struct CacheEffector {
	int type;
	
	ListBase instances;
	
	struct DerivedMesh *dm;
	struct BVHTreeFromMesh *treedata;
	struct ForceFieldVertexCache *vertex_cache;
	
	float strength, falloff;
	float mindist, maxdist;
	bool double_sided;
} CacheEffector;

typedef enum eCacheEffector_Type {
	eCacheEffector_Type_Deflect           = 0,
	eCacheEffector_Type_Drag              = 1,
} eCacheEffector_Type;

typedef struct CacheEffectorPoint {
	int index;
	float x[3], v[3];
} CacheEffectorPoint;

typedef struct CacheEffectorResult {
	float f[3];
} CacheEffectorResult;

int BKE_cache_effectors_get(struct CacheEffector *effectors, int max, struct CacheLibrary *cachelib, struct DupliCache *dupcache, float obmat[4][4]);
void BKE_cache_effectors_free(struct CacheEffector *effectors, int tot);
void BKE_cache_effector_velocity_update(struct CacheLibrary *cachelib, struct DupliCache *dupcache, float obmat[4][4], float frame);
int BKE_cache_effectors_eval(struct CacheEffector *effectors, int tot, struct CacheEffectorPoint *point, struct CacheEffectorResult *result);
int BKE_cache_effectors_eval_ex(struct CacheEffector *effectors, int tot, struct CacheEffectorPoint *point, struct CacheEffectorResult *result,
                                bool (*filter)(void *, struct CacheEffector *), void *filter_data);

/* ========================================================================= */

struct CacheArchiveInfo *BKE_cache_archive_info_new(void);
void BKE_cache_archive_info_free(struct CacheArchiveInfo *info);
void BKE_cache_archive_info_clear(struct CacheArchiveInfo *info);

struct CacheArchiveInfoNode *BKE_cache_archive_info_find_node(struct CacheArchiveInfo *info, struct CacheArchiveInfoNode *parent,
                                                              eCacheArchiveInfoNode_Type type, const char *name);
struct CacheArchiveInfoNode *BKE_cache_archive_info_add_node(struct CacheArchiveInfo *info, struct CacheArchiveInfoNode *parent,
                                                             eCacheArchiveInfoNode_Type type, const char *name);

#endif