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

rna_cache_library.c « intern « makesrna « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c8b8835491e4341c1425922b5597af717979338 (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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
/*
 * ***** 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.
 *
 * Contributor(s): Blender Foundation (2015).
 *
 * ***** END GPL LICENSE BLOCK *****
 */

/** \file blender/makesrna/intern/rna_cache_library.c
 *  \ingroup RNA
 */

#include <stdlib.h>
#include <assert.h>
#include <string.h>

#include "DNA_cache_library_types.h"

#include "RNA_define.h"
#include "RNA_enum_types.h"

#include "rna_internal.h"

#include "WM_types.h"

EnumPropertyItem cache_library_data_type_items[] = {
    {CACHE_TYPE_OBJECT,         "OBJECT",			ICON_OBJECT_DATA,       "Object", "Object base properties"},
    {CACHE_TYPE_DERIVED_MESH,   "DERIVED_MESH",     ICON_OUTLINER_OB_MESH,  "Derived Mesh", "Mesh result from modifiers"},
    {CACHE_TYPE_HAIR,           "HAIR",             ICON_PARTICLE_POINT,    "Hair", "Hair parent strands"},
    {CACHE_TYPE_HAIR_PATHS,     "HAIR_PATHS",       ICON_PARTICLE_PATH,     "Hair Paths", "Full hair paths"},
    {CACHE_TYPE_PARTICLES,      "PARTICLES",        ICON_PARTICLES,         "Particles", "Emitter particles"},
    {0, NULL, 0, NULL, NULL}
};

EnumPropertyItem cache_library_read_result_items[] = {
    {CACHE_READ_SAMPLE_INVALID,         "INVALID",      ICON_ERROR,             "Invalid",      "No valid sample found"},
    {CACHE_READ_SAMPLE_EXACT,           "EXACT",        ICON_SPACE3,            "Exact",        "Found sample for requested frame"},
    {CACHE_READ_SAMPLE_INTERPOLATED,    "INTERPOLATED", ICON_TRIA_DOWN_BAR,     "Interpolated", "Enclosing samples found for interpolation"},
    {CACHE_READ_SAMPLE_EARLY,           "EARLY",        ICON_TRIA_RIGHT_BAR,    "Early",        "Requested frame before the first sample"},
    {CACHE_READ_SAMPLE_LATE,            "LATE",         ICON_TRIA_LEFT_BAR,     "Late",         "Requested frame after the last sample"},
    {0, NULL, 0, NULL, NULL}
};

EnumPropertyItem cache_modifier_type_items[] = {
    {eCacheModifierType_HairSimulation, "HAIR_SIMULATION", ICON_HAIR, "Hair Simulation", ""},
    {eCacheModifierType_ForceField, "FORCE_FIELD", ICON_FORCE_FORCE, "Force Field", ""},
    {eCacheModifierType_ShrinkWrap, "SHRINK_WRAP", ICON_MOD_SHRINKWRAP, "Shrink Wrap", ""},
    {eCacheModifierType_StrandsKey, "STRANDS_KEY", ICON_SHAPEKEY_DATA, "Strands Key", "Shape key for strands"},
    {eCacheModifierType_Haircut, "HAIRCUT", ICON_HAIR, "Hair Cut", "Cut strands where they intersect with an object"},
    {0, NULL, 0, NULL, NULL}
};

#ifdef RNA_RUNTIME

#include "MEM_guardedalloc.h"

#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_string.h"

#include "DNA_key_types.h"
#include "DNA_object_types.h"
#include "DNA_particle_types.h"

#include "BKE_animsys.h"
#include "BKE_cache_library.h"
#include "BKE_depsgraph.h"
#include "BKE_main.h"

#include "RNA_access.h"

#include "WM_api.h"

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

static void rna_CacheLibrary_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
	CacheLibrary *cachelib = ptr->data;
	DAG_id_tag_update(&cachelib->id, OB_RECALC_DATA);
	WM_main_add_notifier(NC_WINDOW, NULL);
}

static void rna_CacheArchiveInfo_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
{
//	CacheLibrary *cachelib = ptr->id.data;
//	WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
}

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

static void rna_CacheModifier_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
{
}

#if 0 /* unused */
static void rna_CacheModifier_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
	rna_CacheModifier_update(bmain, scene, ptr);
	DAG_relations_tag_update(bmain);
}
#endif


static StructRNA *rna_CacheModifier_refine(struct PointerRNA *ptr)
{
	CacheModifier *md = (CacheModifier *)ptr->data;

	switch ((eCacheModifier_Type)md->type) {
		case eCacheModifierType_HairSimulation:
			return &RNA_HairSimulationCacheModifier;
		case eCacheModifierType_ForceField:
			return &RNA_ForceFieldCacheModifier;
		case eCacheModifierType_ShrinkWrap:
			return &RNA_ShrinkWrapCacheModifier;
		case eCacheModifierType_StrandsKey:
			return &RNA_StrandsKeyCacheModifier;
		case eCacheModifierType_Haircut:
			return &RNA_HaircutCacheModifier;
			
		/* Default */
		case eCacheModifierType_None:
		case NUM_CACHE_MODIFIER_TYPES:
			return &RNA_CacheLibraryModifier;
	}

	return &RNA_CacheLibraryModifier;
}

