2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-25 13:30:41 +00:00
|
|
|
/** \file gameengine/Converter/KX_IpoConvert.cpp
|
|
|
|
* \ingroup bgeconv
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-09-15 16:13:32 +00:00
|
|
|
#if defined(WIN32) && !defined(FREE_WINDOWS)
|
2002-10-12 11:37:38 +00:00
|
|
|
// don't show stl-warnings
|
|
|
|
#pragma warning (disable:4786)
|
|
|
|
#endif
|
|
|
|
|
2008-07-25 13:45:57 +00:00
|
|
|
#include "BKE_material.h" /* give_current_material */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "KX_GameObject.h"
|
|
|
|
#include "KX_IpoConvert.h"
|
|
|
|
#include "KX_IInterpolator.h"
|
|
|
|
#include "KX_ScalarInterpolator.h"
|
|
|
|
|
|
|
|
#include "KX_BlenderScalarInterpolator.h"
|
|
|
|
#include "KX_BlenderSceneConverter.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* This little block needed for linking to Blender... */
|
|
|
|
#ifdef WIN32
|
|
|
|
#include "BLI_winstuff.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "DNA_object_types.h"
|
2009-11-15 11:32:53 +00:00
|
|
|
#include "DNA_action_types.h"
|
2011-05-28 07:15:27 +00:00
|
|
|
#include "DNA_anim_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_ipo_types.h"
|
|
|
|
#include "DNA_lamp_types.h"
|
|
|
|
#include "DNA_world_types.h"
|
|
|
|
#include "DNA_camera_types.h"
|
2006-01-06 03:46:54 +00:00
|
|
|
#include "DNA_material_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
/* end of blender include block */
|
|
|
|
|
|
|
|
#include "KX_IPO_SGController.h"
|
|
|
|
#include "KX_LightIpoSGController.h"
|
|
|
|
#include "KX_CameraIpoSGController.h"
|
|
|
|
#include "KX_WorldIpoController.h"
|
|
|
|
#include "KX_ObColorIpoSGController.h"
|
2006-01-06 03:46:54 +00:00
|
|
|
#include "KX_MaterialIpoController.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "SG_Node.h"
|
|
|
|
|
2008-07-25 13:45:57 +00:00
|
|
|
#include "STR_HashedString.h"
|
|
|
|
|
2011-12-30 07:55:15 +00:00
|
|
|
static BL_InterpolatorList *GetAdtList(struct bAction *for_act, KX_BlenderSceneConverter *converter)
|
|
|
|
{
|
2011-08-07 04:57:23 +00:00
|
|
|
BL_InterpolatorList *adtList= converter->FindInterpolatorList(for_act);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
if (!adtList) {
|
2011-08-07 04:57:23 +00:00
|
|
|
adtList = new BL_InterpolatorList(for_act);
|
|
|
|
converter->RegisterInterpolatorList(adtList, for_act);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
return adtList;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2011-05-28 07:15:27 +00:00
|
|
|
SG_Controller *BL_CreateIPO(struct bAction *action, KX_GameObject* gameobj, KX_BlenderSceneConverter *converter)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2011-05-28 07:15:27 +00:00
|
|
|
KX_IpoSGController* ipocontr = new KX_IpoSGController();
|
|
|
|
ipocontr->SetGameObject(gameobj);
|
|
|
|
|
|
|
|
Object* blenderobject = gameobj->GetBlenderObject();
|
|
|
|
|
2011-08-27 03:13:54 +00:00
|
|
|
ipocontr->GetIPOTransform().SetPosition(MT_Point3(blenderobject->loc));
|
|
|
|
ipocontr->GetIPOTransform().SetEulerAngles(MT_Vector3(blenderobject->rot));
|
|
|
|
ipocontr->GetIPOTransform().SetScaling(MT_Vector3(blenderobject->size));
|
2011-05-28 07:15:27 +00:00
|
|
|
|
|
|
|
const char *rotmode, *drotmode;
|
|
|
|
|
2011-08-27 03:13:54 +00:00
|
|
|
switch(blenderobject->rotmode) {
|
2011-05-28 07:15:27 +00:00
|
|
|
case ROT_MODE_AXISANGLE:
|
|
|
|
rotmode = "rotation_axis_angle";
|
|
|
|
drotmode = "delta_rotation_axis_angle";
|
2011-08-27 03:13:54 +00:00
|
|
|
break;
|
2012-03-18 07:38:51 +00:00
|
|
|
case ROT_MODE_QUAT: /* XXX, this isn't working, currently only eulers are supported [#28853] */
|
2011-05-28 07:15:27 +00:00
|
|
|
rotmode = "rotation_quaternion";
|
|
|
|
drotmode = "delta_rotation_quaternion";
|
2011-08-27 03:13:54 +00:00
|
|
|
break;
|
2011-05-28 07:15:27 +00:00
|
|
|
default:
|
|
|
|
rotmode = "rotation_euler";
|
|
|
|
drotmode = "delta_rotation_euler";
|
2011-08-27 03:13:54 +00:00
|
|
|
break;
|
2011-05-28 07:15:27 +00:00
|
|
|
}
|
2009-11-15 11:32:53 +00:00
|
|
|
|
2011-08-07 04:57:23 +00:00
|
|
|
BL_InterpolatorList *adtList= GetAdtList(action, converter);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-05-28 07:15:27 +00:00
|
|
|
// For each active channel in the adtList add an
|
|
|
|
// interpolator to the game object.
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-05-28 07:15:27 +00:00
|
|
|
KX_IInterpolator *interpolator;
|
|
|
|
KX_IScalarInterpolator *interp;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
2011-05-28 07:15:27 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("location", i))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetPosition()[i]), interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetIPOChannelActive(OB_LOC_X+i, true);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-05-28 07:15:27 +00:00
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
2011-05-28 07:15:27 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("delta_location", i))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaPosition()[i]), interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetIPOChannelActive(OB_DLOC_X+i, true);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-05-28 07:15:27 +00:00
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
2011-05-28 07:15:27 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator(rotmode, i))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetEulerAngles()[i]), interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetIPOChannelActive(OB_ROT_X+i, true);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-05-28 07:15:27 +00:00
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
2011-05-28 07:15:27 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator(drotmode, i))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[i]), interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetIPOChannelActive(OB_DROT_X+i, true);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-05-28 07:15:27 +00:00
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
2011-05-28 07:15:27 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("scale", i))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetScaling()[i]), interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetIPOChannelActive(OB_SIZE_X+i, true);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-05-28 07:15:27 +00:00
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
2011-05-28 07:15:27 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("delta_scale", i))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaScaling()[i]), interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetIPOChannelActive(OB_DSIZE_X+i, true);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-05-28 07:15:27 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-05-28 07:15:27 +00:00
|
|
|
{
|
|
|
|
KX_ObColorIpoSGController* ipocontr_obcol=NULL;
|
2009-06-15 10:11:08 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<4; i++) {
|
2011-05-28 07:15:27 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("color", i))) {
|
|
|
|
if (!ipocontr_obcol) {
|
|
|
|
ipocontr_obcol = new KX_ObColorIpoSGController();
|
|
|
|
gameobj->GetSGNode()->AddSGController(ipocontr_obcol);
|
|
|
|
ipocontr_obcol->SetObject(gameobj->GetSGNode());
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-05-28 07:15:27 +00:00
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr_obcol->m_rgba[i], interp);
|
|
|
|
ipocontr_obcol->AddInterpolator(interpolator);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-28 07:15:27 +00:00
|
|
|
|
|
|
|
return ipocontr;
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
SG_Controller *BL_CreateLampIPO(struct bAction *action, KX_GameObject* lightobj, KX_BlenderSceneConverter *converter)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2011-08-17 09:38:50 +00:00
|
|
|
KX_LightIpoSGController* ipocontr = new KX_LightIpoSGController();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
Lamp *blenderlamp = (Lamp*)lightobj->GetBlenderObject()->data;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
ipocontr->m_energy = blenderlamp->energy;
|
|
|
|
ipocontr->m_col_rgb[0] = blenderlamp->r;
|
|
|
|
ipocontr->m_col_rgb[1] = blenderlamp->g;
|
|
|
|
ipocontr->m_col_rgb[2] = blenderlamp->b;
|
|
|
|
ipocontr->m_dist = blenderlamp->dist;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
BL_InterpolatorList *adtList= GetAdtList(action, converter);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
// For each active channel in the adtList add an
|
|
|
|
// interpolator to the game object.
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
KX_IInterpolator *interpolator;
|
|
|
|
KX_IScalarInterpolator *interp;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
if ((interp= adtList->GetScalarInterpolator("energy", 0))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_energy, interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetModifyEnergy(true);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("distance", 0))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_dist, interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetModifyDist(true);
|
|
|
|
}
|
2009-06-15 10:11:08 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
2011-08-17 09:38:50 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("color", i))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_col_rgb[i], interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetModifyColor(true);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-17 09:38:50 +00:00
|
|
|
|
|
|
|
return ipocontr;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
void BL_ConvertLampIpos(struct Lamp* blenderlamp, KX_GameObject *lightobj,KX_BlenderSceneConverter *converter)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
if (blenderlamp->adt) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
SG_Controller* ipocontr = BL_CreateLampIPO(blenderlamp->adt->action, lightobj, converter);
|
|
|
|
lightobj->GetSGNode()->AddSGController(ipocontr);
|
|
|
|
ipocontr->SetObject(lightobj->GetSGNode());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
SG_Controller *BL_CreateCameraIPO(struct bAction *action, KX_GameObject* cameraobj, KX_BlenderSceneConverter *converter)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2011-08-17 09:38:50 +00:00
|
|
|
KX_CameraIpoSGController* ipocontr = new KX_CameraIpoSGController();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
Camera *blendercamera = (Camera*)cameraobj->GetBlenderObject()->data;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
ipocontr->m_lens = blendercamera->lens;
|
|
|
|
ipocontr->m_clipstart = blendercamera->clipsta;
|
|
|
|
ipocontr->m_clipend = blendercamera->clipend;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-09-04 01:27:16 +00:00
|
|
|
BL_InterpolatorList *adtList= GetAdtList(action, converter);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
// For each active channel in the adtList add an
|
|
|
|
// interpolator to the game object.
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
KX_IInterpolator *interpolator;
|
|
|
|
KX_IScalarInterpolator *interp;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("lens", 0))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_lens, interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetModifyLens(true);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("clip_start", 0))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipstart, interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetModifyClipStart(true);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("clip_end", 0))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipend, interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetModifyClipEnd(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ipocontr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BL_ConvertCameraIpos(struct Camera* blendercamera, KX_GameObject *cameraobj,KX_BlenderSceneConverter *converter)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-08-17 09:38:50 +00:00
|
|
|
if (blendercamera->adt) {
|
|
|
|
SG_Controller* ipocontr = BL_CreateCameraIPO(blendercamera->adt->action, cameraobj, converter);
|
|
|
|
cameraobj->GetSGNode()->AddSGController(ipocontr);
|
|
|
|
ipocontr->SetObject(cameraobj->GetSGNode());
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BL_ConvertWorldIpos(struct World* blenderworld,KX_BlenderSceneConverter *converter)
|
|
|
|
{
|
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
if (blenderworld->adt) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
KX_WorldIpoController* ipocontr = new KX_WorldIpoController();
|
|
|
|
|
|
|
|
// Erwin, hook up the world ipo controller here
|
|
|
|
// Gino: hook it up to what ?
|
|
|
|
// is there a userinterface element for that ?
|
|
|
|
// for now, we have some new python hooks to access the data, for a work-around
|
|
|
|
|
|
|
|
ipocontr->m_mist_start = blenderworld->miststa;
|
|
|
|
ipocontr->m_mist_dist = blenderworld->mistdist;
|
|
|
|
ipocontr->m_mist_rgb[0] = blenderworld->horr;
|
|
|
|
ipocontr->m_mist_rgb[1] = blenderworld->horg;
|
|
|
|
ipocontr->m_mist_rgb[2] = blenderworld->horb;
|
|
|
|
|
2011-08-07 04:57:23 +00:00
|
|
|
BL_InterpolatorList *adtList= GetAdtList(blenderworld->adt->action, converter);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
// For each active channel in the adtList add an
|
2002-10-12 11:37:38 +00:00
|
|
|
// interpolator to the game object.
|
|
|
|
|
2009-06-15 11:47:16 +00:00
|
|
|
KX_IInterpolator *interpolator;
|
2009-06-15 10:11:08 +00:00
|
|
|
KX_IScalarInterpolator *interp;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
2009-06-15 10:11:08 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("horizon_color", i))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_mist_rgb[i], interp);
|
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetModifyMistColor(true);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("mist.depth", 0))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_mist_dist, interp);
|
2002-10-12 11:37:38 +00:00
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetModifyMistDist(true);
|
|
|
|
}
|
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
if ((interp = adtList->GetScalarInterpolator("mist.start", 0))) {
|
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_mist_start, interp);
|
2002-10-12 11:37:38 +00:00
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
ipocontr->SetModifyMistStart(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-25 13:45:57 +00:00
|
|
|
static void ConvertMaterialIpos(
|
|
|
|
Material* blendermaterial,
|
|
|
|
dword matname_hash,
|
2006-01-06 03:46:54 +00:00
|
|
|
KX_GameObject* gameobj,
|
|
|
|
KX_BlenderSceneConverter *converter
|
|
|
|
)
|
|
|
|
{
|
2009-06-15 10:11:08 +00:00
|
|
|
if (blendermaterial->adt) {
|
2008-07-25 13:45:57 +00:00
|
|
|
KX_MaterialIpoController* ipocontr = new KX_MaterialIpoController(matname_hash);
|
2006-01-06 03:46:54 +00:00
|
|
|
gameobj->GetSGNode()->AddSGController(ipocontr);
|
|
|
|
ipocontr->SetObject(gameobj->GetSGNode());
|
|
|
|
|
2011-08-07 04:57:23 +00:00
|
|
|
BL_InterpolatorList *adtList= GetAdtList(blendermaterial->adt->action, converter);
|
2006-01-06 03:46:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
KX_IInterpolator *interpolator;
|
|
|
|
KX_IScalarInterpolator *sinterp;
|
2006-01-06 03:46:54 +00:00
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
// --
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
2009-06-15 10:11:08 +00:00
|
|
|
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);
|
2006-01-06 03:46:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
if ((sinterp = adtList->GetScalarInterpolator("alpha", 0))) {
|
2006-01-06 03:46:54 +00:00
|
|
|
if (!ipocontr) {
|
2008-07-25 13:45:57 +00:00
|
|
|
ipocontr = new KX_MaterialIpoController(matname_hash);
|
2006-01-06 03:46:54 +00:00
|
|
|
gameobj->GetSGNode()->AddSGController(ipocontr);
|
|
|
|
ipocontr->SetObject(gameobj->GetSGNode());
|
|
|
|
}
|
2009-06-15 10:11:08 +00:00
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[3], sinterp);
|
2006-01-06 03:46:54 +00:00
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
}
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
2009-06-15 10:11:08 +00:00
|
|
|
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);
|
2006-01-06 03:46:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
if ((sinterp = adtList->GetScalarInterpolator("specular_hardness", 0))) {
|
2006-01-06 03:46:54 +00:00
|
|
|
if (!ipocontr) {
|
2008-07-25 13:45:57 +00:00
|
|
|
ipocontr = new KX_MaterialIpoController(matname_hash);
|
2006-01-06 03:46:54 +00:00
|
|
|
gameobj->GetSGNode()->AddSGController(ipocontr);
|
|
|
|
ipocontr->SetObject(gameobj->GetSGNode());
|
|
|
|
}
|
2009-06-15 10:11:08 +00:00
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_hard, sinterp);
|
2006-01-06 03:46:54 +00:00
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
}
|
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
if ((sinterp = adtList->GetScalarInterpolator("specularity", 0))) {
|
2006-01-06 03:46:54 +00:00
|
|
|
if (!ipocontr) {
|
2008-07-25 13:45:57 +00:00
|
|
|
ipocontr = new KX_MaterialIpoController(matname_hash);
|
2006-01-06 03:46:54 +00:00
|
|
|
gameobj->GetSGNode()->AddSGController(ipocontr);
|
|
|
|
ipocontr->SetObject(gameobj->GetSGNode());
|
|
|
|
}
|
2009-06-15 10:11:08 +00:00
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_spec, sinterp);
|
2006-01-06 03:46:54 +00:00
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
}
|
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
if ((sinterp = adtList->GetScalarInterpolator("diffuse_reflection", 0))) {
|
2006-01-06 03:46:54 +00:00
|
|
|
if (!ipocontr) {
|
2008-07-25 13:45:57 +00:00
|
|
|
ipocontr = new KX_MaterialIpoController(matname_hash);
|
2006-01-06 03:46:54 +00:00
|
|
|
gameobj->GetSGNode()->AddSGController(ipocontr);
|
|
|
|
ipocontr->SetObject(gameobj->GetSGNode());
|
|
|
|
}
|
2009-06-15 10:11:08 +00:00
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_ref, sinterp);
|
2006-01-06 03:46:54 +00:00
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
}
|
|
|
|
|
2009-06-15 10:11:08 +00:00
|
|
|
if ((sinterp = adtList->GetScalarInterpolator("emit", 0))) {
|
2006-01-06 03:46:54 +00:00
|
|
|
if (!ipocontr) {
|
2008-07-25 13:45:57 +00:00
|
|
|
ipocontr = new KX_MaterialIpoController(matname_hash);
|
2006-01-06 03:46:54 +00:00
|
|
|
gameobj->GetSGNode()->AddSGController(ipocontr);
|
|
|
|
ipocontr->SetObject(gameobj->GetSGNode());
|
|
|
|
}
|
2009-06-15 10:11:08 +00:00
|
|
|
interpolator= new KX_ScalarInterpolator(&ipocontr->m_emit, sinterp);
|
2006-01-06 03:46:54 +00:00
|
|
|
ipocontr->AddInterpolator(interpolator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-25 13:45:57 +00:00
|
|
|
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
|
2012-03-24 07:52:14 +00:00
|
|
|
if (mat) ConvertMaterialIpos(mat, 0, gameobj, converter);
|
2008-07-25 13:45:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int material_index=1; material_index <= blenderobject->totcol; material_index++)
|
|
|
|
{
|
|
|
|
Material *mat = give_current_material(blenderobject, material_index);
|
2008-08-05 21:20:14 +00:00
|
|
|
STR_HashedString matname;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (mat) {
|
2009-11-22 00:01:52 +00:00
|
|
|
matname= mat->id.name; // who is using this name? can we remove the MA here?
|
2008-08-05 21:20:14 +00:00
|
|
|
ConvertMaterialIpos(mat, matname.hash(), gameobj, converter);
|
|
|
|
}
|
2008-07-25 13:45:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|