Minor constraint refactoring, to allow SPU-side processing for PLAYSTATION 3 (added non-virtual methods)
Also comment-out some code for __SPU__ to reduce code size Added btContactConstraint (only used on PS3 SPU right now, better to use btPersistentManifold directly for contact constraints) Improved readblend utility library (see also usage in http://gamekit.googlecode.com with Irrlicht) Fix for btConvexConvexAlgorithm, potential division by zero Thanks linzner http://code.google.com/p/bullet/issues/detail?id=260
This commit is contained in:
@@ -10,13 +10,18 @@
|
||||
#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;
|
||||
#ifdef WIN32
|
||||
|
||||
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;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
PLEASE NOTE: This license applies to abs-file.h ONLY; The version of
|
||||
@@ -194,6 +199,8 @@ static int MY_PUTS(const char *s, MY_FILETYPE *const fp) {
|
||||
|
||||
#else /* !USE_PHYSFS */
|
||||
|
||||
//#define USE_POSIX_FILES 1
|
||||
#ifdef USE_POSIX_FILES
|
||||
#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)
|
||||
@@ -221,6 +228,33 @@ static long MY_FILELENGTH(FILE *fp) {
|
||||
fseek(fp, currentpos, SEEK_SET); /* restore previous cursor position */
|
||||
return newpos;
|
||||
}
|
||||
#else
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MY_FILETYPE char
|
||||
|
||||
|
||||
long MY_FILELENGTH(FILE *fp);
|
||||
MY_FILETYPE* MY_OPEN_FOR_READ(const char *const filename);
|
||||
int MY_GETC(MY_FILETYPE *const fp);
|
||||
void MY_SEEK(MY_FILETYPE* fp,int pos);
|
||||
#define MY_REWIND(fp) MY_SEEK(fp,0)
|
||||
int MY_READ(unsigned char* dest,int size,int num,MY_FILETYPE* fp);
|
||||
|
||||
void MY_CLOSE(MY_FILETYPE* fp);
|
||||
int MY_TELL(MY_FILETYPE* fp);
|
||||
int MY_ATEOF(MY_FILETYPE* fp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //USE_POSIX_FILES
|
||||
|
||||
#endif /* USE_PHYSFS */
|
||||
|
||||
#endif /* _ABS_FILE_H */
|
||||
|
||||
87
Extras/readblend/blendtype.h
Normal file
87
Extras/readblend/blendtype.h
Normal file
@@ -0,0 +1,87 @@
|
||||
#ifndef BLEND_TYPE_H
|
||||
#define BLEND_TYPE_H
|
||||
#include "abs-file.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _BlendField BlendField;
|
||||
struct _BlendField {
|
||||
char* field_bytes;
|
||||
int field_bytes_count;
|
||||
|
||||
/* the offset into field_bytes at which each field of a
|
||||
structure begins. this is so we can keep the data aligned
|
||||
correctly for various architectures. a non-structure type
|
||||
is equivalent to a structure with a single field.
|
||||
*/
|
||||
int* field_offsets;
|
||||
int field_offsets_count;
|
||||
};
|
||||
struct _BlendBlock {
|
||||
char tag[5];
|
||||
uint32_t blender_pointer;
|
||||
/*void* fixed_pointer;*/
|
||||
|
||||
int type_index;
|
||||
/* a block is simply an array of its type as defined by type_index.
|
||||
array_entries is an array of pointers to each entry in the block's
|
||||
array.
|
||||
*/
|
||||
BlendField *array_entries;
|
||||
int array_entries_count;
|
||||
void* customData; /* for Link blocks, with custom data such as .jpg pictures etc */
|
||||
int customDataSize;
|
||||
};
|
||||
|
||||
|
||||
typedef struct _BlendBlock BlendBlock;
|
||||
|
||||
/* the types extracted from the Blender file */
|
||||
typedef struct _BlendType BlendType;
|
||||
struct _BlendType {
|
||||
char* name;
|
||||
int size;
|
||||
|
||||
int is_struct;
|
||||
|
||||
/* if is_struct... this defines the types of each of the structure fields */
|
||||
int fieldtypes_count;
|
||||
int* fieldtypes; /* type indices */
|
||||
int fieldnames_count;
|
||||
int* fieldnames; /* name indices */
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* the opaque BlendFile structure */
|
||||
typedef struct _BlendFile{
|
||||
BlendType* types;
|
||||
int types_count;
|
||||
|
||||
char* *names;
|
||||
int names_count;
|
||||
|
||||
int* strc_indices;
|
||||
int strc_indices_count;
|
||||
|
||||
BlendBlock *blocks;
|
||||
int blocks_count;
|
||||
|
||||
int name_undef; /* index of the name we add specially for top blocks */
|
||||
|
||||
} BlendFile;
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //BLEND_TYPE_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -38,11 +38,11 @@
|
||||
/* TODO: Doxygen me. */
|
||||
|
||||
|
||||
/* don't worry yourself about this. */
|
||||
#ifndef BlendFile
|
||||
#define BlendFile void
|
||||
#endif
|
||||
#include "blendtype.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -101,6 +101,7 @@ typedef struct {
|
||||
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
|
||||
@@ -312,20 +313,41 @@ typedef struct {
|
||||
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 _bImage {
|
||||
|
||||
void* m_packedImagePtr;
|
||||
int m_sizePackedImage;
|
||||
char m_imagePathName [128];
|
||||
|
||||
int m_ok;
|
||||
|
||||
int m_xrep;
|
||||
int m_yrep;
|
||||
|
||||
} bImage;
|
||||
|
||||
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;
|
||||
bImage* m_image;
|
||||
int mat;
|
||||
unsigned char flags;
|
||||
int m_flag;
|
||||
int m_mode;
|
||||
BlendBlockPointer image_id;
|
||||
} 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)
|
||||
@@ -389,7 +411,7 @@ typedef struct {
|
||||
|
||||
typedef float bMatrix[4][4];
|
||||
|
||||
typedef struct {
|
||||
typedef struct _bMesh{
|
||||
bVert *vert;
|
||||
int vert_count;
|
||||
bFace *face;
|
||||
@@ -400,14 +422,17 @@ typedef struct {
|
||||
typedef enum {
|
||||
BOBJ_TYPE_UNKNOWN,
|
||||
BOBJ_TYPE_NULL, /* indicates object has no data associated with it! */
|
||||
BOBJ_TYPE_MESH
|
||||
BOBJ_TYPE_MESH,
|
||||
BOBJ_TYPE_INVALID_MESH,
|
||||
BOBJ_TYPE_CAMERA,
|
||||
BOBJ_TYPE_LAMP
|
||||
} bObjType;
|
||||
|
||||
typedef enum {
|
||||
BAQ_INCLUDE_CHILDREN = 0x0001
|
||||
} bAcquireFlags;
|
||||
|
||||
typedef struct {
|
||||
typedef struct _bObj{
|
||||
bObjType type;
|
||||
char *name;
|
||||
|
||||
@@ -417,11 +442,15 @@ typedef struct {
|
||||
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 */
|
||||
|
||||
float mass;//used for rigid body dynamics
|
||||
int gameflag; //used to detect object type (static, ghost, dynamic, rigid body, soft body)
|
||||
int boundtype; //used to detect collision shape type
|
||||
|
||||
union {
|
||||
void *dummy;
|
||||
bMesh *mesh;
|
||||
} data;
|
||||
|
||||
} bObj;
|
||||
|
||||
|
||||
@@ -456,4 +485,8 @@ void blend_free_texlayer(bTexLayer *tl);
|
||||
void blend_acquire_texlayer_from_obj(BlendFile *bf, BlendObject *tlobj,
|
||||
bTexLayer *tl);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,107 +4,170 @@
|
||||
#include "abs-file.h"
|
||||
|
||||
#include "readblend.h"
|
||||
#include "blendtype.h"
|
||||
|
||||
#define MAX_MESHES 10
|
||||
bMesh gMeshes[MAX_MESHES];
|
||||
int gNumMesh = 0;
|
||||
|
||||
#define MAX_OBJECTS 10
|
||||
bObj gObjects[MAX_OBJECTS];
|
||||
int gNumObjects = 0;
|
||||
|
||||
void crawl(BlendFile* blend_file,
|
||||
BlendObject obj)
|
||||
BlendObject obj)
|
||||
{
|
||||
BlendObject data_obj;
|
||||
BlendObject data_obj;
|
||||
BlendObject data_obj2;
|
||||
|
||||
BlendBlock* tmpBlock=0;
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
const char* type_name = blend_file->types[obj.type].name;
|
||||
if (strcmp(type_name,"Object")==0)
|
||||
{
|
||||
if (gNumObjects<MAX_OBJECTS)
|
||||
{
|
||||
blend_acquire_obj_from_obj(blend_file,&obj,&gObjects[gNumObjects],0);
|
||||
gNumObjects++;
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strcmp(type_name,"Mesh")==0)
|
||||
{
|
||||
printf("object type_name = %s\n",type_name);
|
||||
if (gNumMesh<MAX_MESHES)
|
||||
{
|
||||
blend_acquire_mesh_from_obj(blend_file, &obj, &gMeshes[gNumMesh]);
|
||||
gNumMesh++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
///todo: compress those 4 lines into a one-liner, using a C++ wrapper
|
||||
if (blend_object_structure_getfield(blend_file, &data_obj, obj, "curscene")) {
|
||||
if (blend_object_type(blend_file, data_obj) == BLEND_OBJ_POINTER) {
|
||||
if (blend_object_getdata(blend_file, &tmpBlock, data_obj)) {
|
||||
BlendObject blscene= blend_block_get_object(blend_file,tmpBlock,0);
|
||||
|
||||
if (blend_object_structure_getfield(blend_file, &data_obj,blscene , "id"))
|
||||
{
|
||||
if (blend_object_type(blend_file, data_obj) == BLEND_OBJ_STRUCT)
|
||||
{
|
||||
if (blend_object_structure_getfield(blend_file, &data_obj2,data_obj , "name"))
|
||||
{
|
||||
char dest[19];
|
||||
int max_chars=20;
|
||||
|
||||
if (blend_object_getstring(blend_file, data_obj2,
|
||||
dest, max_chars))
|
||||
{
|
||||
printf("dest=%s\n",dest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (blend_object_structure_getfield(blend_file, &data_obj,blscene , "world")) {
|
||||
if (blend_object_type(blend_file, data_obj) == BLEND_OBJ_POINTER) {
|
||||
if (blend_object_getdata(blend_file, &tmpBlock, data_obj)) {
|
||||
BlendObject blworld= blend_block_get_object(blend_file,tmpBlock,0);
|
||||
|
||||
if (blend_object_structure_getfield(blend_file, &data_obj, blworld, "gravity"))
|
||||
{
|
||||
printf("Scene with world and gravity\n");
|
||||
if (blend_object_type(blend_file, data_obj) == BLEND_OBJ_FLOAT) {
|
||||
float data1 = 123456.7;
|
||||
if (blend_object_getdata(blend_file, &data1, data_obj))
|
||||
fprintf(stderr, "gravity=(%f) ", data1);
|
||||
} 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);
|
||||
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);
|
||||
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;
|
||||
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;
|
||||
MY_FILETYPE *file;
|
||||
BlendFile *bf;
|
||||
int rtn = 0;
|
||||
|
||||
if (argc <= 1) {
|
||||
fprintf(stderr, "specify filename on command line.\n");
|
||||
return -1;
|
||||
}
|
||||
if (argc <= 1) {
|
||||
fprintf(stderr, "specify filename on command line.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
file = MY_OPEN_FOR_READ(argv[1]);
|
||||
file = MY_OPEN_FOR_READ(argv[1]);
|
||||
|
||||
if (!file) {
|
||||
fprintf(stderr, "couldn't open file. :(\n");
|
||||
return -1;
|
||||
}
|
||||
if (!file) {
|
||||
fprintf(stderr, "couldn't open file. :(\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
bf = blend_read(file);
|
||||
bf = blend_read(file);
|
||||
|
||||
if (!bf) {
|
||||
fprintf(stderr, "couldn't read blender file. :(\n");
|
||||
rtn = -1;
|
||||
goto closeit;
|
||||
}
|
||||
if (!bf) {
|
||||
fprintf(stderr, "couldn't read blender file. :(\n");
|
||||
rtn = -1;
|
||||
goto closeit;
|
||||
}
|
||||
|
||||
blend_dump_typedefs(bf);
|
||||
blend_dump_typedefs(bf);
|
||||
|
||||
blend_dump_blocks(bf);
|
||||
// blend_dump_blocks(bf);
|
||||
|
||||
fflush(stdout);
|
||||
fflush(stdout);
|
||||
|
||||
blend_foreach_block(bf, blockiter, NULL);
|
||||
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);
|
||||
}
|
||||
}
|
||||
{
|
||||
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);
|
||||
blend_free(bf);
|
||||
|
||||
closeit:
|
||||
MY_CLOSE(file);
|
||||
return rtn;
|
||||
closeit:
|
||||
MY_CLOSE(file);
|
||||
return rtn;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user