static void rna_CacheLibraryModifier_name_set(PointerRNA *ptr, const char *value)
{
	CacheModifier *md = ptr->data;
	char oldname[sizeof(md->name)];
	
	/* make a copy of the old name first */
	BLI_strncpy(oldname, md->name, sizeof(md->name));
	
	/* copy the new name into the name slot */
	BLI_strncpy_utf8(md->name, value, sizeof(md->name));
	
	/* make sure the name is truly unique */
	if (ptr->id.data) {
		CacheLibrary *cachelib = ptr->id.data;
		BKE_cache_modifier_unique_name(&cachelib->modifiers, md);
	}
	
	/* fix all the animation data which may link to this */
	BKE_animdata_fix_paths_rename_all(NULL, "modifiers", oldname, md->name);
}

static char *rna_CacheLibraryModifier_path(PointerRNA *ptr)
{
	CacheModifier *md = ptr->data;
	char name_esc[sizeof(md->name) * 2];

	BLI_strescape(name_esc, md->name, sizeof(name_esc));
	return BLI_sprintfN("modifiers[\"%s\"]", name_esc);
}

static CacheModifier *rna_CacheLibrary_modifier_new(CacheLibrary *cachelib, bContext *UNUSED(C), ReportList *UNUSED(reports),
                                                    const char *name, int type)
{
	return BKE_cache_modifier_add(cachelib, name, type);
}

static void rna_CacheLibrary_modifier_remove(CacheLibrary *cachelib, bContext *UNUSED(C), ReportList *UNUSED(reports), PointerRNA *md_ptr)
{
	CacheModifier *md = md_ptr->data;
	
	BKE_cache_modifier_remove(cachelib, md);

	RNA_POINTER_INVALIDATE(md_ptr);
}

static void rna_CacheLibrary_modifier_clear(CacheLibrary *cachelib, bContext *UNUSED(C))
{
	BKE_cache_modifier_clear(cachelib);
}

/* ------------------------------------------------------------------------- */

static int rna_CacheLibraryModifier_mesh_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
{
	/*HairSimCacheModifier *hsmd = ptr->data;*/
	Object *ob = value.data;
	
	return ob->type == OB_MESH && ob->data != NULL;
}

static int rna_CacheLibraryModifier_hair_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
{
	/*HairSimCacheModifier *hsmd = ptr->data;*/
	Object *ob = value.data;
	ParticleSystem *psys;
	bool has_hair_system = false;
	
	for (psys = ob->particlesystem.first; psys; psys = psys->next) {
		if (psys->part && psys->part->type == PART_HAIR) {
			has_hair_system = true;
			break;
		}
	}
	return has_hair_system;
}

static PointerRNA rna_HairSimulationCacheModifier_hair_system_get(PointerRNA *ptr)
{
	HairSimCacheModifier *hsmd = ptr->data;
	ParticleSystem *psys = hsmd->object ? BLI_findlink(&hsmd->object->particlesystem, hsmd->hair_system) : NULL;
	PointerRNA value;
	
	RNA_pointer_create(ptr->id.data, &RNA_ParticleSystem, psys, &value);
	return value;
}

static void rna_HairSimulationCacheModifier_hair_system_set(PointerRNA *ptr, PointerRNA value)
{
	HairSimCacheModifier *hsmd = ptr->data;
	ParticleSystem *psys = value.data;
	hsmd->hair_system = hsmd->object ? BLI_findindex(&hsmd->object->particlesystem, psys) : -1;
}

static int rna_HairSimulationCacheModifier_hair_system_poll(PointerRNA *ptr, PointerRNA value)
{
	HairSimCacheModifier *hsmd = ptr->data;
	ParticleSystem *psys = value.data;
	
	if (!hsmd->object)
		return false;
	if (BLI_findindex(&hsmd->object->particlesystem, psys) == -1)
		return false;
	if (!psys->part || psys->part->type != PART_HAIR)
		return false;
	return true;
}

static PointerRNA rna_ShrinkWrapCacheModifier_hair_system_get(PointerRNA *ptr)
{
	ShrinkWrapCacheModifier *smd = ptr->data;
	ParticleSystem *psys = smd->object ? BLI_findlink(&smd->object->particlesystem, smd->hair_system) : NULL;
	PointerRNA value;
	
	RNA_pointer_create(ptr->id.data, &RNA_ParticleSystem, psys, &value);
	return value;
}

static void rna_ShrinkWrapCacheModifier_hair_system_set(PointerRNA *ptr, PointerRNA value)
{
	ShrinkWrapCacheModifier *smd = ptr->data;
	ParticleSystem *psys = value.data;
	smd->hair_system = smd->object ? BLI_findindex(&smd->object->particlesystem, psys) : -1;
}

