[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24889] branches/sculpt25: Sculpt: external file storage for multires
Brecht Van Lommel
brecht at blender.org
Wed Nov 25 15:27:52 CET 2009
Revision: 24889
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24889
Author: blendix
Date: 2009-11-25 15:27:50 +0100 (Wed, 25 Nov 2009)
Log Message:
-----------
Sculpt: external file storage for multires
* This is experimental, the file format may change still!
* Helps reduce memory usage, keeps .blend files smaller, and makes
saving quicker when not editing multires.
* This is implemented at the customdata level, currently only the
multires displacements can be stored externally.
ToDo
* Better integration with object duplication/removal/..
* Memory is not yet freed when exiting sculpt mode.
* Loading only lower levels is not supported yet.
Modified Paths:
--------------
branches/sculpt25/release/scripts/ui/properties_data_modifier.py
branches/sculpt25/source/blender/blenkernel/BKE_customdata.h
branches/sculpt25/source/blender/blenkernel/intern/customdata.c
branches/sculpt25/source/blender/blenkernel/intern/multires.c
branches/sculpt25/source/blender/blenkernel/intern/pointcache.c
branches/sculpt25/source/blender/blenlib/BLI_string.h
branches/sculpt25/source/blender/blenlib/intern/string.c
branches/sculpt25/source/blender/blenloader/intern/readfile.c
branches/sculpt25/source/blender/blenloader/intern/writefile.c
branches/sculpt25/source/blender/editors/include/ED_sculpt.h
branches/sculpt25/source/blender/makesdna/DNA_customdata_types.h
branches/sculpt25/source/blender/makesrna/intern/rna_modifier.c
branches/sculpt25/source/blender/windowmanager/intern/wm_files.c
Added Paths:
-----------
branches/sculpt25/source/blender/blenkernel/BKE_btex.h
branches/sculpt25/source/blender/blenkernel/intern/btex.c
Modified: branches/sculpt25/release/scripts/ui/properties_data_modifier.py
===================================================================
--- branches/sculpt25/release/scripts/ui/properties_data_modifier.py 2009-11-25 14:13:43 UTC (rev 24888)
+++ branches/sculpt25/release/scripts/ui/properties_data_modifier.py 2009-11-25 14:27:50 UTC (rev 24889)
@@ -302,9 +302,9 @@
col = split.column()
col.itemO("object.multires_subdivide", text="Subdivide")
col.itemO("object.multires_higher_levels_delete", text="Delete Higher")
- # row = col.row()
- # row.enabled = md.total_levels > 0
- # row.itemR(md, "external")
+ row = col.row()
+ row.enabled = md.total_levels > 0
+ row.itemR(md, "external")
def PARTICLE_INSTANCE(self, layout, ob, md):
layout.itemR(md, "object")
Added: branches/sculpt25/source/blender/blenkernel/BKE_btex.h
===================================================================
--- branches/sculpt25/source/blender/blenkernel/BKE_btex.h (rev 0)
+++ branches/sculpt25/source/blender/blenkernel/BKE_btex.h 2009-11-25 14:27:50 UTC (rev 24889)
@@ -0,0 +1,64 @@
+/*
+ * $Id$
+ *
+ * ***** 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.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef BKE_BTEX_H
+#define BKE_BTEX_H
+
+#define BTEX_TYPE_IMAGE 0
+#define BTEX_TYPE_MESH 1
+
+#define BTEX_LAYER_NAME_MAX 64
+
+typedef struct BTex BTex;
+typedef struct BTexLayer BTexLayer;
+
+/* Create/Free */
+
+BTex *btex_create(int type);
+void btex_free(BTex *btex);
+
+/* File read/write/remove */
+
+int btex_read_open(BTex *btex, char *filename);
+int btex_read_layer(BTex *btex, BTexLayer *blay);
+int btex_read_data(BTex *btex, int size, void *data);
+void btex_read_close(BTex *btex);
+
+int btex_write_open(BTex *btex, char *filename);
+int btex_write_layer(BTex *btex, BTexLayer *blay);
+int btex_write_data(BTex *btex, int size, void *data);
+void btex_write_close(BTex *btex);
+
+void btex_remove(char *filename);
+
+/* Layers */
+
+BTexLayer *btex_layer_find(BTex *btex, int type, char *name);
+BTexLayer *btex_layer_add(BTex *btex, int type, char *name);
+void btex_layer_remove(BTex *btex, BTexLayer *blay);
+
+/* Mesh */
+
+void btex_mesh_set_grids(BTex *btex, int totgrid, int gridsize, int datasize);
+
+#endif /* BKE_BTEX_H */
+
Modified: branches/sculpt25/source/blender/blenkernel/BKE_customdata.h
===================================================================
--- branches/sculpt25/source/blender/blenkernel/BKE_customdata.h 2009-11-25 14:13:43 UTC (rev 24888)
+++ branches/sculpt25/source/blender/blenkernel/BKE_customdata.h 2009-11-25 14:27:50 UTC (rev 24889)
@@ -278,4 +278,20 @@
void CustomData_to_bmeshpoly(struct CustomData *fdata, struct CustomData *pdata, struct CustomData *ldata);
void CustomData_from_bmeshpoly(struct CustomData *fdata, struct CustomData *pdata, struct CustomData *ldata, int total);
void CustomData_bmesh_init_pool(struct CustomData *data, int allocsize);
+
+/* External file storage */
+
+void CustomData_external_add(struct CustomData *data,
+ int type, const char *name, int totelem);
+void CustomData_external_remove(struct CustomData *data,
+ int type, int totelem);
+void CustomData_external_remove_object(struct CustomData *data);
+int CustomData_external_test(struct CustomData *data, int type);
+
+void CustomData_external_write(struct CustomData *data,
+ CustomDataMask mask, int totelem, int free);
+void CustomData_external_read(struct CustomData *data,
+ CustomDataMask mask, int totelem);
+
#endif
+
Added: branches/sculpt25/source/blender/blenkernel/intern/btex.c
===================================================================
--- branches/sculpt25/source/blender/blenkernel/intern/btex.c (rev 0)
+++ branches/sculpt25/source/blender/blenkernel/intern/btex.c 2009-11-25 14:27:50 UTC (rev 24889)
@@ -0,0 +1,482 @@
+/*
+ * $Id$
+ *
+ * ***** 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.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_fileops.h"
+#include "BLI_string.h"
+
+#include "BKE_btex.h"
+#include "BKE_global.h"
+#include "BKE_utildefines.h"
+
+/************************* File Format Definitions ***************************/
+
+#define BTEX_ENDIAN_LITTLE 0
+#define BTEX_ENDIAN_BIG 1
+
+#define BTEX_DATA_FLOAT 0
+
+typedef struct BTexHeader {
+ char ID[4]; /* "BTEX" */
+ char endian; /* little, big */
+ char version; /* non-compatible versions */
+ char subversion; /* compatible sub versions */
+ char pad; /* padding */
+
+ int structbytes; /* size of this struct in bytes */
+ int type; /* image, mesh */
+ int totlayer; /* number of layers in the file */
+} BTexHeader;
+
+typedef struct BTexImageHeader {
+ int structbytes; /* size of this struct in bytes */
+ int width; /* image width */
+ int height; /* image height */
+ int tile_size; /* tile size (required power of 2) */
+} BTexImageHeader;
+
+typedef struct BTexMeshHeader {
+ int structbytes; /* size of this struct in bytes */
+ int totgrid; /* number of grids */
+ int gridsize; /* width of grids */
+} BTexMeshHeader;
+
+struct BTexLayer {
+ int structbytes; /* size of this struct in bytes */
+ int datatype; /* only float for now */
+ int datasize; /* size of data in layer */
+ int type; /* layer type */
+ char name[BTEX_LAYER_NAME_MAX]; /* layer name */
+};
+
+/**************************** Other Definitions ******************************/
+
+#define BTEX_VERSION 0
+#define BTEX_SUBVERSION 0
+#define BTEX_TILE_SIZE 64
+
+struct BTex {
+ int type;
+
+ BTexHeader header;
+ union {
+ BTexImageHeader image;
+ BTexMeshHeader mesh;
+ } btype;
+
+ BTexLayer *layer;
+ int totlayer;
+
+ FILE *readf;
+ FILE *writef;
+ int switchendian;
+ size_t dataoffset;
+};
+
+/********************************* Create/Free *******************************/
+
+static int btex_endian(void)
+{
+ if(ENDIAN_ORDER == L_ENDIAN)
+ return BTEX_ENDIAN_LITTLE;
+ else
+ return BTEX_ENDIAN_BIG;
+}
+
+/*static int btex_data_type_size(int datatype)
+{
+ if(datatype == BTEX_DATA_FLOAT)
+ return sizeof(float);
+
+ return 0;
+}*/
+
+BTex *btex_create(int type)
+{
+ BTex *btex= MEM_callocN(sizeof(BTex), "BTex");
+
+ btex->type= type;
+
+ return btex;
+}
+
+void btex_free(BTex *btex)
+{
+ btex_read_close(btex);
+ btex_write_close(btex);
+
+ if(btex->layer)
+ MEM_freeN(btex->layer);
+
+ MEM_freeN(btex);
+}
+
+/********************************* Read/Write ********************************/
+
+static int btex_read_header(BTex *btex)
+{
+ BTexHeader *header;
+ BTexImageHeader *image;
+ BTexMeshHeader *mesh;
+ BTexLayer *layer;
+ FILE *f= btex->readf;
+ size_t offset = 0;
+ int a;
+
+ header= &btex->header;
+
+ if(!fread(header, sizeof(BTexHeader), 1, btex->readf))
+ return 0;
+
+ if(memcmp(header->ID, "BTEX", sizeof(header->ID)) != 0)
+ return 0;
+ if(header->version > BTEX_VERSION)
+ return 0;
+
+ btex->switchendian= header->endian != btex_endian();
+ header->endian= btex_endian();
+
+ if(btex->switchendian) {
+ SWITCH_INT(header->type);
+ SWITCH_INT(header->totlayer);
+ SWITCH_INT(header->structbytes);
+ }
+
+ if(!ELEM(header->type, BTEX_TYPE_IMAGE, BTEX_TYPE_MESH))
+ return 0;
+
+ offset += header->structbytes;
+ header->structbytes= sizeof(BTexHeader);
+
+ if(fseek(f, offset, SEEK_SET) != 0)
+ return 0;
+
+ if(header->type == BTEX_TYPE_IMAGE) {
+ image= &btex->btype.image;
+ if(!fread(image, sizeof(BTexImageHeader), 1, f))
+ return 0;
+
+ if(btex->switchendian) {
+ SWITCH_INT(image->width);
+ SWITCH_INT(image->height);
+ SWITCH_INT(image->tile_size);
+ SWITCH_INT(image->structbytes);
+ }
+
+ offset += image->structbytes;
+ image->structbytes= sizeof(BTexImageHeader);
+ }
+ else if(header->type == BTEX_TYPE_MESH) {
+ mesh= &btex->btype.mesh;
+ if(!fread(mesh, sizeof(BTexMeshHeader), 1, f))
+ return 0;
+
+ if(btex->switchendian) {
+ SWITCH_INT(mesh->totgrid);
+ SWITCH_INT(mesh->gridsize);
+ SWITCH_INT(mesh->structbytes);
+ }
+
+ offset += mesh->structbytes;
+ mesh->structbytes= sizeof(BTexMeshHeader);
+ }
+
+ if(fseek(f, offset, SEEK_SET) != 0)
+ return 0;
+
+ btex->layer= MEM_callocN(sizeof(BTexLayer)*header->totlayer, "BTexLayer");
+ btex->totlayer= header->totlayer;
+
+ for(a=0; a<header->totlayer; a++) {
+ layer= &btex->layer[a];
+
+ if(!fread(layer, sizeof(BTexLayer), 1, f))
+ return 0;
+
+ if(btex->switchendian) {
+ SWITCH_INT(layer->type);
+ SWITCH_INT(layer->datatype);
+ SWITCH_INT(layer->datasize);
+ SWITCH_INT(layer->structbytes);
+ }
+
+ if(layer->datatype != BTEX_DATA_FLOAT)
+ return 0;
+
+ offset += layer->structbytes;
+ layer->structbytes= sizeof(BTexLayer);
+
+ if(fseek(f, offset, SEEK_SET) != 0)
+ return 0;
+ }
+
+ btex->dataoffset= offset;
+
+ return 1;
+}
+
+static int btex_write_header(BTex *btex)
+{
+ BTexHeader *header;
+ BTexImageHeader *image;
+ BTexMeshHeader *mesh;
+ BTexLayer *layer;
+ FILE *f= btex->writef;
+ int a;
+
+ header= &btex->header;
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list