[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12490] branches/cloth/blender/source/ blender: Merged pointcache from particles branch, but is not used in the moment

Daniel Genrich daniel.genrich at gmx.net
Tue Nov 6 10:44:09 CET 2007


Revision: 12490
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12490
Author:   genscher
Date:     2007-11-06 10:44:09 +0100 (Tue, 06 Nov 2007)

Log Message:
-----------
Merged pointcache from particles branch, but is not used in the moment

Modified Paths:
--------------
    branches/cloth/blender/source/blender/blenkernel/intern/modifier.c
    branches/cloth/blender/source/blender/makesdna/DNA_modifier_types.h
    branches/cloth/blender/source/blender/src/buttons_editing.c

Added Paths:
-----------
    branches/cloth/blender/source/blender/blenkernel/BKE_pointcache.h
    branches/cloth/blender/source/blender/blenkernel/intern/pointcache.c

Added: branches/cloth/blender/source/blender/blenkernel/BKE_pointcache.h
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/BKE_pointcache.h	                        (rev 0)
+++ branches/cloth/blender/source/blender/blenkernel/BKE_pointcache.h	2007-11-06 09:44:09 UTC (rev 12490)
@@ -0,0 +1,41 @@
+/*
+*
+* ***** BEGIN GPL LICENSE BLOCK *****
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software  Foundation,
+* Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*
+* The Original Code is Copyright (C) 2006 Blender Foundation.
+* All rights reserved.
+*
+* The Original Code is: all of this file.
+*
+* Contributor(s): Campbell Barton <ideasman42 at gmail.com>
+*
+* ***** END GPL LICENSE BLOCK *****
+*/
+
+#ifndef BKE_POINTCACHE_H
+#define BKE_POINTCACHE_H
+
+#include "DNA_ID.h"
+
+#define PTCache_EXT ".bphys"
+#define PTCache_PATH "//pointcache/"
+
+int		PTCache_id_filename(struct ID *id, char *filename, int cfra, int stack_index, short do_path, short do_ext);
+FILE *	PTCache_id_fopen(struct ID *id, char mode, int cfra, int stack_index);
+void	PTCache_id_clear(struct ID *id, int cfra, int stack_index);
+
+#endif

Modified: branches/cloth/blender/source/blender/blenkernel/intern/modifier.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/modifier.c	2007-11-06 02:34:53 UTC (rev 12489)
+++ branches/cloth/blender/source/blender/blenkernel/intern/modifier.c	2007-11-06 09:44:09 UTC (rev 12490)
@@ -5382,6 +5382,83 @@
 	dm->release(dm);
 }
 
