BGE: Finally moving material IPOs to the 2.60 BGE animation system (BL_Action). It...
authorMitchell Stokes <mogurijin@gmail.com>
Sat, 23 Feb 2013 02:47:22 +0000 (02:47 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Sat, 23 Feb 2013 02:47:22 +0000 (02:47 +0000)
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/CMakeLists.txt
source/gameengine/Ketsji/BL_Action.cpp
source/gameengine/Ketsji/CMakeLists.txt
source/gameengine/Ketsji/KX_IpoConvert.cpp [moved from source/gameengine/Converter/KX_IpoConvert.cpp with 69% similarity]
source/gameengine/Ketsji/KX_IpoConvert.h [moved from source/gameengine/Converter/KX_IpoConvert.h with 51% similarity]

index f7726ebaf78e248ca0472cdd1e7d5fb69cca2b66..1c160097e2c3728f97aaf6ee5a39552a8a6e1a00 100644 (file)
@@ -2233,8 +2233,6 @@ static void bl_ConvertBlenderObject_Single(
        gameobj->NodeSetLocalScale(scale);
        gameobj->NodeUpdateGS(0);
 
-       BL_ConvertMaterialIpos(blenderobject, gameobj, converter);
-
        sumolist->Add(gameobj->AddRef());
 
        BL_ConvertProperties(blenderobject,gameobj,timemgr,kxscene,isInActiveLayer);
index 38c0d71d24d736120cf8ebb469e065c77a64a8f8..f18646c1de03dcbc9913139ae28d8f6f5cc0a2a9 100644 (file)
@@ -82,7 +82,6 @@ set(SRC
        KX_ConvertControllers.cpp
        KX_ConvertProperties.cpp
        KX_ConvertSensors.cpp
-       KX_IpoConvert.cpp
        KX_LibLoadStatus.cpp
        KX_SoftBodyDeformer.cpp
 
@@ -105,7 +104,6 @@ set(SRC
        KX_ConvertControllers.h
        KX_ConvertProperties.h
        KX_ConvertSensors.h
-       KX_IpoConvert.h
        KX_LibLoadStatus.h
        KX_SoftBodyDeformer.h
 )
index f55d1120a50b2eab21618cd1b7cb63af3a42ca50..ff1f800a6269301f475a7cb527ae95079af43459 100644 (file)
@@ -43,6 +43,10 @@ extern "C" {
 #include "BKE_action.h"
 #include "RNA_access.h"
 #include "RNA_define.h"
+
+// Needed for material IPOs
+#include "BKE_material.h"
+#include "DNA_material_types.h"
 }
 
 BL_Action::BL_Action(class KX_GameObject* gameobj)
@@ -169,6 +173,31 @@ bool BL_Action::Play(const char* name,
                sg_contr->SetObject(m_obj->GetSGNode());
        }
 
+       // Now try materials
+       if (m_obj->GetBlenderObject()->totcol==1) {
+               Material *mat = give_current_material(m_obj->GetBlenderObject(), 1);
+               sg_contr = BL_CreateMaterialIpo(m_action, mat, 0, m_obj, kxscene->GetSceneConverter());
+               if (sg_contr) {
+                       m_sg_contr_list.push_back(sg_contr);
+                       m_obj->GetSGNode()->AddSGController(sg_contr);
+                       sg_contr->SetObject(m_obj->GetSGNode());
+               }
+       } else {
+               Material *mat;
+               STR_HashedString matname;
+
+               for (int matidx = 1; matidx <= m_obj->GetBlenderObject()->totcol; ++matidx) {
+                       mat = give_current_material(m_obj->GetBlenderObject(), matidx);
+                       matname = mat->id.name;
+                       sg_contr = BL_CreateMaterialIpo(m_action, mat, matname.hash(), m_obj, kxscene->GetSceneConverter());
+                       if (sg_contr) {
+                               m_sg_contr_list.push_back(sg_contr);
+                               m_obj->GetSGNode()->AddSGController(sg_contr);
+                               sg_contr->SetObject(m_obj->GetSGNode());
+                       }
+               }
+       }
+
        // Extra controllers
        if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_LIGHT)
        {
index fc322d80cd0e397ce171de8cb0c64c6b54cef742..7f748013648335f39614a78d78858f3532be3f83 100644 (file)
@@ -84,6 +84,7 @@ set(SRC
        KX_FontObject.cpp
        KX_GameActuator.cpp
        KX_GameObject.cpp
+       KX_IpoConvert.cpp
        KX_IPO_SGController.cpp
        KX_IPhysicsController.cpp
        KX_IpoActuator.cpp
@@ -161,6 +162,7 @@ set(SRC
        KX_GameActuator.h
        KX_GameObject.h
        KX_IInterpolator.h
+       KX_IpoConvert.h
        KX_IPOTransform.h
        KX_IPO_SGController.h
        KX_IPhysicsController.h
similarity index 69%
rename from source/gameengine/Converter/KX_IpoConvert.cpp
rename to source/gameengine/Ketsji/KX_IpoConvert.cpp
index 0b0ee132a42354c643b229cdfb9e944f5fe2ce87..9ec354ec84076bc4ebc6e31513b4d847dfaeeb55 100644 (file)
@@ -187,21 +187,6 @@ SG_Controller *BL_CreateObColorIPO(struct bAction *action, KX_GameObject* gameob
        return ipocontr_obcol;
 }
 
-void BL_ConvertIpos(struct Object* blenderobject,KX_GameObject* gameobj,KX_BlenderSceneConverter *converter)
-{
-       if (blenderobject->adt) {
-               SG_Controller *ipocontr = BL_CreateIPO(blenderobject->adt->action, gameobj, converter);
-               gameobj->GetSGNode()->AddSGController(ipocontr);
-               ipocontr->SetObject(gameobj->GetSGNode());
-
-               SG_Controller *ipocontr_obcol = BL_CreateObColorIPO(blenderobject->adt->action, gameobj, converter);
-               if (ipocontr_obcol) {
-                       gameobj->GetSGNode()->AddSGController(ipocontr_obcol);
-                       ipocontr_obcol->SetObject(gameobj->GetSGNode());
-               }
-       }
-}
-
 SG_Controller *BL_CreateLampIPO(struct bAction *action, KX_GameObject*  lightobj, KX_BlenderSceneConverter *converter)
 {
        KX_LightIpoSGController* ipocontr = new KX_LightIpoSGController();
@@ -245,19 +230,6 @@ SG_Controller *BL_CreateLampIPO(struct bAction *action, KX_GameObject*  lightobj
        return ipocontr;
 }
 
-void BL_ConvertLampIpos(struct Lamp* blenderlamp, KX_GameObject *lightobj,KX_BlenderSceneConverter *converter)
-{
-
-       if (blenderlamp->adt) {
-
-               SG_Controller* ipocontr = BL_CreateLampIPO(blenderlamp->adt->action, lightobj, converter);
-               lightobj->GetSGNode()->AddSGController(ipocontr);
-               ipocontr->SetObject(lightobj->GetSGNode());
-               
-               
-       }
-}
-
 SG_Controller *BL_CreateCameraIPO(struct bAction *action, KX_GameObject*  cameraobj, KX_BlenderSceneConverter *converter)
 {
        KX_CameraIpoSGController* ipocontr = new KX_CameraIpoSGController();
@@ -297,17 +269,6 @@ SG_Controller *BL_CreateCameraIPO(struct bAction *action, KX_GameObject*  camera
        return ipocontr;
 }
 
-void BL_ConvertCameraIpos(struct Camera* blendercamera, KX_GameObject *cameraobj,KX_BlenderSceneConverter *converter)
-{
-
-       if (blendercamera->adt) {
-               SG_Controller* ipocontr = BL_CreateCameraIPO(blendercamera->adt->action, cameraobj, converter);
-               cameraobj->GetSGNode()->AddSGController(ipocontr);
-               ipocontr->SetObject(cameraobj->GetSGNode());
-       }
-}
-
-
 void BL_ConvertWorldIpos(struct World* blenderworld,KX_BlenderSceneConverter *converter)
 {
 
@@ -356,141 +317,97 @@ void BL_ConvertWorldIpos(struct World* blenderworld,KX_BlenderSceneConverter *co
        }
 }
 
-static void ConvertMaterialIpos(
+SG_Controller *BL_CreateMaterialIpo(
+       struct bAction *action,
        Material* blendermaterial,
        dword matname_hash,
        KX_GameObject* gameobj,  
        KX_BlenderSceneConverter *converter
        )
 {
-       if (blendermaterial->adt) {
-               KX_MaterialIpoController* ipocontr = new KX_MaterialIpoController(matname_hash);
-               gameobj->GetSGNode()->AddSGController(ipocontr);
-               ipocontr->SetObject(gameobj->GetSGNode());
-               
-               BL_InterpolatorList *adtList= GetAdtList(blendermaterial->adt->action, converter);
+       KX_MaterialIpoController* ipocontr = NULL;
 
+       BL_InterpolatorList *adtList= GetAdtList(action, converter);
+       KX_IInterpolator *interpolator;
+       KX_IScalarInterpolator *sinterp;
 
-               ipocontr->m_rgba[0]     = blendermaterial->r;
-               ipocontr->m_rgba[1]     = blendermaterial->g;
-               ipocontr->m_rgba[2]     = blendermaterial->b;
-               ipocontr->m_rgba[3]     = blendermaterial->alpha;
-
-               ipocontr->m_specrgb[0]  = blendermaterial->specr;
-               ipocontr->m_specrgb[1]  = blendermaterial->specg;
-               ipocontr->m_specrgb[2]  = blendermaterial->specb;
-               
-               ipocontr->m_hard                = blendermaterial->har;
-               ipocontr->m_spec                = blendermaterial->spec;
-               ipocontr->m_ref                 = blendermaterial->ref;
-               ipocontr->m_emit                = blendermaterial->emit;
-               ipocontr->m_alpha               = blendermaterial->alpha;
-               
-               KX_IInterpolator *interpolator;
-               KX_IScalarInterpolator *sinterp;
-               
-               // --
-               for (int i=0; i<3; i++) {
-                       if ((sinterp = adtList->GetScalarInterpolator("diffuse_color", i))) {
-                               if (!ipocontr) {
-                                       ipocontr = new KX_MaterialIpoController(matname_hash);
-                                       gameobj->GetSGNode()->AddSGController(ipocontr);
-                                       ipocontr->SetObject(gameobj->GetSGNode());
-                               }
-                               interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[i], sinterp);
-                               ipocontr->AddInterpolator(interpolator);
-                       }
-               }
-               
-               if ((sinterp = adtList->GetScalarInterpolator("alpha", 0))) {
+       // --
+       for (int i=0; i<3; i++) {
+               if ((sinterp = adtList->GetScalarInterpolator("diffuse_color", i))) {
                        if (!ipocontr) {
                                ipocontr = new KX_MaterialIpoController(matname_hash);
-                               gameobj->GetSGNode()->AddSGController(ipocontr);
-                               ipocontr->SetObject(gameobj->GetSGNode());
                        }
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[3], sinterp);
+                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[i], sinterp);
                        ipocontr->AddInterpolator(interpolator);
                }
+       }
 
-               for (int i=0; i<3; i++) {
-                       if ((sinterp = adtList->GetScalarInterpolator("specular_color", i))) {
-                               if (!ipocontr) {
-                                       ipocontr = new KX_MaterialIpoController(matname_hash);
-                                       gameobj->GetSGNode()->AddSGController(ipocontr);
-                                       ipocontr->SetObject(gameobj->GetSGNode());
-                               }
-                               interpolator= new KX_ScalarInterpolator(&ipocontr->m_specrgb[i], sinterp);
-                               ipocontr->AddInterpolator(interpolator);
-                       }
-               }
-               
-               if ((sinterp = adtList->GetScalarInterpolator("specular_hardness", 0))) {
-                       if (!ipocontr) {
-                               ipocontr = new KX_MaterialIpoController(matname_hash);
-                               gameobj->GetSGNode()->AddSGController(ipocontr);
-                               ipocontr->SetObject(gameobj->GetSGNode());
-                       }
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_hard, sinterp);
-                       ipocontr->AddInterpolator(interpolator);
+       if ((sinterp = adtList->GetScalarInterpolator("alpha", 0))) {
+               if (!ipocontr) {
+                       ipocontr = new KX_MaterialIpoController(matname_hash);
                }
+               interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[3], sinterp);
+               ipocontr->AddInterpolator(interpolator);
+       }
 
-               if ((sinterp = adtList->GetScalarInterpolator("specularity", 0))) {
+       for (int i=0; i<3; i++) {
+               if ((sinterp = adtList->GetScalarInterpolator("specular_color", i))) {
                        if (!ipocontr) {
                                ipocontr = new KX_MaterialIpoController(matname_hash);
-                               gameobj->GetSGNode()->AddSGController(ipocontr);
-                               ipocontr->SetObject(gameobj->GetSGNode());
                        }
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_spec, sinterp);
+                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_specrgb[i], sinterp);
                        ipocontr->AddInterpolator(interpolator);
                }
-               
-               if ((sinterp = adtList->GetScalarInterpolator("diffuse_reflection", 0))) {
-                       if (!ipocontr) {
-                               ipocontr = new KX_MaterialIpoController(matname_hash);
-                               gameobj->GetSGNode()->AddSGController(ipocontr);
-                               ipocontr->SetObject(gameobj->GetSGNode());
-                       }
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_ref, sinterp);
-                       ipocontr->AddInterpolator(interpolator);
+       }
+
+       if ((sinterp = adtList->GetScalarInterpolator("specular_hardness", 0))) {
+               if (!ipocontr) {
+                       ipocontr = new KX_MaterialIpoController(matname_hash);
                }
-               
-               if ((sinterp = adtList->GetScalarInterpolator("emit", 0))) {
-                       if (!ipocontr) {
-                               ipocontr = new KX_MaterialIpoController(matname_hash);
-                               gameobj->GetSGNode()->AddSGController(ipocontr);
-                               ipocontr->SetObject(gameobj->GetSGNode());
-                       }
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_emit, sinterp);
-                       ipocontr->AddInterpolator(interpolator);
+               interpolator= new KX_ScalarInterpolator(&ipocontr->m_hard, sinterp);
+               ipocontr->AddInterpolator(interpolator);
+       }
+
+       if ((sinterp = adtList->GetScalarInterpolator("specularity", 0))) {
+               if (!ipocontr) {
+                       ipocontr = new KX_MaterialIpoController(matname_hash);
                }
+               interpolator= new KX_ScalarInterpolator(&ipocontr->m_spec, sinterp);
+               ipocontr->AddInterpolator(interpolator);
        }
-}
 
-void BL_ConvertMaterialIpos(
-       struct Object* blenderobject,
-       KX_GameObject* gameobj,  
-       KX_BlenderSceneConverter *converter
-       )
-{
-       if (blenderobject->totcol==1)
-       {
-               Material *mat = give_current_material(blenderobject, 1);
-               // if there is only one material attached to the mesh then set material_index in BL_ConvertMaterialIpos to NULL
-               // --> this makes the UpdateMaterialData function in KX_GameObject.cpp use the old hack of using SetObjectColor
-               // because this yields a better performance as not all the vertex colors need to be edited
-               if (mat) ConvertMaterialIpos(mat, 0, gameobj, converter);
+       if ((sinterp = adtList->GetScalarInterpolator("diffuse_reflection", 0))) {
+               if (!ipocontr) {
+                       ipocontr = new KX_MaterialIpoController(matname_hash);
+               }
+               interpolator= new KX_ScalarInterpolator(&ipocontr->m_ref, sinterp);
+               ipocontr->AddInterpolator(interpolator);
        }
-       else
-       {
-               for (int material_index=1; material_index <= blenderobject->totcol; material_index++)
-               {
-                       Material *mat = give_current_material(blenderobject, material_index);
-                       STR_HashedString matname;
-                       if (mat) {
-                               matname= mat->id.name; // who is using this name? can we remove the MA here?
-                               ConvertMaterialIpos(mat, matname.hash(), gameobj, converter);
-                       }
+
+       if ((sinterp = adtList->GetScalarInterpolator("emit", 0))) {
+               if (!ipocontr) {
+                       ipocontr = new KX_MaterialIpoController(matname_hash);
                }
+               interpolator= new KX_ScalarInterpolator(&ipocontr->m_emit, sinterp);
+               ipocontr->AddInterpolator(interpolator);
        }
-}
 
+       if (ipocontr) {
+               ipocontr->m_rgba[0]     = blendermaterial->r;
+               ipocontr->m_rgba[1]     = blendermaterial->g;
+               ipocontr->m_rgba[2]     = blendermaterial->b;
+               ipocontr->m_rgba[3]     = blendermaterial->alpha;
+
+               ipocontr->m_specrgb[0]  = blendermaterial->specr;
+               ipocontr->m_specrgb[1]  = blendermaterial->specg;
+               ipocontr->m_specrgb[2]  = blendermaterial->specb;
+
+               ipocontr->m_hard                = blendermaterial->har;
+               ipocontr->m_spec                = blendermaterial->spec;
+               ipocontr->m_ref                 = blendermaterial->ref;
+               ipocontr->m_emit                = blendermaterial->emit;
+               ipocontr->m_alpha               = blendermaterial->alpha;
+       }
+
+       return ipocontr;
+}
similarity index 51%
rename from source/gameengine/Converter/KX_IpoConvert.h
rename to source/gameengine/Ketsji/KX_IpoConvert.h
index 044993a31e6c079bd6f98f8f789583cd2db7352d..1f4e1bea96d901d5f668b4149f8a258339372c68 100644 (file)
 #define __KX_IPOCONVERT_H__
 
 struct Object;
+struct bAction;
+class SG_Controller;
+class KX_GameObject;
+class KX_BlenderSceneConverter;
 
-class SG_Controller *BL_CreateIPO(struct bAction *action,
-       class KX_GameObject* gameobj,
-       class KX_BlenderSceneConverter *converter);
-class SG_Controller *BL_CreateObColorIPO(struct bAction *action,
-               class KX_GameObject* gameobj,
-               class KX_BlenderSceneConverter *converter);
-void BL_ConvertIpos(struct Object* blenderobject,
-       class KX_GameObject* gameobj, 
-       class KX_BlenderSceneConverter *converter);
+SG_Controller *BL_CreateIPO(bAction *action,
+       KX_GameObject* gameobj,
+       KX_BlenderSceneConverter *converter);
 
-class SG_Controller *BL_CreateLampIPO(struct bAction *action,
-       class KX_GameObject* lightobj,
-       class KX_BlenderSceneConverter *converter);
+SG_Controller *BL_CreateObColorIPO(bAction *action,
+       KX_GameObject* gameobj,
+       KX_BlenderSceneConverter *converter);
 
-void BL_ConvertLampIpos(struct Lamp* blenderlight,
-       class KX_GameObject* lightobj, 
-       class KX_BlenderSceneConverter *converter);
+SG_Controller *BL_CreateLampIPO(bAction *action,
+       KX_GameObject* lightobj,
+       KX_BlenderSceneConverter *converter);
 
 void BL_ConvertWorldIpos(struct World* blenderworld, 
-       class KX_BlenderSceneConverter *converter);
+       KX_BlenderSceneConverter *converter);
 
-class SG_Controller *BL_CreateCameraIPO(struct bAction *action,
-       class KX_GameObject* cameraobj,
-       class KX_BlenderSceneConverter *converter);
+SG_Controller *BL_CreateCameraIPO(bAction *action,
+       KX_GameObject* cameraobj,
+       KX_BlenderSceneConverter *converter);
 
-void BL_ConvertCameraIpos(struct Camera* blendercamera,
-       class KX_GameObject* cameraobj, 
-       class KX_BlenderSceneConverter *converter);
-
-void BL_ConvertMaterialIpos(struct Object* blenderobject,
-       class KX_GameObject* materialobj, 
-       class KX_BlenderSceneConverter *converter);
+SG_Controller *BL_CreateMaterialIpo(
+       bAction *action,
+       class Material* blendermaterial,
+       dword matname_hash,
+       KX_GameObject* gameobj,
+       KX_BlenderSceneConverter *converter);
 
 
 #endif  /* __KX_IPOCONVERT_H__ */