static int rna_ShrinkWrapCacheModifier_hair_system_poll(PointerRNA *ptr, PointerRNA value)
{
	ShrinkWrapCacheModifier *smd = ptr->data;
	ParticleSystem *psys = value.data;
	
	if (!smd->object)
		return false;
	if (BLI_findindex(&smd->object->particlesystem, psys) == -1)
		return false;
	if (!psys->part || psys->part->type != PART_HAIR)
		return false;
	return true;
}

static PointerRNA rna_StrandsKeyCacheModifier_hair_system_get(PointerRNA *ptr)
{
	StrandsKeyCacheModifier *skmd = ptr->data;
	ParticleSystem *psys = skmd->object ? BLI_findlink(&skmd->object->particlesystem, skmd->hair_system) : NULL;
	PointerRNA value;
	
	RNA_pointer_create(ptr->id.data, &RNA_ParticleSystem, psys, &value);
	return value;
}

static void rna_StrandsKeyCacheModifier_hair_system_set(PointerRNA *ptr, PointerRNA value)
{
	StrandsKeyCacheModifier *skmd = ptr->data;
	ParticleSystem *psys = value.data;
	skmd->hair_system = skmd->object ? BLI_findindex(&skmd->object->particlesystem, psys) : -1;
}

static int rna_StrandsKeyCacheModifier_hair_system_poll(PointerRNA *ptr, PointerRNA value)
{
	StrandsKeyCacheModifier *skmd = ptr->data;
	ParticleSystem *psys = value.data;
	
	if (!skmd->object)
		return false;
	if (BLI_findindex(&skmd->object->particlesystem, psys) == -1)
		return false;
	if (!psys->part || psys->part->type != PART_HAIR)
		return false;
	return true;
}

static void rna_StrandsKeyCacheModifier_active_shape_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
#if 0 // TODO
	StrandsKeyCacheModifier *skmd = ptr->data;
	
	if (scene->obedit == ob) {
		/* exit/enter editmode to get new shape */
		switch (ob->type) {
			case OB_MESH:
				EDBM_mesh_load(ob);
				EDBM_mesh_make(scene->toolsettings, ob);
				EDBM_mesh_normals_update(((Mesh *)ob->data)->edit_btmesh);
				BKE_editmesh_tessface_calc(((Mesh *)ob->data)->edit_btmesh);
				break;
			case OB_CURVE:
			case OB_SURF:
				load_editNurb(ob);
				make_editNurb(ob);
				break;
			case OB_LATTICE:
				load_editLatt(ob);
				make_editLatt(ob);
				break;
		}
	}
#endif
	
	rna_CacheModifier_update(bmain, scene, ptr);
}