+
+/* PointCache - example DONT USE SERIOUSLY */
+static void pointCacheModifier_initData(ModifierData *md)
+{
+	PointCacheModifierData *pcm= (PointCacheModifierData*) md;
+
+	pcm->mode= ePointCache_Read; /* read */
+}
+static void pointCacheModifier_freeData(ModifierData *md)
+{
+	PointCacheModifierData *pcm = (PointCacheModifierData*) md;
+}
+static void pointCacheModifier_copyData(ModifierData *md, ModifierData *target)
+{
+	PointCacheModifierData *pcm= (PointCacheModifierData*) md;
+	PointCacheModifierData *tpcm= (PointCacheModifierData*) target;
+
+	tpcm->mode = pcm->mode;
+}
+static int pointCacheModifier_dependsOnTime(ModifierData *md) 
+{
+	return 1;
+}
+CustomDataMask pointCacheModifier_requiredDataMask(ModifierData *md)
+{
+	PointCacheModifierData *pcm= (PointCacheModifierData*) md;
+	CustomDataMask dataMask = 0;
+	return dataMask;
+}
+
+static void pointCacheModifier_deformVerts(
+					   ModifierData *md, Object *ob, DerivedMesh *derivedData,
+	float (*vertexCos)[3], int numVerts)
+{
+	PointCacheModifierData *pcm = (PointCacheModifierData*) md;
+
+	FILE *fp = NULL;
+	int i;
+	int stack_index = modifiers_indexInObject(ob, md);
+	int totvert;
+	MVert *mvert, *mv;
+	
+	DerivedMesh *dm;
+
+	if(derivedData) dm = CDDM_copy(derivedData);
+	else if(ob->type==OB_MESH) dm = CDDM_from_mesh(ob->data, ob);
+	else return;
+
+	CDDM_apply_vert_coords(dm, vertexCos);
+	CDDM_calc_normals(dm);
+	
+	mvert = mv = dm->getVertArray(dm);
+	totvert = dm->getNumVerts(dm);
+			
+	if (pcm->mode == ePointCache_Read) {
+		fp = PTCache_id_fopen((ID *)ob, 'w', G.scene->r.cfra, stack_index);
+		if (!fp) return;
+		for (mv=mvert, i=0; i<totvert; mv++, i++) {
+			fwrite(&mv->co, sizeof(float), 3, fp);
+		}
+		fclose(fp);
+	} else if (pcm->mode == ePointCache_Write) {
+		float pt[3];
+		fp = PTCache_id_fopen((ID *)ob, 'r', G.scene->r.cfra, stack_index);
+		if (!fp) return;
+		for (mv=mvert, i=0; i<totvert; mv++, i++) {
+			float *co = vertexCos[i];
+			if ((fread(co, sizeof(float), 3, fp)) != 3) {
+				break;
+			}
+		}
+		fclose(fp);
+	}
+	
+	if(!derivedData) dm->release(dm);
+}
+
 /***/
 
 static ModifierTypeInfo typeArr[NUM_MODIFIER_TYPES];
@@ -5649,6 +5726,16 @@
 		mti->updateDepgraph = meshdeformModifier_updateDepgraph;
 		mti->deformVerts = meshdeformModifier_deformVerts;
 		mti->deformVertsEM = meshdeformModifier_deformVertsEM;
+		
+		mti = INIT_TYPE(PointCache);
+		mti->type = eModifierTypeType_OnlyDeform;
+		mti->flags = eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_RequiresOriginalData;
+		mti->initData = pointCacheModifier_initData;
+		mti->freeData = pointCacheModifier_freeData;
+		mti->copyData = pointCacheModifier_copyData;
+		mti->dependsOnTime = pointCacheModifier_dependsOnTime;
+		mti->requiredDataMask = pointCacheModifier_requiredDataMask;
+		mti->deformVerts = pointCacheModifier_deformVerts;
 
 		typeArrInit = 0;
 #undef INIT_TYPE
@@ -6032,3 +6119,27 @@
 	return 0;
 }
 
+/* checks we only have deform modifiers */
+int modifiers_isDeformedOnly(Object *ob)
+{
+	ModifierData *md = modifiers_getVirtualModifierList(ob);
+	ModifierTypeInfo *mti;
+	for (; md; md=md->next) {
+		mti = modifierType_getInfo(md->type);
+		/* TODO - check the modifier is being used! */
+		if (mti->type != eModifierTypeType_OnlyDeform) {
+			return 0;
+		}
+	}
+	return 1;
+}
+
+int modifiers_indexInObject(Object *ob, ModifierData *md_seek)
+{
+	int i= 0;
+	ModifierData *md;
+	
+	for (md=ob->modifiers.first; (md && md_seek!=md); md=md->next, i++);
+	if (!md) return -1; /* modifier isnt in the object */
+	return i;
+}

