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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Susano Pinto <andresusanopinto@gmail.com>2009-07-02 15:28:42 +0400
committerAndre Susano Pinto <andresusanopinto@gmail.com>2009-07-02 15:28:42 +0400
commitb14298f959180762c3bbf31d42a747e55ca48494 (patch)
treeff955d0aed045954f3de3c33066fff6a96c94a7f /source/blender/blenkernel
parent2acac0ff997832f5a1b25fdaf36321a6e5d7c771 (diff)
svn merge -r 21041:21301 https://svn.blender.org/svnroot/bf-blender/branches/blender2.5/blender
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_cloth.h5
-rw-r--r--source/blender/blenkernel/BKE_context.h3
-rw-r--r--source/blender/blenkernel/BKE_exotic.h1
-rw-r--r--source/blender/blenkernel/BKE_gpencil.h2
-rw-r--r--source/blender/blenkernel/BKE_material.h15
-rw-r--r--source/blender/blenkernel/BKE_packedFile.h54
-rw-r--r--source/blender/blenkernel/BKE_particle.h7
-rw-r--r--source/blender/blenkernel/BKE_pointcache.h57
-rw-r--r--source/blender/blenkernel/BKE_report.h7
-rw-r--r--source/blender/blenkernel/BKE_sequence.h2
-rw-r--r--source/blender/blenkernel/BKE_utildefines.h8
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c4
-rw-r--r--source/blender/blenkernel/intern/blender.c1
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c2
-rw-r--r--source/blender/blenkernel/intern/cloth.c164
-rw-r--r--source/blender/blenkernel/intern/constraint.c8
-rw-r--r--source/blender/blenkernel/intern/context.c24
-rw-r--r--source/blender/blenkernel/intern/depsgraph.c20
-rw-r--r--source/blender/blenkernel/intern/displist.c36
-rw-r--r--source/blender/blenkernel/intern/effect.c2
-rw-r--r--source/blender/blenkernel/intern/exotic.c594
-rw-r--r--source/blender/blenkernel/intern/fluidsim.c2
-rw-r--r--source/blender/blenkernel/intern/font.c8
-rw-r--r--source/blender/blenkernel/intern/gpencil.c2
-rw-r--r--source/blender/blenkernel/intern/idprop.c8
-rw-r--r--source/blender/blenkernel/intern/image.c6
-rw-r--r--source/blender/blenkernel/intern/implicit.c10
-rw-r--r--source/blender/blenkernel/intern/material.c4
-rw-r--r--source/blender/blenkernel/intern/modifier.c29
-rw-r--r--source/blender/blenkernel/intern/multires.c6
-rw-r--r--source/blender/blenkernel/intern/packedFile.c227
-rw-r--r--source/blender/blenkernel/intern/particle.c99
-rw-r--r--source/blender/blenkernel/intern/particle_system.c200
-rw-r--r--source/blender/blenkernel/intern/pointcache.c896
-rw-r--r--source/blender/blenkernel/intern/report.c6
-rw-r--r--source/blender/blenkernel/intern/scene.c9
-rw-r--r--source/blender/blenkernel/intern/sequence.c2
37 files changed, 1471 insertions, 1059 deletions
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index e09be838f06..4270c677338 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -46,6 +46,7 @@
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "BKE_collision.h"
@@ -245,8 +246,8 @@ void bvhtree_update_from_cloth ( ClothModifierData *clmd, int moving );
void bvhselftree_update_from_cloth ( ClothModifierData *clmd, int moving );
// needed for editmesh.c
-void cloth_write_cache ( Object *ob, ClothModifierData *clmd, float framenr );
-int cloth_read_cache ( Object *ob, ClothModifierData *clmd, float framenr );
+void cloth_write_cache( Object *ob, ClothModifierData *clmd, int framenr );
+int cloth_read_cache( Scene *scene, Object *ob, ClothModifierData *clmd, float framenr, int *old_framenr );
// needed for button_object.c
void cloth_clear_cache ( Object *ob, ClothModifierData *clmd, float framenr );
diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index 1845665a96d..f536e117b7b 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -1,5 +1,5 @@
/**
- * $Id: BKE_context.h 21247 2009-06-29 21:50:53Z jaguarandi $
+ * $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -131,6 +131,7 @@ void CTX_wm_menu_set(bContext *C, struct ARegion *menu);
- the dir listbase consits of LinkData items */
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member);
+PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type);
ListBase CTX_data_collection_get(const bContext *C, const char *member);
ListBase CTX_data_dir_get(const bContext *C);
void CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb);
diff --git a/source/blender/blenkernel/BKE_exotic.h b/source/blender/blenkernel/BKE_exotic.h
index 11dc1f41109..5c47eeabfe8 100644
--- a/source/blender/blenkernel/BKE_exotic.h
+++ b/source/blender/blenkernel/BKE_exotic.h
@@ -47,7 +47,6 @@ int BKE_read_exotic(struct Scene *scene, char *name);
void write_dxf(struct Scene *scene, char *str);
void write_vrml(struct Scene *scene, char *str);
-void write_videoscape(struct Scene *scene, char *str);
void write_stl(struct Scene *scene, char *str);
#endif
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 581285be21c..1892c8e71a4 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -1,5 +1,5 @@
/**
- * $Id: BDR_gpencil.h 19541 2009-04-05 06:54:47Z aligorith $
+ * $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index 38a1d9b13b7..382754ee2b2 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -39,6 +39,8 @@ struct Material;
struct ID;
struct Object;
+/* materials */
+
void init_def_material(void);
void free_material(struct Material *sc);
void test_object_materials(struct ID *id);
@@ -47,15 +49,22 @@ struct Material *add_material(char *name);
struct Material *copy_material(struct Material *ma);
void make_local_material(struct Material *ma);
+void automatname(struct Material *);
+
+/* material slots */
+
struct Material ***give_matarar(struct Object *ob);
short *give_totcolp(struct Object *ob);
struct Material *give_current_material(struct Object *ob, int act);
struct ID *material_from(struct Object *ob, int act);
void assign_material(struct Object *ob, struct Material *ma, int act);
-void new_material_to_objectdata(struct Object *ob);
int find_material_index(struct Object *ob, struct Material *ma);
+void object_add_material_slot(struct Object *ob);
+void object_remove_material_slot(struct Object *ob);
+
+/* rendering */
void init_render_material(struct Material *, int, float *);
void init_render_materials(int, float *);
@@ -64,12 +73,8 @@ void end_render_materials(void);
int material_in_material(struct Material *parmat, struct Material *mat);
-void automatname(struct Material *);
-void delete_material_index(struct Object *ob);
-
void ramp_blend(int type, float *r, float *g, float *b, float fac, float *col);
-
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_packedFile.h b/source/blender/blenkernel/BKE_packedFile.h
index 2d5acc51b7b..efd930d375a 100644
--- a/source/blender/blenkernel/BKE_packedFile.h
+++ b/source/blender/blenkernel/BKE_packedFile.h
@@ -31,31 +31,43 @@
#ifndef BKE_PACKEDFILE_H
#define BKE_PACKEDFILE_H
-#define RET_OK 0
-#define RET_ERROR 1
+#define RET_OK 0
+#define RET_ERROR 1
-struct PackedFile;
-struct VFont;
struct bSample;
struct bSound;
struct Image;
+struct Main;
+struct PackedFile;
+struct ReportList;
+struct VFont;
+
+/* pack */
+struct PackedFile *newPackedFile(struct ReportList *reports, char *filename);
+struct PackedFile *newPackedFileMemory(void *mem, int memlen);
+
+void packAll(struct Main *bmain, struct ReportList *reports);
+
+/* unpack */
+char *unpackFile(struct ReportList *reports, char *abs_name, char *local_name, struct PackedFile *pf, int how);
+int unpackVFont(struct ReportList *reports, struct VFont *vfont, int how);
+int unpackSample(struct ReportList *reports, struct bSample *sample, int how);
+int unpackImage(struct ReportList *reports, struct Image *ima, int how);
+void unpackAll(struct Main *bmain, struct ReportList *reports, int how);
+
+int writePackedFile(struct ReportList *reports, char *filename, struct PackedFile *pf, int guimode);
+
+/* free */
+void freePackedFile(struct PackedFile *pf);
+
+/* info */
+int countPackedFiles(struct Main *bmain);
+int checkPackedFile(char *filename, struct PackedFile *pf);
+
+/* read */
+int seekPackedFile(struct PackedFile *pf, int offset, int whence);
+void rewindPackedFile(struct PackedFile *pf);
+int readPackedFile(struct PackedFile *pf, void *data, int size);
-struct PackedFile * newPackedFile(char * filename);
-struct PackedFile * newPackedFileMemory(void *mem, int memlen);
-
-int seekPackedFile(struct PackedFile * pf, int offset, int whence);
-void rewindPackedFile(struct PackedFile * pf);
-int readPackedFile(struct PackedFile * pf, void * data, int size);
-int countPackedFiles(void);
-void freePackedFile(struct PackedFile * pf);
-void packAll(void);
-int writePackedFile(char * filename, struct PackedFile *pf, int guimode);
-int checkPackedFile(char * filename, struct PackedFile * pf);
-char * unpackFile(char * abs_name, char * local_name, struct PackedFile * pf, int how);
-int unpackVFont(struct VFont * vfont, int how);
-int unpackSample(struct bSample *sample, int how);
-int unpackImage(struct Image * ima, int how);
-void unpackAll(int how);
-
#endif
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 4efd9a7f8ba..73f0195d1d8 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -217,6 +217,8 @@ char *psys_menu_string(struct Object *ob, int for_sb);
struct ParticleSystem *psys_get_current(struct Object *ob);
short psys_get_current_num(struct Object *ob);
+void psys_set_current_num(Object *ob, int index);
+struct Object *psys_find_object(struct Scene *scene, struct ParticleSystem *psys);
//struct ParticleSystem *psys_get(struct Object *ob, int index);
struct ParticleData *psys_get_selected_particle(struct ParticleSystem *psys, int *index);
struct ParticleKey *psys_get_selected_key(struct ParticleSystem *psys, int pa_index, int *key_index);
@@ -249,6 +251,8 @@ void copy_particle_key(struct ParticleKey *to, struct ParticleKey *from, int tim
void psys_particle_on_emitter(struct ParticleSystemModifierData *psmd, int distr, int index, int index_dmcache, float *fuv, float foffset, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor);
struct ParticleSystemModifierData *psys_get_modifier(struct Object *ob, struct ParticleSystem *psys);
+void object_add_particle_system(struct Scene *scene, struct Object *ob);
+void object_remove_particle_system(struct Scene *scene, struct Object *ob);
struct ParticleSettings *psys_new_settings(char *name, struct Main *main);
struct ParticleSettings *psys_copy_settings(struct ParticleSettings *part);
void psys_flush_particle_settings(struct Scene *scene, struct ParticleSettings *part, int recalc);
@@ -290,10 +294,13 @@ void psys_get_reactor_target(struct Object *ob, struct ParticleSystem *psys, str
void psys_init_effectors(struct Scene *scene, struct Object *obsrc, struct Group *group, struct ParticleSystem *psys);
void psys_end_effectors(struct ParticleSystem *psys);
+void psys_get_pointcache_start_end(struct Scene *scene, struct ParticleSystem *psys, int *sfra, int *efra);
+
void particle_system_update(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
/* ----------- functions needed only inside particlesystem ------------ */
/* particle.c */
+void psys_interpolate_particle(short type, struct ParticleKey keys[4], float dt, struct ParticleKey *result, int velocity);
void psys_key_to_object(struct Object *ob, struct ParticleKey *key, float imat[][4]);
//void psys_key_to_geometry(struct DerivedMesh *dm, struct ParticleData *pa, struct ParticleKey *key);
//void psys_key_from_geometry(struct DerivedMesh *dm, struct ParticleData *pa, struct ParticleKey *key);
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index 8ef3ff4d4b7..3f1c45d28ec 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -31,6 +31,8 @@
#include "DNA_ID.h"
+#include "MEM_guardedalloc.h"
+
/* Point cache clearing option, for BKE_ptcache_id_clear, before
* and after are non inclusive (they wont remove the cfra) */
#define PTCACHE_CLEAR_ALL 0
@@ -42,6 +44,7 @@
#define PTCACHE_RESET_DEPSGRAPH 0
#define PTCACHE_RESET_BAKED 1
#define PTCACHE_RESET_OUTDATED 2
+#define PTCACHE_RESET_FREE 3
/* Add the blendfile name after blendcache_ */
#define PTCACHE_EXT ".bphys"
@@ -56,6 +59,11 @@
#define PTCACHE_TYPE_PARTICLES 1
#define PTCACHE_TYPE_CLOTH 2
+/* PTCache read return code */
+#define PTCACHE_READ_EXACT 1
+#define PTCACHE_READ_INTERPOLATED 2
+#define PTCACHE_READ_OLD 3
+
/* Structs */
struct Object;
struct Scene;
@@ -80,6 +88,40 @@ typedef struct PTCacheID {
struct PointCache *cache;
} PTCacheID;
+typedef struct PTCacheWriter {
+ struct PTCacheID *pid;
+ int cfra;
+ int totelem;
+
+ void (*set_elem)(int index, void *calldata, float *data);
+ void *calldata;
+} PTCacheWriter;
+
+typedef struct PTCacheReader {
+ struct Scene *scene;
+ struct PTCacheID *pid;
+ float cfra;
+ int totelem;
+
+ void (*set_elem)(int elem_index, void *calldata, float *data);
+ void (*interpolate_elem)(int index, void *calldata, float frs_sec, float cfra, float cfra1, float cfra2, float *data1, float *data2);
+ void *calldata;
+
+ int *old_frame;
+} PTCacheReader;
+
+typedef struct PTCacheBaker {
+ struct Scene *scene;
+ int bake;
+ int render;
+ int quick_step;
+ struct PTCacheID *pid;
+ int (*break_test)(void *data);
+ void *break_data;
+ void (*progressbar)(void *data, int num);
+ void *progresscontext;
+} PTCacheBaker;
+
/* Creating ID's */
void BKE_ptcache_id_from_softbody(PTCacheID *pid, struct Object *ob, struct SoftBody *sb);
void BKE_ptcache_id_from_particles(PTCacheID *pid, struct Object *ob, struct ParticleSystem *psys);
@@ -93,9 +135,9 @@ void BKE_ptcache_remove(void);
/* ID specific functions */
void BKE_ptcache_id_clear(PTCacheID *id, int mode, int cfra);
int BKE_ptcache_id_exist(PTCacheID *id, int cfra);
-int BKE_ptcache_id_reset(PTCacheID *id, int mode);
+int BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *id, int mode);
void BKE_ptcache_id_time(PTCacheID *pid, struct Scene *scene, float cfra, int *startframe, int *endframe, float *timescale);
-int BKE_ptcache_object_reset(struct Object *ob, int mode);
+int BKE_ptcache_object_reset(struct Scene *scene, struct Object *ob, int mode);
/* File reading/writing */
PTCacheFile *BKE_ptcache_file_open(PTCacheID *id, int mode, int cfra);
@@ -103,6 +145,12 @@ void BKE_ptcache_file_close(PTCacheFile *pf);
int BKE_ptcache_file_read_floats(PTCacheFile *pf, float *f, int tot);
int BKE_ptcache_file_write_floats(PTCacheFile *pf, float *f, int tot);
+void BKE_ptcache_update_info(PTCacheID *pid);
+
+/* General cache reading/writing */
+int BKE_ptcache_read_cache(PTCacheReader *reader);
+int BKE_ptcache_write_cache(PTCacheWriter *writer);
+
/* Continue physics */
void BKE_ptcache_set_continue_physics(struct Scene *scene, int enable);
int BKE_ptcache_get_continue_physics(void);
@@ -112,4 +160,9 @@ struct PointCache *BKE_ptcache_add(void);
void BKE_ptcache_free(struct PointCache *cache);
struct PointCache *BKE_ptcache_copy(struct PointCache *cache);
+/* Baking */
+void BKE_ptcache_quick_cache_all(struct Scene *scene);
+void BKE_ptcache_make_cache(struct PTCacheBaker* baker);
+void BKE_ptcache_toggle_disk_cache(struct PTCacheID *pid);
+
#endif
diff --git a/source/blender/blenkernel/BKE_report.h b/source/blender/blenkernel/BKE_report.h
index 60e48004fb1..1bb7152fbf3 100644
--- a/source/blender/blenkernel/BKE_report.h
+++ b/source/blender/blenkernel/BKE_report.h
@@ -1,5 +1,5 @@
/**
- * $Id: BKE_report.h 21247 2009-06-29 21:50:53Z jaguarandi $
+ * $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -34,7 +34,10 @@ extern "C" {
#include "DNA_listBase.h"
-/* Reporting Information and Errors */
+/* Reporting Information and Errors
+ *
+ * These functions also accept NULL in case no error reporting
+ * is needed. */
typedef enum ReportType {
RPT_DEBUG = 0,
diff --git a/source/blender/blenkernel/BKE_sequence.h b/source/blender/blenkernel/BKE_sequence.h
index 93f68f00d2f..65a3b0216fe 100644
--- a/source/blender/blenkernel/BKE_sequence.h
+++ b/source/blender/blenkernel/BKE_sequence.h
@@ -1,5 +1,5 @@
/**
- * $Id: BKE_sequence.h 21247 2009-06-29 21:50:53Z jaguarandi $
+ * $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
diff --git a/source/blender/blenkernel/BKE_utildefines.h b/source/blender/blenkernel/BKE_utildefines.h
index 6584af085cd..419f0f5beeb 100644
--- a/source/blender/blenkernel/BKE_utildefines.h
+++ b/source/blender/blenkernel/BKE_utildefines.h
@@ -130,7 +130,7 @@
#define IN_RANGE(a, b, c) ((b < c)? ((b<a && a<c)? 1:0) : ((c<a && a<b)? 1:0))
/* this weirdo pops up in two places ... */
-#if !defined(WIN32) && !defined(__BeOS)
+#if !defined(WIN32)
#ifndef O_BINARY
#define O_BINARY 0
#endif
@@ -148,12 +148,6 @@
#define ID_NEW(a) if( (a) && (a)->id.newid ) (a)= (void *)(a)->id.newid
#define FORM MAKE_ID('F','O','R','M')
-#define DDG1 MAKE_ID('3','D','G','1')
-#define DDG2 MAKE_ID('3','D','G','2')
-#define DDG3 MAKE_ID('3','D','G','3')
-#define DDG4 MAKE_ID('3','D','G','4')
-
-#define GOUR MAKE_ID('G','O','U','R')
#define BLEN MAKE_ID('B','L','E','N')
#define DER_ MAKE_ID('D','E','R','_')
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index 30dcb383ef6..441e17f3318 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -43,6 +43,7 @@ static short id_has_animdata (ID *id)
case ID_OB:
case ID_CU:
case ID_KE:
+ case ID_PA:
case ID_MA: case ID_TE: case ID_NT:
case ID_LA: case ID_CA: case ID_WO:
case ID_SCE:
@@ -883,6 +884,9 @@ void BKE_animsys_evaluate_all_animation (Main *main, float ctime)
/* meshes */
// TODO...
+ /* particles */
+ EVAL_ANIM_IDS(main->particle.first, ADT_RECALC_ANIM);
+
/* objects */
/* ADT_RECALC_ANIM doesn't need to be supplied here, since object AnimData gets
* this tagged by Depsgraph on framechange
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 5fc7d18689d..d3d21018c1c 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -221,7 +221,6 @@ static void clear_global(void)
{
// extern short winqueue_break; /* screen.c */
-// XXX freeAllRad();
fastshade_free_render(); /* lamps hang otherwise */
free_main(G.main); /* free all lib data */
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 57ef920f75b..706eece108c 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -1220,7 +1220,7 @@ void CDDM_calc_edges(DerivedMesh *dm)
BLI_edgehashIterator_free(ehi);
/* free old CustomData and assign new one */
- CustomData_free(&dm->edgeData, dm->numVertData);
+ CustomData_free(&dm->edgeData, dm->numEdgeData);
dm->edgeData = edgeData;
dm->numEdgeData = numEdges;
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index e98d7bb01a4..08caea565aa 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -33,6 +33,7 @@
#include "DNA_mesh_types.h"
#include "DNA_object_force.h"
#include "DNA_scene_types.h"
+#include "DNA_particle_types.h"
#include "BKE_deform.h"
#include "BKE_DerivedMesh.h"
@@ -42,6 +43,7 @@
#include "BKE_object.h"
#include "BKE_modifier.h"
#include "BKE_utildefines.h"
+#include "BKE_particle.h"
#include "BKE_pointcache.h"
@@ -339,78 +341,99 @@ void bvhselftree_update_from_cloth(ClothModifierData *clmd, int moving)
}
int modifiers_indexInObject(Object *ob, ModifierData *md_seek);
+static void cloth_write_state(int index, Cloth *cloth, float *data)
+{
+ ClothVertex *vert = cloth->verts + index;
-int cloth_read_cache(Object *ob, ClothModifierData *clmd, float framenr)
+ memcpy(data, vert->x, 3 * sizeof(float));
+ memcpy(data + 3, vert->xconst, 3 * sizeof(float));
+ memcpy(data + 6, vert->v, 3 * sizeof(float));
+}
+static void cloth_read_state(int index, Cloth *cloth, float *data)
{
- PTCacheID pid;
- PTCacheFile *pf;
- Cloth *cloth = clmd->clothObject;
- unsigned int a, ret = 1;
+ ClothVertex *vert = cloth->verts + index;
- if(!cloth)
- return 0;
-
- BKE_ptcache_id_from_cloth(&pid, ob, clmd);
- pf = BKE_ptcache_file_open(&pid, PTCACHE_FILE_READ, framenr);
- if(pf) {
- for(a = 0; a < cloth->numverts; a++) {
- if(!BKE_ptcache_file_read_floats(pf, cloth->verts[a].x, 3)) {
- ret = 0;
- break;
- }
- if(!BKE_ptcache_file_read_floats(pf, cloth->verts[a].xconst, 3)) {
- ret = 0;
- break;
- }
- if(!BKE_ptcache_file_read_floats(pf, cloth->verts[a].v, 3)) {
- ret = 0;
- break;
- }
- }
-
- BKE_ptcache_file_close(pf);
- }
- else
- ret = 0;
-
- return ret;
+ memcpy(vert->x, data, 3 * sizeof(float));
+ memcpy(vert->xconst, data + 3, 3 * sizeof(float));
+ memcpy(vert->v, data + 6, 3 * sizeof(float));
}
+static void cloth_cache_interpolate(int index, Cloth *cloth, float frs_sec, float cfra, float cfra1, float cfra2, float *data1, float *data2)
+{
+ ClothVertex *vert = cloth->verts + index;
+ ParticleKey keys[4];
+ float dfra;
-void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
+ if(cfra1 == cfra2) {
+ cloth_read_state(index, cloth, data1);
+ return;
+ }
+
+ memcpy(keys[1].co, data1, 3 * sizeof(float));
+ memcpy(keys[1].vel, data1 + 6, 3 * sizeof(float));
+
+ memcpy(keys[2].co, data2, 3 * sizeof(float));
+ memcpy(keys[2].vel, data2 + 6, 3 * sizeof(float));
+
+ dfra = cfra2 - cfra1;
+
+ VecMulf(keys[1].vel, dfra);
+ VecMulf(keys[2].vel, dfra);
+
+ psys_interpolate_particle(-1, keys, (cfra - cfra1) / dfra, keys, 1);
+
+ VecMulf(keys->vel, 1.0f / dfra);
+
+ memcpy(vert->x, keys->co, 3 * sizeof(float));
+ memcpy(vert->v, keys->vel, 3 * sizeof(float));
+
+ /* not sure what to do with this - jahka */
+ memcpy(vert->xconst, data1 + 3, 3 * sizeof(float));
+}
+void cloth_write_cache(Object *ob, ClothModifierData *clmd, int cfra)
{
+ PTCacheWriter writer;
PTCacheID pid;
-
+
BKE_ptcache_id_from_cloth(&pid, ob, clmd);
- // don't do anything as long as we're in editmode!
- if(pid.cache->flag & PTCACHE_BAKE_EDIT_ACTIVE)
- return;
-
- BKE_ptcache_id_clear(&pid, PTCACHE_CLEAR_AFTER, framenr);
+ writer.calldata = clmd->clothObject;
+ writer.cfra = cfra;
+ writer.set_elem = cloth_write_state;
+ writer.pid = &pid;
+ writer.totelem = clmd->clothObject->numverts;
+
+ BKE_ptcache_write_cache(&writer);
}
-void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr)
+int cloth_read_cache(Scene *scene, Object *ob, ClothModifierData *clmd, float cfra, int *old_framenr)
{
- Cloth *cloth = clmd->clothObject;
+ PTCacheReader reader;
PTCacheID pid;
- PTCacheFile *pf;
- unsigned int a;
- if(!cloth)
- return;
+ BKE_ptcache_id_from_cloth(&pid, ob, clmd);
+
+ reader.calldata = clmd->clothObject;
+ reader.cfra = cfra;
+ reader.interpolate_elem = cloth_cache_interpolate;
+ reader.old_frame = old_framenr;
+ reader.pid = &pid;
+ reader.scene = scene;
+ reader.set_elem = cloth_read_state;
+ reader.totelem = clmd->clothObject->numverts;
+
+ return BKE_ptcache_read_cache(&reader);
+}
+void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
+{
+ PTCacheID pid;
BKE_ptcache_id_from_cloth(&pid, ob, clmd);
- pf = BKE_ptcache_file_open(&pid, PTCACHE_FILE_WRITE, framenr);
- if(!pf)
+
+ // don't do anything as long as we're in editmode!
+ if(pid.cache->flag & PTCACHE_BAKE_EDIT_ACTIVE)
return;
- for(a = 0; a < cloth->numverts; a++) {
- BKE_ptcache_file_write_floats(pf, cloth->verts[a].x, 3);
- BKE_ptcache_file_write_floats(pf, cloth->verts[a].xconst, 3);
- BKE_ptcache_file_write_floats(pf, cloth->verts[a].v, 3);
- }
-
- BKE_ptcache_file_close(pf);
+ BKE_ptcache_id_clear(&pid, PTCACHE_CLEAR_AFTER, framenr);
}
static int do_init_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *result, int framenr)
@@ -486,6 +509,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
PTCacheID pid;
float timescale;
int framedelta, framenr, startframe, endframe;
+ int cache_result, old_framenr;
clmd->scene= scene; /* nice to pass on later :) */
framenr= (int)scene->r.cfra;
@@ -499,6 +523,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
if(!result) {
cache->flag &= ~PTCACHE_SIMULATION_VALID;
cache->simframe= 0;
+ cache->last_exact= 0;
return dm;
}
@@ -510,6 +535,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
if(result->getNumVerts(result) != clmd->clothObject->numverts) {
cache->flag &= ~PTCACHE_SIMULATION_VALID;
cache->simframe= 0;
+ cache->last_exact= 0;
return result;
}
}
@@ -521,6 +547,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
if(BKE_ptcache_get_continue_physics()) {
cache->flag &= ~PTCACHE_SIMULATION_VALID;
cache->simframe= 0;
+ cache->last_exact= 0;
/* do simulation */
if(!do_init_cloth(ob, clmd, result, framenr))
@@ -536,6 +563,7 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
if(framenr < startframe) {
cache->flag &= ~PTCACHE_SIMULATION_VALID;
cache->simframe= 0;
+ cache->last_exact= 0;
return result;
}
else if(framenr > endframe) {
@@ -552,7 +580,9 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
return result;
/* try to read from cache */
- if(cloth_read_cache(ob, clmd, framenr)) {
+ cache_result = cloth_read_cache(scene, ob, clmd, framenr, &old_framenr);
+
+ if(cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
cache->flag |= PTCACHE_SIMULATION_VALID;
cache->simframe= framenr;
@@ -561,25 +591,40 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
return result;
}
+ else if(cache_result==PTCACHE_READ_OLD) {
+ BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_FREE);
+
+ implicit_set_positions(clmd);
+
+ cache->flag |= PTCACHE_SIMULATION_VALID;
+ cache->simframe= old_framenr;
+ }
else if(ob->id.lib || (cache->flag & PTCACHE_BAKED)) {
/* if baked and nothing in cache, do nothing */
cache->flag &= ~PTCACHE_SIMULATION_VALID;
cache->simframe= 0;
+ cache->last_exact= 0;
return result;
}
if(framenr == startframe) {
+ if(cache->flag & PTCACHE_REDO_NEEDED) {
+ BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
+ do_init_cloth(ob, clmd, result, framenr);
+ }
cache->flag |= PTCACHE_SIMULATION_VALID;
cache->simframe= framenr;
/* don't write cache on first frame, but on second frame write
* cache for frame 1 and 2 */
}
- else if(framedelta == 1) {
+ else {
/* if on second frame, write cache for first frame */
- if(framenr == startframe+1)
+ if(cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
cloth_write_cache(ob, clmd, startframe);
+ clmd->sim_parms->timescale *= framenr - cache->simframe;
+
/* do simulation */
cache->flag |= PTCACHE_SIMULATION_VALID;
cache->simframe= framenr;
@@ -587,16 +632,13 @@ DerivedMesh *clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob,
if(!do_step_cloth(ob, clmd, result, framenr)) {
cache->flag &= ~PTCACHE_SIMULATION_VALID;
cache->simframe= 0;
+ cache->last_exact= 0;
}
else
cloth_write_cache(ob, clmd, framenr);
cloth_to_object (ob, clmd, result);
}
- else {
- cache->flag &= ~PTCACHE_SIMULATION_VALID;
- cache->simframe= 0;
- }
return result;
}
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index a43389a2ef6..88e73a00ba7 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -3028,7 +3028,7 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
if (VALID_CONS_TARGET(ct)) {
float loc[3], eul[3], size[3];
float dvec[3], sval[3];
- short i;
+ int i;
/* obtain target effect */
switch (data->from) {
@@ -3075,7 +3075,7 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
switch (data->to) {
case 2: /* scaling */
for (i=0; i<3; i++)
- size[i]= data->to_min[i] + (sval[data->map[i]] * (data->to_max[i] - data->to_min[i]));
+ size[i]= data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i]));
break;
case 1: /* rotation */
for (i=0; i<3; i++) {
@@ -3085,7 +3085,7 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
tmax= data->to_max[i];
/* all values here should be in degrees */
- eul[i]= tmin + (sval[data->map[i]] * (tmax - tmin));
+ eul[i]= tmin + (sval[(int)data->map[i]] * (tmax - tmin));
/* now convert final value back to radians */
eul[i] = (float)(eul[i] / 180 * M_PI);
@@ -3094,7 +3094,7 @@ static void transform_evaluate (bConstraint *con, bConstraintOb *cob, ListBase *
default: /* location */
/* get new location */
for (i=0; i<3; i++)
- loc[i]= (data->to_min[i] + (sval[data->map[i]] * (data->to_max[i] - data->to_min[i])));
+ loc[i]= (data->to_min[i] + (sval[(int)data->map[i]] * (data->to_max[i] - data->to_min[i])));
/* add original location back on (so that it can still be moved) */
VecAddf(loc, cob->matrix[3], loc);
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 6afbcf4950c..fbad585d9b7 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -1,5 +1,5 @@
/**
- * $Id: context.c 21247 2009-06-29 21:50:53Z jaguarandi $
+ * $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -358,6 +358,9 @@ static int ctx_data_collection_get(const bContext *C, const char *member, ListBa
return 1;
}
+ list->first= NULL;
+ list->last= NULL;
+
return 0;
}
@@ -365,15 +368,20 @@ PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
{
bContextDataResult result;
- if(ctx_data_get((bContext*)C, member, &result)) {
+ if(ctx_data_get((bContext*)C, member, &result))
return result.ptr;
- }
- else {
- PointerRNA ptr;
- memset(&ptr, 0, sizeof(ptr));
- return ptr;
- }
+ else
+ return PointerRNA_NULL;
+}
+
+PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
+{
+ PointerRNA ptr = CTX_data_pointer_get(C, member);
+ if(ptr.data && ptr.type == type)
+ return ptr;
+
+ return PointerRNA_NULL;
}
ListBase CTX_data_collection_get(const bContext *C, const char *member)
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index 8bb34bde122..a36b825293e 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -559,7 +559,7 @@ static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, O
dag_add_relation(dag, node, node, DAG_RL_OB_DATA, "Particle-Object Relation");
- if(psys->flag & PSYS_DISABLED || psys->flag & PSYS_DELETE)
+ if(!psys_check_enabled(ob, psys))
continue;
if(part->phystype==PART_PHYS_KEYED && psys->keyed_ob &&
@@ -1831,7 +1831,7 @@ static unsigned int flush_layer_node(Scene *sce, DagNode *node, int curtime)
}
/* node was checked to have lasttime != curtime , and is of type ID_OB */
-static void flush_pointcache_reset(DagNode *node, int curtime, int reset)
+static void flush_pointcache_reset(Scene *scene, DagNode *node, int curtime, int reset)
{
DagAdjList *itA;
Object *ob;
@@ -1844,13 +1844,13 @@ static void flush_pointcache_reset(DagNode *node, int curtime, int reset)
ob= (Object*)(node->ob);
if(reset || (ob->recalc & OB_RECALC)) {
- if(BKE_ptcache_object_reset(ob, PTCACHE_RESET_DEPSGRAPH))
+ if(BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH))
ob->recalc |= OB_RECALC_DATA;
- flush_pointcache_reset(itA->node, curtime, 1);
+ flush_pointcache_reset(scene, itA->node, curtime, 1);
}
else
- flush_pointcache_reset(itA->node, curtime, 0);
+ flush_pointcache_reset(scene, itA->node, curtime, 0);
}
}
}
@@ -1908,13 +1908,13 @@ void DAG_scene_flush_update(Scene *sce, unsigned int lay, int time)
ob= (Object*)(itA->node->ob);
if(ob->recalc & OB_RECALC) {
- if(BKE_ptcache_object_reset(ob, PTCACHE_RESET_DEPSGRAPH))
+ if(BKE_ptcache_object_reset(sce, ob, PTCACHE_RESET_DEPSGRAPH))
ob->recalc |= OB_RECALC_DATA;
- flush_pointcache_reset(itA->node, lasttime, 1);
+ flush_pointcache_reset(sce, itA->node, lasttime, 1);
}
else
- flush_pointcache_reset(itA->node, lasttime, 0);
+ flush_pointcache_reset(sce, itA->node, lasttime, 0);
}
}
}
@@ -2132,7 +2132,7 @@ void DAG_object_flush_update(Scene *sce, Object *ob, short flag)
if(ob==NULL || sce->theDag==NULL) return;
ob->recalc |= flag;
- BKE_ptcache_object_reset(ob, PTCACHE_RESET_DEPSGRAPH);
+ BKE_ptcache_object_reset(sce, ob, PTCACHE_RESET_DEPSGRAPH);
/* all users of this ob->data should be checked */
/* BUT! displists for curves are still only on cu */
@@ -2147,7 +2147,7 @@ void DAG_object_flush_update(Scene *sce, Object *ob, short flag)
for (obt=G.main->object.first; obt; obt= obt->id.next) {
if (obt != ob && obt->data==ob->data) {
obt->recalc |= OB_RECALC_DATA;
- BKE_ptcache_object_reset(obt, PTCACHE_RESET_DEPSGRAPH);
+ BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
}
}
}
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index 736165a8a98..cdf4b90cee1 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -315,13 +315,19 @@ static void init_fastshade_shadeinput(Render *re)
static Render *fastshade_get_render(Scene *scene)
{
- Render *re= RE_GetRender("_Shade View_");
- if(re==NULL) {
- re= RE_NewRender("_Shade View_");
-
- RE_Database_Baking(re, scene, 0, 0); /* 0= no faces */
+ /* XXX ugly global still, but we can't do preview while rendering */
+ if(G.rendering==0) {
+
+ Render *re= RE_GetRender("_Shade View_");
+ if(re==NULL) {
+ re= RE_NewRender("_Shade View_");
+
+ RE_Database_Baking(re, scene, 0, 0); /* 0= no faces */
+ }
+ return re;
}
- return re;
+
+ return NULL;
}
/* called on file reading */
@@ -611,18 +617,20 @@ static void mesh_create_shadedColors(Render *re, Object *ob, int onlyForMesh, un
void shadeMeshMCol(Scene *scene, Object *ob, Mesh *me)
{
+ Render *re= fastshade_get_render(scene);
int a;
char *cp;
unsigned int *mcol= (unsigned int*)me->mcol;
- Render *re= fastshade_get_render(scene);
- mesh_create_shadedColors(re, ob, 1, &mcol, NULL);
- me->mcol= (MCol*)mcol;
+ if(re) {
+ mesh_create_shadedColors(re, ob, 1, &mcol, NULL);
+ me->mcol= (MCol*)mcol;
- /* swap bytes */
- for(cp= (char *)me->mcol, a= 4*me->totface; a>0; a--, cp+=4) {
- SWAP(char, cp[0], cp[3]);
- SWAP(char, cp[1], cp[2]);
+ /* swap bytes */
+ for(cp= (char *)me->mcol, a= 4*me->totface; a>0; a--, cp+=4) {
+ SWAP(char, cp[0], cp[3]);
+ SWAP(char, cp[1], cp[2]);
+ }
}
}
@@ -641,6 +649,8 @@ void shadeDispList(Scene *scene, Base *base)
int a, need_orco;
re= fastshade_get_render(scene);
+ if(re==NULL)
+ return;
dl = find_displist(&ob->disp, DL_VERTCOL);
if (dl) {
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index 9858025af5a..eaa2d541638 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -29,6 +29,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
+#include "BLI_storage.h" /* _LARGEFILE_SOURCE */
+
#include <math.h>
#include <stdlib.h>
diff --git a/source/blender/blenkernel/intern/exotic.c b/source/blender/blenkernel/intern/exotic.c
index 929d3f942dc..4e7e76dfae3 100644
--- a/source/blender/blenkernel/intern/exotic.c
+++ b/source/blender/blenkernel/intern/exotic.c
@@ -27,48 +27,9 @@
*
* - Blender Foundation
*
- * ***** END GPL LICENSE BLOCK *****
- *
- * eigen videoscape formaat:
- *
- *
- * lamp:
- * 3DG2
- aantal_lampen
-
- type
- spsi spbl
- r, g, b, energy
- locx, locy, locz
- vecx, vecy, vecz
-
-
- curve / nurbs:
- 3DG3
- 5 of 11 (curve of surf)
- aantal_nurbs
- extr1 extr2
-
- mat[0][0] mat[0][1] mat[0][2] mat[0][3]
- mat[1][0] mat[1][1] mat[1][2] mat[1][3]
- ...
-
- type
- pntsu, pntsv
- resolu, resolv
- orderu, orderv
- flagu, flagv
-
- (als type==nurb) x y z w
- x y z w
- ...
- (als type==bez) xyz xyz xyz h1 h2 h3
- xyz xyz xyz h1 h2 h3
- ...
- *
- *
- */
+ * ***** END GPL LICENSE BLOCK *****/
+#include "BLI_storage.h"
#include <ctype.h> /* isdigit, isspace */
#include <math.h>
@@ -482,385 +443,6 @@ static void read_stl_mesh_ascii(Scene *scene, char *str)
#undef STLREADLINE
#undef STLREADVERT
-static void read_videoscape_mesh(Scene *scene, char *str)
-{
- Object *ob;
- Mesh *me;
- MVert *mvert;
- MFace *mface;
- Material *ma;
- FILE *fp;
- float *vertdata, *vd, min[3], max[3], cent[3], ftemp;
- unsigned int color[32], col;
- int totcol, a, b, verts, tottria=0, totquad=0, totedge=0, poly, nr0, nr, first;
- int end;
- char s[50];
-
- fp= fopen(str, "rb");
- if(fp==NULL) {
- //XXX error("Can't read file");
- return;
- }
-
- fscanf(fp, "%40s", s);
-
- fscanf(fp, "%d\n", &verts);
- if(verts<=0) {
- fclose(fp);
- //XXX error("Read error");
- return;
- }
-
- if(verts>MESH_MAX_VERTS) {
- //XXX error("too many vertices");
- fclose(fp);
- return;
- }
-
- INIT_MINMAX(min, max);
- vd= vertdata= MEM_mallocN(sizeof(float)*3*verts, "videoscapelezer");
-
- for(a=0; a<verts; a++) {
- fscanf(fp, "%f %f %f", vd, vd+1, vd+2);
- DO_MINMAX(vd, min, max);
- vd+=3;
- }
-
- /* count faces and colors */
- for(a=0; a<32; a++) color[a]= 0;
- totcol= 0;
- end= 1;
- while(end>0) {
- end= fscanf(fp,"%d", &poly);
- if(end<=0) break;
-
- if(poly==3) tottria++;
- else if(poly==4) totquad++;
- else totedge+= poly;
-
- for(a=0;a<poly;a++) {
- end= fscanf(fp,"%d", &nr);
- if(end<=0) break;
- }
- if(end<=0) break;
-
- end= fscanf(fp,"%i\n", &col);
- col &= 0xF0F0F0;
- for(a=0; a<totcol; a++) {
- if(color[a]==col) break;
- }
- if(a>=totcol && totcol<32) {
- color[totcol]= col;
- totcol++;
- }
- }
-
- /* new object */
- ob= add_object(scene, OB_MESH);
- me= ob->data;
- me->totvert= verts;
- me->totface= totedge+tottria+totquad;
-
- me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC,
- NULL, me->totvert);
- me->mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC,
- NULL, me->totface);
-
- /* colors */
- if(totcol) {
- ob->mat= MEM_callocN(sizeof(void *)*totcol, "ob->mat");
- me->mat= MEM_callocN(sizeof(void *)*totcol, "me->mat");
- me->totcol= totcol;
- ob->totcol= (unsigned char) me->totcol;
- ob->actcol= 1;
- }
-
- /* materials */
- for(a=0; a<totcol; a++) {
- ma= G.main->mat.first;
- while(ma) {
- if(ma->mtex[0]==0) {
- col= rgb_to_cpack(ma->r, ma->g, ma->b);
- if(color[a]==col) {
- me->mat[a]= ma;
- ma->id.us++;
- break;
- }
- }
- ma= ma->id.next;
- }
- if(ma==0) {
- ma= add_material("ext");
- me->mat[a]= ma;
- cpack_to_rgb(color[a], cent, cent+1, cent+2);
- ma->r= cent[0];
- ma->g= cent[1];
- ma->b= cent[2];
- automatname(ma);
- }
- }
-
- /* verts */
-
- cent[0]= (min[0]+max[0])/2.0f;
- cent[1]= (min[1]+max[1])/2.0f;
- cent[2]= (min[2]+max[2])/2.0f;
- VECCOPY(ob->loc, cent);
-
- a= me->totvert;
- vd= vertdata;
- mvert= me->mvert;
- while(a--) {
- VecSubf(mvert->co, vd, cent);
- mvert++;
- vd+= 3;
- }
-
- /* faces */
- if(me->totface) {
- rewind(fp);
-
- fscanf(fp, "%40s", s);
- fscanf(fp, "%d\n", &verts);
- /* fake read */
- for(a=0;a<verts;a++) {
- fscanf(fp, "%f %f %f", &ftemp, &ftemp, &ftemp);
- }
-
- a= me->totface;
- mface= me->mface;
- while(a--) {
- end= fscanf(fp,"%d", &poly);
- if(end<=0) break;
-
- if(poly==3 || poly==4) {
- fscanf(fp,"%d", &nr);
- mface->v1= MIN2(nr, me->totvert-1);
- fscanf(fp,"%d", &nr);
- mface->v2= MIN2(nr, me->totvert-1);
- fscanf(fp,"%d", &nr);
- mface->v3= MIN2(nr, me->totvert-1);
- if(poly==4) {
- if( fscanf(fp,"%d", &nr) <=0 ) break;
- mface->v4= MIN2(nr, me->totvert-1);
- }
-
- test_index_face(mface, NULL, 0, poly);
-
- mface++;
- }
- else {
- if( fscanf(fp,"%d", &nr0) <=0) break;
- first= nr0;
- for(b=1; b<poly; b++) {
- end= fscanf(fp,"%d", &nr);
- if(end<=0) break;
- nr= MIN2(nr, me->totvert-1);
- mface->v1= nr;
- mface->v2= nr0;
- nr0= nr;
- mface++;
- a--;
- }
- mface->v1= first;
- mface->v2= nr;
- mface++;
- if(end<=0) break;
- }
- end= fscanf(fp,"%i", &col);
- col &= 0xF0F0F0;
- if(end<=0) break;
-
- for(b=0; b<totcol; b++) {
- if(color[b]==col) {
- (mface-1)->mat_nr= b;
- break;
- }
- }
- }
- }
-
- fclose(fp);
- MEM_freeN(vertdata);
-
- mesh_add_normals_flags(me);
- make_edges(me, 0);
-
- //XXX waitcursor(1);
-}
-
-static void read_videoscape_lamp(Scene *scene, char *str)
-{
- Object *ob;
- Lamp *la;
- FILE *fp;
- float vec[3], q1[4];
- int tot, val;
- char s[50];
-
- fp= fopen(str, "rb");
- if(fp==NULL) {
- //XXX error("Can't read file");
- return;
- }
-
- fscanf(fp, "%40s", s);
- fscanf(fp, "%d\n", &tot);
-
- while(tot--) {
- ob= add_object(scene, OB_LAMP);
- la= ob->data;
-
- fscanf(fp, "%d\n", &val);
- la->type= val;
- if(la->type==1) la->type= LA_SPOT;
- else if(la->type==2) la->type= LA_SUN;
-
- fscanf(fp, "%f %f\n", &la->spotsize, &la->spotblend);
-
- fscanf(fp, "%f %f %f %f\n", &la->r, &la->g, &la->b, &la->energy);
-
- fscanf(fp, "%f %f %f\n", ob->loc, ob->loc+1, ob->loc+2);
- val= fscanf(fp, "%f %f %f\n", vec, vec+1, vec+2);
- vectoquat(vec, 5, 2, q1);
- QuatToEul(q1, ob->rot);
-
- if(val<=0) break;
-
- }
- fclose(fp);
-}
-
-static void read_videoscape_nurbs(Scene *scene, char *str)
-{
- Object *ob;
- Curve *cu;
- Nurb *nu;
- BezTriple *bezt;
- BPoint *bp;
- FILE *fp;
- float tmat[4][4], omat[3][3], imat[3][3], mat[3][3];
- int a, tot, type, val;
- char s[50];
-
- fp= fopen(str, "rb");
- if(fp==NULL) {
- //XXX error("Can't read file");
- return;
- }
-
- fscanf(fp, "%40s", s);
- fscanf(fp, "%d\n", &type);
-
- if(type==5) ob= add_object(scene, OB_SURF);
- else ob= add_object(scene, OB_CURVE);
- cu= ob->data;
-
- fscanf(fp, "%d\n", &tot);
- fscanf(fp, "%d %d\n", &type, &val);
-
- cu->ext1= 0.002f*type;
- cu->ext2= 0.002f*val;
-
- for(a=0; a<4; a++) fscanf(fp, "%e %e %e %e\n", tmat[a], tmat[a]+1, tmat[a]+2, tmat[a]+3);
-
- VECCOPY(ob->loc, tmat[3]);
-
- Mat3CpyMat4(omat, tmat);
- Mat3ToEul(omat, ob->rot);
- EulToMat3(ob->rot, mat);
- Mat3Inv(imat, mat);
- Mat3MulMat3((float ( * )[3])tmat, imat, omat);
-
- while(tot--) {
- nu= (Nurb*)MEM_callocN(sizeof(Nurb),"nu from exotic");
- BLI_addtail(&cu->nurb, nu);
-
- fscanf(fp, "%d\n", &type);
- nu->type= type;
-
- fscanf(fp, "%d %d\n", &type, &val);
- nu->pntsu= type; nu->pntsv= val;
- fscanf(fp, "%d %d\n", &type, &val);
- nu->resolu= type; nu->resolv= val;
- fscanf(fp, "%d %d\n", &type, &val);
- nu->orderu= type; nu->orderv= val;
- fscanf(fp, "%d %d\n", &type, &val);
- nu->flagu= type; nu->flagv= val;
-
- if( (nu->type & 7)==CU_BEZIER) {
- a= nu->pntsu;
- nu->bezt= bezt= MEM_callocN(a*sizeof(BezTriple), "bezt from exotic");
- while(a--) {
- fscanf(fp, "%f %f %f ", bezt->vec[0], bezt->vec[0]+1, bezt->vec[0]+2);
- Mat4MulVecfl(tmat, bezt->vec[0]);
- fscanf(fp, "%f %f %f ", bezt->vec[1], bezt->vec[1]+1, bezt->vec[1]+2);
- Mat4MulVecfl(tmat, bezt->vec[1]);
- fscanf(fp, "%f %f %f ", bezt->vec[2], bezt->vec[2]+1, bezt->vec[2]+2);
- Mat4MulVecfl(tmat, bezt->vec[2]);
- fscanf(fp, "%d %d\n", &type, &val);
- bezt->h1= type;
- bezt->h2= val;
- bezt++;
- }
- }
- else {
- a= nu->pntsu*nu->pntsv;
- if(a) {
- nu->bp= bp= MEM_callocN(a*sizeof(BPoint), "bp from exotic");
- while(a--) {
- fscanf(fp, "%f %f %f %f\n", bp->vec, bp->vec+1, bp->vec+2, bp->vec+3);
- Mat4MulVecfl(tmat, bp->vec);
- bp++;
- }
-
- val= KNOTSU(nu);
- nu->knotsu= MEM_mallocN(sizeof(float)*val, "knots");
- for(a=0; a<val; a++) fscanf(fp, "%f\n", nu->knotsu+a);
-
- if(nu->pntsv>1) {
- val= KNOTSV(nu);
- nu->knotsv= MEM_mallocN(sizeof(float)*val, "knots");
- for(a=0; a<val; a++) fscanf(fp, "%f\n", nu->knotsv+a);
- }
- }
- else {
- BLI_remlink(&cu->nurb, nu);
- MEM_freeN(nu);
- }
- }
- }
- fclose(fp);
-}
-
-static void read_videoscape(Scene *scene, char *str)
-{
- int file, type;
- unsigned int val;
- unsigned short numlen;
- char name[FILE_MAXDIR+FILE_MAXFILE], head[FILE_MAXDIR+FILE_MAXFILE], tail[FILE_MAXFILE];
-
- strcpy(name, str);
-
- while( TRUE ) {
- file= open(name, O_BINARY|O_RDONLY);
- if(file<=0) break;
- else {
- read(file, &type, 4);
- close(file);
-
- if(type==DDG1) read_videoscape_mesh(scene, name);
- else if(type==DDG2) read_videoscape_lamp(scene, name);
- else if(type==DDG3) read_videoscape_nurbs(scene, name);
- }
-
- val = BLI_stringdec(name, head, tail, &numlen);
- BLI_stringenc(name, head, tail, numlen, val + 1);
-
- }
-}
-
-
/* ***************** INVENTOR ******************* */
@@ -2204,16 +1786,7 @@ int BKE_read_exotic(Scene *scene, char *name)
if ((*s0 != FORM) && (strncmp(str, "BLEN", 4) != 0) && !BLI_testextensie(name,".blend.gz")) {
//XXX waitcursor(1);
-
- if(ELEM4(*s0, DDG1, DDG2, DDG3, DDG4)) {
- if(0) { // XXX obedit) {
- //XXX error("Unable to perform function in EditMode");
- } else {
- read_videoscape(scene, name);
- retval = 1;
- }
- }
- else if(strncmp(str, "#Inventor V1.0", 14)==0) {
+ if(strncmp(str, "#Inventor V1.0", 14)==0) {
if( strncmp(str+15, "ascii", 5)==0) {
read_inventor(scene, name, &lbase);
displist_to_objects(scene, &lbase);
@@ -2385,167 +1958,6 @@ void write_stl(Scene *scene, char *str)
//XXX waitcursor(0);
}
-static void write_videoscape_mesh(Scene *scene, Object *ob, char *str)
-{
- Mesh *me= ob->data;
- EditMesh *em = BKE_mesh_get_editmesh(me);
- Material *ma;
- MFace *mface;
- FILE *fp;
- EditVert *eve;
- EditFace *evl;
- unsigned int kleur[32];
- float co[3];
- int a;
- intptr_t tot;
- char *cp;
-
- if(ob && ob->type==OB_MESH);
- else {
- return;
- }
-
- kleur[0]= 0x00C0C0C0;
-
- cp= (char *)kleur;
- for(a=0; a<ob->totcol; a++, cp+=4) {
-
- ma= give_current_material(ob, a+1);
- if(ma) {
- cp[0]= (unsigned char) (255.0*ma->emit);
- cp[1]= (unsigned char) (255.0*ma->b);
- cp[2]= (unsigned char) (255.0*ma->g);
- cp[3]= (unsigned char) (255.0*ma->r);
- if(ENDIAN_ORDER==L_ENDIAN) SWITCH_INT(kleur[a]);
- }
- else kleur[a]= 0x00C0C0C0;
-
- if(a>30) break;
- }
-
- fp= fopen(str, "wb");
- if(fp==NULL) return;
-
- fprintf(fp,"3DG1\n");
-
- if(em) {
-
- fprintf(fp, "%d\n", em->totvert);
-
- tot= 0;
- eve= em->verts.first;
- while(eve) {
- VECCOPY(co, eve->co);
- Mat4MulVecfl(ob->obmat, co);
- fprintf(fp, "%f %f %f\n", co[0], co[1], co[2] );
- eve->tmp.l = tot;
- tot++;
- eve= eve->next;
- }
- evl= em->faces.first;
- while(evl) {
-
- if(evl->v4==0) {
- fprintf(fp, "3 %ld %ld %ld 0x%x\n",
- (intptr_t) evl->v1->tmp.l,
- (intptr_t) evl->v2->tmp.l,
- (intptr_t) evl->v3->tmp.l,
- kleur[evl->mat_nr]);
- }
- else {
- fprintf(fp, "4 %ld %ld %ld %ld 0x%x\n",
- (intptr_t) evl->v1->tmp.l,
- (intptr_t) evl->v2->tmp.l,
- (intptr_t) evl->v3->tmp.l,
- (intptr_t) evl->v4->tmp.l,
- kleur[evl->mat_nr]);
- }
- evl= evl->next;
- }
- }
- else {
- DerivedMesh *dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
-
- me= ob->data;
-
- fprintf(fp, "%d\n", me->totvert);
-
- mface= me->mface;
- for(a=0; a<me->totvert; a++) {
- dm->getVertCo(dm, a, co);
- Mat4MulVecfl(ob->obmat, co);
- fprintf(fp, "%f %f %f\n", co[0], co[1], co[2] );
- }
- for(a=0; a<me->totface; a++, mface++) {
- if(mface->v4==0) {
- fprintf(fp, "3 %d %d %d 0x%x\n", mface->v1, mface->v2, mface->v3, kleur[(int)mface->mat_nr]);
- }
- else {
- fprintf(fp, "4 %d %d %d %d 0x%x\n", mface->v1, mface->v2, mface->v3, mface->v4, kleur[(int)mface->mat_nr]);
- }
- }
-
- dm->release(dm);
- }
-
- fclose(fp);
-
- if (em) BKE_mesh_end_editmesh(me, em);
-
-}
-
-
-void write_videoscape(Scene *scene, char *str)
-{
- Base *base;
- int file, val, lampdone=0;
- unsigned short numlen;
- char head[FILE_MAXFILE], tail[FILE_MAXFILE];
-
- if(BLI_testextensie(str,".trace")) str[ strlen(str)-6]= 0;
- if(BLI_testextensie(str,".blend")) str[ strlen(str)-6]= 0;
- if(BLI_testextensie(str,".ble")) str[ strlen(str)-4]= 0;
- if(BLI_testextensie(str,".obj")==0) strcat(str, ".obj");
-
- file= open(str,O_BINARY|O_RDONLY);
- close(file);
- //XXX saveover()
- // if(file>-1) if(!during_script() && saveover(str)==0) return;
-
- strcpy(temp_dir, str);
-
- base= scene->base.first;
- while(base) {
- if((base->flag & SELECT) && (base->lay & scene->lay)) {
- if(base->object->type==OB_MESH) {
- write_videoscape_mesh(scene, base->object, str);
- val = BLI_stringdec(str, head, tail, &numlen);
- BLI_stringenc(str, head, tail, numlen, val + 1);
- }
- else if(base->object->type==OB_CURVE || base->object->type==OB_SURF) {
- /* write_videoscape_nurbs(base->object, str); */
- /* val = stringdec(str, head, tail, &numlen); */
- /* stringenc(str, head, tail, numlen, val + 1); */
- }
- else if(lampdone==0 && base->object->type==OB_LAMP) {
- /* lampdone= 1; */
- /* write_videoscape_lamps(str); */
- /* val = stringdec(str, head, tail, &numlen); */
- /* stringenc(str, head, tail, numlen, val + 1); */
- }
- }
- base= base->next;
- }
-
-
- /* remove when higher numbers exist */
- while(remove(str)==0) {
-
- val = BLI_stringdec(str, head, tail, &numlen);
- BLI_stringenc(str, head, tail, numlen, val + 1);
- }
-}
-
/* ******************************* WRITE VRML ***************************** */
static void replace_chars(char *str1, char *str2)
diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c
index 9eefd48cae4..54008185f72 100644
--- a/source/blender/blenkernel/intern/fluidsim.c
+++ b/source/blender/blenkernel/intern/fluidsim.c
@@ -28,6 +28,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
+#include "BLI_storage.h" /* _LARGEFILE_SOURCE */
+
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 60a7ffc28d9..70901778585 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -333,11 +333,11 @@ static VFontData *vfont_get_data(VFont *vfont)
BLI_addtail(&ttfdata, tmpfnt);
}
} else {
- pf= newPackedFile(vfont->name);
+ pf= newPackedFile(NULL, vfont->name);
if(!tmpfnt)
{
- tpf= newPackedFile(vfont->name);
+ tpf= newPackedFile(NULL, vfont->name);
// Add temporary packed file to globals
tmpfnt= (struct TmpFont *) MEM_callocN(sizeof(struct TmpFont), "temp_font");
@@ -385,8 +385,8 @@ VFont *load_vfont(char *name)
strcpy(dir, name);
BLI_splitdirstring(dir, filename);
- pf= newPackedFile(name);
- tpf= newPackedFile(name);
+ pf= newPackedFile(NULL, name);
+ tpf= newPackedFile(NULL, name);
is_builtin= 0;
}
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 6086aa58d40..dd8f44c71d5 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1,5 +1,5 @@
/**
- * $Id: gpencil.c 19758 2009-04-16 13:10:08Z aligorith $
+ * $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index 3be47778674..54366aadd92 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -230,16 +230,16 @@ void IDP_ResizeArray(IDProperty *prop, int newlen)
*/
newsize = (newsize >> 3) + (newsize < 9 ? 3 : 6) + newsize;
- newarr = MEM_callocN(idp_size_table[prop->subtype]*newsize, "idproperty array resized");
+ newarr = MEM_callocN(idp_size_table[(int)prop->subtype]*newsize, "idproperty array resized");
if (newlen >= prop->len) {
/* newlen is bigger*/
- memcpy(newarr, prop->data.pointer, prop->len*idp_size_table[prop->subtype]);
+ memcpy(newarr, prop->data.pointer, prop->len*idp_size_table[(int)prop->subtype]);
idp_resize_group_array(prop, newlen, newarr);
}
else {
/* newlen is smaller*/
idp_resize_group_array(prop, newlen, newarr);
- memcpy(newarr, prop->data.pointer, newlen*prop->len*idp_size_table[prop->subtype]);
+ memcpy(newarr, prop->data.pointer, newlen*prop->len*idp_size_table[(int)prop->subtype]);
}
MEM_freeN(prop->data.pointer);
@@ -546,7 +546,7 @@ int IDP_EqualsProperties(IDProperty *prop1, IDProperty *prop2)
return BSTR_EQ(IDP_String(prop1), IDP_String(prop2));
else if(prop1->type == IDP_ARRAY) {
if(prop1->len == prop2->len && prop1->subtype == prop2->subtype)
- return memcmp(IDP_Array(prop1), IDP_Array(prop2), idp_size_table[prop1->subtype]*prop1->len);
+ return memcmp(IDP_Array(prop1), IDP_Array(prop2), idp_size_table[(int)prop1->subtype]*prop1->len);
else
return 0;
}
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 8eef9984c92..ef0984bf93d 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1431,7 +1431,7 @@ void BKE_image_signal(Image *ima, ImageUser *iuser, int signal)
/* try to repack file */
if(ima->packedfile) {
PackedFile *pf;
- pf = newPackedFile(ima->name);
+ pf = newPackedFile(NULL, ima->name);
if (pf) {
freePackedFile(ima->packedfile);
ima->packedfile = pf;
@@ -1750,7 +1750,7 @@ static ImBuf *image_load_image_file(Image *ima, ImageUser *iuser, int cfra)
/* make packed file for autopack */
if ((ima->packedfile == NULL) && (G.fileflags & G_AUTOPACK))
- ima->packedfile = newPackedFile(str);
+ ima->packedfile = newPackedFile(NULL, str);
}
if(ima->flag & IMA_DO_PREMUL)
@@ -1812,7 +1812,7 @@ static ImBuf *image_get_render_result(Image *ima, ImageUser *iuser)
Render *re= NULL;
RenderResult *rr= NULL;
- if(iuser->scene) {
+ if(iuser && iuser->scene) {
re= RE_GetRender(iuser->scene->id.name);
rr= RE_GetResult(re);
}
diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c
index 40c98c1d9cc..fc5213d5532 100644
--- a/source/blender/blenkernel/intern/implicit.c
+++ b/source/blender/blenkernel/intern/implicit.c
@@ -1600,6 +1600,10 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
if(clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_ENABLED)
{
+ float temp = clmd->sim_parms->stepsPerFrame;
+ /* not too nice hack, but collisions need this correction -jahka */
+ clmd->sim_parms->stepsPerFrame /= clmd->sim_parms->timescale;
+
// collisions
// itstart();
@@ -1614,7 +1618,7 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
// call collision function
// TODO: check if "step" or "step+dt" is correct - dg
- result = cloth_bvh_objcollision(ob, clmd, step, dt);
+ result = cloth_bvh_objcollision(ob, clmd, step/clmd->sim_parms->timescale, dt/clmd->sim_parms->timescale);
// correct velocity again, just to be sure we had to change it due to adaptive collisions
for(i = 0; i < numverts; i++)
@@ -1637,6 +1641,9 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
}
}
+ /* restore original stepsPerFrame */
+ clmd->sim_parms->stepsPerFrame = temp;
+
// X = Xnew;
cp_lfvector(id->X, id->Xnew, numverts);
@@ -1654,7 +1661,6 @@ int implicit_solver (Object *ob, float frame, ClothModifierData *clmd, ListBase
simulate_implicit_euler(id->Vnew, id->X, id->V, id->F, id->dFdV, id->dFdX, dt / 2.0f, id->A, id->B, id->dV, id->S, id->z, id->olddV, id->P, id->Pinv, id->M, id->bigI);
}
-
}
else
{
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index b410c521dea..57b88bb0b3f 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -615,7 +615,7 @@ int find_material_index(Object *ob, Material *ma)
return 0;
}
-void new_material_to_objectdata(Object *ob)
+void object_add_material_slot(Object *ob)
{
Material *ma;
@@ -854,7 +854,7 @@ void automatname(Material *ma)
}
-void delete_material_index(Object *ob)
+void object_remove_material_slot(Object *ob)
{
Material *mao, ***matarar;
Object *obt;
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index bf3d27cafbf..80a9f173d6a 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -3543,7 +3543,7 @@ static void displaceModifier_updateDepgraph(
}
}
-static void validate_layer_name(const CustomData *data, int type, char *name)
+static void validate_layer_name(const CustomData *data, int type, char *name, char *outname)
{
int index = -1;
@@ -3556,8 +3556,10 @@ static void validate_layer_name(const CustomData *data, int type, char *name)
* deleted, so assign the active layer to name
*/
index = CustomData_get_active_layer_index(data, CD_MTFACE);
- strcpy(name, data->layers[index].name);
+ strcpy(outname, data->layers[index].name);
}
+ else
+ strcpy(outname, name);
}
static void get_texture_coords(DisplaceModifierData *dmd, Object *ob,
@@ -3583,12 +3585,11 @@ static void get_texture_coords(DisplaceModifierData *dmd, Object *ob,
char *done = MEM_callocN(sizeof(*done) * numVerts,
"get_texture_coords done");
int numFaces = dm->getNumFaces(dm);
+ char uvname[32];
MTFace *tf;
- validate_layer_name(&dm->faceData, CD_MTFACE, dmd->uvlayer_name);
-
- tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE,
- dmd->uvlayer_name);
+ validate_layer_name(&dm->faceData, CD_MTFACE, dmd->uvlayer_name, uvname);
+ tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname);
/* verts are given the UV from the first face that uses them */
for(i = 0, mf = mface; i < numFaces; ++i, ++mf, ++tf) {
@@ -3884,6 +3885,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
Projector projectors[MOD_UVPROJECT_MAXPROJECTORS];
int num_projectors = 0;
float aspect;
+ char uvname[32];
if(umd->aspecty != 0) aspect = umd->aspectx / umd->aspecty;
else aspect = 1.0f;
@@ -3898,12 +3900,11 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
if(!dm->getFaceDataArray(dm, CD_MTFACE)) return dm;
/* make sure we're using an existing layer */
- validate_layer_name(&dm->faceData, CD_MTFACE, umd->uvlayer_name);
+ validate_layer_name(&dm->faceData, CD_MTFACE, umd->uvlayer_name, uvname);
/* make sure we are not modifying the original UV layer */
tface = CustomData_duplicate_referenced_layer_named(&dm->faceData,
- CD_MTFACE,
- umd->uvlayer_name);
+ CD_MTFACE, uvname);
numVerts = dm->getNumVerts(dm);
@@ -5185,12 +5186,11 @@ static void wavemod_get_texture_coords(WaveModifierData *wmd, Object *ob,
char *done = MEM_callocN(sizeof(*done) * numVerts,
"get_texture_coords done");
int numFaces = dm->getNumFaces(dm);
+ char uvname[32];
MTFace *tf;
- validate_layer_name(&dm->faceData, CD_MTFACE, wmd->uvlayer_name);
-
- tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE,
- wmd->uvlayer_name);
+ validate_layer_name(&dm->faceData, CD_MTFACE, wmd->uvlayer_name, uvname);
+ tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname);
/* verts are given the UV from the first face that uses them */
for(i = 0, mf = mface; i < numFaces; ++i, ++mf, ++tf) {
@@ -6295,6 +6295,9 @@ CustomDataMask particleSystemModifier_requiredDataMask(Object *ob, ModifierData
MTex *mtex;
int i;
+ if(!psmd->psys->part)
+ return 0;
+
ma= give_current_material(ob, psmd->psys->part->omat);
if(ma) {
for(i=0; i<MAX_MTEX; i++) {
diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index b1387281cf5..5def910ddef 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -1270,8 +1270,10 @@ void multires_free(Multires *mr)
if(lvl) {
CustomData_free(&mr->vdata, lvl->totvert);
CustomData_free(&mr->fdata, lvl->totface);
- MEM_freeN(mr->edge_flags);
- MEM_freeN(mr->edge_creases);
+ if(mr->edge_flags)
+ MEM_freeN(mr->edge_flags);
+ if(mr->edge_creases)
+ MEM_freeN(mr->edge_creases);
}
while(lvl) {
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c
index 22e4e8a8309..4d88556d8bf 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -61,8 +61,9 @@
#include "BKE_image.h"
#include "BKE_font.h"
#include "BKE_packedFile.h"
+#include "BKE_report.h"
-int seekPackedFile(PackedFile * pf, int offset, int whence)
+int seekPackedFile(PackedFile *pf, int offset, int whence)
{
int oldseek = -1, seek = 0;
@@ -92,12 +93,12 @@ int seekPackedFile(PackedFile * pf, int offset, int whence)
return(oldseek);
}
-void rewindPackedFile(PackedFile * pf)
+void rewindPackedFile(PackedFile *pf)
{
seekPackedFile(pf, 0, SEEK_SET);
}
-int readPackedFile(PackedFile * pf, void * data, int size)
+int readPackedFile(PackedFile *pf, void *data, int size)
{
if ((pf != NULL) && (size >= 0) && (data != NULL)) {
if (size + pf->seek > pf->size) {
@@ -118,66 +119,55 @@ int readPackedFile(PackedFile * pf, void * data, int size)
return(size);
}
-int countPackedFiles()
+int countPackedFiles(Main *bmain)
{
- int count = 0;
Image *ima;
VFont *vf;
bSample *sample;
+ int count = 0;
// let's check if there are packed files...
- ima = G.main->image.first;
- while (ima) {
- if (ima->packedfile) {
+ for(ima=bmain->image.first; ima; ima=ima->id.next)
+ if(ima->packedfile)
count++;
- }
- ima= ima->id.next;
- }
- vf = G.main->vfont.first;
- while (vf) {
- if (vf->packedfile) {
+ for(vf=bmain->vfont.first; vf; vf=vf->id.next)
+ if(vf->packedfile)
count++;
- }
- vf = vf->id.next;
- }
- sample = samples->first;
- while (sample) {
- if (sample->packedfile) {
- count++;
- }
- sample = sample->id.next;
- }
+ if(samples)
+ for(sample=samples->first; sample; sample=sample->id.next)
+ if(sample->packedfile)
+ count++;
- return(count);
+ return count;
}
-void freePackedFile(PackedFile * pf)
+void freePackedFile(PackedFile *pf)
{
- if (pf) {
+ if(pf) {
MEM_freeN(pf->data);
MEM_freeN(pf);
- } else {
- printf("freePackedFile: Trying to free a NULL pointer\n");
}
+ else
+ printf("freePackedFile: Trying to free a NULL pointer\n");
}
-PackedFile * newPackedFileMemory(void *mem, int memlen)
+PackedFile *newPackedFileMemory(void *mem, int memlen)
{
- PackedFile * pf = MEM_callocN(sizeof(*pf), "PackedFile");
+ PackedFile *pf = MEM_callocN(sizeof(*pf), "PackedFile");
pf->data = mem;
pf->size = memlen;
return pf;
}
-PackedFile * newPackedFile(char * filename)
+PackedFile *newPackedFile(ReportList *reports, char *filename)
{
- PackedFile * pf = NULL;
+ PackedFile *pf = NULL;
int file, filelen;
char name[FILE_MAXDIR+FILE_MAXFILE];
- void * data;
+ void *data;
//XXX waitcursor(1);
@@ -191,7 +181,7 @@ PackedFile * newPackedFile(char * filename)
file= open(name, O_BINARY|O_RDONLY);
if (file <= 0) {
- // error("Can't open file: %s", name);
+ BKE_reportf(reports, RPT_ERROR, "Can't open file: %s", name);
} else {
filelen = BLI_filesize(file);
@@ -214,36 +204,24 @@ PackedFile * newPackedFile(char * filename)
return (pf);
}
-void packAll()
+void packAll(Main *bmain, ReportList *reports)
{
Image *ima;
VFont *vf;
bSample *sample;
- ima = G.main->image.first;
- while (ima) {
- if (ima->packedfile == NULL) {
- ima->packedfile = newPackedFile(ima->name);
- }
- ima= ima->id.next;
- }
-
- vf = G.main->vfont.first;
- while (vf) {
- if (vf->packedfile == NULL) {
- vf->packedfile = newPackedFile(vf->name);
- }
- vf = vf->id.next;
- }
+ for(ima=bmain->image.first; ima; ima=ima->id.next)
+ if(ima->packedfile == NULL)
+ ima->packedfile = newPackedFile(reports, ima->name);
+ for(vf=bmain->vfont.first; vf; vf=vf->id.next)
+ if(vf->packedfile == NULL)
+ vf->packedfile = newPackedFile(reports, vf->name);
- sample = samples->first;
- while (sample) {
- if (sample->packedfile == NULL) {
- sound_set_packedfile(sample, newPackedFile(sample->name));
- }
- sample = sample->id.next;
- }
+ if(samples)
+ for(sample=samples->first; sample; sample=sample->id.next)
+ if(sample->packedfile == NULL)
+ sound_set_packedfile(sample, newPackedFile(reports, sample->name));
}
@@ -252,10 +230,10 @@ void packAll()
// attempt to create a function that generates an unique filename
// this will work when all funtions in fileops.c understand relative filenames...
-char * find_new_name(char * name)
+char *find_new_name(char *name)
{
char tempname[FILE_MAXDIR + FILE_MAXFILE];
- char * newname;
+ char *newname;
if (fop_exists(name)) {
for (number = 1; number <= 999; number++) {
@@ -274,13 +252,13 @@ char * find_new_name(char * name)
*/
-int writePackedFile(char * filename, PackedFile *pf, int guimode)
+int writePackedFile(ReportList *reports, char *filename, PackedFile *pf, int guimode)
{
int file, number, remove_tmp = FALSE;
int ret_value = RET_OK;
char name[FILE_MAXDIR + FILE_MAXFILE];
char tempname[FILE_MAXDIR + FILE_MAXFILE];
-/* void * data; */
+/* void *data; */
if (guimode); //XXX waitcursor(1);
@@ -305,23 +283,23 @@ int writePackedFile(char * filename, PackedFile *pf, int guimode)
file = open(name, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
if (file >= 0) {
if (write(file, pf->data, pf->size) != pf->size) {
- if(guimode) ; //XXX error("Error writing file: %s", name);
+ BKE_reportf(reports, RPT_ERROR, "Error writing file: %s", name);
ret_value = RET_ERROR;
}
close(file);
} else {
- if(guimode); //XXX error("Error creating file: %s", name);
+ BKE_reportf(reports, RPT_ERROR, "Error creating file: %s", name);
ret_value = RET_ERROR;
}
if (remove_tmp) {
if (ret_value == RET_ERROR) {
if (BLI_rename(tempname, name) != 0) {
- if(guimode); //XXX error("Error restoring tempfile. Check files: '%s' '%s'", tempname, name);
+ BKE_reportf(reports, RPT_ERROR, "Error restoring tempfile. Check files: '%s' '%s'", tempname, name);
}
} else {
if (BLI_delete(tempname, 0, 0) != 0) {
- if(guimode); //XXX error("Error deleting '%s' (ignored)");
+ BKE_reportf(reports, RPT_ERROR, "Error deleting '%s' (ignored)", tempname);
}
}
}
@@ -342,7 +320,7 @@ PF_NOFILE - the original file doens't exist
*/
-int checkPackedFile(char * filename, PackedFile * pf)
+int checkPackedFile(char *filename, PackedFile *pf)
{
struct stat st;
int ret_val, i, len, file;
@@ -390,68 +368,23 @@ int checkPackedFile(char * filename, PackedFile * pf)
/*
-unpackFile() looks at the existing files (abs_name, local_name) and a packed file.
-If how == PF_ASK it offers the user a couple of options what to do with the packed file.
+ unpackFile() looks at the existing files (abs_name, local_name) and a packed file.
-It returns a char * to the existing file name / new file name or NULL when
+It returns a char *to the existing file name / new file name or NULL when
there was an error or when the user desides to cancel the operation.
*/
-char *unpackFile(char * abs_name, char * local_name, PackedFile * pf, int how)
+char *unpackFile(ReportList *reports, char *abs_name, char *local_name, PackedFile *pf, int how)
{
- char menu[6 * (FILE_MAXDIR + FILE_MAXFILE + 100)];
+ char menu[6 *(FILE_MAXDIR + FILE_MAXFILE + 100)];
char line[FILE_MAXDIR + FILE_MAXFILE + 100];
- char * newname = NULL, * temp = NULL;
+ char *newname = NULL, *temp = NULL;
// char newabs[FILE_MAXDIR + FILE_MAXFILE];
// char newlocal[FILE_MAXDIR + FILE_MAXFILE];
if (pf != NULL) {
- if (how == PF_ASK) {
- sprintf(menu, "UnPack file%%t|Remove Pack %%x%d", PF_REMOVE);
-
- if (strcmp(abs_name, local_name)) {
- switch (checkPackedFile(local_name, pf)) {
- case PF_NOFILE:
- sprintf(line, "|Create %s%%x%d", local_name, PF_WRITE_LOCAL);
- strcat(menu, line);
- break;
- case PF_EQUAL:
- sprintf(line, "|Use %s (identical)%%x%d", local_name, PF_USE_LOCAL);
- strcat(menu, line);
- break;
- case PF_DIFFERS:
- sprintf(line, "|Use %s (differs)%%x%d", local_name, PF_USE_LOCAL);
- strcat(menu, line);
- sprintf(line, "|Overwrite %s%%x%d", local_name, PF_WRITE_LOCAL);
- strcat(menu, line);
- break;
- }
- // sprintf(line, "|%%x%d", PF_INVALID);
- // strcat(menu, line);
- }
-
- switch (checkPackedFile(abs_name, pf)) {
- case PF_NOFILE:
- sprintf(line, "|Create %s%%x%d", abs_name, PF_WRITE_ORIGINAL);
- strcat(menu, line);
- break;
- case PF_EQUAL:
- sprintf(line, "|Use %s (identical)%%x%d", abs_name, PF_USE_ORIGINAL);
- strcat(menu, line);
- break;
- case PF_DIFFERS:
- sprintf(line, "|Use %s (differs)%%x%d", abs_name, PF_USE_ORIGINAL);
- strcat(menu, line);
- sprintf(line, "|Overwrite %s%%x%d", abs_name, PF_WRITE_ORIGINAL);
- strcat(menu, line);
- break;
- }
-
- //XXX how = pupmenu(menu);
- }
-
switch (how) {
case -1:
case PF_KEEP:
@@ -467,7 +400,7 @@ char *unpackFile(char * abs_name, char * local_name, PackedFile * pf, int how)
}
// else fall through and create it
case PF_WRITE_LOCAL:
- if (writePackedFile(local_name, pf, 1) == RET_OK) {
+ if (writePackedFile(reports, local_name, pf, 1) == RET_OK) {
temp = local_name;
}
break;
@@ -479,7 +412,7 @@ char *unpackFile(char * abs_name, char * local_name, PackedFile * pf, int how)
}
// else fall through and create it
case PF_WRITE_ORIGINAL:
- if (writePackedFile(abs_name, pf, 1) == RET_OK) {
+ if (writePackedFile(reports, abs_name, pf, 1) == RET_OK) {
temp = abs_name;
}
break;
@@ -498,10 +431,10 @@ char *unpackFile(char * abs_name, char * local_name, PackedFile * pf, int how)
}
-int unpackVFont(VFont * vfont, int how)
+int unpackVFont(ReportList *reports, VFont *vfont, int how)
{
char localname[FILE_MAXDIR + FILE_MAXFILE], fi[FILE_MAXFILE];
- char * newname;
+ char *newname;
int ret_value = RET_ERROR;
if (vfont != NULL) {
@@ -510,7 +443,7 @@ int unpackVFont(VFont * vfont, int how)
sprintf(localname, "//fonts/%s", fi);
- newname = unpackFile(vfont->name, localname, vfont->packedfile, how);
+ newname = unpackFile(reports, vfont->name, localname, vfont->packedfile, how);
if (newname != NULL) {
ret_value = RET_OK;
freePackedFile(vfont->packedfile);
@@ -523,10 +456,10 @@ int unpackVFont(VFont * vfont, int how)
return (ret_value);
}
-int unpackSample(bSample *sample, int how)
+int unpackSample(ReportList *reports, bSample *sample, int how)
{
char localname[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
- char * newname;
+ char *newname;
int ret_value = RET_ERROR;
PackedFile *pf;
@@ -535,7 +468,7 @@ int unpackSample(bSample *sample, int how)
BLI_splitdirstring(localname, fi);
sprintf(localname, "//samples/%s", fi);
- newname = unpackFile(sample->name, localname, sample->packedfile, how);
+ newname = unpackFile(reports, sample->name, localname, sample->packedfile, how);
if (newname != NULL) {
strcpy(sample->name, newname);
MEM_freeN(newname);
@@ -553,10 +486,10 @@ int unpackSample(bSample *sample, int how)
return(ret_value);
}
-int unpackImage(Image * ima, int how)
+int unpackImage(ReportList *reports, Image *ima, int how)
{
char localname[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
- char * newname;
+ char *newname;
int ret_value = RET_ERROR;
if (ima != NULL) {
@@ -564,7 +497,7 @@ int unpackImage(Image * ima, int how)
BLI_splitdirstring(localname, fi);
sprintf(localname, "//textures/%s", fi);
- newname = unpackFile(ima->name, localname, ima->packedfile, how);
+ newname = unpackFile(reports, ima->name, localname, ima->packedfile, how);
if (newname != NULL) {
ret_value = RET_OK;
freePackedFile(ima->packedfile);
@@ -578,33 +511,23 @@ int unpackImage(Image * ima, int how)
return(ret_value);
}
-void unpackAll(int how)
+void unpackAll(Main *bmain, ReportList *reports, int how)
{
Image *ima;
VFont *vf;
bSample *sample;
-
- ima = G.main->image.first;
- while (ima) {
- if (ima->packedfile) {
- unpackImage(ima, how);
- }
- ima= ima->id.next;
- }
-
- vf = G.main->vfont.first;
- while (vf) {
- if (vf->packedfile) {
- unpackVFont(vf, how);
- }
- vf = vf->id.next;
- }
- sample = samples->first;
- while (sample) {
- if (sample->packedfile) {
- unpackSample(sample, how);
- }
- sample = sample->id.next;
- }
+ for(ima=bmain->image.first; ima; ima=ima->id.next)
+ if(ima->packedfile)
+ unpackImage(reports, ima, how);
+
+ for(vf=bmain->vfont.first; vf; vf=vf->id.next)
+ if(vf->packedfile)
+ unpackVFont(reports, vf, how);
+
+ if(samples)
+ for(sample=samples->first; sample; sample=sample->id.next)
+ if(sample->packedfile)
+ unpackSample(reports, sample, how);
}
+
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 34e69b2d736..5bf9335d211 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -222,6 +222,34 @@ short psys_get_current_num(Object *ob)
return i;
}
+void psys_set_current_num(Object *ob, int index)
+{
+ ParticleSystem *psys;
+ short i;
+
+ if(ob==0) return;
+
+ for(psys=ob->particlesystem.first, i=0; psys; psys=psys->next, i++) {
+ if(i == index)
+ psys->flag |= PSYS_CURRENT;
+ else
+ psys->flag &= ~PSYS_CURRENT;
+ }
+}
+Object *psys_find_object(Scene *scene, ParticleSystem *psys)
+{
+ Base *base = scene->base.first;
+ ParticleSystem *tpsys;
+
+ for(base = scene->base.first; base; base = base->next) {
+ for(tpsys = base->object->particlesystem.first; psys; psys=psys->next) {
+ if(tpsys == psys)
+ return base->object;
+ }
+ }
+
+ return NULL;
+}
/* change object's active particle system */
void psys_change_act(void *ob_v, void *act_v)
{
@@ -293,7 +321,7 @@ int psys_check_enabled(Object *ob, ParticleSystem *psys)
ParticleSystemModifierData *psmd;
Mesh *me;
- if(psys->flag & PSYS_DISABLED || psys->flag & PSYS_DELETE)
+ if(psys->flag & PSYS_DISABLED || psys->flag & PSYS_DELETE || !psys->part)
return 0;
if(ob->type == OB_MESH) {
@@ -864,7 +892,7 @@ static void weighted_particle_vector(float *v1, float *v2, float *v3, float *v4,
vec[1]= weights[0]*v1[1] + weights[1]*v2[1] + weights[2]*v3[1] + weights[3]*v4[1];
vec[2]= weights[0]*v1[2] + weights[1]*v2[2] + weights[2]*v3[2] + weights[3]*v4[2];
}
-static void interpolate_particle(short type, ParticleKey keys[4], float dt, ParticleKey *result, int velocity)
+void psys_interpolate_particle(short type, ParticleKey keys[4], float dt, ParticleKey *result, int velocity)
{
float t[4];
@@ -2569,7 +2597,7 @@ void psys_cache_paths(Scene *scene, Object *ob, ParticleSystem *psys, float cfra
}
/* now we should have in chronologiacl order k1<=k2<=t<=k3<=k4 with keytime between [0,1]->[k2,k3] (k1 & k4 used for cardinal & bspline interpolation)*/
- interpolate_particle((psys->flag & PSYS_KEYED) ? -1 /* signal for cubic interpolation */
+ psys_interpolate_particle((psys->flag & PSYS_KEYED) ? -1 /* signal for cubic interpolation */
: ((psys->part->flag & PART_HAIR_BSPLINE) ? KEY_BSPLINE : KEY_CARDINAL)
,keys, keytime, &result, 0);
@@ -2901,6 +2929,61 @@ void psys_mat_hair_to_global(Object *ob, DerivedMesh *dm, short from, ParticleDa
/************************************************/
/* ParticleSettings handling */
/************************************************/
+void object_add_particle_system(Scene *scene, Object *ob)
+{
+ ParticleSystem *psys;
+ ModifierData *md;
+ ParticleSystemModifierData *psmd;
+
+ if(!ob || ob->type != OB_MESH)
+ return;
+
+ psys = ob->particlesystem.first;
+ for(; psys; psys=psys->next)
+ psys->flag &= ~PSYS_CURRENT;
+
+ psys = MEM_callocN(sizeof(ParticleSystem), "particle_system");
+ psys->pointcache = BKE_ptcache_add();
+ BLI_addtail(&ob->particlesystem, psys);
+
+ psys->part = psys_new_settings("PSys", NULL);
+
+ md= modifier_new(eModifierType_ParticleSystem);
+ sprintf(md->name, "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
+ psmd= (ParticleSystemModifierData*) md;
+ psmd->psys=psys;
+ BLI_addtail(&ob->modifiers, md);
+
+ psys->totpart=0;
+ psys->flag = PSYS_ENABLED|PSYS_CURRENT;
+ psys->cfra=bsystem_time(scene,ob,scene->r.cfra+1,0.0);
+
+ DAG_scene_sort(scene);
+ DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+}
+void object_remove_particle_system(Scene *scene, Object *ob)
+{
+ ParticleSystem *psys = psys_get_current(ob);
+ ParticleSystemModifierData *psmd;
+
+ if(!psys)
+ return;
+
+ /* 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);
+
+ if(ob->particlesystem.first)
+ ((ParticleSystem *) ob->particlesystem.first)->flag |= PSYS_CURRENT;
+
+ DAG_scene_sort(scene);
+ DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+}
static void default_particle_settings(ParticleSettings *part)
{
int i;
@@ -2987,6 +3070,9 @@ ParticleSettings *psys_new_settings(char *name, Main *main)
{
ParticleSettings *part;
+ if(main==NULL)
+ main = G.main;
+
part= alloc_libblock(&main->particle, ID_PA, name);
default_particle_settings(part);
@@ -3062,7 +3148,6 @@ void make_local_particlesettings(ParticleSettings *part)
}
}
}
-
void psys_flush_particle_settings(Scene *scene, ParticleSettings *part, int recalc)
{
Base *base = scene->base.first;
@@ -3495,7 +3580,7 @@ void psys_get_particle_on_path(Scene *scene, Object *ob, ParticleSystem *psys, i
QuatInterpol(state->rot,keys[1].rot,keys[2].rot,keytime);
}
- interpolate_particle((psys->flag & PSYS_KEYED) ? -1 /* signal for cubic interpolation */
+ psys_interpolate_particle((psys->flag & PSYS_KEYED) ? -1 /* signal for cubic interpolation */
: ((psys->part->flag & PART_HAIR_BSPLINE) ? KEY_BSPLINE : KEY_CARDINAL)
,keys, keytime, state, 1);
@@ -3702,6 +3787,8 @@ int psys_get_particle_state(struct Scene *scene, Object *ob, ParticleSystem *psy
if((pa->alive==PARS_UNBORN && (part->flag & PART_UNBORN)==0)
|| (pa->alive==PARS_DEAD && (part->flag & PART_DIED)==0))
return 0;
+
+ state->time = MIN2(state->time, pa->dietime);
}
if(psys->flag & PSYS_KEYED){
@@ -3776,7 +3863,7 @@ int psys_get_particle_state(struct Scene *scene, Object *ob, ParticleSystem *psy
VecMulf(keys[1].vel, dfra / frs_sec);
VecMulf(keys[2].vel, dfra / frs_sec);
- interpolate_particle(-1, keys, keytime, state, 1);
+ psys_interpolate_particle(-1, keys, keytime, state, 1);
/* convert back to real velocity */
VecMulf(state->vel, frs_sec / dfra);
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 52f13eeadb8..591b6ca9be5 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -29,6 +29,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
+#include "BLI_storage.h" /* _LARGEFILE_SOURCE */
+
#include <stdlib.h>
#include <math.h>
#include <string.h>
@@ -104,7 +106,8 @@ static int get_current_display_percentage(ParticleSystem *psys)
{
ParticleSettings *part=psys->part;
- if(psys->renderdata || (part->child_nbr && part->childtype))
+ if(psys->renderdata || (part->child_nbr && part->childtype)
+ || (psys->pointcache->flag & PTCACHE_BAKING))
return 100;
if(part->phystype==PART_PHYS_KEYED){
@@ -2195,57 +2198,91 @@ void psys_get_reactor_target(Object *ob, ParticleSystem *psys, Object **target_o
/************************************************/
/* Point Cache */
/************************************************/
+void psys_get_pointcache_start_end(Scene *scene, ParticleSystem *psys, int *sfra, int *efra)
+{
+ ParticleSettings *part = psys->part;
-static void write_particles_to_cache(Object *ob, ParticleSystem *psys, int cfra)
+ *sfra = MAX2(1, (int)part->sta);
+ *efra = MIN2((int)(part->end + part->lifetime + 1.0), scene->r.efra);
+}
+static void particle_write_state(int index, ParticleSystem *psys, float *data)
{
- PTCacheID pid;
- PTCacheFile *pf;
- ParticleData *pa;
- int i, totpart= psys->totpart;
+ memcpy(data, (float *)(&(psys->particles+index)->state), sizeof(ParticleKey));
+}
+static void particle_read_state(int index, void *psys_ptr, float *data)
+{
+ ParticleSystem *psys= psys_ptr;
+ ParticleData *pa = psys->particles + index;
+ ParticleKey *key = (ParticleKey *)data;
- if(totpart == 0)
- return;
+ if(key->time > pa->state.time)
+ copy_particle_key(&pa->prev_state, &pa->state, 1);
- BKE_ptcache_id_from_particles(&pid, ob, psys);
- pf= BKE_ptcache_file_open(&pid, PTCACHE_FILE_WRITE, cfra);
- if(!pf)
+ copy_particle_key(&pa->state, key, 1);
+}
+static void particle_cache_interpolate(int index, void *psys_ptr, float frs_sec, float cfra, float cfra1, float cfra2, float *data1, float *data2)
+{
+ ParticleSystem *psys= psys_ptr;
+ ParticleData *pa = psys->particles + index;
+ ParticleKey keys[4];
+ float dfra, cfra1f = (float)cfra1, cfra2f(float);
+
+ cfra = MIN2(cfra, pa->dietime);
+ cfra1 = MIN2(cfra1, pa->dietime);
+ cfra2 = MIN2(cfra2, pa->dietime);
+
+ keys[1] = *((ParticleKey*)data1);
+ keys[2] = *((ParticleKey*)data2);
+
+ if(cfra1 == cfra2) {
+ copy_particle_key(&pa->state, &keys[1], 1);
return;
+ }
- /* assuming struct consists of tightly packed floats */
- for(i=0, pa=psys->particles; i<totpart; i++, pa++)
- BKE_ptcache_file_write_floats(pf, (float*)&pa->state, sizeof(ParticleKey)/sizeof(float));
-
- BKE_ptcache_file_close(pf);
-}
+ dfra = cfra2 - cfra1;
-static int get_particles_from_cache(Object *ob, ParticleSystem *psys, int cfra)
+ VecMulf(keys[1].vel, dfra / frs_sec);
+ VecMulf(keys[2].vel, dfra / frs_sec);
+
+ psys_interpolate_particle(-1, keys, (cfra - cfra1) / dfra, &pa->state, 1);
+
+ VecMulf(pa->state.vel, frs_sec / dfra);
+
+ pa->state.time = cfra;
+}
+static void write_particles_to_cache(Object *ob, ParticleSystem *psys, int cfra)
{
+ PTCacheWriter writer;
PTCacheID pid;
- PTCacheFile *pf;
- ParticleData *pa;
- int i, totpart= psys->totpart;
-
- if(totpart == 0)
- return 0;
BKE_ptcache_id_from_particles(&pid, ob, psys);
- pf= BKE_ptcache_file_open(&pid, PTCACHE_FILE_READ, cfra);
- if(!pf)
- return 0;
- /* assuming struct consists of tightly packed floats */
- for(i=0, pa=psys->particles; i<totpart; i++, pa++) {
- if(cfra!=pa->state.time)
- copy_particle_key(&pa->prev_state,&pa->state,1);
- if(!BKE_ptcache_file_read_floats(pf, (float*)&pa->state, sizeof(ParticleKey)/sizeof(float))) {
- BKE_ptcache_file_close(pf);
- return 0;
- }
- }
+ writer.calldata = psys;
+ writer.cfra = cfra;
+ writer.set_elem = particle_write_state;
+ writer.pid = &pid;
+ writer.totelem = psys->totpart;
- BKE_ptcache_file_close(pf);
+ BKE_ptcache_write_cache(&writer);
+}
- return 1;
+static int get_particles_from_cache(Scene *scene, Object *ob, ParticleSystem *psys, float cfra, int *old_frame)
+{
+ PTCacheReader reader;
+ PTCacheID pid;
+
+ BKE_ptcache_id_from_particles(&pid, ob, psys);
+
+ reader.calldata = psys;
+ reader.cfra = cfra;
+ reader.interpolate_elem = particle_cache_interpolate;
+ reader.old_frame = old_frame;
+ reader.pid = &pid;
+ reader.scene = scene;
+ reader.set_elem = particle_read_state;
+ reader.totelem = psys->totpart;
+
+ return BKE_ptcache_read_cache(&reader);
}
/************************************************/
@@ -2372,6 +2409,8 @@ static void add_to_effectors(ListBase *lb, Scene *scene, Object *ob, Object *obs
Object *tob;
for(i=0; epsys; epsys=epsys->next,i++){
+ if(!psys_check_enabled(ob, epsys))
+ continue;
type=0;
if(epsys!=psys || (psys->part->flag & PART_SELF_EFFECT)){
epart=epsys->part;
@@ -4085,7 +4124,7 @@ static void dynamics_step(Scene *scene, Object *ob, ParticleSystem *psys, Partic
/* main loop: calculate physics for all particles */
for(p=0, pa=psys->particles; p<totpart; p++,pa++){
- if(pa->flag & PARS_UNEXIST) continue;
+ if(pa->flag & (PARS_UNEXIST+PARS_NO_DISP)) continue;
copy_particle_key(&pa->prev_state,&pa->state,1);
@@ -4110,25 +4149,26 @@ static void dynamics_step(Scene *scene, Object *ob, ParticleSystem *psys, Partic
if(pa->alive==PARS_UNBORN
|| pa->alive==PARS_KILLED
|| ELEM(part->phystype,PART_PHYS_NO,PART_PHYS_KEYED)
- || birthtime >= cfra){
+ || birthtime >= psys->cfra){
reset_particle(scene, pa,psys,psmd,ob,dtime,cfra,vg_vel,vg_tan,vg_rot);
}
pa_dfra = dfra;
pa_dtime = dtime;
- if(birthtime <= cfra && birthtime >= psys->cfra){
+
+ if(dietime <= cfra && psys->cfra < dietime){
+ /* particle dies some time between this and last step */
+ pa_dfra = dietime - ((birthtime > psys->cfra) ? birthtime : psys->cfra);
+ pa_dtime = pa_dfra * timestep;
+ pa->alive = PARS_DYING;
+ }
+ else if(birthtime <= cfra && birthtime >= psys->cfra){
/* particle is born some time between this and last step*/
pa->alive = PARS_ALIVE;
pa_dfra = cfra - birthtime;
pa_dtime = pa_dfra*timestep;
}
- else if(dietime <= cfra && psys->cfra < dietime){
- /* particle dies some time between this and last step */
- pa_dfra = dietime - psys->cfra;
- pa_dtime = pa_dfra * timestep;
- pa->alive = PARS_DYING;
- }
else if(dietime < cfra){
/* nothing to be done when particle is dead */
}
@@ -4335,7 +4375,7 @@ static void cached_step(Scene *scene, Object *ob, ParticleSystemModifierData *ps
pa->alive = PARS_UNBORN;
else if(dietime <= cfra){
if(dietime > psys->cfra){
- state.time = pa->dietime;
+ state.time = dietime;
psys_get_particle_state(scene, ob,psys,p,&state,1);
push_reaction(ob,psys,p,PART_EVENT_DEATH,&state);
}
@@ -4520,7 +4560,7 @@ static void system_step(Scene *scene, Object *ob, ParticleSystem *psys, Particle
int totpart, oldtotpart, totchild, oldtotchild, p;
float disp, *vg_vel= 0, *vg_tan= 0, *vg_rot= 0, *vg_size= 0;
int init= 0, distr= 0, alloc= 0, usecache= 0, only_children_changed= 0;
- int framenr, framedelta, startframe, endframe;
+ int framenr, framedelta, startframe, endframe, old_framenr;
part= psys->part;
cache= psys->pointcache;
@@ -4528,6 +4568,10 @@ static void system_step(Scene *scene, Object *ob, ParticleSystem *psys, Particle
framenr= (int)scene->r.cfra;
framedelta= framenr - cache->simframe;
+ /* set suitable cache range automatically */
+ if((cache->flag & (PTCACHE_BAKING|PTCACHE_BAKED))==0)
+ psys_get_pointcache_start_end(scene, psys, &cache->startframe, &cache->endframe);
+
BKE_ptcache_id_from_particles(&pid, ob, psys);
BKE_ptcache_id_time(&pid, scene, 0.0f, &startframe, &endframe, NULL);
@@ -4600,9 +4644,13 @@ static void system_step(Scene *scene, Object *ob, ParticleSystem *psys, Particle
if(init) {
if(distr) {
- if(alloc)
+ if(alloc) {
realloc_particles(ob, psys, totpart);
+ if(usecache)
+ BKE_ptcache_id_clear(&pid, PTCACHE_CLEAR_ALL, 0);
+ }
+
distribute_particles(scene, ob, psys, part->from);
if((psys->part->type == PART_HAIR) && !(psys->flag & PSYS_HAIR_DONE))
@@ -4616,9 +4664,11 @@ static void system_step(Scene *scene, Object *ob, ParticleSystem *psys, Particle
free_keyed_keys(psys);
initialize_all_particles(ob, psys, psmd);
+
- if(alloc)
+ if(alloc) {
reset_all_particles(scene, ob, psys, psmd, 0.0, cfra, oldtotpart);
+ }
}
/* flag for possible explode modifiers after this system */
@@ -4627,46 +4677,59 @@ static void system_step(Scene *scene, Object *ob, ParticleSystem *psys, Particle
/* try to read from the cache */
if(usecache) {
- if(get_particles_from_cache(ob, psys, framenr)) {
- if(part->phystype==PART_PHYS_KEYED && psys->flag&PSYS_FIRST_KEYED) {
- psys_count_keyed_targets(ob,psys);
- set_keyed_keys(scene, ob, psys);
- }
+ int result = get_particles_from_cache(scene, ob, psys, (float)framenr, &old_framenr);
+
+ if(result == PTCACHE_READ_EXACT || result == PTCACHE_READ_INTERPOLATED) {
+ //if(part->phystype==PART_PHYS_KEYED && psys->flag&PSYS_FIRST_KEYED) {
+ // psys_count_keyed_targets(ob,psys);
+ // set_keyed_keys(scene, ob, psys);
+ //}
cached_step(scene, ob, psmd, psys, cfra);
psys->cfra=cfra;
psys->recalc = 0;
- if(part->phystype==PART_PHYS_KEYED && psys->flag&PSYS_FIRST_KEYED) {
- psys_update_path_cache(scene, ob, psmd, psys, framenr);
- }
+ //if(part->phystype==PART_PHYS_KEYED && psys->flag&PSYS_FIRST_KEYED) {
+ // psys_update_path_cache(scene, ob, psmd, psys, framenr);
+ //}
cache->simframe= framenr;
cache->flag |= PTCACHE_SIMULATION_VALID;
+ if(result == PTCACHE_READ_INTERPOLATED && cache->flag & PTCACHE_REDO_NEEDED)
+ write_particles_to_cache(ob, psys, cfra);
+
return;
}
+ else if(result==PTCACHE_READ_OLD) {
+ /* set old cfra */
+ psys->cfra = (float)old_framenr;
+
+ for(p=0, pa=psys->particles; p<totpart; p++, pa++) {
+ /* update alive status */
+ if(pa->time > psys->cfra)
+ pa->alive = PARS_UNBORN;
+ else if(pa->dietime <= psys->cfra)
+ pa->alive = PARS_DEAD;
+ else
+ pa->alive = PARS_ALIVE;
+ }
+ }
else if(ob->id.lib || (cache->flag & PTCACHE_BAKED)) {
psys_reset(psys, PSYS_RESET_CACHE_MISS);
psys->cfra=cfra;
psys->recalc = 0;
return;
}
-
- if(framenr != startframe && framedelta != 1) {
- psys_reset(psys, PSYS_RESET_CACHE_MISS);
- psys->cfra = cfra;
- psys->recalc = 0;
- return;
- }
}
else {
cache->flag &= ~PTCACHE_SIMULATION_VALID;
cache->simframe= 0;
+ cache->last_exact= 0;
}
/* if on second frame, write cache for first frame */
- if(usecache && framenr == startframe+1)
+ if(usecache && psys->cfra == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
write_particles_to_cache(ob, psys, startframe);
if(part->phystype==PART_PHYS_KEYED && psys->flag&PSYS_FIRST_KEYED)
@@ -4768,8 +4831,7 @@ static void psys_to_softbody(Scene *scene, Object *ob, ParticleSystem *psys)
static int hair_needs_recalc(ParticleSystem *psys)
{
if((psys->flag & PSYS_EDITED)==0 &&
- ((psys->flag & PSYS_HAIR_DONE)==0 || psys->recalc & PSYS_RECALC_REDO)) {
- psys->recalc &= ~PSYS_RECALC_REDO;
+ ((psys->flag & PSYS_HAIR_DONE)==0 || psys->recalc & PSYS_RECALC_RESET)) {
return 1;
}
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index b00755f7135..64473d07151 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -51,9 +51,11 @@
#include "BKE_object.h"
#include "BKE_particle.h"
#include "BKE_pointcache.h"
+#include "BKE_scene.h"
#include "BKE_softbody.h"
#include "BKE_utildefines.h"
+#include "BLI_blenlib.h"
/* needed for directory lookup */
#ifndef WIN32
@@ -213,21 +215,29 @@ static int BKE_ptcache_id_filename(PTCacheID *pid, char *filename, int cfra, sho
filename[0] = '\0';
newname = filename;
- /*if (!G.relbase_valid) return 0; *//* save blend file before using pointcache */
+ if (!G.relbase_valid) return 0; /* save blend file before using disk pointcache */
/* start with temp dir */
if (do_path) {
len = ptcache_path(pid, filename);
newname += len;
}
- idname = (pid->ob->id.name+2);
- /* convert chars to hex so they are always a valid filename */
- while('\0' != *idname) {
- snprintf(newname, MAX_PTCACHE_FILE, "%02X", (char)(*idname++));
- newname+=2;
- len += 2;
+ if(strcmp(pid->cache->name, "")==0) {
+ idname = (pid->ob->id.name+2);
+ /* convert chars to hex so they are always a valid filename */
+ while('\0' != *idname) {
+ snprintf(newname, MAX_PTCACHE_FILE, "%02X", (char)(*idname++));
+ newname+=2;
+ len += 2;
+ }
}
-
+ else {
+ int temp = strlen(pid->cache->name);
+ strcpy(newname, pid->cache->name);
+ newname+=temp;
+ len += temp;
+ }
+
if (do_ext) {
snprintf(newname, MAX_PTCACHE_FILE, "_%06d_%02d"PTCACHE_EXT, cfra, pid->stack_index); /* always 6 chars */
len += 16;
@@ -247,7 +257,7 @@ PTCacheFile *BKE_ptcache_file_open(PTCacheID *pid, int mode, int cfra)
if(pid->ob->id.lib && mode == PTCACHE_FILE_WRITE)
return NULL;
- /*if (!G.relbase_valid) return NULL; *//* save blend file before using pointcache */
+ if (!G.relbase_valid) return NULL; /* save blend file before using disk pointcache */
BKE_ptcache_id_filename(pid, filename, cfra, 1, 1);
@@ -286,6 +296,427 @@ int BKE_ptcache_file_write_floats(PTCacheFile *pf, float *f, int tot)
return (fwrite(f, sizeof(float), tot, pf->fp) == tot);
}
+static int ptcache_pid_elemsize(PTCacheID *pid)
+{
+ if(pid->type==PTCACHE_TYPE_SOFTBODY)
+ return 0; // TODO
+ else if(pid->type==PTCACHE_TYPE_PARTICLES)
+ return sizeof(ParticleKey);
+ else if(pid->type==PTCACHE_TYPE_CLOTH)
+ return 9 * sizeof(float);
+
+ return 0;
+}
+static int ptcache_pid_totelem(PTCacheID *pid)
+{
+ if(pid->type==PTCACHE_TYPE_SOFTBODY)
+ return 0; // TODO
+ else if(pid->type==PTCACHE_TYPE_PARTICLES) {
+ ParticleSystem *psys = pid->data;
+ return psys->totpart;
+ }
+ else if(pid->type==PTCACHE_TYPE_CLOTH)
+ return 0; // TODO
+
+ return 0;
+}
+
+void BKE_ptcache_update_info(PTCacheID *pid)
+{
+ PointCache *cache = pid->cache;
+ int totframes = 0;
+ char mem_info[64];
+
+ if(cache->flag & PTCACHE_DISK_CACHE) {
+ int cfra = cache->startframe;
+
+ for(; cfra<=cache->endframe; cfra++) {
+ if(BKE_ptcache_id_exist(pid, cfra))
+ totframes++;
+ }
+
+ sprintf(mem_info, "%i frames on disk", totframes);
+ }
+ else {
+ PTCacheMem *pm = cache->mem_cache.first;
+ float framesize = 0.0f, bytes = 0.0f;
+ int mb;
+
+ if(pm)
+ framesize = (float)ptcache_pid_elemsize(pid) * (float)pm->totpoint;
+
+ for(; pm; pm=pm->next)
+ totframes++;
+
+ bytes = totframes * framesize;
+
+ mb = (bytes > 1024.0f * 1024.0f);
+
+ sprintf(mem_info, "%i frames in memory (%.1f %s)",
+ totframes,
+ bytes / (mb ? 1024.0f * 1024.0f : 1024.0f),
+ mb ? "Mb" : "kb");
+ }
+
+ if(cache->flag & PTCACHE_OUTDATED) {
+ sprintf(cache->info, "%s, cache is outdated!", mem_info);
+ }
+ else if(cache->flag & PTCACHE_FRAMES_SKIPPED) {
+ sprintf(cache->info, "%s, not exact since frame %i.", mem_info, cache->last_exact);
+ }
+ else
+ sprintf(cache->info, "%s.", mem_info);
+}
+/* reads cache from disk or memory */
+/* possible to get old or interpolated result */
+int BKE_ptcache_read_cache(PTCacheReader *reader)
+{
+ PTCacheID *pid = reader->pid;
+ PTCacheFile *pf=NULL, *pf2=NULL;
+ PTCacheMem *pm=NULL, *pm2=NULL;
+ int totelem = reader->totelem;
+ float cfra = reader->cfra;
+ int cfrai = (int)cfra;
+ int elemsize = ptcache_pid_elemsize(pid);
+ int i, incr = elemsize / sizeof(float);
+ float frs_sec = reader->scene->r.frs_sec;
+ int cfra1=0, cfra2;
+ int ret = 0;
+
+ if(totelem == 0)
+ return 0;
+
+
+ /* first check if we have the actual frame cached */
+ if(cfra == (float)cfrai) {
+ if(pid->cache->flag & PTCACHE_DISK_CACHE) {
+ pf= BKE_ptcache_file_open(pid, PTCACHE_FILE_READ, cfrai);
+ }
+ else {
+ pm = pid->cache->mem_cache.first;
+
+ for(; pm; pm=pm->next) {
+ if(pm->frame == cfrai)
+ break;
+ }
+ }
+ }
+
+ /* if found, use exact frame */
+ if(pf || pm) {
+ float *data;
+
+ if(pm)
+ data = pm->data;
+ else
+ data = MEM_callocN(elemsize, "pointcache read data");
+
+ for(i=0; i<totelem; i++) {
+ if(pf) {
+ if(!BKE_ptcache_file_read_floats(pf, data, incr)) {
+ BKE_ptcache_file_close(pf);
+ MEM_freeN(data);
+ return 0;
+ }
+
+ reader->set_elem(i, reader->calldata, data);
+ }
+ else {
+ reader->set_elem(i, reader->calldata, data);
+ data += incr;
+ }
+ }
+
+ if(pf) {
+ BKE_ptcache_file_close(pf);
+ MEM_freeN(data);
+ }
+
+ ret = PTCACHE_READ_EXACT;
+ }
+
+ if(ret)
+ ;
+ /* no exact cache frame found so try to find cached frames around cfra */
+ else if(pid->cache->flag & PTCACHE_DISK_CACHE) {
+ pf=NULL;
+ while(cfrai > pid->cache->startframe && !pf) {
+ cfrai--;
+ pf= BKE_ptcache_file_open(pid, PTCACHE_FILE_READ, cfrai);
+ cfra1 = cfrai;
+ }
+
+ if(reader->old_frame)
+ *(reader->old_frame) = cfrai;
+
+ cfrai = (int)cfra;
+ while(cfrai < pid->cache->endframe && !pf2) {
+ cfrai++;
+ pf2= BKE_ptcache_file_open(pid, PTCACHE_FILE_READ, cfrai);
+ cfra2 = cfrai;
+ }
+ }
+ else if(pid->cache->mem_cache.first){
+ pm = pid->cache->mem_cache.first;
+
+ while(pm->next && pm->next->frame < cfra)
+ pm= pm->next;
+
+ if(pm) {
+ if(reader->old_frame)
+ *(reader->old_frame) = pm->frame;
+ cfra1 = pm->frame;
+ }
+
+ pm2 = pid->cache->mem_cache.last;
+
+ if(pm2 && pm2->frame < cfra)
+ pm2 = NULL;
+ else {
+ while(pm2->prev && pm2->prev->frame > cfra)
+ pm2= pm2->prev;
+
+ if(pm2)
+ cfra2 = pm2->frame;
+ }
+ }
+
+ if(ret)
+ ;
+ else if((pf && pf2) || (pm && pm2)) {
+ /* interpolate from nearest frames if cache isn't outdated */
+ float *data1, *data2;
+
+ if(pm) {
+ data1 = pm->data;
+ data2 = pm2->data;
+ }
+ else {
+ data1 = MEM_callocN(elemsize, "pointcache read data1");
+ data2 = MEM_callocN(elemsize, "pointcache read data2");
+ }
+
+ for(i=0; i<totelem; i++) {
+ if(pf && pf2) {
+ if(!BKE_ptcache_file_read_floats(pf, data1, incr)) {
+ BKE_ptcache_file_close(pf);
+ BKE_ptcache_file_close(pf2);
+ MEM_freeN(data1);
+ MEM_freeN(data2);
+ return 0;
+ }
+ if(!BKE_ptcache_file_read_floats(pf2, data2, incr)) {
+ BKE_ptcache_file_close(pf);
+ BKE_ptcache_file_close(pf2);
+ MEM_freeN(data1);
+ MEM_freeN(data2);
+ return 0;
+ }
+ reader->interpolate_elem(i, reader->calldata, frs_sec, cfra, (float)cfra1, (float)cfra2, data1, data2);
+ }
+ else {
+ reader->interpolate_elem(i, reader->calldata, frs_sec, cfra, (float)cfra1, (float)cfra2, data1, data2);
+ data1 += incr;
+ data2 += incr;
+ }
+ }
+
+ if(pf) {
+ BKE_ptcache_file_close(pf);
+ BKE_ptcache_file_close(pf2);
+ MEM_freeN(data1);
+ MEM_freeN(data2);
+ }
+
+ ret = PTCACHE_READ_INTERPOLATED;
+ }
+ else if(pf || pm) {
+ /* use last valid cache frame */
+ float *data;
+
+ /* don't read cache if allready simulated past cached frame */
+ if(cfra1 && cfra1 <= pid->cache->simframe) {
+ if(pf)
+ BKE_ptcache_file_close(pf);
+ if(pf2)
+ BKE_ptcache_file_close(pf2);
+
+ return 0;
+ }
+
+ if(pm)
+ data = pm->data;
+ else
+ data = MEM_callocN(elemsize, "pointcache read data");
+
+ for(i=0; i<totelem; i++) {
+ if(pf) {
+ if(!BKE_ptcache_file_read_floats(pf, data, incr)) {
+ BKE_ptcache_file_close(pf);
+ if(pf2)
+ BKE_ptcache_file_close(pf2);
+ return 0;
+ }
+ reader->set_elem(i, reader->calldata, data);
+ }
+ else {
+ reader->set_elem(i, reader->calldata, data);
+ data += incr;
+ }
+ }
+
+ if(pf) {
+ BKE_ptcache_file_close(pf);
+ MEM_freeN(data);
+ }
+ if(pf2)
+ BKE_ptcache_file_close(pf2);
+
+ ret = PTCACHE_READ_OLD;
+ }
+
+ if(pf)
+ BKE_ptcache_file_close(pf);
+ if(pf2)
+ BKE_ptcache_file_close(pf2);
+
+ if((pid->cache->flag & PTCACHE_QUICK_CACHE)==0) {
+ /* clear invalid cache frames so that better stuff can be simulated */
+ if(pid->cache->flag & PTCACHE_OUTDATED) {
+ BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_AFTER, cfra);
+ }
+ else if(pid->cache->flag & PTCACHE_FRAMES_SKIPPED) {
+ if(cfra <= pid->cache->last_exact)
+ pid->cache->flag &= ~PTCACHE_FRAMES_SKIPPED;
+
+ BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_AFTER, MAX2(cfra,pid->cache->last_exact));
+ }
+ }
+
+ return ret;
+}
+/* writes cache to disk or memory */
+int BKE_ptcache_write_cache(PTCacheWriter *writer)
+{
+ PointCache *cache = writer->pid->cache;
+ PTCacheFile *pf= NULL;
+ int elemsize = ptcache_pid_elemsize(writer->pid);
+ int i, incr = elemsize / sizeof(float);
+ int add = 0, overwrite = 0, ocfra;
+ float temp[14];
+
+ if(writer->totelem == 0 || writer->cfra <= 0)
+ return 0;
+
+ if(cache->flag & PTCACHE_DISK_CACHE) {
+ /* allways start from scratch on the first frame */
+ if(writer->cfra == cache->startframe) {
+ BKE_ptcache_id_clear(writer->pid, PTCACHE_CLEAR_ALL, writer->cfra);
+ cache->flag &= ~PTCACHE_REDO_NEEDED;
+ add = 1;
+ }
+ else {
+ int cfra = cache->endframe;
+ /* find last cached frame */
+ while(cfra > cache->startframe && !BKE_ptcache_id_exist(writer->pid, cfra))
+ cfra--;
+
+ /* find second last cached frame */
+ ocfra = cfra-1;
+ while(ocfra > cache->startframe && !BKE_ptcache_id_exist(writer->pid, ocfra))
+ ocfra--;
+
+ if(writer->cfra > cfra) {
+ if(ocfra >= cache->startframe && cfra - ocfra < cache->step)
+ overwrite = 1;
+ else
+ add = 1;
+ }
+ }
+
+ if(add || overwrite) {
+ if(overwrite)
+ BKE_ptcache_id_clear(writer->pid, PTCACHE_CLEAR_FRAME, ocfra);
+
+ pf = BKE_ptcache_file_open(writer->pid, PTCACHE_FILE_WRITE, writer->cfra);
+ if(!pf)
+ return 0;
+
+ for(i=0; i<writer->totelem; i++) {
+ writer->set_elem(i, writer->calldata, &temp);
+ BKE_ptcache_file_write_floats(pf, &temp, incr);
+ }
+ }
+ }
+ else {
+ PTCacheMem *pm;
+ PTCacheMem *pm2;
+ float *pmdata;
+
+ pm2 = cache->mem_cache.first;
+
+ /* allways start from scratch on the first frame */
+ if(writer->cfra == cache->startframe) {
+ BKE_ptcache_id_clear(writer->pid, PTCACHE_CLEAR_ALL, writer->cfra);
+ cache->flag &= ~PTCACHE_REDO_NEEDED;
+ add = 1;
+ }
+ else {
+ pm2 = cache->mem_cache.last;
+
+ if(pm2 && writer->cfra > pm2->frame) {
+ if(pm2 && pm2->prev && pm2->frame - pm2->prev->frame < cache->step)
+ overwrite = 1;
+ else
+ add = 1;
+ }
+ }
+
+ if(overwrite) {
+ pm = cache->mem_cache.last;
+ pmdata = pm->data;
+
+ for(i=0; i<writer->totelem; i++, pmdata+=incr) {
+ writer->set_elem(i, writer->calldata, &temp);
+ memcpy(pmdata, &temp, elemsize);
+ }
+
+ pm->frame = writer->cfra;
+ }
+ else if(add) {
+ pm = MEM_callocN(sizeof(PTCacheMem), "Pointcache mem");
+ pm->data = MEM_callocN(elemsize * writer->totelem, "Pointcache mem data");
+ pmdata = pm->data;
+
+ for(i=0; i<writer->totelem; i++, pmdata+=incr) {
+ writer->set_elem(i, writer->calldata, &temp);
+ memcpy(pmdata, &temp, elemsize);
+ }
+
+ pm->frame = writer->cfra;
+ pm->totpoint = writer->totelem;
+
+ BLI_addtail(&cache->mem_cache, pm);
+ }
+ }
+
+ if(add || overwrite) {
+ if(writer->cfra - cache->last_exact == 1
+ || writer->cfra == cache->startframe) {
+ cache->last_exact = writer->cfra;
+ cache->flag &= ~PTCACHE_FRAMES_SKIPPED;
+ }
+ else
+ cache->flag |= PTCACHE_FRAMES_SKIPPED;
+ }
+
+ if(pf)
+ BKE_ptcache_file_close(pf);
+
+ BKE_ptcache_update_info(writer->pid);
+
+ return 1;
+}
/* youll need to close yourself after!
* mode - PTCACHE_CLEAR_ALL,
@@ -317,62 +748,116 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, int cfra)
case PTCACHE_CLEAR_ALL:
case PTCACHE_CLEAR_BEFORE:
case PTCACHE_CLEAR_AFTER:
- ptcache_path(pid, path);
-
- len = BKE_ptcache_id_filename(pid, filename, cfra, 0, 0); /* no path */
-
- dir = opendir(path);
- if (dir==NULL)
- return;
-
- snprintf(ext, sizeof(ext), "_%02d"PTCACHE_EXT, pid->stack_index);
-
- while ((de = readdir(dir)) != NULL) {
- if (strstr(de->d_name, ext)) { /* do we have the right extension?*/
- if (strncmp(filename, de->d_name, len ) == 0) { /* do we have the right prefix */
- if (mode == PTCACHE_CLEAR_ALL) {
- BLI_join_dirfile(path_full, path, de->d_name);
- BLI_delete(path_full, 0, 0);
- } else {
- /* read the number of the file */
- int frame, len2 = strlen(de->d_name);
- char num[7];
-
- if (len2 > 15) { /* could crash if trying to copy a string out of this range*/
- BLI_strncpy(num, de->d_name + (strlen(de->d_name) - 15), sizeof(num));
- frame = atoi(num);
-
- if((mode==PTCACHE_CLEAR_BEFORE && frame < cfra) ||
- (mode==PTCACHE_CLEAR_AFTER && frame > cfra) ) {
+ if(pid->cache->flag & PTCACHE_DISK_CACHE) {
+ ptcache_path(pid, path);
+
+ len = BKE_ptcache_id_filename(pid, filename, cfra, 0, 0); /* no path */
+
+ dir = opendir(path);
+ if (dir==NULL)
+ return;
+
+ snprintf(ext, sizeof(ext), "_%02d"PTCACHE_EXT, pid->stack_index);
+
+ while ((de = readdir(dir)) != NULL) {
+ if (strstr(de->d_name, ext)) { /* do we have the right extension?*/
+ if (strncmp(filename, de->d_name, len ) == 0) { /* do we have the right prefix */
+ if (mode == PTCACHE_CLEAR_ALL) {
+ pid->cache->last_exact = 0;
+ BLI_join_dirfile(path_full, path, de->d_name);
+ BLI_delete(path_full, 0, 0);
+ } else {
+ /* read the number of the file */
+ int frame, len2 = strlen(de->d_name);
+ char num[7];
+
+ if (len2 > 15) { /* could crash if trying to copy a string out of this range*/
+ BLI_strncpy(num, de->d_name + (strlen(de->d_name) - 15), sizeof(num));
+ frame = atoi(num);
- BLI_join_dirfile(path_full, path, de->d_name);
- BLI_delete(path_full, 0, 0);
+ if((mode==PTCACHE_CLEAR_BEFORE && frame < cfra) ||
+ (mode==PTCACHE_CLEAR_AFTER && frame > cfra) ) {
+
+ BLI_join_dirfile(path_full, path, de->d_name);
+ BLI_delete(path_full, 0, 0);
+ }
}
}
}
}
}
+ closedir(dir);
+ }
+ else {
+ PTCacheMem *pm= pid->cache->mem_cache.first;
+ PTCacheMem *link= NULL;
+
+ if(mode == PTCACHE_CLEAR_ALL) {
+ pid->cache->last_exact = 0;
+ for(; pm; pm=pm->next)
+ MEM_freeN(pm->data);
+ BLI_freelistN(&pid->cache->mem_cache);
+ } else {
+ while(pm) {
+ if((mode==PTCACHE_CLEAR_BEFORE && pm->frame < cfra) ||
+ (mode==PTCACHE_CLEAR_AFTER && pm->frame > cfra) ) {
+ link = pm;
+ pm = pm->next;
+ MEM_freeN(link->data);
+ BLI_freelinkN(&pid->cache->mem_cache, link);
+ }
+ else
+ pm = pm->next;
+ }
+ }
}
- closedir(dir);
break;
case PTCACHE_CLEAR_FRAME:
- len = BKE_ptcache_id_filename(pid, filename, cfra, 1, 1); /* no path */
- BLI_delete(filename, 0, 0);
+ if(pid->cache->flag & PTCACHE_DISK_CACHE) {
+ if(BKE_ptcache_id_exist(pid, cfra)) {
+ BKE_ptcache_id_filename(pid, filename, cfra, 1, 1); /* no path */
+ BLI_delete(filename, 0, 0);
+ }
+ }
+ else {
+ PTCacheMem *pm = pid->cache->mem_cache.first;
+
+ for(; pm; pm=pm->next) {
+ if(pm->frame == cfra) {
+ MEM_freeN(pm->data);
+ BLI_freelinkN(&pid->cache->mem_cache, pm);
+ break;
+ }
+ }
+ }
break;
}
+
+ BKE_ptcache_update_info(pid);
}
int BKE_ptcache_id_exist(PTCacheID *pid, int cfra)
{
- char filename[MAX_PTCACHE_FILE];
-
if(!pid->cache)
return 0;
- BKE_ptcache_id_filename(pid, filename, cfra, 1, 1);
+ if(pid->cache->flag & PTCACHE_DISK_CACHE) {
+ char filename[MAX_PTCACHE_FILE];
+
+ BKE_ptcache_id_filename(pid, filename, cfra, 1, 1);
- return BLI_exists(filename);
+ return BLI_exists(filename);
+ }
+ else {
+ PTCacheMem *pm = pid->cache->mem_cache.first;
+
+ for(; pm; pm=pm->next) {
+ if(pm->frame==cfra)
+ return 1;
+ }
+ return 0;
+ }
}
void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startframe, int *endframe, float *timescale)
@@ -381,6 +866,9 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra
PointCache *cache;
float offset, time, nexttime;
+ /* TODO: this has to be sorter out once bsystem_time gets redone, */
+ /* now caches can handle interpolating etc. too - jahka */
+
/* time handling for point cache:
* - simulation time is scaled by result of bsystem_time
* - for offsetting time only time offset is taken into account, since
@@ -414,10 +902,10 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra
}
}
-int BKE_ptcache_id_reset(PTCacheID *pid, int mode)
+int BKE_ptcache_id_reset(Scene *scene, PTCacheID *pid, int mode)
{
PointCache *cache;
- int reset, clear;
+ int reset, clear, after;
if(!pid->cache)
return 0;
@@ -425,14 +913,17 @@ int BKE_ptcache_id_reset(PTCacheID *pid, int mode)
cache= pid->cache;
reset= 0;
clear= 0;
+ after= 0;
if(mode == PTCACHE_RESET_DEPSGRAPH) {
if(!(cache->flag & PTCACHE_BAKED) && !BKE_ptcache_get_continue_physics()) {
- reset= 1;
- clear= 1;
+ if(cache->flag & PTCACHE_QUICK_CACHE)
+ clear= 1;
+
+ after= 1;
}
- else
- cache->flag |= PTCACHE_OUTDATED;
+
+ cache->flag |= PTCACHE_OUTDATED;
}
else if(mode == PTCACHE_RESET_BAKED) {
if(!BKE_ptcache_get_continue_physics()) {
@@ -451,8 +942,9 @@ int BKE_ptcache_id_reset(PTCacheID *pid, int mode)
}
if(reset) {
- cache->flag &= ~(PTCACHE_OUTDATED|PTCACHE_SIMULATION_VALID);
+ cache->flag &= ~(PTCACHE_REDO_NEEDED|PTCACHE_SIMULATION_VALID);
cache->simframe= 0;
+ cache->last_exact= 0;
if(pid->type == PTCACHE_TYPE_CLOTH)
cloth_free_modifier(pid->ob, pid->data);
@@ -463,11 +955,13 @@ int BKE_ptcache_id_reset(PTCacheID *pid, int mode)
}
if(clear)
BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
+ else if(after)
+ BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_AFTER, CFRA);
- return (reset || clear);
+ return (reset || clear || after);
}
-int BKE_ptcache_object_reset(Object *ob, int mode)
+int BKE_ptcache_object_reset(Scene *scene, Object *ob, int mode)
{
PTCacheID pid;
ParticleSystem *psys;
@@ -479,7 +973,7 @@ int BKE_ptcache_object_reset(Object *ob, int mode)
if(ob->soft) {
BKE_ptcache_id_from_softbody(&pid, ob, ob->soft);
- reset |= BKE_ptcache_id_reset(&pid, mode);
+ reset |= BKE_ptcache_id_reset(scene, &pid, mode);
}
for(psys=ob->particlesystem.first; psys; psys=psys->next) {
@@ -488,23 +982,23 @@ int BKE_ptcache_object_reset(Object *ob, int mode)
if(psys->soft) {
BKE_ptcache_id_from_softbody(&pid, ob, psys->soft);
if(mode == PSYS_RESET_ALL || !(psys->part->type == PART_HAIR && (pid.cache->flag & PTCACHE_BAKED)))
- reset |= BKE_ptcache_id_reset(&pid, mode);
+ reset |= BKE_ptcache_id_reset(scene, &pid, mode);
else
skip = 1;
}
- else if((psys->recalc & PSYS_RECALC_RESET)==0)
+ else if(psys->recalc & PSYS_RECALC_REDO || psys->recalc & PSYS_RECALC_CHILD)
skip = 1;
if(skip == 0) {
BKE_ptcache_id_from_particles(&pid, ob, psys);
- reset |= BKE_ptcache_id_reset(&pid, mode);
+ reset |= BKE_ptcache_id_reset(scene, &pid, mode);
}
}
for(md=ob->modifiers.first; md; md=md->next) {
if(md->type == eModifierType_Cloth) {
BKE_ptcache_id_from_cloth(&pid, ob, (ClothModifierData*)md);
- reset |= BKE_ptcache_id_reset(&pid, mode);
+ reset |= BKE_ptcache_id_reset(scene, &pid, mode);
}
}
@@ -564,7 +1058,7 @@ void BKE_ptcache_set_continue_physics(Scene *scene, int enable)
if(CONTINUE_PHYSICS == 0) {
for(ob=G.main->object.first; ob; ob=ob->id.next)
- if(BKE_ptcache_object_reset(ob, PTCACHE_RESET_OUTDATED))
+ if(BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_OUTDATED))
DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
}
}
@@ -584,12 +1078,21 @@ PointCache *BKE_ptcache_add()
cache= MEM_callocN(sizeof(PointCache), "PointCache");
cache->startframe= 1;
cache->endframe= 250;
+ cache->step= 10;
return cache;
}
void BKE_ptcache_free(PointCache *cache)
{
+ PTCacheMem *pm = cache->mem_cache.first;
+ if(pm) {
+ for(; pm; pm=pm->next)
+ MEM_freeN(pm->data);
+
+ BLI_freelistN(&cache->mem_cache);
+ }
+
MEM_freeN(cache);
}
@@ -605,3 +1108,276 @@ PointCache *BKE_ptcache_copy(PointCache *cache)
return ncache;
}
+
+
+/* Baking */
+static int count_quick_cache(Scene *scene, int *quick_step)
+{
+ Base *base = scene->base.first;
+ PTCacheID *pid;
+ ListBase pidlist;
+ int autocache_count= 0;
+
+ for(base = scene->base.first; base; base = base->next) {
+ if(base->object) {
+ BKE_ptcache_ids_from_object(&pidlist, base->object);
+
+ for(pid=pidlist.first; pid; pid=pid->next) {
+ if((pid->cache->flag & PTCACHE_BAKED)
+ || (pid->cache->flag & PTCACHE_QUICK_CACHE)==0)
+ continue;
+
+ if(pid->cache->flag & PTCACHE_OUTDATED || (pid->cache->flag & PTCACHE_SIMULATION_VALID)==0) {
+ if(!autocache_count)
+ *quick_step = pid->cache->step;
+ else
+ *quick_step = MIN2(*quick_step, pid->cache->step);
+
+ autocache_count++;
+ }
+ }
+
+ BLI_freelistN(&pidlist);
+ }
+ }
+
+ return autocache_count;
+}
+void BKE_ptcache_quick_cache_all(Scene *scene)
+{
+ PTCacheBaker baker;
+
+ baker.bake=0;
+ baker.break_data=NULL;
+ baker.break_test=NULL;
+ baker.pid=NULL;
+ baker.progressbar=NULL;
+ baker.progresscontext=NULL;
+ baker.render=0;
+ baker.scene=scene;
+
+ if(count_quick_cache(scene, &baker.quick_step))
+ BKE_ptcache_make_cache(&baker);
+}
+
+/* if bake is not given run simulations to current frame */
+void BKE_ptcache_make_cache(PTCacheBaker* baker)
+{
+ Scene *scene = baker->scene;
+ Base *base;
+ ListBase pidlist;
+ PTCacheID *pid = baker->pid;
+ PointCache *cache;
+ float frameleno = scene->r.framelen;
+ int cfrao = CFRA;
+ int startframe = MAXFRAME;
+ int endframe = CFRA;
+ int bake = baker->bake;
+ int render = baker->render;
+ int step = baker->quick_step;
+
+ G.afbreek = 0;
+
+ /* set caches to baking mode and figure out start frame */
+ if(pid) {
+ /* cache/bake a single object */
+ cache = pid->cache;
+ if((cache->flag & PTCACHE_BAKED)==0) {
+ if(pid->type==PTCACHE_TYPE_PARTICLES)
+ psys_get_pointcache_start_end(scene, pid->data, &cache->startframe, &cache->endframe);
+
+ if(bake || cache->flag & PTCACHE_REDO_NEEDED)
+ BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
+
+ startframe = MAX2(cache->last_exact, cache->startframe);
+
+ if(bake) {
+ endframe = cache->endframe;
+ cache->flag |= PTCACHE_BAKING;
+ }
+ else {
+ endframe = MIN2(endframe, cache->endframe);
+ }
+
+ cache->flag &= ~PTCACHE_BAKED;
+ }
+ }
+ else for(base=scene->base.first; base; base= base->next) {
+ /* cache/bake everything in the scene */
+ BKE_ptcache_ids_from_object(&pidlist, base->object);
+
+ for(pid=pidlist.first; pid; pid=pid->next) {
+ cache = pid->cache;
+ if((cache->flag & PTCACHE_BAKED)==0) {
+ if(pid->type==PTCACHE_TYPE_PARTICLES)
+ psys_get_pointcache_start_end(scene, pid->data, &cache->startframe, &cache->endframe);
+
+ if((cache->flag & PTCACHE_REDO_NEEDED || (cache->flag & PTCACHE_SIMULATION_VALID)==0)
+ && ((cache->flag & PTCACHE_QUICK_CACHE)==0 || render || bake))
+ BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
+
+ startframe = MIN2(startframe, cache->startframe);
+
+ if(bake || render) {
+ cache->flag |= PTCACHE_BAKING;
+
+ if(bake)
+ endframe = MAX2(endframe, cache->endframe);
+ }
+
+ cache->flag &= ~PTCACHE_BAKED;
+
+ }
+ }
+ BLI_freelistN(&pidlist);
+ }
+
+ CFRA= startframe;
+ scene->r.framelen = 1.0;
+
+ for(; CFRA <= endframe; CFRA+=step) {
+ float prog;
+
+ if(bake)
+ prog = (int)(100.0 * (float)(CFRA - startframe)/(float)(endframe-startframe));
+ else
+ prog = CFRA;
+
+ /* NOTE: baking should not redraw whole ui as this slows things down */
+ if(baker->progressbar)
+ baker->progressbar(baker->progresscontext, prog);
+
+ scene_update_for_newframe(scene, scene->lay);
+
+ /* NOTE: breaking baking should leave calculated frames in cache, not clear it */
+ if(baker->break_test && baker->break_test(baker->break_data))
+ break;
+ }
+
+ /* clear baking flag */
+ if(pid) {
+ cache->flag &= ~(PTCACHE_BAKING|PTCACHE_REDO_NEEDED);
+ cache->flag |= PTCACHE_SIMULATION_VALID;
+ if(bake)
+ cache->flag |= PTCACHE_BAKED;
+ }
+ else for(base=scene->base.first; base; base= base->next) {
+ BKE_ptcache_ids_from_object(&pidlist, base->object);
+
+ for(pid=pidlist.first; pid; pid=pid->next) {
+ cache = pid->cache;
+
+ if(step > 1)
+ cache->flag &= ~(PTCACHE_BAKING|PTCACHE_OUTDATED);
+ else
+ cache->flag &= ~(PTCACHE_BAKING|PTCACHE_REDO_NEEDED);
+
+ cache->flag |= PTCACHE_SIMULATION_VALID;
+
+ if(bake)
+ cache->flag |= PTCACHE_BAKED;
+ }
+ BLI_freelistN(&pidlist);
+ }
+
+ scene->r.framelen = frameleno;
+ CFRA = cfrao;
+ scene_update_for_newframe(scene, scene->lay);
+
+ /* TODO: call redraw all windows somehow */
+}
+
+void BKE_ptcache_toggle_disk_cache(PTCacheID *pid) {
+ PointCache *cache = pid->cache;
+ PTCacheFile *pf;
+ PTCacheMem *pm;
+ int totelem=0;
+ int float_count=0;
+ int tot;
+ int last_exact = cache->last_exact;
+
+ if (!G.relbase_valid){
+ cache->flag &= ~PTCACHE_DISK_CACHE;
+ return;
+ }
+
+ totelem = ptcache_pid_totelem(pid);
+ float_count = ptcache_pid_elemsize(pid) / sizeof(float);
+
+ if(totelem==0 || float_count==0)
+ return;
+
+ tot = totelem*float_count;
+
+ /* MEM -> DISK */
+ if(cache->flag & PTCACHE_DISK_CACHE) {
+ pm = cache->mem_cache.first;
+
+ BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
+
+ for(; pm; pm=pm->next) {
+ pf = BKE_ptcache_file_open(pid, PTCACHE_FILE_WRITE, pm->frame);
+
+ if(pf) {
+ if(fwrite(pm->data, sizeof(float), tot, pf->fp) != tot) {
+ printf("Error writing to disk cache\n");
+
+ cache->flag &= ~PTCACHE_DISK_CACHE;
+
+ BKE_ptcache_file_close(pf);
+ return;
+ }
+ BKE_ptcache_file_close(pf);
+ }
+ else
+ printf("Error creating disk cache file\n");
+ }
+
+ cache->flag &= ~PTCACHE_DISK_CACHE;
+ BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
+ cache->flag |= PTCACHE_DISK_CACHE;
+ }
+ /* DISK -> MEM */
+ else {
+ int cfra;
+ int sfra = cache->startframe;
+ int efra = cache->endframe;
+
+ BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
+
+ for(cfra=sfra; cfra <= efra; cfra++) {
+ pf = BKE_ptcache_file_open(pid, PTCACHE_FILE_READ, cfra);
+
+ if(pf) {
+ pm = MEM_callocN(sizeof(PTCacheMem), "Pointcache mem");
+ pm->data = MEM_callocN(sizeof(float)*tot, "Pointcache mem data");
+
+ if(fread(pm->data, sizeof(float), tot, pf->fp)!= tot) {
+ printf("Error reading from disk cache\n");
+
+ cache->flag |= PTCACHE_DISK_CACHE;
+
+ MEM_freeN(pm->data);
+ MEM_freeN(pm);
+ BKE_ptcache_file_close(pf);
+ return;
+ }
+
+ pm->frame = cfra;
+ pm->totpoint = totelem;
+
+ BLI_addtail(&pid->cache->mem_cache, pm);
+
+ BKE_ptcache_file_close(pf);
+ }
+ }
+
+ cache->flag |= PTCACHE_DISK_CACHE;
+ BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
+ cache->flag &= ~PTCACHE_DISK_CACHE;
+ }
+
+ cache->last_exact = last_exact;
+
+ BKE_ptcache_update_info(pid);
+}
diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c
index 1d97eccb9f3..8de8cf8d0f4 100644
--- a/source/blender/blenkernel/intern/report.c
+++ b/source/blender/blenkernel/intern/report.c
@@ -1,5 +1,5 @@
/**
- * $Id: report.c 21247 2009-06-29 21:50:53Z jaguarandi $
+ * $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -65,8 +65,8 @@ void BKE_reports_init(ReportList *reports, int flag)
memset(reports, 0, sizeof(ReportList));
- reports->storelevel= RPT_WARNING;
- reports->printlevel= RPT_WARNING;
+ reports->storelevel= RPT_INFO;
+ reports->printlevel= RPT_INFO;
reports->flag= flag;
}
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 156bdae9b00..23da5c66850 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -142,8 +142,6 @@ void free_scene(Scene *sce)
BLI_freelistN(&sce->base);
seq_free_editing(sce->ed);
- if(sce->radio) MEM_freeN(sce->radio);
- sce->radio= 0;
#ifndef DISABLE_PYTHON
BPY_free_scriptlink(&sce->scriptlink);
@@ -205,9 +203,6 @@ Scene *add_scene(char *name)
sce= alloc_libblock(&G.main->scene, ID_SCE, name);
sce->lay= 1;
- sce->selectmode= SCE_SELECT_VERTEX;
- sce->editbutsize= 0.1;
- sce->autokey_mode= U.autokey_mode;
sce->r.mode= R_GAMMA;
sce->r.cfra= 1;
@@ -277,6 +272,10 @@ Scene *add_scene(char *name)
sce->toolsettings->select_thresh= 0.01f;
sce->toolsettings->jointrilimit = 0.8f;
+ sce->toolsettings->selectmode= SCE_SELECT_VERTEX;
+ sce->toolsettings->normalsize= 0.1;
+ sce->toolsettings->autokey_mode= U.autokey_mode;
+
sce->toolsettings->skgen_resolution = 100;
sce->toolsettings->skgen_threshold_internal = 0.01f;
sce->toolsettings->skgen_threshold_external = 0.01f;
diff --git a/source/blender/blenkernel/intern/sequence.c b/source/blender/blenkernel/intern/sequence.c
index bb0665a5b0f..7fc262b4796 100644
--- a/source/blender/blenkernel/intern/sequence.c
+++ b/source/blender/blenkernel/intern/sequence.c
@@ -1,5 +1,5 @@
/**
-* $Id: sequence.c 17508 2008-11-20 00:34:24Z campbellbarton $
+* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*