static void rna_StrandsKeyCacheModifier_active_shape_key_index_range(PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
{
	StrandsKeyCacheModifier *skmd = ptr->data;
	Key *key = skmd->key;

	*min = 0;
	if (key) {
		*max = BLI_listbase_count(&key->block) - 1;
		if (*max < 0) *max = 0;
	}
	else {
		*max = 0;
	}
}

static int rna_StrandsKeyCacheModifier_active_shape_key_index_get(PointerRNA *ptr)
{
	StrandsKeyCacheModifier *skmd = ptr->data;

	return max_ii(skmd->shapenr - 1, 0);
}

static void rna_StrandsKeyCacheModifier_active_shape_key_index_set(PointerRNA *ptr, int value)
{
	StrandsKeyCacheModifier *skmd = ptr->data;

	skmd->shapenr = value + 1;
}

static PointerRNA rna_StrandsKeyCacheModifier_active_shape_key_get(PointerRNA *ptr)
{
	StrandsKeyCacheModifier *skmd = ptr->data;
	Key *key = skmd->key;
	KeyBlock *kb;
	PointerRNA keyptr;

	if (key == NULL)
		return PointerRNA_NULL;
	
	kb = BLI_findlink(&key->block, skmd->shapenr - 1);
	RNA_pointer_create((ID *)key, &RNA_ShapeKey, kb, &keyptr);
	return keyptr;
}

static PointerRNA rna_HaircutCacheModifier_hair_system_get(PointerRNA *ptr)
{
	HaircutCacheModifier *hmd = ptr->data;
	ParticleSystem *psys = hmd->object ? BLI_findlink(&hmd->object->particlesystem, hmd->hair_system) : NULL;
	PointerRNA value;
	
	RNA_pointer_create(ptr->id.data, &RNA_ParticleSystem, psys, &value);
	return value;
}

static void rna_HaircutCacheModifier_hair_system_set(PointerRNA *ptr, PointerRNA value)
{
	HaircutCacheModifier *hmd = ptr->data;
	ParticleSystem *psys = value.data;
	hmd->hair_system = hmd->object ? BLI_findindex(&hmd->object->particlesystem, psys) : -1;
}

static int rna_HaircutCacheModifier_hair_system_poll(PointerRNA *ptr, PointerRNA value)
{
	HaircutCacheModifier *hmd = ptr->data;
	ParticleSystem *psys = value.data;
	
	if (!hmd->object)
		return false;
	if (BLI_findindex(&hmd->object->particlesystem, psys) == -1)
		return false;
	if (!psys->part || psys->part->type != PART_HAIR)
		return false;
	return true;
}

static void rna_CacheArchiveInfoNode_bytes_size_get(PointerRNA *ptr, char *value)
{
	CacheArchiveInfoNode *node = ptr->data;
	BLI_snprintf(value, MAX_NAME, "%lld", (long long int)node->bytes_size);
}

static int rna_CacheArchiveInfoNode_bytes_size_length(PointerRNA *ptr)
{
	char buf[MAX_NAME];
	/* theoretically could do a dummy BLI_snprintf here, but BLI does not allow NULL buffer ... */
	CacheArchiveInfoNode *node = ptr->data;
	return BLI_snprintf(buf, sizeof(buf), "%lld", (long long int)node->bytes_size);
}

#else

static void rna_def_hair_sim_params(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "HairSimulationParameters", NULL);
	RNA_def_struct_sdna(srna, "HairSimParams");
	RNA_def_struct_ui_text(srna, "Hair Simulation Parameters", "Simulation parameters for hair simulation");
	RNA_def_struct_ui_icon(srna, ICON_HAIR);
	
	prop = RNA_def_property(srna, "timescale", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 0.1f, 3);
	RNA_def_property_ui_text(prop, "Time Scale", "Simulation time scale relative to scene time");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "substeps", PROP_INT, PROP_NONE);
	RNA_def_property_range(prop, 1, 80);
	RNA_def_property_ui_text(prop, "Substeps", "Simulation steps per frame");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "effector_weights", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "EffectorWeights");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Effector Weights", "");
	
	prop = RNA_def_property(srna, "mass", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, 0.0f, 10.0f);
	RNA_def_property_ui_text(prop, "Mass", "Mass of hair vertices");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "drag", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 0.1f, 3);
	RNA_def_property_ui_text(prop, "Drag", "Drag simulating friction with surrounding air");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "goal_stiffness", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 0.1f, 3);
	RNA_def_property_float_default(prop, 0.0f);
	RNA_def_property_ui_text(prop, "Goal Strength", "Goal spring, pulling vertices toward their rest position");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "goal_damping", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 3);
	RNA_def_property_float_default(prop, 1.0f);
	RNA_def_property_ui_text(prop, "Goal Damping", "Damping factor of goal springs");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "use_goal_stiffness_curve", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", eHairSimParams_Flag_UseGoalStiffnessCurve);
	RNA_def_property_ui_text(prop, "Use Goal Stiffness Curve", "Use a curve to define goal stiffness along the strand");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "goal_stiffness_curve", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "goal_stiffness_mapping");
	RNA_def_property_struct_type(prop, "CurveMapping");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Goal Stiffness Curve", "Stiffness of goal springs along the strand curves");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "use_goal_deflect", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", eHairSimParams_Flag_UseGoalDeflect);
	RNA_def_property_ui_text(prop, "Use Goal Deflect", "Disable goal springs inside deflectors, to avoid unstable deformations");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "use_bend_stiffness_curve", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", eHairSimParams_Flag_UseBendStiffnessCurve);
	RNA_def_property_ui_text(prop, "Use Bend Stiffness Curve", "Use a curve to define bend resistance along the strand");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "bend_stiffness_curve", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "bend_stiffness_mapping");
	RNA_def_property_struct_type(prop, "CurveMapping");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Bend Stiffness Curve", "Resistance to bending along the strand curves");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "stretch_stiffness", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 10000.0f, 0.1f, 3);
	RNA_def_property_float_default(prop, 10000.0f);
	RNA_def_property_ui_text(prop, "Stretch Stiffness", "Resistance to stretching");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "stretch_damping", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 3);
	RNA_def_property_float_default(prop, 0.1f);
	RNA_def_property_ui_text(prop, "Stretch Damping", "Damping factor of stretch springs");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "bend_stiffness", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 1000.0f, 0.1f, 3);
	RNA_def_property_float_default(prop, 100.0f);
	RNA_def_property_ui_text(prop, "Bend Stiffness", "Resistance to bending of the rest shape");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "bend_damping", PROP_FLOAT, PROP_FACTOR);
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 3);
	RNA_def_property_float_default(prop, 1.0f);
	RNA_def_property_ui_text(prop, "Bend Damping", "Damping factor of bending springs");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
}

static void rna_def_cache_modifier_hair_simulation(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	rna_def_hair_sim_params(brna);
	
	srna = RNA_def_struct(brna, "HairSimulationCacheModifier", "CacheLibraryModifier");
	RNA_def_struct_sdna(srna, "HairSimCacheModifier");
	RNA_def_struct_ui_text(srna, "Hair Simulation Cache Modifier", "Apply hair dynamics simulation to the cache");
	RNA_def_struct_ui_icon(srna, ICON_HAIR);
	
	prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "object");
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_CacheLibraryModifier_hair_object_poll");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Object", "Object whose cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "hair_system_index", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "hair_system");
	RNA_def_property_ui_text(prop, "Hair System Index", "Hair system cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "hair_system", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_funcs(prop, "rna_HairSimulationCacheModifier_hair_system_get", "rna_HairSimulationCacheModifier_hair_system_set", NULL, "rna_HairSimulationCacheModifier_hair_system_poll");
	RNA_def_property_struct_type(prop, "ParticleSystem");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Hair System", "Hair system cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "parameters", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "sim_params");
	RNA_def_property_struct_type(prop, "HairSimulationParameters");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Simulation Parameters", "Parameters of the simulation");
}

