From cb89decfdcf5e6b2f26376d416633f4ccf0c532d Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 4 Sep 2008 20:51:28 +0000 Subject: Merge of first part of changes from the apricot branch, especially the features that are needed to run the game. Compile tested with scons, make, but not cmake, that seems to have an issue not related to these changes. The changes include: * GLSL support in the viewport and game engine, enable in the game menu in textured draw mode. * Synced and merged part of the duplicated blender and gameengine/ gameplayer drawing code. * Further refactoring of game engine drawing code, especially mesh storage changed a lot. * Optimizations in game engine armatures to avoid recomputations. * A python function to get the framerate estimate in game. * An option take object color into account in materials. * An option to restrict shadow casters to a lamp's layers. * Increase from 10 to 18 texture slots for materials, lamps, word. An extra texture slot shows up once the last slot is used. * Memory limit for undo, not enabled by default yet because it needs the .B.blend to be changed. * Multiple undo for image painting. * An offset for dupligroups, so not all objects in a group have to be at the origin. --- source/gameengine/Converter/BL_ArmatureObject.cpp | 74 ++++++----- source/gameengine/Converter/BL_ArmatureObject.h | 8 +- .../Converter/BL_BlenderDataConversion.cpp | 140 ++++++++------------- .../Converter/BL_DeformableGameObject.cpp | 8 +- source/gameengine/Converter/BL_MeshDeformer.cpp | 89 +++++++------ source/gameengine/Converter/BL_MeshDeformer.h | 3 +- .../Converter/BL_ShapeActionActuator.cpp | 1 - source/gameengine/Converter/BL_ShapeDeformer.cpp | 3 - source/gameengine/Converter/BL_ShapeDeformer.h | 11 -- source/gameengine/Converter/BL_SkinDeformer.cpp | 47 ++++--- source/gameengine/Converter/BL_SkinDeformer.h | 16 +-- source/gameengine/Converter/BL_SkinMeshObject.cpp | 74 +++++++---- source/gameengine/Converter/BL_SkinMeshObject.h | 45 +------ source/gameengine/Converter/CMakeLists.txt | 1 + .../Converter/KX_BlenderSceneConverter.cpp | 25 ++-- .../Converter/KX_BlenderSceneConverter.h | 2 + .../gameengine/Converter/KX_ConvertActuators.cpp | 2 +- source/gameengine/Converter/Makefile | 1 + source/gameengine/Converter/SConscript | 2 +- 19 files changed, 263 insertions(+), 289 deletions(-) (limited to 'source/gameengine/Converter') diff --git a/source/gameengine/Converter/BL_ArmatureObject.cpp b/source/gameengine/Converter/BL_ArmatureObject.cpp index cdfce321713..bf774bf7568 100644 --- a/source/gameengine/Converter/BL_ArmatureObject.cpp +++ b/source/gameengine/Converter/BL_ArmatureObject.cpp @@ -53,16 +53,20 @@ BL_ArmatureObject::BL_ArmatureObject( : KX_GameObject(sgReplicationInfo,callbacks), m_objArma(armature), - m_mrdPose(NULL), m_framePose(NULL), - m_lastframe(0.), + m_lastframe(0.0), m_activeAct(NULL), - m_activePriority(999) + m_activePriority(999), + m_lastapplyframe(0.0) { m_armature = get_armature(m_objArma); - m_pose = m_objArma->pose; -} + /* we make a copy of blender object's pose, and then always swap it with + * the original pose before calling into blender functions, to deal with + * replica's or other objects using the same blender object */ + m_pose = NULL; + copy_pose(&m_pose, m_objArma->pose, 1 /* copy_constraint_channels_hack */); +} CValue* BL_ArmatureObject::GetReplica() { @@ -79,34 +83,39 @@ void BL_ArmatureObject::ProcessReplica(BL_ArmatureObject *replica) { KX_GameObject::ProcessReplica(replica); + replica->m_pose = NULL; + copy_pose(&replica->m_pose, m_pose, 1 /* copy_constraint_channels_hack */); } BL_ArmatureObject::~BL_ArmatureObject() { - if (m_mrdPose) - free_pose(m_mrdPose); + if (m_pose) + free_pose(m_pose); } -/* note, you can only call this for exisiting Armature objects, and not mix it with other Armatures */ -/* there is only 1 unique Pose per Armature */ -void BL_ArmatureObject::ApplyPose() +bool BL_ArmatureObject::VerifyPose() { - if (m_pose) { - // copy to armature object - if (m_objArma->pose != m_pose)/* This should never happen but it does - Campbell */ - extract_pose_from_pose(m_objArma->pose, m_pose); - - // is this needed anymore? - //if (!m_mrdPose) - // copy_pose (&m_mrdPose, m_pose, 0); - //else - // extract_pose_from_pose(m_mrdPose, m_pose); + if(m_lastapplyframe != m_lastframe) { + extract_pose_from_pose(m_objArma->pose, m_pose); + where_is_pose(m_objArma); + m_lastapplyframe = m_lastframe; + extract_pose_from_pose(m_pose, m_objArma->pose); + return false; } + else + return true; +} + +void BL_ArmatureObject::ApplyPose() +{ + if(VerifyPose()) + extract_pose_from_pose(m_objArma->pose, m_pose); } void BL_ArmatureObject::SetPose(bPose *pose) { - m_pose = pose; + extract_pose_from_pose(m_pose, pose); + m_lastapplyframe = -1.0; } bool BL_ArmatureObject::SetActiveAction(BL_ActionActuator *act, short priority, double curtime) @@ -162,6 +171,7 @@ void BL_ArmatureObject::GetPose(bPose **pose) if (*pose == m_pose) // no need to copy if the pointers are the same return; + extract_pose_from_pose(*pose, m_pose); } } @@ -171,20 +181,16 @@ void BL_ArmatureObject::GetMRDPose(bPose **pose) /* If the caller supplies a null pose, create a new one. */ /* Otherwise, copy the armature's pose channels into the caller-supplied pose */ - // is this needed anymore? - //if (!m_mrdPose){ - // copy_pose (&m_mrdPose, m_pose, 0); - //} - if (!*pose) { // must duplicate the constraints too otherwise we have corruption in free_pose_channels() // because it will free the blender constraints. // Ideally, blender should rememeber that the constraints were not copied so that // free_pose_channels() would not free them. - copy_pose(pose, m_objArma->pose, 1); + copy_pose(pose, m_pose, 1); + } + else { + extract_pose_from_pose(*pose, m_pose); } - else - extract_pose_from_pose(*pose, m_objArma->pose); } @@ -198,16 +204,18 @@ double BL_ArmatureObject::GetLastFrame() return m_lastframe; } -bool BL_ArmatureObject::GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix) const +bool BL_ArmatureObject::GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix) { - Object* par_arma = m_objArma; - where_is_pose(par_arma); - bPoseChannel *pchan= get_pose_channel(par_arma->pose, bone->name); + bPoseChannel *pchan; + + ApplyPose(); + pchan = get_pose_channel(m_objArma->pose, bone->name); if(pchan) { matrix.setValue(&pchan->pose_mat[0][0]); return true; } + return false; } diff --git a/source/gameengine/Converter/BL_ArmatureObject.h b/source/gameengine/Converter/BL_ArmatureObject.h index a612ca77ec0..6f2c0d2f4c9 100644 --- a/source/gameengine/Converter/BL_ArmatureObject.h +++ b/source/gameengine/Converter/BL_ArmatureObject.h @@ -59,7 +59,10 @@ public: void GetMRDPose(struct bPose **pose); void GetPose(struct bPose **pose); void SetPose (struct bPose *pose); + void ApplyPose(); + bool VerifyPose(); + bool SetActiveAction(class BL_ActionActuator *act, short priority, double curtime); struct bArmature * GetArmature() { return m_armature; } @@ -69,7 +72,7 @@ public: /// Retrieve the pose matrix for the specified bone. /// Returns true on success. - bool GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix) const; + bool GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix); /// Returns the bone length. The end of the bone is in the local y direction. float GetBoneLength(Bone* bone) const; @@ -79,11 +82,12 @@ protected: Object *m_objArma; struct bArmature *m_armature; struct bPose *m_pose; - struct bPose *m_mrdPose; struct bPose *m_framePose; double m_lastframe; class BL_ActionActuator *m_activeAct; short m_activePriority; + + double m_lastapplyframe; }; #endif diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index edc14dabc70..def4938b053 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -601,7 +601,6 @@ BL_Material* ConvertMaterial( (tface->mode & TF_INVISIBLE) )?POLY_VIS:0; - material->ras_mode |= ( (tface->mode & TF_DYNAMIC)!= 0 )?COLLIDER:0; material->transp = tface->transp; material->tile = tface->tile; material->mode = tface->mode; @@ -617,7 +616,7 @@ BL_Material* ConvertMaterial( } else { // nothing at all - material->ras_mode |= (COLLIDER|POLY_VIS| (validmat?0:USE_LIGHT)); + material->ras_mode |= (POLY_VIS| (validmat?0:USE_LIGHT)); material->mode = default_face_mode; material->transp = TF_SOLID; material->tile = 0; @@ -627,13 +626,19 @@ BL_Material* ConvertMaterial( if(validmat && (mat->mode & MA_ZTRA) && (material->transp == TF_SOLID)) material->transp = TF_ALPHA; - // always zsort alpha + add - if((material->transp == TF_ALPHA || material->transp == TF_ADD || texalpha) - && (material->transp != TF_CLIP)) { + // always zsort alpha + add + if((material->transp == TF_ALPHA || texalpha) && (material->transp != TF_CLIP)) { material->ras_mode |= ALPHA; material->ras_mode |= (material->mode & TF_ALPHASORT)? ZSORT: 0; } + // collider or not? + material->ras_mode |= (material->mode & TF_DYNAMIC)? COLLIDER: 0; + + // these flags are irrelevant at this point, remove so they + // don't hurt material bucketing + material->mode &= ~(TF_DYNAMIC|TF_ALPHASORT|TF_TEX); + // get uv sets if(validmat) { @@ -644,6 +649,7 @@ BL_Material* ConvertMaterial( for (int vind = 0; vindnum_enabled; vind++) { BL_Mapping &map = material->mapping[vind]; + if (map.uvCoName.IsEmpty()) isFirstSet = false; else @@ -673,7 +679,7 @@ BL_Material* ConvertMaterial( isFirstSet = false; uvName = layer.name; } - else + else if(strcmp(layer.name, uvName) != 0) { uv2[0] = uvSet[0]; uv2[1] = uvSet[1]; uv2[2] = uvSet[2]; uv2[3] = uvSet[3]; @@ -702,7 +708,6 @@ BL_Material* ConvertMaterial( material->SetConversionUV(uvName, uv); material->SetConversionUV2(uv2Name, uv2); - material->ras_mode |= (mface->v4==0)?TRIANGLE:0; if(validmat) material->matname =(mat->id.name); @@ -767,7 +772,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* } meshobj->SetName(mesh->id.name); - meshobj->m_xyz_index_to_vertex_index_mapping.resize(totvert); + meshobj->m_sharedvertex_map.resize(totvert); for (int f=0;fmat_nr+1); { - bool polyvisible = true; + bool visible = true; RAS_IPolyMaterial* polymat = NULL; BL_Material *bl_mat = NULL; @@ -845,7 +850,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* bl_mat->material_index = (int)mface->mat_nr; - polyvisible = ((bl_mat->ras_mode & POLY_VIS)!=0); + visible = ((bl_mat->ras_mode & POLY_VIS)!=0); collider = ((bl_mat->ras_mode & COLLIDER)!=0); /* vertex colors and uv's were stored in bl_mat temporarily */ @@ -862,7 +867,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* uv22 = uv[2]; uv23 = uv[3]; /* then the KX_BlenderMaterial */ - polymat = new KX_BlenderMaterial(scene, bl_mat, skinMesh, lightlayer, blenderobj ); + polymat = new KX_BlenderMaterial(scene, bl_mat, skinMesh, lightlayer); } else { /* do Texture Face materials */ @@ -886,7 +891,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* tile = tface->tile; mode = tface->mode; - polyvisible = !((mface->flag & ME_HIDE)||(tface->mode & TF_INVISIBLE)); + visible = !((mface->flag & ME_HIDE)||(tface->mode & TF_INVISIBLE)); uv0 = MT_Point2(tface->uv[0]); uv1 = MT_Point2(tface->uv[1]); @@ -940,15 +945,13 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* rgb3 = KX_rgbaint2uint_new(color); } - bool istriangle = (mface->v4==0); - // only zsort alpha + add bool alpha = (transp == TF_ALPHA || transp == TF_ADD); bool zsort = (mode & TF_ALPHASORT)? alpha: 0; polymat = new KX_PolygonMaterial(imastr, ma, tile, tilexrep, tileyrep, - mode, transp, alpha, zsort, lightlayer, istriangle, blenderobj, tface, (unsigned int*)mcol); + mode, transp, alpha, zsort, lightlayer, tface, (unsigned int*)mcol); if (ma) { polymat->m_specular = MT_Vector3(ma->specr, ma->specg, ma->specb)*ma->spec; @@ -961,6 +964,9 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* } } + /* mark face as flat, so vertices are split */ + bool flat = (mface->flag & ME_SMOOTH) == 0; + // see if a bucket was reused or a new one was created // this way only one KX_BlenderMaterial object has to exist per bucket bool bucketCreated; @@ -981,49 +987,19 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* polymat = bucket->GetPolyMaterial(); } - int nverts = mface->v4?4:3; - int vtxarray = meshobj->FindVertexArray(nverts,polymat); - RAS_Polygon* poly = new RAS_Polygon(bucket,polyvisible,nverts,vtxarray); - - bool flat; - - if (skinMesh) { - /* If the face is set to solid, all fnors are the same */ - if (mface->flag & ME_SMOOTH) - flat = false; - else - flat = true; - } - else - flat = false; + int nverts = (mface->v4)? 4: 3; + RAS_Polygon *poly = meshobj->AddPolygon(bucket, nverts); - poly->SetVertex(0,meshobj->FindOrAddVertex(vtxarray,pt0,uv0,uv20,tan0,rgb0,no0,flat,polymat,mface->v1)); - poly->SetVertex(1,meshobj->FindOrAddVertex(vtxarray,pt1,uv1,uv21,tan1,rgb1,no1,flat,polymat,mface->v2)); - poly->SetVertex(2,meshobj->FindOrAddVertex(vtxarray,pt2,uv2,uv22,tan2,rgb2,no2,flat,polymat,mface->v3)); - if (nverts==4) - poly->SetVertex(3,meshobj->FindOrAddVertex(vtxarray,pt3,uv3,uv23,tan3,rgb3,no3,flat,polymat,mface->v4)); - - meshobj->AddPolygon(poly); - if (poly->IsCollider()) - { - RAS_TriangleIndex idx; - idx.m_index[0] = mface->v1; - idx.m_index[1] = mface->v2; - idx.m_index[2] = mface->v3; - idx.m_collider = collider; - meshobj->m_triangle_indices.push_back(idx); - if (nverts==4) - { - idx.m_index[0] = mface->v1; - idx.m_index[1] = mface->v3; - idx.m_index[2] = mface->v4; - idx.m_collider = collider; - meshobj->m_triangle_indices.push_back(idx); - } - } - -// poly->SetVisibleWireframeEdges(mface->edcode); + poly->SetVisible(visible); poly->SetCollider(collider); + //poly->SetEdgeCode(mface->edcode); + + meshobj->AddVertex(poly,0,pt0,uv0,uv20,tan0,rgb0,no0,flat,mface->v1); + meshobj->AddVertex(poly,1,pt1,uv1,uv21,tan1,rgb1,no1,flat,mface->v2); + meshobj->AddVertex(poly,2,pt2,uv2,uv22,tan2,rgb2,no2,flat,mface->v3); + + if (nverts==4) + meshobj->AddVertex(poly,3,pt3,uv3,uv23,tan3,rgb3,no3,flat,mface->v4); } if (tface) @@ -1039,13 +1015,12 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* layer.face++; } } - meshobj->m_xyz_index_to_vertex_index_mapping.clear(); - meshobj->UpdateMaterialList(); + meshobj->m_sharedvertex_map.clear(); // pre calculate texture generation - for(RAS_MaterialBucket::Set::iterator mit = meshobj->GetFirstMaterial(); + for(list::iterator mit = meshobj->GetFirstMaterial(); mit != meshobj->GetLastMaterial(); ++ mit) { - (*mit)->GetPolyMaterial()->OnConstruction(); + mit->m_bucket->GetPolyMaterial()->OnConstruction(); } if (layers) @@ -1490,14 +1465,9 @@ static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int l lightobj.m_type = RAS_LightObject::LIGHT_NORMAL; } -#ifdef BLENDER_GLSL - if(converter->GetGLSLMaterials()) - GPU_lamp_from_blender(ob, la); - - gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rendertools, lightobj, ob->gpulamp); -#else - gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rendertools, lightobj, NULL); -#endif + gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rendertools, + lightobj, converter->GetGLSLMaterials()); + BL_ConvertLampIpos(la, gamelight, converter); return gamelight; @@ -1534,7 +1504,7 @@ static KX_GameObject *gameobject_from_blenderobject( gamelight->AddRef(); kxscene->GetLightList()->Add(gamelight); - + break; } @@ -1643,20 +1613,6 @@ struct parentChildLink { SG_Node* m_gamechildnode; }; - /** - * Find the specified scene by name, or the first - * scene if nothing matches (shouldn't happen). - */ -static struct Scene *GetSceneForName(struct Main *maggie, const STR_String& scenename) { - Scene *sce; - - for (sce= (Scene*) maggie->scene.first; sce; sce= (Scene*) sce->id.next) - if (scenename == (sce->id.name+2)) - return sce; - - return (Scene*) maggie->scene.first; -} - #include "DNA_constraint_types.h" #include "BIF_editconstraint.h" @@ -1755,7 +1711,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, ) { - Scene *blenderscene = GetSceneForName(maggie, scenename); + Scene *blenderscene = converter->GetBlenderSceneForName(scenename); // for SETLOOPER Scene *sce; Base *base; @@ -1990,7 +1946,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, //tf.Add(gameobj->GetSGNode()); gameobj->NodeUpdateGS(0,true); - gameobj->Bucketize(); + gameobj->AddMeshUser(); } else @@ -2187,7 +2143,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, //tf.Add(gameobj->GetSGNode()); gameobj->NodeUpdateGS(0,true); - gameobj->Bucketize(); + gameobj->AddMeshUser(); } else @@ -2273,8 +2229,11 @@ void BL_ConvertBlenderObjects(struct Main* maggie, { // parent this to a bone Bone *parent_bone = get_named_bone(get_armature(blenderchild->parent), blenderchild->parsubstr); - KX_BoneParentRelation *bone_parent_relation = KX_BoneParentRelation::New(parent_bone); - pcit->m_gamechildnode->SetParentRelation(bone_parent_relation); + + if(parent_bone) { + KX_BoneParentRelation *bone_parent_relation = KX_BoneParentRelation::New(parent_bone); + pcit->m_gamechildnode->SetParentRelation(bone_parent_relation); + } break; } @@ -2511,5 +2470,10 @@ void BL_ConvertBlenderObjects(struct Main* maggie, kxscene->DupliGroupRecurse(gameobj, 0); } } + + KX_Camera *activecam = kxscene->GetActiveCamera(); + MT_Scalar distance = (activecam)? activecam->GetCameraFar() - activecam->GetCameraNear(): 100.0f; + RAS_BucketManager *bucketmanager = kxscene->GetBucketManager(); + bucketmanager->OptimizeBuckets(distance); } diff --git a/source/gameengine/Converter/BL_DeformableGameObject.cpp b/source/gameengine/Converter/BL_DeformableGameObject.cpp index d23274324ee..1d62a41cce9 100644 --- a/source/gameengine/Converter/BL_DeformableGameObject.cpp +++ b/source/gameengine/Converter/BL_DeformableGameObject.cpp @@ -41,12 +41,14 @@ BL_DeformableGameObject::~BL_DeformableGameObject() delete m_pDeformer; // __NLA : Temporary until we decide where to put this } -void BL_DeformableGameObject::ProcessReplica(KX_GameObject* replica) +void BL_DeformableGameObject::ProcessReplica(KX_GameObject* replica) { + BL_MeshDeformer *deformer; KX_GameObject::ProcessReplica(replica); - if (m_pDeformer){ - ((BL_DeformableGameObject*)replica)->m_pDeformer = m_pDeformer->GetReplica(); + if (m_pDeformer) { + deformer = (BL_MeshDeformer*)m_pDeformer->GetReplica(); + ((BL_DeformableGameObject*)replica)->m_pDeformer = deformer; } } diff --git a/source/gameengine/Converter/BL_MeshDeformer.cpp b/source/gameengine/Converter/BL_MeshDeformer.cpp index 39d66a90e92..fa3b8185fe2 100644 --- a/source/gameengine/Converter/BL_MeshDeformer.cpp +++ b/source/gameengine/Converter/BL_MeshDeformer.cpp @@ -50,26 +50,26 @@ bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*) { - size_t i, j; + size_t i; float *co; // only apply once per frame if the mesh is actually modified if(m_pMeshObject->MeshModified() && m_lastDeformUpdate != m_gameobj->GetLastFrame()) { // For each material - for(RAS_MaterialBucket::Set::iterator mit = m_pMeshObject->GetFirstMaterial(); + for(list::iterator mit= m_pMeshObject->GetFirstMaterial(); mit != m_pMeshObject->GetLastMaterial(); ++ mit) { - RAS_IPolyMaterial *mat = (*mit)->GetPolyMaterial(); + if(!mit->m_slots[(void*)m_gameobj]) + continue; - vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat); - - // For each array - for (i=0; im_slots[(void*)m_gameobj]; + RAS_MeshSlot::iterator it; + // for each array + for(slot->begin(it); !slot->end(it); slot->next(it)) { // For each vertex - for (j=0; jmvert[v.getOrigIndex()].co; v.SetXYZ(MT_Point3(co)); } @@ -90,7 +90,17 @@ BL_MeshDeformer::~BL_MeshDeformer() delete [] m_transverts; if (m_transnors) delete [] m_transnors; -}; +} + +void BL_MeshDeformer::Relink(GEN_Map*map) +{ + void **h_obj = (*map)[m_gameobj]; + + if (h_obj) + m_gameobj = (BL_DeformableGameObject*)(*h_obj); + else + m_gameobj = NULL; +} /** * @warning This function is expensive! @@ -101,41 +111,41 @@ void BL_MeshDeformer::RecalcNormals() * gives area-weight normals which often look better anyway, and use * GL_NORMALIZE so we don't have to do per vertex normalization either * since the GPU can do it faster */ - size_t i, j; + list::iterator mit; + RAS_MeshSlot::iterator it; + size_t i; /* set vertex normals to zero */ memset(m_transnors, 0, sizeof(float)*3*m_bmesh->totvert); /* add face normals to vertices. */ - for(RAS_MaterialBucket::Set::iterator mit = m_pMeshObject->GetFirstMaterial(); + for(mit = m_pMeshObject->GetFirstMaterial(); mit != m_pMeshObject->GetLastMaterial(); ++ mit) { - RAS_IPolyMaterial *mat = (*mit)->GetPolyMaterial(); + if(!mit->m_slots[(void*)m_gameobj]) + continue; - const vecIndexArrays& indexarrays = m_pMeshObject->GetIndexCache(mat); - vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat); + RAS_MeshSlot *slot = *mit->m_slots[(void*)m_gameobj]; - for (i=0; iUsesTriangles()? 3: 4; + for(slot->begin(it); !slot->end(it); slot->next(it)) { + int nvert = (int)it.array->m_type; - for(j=0; jgetLocalXYZ(); + v4 = &it.vertex[it.index[i+3]]; + co4 = v4->getXYZ(); n1[0]= co1[0]-co3[0]; n1[1]= co1[1]-co3[1]; @@ -174,7 +184,7 @@ void BL_MeshDeformer::RecalcNormals() } /* in case of flat - just assign, the vertices are split */ - if(v1.getFlag() & TV_CALCFACENORMAL) { + if(v1.getFlag() & RAS_TexVert::FLAT) { v1.SetNormal(fnor); v2.SetNormal(fnor); v3.SetNormal(fnor); @@ -186,19 +196,18 @@ void BL_MeshDeformer::RecalcNormals() } /* assign smooth vertex normals */ - for(RAS_MaterialBucket::Set::iterator mit = m_pMeshObject->GetFirstMaterial(); + for(mit = m_pMeshObject->GetFirstMaterial(); mit != m_pMeshObject->GetLastMaterial(); ++ mit) { - RAS_IPolyMaterial *mat = (*mit)->GetPolyMaterial(); + if(!mit->m_slots[(void*)m_gameobj]) + continue; - vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat); + RAS_MeshSlot *slot = *mit->m_slots[(void*)m_gameobj]; - for (i=0; ibegin(it); !slot->end(it); slot->next(it)) { + for(i=it.startvertex; itotvert; } } - + diff --git a/source/gameengine/Converter/BL_MeshDeformer.h b/source/gameengine/Converter/BL_MeshDeformer.h index e9f7f0b192f..9d3d2e78123 100644 --- a/source/gameengine/Converter/BL_MeshDeformer.h +++ b/source/gameengine/Converter/BL_MeshDeformer.h @@ -47,7 +47,7 @@ class BL_MeshDeformer : public RAS_Deformer public: void VerifyStorage(); void RecalcNormals(); - virtual void Relink(GEN_Map*map){}; + virtual void Relink(GEN_Map*map); BL_MeshDeformer(BL_DeformableGameObject *gameobj, struct Object* obj, class BL_SkinMeshObject *meshobj ): @@ -67,6 +67,7 @@ public: virtual RAS_Deformer* GetReplica(){return NULL;}; struct Mesh* GetMesh() { return m_bmesh; }; // virtual void InitDeform(double time){}; + protected: class BL_SkinMeshObject* m_pMeshObject; struct Mesh* m_bmesh; diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp index 942e3b502e0..799b6b74b66 100644 --- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp +++ b/source/gameengine/Converter/BL_ShapeActionActuator.cpp @@ -134,7 +134,6 @@ void BL_ShapeActionActuator::BlendShape(Key* key, float srcweight) { vector::const_iterator it; float dstweight; - int i; KeyBlock *kb; dstweight = 1.0F - srcweight; diff --git a/source/gameengine/Converter/BL_ShapeDeformer.cpp b/source/gameengine/Converter/BL_ShapeDeformer.cpp index b2e54539b19..236cd1a6667 100644 --- a/source/gameengine/Converter/BL_ShapeDeformer.cpp +++ b/source/gameengine/Converter/BL_ShapeDeformer.cpp @@ -111,10 +111,7 @@ bool BL_ShapeDeformer::ExecuteShapeDrivers(void) int type; // the shape drivers use the bone matrix as input. Must // update the matrix now - Object* par_arma = m_armobj->GetArmatureObject(); m_armobj->ApplyPose(); - where_is_pose( par_arma ); - PoseApplied(true); for (it=m_shapeDrivers.begin(); it!=m_shapeDrivers.end(); it++) { // no need to set a specific time: this curve has a driver diff --git a/source/gameengine/Converter/BL_ShapeDeformer.h b/source/gameengine/Converter/BL_ShapeDeformer.h index 5f0188e3a42..1465bb01e22 100644 --- a/source/gameengine/Converter/BL_ShapeDeformer.h +++ b/source/gameengine/Converter/BL_ShapeDeformer.h @@ -43,17 +43,6 @@ struct IpoCurve; class BL_ShapeDeformer : public BL_SkinDeformer { public: - virtual void Relink(GEN_Map*map) - { - void **h_obj = (*map)[m_gameobj]; - if (h_obj){ - m_gameobj = (BL_DeformableGameObject*)(*h_obj); - } - else - m_gameobj=NULL; - // relink the underlying skin deformer - BL_SkinDeformer::Relink(map); - }; BL_ShapeDeformer(BL_DeformableGameObject *gameobj, Object *bmeshobj, BL_SkinMeshObject *mesh) diff --git a/source/gameengine/Converter/BL_SkinDeformer.cpp b/source/gameengine/Converter/BL_SkinDeformer.cpp index f96c40c098f..d8e7a9cdadf 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.cpp +++ b/source/gameengine/Converter/BL_SkinDeformer.cpp @@ -99,9 +99,26 @@ BL_SkinDeformer::~BL_SkinDeformer() m_armobj->Release(); } +void BL_SkinDeformer::Relink(GEN_Map*map) +{ + if (m_armobj) { + void **h_obj = (*map)[m_armobj]; + + if (h_obj) + SetArmature( (BL_ArmatureObject*)(*h_obj) ); + else + m_armobj=NULL; + } + + BL_MeshDeformer::Relink(map); +} + bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *mat) { - size_t i, j; + RAS_MeshSlot::iterator it; + RAS_MeshMaterial *mmat; + RAS_MeshSlot *slot; + size_t i; // update the vertex in m_transverts Update(); @@ -110,16 +127,18 @@ bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *mat) // Duplicated objects with more than one ploymaterial (=multiple mesh slot per object) // share the same mesh (=the same cache). As the rendering is done per polymaterial // cycling through the objects, the entire mesh cache cannot be updated in one shot. - vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat); + mmat = m_pMeshObject->GetMeshMaterial(mat); + if(!mmat->m_slots[(void*)m_gameobj]) + return true; - // For each array - for (i=0; im_slots[(void*)m_gameobj]; - // For each vertex + // for each array + for(slot->begin(it); !slot->end(it); slot->next(it)) { + // for each vertex // copy the untransformed data from the original mvert - for (j=0; jGetArmatureObject(); - if (!PoseApplied()){ - m_armobj->ApplyPose(); - where_is_pose( par_arma ); - } /* store verts locally */ VerifyStorage(); @@ -163,6 +178,8 @@ bool BL_SkinDeformer::Update(void) for (int v =0; vtotvert; v++) VECCOPY(m_transverts[v], m_bmesh->mvert[v].co); + m_armobj->ApplyPose(); + // save matrix first Mat4CpyMat4(obmat, m_objMesh->obmat); // set reference matrix @@ -179,11 +196,11 @@ bool BL_SkinDeformer::Update(void) /* Update the current frame */ m_lastArmaUpdate=m_armobj->GetLastFrame(); - /* reset for next frame */ - PoseApplied(false); + /* indicate that the m_transverts and normals are up to date */ return true; } + return false; } diff --git a/source/gameengine/Converter/BL_SkinDeformer.h b/source/gameengine/Converter/BL_SkinDeformer.h index d3fc5ae2a81..e08de8c478a 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.h +++ b/source/gameengine/Converter/BL_SkinDeformer.h @@ -50,17 +50,7 @@ class BL_SkinDeformer : public BL_MeshDeformer { public: // void SetArmatureController (BL_ArmatureController *cont); - virtual void Relink(GEN_Map*map) - { - if (m_armobj){ - void **h_obj = (*map)[m_armobj]; - if (h_obj){ - SetArmature( (BL_ArmatureObject*)(*h_obj) ); - } - else - m_armobj=NULL; - } - } + virtual void Relink(GEN_Map*map); void SetArmature (class BL_ArmatureObject *armobj); BL_SkinDeformer(BL_DeformableGameObject *gameobj, @@ -81,10 +71,6 @@ public: virtual ~BL_SkinDeformer(); bool Update (void); bool Apply (class RAS_IPolyMaterial *polymat); - bool PoseApplied() - { return m_poseApplied; } - void PoseApplied(bool applied) - { m_poseApplied = applied; } bool PoseUpdated(void) { if (m_armobj && m_lastArmaUpdate!=m_armobj->GetLastFrame()) { diff --git a/source/gameengine/Converter/BL_SkinMeshObject.cpp b/source/gameengine/Converter/BL_SkinMeshObject.cpp index fa215df1e1c..4f9f1a434b5 100644 --- a/source/gameengine/Converter/BL_SkinMeshObject.cpp +++ b/source/gameengine/Converter/BL_SkinMeshObject.cpp @@ -28,42 +28,69 @@ * Deformer that supports armature skinning */ -#ifdef HAVE_CONFIG_H -#include -#endif - #ifdef WIN32 #pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning #endif //WIN32 -#include "RAS_IPolygonMaterial.h" -#include "BL_SkinMeshObject.h" -#include "BL_DeformableGameObject.h" + +#include "MEM_guardedalloc.h" + +#include "DNA_key_types.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" -#include "KX_GameObject.h" + #include "RAS_BucketManager.h" +#include "RAS_IPolygonMaterial.h" -//void BL_SkinMeshObject::Bucketize(double* oglmatrix,void* clientobj,bool useObjectColor,const MT_Vector4& rgbavec,RAS_BucketManager* bucketmgr) -void BL_SkinMeshObject::Bucketize(double* oglmatrix,void* clientobj,bool useObjectColor,const MT_Vector4& rgbavec) -{ +#include "KX_GameObject.h" + +#include "BL_SkinMeshObject.h" +#include "BL_DeformableGameObject.h" - KX_MeshSlot ms; - ms.m_clientObj = clientobj; - ms.m_mesh = this; - ms.m_OpenGLMatrix = oglmatrix; - ms.m_bObjectColor = useObjectColor; - ms.m_RGBAcolor = rgbavec; - ms.m_pDeformer = ((BL_DeformableGameObject*)clientobj)->m_pDeformer; - - for (RAS_MaterialBucket::Set::iterator it = m_materials.begin();it!=m_materials.end();it++) +BL_SkinMeshObject::BL_SkinMeshObject(Mesh* mesh, int lightlayer) + : RAS_MeshObject (mesh, lightlayer) +{ + m_bDeformed = true; + + if (m_mesh && m_mesh->key) { + KeyBlock *kb; + int count=0; + // initialize weight cache for shape objects + // count how many keys in this mesh + for(kb= (KeyBlock*)m_mesh->key->block.first; kb; kb= (KeyBlock*)kb->next) + count++; + m_cacheWeightIndex.resize(count,-1); + } +} - RAS_MaterialBucket* materialbucket = (*it); +BL_SkinMeshObject::~BL_SkinMeshObject() +{ + if (m_mesh && m_mesh->key) + { + KeyBlock *kb; + // remove the weight cache to avoid memory leak + for(kb= (KeyBlock*)m_mesh->key->block.first; kb; kb= (KeyBlock*)kb->next) { + if(kb->weights) + MEM_freeN(kb->weights); + kb->weights= NULL; + } + } +} + +void BL_SkinMeshObject::UpdateBuckets(void* clientobj,double* oglmatrix,bool useObjectColor,const MT_Vector4& rgbavec, bool visible, bool culled) +{ + list::iterator it; + list::iterator sit; + + for(it = m_materials.begin();it!=m_materials.end();++it) { + if(!it->m_slots[clientobj]) + continue; -// KX_ArrayOptimizer* oa = GetArrayOptimizer(materialbucket->GetPolyMaterial()); - materialbucket->SetMeshSlot(ms); + RAS_MeshSlot *slot = *it->m_slots[clientobj]; + slot->m_pDeformer = ((BL_DeformableGameObject*)clientobj)->m_pDeformer; } + RAS_MeshObject::UpdateBuckets(clientobj, oglmatrix, useObjectColor, rgbavec, visible, culled); } static int get_def_index(Object* ob, const char* vgroup) @@ -74,6 +101,7 @@ static int get_def_index(Object* ob, const char* vgroup) for (curdef = (bDeformGroup*)ob->defbase.first; curdef; curdef=(bDeformGroup*)curdef->next, index++) if (!strcmp(curdef->name, vgroup)) return index; + return -1; } diff --git a/source/gameengine/Converter/BL_SkinMeshObject.h b/source/gameengine/Converter/BL_SkinMeshObject.h index c21fb64204b..8544a2b958c 100644 --- a/source/gameengine/Converter/BL_SkinMeshObject.h +++ b/source/gameengine/Converter/BL_SkinMeshObject.h @@ -33,62 +33,27 @@ #ifdef WIN32 #pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning #endif //WIN32 -#include "MEM_guardedalloc.h" + #include "RAS_MeshObject.h" #include "RAS_Deformer.h" #include "RAS_IPolygonMaterial.h" #include "BL_MeshDeformer.h" -#include "DNA_mesh_types.h" -#include "DNA_key_types.h" -#include "DNA_meshdata_types.h" - class BL_SkinMeshObject : public RAS_MeshObject { - -// enum { BUCKET_MAX_INDICES = 16384};//2048};//8192}; -// enum { BUCKET_MAX_TRIANGLES = 4096}; - protected: vector m_cacheWeightIndex; public: - void Bucketize(double* oglmatrix,void* clientobj,bool useObjectColor,const MT_Vector4& rgbavec); -// void Bucketize(double* oglmatrix,void* clientobj,bool useObjectColor,const MT_Vector4& rgbavec,class RAS_BucketManager* bucketmgr); - - BL_SkinMeshObject(Mesh* mesh, int lightlayer) : RAS_MeshObject (mesh, lightlayer) - { - m_class = 1; - if (m_mesh && m_mesh->key) - { - KeyBlock *kb; - int count=0; - // initialize weight cache for shape objects - // count how many keys in this mesh - for(kb= (KeyBlock*)m_mesh->key->block.first; kb; kb= (KeyBlock*)kb->next) - count++; - m_cacheWeightIndex.resize(count,-1); - } - }; + BL_SkinMeshObject(Mesh* mesh, int lightlayer); + ~BL_SkinMeshObject(); - virtual ~BL_SkinMeshObject() - { - if (m_mesh && m_mesh->key) - { - KeyBlock *kb; - // remove the weight cache to avoid memory leak - for(kb= (KeyBlock*)m_mesh->key->block.first; kb; kb= (KeyBlock*)kb->next) { - if(kb->weights) - MEM_freeN(kb->weights); - kb->weights= NULL; - } - } - }; + void UpdateBuckets(void* clientobj, double* oglmatrix, + bool useObjectColor, const MT_Vector4& rgbavec, bool visible, bool culled); // for shape keys, void CheckWeightCache(struct Object* obj); - }; #endif diff --git a/source/gameengine/Converter/CMakeLists.txt b/source/gameengine/Converter/CMakeLists.txt index adb7304b10e..217bdb30907 100644 --- a/source/gameengine/Converter/CMakeLists.txt +++ b/source/gameengine/Converter/CMakeLists.txt @@ -64,6 +64,7 @@ SET(INC ../../../source/gameengine/Network/LoopBackNetwork ../../../source/blender/misc ../../../source/blender/blenloader + ../../../source/blender/gpu ../../../extern/bullet2/src ../../../extern/solid ${PYTHON_INC} diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index de91bce2ab1..1f5b578d441 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -184,20 +184,21 @@ bool KX_BlenderSceneConverter::TryAndLoadNewFile() return result; } - +Scene *KX_BlenderSceneConverter::GetBlenderSceneForName(const STR_String& name) +{ + Scene *sce; /** * Find the specified scene by name, or the first * scene if nothing matches (shouldn't happen). */ -static struct Scene *GetSceneForName2(struct Main *maggie, const STR_String& scenename) { - Scene *sce; - for (sce= (Scene*) maggie->scene.first; sce; sce= (Scene*) sce->id.next) - if (scenename == (sce->id.name+2)) + for (sce= (Scene*) m_maggie->scene.first; sce; sce= (Scene*) sce->id.next) + if (name == (sce->id.name+2)) return sce; - return (Scene*) maggie->scene.first; + return (Scene*)m_maggie->scene.first; + } #include "KX_PythonInit.h" @@ -258,7 +259,7 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename, class RAS_ICanvas* canvas) { //find out which physics engine - Scene *blenderscene = GetSceneForName2(m_maggie, scenename); + Scene *blenderscene = GetBlenderSceneForName(scenename); e_PhysicsEngine physics_engine = UseBullet; // hook for registration function during conversion. @@ -818,7 +819,7 @@ void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g); if (gameObj->IsDynamic()) { - KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController(); + //KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController(); Object* blenderObject = FindBlenderObject(gameObj); if (blenderObject) @@ -846,7 +847,7 @@ void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) - const MT_Vector3& scale = gameObj->NodeGetWorldScaling(); + //const MT_Vector3& scale = gameObj->NodeGetWorldScaling(); const MT_Point3& position = gameObj->NodeGetWorldPosition(); Ipo* ipo = blenderObject->ipo; @@ -974,7 +975,7 @@ void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo() KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g); if (gameObj->IsDynamic()) { - KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController(); + //KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController(); Object* blenderObject = FindBlenderObject(gameObj); if (blenderObject) @@ -1002,8 +1003,8 @@ void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo() - const MT_Vector3& scale = gameObj->NodeGetWorldScaling(); - const MT_Point3& position = gameObj->NodeGetWorldPosition(); + //const MT_Vector3& scale = gameObj->NodeGetWorldScaling(); + //const MT_Point3& position = gameObj->NodeGetWorldPosition(); Ipo* ipo = blenderObject->ipo; if (ipo) diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h index e5d6ccc5caf..2317e952a0a 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.h +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.h @@ -45,6 +45,7 @@ class BL_Material; struct IpoCurve; struct Main; struct SpaceIpo; +struct Scene; class KX_BlenderSceneConverter : public KX_ISceneConverter { @@ -151,6 +152,7 @@ public: virtual void SetGLSLMaterials(bool val); virtual bool GetGLSLMaterials(); + struct Scene* GetBlenderSceneForName(const STR_String& name); }; #endif //__KX_BLENDERSCENECONVERTER_H diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index 7e976beaf44..321fc325bb8 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -1064,7 +1064,7 @@ void BL_ConvertActuators(char* maggiename, { bParentActuator *parAct = (bParentActuator *) bact->data; int mode = KX_ParentActuator::KX_PARENT_NODEF; - KX_GameObject *tmpgob; + KX_GameObject *tmpgob = NULL; switch(parAct->type) { diff --git a/source/gameengine/Converter/Makefile b/source/gameengine/Converter/Makefile index f312fc13221..4dd63e428bd 100644 --- a/source/gameengine/Converter/Makefile +++ b/source/gameengine/Converter/Makefile @@ -51,6 +51,7 @@ CPPFLAGS += -I../../blender/include CPPFLAGS += -I../../blender/blenlib CPPFLAGS += -I../../blender/blenkernel CPPFLAGS += -I../../blender/render/extern/include +CPPFLAGS += -I../../blender/gpu CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include CPPFLAGS += -I../Expressions -I../Rasterizer -I../GameLogic CPPFLAGS += -I../Ketsji -I../BlenderRoutines -I../SceneGraph diff --git a/source/gameengine/Converter/SConscript b/source/gameengine/Converter/SConscript index f5e382b471e..3be352c568b 100644 --- a/source/gameengine/Converter/SConscript +++ b/source/gameengine/Converter/SConscript @@ -16,7 +16,7 @@ incs += ' #source/gameengine/Expressions #source/gameengine/Network #source/game incs += ' #source/gameengine/Physics/common #source/gameengine/Physics/Bullet #source/gameengine/Physics/BlOde' incs += ' #source/gameengine/Physics/Dummy #source/gameengine/Physics/Sumo' incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork' -incs += ' #source/blender/misc #source/blender/blenloader' +incs += ' #source/blender/misc #source/blender/blenloader #source/blender/gpu' incs += ' ' + env['BF_PYTHON_INC'] incs += ' ' + env['BF_SOLID_INC'] -- cgit v1.2.3