2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
* .blend file reading entry point
|
|
|
|
*/
|
|
|
|
|
2002-11-25 12:02:15 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_ghash.h"
|
|
|
|
#include "BLI_linklist.h"
|
|
|
|
|
|
|
|
#include "DNA_sdna_types.h"
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
#include "DNA_ID.h"
|
2007-09-02 17:25:03 +00:00
|
|
|
#include "DNA_material_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "BKE_utildefines.h" // for ENDB
|
|
|
|
|
|
|
|
#include "BKE_main.h"
|
2006-11-25 13:07:28 +00:00
|
|
|
#include "BKE_global.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_library.h" // for free_main
|
|
|
|
|
|
|
|
#include "BLO_readfile.h"
|
2004-09-05 13:43:51 +00:00
|
|
|
#include "BLO_undofile.h"
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "readfile.h"
|
2007-09-02 17:25:03 +00:00
|
|
|
#include "genfile.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "BLO_readblenfile.h"
|
|
|
|
|
2008-08-17 16:36:37 +00:00
|
|
|
#include "BLO_sys_types.h" // needed for intptr_t
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
* IDType stuff, I plan to move this
|
|
|
|
* out into its own file + prefix, and
|
|
|
|
* make sure all IDType handling goes through
|
|
|
|
* these routines.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned short code;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
int flags;
|
|
|
|
#define IDTYPE_FLAGS_ISLINKABLE (1<<0)
|
|
|
|
} IDType;
|
|
|
|
|
|
|
|
static IDType idtypes[]= {
|
|
|
|
{ ID_AC, "Action", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_AR, "Armature", IDTYPE_FLAGS_ISLINKABLE},
|
Brush Datablock:
- Added a new Brush datablock, only used by image paint, but intended
to be used in texture paint, vertex paint, weight paint and sculpt
mode also.
- Being a datablock, these brushes can be saved, appended and linked.
They have a fake user by default, to make sure they are saved even if
not selected.
Image Painting:
- Replaced the img module with C code in imagepaint.c
- Airbrush is no longer a separate tool, but rather an option that can
be used for soften, smear and clone also.
- Blend modes mix, add, subtract, multiply, darken and lighten have been
added, code taken directly from vertex paint.
Note to project files maintainers:
- The img module was removed from SCons and Makefiles, and this should
be done in other build systems also. I'll wait to remove the module
from cvs, to not break compilation.
2006-07-26 22:29:23 +00:00
|
|
|
{ ID_BR, "Brush", IDTYPE_FLAGS_ISLINKABLE},
|
2002-10-12 11:37:38 +00:00
|
|
|
{ ID_CA, "Camera", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_CU, "Curve", IDTYPE_FLAGS_ISLINKABLE},
|
Orange branch: Revived hidden treasure, the Groups!
Previous experiment (in 2000) didn't satisfy, it had even some primitive
NLA option in groups... so, cleaned up the old code (removed most) and
integrated it back in a more useful way.
Usage:
- CTRL+G gives menu to add group, add to existing group, or remove from
groups.
- In Object buttons, a new (should become first) Panel was added, showing
not only Object "ID button" and Parent, but also the Groups the Object
Belongs to. These buttons also allow rename, assigning or removing.
- To indicate Objects are grouped, they're drawn in a (not theme yet, so
temporal?) green wire color.
- Use ALT+SHIFT mouse-select to (de)select an entire group
But, the real power of groups is in the following features:
-> Particle Force field and Guide control
In the "Particle Motion" Panel, you can indicate a Group name, this then
limits force fields or guides to members of that Group. (Note that layers
still work on top of that... not sure about that).
-> Light Groups
In the Material "Shaders" Panel, you can indicate a Group name to limit
lighting for the Material to lamps in this group. The Lights in a Group do
need to be 'visible' for the Scene to be rendered (as usual).
-> Group Duplicator
In the Object "Anim" Panel, you can set any Object (use Empty!) to
duplicate an entire Group. It will make copies of all Objects in that Group.
Also works for animated Objects, but it will copy the current positions or
deforms. Control over 'local timing' (so we can do Massive anims!) will be
added later.
(Note; this commit won't render Group duplicators yet, a fix in bf-blender
will enable that, next commit will sync)
-> Library Appending
In the SHIFT-F1 or SHIFT+F4 browsers, you can also find the Groups listed.
By appending or linking the Group itself, and use the Group Duplicator, you
now can animate and position linked Objects. The nice thing is that the
local saved file itself will only store the Group name that was linked, so
on a next file read, the Group Objects will be re-read as stored (changed)
in the Library file.
(Note; current implementation also "gives a base" to linked Group Objects,
to show them as Objects in the current Scene. Need that now for testing
purposes, but probably will be removed later).
-> Outliner
Outliner now shows Groups as optio too, nice to organize your data a bit too!
In General, Groups have a very good potential... for example, it could
become default for MetaBall Objects too (jiri, I can help you later on how
this works). All current 'layer relationships' in Blender should be dropped
in time, I guess...
2005-12-06 10:55:30 +00:00
|
|
|
{ ID_GR, "Group", IDTYPE_FLAGS_ISLINKABLE},
|
2002-10-12 11:37:38 +00:00
|
|
|
{ ID_ID, "ID", 0},
|
|
|
|
{ ID_IM, "Image", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_IP, "Ipo", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_KE, "Key", 0},
|
|
|
|
{ ID_LA, "Lamp", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_LF, "Life", 0},
|
|
|
|
{ ID_LI, "Library", 0},
|
|
|
|
{ ID_LT, "Lattice", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_MA, "Material", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_MB, "Metaball", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_ME, "Mesh", IDTYPE_FLAGS_ISLINKABLE},
|
Orange: more noodle updates!
**** NEW: Group Nodes
Node trees usually become messy and confusing quickly, so we need
not only a way to collapse Nodes into single 'groups', but also a
way to re-use that data to create libraries of effects.
This has been done by making a new Library data type, the NodeTree.
Everything that has been grouped is stored here, and available for
re-use, appending or linking. These NodeTrees are fully generic,
i.e. can store shader trees, composit trees, and so on. The 'type'
value as stored in the NodeTree will keep track of internal type
definitions and execute/drawing callbacks. Needless to say, re-using
shader trees in a composit tree is a bit useless, and will be
prevented in the browsing code. :)
So; any NodeTree can become a "Goup Node" inside in a NodeTree. This
Group Node then works just like any Node.
To prevent the current code to become too complex, I've disabled
the possibility to insert Groups inside of Groups. That might be
enabled later, but is a real nasty piece of code to get OK.
Since Group Nodes are a dynamic Node type, a lot of work has been
done to ensure Node definitions can be dynamic too, but still allow
to be stored in files, and allow to be verified for type-definition
changes on reloading. This system needs a little bit maturing still,
so the Python gurus should better wait a little bit! (Also for me to
write the definite API docs for it).
What works now:
- Press CTRL+G to create a new Group. The grouping code checks for
impossible selections (like an unselected node between selected nodes).
Everthing that's selected then gets removed from the current tree, and
inserted in a new NodeTree library data block. A Group Node then is
added which links to this new NodeTree.
- Press ALT+G to ungroup. This will not delete the NodeTree library
data, but just duplicate the Group into the current tree.
- Press TAB, or click on the NodeTree icon to edit Groups. Note that
NodeTrees are instances, so editing one Group will also change the
other users.
This also means that when removing nodes in a Group (or hiding sockets
or changing internal links) this is immediately corrected for all users
of this Group, also in other Materials.
- While editing Groups, only the internal Nodes can be edited. A single
click outside of the Group boundary will close this 'edit mode'.
What needs to be done:
- SHIFT+A menu in toolbox style, also including a list of Groups
- Enable the single-user button in the Group Node
- Displaying all (visible) internal group UI elements in the Node Panel
- Enable Library linking and prevent editing of Groups then.
**** NEW: Socket Visibility control
Node types will be generated with a lot of possible inputs or outputs,
and drawing all sockets all the time isn't very useful then.
A new option in the Node header ('plus' icon) allows to either hide all
unused sockets (first keypress) or to reveil them (when there are hidden
sockets, the icon displays black, otherwise it's blended).
Hidden sockets in Nodes also are not exported to a Group, so this way
you can control what options (in/outputs) exactly are available.
To be done:
- a way to hide individual sockets, like with a RMB click on it.
**** NEW: Nodes now render!
This is still quite primitive, more on a level to replace the (now
obsolete and disabled) Material Layers.
What needs to be done:
- make the "Geometry" node work properly, also for AA textures
- make the Texture Node work (does very little at the moment)
- give Material Nodes all inputs as needed (like Map-to Panel)
- find a way to export more data from a Material Node, like the
shadow value, or light intensity only, etc
Very important also to separate from the Material Buttons the
"global" options, like "Ztransp" or "Wire" or "Halo". These can not
be set for each Material-Node individually.
Also note that the Preview Render (Buttons window) now renders a bit
differently. This was a horrid piece of antique code, using a totally
incompatible way of rendering. Target is to fully re-use internal
render code for previews.
OK... that's it mostly. Now test!
2006-01-02 13:06:05 +00:00
|
|
|
{ ID_NT, "NodeTree", IDTYPE_FLAGS_ISLINKABLE},
|
2002-10-12 11:37:38 +00:00
|
|
|
{ ID_OB, "Object", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_SCE, "Scene", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_SCR, "Screen", 0},
|
|
|
|
{ ID_SEQ, "Sequence", 0},
|
|
|
|
{ ID_SE, "Sector", 0},
|
|
|
|
{ ID_SO, "Sound", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_TE, "Texture", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_TXT, "Text", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_VF, "VFont", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_WO, "World", IDTYPE_FLAGS_ISLINKABLE},
|
|
|
|
{ ID_WV, "Wave", 0},
|
|
|
|
};
|
|
|
|
static int nidtypes= sizeof(idtypes)/sizeof(idtypes[0]);
|
|
|
|
|
2005-03-09 19:45:59 +00:00
|
|
|
/* local prototypes --------------------- */
|
|
|
|
void BLO_blendhandle_print_sizes(BlendHandle *, void *);
|
|
|
|
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
static IDType *idtype_from_name(char *str)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
int i= nidtypes;
|
|
|
|
|
|
|
|
while (i--)
|
|
|
|
if (BLI_streq(str, idtypes[i].name))
|
|
|
|
return &idtypes[i];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-09-05 13:43:51 +00:00
|
|
|
static IDType *idtype_from_code(int code)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
int i= nidtypes;
|
|
|
|
|
|
|
|
while (i--)
|
|
|
|
if (code==idtypes[i].code)
|
|
|
|
return &idtypes[i];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
static int bheadcode_is_idcode(int code)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
return idtype_from_code(code)?1:0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int idcode_is_linkable(int code) {
|
|
|
|
IDType *idt= idtype_from_code(code);
|
|
|
|
return idt?(idt->flags&IDTYPE_FLAGS_ISLINKABLE):0;
|
|
|
|
}
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
char *BLO_idcode_to_name(int code)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
IDType *idt= idtype_from_code(code);
|
|
|
|
|
|
|
|
return idt?idt->name:NULL;
|
|
|
|
}
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
int BLO_idcode_from_name(char *name)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
IDType *idt= idtype_from_name(name);
|
|
|
|
|
|
|
|
return idt?idt->code:0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Access routines used by filesel. */
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
BlendHandle *BLO_blendhandle_from_file(char *file)
|
|
|
|
{
|
2005-07-25 18:35:49 +00:00
|
|
|
BlendReadError err;
|
|
|
|
|
|
|
|
return (BlendHandle*) blo_openblenderfile(file, &err);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
void BLO_blendhandle_print_sizes(BlendHandle *bh, void *fp)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
FileData *fd= (FileData*) bh;
|
|
|
|
BHead *bhead;
|
|
|
|
|
|
|
|
fprintf(fp, "[\n");
|
|
|
|
for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead)) {
|
|
|
|
if (bhead->code==ENDB)
|
|
|
|
break;
|
|
|
|
else {
|
|
|
|
short *sp= fd->filesdna->structs[bhead->SDNAnr];
|
|
|
|
char *name= fd->filesdna->types[ sp[0] ];
|
|
|
|
char buf[4];
|
|
|
|
|
|
|
|
buf[0]= (bhead->code>>24)&0xFF;
|
|
|
|
buf[1]= (bhead->code>>16)&0xFF;
|
|
|
|
buf[2]= (bhead->code>>8)&0xFF;
|
|
|
|
buf[3]= (bhead->code>>0)&0xFF;
|
|
|
|
|
|
|
|
buf[0]= buf[0]?buf[0]:' ';
|
|
|
|
buf[1]= buf[1]?buf[1]:' ';
|
|
|
|
buf[2]= buf[2]?buf[2]:' ';
|
|
|
|
buf[3]= buf[3]?buf[3]:' ';
|
|
|
|
|
2008-08-17 16:36:37 +00:00
|
|
|
fprintf(fp, "['%.4s', '%s', %d, %ld ], \n", buf, name, bhead->nr, (intptr_t)bhead->len+sizeof(BHead));
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(fp, "]\n");
|
|
|
|
}
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh, int ofblocktype)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
FileData *fd= (FileData*) bh;
|
|
|
|
LinkNode *names= NULL;
|
|
|
|
BHead *bhead;
|
|
|
|
|
|
|
|
for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead)) {
|
|
|
|
if (bhead->code==ofblocktype) {
|
2007-04-28 16:15:00 +00:00
|
|
|
char *idname= bhead_id_name(fd, bhead);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2007-04-28 16:15:00 +00:00
|
|
|
BLI_linklist_prepend(&names, strdup(idname+2));
|
2002-10-12 11:37:38 +00:00
|
|
|
} else if (bhead->code==ENDB)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2007-09-02 17:25:03 +00:00
|
|
|
LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype)
|
|
|
|
{
|
|
|
|
FileData *fd= (FileData*) bh;
|
|
|
|
LinkNode *previews= NULL;
|
|
|
|
BHead *bhead;
|
|
|
|
int looking=0;
|
|
|
|
int npreviews = 0;
|
|
|
|
PreviewImage* prv = NULL;
|
|
|
|
PreviewImage* new_prv = NULL;
|
|
|
|
|
|
|
|
for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead)) {
|
|
|
|
if (bhead->code==ofblocktype) {
|
|
|
|
ID *id= (ID*) (bhead+1);
|
2007-10-02 09:11:50 +00:00
|
|
|
if ( (GS(id->name) == ID_MA) || (GS(id->name) == ID_TE)) {
|
2007-09-02 17:25:03 +00:00
|
|
|
new_prv = MEM_callocN(sizeof(PreviewImage), "newpreview");
|
|
|
|
BLI_linklist_prepend(&previews, new_prv);
|
|
|
|
looking = 1;
|
|
|
|
}
|
|
|
|
} else if (bhead->code==DATA) {
|
|
|
|
if (looking) {
|
|
|
|
if (bhead->SDNAnr == dna_findstruct_nr(fd->filesdna, "PreviewImage") ) {
|
|
|
|
prv = (PreviewImage*) (bhead+1);
|
|
|
|
npreviews = 0;
|
|
|
|
memcpy(new_prv, prv, sizeof(PreviewImage));
|
|
|
|
if (prv->rect[0]) {
|
|
|
|
unsigned int *rect = NULL;
|
|
|
|
int rectlen = 0;
|
|
|
|
new_prv->rect[0] = MEM_callocN(new_prv->w[0]*new_prv->h[0]*sizeof(unsigned int), "prvrect");
|
|
|
|
bhead= blo_nextbhead(fd, bhead);
|
|
|
|
rect = (unsigned int*)(bhead+1);
|
|
|
|
rectlen = new_prv->w[0]*new_prv->h[0]*sizeof(unsigned int);
|
|
|
|
memcpy(new_prv->rect[0], rect, bhead->len);
|
|
|
|
} else {
|
|
|
|
new_prv->rect[0] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prv->rect[1]) {
|
|
|
|
unsigned int *rect = NULL;
|
|
|
|
int rectlen = 0;
|
|
|
|
new_prv->rect[1] = MEM_callocN(new_prv->w[1]*new_prv->h[1]*sizeof(unsigned int), "prvrect");
|
|
|
|
bhead= blo_nextbhead(fd, bhead);
|
|
|
|
rect = (unsigned int*)(bhead+1);
|
|
|
|
rectlen = new_prv->w[1]*new_prv->h[1]*sizeof(unsigned int);
|
|
|
|
memcpy(new_prv->rect[1], rect, bhead->len);
|
|
|
|
} else {
|
|
|
|
new_prv->rect[1] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (bhead->code==ENDB) {
|
|
|
|
break;
|
|
|
|
} else if (bhead->code==DATA) {
|
|
|
|
/* DATA blocks between IDBlock and Preview */
|
|
|
|
} else {
|
|
|
|
looking = 0;
|
|
|
|
new_prv = NULL;
|
|
|
|
prv = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return previews;
|
|
|
|
}
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
FileData *fd= (FileData*) bh;
|
|
|
|
GHash *gathered= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
|
|
|
|
LinkNode *names= NULL;
|
|
|
|
BHead *bhead;
|
|
|
|
|
|
|
|
for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead)) {
|
|
|
|
if (bhead->code==ENDB) {
|
|
|
|
break;
|
|
|
|
} else if (bheadcode_is_idcode(bhead->code)) {
|
|
|
|
if (idcode_is_linkable(bhead->code)) {
|
|
|
|
char *str= BLO_idcode_to_name(bhead->code);
|
|
|
|
|
|
|
|
if (!BLI_ghash_haskey(gathered, str)) {
|
|
|
|
BLI_linklist_prepend(&names, strdup(str));
|
|
|
|
BLI_ghash_insert(gathered, str, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_ghash_free(gathered, NULL, NULL);
|
|
|
|
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BLO_blendhandle_close(BlendHandle *bh) {
|
|
|
|
FileData *fd= (FileData*) bh;
|
|
|
|
|
|
|
|
blo_freefiledata(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********/
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
BlendFileData *BLO_read_from_file(char *file, BlendReadError *error_r)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
BlendFileData *bfd = NULL;
|
|
|
|
FileData *fd;
|
|
|
|
|
2005-07-25 18:35:49 +00:00
|
|
|
fd = blo_openblenderfile(file, error_r);
|
2002-10-12 11:37:38 +00:00
|
|
|
if (fd) {
|
|
|
|
bfd= blo_read_file_internal(fd, error_r);
|
|
|
|
if (bfd) {
|
|
|
|
bfd->type= BLENFILETYPE_BLEND;
|
2006-08-09 10:00:27 +00:00
|
|
|
strncpy(bfd->main->name, file, sizeof(bfd->main->name)-1);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
blo_freefiledata(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bfd;
|
|
|
|
}
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
BlendFileData *BLO_read_from_memory(void *mem, int memsize, BlendReadError *error_r)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
BlendFileData *bfd = NULL;
|
|
|
|
FileData *fd;
|
|
|
|
|
2005-07-25 18:35:49 +00:00
|
|
|
fd = blo_openblendermemory(mem, memsize, error_r);
|
2002-10-12 11:37:38 +00:00
|
|
|
if (fd) {
|
|
|
|
bfd= blo_read_file_internal(fd, error_r);
|
|
|
|
if (bfd) {
|
|
|
|
bfd->type= BLENFILETYPE_BLEND;
|
|
|
|
strcpy(bfd->main->name, "");
|
|
|
|
}
|
|
|
|
blo_freefiledata(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bfd;
|
|
|
|
}
|
|
|
|
|
2006-01-05 14:12:07 +00:00
|
|
|
BlendFileData *BLO_read_from_memfile(const char *filename, MemFile *memfile, BlendReadError *error_r)
|
2004-09-05 13:43:51 +00:00
|
|
|
{
|
|
|
|
BlendFileData *bfd = NULL;
|
|
|
|
FileData *fd;
|
2006-11-25 13:07:28 +00:00
|
|
|
ListBase mainlist;
|
|
|
|
|
2005-07-25 18:35:49 +00:00
|
|
|
fd = blo_openblendermemfile(memfile, error_r);
|
2004-09-05 13:43:51 +00:00
|
|
|
if (fd) {
|
2006-01-05 14:12:07 +00:00
|
|
|
strcpy(fd->filename, filename);
|
2006-11-10 10:17:04 +00:00
|
|
|
|
2006-11-25 13:07:28 +00:00
|
|
|
/* separate libraries from G.main */
|
|
|
|
blo_split_main(&mainlist, G.main);
|
|
|
|
/* add the library pointers in oldmap lookup */
|
|
|
|
blo_add_library_pointer_map(&mainlist, fd);
|
|
|
|
|
2006-11-10 10:17:04 +00:00
|
|
|
/* makes lookup of existing images in G.main */
|
|
|
|
blo_make_image_pointer_map(fd);
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
bfd= blo_read_file_internal(fd, error_r);
|
|
|
|
if (bfd) {
|
|
|
|
bfd->type= BLENFILETYPE_BLEND;
|
|
|
|
strcpy(bfd->main->name, "");
|
|
|
|
}
|
2006-11-10 10:17:04 +00:00
|
|
|
|
|
|
|
/* ensures relinked images are not freed */
|
|
|
|
blo_end_image_pointer_map(fd);
|
|
|
|
|
2006-11-25 13:07:28 +00:00
|
|
|
/* move libraries from G.main to new main */
|
|
|
|
if(bfd && mainlist.first!=mainlist.last) {
|
|
|
|
|
|
|
|
/* Library structs themselves */
|
|
|
|
bfd->main->library= G.main->library;
|
|
|
|
G.main->library.first= G.main->library.last= NULL;
|
|
|
|
|
|
|
|
/* add the Library mainlist to the new main */
|
|
|
|
BLI_remlink(&mainlist, G.main);
|
|
|
|
BLI_addhead(&mainlist, bfd->main);
|
|
|
|
}
|
|
|
|
blo_join_main(&mainlist);
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
blo_freefiledata(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bfd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BLO_blendfiledata_free(BlendFileData *bfd)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
if (bfd->main) {
|
|
|
|
free_main(bfd->main);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bfd->user) {
|
|
|
|
MEM_freeN(bfd->user);
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(bfd);
|
|
|
|
}
|
|
|
|
|
2004-09-05 13:43:51 +00:00
|
|
|
char *BLO_bre_as_string(BlendReadError error)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
switch (error) {
|
|
|
|
case BRE_NONE:
|
|
|
|
return "No error";
|
|
|
|
|
|
|
|
case BRE_UNABLE_TO_OPEN:
|
|
|
|
return "Unable to open";
|
|
|
|
case BRE_UNABLE_TO_READ:
|
|
|
|
return "Unable to read";
|
|
|
|
|
|
|
|
case BRE_OUT_OF_MEMORY:
|
|
|
|
return "Out of memory";
|
|
|
|
case BRE_INTERNAL_ERROR:
|
|
|
|
return "<internal error>";
|
|
|
|
|
|
|
|
case BRE_NOT_A_BLEND:
|
|
|
|
return "File is not a Blender file";
|
|
|
|
case BRE_NOT_A_PUBFILE:
|
|
|
|
return "File is not a compressed, locked or signed Blender file";
|
|
|
|
case BRE_INCOMPLETE:
|
|
|
|
return "File incomplete";
|
|
|
|
case BRE_CORRUPT:
|
|
|
|
return "File corrupt";
|
|
|
|
|
|
|
|
case BRE_TOO_NEW:
|
|
|
|
return "File needs newer Blender version, please upgrade";
|
|
|
|
case BRE_NOT_ALLOWED:
|
|
|
|
return "File is locked";
|
|
|
|
|
|
|
|
case BRE_NO_SCREEN:
|
|
|
|
return "File has no screen";
|
|
|
|
case BRE_NO_SCENE:
|
|
|
|
return "File has no scene";
|
|
|
|
|
|
|
|
default:
|
|
|
|
case BRE_INVALID:
|
|
|
|
return "<invalid read error>";
|
|
|
|
}
|
|
|
|
}
|