Don't increment tface if tface == NULL

Generate bounding boxes for frustum culling
This commit is contained in:
Kester Maddock 2004-05-16 12:52:08 +00:00
parent cfffc96ad8
commit 5659bedf34

@ -143,6 +143,8 @@
#include "SYS_System.h" #include "SYS_System.h"
#include "SG_Node.h" #include "SG_Node.h"
#include "SG_BBox.h"
#include "SG_Tree.h"
// defines USE_ODE to choose physics engine // defines USE_ODE to choose physics engine
#include "KX_ConvertPhysicsObject.h" #include "KX_ConvertPhysicsObject.h"
@ -174,10 +176,10 @@ static unsigned int KX_Mcol2uint_new(MCol col)
/* color has to be converted without endian sensitivity. So no shifting! */ /* color has to be converted without endian sensitivity. So no shifting! */
unsigned int temp=0; unsigned int temp=0;
unsigned char *cp= (unsigned char *)&temp; unsigned char *cp= (unsigned char *)&temp;
cp[3]=255;
cp[0]= col.r; cp[0]= col.r;
cp[1]= col.g; cp[1]= col.g;
cp[2]= col.b; cp[2]= col.b;
cp[3]= col.a;
return temp; return temp;
} }
@ -199,17 +201,14 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
meshobj->SetName(mesh->id.name); meshobj->SetName(mesh->id.name);
MFace* mface = static_cast<MFace*>(mesh->mface); MFace* mface = static_cast<MFace*>(mesh->mface);
TFace* tface = static_cast<TFace*>(mesh->tface); TFace* tface = static_cast<TFace*>(mesh->tface);
assert(mface);
MCol* mmcol = mesh->mcol; MCol* mmcol = mesh->mcol;
meshobj->m_xyz_index_to_vertex_index_mapping.resize(mesh->totvert); meshobj->m_xyz_index_to_vertex_index_mapping.resize(mesh->totvert);
for (int f=0;f<mesh->totface;f++,mface++,tface++) for (int f=0;f<mesh->totface;f++,mface++)
{ {
bool collider = true; bool collider = true;
@ -265,8 +264,6 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
); );
} }
if((!mface->flag & ME_SMOOTH)) if((!mface->flag & ME_SMOOTH))
{ {
MT_Vector3 norm = ((pt1-pt0).cross(pt2-pt0)).safe_normalized(); MT_Vector3 norm = ((pt1-pt0).cross(pt2-pt0)).safe_normalized();
@ -439,6 +436,8 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
poly->SetCollider(collider); poly->SetCollider(collider);
} }
} }
if (tface)
tface++;
} }
meshobj->UpdateMaterialList(); meshobj->UpdateMaterialList();
@ -623,7 +622,7 @@ void my_tex_space_mesh(Mesh *me)
} }
void my_get_local_bounds(Object *ob, float *centre, float *size) void my_get_local_bounds(Object *ob, float *centre, float *size)
{ {
BoundBox *bb= NULL; BoundBox *bb= NULL;
/* uses boundbox, function used by Ketsji */ /* uses boundbox, function used by Ketsji */
@ -862,6 +861,8 @@ static KX_GameObject *gameobject_from_blenderobject(
{ {
Mesh* mesh = static_cast<Mesh*>(ob->data); Mesh* mesh = static_cast<Mesh*>(ob->data);
RAS_MeshObject* meshobj = converter->FindGameMesh(mesh, ob->lay); RAS_MeshObject* meshobj = converter->FindGameMesh(mesh, ob->lay);
float centre[3], extents[3];
my_boundbox_mesh((Mesh*) ob->data, centre, extents);
if (!meshobj) { if (!meshobj) {
meshobj = BL_ConvertMesh(mesh,ob,rendertools,kxscene,converter); meshobj = BL_ConvertMesh(mesh,ob,rendertools,kxscene,converter);
@ -892,6 +893,11 @@ static KX_GameObject *gameobject_from_blenderobject(
((BL_DeformableGameObject*)gameobj)->m_pDeformer = dcont; ((BL_DeformableGameObject*)gameobj)->m_pDeformer = dcont;
} }
MT_Point3 min = MT_Point3(centre) - MT_Vector3(extents);
MT_Point3 max = MT_Point3(centre) + MT_Vector3(extents);
SG_BBox bbox = SG_BBox(min, max);
gameobj->GetSGNode()->SetBBox(bbox);
break; break;
} }
@ -1011,6 +1017,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
CListValue* logicbrick_conversionlist = new CListValue(); CListValue* logicbrick_conversionlist = new CListValue();
SG_TreeFactory tf;
// Convert actions to actionmap // Convert actions to actionmap
bAction *curAct; bAction *curAct;
for (curAct = (bAction*)maggie->action.first; curAct; curAct=(bAction*)curAct->id.next) for (curAct = (bAction*)maggie->action.first; curAct; curAct=(bAction*)curAct->id.next)
@ -1101,11 +1109,13 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
if (isInActiveLayer) if (isInActiveLayer)
{ {
objectlist->Add(gameobj->AddRef()); objectlist->Add(gameobj->AddRef());
tf.Add(gameobj->GetSGNode());
gameobj->NodeUpdateGS(0,true); gameobj->NodeUpdateGS(0,true);
gameobj->Bucketize(); gameobj->Bucketize();
} }
} }
base = base->next; base = base->next;
@ -1242,4 +1252,9 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
BL_ConvertSensors(blenderobj,gameobj,logicmgr,kxscene,keydev,executePriority,activeLayerBitInfo,isInActiveLayer,canvas,converter); BL_ConvertSensors(blenderobj,gameobj,logicmgr,kxscene,keydev,executePriority,activeLayerBitInfo,isInActiveLayer,canvas,converter);
} }
logicbrick_conversionlist->Release(); logicbrick_conversionlist->Release();
// Calculate the scene btree -
// too slow - commented out.
//kxscene->SetNodeTree(tf.MakeTree());
} }