static void rna_def_cache_modifier_force_field(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	static EnumPropertyItem force_type_items[] = {
	    {eForceFieldCacheModifier_Type_Deflect, "DEFLECT", ICON_FORCE_FORCE, "Deflect", "Push away from the surface"},
	    {eForceFieldCacheModifier_Type_Drag, "DRAG", ICON_FORCE_DRAG, "Drag", "Adjust velocity to the surface"},
	    {0, NULL, 0, NULL, NULL}
	};
	
	srna = RNA_def_struct(brna, "ForceFieldCacheModifier", "CacheLibraryModifier");
	RNA_def_struct_sdna(srna, "ForceFieldCacheModifier");
	RNA_def_struct_ui_text(srna, "Force Field Cache Modifier", "Use an object as a force field");
	RNA_def_struct_ui_icon(srna, ICON_FORCE_FORCE);
	
	prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "object");
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_CacheLibraryModifier_mesh_object_poll");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Object", "Object whose cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "force_type", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "type");
	RNA_def_property_enum_items(prop, force_type_items);
	RNA_def_property_ui_text(prop, "Force Type", "Type of force field");
	
	prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
	RNA_def_property_ui_range(prop, -10000.0f, 10000.0f, 0.1, 3);
	RNA_def_property_ui_text(prop, "Strength", "");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE);
	RNA_def_property_range(prop, 0.0f, FLT_MAX);
	RNA_def_property_ui_range(prop, 0.0f, 10.0f, 0.1, 3);
	RNA_def_property_ui_text(prop, "Falloff", "");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "min_distance", PROP_FLOAT, PROP_DISTANCE);
	RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
	RNA_def_property_ui_range(prop, -100.0f, 100.0f, 0.1, 4);
	RNA_def_property_ui_text(prop, "Minimum Distance", "");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "max_distance", PROP_FLOAT, PROP_DISTANCE);
	RNA_def_property_range(prop, -FLT_MAX, FLT_MAX);
	RNA_def_property_ui_range(prop, -100.0f, 100.0f, 0.1, 4);
	RNA_def_property_ui_text(prop, "Maximum Distance", "");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "use_double_sided", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", eForceFieldCacheModifier_Flag_DoubleSided);
	RNA_def_property_ui_text(prop, "Use Double Sided", "");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
}

static void rna_def_cache_modifier_shrink_wrap(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "ShrinkWrapCacheModifier", "CacheLibraryModifier");
	RNA_def_struct_sdna(srna, "ShrinkWrapCacheModifier");
	RNA_def_struct_ui_text(srna, "Shrink Wrap Cache Modifier", "");
	RNA_def_struct_ui_icon(srna, ICON_HAIR);
	
	prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "object");
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_CacheLibraryModifier_hair_object_poll");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Object", "Object whose cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "hair_system_index", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "hair_system");
	RNA_def_property_ui_text(prop, "Hair System Index", "Hair system cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "hair_system", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_funcs(prop, "rna_ShrinkWrapCacheModifier_hair_system_get", "rna_ShrinkWrapCacheModifier_hair_system_set", NULL, "rna_ShrinkWrapCacheModifier_hair_system_poll");
	RNA_def_property_struct_type(prop, "ParticleSystem");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Hair System", "Hair system cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "target", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "target");
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Target", "Mesh object to wrap onto");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "use_internal_target", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", eShrinkWrapCacheModifier_Flag_InternalTarget);
	RNA_def_property_ui_text(prop, "Use Internal Target", "Use a cached object from the group instead of an object in the scene");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
}

