Initial revision

This commit is contained in:
Hans Lambermont
2002-10-12 11:37:38 +00:00
commit 12315f4d0e
1699 changed files with 444708 additions and 0 deletions

View File

@@ -0,0 +1,238 @@
/* BKE_action.h May 2001
*
* Blender kernel action functionality
*
* Reevan McKay
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_ACTION_H
#define BKE_ACTION_H
#include "DNA_listBase.h"
/**
* The following structures are defined in DNA_action_types.h
*/
struct bAction;
struct bActionChannel;
struct bPose;
struct bPoseChannel;
struct Object;
/* Kernel prototypes */
#ifdef __cplusplus
extern "C" {
#endif
/**
* Allocate a new pose channel on the heap and binary copy the
* contents of the src pose channel.
*/
struct bPoseChannel *
copy_pose_channel (
const struct bPoseChannel *src
);
/**
* Removes and deallocates all channels from a pose.
* Does not free the pose itself.
*/
void
clear_pose (
struct bPose *pose
);
/* Sets the value of a pose channel */
struct bPoseChannel *
set_pose_channel (
struct bPose *pose,
struct bPoseChannel *chan
);
/**
* Allocate a new pose on the heap, and copy the src pose and it's channels
* into the new pose. *dst is set to the newly allocated structure.
*/
void
copy_pose(
struct bPose **dst,
const struct bPose *src,
int copyconstraints
);
/**
* Deallocate the action's channels including constraint channels.
* does not free the action structure.
*/
void
free_action(
struct bAction * id
);
void
make_local_action(
struct bAction *act
);
void
do_all_actions(
void
);
/**
* Return a pointer to the pose channel of the given name
* from this pose.
*/
struct bPoseChannel *
get_pose_channel (
const struct bPose *pose,
const char *name
);
/**
* Looks to see if the channel with the given name
* already exists in this pose - if not a new one is
* allocated and initialized.
*/
void
verify_pose_channel (
struct bPose* pose,
const char* name
);
/**
* Allocate a new bAction on the heap and copy
* the contents of src into it. If src is NULL NULL is returned.
*/
struct bAction*
copy_action(
const struct bAction *src
);
/**
* Some kind of bounding box operation on the action.
*/
float
calc_action_start (
const struct bAction *act
);
float
calc_action_end (
const struct bAction *act
);
/**
* Evaluate the pose from the given action.
* If the pose does not exist, a new one is created.
* Some deep calls into blender are made here.
*/
void
get_pose_from_action (
struct bPose **pose,
struct bAction *act,
float ctime
);
/**
* I think this duplicates the src into *pose.
* If the pose does not exist, a new one is created.
* If the pose does not contain channels from src
* new channels are created.
*/
void
get_pose_from_pose (
struct bPose **pose,
const struct bPose *src
);
void
clear_pose_constraint_status (
struct Object *ob
);
/**
* Blends the common subset of channels from dst and src.
* and writes result to dst.
*/
void
blend_poses (
struct bPose *dst,
const struct bPose *src,
float srcweight,
short mode
);
/**
* Iterate through the action channels of the action
* and return the channel with the given name.
* Returns NULL if no channel.
*/
struct bActionChannel *
get_named_actionchannel (
struct bAction *act,
const char *name
);
#ifdef __cplusplus
};
#endif
enum {
POSE_BLEND = 0,
POSE_ADD
};
enum {
POSE_KEY = 0x10000000,
POSE_LOC = 0x00000001,
POSE_ROT = 0x00000002,
POSE_SIZE = 0x00000004,
POSE_UNUSED1 = 0x00000008,
POSE_UNUSED2 = 0x00000010,
POSE_UNUSED3 = 0x00000020,
POSE_UNUSED4 = 0x00000040,
POSE_UNUSED5 = 0x00000080,
POSE_OBMAT = 0x00000100,
POSE_PARMAT = 0x00000200,
PCHAN_DONE = 0x00000400
};
#endif

View File

@@ -0,0 +1,52 @@
/**
* blenlib/BKE_anim.h (mar-2001 nzc);
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_ANIM_H
#define BKE_ANIM_H
struct Path;
struct Object;
struct PartEff;
struct Scene;
void free_path(struct Path *path);
void calc_curvepath(struct Object *ob);
int interval_test(int min, int max, int p1, int cycl);
int where_on_path(struct Object *ob, float ctime, float *vec, float *dir);
void frames_duplilist(struct Object *ob);
void vertex_duplilist(struct Scene *sce, struct Object *par);
void particle_duplilist(struct Scene *sce, struct Object *par, struct PartEff *paf);
void free_duplilist(void);
void make_duplilist(struct Scene *sce, struct Object *ob);
#endif

View File

@@ -0,0 +1,121 @@
/**
* blenlib/BKE_armature.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_ARMATURE_H
#define BKE_ARMATURE_H
struct Bone;
struct Main;
struct bArmature;
struct bPose;
struct Object;
struct MDeformVert;
struct Mesh;
struct PoseChain;
struct ListBase;
typedef struct PoseChain
{
struct PoseChain *next, *prev;
struct Bone *root;
struct Bone *target;
struct bPose *pose;
float goal[3];
float tolerance;
int iterations;
float goalinv[4][4];
struct IK_Chain_Extern *solver;
} PoseChain;
/* Core armature functionality */
#ifdef __cplusplus
extern "C" {
#endif
struct bArmature *add_armature(void);
void free_boneChildren(struct Bone *bone);
void free_bones (struct bArmature *arm);
void unlink_armature(struct bArmature *arm);
void free_armature(struct bArmature *arm);
void make_local_armature(struct bArmature *arm);
struct bArmature *copy_armature(struct bArmature *arm);
void apply_pose_armature (struct bArmature* arm, struct bPose* pose, int doit);
void calc_armature_deform (struct Object *ob, float *co, int index);
int verify_boneptr (struct bArmature *arm, struct Bone *tBone);
void init_armature_deform(struct Object *parent, struct Object *ob);
struct bArmature* get_armature (struct Object* ob);
struct Bone *get_named_bone (struct bArmature *arm, const char *name);
struct Bone *get_indexed_bone (struct bArmature *arm, int index);
void make_displists_by_armature (struct Object *ob);
void calc_bone_deform (struct Bone *bone, float weight, float *vec, float *co, float *contrib);
void where_is_armature_time (struct Object *ob, float ctime);
void where_is_armature (struct Object *ob);
void where_is_bone1_time (struct Object *ob, struct Bone *bone, float ctime);
/* Handy bone matrix functions */
void bone_to_mat4(struct Bone *bone, float mat[][4]);
void bone_to_mat3(struct Bone *bone, float mat[][3]);
void make_boneMatrixvr (float outmatrix[][4],float delta[3], float roll);
void make_boneMatrix (float outmatrix[][4], struct Bone *bone);
void get_bone_root_pos (struct Bone* bone, float vec[3], int posed);
void get_bone_tip_pos (struct Bone* bone, float vec[3], int posed);
float get_bone_length (struct Bone *bone);
void get_objectspace_bone_matrix (struct Bone* bone, float M_accumulatedMatrix[][4], int root, int posed);
void precalc_bone_irestmat (struct Bone *bone);
void precalc_armature_posemats (struct bArmature *arm);
void precalc_bonelist_irestmats (struct ListBase* bonelist);
void apply_bonemat(struct Bone *bone);
/* void make_armatureParentMatrices (struct bArmature *arm); */
void precalc_bone_defmat (struct Bone *bone);
void rebuild_bone_parent_matrix (struct Bone *bone);
/* Animation functions */
void where_is_bone_time (struct Object *ob, struct Bone *bone, float ctime);
void where_is_bone (struct Object *ob, struct Bone *bone);
struct PoseChain *ik_chain_to_posechain (struct Object *ob, struct Bone *bone);
void solve_posechain (PoseChain *chain);
void free_posechain (PoseChain *chain);
/* Gameblender hacks */
void GB_init_armature_deform(struct ListBase *defbase, float premat[][4], float postmat[][4]);
void GB_calc_armature_deform (float *co, struct MDeformVert *dvert);
void GB_build_mats (float parmat[][4], float obmat[][4], float premat[][4], float postmat[][4]);
void GB_validate_defgroups (struct Mesh *mesh, struct ListBase *defbase);
/*void make_boneParentMatrix (struct Bone* bone, float mat[][4]);*/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,143 @@
/**
* blenlib/BKE_bad_level_calls.h (mar-2001 nzc)
*
* Stuff that definitely does not belong in the kernel! These will all
* have to be removed in order to restore sanity.
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_BAD_LEVEL_CALLS_H
#define BKE_BAD_LEVEL_CALLS_H
/* readfile.c */
struct PluginSeq;
void open_plugin_seq(struct PluginSeq *pis, char *seqname);
struct SpaceButs;
void set_rects_butspace(struct SpaceButs *buts);
struct SpaceImaSel;
void check_imasel_copy(struct SpaceImaSel *simasel);
struct ScrArea;
struct bScreen;
void unlink_screen(struct bScreen *sc);
void freeAllRad(void);
void free_editText(void);
void setscreen(struct bScreen *sc);
void force_draw_all(void);
/* otherwise the WHILE_SEQ doesn't work */
struct Sequence;
void build_seqar(struct ListBase *seqbase, struct Sequence ***seqar, int *totseq);
struct ID;
void BPY_do_pyscript (struct ID *id, short int event);
/* writefile.c */
struct Oops;
void free_oops(struct Oops *oops);
void error(char *str, ...);
/* anim.c */
extern struct ListBase editNurb;
/* displist.c */
#include "DNA_world_types.h" /* for render_types */
#include "render_types.h"
extern struct RE_Render R;
float RE_Spec(float, int);
void waitcursor(int);
void allqueue(unsigned short event, short val);
#define REDRAWVIEW3D 0x4010
struct Material;
extern struct Material defmaterial;
/* effect.c */
void RE_jitterate1(float *jit1, float *jit2, int num, float rad1);
void RE_jitterate2(float *jit1, float *jit2, int num, float rad2);
/* exotic.c */
void load_editMesh(void);
void make_editMesh(void);
void free_editMesh(void);
void free_editArmature(void);
void docentre_new(void);
int saveover(char *str);
/* image.c */
#include "DNA_image_types.h"
void free_realtime_image(Image *ima); // has to become a callback, opengl stuff
void RE_make_existing_file(char *name); // from render, but these funcs should be moved anyway
/* ipo.c */
void copy_view3d_lock(short val); // was a hack, to make scene layer ipo's possible
/* library.c */
void allspace(unsigned short event, short val) ;
#define OOPS_TEST 2
/* mball.c */
extern ListBase editelems;
/* object.c */
/* void BPY_free_scriptlink(ScriptLink *slink); */
/* void BPY_copy_scriptlink(ScriptLink *scriptlink); */
float *give_cursor(void); // become a callback or argument
void exit_posemode(int freedata);
/* packedFile.c */
short pupmenu(char *instr); // will be general callback
/* sca.c */
#define LEFTMOUSE 0x001 // because of mouse sensor
/* scene.c */
#include "DNA_sequence_types.h"
void free_editing(struct Editing *ed); // scenes and sequences problem...
/* texture.c */
#define FLO 128
#define INT 96
struct EnvMap;
struct Tex;
void RE_free_envmap(struct EnvMap *env);
struct EnvMap *RE_copy_envmap(struct EnvMap *env);
void RE_free_envmapdata(struct EnvMap *env);
int RE_envmaptex(struct Tex *tex, float *texvec, float *dxt, float *dyt);
void RE_calc_R_ref(void);
extern char texstr[15][8]; /* buttons.c */
/* memory for O is declared in the render module... */
#include "BKE_osa_types.h"
extern Osa O;
/* editsca.c */
void make_unique_prop_names(char *str);
#endif

View File

@@ -0,0 +1,64 @@
/**
* blenlib/BKE_blender.h (mar-2001 nzc)
*
* Blender util stuff?
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_BLENDER_H
#define BKE_BLENDER_H
#ifdef __cplusplus
extern "C" {
#endif
struct ListBase;
#define BLENDER_VERSION 225
int BKE_read_file(char *dir, void *type_r);
int BKE_read_file_from_memory(char* filebuf, int filelength, void *type_r);
void duplicatelist(struct ListBase *list1, struct ListBase *list2);
void free_blender(void);
void initglobals(void);
void pushdata(void *data, int len);
void popfirst(void *data);
void poplast(void *data);
void free_pushpop(void);
void pushpop_test(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,64 @@
/**
* blenlib/BKE_bmfont.h (mar-2001 nzc)
*
*
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_BMFONT_H
#define BKE_BMFONT_H
#ifdef __cplusplus
extern "C" {
#endif
struct bmGlyph;
struct ImBuf;
struct bmFont;
void printfGlyph(struct bmGlyph * glyph);
void calcAlpha(struct ImBuf * ibuf);
void readBitmapFontVersion0(struct ImBuf * ibuf,
unsigned char * rect,
int step);
void detectBitmapFont(struct ImBuf *ibuf);
int locateGlyph(struct bmFont *bmfont, unsigned short unicode);
void matrixGlyph(struct ImBuf * ibuf, unsigned short unicode,
float *centerx, float *centery,
float *sizex, float *sizey,
float *transx, float *transy,
float *movex, float *movey, float *advance);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,61 @@
/**
* blenlib/BKE_bmfont_types.h (mar-2001 nzc)
*
*
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_BMFONT_TYPES_H
#define BKE_BMFONT_TYPES_H
#define is_power_of_two(N) ((N ^ (N - 1)) == (2 * N - 1))
/*
Moved to IMB_imbuf_types.h where it will live close to the ImBuf type.
It is used as a userflag bit mask.
#define IB_BITMAPFONT 1
*/
typedef struct bmGlyph {
unsigned short unicode;
short locx, locy;
signed char ofsx, ofsy;
unsigned char sizex, sizey;
unsigned char advance, reserved;
} bmGlyph;
typedef struct bmFont {
char magic[4];
short version;
short glyphcount;
short xsize, ysize;
bmGlyph glyphs[1];
} bmFont;
#endif

View File

@@ -0,0 +1,143 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_BOOLEANOPS_H
#define BKE_BOOLEANOPS_H
struct Mesh;
struct Object;
struct Base;
struct CSG_FaceIteratorDescriptor;
struct CSG_VertexIteratorDescriptor;
struct CSG_MeshPropertyDescriptor;
/**
* Perform a boolean operation between 2 mesh objects and
* add the result as a new mesh into blender data structures.
* Assumes you have checked that the 2 objects are infact mesh
* objects. Returns 1 on success and zero when it encountered
* a problem. In the latter case no object is added and you should
* report an appropriate error.
*/
extern
int
NewBooleanMesh(
struct Base * base,
struct Base * base_select,
int op_type
);
/**
* Functions exposed for use by BKE_booleanops_mesh
*/
/**
* Returns pointers to new mesh descriptors for
* the given mesh. Make sure you call FreeMeshDescriptors
* after calling this function.
*/
extern
void
BuildMeshDescriptors(
struct Object * ob,
struct CSG_FaceIteratorDescriptor * face_it,
struct CSG_VertexIteratorDescriptor * vertex_it
);
extern
void
FreeMeshDescriptors(
struct CSG_FaceIteratorDescriptor * face_it,
struct CSG_VertexIteratorDescriptor * vertex_it
);
extern
int
ConvertCSGDescriptorsToMeshObject(
struct Object *ob,
struct CSG_MeshPropertyDescriptor * props,
struct CSG_FaceIteratorDescriptor * face_it,
struct CSG_VertexIteratorDescriptor * vertex_it,
float parinv[][4]
);
/**
* This little function adds a new mesh object
* to the blender object list. It uses ob to duplicate
* data as this seems to be easier than cerating a new one.
* This new oject contains no faces nor vertices.
*/
extern
struct Object *
AddNewBlenderMesh(
struct Base *base
);
extern
int
InterpNoUserData(
void *d1,
void *d2,
void *dnew,
float epsilon
);
extern
int
InterpFaceVertexData(
void *d1,
void *d2,
void *dnew,
float epsilon
);
typedef struct {
float uv[2];
float color[4];
} FaceVertexData;
typedef struct {
struct Material *material;
/* assorted tface flags */
void *tpage;
char flag, transp;
short mode, tile;
} FaceData;
#endif

View File

@@ -0,0 +1,122 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_PyBooleanOps_h
#define BKE_PyBooleanOps_h
#include "CSG_BooleanOps.h"
/**
* Internal mesh structure.
* Safe to copy by value... hopefully.
*/
struct Base;
struct Object;
struct CSG_MeshDescriptor;
typedef void (*CSG_DestroyMeshFunc)(struct CSG_MeshDescriptor *);
typedef struct CSG_MeshDescriptor {
struct Base *base; // Ptr to base of original blender object - used in creating a new object
CSG_MeshPropertyDescriptor m_descriptor;
CSG_FaceIteratorDescriptor m_face_iterator;
CSG_VertexIteratorDescriptor m_vertex_iterator;
CSG_DestroyMeshFunc m_destroy_func;
} CSG_MeshDescriptor;
extern
int
CSG_LoadBlenderMesh(
struct Object * obj,
CSG_MeshDescriptor *output
);
/**
* Destroy the contents of a mesh descriptor.
* If the internal descriptor refers to a blender
* mesh, no action is performed apart from freeing
* internal memory in the desriptor.
*/
extern
void
CSG_DestroyMeshDescriptor(
CSG_MeshDescriptor *mesh
);
/**
* Perform a boolean operation between 2 meshes and return the
* result as a new mesh descriptor.
* op_type is an integer code of the boolean operation type.
* 1 = intersection,
* 2 = union,
* 3 = difference.
*/
extern
int
CSG_PerformOp(
CSG_MeshDescriptor *mesh1,
CSG_MeshDescriptor *mesh2,
int op_type,
CSG_MeshDescriptor *output
);
/**
* Add a mesh to blender as a new object.
*/
extern
int
CSG_AddMeshToBlender(
CSG_MeshDescriptor *mesh
);
/**
* Test functionality.
*/
extern
int
NewBooleanMeshTest(
struct Base * base,
struct Base * base_select,
int op_type
);
#endif

View File

@@ -0,0 +1,64 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_CONSTRAINT_H
#define BKE_CONSTRAINT_H
struct bConstraint;
struct Object;
struct ListBase;
struct bConstraintChannel;
struct bAction;
struct bArmature;
/* Function prototypes */
void evaluate_constraint (struct bConstraint *constraint, struct Object *ob, short ownertype, void *ownerdata, float targetmat[][4]);
void free_constraints (struct ListBase *conlist);
void copy_constraints (struct ListBase *dst, struct ListBase *src);
void *copy_constraint_channels (ListBase *dst, ListBase *src);
struct bConstraintChannel *clone_constraint_channels (struct ListBase *dst, struct ListBase *src, struct bConstraintChannel *oldact);
void relink_constraints (struct ListBase *list);
void free_constraint_data (struct bConstraint *con);
void clear_object_constraint_status (struct Object *ob);
void do_constraint_channels (struct ListBase *conbase, struct ListBase *chanbase, float ctime);
short get_constraint_target (struct bConstraint *con, short ownertype, void *ownerdata, float mat[][4], float size[3], float time);
struct bConstraintChannel *find_constraint_channel (ListBase *list, const char *name);
void free_constraint_channels (ListBase *chanbase);
/* Constraint target/owner types */
#define TARGET_OBJECT 1 // string is ""
#define TARGET_BONE 2 // string is bone-name
#define TARGET_VERT 3 // string is "VE:#"
#define TARGET_FACE 4 // string is "FA:#"
#define TARGET_CV 5 // string is "CV:#"
#endif

View File

@@ -0,0 +1,86 @@
/**
* blenlib/BKE_curve.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_CURVE_H
#define BKE_CURVE_H
struct Curve;
struct ListBase;
struct Object;
struct Nurb;
struct ListBase;
struct BezTriple;
struct BevList;
int copyintoExtendedArray(float *old, int oldx, int oldy, float *newp, int newx, int newy);
void unlink_curve( struct Curve *cu);
void free_curve( struct Curve *cu);
struct Curve *add_curve(int type);
struct Curve *copy_curve( struct Curve *cu);
void make_local_curve( struct Curve *cu);
void test_curve_type( struct Object *ob);
void tex_space_curve( struct Curve *cu);
int count_curveverts( struct ListBase *nurb);
void freeNurb( struct Nurb *nu);
void freeNurblist( struct ListBase *lb);
struct Nurb *duplicateNurb( struct Nurb *nu);
void duplicateNurblist( struct ListBase *lb1, struct ListBase *lb2);
void test2DNurb( struct Nurb *nu);
void minmaxNurb( struct Nurb *nu, float *min, float *max);
void extend_spline(float * pnts, int in, int out);
void calcknots(float *knots, short aantal, short order, short type);
void makecyclicknots(float *knots, short pnts, short order);
void makeknots( struct Nurb *nu, short uv, short type);
void basisNurb(float t, short order, short pnts, float *knots, float *basis, int *start, int *end);
void makeNurbfaces( struct Nurb *nu, float *data);
void makeNurbcurve_forw(struct Nurb *nu, float *data);
void makeNurbcurve( struct Nurb *nu, float *data, int dim);
void maakbez(float q0, float q1, float q2, float q3, float *p, int it);
void make_orco_surf( struct Curve *cu);
void makebevelcurve( struct Object *ob, struct ListBase *disp);
short bevelinside(struct BevList *bl1,struct BevList *bl2);
int vergxcobev(const void *a1, const void *a2);
void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *sina, float *cosa);
void alfa_bezpart( struct BezTriple *prevbezt, struct BezTriple *bezt, struct Nurb *nu, float *data_a);
void makeBevelList( struct Object *ob);
void calchandleNurb( struct BezTriple *bezt, struct BezTriple *prev, struct BezTriple *next, int mode);
void calchandlesNurb( struct Nurb *nu);
void testhandlesNurb( struct Nurb *nu);
void autocalchandlesNurb( struct Nurb *nu, int flag);
void autocalchandlesNurb_all(int flag);
void sethandlesNurb(short code);
void swapdata(void *adr1, void *adr2, int len);
void switchdirectionNurb( struct Nurb *nu);
#endif

View File

@@ -0,0 +1,50 @@
/* BKE_deform.h June 2001
*
* support for deformation groups
*
* Reevan McKay
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_DEFORM_H
#define BKE_DEFORM_H
struct Object;
struct ListBase;
struct bDeformGroup;
void copy_defgroups (struct ListBase *lb1, struct ListBase *lb2);
struct bDeformGroup* copy_defgroup (struct bDeformGroup *ingroup);
void color_temperature (float input, unsigned char *r, unsigned char *g, unsigned char *b);
#endif

View File

@@ -0,0 +1,117 @@
/* display list (or rather multi purpose list) stuff */
/*
$Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_DISPLIST_H
#define BKE_DISPLIST_H
#define DL_POLY 0
#define DL_SEGM 1
#define DL_SURF 2
#define DL_TRIA 3
#define DL_INDEX3 4
#define DL_INDEX4 5
#define DL_VERTCOL 6
#define DL_VERTS 7
#define DL_NORS 8
#define DL_MESH 9
/* EVIL: #define DL_SURFINDEX(cyclu, cyclv, sizeu, sizev) */
/* prototypes */
struct Object;
struct Curve;
struct ListBase;
struct Material;
struct Bone;
struct TFace;
typedef struct DispListMesh DispListMesh;
struct DispListMesh {
int totvert, totface;
struct MVert *mvert;
struct MCol *mcol;
struct MFaceInt *mface;
struct TFace *tface;
};
/*
* All the different DispList.type's use the
* data in the displist structure in fairly
* different ways which can be rather confusing,
* the best thing to do would be to make a structure
* for each displaylist type that has the fields
* needed w/ proper names, and then make the actual
* DispList structure a typed union.
* - zr
*/
/* needs splitting! */
typedef struct DispList {
struct DispList *next, *prev;
short type, flag;
int parts, nr;
short col, rt; /* rt wordt gebruikt door initrenderNurbs */
float *verts, *nors;
int *index;
unsigned int *col1, *col2;
struct DispListMesh *mesh;
/* Begin NASTY_NLA_STUFF */
// int *offset, *run; /* Used to index into the bone & weight lists */
// struct Bone *bones;
// float *weights;
/* End NASTY_NLA_STUFF */
} DispList;
extern void copy_displist(struct ListBase *lbn, struct ListBase *lb);
extern void free_disp_elem(DispList *dl);
extern void free_displist_by_type(struct ListBase *lb, int type);
extern DispList *find_displist_create(struct ListBase *lb, int type);
extern DispList *find_displist(struct ListBase *lb, int type);
extern void addnormalsDispList(struct Object *ob, struct ListBase *lb);
extern void count_displist(struct ListBase *lb, int *totvert, int *totface);
extern void curve_to_filledpoly(struct Curve *cu, struct ListBase *dispbase);
extern void freedisplist(struct ListBase *lb);
extern void makeDispList(struct Object *ob);
extern void set_displist_onlyzero(int val);
extern void shadeDispList(struct Object *ob);
void freefastshade(void);
void boundbox_displist(struct Object *ob);
void imagestodisplist(void);
void reshadeall_displist(void);
void test_all_displists(void);
#endif

View File

@@ -0,0 +1,65 @@
/**
* blenlib/BKE_effect.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_EFFECT_H
#define BKE_EFFECT_H
struct Effect;
struct ListBase;
struct Object;
struct PartEff;
struct MTex;
struct Mesh;
struct WaveEff;
struct Particle;
struct Effect *add_effect(int type);
void free_effect(struct Effect *eff);
void free_effects(struct ListBase *lb);
struct Effect *copy_effect(struct Effect *eff);
void copy_act_effect(struct Object *ob);
void copy_effects(struct ListBase *lbn, struct ListBase *lb);
void deselectall_eff(struct Object *ob);
void set_buildvars(struct Object *ob, int *start, int *end);
struct Particle *new_particle(struct PartEff *paf);
struct PartEff *give_parteff(struct Object *ob);
void where_is_particle(struct PartEff *paf, struct Particle *pa, float ctime, float *vec);
void particle_tex(struct MTex *mtex, struct PartEff *paf, float *co, float *no);
void make_particle_keys(int depth, int nr, struct PartEff *paf, struct Particle *part, float *force, int deform, struct MTex *mtex);
void init_mv_jit(float *jit, int num);
void give_mesh_mvert(struct Mesh *me, int nr, float *co, short *no);
void build_particle_system(struct Object *ob);
void calc_wave_deform(struct WaveEff *wav, float ctime, float *co);
void object_wave(struct Object *ob);
#endif

View File

@@ -0,0 +1,46 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* Are we little or big endian? From Harbison&Steele.
* BKE_ENDIANNESS(a) returns 1 if big endian and returns 0 if little endian
*/
#ifndef BKE_ENDIAN_H
#define BKE_ENDIAN_H
#define BKE_ENDIANNESS(a) { \
union { \
long l; \
char c[sizeof (long)]; \
} u; \
u.l = 1; \
a = (u.c[sizeof (long) - 1] == 1) ? 1 : 0; \
}
#endif

View File

@@ -0,0 +1,54 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* dxf/vrml/videoscape external file io function prototypes
*/
#ifndef BKE_EXOTIC_H
#define BKE_EXOTIC_H
struct Mesh;
void mcol_to_rgba(unsigned int col, float *r, float *g, float *b, float *a);
unsigned int *mcol_to_vcol(struct Mesh *me); // used in py_main.c
/**
* Reads all 3D fileformats other than Blender fileformat
* @retval 0 The file could not be read.
* @retval 1 The file was read succesfully.
* @attention Used in filesel.c
*/
int BKE_read_exotic(char *name);
void write_dxf(char *str);
void write_vrml(char *str);
void write_videoscape(char *str);
#endif

View File

@@ -0,0 +1,50 @@
/**
* blenlib/BKE_vfont.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_VFONT_H
#define BKE_VFONT_H
struct VFont;
struct Object;
struct Curve;
struct objfnt;
void BKE_font_register_builtin(void *mem, int size);
void free_vfont(struct VFont *sc);
struct VFont *load_vfont(char *name);
struct chartrans *text_to_curve(struct Object *ob, int mode);
void font_duplilist(struct Object *par);
#endif

View File

@@ -0,0 +1,224 @@
/**
* blenlib/BKE_global.h (mar-2001 nzc)
*
* Global settings, handles, pointers. This is the root for finding
* any data in Blender. This block is not serialized, but built anew
* for every fresh Blender run.
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_GLOBAL_H
#define BKE_GLOBAL_H
#include "DNA_listBase.h"
#ifdef __cplusplus
extern "C" {
#endif
/* forwards */
struct View3D;
struct View2D;
struct SpaceIpo;
struct SpaceButs;
struct SpaceImage;
struct SpaceOops;
struct SpaceText;
struct SpaceSound;
struct SpaceAction;
struct SpaceNla;
struct Main;
struct Scene;
struct bScreen;
struct Object;
struct bSoundListener;
struct BMF_Font;
typedef struct Global {
/* active pointers */
struct View3D *vd;
struct View2D *v2d;
struct SpaceIpo *sipo;
struct SpaceButs *buts;
struct SpaceImage *sima;
struct SpaceOops *soops;
struct SpaceSound *ssound;
struct SpaceAction *saction; /* __NLA */
struct SpaceNla *snla;
struct Main *main;
struct Scene *scene; /* denk aan file.c */
struct bScreen *curscreen;
struct Object *obedit;
/* fonts, allocated global data */
struct BMF_Font *font, *fonts, *fontss;
/* strings: lastsaved */
char ima[160], sce[160], lib[160];
/* totalen */
short totobj, totlamp, totobjsel, totcurve, totmesh, totmat;
int totvert, totface, totvertsel, totfacesel;
short machine, afbreek, moving, colact, zbuf;
short qual, background, imagewin, animspeed;
/**
* The current version of Blender.
*/
short version;
short simulf, fields, order, rt;
int f;
/* Editmode lists */
struct ListBase edve;
struct ListBase eded;
struct ListBase edvl;
float textcurs[4][2];
/* Frank's variables */
int renderd;
int real_sfra, real_efra;
int save_over;
/* Reevan's __NLA variables */
struct Object *obpose; /* Current posable object */
struct ListBase edbo; /* Armature Editmode bones */
/* this variable is written to / read from FileGlobal->fileflags */
int fileflags;
/* Janco's playing ground */
struct bSoundListener* listener;
/* Test thingy for Nzc */
int magic; /* toggle use of experimental render pipe */
int compat; /* toggle compatibility mode for edge rendering */
int notonlysolid;/* T-> also edge-render transparent faces */
int useRscale; /* bitflag for using colour scaling */
int useGscale; /* bitflag for using colour scaling */
int useBscale; /* bitflag for using colour scaling */
float cscale[4]; /* sliders for colour scaling */
int Rhisto; /* flags for making histograms */
int Ghisto;
int Bhisto;
/* special versions */
short special1, special2;
int flags;
} Global;
/* **************** GLOBAL ********************* */
/* G.f */
#define G_DISABLE_OK 1
#define G_PLAYANIM 2
#define G_TEST_DUPLI 4
#define G_SIMULATION 8
#define G_BACKBUFSEL 16
#define G_PICKSEL 32
#define G_DRAWNORMALS 64
#define G_DRAWFACES 128
#define G_FACESELECT 256
#define G_DRAW_EXT 512
#define G_VERTEXPAINT 1024
#define G_ALLEDGES 2048
#define G_DEBUG 4096
#define G_SCENESCRIPT 8192
#define G_PROPORTIONAL 16384
#define G_WEIGHTPAINT 32768 /* __NLA */
#define G_TEXTUREPAINT 65536
#define G_NOFROZEN (1 << 17) // frozen modules inactive
/* G.fileflags */
#define G_AUTOPACK_BIT 0
#define G_FILE_COMPRESS_BIT 1
#define G_FILE_AUTOPLAY_BIT 2
#define G_FILE_ENABLE_ALL_FRAMES_BIT 3
#define G_FILE_SHOW_DEBUG_PROPS_BIT 4
#define G_FILE_SHOW_FRAMERATE_BIT 5
#define G_FILE_SHOW_PROFILE_BIT 6
#define G_FILE_LOCK_BIT 7
#define G_FILE_SIGN_BIT 8
#define G_FILE_PUBLISH_BIT 9
#define G_AUTOPACK (1 << G_AUTOPACK_BIT)
#define G_FILE_COMPRESS (1 << G_FILE_COMPRESS_BIT)
#define G_FILE_AUTOPLAY (1 << G_FILE_AUTOPLAY_BIT)
#define G_FILE_ENABLE_ALL_FRAMES (1 << G_FILE_ENABLE_ALL_FRAMES_BIT)
#define G_FILE_SHOW_DEBUG_PROPS (1 << G_FILE_SHOW_DEBUG_PROPS_BIT)
#define G_FILE_SHOW_FRAMERATE (1 << G_FILE_SHOW_FRAMERATE_BIT)
#define G_FILE_SHOW_PROFILE (1 << G_FILE_SHOW_PROFILE_BIT)
#define G_FILE_LOCK (1 << G_FILE_LOCK_BIT)
#define G_FILE_SIGN (1 << G_FILE_SIGN_BIT)
#define G_FILE_PUBLISH (1 << G_FILE_PUBLISH_BIT)
/* G.simulf */
#define G_LOADFILE 2
#define G_RESTART 4
#define G_QUIT 8
#define G_SETSCENE 16
/* G.flags: double? */
#define G_FLAGS_AUTOPLAY_BIT 2
#define G_FLAGS_AUTOPLAY (1 << G_FLAGS_AUTOPLAY_BIT)
/* G.qual */
#define R_SHIFTKEY 1
#define L_SHIFTKEY 2
#define LR_SHIFTKEY 3
#define R_ALTKEY 4
#define L_ALTKEY 8
#define LR_ALTKEY 12
#define R_CTRLKEY 16
#define L_CTRLKEY 32
#define LR_CTRLKEY 48
/* G.order: indicates what endianness the platform where the file was
* written had. */
#define L_ENDIAN 1
#define B_ENDIAN 0
/* G.special1 */
#define G_HOLO 1
/* Memory is allocated where? blender.c */
extern Global G;
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,58 @@
/**
* blenlib/BKE_group.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_GROUP_H
#define BKE_GROUP_H
struct Group;
struct GroupKey;
struct GroupObject;
struct ObjectKey;
struct Object;
void free_object_key(struct ObjectKey *ok);
void free_group_object(struct GroupObject *go);
void free_group(struct Group *group);
struct Group *add_group(void);
void object_to_obkey(struct Object *ob, struct ObjectKey *ok);
void obkey_to_object(struct ObjectKey *ok, struct Object *ob);
void add_object_key(struct GroupObject *go, struct GroupKey *gk);
void add_to_group(struct Group *group, struct Object *ob);
void rem_from_group(struct Group *group, struct Object *ob);
void add_group_key(struct Group *group);
void set_object_key(struct Object *ob, struct ObjectKey *ok);
void set_group_key(struct Group *group);
struct Group *find_group(struct Object *ob);
void set_group_key_name(struct Group *group, char *name);
void set_group_key_frame(struct Group *group, float frame);
#endif

View File

@@ -0,0 +1,59 @@
/**
* blenlib/BKE_ika.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_IKA_H
#define BKE_IKA_H
struct Ika;
struct Limb;
struct Object;
void unlink_ika(struct Ika *ika);
void free_ika(struct Ika *ika);
struct Ika *add_ika(void);
struct Ika *copy_ika(struct Ika *ika);
void make_local_ika(struct Ika *ika);
int count_limbs(struct Object *ob);
void calc_limb(struct Limb *li);
void calc_ika(struct Ika *ika, struct Limb *li);
void init_defstate_ika(struct Object *ob);
void itterate_limb(struct Ika *ika, struct Limb *li);
void rotate_ika(struct Object *ob, struct Ika *ika);
void rotate_ika_xy(struct Object *ob, struct Ika *ika);
void itterate_ika(struct Object *ob);
void do_all_ikas(void);
void do_all_visible_ikas(void);
void init_skel_deform(struct Object *par, struct Object *ob);
void calc_skel_deform(struct Ika *ika, float *co);
#endif

View File

@@ -0,0 +1,67 @@
/**
* blenlib/BKE_image.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_IMAGE_H
#define BKE_IMAGE_H
#ifdef __cplusplus
extern "C" {
#endif
struct Image;
struct ImBuf;
struct Tex;
struct anim;
void free_image(struct Image *me);
void free_image_buffers(struct Image *ima);
struct Image *add_image(char *name);
void free_unused_animimages(void);
void makepicstring(char *string, int frame);
struct anim *openanim(char * name, int flags);
int calcimanr(int cfra, struct Tex *tex);
void do_laseroptics_patch(struct ImBuf *ibuf);
void de_interlace_ng(struct ImBuf *ibuf);
void de_interlace_st(struct ImBuf *ibuf);
void load_image(struct Image * ima, int flags, char *relabase, int framenum);
void ima_ibuf_is_nul(struct Tex *tex);
int imagewrap(struct Tex *tex, float *texvec);
int imagewraposa(struct Tex *tex, float *texvec, float *dxt, float *dyt);
void converttopremul(struct ImBuf *ibuf);
void makemipmap(struct Image *ima);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,101 @@
/**
* blenlib/BKE_ipo.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_IPO_H
#define BKE_IPO_H
typedef struct CfraElem {
struct CfraElem *next, *prev;
float cfra;
int sel;
} CfraElem;
struct Ipo;
struct IpoCurve;
struct MTex;
struct Material;
struct Object;
struct Sequence;
struct ListBase;
struct BezTriple;
/* struct IPO_Channel; */
float frame_to_float(int cfra);
void free_ipo(struct Ipo *ipo);
struct Ipo *add_ipo(char *name, int idcode);
struct Ipo *copy_ipo(struct Ipo *ipo);
void make_local_obipo(struct Ipo *ipo);
void make_local_matipo(struct Ipo *ipo);
void make_local_keyipo(struct Ipo *ipo);
void make_local_ipo(struct Ipo *ipo);
void calchandles_ipocurve(struct IpoCurve *icu);
void testhandles_ipocurve(struct IpoCurve *icu);
void sort_time_ipocurve(struct IpoCurve *icu);
int test_time_ipocurve(struct IpoCurve *icu);
void correct_bezpart(float *v1, float *v2, float *v3, float *v4);
int findzero(float x, float q0, float q1, float q2, float q3, float *o);
void berekeny(float f1, float f2, float f3, float f4, float *o, int b);
void berekenx(float *f, float *o, int b);
float eval_icu(struct IpoCurve *icu, float ipotime);
void calc_icu(struct IpoCurve *icu, float ctime);
float calc_ipo_time(struct Ipo *ipo, float ctime);
void calc_ipo(struct Ipo *ipo, float ctime);
void write_ipo_poin(void *poin, int type, float val);
float read_ipo_poin(void *poin, int type);
void *give_mtex_poin(struct MTex *mtex, int adrcode );
void *get_ipo_poin(struct ID *id, struct IpoCurve *icu, int *type);
void set_icu_vars(struct IpoCurve *icu);
void execute_ipo(struct ID *id, struct Ipo *ipo);
void do_ipo_nocalc(struct Ipo *ipo);
void do_ipo(struct Ipo *ipo);
void do_mat_ipo(struct Material *ma);
void do_ob_ipo(struct Object *ob);
void do_seq_ipo(struct Sequence *seq);
int has_ipo_code(struct Ipo *ipo, int code);
void do_all_ipos(void);
int calc_ipo_spec(struct Ipo *ipo, int adrcode, float *ctime);
void clear_delta_obipo(struct Ipo *ipo);
void add_to_cfra_elem(struct ListBase *lb, struct BezTriple *bezt);
void make_cfra_list(struct Ipo *ipo, struct ListBase *elems);
/* the sort is an IPO_Channel... */
int IPO_GetChannels(struct Ipo *ipo, short *channels);
void test_ipo_get(void);
float IPO_GetFloatValue(struct Ipo *ipo,
/* struct IPO_Channel channel, */
/* channels are shorts... bit ugly for now*/
short c,
float ctime);
#endif

View File

@@ -0,0 +1,69 @@
/**
* blenlib/BKE_key.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_KEY_H
#define BKE_KEY_H
struct Key;
struct KeyBlock;
struct ID;
struct ListBase;
struct Curve;
struct Object;
struct Lattice;
struct Mesh;
void free_key(struct Key *sc);
struct Key *add_key(struct ID *id);
struct Key *copy_key(struct Key *key);
void make_local_key(struct Key *key);
void sort_keys(struct Key *key);
void set_four_ipo(float d, float *data, int type);
void set_afgeleide_four_ipo(float d, float *data, int type);
int setkeys(float fac, struct ListBase *lb, struct KeyBlock *k[], float *t, int cycl);
void flerp(int aantal, float *in, float *f0, float *f1, float *f2, float *f3, float *t);
void cp_key(int start, int end, int tot, char *poin, struct Key *key, struct KeyBlock *k, int mode);
void cp_cu_key(struct Curve *cu, struct KeyBlock *kb, int start, int end);
void rel_flerp(int aantal, float *in, float *ref, float *out, float fac);
void do_rel_key(int start, int end, int tot, char *basispoin, struct Key *key, float ctime, int mode);
void do_key(int start, int end, int tot, char *poin, struct Key *key, struct KeyBlock **k, float *t, int mode);
void do_mesh_key(struct Mesh *me);
void do_cu_key(struct Curve *cu, struct KeyBlock **k, float *t);
void do_rel_cu_key(struct Curve *cu, float ctime);
void do_curve_key(struct Curve *cu);
void do_latt_key(struct Lattice *lt);
void do_all_keys(void);
void do_ob_key(struct Object *ob);
void do_spec_key(struct Key *key);
#endif

View File

@@ -0,0 +1,59 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* june-2001 ton
*/
#ifndef BKE_LATTICE_H
#define BKE_LATTICE_H
struct Lattice;
struct Object;
struct BPoint;
extern struct Lattice *editLatt;
extern int lt_applyflag;
void resizelattice(struct Lattice *lt);
struct Lattice *add_lattice(void);
struct Lattice *copy_lattice(struct Lattice *lt);
void free_lattice(struct Lattice *lt);
void make_local_lattice(struct Lattice *lt);
void calc_lat_fudu(int flag, int res, float *fu, float *du);
void init_latt_deform(struct Object *oblatt, struct Object *ob);
void calc_latt_deform(float *co);
void end_latt_deform(void);
int object_deform(struct Object *ob);
struct BPoint *latt_bp(struct Lattice *lt, int u, int v, int w);
void outside_lattice(struct Lattice *lt);
#endif

View File

@@ -0,0 +1,69 @@
/**
* blenlib/BKE_library.h (mar-2001 nzc)
*
* Library
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_LIBRARY_TYPES_H
#define BKE_LIBRARY_TYPES_H
struct ListBase;
struct ID;
struct Main;
struct Library;
void *alloc_libblock(struct ListBase *lb, short type, char *name);
void *copy_libblock(void *rt);
void id_lib_extern(struct ID *id);
void id_us_plus(struct ID *id);
int new_id(struct ListBase *lb, struct ID *id, char *name);
struct ListBase *wich_libbase(struct Main *mainlib, short type);
int set_listbasepointers(struct Main *main, struct ListBase **lb);
void free_libblock(struct ListBase *lb, void *idv);
void free_libblock_us(struct ListBase *lb, void *idv);
void free_main(struct Main *mainvar);
void splitIDname(char *name, char *left, int *nr);
void rename_id(struct ID *id, char *name);
void test_idbutton(char *name);
void all_local(void);
struct ID *find_id(char *type, char *name);
void clear_id_newpoins(void);
void IDnames_to_pupstring(char **str, char *title, char *extraops, struct ListBase *lb,struct ID* link, short *nr);
void IPOnames_to_pupstring(char **str, char *title, char *extraops, struct ListBase *lb, struct ID* link, short *nr, int blocktype);
#endif

View File

@@ -0,0 +1,80 @@
/**
* blenlib/BKE_main.h (mar-2001 nzc)
*
* Main is the root of the 'database' of a Blender context. All data
* is stuffed into lists, and all these lists are knotted to here. A
* Blender file is not much more but a binary dump of these
* lists. This list of lists is not serialized itself.
*
* Oops... this should be a _types.h file.
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_MAIN_H
#define BKE_MAIN_H
#include "DNA_listBase.h"
struct Library;
typedef struct Main {
struct Main *next, *prev;
char name[160];
short versionfile, rt;
struct Library *curlib;
ListBase scene;
ListBase library;
ListBase object;
ListBase mesh;
ListBase curve;
ListBase mball;
ListBase mat;
ListBase tex;
ListBase image;
ListBase ika;
ListBase wave;
ListBase latt;
ListBase lamp;
ListBase camera;
ListBase ipo;
ListBase key;
ListBase world;
ListBase screen;
ListBase vfont;
ListBase text;
ListBase sound;
ListBase group;
ListBase armature; /* NLA */
ListBase action; /* NLA */
} Main;
#endif

View File

@@ -0,0 +1,68 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* General operations, lookup, etc. for materials.
*/
#ifndef BKE_MATERIAL_H
#define BKE_MATERIAL_H
#ifdef __cplusplus
extern "C" {
#endif
struct Material;
struct ID;
struct Object;
void free_material(struct Material *sc);
void test_object_materials(struct ID *id);
void init_material(struct Material *ma);
struct Material *add_material(char *name);
struct Material *copy_material(struct Material *ma);
void make_local_material(struct Material *ma);
struct Material ***give_matarar(struct Object *ob);
short *give_totcolp(struct Object *ob);
struct Material *give_current_material(struct Object *ob, int act);
ID *material_from(struct Object *ob, int act);
void assign_material(struct Object *ob, struct Material *ma, int act);
void new_material_to_objectdata(struct Object *ob);
void init_render_material(struct Material *ma);
void init_render_materials(void);
void end_render_material(struct Material *ma);
void end_render_materials(void);
void automatname(struct Material *ma);
void delete_material_index(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,64 @@
/**
* blenlib/BKE_mball.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_MBALL_H
#define BKE_MBALL_H
struct MetaBall;
struct Object;
struct MetaElem;
struct VERTICES;
struct VERTEX;
struct MB_POINT;
struct PROCESS;
struct CUBE;
struct PROCESS;
void unlink_mball(struct MetaBall *mb);
void free_mball(struct MetaBall *mb);
struct MetaBall *add_mball(void);
struct MetaBall *copy_mball(struct MetaBall *mb);
void make_local_mball(struct MetaBall *mb);
void tex_space_mball( struct Object *ob);
void make_orco_mball( struct Object *ob);
struct Object *find_basis_mball( struct Object *ob);
void metaball_polygonize(struct Object *ob);
void calc_mballco(struct MetaElem *ml, float *vec);
float densfunc(struct MetaElem *ball, float x, float y, float z);
float metaball(float x, float y, float z);
void accum_mballfaces(int i1, int i2, int i3, int i4);
void *new_pgn_element(int size);
int nextcwedge (int edge, int face);
void BKE_freecubetable(void);
#endif

View File

@@ -0,0 +1,116 @@
/**
* blenlib/BKE_mesh.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_MESH_H
#define BKE_MESH_H
/* texflag */
#define AUTOSPACE 1
/* me->flag (let op alternatieven in blendpsx.h) */
#define ME_ISDONE 1
#define ME_NOPUNOFLIP 2
#define ME_TWOSIDED 4
#define ME_UVEFFECT 8
#define ME_VCOLEFFECT 16
#define ME_AUTOSMOOTH 32
#define ME_SMESH 64
#define ME_SUBSURF 128
/* puno (mface) */
#define ME_FLIPV1 1
#define ME_FLIPV2 2
#define ME_FLIPV3 4
#define ME_FLIPV4 8
#define ME_PROJXY 16
#define ME_PROJXZ 32
#define ME_PROJYZ 64
/* edcode (mface) */
#define ME_V1V2 1
#define ME_V2V3 2
#define ME_V3V1 4
#define ME_V3V4 4
#define ME_V4V1 8
/* flag (mface) */
#define ME_SMOOTH 1
/***/
struct DispList;
struct ListBase;
struct MDeformVert;
struct Mesh;
struct MFace;
struct MVert;
struct Object;
struct TFace;
struct VecNor;
#ifdef __cplusplus
extern "C" {
#endif
void unlink_mesh(struct Mesh *me);
void free_mesh(struct Mesh *me);
struct Mesh *add_mesh(void);
struct Mesh *copy_mesh(struct Mesh *me);
void make_local_tface(struct Mesh *me);
void make_local_mesh(struct Mesh *me);
void boundbox_mesh(struct Mesh *me, float *loc, float *size);
void tex_space_mesh(struct Mesh *me);
void make_orco_displist_mesh(struct Object *ob, int subdivlvl);
void make_orco_mesh(struct Mesh *me);
void test_index_mface(struct MFace *mface, int nr);
void test_index_face(struct MFace *mface, struct TFace *tface, int nr);
void flipnorm_mesh(struct Mesh *me);
struct Mesh *get_mesh(struct Object *ob);
void set_mesh(struct Object *ob, struct Mesh *me);
void mball_to_mesh(struct ListBase *lb, struct Mesh *me);
void nurbs_to_mesh(struct Object *ob);
void edge_drawflags_mesh(struct Mesh *me);
void mcol_to_tface(struct Mesh *me, int freedata);
void tface_to_mcol(struct Mesh *me);
void free_dverts(struct MDeformVert *dvert, int totvert);
void copy_dverts(struct MDeformVert *dst, struct MDeformVert *src, int totvert); /* __NLA */
int mesh_uses_displist(struct Mesh *me);
int rendermesh_uses_displist(struct Mesh *me);
float get_mvert_weight (struct Object *ob, int vert, int defgroup);
int update_realtime_texture(struct TFace *tface, double time);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,46 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_NLA_H
#define BKE_NLA_H
struct bActionStrip;
struct ListBase;
void free_actionstrip(struct bActionStrip* strip);
void free_nlastrips (struct ListBase *nlalist);
void copy_nlastrips (struct ListBase *dst, struct ListBase *src);
void copy_actionstrip (struct bActionStrip **dst, struct bActionStrip **src);
#endif

View File

@@ -0,0 +1,99 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* General operations, lookup, etc. for blender objects.
*/
#ifndef BKE_OBJECT_H
#define BKE_OBJECT_H
#ifdef __cplusplus
extern "C" {
#endif
struct Base;
struct Object;
struct Camera;
struct BoundBox;
struct View3D;
void clear_workob(void);
void copy_baseflags(void);
void copy_objectflags(void);
void update_base_layer(struct Object *ob);
void free_object(struct Object *ob);
void unlink_object(struct Object *ob);
int exist_object(struct Object *obtest);
void *add_camera(void);
struct Camera *copy_camera(struct Camera *cam);
void make_local_camera(struct Camera *cam);
void *add_lamp(void);
struct Lamp *copy_lamp(struct Lamp *la);
void make_local_lamp(struct Lamp *la);
void free_camera(struct Camera *ca);
void free_lamp(struct Lamp *la);
void *add_wave(void);
struct Object *add_object(int type);
void base_init_from_view3d(struct Base *base, struct View3D *v3d);
struct Object *copy_object(struct Object *ob);
void expand_local_object(struct Object *ob);
void make_local_object(struct Object *ob);
void set_mblur_offs(int blur);
void disable_speed_curve(int val);
float bsystem_time(struct Object *ob, struct Object *par, float cfra, float ofs);
void object_to_mat3(struct Object *ob, float mat[][3]);
void object_to_mat4(struct Object *ob, float mat[][4]);
void ob_parcurve(struct Object *ob, struct Object *par, float mat[][4]);
void ob_parlimb(struct Object *ob, struct Object *par, float mat[][4]);
void ob_parbone(struct Object *ob, struct Object *par, float mat[][4]); /* __NLA */
void give_parvert(struct Object *par, int nr, float *vec);
void ob_parvert3(struct Object *ob, struct Object *par, float mat[][4]);
void set_no_parent_ipo(int val);
void set_dtime(int dtime);
void disable_where_script(short on);
int during_script(void);
void where_is_object_time(struct Object *ob, float ctime);
void where_is_object(struct Object *ob);
void where_is_object_simul(struct Object *ob);
void what_does_parent1(struct Object *par, int partype, int par1, int par2, int par3);
void what_does_parent(struct Object *ob);
struct BoundBox *unit_boundbox(void);
void minmax_object(struct Object *ob, float *min, float *max);
void solve_tracking (struct Object *ob, float targetmat[][4]);
void solve_constraints (struct Object *ob, short obtype, void *obdata, float ctime);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,53 @@
/**
* blenlib/BKE_osa_types.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_OSA_TYPES_H
#define BKE_OSA_TYPES_H
/* typedef struct Osa */
typedef struct RE_Osa
{
float dxco[3], dyco[3];
float dxlo[3], dylo[3], dxgl[3], dygl[3], dxuv[3], dyuv[3];
float dxref[3], dyref[3], dxorn[3], dyorn[3];
float dxno[3], dyno[3], dxview, dyview;
float dxlv[3], dylv[3];
float dxwin[3], dywin[3];
float dxsticky[3], dysticky[3];
} Osa;
/* extern Osa O; */
/* This one used to be done in render/extern/include/render.h, because
memory was allocated in that module. (nzc)*/
#endif

View File

@@ -0,0 +1,61 @@
/**
* blenlib/BKE_packedFile.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_PACKEDFILE_H
#define BKE_PACKEDFILE_H
struct PackedFile;
struct VFont;
struct bSample;
struct bSound;
struct Image;
struct PackedFile * newPackedFile(char * filename);
struct PackedFile * newPackedFileMemory(void *mem, int memlen);
int seekPackedFile(struct PackedFile * pf, int offset, int whence);
void rewindPackedFile(struct PackedFile * pf);
int readPackedFile(struct PackedFile * pf, void * data, int size);
int countPackedFiles(void);
void freePackedFile(struct PackedFile * pf);
void packAll(void);
int writePackedFile(char * filename, struct PackedFile *pf);
int checkPackedFile(char * filename, struct PackedFile * pf);
char * unpackFile(char * abs_name, char * local_name, struct PackedFile * pf, int how);
int unpackVFont(struct VFont * vfont, int how);
void create_local_name(char *localname, char *prefix, char *filename);
int unpackSample(struct bSample *sample, int how);
int unpackImage(struct Image * ima, int how);
void unpackAll(int how);
#endif

View File

@@ -0,0 +1,70 @@
/**
* blenlib/BKE_plugin_types.h (mar-2001 nzc)
*
* Renderrecipe and scene decription. The fact that there is a
* hierarchy here is a bit strange, and not desirable.
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_PLUGIN_TYPES_H
#define BKE_PLUGIN_TYPES_H
struct ImBuf;
typedef int (*TexDoit)(int, void*, float*, float*, float*);
typedef void (*SeqDoit)(void*, float, float, int, int,
struct ImBuf*, struct ImBuf*,
struct ImBuf*, struct ImBuf*);
typedef struct VarStruct {
int type;
char name[16];
float def, min, max;
char tip[80];
} VarStruct;
typedef struct _PluginInfo {
char *name;
char *snames;
int stypes;
int nvars;
VarStruct *varstr;
float *result;
float *cfra;
void (*init)(void);
void (*callback)(int);
TexDoit tex_doit;
SeqDoit seq_doit;
} PluginInfo;
#endif

View File

@@ -0,0 +1,54 @@
/**
* blenkernel/BKE_property.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_PROPERTY_H
#define BKE_PROPERTY_H
struct bProperty;
struct ListBase;
struct Object;
void free_property(struct bProperty *prop);
void free_properties(struct ListBase *lb);
struct bProperty *copy_property(struct bProperty *prop);
void copy_properties(struct ListBase *lbn, struct ListBase *lbo);
void init_property(struct bProperty *prop);
struct bProperty *new_property(int type);
struct bProperty *get_property(struct Object *ob, char *name);
int compare_property(struct bProperty *prop, char *str);
void set_property(struct bProperty *prop, char *str);
void add_property(struct bProperty *prop, char *str);
void set_property_valstr(struct bProperty *prop, char *str);
void cp_property(struct bProperty *prop1, struct bProperty *prop2);
#endif

View File

@@ -0,0 +1,74 @@
/**
* blenlib/BKE_sca.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_SCA_H
#define BKE_SCA_H
struct Text;
struct bSensor;
struct Object;
struct bController;
struct bActuator;
void unlink_controller(struct bController *cont);
void unlink_controllers(struct ListBase *lb);
void free_controller(struct bController *cont);
void free_controllers(struct ListBase *lb);
void unlink_actuator(struct bActuator *act);
void unlink_actuators(struct ListBase *lb);
void free_actuator(struct bActuator *act);
void free_actuators(struct ListBase *lb);
void free_text_controllers(struct Text *txt);
void free_sensor(struct bSensor *sens);
void free_sensors(struct ListBase *lb);
struct bSensor *copy_sensor(struct bSensor *sens);
void copy_sensors(struct ListBase *lbn, struct ListBase *lbo);
void init_sensor(struct bSensor *sens);
struct bSensor *new_sensor(int type);
struct bController *copy_controller(struct bController *cont);
void copy_controllers(struct ListBase *lbn, struct ListBase *lbo);
void init_controller(struct bController *cont);
struct bController *new_controller(int type);
struct bActuator *copy_actuator(struct bActuator *act);
void copy_actuators(struct ListBase *lbn, struct ListBase *lbo);
void init_actuator(struct bActuator *act);
struct bActuator *new_actuator(int type);
void clear_sca_new_poins_ob(struct Object *ob);
void clear_sca_new_poins(void);
void set_sca_new_poins_ob(struct Object *ob);
void set_sca_new_poins(void);
void sca_remove_ob_poin(struct Object *obt, struct Object *ob);
#endif

View File

@@ -0,0 +1,56 @@
/**
* blenlib/BKE_scene.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_SCENE_H
#define BKE_SCENE_H
struct Scene;
struct Object;
struct Base;
struct AviCodecData;
void free_avicodecdata(struct AviCodecData *acd);
void free_scene(struct Scene *me);
struct Scene *add_scene(char *name);
int object_in_scene(struct Object *ob, struct Scene *sce);
void sort_baselist(struct Scene *sce);
void set_scene_bg(struct Scene *sce);
void set_scene_name(char *name);
int next_object(int val, struct Base **base, struct Object **ob);
struct Object *scene_find_camera(struct Scene *sc);
struct Base *scene_add_base(struct Scene *sce, struct Object *ob);
void scene_deselect_all(struct Scene *sce);
void scene_select_base(struct Scene *sce, struct Base *selbase);
#endif

View File

@@ -0,0 +1,40 @@
/**
* blenlib/BKE_screen.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_SCREEN_H
#define BKE_SCREEN_H
void free_screen(struct bScreen *sc);
#endif

View File

@@ -0,0 +1,51 @@
/**
* sound.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_SOUND_H
#define BKE_SOUND_H
struct PackedFile;
struct bSound;
struct bSample;
struct ListBase;
extern struct ListBase *samples;
/* void *sound_get_listener(void); implemented in src!also declared there now */
void sound_set_packedfile(struct bSample* sample, struct PackedFile* pf);
struct PackedFile* sound_find_packedfile(struct bSound* sound);
void sound_free_sample(struct bSample* sample);
void sound_free_sound(struct bSound* sound);
#endif

View File

@@ -0,0 +1,43 @@
/* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_SUBSURF_H
#define BKE_SUBSURF_H
struct Mesh;
struct Object;
struct Displist;
void subsurf_to_mesh(struct Object *oldob, struct Mesh *newme);
void subsurf_make_mesh(struct Object *ob, short subdiv);
void subsurf_make_editmesh(struct Object *ob);
struct DispList* subsurf_mesh_to_displist(struct Mesh *me, struct DispList *dl, short subdiv);
#endif

View File

@@ -0,0 +1,128 @@
/**
* blenlib/BKE_text.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_TEXT_H
#define BKE_TEXT_H
#ifdef __cplusplus
extern "C" {
#endif
struct Text;
struct TextLine;
void free_text (struct Text *text);
void txt_set_undostate (int u);
int txt_get_undostate (void);
struct Text* add_empty_text (void);
int reopen_text (struct Text *text);
struct Text* add_text (char *file);
struct Text* copy_text (struct Text *ta);
void txt_free_cut_buffer (void);
char* txt_to_buf (struct Text *text);
void txt_clean_text (struct Text *text);
void txt_order_cursors (struct Text *text);
int txt_find_string (struct Text *text, char *findstr);
int txt_has_sel (struct Text *text);
int txt_get_span (struct TextLine *from, struct TextLine *to);
void txt_move_up (struct Text *text, short sel);
void txt_move_down (struct Text *text, short sel);
void txt_move_left (struct Text *text, short sel);
void txt_move_right (struct Text *text, short sel);
void txt_move_bof (struct Text *text, short sel);
void txt_move_eof (struct Text *text, short sel);
void txt_move_bol (struct Text *text, short sel);
void txt_move_eol (struct Text *text, short sel);
void txt_move_toline (struct Text *text, unsigned int line, short sel);
void txt_pop_sel (struct Text *text);
void txt_delete_char (struct Text *text);
void txt_copy_sel (struct Text *text);
void txt_sel_all (struct Text *text);
void txt_sel_line (struct Text *text);
void txt_print_cutbuffer (void);
void txt_cut_sel (struct Text *text);
char* txt_sel_to_buf (struct Text *text);
void txt_insert_buf (struct Text *text, char *in_buffer);
void txt_paste (struct Text *text);
void txt_print_undo (struct Text *text);
void txt_undo_add_toop (struct Text *text, int op, unsigned int froml, unsigned short fromc, unsigned int tol, unsigned short toc);
void txt_do_undo (struct Text *text);
void txt_do_redo (struct Text *text);
void txt_split_curline (struct Text *text);
void txt_backspace_char (struct Text *text);
int txt_add_char (struct Text *text, char add);
/* Undo opcodes */
/* Simple main cursor movement */
#define UNDO_CLEFT 001
#define UNDO_CRIGHT 002
#define UNDO_CUP 003
#define UNDO_CDOWN 004
/* Simple selection cursor movement */
#define UNDO_SLEFT 005
#define UNDO_SRIGHT 006
#define UNDO_SUP 007
#define UNDO_SDOWN 021
/* Complex movement (opcode is followed
* by 4 character line ID + a 2 character
* position ID and opcode (repeat)) */
#define UNDO_CTO 022
#define UNDO_STO 023
/* Complex editing (opcode is followed
* by 1 character ID and opcode (repeat)) */
#define UNDO_INSERT 024
#define UNDO_BS 025
#define UNDO_DEL 026
/* Text block (opcode is followed
* by 4 character length ID + the text
* block itself + the 4 character length
* ID (repeat) and opcode (repeat)) */
#define UNDO_DBLOCK 027 /* Delete block */
#define UNDO_IBLOCK 030 /* Insert block */
/* Misc */
#define UNDO_SWAP 031 /* Swap cursors */
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,85 @@
/**
* blenlib/BKE_texture.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_TEXTURE_H
#define BKE_TEXTURE_H
struct Tex;
struct MTex;
struct PluginTex;
struct LampRen;
struct ColorBand;
struct HaloRen;
/* in ColorBand struct */
#define MAXCOLORBAND 16
void free_texture(struct Tex *t);
int test_dlerr(const char *name, const char *symbol);
void open_plugin_tex(struct PluginTex *pit);
struct PluginTex *add_plugin_tex(char *str);
void free_plugin_tex(struct PluginTex *pit);
struct ColorBand *add_colorband(void);
int do_colorband(struct ColorBand *coba);
void default_tex(struct Tex *tex);
struct Tex *add_texture(char *name);
void default_mtex(struct MTex *mtex);
struct MTex *add_mtex(void);
struct Tex *copy_texture(struct Tex *tex);
void make_local_texture(struct Tex *tex);
void autotexname(struct Tex *tex);
void init_render_texture(struct Tex *tex);
void init_render_textures(void);
void end_render_texture(struct Tex *tex);
void end_render_textures(void);
int clouds(struct Tex *tex, float *texvec);
int blend(struct Tex *tex, float *texvec);
int wood(struct Tex *tex, float *texvec);
int marble(struct Tex *tex, float *texvec);
int magic(struct Tex *tex, float *texvec);
int stucci(struct Tex *tex, float *texvec);
int texnoise(struct Tex *tex);
int plugintex(struct Tex *tex, float *texvec, float *dxt, float *dyt);
void tubemap(float x, float y, float z, float *adr1, float *adr2);
void spheremap(float x, float y, float z, float *adr1, float *adr2);
void do_2d_mapping(struct MTex *mtex, float *t, float *dxt, float *dyt);
int multitex(struct Tex *tex, float *texvec, float *dxt, float *dyt);
void do_material_tex(void);
void do_halo_tex(struct HaloRen *har, float xn, float yn, float *colf);
void do_sky_tex(void);
void do_lamp_tex(struct LampRen *la, float *lavec);
void externtex(struct MTex *mtex, float *vec);
void externtexcol(struct MTex *mtex, float *orco, char *col);
void render_realtime_texture(void);
#endif

View File

@@ -0,0 +1,300 @@
/* util defines -- might go away ?*/
/*
$Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_UTILDEFINES_H
#define BKE_UTILDEFINES_H
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define ELEM(a, b, c) ( (a)==(b) || (a)==(c) )
#define ELEM3(a, b, c, d) ( ELEM(a, b, c) || (a)==(d) )
#define ELEM4(a, b, c, d, e) ( ELEM(a, b, c) || ELEM(a, d, e) )
#define ELEM5(a, b, c, d, e, f) ( ELEM(a, b, c) || ELEM3(a, d, e, f) )
#define ELEM6(a, b, c, d, e, f, g) ( ELEM(a, b, c) || ELEM4(a, d, e, f, g) )
#define ELEM7(a, b, c, d, e, f, g, h) ( ELEM3(a, b, c, d) || ELEM4(a, e, f, g, h) )
#define ELEM8(a, b, c, d, e, f, g, h, i) ( ELEM4(a, b, c, d, e) || ELEM4(a, f, g, h, i) )
/* string compare */
#define STREQ(str, a) ( strcmp((str), (a))==0 )
#define STREQ2(str, a, b) ( STREQ(str, a) || STREQ(str, b) )
#define STREQ3(str, a, b, c) ( STREQ2(str, a, b) || STREQ(str, c) )
/* min/max */
#define MIN2(x,y) ( (x)<(y) ? (x) : (y) )
#define MIN3(x,y,z) MIN2( MIN2((x),(y)) , (z) )
#define MIN4(x,y,z,a) MIN2( MIN2((x),(y)) , MIN2((z),(a)) )
#define MAX2(x,y) ( (x)>(y) ? (x) : (y) )
#define MAX3(x,y,z) MAX2( MAX2((x),(y)) , (z) )
#define MAX4(x,y,z,a) MAX2( MAX2((x),(y)) , MAX2((z),(a)) )
#define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; }
#define ABS(a) ( (a)<0 ? (-a) : (a) )
#define VECCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2);}
#define QUATCOPY(v1,v2) {*(v1)= *(v2); *(v1+1)= *(v2+1); *(v1+2)= *(v2+2); *(v1+3)= *(v2+3);}
#define INIT_MINMAX(min, max) (min)[0]= (min)[1]= (min)[2]= 1.0e30; (max)[0]= (max)[1]= (max)[2]= -1.0e30;
#define DO_MINMAX(vec, min, max) if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \
if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \
if( (min)[2]>(vec)[2] ) (min)[2]= (vec)[2]; \
if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1]; \
if( (max)[2]<(vec)[2] ) (max)[2]= (vec)[2]; \
#define DO_MINMAX2(vec, min, max) if( (min)[0]>(vec)[0] ) (min)[0]= (vec)[0]; \
if( (min)[1]>(vec)[1] ) (min)[1]= (vec)[1]; \
if( (max)[0]<(vec)[0] ) (max)[0]= (vec)[0]; \
if( (max)[1]<(vec)[1] ) (max)[1]= (vec)[1];
/* interferes elsewhere */
/* deze getallen ook invullen in blender.h SpaceFile: struct dna herkent geen defines */
#define FILE_MAXDIR 160
#define FILE_MAXFILE 80
/* some misc stuff.... */
#define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c)
#define KNOTSU(nu) ( (nu)->orderu+ (nu)->pntsu+ (nu->orderu-1)*((nu)->flagu & 1) )
#define KNOTSV(nu) ( (nu)->orderv+ (nu)->pntsv+ (nu->orderv-1)*((nu)->flagv & 1) )
/* this weirdo pops up in two places ... */
#if !defined(WIN32) && !defined(__BeOS)
#define O_BINARY 0
#endif
/* INTEGER CODES */
#if defined(__sgi) || defined (__sparc) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__)
/* Big Endian */
#define MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) )
#else
/* Little Endian */
#define MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) )
#endif
#define ID_NEW(a) if( (a) && (a)->id.newid ) (a)= (void *)(a)->id.newid
#define FORM MAKE_ID('F','O','R','M')
#define DDG1 MAKE_ID('3','D','G','1')
#define DDG2 MAKE_ID('3','D','G','2')
#define DDG3 MAKE_ID('3','D','G','3')
#define DDG4 MAKE_ID('3','D','G','4')
#define GOUR MAKE_ID('G','O','U','R')
#define BLEN MAKE_ID('B','L','E','N')
#define DER_ MAKE_ID('D','E','R','_')
#define V100 MAKE_ID('V','1','0','0')
#define DATA MAKE_ID('D','A','T','A')
#define GLOB MAKE_ID('G','L','O','B')
#define IMAG MAKE_ID('I','M','A','G')
#define DNA1 MAKE_ID('D','N','A','1')
#define TEST MAKE_ID('T','E','S','T')
#define REND MAKE_ID('R','E','N','D')
#define USER MAKE_ID('U','S','E','R')
#define ENDB MAKE_ID('E','N','D','B')
/* This should, of course, become a function */
#define DL_SURFINDEX(cyclu, cyclv, sizeu, sizev) \
\
if( (cyclv)==0 && a==(sizev)-1) break; \
if(cyclu) { \
p1= sizeu*a; \
p2= p1+ sizeu-1; \
p3= p1+ sizeu; \
p4= p2+ sizeu; \
b= 0; \
} \
else { \
p2= sizeu*a; \
p1= p2+1; \
p4= p2+ sizeu; \
p3= p1+ sizeu; \
b= 1; \
} \
if( (cyclv) && a==sizev-1) { \
p3-= sizeu*sizev; \
p4-= sizeu*sizev; \
}
/* This one rotates the bytes in an int */
#define SWITCH_INT(a) { \
char s_i, *p_i; \
p_i= (char *)&(a); \
s_i=p_i[0]; p_i[0]=p_i[3]; p_i[3]=s_i; \
s_i=p_i[1]; p_i[1]=p_i[2]; p_i[2]=s_i; }
/* More brain damage. Only really used by packedFile.c */
// return values
#define RET_OK 0
#define RET_ERROR 1
/* and these aren't used at all */
/* #define RET_CANCEL 2 */
/* #define RET_YES (1 == 1) */
/* #define RET_NO (1 == 0) */
/* sequence related defines */
#define WHILE_SEQ(base) { \
int totseq_, seq_; Sequence **seqar; \
build_seqar( base, &seqar, &totseq_); \
for(seq_ = 0; seq_ < totseq_; seq_++) { \
seq= seqar[seq_];
#define END_SEQ } \
if(seqar) MEM_freeN(seqar); \
}
/* not really sure about these... some kind of event codes ?*/
/* INFO: 300 */
/* pas op: ook in filesel.c en editobject.c */
#define B_INFOSCR 301
#define B_INFODELSCR 302
#define B_INFOSCE 304
#define B_INFODELSCE 305
#define B_FILEMENU 306
#define B_PACKFILE 307
/* From iff.h, but seemingly detached from anything else... To which
* encoding scheme do they belong? */
#define AMI (1 << 31)
#define CDI (1 << 30)
#define Anim (1 << 29)
#define TGA (1 << 28)
#define JPG (1 << 27)
#define TIM (1 << 26)
#define TIM_CLUT (010)
#define TIM_4 (TIM | TIM_CLUT | 0)
#define TIM_8 (TIM | TIM_CLUT | 1)
#define TIM_16 (TIM | 2)
#define TIM_24 (TIM | 3)
#define RAWTGA (TGA | 1)
#define JPG_STD (JPG | (0 << 8))
#define JPG_VID (JPG | (1 << 8))
#define JPG_JST (JPG | (2 << 8))
#define JPG_MAX (JPG | (3 << 8))
#define JPG_MSK (0xffffff00)
#define AM_ham (0x0800 | AMI)
#define AM_hbrite (0x0080 | AMI)
#define AM_lace (0x0004 | AMI)
#define AM_hires (0x8000 | AMI)
#define AM_hblace (AM_hbrite | AM_lace)
#define AM_hilace (AM_hires | AM_lace)
#define AM_hamlace (AM_ham | AM_lace)
#define RGB888 1
#define RGB555 2
#define DYUV 3
#define CLUT8 4
#define CLUT7 5
#define CLUT4 6
#define CLUT3 7
#define RL7 8
#define RL3 9
#define MPLTE 10
#define DYUV1 0
#define DYUVE 1
#define CD_rgb8 (RGB888 | CDI)
#define CD_rgb5 (RGB555 | CDI)
#define CD_dyuv (DYUV | CDI)
#define CD_clut8 (CLUT8 | CDI)
#define CD_clut7 (CLUT7 | CDI)
#define CD_clut4 (CLUT4 | CDI)
#define CD_clut3 (CLUT3 | CDI)
#define CD_rl7 (RL7 | CDI)
#define CD_rl3 (RL3 | CDI)
#define CD_mplte (MPLTE | CDI)
#define C233 1
#define YUVX 2
#define HAMX 3
#define TANX 4
#define AN_c233 (Anim | C233)
#define AN_yuvx (Anim | YUVX)
#define AN_hamx (Anim | HAMX)
#define AN_tanx (Anim | TANX)
#define IMAGIC 0732
/* This used to reside in render.h. It does some texturing. */
#define BRICON Tin= (Tin-0.5)*tex->contrast+tex->bright-0.5; \
if(Tin<0.0) Tin= 0.0; else if(Tin>1.0) Tin= 1.0;
#define BRICONRGB Tr= tex->rfac*((Tr-0.5)*tex->contrast+tex->bright-0.5); \
if(Tr<0.0) Tr= 0.0; else if(Tr>1.0) Tr= 1.0; \
Tg= tex->gfac*((Tg-0.5)*tex->contrast+tex->bright-0.5); \
if(Tg<0.0) Tg= 0.0; else if(Tg>1.0) Tg= 1.0; \
Tb= tex->bfac*((Tb-0.5)*tex->contrast+tex->bright-0.5); \
if(Tb<0.0) Tb= 0.0; else if(Tb>1.0) Tb= 1.0;
/* mystifying stuff from blendef... */
#define SELECT 1
#define ACTIVE 2
#define NOT_YET 0
/* ???? */
#define BTST(a,b) ( ( (a) & 1<<(b) )!=0 )
#define BSET(a,b) ( (a) | 1<<(b) )
/* needed for material.c*/
#define REDRAWBUTSMAT 0x4015
/* useless game shit */
#define MA_FH_NOR 2
#endif

View File

@@ -0,0 +1,45 @@
/**
* blenlib/BKE_world.h (mar-2001 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_WORLD_H
#define BKE_WORLD_H
struct World;
void free_world(struct World *sc);
struct World *add_world(char *name);
struct World *copy_world(struct World *wrld);
void make_local_world(struct World *wrld);
void init_render_world(void);
#endif

View File

@@ -0,0 +1,50 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef BKE_WRITEAVI_H
#define BKE_WRITEAVI_H
#ifdef __cplusplus
extern "C" {
#endif
void start_avi(void);
void end_avi(void);
void append_avi(int frame);
void makeavistring(char *string);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,37 @@
#
# $Id$
#
# ***** 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.
#
# The Original Code is: all of this file.
#
# Contributor(s): none yet.
#
# ***** END GPL/BL DUAL LICENSE BLOCK *****
#
# Bounces make to subdirectories.
SOURCEDIR = source/blender/blenkernel
DIRS = intern bad_level_call_stubs
include nan_subdirs.mk

View File

@@ -0,0 +1,55 @@
#
# $Id$
#
# ***** 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.
#
# The Original Code is: all of this file.
#
# Contributor(s): none yet.
#
# ***** END GPL/BL DUAL LICENSE BLOCK *****
#
#
LIBNAME = blenkernel_blc
DIR = $(OCGDIR)/blender/blenkernel/$(LIBNAME)
include nan_compile.mk
CFLAGS += $(LEVEL_2_C_WARNINGS)
CFLAGS += $(FIX_STUBS_WARNINGS)
ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd linux openbsd solaris windows"))
CFLAGS += -funsigned-char
endif
CPPFLAGS += $(OGL_CPPFLAGS)
CPPFLAGS += -I../../makesdna
CPPFLAGS += -I../../include
CPPFLAGS += -I../../blenlib
CPPFLAGS += -I../../render/extern/include
CPPFLAGS += -I$(NAN_IKSOLVER)/include
# path to our own external headerfiles
CPPFLAGS += -I..

View File

@@ -0,0 +1,180 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* BKE_bad_level_calls function stubs
*/
#include "BLI_blenlib.h"
#include "DNA_material_types.h"
#include "BKE_bad_level_calls.h"
int winqueue_break= 0;
/* readfile.c */
/* struct PluginSeq; */
void open_plugin_seq(struct PluginSeq *pis, char *seqname){}
/* struct SpaceButs; */
void set_rects_butspace(struct SpaceButs *buts){}
/* struct SpaceImaSel; */
void check_imasel_copy(struct SpaceImaSel *simasel){}
/* struct ScrArea; */
void unlink_screen(struct bScreen *sc){}
void freeAllRad(void){}
void free_editText(void){}
void free_editArmature(void){}
void setscreen(struct bScreen *sc){}
void force_draw_all(void){}
/* otherwise the WHILE_SEQ doesn't work */
/* struct Sequence; */
/* MAART: added "seqar = 0; totseq = 0" because the loader will crash without it. */
void build_seqar(ListBase *seqbase, struct Sequence ***seqar, int *totseq)
{
*seqar = 0;
*totseq = 0;
}
void BPY_do_pyscript(ID *id, short int event){}
void BPY_free_compiled_text(struct Text *text) {};
/* writefile.c */
/* struct Oops; */
void free_oops(struct Oops *oops){}
void exit_posemode(int freedata){}
void error(char *str, ...){}
/* anim.c */
ListBase editNurb;
/* displist.c */
#include "DNA_world_types.h" /* for render_types */
#include "render_types.h"
struct RE_Render R;
float RE_Spec(float inp, int hard){}
void waitcursor(int val){}
void allqueue(unsigned short event, short val){}
#define REDRAWVIEW3D 0x4010
Material defmaterial;
/* effect.c */
void RE_jitterate1(float *jit1, float *jit2, int num, float rad1){}
void RE_jitterate2(float *jit1, float *jit2, int num, float rad2){}
/* exotic.c */
void load_editMesh(void){}
void make_editMesh(void){}
void free_editMesh(void){}
void docentre_new(void){}
int saveover(char *str){}
/* image.c */
#include "DNA_image_types.h"
void free_realtime_image(Image *ima){} // has to become a callback, opengl stuff
void RE_make_existing_file(char *name){} // from render, but these funcs should be moved anyway
/* ipo.c */
void copy_view3d_lock(short val){} // was a hack, to make scene layer ipo's possible
/* library.c */
void allspace(unsigned short event, short val){}
#define OOPS_TEST 2
/* mball.c */
ListBase editelems;
/* object.c */
void BPY_free_scriptlink(ScriptLink *slink){}
void BPY_copy_scriptlink(ScriptLink *scriptlink){}
float *give_cursor(void){} // become a callback or argument
/* packedFile.c */
short pupmenu(char *instr){} // will be general callback
/* sca.c */
#define LEFTMOUSE 0x001 // because of mouse sensor
/* scene.c */
#include "DNA_sequence_types.h"
void free_editing(struct Editing *ed){} // scenes and sequences problem...
void BPY_do_all_scripts (short int event){}
/* IKsolver stubs */
#include "IK_solver.h"
extern int IK_LoadChain(IK_Chain_ExternPtr chain,IK_Segment_ExternPtr segments, int num_segs)
{
return 0;
}
extern int IK_SolveChain(
IK_Chain_ExternPtr chain,
float goal[3],
float tolerance,
int max_iterations,
float max_angle_change,
IK_Segment_ExternPtr output
)
{
return 0;
}
extern void IK_FreeChain(IK_Chain_ExternPtr chain)
{
;
}
extern IK_Chain_ExternPtr IK_CreateChain(void)
{
return 0;
}
/* texture.c */
#define FLO 128
#define INT 96
/* struct EnvMap; */
/* struct Tex; */
void RE_free_envmap(struct EnvMap *env){}
struct EnvMap *RE_copy_envmap(struct EnvMap *env){}
void RE_free_envmapdata(struct EnvMap *env){}
int RE_envmaptex(struct Tex *tex, float *texvec, float *dxt, float *dyt){}
void RE_calc_R_ref(void){}
char texstr[15][8]; /* buttons.c */
Osa O;
/* editsca.c */
void make_unique_prop_names(char *str) {}

View File

@@ -0,0 +1,74 @@
#
# $Id$
#
# ***** 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.
#
# The Original Code is: all of this file.
#
# Contributor(s): none yet.
#
# ***** END GPL/BL DUAL LICENSE BLOCK *****
#
#
LIBNAME = blenkernel
DIR = $(OCGDIR)/blender/$(LIBNAME)
include nan_compile.mk
ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd openbsd linux solaris windows"))
CFLAGS += -funsigned-char
endif
CFLAGS += $(LEVEL_1_C_WARNINGS)
# OpenGL and Python
CPPFLAGS += -I$(OPENGL_HEADERS)
CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
# Reference to the types in makesdna and imbuf
CPPFLAGS += -I../../makesdna
CPPFLAGS += -I../../imbuf
# This mod uses the BLI and BLO module
CPPFLAGS += -I../../blenlib
CPPFLAGS += -I../../blenloader
CPPFLAGS += -I../../bpython/include
# also avi is used
CPPFLAGS += -I../../avi
CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include
# we still refer to /include a bit...
CPPFLAGS += -I../../include
# to include the render stuff:
CPPFLAGS += -I../../render/extern/include
# for sound
#CPPFLAGS += -I../../../kernel/gen_system
CPPFLAGS += -I$(NAN_IKSOLVER)/include
# path to our own external headerfiles
CPPFLAGS += -I..

View File

@@ -0,0 +1,873 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <string.h>
#include <math.h>
#include <stdlib.h> /* for NULL */
#include "MEM_guardedalloc.h"
#include "BLI_arithb.h"
#include "BLI_blenlib.h"
#include "BKE_action.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_utildefines.h"
#include "DNA_object_types.h"
#include "DNA_ipo_types.h"
#include "DNA_curve_types.h"
#include "DNA_scene_types.h"
#include "DNA_action_types.h"
#include "DNA_nla_types.h"
#include "BKE_blender.h"
#include "BKE_ipo.h"
#include "BKE_object.h"
#include "BKE_library.h"
#include "BKE_anim.h"
#include "BKE_armature.h"
#include "nla.h"
#include "BKE_constraint.h"
#include "DNA_constraint_types.h"
/* Local function prototypes */
static
void
do_pose_constraint_channels(
bPose *pose,
bAction *act,
float ctime
);
static
void
get_constraint_influence_from_pose (
bPose *dst,
bPose *src
);
static
void
blend_constraints(
ListBase *dst,
const ListBase *src,
float srcweight,
short mode
);
static
void
rest_pose (
bPose *pose,
int clearflag
);
/* Implementation */
bPoseChannel *
get_pose_channel (
const bPose *pose,
const char *name
){
bPoseChannel *chan;
for (chan=pose->chanbase.first; chan; chan=chan->next){
if (!strcmp (chan->name, name))
return chan;
}
return NULL;
}
static
void
rest_pose (
bPose *pose,
int clearflag
){
bPoseChannel *chan;
int i;
if (!pose)
return;
for (chan=pose->chanbase.first; chan; chan=chan->next){
for (i=0; i<3; i++){
chan->loc[i]=0.0;
chan->quat[i+1]=0.0;
chan->size[i]=1.0;
}
chan->quat[0]=1.0;
if (clearflag)
chan->flag =0;
}
}
static
void
blend_constraints(
ListBase *dst,
const ListBase *src,
float srcweight,
short mode
){
bConstraint *dcon;
const bConstraint *scon;
float dstweight;
switch (mode){
case POSE_BLEND:
dstweight = 1.0F - srcweight;
break;
case POSE_ADD:
dstweight = 1.0F;
break;
}
/* Blend constraints */
for (dcon=dst->first; dcon; dcon=dcon->next){
for (scon = src->first; scon; scon=scon->next){
if (!strcmp(scon->name, dcon->name))
break;
}
if (scon){
dcon->enforce = (dcon->enforce*dstweight) + (scon->enforce*srcweight);
if (mode == POSE_BLEND)
dcon->enforce/=2.0;
if (dcon->enforce>1.0)
dcon->enforce=1.0;
if (dcon->enforce<0.0)
dcon->enforce=0.0;
}
}
}
void
blend_poses (
bPose *dst,
const bPose *src,
float srcweight,
short mode
){
bPoseChannel *dchan;
const bPoseChannel *schan;
float dquat[4], squat[4], mat[3][3];
float dstweight;
int i;
switch (mode){
case POSE_BLEND:
dstweight = 1.0F - srcweight;
break;
case POSE_ADD:
dstweight = 1.0F;
break;
default :
dstweight = 1.0F;
}
for (dchan = dst->chanbase.first; dchan; dchan=dchan->next){
schan = get_pose_channel(src, dchan->name);
if (schan){
if (schan->flag & (POSE_ROT|POSE_LOC|POSE_SIZE)){
/* Convert both quats to matrices and then back again.
* This prevents interpolation problems
* This sucks because it is slow and stupid
*/
QuatToMat3(dchan->quat, mat);
Mat3ToQuat(mat, dquat);
QuatToMat3(schan->quat, mat);
Mat3ToQuat(mat, squat);
/* Do the transformation blend */
for (i=0; i<3; i++){
if (schan->flag & POSE_LOC)
dchan->loc[i] = (dchan->loc[i]*dstweight) + (schan->loc[i]*srcweight);
if (schan->flag & POSE_SIZE)
dchan->size[i] = 1.0f + ((dchan->size[i]-1.0f)*dstweight) + ((schan->size[i]-1.0f)*srcweight);
if (schan->flag & POSE_ROT)
dchan->quat[i+1] = (dquat[i+1]*dstweight) + (squat[i+1]*srcweight);
}
/* Do one more iteration for the quaternions only and normalize the quaternion if needed */
if (schan->flag & POSE_ROT)
dchan->quat[0] = 1.0f + ((dquat[0]-1.0f)*dstweight) + ((squat[0]-1.0f)*srcweight);
if (mode==POSE_BLEND)
NormalQuat (dchan->quat);
dchan->flag |= schan->flag;
}
}
}
}
void
clear_pose_constraint_status (
Object *ob
){
bPoseChannel *chan;
if (!ob)
return;
if (!ob->pose)
return;
for (chan = ob->pose->chanbase.first; chan; chan=chan->next){
chan->flag &= ~PCHAN_DONE;
}
}
float
calc_action_start (
const bAction *act
){
const bActionChannel *chan;
const IpoCurve *icu;
float size=999999999.0f;
int i;
int foundvert=0;
const bConstraintChannel *conchan;
if (!act)
return 0;
for (chan=act->chanbase.first; chan; chan=chan->next){
for (icu=chan->ipo->curve.first; icu; icu=icu->next)
for (i=0; i<icu->totvert; i++){
size = MIN2 (size, icu->bezt[i].vec[1][0]);
foundvert=1;
}
for (conchan=chan->constraintChannels.first; conchan; conchan=conchan->next){
for (icu=conchan->ipo->curve.first; icu; icu=icu->next)
for (i=0; i<icu->totvert; i++){
size = MIN2 (size, icu->bezt[i].vec[1][0]);
foundvert=1;
}
}
}
if (!foundvert)
return 0;
else
return size;
}
float
calc_action_end (
const bAction *act
){
const bActionChannel *chan;
const bConstraintChannel *conchan;
const IpoCurve *icu;
float size=0;
int i;
if (!act)
return 0;
for (chan=act->chanbase.first; chan; chan=chan->next){
for (icu=chan->ipo->curve.first; icu; icu=icu->next)
for (i=0; i<icu->totvert; i++)
size = MAX2 (size, icu->bezt[i].vec[1][0]);
for (conchan=chan->constraintChannels.first; conchan; conchan=conchan->next){
for (icu=conchan->ipo->curve.first; icu; icu=icu->next)
for (i=0; i<icu->totvert; i++)
size = MAX2 (size, icu->bezt[i].vec[1][0]);
}
}
return size;
}
void
verify_pose_channel (
bPose* pose,
const char* name
) {
bPoseChannel *chan;
if (!pose){
return;
}
/* See if this channel exists */
for (chan=pose->chanbase.first; chan; chan=chan->next){
if (!strcmp (name, chan->name))
return;
}
/* If not, create it and add it */
chan = MEM_callocN(sizeof(bPoseChannel), "verifyPoseChannel");
strcpy (chan->name, name);
chan->loc[0] = chan->loc[1] = chan->loc[2] = 0.0F;
chan->quat[1] = chan->quat[2] = chan->quat[3] = 0.0F; chan->quat[0] = 1.0F;
chan->size[0] = chan->size[1] = chan->size[2] = 1.0F;
chan->flag |= POSE_ROT|POSE_SIZE|POSE_LOC;
BLI_addtail (&pose->chanbase, chan);
}
void
get_pose_from_pose (
bPose **pose,
const bPose *src
){
const bPoseChannel *pchan;
bPoseChannel *newchan;
if (!src)
return;
if (!pose)
return;
/* If there is no pose, create one */
if (!*pose){
*pose=MEM_callocN (sizeof(bPose), "pose");
}
/* Copy the data from the action into the pose */
for (pchan=src->chanbase.first; pchan; pchan=pchan->next){
newchan = copy_pose_channel(pchan);
verify_pose_channel(*pose, pchan->name);
set_pose_channel(*pose, newchan);
}
}
static void get_constraint_influence_from_pose (bPose *dst, bPose *src)
{
bConstraint *dcon, *scon;
if (!src || !dst)
return;
for (dcon = dst->chanbase.first; dcon; dcon=dcon->next){
for (scon=src->chanbase.first; scon; scon=scon->next){
if (!strcmp(scon->name, dcon->name))
break;
}
if (scon){
dcon->enforce = scon->enforce;
}
}
}
/* If the pose does not exist, a new one is created */
void
get_pose_from_action (
bPose **pose,
bAction *act,
float ctime
) {
bActionChannel *achan;
bPoseChannel *pchan;
Ipo *ipo;
IpoCurve *curve;
if (!act)
return;
if (!pose)
return;
/* If there is no pose, create one */
if (!*pose){
*pose=MEM_callocN (sizeof(bPose), "pose");
}
/* Copy the data from the action into the pose */
for (achan=act->chanbase.first; achan; achan=achan->next){
act->achan= achan;
ipo = achan->ipo;
if (ipo){
pchan=MEM_callocN (sizeof(bPoseChannel), "gpfa_poseChannel");
strcpy (pchan->name, achan->name);
act->pchan=pchan;
/* Evaluates and sets the internal ipo value */
calc_ipo(ipo, ctime);
/* Set the pchan flags */
for (curve = achan->ipo->curve.first; curve; curve=curve->next){
/* Skip empty curves */
if (!curve->totvert)
continue;
switch (curve->adrcode){
case AC_QUAT_X:
case AC_QUAT_Y:
case AC_QUAT_Z:
case AC_QUAT_W:
pchan->flag |= POSE_ROT;
break;
case AC_LOC_X:
case AC_LOC_Y:
case AC_LOC_Z:
pchan->flag |= POSE_LOC;
break;
case AC_SIZE_X:
case AC_SIZE_Y:
case AC_SIZE_Z:
pchan->flag |= POSE_SIZE;
break;
}
}
execute_ipo((ID*)act, achan->ipo);
set_pose_channel(*pose, pchan);
}
}
}
void
do_all_actions(
){
Base *base;
bPose *apose=NULL;
bPose *tpose=NULL;
Object *ob;
bActionStrip *strip;
int doit;
float striptime, frametime, length, actlength;
float blendfac, stripframe;
int set;
/* NEW: current scene ob ipo's */
base= G.scene->base.first;
set= 0;
while(base) {
ob = base->object;
/* Retrieve data from the NLA */
if(ob->type==OB_ARMATURE){
doit=0;
/* Clear pose */
if (apose){
clear_pose(apose);
MEM_freeN(apose);
}
/* Clear pose */
if (tpose){
clear_pose(tpose);
MEM_freeN(tpose);
}
copy_pose(&apose, ob->pose, 1);
copy_pose(&tpose, ob->pose, 1);
rest_pose(apose, 1);
if (base->object->nlastrips.first){
rest_pose(base->object->pose, 0);
}
for (strip=base->object->nlastrips.first; strip; strip=strip->next){
doit = 0;
if (strip->act){
/* Determine if the current frame is within the strip's range */
length = strip->end-strip->start;
actlength = strip->actend-strip->actstart;
striptime = (G.scene->r.cfra-(strip->start)) / length;
stripframe = (G.scene->r.cfra-(strip->start)) ;
if (striptime>=0.0){
rest_pose(tpose, 1);
/* Handle path */
if (strip->flag & ACTSTRIP_USESTRIDE){
if (ob->parent && ob->parent->type==OB_CURVE){
Curve *cu = ob->parent->data;
float ctime, pdist;
if (cu->flag & CU_PATH){
/* Ensure we have a valid path */
if(cu->path==0 || cu->path->data==0) calc_curvepath(ob->parent);
/* Find the position on the path */
ctime= bsystem_time(ob, ob->parent, (float)G.scene->r.cfra, 0.0);
if(calc_ipo_spec(cu->ipo, CU_SPEED, &ctime)==0) {
ctime /= cu->pathlen;
CLAMP(ctime, 0.0, 1.0);
}
pdist = ctime*cu->path->totdist;
if (strip->stridelen)
striptime = pdist / strip->stridelen;
else
striptime = 0;
striptime = (float)fmod (striptime, 1.0);
frametime = (striptime * actlength) + strip->actstart;
get_pose_from_action (&tpose, strip->act, bsystem_time(ob, 0, frametime, 0.0));
#ifdef __NLA_BLENDCON
do_pose_constraint_channels(tpose, strip->act, bsystem_time(ob, 0, frametime, 0.0));
#endif
doit=1;
}
}
}
/* Handle repeat */
else if (striptime < 1.0){
/* Mod to repeat */
striptime*=strip->repeat;
striptime = (float)fmod (striptime, 1.0);
frametime = (striptime * actlength) + strip->actstart;
get_pose_from_action (&tpose, strip->act, bsystem_time(ob, 0, frametime, 0.0));
#ifdef __NLA_BLENDCON
do_pose_constraint_channels(tpose, strip->act, bsystem_time(ob, 0, frametime, 0.0));
#endif
doit=1;
}
/* Handle extend */
else{
if (strip->flag & ACTSTRIP_HOLDLASTFRAME){
striptime = 1.0;
frametime = (striptime * actlength) + strip->actstart;
get_pose_from_action (&tpose, strip->act, bsystem_time(ob, 0, frametime, 0.0));
#ifdef __NLA_BLENDCON
do_pose_constraint_channels(tpose, strip->act, bsystem_time(ob, 0, frametime, 0.0));
#endif
doit=1;
}
}
/* Handle blendin & blendout */
if (doit){
/* Handle blendin */
if (strip->blendin>0.0 && stripframe<=strip->blendin && G.scene->r.cfra>=strip->start){
blendfac = stripframe/strip->blendin;
}
else if (strip->blendout>0.0 && stripframe>=(length-strip->blendout) && G.scene->r.cfra<=strip->end){
blendfac = (length-stripframe)/(strip->blendout);
}
else
blendfac = 1;
/* Blend this pose with the accumulated pose */
blend_poses (apose, tpose, blendfac, strip->mode);
#ifdef __NLA_BLENDCON
blend_constraints(&apose->chanbase, &tpose->chanbase, blendfac, strip->mode);
#endif
}
}
if (apose){
get_pose_from_pose(&ob->pose, apose);
#ifdef __NLA_BLENDCON
get_constraint_influence_from_pose(ob->pose, apose);
#endif
}
}
}
/* Do local action (always overrides the nla actions) */
/* At the moment, only constraint ipos on the local action have any effect */
if(base->object->action) {
get_pose_from_action (&ob->pose, ob->action, bsystem_time(ob, 0, (float) G.scene->r.cfra, 0.0));
do_pose_constraint_channels(ob->pose, ob->action, bsystem_time(ob, 0, (float) G.scene->r.cfra, 0.0));
doit = 1;
}
if (doit)
apply_pose_armature(get_armature(ob), ob->pose, 1);
}
base= base->next;
if(base==0 && set==0 && G.scene->set) {
set= 1;
base= G.scene->set->base.first;
}
}
if (apose){
clear_pose(apose);
MEM_freeN(apose);
apose = NULL;
}
if (tpose){
clear_pose(tpose);
MEM_freeN(tpose);
apose = NULL;
}
}
static void do_pose_constraint_channels(bPose *pose, bAction *act, float ctime)
{
bPoseChannel *pchan;
bActionChannel *achan;
if (!pose || !act)
return;
for (pchan=pose->chanbase.first; pchan; pchan=pchan->next){
achan=get_named_actionchannel(act, pchan->name);
if (achan)
do_constraint_channels(&pchan->constraints, &achan->constraintChannels, ctime);
}
}
bActionChannel *
get_named_actionchannel (
bAction *act,
const char *name
){
bActionChannel *chan;
if (!act)
return NULL;
for (chan = act->chanbase.first; chan; chan=chan->next){
if (!strcmp (chan->name, name))
return chan;
}
return NULL;
}
void
clear_pose (
bPose *pose
) {
bPoseChannel *chan;
if (pose->chanbase.first){
for (chan = pose->chanbase.first; chan; chan=chan->next){
free_constraints(&chan->constraints);
}
BLI_freelistN (&pose->chanbase);
}
}
void
make_local_action(
bAction *act
){
Object *ob;
bAction *actn;
int local=0, lib=0;
if(act->id.lib==0) return;
if(act->id.us==1) {
act->id.lib= 0;
act->id.flag= LIB_LOCAL;
new_id(0, (ID *)act, 0);
return;
}
ob= G.main->object.first;
while(ob) {
if(ob->action==act) {
if(ob->id.lib) lib= 1;
else local= 1;
}
ob= ob->id.next;
}
if(local && lib==0) {
act->id.lib= 0;
act->id.flag= LIB_LOCAL;
new_id(0, (ID *)act, 0);
}
else if(local && lib) {
actn= copy_action(act);
actn->id.us= 0;
ob= G.main->object.first;
while(ob) {
if(ob->action==act) {
if(ob->id.lib==0) {
ob->action = actn;
ob->activecon = NULL;
actn->id.us++;
act->id.us--;
}
}
ob= ob->id.next;
}
}
}
void
free_action(
bAction *act
){
bActionChannel *chan;
/* Free channels */
for (chan=act->chanbase.first; chan; chan=chan->next){
if (chan->ipo)
chan->ipo->id.us--;
free_constraint_channels(&chan->constraintChannels);
}
if (act->chanbase.first)
BLI_freelistN (&act->chanbase);
}
bAction*
copy_action (
const bAction *src
){
bAction *dst = NULL;
bActionChannel *dchan, *schan;
if(!src) return NULL;
dst= copy_libblock(src);
duplicatelist(&(dst->chanbase), &(src->chanbase));
for (dchan=dst->chanbase.first, schan=src->chanbase.first; dchan; dchan=dchan->next, schan=schan->next){
dchan->ipo = copy_ipo(dchan->ipo);
copy_constraint_channels(&dchan->constraintChannels, &schan->constraintChannels);
}
dst->id.flag |= LIB_FAKEUSER;
dst->id.us++;
return dst;
}
bPoseChannel *
copy_pose_channel (
const bPoseChannel* src
){
bPoseChannel *dst;
if (!src)
return NULL;
dst = MEM_callocN (sizeof(bPoseChannel), "copyPoseChannel");
memcpy (dst, src, sizeof(bPoseChannel));
dst->prev=dst->next=NULL;
return dst;
}
void
copy_pose(
bPose **dst,
const bPose *src,
int copycon
){
bPose *outPose;
const bPose * inPose;
bPoseChannel *newChan;
const bPoseChannel *curChan;
inPose = src;
if (!inPose){
*dst=NULL;
return;
}
outPose=MEM_callocN(sizeof(bPose), "pose");
for (curChan=inPose->chanbase.first; curChan; curChan=curChan->next){
newChan=MEM_callocN(sizeof(bPoseChannel), "copyposePoseChannel");
strcpy (newChan->name, curChan->name);
newChan->flag=curChan->flag;
memcpy (newChan->loc, curChan->loc, sizeof (curChan->loc));
memcpy (newChan->size, curChan->size, sizeof (curChan->size));
memcpy (newChan->quat, curChan->quat, sizeof (curChan->quat));
Mat4CpyMat4 (newChan->obmat, curChan->obmat);
BLI_addtail (&outPose->chanbase, newChan);
if (copycon){
copy_constraints(&newChan->constraints, &curChan->constraints);
}
}
*dst=outPose;
}
bPoseChannel *set_pose_channel (bPose *pose, bPoseChannel *chan){
/* chan is no longer valid for the calling function.
and should not be used by that function after calling
this one
*/
bPoseChannel *curChan;
/* Determine if an equivalent channel exists already */
for (curChan=pose->chanbase.first; curChan; curChan=curChan->next){
if (!strcmp (curChan->name, chan->name)){
if (chan->flag & POSE_ROT)
memcpy (curChan->quat, chan->quat, sizeof(chan->quat));
if (chan->flag & POSE_SIZE)
memcpy (curChan->size, chan->size, sizeof(chan->size));
if (chan->flag & POSE_LOC)
memcpy (curChan->loc, chan->loc, sizeof(chan->loc));
if (chan->flag & PCHAN_DONE)
Mat4CpyMat4 (curChan->obmat, chan->obmat);
curChan->flag |= chan->flag;
MEM_freeN (chan);
return curChan;
}
}
MEM_freeN (chan);
return NULL;
/* If an equivalent channel doesn't exist, then don't bother setting it. */
}

View File

@@ -0,0 +1,512 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <math.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "DNA_listBase.h"
#include "DNA_object_types.h"
#include "DNA_curve_types.h"
#include "DNA_key_types.h"
#include "DNA_view3d_types.h"
#include "DNA_effect_types.h"
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
#include "BKE_global.h"
#include "BKE_utildefines.h"
#include "BKE_anim.h"
#include "BKE_ipo.h"
#include "BKE_object.h"
#include "BKE_displist.h"
#include "BKE_key.h"
#include "BKE_font.h"
#include "BKE_effect.h"
#include "BKE_bad_level_calls.h"
ListBase duplilist= {0, 0};
void free_path(Path *path)
{
if(path->data) MEM_freeN(path->data);
MEM_freeN(path);
}
void calc_curvepath(Object *ob)
{
BevList *bl;
BevPoint *bevp, *bevpn, *bevpfirst, *bevplast;
Curve *cu;
Nurb *nu;
Path *path;
float *fp, *dist, *maxdist, x, y, z;
float fac, d=0, fac1, fac2;
int a, tot, cycl=0;
float *ft;
/* in een pad zitten allemaal punten met gelijke afstand: path->len = aantal pt */
/* NU MET BEVELCURVE!!! */
if(ob==0 || ob->type != OB_CURVE) return;
cu= ob->data;
if(ob==G.obedit) nu= editNurb.first;
else nu= cu->nurb.first;
if(cu->path) free_path(cu->path);
cu->path= 0;
if((cu->flag & CU_PATH)==0) return;
bl= cu->bev.first;
if(bl==0) {
makeDispList(ob);
bl= cu->bev.first;
}
if(bl==0) return;
cu->path=path= MEM_callocN(sizeof(Path), "path");
/* als POLY: laatste punt != eerste punt */
cycl= (bl->poly!= -1);
if(cycl) tot= bl->nr;
else tot= bl->nr-1;
path->len= tot+1;
/* exception: vector handle paths and polygon paths should be subdivided at least a factor 6 (or more?) */
if(path->len<6*nu->pntsu) path->len= 6*nu->pntsu;
dist= (float *)MEM_mallocN((tot+1)*4, "berekenpaddist");
/* alle lengtes in *dist */
bevp= bevpfirst= (BevPoint *)(bl+1);
fp= dist;
*fp= 0;
for(a=0; a<tot; a++) {
fp++;
if(cycl && a==tot-1) {
x= bevpfirst->x - bevp->x;
y= bevpfirst->y - bevp->y;
z= bevpfirst->z - bevp->z;
}
else {
x= (bevp+1)->x - bevp->x;
y= (bevp+1)->y - bevp->y;
z= (bevp+1)->z - bevp->z;
}
*fp= *(fp-1)+ (float)sqrt(x*x+y*y+z*z);
bevp++;
}
path->totdist= *fp;
/* de padpunten in path->data */
/* nu ook met TILT */
ft= path->data = (float *)MEM_callocN(16*path->len, "pathdata");
bevp= bevpfirst;
bevpn= bevp+1;
bevplast= bevpfirst + (bl->nr-1);
fp= dist+1;
maxdist= dist+tot;
fac= 1.0f/((float)path->len-1.0f);
for(a=0; a<path->len; a++) {
d= ((float)a)*fac*path->totdist;
/* we zoeken plek 'd' in het array */
while((d>= *fp) && fp<maxdist) {
fp++;
if(bevp<bevplast) bevp++;
bevpn= bevp+1;
if(bevpn>bevplast) {
if(cycl) bevpn= bevpfirst;
else bevpn= bevplast;
}
}
fac1= *(fp)- *(fp-1);
fac2= *(fp)-d;
fac1= fac2/fac1;
fac2= 1.0f-fac1;
ft[0]= fac1*bevp->x+ fac2*(bevpn)->x;
ft[1]= fac1*bevp->y+ fac2*(bevpn)->y;
ft[2]= fac1*bevp->z+ fac2*(bevpn)->z;
ft[3]= fac1*bevp->alfa+ fac2*(bevpn)->alfa;
ft+= 4;
}
MEM_freeN(dist);
}
int interval_test(int min, int max, int p1, int cycl)
{
if(cycl) {
if( p1 < min)
p1= ((p1 -min) % (max-min+1)) + max+1;
else if(p1 > max)
p1= ((p1 -min) % (max-min+1)) + min;
}
else {
if(p1 < min) p1= min;
else if(p1 > max) p1= max;
}
return p1;
}
int where_on_path(Object *ob, float ctime, float *vec, float *dir) /* geeft OK terug */
{
Curve *cu;
Nurb *nu;
BevList *bl;
Path *path;
float *fp, *p0, *p1, *p2, *p3, fac;
float data[4];
int cycl=0, s0, s1, s2, s3;
if(ob==0 || ob->type != OB_CURVE) return 0;
cu= ob->data;
if(cu->path==0 || cu->path->data==0) calc_curvepath(ob);
path= cu->path;
fp= path->data;
/* cyclic testen */
bl= cu->bev.first;
if(bl && bl->poly> -1) cycl= 1;
/* ctime is van 0.0-1.0 */
ctime *= (path->len-1);
s1= (int)floor(ctime);
fac= (float)(s1+1)-ctime;
/* path->len is gecorrigeerd voor cyclic, zie boven, is beetje warrig! */
s0= interval_test(0, path->len-1-cycl, s1-1, cycl);
s1= interval_test(0, path->len-1-cycl, s1, cycl);
s2= interval_test(0, path->len-1-cycl, s1+1, cycl);
s3= interval_test(0, path->len-1-cycl, s1+2, cycl);
p0= fp + 4*s0;
p1= fp + 4*s1;
p2= fp + 4*s2;
p3= fp + 4*s3;
if(cu->flag & CU_FOLLOW) {
set_afgeleide_four_ipo(1.0f-fac, data, KEY_BSPLINE);
dir[0]= data[0]*p0[0] + data[1]*p1[0] + data[2]*p2[0] + data[3]*p3[0] ;
dir[1]= data[0]*p0[1] + data[1]*p1[1] + data[2]*p2[1] + data[3]*p3[1] ;
dir[2]= data[0]*p0[2] + data[1]*p1[2] + data[2]*p2[2] + data[3]*p3[2] ;
/* compatible maken met vectoquat */
dir[0]= -dir[0];
dir[1]= -dir[1];
dir[2]= -dir[2];
}
nu= cu->nurb.first;
/* zeker van zijn dat de eerste en laatste frame door de punten gaat */
if((nu->type & 7)==CU_POLY) set_four_ipo(1.0f-fac, data, KEY_LINEAR);
else if((nu->type & 7)==CU_BEZIER) set_four_ipo(1.0f-fac, data, KEY_LINEAR);
else if(s0==s1 || p2==p3) set_four_ipo(1.0f-fac, data, KEY_CARDINAL);
else set_four_ipo(1.0f-fac, data, KEY_BSPLINE);
vec[0]= data[0]*p0[0] + data[1]*p1[0] + data[2]*p2[0] + data[3]*p3[0] ;
vec[1]= data[0]*p0[1] + data[1]*p1[1] + data[2]*p2[1] + data[3]*p3[1] ;
vec[2]= data[0]*p0[2] + data[1]*p1[2] + data[2]*p2[2] + data[3]*p3[2] ;
vec[3]= data[0]*p0[3] + data[1]*p1[3] + data[2]*p2[3] + data[3]*p3[3] ;
return 1;
}
void frames_duplilist(Object *ob)
{
extern int enable_cu_speed; /* object.c */
Object *newob;
int cfrao, ok;
cfrao= G.scene->r.cfra;
if(ob->parent==0 && ob->track==0 && ob->ipo==0) return;
if(ob->transflag & OB_DUPLINOSPEED) enable_cu_speed= 0;
/* dit om zeker van te zijn dat er iets gezbufferd wordt: in drawobject.c: dt==wire en boundboxclip */
if(G.background==0 && ob->type==OB_MESH) {
Mesh *me= ob->data;
DispList *dl;
if(me->disp.first==0) addnormalsDispList(ob, &me->disp);
if(ob->dt==OB_SHADED) {
dl= ob->disp.first;
if(dl==0 || dl->col1==0) shadeDispList(ob);
}
}
for(G.scene->r.cfra= ob->dupsta; G.scene->r.cfra<=ob->dupend; G.scene->r.cfra++) {
ok= 1;
if(ob->dupoff) {
ok= G.scene->r.cfra - ob->dupsta;
ok= ok % (ob->dupon+ob->dupoff);
if(ok < ob->dupon) ok= 1;
else ok= 0;
}
if(ok) {
newob= MEM_mallocN(sizeof(Object), "newobobj dupli");
memcpy(newob, ob, sizeof(Object));
/* alleen de basis-ball behoeft een displist */
if(newob->type==OB_MBALL) newob->disp.first= newob->disp.last= 0;
BLI_addtail(&duplilist, newob);
do_ob_ipo(newob);
where_is_object(newob);
newob->flag |= OB_FROMDUPLI;
newob->id.newid= (ID *)ob; /* duplicator bewaren */
}
}
G.scene->r.cfra= cfrao;
enable_cu_speed= 1;
do_ob_ipo(ob);
}
void vertex_duplilist(Scene *sce, Object *par)
{
Object *ob, *newob;
Base *base;
MVert *mvert;
Mesh *me;
float vec[3], pvec[3], pmat[4][4], mat[3][3], tmat[4][4];
float *q2;
int lay, totvert, a;
Mat4CpyMat4(pmat, par->obmat);
Mat4One(tmat);
lay= G.scene->lay;
base= sce->base.first;
while(base) {
if(base->object->type>0 && (lay & base->lay) && G.obedit!=base->object) {
ob= base->object->parent;
while(ob) {
if(ob==par) {
ob= base->object;
/* mballs have a different dupli handling */
if(ob->type!=OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */
me= par->data;
mvert= me->mvert;
mvert+= (me->totvert-1);
VECCOPY(pvec, mvert->co);
Mat4MulVecfl(pmat, pvec);
mvert= me->mvert;
totvert= me->totvert;
for(a=0; a<totvert; a++, mvert++) {
/* bereken de extra offset (tov. nulpunt parent) die de kinderen krijgen */
VECCOPY(vec, mvert->co);
Mat4MulVecfl(pmat, vec);
VecSubf(vec, vec, pmat[3]);
VecAddf(vec, vec, ob->obmat[3]);
newob= MEM_mallocN(sizeof(Object), "newobj dupli");
memcpy(newob, ob, sizeof(Object));
newob->flag |= OB_FROMDUPLI;
newob->id.newid= (ID *)par; /* duplicator bewaren */
/* alleen de basis-ball behoeft een displist */
if(newob->type==OB_MBALL) newob->disp.first= newob->disp.last= 0;
VECCOPY(newob->obmat[3], vec);
if(par->transflag & OB_DUPLIROT) {
VECCOPY(vec, mvert->no);
vec[0]= -vec[0]; vec[1]= -vec[1]; vec[2]= -vec[2];
q2= vectoquat(vec, ob->trackflag, ob->upflag);
QuatToMat3(q2, mat);
Mat4CpyMat4(tmat, newob->obmat);
Mat4MulMat43(newob->obmat, tmat, mat);
}
newob->parent= 0;
newob->track= 0;
/* newob->borig= base; */
BLI_addtail(&duplilist, newob);
VECCOPY(pvec, vec);
}
break;
}
ob= ob->parent;
}
}
base= base->next;
}
}
void particle_duplilist(Scene *sce, Object *par, PartEff *paf)
{
Object *ob, *newob;
Base *base;
Particle *pa;
float ctime, vec1[3];
float vec[3], tmat[4][4], mat[3][3];
float *q2;
int lay, a;
pa= paf->keys;
if(pa==0) {
build_particle_system(par);
pa= paf->keys;
if(pa==0) return;
}
ctime= bsystem_time(par, 0, (float)G.scene->r.cfra, 0.0);
lay= G.scene->lay;
base= sce->base.first;
while(base) {
if(base->object->type>0 && (base->lay & lay) && G.obedit!=base->object) {
ob= base->object->parent;
while(ob) {
if(ob==par) {
ob= base->object;
pa= paf->keys;
for(a=0; a<paf->totpart; a++, pa+=paf->totkey) {
if(ctime > pa->time) {
if(ctime < pa->time+pa->lifetime) {
newob= MEM_mallocN(sizeof(Object), "newobj dupli");
memcpy(newob, ob, sizeof(Object));
newob->flag |= OB_FROMDUPLI;
newob->id.newid= (ID *)par; /* duplicator bewaren */
/* alleen de basis-ball behoeft een displist */
if(newob->type==OB_MBALL) newob->disp.first= newob->disp.last= 0;
where_is_particle(paf, pa, ctime, vec);
if(paf->stype==PAF_VECT) {
where_is_particle(paf, pa, ctime+1.0f, vec1);
VecSubf(vec1, vec1, vec);
q2= vectoquat(vec1, ob->trackflag, ob->upflag);
QuatToMat3(q2, mat);
Mat4CpyMat4(tmat, newob->obmat);
Mat4MulMat43(newob->obmat, tmat, mat);
}
VECCOPY(newob->obmat[3], vec);
newob->parent= 0;
newob->track= 0;
BLI_addtail(&duplilist, newob);
}
}
}
break;
}
ob= ob->parent;
}
}
base= base->next;
}
}
void free_duplilist()
{
Object *ob;
while( ob= duplilist.first) {
BLI_remlink(&duplilist, ob);
MEM_freeN(ob);
}
}
void make_duplilist(Scene *sce, Object *ob)
{
PartEff *paf;
if(ob->transflag & OB_DUPLI) {
if(ob->transflag & OB_DUPLIVERTS) {
if(ob->type==OB_MESH) {
if(ob->transflag & OB_DUPLIVERTS) {
if( paf=give_parteff(ob) ) particle_duplilist(sce, ob, paf);
else vertex_duplilist(sce, ob);
}
}
else if(ob->type==OB_FONT) {
font_duplilist(ob);
}
}
else if(ob->transflag & OB_DUPLIFRAMES) frames_duplilist(ob);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,343 @@
/* blender.c jan 94 MIXED MODEL
*
* algemene hulp funkties en data
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef WIN32
#include <unistd.h> // for read close
#include <sys/param.h> // for MAXPATHLEN
#else
#include <io.h> // for open close read
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h> // for open
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
#include "DNA_sdna_types.h"
#include "DNA_userdef_types.h"
#include "DNA_object_types.h"
#include "DNA_curve_types.h"
#include "BLI_blenlib.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
#include "DNA_screen_types.h"
#include "BKE_library.h"
#include "BKE_blender.h"
#include "BKE_displist.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_scene.h"
#include "BKE_effect.h"
#include "BKE_curve.h"
#include "BKE_font.h"
#include "BKE_bad_level_calls.h" /* for BPY_do_pyscript */
#include "BLO_readfile.h" /* for BLO_read_file */
#include "BKE_bad_level_calls.h" // for freeAllRad editNurb free_editMesh free_editText free_editArmature
#include "BKE_utildefines.h" // O_BINARY FALSE
#include "nla.h"
Global G;
UserDef U;
char versionstr[48]= "";
/* ************************************************ */
/* pushpop faciliteit: om tijdelijk data te bewaren */
ListBase ppmain={0, 0};
typedef struct PushPop {
struct PushPop *next, *prev;
void *data;
int len;
} PushPop;
void pushdata(void *data, int len)
{
PushPop *pp;
pp= MEM_mallocN(sizeof(PushPop), "pushpop");
BLI_addtail(&ppmain, pp);
pp->data= MEM_mallocN(len, "pushpop");
pp->len= len;
memcpy(pp->data, data, len);
}
void popfirst(void *data)
{
PushPop *pp;
pp= ppmain.first;
if(pp) {
memcpy(data, pp->data, pp->len);
BLI_remlink(&ppmain, pp);
MEM_freeN(pp->data);
MEM_freeN(pp);
}
else printf("error in popfirst\n");
}
void poplast(void *data)
{
PushPop *pp;
pp= ppmain.last;
if(pp) {
memcpy(data, pp->data, pp->len);
BLI_remlink(&ppmain, pp);
MEM_freeN(pp->data);
MEM_freeN(pp);
}
else printf("error in poplast\n");
}
void free_pushpop()
{
PushPop *pp;
pp= ppmain.first;
while(pp) {
BLI_remlink(&ppmain, pp);
MEM_freeN(pp->data);
MEM_freeN(pp);
}
}
void pushpop_test()
{
if(ppmain.first) printf("pushpop not empty\n");
free_pushpop();
}
/* ********** vrijgeven ********** */
void free_blender(void)
{
free_main(G.main);
G.main= NULL;
IMB_freeImBufdata(); /* imbuf lib */
}
void duplicatelist(ListBase *list1, ListBase *list2) /* kopie van 2 naar 1 */
{
struct Link *link1, *link2;
list1->first= list1->last= 0;
link2= list2->first;
while(link2) {
link1= MEM_dupallocN(link2);
BLI_addtail(list1, link1);
link2= link2->next;
}
}
void initglobals(void)
{
memset(&G, 0, sizeof(Global));
U.savetime= 1;
G.animspeed= 4;
G.main= MEM_callocN(sizeof(Main), "initglobals");
strcpy(G.ima, "//");
G.version= BLENDER_VERSION;
G.order= 1;
G.order= (((char*)&G.order)[0])?L_ENDIAN:B_ENDIAN;
sprintf(versionstr, "www.blender.nl %d", G.version);
clear_workob(); /* object.c */
}
/***/
static void clear_global(void) {
extern short winqueue_break; /* screen.c */
freeAllRad();
free_main(G.main); /* free all lib data */
freefastshade(); /* anders oude lampgegevens */
/* hangende vars voorkomen */
R.backbuf= 0;
/* force all queues to be left */
winqueue_break= 1;
if (G.obedit) {
freeNurblist(&editNurb);
free_editMesh();
free_editText();
free_editArmature();
}
G.curscreen= NULL;
G.scene= NULL;
G.main= NULL;
G.obedit= NULL;
G.obpose= NULL;
G.saction= NULL;
G.buts= NULL;
G.v2d= NULL;
G.vd= NULL;
G.soops= NULL;
G.sima= NULL;
G.sipo= NULL;
G.f &= ~(G_WEIGHTPAINT + G_VERTEXPAINT + G_FACESELECT);
}
static void setup_app_data(BlendFileData *bfd, char *filename) {
Object *ob;
clear_global();
G.save_over = 1;
G.main= bfd->main;
if (bfd->user) {
U= *bfd->user;
MEM_freeN(bfd->user);
}
R.winpos= bfd->winpos;
R.displaymode= bfd->displaymode;
G.curscreen= bfd->curscreen;
G.fileflags= bfd->fileflags;
G.scene= G.curscreen->scene;
/* weinig DispListen, wel text_to_curve */
// this should be removed!!! But first a better displist system (ton)
for (ob= G.main->object.first; ob; ob= ob->id.next) {
if(ob->type==OB_FONT) {
Curve *cu= ob->data;
if(cu->nurb.first==0) text_to_curve(ob, 0);
}
else if(ob->type==OB_MESH) {
makeDispList(ob);
if(ob->effect.first) object_wave(ob);
}
}
if (!G.background) {
setscreen(G.curscreen);
}
/* baseflags */
set_scene_bg(G.scene);
if (G.f & G_SCENESCRIPT) {
BPY_do_pyscript(&G.scene->id, SCRIPT_ONLOAD);
}
strcpy(G.sce, filename);
strcpy(G.main->name, filename); /* is gegarandeerd current file */
MEM_freeN(bfd);
}
int BKE_read_file(char *dir, void *type_r) {
BlendReadError bre;
BlendFileData *bfd;
if (!G.background)
waitcursor(1);
bfd= BLO_read_from_file(dir, &bre);
if (bfd) {
if (type_r)
*((BlenFileType*)type_r)= bfd->type;
setup_app_data(bfd, dir);
} else {
error("Loading %s failed: %s", dir, BLO_bre_as_string(bre));
}
if (!G.background)
waitcursor(0);
return (bfd?1:0);
}
int BKE_read_file_from_memory(char* filebuf, int filelength, void *type_r)
{
BlendReadError bre;
BlendFileData *bfd;
if (!G.background)
waitcursor(1);
bfd= BLO_read_from_memory(filebuf, filelength, &bre);
if (bfd) {
if (type_r)
*((BlenFileType*)type_r)= bfd->type;
setup_app_data(bfd, "<memory>");
} else {
error("Loading failed: %s", BLO_bre_as_string(bre));
}
if (!G.background)
waitcursor(0);
return (bfd?1:0);
}

View File

@@ -0,0 +1,293 @@
/**
* bmfont.c
*
* 04-10-2000 frank
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*
*/
/**
* Two external functions:
*
* void detectBitmapFont(ImBuf *ibuf)
* detects if an image buffer contains a bitmap font. It makes the
* specific bitmap data which is stored in the bitmap invisible to blender.
*
* void matrixGlyph(ImBuf * ibuf, unsigned short unicode, *float x 7)
* returns all the information about the character (unicode) in the floats
*
* Room for improvement:
* add kerning data in the bitmap
* all calculations in matrixGlyph() are static and could be done during
* initialization
*/
#include <stdio.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BKE_global.h"
#include "IMB_imbuf_types.h"
#include "BKE_bmfont.h"
#include "BKE_bmfont_types.h"
void printfGlyph(bmGlyph * glyph)
{
printf("unicode: %d '%c'\n", glyph->unicode, glyph->unicode);
printf(" locx: %4d locy: %4d\n", glyph->locx, glyph->locy);
printf(" sizex: %3d sizey: %3d\n", glyph->sizex, glyph->sizey);
printf(" ofsx: %3d ofsy: %3d\n", glyph->ofsx, glyph->ofsy);
printf(" advan: %3d reser: %3d\n", glyph->advance, glyph->reserved);
}
#define MAX2(x,y) ( (x)>(y) ? (x) : (y) )
#define MAX3(x,y,z) MAX2( MAX2((x),(y)) , (z) )
void calcAlpha(ImBuf * ibuf)
{
int i;
char * rect;
if (ibuf) {
rect = (char *) ibuf->rect;
for (i = ibuf->x * ibuf->y ; i > 0 ; i--) {
rect[3] = MAX3(rect[0], rect[1], rect[2]);
rect += 4;
}
}
}
void readBitmapFontVersion0(ImBuf * ibuf, unsigned char * rect, int step)
{
int glyphcount, bytes, i, index, linelength, ysize;
unsigned char * buffer;
bmFont * bmfont;
linelength = ibuf->x * step;
glyphcount = (rect[6 * step] << 8) | rect[7 * step];
bytes = ((glyphcount - 1) * sizeof(bmGlyph)) + sizeof(bmFont);
ysize = (bytes + (ibuf->x - 1)) / ibuf->x;
if (ysize < ibuf->y) {
// we're first going to copy all data into a liniar buffer.
// step can be 4 or 1 bytes, and the data is not sequential because
// the bitmap was flipped vertically.
buffer = MEM_mallocN(bytes, "readBitmapFontVersion0:buffer");
index = 0;
for (i = 0; i < bytes; i++) {
buffer[i] = rect[index];
index += step;
if (index >= linelength) {
// we've read one line, no skip to the line *before* that
rect -= linelength;
index -= linelength;
}
}
// we're now going to endian convert the data
bmfont = MEM_mallocN(bytes, "readBitmapFontVersion0:bmfont");
index = 0;
// first read the header
bmfont->magic[0] = buffer[index++];
bmfont->magic[1] = buffer[index++];
bmfont->magic[2] = buffer[index++];
bmfont->magic[3] = buffer[index++];
bmfont->version = (buffer[index] << 8) | buffer[index + 1]; index += 2;
bmfont->glyphcount = (buffer[index] << 8) | buffer[index + 1]; index += 2;
bmfont->xsize = (buffer[index] << 8) | buffer[index + 1]; index += 2;
bmfont->ysize = (buffer[index] << 8) | buffer[index + 1]; index += 2;
for (i = 0; i < bmfont->glyphcount; i++) {
bmfont->glyphs[i].unicode = (buffer[index] << 8) | buffer[index + 1]; index += 2;
bmfont->glyphs[i].locx = (buffer[index] << 8) | buffer[index + 1]; index += 2;
bmfont->glyphs[i].locy = (buffer[index] << 8) | buffer[index + 1]; index += 2;
bmfont->glyphs[i].ofsx = buffer[index++];
bmfont->glyphs[i].ofsy = buffer[index++];
bmfont->glyphs[i].sizex = buffer[index++];
bmfont->glyphs[i].sizey = buffer[index++];
bmfont->glyphs[i].advance = buffer[index++];
bmfont->glyphs[i].reserved = buffer[index++];
if (G.f & G_DEBUG) {
printfGlyph(&bmfont->glyphs[i]);
}
}
MEM_freeN(buffer);
if (G.f & G_DEBUG) {
printf("Oldy = %d Newy = %d\n", ibuf->y, ibuf->y - ysize);
printf("glyphcount = %d\n", glyphcount);
printf("bytes = %d\n", bytes);
}
// we've read the data from the image. Now we're going
// to crop the image vertically so only the bitmap data
// remains visible
ibuf->y -= ysize;
ibuf->userdata = bmfont;
ibuf->userflags |= IB_BITMAPFONT;
if (ibuf->depth < 32) {
// we're going to fake alpha here:
calcAlpha(ibuf);
}
} else {
printf("readBitmapFontVersion0: corrupted bitmapfont\n");
}
}
void detectBitmapFont(ImBuf *ibuf)
{
unsigned char * rect;
unsigned short version;
long i;
if (ibuf != NULL) {
// bitmap must have an x size that is a power of two
if (is_power_of_two(ibuf->x)) {
rect = (unsigned char *) (ibuf->rect + (ibuf->x * (ibuf->y - 1)));
// printf ("starts with: %s %c %c %c %c\n", rect, rect[0], rect[1], rect[2], rect[3]);
if (rect[0] == 'B' && rect[1] == 'F' && rect[2] == 'N' && rect[3] == 'T') {
// printf("found 8bit font !\n");
// round y size down
// do the 8 bit font stuff. (not yet)
} else {
// we try all 4 possible combinations
for (i = 0; i < 4; i++) {
if (rect[0] == 'B' && rect[4] == 'F' && rect[8] == 'N' && rect[12] == 'T') {
// printf("found 24bit font !\n");
// We're going to parse the file:
version = (rect[16] << 8) | rect[20];
if (version == 0) {
readBitmapFontVersion0(ibuf, rect, 4);
} else {
printf("detectBitmapFont :Unsupported version %d\n", version);
}
// on succes ibuf->userdata points to the bitmapfont
if (ibuf->userdata) {
break;
}
}
rect++;
}
}
}
}
}
int locateGlyph(bmFont *bmfont, unsigned short unicode)
{
int min, max, current = 0;
if (bmfont) {
min = 0;
max = bmfont->glyphcount;
while (1) {
// look halfway for glyph
current = (min + max) >> 1;
if (bmfont->glyphs[current].unicode == unicode) {
break;
} else if (bmfont->glyphs[current].unicode < unicode) {
// have to move up
min = current;
} else {
// have to move down
max = current;
}
if (max - min <= 1) {
// unable to locate glyph
current = 0;
break;
}
}
}
return(current);
}
void matrixGlyph(ImBuf * ibuf, unsigned short unicode,
float *centerx, float *centery,
float *sizex, float *sizey,
float *transx, float *transy,
float *movex, float *movey,
float *advance)
{
int index;
bmFont *bmfont;
*centerx = *centery = 0.0;
*sizex = *sizey = 1.0;
*transx = *transy = 0.0;
*movex = *movey = 0.0;
*advance = 1.0;
if (ibuf) {
bmfont = ibuf->userdata;
if (bmfont && (ibuf->userflags & IB_BITMAPFONT)) {
index = locateGlyph(bmfont, unicode);
if (index) {
*sizex = (bmfont->glyphs[index].sizex) / (float) (bmfont->glyphs[0].sizex);
*sizey = (bmfont->glyphs[index].sizey) / (float) (bmfont->glyphs[0].sizey);
*transx = bmfont->glyphs[index].locx / (float) ibuf->x;
*transy = (ibuf->y - bmfont->glyphs[index].locy) / (float) ibuf->y;
*centerx = bmfont->glyphs[0].locx / (float) ibuf->x;
*centery = (ibuf->y - bmfont->glyphs[0].locy) / (float) ibuf->y;
// 2.0 units is the default size of an object
*movey = 1.0f - *sizey + 2.0f * (bmfont->glyphs[index].ofsy - bmfont->glyphs[0].ofsy) / (float) bmfont->glyphs[0].sizey;
*movex = *sizex - 1.0f + 2.0f * (bmfont->glyphs[index].ofsx - bmfont->glyphs[0].ofsx) / (float) bmfont->glyphs[0].sizex;
*advance = 2.0f * bmfont->glyphs[index].advance / (float) bmfont->glyphs[0].advance;
// printfGlyph(&bmfont->glyphs[index]);
// printf("%c %d %0.5f %0.5f %0.5f %0.5f %0.5f \n", unicode, index, *sizex, *sizey, *transx, *transy, *advance);
}
}
}
}

View File

@@ -0,0 +1,732 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <stdio.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "nla.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "DNA_armature_types.h"
#include "DNA_constraint_types.h"
#include "DNA_object_types.h"
#include "DNA_action_types.h"
#include "DNA_curve_types.h"
#include "BKE_utildefines.h"
#include "BKE_action.h"
#include "BKE_armature.h"
#include "BKE_blender.h"
#include "BKE_constraint.h"
#include "BKE_object.h"
#include "BKE_ipo.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "blendef.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
/* Local function prototypes */
static void constraint_target_to_mat4 (Object *ob, const char *substring, float mat[][4], float size[3], float ctime);
/* Functions */
bConstraintChannel *find_constraint_channel (ListBase *list, const char *name){
bConstraintChannel *chan;
for (chan = list->first; chan; chan=chan->next){
if (!strcmp(name, chan->name)){
return chan;
}
}
return NULL;
}
void do_constraint_channels (ListBase *conbase, ListBase *chanbase, float ctime)
{
bConstraint *con;
bConstraintChannel *chan;
IpoCurve *icu;
for (con=conbase->first; con; con=con->next){
chan = find_constraint_channel(chanbase, con->name);
if (chan && chan->ipo){
calc_ipo(chan->ipo, ctime);
for (icu=chan->ipo->curve.first; icu; icu=icu->next){
switch (icu->adrcode){
case CO_ENFORCE:
con->enforce = icu->curval;
if (con->enforce<0) con->enforce=0;
else if (con->enforce>1) con->enforce=1;
break;
}
}
}
}
}
void Mat4BlendMat4(float out[][4], float dst[][4], float src[][4], float srcweight)
{
float squat[4], dquat[4], fquat[4];
float ssize[3], dsize[3], fsize[4];
float sloc[3], dloc[3], floc[3];
float mat3[3][3], dstweight;
float qmat[3][3], smat[3][3];
int i;
dstweight = 1.0F-srcweight;
Mat3CpyMat4(mat3, dst);
Mat3ToQuat(mat3, dquat);
Mat3ToSize(mat3, dsize);
VECCOPY (dloc, dst[3]);
Mat3CpyMat4(mat3, src);
Mat3ToQuat(mat3, squat);
Mat3ToSize(mat3, ssize);
VECCOPY (sloc, src[3]);
/* Do the actual blend */
for (i=0; i<3; i++){
floc[i] = (dloc[i]*dstweight) + (sloc[i]*srcweight);
fsize[i] = 1.0f + ((dsize[i]-1.0f)*dstweight) + ((ssize[i]-1.0f)*srcweight);
fquat[i+1] = (dquat[i+1]*dstweight) + (squat[i+1]*srcweight);
}
/* Do one more iteration for the quaternions only and normalize the quaternion if needed */
fquat[0] = 1.0f + ((dquat[0]-1.0f)*dstweight) + ((squat[0]-1.0f)*srcweight);
NormalQuat (fquat);
QuatToMat3(fquat, qmat);
SizeToMat3(fsize, smat);
Mat3MulMat3(mat3, qmat, smat);
Mat4CpyMat3(out, mat3);
VECCOPY (out[3], floc);
}
static void constraint_target_to_mat4 (Object *ob, const char *substring, float mat[][4], float size[3], float ctime)
{
/* Update the location of the target object */
where_is_object_time (ob, ctime);
/* Case OBJECT */
if (!strlen(substring)){
Mat4CpyMat4 (mat, ob->obmat);
VECCOPY (size, ob->size);
return;
}
/* Case BONE */
else {
bArmature *arm;
Bone *bone;
float bmat[4][4];
float bsize[3]={1, 1, 1};
arm = get_armature(ob);
/**
* Locate the bone (if there is one)
* Ensures that the bone's transformation is fully constrained
* (Cyclical relationships are disallowed elsewhere)
*/
bone = get_named_bone(arm, substring);
if (bone){
where_is_bone_time(ob, bone, ctime);
get_objectspace_bone_matrix(bone, bmat, 1, 1);
VECCOPY(bsize, bone->size);
}
else
Mat4One (bmat);
/**
* Multiply the objectspace bonematrix by the skeletons's global
* transform to obtain the worldspace transformation of the target
*/
VECCOPY(size, bsize);
Mat4MulMat4 (mat, bmat, ob->obmat);
return;
}
}
void clear_object_constraint_status (Object *ob)
{
bConstraint *con;
if (!ob) return;
/* Clear the object's constraints */
for (con = ob->constraints.first; con; con=con->next){
con->flag &= ~CONSTRAINT_DONE;
}
/* Clear the object's subdata constraints */
switch (ob->type){
case OB_ARMATURE:
{
clear_pose_constraint_status (ob);
}
break;
default:
break;
}
}
short get_constraint_target (bConstraint *con, short ownertype, void* ownerdata, float mat[][4], float size[3], float ctime)
{
short valid=0;
switch (con->type){
case CONSTRAINT_TYPE_NULL:
{
Mat4One(mat);
}
break;
case CONSTRAINT_TYPE_ACTION:
{
if (ownertype == TARGET_BONE){
bActionConstraint *data = (bActionConstraint*)con->data;
bPose *pose=NULL;
bPoseChannel *pchan=NULL;
float tempmat[4][4], imat[4][4], ans[4][4], restmat[4][4], irestmat[4][4];
float tempmat3[3][3];
float eul[3], size[3];
float s,t;
Bone *curBone;
Bone tbone;
int i;
curBone = (Bone*)ownerdata;
if (data->tar){
constraint_target_to_mat4(data->tar, data->subtarget, tempmat, size, ctime);
valid=1;
}
else
Mat4One (tempmat);
/* If this is a bone, undo parent transforms */
if (strlen(data->subtarget)){
Bone* bone;
Mat4Invert(imat, data->tar->obmat);
bone = get_named_bone(get_armature(data->tar), data->subtarget);
if (bone){
get_objectspace_bone_matrix(bone, restmat, 1, 0);
Mat4Invert(irestmat, restmat);
}
}
else{
Mat4One(imat);
Mat4One(irestmat);
}
Mat4MulSerie(ans, imat, tempmat, irestmat, NULL, NULL, NULL, NULL, NULL);
Mat3CpyMat4(tempmat3, ans);
Mat3ToEul(tempmat3, eul);
eul[0]*=(float)(180.0/M_PI);
eul[1]*=(float)(180.0/M_PI);
eul[2]*=(float)(180.0/M_PI);
/* Target is the animation */
s = (eul[data->type]-data->min)/(data->max-data->min);
if (s<0)
s=0;
if (s>1)
s=1;
t = ( s * (data->end-data->start)) + data->start;
/* Get the appropriate information from the action */
pose = MEM_callocN(sizeof(bPose), "pose");
verify_pose_channel(pose, curBone->name);
get_pose_from_action (&pose, data->act, t);
/* Find the appropriate channel */
pchan = get_pose_channel(pose, curBone->name);
if (pchan){
memset(&tbone, 0x00, sizeof(Bone));
VECCOPY (tbone.loc, pchan->loc);
VECCOPY (tbone.size, pchan->size);
for (i=0; i<4; i++)
tbone.quat[i]=pchan->quat[i];
bone_to_mat4(&tbone, mat);
}
else{
Mat4One(mat);
}
/* Clean up */
clear_pose(pose);
MEM_freeN(pose);
}
}
break;
case CONSTRAINT_TYPE_LOCLIKE:
{
bLocateLikeConstraint *data = (bLocateLikeConstraint*)con->data;
if (data->tar){
constraint_target_to_mat4(data->tar, data->subtarget, mat, size, ctime);
valid=1;
}
else
Mat4One (mat);
}
break;
case CONSTRAINT_TYPE_ROTLIKE:
{
bRotateLikeConstraint *data;
data = (bRotateLikeConstraint*)con->data;
if (data->tar){
constraint_target_to_mat4(data->tar, data->subtarget, mat, size, ctime);
valid=1;
}
else
Mat4One (mat);
}
break;
case CONSTRAINT_TYPE_TRACKTO:
{
bTrackToConstraint *data;
data = (bTrackToConstraint*)con->data;
if (data->tar){
constraint_target_to_mat4(data->tar, data->subtarget, mat, size, ctime);
valid=1;
}
else
Mat4One (mat);
}
break;
case CONSTRAINT_TYPE_KINEMATIC:
{
bTrackToConstraint *data;
data = (bTrackToConstraint*)con->data;
if (data->tar){
constraint_target_to_mat4(data->tar, data->subtarget, mat, size, ctime);
valid=1;
}
else
Mat4One (mat);
}
break;
default:
Mat4One(mat);
break;
}
return valid;
}
void relink_constraints (struct ListBase *list)
{
bConstraint *con;
for (con = list->first; con; con=con->next){
switch (con->type){
case CONSTRAINT_TYPE_KINEMATIC:
{
bKinematicConstraint *data;
data = con->data;
ID_NEW(data->tar);
}
break;
case CONSTRAINT_TYPE_NULL:
{
}
break;
case CONSTRAINT_TYPE_TRACKTO:
{
bTrackToConstraint *data;
data = con->data;
ID_NEW(data->tar);
}
break;
case CONSTRAINT_TYPE_ACTION:
{
bActionConstraint *data;
data = con->data;
ID_NEW(data->tar);
}
break;
case CONSTRAINT_TYPE_LOCLIKE:
{
bLocateLikeConstraint *data;
data = con->data;
ID_NEW(data->tar);
}
break;
case CONSTRAINT_TYPE_ROTLIKE:
{
bRotateLikeConstraint *data;
data = con->data;
ID_NEW(data->tar);
}
break;
}
}
}
void *copy_constraint_channels (ListBase *dst, ListBase *src)
{
bConstraintChannel *dchan, *schan;
bConstraintChannel *newact=NULL;
dst->first=dst->last=NULL;
duplicatelist(dst, src);
for (dchan=dst->first, schan=src->first; dchan; dchan=dchan->next, schan=schan->next){
dchan->ipo = copy_ipo(schan->ipo);
}
return newact;
}
bConstraintChannel *clone_constraint_channels (ListBase *dst, ListBase *src, bConstraintChannel *oldact)
{
bConstraintChannel *dchan, *schan;
bConstraintChannel *newact=NULL;
dst->first=dst->last=NULL;
duplicatelist(dst, src);
for (dchan=dst->first, schan=src->first; dchan; dchan=dchan->next, schan=schan->next){
id_us_plus((ID *)dchan->ipo);
if (schan==oldact)
newact=dchan;
}
return newact;
}
void copy_constraints (ListBase *dst, ListBase *src)
{
bConstraint *con;
dst->first=dst->last=NULL;
duplicatelist (dst, src);
/* Update specific data */
if (!dst->first)
return;
for (con = dst->first; con; con=con->next){
switch (con->type){
case CONSTRAINT_TYPE_ACTION:
{
bActionConstraint *data;
con->data = MEM_dupallocN (con->data);
data = (bActionConstraint*) con->data;
}
break;
case CONSTRAINT_TYPE_LOCLIKE:
{
bLocateLikeConstraint *data;
con->data = MEM_dupallocN (con->data);
data = (bLocateLikeConstraint*) con->data;
}
break;
case CONSTRAINT_TYPE_ROTLIKE:
{
bRotateLikeConstraint *data;
con->data = MEM_dupallocN (con->data);
data = (bRotateLikeConstraint*) con->data;
}
break;
case CONSTRAINT_TYPE_NULL:
{
con->data = NULL;
}
break;
case CONSTRAINT_TYPE_TRACKTO:
{
bTrackToConstraint *data;
con->data = MEM_dupallocN (con->data);
data = (bTrackToConstraint*) con->data;
}
break;
case CONSTRAINT_TYPE_KINEMATIC:
{
bKinematicConstraint *data;
con->data = MEM_dupallocN (con->data);
data = (bKinematicConstraint*) con->data;
}
break;
default:
con->data = MEM_dupallocN (con->data);
break;
}
}
}
void evaluate_constraint (bConstraint *constraint, Object *ob, short ownertype, void *ownerdata, float targetmat[][4])
/* ob is likely to be a workob */
{
float M_oldmat[4][4];
float M_identity[4][4];
float enforce = 1.0;
if (!constraint || !ob)
return;
Mat4One (M_identity);
/* We've already been calculated */
if (constraint->flag & CONSTRAINT_DONE){
return;
}
switch (constraint->type){
case CONSTRAINT_TYPE_ACTION:
{
float temp[4][4];
bActionConstraint *data;
data = constraint->data;
Mat4CpyMat4 (temp, ob->obmat);
Mat4MulMat4(ob->obmat, targetmat, temp);
}
break;
case CONSTRAINT_TYPE_LOCLIKE:
{
bLocateLikeConstraint *data;
data = constraint->data;
if (data->flag & LOCLIKE_X)
ob->obmat[3][0] = targetmat[3][0];
if (data->flag & LOCLIKE_Y)
ob->obmat[3][1] = targetmat[3][1];
if (data->flag & LOCLIKE_Z)
ob->obmat[3][2] = targetmat[3][2];
}
break;
case CONSTRAINT_TYPE_ROTLIKE:
{
float tmat[4][4];
float size[3];
Mat4ToSize(ob->obmat, size);
Mat4CpyMat4 (tmat, targetmat);
Mat4Ortho(tmat);
ob->obmat[0][0] = tmat[0][0]*size[0];
ob->obmat[0][1] = tmat[0][1]*size[1];
ob->obmat[0][2] = tmat[0][2]*size[2];
ob->obmat[1][0] = tmat[1][0]*size[0];
ob->obmat[1][1] = tmat[1][1]*size[1];
ob->obmat[1][2] = tmat[1][2]*size[2];
ob->obmat[2][0] = tmat[2][0]*size[0];
ob->obmat[2][1] = tmat[2][1]*size[1];
ob->obmat[2][2] = tmat[2][2]*size[2];
}
break;
case CONSTRAINT_TYPE_NULL:
{
}
break;
case CONSTRAINT_TYPE_TRACKTO:
{
bTrackToConstraint *data;
float size[3];
data=(bTrackToConstraint*)constraint->data;
if (data->tar){
Mat4ToSize (ob->obmat, size);
Mat4CpyMat4 (M_oldmat, ob->obmat);
// Clear the object's rotation
ob->obmat[0][0]=ob->size[0];
ob->obmat[0][1]=0;
ob->obmat[0][2]=0;
ob->obmat[1][0]=0;
ob->obmat[1][1]=ob->size[1];
ob->obmat[1][2]=0;
ob->obmat[2][0]=0;
ob->obmat[2][1]=0;
ob->obmat[2][2]=ob->size[2];
solve_tracking(ob, targetmat);
}
}
break;
case CONSTRAINT_TYPE_KINEMATIC:
{
bKinematicConstraint *data;
float imat[4][4];
float temp[4][4];
float totmat[4][4];
data=(bKinematicConstraint*)constraint->data;
if (data->tar && ownertype==TARGET_BONE && ownerdata){
Bone *curBone = (Bone*)ownerdata;
PoseChain *chain;
Object *armob;
/* Retrieve the owner armature object from the workob */
armob = ob->parent;
/* Make an IK chain */
chain = ik_chain_to_posechain(armob, curBone);
if (!chain)
return;
chain->iterations = data->iterations;
chain->tolerance = data->tolerance;
{
float parmat[4][4];
/* Take the obmat to objectspace */
Mat4CpyMat4 (temp, curBone->obmat);
Mat4One (curBone->obmat);
get_objectspace_bone_matrix(curBone, parmat, 1, 1);
Mat4CpyMat4 (curBone->obmat, temp);
Mat4MulMat4 (totmat, parmat, ob->parent->obmat);
Mat4Invert (imat, totmat);
Mat4CpyMat4 (temp, ob->obmat);
Mat4MulMat4 (ob->obmat, temp, imat);
}
/* Solve it */
if (chain->solver){
VECCOPY (chain->goal, targetmat[3]);
solve_posechain(chain);
}
free_posechain(chain);
{
float parmat[4][4];
/* Take the obmat to worldspace */
Mat4CpyMat4 (temp, curBone->obmat);
Mat4One (curBone->obmat);
get_objectspace_bone_matrix(curBone, parmat, 1, 1);
Mat4CpyMat4 (curBone->obmat, temp);
Mat4MulMat4 (totmat, parmat, ob->parent->obmat);
Mat4CpyMat4 (temp, ob->obmat);
Mat4MulMat4 (ob->obmat, temp, totmat);
}
}
}
break;
case CONSTRAINT_TYPE_FOLLOWPATH:
break;
default:
printf ("Error: Unknown constraint type\n");
break;
}
}
void free_constraint_data (bConstraint *con)
{
if (con->data){
switch (con->type){
default:
break;
};
MEM_freeN (con->data);
}
}
void free_constraints (ListBase *conlist)
{
bConstraint *con;
/* Do any specific freeing */
for (con=conlist->first; con; con=con->next)
{
free_constraint_data (con);
};
/* Free the whole list */
BLI_freelistN(conlist);
}
void free_constraint_channels (ListBase *chanbase)
{
bConstraintChannel *chan;
for (chan=chanbase->first; chan; chan=chan->next)
{
if (chan->ipo){
chan->ipo->id.us--;
}
}
BLI_freelistN(chanbase);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,120 @@
/* deform.c June 2001
*
* support for deformation groups
*
* Reevan McKay
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "DNA_object_types.h"
#include "BKE_deform.h"
void color_temperature (float input, unsigned char *r, unsigned char *g, unsigned char *b)
{
/* blue to red */
float fr = (float)(*r);
float fg = (float)(*g);
float fb = (float)(*b);
if (input < 0.0F)
input = 0.0F;
if (input > 1.0F)
input = 1.0F;
if (input<=0.25f){
fr=0.0f;
fg=255.0f * (input*4.0f);
fb=255.0f;
}
else if (input<=0.50f){
fr=0.0f;
fg=255.0f;
fb=255.0f * (1.0f-((input-0.25f)*4.0f));
}
else if (input<=0.75){
fr=255.0f * ((input-0.50f)*4.0f);
fg=255.0f;
fb=0.0f;
}
else if (input<=1.0){
fr=255.0f;
fg=255.0f * (1.0f-((input-0.75f)*4.0f));
fb=0.0f;
}
(*r) = (unsigned char)(fr * ((input/2.0f)+0.5f));
(*g) = (unsigned char)(fg * ((input/2.0f)+0.5f));
(*b) = (unsigned char)(fb * ((input/2.0f)+0.5f));
};
void copy_defgroups(ListBase *outbase, ListBase *inbase)
{
bDeformGroup *defgroup, *defgroupn;
outbase->first= outbase->last= 0;
for (defgroup = inbase->first; defgroup; defgroup=defgroup->next){
defgroupn= copy_defgroup(defgroup);
BLI_addtail(outbase, defgroupn);
}
}
bDeformGroup* copy_defgroup (bDeformGroup *ingroup)
{
bDeformGroup *outgroup;
if (!ingroup)
return NULL;
outgroup=MEM_callocN(sizeof(bDeformGroup), "deformGroup");
/* For now, just copy everything over. */
memcpy (outgroup, ingroup, sizeof(bDeformGroup));
outgroup->next=outgroup->prev=NULL;
return outgroup;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,854 @@
/* effect.c MIX MODEL
*
* dec 95
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <math.h>
#include <stdlib.h>
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
#include "DNA_effect_types.h"
#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_material_types.h"
#include "DNA_curve_types.h"
#include "DNA_key_types.h"
#include "DNA_texture_types.h"
#include "DNA_scene_types.h"
#include "DNA_lattice_types.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "BLI_rand.h"
#include "BKE_utildefines.h"
#include "BKE_bad_level_calls.h"
#include "BKE_global.h"
#include "BKE_material.h"
#include "BKE_effect.h"
#include "BKE_key.h"
#include "BKE_ipo.h"
#include "BKE_screen.h"
#include "BKE_texture.h"
#include "BKE_blender.h"
#include "BKE_object.h"
#include "BKE_displist.h"
#include "BKE_lattice.h"
Effect *add_effect(int type)
{
Effect *eff=0;
BuildEff *bld;
PartEff *paf;
WaveEff *wav;
int a;
switch(type) {
case EFF_BUILD:
bld= MEM_callocN(sizeof(BuildEff), "neweff");
eff= (Effect *)bld;
bld->sfra= 1.0;
bld->len= 100.0;
break;
case EFF_PARTICLE:
paf= MEM_callocN(sizeof(PartEff), "neweff");
eff= (Effect *)paf;
paf->sta= 1.0;
paf->end= 100.0;
paf->lifetime= 50.0;
for(a=0; a<PAF_MAXMULT; a++) {
paf->life[a]= 50.0;
paf->child[a]= 4;
paf->mat[a]= 1;
}
paf->totpart= 1000;
paf->totkey= 8;
paf->staticstep= 5;
paf->defvec[2]= 1.0f;
paf->nabla= 0.05f;
break;
case EFF_WAVE:
wav= MEM_callocN(sizeof(WaveEff), "neweff");
eff= (Effect *)wav;
wav->flag |= (WAV_X+WAV_Y+WAV_CYCL);
wav->height= 0.5f;
wav->width= 1.5f;
wav->speed= 0.5f;
wav->narrow= 1.5f;
wav->lifetime= 0.0f;
wav->damp= 10.0f;
break;
}
eff->type= eff->buttype= type;
eff->flag |= SELECT;
return eff;
}
void free_effect(Effect *eff)
{
PartEff *paf;
if(eff->type==EFF_PARTICLE) {
paf= (PartEff *)eff;
if(paf->keys) MEM_freeN(paf->keys);
}
MEM_freeN(eff);
}
void free_effects(ListBase *lb)
{
Effect *eff;
eff= lb->first;
while(eff) {
BLI_remlink(lb, eff);
free_effect(eff);
eff= lb->first;
}
}
Effect *copy_effect(Effect *eff)
{
Effect *effn;
effn= MEM_dupallocN(eff);
if(effn->type==EFF_PARTICLE) ((PartEff *)effn)->keys= 0;
return effn;
}
void copy_act_effect(Object *ob)
{
/* return de aktieve eff gekopieerd */
Effect *effn, *eff;
eff= ob->effect.first;
while(eff) {
if(eff->flag & SELECT) {
effn= copy_effect(eff);
BLI_addtail(&ob->effect, effn);
eff->flag &= ~SELECT;
return;
}
eff= eff->next;
}
/* als tie hier komt: new effect */
eff= add_effect(EFF_BUILD);
BLI_addtail(&ob->effect, eff);
}
void copy_effects(ListBase *lbn, ListBase *lb)
{
Effect *eff, *effn;
lbn->first= lbn->last= 0;
eff= lb->first;
while(eff) {
effn= copy_effect(eff);
BLI_addtail(lbn, effn);
eff= eff->next;
}
}
void deselectall_eff(Object *ob)
{
Effect *eff= ob->effect.first;
while(eff) {
eff->flag &= ~SELECT;
eff= eff->next;
}
}
void set_buildvars(Object *ob, int *start, int *end)
{
BuildEff *bld;
float ctime;
bld= ob->effect.first;
while(bld) {
if(bld->type==EFF_BUILD) {
ctime= bsystem_time(ob, 0, (float)G.scene->r.cfra, bld->sfra-1.0f);
if(ctime < 0.0) {
*end= *start;
}
else if(ctime < bld->len) {
*end= *start+ (int)((*end - *start)*ctime/bld->len);
}
return;
}
bld= bld->next;
}
}
/* ***************** PARTICLES ***************** */
Particle *new_particle(PartEff *paf)
{
static Particle *pa;
static int cur;
/* afspraak: als paf->keys==0: alloc */
if(paf->keys==0) {
pa= paf->keys= MEM_callocN( paf->totkey*paf->totpart*sizeof(Particle), "particlekeys" );
cur= 0;
}
else {
if(cur && cur<paf->totpart) pa+=paf->totkey;
cur++;
}
return pa;
}
PartEff *give_parteff(Object *ob)
{
PartEff *paf;
paf= ob->effect.first;
while(paf) {
if(paf->type==EFF_PARTICLE) return paf;
paf= paf->next;
}
return 0;
}
void where_is_particle(PartEff *paf, Particle *pa, float ctime, float *vec)
{
Particle *p[4];
float dt, t[4];
int a;
if(paf->totkey==1) {
VECCOPY(vec, pa->co);
return;
}
/* eerst op zoek naar de eerste particlekey */
a= (int)((paf->totkey-1)*(ctime-pa->time)/pa->lifetime);
if(a>=paf->totkey) a= paf->totkey-1;
pa+= a;
if(a>0) p[0]= pa-1; else p[0]= pa;
p[1]= pa;
if(a+1<paf->totkey) p[2]= pa+1; else p[2]= pa;
if(a+2<paf->totkey) p[3]= pa+2; else p[3]= p[2];
if(p[1]==p[2]) dt= 0.0;
else dt= (ctime-p[1]->time)/(p[2]->time - p[1]->time);
if(paf->flag & PAF_BSPLINE) set_four_ipo(dt, t, KEY_BSPLINE);
else set_four_ipo(dt, t, KEY_CARDINAL);
vec[0]= t[0]*p[0]->co[0] + t[1]*p[1]->co[0] + t[2]*p[2]->co[0] + t[3]*p[3]->co[0];
vec[1]= t[0]*p[0]->co[1] + t[1]*p[1]->co[1] + t[2]*p[2]->co[1] + t[3]*p[3]->co[1];
vec[2]= t[0]*p[0]->co[2] + t[1]*p[1]->co[2] + t[2]*p[2]->co[2] + t[3]*p[3]->co[2];
}
void particle_tex(MTex *mtex, PartEff *paf, float *co, float *no)
{
extern float Tin, Tr, Tg, Tb;
float old;
externtex(mtex, co);
if(paf->texmap==PAF_TEXINT) {
Tin*= paf->texfac;
no[0]+= Tin*paf->defvec[0];
no[1]+= Tin*paf->defvec[1];
no[2]+= Tin*paf->defvec[2];
}
else if(paf->texmap==PAF_TEXRGB) {
no[0]+= (Tr-0.5f)*paf->texfac;
no[1]+= (Tg-0.5f)*paf->texfac;
no[2]+= (Tb-0.5f)*paf->texfac;
}
else { /* PAF_TEXGRAD */
old= Tin;
co[0]+= paf->nabla;
externtex(mtex, co);
no[0]+= (old-Tin)*paf->texfac;
co[0]-= paf->nabla;
co[1]+= paf->nabla;
externtex(mtex, co);
no[1]+= (old-Tin)*paf->texfac;
co[1]-= paf->nabla;
co[2]+= paf->nabla;
externtex(mtex, co);
no[2]+= (old-Tin)*paf->texfac;
}
}
void make_particle_keys(int depth, int nr, PartEff *paf, Particle *part, float *force, int deform, MTex *mtex)
{
Particle *pa, *opa = NULL;
float damp, deltalife;
int b, rt1, rt2;
damp= 1.0f-paf->damp;
pa= part;
/* startsnelheid: random */
if(paf->randfac!=0.0) {
pa->no[0]+= (float)(paf->randfac*( BLI_drand() -0.5));
pa->no[1]+= (float)(paf->randfac*( BLI_drand() -0.5));
pa->no[2]+= (float)(paf->randfac*( BLI_drand() -0.5));
}
/* startsnelheid: texture */
if(mtex && paf->texfac!=0.0) {
particle_tex(mtex, paf, pa->co, pa->no);
}
/* keys */
if(paf->totkey>1) {
deltalife= pa->lifetime/(paf->totkey-1);
opa= pa;
pa++;
b= paf->totkey-1;
while(b--) {
/* nieuwe tijd */
pa->time= opa->time+deltalife;
/* nieuwe plek */
pa->co[0]= opa->co[0] + deltalife*opa->no[0];
pa->co[1]= opa->co[1] + deltalife*opa->no[1];
pa->co[2]= opa->co[2] + deltalife*opa->no[2];
/* nieuwe snelheid */
pa->no[0]= opa->no[0] + deltalife*force[0];
pa->no[1]= opa->no[1] + deltalife*force[1];
pa->no[2]= opa->no[2] + deltalife*force[2];
/* snelheid: texture */
if(mtex && paf->texfac!=0.0) {
particle_tex(mtex, paf, pa->co, pa->no);
}
if(damp!=1.0) {
pa->no[0]*= damp;
pa->no[1]*= damp;
pa->no[2]*= damp;
}
opa= pa;
pa++;
/* opa wordt onderin ook gebruikt */
}
}
if(deform) {
/* alle keys deformen */
pa= part;
b= paf->totkey;
while(b--) {
calc_latt_deform(pa->co);
pa++;
}
}
/* de grote vermenigvuldiging */
if(depth<PAF_MAXMULT && paf->mult[depth]!=0.0) {
/* uit gemiddeld 'mult' deel van de particles ontstaan 'child' nieuwe */
damp = (float)nr;
rt1= (int)(damp*paf->mult[depth]);
rt2= (int)((damp+1.0)*paf->mult[depth]);
if(rt1!=rt2) {
for(b=0; b<paf->child[depth]; b++) {
pa= new_particle(paf);
*pa= *opa;
pa->lifetime= paf->life[depth];
if(paf->randlife!=0.0) {
pa->lifetime*= 1.0f+ (float)(paf->randlife*( BLI_drand() - 0.5));
}
pa->mat_nr= paf->mat[depth];
make_particle_keys(depth+1, b, paf, pa, force, deform, mtex);
}
}
}
}
void init_mv_jit(float *jit, int num)
{
float *jit2, x, rad1, rad2, rad3;
int i;
if(num==0) return;
rad1= (float)(1.0/sqrt((float)num));
rad2= (float)(1.0/((float)num));
rad3= (float)sqrt((float)num)/((float)num);
BLI_srand(31415926 + num);
x= 0;
for(i=0; i<2*num; i+=2) {
jit[i]= x+ (float)(rad1*(0.5-BLI_drand()));
jit[i+1]= ((float)i/2)/num +(float)(rad1*(0.5-BLI_drand()));
jit[i]-= (float)floor(jit[i]);
jit[i+1]-= (float)floor(jit[i+1]);
x+= rad3;
x -= (float)floor(x);
}
jit2= MEM_mallocN(12 + 2*sizeof(float)*num, "initjit");
for (i=0 ; i<4 ; i++) {
RE_jitterate1(jit, jit2, num, rad1);
RE_jitterate1(jit, jit2, num, rad1);
RE_jitterate2(jit, jit2, num, rad2);
}
MEM_freeN(jit2);
}
void give_mesh_mvert(Mesh *me, int nr, float *co, short *no)
{
static float *jit=0;
static int jitlevel=1;
MVert *mvert;
MFace *mface;
float u, v, *v1, *v2, *v3, *v4;
int curface, curjit;
short *n1, *n2, *n3, *n4;
/* signal */
if(me==0) {
if(jit) MEM_freeN(jit);
jit= 0;
return;
}
if(me->totface==0 || nr<me->totvert) {
mvert= me->mvert + (nr % me->totvert);
VECCOPY(co, mvert->co);
VECCOPY(no, mvert->no);
}
else {
nr-= me->totvert;
if(jit==0) {
jitlevel= nr/me->totface;
if(jitlevel==0) jitlevel= 1;
if(jitlevel>100) jitlevel= 100;
jit= MEM_callocN(2+ jitlevel*2*sizeof(float), "jit");
init_mv_jit(jit, jitlevel);
}
curjit= nr/me->totface;
curjit= curjit % jitlevel;
curface= nr % me->totface;
mface= me->mface;
mface+= curface;
v1= (me->mvert+(mface->v1))->co;
v2= (me->mvert+(mface->v2))->co;
n1= (me->mvert+(mface->v1))->no;
n2= (me->mvert+(mface->v2))->no;
if(mface->v3==0) {
v3= (me->mvert+(mface->v2))->co;
v4= (me->mvert+(mface->v1))->co;
n3= (me->mvert+(mface->v2))->no;
n4= (me->mvert+(mface->v1))->no;
}
else if(mface->v4==0) {
v3= (me->mvert+(mface->v3))->co;
v4= (me->mvert+(mface->v1))->co;
n3= (me->mvert+(mface->v3))->no;
n4= (me->mvert+(mface->v1))->no;
}
else {
v3= (me->mvert+(mface->v3))->co;
v4= (me->mvert+(mface->v4))->co;
n3= (me->mvert+(mface->v3))->no;
n4= (me->mvert+(mface->v4))->no;
}
u= jit[2*curjit];
v= jit[2*curjit+1];
co[0]= (float)((1.0-u)*(1.0-v)*v1[0] + (1.0-u)*(v)*v2[0] + (u)*(v)*v3[0] + (u)*(1.0-v)*v4[0]);
co[1]= (float)((1.0-u)*(1.0-v)*v1[1] + (1.0-u)*(v)*v2[1] + (u)*(v)*v3[1] + (u)*(1.0-v)*v4[1]);
co[2]= (float)((1.0-u)*(1.0-v)*v1[2] + (1.0-u)*(v)*v2[2] + (u)*(v)*v3[2] + (u)*(1.0-v)*v4[2]);
no[0]= (short)((1.0-u)*(1.0-v)*n1[0] + (1.0-u)*(v)*n2[0] + (u)*(v)*n3[0] + (u)*(1.0-v)*n4[0]);
no[1]= (short)((1.0-u)*(1.0-v)*n1[1] + (1.0-u)*(v)*n2[1] + (u)*(v)*n3[1] + (u)*(1.0-v)*n4[1]);
no[2]= (short)((1.0-u)*(1.0-v)*n1[2] + (1.0-u)*(v)*n2[2] + (u)*(v)*n3[2] + (u)*(1.0-v)*n4[2]);
}
}
void build_particle_system(Object *ob)
{
Object *par;
PartEff *paf;
Particle *pa;
Mesh *me;
MVert *mvert;
MTex *mtexmove=0;
Material *ma;
float framelenont, ftime, dtime, force[3], imat[3][3], vec[3];
float fac, prevobmat[4][4], sfraont, co[3];
int deform=0, a, cur, cfraont, cfralast, totpart;
short no[3];
if(ob->type!=OB_MESH) return;
me= ob->data;
if(me->totvert==0) return;
ma= give_current_material(ob, 1);
if(ma) {
mtexmove= ma->mtex[7];
}
paf= give_parteff(ob);
if(paf==0) return;
waitcursor(1);
disable_speed_curve(1);
/* alle particles genereren */
if(paf->keys) MEM_freeN(paf->keys);
paf->keys= 0;
new_particle(paf);
cfraont= G.scene->r.cfra;
cfralast= -1000;
framelenont= G.scene->r.framelen;
G.scene->r.framelen= 1.0;
sfraont= ob->sf;
ob->sf= 0.0;
/* mult generaties? */
totpart= paf->totpart;
for(a=0; a<PAF_MAXMULT; a++) {
if(paf->mult[a]!=0.0) {
/* interessante formule! opdezewijze is na 'x' generaties het totale aantal paf->totpart */
totpart= (int)(totpart / (1.0+paf->mult[a]*paf->child[a]));
}
else break;
}
ftime= paf->sta;
dtime= (paf->end - paf->sta)/totpart;
/* hele hiera onthouden */
par= ob;
while(par) {
pushdata(par, sizeof(Object));
par= par->parent;
}
/* alles op eerste frame zetten */
G.scene->r.cfra= cfralast= (int)floor(ftime);
par= ob;
while(par) {
/* do_ob_ipo(par); */
do_ob_key(par);
par= par->parent;
}
do_mat_ipo(ma);
if((paf->flag & PAF_STATIC)==0) {
where_is_object(ob);
Mat4CpyMat4(prevobmat, ob->obmat);
Mat4Invert(ob->imat, ob->obmat);
Mat3CpyMat4(imat, ob->imat);
}
else {
Mat4One(prevobmat);
Mat3One(imat);
}
BLI_srand(paf->seed);
/* gaat anders veuls te hard */
force[0]= paf->force[0]*0.05f;
force[1]= paf->force[1]*0.05f;
force[2]= paf->force[2]*0.05f;
deform= (ob->parent && ob->parent->type==OB_LATTICE);
if(deform) init_latt_deform(ob->parent, 0);
/* init */
give_mesh_mvert(me, totpart, co, no);
for(a=0; a<totpart; a++, ftime+=dtime) {
pa= new_particle(paf);
pa->time= ftime;
/* ob op juiste tijd zetten */
if((paf->flag & PAF_STATIC)==0) {
cur= (int)floor(ftime) + 1 ; /* + 1 heeft een reden: (obmat/prevobmat) anders beginnen b.v. komeetstaartjes te laat */
if(cfralast != cur) {
G.scene->r.cfra= cfralast= cur;
/* later bijgevoegd: blur? */
bsystem_time(ob, ob->parent, (float)G.scene->r.cfra, 0.0);
par= ob;
while(par) {
/* do_ob_ipo(par); */
par->ctime= -1234567.0;
do_ob_key(par);
par= par->parent;
}
do_mat_ipo(ma);
Mat4CpyMat4(prevobmat, ob->obmat);
where_is_object(ob);
Mat4Invert(ob->imat, ob->obmat);
Mat3CpyMat4(imat, ob->imat);
}
}
/* coordinaat ophalen */
if(paf->flag & PAF_FACE) give_mesh_mvert(me, a, co, no);
else {
mvert= me->mvert + (a % me->totvert);
VECCOPY(co, mvert->co);
VECCOPY(no, mvert->no);
}
VECCOPY(pa->co, co);
if(paf->flag & PAF_STATIC);
else {
Mat4MulVecfl(ob->obmat, pa->co);
VECCOPY(vec, co);
Mat4MulVecfl(prevobmat, vec);
/* eerst even startsnelheid: object */
VecSubf(pa->no, pa->co, vec);
VecMulf(pa->no, paf->obfac);
/* nu juiste interframe co berekenen */
fac= (ftime- (float)floor(ftime));
pa->co[0]= fac*pa->co[0] + (1.0f-fac)*vec[0];
pa->co[1]= fac*pa->co[1] + (1.0f-fac)*vec[1];
pa->co[2]= fac*pa->co[2] + (1.0f-fac)*vec[2];
}
/* startsnelheid: normaal */
if(paf->normfac!=0.0) {
/* sp= mvert->no; */
/* transpose ! */
vec[0]= imat[0][0]*no[0] + imat[0][1]*no[1] + imat[0][2]*no[2];
vec[1]= imat[1][0]*no[0] + imat[1][1]*no[1] + imat[1][2]*no[2];
vec[2]= imat[2][0]*no[0] + imat[2][1]*no[1] + imat[2][2]*no[2];
Normalise(vec);
VecMulf(vec, paf->normfac);
VecAddf(pa->no, pa->no, vec);
}
pa->lifetime= paf->lifetime;
if(paf->randlife!=0.0) {
pa->lifetime*= 1.0f+ (float)(paf->randlife*( BLI_drand() - 0.5));
}
pa->mat_nr= 1;
make_particle_keys(0, a, paf, pa, force, deform, mtexmove);
}
if(deform) end_latt_deform();
/* restore */
G.scene->r.cfra= cfraont;
G.scene->r.framelen= framelenont;
give_mesh_mvert(0, 0, 0, 0);
/* hele hiera terug */
par= ob;
while(par) {
popfirst(par);
/* geen ob->ipo doen: insertkey behouden */
do_ob_key(par);
par= par->parent;
}
/* restore: NA popfirst */
ob->sf= sfraont;
disable_speed_curve(0);
waitcursor(0);
}
/* ************* WAVE **************** */
void calc_wave_deform(WaveEff *wav, float ctime, float *co)
{
/* co is in lokale coords */
float lifefac, x, y, amplit;
/* mag eigenlijk niet voorkomen */
if((wav->flag & (WAV_X+WAV_Y))==0) return;
lifefac= wav->height;
if( wav->lifetime!=0.0) {
x= ctime - wav->timeoffs;
if(x>wav->lifetime) {
lifefac= x-wav->lifetime;
if(lifefac > wav->damp) lifefac= 0.0;
else lifefac= (float)(wav->height*(1.0 - sqrt(lifefac/wav->damp)));
}
}
if(lifefac==0.0) return;
x= co[0]-wav->startx;
y= co[1]-wav->starty;
if(wav->flag & WAV_X) {
if(wav->flag & WAV_Y) amplit= (float)sqrt( (x*x + y*y));
else amplit= x;
}
else amplit= y;
/* zo maaktie mooie cirkels */
amplit-= (ctime-wav->timeoffs)*wav->speed;
if(wav->flag & WAV_CYCL) {
amplit = (float)fmod(amplit-wav->width, 2.0*wav->width) + wav->width;
}
/* GAUSSIAN */
if(amplit> -wav->width && amplit<wav->width) {
amplit = amplit*wav->narrow;
amplit= (float)(1.0/exp(amplit*amplit) - wav->minfac);
co[2]+= lifefac*amplit;
}
}
void object_wave(Object *ob)
{
WaveEff *wav;
DispList *dl;
Mesh *me;
MVert *mvert;
float *fp, ctime;
int a, first;
/* is er een mave */
wav= ob->effect.first;
while(wav) {
if(wav->type==EFF_WAVE) break;
wav= wav->next;
}
if(wav==0) return;
if(ob->type==OB_MESH) {
ctime= bsystem_time(ob, 0, (float)G.scene->r.cfra, 0.0);
first= 1;
me= ob->data;
dl= find_displist_create(&ob->disp, DL_VERTS);
if(dl->verts) MEM_freeN(dl->verts);
dl->nr= me->totvert;
dl->verts= MEM_mallocN(3*4*me->totvert, "wave");
wav= ob->effect.first;
while(wav) {
if(wav->type==EFF_WAVE) {
/* voorberekenen */
wav->minfac= (float)(1.0/exp(wav->width*wav->narrow*wav->width*wav->narrow));
if(wav->damp==0) wav->damp= 10.0f;
mvert= me->mvert;
fp= dl->verts;
for(a=0; a<me->totvert; a++, mvert++, fp+=3) {
if(first) VECCOPY(fp, mvert->co);
calc_wave_deform(wav, ctime, fp);
}
first= 0;
}
wav= wav->next;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,656 @@
/* font.c MIXED MODEL
*
* maart 95
*
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
#include "MEM_guardedalloc.h"
#include "BLI_arithb.h"
#include "BLI_blenlib.h"
#include "BLI_vfontdata.h"
#include "DNA_packedFile_types.h"
#include "DNA_curve_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_view3d_types.h"
#include "DNA_vfont_types.h"
#include "DNA_scene_types.h"
#include "BKE_utildefines.h"
#include "BKE_bad_level_calls.h"
#include "BKE_packedFile.h"
#include "BKE_library.h"
#include "BKE_font.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_screen.h"
#include "BKE_anim.h"
#include "BKE_curve.h"
#include "BKE_displist.h"
/* Nieuwe opzet voor vectorfont:
*
* geen PDrawfont meer, alles meteen naar Nurb en BezTriple
*
*/
struct chartrans {
float xof, yof;
float rot;
short linenr,charnr;
};
void free_vfont(struct VFont *vf)
{
int i;
if (vf == 0) return;
if (vf->data) {
for (i = 0; i < MAX_VF_CHARS; i++){
while (vf->data->nurbsbase[i].first) {
Nurb *nu = vf->data->nurbsbase[i].first;
if (nu->bezt) MEM_freeN(nu->bezt);
BLI_freelinkN(&vf->data->nurbsbase[i], nu);
}
}
MEM_freeN(vf->data);
vf->data = NULL;
}
if (vf->packedfile) {
freePackedFile(vf->packedfile);
vf->packedfile = NULL;
}
}
static void *builtin_font_data= NULL;
static int builtin_font_size= 0;
void BKE_font_register_builtin(void *mem, int size)
{
builtin_font_data= mem;
builtin_font_size= size;
}
static PackedFile *get_builtin_packedfile(void)
{
if (!builtin_font_data) {
printf("Internal error, builtin font not loaded");
return NULL;
} else {
void *mem= MEM_mallocN(builtin_font_size, "vfd_builtin");
memcpy(mem, builtin_font_data, builtin_font_size);
return newPackedFileMemory(mem, builtin_font_size);
}
}
static VFontData *vfont_get_data(VFont *vfont)
{
if (!vfont->data) {
PackedFile *pf;
if (BLI_streq(vfont->name, "<builtin>")) {
pf= get_builtin_packedfile();
} else {
if (vfont->packedfile) {
pf= vfont->packedfile;
} else {
pf= newPackedFile(vfont->name);
}
}
if (pf) {
vfont->data= BLI_vfontdata_from_psfont(pf);
if (pf != vfont->packedfile) {
freePackedFile(pf);
}
}
}
return vfont->data;
}
VFont *load_vfont(char *name)
{
char filename[FILE_MAXFILE];
VFont *vfont= NULL;
PackedFile *pf;
int is_builtin;
if (BLI_streq(name, "<builtin>")) {
strcpy(filename, name);
pf= get_builtin_packedfile();
is_builtin= 1;
} else {
char dir[FILE_MAXDIR];
strcpy(dir, name);
BLI_splitdirstring(dir, filename);
pf= newPackedFile(name);
is_builtin= 0;
}
if (pf) {
VFontData *vfd;
waitcursor(1);
vfd= BLI_vfontdata_from_psfont(pf);
if (vfd) {
vfont = alloc_libblock(&G.main->vfont, ID_VF, filename);
vfont->data = vfd;
BLI_strncpy(vfont->name, name, sizeof(vfont->name));
// if autopack is on store the packedfile in de font structure
if (!is_builtin && (G.fileflags & G_AUTOPACK)) {
vfont->packedfile = pf;
}
}
if (!vfont || vfont->packedfile != pf) {
freePackedFile(pf);
}
waitcursor(0);
}
return vfont;
}
static void buildchar(Curve *cu, unsigned char ascii, float ofsx, float ofsy, float rot)
{
BezTriple *bezt1, *bezt2;
Nurb *nu1, *nu2;
float *fp, fsize, shear, x, si, co;
VFontData *vfd;
int i;
vfd= vfont_get_data(cu->vfont);
if (!vfd) return;
/* maak een kopie op afstand ofsx, ofsy met shear*/
fsize= cu->fsize;
shear= cu->shear;
si= (float)sin(rot);
co= (float)cos(rot);
nu1 = vfd->nurbsbase[ascii].first;
while(nu1)
{
bezt1 = nu1->bezt;
if (bezt1){
nu2 =(Nurb*) MEM_mallocN(sizeof(Nurb),"duplichar_nurb");
if (nu2 == 0) break;
memcpy(nu2, nu1, sizeof(struct Nurb));
nu2->resolu= cu->resolu;
nu2->bp = 0;
nu2->knotsu = nu2->knotsv = 0;
nu2->flag= ME_SMOOTH;
/* nu2->trim.first = 0; */
/* nu2->trim.last = 0; */
i = nu2->pntsu;
bezt2 = (BezTriple*)MEM_mallocN(i * sizeof(BezTriple),"duplichar_bezt2");
if (bezt2 == 0){
MEM_freeN(nu2);
break;
}
memcpy(bezt2, bezt1, i * sizeof(struct BezTriple));
nu2->bezt = bezt2;
if (shear != 0.0) {
bezt2 = nu2->bezt;
for (i= nu2->pntsu; i > 0; i--) {
bezt2->vec[0][0] += shear * bezt2->vec[0][1];
bezt2->vec[1][0] += shear * bezt2->vec[1][1];
bezt2->vec[2][0] += shear * bezt2->vec[2][1];
bezt2++;
}
}
if(rot!=0.0) {
bezt2= nu2->bezt;
for (i=nu2->pntsu; i > 0; i--) {
fp= bezt2->vec[0];
x= fp[0];
fp[0]= co*x + si*fp[1];
fp[1]= -si*x + co*fp[1];
x= fp[3];
fp[3]= co*x + si*fp[4];
fp[4]= -si*x + co*fp[4];
x= fp[6];
fp[6]= co*x + si*fp[7];
fp[7]= -si*x + co*fp[7];
bezt2++;
}
}
bezt2 = nu2->bezt;
for (i= nu2->pntsu; i > 0; i--) {
fp= bezt2->vec[0];
fp[0]= (fp[0]+ofsx)*fsize;
fp[1]= (fp[1]+ofsy)*fsize;
fp[3]= (fp[3]+ofsx)*fsize;
fp[4]= (fp[4]+ofsy)*fsize;
fp[6]= (fp[6]+ofsx)*fsize;
fp[7]= (fp[7]+ofsy)*fsize;
bezt2++;
}
BLI_addtail(&(cu->nurb), nu2);
}
nu1 = nu1->next;
}
}
struct chartrans *text_to_curve(Object *ob, int mode)
{
VFont *vfont;
VFontData *vfd;
Curve *cu, *cucu;
struct chartrans *chartransdata, *ct;
float distfac, tabfac, ctime, dtime, tvec[4], vec[4], rotvec[3], minx, maxx, miny, maxy;
float cmat[3][3], timeofs, si, co, sizefac;
float *f, maxlen=0, xof, yof, xtrax, linedist, *linedata, *linedata2;
int i, slen, oldflag;
short cnr=0, lnr=0;
char ascii, *mem;
/* opmerking: berekeningen altijd tot en met de '\0' van de string omdat
de cursor op die plek moet kunnen staan */
if(ob->type!=OB_FONT) return 0;
cu= ob->data;
vfont= cu->vfont;
if (vfont==0) return 0;
if (cu->str==0) return 0;
vfd= vfont_get_data(vfont);
if (!vfd) return 0;
/* aantal regels tellen */
mem= cu->str;
slen = strlen(mem);
cu->lines= 1;
for (i= 0; i<=slen; i++, mem++) {
ascii = *mem;
if(ascii== '\n' || ascii== '\r') cu->lines++;
}
/* bereken ofset en rotatie van iedere letter */
ct = chartransdata =
(struct chartrans*)MEM_callocN((slen+1)* sizeof(struct chartrans),"buildtext");
linedata= MEM_mallocN(sizeof(float)*cu->lines,"buildtext2");
linedata2= MEM_mallocN(sizeof(float)*cu->lines,"buildtext2");
xof= cu->xof;
yof= cu->yof;
xtrax= 0.5f*cu->spacing-0.5f;
linedist= cu->linedist;
for (i = 0 ; i<=slen ; i++) {
ascii = cu->str[i];
if(ascii== '\n' || ascii== '\r' || ascii==0) {
ct->xof= xof;
ct->yof= yof;
ct->linenr= lnr;
ct->charnr= cnr;
/* alleen lege regels mogen kleiner dan 1 zijn */
if( linedist<1.0) {
if(i<slen && (cu->str[i+1]=='\r' || cu->str[i+1]=='\n')) yof-= linedist;
else yof-= 1.0;
}
else yof-= linedist;
maxlen= MAX2(maxlen, xof);
linedata[lnr]= xof;
linedata2[lnr]= cnr;
xof= cu->xof;
lnr++;
cnr= 0;
}
else if(ascii==9) { /* TAB */
ct->xof= xof;
ct->yof= yof;
ct->linenr= lnr;
ct->charnr= cnr++;
tabfac= (xof-cu->xof+0.01f);
tabfac= (float)(2.0*ceil(tabfac/2.0));
xof= cu->xof+tabfac;
}
else {
ct->xof= xof;
ct->yof= yof;
ct->linenr= lnr;
ct->charnr= cnr++;
xof += vfd->width[ascii] + xtrax;
}
ct++;
}
/* met alle fontsettings plekken letters berekenen */
if(cu->spacemode!=CU_LEFT && lnr>1) {
ct= chartransdata;
if(cu->spacemode==CU_RIGHT) {
for(i=0;i<lnr;i++) linedata[i]= maxlen-linedata[i];
for (i=0; i<=slen; i++) {
ct->xof+= linedata[ct->linenr];
ct++;
}
} else if(cu->spacemode==CU_MIDDLE) {
for(i=0;i<lnr;i++) linedata[i]= (maxlen-linedata[i])/2;
for (i=0; i<=slen; i++) {
ct->xof+= linedata[ct->linenr];
ct++;
}
} else if(cu->spacemode==CU_FLUSH) {
for(i=0;i<lnr;i++)
if(linedata2[i]>1)
linedata[i]= (maxlen-linedata[i])/(linedata2[i]-1);
for (i=0; i<=slen; i++) {
ct->xof+= ct->charnr*linedata[ct->linenr];
ct++;
}
}
}
/* TEXT ON CURVE */
if(cu->textoncurve) {
cucu= cu->textoncurve->data;
oldflag= cucu->flag;
cucu->flag |= (CU_PATH+CU_FOLLOW);
if(cucu->path==0) calc_curvepath(cu->textoncurve);
if(cucu->path) {
Mat3CpyMat4(cmat, cu->textoncurve->obmat);
sizefac= Normalise(cmat[0])/cu->fsize;
minx=miny= 1.0e20f;
maxx=maxy= -1.0e20f;
ct= chartransdata;
for (i=0; i<=slen; i++, ct++) {
if(minx>ct->xof) minx= ct->xof;
if(maxx<ct->xof) maxx= ct->xof;
if(miny>ct->yof) miny= ct->yof;
if(maxy<ct->yof) maxy= ct->yof;
}
/* we zetten de x-coordinaat exact op de curve, de y wordt geroteerd */
/* de lengte correctie */
distfac= sizefac*cucu->path->totdist/(maxx-minx);
timeofs= 0.0;
if(distfac > 1.0) {
/* pad langer dan tekst: spacemode doet mee */
distfac= 1.0f/distfac;
if(cu->spacemode==CU_RIGHT) {
timeofs= 1.0f-distfac;
}
else if(cu->spacemode==CU_MIDDLE) {
timeofs= (1.0f-distfac)/2.0f;
}
else if(cu->spacemode==CU_FLUSH) distfac= 1.0f;
}
else distfac= 1.0;
distfac/= (maxx-minx);
timeofs+= distfac*cu->xof; /* niet cyclic */
ct= chartransdata;
for (i=0; i<=slen; i++, ct++) {
/* roteren rond centrum letter */
ascii = cu->str[i];
dtime= distfac*0.35f*vfd->width[ascii]; /* Waarom is 0.5 te groot? */
dtime= distfac*0.0f*vfd->width[ascii]; /* Waarom is 0.5 te groot? */
ctime= timeofs + distfac*( ct->xof - minx);
CLAMP(ctime, 0.0, 1.0);
/* de goede plek EN de goede rotatie apart berekenen */
where_on_path(cu->textoncurve, ctime, vec, tvec);
where_on_path(cu->textoncurve, ctime+dtime, tvec, rotvec);
VecMulf(vec, sizefac);
ct->rot= (float)(M_PI-atan2(rotvec[1], rotvec[0]));
si= (float)sin(ct->rot);
co= (float)cos(ct->rot);
yof= ct->yof;
ct->xof= vec[0] + si*yof;
ct->yof= vec[1] + co*yof;
}
cucu->flag= oldflag;
}
}
if(mode==FO_CURSUP || mode==FO_CURSDOWN) {
/* 2: curs omhoog
3: curs omlaag */
ct= chartransdata+cu->pos;
if(mode==FO_CURSUP && ct->linenr==0);
else if(mode==FO_CURSDOWN && ct->linenr==lnr);
else {
if(mode==FO_CURSUP) lnr= ct->linenr-1;
else lnr= ct->linenr+1;
cnr= ct->charnr;
/* zoek karakter met lnr en cnr */
cu->pos= 0;
ct= chartransdata;
for (i= 0; i<slen; i++) {
if(ct->linenr==lnr) {
if(ct->charnr==cnr) break;
if( (ct+1)->charnr==0) break;
}
else if(ct->linenr>lnr) break;
cu->pos++;
ct++;
}
}
}
/* eerst cursor */
if(ob==G.obedit) {
ct= chartransdata+cu->pos;
si= (float)sin(ct->rot);
co= (float)cos(ct->rot);
f= G.textcurs[0];
f[0]= cu->fsize*(-0.1f*co + ct->xof);
f[1]= cu->fsize*(0.1f*si + ct->yof);
f[2]= cu->fsize*(0.1f*co + ct->xof);
f[3]= cu->fsize*(-0.1f*si + ct->yof);
f[4]= cu->fsize*( 0.1f*co + 0.8f*si + ct->xof);
f[5]= cu->fsize*(-0.1f*si + 0.8f*co + ct->yof);
f[6]= cu->fsize*(-0.1f*co + 0.8f*si + ct->xof);
f[7]= cu->fsize*( 0.1f*si + 0.8f*co + ct->yof);
}
if(mode==0) {
/* nurbdata maken */
freeNurblist(&cu->nurb);
ct= chartransdata;
for (i= 0; i<slen; i++) {
ascii = cu->str[i];
buildchar(cu, ascii, ct->xof, ct->yof, ct->rot);
ct++;
}
}
MEM_freeN(linedata);
MEM_freeN(linedata2);
if(mode==FO_DUPLI) {
return chartransdata;
}
MEM_freeN(chartransdata);
return 0;
}
/* ***************** DUPLI ***************** */
static Object *find_family_object(Object **obar, char *family, char ch)
{
Object *ob;
int flen;
if( obar[ch] ) return obar[ch];
flen= strlen(family);
ob= G.main->object.first;
while(ob) {
if( ob->id.name[flen+2]==ch ) {
if( strncmp(ob->id.name+2, family, flen)==0 ) break;
}
ob= ob->id.next;
}
obar[ch]= ob;
return ob;
}
void font_duplilist(Object *par)
{
extern ListBase duplilist;
Object *ob, *newob, *obar[256];
Curve *cu;
struct chartrans *ct, *chartransdata;
float vec[3], pmat[4][4], fsize, xof, yof;
int slen, a;
Mat4CpyMat4(pmat, par->obmat);
/* in par staat een familienaam, deze gebruiken om objecten te vinden */
chartransdata= text_to_curve(par, FO_DUPLI);
if(chartransdata==0) return;
memset(obar, 0, 256*4);
cu= par->data;
slen= strlen(cu->str);
fsize= cu->fsize;
xof= cu->xof;
yof= cu->yof;
ct= chartransdata;
set_displist_onlyzero(1);
for(a=0; a<slen; a++, ct++) {
ob= find_family_object(obar, cu->family, cu->str[a]);
if(ob) {
makeDispList(ob);
vec[0]= fsize*(ct->xof - xof);
vec[1]= fsize*(ct->yof - yof);
vec[2]= 0.0;
Mat4MulVecfl(pmat, vec);
newob= MEM_mallocN(sizeof(Object), "newobj dupli");
memcpy(newob, ob, sizeof(Object));
newob->flag |= OB_FROMDUPLI;
newob->id.newid= (ID *)par; /* duplicator bewaren */
newob->totcol= par->totcol; /* voor give_current_material */
Mat4CpyMat4(newob->obmat, par->obmat);
VECCOPY(newob->obmat[3], vec);
newob->parent= 0;
newob->track= 0;
BLI_addtail(&duplilist, newob);
}
}
set_displist_onlyzero(0);
MEM_freeN(chartransdata);
}

View File

@@ -0,0 +1,329 @@
/* group.c sept 2000
* - cleaned up mar-01 nzc
*
*
* ton roosendaal
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <stdio.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_ID.h"
#include "DNA_group_types.h"
#include "DNA_object_types.h"
#include "DNA_ipo_types.h"
#include "BLI_blenlib.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_library.h"
#include "BKE_group.h"
#include "BKE_object.h"
#include "BKE_ipo.h"
void free_object_key(ObjectKey *ok)
{
if(ok->ipo) ok->ipo->id.us--;
MEM_freeN(ok);
}
void free_group_object(GroupObject *go)
{
ObjectKey *ok;
while(go->okey.first) {
ok= go->okey.first;
BLI_remlink(&go->okey, ok);
free_object_key(ok);
}
MEM_freeN(go);
}
void free_group(Group *group)
{
/* don't free group itself */
GroupObject *go;
BLI_freelistN(&group->gkey);
while(group->gobject.first) {
go= group->gobject.first;
BLI_remlink(&group->gobject, go);
free_group_object(go);
}
}
Group *add_group()
{
Group *group;
group = alloc_libblock(&G.main->group, ID_GR, "Group");
return group;
}
/* assumes 'ok' is unitialized */
void object_to_obkey(Object *ob, ObjectKey *ok)
{
ok->partype= ob->partype;
ok->par1= ob->par1;
ok->par2= ob->par2;
ok->par3= ob->par3;
ok->parent= ob->parent;
ok->track= ob->track;
ok->ipo= copy_ipo(ob->ipo);
memcpy(ok->loc, ob->loc, 7*3*sizeof(float));
memcpy(ok->quat, ob->quat, 2*4*sizeof(float));
memcpy(ok->obmat, ob->obmat, 3*4*4*sizeof(float));
ok->lay= ob->lay;
ok->transflag= ob->transflag;
ok->trackflag= ob->transflag;
ok->upflag= ob->upflag;
ok->sf= ob->sf;
ok->ctime= ob->ctime;
}
void obkey_to_object(ObjectKey *ok, Object *ob)
{
ob->partype= ok->partype;
ob->par1= ok->par1;
ob->par2= ok->par2;
ob->par3= ok->par3;
ob->parent= ok->parent;
ob->track= ok->track;
/* pretty tricky, this makes ob->ipo blocks with users 'hanging around' */
if(ob->ipo) {
free_libblock_us(&G.main->ipo, ob->ipo);
}
ob->ipo= copy_ipo(ok->ipo);
memcpy(ob->loc, ok->loc, 7*3*sizeof(float));
memcpy(ob->quat, ok->quat, 2*4*sizeof(float));
memcpy(ob->obmat, ok->obmat, 3*4*4*sizeof(float));
ob->lay= ok->lay;
ob->transflag= ok->transflag;
ob->trackflag= ok->transflag;
ob->upflag= ok->upflag;
ob->sf= ok->sf;
ob->ctime= ok->ctime;
}
/* current ob position */
void add_object_key(GroupObject *go, GroupKey *gk)
{
ObjectKey *ok;
/* check if there already is a key */
ok= go->okey.first;
while(ok) {
if(ok->gkey == gk) break;
ok= ok->next;
}
if(ok) {
BLI_remlink(&go->okey, ok);
free_object_key(ok);
}
ok= MEM_mallocN(sizeof(ObjectKey), "objectkey");
ok->gkey= gk;
object_to_obkey(go->ob, ok);
BLI_addtail(&go->okey, ok);
}
/* external */
void add_to_group(Group *group, Object *ob)
{
GroupObject *go;
GroupKey *gk;
/* check if the object has been added already */
go= group->gobject.first;
while(go) {
if(go->ob==ob) return;
go= go->next;
}
go= MEM_callocN(sizeof(GroupObject), "groupobject");
BLI_addtail( &group->gobject, go);
go->ob= ob;
/* keys? */
gk= group->gkey.first;
while(gk) {
add_object_key(go, gk);
gk= gk->next;
}
}
void rem_from_group(Group *group, Object *ob)
{
GroupObject *go, *gon;
ObjectKey *ok;
go= group->gobject.first;
while(go) {
gon= go->next;
if(go->ob==ob) {
BLI_remlink(&group->gobject, go);
free_group_object(go);
}
else {
ok= go->okey.first;
while(ok) {
if(ok->parent==ob) ok->parent= NULL;
if(ok->track==ob) ok->track= NULL;
ok= ok->next;
}
}
go= gon;
}
}
void add_group_key(Group *group)
{
GroupObject *go;
GroupKey *gk;
int nr=10;
extern char colname_array[][20]; /* material.c */
gk= group->gkey.first;
while(gk) {
nr++;
gk= gk->next;
}
gk= MEM_callocN(sizeof(GroupKey), "groupkey");
BLI_addtail(&group->gkey, gk);
strcpy(gk->name, colname_array[ nr % 120 ]);
go= group->gobject.first;
while(go) {
add_object_key(go, gk);
go= go->next;
}
group->active= gk;
}
void set_object_key(Object *ob, ObjectKey *ok)
{
obkey_to_object(ok, ob);
}
void set_group_key(Group *group)
{
/* sets active */
GroupObject *go;
ObjectKey *ok;
if(group->active==NULL) return;
go= group->gobject.first;
while(go) {
ok= go->okey.first;
while(ok) {
if(ok->gkey==group->active) {
set_object_key(go->ob, ok);
break;
}
ok= ok->next;
}
go= go->next;
}
}
Group *find_group(Object *ob)
{
Group *group= G.main->group.first;
GroupObject *go;
while(group) {
go= group->gobject.first;
while(go) {
if(go->ob==ob) return group;
go= go->next;
}
group= group->id.next;
}
return NULL;
}
void set_group_key_name(Group *group, char *name)
{
GroupKey *gk;
if(group==NULL) return;
gk= group->gkey.first;
while(gk) {
if(strcmp(name, gk->name)==0) break;
gk= gk->next;
}
if(gk) {
group->active= gk;
set_group_key(group);
}
}
void set_group_key_frame(Group *group, float frame)
{
GroupObject *go;
if(group==NULL) return;
go= group->gobject.first;
while(go) {
where_is_object_time(go->ob, frame);
go= go->next;
}
}

View File

@@ -0,0 +1,596 @@
/* ika.c MIXED MODEL
*
* april 96
*
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <math.h>
#include <stdlib.h>
#include "MEM_guardedalloc.h"
/* types */
#include "DNA_ika_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_view3d_types.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
/* functions */
#include "BKE_blender.h"
#include "BKE_library.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_ika.h"
/* Let's go! */
#define TOLER 0.000076
#define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c)
void unlink_ika(Ika *ika)
{
/* loskoppelen: */
}
/* niet Ika zelf vrijgeven */
void free_ika(Ika *ika)
{
/* unimplemented!!! */
unlink_ika(ika);
BLI_freelistN(&ika->limbbase);
if(ika->def) MEM_freeN(ika->def);
}
Ika *add_ika()
{
Ika *ika;
ika= alloc_libblock(&G.main->ika, ID_IK, "Ika");
ika->flag = IK_GRABEFF | IK_XYCONSTRAINT;
ika->xyconstraint= 0.5f;
ika->mem= 0.3f;
ika->iter= 6;
return ika;
}
Ika *copy_ika(Ika *ika)
{
Ika *ikan;
ikan= copy_libblock(ika);
duplicatelist(&ikan->limbbase, &ika->limbbase);
ikan->def= MEM_dupallocN(ikan->def);
return ikan;
}
void make_local_ika(Ika *ika)
{
Object *ob;
Ika *ikan;
int local=0, lib=0;
/* - zijn er alleen lib users: niet doen
* - zijn er alleen locale users: flag zetten
* - mixed: copy
*/
if(ika->id.lib==0) return;
if(ika->id.us==1) {
ika->id.lib= 0;
ika->id.flag= LIB_LOCAL;
new_id(0, (ID *)ika, 0);
return;
}
ob= G.main->object.first;
while(ob) {
if(ob->data==ika) {
if(ob->id.lib) lib= 1;
else local= 1;
}
ob= ob->id.next;
}
if(local && lib==0) {
ika->id.lib= 0;
ika->id.flag= LIB_LOCAL;
new_id(0, (ID *)ika, 0);
}
else if(local && lib) {
ikan= copy_ika(ika);
ikan->id.us= 0;
ob= G.main->object.first;
while(ob) {
if(ob->data==ika) {
if(ob->id.lib==0) {
ob->data= ikan;
ikan->id.us++;
ika->id.us--;
}
}
ob= ob->id.next;
}
}
}
int count_limbs(Object *ob)
{
int tot=0;
Ika *ika;
Limb *li;
if(ob->type!=OB_IKA) return 0;
ika= ob->data;
li= ika->limbbase.first;
while(li) {
tot++;
li= li->next;
}
return tot;
}
/* ************************************************** */
/* aan hand van eff[] de len en alpha */
void calc_limb(Limb *li)
{
Limb *prev= li;
float vec[2], alpha= 0.0;
/* alpha van 'parents' */
while( (prev=prev->prev) ) {
alpha+= prev->alpha;
}
if(li->prev) {
vec[0]= -li->prev->eff[0];
vec[1]= -li->prev->eff[1];
}
else vec[0]= vec[1]= 0.0;
vec[0]+= li->eff[0];
vec[1]+= li->eff[1];
li->alpha= (float)atan2(vec[1], vec[0]) - alpha;
li->len= (float)sqrt(vec[0]*vec[0] + vec[1]*vec[1]);
}
/* aan hand van len en alpha worden de eindpunten berekend */
void calc_ika(Ika *ika, Limb *li)
{
float alpha=0.0, co, si;
if(li) {
Limb *prev= li;
while((prev=prev->prev)) {
alpha+= prev->alpha;
}
}
else li= ika->limbbase.first;
while(li) {
if(li->alpha != li->alpha) li->alpha= 0.0f; /* NaN patch */
alpha+= li->alpha;
co= (float)cos(alpha);
si= (float)sin(alpha);
li->eff[0]= co*li->len;
li->eff[1]= si*li->len;
if(li->prev) {
li->eff[0]+= li->prev->eff[0];
li->eff[1]+= li->prev->eff[1];
}
if(li->next==0) {
ika->eff[0]= li->eff[0];
ika->eff[1]= li->eff[1];
}
li= li->next;
}
}
void init_defstate_ika(Object *ob)
{
Ika *ika;
Limb *li;
ika= ob->data;
ika->totx= 0.0;
ika->toty= 0.0;
li= ika->limbbase.first;
calc_ika(ika, 0); /* correcte eindpunten */
while(li) {
li->alphao= li->alpha;
li->leno= li->len;
li= li->next;
}
ika->eff[2]= 0.0;
VecMat4MulVecfl(ika->effg, ob->obmat, ika->eff);
}
void itterate_limb(Ika *ika, Limb *li)
{
float da, n1[2], n2[2], len1, len2;
if(li->prev) {
n1[0]= ika->eff[0] - li->prev->eff[0];
n1[1]= ika->eff[1] - li->prev->eff[1];
n2[0]= ika->effn[0] - li->prev->eff[0];
n2[1]= ika->effn[1] - li->prev->eff[1];
}
else {
n1[0]= ika->eff[0];
n1[1]= ika->eff[1];
n2[0]= ika->effn[0];
n2[1]= ika->effn[1];
}
len1= (float)sqrt(n1[0]*n1[0] + n1[1]*n1[1]);
len2= (float)sqrt(n2[0]*n2[0] + n2[1]*n2[1]);
da= (1.0f-li->fac)*saacos( (n1[0]*n2[0]+n1[1]*n2[1])/(len1*len2) );
if(n1[0]*n2[1] < n1[1]*n2[0]) da= -da;
li->alpha+= da;
}
void rotate_ika(Object *ob, Ika *ika)
{
Limb *li;
float len2, da, n1[2], n2[2];
/* terug roteren */
euler_rot(ob->rot, -ika->toty, 'y');
ika->toty= 0.0;
where_is_object(ob);
Mat4Invert(ob->imat, ob->obmat);
VecMat4MulVecfl(ika->effn, ob->imat, ika->effg);
li= ika->limbbase.last;
if(li==0) return;
n1[0]= ika->eff[0];
n2[0]= ika->effn[0];
n2[1]= ika->effn[2];
len2= (float)sqrt(n2[0]*n2[0] + n2[1]*n2[1]);
if(len2>TOLER) {
da= (n2[0])/(len2);
if(n1[0]<0.0) da= -da;
/* als de x comp bijna nul is kan dit gebeuren */
if(da<=-1.0+TOLER || da>=1.0) ;
else {
da= saacos( da );
if(n1[0]*n2[1] > 0.0) da= -da;
euler_rot(ob->rot, da, 'y');
ika->toty= da;
}
}
}
void rotate_ika_xy(Object *ob, Ika *ika)
{
Limb *li;
float ang, da, n1[3], n2[3], axis[3], quat[4];
/* terug roteren */
euler_rot(ob->rot, -ika->toty, 'y');
euler_rot(ob->rot, -ika->totx, 'x');
where_is_object(ob);
Mat4Invert(ob->imat, ob->obmat);
VecMat4MulVecfl(ika->effn, ob->imat, ika->effg);
li= ika->limbbase.last;
if(li==0) return;
/* ika->eff = old situation */
/* ika->effn = desired situation */
*(n1)= *(ika->effn);
*(n1+1)= *(ika->effn+1);
*(n1+2)= 0.0;
*(n2)= *(ika->effn);
*(n2+1)= *(ika->effn+1);
*(n2+2)= *(ika->effn+2);
Normalise(n1);
Normalise(n2);
ang= n1[0]*n2[0] + n1[1]*n2[1] + n1[2]*n2[2];
ang= saacos(ang);
if(ang<-0.0000001 || ang>0.00000001) {
Crossf(axis, n1, n2);
Normalise(axis);
quat[0]= (float)cos(0.5*ang);
da= (float)sin(0.5*ang);
quat[1]= da*axis[0];
quat[2]= da*axis[1];
quat[3]= da*axis[2];
QuatToEul(quat, axis);
ika->totx= axis[0];
CLAMP(ika->totx, -ika->xyconstraint, ika->xyconstraint);
ika->toty= axis[1];
CLAMP(ika->toty, -ika->xyconstraint, ika->xyconstraint);
}
euler_rot(ob->rot, ika->totx, 'x');
euler_rot(ob->rot, ika->toty, 'y');
}
void itterate_ika(Object *ob)
{
Ika *ika;
Limb *li;
int it = 0;
ika= ob->data;
if((ika->flag & IK_GRABEFF)==0) return;
disable_where_script(1);
/* memory: grote tijdsprongen afvangen */
it= abs(ika->lastfra - G.scene->r.cfra);
ika->lastfra= G.scene->r.cfra;
if(it>10) {
/* one itteration extra */
itterate_ika(ob);
}
else {
li= ika->limbbase.first;
while(li) {
li->alpha= (1.0f-ika->mem)*li->alpha + ika->mem*li->alphao;
if(li->fac==1.0f) li->fac= 0.05f; /* oude files: kan weg in juni 96 */
li= li->next;
}
}
calc_ika(ika, 0);
/* effector heeft parent? */
if(ika->parent) {
if(ika->partype==PAROBJECT) {
if(ika->parent->ctime != (float) G.scene->r.cfra) where_is_object(ika->parent);
*(ika->effg)= *(ika->parent->obmat[3]);
*(ika->effg+1)= *(ika->parent->obmat[3]+1);
*(ika->effg+2)= *(ika->parent->obmat[3]+2);
}
else {
what_does_parent1(ika->parent, ika->partype, ika->par1, 0, 0);
*(ika->effg)= *(workob.obmat[3]);
*(ika->effg+1)= *(workob.obmat[3]+1);
*(ika->effg+2)= *(workob.obmat[3]+2);
}
}
/* y-as goed draaien */
if(ika->flag & IK_XYCONSTRAINT)
rotate_ika_xy(ob, ika);
else
rotate_ika(ob, ika);
it= ika->iter;
while(it--) {
where_is_object(ob);
Mat4Invert(ob->imat, ob->obmat);
VecMat4MulVecfl(ika->effn, ob->imat, ika->effg);
/* forward: dan gaan ook de eerste limbs */
li= ika->limbbase.first;
while(li) {
itterate_limb(ika, li);
/* zet je calc_ika() buiten deze lus: lange kettingen instabiel */
calc_ika(ika, li);
li= li->next;
}
where_is_object(ob);
Mat4Invert(ob->imat, ob->obmat);
VecMat4MulVecfl(ika->effn, ob->imat, ika->effg);
/* backward */
li= ika->limbbase.last;
while(li) {
itterate_limb(ika, li);
/* zet je calc_ika() buiten deze lus: lange kettingen instabiel */
calc_ika(ika, li);
li= li->prev;
}
}
disable_where_script(0);
}
void do_all_ikas()
{
Base *base = 0;
base= G.scene->base.first;
while(base) {
if(base->object->type==OB_IKA) itterate_ika(base->object);
base= base->next;
}
}
void do_all_visible_ikas()
{
Base *base = 0;
base= G.scene->base.first;
while(base) {
if(base->lay & G.scene->lay) {
if(base->object->type==OB_IKA) itterate_ika(base->object);
}
base= base->next;
}
}
/* ******************** DEFORM ************************ */
void init_skel_deform(Object *par, Object *ob)
{
Deform *def;
Ika *ika;
int a;
/* deform:
*
* ob_vec * ob_obmat * def_imat (weight fie) * def_obmat * ob_imat = ob_vec'
*
* <----- premat ----> <---- postmat ---->
*/
if(par->type!=OB_IKA) return;
Mat4Invert(ob->imat, ob->obmat);
ika= par->data;
a= ika->totdef;
def= ika->def;
while(a--) {
what_does_parent1(def->ob, def->partype, def->par1, def->par2, def->par3);
Mat4MulMat4(def->premat, ob->obmat, def->imat);
Mat4MulMat4(def->postmat, workob.obmat, ob->imat);
def++;
}
}
void calc_skel_deform(Ika *ika, float *co)
{
Deform *def;
int a;
float totw=0.0, weight, fac, len, vec[3], totvec[3];
def= ika->def;
if(def==0) return;
a= ika->totdef;
totvec[0]=totvec[1]=totvec[2]= 0.0;
while(a--) {
VecMat4MulVecfl(vec, def->premat, co);
len= (float)sqrt(vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2]);
if(def->vec[0]==0.0f) len= 2.0f*len;
else len= len + (float)sqrt( (vec[0]+def->vec[0])*(vec[0]+def->vec[0]) + vec[1]*vec[1] + vec[2]*vec[2]);
/* def->vec[0]= len limb */
weight= 1.0f/(0.001f+len);
weight*= weight;
weight*= weight;
weight*= def->fac;
len -= def->vec[0];
if(def->dist != 0.0) {
if(len >= def->dist) {
weight= 0.0;
}
else {
fac= (def->dist - len)/def->dist;
weight*= fac;
}
}
if(weight > 0.0) {
Mat4MulVecfl(def->postmat, vec);
VecMulf(vec, weight);
VecAddf(totvec, totvec, vec);
totw+= weight;
}
def++;
}
if(totw==0.0) return;
co[0]= totvec[0]/totw;
co[1]= totvec[1]/totw;
co[2]= totvec[2]/totw;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,633 @@
/**
* lattice.c MIXED MODEL
* june 2001 ton
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "DNA_armature_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_lattice_types.h"
#include "DNA_curve_types.h"
#include "DNA_key_types.h"
#include "DNA_ika_types.h"
#include "BKE_utildefines.h"
#include "BKE_armature.h"
#include "BKE_library.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_screen.h"
#include "BKE_displist.h"
#include "BKE_lattice.h"
#include "BKE_key.h"
#include "BKE_object.h"
#include "BKE_ika.h"
Lattice *editLatt=0, *deformLatt=0;
float *latticedata=0, latmat[4][4];
int lt_applyflag= 0;
void resizelattice(Lattice *lt)
{
BPoint *bp;
int u, v, w;
float vec[3], fu, fv, fw, du=0.0, dv=0.0, dw=0.0;
MEM_freeN(lt->def);
lt->def= MEM_callocN(lt->pntsu*lt->pntsv*lt->pntsw*sizeof(BPoint), "lattice bp");
bp= lt->def;
while(lt->pntsu*lt->pntsv*lt->pntsw > 32000) {
if( lt->pntsu>=lt->pntsv && lt->pntsu>=lt->pntsw) lt->pntsu--;
else if( lt->pntsv>=lt->pntsu && lt->pntsv>=lt->pntsw) lt->pntsv--;
else lt->pntsw--;
}
calc_lat_fudu(lt->flag, lt->pntsu, &fu, &du);
calc_lat_fudu(lt->flag, lt->pntsv, &fv, &dv);
calc_lat_fudu(lt->flag, lt->pntsw, &fw, &dw);
vec[2]= fw;
for(w=0; w<lt->pntsw; w++) {
vec[1]= fv;
for(v=0; v<lt->pntsv; v++) {
vec[0]= fu;
for(u=0; u<lt->pntsu; u++, bp++) {
VECCOPY(bp->vec, vec);
vec[0]+= du;
}
vec[1]+= dv;
}
vec[2]+= dw;
}
}
Lattice *add_lattice()
{
Lattice *lt;
lt= alloc_libblock(&G.main->latt, ID_LT, "Lattice");
lt->pntsu=lt->pntsv=lt->pntsw= 2;
lt->flag= LT_GRID;
lt->typeu= lt->typev= lt->typew= KEY_BSPLINE;
/* tijdelijk */
lt->def= MEM_callocN(sizeof(BPoint), "lattvert");
resizelattice(lt); /* maakt een regelmatige lattice */
return lt;
}
Lattice *copy_lattice(Lattice *lt)
{
Lattice *ltn;
ltn= copy_libblock(lt);
ltn->def= MEM_dupallocN(lt->def);
id_us_plus((ID *)ltn->ipo);
ltn->key= copy_key(ltn->key);
if(ltn->key) ltn->key->from= (ID *)ltn;
return ltn;
}
void free_lattice(Lattice *lt)
{
if(lt->def) MEM_freeN(lt->def);
}
void make_local_lattice(Lattice *lt)
{
Object *ob;
Lattice *ltn;
int local=0, lib=0;
/* - zijn er alleen lib users: niet doen
* - zijn er alleen locale users: flag zetten
* - mixed: copy
*/
if(lt->id.lib==0) return;
if(lt->id.us==1) {
lt->id.lib= 0;
lt->id.flag= LIB_LOCAL;
new_id(0, (ID *)lt, 0);
return;
}
ob= G.main->object.first;
while(ob) {
if(ob->data==lt) {
if(ob->id.lib) lib= 1;
else local= 1;
}
ob= ob->id.next;
}
if(local && lib==0) {
lt->id.lib= 0;
lt->id.flag= LIB_LOCAL;
new_id(0, (ID *)lt, 0);
}
else if(local && lib) {
ltn= copy_lattice(lt);
ltn->id.us= 0;
ob= G.main->object.first;
while(ob) {
if(ob->data==lt) {
if(ob->id.lib==0) {
ob->data= ltn;
ltn->id.us++;
lt->id.us--;
}
}
ob= ob->id.next;
}
}
}
void calc_lat_fudu(int flag, int res, float *fu, float *du)
{
if(res==1) {
*fu= 0.0;
*du= 0.0;
}
else if(flag & LT_GRID) {
*fu= -0.5f*(res-1);
*du= 1.0f;
}
else {
*fu= -1.0f;
*du= 2.0f/(res-1);
}
}
void init_latt_deform(Object *oblatt, Object *ob)
{
/* we maken een array met alle verschillen */
BPoint *bp;
float *fp, imat[4][4];
float vec[3], fu, fv, fw, du=0.0, dv=0.0, dw=0.0;
int u, v, w;
if(oblatt==G.obedit) deformLatt= editLatt;
else deformLatt= oblatt->data;
fp= latticedata= MEM_mallocN(sizeof(float)*3*deformLatt->pntsu*deformLatt->pntsv*deformLatt->pntsw, "latticedata");
bp= deformLatt->def;
if(ob) where_is_object(ob);
/* bijv bij particle systeem: ob==0 */
if(ob==0) {
/* in deformspace, matrix berekenen */
Mat4Invert(latmat, oblatt->obmat);
/* terug: in deform array verwerken */
Mat4Invert(imat, latmat);
}
else {
/* in deformspace, matrix berekenen */
Mat4Invert(imat, oblatt->obmat);
Mat4MulMat4(latmat, ob->obmat, imat);
/* terug: in deform array verwerken */
Mat4Invert(imat, latmat);
}
calc_lat_fudu(deformLatt->flag, deformLatt->pntsu, &fu, &du);
calc_lat_fudu(deformLatt->flag, deformLatt->pntsv, &fv, &dv);
calc_lat_fudu(deformLatt->flag, deformLatt->pntsw, &fw, &dw);
/* we berekenen hier steeds de u v w lattice coordinaten, weinig reden ze te onthouden */
vec[2]= fw;
for(w=0; w<deformLatt->pntsw; w++) {
vec[1]= fv;
for(v=0; v<deformLatt->pntsv; v++) {
vec[0]= fu;
for(u=0; u<deformLatt->pntsu; u++, bp++) {
VecSubf(fp, bp->vec, vec);
Mat4Mul3Vecfl(imat, fp);
vec[0]+= du;
fp+= 3;
}
vec[1]+= dv;
}
vec[2]+= dw;
}
}
void calc_latt_deform(float *co)
{
Lattice *lt;
float fu, du, u, v, w, tu[4], tv[4], tw[4];
float *fpw, *fpv, *fpu, vec[3];
int ui, vi, wi, uu, vv, ww;
if(latticedata==0) return;
lt= deformLatt; /* kortere notatie! */
/* co is in lokale coords, met latmat behandelen */
VECCOPY(vec, co);
Mat4MulVecfl(latmat, vec);
/* u v w coords */
if(lt->pntsu>1) {
calc_lat_fudu(lt->flag, lt->pntsu, &fu, &du);
u= (vec[0]-fu)/du;
ui= (int)floor(u);
u -= ui;
set_four_ipo(u, tu, lt->typeu);
}
else {
tu[0]= tu[2]= tu[3]= 0.0; tu[1]= 1.0;
ui= 0;
}
if(lt->pntsv>1) {
calc_lat_fudu(lt->flag, lt->pntsv, &fu, &du);
v= (vec[1]-fu)/du;
vi= (int)floor(v);
v -= vi;
set_four_ipo(v, tv, lt->typev);
}
else {
tv[0]= tv[2]= tv[3]= 0.0; tv[1]= 1.0;
vi= 0;
}
if(lt->pntsw>1) {
calc_lat_fudu(lt->flag, lt->pntsw, &fu, &du);
w= (vec[2]-fu)/du;
wi= (int)floor(w);
w -= wi;
set_four_ipo(w, tw, lt->typew);
}
else {
tw[0]= tw[2]= tw[3]= 0.0; tw[1]= 1.0;
wi= 0;
}
for(ww= wi-1; ww<=wi+2; ww++) {
w= tw[ww-wi+1];
if(w!=0.0) {
if(ww>0) {
if(ww<lt->pntsw) fpw= latticedata + 3*ww*lt->pntsu*lt->pntsv;
else fpw= latticedata + 3*(lt->pntsw-1)*lt->pntsu*lt->pntsv;
}
else fpw= latticedata;
for(vv= vi-1; vv<=vi+2; vv++) {
v= w*tv[vv-vi+1];
if(v!=0.0) {
if(vv>0) {
if(vv<lt->pntsv) fpv= fpw + 3*vv*lt->pntsu;
else fpv= fpw + 3*(lt->pntsv-1)*lt->pntsu;
}
else fpv= fpw;
for(uu= ui-1; uu<=ui+2; uu++) {
u= v*tu[uu-ui+1];
if(u!=0.0) {
if(uu>0) {
if(uu<lt->pntsu) fpu= fpv + 3*uu;
else fpu= fpv + 3*(lt->pntsu-1);
}
else fpu= fpv;
co[0]+= u*fpu[0];
co[1]+= u*fpu[1];
co[2]+= u*fpu[2];
}
}
}
}
}
}
}
void end_latt_deform()
{
MEM_freeN(latticedata);
latticedata= 0;
}
int object_deform(Object *ob)
{
Mesh *me;
Curve *cu;
DispList *dl;
MVert *mvert;
float *fp;
int a, tot;
if(ob->parent==0) return 0;
/* altijd proberen in deze fie de hele deform te doen: apply! */
if(ob->parent->type==OB_LATTICE) {
init_latt_deform(ob->parent, ob);
if(ob->type==OB_MESH) {
me= ob->data;
dl= find_displist_create(&ob->disp, DL_VERTS);
mvert= me->mvert;
if(dl->verts) MEM_freeN(dl->verts);
dl->nr= me->totvert;
dl->verts= fp= MEM_mallocN(3*sizeof(float)*me->totvert, "deform1");
for(a=0; a<me->totvert; a++, mvert++, fp+=3) {
if(lt_applyflag) calc_latt_deform(mvert->co);
else {
VECCOPY(fp, mvert->co);
calc_latt_deform(fp);
}
}
}
else if ELEM(ob->type, OB_CURVE, OB_SURF) {
cu= ob->data;
if(lt_applyflag) {
Nurb *nu;
BPoint *bp;
nu= cu->nurb.first;
while(nu) {
if(nu->bp) {
a= nu->pntsu*nu->pntsv;
bp= nu->bp;
while(a--) {
calc_latt_deform(bp->vec);
bp++;
}
}
nu= nu->next;
}
}
/* when apply, do this too, looks more interactive */
dl= cu->disp.first;
while(dl) {
fp= dl->verts;
if(dl->type==DL_INDEX3) tot=dl->parts;
else tot= dl->nr*dl->parts;
for(a=0; a<tot; a++, fp+=3) {
calc_latt_deform(fp);
}
dl= dl->next;
}
}
end_latt_deform();
boundbox_displist(ob);
return 1;
}
else if(ob->parent->type==OB_ARMATURE) {
if (ob->partype != PARSKEL){
return 0;
}
init_armature_deform (ob->parent, ob);
switch (ob->type){
case OB_MESH:
me= ob->data;
dl= find_displist_create(&ob->disp, DL_VERTS);
mvert= me->mvert;
if(dl->verts) MEM_freeN(dl->verts);
dl->nr= me->totvert;
dl->verts= fp= MEM_mallocN(3*sizeof(float)*me->totvert, "deform1");
for(a=0; a<me->totvert; a++, mvert++, fp+=3) {
if(lt_applyflag){
calc_armature_deform(ob->parent, mvert->co, a);
}
else {
VECCOPY(fp, mvert->co);
calc_armature_deform(ob->parent, fp, a);
}
}
break;
default:
break;
}
boundbox_displist(ob);
return 1;
}
else if(ob->parent->type==OB_IKA) {
Ika *ika;
if(ob->partype!=PARSKEL) return 0;
ika= ob->parent->data;
if(ika->def==0) return 0;
init_skel_deform(ob->parent, ob);
if(ob->type==OB_MESH) {
me= ob->data;
dl= find_displist_create(&ob->disp, DL_VERTS);
mvert= me->mvert;
if(dl->verts) MEM_freeN(dl->verts);
dl->nr= me->totvert;
dl->verts= fp= MEM_mallocN(3*sizeof(float)*me->totvert, "deform1");
for(a=0; a<me->totvert; a++, mvert++, fp+=3) {
if(lt_applyflag) calc_skel_deform(ika, mvert->co);
else {
VECCOPY(fp, mvert->co);
calc_skel_deform(ika, fp);
}
}
}
else if ELEM(ob->type, OB_CURVE, OB_SURF) {
cu= ob->data;
if(lt_applyflag) {
Nurb *nu;
BPoint *bp;
nu= cu->nurb.first;
while(nu) {
if(nu->bp) {
a= nu->pntsu*nu->pntsv;
bp= nu->bp;
while(a--) {
calc_skel_deform(ika, bp->vec);
bp++;
}
}
nu= nu->next;
}
}
/* when apply, do this too, looks more interactive */
dl= cu->disp.first;
while(dl) {
fp= dl->verts;
tot= dl->nr*dl->parts;
for(a=0; a<tot; a++, fp+=3) {
calc_skel_deform(ika, fp);
}
dl= dl->next;
}
}
boundbox_displist(ob);
return 1;
}
return 0;
}
BPoint *latt_bp(Lattice *lt, int u, int v, int w)
{
return lt->def+ u + v*lt->pntsu + w*lt->pntsu*lt->pntsv;
}
void outside_lattice(Lattice *lt)
{
BPoint *bp, *bp1, *bp2;
int u, v, w;
float fac1, du=0.0, dv=0.0, dw=0.0;
bp= lt->def;
if(lt->pntsu>1) du= 1.0f/((float)lt->pntsu-1);
if(lt->pntsv>1) dv= 1.0f/((float)lt->pntsv-1);
if(lt->pntsw>1) dw= 1.0f/((float)lt->pntsw-1);
for(w=0; w<lt->pntsw; w++) {
for(v=0; v<lt->pntsv; v++) {
for(u=0; u<lt->pntsu; u++, bp++) {
if(u==0 || v==0 || w==0 || u==lt->pntsu-1 || v==lt->pntsv-1 || w==lt->pntsw-1);
else {
bp->hide= 1;
bp->f1 &= ~SELECT;
/* u extrema */
bp1= latt_bp(lt, 0, v, w);
bp2= latt_bp(lt, lt->pntsu-1, v, w);
fac1= du*u;
bp->vec[0]= (1.0f-fac1)*bp1->vec[0] + fac1*bp2->vec[0];
bp->vec[1]= (1.0f-fac1)*bp1->vec[1] + fac1*bp2->vec[1];
bp->vec[2]= (1.0f-fac1)*bp1->vec[2] + fac1*bp2->vec[2];
/* v extrema */
bp1= latt_bp(lt, u, 0, w);
bp2= latt_bp(lt, u, lt->pntsv-1, w);
fac1= dv*v;
bp->vec[0]+= (1.0f-fac1)*bp1->vec[0] + fac1*bp2->vec[0];
bp->vec[1]+= (1.0f-fac1)*bp1->vec[1] + fac1*bp2->vec[1];
bp->vec[2]+= (1.0f-fac1)*bp1->vec[2] + fac1*bp2->vec[2];
/* w extrema */
bp1= latt_bp(lt, u, v, 0);
bp2= latt_bp(lt, u, v, lt->pntsw-1);
fac1= dw*w;
bp->vec[0]+= (1.0f-fac1)*bp1->vec[0] + fac1*bp2->vec[0];
bp->vec[1]+= (1.0f-fac1)*bp1->vec[1] + fac1*bp2->vec[1];
bp->vec[2]+= (1.0f-fac1)*bp1->vec[2] + fac1*bp2->vec[2];
VecMulf(bp->vec, 0.3333333f);
}
}
}
}
}

View File

@@ -0,0 +1,905 @@
/* library.c aug 94 MIXED MODEL
*
* jan 95
*
* afhandeling ID's en libraries
* allocceren en vrijgeven alle library data
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
#include "MEM_guardedalloc.h"
/* all types are needed here, in order to do memory operations */
#include "DNA_ID.h"
#include "DNA_listBase.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_lattice_types.h"
#include "DNA_curve_types.h"
#include "DNA_meta_types.h"
#include "DNA_material_types.h"
#include "DNA_texture_types.h"
#include "DNA_ika_types.h"
#include "DNA_image_types.h"
#include "DNA_wave_types.h"
#include "DNA_lamp_types.h"
#include "DNA_camera_types.h"
#include "DNA_ipo_types.h"
#include "DNA_key_types.h"
#include "DNA_world_types.h"
#include "DNA_screen_types.h"
#include "DNA_vfont_types.h"
#include "DNA_text_types.h"
#include "DNA_sound_types.h"
#include "DNA_group_types.h"
#include "DNA_armature_types.h"
#include "DNA_action_types.h"
#include "BLI_blenlib.h"
#include "BLI_dynstr.h"
#include "BKE_bad_level_calls.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_global.h"
#include "BKE_sound.h"
#include "BKE_object.h"
#include "BKE_screen.h"
#include "BKE_mesh.h"
#include "BKE_material.h"
#include "BKE_curve.h"
#include "BKE_mball.h"
#include "BKE_text.h"
#include "BKE_texture.h"
#include "BKE_scene.h"
#include "BKE_image.h"
#include "BKE_ika.h"
#include "BKE_ipo.h"
#include "BKE_key.h"
#include "BKE_world.h"
#include "BKE_font.h"
#include "BKE_group.h"
#include "BKE_lattice.h"
#include "BKE_armature.h"
#include "BKE_action.h"
#define MAX_IDPUP 30 /* was 24 */
#define MAX_LIBARRAY 100 /* was 30 */
/* ************* ALGEMEEN ************************ */
void id_lib_extern(ID *id)
{
if(id) {
if(id->flag & LIB_INDIRECT) {
id->flag -= LIB_INDIRECT;
id->flag |= LIB_EXTERN;
}
}
}
void id_us_plus(ID *id)
{
if(id) {
id->us++;
if(id->flag & LIB_INDIRECT) {
id->flag -= LIB_INDIRECT;
id->flag |= LIB_EXTERN;
}
}
}
ListBase *wich_libbase(Main *mainlib, short type)
{
switch( type ) {
case ID_SCE:
return &(mainlib->scene);
case ID_LI:
return &(mainlib->library);
case ID_OB:
return &(mainlib->object);
case ID_ME:
return &(mainlib->mesh);
case ID_CU:
return &(mainlib->curve);
case ID_MB:
return &(mainlib->mball);
case ID_MA:
return &(mainlib->mat);
case ID_TE:
return &(mainlib->tex);
case ID_IM:
return &(mainlib->image);
case ID_IK:
return &(mainlib->ika);
case ID_WV:
return &(mainlib->wave);
case ID_LT:
return &(mainlib->latt);
case ID_LA:
return &(mainlib->lamp);
case ID_CA:
return &(mainlib->camera);
case ID_IP:
return &(mainlib->ipo);
case ID_KE:
return &(mainlib->key);
case ID_WO:
return &(mainlib->world);
case ID_SCR:
return &(mainlib->screen);
case ID_VF:
return &(mainlib->vfont);
case ID_TXT:
return &(mainlib->text);
case ID_SO:
return &(mainlib->sound);
case ID_SAMPLE:
/* declared as an external in sound.h !!! */
return (samples);
case ID_GR:
return &(mainlib->group);
case ID_AR:
return &(mainlib->armature);
case ID_AC:
return &(mainlib->action);
}
return 0;
}
int set_listbasepointers(Main *main, ListBase **lb)
{
/* BACKWARDS! let op volgorde van vrijgeven! (mesh<->mat) */
lb[0]= &(main->ipo);
lb[1]= &(main->key);
lb[2]= &(main->image);
lb[3]= &(main->tex);
lb[4]= &(main->mat);
lb[5]= &(main->vfont);
/* Important!: When adding a new object type,
* the specific data should be inserted here
*/
lb[6]= &(main->armature);
lb[7]= &(main->action);
lb[8]= &(main->mesh);
lb[9]= &(main->curve);
lb[10]= &(main->mball);
lb[11]= &(main->ika);
lb[12]= &(main->wave);
lb[13]= &(main->latt);
lb[14]= &(main->lamp);
lb[15]= &(main->camera);
lb[16]= &(main->world);
lb[17]= &(main->screen);
lb[18]= &(main->object);
lb[19]= &(main->scene);
lb[20]= &(main->library);
lb[21]= &(main->text);
lb[22]= &(main->sound);
lb[23]= &(main->group);
lb[24]= samples;
lb[25]= 0;
return 25;
}
/* *********** ALLOC EN FREE *****************
free_libblock(ListBase *lb, ID *id )
lijstbasis en datablok geven, alleen ID wordt uitgelezen
void *alloc_libblock(ListBase *lb, type, name)
hangt in lijst en geeft nieuw ID
***************************** */
static ID *alloc_libblock_notest(short type)
{
ID *id= 0;
switch( type ) {
case ID_SCE:
id= MEM_callocN(sizeof(Scene), "scene");
break;
case ID_LI:
id= MEM_callocN(sizeof(Library), "library");
break;
case ID_OB:
id= MEM_callocN(sizeof(Object), "object");
break;
case ID_ME:
id= MEM_callocN(sizeof(Mesh), "mesh");
break;
case ID_CU:
id= MEM_callocN(sizeof(Curve), "curve");
break;
case ID_MB:
id= MEM_callocN(sizeof(MetaBall), "mball");
break;
case ID_MA:
id= MEM_callocN(sizeof(Material), "mat");
break;
case ID_TE:
id= MEM_callocN(sizeof(Tex), "tex");
break;
case ID_IM:
id= MEM_callocN(sizeof(Image), "image");
break;
case ID_IK:
id= MEM_callocN(sizeof(Ika), "ika");
break;
case ID_WV:
id= MEM_callocN(sizeof(Wave), "wave");
break;
case ID_LT:
id= MEM_callocN(sizeof(Lattice), "latt");
break;
case ID_LA:
id= MEM_callocN(sizeof(Lamp), "lamp");
break;
case ID_CA:
id= MEM_callocN(sizeof(Camera), "camera");
break;
case ID_IP:
id= MEM_callocN(sizeof(Ipo), "ipo");
break;
case ID_KE:
id= MEM_callocN(sizeof(Key), "key");
break;
case ID_WO:
id= MEM_callocN(sizeof(World), "world");
break;
case ID_SCR:
id= MEM_callocN(sizeof(bScreen), "screen");
break;
case ID_VF:
id= MEM_callocN(sizeof(VFont), "vfont");
break;
case ID_TXT:
id= MEM_callocN(sizeof(Text), "text");
break;
case ID_SO:
id= MEM_callocN(sizeof(bSound), "sound");
break;
case ID_SAMPLE:
id = MEM_callocN(sizeof(bSample), "sound");
break;
case ID_GR:
id= MEM_callocN(sizeof(Group), "sound");
break;
case ID_AR:
id = MEM_callocN(sizeof(bArmature), "armature");
break;
case ID_AC:
id = MEM_callocN(sizeof(bAction), "action");
break;
}
return id;
}
// used everywhere in blenkernel and text.c
void *alloc_libblock(ListBase *lb, short type, char *name)
{
ID *id= 0;
id= alloc_libblock_notest(type);
if(id) {
BLI_addtail(lb, id);
id->us= 1;
*( (short *)id->name )= type;
new_id(lb, id, name);
/* alfabetisch opnieuw invoegen: zit in new_id */
}
return id;
}
/* GS reads the memory pointed at in a specific ordering. There are,
* however two definitions for it. I have jotted them down here, both,
* but I think the first one is actually used. The thing is that
* big-endian systems might read this the wrong way round. OTOH, we
* constructed the IDs that are read out with this macro explicitly as
* well. I expect we'll sort it out soon... */
/* from blendef: */
#define GS(a) (*((short *)(a)))
/* from misc_util: flip the bytes from x */
/*#define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */
// used everywhere in blenkernel and text.c
void *copy_libblock(void *rt)
{
ID *idn, *id;
ListBase *lb;
char *cp, *cpn;
int idn_len;
id= rt;
lb= wich_libbase(G.main, GS(id->name));
idn= alloc_libblock(lb, GS(id->name), id->name+2);
idn_len= MEM_allocN_len(idn);
if(idn_len - sizeof(ID) > 0) {
cp= (char *)id;
cpn= (char *)idn;
memcpy(cpn+sizeof(ID), cp+sizeof(ID), idn_len - sizeof(ID));
}
id->newid= idn;
idn->flag |= LIB_NEW;
return idn;
}
static void free_library(Library *lib)
{
/* no freeing needed for libraries yet */
}
// used in headerbuttons.c image.c mesh.c screen.c sound.c and library.c
void free_libblock(ListBase *lb, void *idv)
{
ID *id= idv;
switch( GS(id->name) ) { /* GetShort uit util.h */
case ID_SCE:
free_scene((Scene *)id);
break;
case ID_LI:
free_library((Library *)id);
break;
case ID_OB:
free_object((Object *)id);
break;
case ID_ME:
free_mesh((Mesh *)id);
break;
case ID_CU:
free_curve((Curve *)id);
break;
case ID_MB:
free_mball((MetaBall *)id);
break;
case ID_MA:
free_material((Material *)id);
break;
case ID_TE:
free_texture((Tex *)id);
break;
case ID_IM:
free_image((Image *)id);
break;
case ID_IK:
free_ika((Ika *)id);
break;
case ID_WV:
/* free_wave(id); */
break;
case ID_LT:
free_lattice((Lattice *)id);
break;
case ID_LA:
free_lamp((Lamp *)id);
break;
case ID_CA:
/* free_camera(id); */
/* cast wasn't here before... spooky... */
free_camera((Camera*) id);
break;
case ID_IP:
free_ipo((Ipo *)id);
break;
case ID_KE:
free_key((Key *)id);
break;
case ID_WO:
free_world((World *)id);
break;
case ID_SCR:
free_screen((bScreen *)id);
break;
case ID_VF:
free_vfont((VFont *)id);
break;
case ID_TXT:
free_text((Text *)id);
break;
case ID_SO:
sound_free_sound((bSound *)id);
break;
case ID_SAMPLE:
sound_free_sample((bSample *)id);
break;
case ID_GR:
free_group((Group *)id);
break;
case ID_AR:
free_armature((bArmature *)id);
break;
case ID_AC:
free_action((bAction *)id);
break;
}
BLI_remlink(lb, id);
MEM_freeN(id);
/* should not be here!! this is an interface-thing */
allspace(OOPS_TEST, 0);
}
void free_libblock_us(ListBase *lb, void *idv) /* test users */
{
ID *id= idv;
id->us--;
if(id->us<0) {
if(id->lib) printf("ERROR block %s %s users %d\n", id->lib->name, id->name, id->us);
else printf("ERROR block %s users %d\n", id->name, id->us);
}
if(id->us==0) {
if( GS(id->name)==ID_OB ) unlink_object((Object *)id);
free_libblock(lb, id);
}
}
void free_main(Main *mainvar)
{
/* ook aanroepen bij file inlezen, erase all, etc */
ListBase *lbarray[MAX_LIBARRAY];
int a;
a= set_listbasepointers(mainvar, lbarray);
while(a--) {
ListBase *lb= lbarray[a];
ID *id;
while (id= lb->first) {
free_libblock(lb, id);
}
}
MEM_freeN(mainvar);
}
/* ***************** ID ************************ */
// only used in exotic.c
ID *find_id(char *type, char *name) /* type: "OB" of "MA" etc */
{
ID *id;
ListBase *lb;
lb= wich_libbase(G.main, GS(type));
id= lb->first;
while(id) {
if( strcmp(id->name+2, name)==0 ) return id;
id= id->next;
}
return 0;
}
static void get_flags_for_id(ID *id, char *buf) {
int isfake= id->flag & LIB_FAKEUSER;
/* Writeout the flags for the entry, note there
* is a small hack that writes 5 spaces instead
* of 4 if no flags are displayed... this makes
* things usually line up ok - better would be
* to have that explicit, oh well - zr
*/
if (id->us<0)
sprintf(buf, "-1W ");
else if (!id->lib && !isfake && id->us)
sprintf(buf, " ");
else
sprintf(buf, "%c%c%c ", id->lib?'L':' ', isfake?'F':' ', (id->us==0)?'O':' ');
}
static void IDnames_to_dyn_pupstring(DynStr *pupds, ListBase *lb, ID *link, short *nr)
{
int i, nids= BLI_countlist(lb);
*nr= -1;
if (nids>MAX_IDPUP) {
BLI_dynstr_append(pupds, "DataBrowse %x-2");
} else {
ID *id;
for (i=0, id= lb->first; id; id= id->next, i++) {
char buf[32];
if (id==link)
*nr= i+1;
get_flags_for_id(id, buf);
BLI_dynstr_append(pupds, buf);
BLI_dynstr_append(pupds, id->name+2);
if(id->next)
BLI_dynstr_append(pupds, "|");
}
}
}
/* Silly routine, the only difference between the one
* above is that it only adds items with a matching
* blocktype... this should be unified somehow... - zr
*/
static void IPOnames_to_dyn_pupstring(DynStr *pupds, ListBase *lb, ID *link, short *nr, int blocktype)
{
ID *id;
int i, nids;
for (id= lb->first, nids= 0; id; id= id->next) {
Ipo *ipo= (Ipo*) id;
if (ipo->blocktype==blocktype)
nids++;
}
if (nids>MAX_IDPUP) {
BLI_dynstr_append(pupds, "DataBrowse %x-2");
} else {
for (i=0, id= lb->first; id; id= id->next) {
Ipo *ipo= (Ipo*) id;
if (ipo->blocktype==blocktype) {
char buf[32];
if (id==link)
*nr= i+1;
get_flags_for_id(id, buf);
BLI_dynstr_append(pupds, buf);
BLI_dynstr_append(pupds, id->name+2);
if(id->next)
BLI_dynstr_append(pupds, "|");
i++;
}
}
}
}
// used by headerbuttons.c buttons.c editobject.c editseq.c
void IDnames_to_pupstring(char **str, char *title, char *extraops, ListBase *lb, ID *link, short *nr)
{
DynStr *pupds= BLI_dynstr_new();
if (title) {
BLI_dynstr_append(pupds, title);
BLI_dynstr_append(pupds, "%t|");
}
IDnames_to_dyn_pupstring(pupds, lb, link, nr);
if (extraops) {
if (BLI_dynstr_get_len(pupds))
BLI_dynstr_append(pupds, "|");
BLI_dynstr_append(pupds, extraops);
}
*str= BLI_dynstr_get_cstring(pupds);
BLI_dynstr_free(pupds);
}
// only used by headerbuttons.c
void IPOnames_to_pupstring(char **str, char *title, char *extraops, ListBase *lb, ID *link, short *nr, int blocktype)
{
DynStr *pupds= BLI_dynstr_new();
if (title) {
BLI_dynstr_append(pupds, title);
BLI_dynstr_append(pupds, "%t|");
}
IPOnames_to_dyn_pupstring(pupds, lb, link, nr, blocktype);
if (extraops) {
if (BLI_dynstr_get_len(pupds))
BLI_dynstr_append(pupds, "|");
BLI_dynstr_append(pupds, extraops);
}
*str= BLI_dynstr_get_cstring(pupds);
BLI_dynstr_free(pupds);
}
// used by buttons.c library.c mball.c
void splitIDname(char *name, char *left, int *nr)
{
int a;
*nr= 0;
strncpy(left, name, 21);
a= strlen(name);
if(a>1 && name[a-1]=='.') return;
while(a--) {
if( name[a]=='.' ) {
left[a]= 0;
*nr= atol(name+a+1);
return;
}
if( isdigit(name[a])==0 ) break;
left[a]= 0;
}
strcpy(left, name);
}
static void sort_alpha_id(ListBase *lb, ID *id)
{
ID *idtest;
/* alfabetisch opnieuw invoegen */
if(lb->first!=lb->last) {
BLI_remlink(lb, id);
idtest= lb->first;
while(idtest) {
if(strcasecmp(idtest->name, id->name)>0 || idtest->lib) {
BLI_insertlinkbefore(lb, idtest, id);
break;
}
idtest= idtest->next;
}
/* als laatste */
if(idtest==0) {
BLI_addtail(lb, id);
}
}
}
int new_id(ListBase *lb, ID *id, char *tname)
/* alleen locale blokken: externe en indirekte hebben al een unieke ID */
/* return 1: nieuwe naam gemaakt */
{
ID *idtest;
int nr= 0, nrtest, maxtest=32, a;
char aname[32], *name, left[24], leftest[24], in_use[32];
/* - naam splitsen
* - zoeken
*/
if(id->lib) return 0;
if(tname==0) name= id->name+2;
else {
/* tname can be const */
strncpy(aname, tname, 21);
name= aname;
if( strlen(name) > 21 ) name[21]= 0;
}
if(lb==0) lb= wich_libbase(G.main, GS(id->name));
/* eerste fase: bestaat de id al? */
idtest= lb->first;
while(idtest) {
if(id!=idtest && idtest->lib==0) {
/* niet alphabetic testen! */
/* optim */
if( idtest->name[2] == name[0] ) {
if(strcmp(name, idtest->name+2)==0) break;
}
}
idtest= idtest->next;
}
/* if there is no double return */
if(idtest==0) {
strcpy(id->name+2, name);
return 0;
}
memset(in_use, 0, maxtest);
splitIDname(name, left, &nr);
if(nr>999 && strlen(left)>16) left[16]= 0;
else if(strlen(left)>17) left[17]= 0;
idtest= lb->first;
while(idtest) {
if(id!=idtest && idtest->lib==0) {
splitIDname(idtest->name+2, leftest, &nrtest);
if(strcmp(left, leftest)==0) {
if(nrtest<maxtest) in_use[nrtest]= 1;
if(nr <= nrtest) nr= nrtest+1;
}
}
idtest= idtest->next;
}
for(a=0; a<maxtest; a++) {
if(a>=nr) break;
if( in_use[a]==0 ) {
nr= a;
break;
}
}
if(nr==0) sprintf(id->name+2, "%s", left);
else {
if (nr >= 1000 && strlen(left) > 16) {
// this would overflow name buffer
left[16]= 0;
return (new_id(lb, id, left));
}
/* this format specifier is fucked... */
sprintf(id->name+2, "%s.%0.3d", left, nr);
}
sort_alpha_id(lb, id);
return 1;
}
// next to indirect usage in read/writefile also in editobject.c scene.c
void clear_id_newpoins()
{
ListBase *lbarray[MAX_LIBARRAY];
ID *id;
int a;
a= set_listbasepointers(G.main, lbarray);
while(a--) {
id= lbarray[a]->first;
while(id) {
id->newid= 0;
id->flag &= ~LIB_NEW;
id= id->next;
}
}
}
void all_local(void)
{
ListBase *lbarray[MAX_LIBARRAY], tempbase={0, 0};
ID *id, *idn;
int a;
a= set_listbasepointers(G.main, lbarray);
while(a--) {
id= lbarray[a]->first;
while(id) {
id->newid= 0;
id->flag &= ~(LIB_EXTERN|LIB_INDIRECT|LIB_NEW);
idn= id->next; /* id wordt mogelijk opnieuw ingevoegd */
if(id->lib) {
id->lib= 0;
new_id(lbarray[a], id, 0); /* new_id doet dit alleen bij dubbele namen */
sort_alpha_id(lbarray[a], id);
}
else {
/* patch: testen of de zaak wel alphabetisch is */
/*
if(idn) {
if(strcasecmp(id->name, idn->name)>0) {
remlink(lbarray[a], id);
addtail(&tempbase, id);
}
else if(id->prev) {
idp= id->prev;
if(strcasecmp(idp->name, id->name)>0) {
remlink(lbarray[a], id);
addtail(&tempbase, id);
}
}
}
*/
}
id= idn;
}
/* patch2: zorgen dat de zaak wel alphabetisch is */
while( (id=tempbase.first) ) {
BLI_remlink(&tempbase, id);
BLI_addtail(lbarray[a], id);
new_id(lbarray[a], id, 0);
}
}
}
void test_idbutton(char *name)
{
/* vanuit buttons: als naam al bestaat: new_id aanroepen */
ListBase *lb;
ID *idtest;
lb= wich_libbase(G.main, GS(name-2) );
if(lb==0) return;
/* zoek welke id */
idtest= lb->first;
while(idtest) {
if( strcmp(idtest->name+2, name)==0) break;
idtest= idtest->next;
}
if(idtest) if( new_id(lb, idtest, name)==0 ) sort_alpha_id(lb, idtest);
}
void rename_id(ID *id, char *name)
{
ListBase *lb;
strncpy(id->name+2, name, 21);
lb= wich_libbase(G.main, GS(id->name) );
new_id(lb, id, name);
}

View File

@@ -0,0 +1,747 @@
/* material.c MIX MODEL
*
* maart 95
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_material_types.h"
#include "DNA_texture_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_curve_types.h"
#include "DNA_meta_types.h"
#include "DNA_scene_types.h"
#include "BLI_blenlib.h"
#include "BKE_bad_level_calls.h"
#include "BKE_utildefines.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_library.h"
#include "BKE_displist.h"
#include "BPY_extern.h"
#include "BKE_material.h"
void free_material(Material *ma)
{
int a;
MTex *mtex;
BPY_free_scriptlink(&ma->scriptlink);
if(ma->ren) MEM_freeN(ma->ren);
ma->ren= 0;
for(a=0; a<8; a++) {
mtex= ma->mtex[a];
if(mtex && mtex->tex) mtex->tex->id.us--;
if(mtex) MEM_freeN(mtex);
}
}
void init_material(Material *ma)
{
ma->lay= 1;
ma->r= ma->g= ma->b= ma->ref= 0.8f;
ma->specr= ma->specg= ma->specb= 1.0f;
ma->mirr= ma->mirg= ma->mirb= 1.0f;
ma->amb= 0.5f;
ma->alpha= 1.0f;
ma->spec= ma->hasize= 0.5f;
ma->har= 50;
ma->starc= ma->ringc= 4;
ma->linec= 12;
ma->flarec= 1;
ma->flaresize= ma->subsize= 1.0f;
ma->friction= 0.5f;
ma->mode= MA_TRACEBLE+MA_SHADOW;
}
Material *add_material(char *name)
{
Material *ma;
ma= alloc_libblock(&G.main->mat, ID_MA, name);
init_material(ma);
return ma;
}
Material *copy_material(Material *ma)
{
Material *man;
int a;
man= copy_libblock(ma);
id_us_plus((ID *)man->ipo);
for(a=0; a<8; a++) {
if(ma->mtex[a]) {
man->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial");
memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex));
id_us_plus((ID *)man->mtex[a]->tex);
}
}
BPY_copy_scriptlink(&ma->scriptlink);
return man;
}
void make_local_material(Material *ma)
{
Object *ob;
Mesh *me;
Curve *cu;
MetaBall *mb;
Material *man;
int a, local=0, lib=0;
/* - zijn er alleen lib users: niet doen
* - zijn er alleen locale users: flag zetten
* - mixed: copy
*/
if(ma->id.lib==0) return;
if(ma->id.us==1) {
ma->id.lib= 0;
ma->id.flag= LIB_LOCAL;
new_id(0, (ID *)ma, 0);
for(a=0; a<8; a++) {
if(ma->mtex[a]) id_lib_extern((ID *)ma->mtex[a]->tex);
}
return;
}
/* test objects */
ob= G.main->object.first;
while(ob) {
if(ob->mat) {
for(a=0; a<ob->totcol; a++) {
if(ob->mat[a]==ma) {
if(ob->id.lib) lib= 1;
else local= 1;
}
}
}
ob= ob->id.next;
}
/* test meshes */
me= G.main->mesh.first;
while(me) {
if(me->mat) {
for(a=0; a<me->totcol; a++) {
if(me->mat[a]==ma) {
if(me->id.lib) lib= 1;
else local= 1;
}
}
}
me= me->id.next;
}
/* test curves */
cu= G.main->curve.first;
while(cu) {
if(cu->mat) {
for(a=0; a<cu->totcol; a++) {
if(cu->mat[a]==ma) {
if(cu->id.lib) lib= 1;
else local= 1;
}
}
}
cu= cu->id.next;
}
/* test mballs */
mb= G.main->mball.first;
while(mb) {
if(mb->mat) {
for(a=0; a<mb->totcol; a++) {
if(mb->mat[a]==ma) {
if(mb->id.lib) lib= 1;
else local= 1;
}
}
}
mb= mb->id.next;
}
if(local && lib==0) {
ma->id.lib= 0;
ma->id.flag= LIB_LOCAL;
for(a=0; a<8; a++) {
if(ma->mtex[a]) id_lib_extern((ID *)ma->mtex[a]->tex);
}
new_id(0, (ID *)ma, 0);
}
else if(local && lib) {
man= copy_material(ma);
man->id.us= 0;
/* do objects */
ob= G.main->object.first;
while(ob) {
if(ob->mat) {
for(a=0; a<ob->totcol; a++) {
if(ob->mat[a]==ma) {
if(ob->id.lib==0) {
ob->mat[a]= man;
man->id.us++;
ma->id.us--;
}
}
}
}
ob= ob->id.next;
}
/* do meshes */
me= G.main->mesh.first;
while(me) {
if(me->mat) {
for(a=0; a<me->totcol; a++) {
if(me->mat[a]==ma) {
if(me->id.lib==0) {
me->mat[a]= man;
man->id.us++;
ma->id.us--;
}
}
}
}
me= me->id.next;
}
/* do curves */
cu= G.main->curve.first;
while(cu) {
if(cu->mat) {
for(a=0; a<cu->totcol; a++) {
if(cu->mat[a]==ma) {
if(cu->id.lib==0) {
cu->mat[a]= man;
man->id.us++;
ma->id.us--;
}
}
}
}
cu= cu->id.next;
}
/* do mballs */
mb= G.main->mball.first;
while(mb) {
if(mb->mat) {
for(a=0; a<mb->totcol; a++) {
if(mb->mat[a]==ma) {
if(mb->id.lib==0) {
mb->mat[a]= man;
man->id.us++;
ma->id.us--;
}
}
}
}
mb= mb->id.next;
}
}
}
Material ***give_matarar(Object *ob)
{
Mesh *me;
Curve *cu;
MetaBall *mb;
if(ob->type==OB_MESH) {
me= ob->data;
return &(me->mat);
}
else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
cu= ob->data;
return &(cu->mat);
}
else if(ob->type==OB_MBALL) {
mb= ob->data;
return &(mb->mat);
}
return 0;
}
short *give_totcolp(Object *ob)
{
Mesh *me;
Curve *cu;
MetaBall *mb;
if(ob->type==OB_MESH) {
me= ob->data;
return &(me->totcol);
}
else if ELEM3(ob->type, OB_CURVE, OB_FONT, OB_SURF) {
cu= ob->data;
return &(cu->totcol);
}
else if(ob->type==OB_MBALL) {
mb= ob->data;
return &(mb->totcol);
}
return 0;
}
Material *give_current_material(Object *ob, int act)
{
Material ***matarar, *ma;
if(ob==0) return 0;
if(ob->totcol==0) return 0;
if(act>ob->totcol) act= ob->totcol;
else if(act==0) act= 1;
if( BTST(ob->colbits, act-1) ) { /* aan object */
ma= ob->mat[act-1];
}
else { /* aan data */
matarar= give_matarar(ob);
if(matarar && *matarar) ma= (*matarar)[act-1];
else ma= 0;
}
return ma;
}
ID *material_from(Object *ob, int act)
{
if(ob==0) return 0;
if(ob->totcol==0) return ob->data;
if(act==0) act= 1;
if( BTST(ob->colbits, act-1) ) return (ID *)ob;
else return ob->data;
}
/* GS reads the memory pointed at in a specific ordering. There are,
* however two definitions for it. I have jotted them down here, both,
* but I think the first one is actually used. The thing is that
* big-endian systems might read this the wrong way round. OTOH, we
* constructed the IDs that are read out with this macro explicitly as
* well. I expect we'll sort it out soon... */
/* from blendef: */
#define GS(a) (*((short *)(a)))
/* from misc_util: flip the bytes from x */
/* #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */
void test_object_materials(ID *id)
{
/* ob mat-array evenlang maken als obdata mat-array */
Object *ob;
Mesh *me;
Curve *cu;
MetaBall *mb;
Material **newmatar;
int totcol=0;
if(id==0) return;
if( GS(id->name)==ID_ME ) {
me= (Mesh *)id;
totcol= me->totcol;
}
else if( GS(id->name)==ID_CU ) {
cu= (Curve *)id;
totcol= cu->totcol;
}
else if( GS(id->name)==ID_MB ) {
mb= (MetaBall *)id;
totcol= mb->totcol;
}
else return;
ob= G.main->object.first;
while(ob) {
if(ob->data==id) {
if(totcol==0) {
if(ob->totcol) {
MEM_freeN(ob->mat);
ob->mat= 0;
}
}
else if(ob->totcol<totcol) {
newmatar= MEM_callocN(sizeof(void *)*totcol, "newmatar");
if(ob->totcol) {
memcpy(newmatar, ob->mat, sizeof(void *)*ob->totcol);
MEM_freeN(ob->mat);
}
ob->mat= newmatar;
}
ob->totcol= totcol;
if(ob->totcol && ob->actcol==0) ob->actcol= 1;
if(ob->actcol>ob->totcol) ob->actcol= ob->totcol;
}
ob= ob->id.next;
}
}
void assign_material(Object *ob, Material *ma, int act)
{
Material *mao, **matar, ***matarar;
short *totcolp;
if(act>MAXMAT) return;
if(act<1) act= 1;
/* test arraylens */
totcolp= give_totcolp(ob);
matarar= give_matarar(ob);
if(totcolp==0 || matarar==0) return;
if( act > *totcolp) {
matar= MEM_callocN(sizeof(void *)*act, "matarray1");
if( *totcolp) {
memcpy(matar, *matarar, sizeof(void *)*( *totcolp ));
MEM_freeN(*matarar);
}
*matarar= matar;
*totcolp= act;
}
if(act > ob->totcol) {
matar= MEM_callocN(sizeof(void *)*act, "matarray2");
if( ob->totcol) {
memcpy(matar, ob->mat, sizeof(void *)*( ob->totcol ));
MEM_freeN(ob->mat);
}
ob->mat= matar;
ob->totcol= act;
}
/* doe 't */
if( BTST(ob->colbits, act-1) ) { /* aan object */
mao= ob->mat[act-1];
if(mao) mao->id.us--;
ob->mat[act-1]= ma;
}
else { /* aan data */
mao= (*matarar)[act-1];
if(mao) mao->id.us--;
(*matarar)[act-1]= ma;
}
id_us_plus((ID *)ma);
test_object_materials(ob->data);
}
void new_material_to_objectdata(Object *ob)
{
Material *ma;
if(ob==0) return;
if(ob->totcol>=MAXMAT) return;
ma= give_current_material(ob, ob->actcol);
if(ma==0) {
ma= add_material("Material");
ma->id.us= 0;
}
if(ob->actcol) {
if( BTST(ob->colbits, ob->actcol-1) ) {
ob->colbits= BSET(ob->colbits, ob->totcol);
}
}
assign_material(ob, ma, ob->totcol+1);
ob->actcol= ob->totcol;
}
void init_render_material(Material *ma)
{
MTex *mtex;
int a, needuv=0;
if(ma->ren) return;
if(ma->flarec==0) ma->flarec= 1;
ma->ren= MEM_mallocN(sizeof(Material), "initrendermaterial");
memcpy(ma->ren, ma, sizeof(Material));
/* alle texcoflags van mtex adden */
ma= ma->ren;
ma->texco= 0;
ma->mapto= 0;
for(a=0; a<8; a++) {
mtex= ma->mtex[a];
if(mtex && mtex->tex) {
/* force std. ref mapping for envmap */
if(mtex->tex->type==TEX_ENVMAP) {
/* mtex->texco= TEXCO_REFL; */
/* mtex->projx= PROJ_X; */
/* mtex->projy= PROJ_Y; */
/* mtex->projz= PROJ_Z; */
/* mtex->mapping= MTEX_FLAT; */
}
/* hier niet testen op mtex->object en mtex->texco op TEXCO_ORCO zetten: mtex is linked! */
ma->texco |= mtex->texco;
ma->mapto |= mtex->mapto;
if(R.osa) {
if ELEM3(mtex->tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP) ma->texco |= TEXCO_OSA;
}
if(ma->texco & (511)) needuv= 1;
if(mtex->object) mtex->object->flag |= OB_DO_IMAT;
}
}
if(ma->mode & MA_ZTRA) {
/* if(ma->alpha==0.0 || ma->alpha==1.0) */
R.flag |= R_ZTRA;
}
if(ma->mode & MA_VERTEXCOLP) ma->mode |= MA_VERTEXCOL;
if(ma->mode & (MA_VERTEXCOL|MA_FACETEXTURE)) {
needuv= 1;
if(R.osa) ma->texco |= TEXCO_OSA; /* for texfaces */
}
if(needuv) ma->texco |= NEED_UV;
ma->ambr= ma->amb*R.wrld.ambr;
ma->ambg= ma->amb*R.wrld.ambg;
ma->ambb= ma->amb*R.wrld.ambb;
}
void init_render_materials()
{
Material *ma;
ma= G.main->mat.first;
while(ma) {
if(ma->id.us) init_render_material(ma);
ma= ma->id.next;
}
}
void end_render_material(Material *ma)
{
if(ma->ren) MEM_freeN(ma->ren);
ma->ren= 0;
if(ma->mode & (MA_VERTEXCOLP|MA_FACETEXTURE)) {
if( !(ma->mode & MA_HALO) ) {
ma->r= ma->g= ma->b= 1.0;
}
}
}
void end_render_materials()
{
Material *ma;
ma= G.main->mat.first;
while(ma) {
if(ma->id.us) end_render_material(ma);
ma= ma->id.next;
}
}
/* ****************** */
char colname_array[125][20]= {
"Black","DarkRed","HalveRed","Red","Red",
"DarkGreen","DarkOlive","Brown","Chocolate","OrangeRed",
"HalveGreen","GreenOlive","DryOlive","Goldenrod","DarkOrange",
"LightGreen","Chartreuse","YellowGreen","Yellow","Gold",
"Green","LawnGreen","GreenYellow","LightOlive","Yellow",
"DarkBlue","DarkPurple","HotPink","VioletPink","RedPink",
"SlateGray","DarkGrey","PalePurple","IndianRed","Tomato",
"SeaGreen","PaleGreen","GreenKhaki","LightBrown","LightSalmon",
"SpringGreen","PaleGreen","MediumOlive","YellowBrown","LightGold",
"LightGreen","LightGreen","LightGreen","GreenYellow","PaleYellow",
"HalveBlue","DarkSky","HalveMagenta","VioletRed","DeepPink",
"SteelBlue","SkyBlue","Orchid","LightHotPink","HotPink",
"SeaGreen","SlateGray","MediumGrey","Burlywood","LightPink",
"SpringGreen","Aquamarine","PaleGreen","Khaki","PaleOrange",
"SpringGreen","SeaGreen","PaleGreen","PaleWhite","YellowWhite",
"LightBlue","Purple","MediumOrchid","Magenta","Magenta",
"RoyalBlue","SlateBlue","MediumOrchid","Orchid","Magenta",
"DeepSkyBlue","LightSteelBlue","LightSkyBlue","Violet","LightPink",
"Cyaan","DarkTurquoise","SkyBlue","Grey","Snow",
"Mint","Mint","Aquamarine","MintCream","Ivory",
"Blue","Blue","DarkMagenta","DarkOrchid","Magenta",
"SkyBlue","RoyalBlue","LightSlateBlue","MediumOrchid","Magenta",
"DodgerBlue","SteelBlue","MediumPurple","PalePurple","Plum",
"DeepSkyBlue","PaleBlue","LightSkyBlue","PalePurple","Thistle",
"Cyan","ColdBlue","PaleTurquoise","GhostWhite","White"
};
void automatname(Material *ma)
{
int nr, r, g, b;
float ref;
if(ma==0) return;
if(ma->mode & MA_SHLESS) ref= 1.0;
else ref= ma->ref;
r= (int)(4.99*(ref*ma->r));
g= (int)(4.99*(ref*ma->g));
b= (int)(4.99*(ref*ma->b));
nr= r + 5*g + 25*b;
if(nr>124) nr= 124;
new_id(&G.main->mat, (ID *)ma, colname_array[nr]);
}
void delete_material_index()
{
Material *mao, ***matarar;
Object *ob, *obt;
Mesh *me;
Curve *cu;
Nurb *nu;
MFace *mface;
short *totcolp;
int a, actcol;
if(G.obedit) {
error("Unable to perform function in EditMode");
return;
}
ob= ((G.scene->basact)? (G.scene->basact->object) : 0) ;
if(ob==0 || ob->totcol==0) return;
/* neem als uitgangspunt de mesh/curve/mball, verwijder 1 index, EN bij alle ob's
* die ook zelfde ob->data hebben
*
* Daarna ook indexen in mesh/curve/mball wijzigen!!!
*/
totcolp= give_totcolp(ob);
matarar= give_matarar(ob);
/* we deleten de actcol */
if(ob->totcol) {
mao= (*matarar)[ob->actcol-1];
if(mao) mao->id.us--;
}
for(a=ob->actcol; a<ob->totcol; a++) {
(*matarar)[a-1]= (*matarar)[a];
}
(*totcolp)--;
if(*totcolp==0) {
MEM_freeN(*matarar);
*matarar= 0;
}
actcol= ob->actcol;
obt= G.main->object.first;
while(obt) {
if(obt->data==ob->data) {
/* LET OP: actcol hier niet van ob of van obt pakken (kan nul worden) */
mao= obt->mat[actcol-1];
if(mao) mao->id.us--;
for(a=actcol; a<obt->totcol; a++) obt->mat[a-1]= obt->mat[a];
obt->totcol--;
if(obt->actcol > obt->totcol) obt->actcol= obt->totcol;
if(obt->totcol==0) {
MEM_freeN(obt->mat);
obt->mat= 0;
}
}
obt= obt->id.next;
}
allqueue(REDRAWBUTSMAT, 0);
/* indexen van mesh goedzetten */
if(ob->type==OB_MESH) {
me= get_mesh(ob);
mface= me->mface;
a= me->totface;
while(a--) {
if(mface->mat_nr && mface->mat_nr>=actcol-1) mface->mat_nr--;
mface++;
}
makeDispList(ob);
}
else if ELEM(ob->type, OB_CURVE, OB_SURF) {
cu= ob->data;
nu= cu->nurb.first;
while(nu) {
if(nu->mat_nr && nu->mat_nr>=actcol-1) nu->mat_nr--;
nu= nu->next;
}
makeDispList(ob);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,118 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <stdlib.h>
#include "BKE_nla.h"
#include "BKE_blender.h"
#include "BLI_blenlib.h"
#include "DNA_space_types.h"
#include "DNA_nla_types.h"
#include "DNA_action_types.h"
#include "DNA_ID.h"
#include "DNA_ipo_types.h"
#include "MEM_guardedalloc.h"
void copy_actionstrip (bActionStrip **dst, bActionStrip **src){
bActionStrip *dstrip;
bActionStrip *sstrip = *src;
if (!*src){
*dst=NULL;
return;
}
*dst = MEM_dupallocN(sstrip);
dstrip = *dst;
if (dstrip->act)
dstrip->act->id.us++;
if (dstrip->ipo)
dstrip->ipo->id.us++;
}
void copy_nlastrips (ListBase *dst, ListBase *src)
{
bActionStrip *strip;
dst->first=dst->last=NULL;
duplicatelist (dst, src);
/* Update specific data */
if (!dst->first)
return;
for (strip = dst->first; strip; strip=strip->next){
if (strip->act)
strip->act->id.us++;
if (strip->ipo)
strip->ipo->id.us++;
}
}
void free_actionstrip(bActionStrip* strip)
{
if (!strip)
return;
if (strip->act){
strip->act->id.us--;
strip->act = NULL;
}
if (strip->ipo){
strip->ipo->id.us--;
strip->ipo = NULL;
}
}
void free_nlastrips (ListBase *nlalist)
{
bActionStrip *strip;
if (!nlalist->first)
return;
/* Do any specific freeing */
for (strip=nlalist->first; strip; strip=strip->next)
{
free_actionstrip (strip);
};
/* Free the whole list */
BLI_freelistN(nlalist);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,638 @@
/**
* blenkernel/packedFile.c - (cleaned up mar-01 nzc)
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
#else
#include <io.h>
#endif
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_image_types.h"
#include "DNA_sound_types.h"
#include "DNA_vfont_types.h"
#include "DNA_packedFile_types.h"
#include "BLI_blenlib.h"
#include "BKE_utildefines.h"
#include "BKE_bad_level_calls.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_screen.h"
#include "BKE_sound.h"
//#include "sound.h"
#include "BKE_image.h"
#include "BKE_font.h"
#include "BKE_packedFile.h"
int seekPackedFile(PackedFile * pf, int offset, int whence)
{
int oldseek = -1, seek = 0;
if (pf) {
oldseek = pf->seek;
switch(whence) {
case SEEK_CUR:
seek = oldseek + offset;
break;
case SEEK_END:
seek = pf->size + offset;
break;
case SEEK_SET:
seek = offset;
break;
default:
oldseek = -1;
}
if (seek < 0) {
seek = 0;
} else if (seek > pf->size) {
seek = pf->size;
}
pf->seek = seek;
}
return(oldseek);
}
void rewindPackedFile(PackedFile * pf)
{
seekPackedFile(pf, 0, SEEK_SET);
}
int readPackedFile(PackedFile * pf, void * data, int size)
{
if ((pf != NULL) && (size >= 0) && (data != NULL)) {
if (size + pf->seek > pf->size) {
size = pf->size - pf->seek;
}
if (size > 0) {
memcpy(data, ((char *) pf->data) + pf->seek, size);
} else {
size = 0;
}
pf->seek += size;
} else {
size = -1;
}
return(size);
}
int countPackedFiles()
{
int count = 0;
Image *ima;
VFont *vf;
bSample *sample;
// let's check if there are packed files...
ima = G.main->image.first;
while (ima) {
if (ima->packedfile) {
count++;
}
ima= ima->id.next;
}
vf = G.main->vfont.first;
while (vf) {
if (vf->packedfile) {
count++;
}
vf = vf->id.next;
}
sample = samples->first;
while (sample) {
if (sample->packedfile) {
count++;
}
sample = sample->id.next;
}
return(count);
}
void freePackedFile(PackedFile * pf)
{
if (pf) {
MEM_freeN(pf->data);
MEM_freeN(pf);
} else {
printf("freePackedFile: Trying to free a NULL pointer\n");
}
}
PackedFile * newPackedFileMemory(void *mem, int memlen)
{
PackedFile * pf = MEM_callocN(sizeof(*pf), "PackedFile");
pf->data = mem;
pf->size = memlen;
return pf;
}
PackedFile * newPackedFile(char * filename)
{
PackedFile * pf = NULL;
int file, filelen;
char name[FILE_MAXDIR+FILE_MAXFILE];
void * data;
waitcursor(1);
// convert relative filenames to absolute filenames
strcpy(name, filename);
BLI_convertstringcode(name, G.sce, G.scene->r.cfra);
// open the file
// and create a PackedFile structure
file= open(name, O_BINARY|O_RDONLY);
if (file <= 0) {
// error("Can't open file: %s", name);
} else {
filelen = BLI_filesize(file);
if (filelen == 0) {
// MEM_mallocN complains about MEM_mallocN(0, "bla");
// we don't care....
data = MEM_mallocN(1, "packFile");
} else {
data = MEM_mallocN(filelen, "packFile");
}
if (read(file, data, filelen) == filelen) {
pf = newPackedFileMemory(data, filelen);
}
close(file);
}
waitcursor(0);
return (pf);
}
void packAll()
{
Image *ima;
VFont *vf;
bSample *sample;
ima = G.main->image.first;
while (ima) {
if (ima->packedfile == NULL) {
ima->packedfile = newPackedFile(ima->name);
}
ima= ima->id.next;
}
vf = G.main->vfont.first;
while (vf) {
if (vf->packedfile == NULL) {
vf->packedfile = newPackedFile(vf->name);
}
vf = vf->id.next;
}
sample = samples->first;
while (sample) {
if (sample->packedfile == NULL) {
sound_set_packedfile(sample, newPackedFile(sample->name));
}
sample = sample->id.next;
}
}
/*
// attempt to create a function that generates an unique filename
// this will work when all funtions in fileops.c understand relative filenames...
char * find_new_name(char * name)
{
char tempname[FILE_MAXDIR + FILE_MAXFILE];
char * newname;
if (fop_exists(name)) {
for (number = 1; number <= 999; number++) {
sprintf(tempname, "%s.%03d", name, number);
if (! fop_exists(tempname)) {
break;
}
}
}
newname = mallocN(strlen(tempname) + 1, "find_new_name");
strcpy(newname, tempname);
return(newname);
}
*/
int writePackedFile(char * filename, PackedFile *pf)
{
int file, number, remove_tmp = FALSE;
int ret_value = RET_OK;
char name[FILE_MAXDIR + FILE_MAXFILE];
char tempname[FILE_MAXDIR + FILE_MAXFILE];
/* void * data; */
waitcursor(1);
strcpy(name, filename);
BLI_convertstringcode(name, G.sce, G.scene->r.cfra);
if (BLI_exists(name)) {
for (number = 1; number <= 999; number++) {
sprintf(tempname, "%s.%03d_", name, number);
if (! BLI_exists(tempname)) {
if (BLI_copy_fileops(name, tempname) == RET_OK) {
remove_tmp = TRUE;
}
break;
}
}
}
// make sure the path to the file exists...
RE_make_existing_file(name);
file = open(name, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
if (file >= 0) {
if (write(file, pf->data, pf->size) != pf->size) {
error("Error writing file: %s", name);
ret_value = RET_ERROR;
}
close(file);
} else {
error("Error creating file: %s", name);
ret_value = RET_ERROR;
}
if (remove_tmp) {
if (ret_value == RET_ERROR) {
if (BLI_rename(tempname, name) == RET_ERROR) {
error("Error restoring tempfile. Check files: '%s' '%s'", tempname, name);
}
} else {
if (BLI_delete(tempname, 0, 0) == RET_ERROR) {
error("Error deleting '%s' (ignored)");
}
}
}
waitcursor(0);
return (ret_value);
}
/*
This function compares a packed file to a 'real' file.
It returns an integer indicating if:
PF_EQUAL - the packed file and original file are identical
PF_DIFFERENT - the packed file and original file differ
PF_NOFILE - the original file doens't exist
*/
int checkPackedFile(char * filename, PackedFile * pf)
{
struct stat st;
int ret_val, i, len, file;
char buf[4096];
char name[FILE_MAXDIR + FILE_MAXFILE];
strcpy(name, filename);
BLI_convertstringcode(name, G.sce, G.scene->r.cfra);
if (stat(name, &st)) {
ret_val = PF_NOFILE;
} else if (st.st_size != pf->size) {
ret_val = PF_DIFFERS;
} else {
// we'll have to compare the two...
file = open(name, O_BINARY | O_RDONLY);
if (file < 0) {
ret_val = PF_NOFILE;
} else {
ret_val = PF_EQUAL;
for (i = 0; i < pf->size; i += sizeof(buf)) {
len = pf->size - i;
if (len > sizeof(buf)) {
len = sizeof(buf);
}
if (read(file, buf, len) != len) {
// read error ...
ret_val = PF_DIFFERS;
break;
} else {
if (memcmp(buf, ((char *)pf->data) + i, len)) {
ret_val = PF_DIFFERS;
break;
}
}
}
}
}
return(ret_val);
}
/*
unpackFile() looks at the existing files (abs_name, local_name) and a packed file.
If how == PF_ASK it offers the user a couple of options what to do with the packed file.
It returns a char * to the existing file name / new file name or NULL when
there was an error or when the user desides to cancel the operation.
*/
char * unpackFile(char * abs_name, char * local_name, PackedFile * pf, int how)
{
char menu[6 * (FILE_MAXDIR + FILE_MAXFILE + 100)];
char line[FILE_MAXDIR + FILE_MAXFILE + 100];
char * newname = NULL, * temp = NULL;
// char newabs[FILE_MAXDIR + FILE_MAXFILE];
// char newlocal[FILE_MAXDIR + FILE_MAXFILE];
if (pf != NULL) {
if (how == PF_ASK) {
strcpy(menu, "UnPack file%t");
if (strcmp(abs_name, local_name)) {
switch (checkPackedFile(local_name, pf)) {
case PF_NOFILE:
sprintf(line, "|Create %s%%x%d", local_name, PF_WRITE_LOCAL);
strcat(menu, line);
break;
case PF_EQUAL:
sprintf(line, "|Use %s (identical)%%x%d", local_name, PF_USE_LOCAL);
strcat(menu, line);
break;
case PF_DIFFERS:
sprintf(line, "|Use %s (differs)%%x%d", local_name, PF_USE_LOCAL);
strcat(menu, line);
sprintf(line, "|Overwrite %s%%x%d", local_name, PF_WRITE_LOCAL);
strcat(menu, line);
break;
}
// sprintf(line, "|%%x%d", PF_INVALID);
// strcat(menu, line);
}
switch (checkPackedFile(abs_name, pf)) {
case PF_NOFILE:
sprintf(line, "|Create %s%%x%d", abs_name, PF_WRITE_ORIGINAL);
strcat(menu, line);
break;
case PF_EQUAL:
sprintf(line, "|Use %s (identical)%%x%d", abs_name, PF_USE_ORIGINAL);
strcat(menu, line);
break;
case PF_DIFFERS:
sprintf(line, "|Use %s (differs)%%x%d", abs_name, PF_USE_ORIGINAL);
strcat(menu, line);
sprintf(line, "|Overwrite %s%%x%d", abs_name, PF_WRITE_ORIGINAL);
strcat(menu, line);
break;
}
how = pupmenu(menu);
}
switch (how) {
case -1:
case PF_KEEP:
break;
case PF_USE_LOCAL:
// if file exists use it
if (BLI_exists(local_name)) {
temp = local_name;
break;
}
// else fall through and create it
case PF_WRITE_LOCAL:
if (writePackedFile(local_name, pf) == RET_OK) {
temp = local_name;
}
break;
case PF_USE_ORIGINAL:
// if file exists use it
if (BLI_exists(abs_name)) {
temp = abs_name;
break;
}
// else fall through and create it
case PF_WRITE_ORIGINAL:
if (writePackedFile(abs_name, pf) == RET_OK) {
temp = abs_name;
}
break;
default:
printf("unpackFile: unknown return_value %d\n", how);
break;
}
if (temp) {
newname = MEM_mallocN(strlen(temp) + 1, "unpack_file newname");
strcpy(newname, temp);
}
}
return (newname);
}
int unpackVFont(VFont * vfont, int how)
{
char localname[FILE_MAXDIR + FILE_MAXFILE], fi[FILE_MAXFILE];
char * newname;
int ret_value = RET_ERROR;
if (vfont != NULL) {
strcpy(localname, vfont->name);
BLI_splitdirstring(localname, fi);
sprintf(localname, "//fonts/%s", fi);
newname = unpackFile(vfont->name, localname, vfont->packedfile, how);
if (newname != NULL) {
ret_value = RET_OK;
freePackedFile(vfont->packedfile);
vfont->packedfile = 0;
strcpy(vfont->name, newname);
MEM_freeN(newname);
}
}
return (ret_value);
}
/*
create_local_name() creates a relative (starting with //) name.
Because it is allowed to have /'s and \'s in blenderobject names
we have to remove these first.
*/
void create_local_name(char *localname, char *prefix, char *filename)
{
char tempname[FILE_MAXDIR + FILE_MAXFILE];
int i, len;
strcpy(tempname, filename);
len = strlen(tempname);
for (i = 0; i < len ; i++) {
switch (tempname[i])
{
case '/':
case '\\':
case ' ':
tempname[i] = '_';
break;
}
}
strcpy(localname, prefix);
strcat(localname, tempname);
}
int unpackSample(bSample *sample, int how)
{
char localname[FILE_MAXDIR + FILE_MAXFILE];
char * newname;
int ret_value = RET_ERROR;
PackedFile *pf;
if (sample != NULL) {
create_local_name(localname, "//samples/", sample->id.name + 2);
newname = unpackFile(sample->name, localname, sample->packedfile, how);
if (newname != NULL) {
strcpy(sample->name, newname);
MEM_freeN(newname);
pf = sample->packedfile;
// because samples and sounds can point to the
// same packedfile we have to check them all
sound_set_packedfile(sample, NULL);
freePackedFile(pf);
ret_value = RET_OK;
}
}
return(ret_value);
}
int unpackImage(Image * ima, int how)
{
char localname[FILE_MAXDIR + FILE_MAXFILE];
char * newname;
int ret_value = RET_ERROR;
if (ima != NULL) {
create_local_name(localname, "//textures/", ima->id.name + 2);
newname = unpackFile(ima->name, localname, ima->packedfile, how);
if (newname != NULL) {
ret_value = RET_OK;
freePackedFile(ima->packedfile);
ima->packedfile = 0;
strcpy(ima->name, newname);
MEM_freeN(newname);
free_image_buffers(ima);
}
}
return(ret_value);
}
void unpackAll(int how)
{
Image *ima;
VFont *vf;
bSample *sample;
ima = G.main->image.first;
while (ima) {
if (ima->packedfile) {
unpackImage(ima, how);
}
ima= ima->id.next;
}
vf = G.main->vfont.first;
while (vf) {
if (vf->packedfile) {
unpackVFont(vf, how);
}
vf = vf->id.next;
}
sample = samples->first;
while (sample) {
if (sample->packedfile) {
unpackSample(sample, how);
}
sample = sample->id.next;
}
}

View File

@@ -0,0 +1,269 @@
/* property.c june 2000
*
* ton roosendaal
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
#include "MEM_guardedalloc.h"
#include "DNA_property_types.h"
#include "DNA_object_types.h"
#include "DNA_listBase.h"
#include "BLI_blenlib.h"
#include "BKE_bad_level_calls.h"
#include "BKE_property.h"
void free_property(bProperty *prop)
{
if(prop->poin && prop->poin != &prop->data) MEM_freeN(prop->poin);
MEM_freeN(prop);
}
void free_properties(ListBase *lb)
{
bProperty *prop;
while( (prop= lb->first) ) {
BLI_remlink(lb, prop);
free_property(prop);
}
}
bProperty *copy_property(bProperty *prop)
{
bProperty *propn;
propn= MEM_dupallocN(prop);
if(prop->poin && prop->poin != &prop->data) {
propn->poin= MEM_dupallocN(prop->poin);
}
else propn->poin= &propn->data;
return propn;
}
void copy_properties(ListBase *lbn, ListBase *lbo)
{
bProperty *prop, *propn;
lbn->first= lbn->last= 0;
prop= lbo->first;
while(prop) {
propn= copy_property(prop);
BLI_addtail(lbn, propn);
prop= prop->next;
}
}
void init_property(bProperty *prop)
{
/* also use when property changes type */
if(prop->poin && prop->poin != &prop->data) MEM_freeN(prop->poin);
prop->poin= 0;
prop->otype= prop->type;
prop->data= 0;
switch(prop->type) {
case PROP_BOOL:
prop->poin= &prop->data;
break;
case PROP_INT:
prop->poin= &prop->data;
break;
case PROP_FLOAT:
prop->poin= &prop->data;
break;
case PROP_STRING:
prop->poin= MEM_callocN(MAX_PROPSTRING, "property string");
break;
case PROP_TIME:
prop->poin= &prop->data;
break;
}
}
bProperty *new_property(int type)
{
bProperty *prop;
prop= MEM_callocN(sizeof(bProperty), "property");
prop->type= type;
init_property(prop);
strcpy(prop->name, "prop");
return prop;
}
bProperty *get_property(Object *ob, char *name)
{
bProperty *prop;
prop= ob->prop.first;
while(prop) {
if( strcmp(prop->name, name)==0 ) return prop;
prop= prop->next;
}
return NULL;
}
/* negative: prop is smaller
* positive: prop is larger
*/
int compare_property(bProperty *prop, char *str)
{
// extern int Gdfra; /* sector.c */
float fvalue, ftest;
switch(prop->type) {
case PROP_BOOL:
if(strcasecmp(str, "true")==0) {
if(prop->data==1) return 0;
else return 1;
}
else if(strcasecmp(str, "false")==0) {
if(prop->data==0) return 0;
else return 1;
}
/* no break, do prop_int too! */
case PROP_INT:
return prop->data - atoi(str);
case PROP_FLOAT:
case PROP_TIME:
// WARNING: untested for PROP_TIME
// function isn't used currently
fvalue= *((float *)&prop->data);
ftest= (float)atof(str);
if( fvalue > ftest) return 1;
else if( fvalue < ftest) return -1;
return 0;
case PROP_STRING:
return strcmp(prop->poin, str);
}
return 0;
}
void set_property(bProperty *prop, char *str)
{
// extern int Gdfra; /* sector.c */
switch(prop->type) {
case PROP_BOOL:
if(strcasecmp(str, "true")==0) prop->data= 1;
else if(strcasecmp(str, "false")==0) prop->data= 0;
else prop->data= (atoi(str)!=0);
break;
case PROP_INT:
prop->data= atoi(str);
break;
case PROP_FLOAT:
case PROP_TIME:
*((float *)&prop->data)= (float)atof(str);
break;
case PROP_STRING:
strcpy(prop->poin, str);
break;
}
}
void add_property(bProperty *prop, char *str)
{
// extern int Gdfra; /* sector.c */
switch(prop->type) {
case PROP_BOOL:
case PROP_INT:
prop->data+= atoi(str);
break;
case PROP_FLOAT:
case PROP_TIME:
*((float *)&prop->data)+= (float)atof(str);
break;
case PROP_STRING:
/* strcpy(prop->poin, str); */
break;
}
}
/* reads value of property, sets it in chars in str */
void set_property_valstr(bProperty *prop, char *str)
{
// extern int Gdfra; /* sector.c */
if(str == NULL) return;
switch(prop->type) {
case PROP_BOOL:
case PROP_INT:
sprintf(str, "%d", prop->data);
break;
case PROP_FLOAT:
case PROP_TIME:
sprintf(str, "%f", *((float *)&prop->data));
break;
case PROP_STRING:
BLI_strncpy(str, prop->poin, MAX_PROPSTRING);
break;
}
}
void cp_property(bProperty *prop1, bProperty *prop2)
{
char str[128];
set_property_valstr(prop2, str);
set_property(prop1, str);
}

View File

@@ -0,0 +1,631 @@
/**
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* these all are linked to objects (listbase)
* all data is 'direct data', not Blender lib data.
*/
#include <stdio.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "nla.h" /* For __NLA: Important, do not remove */
#include "DNA_text_types.h"
#include "DNA_controller_types.h"
#include "DNA_sensor_types.h"
#include "DNA_actuator_types.h"
#include "DNA_object_types.h"
#include "BLI_blenlib.h"
#include "BKE_bad_level_calls.h"
#include "BKE_utildefines.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_blender.h"
#include "BKE_sca.h"
void free_text_controllers(Text *txt)
{
Object *ob;
bController *cont;
ob= G.main->object.first;
while(ob) {
cont= ob->controllers.first;
while(cont) {
if(cont->type==CONT_PYTHON) {
bPythonCont *pc;
pc= cont->data;
if(pc->text==txt) pc->text= NULL;
}
cont= cont->next;
}
ob= ob->id.next;
}
}
/* ******************* SENSORS ************************ */
void free_sensor(bSensor *sens)
{
if(sens->links) MEM_freeN(sens->links);
if(sens->data) MEM_freeN(sens->data);
MEM_freeN(sens);
}
void free_sensors(ListBase *lb)
{
bSensor *sens;
while((sens= lb->first)) {
BLI_remlink(lb, sens);
free_sensor(sens);
}
}
bSensor *copy_sensor(bSensor *sens)
{
bSensor *sensn;
sensn= MEM_dupallocN(sens);
sensn->flag |= SENS_NEW;
if(sens->data) {
sensn->data= MEM_dupallocN(sens->data);
}
if(sens->links) sensn->links= MEM_dupallocN(sens->links);
return sensn;
}
void copy_sensors(ListBase *lbn, ListBase *lbo)
{
bSensor *sens, *sensn;
lbn->first= lbn->last= 0;
sens= lbo->first;
while(sens) {
sensn= copy_sensor(sens);
BLI_addtail(lbn, sensn);
sens= sens->next;
}
}
void init_sensor(bSensor *sens)
{
/* also use when sensor changes type */
bNearSensor *ns;
bMouseSensor *ms;
if(sens->data) MEM_freeN(sens->data);
sens->data= NULL;
sens->pulse = 0;
switch(sens->type) {
case SENS_ALWAYS:
sens->pulse = 1;
break;
case SENS_TOUCH:
sens->data= MEM_callocN(sizeof(bTouchSensor), "touchsens");
break;
case SENS_NEAR:
ns=sens->data= MEM_callocN(sizeof(bNearSensor), "nearsens");
ns->dist= 1.0;
ns->resetdist= 2.0;
break;
case SENS_KEYBOARD:
sens->data= MEM_callocN(sizeof(bKeyboardSensor), "keysens");
break;
case SENS_PROPERTY:
sens->data= MEM_callocN(sizeof(bPropertySensor), "propsens");
break;
case SENS_MOUSE:
ms=sens->data= MEM_callocN(sizeof(bMouseSensor), "mousesens");
ms->type= LEFTMOUSE;
break;
case SENS_COLLISION:
sens->data= MEM_callocN(sizeof(bCollisionSensor), "colsens");
break;
case SENS_RADAR:
sens->data= MEM_callocN(sizeof(bRadarSensor), "radarsens");
break;
case SENS_RANDOM:
sens->data= MEM_callocN(sizeof(bRandomSensor), "randomsens");
break;
case SENS_RAY:
sens->data= MEM_callocN(sizeof(bRaySensor), "raysens");
break;
case SENS_MESSAGE:
sens->data= MEM_callocN(sizeof(bMessageSensor), "messagesens");
break;
default:
; /* this is very severe... I cannot make any memory for this */
/* logic brick... */
}
}
bSensor *new_sensor(int type)
{
bSensor *sens;
sens= MEM_callocN(sizeof(bSensor), "Sensor");
sens->type= type;
sens->flag= SENS_SHOW;
init_sensor(sens);
strcpy(sens->name, "sensor");
make_unique_prop_names(sens->name);
return sens;
}
/* ******************* CONTROLLERS ************************ */
void unlink_controller(bController *cont)
{
bSensor *sens;
Object *ob;
int a, removed;
/* check for controller pointers in sensors */
ob= G.main->object.first;
while(ob) {
sens= ob->sensors.first;
while(sens) {
removed= 0;
for(a=0; a<sens->totlinks; a++) {
if(removed) (sens->links)[a-1] = (sens->links)[a];
else if((sens->links)[a] == cont) removed= 1;
}
if(removed) {
sens->totlinks--;
if(sens->totlinks==0) {
MEM_freeN(sens->links);
sens->links= NULL;
}
}
sens= sens->next;
}
ob= ob->id.next;
}
}
void unlink_controllers(ListBase *lb)
{
bController *cont;
for (cont= lb->first; cont; cont= cont->next)
unlink_controller(cont);
}
void free_controller(bController *cont)
{
if(cont->links) MEM_freeN(cont->links);
/* the controller itself */
if(cont->data) MEM_freeN(cont->data);
MEM_freeN(cont);
}
void free_controllers(ListBase *lb)
{
bController *cont;
while((cont= lb->first)) {
BLI_remlink(lb, cont);
if(cont->slinks) MEM_freeN(cont->slinks);
free_controller(cont);
}
}
bController *copy_controller(bController *cont)
{
bController *contn;
cont->mynew=contn= MEM_dupallocN(cont);
contn->flag |= CONT_NEW;
if(cont->data) {
contn->data= MEM_dupallocN(cont->data);
}
if(cont->links) contn->links= MEM_dupallocN(cont->links);
contn->slinks= NULL;
contn->totslinks= 0;
return contn;
}
void copy_controllers(ListBase *lbn, ListBase *lbo)
{
bController *cont, *contn;
lbn->first= lbn->last= 0;
cont= lbo->first;
while(cont) {
contn= copy_controller(cont);
BLI_addtail(lbn, contn);
cont= cont->next;
}
}
void init_controller(bController *cont)
{
/* also use when controller changes type, leave actuators... */
if(cont->data) MEM_freeN(cont->data);
cont->data= 0;
switch(cont->type) {
case CONT_EXPRESSION:
cont->data= MEM_callocN(sizeof(bExpressionCont), "expcont");
break;
case CONT_PYTHON:
cont->data= MEM_callocN(sizeof(bPythonCont), "pycont");
break;
}
}
bController *new_controller(int type)
{
bController *cont;
cont= MEM_callocN(sizeof(bController), "Controller");
cont->type= type;
cont->flag= CONT_SHOW;
init_controller(cont);
strcpy(cont->name, "cont");
make_unique_prop_names(cont->name);
return cont;
}
/* ******************* ACTUATORS ************************ */
void unlink_actuator(bActuator *act)
{
bController *cont;
Object *ob;
int a, removed;
/* check for actuator pointers in controllers */
ob= G.main->object.first;
while(ob) {
cont= ob->controllers.first;
while(cont) {
removed= 0;
for(a=0; a<cont->totlinks; a++) {
if(removed) (cont->links)[a-1] = (cont->links)[a];
else if((cont->links)[a] == act) removed= 1;
}
if(removed) {
cont->totlinks--;
if(cont->totlinks==0) {
MEM_freeN(cont->links);
cont->links= NULL;
}
}
cont= cont->next;
}
ob= ob->id.next;
}
}
void unlink_actuators(ListBase *lb)
{
bActuator *act;
for (act= lb->first; act; act= act->next)
unlink_actuator(act);
}
void free_actuator(bActuator *act)
{
if(act->data) MEM_freeN(act->data);
MEM_freeN(act);
}
void free_actuators(ListBase *lb)
{
bActuator *act;
while((act= lb->first)) {
BLI_remlink(lb, act);
free_actuator(act);
}
}
bActuator *copy_actuator(bActuator *act)
{
bActuator *actn;
act->mynew=actn= MEM_dupallocN(act);
actn->flag |= ACT_NEW;
if(act->data) {
actn->data= MEM_dupallocN(act->data);
}
return actn;
}
void copy_actuators(ListBase *lbn, ListBase *lbo)
{
bActuator *act, *actn;
lbn->first= lbn->last= 0;
act= lbo->first;
while(act) {
actn= copy_actuator(act);
BLI_addtail(lbn, actn);
act= act->next;
}
}
void init_actuator(bActuator *act)
{
/* also use when actuator changes type */
bObjectActuator *oa;
if(act->data) MEM_freeN(act->data);
act->data= 0;
switch(act->type) {
#ifdef __NLA
case ACT_ACTION:
act->data= MEM_callocN(sizeof(bActionActuator), "actionact");
break;
#endif
case ACT_SOUND:
act->data= MEM_callocN(sizeof(bSoundActuator), "soundact");
break;
case ACT_CD:
act->data= MEM_callocN(sizeof(bCDActuator), "cdact");
break;
case ACT_OBJECT:
act->data= MEM_callocN(sizeof(bObjectActuator), "objectact");
oa= act->data;
oa->flag= 15;
break;
case ACT_IPO:
act->data= MEM_callocN(sizeof(bIpoActuator), "ipoact");
break;
case ACT_PROPERTY:
act->data= MEM_callocN(sizeof(bPropertyActuator), "propact");
break;
case ACT_CAMERA:
act->data= MEM_callocN(sizeof(bCameraActuator), "camact");
break;
case ACT_EDIT_OBJECT:
act->data= MEM_callocN(sizeof(bEditObjectActuator), "editobact");
break;
case ACT_CONSTRAINT:
act->data= MEM_callocN(sizeof(bConstraintActuator), "cons act");
break;
case ACT_SCENE:
act->data= MEM_callocN(sizeof(bSceneActuator), "scene act");
break;
case ACT_GROUP:
act->data= MEM_callocN(sizeof(bGroupActuator), "group act");
break;
case ACT_RANDOM:
act->data= MEM_callocN(sizeof(bRandomActuator), "random act");
break;
case ACT_MESSAGE:
act->data= MEM_callocN(sizeof(bMessageActuator), "message act");
break;
case ACT_GAME:
act->data= MEM_callocN(sizeof(bGameActuator), "game act");
break;
case ACT_VISIBILITY:
act->data= MEM_callocN(sizeof(bVisibilityActuator), "visibility act");
break;
default:
; /* this is very severe... I cannot make any memory for this */
/* logic brick... */
}
}
bActuator *new_actuator(int type)
{
bActuator *act;
act= MEM_callocN(sizeof(bActuator), "Actuator");
act->type= type;
act->flag= ACT_SHOW;
init_actuator(act);
strcpy(act->name, "act");
make_unique_prop_names(act->name);
return act;
}
/* ******************** GENERAL ******************* */
void clear_sca_new_poins_ob(Object *ob)
{
bSensor *sens;
bController *cont;
bActuator *act;
sens= ob->sensors.first;
while(sens) {
sens->flag &= ~SENS_NEW;
sens= sens->next;
}
cont= ob->controllers.first;
while(cont) {
cont->mynew= NULL;
cont->flag &= ~CONT_NEW;
cont= cont->next;
}
act= ob->actuators.first;
while(act) {
act->mynew= NULL;
act->flag &= ~ACT_NEW;
act= act->next;
}
}
void clear_sca_new_poins()
{
Object *ob;
ob= G.main->object.first;
while(ob) {
clear_sca_new_poins_ob(ob);
ob= ob->id.next;
}
}
void set_sca_new_poins_ob(Object *ob)
{
bSensor *sens;
bController *cont;
bActuator *act;
int a;
sens= ob->sensors.first;
while(sens) {
if(sens->flag & SENS_NEW) {
for(a=0; a<sens->totlinks; a++) {
if(sens->links[a] && sens->links[a]->mynew)
sens->links[a]= sens->links[a]->mynew;
}
}
sens= sens->next;
}
cont= ob->controllers.first;
while(cont) {
if(cont->flag & CONT_NEW) {
for(a=0; a<cont->totlinks; a++) {
if( cont->links[a] && cont->links[a]->mynew)
cont->links[a]= cont->links[a]->mynew;
}
}
cont= cont->next;
}
act= ob->actuators.first;
while(act) {
if(act->flag & ACT_NEW) {
if(act->type==ACT_EDIT_OBJECT) {
bEditObjectActuator *eoa= act->data;
ID_NEW(eoa->ob);
}
else if(act->type==ACT_SCENE) {
bSceneActuator *sca= act->data;
ID_NEW(sca->camera);
}
else if(act->type==ACT_CAMERA) {
bCameraActuator *ca= act->data;
ID_NEW(ca->ob);
}
else if(act->type==ACT_SCENE) {
bSceneActuator *sca= act->data;
ID_NEW(sca->camera);
}
}
act= act->next;
}
}
void set_sca_new_poins()
{
Object *ob;
ob= G.main->object.first;
while(ob) {
set_sca_new_poins_ob(ob);
ob= ob->id.next;
}
}
void sca_remove_ob_poin(Object *obt, Object *ob)
{
bSensor *sens;
bMessageSensor *ms;
bActuator *act;
bCameraActuator *ca;
bSceneActuator *sa;
bEditObjectActuator *eoa;
bPropertyActuator *pa;
bMessageActuator *ma;
sens= obt->sensors.first;
while(sens) {
switch(sens->type) {
case SENS_MESSAGE:
ms= sens->data;
if(ms->fromObject==ob) ms->fromObject= NULL;
}
sens= sens->next;
}
act= obt->actuators.first;
while(act) {
switch(act->type) {
case ACT_CAMERA:
ca= act->data;
if(ca->ob==ob) ca->ob= NULL;
break;
case ACT_PROPERTY:
pa= act->data;
if(pa->ob==ob) pa->ob= NULL;
break;
case ACT_SCENE:
sa= act->data;
if(sa->camera==ob) sa->camera= NULL;
break;
case ACT_EDIT_OBJECT:
eoa= act->data;
if(eoa->ob==ob) eoa->ob= NULL;
break;
case ACT_MESSAGE:
ma= act->data;
if(ma->toObject==ob) ma->toObject= NULL;
break;
}
act= act->next;
}
}

View File

@@ -0,0 +1,536 @@
/* scene.c MIXED MODEL
*
* jan 95
*
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <stdio.h>
#ifndef WIN32
#include <unistd.h>
#else
#include "BLI_winstuff.h"
#include <io.h>
#endif
#include "MEM_guardedalloc.h"
#include "nla.h" /* for __NLA : IMPORTANT Do not delete me yet! */
#ifdef __NLA /* for __NLA : IMPORTANT Do not delete me yet! */
#include "DNA_armature_types.h" /* for __NLA : IMPORTANT Do not delete me yet! */
#include "BKE_armature.h" /* for __NLA : IMPORTANT Do not delete me yet! */
#include "BKE_action.h" /* for __NLA : IMPORTANT Do not delete me yet! */
#endif /* for __NLA : IMPORTANT Do not delete me yet! */
#include "DNA_constraint_types.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_scriptlink_types.h"
#include "DNA_meta_types.h"
#include "DNA_ika_types.h"
#include "DNA_lamp_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_group_types.h"
#include "DNA_curve_types.h"
#include "DNA_userdef_types.h"
#include "BLI_blenlib.h"
#include "BKE_bad_level_calls.h"
#include "BKE_utildefines.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_anim.h"
#include "BKE_library.h"
#include "BPY_extern.h"
#include "BKE_scene.h"
#include "BKE_world.h"
#include "BKE_ipo.h"
#include "BKE_ika.h"
#include "BKE_key.h"
void free_avicodecdata(AviCodecData *acd)
{
if (acd) {
if (acd->lpFormat){
MEM_freeN(acd->lpFormat);
acd->lpFormat = NULL;
acd->cbFormat = 0;
}
if (acd->lpParms){
MEM_freeN(acd->lpParms);
acd->lpParms = NULL;
acd->cbParms = 0;
}
}
}
/* niet scene zelf vrijgeven */
void free_scene(Scene *sce)
{
Base *base;
base= sce->base.first;
while(base) {
base->object->id.us--;
base= base->next;
}
/* pas op: niet objects vrijgeven! */
BLI_freelistN(&sce->base);
free_editing(sce->ed);
if(sce->radio) MEM_freeN(sce->radio);
if(sce->fcam) MEM_freeN(sce->fcam);
sce->radio= 0;
BPY_free_scriptlink(&sce->scriptlink);
if (sce->r.avicodecdata) {
free_avicodecdata(sce->r.avicodecdata);
MEM_freeN(sce->r.avicodecdata);
sce->r.avicodecdata = NULL;
}
}
Scene *add_scene(char *name)
{
Scene *sce;
sce= alloc_libblock(&G.main->scene, ID_SCE, name);
sce->lay= 1;
sce->r.mode= R_GAMMA;
sce->r.cfra= 1;
sce->r.sfra= 1;
sce->r.efra= 250;
sce->r.xsch= 320;
sce->r.ysch= 256;
sce->r.xasp= 1;
sce->r.yasp= 1;
sce->r.xparts= 1;
sce->r.yparts= 1;
sce->r.size= 100;
sce->r.planes= 24;
sce->r.quality= 90;
sce->r.framapto= 100;
sce->r.images= 100;
sce->r.framelen= 1.0;
sce->r.frs_sec= 25;
sce->r.xplay= 640;
sce->r.yplay= 480;
sce->r.freqplay= 60;
sce->r.depth= 32;
sce->r.stereomode = 1; // no stereo
strcpy(sce->r.backbuf, "//backbuf");
strcpy(sce->r.pic, U.renderdir);
strcpy(sce->r.ftype, "//ftype");
BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
sce->r.osa= 8;
return sce;
}
int object_in_scene(Object *ob, Scene *sce)
{
Base *base;
base= sce->base.first;
while(base) {
if(base->object == ob) return 1;
base= base->next;
}
return 0;
}
void sort_baselist(Scene *sce)
{
/* alles in volgorde van parent en track */
ListBase tempbase, noparentbase, notyetbase;
Base *base, *test=NULL;
Object *par;
int doit, domore= 0, lastdomore=1;
/* volgorde gelijk houden als er niets veranderd is! */
/* hier waren problemen met campos array's: volgorde camera's is van belang */
while(domore!=lastdomore) {
lastdomore= domore;
domore= 0;
tempbase.first= tempbase.last= 0;
noparentbase.first= noparentbase.last= 0;
notyetbase.first= notyetbase.last= 0;
while( (base= sce->base.first) ) {
BLI_remlink(&sce->base, base);
par= 0;
if(base->object->type==OB_IKA) {
Ika *ika= base->object->data;
par= ika->parent;
}
if(par || base->object->parent || base->object->track) {
doit= 0;
if(base->object->parent) doit++;
if(base->object->track) doit++;
/* Count constraints */
{
bConstraint *con;
for (con = base->object->constraints.first; con; con=con->next){
switch (con->type){
case CONSTRAINT_TYPE_KINEMATIC:
{
bKinematicConstraint *data=con->data;
if (data->tar) doit++;
}
break;
case CONSTRAINT_TYPE_TRACKTO:
{
bTrackToConstraint *data=con->data;
if (data->tar) doit++;
}
break;
case CONSTRAINT_TYPE_NULL:
break;
case CONSTRAINT_TYPE_ROTLIKE:
{
bRotateLikeConstraint *data=con->data;
if (data->tar) doit++;
}
break;
case CONSTRAINT_TYPE_LOCLIKE:
{
bLocateLikeConstraint *data=con->data;
if (data->tar) doit++;
}
break;
case CONSTRAINT_TYPE_ACTION:
{
bActionConstraint *data=con->data;
if (data->tar) doit++;
}
break;
default:
break;
}
}
}
if(par) doit++;
test= tempbase.first;
while(test) {
if(test->object==base->object->parent) doit--;
if(test->object==base->object->track) doit--;
if(test->object==par) doit--;
/* Decrement constraints */
{
bConstraint *con;
for (con = base->object->constraints.first; con; con=con->next){
switch (con->type){
case CONSTRAINT_TYPE_KINEMATIC:
{
bKinematicConstraint *data=con->data;
if (test->object == data->tar && test->object!=base->object) doit--;
}
break;
case CONSTRAINT_TYPE_TRACKTO:
{
bTrackToConstraint *data=con->data;
if (test->object == data->tar && test->object!=base->object) doit--;
}
break;
case CONSTRAINT_TYPE_NULL:
break;
case CONSTRAINT_TYPE_ROTLIKE:
{
bRotateLikeConstraint *data=con->data;
if (test->object == data->tar && test->object!=base->object) doit--;
}
break;
case CONSTRAINT_TYPE_LOCLIKE:
{
bLocateLikeConstraint *data=con->data;
if (test->object == data->tar && test->object!=base->object) doit--;
}
break;
case CONSTRAINT_TYPE_ACTION:
{
bActionConstraint *data=con->data;
if (test->object == data->tar && test->object!=base->object) doit--;
}
break;
default:
break;
}
}
}
if(doit==0) break;
test= test->next;
}
if(test) BLI_insertlink(&tempbase, test, base);
else {
BLI_addhead(&tempbase, base);
domore++;
}
}
else BLI_addtail(&noparentbase, base);
}
sce->base= noparentbase;
addlisttolist(&sce->base, &tempbase);
addlisttolist(&sce->base, &notyetbase);
}
}
void set_scene_bg(Scene *sce)
{
Base *base;
Object *ob;
Group *group;
GroupObject *go;
int flag;
G.scene= sce;
/* objecten deselecteren (voor dataselect) */
ob= G.main->object.first;
while(ob) {
ob->flag &= ~(SELECT|OB_FROMGROUP);
ob= ob->id.next;
}
/* group flags again */
group= G.main->group.first;
while(group) {
go= group->gobject.first;
while(go) {
if(go->ob) go->ob->flag |= OB_FROMGROUP;
go= go->next;
}
group= group->id.next;
}
/* baselijst sorteren */
sort_baselist(sce);
/* layers en flags uit bases naar objecten kopieeren */
base= G.scene->base.first;
while(base) {
base->object->lay= base->lay;
base->flag &= ~OB_FROMGROUP;
flag= base->object->flag & OB_FROMGROUP;
base->flag |= flag;
base->object->ctime= -1234567.0; /* forceer ipo */
base= base->next;
}
do_all_ipos(); /* layers/materials */
BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
do_all_keys();
#ifdef __NLA
do_all_actions();
#endif
do_all_ikas();
}
void set_scene_name(char *name)
{
Scene *sce;
for (sce= G.main->scene.first; sce; sce= sce->id.next) {
if (BLI_streq(name, sce->id.name+2)) {
set_scene_bg(sce);
return;
}
}
error("Can't find scene: %s", name);
}
/* used by metaballs
* doesnt return the original duplicated object, only dupli's
*/
int next_object(int val, Base **base, Object **ob)
{
extern ListBase duplilist;
static Object *dupob;
static int fase;
int run_again=1;
/* init */
if(val==0) {
fase= F_START;
dupob= 0;
}
else {
/* run_again is set when a duplilist has been ended */
while(run_again) {
run_again= 0;
/* de eerste base */
if(fase==F_START) {
*base= G.scene->base.first;
if(*base) {
*ob= (*base)->object;
fase= F_SCENE;
}
else {
/* uitzondering: een lege scene */
if(G.scene->set && G.scene->set->base.first) {
*base= G.scene->set->base.first;
*ob= (*base)->object;
fase= F_SET;
}
}
}
else {
if(*base && fase!=F_DUPLI) {
*base= (*base)->next;
if(*base) *ob= (*base)->object;
else {
if(fase==F_SCENE) {
/* de scene is klaar, we gaan door met de set */
if(G.scene->set && G.scene->set->base.first) {
*base= G.scene->set->base.first;
*ob= (*base)->object;
fase= F_SET;
}
}
}
}
}
if(*base == 0) fase= F_START;
else {
if(fase!=F_DUPLI) {
if( (*base)->object->transflag & OB_DUPLI) {
make_duplilist(G.scene, (*base)->object);
dupob= duplilist.first;
}
}
/* dupli's afhandelen */
if(dupob) {
*ob= dupob;
fase= F_DUPLI;
dupob= dupob->id.next;
}
else if(fase==F_DUPLI) {
fase= F_SCENE;
free_duplilist();
run_again= 1;
}
}
}
}
return fase;
}
Object *scene_find_camera(Scene *sc)
{
Base *base;
for (base= sc->base.first; base; base= base->next)
if (base->object->type==OB_CAMERA)
return base->object;
return NULL;
}
Base *scene_add_base(Scene *sce, Object *ob)
{
Base *b= MEM_callocN(sizeof(*b), "scene_add_base");
BLI_addhead(&sce->base, b);
b->object= ob;
b->flag= ob->flag;
b->lay= ob->lay;
return b;
}
void scene_deselect_all(Scene *sce)
{
Base *b;
for (b= sce->base.first; b; b= b->next) {
b->flag&= ~SELECT;
b->object->flag= b->flag;
}
}
void scene_select_base(Scene *sce, Base *selbase)
{
scene_deselect_all(sce);
selbase->flag |= SELECT;
selbase->object->flag= selbase->flag;
sce->basact= selbase;
}

View File

@@ -0,0 +1,53 @@
/* screen.c dec/jan 93/94 GRAPHICS
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "DNA_screen_types.h"
#include "BKE_bad_level_calls.h"
#include "BLI_blenlib.h"
/* don't free screen itself */
void free_screen(bScreen *sc)
{
unlink_screen(sc);
BLI_freelistN(&sc->vertbase);
BLI_freelistN(&sc->edgebase);
BLI_freelistN(&sc->areabase);
}

View File

@@ -0,0 +1,112 @@
/**
* sound.c (mar-2001 nzc)
*
* $Id$
*/
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "DNA_scene_types.h"
#include "DNA_sound_types.h"
#include "DNA_packedFile_types.h"
#include "BKE_utildefines.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_sound.h"
#include "BKE_packedFile.h"
ListBase _samples = {0,0}, *samples = &_samples;
void sound_free_sound(bSound *sound)
{
/* this crashes blender, PLEASE fix! */
// still crashes :(
//if (sound) {
// sound_set_sample(sound, NULL);
//}
}
void sound_free_sample(bSample *sample)
{
if (sample) {
if (sample->data != &sample->fakedata[0] && sample->data != NULL) {
MEM_freeN(sample->data);
sample->data = &sample->fakedata[0];
}
if (sample->packedfile) {
freePackedFile(sample->packedfile); //FIXME: crashes sometimes
sample->packedfile = NULL;
}
if (sample->alindex != SAMPLE_INVALID) {
// AUD_free_sample(sample->snd_sample);
sample->alindex = SAMPLE_INVALID;
}
sample->type = SAMPLE_INVALID;
}
}
void sound_set_packedfile(bSample *sample, PackedFile *pf)
{
bSound *sound;
if (sample) {
sample->packedfile = pf;
sound = G.main->sound.first;
while (sound) {
if (sound->sample == sample) {
sound->newpackedfile = pf;
if (pf == NULL) {
strcpy(sound->name, sample->name);
}
}
sound = sound->id.next;
}
}
}
PackedFile* sound_find_packedfile(bSound *sound)
{
bSound *search;
PackedFile *pf = NULL;
char soundname[FILE_MAXDIR + FILE_MAXFILE], searchname[FILE_MAXDIR + FILE_MAXFILE];
// convert sound->name to abolute filename
strcpy(soundname, sound->name);
BLI_convertstringcode(soundname, G.sce, G.scene->r.cfra);
search = G.main->sound.first;
while (search) {
if (search->sample && search->sample->packedfile) {
strcpy(searchname, search->sample->name);
BLI_convertstringcode(searchname, G.sce, G.scene->r.cfra);
if (BLI_streq(searchname, soundname)) {
pf = search->sample->packedfile;
break;
}
}
if (search->newpackedfile) {
strcpy(searchname, search->name);
BLI_convertstringcode(searchname, G.sce, G.scene->r.cfra);
if (BLI_streq(searchname, soundname)) {
pf = search->newpackedfile;
break;
}
}
search = search->id.next;
}
return (pf);
}

View File

@@ -0,0 +1,890 @@
/* subsurf.c MIXED MODEL
*
* jun 2001
*
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "BKE_bad_level_calls.h"
#include "BKE_global.h"
#include "BKE_mesh.h"
#include "BKE_subsurf.h"
#include "BKE_displist.h"
#include "BLI_blenlib.h"
#include "BLI_editVert.h"
#include "BLI_arithb.h"
#include "BLI_linklist.h"
#include "BLI_memarena.h"
/*
* TODO
*
* make uvco's && vcol's properly subdivided
* - requires moving uvco and vcol data to vertices
* (where it belongs?), or making sharedness explicit
* remove/integrate zsl functions
* clean up uvco && vcol stuff
* add option to update subsurf only after done transverting
* decouple display subdivlevel and render subdivlevel
* look into waves/particles with subsurfs
* groan... make it work with sticky?
* U check if storing tfaces (clut, tpage) in a displist is
* going to be a mem problem (for example, on duplicate)
* U write game blender convert routine
* U thorough rendering check + background
*
*/
/****/
static float *Vec2Cpy(float *t, float *a) {
t[0]= a[0];
t[1]= a[1];
return t;
}
static float *Vec3Cpy(float *t, float *a) {
t[0]= a[0];
t[1]= a[1];
t[2]= a[2];
return t;
}
static float *Vec2CpyI(float *t, float x, float y) {
t[0]= x;
t[1]= y;
return t;
}
static float *Vec3CpyI(float *t, float x, float y, float z) {
t[0]= x;
t[1]= y;
t[2]= z;
return t;
}
static float *Vec2AvgT(float *t, float *a, float *b) {
t[0]= (a[0]+b[0])*0.5f;
t[1]= (a[1]+b[1])*0.5f;
return t;
}
static float *Vec3AvgT(float *t, float *a, float *b) {
t[0]= (a[0]+b[0])*0.5f;
t[1]= (a[1]+b[1])*0.5f;
t[2]= (a[2]+b[2])*0.5f;
return t;
}
static float *Vec3AddT(float *t, float *a, float *b) {
t[0]= a[0]+b[0];
t[1]= a[1]+b[1];
t[2]= a[2]+b[2];
return t;
}
static float *Vec2Add(float *ta, float *b) {
ta[0]+= b[0];
ta[1]+= b[1];
ta[2]+= b[2];
return ta;
}
static float *Vec3MulNT(float *t, float *a, float n) {
t[0]= a[0]*n;
t[1]= a[1]*n;
t[2]= a[2]*n;
return t;
}
static float *Vec3Add(float *ta, float *b) {
ta[0]+= b[0];
ta[1]+= b[1];
ta[2]+= b[2];
return ta;
}
static float *Vec3MulN(float *ta, float n) {
ta[0]*= n;
ta[1]*= n;
ta[2]*= n;
return ta;
}
/****/
typedef struct _HyperVert HyperVert;
typedef struct _HyperEdge HyperEdge;
typedef struct _HyperFace HyperFace;
typedef struct _HyperMesh HyperMesh;
struct _HyperVert {
HyperVert *next;
float co[3];
HyperVert *nmv;
LinkNode *edges, *faces;
};
struct _HyperEdge {
HyperEdge *next;
HyperVert *v[2];
HyperVert *ep;
LinkNode *faces;
};
struct _HyperFace {
HyperFace *next;
int nverts;
HyperVert **verts;
HyperEdge **edges;
HyperVert *mid;
unsigned char (*vcol)[4];
float (*uvco)[2];
/* for getting back tface, matnr, etc */
union {
int ind;
EditVlak *ef;
} orig;
};
struct _HyperMesh {
HyperVert *verts;
HyperEdge *edges;
HyperFace *faces;
Mesh *orig_me;
short hasuvco, hasvcol;
MemArena *arena;
};
/***/
static HyperEdge *hypervert_find_edge(HyperVert *v, HyperVert *to) {
LinkNode *l;
for (l= v->edges; l; l= l->next) {
HyperEdge *e= l->link;
if ((e->v[0]==v&&e->v[1]==to) || (e->v[1]==v&&e->v[0]==to))
return e;
}
return NULL;
}
static int hyperedge_is_boundary(HyperEdge *e) {
/* len(e->faces) <= 1 */
return (!e->faces || !e->faces->next);
}
static int hypervert_is_boundary(HyperVert *v) {
LinkNode *l;
for (l= v->edges; l; l= l->next)
if (hyperedge_is_boundary(l->link))
return 1;
return 0;
}
static HyperVert *hyperedge_other_vert(HyperEdge *e, HyperVert *a) {
return (a==e->v[0])?e->v[1]:e->v[0];
}
static HyperVert *hypermesh_add_vert(HyperMesh *hme, float *co) {
HyperVert *hv= BLI_memarena_alloc(hme->arena, sizeof(*hv));
hv->nmv= NULL;
hv->edges= NULL;
hv->faces= NULL;
Vec3Cpy(hv->co, co);
hv->next= hme->verts;
hme->verts= hv;
return hv;
}
static HyperEdge *hypermesh_add_edge(HyperMesh *hme, HyperVert *v1, HyperVert *v2) {
HyperEdge *he= BLI_memarena_alloc(hme->arena, sizeof(*he));
BLI_linklist_prepend_arena(&v1->edges, he, hme->arena);
BLI_linklist_prepend_arena(&v2->edges, he, hme->arena);
he->v[0]= v1;
he->v[1]= v2;
he->ep= NULL;
he->faces= NULL;
he->next= hme->edges;
hme->edges= he;
return he;
}
static HyperFace *hypermesh_add_face(HyperMesh *hme, HyperVert **verts, int nverts) {
HyperFace *f= BLI_memarena_alloc(hme->arena, sizeof(*f));
HyperVert *last;
int j;
f->mid= NULL;
f->vcol= NULL;
f->uvco= NULL;
f->nverts= nverts;
f->verts= BLI_memarena_alloc(hme->arena, sizeof(*f->verts)*f->nverts);
f->edges= BLI_memarena_alloc(hme->arena, sizeof(*f->edges)*f->nverts);
last= verts[nverts-1];
for (j=0; j<nverts; j++) {
HyperVert *v= verts[j];
HyperEdge *e= hypervert_find_edge(v, last);
if (!e)
e= hypermesh_add_edge(hme, v, last);
f->verts[j]= v;
f->edges[j]= e;
BLI_linklist_prepend_arena(&v->faces, f, hme->arena);
BLI_linklist_prepend_arena(&e->faces, f, hme->arena);
last= v;
}
f->next= hme->faces;
hme->faces= f;
return f;
}
static HyperMesh *hypermesh_new(void) {
HyperMesh *hme= MEM_mallocN(sizeof(*hme), "hme");
hme->verts= NULL;
hme->edges= NULL;
hme->faces= NULL;
hme->orig_me= NULL;
hme->hasuvco= hme->hasvcol= 0;
hme->arena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE);
return hme;
}
static HyperMesh *hypermesh_from_mesh(Mesh *me, DispList *dlverts) {
HyperMesh *hme= hypermesh_new();
HyperVert **vert_tbl;
MFace *mface= me->mface;
int i, j;
hme->orig_me= me;
if (me->tface)
hme->hasvcol= hme->hasuvco= 1;
else if (me->mcol)
hme->hasvcol= 1;
vert_tbl= MEM_mallocN(sizeof(*vert_tbl)*me->totvert, "vert_tbl");
for (i= 0; i<me->totvert; i++) {
if (dlverts)
vert_tbl[i]= hypermesh_add_vert(hme, &dlverts->verts[i*3]);
else
vert_tbl[i]= hypermesh_add_vert(hme, me->mvert[i].co);
}
for (i=0; i<me->totface; i++) {
MFace *mf= &mface[i];
if (mf->v3) {
int nverts= mf->v4?4:3;
HyperVert *verts[4];
HyperFace *f;
verts[0]= vert_tbl[mf->v1];
verts[1]= vert_tbl[mf->v2];
verts[2]= vert_tbl[mf->v3];
if (nverts>3)
verts[3]= vert_tbl[mf->v4];
f= hypermesh_add_face(hme, verts, nverts);
f->orig.ind= i;
if (hme->hasuvco) {
TFace *tf= &((TFace*) me->tface)[i];
f->uvco= BLI_memarena_alloc(hme->arena, sizeof(*f->uvco)*nverts);
for (j=0; j<nverts; j++)
Vec2Cpy(f->uvco[j], tf->uv[j]);
f->vcol= BLI_memarena_alloc(hme->arena, sizeof(*f->vcol)*nverts);
for (j=0; j<nverts; j++)
*((unsigned int*) f->vcol[j])= tf->col[j];
} else if (hme->hasvcol) {
MCol *mcol= &me->mcol[i*4];
f->vcol= BLI_memarena_alloc(hme->arena, sizeof(*f->vcol)*nverts);
for (j=0; j<nverts; j++)
*((unsigned int*) f->vcol[j])= *((unsigned int*) &mcol[j]);
}
} else {
hypermesh_add_edge(hme, vert_tbl[mf->v1], vert_tbl[mf->v2]);
}
}
MEM_freeN(vert_tbl);
return hme;
}
static HyperMesh *hypermesh_from_editmesh(EditVert *everts, EditEdge *eedges, EditVlak *efaces) {
HyperMesh *hme= hypermesh_new();
EditVert *ev, *prevev;
EditEdge *ee;
EditVlak *ef;
/* hack, tuck the new hypervert pointer into
* the ev->prev link so we can find it easy,
* then restore real prev links later.
*/
for (ev= everts; ev; ev= ev->next)
ev->prev= (EditVert*) hypermesh_add_vert(hme, ev->co);
for (ee= eedges; ee; ee= ee->next)
hypermesh_add_edge(hme, (HyperVert*) ee->v1->prev, (HyperVert*) ee->v2->prev);
for (ef= efaces; ef; ef= ef->next) {
int nverts= ef->v4?4:3;
HyperVert *verts[4];
HyperFace *f;
verts[0]= (HyperVert*) ef->v1->prev;
verts[1]= (HyperVert*) ef->v2->prev;
verts[2]= (HyperVert*) ef->v3->prev;
if (nverts>3)
verts[3]= (HyperVert*) ef->v4->prev;
f= hypermesh_add_face(hme, verts, nverts);
f->orig.ef= ef;
}
/* see hack above, restore the prev links */
for (prevev= NULL, ev= everts; ev; prevev= ev, ev= ev->next)
ev->prev= prevev;
return hme;
}
static void VColAvgT(unsigned char *t, unsigned char *a, unsigned char *b) {
t[0]= (a[0]+b[0])>>1;
t[1]= (a[1]+b[1])>>1;
t[2]= (a[2]+b[2])>>1;
t[3]= (a[3]+b[3])>>1;
}
static void hypermesh_subdivide(HyperMesh *me, HyperMesh *nme) {
HyperVert *v;
HyperEdge *e;
HyperFace *f;
LinkNode *link;
float co[3];
int j, k, count;
for (f= me->faces; f; f= f->next) {
Vec3CpyI(co, 0.0, 0.0, 0.0);
for (j=0; j<f->nverts; j++)
Vec3Add(co, f->verts[j]->co);
Vec3MulN(co, (float)(1.0/f->nverts));
f->mid= hypermesh_add_vert(nme, co);
}
for (e= me->edges; e; e= e->next) {
if (hyperedge_is_boundary(e)) {
Vec3AvgT(co, e->v[0]->co, e->v[1]->co);
} else {
Vec3AddT(co, e->v[0]->co, e->v[1]->co);
for (count=2, link= e->faces; link; count++, link= link->next) {
f= (HyperFace *) link->link;
Vec3Add(co, f->mid->co);
}
Vec3MulN(co, (float)(1.0/count));
}
e->ep= hypermesh_add_vert(nme, co);
}
for (v= me->verts; v; v= v->next) {
float q[3], r[3], s[3];
if (hypervert_is_boundary(v)) {
Vec3CpyI(r, 0.0, 0.0, 0.0);
for (count= 0, link= v->edges; link; link= link->next) {
if (hyperedge_is_boundary(link->link)) {
HyperVert *ov= hyperedge_other_vert(link->link, v);
Vec3Add(r, ov->co);
count++;
}
}
/* I believe CC give the factors as
3/2k and 1/4k, but that doesn't make
sense (to me) as they don't sum to unity...
It's rarely important.
*/
Vec3MulNT(s, v->co, 0.75f);
Vec3Add(s, Vec3MulN(r, (float)(1.0/(4.0*count))));
} else {
Vec3Cpy(q, Vec3Cpy(r, Vec3CpyI(s, 0.0f, 0.0f, 0.0f)));
for (count=0, link= v->faces; link; count++, link= link->next) {
f= (HyperFace *) link->link;
Vec3Add(q, f->mid->co);
}
Vec3MulN(q, (float)(1.0/count));
for (count=0, link= v->edges; link; count++, link= link->next) {
e= (HyperEdge *) link->link;
Vec3Add(r, hyperedge_other_vert(e, v)->co);
}
Vec3MulN(r, (float)(1.0/count));
Vec3MulNT(s, v->co, (float)(count-2));
Vec3Add(s, q);
Vec3Add(s, r);
Vec3MulN(s, (float)(1.0/count));
}
v->nmv= hypermesh_add_vert(nme, s);
}
for (e= me->edges; e; e= e->next) {
hypermesh_add_edge(nme, e->v[0]->nmv, e->ep);
hypermesh_add_edge(nme, e->v[1]->nmv, e->ep);
}
for (f= me->faces; f; f= f->next) {
int last= f->nverts-1;
unsigned char vcol_mid[4];
unsigned char vcol_edge[4][4];
float uvco_mid[2];
float uvco_edge[4][4];
if (me->hasvcol) {
int t[4]= {0, 0, 0, 0};
for (j=0; j<f->nverts; j++) {
t[0]+= f->vcol[j][0];
t[1]+= f->vcol[j][1];
t[2]+= f->vcol[j][2];
t[3]+= f->vcol[j][3];
}
vcol_mid[0]= t[0]/f->nverts;
vcol_mid[1]= t[1]/f->nverts;
vcol_mid[2]= t[2]/f->nverts;
vcol_mid[3]= t[3]/f->nverts;
for (j=0; j<f->nverts; last= j, j++)
VColAvgT(vcol_edge[j], f->vcol[last], f->vcol[j]);
last= f->nverts-1;
}
if (me->hasuvco) {
Vec2CpyI(uvco_mid, 0.0, 0.0);
for (j=0; j<f->nverts; j++)
Vec2Add(uvco_mid, f->uvco[j]);
Vec3MulN(uvco_mid, (float)(1.0/f->nverts));
for (j=0; j<f->nverts; last= j, j++)
Vec2AvgT(uvco_edge[j], f->uvco[last], f->uvco[j]);
last= f->nverts-1;
}
for (j=0; j<f->nverts; last=j, j++) {
HyperVert *nv[4];
HyperFace *nf;
nv[0]= f->verts[last]->nmv;
nv[1]= f->edges[j]->ep;
nv[2]= f->mid;
nv[3]= f->edges[last]->ep;
nf= hypermesh_add_face(nme, nv, 4);
nf->orig= f->orig;
if (me->hasvcol) {
nf->vcol= BLI_memarena_alloc(nme->arena, sizeof(*nf->vcol)*4);
for (k=0; k<4; k++) {
nf->vcol[0][k]= f->vcol[last][k];
nf->vcol[1][k]= vcol_edge[j][k];
nf->vcol[2][k]= vcol_mid[k];
nf->vcol[3][k]= vcol_edge[last][k];
}
}
if (me->hasuvco) {
nf->uvco= BLI_memarena_alloc(nme->arena, sizeof(*nf->uvco)*4);
Vec2Cpy(nf->uvco[0], f->uvco[last]);
Vec2Cpy(nf->uvco[1], uvco_edge[j]);
Vec2Cpy(nf->uvco[2], uvco_mid);
Vec2Cpy(nf->uvco[3], uvco_edge[last]);
}
}
}
}
static void hypermesh_free(HyperMesh *me) {
BLI_memarena_free(me->arena);
MEM_freeN(me);
}
/*****/
static void add_mvert_normals_from_mfaces(MVert *mverts, int nmverts, MFaceInt *mfaces, int nmfaces) {
float (*tnorms)[3]= MEM_callocN(nmverts*sizeof(*tnorms), "tnorms");
int i;
for (i=0; i<nmfaces; i++) {
MFaceInt *mf= &mfaces[i];
float f_no[3];
if (!mf->v3)
continue;
if (mf->v4)
CalcNormFloat4(mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co, f_no);
else
CalcNormFloat(mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, f_no);
Vec3Add(tnorms[mf->v1], f_no);
Vec3Add(tnorms[mf->v2], f_no);
Vec3Add(tnorms[mf->v3], f_no);
if (mf->v4)
Vec3Add(tnorms[mf->v4], f_no);
}
for (i=0; i<nmverts; i++) {
MVert *mv= &mverts[i];
float *no= tnorms[i];
Normalise(no);
mv->no[0]= (short)(no[0]*32767.0);
mv->no[1]= (short)(no[1]*32767.0);
mv->no[2]= (short)(no[2]*32767.0);
}
MEM_freeN(tnorms);
}
static int hypermesh_get_nverts(HyperMesh *hme) {
HyperVert *v;
int count= 0;
for (v= hme->verts; v; v= v->next)
count++;
return count;
}
static int hypermesh_get_nfaces(HyperMesh *hme) {
HyperFace *f;
int count= 0;
for (f= hme->faces; f; f= f->next)
count++;
return count;
}
static int hypermesh_get_nlines(HyperMesh *hme) {
HyperEdge *e;
int n= 0;
for (e= hme->edges; e; e= e->next)
if (!e->faces)
n++;
return n;
}
static int editface_is_hidden(EditVlak *ef) {
return (ef->v1->h || ef->v2->h || ef->v3->h || (ef->v4 && ef->v4->h));
}
static int hypermesh_get_nhidden(HyperMesh *hme) {
int count= 0;
/* hme->orig_me==NULL if we are working on an editmesh */
if (!hme->orig_me) {
HyperFace *f;
for (f= hme->faces; f; f= f->next)
if (editface_is_hidden(f->orig.ef))
count++;
}
return count;
}
static DispList *hypermesh_to_displist(HyperMesh *hme) {
int nverts= hypermesh_get_nverts(hme);
int nfaces= hypermesh_get_nfaces(hme) + hypermesh_get_nlines(hme) - hypermesh_get_nhidden(hme);
DispList *dl= MEM_callocN(sizeof(*dl), "dl");
DispListMesh *dlm= MEM_callocN(sizeof(*dlm), "dlmesh");
HyperFace *f;
HyperVert *v;
HyperEdge *e;
TFace *tfaces;
MFace *mfaces;
MFaceInt *mf;
int i, j;
/* hme->orig_me==NULL if we are working on an editmesh */
if (hme->orig_me) {
tfaces= hme->orig_me->tface;
mfaces= hme->orig_me->mface;
} else {
tfaces= NULL;
mfaces= NULL;
}
dl->type= DL_MESH;
dl->mesh= dlm;
dlm->totvert= nverts;
dlm->totface= nfaces;
dlm->mvert= MEM_mallocN(dlm->totvert*sizeof(*dlm->mvert), "dlm->mvert");
dlm->mface= MEM_mallocN(dlm->totface*sizeof(*dlm->mface), "dlm->mface");
if (hme->hasuvco)
dlm->tface= MEM_callocN(dlm->totface*sizeof(*dlm->tface), "dlm->tface");
else if (hme->hasvcol)
dlm->mcol= MEM_mallocN(dlm->totface*4*sizeof(*dlm->mcol), "dlm->mcol");
for (i=0, v= hme->verts; i<nverts; i++, v= v->next) {
MVert *mv= &dlm->mvert[i];
Vec3Cpy(mv->co, v->co);
v->nmv= (void*) i;
}
mf= dlm->mface;
for (i=0, f= hme->faces; f; i++, f= f->next) {
int voff= (((int) f->verts[3]->nmv)==0)?1:0;
if (!hme->orig_me && editface_is_hidden(f->orig.ef))
continue;
/* compensate for blender's [braindead] way of encoding
* nverts by face vertices, if necessary.
*/
mf->v1= (int) f->verts[(0+voff)%4]->nmv;
mf->v2= (int) f->verts[(1+voff)%4]->nmv;
mf->v3= (int) f->verts[(2+voff)%4]->nmv;
mf->v4= (int) f->verts[(3+voff)%4]->nmv;
if (hme->orig_me) {
MFace *origmf= &mfaces[f->orig.ind];
mf->mat_nr= origmf->mat_nr;
mf->flag= origmf->flag;
mf->puno= 0;
mf->edcode= ME_V1V2|ME_V2V3|ME_V3V4|ME_V4V1;
} else {
EditVlak *origef= f->orig.ef;
mf->mat_nr= origef->mat_nr;
mf->flag= origef->flag;
mf->puno= 0;
mf->edcode= ME_V1V2|ME_V2V3|ME_V3V4|ME_V4V1;
}
if (hme->hasuvco) {
TFace *origtf, *tf= &dlm->tface[i];
if (hme->orig_me)
origtf= &tfaces[f->orig.ind];
else
origtf= f->orig.ef->tface;
for (j=0; j<4; j++) {
Vec2Cpy(tf->uv[j], f->uvco[(j+voff)%4]);
tf->col[j]= *((unsigned int*) f->vcol[(j+voff)%4]);
}
tf->tpage= origtf->tpage;
tf->flag= origtf->flag;
tf->transp= origtf->transp;
tf->mode= origtf->mode;
tf->tile= origtf->tile;
} else if (hme->hasvcol) {
MCol *mcolbase= &dlm->mcol[i*4];
for (j=0; j<4; j++)
*((unsigned int*) &mcolbase[j])= *((unsigned int*) f->vcol[(j+voff)%4]);
}
mf++;
}
for (e= hme->edges; e; e= e->next) {
if (!e->faces) {
mf->v1= (int) e->v[0]->nmv;
mf->v2= (int) e->v[1]->nmv;
mf->v3= 0;
mf->v4= 0;
mf->mat_nr= 0;
mf->flag= 0;
mf->puno= 0;
mf->edcode= ME_V1V2;
mf++;
}
}
add_mvert_normals_from_mfaces(dlm->mvert, dlm->totvert, dlm->mface, dlm->totface);
return dl;
}
static DispList *subsurf_subdivide_to_displist(HyperMesh *hme, short subdiv) {
DispList *dl;
int i;
for (i= 0; i<subdiv; i++) {
HyperMesh *tmp= hypermesh_new();
tmp->hasvcol= hme->hasvcol;
tmp->hasuvco= hme->hasuvco;
tmp->orig_me= hme->orig_me;
hypermesh_subdivide(hme, tmp);
hypermesh_free(hme);
hme= tmp;
}
dl= hypermesh_to_displist(hme);
hypermesh_free(hme);
return dl;
}
void subsurf_make_editmesh(Object *ob) {
if (G.eded.first) {
Mesh *me= ob->data;
HyperMesh *hme= hypermesh_from_editmesh(G.edve.first, G.eded.first, G.edvl.first);
free_displist_by_type(&me->disp, DL_MESH);
BLI_addtail(&me->disp, subsurf_subdivide_to_displist(hme, me->subdiv));
}
}
void subsurf_make_mesh(Object *ob, short subdiv) {
Mesh *me= ob->data;
if (me->totface) {
HyperMesh *hme= hypermesh_from_mesh(me, find_displist(&ob->disp, DL_VERTS));
free_displist_by_type(&me->disp, DL_MESH);
BLI_addtail(&me->disp, subsurf_subdivide_to_displist(hme, subdiv));
}
}
void subsurf_to_mesh(Object *oldob, Mesh *me) {
Mesh *oldme= oldob->data;
if (oldme->totface) {
HyperMesh *hme= hypermesh_from_mesh(oldme, NULL);
DispList *dl= subsurf_subdivide_to_displist(hme, oldme->subdiv);
DispListMesh *dlm= dl->mesh;
MFace *mfaces;
int i;
if (dlm->totvert>65000)
error("Too many vertices");
else {
me->totface= dlm->totface;
me->totvert= dlm->totvert;
me->mvert= MEM_dupallocN(dlm->mvert);
me->mface= mfaces= MEM_mallocN(sizeof(*mfaces)*me->totface, "me->mface");
me->tface= MEM_dupallocN(dlm->tface);
me->mcol= MEM_dupallocN(dlm->mcol);
for (i=0; i<me->totface; i++) {
MFace *mf= &mfaces[i];
MFaceInt *oldmf= &dlm->mface[i];
mf->v1= oldmf->v1;
mf->v2= oldmf->v2;
mf->v3= oldmf->v3;
mf->v4= oldmf->v4;
mf->flag= oldmf->flag;
mf->mat_nr= oldmf->mat_nr;
mf->puno= 0;
mf->edcode= ME_V1V2|ME_V2V3|ME_V3V4|ME_V4V1;
}
}
free_disp_elem(dl);
}
}
DispList* subsurf_mesh_to_displist(Mesh *me, DispList *dl, short subdiv)
{
HyperMesh *hme;
hme= hypermesh_from_mesh(me, dl);
return subsurf_subdivide_to_displist(hme, subdiv);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,201 @@
/* world.c MIX MODEL
*
* april 95
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <string.h>
#include <math.h>
#include "MEM_guardedalloc.h"
#include "DNA_world_types.h"
#include "DNA_texture_types.h"
#include "DNA_scriptlink_types.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_camera_types.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "BKE_bad_level_calls.h"
#include "BKE_utildefines.h"
#include "BKE_library.h"
#include "BKE_world.h"
#include "BKE_global.h"
#include "BPY_extern.h"
#include "BKE_main.h"
void free_world(World *wrld)
{
MTex *mtex;
int a;
BPY_free_scriptlink(&wrld->scriptlink);
for(a=0; a<8; a++) {
mtex= wrld->mtex[a];
if(mtex && mtex->tex) mtex->tex->id.us--;
if(mtex) MEM_freeN(mtex);
}
wrld->ipo= 0;
}
World *add_world(char *name)
{
World *wrld;
wrld= alloc_libblock(&G.main->world, ID_WO, name);
wrld->horb= 0.6f;
wrld->skytype= WO_SKYBLEND;
wrld->exposure= 1.0f;
wrld->stardist= 15.0f;
wrld->starsize= 2.0f;
wrld->gravity= 9.8f;
return wrld;
}
World *copy_world(World *wrld)
{
World *wrldn;
int a;
wrldn= copy_libblock(wrld);
for(a=0; a<8; a++) {
if(wrld->mtex[a]) {
wrldn->mtex[a]= MEM_mallocN(sizeof(MTex), "copymaterial");
memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex));
id_us_plus((ID *)wrldn->mtex[a]->tex);
}
}
BPY_copy_scriptlink(&wrld->scriptlink);
id_us_plus((ID *)wrldn->ipo);
return wrldn;
}
void make_local_world(World *wrld)
{
Scene *sce;
World *wrldn;
int local=0, lib=0;
/* - zijn er alleen lib users: niet doen
* - zijn er alleen locale users: flag zetten
* - mixed: copy
*/
if(wrld->id.lib==0) return;
if(wrld->id.us==1) {
wrld->id.lib= 0;
wrld->id.flag= LIB_LOCAL;
new_id(0, (ID *)wrld, 0);
return;
}
sce= G.main->scene.first;
while(sce) {
if(sce->world==wrld) {
if(sce->id.lib) lib= 1;
else local= 1;
}
sce= sce->id.next;
}
if(local && lib==0) {
wrld->id.lib= 0;
wrld->id.flag= LIB_LOCAL;
new_id(0, (ID *)wrld, 0);
}
else if(local && lib) {
wrldn= copy_world(wrld);
wrldn->id.us= 0;
sce= G.main->scene.first;
while(sce) {
if(sce->world==wrld) {
if(sce->id.lib==0) {
sce->world= wrldn;
wrldn->id.us++;
wrld->id.us--;
}
}
sce= sce->id.next;
}
}
}
void init_render_world()
{
int a;
char *cp;
if(G.scene->world) {
R.wrld= *(G.scene->world);
cp= (char *)&R.wrld.fastcol;
cp[0]= 255.0*R.wrld.horr;
cp[1]= 255.0*R.wrld.horg;
cp[2]= 255.0*R.wrld.horb;
cp[3]= 1;
VECCOPY(R.grvec, R.viewmat[2]);
Normalise(R.grvec);
Mat3CpyMat4(R.imat, R.viewinv);
for(a=0; a<6; a++) if(R.wrld.mtex[a] && R.wrld.mtex[a]->tex) R.wrld.skytype |= WO_SKYTEX;
if(G.scene->camera && G.scene->camera->type==OB_CAMERA) {
Camera *cam= G.scene->camera->data;
if(cam->type==CAM_ORTHO) {
/* dit is maar ongeveer */
R.wrld.miststa+= (float)fabs(R.viewmat[3][2]);
}
}
}
else {
memset(&R.wrld, 0, sizeof(World));
R.wrld.exposure= 1.0;
}
}

View File

@@ -0,0 +1,147 @@
/**
* Functions for writing avi-format files.
*
* $Id$
*
* ***** 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.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*
*/
#include <string.h>
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "AVI_avi.h"
#include "BKE_bad_level_calls.h"
#include "BKE_global.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
static AviMovie *avi=NULL;
static int sframe;
void makeavistring (char *string)
{
char txt[64];
if (string==0) return;
strcpy(string, G.scene->r.pic);
BLI_convertstringcode(string, G.sce, G.scene->r.cfra);
RE_make_existing_file(string);
if (strcasecmp(string + strlen(string) - 4, ".avi")) {
sprintf(txt, "%04d_%04d.avi", (G.scene->r.sfra) , (G.scene->r.efra) );
strcat(string, txt);
}
}
void start_avi(void)
{
int x, y;
char name[256];
AviFormat format;
int quality, framerate;
makeavistring(name);
sframe = (G.scene->r.sfra);
x = R.rectx;
y = R.recty;
quality= R.r.quality;
framerate= R.r.frs_sec;
avi = MEM_mallocN (sizeof(AviMovie), "avimovie");
if (R.r.imtype != AVI_FORMAT_MJPEG) format = AVI_FORMAT_AVI_RGB;
else format = AVI_FORMAT_MJPEG;
if (AVI_open_compress (name, avi, 1, format) != AVI_ERROR_NONE) {
error("open movie");
MEM_freeN (avi);
avi = NULL;
return;
}
AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_WIDTH, &x);
AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_HEIGHT, &y);
AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_QUALITY, &quality);
AVI_set_compress_option (avi, AVI_OPTION_TYPE_MAIN, 0, AVI_OPTION_FRAMERATE, &framerate);
avi->interlace= 0;
avi->odd_fields= 0;
/* avi->interlace= R.r.mode & R_FIELDS; */
/* avi->odd_fields= (R.r.mode & R_ODDFIELD)?1:0; */
printf("Created avi: %s\n", name);
}
void append_avi(int frame)
{
unsigned int *rt1, *rt2, *temp;
int y;
if (avi == NULL) {
G.afbreek = 1;
return;
}
/* note that libavi free's the buffer... stupid interface - zr */
temp = MEM_mallocN(R.rectx*R.recty*4, "append_avi buf");
rt1= temp;
rt2= R.rectot + (R.recty-1)*R.rectx;
for (y=0; y < R.recty; y++, rt1+= R.rectx, rt2-= R.rectx) {
memcpy (rt1, rt2, R.rectx*4);
}
IMB_convert_rgba_to_abgr(R.rectx*R.recty, temp);
AVI_write_frame (avi, (frame-sframe), AVI_FORMAT_RGB32,
temp, R.rectx*R.recty*4);
printf ("added frame %3d (frame %3d in avi): ", frame, frame-sframe);
}
void end_avi(void)
{
if (avi == NULL) return;
AVI_close_compress (avi);
MEM_freeN (avi);
avi= NULL;
}