BGE: Finally moving material IPOs to the 2.60 BGE animation system (BL_Action). It was kind of a fluke that they worked before.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,21 +317,82 @@ 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;
|
||||
|
||||
// --
|
||||
for (int i=0; i<3; i++) {
|
||||
if ((sinterp = adtList->GetScalarInterpolator("diffuse_color", i))) {
|
||||
if (!ipocontr) {
|
||||
ipocontr = new KX_MaterialIpoController(matname_hash);
|
||||
}
|
||||
interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[i], 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);
|
||||
}
|
||||
|
||||
for (int i=0; i<3; i++) {
|
||||
if ((sinterp = adtList->GetScalarInterpolator("specular_color", i))) {
|
||||
if (!ipocontr) {
|
||||
ipocontr = new KX_MaterialIpoController(matname_hash);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -379,118 +401,13 @@ static void ConvertMaterialIpos(
|
||||
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))) {
|
||||
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);
|
||||
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("specularity", 0))) {
|
||||
if (!ipocontr) {
|
||||
ipocontr = new KX_MaterialIpoController(matname_hash);
|
||||
gameobj->GetSGNode()->AddSGController(ipocontr);
|
||||
ipocontr->SetObject(gameobj->GetSGNode());
|
||||
}
|
||||
interpolator= new KX_ScalarInterpolator(&ipocontr->m_spec, 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("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);
|
||||
}
|
||||
}
|
||||
|
||||
return ipocontr;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,39 +33,36 @@
|
||||
#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__ */
|
||||
Reference in New Issue
Block a user