static void rna_def_cache_modifier_strands_key(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "StrandsKeyCacheModifier", "CacheLibraryModifier");
	RNA_def_struct_sdna(srna, "StrandsKeyCacheModifier");
	RNA_def_struct_ui_text(srna, "Strands Key Cache Modifier", "");
	RNA_def_struct_ui_icon(srna, ICON_SHAPEKEY_DATA);
	
	prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "object");
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_CacheLibraryModifier_hair_object_poll");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Object", "Object whose cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "hair_system_index", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "hair_system");
	RNA_def_property_ui_text(prop, "Hair System Index", "Hair system cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "hair_system", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_funcs(prop, "rna_StrandsKeyCacheModifier_hair_system_get", "rna_StrandsKeyCacheModifier_hair_system_set", NULL, "rna_StrandsKeyCacheModifier_hair_system_poll");
	RNA_def_property_struct_type(prop, "ParticleSystem");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Hair System", "Hair system cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	/* shape keys */
	prop = RNA_def_property(srna, "shape_keys", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "key");
	RNA_def_property_ui_text(prop, "Shape Keys", "");
	
	prop = RNA_def_property(srna, "use_motion_state", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", eStrandsKeyCacheModifier_Flag_UseMotionState);
	RNA_def_property_ui_text(prop, "Use Motion State", "Apply the shape key to the motion state instead of the base shape");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "show_only_shape_key", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", eStrandsKeyCacheModifier_Flag_ShapeLock);
	RNA_def_property_ui_text(prop, "Shape Key Lock", "Always show the current Shape for this Object");
	RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "active_shape_key", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "ShapeKey");
	RNA_def_property_pointer_funcs(prop, "rna_StrandsKeyCacheModifier_active_shape_key_get", NULL, NULL, NULL);
	RNA_def_property_ui_text(prop, "Active Shape Key", "Current shape key");
	
	prop = RNA_def_property(srna, "active_shape_key_index", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "shapenr");
	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); /* XXX this is really unpredictable... */
	RNA_def_property_int_funcs(prop, "rna_StrandsKeyCacheModifier_active_shape_key_index_get", "rna_StrandsKeyCacheModifier_active_shape_key_index_set",
	                           "rna_StrandsKeyCacheModifier_active_shape_key_index_range");
	RNA_def_property_ui_text(prop, "Active Shape Key Index", "Current shape key index");
	RNA_def_property_update(prop, 0, "rna_StrandsKeyCacheModifier_active_shape_update");
}

static void rna_def_cache_modifier_haircut(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	static EnumPropertyItem cut_mode_items[] = {
	    {eHaircutCacheModifier_CutMode_Enter, "ENTER", 0, "Enter", "Cut strands when entering the target mesh"},
	    {eHaircutCacheModifier_CutMode_Exit, "EXIT", 0, "Exit", "Cut strands when exiting the target mesh"},
	    {0, NULL, 0, NULL, NULL}
	};
	
	srna = RNA_def_struct(brna, "HaircutCacheModifier", "CacheLibraryModifier");
	RNA_def_struct_sdna(srna, "HaircutCacheModifier");
	RNA_def_struct_ui_text(srna, "Hair Cut Cache Modifier", "");
	RNA_def_struct_ui_icon(srna, ICON_HAIR);
	
	prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "object");
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_CacheLibraryModifier_hair_object_poll");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Object", "Object whose cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "hair_system_index", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "hair_system");
	RNA_def_property_ui_text(prop, "Hair System Index", "Hair system cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "hair_system", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_funcs(prop, "rna_HaircutCacheModifier_hair_system_get", "rna_HaircutCacheModifier_hair_system_set", NULL, "rna_HaircutCacheModifier_hair_system_poll");
	RNA_def_property_struct_type(prop, "ParticleSystem");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Hair System", "Hair system cache to simulate");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "target", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "target");
	RNA_def_property_struct_type(prop, "Object");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Target", "Mesh object to wrap onto");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "use_internal_target", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", eHaircutCacheModifier_Flag_InternalTarget);
	RNA_def_property_ui_text(prop, "Use Internal Target", "Use a cached object from the group instead of an object in the scene");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
	
	prop = RNA_def_property(srna, "cut_mode", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "cut_mode");
	RNA_def_property_enum_items(prop, cut_mode_items);
	RNA_def_property_flag(prop, PROP_ENUM_FLAG);
	RNA_def_property_ui_text(prop, "Cut Mode", "When to cut strands with the target");
	RNA_def_property_update(prop, 0, "rna_CacheModifier_update");
}

static void rna_def_cache_modifier(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "CacheLibraryModifier", NULL);
	RNA_def_struct_sdna(srna, "CacheModifier");
	RNA_def_struct_path_func(srna, "rna_CacheLibraryModifier_path");
	RNA_def_struct_refine_func(srna, "rna_CacheModifier_refine");
	RNA_def_struct_ui_text(srna, "Cache Modifier", "Cache Modifier");
	RNA_def_struct_ui_icon(srna, ICON_PHYSICS);
	
	prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "type");
	RNA_def_property_enum_items(prop, cache_modifier_type_items);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Type", "Type of the cache modifier");
	
	prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_CacheLibraryModifier_name_set");
	RNA_def_property_ui_text(prop, "Name", "Modifier name");
	RNA_def_property_update(prop, NC_ID | NA_RENAME, NULL);
	RNA_def_struct_name_property(srna, prop);
	
	rna_def_cache_modifier_hair_simulation(brna);
	rna_def_cache_modifier_force_field(brna);
	rna_def_cache_modifier_shrink_wrap(brna);
	rna_def_cache_modifier_strands_key(brna);
	rna_def_cache_modifier_haircut(brna);
}

