Added ReadBlend, a data extraction API for Blender's .blend files
This can come in handy, to author physics data for Bullet from Blender, and directly get the physics data straight from the .blend file Thanks a lot to Adam D. Moss, to digg up this code and make it available under the MIT license It was mentioned several years ago in this thread: http://archives.seul.org/linuxgames/Apr-2005/msg00002.html
This commit is contained in:
24
Extras/readblend/LICENSE.txt
Normal file
24
Extras/readblend/LICENSE.txt
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
Copyright (C) 2003-2006 Adam D. Moss (the "Author"). All Rights Reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is fur-
|
||||
nished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
|
||||
NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
|
||||
NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of the Author of the
|
||||
Software shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written authorization
|
||||
from the Author.
|
||||
36
Extras/readblend/Makefile
Normal file
36
Extras/readblend/Makefile
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
CC = gcc
|
||||
COPTS = -O2 -Wall
|
||||
|
||||
#CC = gcc31
|
||||
#COPTS = -O2 -Wall -ggdb -lm
|
||||
|
||||
#COPTS = -O3 -g -fno-inline-functions -ffast-math -pg -Wall
|
||||
#COPTS = -ggdb -Wall
|
||||
|
||||
CFLAGS = $(COPTS) $(INCS) -lm
|
||||
|
||||
EXEC = testblend
|
||||
|
||||
OBJ_SRCS = testblend.c readblend.c
|
||||
OBJ_OBJS = $(OBJ_SRCS:.c=.o)
|
||||
|
||||
%.o: %.c
|
||||
${CC} ${CFLAGS} -c $< -o $@
|
||||
|
||||
all: $(EXEC)
|
||||
|
||||
clean:
|
||||
rm -f $(EXEC) *.o gmon.out
|
||||
|
||||
#dist:
|
||||
# tar -hzvcf flynn-`cat VERSION`.tar.gz `cat MANIFEST`
|
||||
# ls -la flynn-`cat VERSION`.tar.gz
|
||||
|
||||
#testdist:
|
||||
# tar -zvcf flynn-testdir.tar.gz test
|
||||
# ls -la flynn-testdir.tar.gz
|
||||
|
||||
$(EXEC): $(OBJ_OBJS)
|
||||
$(CC) $(CFLAGS) $^ -o $@
|
||||
|
||||
26
Extras/readblend/README.blendstruct
Normal file
26
Extras/readblend/README.blendstruct
Normal file
@@ -0,0 +1,26 @@
|
||||
ReadBlend, a data extraction API for Blender's .blend files
|
||||
|
||||
quick notes on the logical .blend file format as presented
|
||||
by readblend:
|
||||
|
||||
|
||||
BLENDFILE
|
||||
|
|
||||
|--BLENDFILE_VERSION
|
||||
|
|
||||
|--NUM_BLOCKS ... number of blocks in the file
|
||||
|--BLOCK[NUM_BLOCKS] ... array of blocks
|
||||
|
|
||||
|--BLOCK_TAG ... general 'DATA', otherwise specialized type
|
||||
|
|
||||
|--OBJECT_TYPE ... the block is an array of objects of this type
|
||||
|--OBJECT_COUNT ... this is the number of objects in the block
|
||||
|--OBJECT[OBJECT_COUNT] ... array of objects
|
||||
|
|
||||
|--OBJECT
|
||||
an OBJECT...
|
||||
= ATOMIC type (uchar, float, etc)
|
||||
or
|
||||
= STRUCTURE (array of assorted OBJECTs, nested)
|
||||
or
|
||||
= POINTER (a reference to another BLOCK)
|
||||
20
Extras/readblend/ReadBlend.sln
Normal file
20
Extras/readblend/ReadBlend.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ReadBlend", "ReadBlend.vcproj", "{74CA6BF4-60C4-4FE6-BAB5-31F31FA2A0B3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{74CA6BF4-60C4-4FE6-BAB5-31F31FA2A0B3}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{74CA6BF4-60C4-4FE6-BAB5-31F31FA2A0B3}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{74CA6BF4-60C4-4FE6-BAB5-31F31FA2A0B3}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{74CA6BF4-60C4-4FE6-BAB5-31F31FA2A0B3}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
213
Extras/readblend/ReadBlend.vcproj
Normal file
213
Extras/readblend/ReadBlend.vcproj
Normal file
@@ -0,0 +1,213 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="ReadBlend"
|
||||
ProjectGUID="{74CA6BF4-60C4-4FE6-BAB5-31F31FA2A0B3}"
|
||||
RootNamespace="ReadBlend"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath="abs-file.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="readblend.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="readblend.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="testblend.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
226
Extras/readblend/abs-file.h
Normal file
226
Extras/readblend/abs-file.h
Normal file
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* stdio/physfs abstraction layer 2004-02-06
|
||||
*
|
||||
* Adam D. Moss <adam@gimp.org> <aspirin@icculus.org>
|
||||
*
|
||||
* These wrapper macros and functions are designed to allow a program
|
||||
* to perform file I/O with identical semantics and syntax regardless
|
||||
* of whether PhysicsFS is being used or not.
|
||||
*/
|
||||
#ifndef _ABS_FILE_H
|
||||
#define _ABS_FILE_H
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned long int uint64_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef int int32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef short int16_t;
|
||||
|
||||
|
||||
/*
|
||||
PLEASE NOTE: This license applies to abs-file.h ONLY; The version of
|
||||
PhysicsFS itself which you are using may have been released under a
|
||||
license with additional restrictions.
|
||||
|
||||
Copyright (C) 2002-2004 Adam D. Moss (the "Author"). All Rights Reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is fur-
|
||||
nished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
|
||||
NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
|
||||
NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of the Author of the
|
||||
Software shall not be used in advertising or otherwise to promote the sale,
|
||||
use or other dealings in this Software without prior written authorization
|
||||
from the Author.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* API:
|
||||
*
|
||||
* Macro/function use like stdio equivalent...
|
||||
* -------------- ----------------------------
|
||||
* MY_FILETYPE FILE
|
||||
* MY_OPEN_FOR_READ fopen(..., "rb")
|
||||
* MY_READ fread(...)
|
||||
* MY_GETC fgetc(...)
|
||||
* MY_GETS fgets(...)
|
||||
* MY_OPEN_FOR_WRITE fopen(..., "wb")
|
||||
* MY_WRITE fwrite(...)
|
||||
* MY_PUTC fputc(...)
|
||||
* MY_PUTS fputs(...)
|
||||
* MY_CLOSE fclose(...)
|
||||
* MY_ATEOF feof(...)
|
||||
* MY_TELL ftell(...)
|
||||
* MY_SEEK fseek(..., SEEK_SET)
|
||||
* MY_REWIND rewind(...)
|
||||
* MY_SETBUFFER (not a standard for stdio, does nothing there)
|
||||
* MY_FILELENGTH (not a standard for stdio, but implemented anyway)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Important DEFINEs:
|
||||
*
|
||||
* It is important to define these consistantly across the various
|
||||
* compilation modules of your program if you wish to exchange file
|
||||
* handles between them.
|
||||
*
|
||||
* USE_PHYSFS: Define USE_PHYSFS if PhysicsFS is being used; note that if
|
||||
* you do intend to use PhysicsFS then you will still need to initialize
|
||||
* PhysicsFS yourself and set up its search-paths.
|
||||
*
|
||||
* Optional DEFINEs:
|
||||
*
|
||||
* PHYSFS_DEFAULT_BUFFER_SIZE <bytes>: If set then abs-file.h sets the
|
||||
* PhysicsFS buffer size to this value whenever you open a file. You
|
||||
* may over-ride this on a per-filehandle basis by using the
|
||||
* MY_SETBUFFER() macro (which simply does nothing when not using
|
||||
* PhysicsFS). If you have not defined this value explicitly then
|
||||
* abs-file.h will default to the same default buffer size as used by
|
||||
* stdio if it can be determined, or 8192 bytes otherwise.
|
||||
*/
|
||||
|
||||
#ifndef PHYSFS_DEFAULT_BUFFER_SIZE
|
||||
#ifdef BUFSIZ
|
||||
#define PHYSFS_DEFAULT_BUFFER_SIZE BUFSIZ
|
||||
#else
|
||||
#define PHYSFS_DEFAULT_BUFFER_SIZE 8192
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef USE_PHYSFS
|
||||
|
||||
#include <physfs.h>
|
||||
#define MY_FILETYPE PHYSFS_file
|
||||
#define MY_SETBUFFER(fp,size) PHYSFS_setBuffer(fp,size)
|
||||
#define MY_READ(p,s,n,fp) PHYSFS_read(fp,p,s,n)
|
||||
#define MY_WRITE(p,s,n,fp) PHYSFS_write(fp,p,s,n)
|
||||
#if PHYSFS_DEFAULT_BUFFER_SIZE
|
||||
static MY_FILETYPE* MY_OPEN_FOR_READ(const char *const filename)
|
||||
{
|
||||
MY_FILETYPE *const file = PHYSFS_openRead(filename);
|
||||
if (file) {
|
||||
MY_SETBUFFER(file, PHYSFS_DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
static MY_FILETYPE* MY_OPEN_FOR_WRITE(const char *const filename)
|
||||
{
|
||||
MY_FILETYPE *const file = PHYSFS_openWrite(filename);
|
||||
if (file) {
|
||||
MY_SETBUFFER(file, PHYSFS_DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
#else
|
||||
#define MY_OPEN_FOR_READ(fn) PHYSFS_openRead(fn)
|
||||
#define MY_OPEN_FOR_WRITE(fn) PHYSFS_openWrite(fn)
|
||||
#endif
|
||||
static int MY_GETC(MY_FILETYPE *const fp) {
|
||||
unsigned char c;
|
||||
/*if (PHYSFS_eof(fp)) {
|
||||
return EOF;
|
||||
}
|
||||
MY_READ(&c, 1, 1, fp);*/
|
||||
if (MY_READ(&c, 1, 1, fp) != 1) {
|
||||
return EOF;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
static char * MY_GETS(char * const str, const int size,
|
||||
MY_FILETYPE *const fp) {
|
||||
int i = 0;
|
||||
int c;
|
||||
do {
|
||||
if (i == size-1) {
|
||||
break;
|
||||
}
|
||||
c = MY_GETC(fp);
|
||||
if (c == EOF) {
|
||||
break;
|
||||
}
|
||||
str[i++] = c;
|
||||
} while (c != '\0' &&
|
||||
c != -1 &&
|
||||
c != '\n');
|
||||
str[i] = '\0';
|
||||
if (i == 0) {
|
||||
return NULL;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
static int MY_PUTC(int c, MY_FILETYPE *const fp) {
|
||||
unsigned char cc = (unsigned char)c;
|
||||
if (MY_WRITE(&cc, 1, 1, fp) != 1) {
|
||||
return EOF;
|
||||
}
|
||||
return (int)cc;
|
||||
}
|
||||
static int MY_PUTS(const char *s, MY_FILETYPE *const fp) {
|
||||
int i = 0;
|
||||
while (s[i] != '\0') {
|
||||
if (MY_PUTC(s[i], fp) == EOF) {
|
||||
return EOF;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (MY_PUTC('\n', fp) == EOF) {
|
||||
return EOF;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#define MY_CLOSE(fp) (0==PHYSFS_close(fp))
|
||||
#define MY_ATEOF(fp) PHYSFS_eof(fp)
|
||||
#define MY_TELL(fp) PHYSFS_tell(fp)
|
||||
#define MY_SEEK(fp,o) (0==PHYSFS_seek(fp,o))
|
||||
#define MY_REWIND(fp) MY_SEEK(fp,0)
|
||||
#define MY_FILELENGTH(fp) PHYSFS_fileLength(fp)
|
||||
|
||||
#else /* !USE_PHYSFS */
|
||||
|
||||
#define MY_FILETYPE FILE
|
||||
#define MY_READ(p,s,n,fp) fread(p,s,n,fp)
|
||||
#define MY_WRITE(p,s,n,fp) fwrite(p,s,n,fp)
|
||||
#define MY_OPEN_FOR_READ(n) fopen(n, "rb")
|
||||
#define MY_OPEN_FOR_WRITE(n) fopen(n, "wb")
|
||||
#define MY_GETC(fp) fgetc(fp)
|
||||
#define MY_GETS(str,size,fp) fgets(str,size,fp)
|
||||
#define MY_PUTC(c,fp) fputc(c,fp)
|
||||
#define MY_PUTS(str,fp) fput(str,fp)
|
||||
#define MY_CLOSE(fp) fclose(fp)
|
||||
#define MY_ATEOF(fp) feof(fp)
|
||||
#define MY_TELL(fp) ftell(fp)
|
||||
#define MY_SEEK(fp,o) fseek(fp,o, SEEK_SET)
|
||||
#define MY_REWIND(fp) rewind(fp)
|
||||
#define MY_SETBUFFER(fp,size)
|
||||
/* a TODO from ryan: "seeking to the end followed by an ftell() is probably
|
||||
more portable, but you can also use fileno() to get a handle from a
|
||||
(FILE *) to use with fstat()...on supported platforms, that is, most
|
||||
platforms, this is probably faster." */
|
||||
static long MY_FILELENGTH(FILE *fp) {
|
||||
long currentpos = ftell(fp); /* save current cursor position */
|
||||
long newpos;
|
||||
fseek(fp, 0, SEEK_END); /* seek to end */
|
||||
newpos = ftell(fp); /* find position of end -- this is the length */
|
||||
fseek(fp, currentpos, SEEK_SET); /* restore previous cursor position */
|
||||
return newpos;
|
||||
}
|
||||
#endif /* USE_PHYSFS */
|
||||
|
||||
#endif /* _ABS_FILE_H */
|
||||
2397
Extras/readblend/readblend.c
Normal file
2397
Extras/readblend/readblend.c
Normal file
File diff suppressed because it is too large
Load Diff
459
Extras/readblend/readblend.h
Normal file
459
Extras/readblend/readblend.h
Normal file
@@ -0,0 +1,459 @@
|
||||
/***************************************************************
|
||||
* readblend.h --
|
||||
* ReadBlend, a data extraction API for Blender's .blend files
|
||||
*
|
||||
* (c) 2003 Adam D. Moss <adam@gimp.org> <aspirin@icculus.org>
|
||||
*
|
||||
*/
|
||||
|
||||
/* VERSION HISTORY
|
||||
* 2003-04-05 : v1.0
|
||||
* 2008-10-05 : v1.1-beta
|
||||
*/
|
||||
|
||||
/* Blender files are 'curiously' structured and this is mirrored in
|
||||
* the low-level data access API (the section labelled 'Low-level
|
||||
* querying functions').
|
||||
*
|
||||
* The mid-level data access API (the section labelled 'Mid-level
|
||||
* querying functions') tries to provide some handy utilities to
|
||||
* ease your data-extraction pain, and finally the (partially written)
|
||||
* high-level data access API incorporates semantic knowledge of Blender's
|
||||
* useful high-level types such as Meshes and Materials to shield you
|
||||
* from the full horror.
|
||||
*/
|
||||
#ifndef _READBLEND_H
|
||||
#define _READBLEND_H
|
||||
|
||||
#include <stdlib.h>
|
||||
//#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>//size_t for MSVC 6.0
|
||||
|
||||
#include <cfloat>
|
||||
#include <float.h>
|
||||
|
||||
#include "abs-file.h"
|
||||
|
||||
/* TODO: Doxygen me. */
|
||||
|
||||
|
||||
/* don't worry yourself about this. */
|
||||
#ifndef BlendFile
|
||||
#define BlendFile void
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************/
|
||||
/* .blend handle load/free functions */
|
||||
/*************************************/
|
||||
|
||||
|
||||
/* Pass in an already-opened file handle; this function will then
|
||||
examine the file to check that it is a Blender file and scan the
|
||||
entire file to extract all vital information (quite expensive)
|
||||
before any query operations can be performed. The resulting
|
||||
.blend data handle is returned.
|
||||
*/
|
||||
|
||||
BlendFile* blend_read(MY_FILETYPE* file);
|
||||
|
||||
|
||||
/* Free all of the given BlendFile data (note: obviously, do not attempt
|
||||
to extract data from a BlendFile which has been freed!) */
|
||||
|
||||
void blend_free(BlendFile* blend_file);
|
||||
|
||||
|
||||
/********************************/
|
||||
/* Public data querying types */
|
||||
/********************************/
|
||||
|
||||
|
||||
/* heed this enum well. */
|
||||
typedef enum {
|
||||
/* you're unlikely to encounter these in the wild. */
|
||||
BLEND_OBJ_NULL,
|
||||
BLEND_OBJ_OPAQUE,
|
||||
|
||||
/* these object types are fetchable as-is */
|
||||
BLEND_OBJ_UCHAR8,
|
||||
BLEND_OBJ_CHAR8,
|
||||
BLEND_OBJ_USHORT16,
|
||||
BLEND_OBJ_SHORT16,
|
||||
BLEND_OBJ_ULONG32,
|
||||
BLEND_OBJ_LONG32,
|
||||
BLEND_OBJ_FLOAT,
|
||||
BLEND_OBJ_DOUBLE,
|
||||
BLEND_OBJ_POINTER,
|
||||
|
||||
/* you'll need to extract the fields from these individually */
|
||||
BLEND_OBJ_STRUCT
|
||||
} BlendObjType;
|
||||
|
||||
typedef void* BlendBlockPointer;
|
||||
|
||||
/* note: treat this as an opaque type and you'll live longer. */
|
||||
typedef struct {
|
||||
long type; long name; BlendBlockPointer block;
|
||||
long entry_index; long field_index;
|
||||
} BlendObject;
|
||||
|
||||
/* The callback type for passing to blend_foreach_block() (the callback
|
||||
should return zero if it doesn't want to see any more blocks.) */
|
||||
#define BLENDBLOCKCALLBACK_RETURN int
|
||||
#define BLENDBLOCKCALLBACK_ARGS BlendBlockPointer block, \
|
||||
BlendFile* blend_file, \
|
||||
void* userdata
|
||||
typedef BLENDBLOCKCALLBACK_RETURN(BlendBlockCallback)
|
||||
(BLENDBLOCKCALLBACK_ARGS);
|
||||
|
||||
|
||||
/********************************/
|
||||
/* File info dumping functions */
|
||||
/********************************/
|
||||
|
||||
/* these functions simply print dumps of information about the given
|
||||
BlendFile. These are vital for familiarising yourself with the
|
||||
structure of Blender's various scene objects if you're using the
|
||||
low/mid-level APIs to construct queries to extract information about
|
||||
specific types of objects that haven't been conveniently abstracted by
|
||||
the high-level API yet. (That is, most of them right now, particularly
|
||||
the more obscure or deprecated ones.) */
|
||||
|
||||
/* print out the size, field-types and field-names of all of the varieties
|
||||
of types (atomic and struct) represented within this BlendFile. The
|
||||
sizes are the in-file representations; the in-memory representations
|
||||
are potentially subject to additional padding and conversions.
|
||||
*/
|
||||
void blend_dump_typedefs(BlendFile* bf);
|
||||
|
||||
/* For every top-level block of data in the file, print the block's
|
||||
tag, its in-memory address, its type, and the number of entries of that
|
||||
type. (Every pointer in a structure should point to one of these
|
||||
in-memory block addresses because we convert from in-file pointers to
|
||||
in-memory pointers automagically; a few in-file pointers within structures
|
||||
do actually point somewhere into the middle of a block or nowhere, which we
|
||||
don't currently support and silently convert to NULL.) Also, any structs
|
||||
at the top-level with an id->name have that name printed out. */
|
||||
void blend_dump_blocks(BlendFile* bf);
|
||||
|
||||
|
||||
/********************************/
|
||||
/* Low-level querying functions */
|
||||
/********************************/
|
||||
|
||||
|
||||
/* Calls the user-supplied callback function for every top-level
|
||||
data block in the .blend file. You can use this to count blocks
|
||||
(which is pretty pointless) or search for a particular block you're
|
||||
interested in. */
|
||||
void blend_foreach_block(BlendFile* blend_file,
|
||||
BlendBlockCallback* func,
|
||||
void* userdata);
|
||||
|
||||
/* Returns the tag-name ('IM', 'DATA', 'ME', etc) for the given
|
||||
top-level data block. */
|
||||
const char* blend_block_get_tagname(BlendFile* blend_file,
|
||||
BlendBlockPointer block);
|
||||
|
||||
/* Returns the type of the given top-level data block in raw
|
||||
string form ('uchar', 'float', 'MFace', 'Mesh', etc). */
|
||||
const char* blend_block_get_typename(BlendFile* blend_file,
|
||||
BlendBlockPointer block);
|
||||
|
||||
/* Translate a pointer from the file's raw data into a BlendBlockPointer
|
||||
that you can query via the API. You will usually NOT need to ever
|
||||
use this unless you're manually extracting pointers from opaque raw data
|
||||
types. Returns NULL on failure or if the input pointer is really NULL. */
|
||||
BlendBlockPointer blend_block_from_blendpointer(BlendFile *blend_file,
|
||||
uint32_t blendpointer);
|
||||
|
||||
/* Returns the number of entries there are in the given top-level
|
||||
data block (a top-level data block is like an array of entries of a specific
|
||||
Blender type, this type usually being one of Blender's structs). */
|
||||
int blend_block_get_entry_count(BlendFile* blend_file,
|
||||
BlendBlockPointer block);
|
||||
|
||||
/* This gets an object handle on the Nth piece of data (in the range
|
||||
0..TOTAL-1, where TOTAL is the figure returned by
|
||||
blend_block_get_entry_count() ) in the given top-level block. */
|
||||
BlendObject blend_block_get_object(BlendFile* blend_file,
|
||||
BlendBlockPointer block,
|
||||
int entry_index);
|
||||
|
||||
/* Returns a BlendObjType enum handy for checking that the general type
|
||||
of the object you have a handle on is what you're expecting. */
|
||||
BlendObjType blend_object_type(BlendFile* blend_file,
|
||||
BlendObject obj);
|
||||
|
||||
/* Given a BlendObject of type BLEND_OBJ_STRUCT in 'obj', fill in the
|
||||
BlendObject pointed to by 'result' with a handle to the named
|
||||
field of that structure (note that the resulting data object might
|
||||
itself be a structure!). 0 is returned on failure (i.e. this structure
|
||||
does not have a field of the requested name, or you supplied an
|
||||
object which is not a structure). */
|
||||
int blend_object_structure_getfield(BlendFile* blend_file,
|
||||
BlendObject *result,
|
||||
BlendObject obj,
|
||||
const char* field_name);
|
||||
|
||||
/* Gets the size (in elements) of an object which is a 1D or 2D array.
|
||||
A non-array is equivalent to an array of size 1x1. A 1D array will
|
||||
always have dim1 == 1. */
|
||||
void blend_object_array_getdims(BlendFile* blend_file,
|
||||
BlendObject obj,
|
||||
int* dim1, int* dim2);
|
||||
|
||||
/* This fetches a piece of data from the .blend file in a format
|
||||
suitable for your architecture (i.e. ints will be of proper size
|
||||
and endianness, pointers are transformed to valid BlendBlockPointers
|
||||
or NULL, etc) into the address pointed to by dest. It's up to you to
|
||||
check that the data you're asking for will fit into the type you're
|
||||
trying to put it in (use blend_object_type() and see the BlendObjType
|
||||
enum to check that the object's type is the one you're expecting.)
|
||||
|
||||
Composite structures (BLEND_OBJ_STRUCT) are not handled atomically;
|
||||
use blend_object_structure_getfield() to extract each named field from
|
||||
a structure individually.
|
||||
|
||||
1 is returned on success. Failure occurs when you try to extract
|
||||
data from a structure (see blend_object_structure_getfield()) or
|
||||
an array (use blend_object_array_getdata()).
|
||||
*/
|
||||
int blend_object_getdata(BlendFile* blend_file,
|
||||
void* dest, BlendObject obj);
|
||||
|
||||
/* This operates like blend_object_getdata() except that it is happy
|
||||
to copy an item of data out of an array. The array is always treated
|
||||
as two-dimensional (data[dimension1][dimension2]); if you're accessing
|
||||
a one-dimensional array then simply specify dim_index_1 as 0.
|
||||
(Indices are in the range 0..DIMSIZE-1.)
|
||||
|
||||
Similarly, plain non-array data can be fetched by specifying
|
||||
dim_index_1 == dim_index_2 == 0. This makes
|
||||
blend_object_array_getdata(bf, dest, obj, 0, 0) equivalent to
|
||||
blend_object_getdata(bf, dest, obj) except that it is happy to
|
||||
be called with an array, from which it will extract the first
|
||||
element.
|
||||
|
||||
Like blend_object_getdata(), it will not fetch a structure (from
|
||||
an array of structures; fortunately I've not seen a .blend file
|
||||
featuring an array of structures so we'll bridge that API gap
|
||||
when we come to it).
|
||||
*/
|
||||
int blend_object_array_getdata(BlendFile* blend_file,
|
||||
void* dest, BlendObject obj,
|
||||
int dim_index_1, int dim_index_2);
|
||||
|
||||
/********************************/
|
||||
/* Mid-level querying functions */
|
||||
/********************************/
|
||||
|
||||
typedef unsigned long BlendLayerMask;
|
||||
|
||||
/* extract a string from a char-array or uchar-array object, up to
|
||||
max_chars in length including the \0 terminator. If the object is
|
||||
a two-dimensional array then the first string is extracted. Returns
|
||||
0 on failure.
|
||||
*/
|
||||
int blend_object_getstring(BlendFile* blend_file,
|
||||
BlendObject obj,
|
||||
char *dest, int max_chars);
|
||||
|
||||
/* Searches the file for a top-level object with the given ID name.
|
||||
Typical ID names are 'OBCamera', 'MECircle.003', 'MAplastic', 'TEgrass' etc.
|
||||
The first two characters of an ID name keep the namespaces separate,
|
||||
so that a material (MA) with the name 'metal' is distinguishable from
|
||||
a texture (TE) with the name 'metal'. That's a foible of Blender itself.
|
||||
|
||||
blend_object_get_by_IDname() returns 0 on failure. It only returns one
|
||||
object of the given IDname; there should indeed be only one, as Blender
|
||||
enforces this uniqueness.
|
||||
*/
|
||||
int blend_object_get_by_IDname(BlendFile* blend_file,
|
||||
BlendObject *result,
|
||||
const char* IDname);
|
||||
/* get string from [obj].ID.name -- caller allocs/frees */
|
||||
int blend_object_get_IDname(BlendFile* blend_file,
|
||||
BlendObject obj,
|
||||
char *dest, int max_chars);
|
||||
|
||||
/* returns !0 if the blender Object whose handle is objobj is a top-level
|
||||
object -- that is, it's not a child of another Object. */
|
||||
int blend_obj_is_rootobject(BlendFile *bf, BlendObject *objobj);
|
||||
/* return the layers (bitmask) that an Object lives on. */
|
||||
BlendLayerMask blend_obj_get_layermask(BlendFile *bf, BlendObject *objobj);
|
||||
|
||||
/* These functions can be a bit slow -- each one requires a linear scan
|
||||
of the file's blocks. But they're handy... */
|
||||
/* Return number of children that this Object has. Can be 0. */
|
||||
int blend_obj_get_childcount(BlendFile *bf, BlendObject *objobj);
|
||||
/* Gets child number childnum of the Object. childnum=0 returns
|
||||
the first, childnum=1 returns the second, etc. */
|
||||
BlendBlockPointer blend_obj_get_child(BlendFile *bf, BlendObject *objobj,
|
||||
int childnum);
|
||||
|
||||
/*********************************/
|
||||
/* High-level querying functions */
|
||||
/*********************************/
|
||||
|
||||
typedef struct {
|
||||
int bone_id;
|
||||
float weight;
|
||||
} bDeformWeight;
|
||||
|
||||
typedef struct {
|
||||
float xyz[3];
|
||||
float cnormal[3]; /* cosmetic normal */
|
||||
int mat;
|
||||
bDeformWeight* deform_weights;
|
||||
int deform_weights_count;
|
||||
} bVert;
|
||||
#define BVERT_HAS_CNORMAL(BV) ((BV)->cnormal[0] != 0.0f || \
|
||||
(BV)->cnormal[1] != 0.0f || \
|
||||
(BV)->cnormal[2] != 0.0f)
|
||||
|
||||
#define BFACE_FLAG_SMOOTH 0x01
|
||||
typedef struct {
|
||||
int v[4];
|
||||
float rgba[4][4]; /* vertex colours */
|
||||
float rgba2[4][4]; /* texture face colours (errrr...?) */
|
||||
float uv[4][2];
|
||||
BlendBlockPointer image_id;
|
||||
int mat;
|
||||
unsigned char flags;
|
||||
} bFace;
|
||||
#define BFACE_HAS_TEXTURE(BF) ((BF)->image_id != NULL)
|
||||
#define BFACE_IS_QUAD(BF) ((BF)->v[3] != 0)
|
||||
#define BFACE_IS_TRI(BF) ((BF)->v[2] != 0 && (BF)->v[3] == 0)
|
||||
#define BFACE_IS_LINE(BF) ((BF)->v[1] != 0 && (BF)->v[2] == 0)
|
||||
|
||||
typedef enum {
|
||||
BTEX_AFFECT_COLOUR = 0x01,
|
||||
BTEX_AFFECT_ALPHA = 0x02,
|
||||
BTEX_AFFECT_EMIT = 0x04,
|
||||
BTEX_AFFECT_NORMAL = 0x08,
|
||||
BTEX_AFFECT_NEGNORM = 0x10,
|
||||
BTEX_AFFECT_STENCIL = 0x20 /* not really an 'affect' in blender, but it is */
|
||||
} bTexLayerAffects;
|
||||
|
||||
typedef enum {
|
||||
BTEX_BLEND_NORMAL, /* 'mix' */
|
||||
BTEX_BLEND_MULTIPLY, /* 'mul' -- modulate. */
|
||||
BTEX_BLEND_ADD,
|
||||
BTEX_BLEND_SUB
|
||||
} bTexLayerBlendmode;
|
||||
|
||||
typedef enum {
|
||||
BTEX_COORDS_NONE,
|
||||
BTEX_COORDS_UV,
|
||||
BTEX_COORDS_REFLECT
|
||||
} bTexLayerCoordsType;
|
||||
|
||||
typedef enum {
|
||||
BIMG_FLAG_INTERPOLATE = 0x01, /* upsample */
|
||||
BIMG_FLAG_ANTIALIAS = 0x02, /* downsample */
|
||||
BIMG_FLAG_MIPMAP = 0x04 /* use mipmaps */
|
||||
} bTexImageFlags;
|
||||
|
||||
typedef struct {
|
||||
char *filename; /* image file name -- absolute path! -- NULL if not image. */
|
||||
bTexLayerAffects affects_mask;
|
||||
bTexLayerBlendmode blend_mode;
|
||||
bTexLayerCoordsType coords_type;
|
||||
/* Tex substruct */
|
||||
int is_st_clamped; /* otherwise, repeat... (GL texwrap mode.) */
|
||||
bTexImageFlags flags;
|
||||
short Nflags, Ntype; /* not decoded yet */
|
||||
short xrepeat, yrepeat; /* amounts to scale texcoords by, really */
|
||||
} bTexLayer;
|
||||
|
||||
typedef enum {
|
||||
BMAT_FEATURE_VCOLLIGHT = 0x01,
|
||||
BMAT_FEATURE_VCOLPAINT = 0x02,
|
||||
BMAT_FEATURE_TEXFACE = 0x04,
|
||||
BMAT_FEATURE_SHADELESS = 0x08,
|
||||
BMAT_FEATURE_WIRE = 0x10 /* wireframe rendering */
|
||||
} bMatFeatureMask;
|
||||
|
||||
#define BLENDER_MAX_TEX_LAYERS 8
|
||||
typedef struct {
|
||||
bTexLayer *tex_layer[BLENDER_MAX_TEX_LAYERS];
|
||||
bMatFeatureMask feature_mask;
|
||||
float colour_rgba[4]; /* main material colour */
|
||||
float emit; /* emissive strength, 0..1 */
|
||||
} bMaterial;
|
||||
|
||||
typedef float bMatrix[4][4];
|
||||
|
||||
typedef struct {
|
||||
bVert *vert;
|
||||
int vert_count;
|
||||
bFace *face;
|
||||
int face_count;
|
||||
bMaterial *material; /* or NULL if none */
|
||||
} bMesh;
|
||||
|
||||
typedef enum {
|
||||
BOBJ_TYPE_UNKNOWN,
|
||||
BOBJ_TYPE_NULL, /* indicates object has no data associated with it! */
|
||||
BOBJ_TYPE_MESH
|
||||
} bObjType;
|
||||
|
||||
typedef enum {
|
||||
BAQ_INCLUDE_CHILDREN = 0x0001
|
||||
} bAcquireFlags;
|
||||
|
||||
typedef struct {
|
||||
bObjType type;
|
||||
char *name;
|
||||
|
||||
bMatrix transform; /* local transformation matrix */
|
||||
bMatrix parentimat; /* parent's inverse transform matrix */
|
||||
float scaling[3]; /* scaling component of transform */
|
||||
float rotphr[3]; /* pitch/head/roll rotation component of transform (use for normals) */
|
||||
float location[3]; /* location component of transform */
|
||||
unsigned char transflags; /* NOT DECODED YET, RAW BYTE */
|
||||
|
||||
union {
|
||||
void *dummy;
|
||||
bMesh *mesh;
|
||||
} data;
|
||||
} bObj;
|
||||
|
||||
|
||||
bObj *blend_alloc_obj(void);
|
||||
void blend_init_obj(bObj *obj);
|
||||
void blend_free_obj(bObj *obj);
|
||||
void blend_free_obj_inner(bObj *obj);
|
||||
void blend_acquire_obj_from_obj(BlendFile *bf, BlendObject *objobj,
|
||||
bObj *outobj,
|
||||
/* malloc'd BlendObject will be written here if pointer if non-NULL: */ BlendObject **outblendobject);
|
||||
|
||||
bMesh *blend_alloc_mesh(void);
|
||||
void blend_init_mesh(bMesh *mesh);
|
||||
void blend_free_mesh_inner(bMesh *mesh);
|
||||
void blend_free_mesh(bMesh *mesh);
|
||||
void blend_acquire_mesh(const char *fname, const char *want_name, bMesh *mesh);
|
||||
void blend_acquire_mesh_from_obj(BlendFile *bf,
|
||||
BlendObject *meobj,
|
||||
bMesh *mesh);
|
||||
/* apply transformation found in 'obj' to 'mesh' */
|
||||
void blend_transform_mesh_from_obj(bMesh *mesh, bObj *obj);
|
||||
|
||||
bMaterial *blend_alloc_material(void);
|
||||
void blend_init_material(bMaterial *mat);
|
||||
void blend_free_material(bMaterial *mat);
|
||||
void blend_acquire_material_from_obj(BlendFile *bf, BlendObject *meobj,
|
||||
bMaterial *mat);
|
||||
|
||||
bTexLayer *blend_alloc_texlayer(void);
|
||||
void blend_init_texlayer(bTexLayer *tl);
|
||||
void blend_free_texlayer(bTexLayer *tl);
|
||||
void blend_acquire_texlayer_from_obj(BlendFile *bf, BlendObject *tlobj,
|
||||
bTexLayer *tl);
|
||||
|
||||
#endif
|
||||
110
Extras/readblend/testblend.c
Normal file
110
Extras/readblend/testblend.c
Normal file
@@ -0,0 +1,110 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "abs-file.h"
|
||||
|
||||
#include "readblend.h"
|
||||
|
||||
void crawl(BlendFile* blend_file,
|
||||
BlendObject obj)
|
||||
{
|
||||
BlendObject data_obj;
|
||||
|
||||
if (blend_object_structure_getfield(blend_file, &data_obj, obj, "totvert")) {
|
||||
if (blend_object_type(blend_file, data_obj) == BLEND_OBJ_LONG32) {
|
||||
long data1 = 123456;
|
||||
if (blend_object_getdata(blend_file, &data1, data_obj)) {
|
||||
fprintf(stderr, "TOTVERT=(%ld) ", data1);
|
||||
} else {
|
||||
fprintf(stderr, "FETCH ERROR\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (blend_object_structure_getfield(blend_file, &data_obj, obj, "co")) {
|
||||
if (blend_object_type(blend_file, data_obj) == BLEND_OBJ_FLOAT) {
|
||||
float data1 = 123456.7;
|
||||
float data2 = 123456.8;
|
||||
float data3 = 123456.9;
|
||||
if (blend_object_array_getdata(blend_file, &data1, data_obj, 0,0) &&
|
||||
blend_object_array_getdata(blend_file, &data2, data_obj, 0,1) &&
|
||||
blend_object_array_getdata(blend_file, &data3, data_obj, 0,2)) {
|
||||
fprintf(stderr, "CO=(%f,%f,%f) ", data1, data2, data3);
|
||||
} else {
|
||||
fprintf(stderr, "FETCH ERROR\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static BLENDBLOCKCALLBACK_RETURN
|
||||
blockiter(BLENDBLOCKCALLBACK_ARGS) {
|
||||
int i;
|
||||
int entry_count = blend_block_get_entry_count(blend_file, block);
|
||||
#if 0
|
||||
const char* tagname = blend_block_get_tagname(blend_file, block);
|
||||
const char* typename = blend_block_get_typename(blend_file, block);
|
||||
fprintf(stderr, "block: tag=%s type=%s entries=%d ",
|
||||
tagname, typename, entry_count);
|
||||
#endif
|
||||
for (i=0; i<entry_count; ++i) {
|
||||
BlendObject obj = blend_block_get_object(blend_file, block, i);
|
||||
crawl(blend_file, obj);
|
||||
}
|
||||
//fprintf(stderr, "\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
MY_FILETYPE *file;
|
||||
BlendFile *bf;
|
||||
int rtn = 0;
|
||||
|
||||
if (argc <= 1) {
|
||||
fprintf(stderr, "specify filename on command line.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
file = MY_OPEN_FOR_READ(argv[1]);
|
||||
|
||||
if (!file) {
|
||||
fprintf(stderr, "couldn't open file. :(\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
bf = blend_read(file);
|
||||
|
||||
if (!bf) {
|
||||
fprintf(stderr, "couldn't read blender file. :(\n");
|
||||
rtn = -1;
|
||||
goto closeit;
|
||||
}
|
||||
|
||||
blend_dump_typedefs(bf);
|
||||
|
||||
blend_dump_blocks(bf);
|
||||
|
||||
fflush(stdout);
|
||||
|
||||
blend_foreach_block(bf, blockiter, NULL);
|
||||
|
||||
|
||||
{
|
||||
BlendObject obj;
|
||||
char want_name[] = "IMmetalrock.jpg";
|
||||
if (blend_object_get_by_IDname(bf,&obj, want_name)) {
|
||||
fprintf(stderr, "got %s.\n", want_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
blend_free(bf);
|
||||
|
||||
closeit:
|
||||
MY_CLOSE(file);
|
||||
return rtn;
|
||||
}
|
||||
Reference in New Issue
Block a user