Added: branches/cloth/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/pointcache.c	                        (rev 0)
+++ branches/cloth/blender/source/blender/blenkernel/intern/pointcache.c	2007-11-06 09:44:09 UTC (rev 12490)
@@ -0,0 +1,159 @@
+/**
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License.  See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+* Contributor(s): Campbell Barton <ideasman42 at gmail.com>
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "BKE_pointcache.h"
+
+#include "BKE_utildefines.h"
+#include "BKE_global.h"
+#include "BKE_library.h"
+
+#include "BLI_blenlib.h"
+#include "BKE_utildefines.h"
+#include "blendef.h"
+
+/* needed for directory lookup */
+#ifndef WIN32
+  #include <dirent.h>
+#else
+  #include "BLI_winstuff.h"
+#endif
+
+/*	Takes an Object ID and returns a unique name
+	- id: object id
+	- cfra: frame for the cache, can be negative
+	- stack_index: index in the modifier stack. we can have cache for more then one stack_index
+*/
+
+int PTCache_path(char *filename)
+{
+	sprintf(filename, PTCache_PATH);
+	BLI_convertstringcode(filename, G.sce, 0);
+	return strlen(filename);
+}
+
+int PTCache_id_filename(struct ID *id, char *filename, int cfra, int stack_index, short do_path, short do_ext)
+{
+	int len=0;
+	char *idname;
+	char *newname;
+	filename[0] = '\0';
+	newname = filename;
+	
+	/* start with temp dir */
+	if (do_path) {
+		len = PTCache_path(filename);
+		newname += len;
+	}
+	idname = (id->name+2);
+	/* convert chars to hex so they are always a valid file */
+	while('\0' != *idname) {
+		sprintf(newname, "%02X", (char)(*idname++));
+		newname+=2;
+		len += 2;
+	}
+	
+	if (do_ext) {
+		sprintf(newname, "_%06d_%02d"PTCache_EXT, cfra, stack_index); /* always 6 chars */
+		len += 16;
+	}
+	
+	return len; /* make sure the above string is always 16 chars */
+}
+
+/* youll need to close yourself after! */
+FILE *PTCache_id_fopen(struct ID *id, char mode, int cfra, int stack_index)
+{
+	/* mode is same as fopen's modes */
+	FILE *fp;
+	char filename[(FILE_MAXDIR+FILE_MAXFILE)*2];
+
+	PTCache_id_filename(id, filename, cfra, stack_index, 1, 1);
+
+	if (mode=='r') {
+		if (!BLI_exists(filename)) {
+			printf("Error, file does not exist '%s'\n", filename);
+			return NULL;
+		}
+ 		fp = fopen(filename, "rb");
+	} else if (mode=='w') {
+		BLI_make_existing_file(filename); /* will create the dir if needs be, same as //textures is created */
+		fp = fopen(filename, "wb");
+	}
+
+ 	if (!fp) {
+ 		printf("Error creating file filename '%s'\n", filename);
+ 		return NULL;
+ 	}
+ 	
+ 	return fp;
+}
+
+/* youll need to close yourself after! */
+void PTCache_id_clear(struct ID *id, int cfra, int stack_index)
+{
+	int len; /* store the length of the string */
+
+	/* mode is same as fopen's modes */
+	DIR *dir; 
+	struct dirent *de;
+	char path[FILE_MAX];
+	char filename[(FILE_MAXDIR+FILE_MAXFILE)*2];
+	char path_full[(FILE_MAXDIR+FILE_MAXFILE)*2];
+
+	PTCache_path(path);
+	len = PTCache_id_filename(id, filename, cfra, stack_index, 0, 0); /* no path */
+	
+	/* clear all files in the temp dir with the prefix of the ID and the ".bphys" suffix */
+	
+	dir = opendir(path);
+	if (dir==NULL)
+		return;
+	
+	while ((de = readdir(dir)) != NULL) {
+		//if (S_ISREG(status.st_mode)) { /* is file */
+			if (strstr(de->d_name, PTCache_EXT)) { /* do we have the right extension?*/
+				if (strncmp(filename, de->d_name, len ) == 0) { /* do we have the right prefix */
+					BLI_join_dirfile(path_full, path, de->d_name);
+					BLI_delete(path_full, 0, 0);
+				}
+			}
+		//}
+	}
+	
+	closedir(dir);
+	return;
+}
+


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list