static void rna_def_cache_library_modifiers(BlenderRNA *brna, PropertyRNA *cprop)
{
	StructRNA *srna;
	FunctionRNA *func;
	PropertyRNA *parm;
	
	RNA_def_property_srna(cprop, "CacheLibraryModifiers");
	srna = RNA_def_struct(brna, "CacheLibraryModifiers", NULL);
	RNA_def_struct_sdna(srna, "CacheLibrary");
	RNA_def_struct_ui_text(srna, "Cache Modifiers", "Collection of cache modifiers");
	
	/* add modifier */
	func = RNA_def_function(srna, "new", "rna_CacheLibrary_modifier_new");
	RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
	RNA_def_function_ui_description(func, "Add a new modifier");
	parm = RNA_def_string(func, "name", "Name", 0, "", "New name for the modifier");
	RNA_def_property_flag(parm, PROP_REQUIRED);
	/* modifier to add */
	parm = RNA_def_enum(func, "type", cache_modifier_type_items, 1, "", "Modifier type to add");
	RNA_def_property_flag(parm, PROP_REQUIRED);
	/* return type */
	parm = RNA_def_pointer(func, "modifier", "CacheLibraryModifier", "", "Newly created modifier");
	RNA_def_function_return(func, parm);
	
	/* remove modifier */
	func = RNA_def_function(srna, "remove", "rna_CacheLibrary_modifier_remove");
	RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
	RNA_def_function_ui_description(func, "Remove an existing modifier");
	/* modifier to remove */
	parm = RNA_def_pointer(func, "modifier", "CacheLibraryModifier", "", "Modifier to remove");
	RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
	RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
	
	/* clear all modifiers */
	func = RNA_def_function(srna, "clear", "rna_CacheLibrary_modifier_clear");
	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
	RNA_def_function_ui_description(func, "Remove all modifiers");
}

static void rna_def_cache_library(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	static EnumPropertyItem source_mode_items[] = {
	    {CACHE_LIBRARY_SOURCE_SCENE,    "SCENE",        0,      "Scene",        "Use generated scene data as source"},
	    {CACHE_LIBRARY_SOURCE_CACHE,    "CACHE",        0,      "Cache",        "Use cache data as source"},
	    {0, NULL, 0, NULL, NULL}
	};
	
	static EnumPropertyItem display_mode_items[] = {
	    {CACHE_LIBRARY_DISPLAY_SOURCE,  "SOURCE",       0,      "Source",       "Display source data unmodified"},
	    {CACHE_LIBRARY_DISPLAY_MODIFIERS, "MODIFIERS",  0,      "Modifiers",    "Display source data with modifiers applied"},
	    {CACHE_LIBRARY_DISPLAY_RESULT,  "RESULT",       0,      "Result",       "Display resulting data"},
	    {0, NULL, 0, NULL, NULL}
	};
	
	srna = RNA_def_struct(brna, "CacheLibrary", "ID");
	RNA_def_struct_ui_text(srna, "Cache Library", "Cache Library datablock for constructing an archive of caches");
	RNA_def_struct_ui_icon(srna, ICON_PHYSICS);
	
	prop = RNA_def_property(srna, "input_filepath", PROP_STRING, PROP_FILEPATH);
	RNA_def_property_string_sdna(prop, NULL, "input_filepath");
	RNA_def_property_ui_text(prop, "Input File Path", "Path to a cache archive for reading input");
	RNA_def_property_update(prop, 0, "rna_CacheLibrary_update");
	
	prop = RNA_def_property(srna, "output_filepath", PROP_STRING, PROP_FILEPATH);
	RNA_def_property_string_sdna(prop, NULL, "output_filepath");
	RNA_def_property_ui_text(prop, "Output File Path", "Path where cache output is written");
	RNA_def_property_update(prop, 0, "rna_CacheLibrary_update");
	
	prop = RNA_def_property(srna, "source_mode", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "source_mode");
	RNA_def_property_enum_items(prop, source_mode_items);
	RNA_def_property_ui_text(prop, "Source Mode", "Source of the cache library data");
	RNA_def_property_update(prop, 0, "rna_CacheLibrary_update");
	
	prop = RNA_def_property(srna, "display_mode", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "display_mode");
	RNA_def_property_enum_items(prop, display_mode_items);
	RNA_def_property_ui_text(prop, "Display Mode", "What data to display in the viewport");
	RNA_def_property_update(prop, 0, "rna_CacheLibrary_update");
	
	prop = RNA_def_property(srna, "display_motion", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "display_flag", CACHE_LIBRARY_DISPLAY_MOTION);
	RNA_def_property_ui_text(prop, "Display Motion", "Display motion state result from simulation, if available");
	RNA_def_property_update(prop, 0, "rna_CacheLibrary_update");
	
	prop = RNA_def_property(srna, "display_children", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "display_flag", CACHE_LIBRARY_DISPLAY_CHILDREN);
	RNA_def_property_ui_text(prop, "Display Children", "Display child strands, if available");
	RNA_def_property_update(prop, 0, "rna_CacheLibrary_update");
	
	prop = RNA_def_property(srna, "data_types", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_sdna(prop, NULL, "data_types");
	RNA_def_property_enum_items(prop, cache_library_data_type_items);
	RNA_def_property_flag(prop, PROP_ENUM_FLAG);
	RNA_def_property_ui_text(prop, "Data Types", "Types of data to store in the cache");
	
	prop = RNA_def_property(srna, "filter_group", PROP_POINTER, PROP_NONE);
	RNA_def_property_pointer_sdna(prop, NULL, "filter_group");
	RNA_def_property_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Filter Group", "If set, only objects in this group will be cached");
	
	prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
	RNA_def_property_ui_text(prop, "Description", "Description of the output archive");
	
	/* modifiers */
	prop = RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "CacheLibraryModifier");
	RNA_def_property_ui_text(prop, "Modifiers", "Modifiers applying to the cached data");
	rna_def_cache_library_modifiers(brna, prop);
	
	prop = RNA_def_property(srna, "archive_info", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "CacheArchiveInfo");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Archive Info", "Information about structure and contents of the archive");
}

static void rna_def_cache_archive_info_node(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	static EnumPropertyItem type_items[] = {
	    {eCacheArchiveInfoNode_Type_Object, "OBJECT", 0, "Object", "Structural object node forming the hierarchy"},
	    {eCacheArchiveInfoNode_Type_ScalarProperty, "SCALAR_PROPERTY", 0, "Scalar Property", "Property with a single value per sample"},
	    {eCacheArchiveInfoNode_Type_ArrayProperty, "ARRAY_PROPERTY", 0, "Array Property", "Array property with an arbitrary number of values per sample"},
	    {eCacheArchiveInfoNode_Type_CompoundProperty, "COMPOUND_PROPERTY", 0, "Compound Property", "Compound property containing other properties"},
	    {0, NULL, 0, NULL, NULL}
	};
	
	srna = RNA_def_struct(brna, "CacheArchiveInfoNode", NULL);
	RNA_def_struct_ui_text(srna, "Cache Archive Info Node", "Node in the structure of a cache archive");
	
	prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
	RNA_def_property_enum_items(prop, type_items);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Type", "Type of archive node");
	
	prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Name", "Name of the archive node");
	RNA_def_struct_name_property(srna, prop);
	
	prop = RNA_def_property(srna, "child_nodes", PROP_COLLECTION, PROP_NONE);
	RNA_def_property_struct_type(prop, "CacheArchiveInfoNode");
	RNA_def_property_ui_text(prop, "Child Nodes", "Nested archive nodes");
	
	prop = RNA_def_property(srna, "expand", PROP_BOOLEAN, PROP_NONE);
	RNA_def_property_boolean_sdna(prop, NULL, "flag", eCacheArchiveInfoNode_Flag_Expand);
	RNA_def_property_ui_text(prop, "Expand", "Show contents of the node");
	RNA_def_property_update(prop, 0, "rna_CacheArchiveInfo_update");
	
	/* XXX this is a 64bit integer, not supported nicely by RNA,
	 * but string encoding is sufficient for feedback
	 */
	prop = RNA_def_property(srna, "bytes_size", PROP_STRING, PROP_NONE);
	RNA_def_property_string_funcs(prop, "rna_CacheArchiveInfoNode_bytes_size_get", "rna_CacheArchiveInfoNode_bytes_size_length", NULL);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Bytes Size", "Overall size of the node data in bytes");
	
	prop = RNA_def_property(srna, "datatype", PROP_STRING, PROP_NONE);
	RNA_def_property_string_sdna(prop, NULL, "datatype_name");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Datatype", "Type of values stored in the property");
	
	prop = RNA_def_property(srna, "datatype_extent", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Datatype Extent", "Array extent of a single data element");
	
	prop = RNA_def_property(srna, "samples", PROP_INT, PROP_NONE);
	RNA_def_property_int_sdna(prop, NULL, "num_samples");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Samples", "Number of samples stored for the property");
	
	prop = RNA_def_property(srna, "array_size", PROP_INT, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Array Size", "Maximum array size for any sample of the property");
}

static void rna_def_cache_archive_info(BlenderRNA *brna)
{
	StructRNA *srna;
	PropertyRNA *prop;
	
	srna = RNA_def_struct(brna, "CacheArchiveInfo", NULL);
	RNA_def_struct_ui_text(srna, "Cache Archive Info", "Information about structure and contents of a cache file");
	
	prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "File Path", "Path to the cache archive");
	
	prop = RNA_def_property(srna, "app_name", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Application", "Name of the application that created the archive");
	
	prop = RNA_def_property(srna, "date_written", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Date", "Date and time when the archive was created");
	
	prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Description", "Description of the archive");
	
	prop = RNA_def_property(srna, "root_node", PROP_POINTER, PROP_NONE);
	RNA_def_property_struct_type(prop, "CacheArchiveInfoNode");
	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
	RNA_def_property_ui_text(prop, "Root Node", "Root node of the archive");
}

void RNA_def_cache_library(BlenderRNA *brna)
{
	rna_def_cache_modifier(brna);
	rna_def_cache_library(brna);
	rna_def_cache_archive_info_node(brna);
	rna_def_cache_archive_info(brna);
}

#endif