Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/gameengine/Converter')
-rw-r--r--source/gameengine/Converter/BL_ActionActuator.cpp664
-rw-r--r--source/gameengine/Converter/BL_ActionActuator.h158
-rw-r--r--source/gameengine/Converter/BL_ArmatureActuator.cpp271
-rw-r--r--source/gameengine/Converter/BL_ArmatureActuator.h96
-rw-r--r--source/gameengine/Converter/BL_ArmatureChannel.cpp469
-rw-r--r--source/gameengine/Converter/BL_ArmatureChannel.h101
-rw-r--r--source/gameengine/Converter/BL_ArmatureConstraint.cpp456
-rw-r--r--source/gameengine/Converter/BL_ArmatureConstraint.h125
-rw-r--r--source/gameengine/Converter/BL_ArmatureObject.cpp687
-rw-r--r--source/gameengine/Converter/BL_ArmatureObject.h145
-rw-r--r--source/gameengine/Converter/BL_BlenderDataConversion.cpp2467
-rw-r--r--source/gameengine/Converter/BL_BlenderDataConversion.h56
-rw-r--r--source/gameengine/Converter/BL_DeformableGameObject.cpp116
-rw-r--r--source/gameengine/Converter/BL_DeformableGameObject.h107
-rw-r--r--source/gameengine/Converter/BL_MeshDeformer.cpp239
-rw-r--r--source/gameengine/Converter/BL_MeshDeformer.h98
-rw-r--r--source/gameengine/Converter/BL_ModifierDeformer.cpp219
-rw-r--r--source/gameengine/Converter/BL_ModifierDeformer.h115
-rw-r--r--source/gameengine/Converter/BL_ShapeActionActuator.cpp563
-rw-r--r--source/gameengine/Converter/BL_ShapeActionActuator.h144
-rw-r--r--source/gameengine/Converter/BL_ShapeDeformer.cpp237
-rw-r--r--source/gameengine/Converter/BL_ShapeDeformer.h86
-rw-r--r--source/gameengine/Converter/BL_SkinDeformer.cpp384
-rw-r--r--source/gameengine/Converter/BL_SkinDeformer.h125
-rw-r--r--source/gameengine/Converter/CMakeLists.txt123
-rw-r--r--source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp81
-rw-r--r--source/gameengine/Converter/KX_BlenderScalarInterpolator.h76
-rw-r--r--source/gameengine/Converter/KX_BlenderSceneConverter.cpp1477
-rw-r--r--source/gameengine/Converter/KX_BlenderSceneConverter.h232
-rw-r--r--source/gameengine/Converter/KX_ConvertActuators.cpp1146
-rw-r--r--source/gameengine/Converter/KX_ConvertActuators.h45
-rw-r--r--source/gameengine/Converter/KX_ConvertControllers.cpp250
-rw-r--r--source/gameengine/Converter/KX_ConvertControllers.h47
-rw-r--r--source/gameengine/Converter/KX_ConvertProperties.cpp243
-rw-r--r--source/gameengine/Converter/KX_ConvertProperties.h41
-rw-r--r--source/gameengine/Converter/KX_ConvertSensors.cpp663
-rw-r--r--source/gameengine/Converter/KX_ConvertSensors.h45
-rw-r--r--source/gameengine/Converter/KX_LibLoadStatus.cpp255
-rw-r--r--source/gameengine/Converter/KX_LibLoadStatus.h93
-rw-r--r--source/gameengine/Converter/KX_SoftBodyDeformer.cpp121
-rw-r--r--source/gameengine/Converter/KX_SoftBodyDeformer.h102
41 files changed, 0 insertions, 13168 deletions
diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp
deleted file mode 100644
index 558fd6cd2b5..00000000000
--- a/source/gameengine/Converter/BL_ActionActuator.cpp
+++ /dev/null
@@ -1,664 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ActionActuator.cpp
- * \ingroup bgeconv
- */
-
-
-#include "SCA_LogicManager.h"
-#include "BL_ActionActuator.h"
-#include "BL_ArmatureObject.h"
-#include "BL_SkinDeformer.h"
-#include "BL_Action.h"
-#include "BL_ActionManager.h"
-#include "KX_GameObject.h"
-#include "STR_HashedString.h"
-#include "MEM_guardedalloc.h"
-#include "DNA_nla_types.h"
-#include "DNA_action_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_scene_types.h"
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-#include "MT_Matrix4x4.h"
-
-#include "BKE_action.h"
-#include "EXP_FloatValue.h"
-#include "EXP_PyObjectPlus.h"
-#include "KX_PyMath.h"
-
-extern "C" {
-#include "BKE_animsys.h"
-#include "BKE_action.h"
-#include "RNA_access.h"
-#include "RNA_define.h"
-}
-
-BL_ActionActuator::BL_ActionActuator(SCA_IObject *gameobj,
- const STR_String& propname,
- const STR_String& framepropname,
- float starttime,
- float endtime,
- struct bAction *action,
- short playtype,
- short blend_mode,
- short blendin,
- short priority,
- short layer,
- float layer_weight,
- short ipo_flags,
- short end_reset,
- float stride)
- : SCA_IActuator(gameobj, KX_ACT_ACTION),
-
- m_lastpos(0, 0, 0),
- m_blendframe(0),
- m_flag(0),
- m_startframe (starttime),
- m_endframe(endtime) ,
- m_starttime(0),
- m_localtime(starttime),
- m_lastUpdate(-1),
- m_blendin(blendin),
- m_blendstart(0),
- m_stridelength(stride),
- m_layer_weight(layer_weight),
- m_playtype(playtype),
- m_blendmode(blend_mode),
- m_priority(priority),
- m_layer(layer),
- m_ipo_flags(ipo_flags),
- m_action(action),
- m_propname(propname),
- m_framepropname(framepropname)
-{
- if (!end_reset)
- m_flag |= ACT_FLAG_CONTINUE;
-};
-
-BL_ActionActuator::~BL_ActionActuator()
-{
-}
-
-void BL_ActionActuator::ProcessReplica()
-{
- SCA_IActuator::ProcessReplica();
-
- m_localtime=m_startframe;
- m_lastUpdate=-1;
-
-}
-
-void BL_ActionActuator::SetBlendTime(float newtime)
-{
- m_blendframe = newtime;
-}
-
-void BL_ActionActuator::SetLocalTime(float curtime)
-{
- float dt = (curtime-m_starttime)*KX_KetsjiEngine::GetAnimFrameRate();
-
- if (m_endframe < m_startframe)
- dt = -dt;
-
- m_localtime = m_startframe + dt;
-
- // Handle wrap around
- if (m_localtime < min(m_startframe, m_endframe) || m_localtime > max(m_startframe, m_endframe))
- {
- switch (m_playtype) {
- case ACT_ACTION_PLAY:
- // Clamp
- m_localtime = m_endframe;
- break;
- case ACT_ACTION_LOOP_END:
- // Put the time back to the beginning
- m_localtime = m_startframe;
- m_starttime = curtime;
- break;
- case ACT_ACTION_PINGPONG:
- // Swap the start and end frames
- float temp = m_startframe;
- m_startframe = m_endframe;
- m_endframe = temp;
-
- m_starttime = curtime;
-
- m_flag ^= ACT_FLAG_REVERSE;
-
- break;
- }
- }
-}
-
-void BL_ActionActuator::ResetStartTime(float curtime)
-{
- float dt = m_localtime - m_startframe;
-
- m_starttime = curtime - dt / (KX_KetsjiEngine::GetAnimFrameRate());
- //SetLocalTime(curtime);
-}
-
-CValue* BL_ActionActuator::GetReplica()
-{
- BL_ActionActuator* replica = new BL_ActionActuator(*this);//m_float,GetName());
- replica->ProcessReplica();
- return replica;
-}
-
-bool BL_ActionActuator::Update(double curtime, bool frame)
-{
- bool bNegativeEvent = false;
- bool bPositiveEvent = false;
- bool bUseContinue = false;
- KX_GameObject *obj = (KX_GameObject*)GetParent();
- short playtype = BL_Action::ACT_MODE_PLAY;
- short blendmode = (m_blendmode == ACT_ACTION_ADD) ? BL_Action::ACT_BLEND_ADD : BL_Action::ACT_BLEND_BLEND;
- float start = m_startframe;
- float end = m_endframe;
-
- // If we don't have an action, we can't do anything
- if (!m_action)
- return false;
-
- // Convert our playtype to one that BL_Action likes
- switch (m_playtype) {
- case ACT_ACTION_LOOP_END:
- case ACT_ACTION_LOOP_STOP:
- playtype = BL_Action::ACT_MODE_LOOP;
- break;
-
- case ACT_ACTION_PINGPONG:
- // We handle ping pong ourselves to increase compabitility
- // with files made prior to animation changes from GSoC 2011.
- playtype = BL_Action::ACT_MODE_PLAY;
-
- if (m_flag & ACT_FLAG_REVERSE)
- {
- start = m_endframe;
- end = m_startframe;
- }
-
- break;
- case ACT_ACTION_FROM_PROP:
- CValue* prop = GetParent()->GetProperty(m_propname);
-
- // If we don't have a property, we can't do anything, so just bail
- if (!prop) return false;
-
- playtype = BL_Action::ACT_MODE_PLAY;
- start = end = prop->GetNumber();
-
- break;
- }
-
- if (m_flag & ACT_FLAG_CONTINUE)
- bUseContinue = true;
-
-
- // Handle events
- if (frame)
- {
- bNegativeEvent = m_negevent;
- bPositiveEvent = m_posevent;
- RemoveAllEvents();
- }
-
- // "Active" actions need to keep updating their current frame
- if (bUseContinue && (m_flag & ACT_FLAG_ACTIVE))
- m_localtime = obj->GetActionFrame(m_layer);
-
- if (m_flag & ACT_FLAG_ATTEMPT_PLAY)
- SetLocalTime(curtime);
- else
- ResetStartTime(curtime);
-
- // Handle a frame property if it's defined
- if ((m_flag & ACT_FLAG_ACTIVE) && m_framepropname[0] != 0)
- {
- CValue* oldprop = obj->GetProperty(m_framepropname);
- CValue* newval = new CFloatValue(obj->GetActionFrame(m_layer));
- if (oldprop)
- oldprop->SetValue(newval);
- else
- obj->SetProperty(m_framepropname, newval);
-
- newval->Release();
- }
-
- // Handle a finished animation
- if ((m_flag & ACT_FLAG_PLAY_END) && (m_flag & ACT_FLAG_ACTIVE) && obj->IsActionDone(m_layer))
- {
- m_flag &= ~ACT_FLAG_ACTIVE;
-
- if (m_playtype == ACT_ACTION_PINGPONG) {
- m_flag ^= ACT_FLAG_REVERSE;
- }
- else {
- m_flag &= ~ACT_FLAG_ATTEMPT_PLAY;
- return false;
- }
- }
-
- // If a different action is playing, we've been overruled and are no longer active
- if (obj->GetCurrentAction(m_layer) != m_action && !obj->IsActionDone(m_layer))
- m_flag &= ~ACT_FLAG_ACTIVE;
-
- if (bPositiveEvent || (m_flag & ACT_FLAG_ATTEMPT_PLAY && !(m_flag & ACT_FLAG_ACTIVE)))
- {
- if (bPositiveEvent && m_playtype == ACT_ACTION_PLAY)
- {
- if (obj->IsActionDone(m_layer))
- m_localtime = start;
- ResetStartTime(curtime);
- }
-
- if (obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, m_blendin, playtype, m_layer_weight, m_ipo_flags, 1.f, blendmode))
- {
- m_flag |= ACT_FLAG_ACTIVE;
- if (bUseContinue)
- obj->SetActionFrame(m_layer, m_localtime);
-
- if (m_playtype == ACT_ACTION_PLAY || m_playtype == ACT_ACTION_PINGPONG)
- m_flag |= ACT_FLAG_PLAY_END;
- else
- m_flag &= ~ACT_FLAG_PLAY_END;
- }
- m_flag |= ACT_FLAG_ATTEMPT_PLAY;
- }
- else if ((m_flag & ACT_FLAG_ACTIVE) && bNegativeEvent)
- {
- m_flag &= ~ACT_FLAG_ATTEMPT_PLAY;
- m_localtime = obj->GetActionFrame(m_layer);
- bAction *curr_action = obj->GetCurrentAction(m_layer);
- if (curr_action && curr_action != m_action)
- {
- // Someone changed the action on us, so we wont mess with it
- // Hopefully there wont be too many problems with two actuators using
- // the same action...
- m_flag &= ~ACT_FLAG_ACTIVE;
- return false;
- }
-
- switch (m_playtype) {
- case ACT_ACTION_FROM_PROP:
- case ACT_ACTION_LOOP_STOP:
- obj->StopAction(m_layer); // Stop the action after getting the frame
-
- // We're done
- m_flag &= ~ACT_FLAG_ACTIVE;
- return false;
- case ACT_ACTION_LOOP_END:
- // Convert into a play and let it finish
- obj->SetPlayMode(m_layer, BL_Action::ACT_MODE_PLAY);
-
- m_flag |= ACT_FLAG_PLAY_END;
- break;
-
- case ACT_ACTION_FLIPPER:
- // Convert into a play action and play back to the beginning
- float temp = end;
- end = start;
- start = curr_action ? obj->GetActionFrame(m_layer) : temp;
- obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, 0, BL_Action::ACT_MODE_PLAY, m_layer_weight, m_ipo_flags, 1.f, blendmode);
-
- m_flag |= ACT_FLAG_PLAY_END;
- break;
- }
- }
-
- return m_flag & ACT_FLAG_ACTIVE;
-}
-
-void BL_ActionActuator::DecLink()
-{
- SCA_IActuator::DecLink();
- /* In this case no controllers use this action actuator,
- and it should stop its action. */
- if (m_links == 0) {
- KX_GameObject *obj = (KX_GameObject *)GetParent();
- obj->StopAction(m_layer);
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-PyObject *BL_ActionActuator::PyGetChannel(PyObject *value)
-{
- PyErr_SetString(PyExc_NotImplementedError, "BL_ActionActuator.getChannel() no longer works, please use BL_ArmatureObject.channels instead");
- return NULL;
-#if 0 // XXX To be removed in a later version (first removed in 2.64)
- const char *string= _PyUnicode_AsString(value);
-
- if (GetParent()->GetGameObjectType() != SCA_IObject::OBJ_ARMATURE)
- {
- PyErr_SetString(PyExc_NotImplementedError, "actuator.getChannel(): Only armatures support channels");
- return NULL;
- }
-
- if (!string) {
- PyErr_SetString(PyExc_TypeError, "expected a single string");
- return NULL;
- }
-
- bPoseChannel *pchan;
-
- if (m_userpose==NULL && m_pose==NULL) {
- BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
- obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
- }
-
- // BKE_pose_channel_find_name accounts for NULL pose, run on both in case one exists but
- // the channel doesnt
- if ( !(pchan=BKE_pose_channel_find_name(m_userpose, string)) &&
- !(pchan=BKE_pose_channel_find_name(m_pose, string)) )
- {
- PyErr_SetString(PyExc_ValueError, "channel doesnt exist");
- return NULL;
- }
-
- PyObject *ret = PyTuple_New(3);
-
- PyObject *list = PyList_New(3);
- PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->loc[0]));
- PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->loc[1]));
- PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->loc[2]));
- PyTuple_SET_ITEM(ret, 0, list);
-
- list = PyList_New(3);
- PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->size[0]));
- PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->size[1]));
- PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->size[2]));
- PyTuple_SET_ITEM(ret, 1, list);
-
- list = PyList_New(4);
- PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->quat[0]));
- PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->quat[1]));
- PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->quat[2]));
- PyList_SET_ITEM(list, 3, PyFloat_FromDouble(pchan->quat[3]));
- PyTuple_SET_ITEM(ret, 2, list);
-
- return ret;
-#if 0
- return Py_BuildValue("([fff][fff][ffff])",
- pchan->loc[0], pchan->loc[1], pchan->loc[2],
- pchan->size[0], pchan->size[1], pchan->size[2],
- pchan->quat[0], pchan->quat[1], pchan->quat[2], pchan->quat[3] );
-#endif
-#endif
-}
-
-/* setChannel */
-KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel,
-"setChannel(channel, matrix)\n"
-"\t - channel : A string specifying the name of the bone channel.\n"
-"\t - matrix : A 4x4 matrix specifying the overriding transformation\n"
-"\t as an offset from the bone's rest position.\n")
-{
- PyErr_SetString(PyExc_NotImplementedError, "BL_ActionActuator.setChannel() no longer works, please use BL_ArmatureObject.channels instead");
- return NULL;
-
-#if 0 // XXX To be removed in a later version (first removed in 2.64)
- BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
- char *string;
- PyObject *pymat= NULL;
- PyObject *pyloc= NULL, *pysize= NULL, *pyquat= NULL;
- bPoseChannel *pchan;
-
- if (GetParent()->GetGameObjectType() != SCA_IObject::OBJ_ARMATURE)
- {
- PyErr_SetString(PyExc_NotImplementedError, "actuator.setChannel(): Only armatures support channels");
- return NULL;
- }
-
- if (PyTuple_Size(args)==2) {
- if (!PyArg_ParseTuple(args,"sO:setChannel", &string, &pymat)) // matrix
- return NULL;
- }
- else if (PyTuple_Size(args)==4) {
- if (!PyArg_ParseTuple(args,"sOOO:setChannel", &string, &pyloc, &pysize, &pyquat)) // loc/size/quat
- return NULL;
- }
- else {
- PyErr_SetString(PyExc_ValueError, "Expected a string and a 4x4 matrix (2 args) or a string and loc/size/quat sequences (4 args)");
- return NULL;
- }
-
- if (pymat) {
- float matrix[4][4];
- MT_Matrix4x4 mat;
-
- if (!PyMatTo(pymat, mat))
- return NULL;
-
- mat.getValue((float*)matrix);
-
- BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
-
- if (!m_userpose) {
- if (!m_pose)
- obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
- game_copy_pose(&m_userpose, m_pose, 0);
- }
- // pchan= BKE_pose_channel_verify(m_userpose, string); // adds the channel if its not there.
- pchan= BKE_pose_channel_find_name(m_userpose, string); // adds the channel if its not there.
-
- if (pchan) {
- copy_v3_v3(pchan->loc, matrix[3]);
- mat4_to_size(pchan->size, matrix);
- mat4_to_quat(pchan->quat, matrix);
- }
- }
- else {
- MT_Vector3 loc;
- MT_Vector3 size;
- MT_Quaternion quat;
-
- if (!PyVecTo(pyloc, loc) || !PyVecTo(pysize, size) || !PyQuatTo(pyquat, quat))
- return NULL;
-
- // same as above
- if (!m_userpose) {
- if (!m_pose)
- obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
- game_copy_pose(&m_userpose, m_pose, 0);
- }
- // pchan= BKE_pose_channel_verify(m_userpose, string);
- pchan= BKE_pose_channel_find_name(m_userpose, string); // adds the channel if its not there.
-
- // for some reason loc.setValue(pchan->loc) fails
- if (pchan) {
- pchan->loc[0] = loc[0]; pchan->loc[1] = loc[1]; pchan->loc[2] = loc[2];
- pchan->size[0] = size[0]; pchan->size[1] = size[1]; pchan->size[2] = size[2];
- pchan->quat[0] = quat[3]; pchan->quat[1] = quat[0]; pchan->quat[2] = quat[1]; pchan->quat[3] = quat[2]; /* notice xyzw -> wxyz is intentional */
- }
- }
-
- if (pchan==NULL) {
- PyErr_SetString(PyExc_ValueError, "Channel could not be found, use the 'channelNames' attribute to get a list of valid channels");
- return NULL;
- }
-
- Py_RETURN_NONE;
-#endif
-}
-
-/* ------------------------------------------------------------------------- */
-/* Python Integration Hooks */
-/* ------------------------------------------------------------------------- */
-
-PyTypeObject BL_ActionActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ActionActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef BL_ActionActuator::Methods[] = {
- {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_O},
- KX_PYMETHODTABLE(BL_ActionActuator, setChannel),
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef BL_ActionActuator::Attributes[] = {
- KX_PYATTRIBUTE_FLOAT_RW("frameStart", 0, MAXFRAMEF, BL_ActionActuator, m_startframe),
- KX_PYATTRIBUTE_FLOAT_RW("frameEnd", 0, MAXFRAMEF, BL_ActionActuator, m_endframe),
- KX_PYATTRIBUTE_FLOAT_RW("blendIn", 0, MAXFRAMEF, BL_ActionActuator, m_blendin),
- KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ActionActuator, pyattr_get_action, pyattr_set_action),
- KX_PYATTRIBUTE_RO_FUNCTION("channelNames", BL_ActionActuator, pyattr_get_channel_names),
- KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ActionActuator, m_priority),
- KX_PYATTRIBUTE_SHORT_RW("layer", 0, MAX_ACTION_LAYERS-1, true, BL_ActionActuator, m_layer),
- KX_PYATTRIBUTE_FLOAT_RW("layerWeight", 0, 1.0, BL_ActionActuator, m_layer_weight),
- KX_PYATTRIBUTE_RW_FUNCTION("frame", BL_ActionActuator, pyattr_get_frame, pyattr_set_frame),
- KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, BL_ActionActuator, m_propname),
- KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, BL_ActionActuator, m_framepropname),
- KX_PYATTRIBUTE_RW_FUNCTION("useContinue", BL_ActionActuator, pyattr_get_use_continue, pyattr_set_use_continue),
- KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ActionActuator, m_blendframe, CheckBlendTime),
- KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ActionActuator,m_playtype,CheckType),
- { NULL } //Sentinel
-};
-
-PyObject *BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
- return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
-}
-
-int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
-
- if (!PyUnicode_Check(value))
- {
- PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, expected the string name of the action");
- return PY_SET_ATTR_FAIL;
- }
-
- bAction *action= NULL;
- STR_String val = _PyUnicode_AsString(value);
-
- if (val != "")
- {
- action= (bAction*)self->GetLogicManager()->GetActionByName(val);
- if (!action)
- {
- PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, action not found!");
- return PY_SET_ATTR_FAIL;
- }
- }
-
- self->SetAction(action);
- return PY_SET_ATTR_SUCCESS;
-
-}
-
-PyObject *BL_ActionActuator::pyattr_get_channel_names(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- PyErr_SetString(PyExc_NotImplementedError, "BL_ActionActuator.channelNames no longer works, please use BL_ArmatureObject.channels instead");
- return NULL;
-
-#if 0 // XXX To be removed in a later version (first removed in 2.64)
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
- PyObject *ret= PyList_New(0);
- PyObject *item;
-
- if (self->GetParent()->GetGameObjectType() != SCA_IObject::OBJ_ARMATURE)
- {
- PyErr_SetString(PyExc_NotImplementedError, "actuator.channelNames: Only armatures support channels");
- return NULL;
- }
-
- bPose *pose= ((BL_ArmatureObject*)self->GetParent())->GetOrigPose();
-
- if (pose) {
- bPoseChannel *pchan;
- for (pchan= (bPoseChannel *)pose->chanbase.first; pchan; pchan= (bPoseChannel *)pchan->next) {
- item= PyUnicode_FromString(pchan->name);
- PyList_Append(ret, item);
- Py_DECREF(item);
- }
- }
-
- return ret;
-#endif
-}
-
-PyObject *BL_ActionActuator::pyattr_get_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
- return PyBool_FromLong(self->m_flag & ACT_FLAG_CONTINUE);
-}
-
-int BL_ActionActuator::pyattr_set_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
-
- if (PyObject_IsTrue(value))
- self->m_flag |= ACT_FLAG_CONTINUE;
- else
- self->m_flag &= ~ACT_FLAG_CONTINUE;
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *BL_ActionActuator::pyattr_get_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
- return PyFloat_FromDouble(((KX_GameObject*)self->m_gameobj)->GetActionFrame(self->m_layer));
-}
-
-int BL_ActionActuator::pyattr_set_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
-
- ((KX_GameObject*)self->m_gameobj)->SetActionFrame(self->m_layer, PyFloat_AsDouble(value));
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/BL_ActionActuator.h b/source/gameengine/Converter/BL_ActionActuator.h
deleted file mode 100644
index a1ba2e4a98f..00000000000
--- a/source/gameengine/Converter/BL_ActionActuator.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ActionActuator.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_ACTIONACTUATOR_H__
-#define __BL_ACTIONACTUATOR_H__
-
-#include "CTR_HashedPtr.h"
-#include "SCA_IActuator.h"
-#include "DNA_actuator_types.h"
-#include "MT_Point3.h"
-
-class BL_ActionActuator : public SCA_IActuator
-{
-public:
- Py_Header
- BL_ActionActuator(SCA_IObject* gameobj,
- const STR_String& propname,
- const STR_String& framepropname,
- float starttime,
- float endtime,
- struct bAction *action,
- short playtype,
- short blend_mode,
- short blendin,
- short priority,
- short layer,
- float layer_weight,
- short ipo_flags,
- short end_reset,
- float stride);
-
- virtual ~BL_ActionActuator();
- virtual bool Update(double curtime, bool frame);
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
-
- void SetBlendTime(float newtime);
- void SetLocalTime(float curtime);
- void ResetStartTime(float curtime);
-
- bAction* GetAction() { return m_action; }
- void SetAction(bAction* act) { m_action= act; }
-
- virtual void DecLink();
-
-#ifdef WITH_PYTHON
-
- KX_PYMETHOD_O(BL_ActionActuator,GetChannel)
- KX_PYMETHOD_DOC(BL_ActionActuator,setChannel)
-
- static PyObject* pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_channel_names(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static int CheckBlendTime(void *self, const PyAttributeDef*)
- {
- BL_ActionActuator* act = reinterpret_cast<BL_ActionActuator*>(self);
-
- if (act->m_blendframe > act->m_blendin)
- act->m_blendframe = act->m_blendin;
-
- return 0;
- }
-
- static int CheckType(void *self, const PyAttributeDef*)
- {
- BL_ActionActuator* act = reinterpret_cast<BL_ActionActuator*>(self);
-
- switch (act->m_playtype) {
- case ACT_ACTION_PLAY:
- case ACT_ACTION_PINGPONG:
- case ACT_ACTION_FLIPPER:
- case ACT_ACTION_LOOP_STOP:
- case ACT_ACTION_LOOP_END:
- case ACT_ACTION_FROM_PROP:
- return 0;
- default:
- PyErr_SetString(PyExc_ValueError, "Action Actuator, invalid play type supplied");
- return 1;
- }
- }
-#endif /* WITH_PYTHON */
-
-protected:
- MT_Point3 m_lastpos;
- float m_blendframe;
- int m_flag;
- /** The frame this action starts */
- float m_startframe;
- /** The frame this action ends */
- float m_endframe;
- /** The time this action started */
- float m_starttime;
- /** The current time of the action */
- float m_localtime;
-
- float m_lastUpdate;
- float m_blendin;
- float m_blendstart;
- float m_stridelength;
- float m_layer_weight;
- short m_playtype;
- short m_blendmode;
- short m_priority;
- short m_layer;
- short m_ipo_flags;
- struct bAction *m_action;
- STR_String m_propname;
- STR_String m_framepropname;
-};
-
-// Not all of these values are used in BL_ActionActuator anymore,
-// but BL_ShapeActionActuator still uses them, so we keep them around
-// for now.
-enum {
- ACT_FLAG_REVERSE = 1<<0,
- ACT_FLAG_LOCKINPUT = 1<<1,
- ACT_FLAG_KEYUP = 1<<2,
- ACT_FLAG_ACTIVE = 1<<3,
- ACT_FLAG_CONTINUE = 1<<4,
- ACT_FLAG_PLAY_END = 1<<5,
- ACT_FLAG_ATTEMPT_PLAY = 1<<6,
-};
-
-#endif
-
diff --git a/source/gameengine/Converter/BL_ArmatureActuator.cpp b/source/gameengine/Converter/BL_ArmatureActuator.cpp
deleted file mode 100644
index 21364075429..00000000000
--- a/source/gameengine/Converter/BL_ArmatureActuator.cpp
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ArmatureActuator.cpp
- * \ingroup bgeconv
- */
-
-
-#include "DNA_action_types.h"
-#include "DNA_constraint_types.h"
-#include "DNA_actuator_types.h"
-#include "BKE_constraint.h"
-#include "BL_ArmatureActuator.h"
-#include "BL_ArmatureObject.h"
-#include "BLI_math.h"
-
-/**
- * This class is the conversion of the Pose channel constraint.
- * It makes a link between the pose constraint and the KX scene.
- * The main purpose is to give access to the constraint target
- * to link it to a game object.
- * It also allows to activate/deactivate constraints during the game.
- * Later it will also be possible to create constraint on the fly
- */
-
-BL_ArmatureActuator::BL_ArmatureActuator(SCA_IObject* obj,
- int type,
- const char *posechannel,
- const char *constraintname,
- KX_GameObject* targetobj,
- KX_GameObject* subtargetobj,
- float weight,
- float influence) :
- SCA_IActuator(obj, KX_ACT_ARMATURE),
- m_constraint(NULL),
- m_gametarget(targetobj),
- m_gamesubtarget(subtargetobj),
- m_posechannel(posechannel),
- m_constraintname(constraintname),
- m_weight(weight),
- m_influence(influence),
- m_type(type)
-{
- if (m_gametarget)
- m_gametarget->RegisterActuator(this);
- if (m_gamesubtarget)
- m_gamesubtarget->RegisterActuator(this);
- FindConstraint();
-}
-
-BL_ArmatureActuator::~BL_ArmatureActuator()
-{
- if (m_gametarget)
- m_gametarget->UnregisterActuator(this);
- if (m_gamesubtarget)
- m_gamesubtarget->UnregisterActuator(this);
-}
-
-void BL_ArmatureActuator::ProcessReplica()
-{
- // the replica is tracking the same object => register it (this may be changed in Relnk())
- if (m_gametarget)
- m_gametarget->RegisterActuator(this);
- if (m_gamesubtarget)
- m_gamesubtarget->UnregisterActuator(this);
- SCA_IActuator::ProcessReplica();
-}
-
-void BL_ArmatureActuator::ReParent(SCA_IObject* parent)
-{
- SCA_IActuator::ReParent(parent);
- // must remap the constraint
- FindConstraint();
-}
-
-bool BL_ArmatureActuator::UnlinkObject(SCA_IObject* clientobj)
-{
- bool res=false;
- if (clientobj == m_gametarget)
- {
- // this object is being deleted, we cannot continue to track it.
- m_gametarget = NULL;
- res = true;
- }
- if (clientobj == m_gamesubtarget)
- {
- // this object is being deleted, we cannot continue to track it.
- m_gamesubtarget = NULL;
- res = true;
- }
- return res;
-}
-
-void BL_ArmatureActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_gametarget];
- if (h_obj) {
- if (m_gametarget)
- m_gametarget->UnregisterActuator(this);
- m_gametarget = (KX_GameObject*)(*h_obj);
- m_gametarget->RegisterActuator(this);
- }
- h_obj = (*obj_map)[m_gamesubtarget];
- if (h_obj) {
- if (m_gamesubtarget)
- m_gamesubtarget->UnregisterActuator(this);
- m_gamesubtarget = (KX_GameObject*)(*h_obj);
- m_gamesubtarget->RegisterActuator(this);
- }
-}
-
-void BL_ArmatureActuator::FindConstraint()
-{
- m_constraint = NULL;
-
- if (m_gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) {
- BL_ArmatureObject* armobj = (BL_ArmatureObject*)m_gameobj;
- m_constraint = armobj->GetConstraint(m_posechannel, m_constraintname);
- }
-}
-
-bool BL_ArmatureActuator::Update(double curtime, bool frame)
-{
- // the only role of this actuator is to ensure that the armature pose will be evaluated
- bool result = false;
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (!bNegativeEvent) {
- BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
- switch (m_type) {
- case ACT_ARM_RUN:
- result = true;
- obj->UpdateTimestep(curtime);
- break;
- case ACT_ARM_ENABLE:
- if (m_constraint)
- m_constraint->ClrConstraintFlag(CONSTRAINT_OFF);
- break;
- case ACT_ARM_DISABLE:
- if (m_constraint)
- m_constraint->SetConstraintFlag(CONSTRAINT_OFF);
- break;
- case ACT_ARM_SETTARGET:
- if (m_constraint) {
- m_constraint->SetTarget(m_gametarget);
- m_constraint->SetSubtarget(m_gamesubtarget);
- }
- break;
- case ACT_ARM_SETWEIGHT:
- if (m_constraint)
- m_constraint->SetWeight(m_weight);
- break;
- case ACT_ARM_SETINFLUENCE:
- if (m_constraint)
- m_constraint->SetInfluence(m_influence);
- break;
- }
- }
- return result;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python Integration Hooks */
-/* ------------------------------------------------------------------------- */
-
-PyTypeObject BL_ArmatureActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ArmatureActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-
-PyMethodDef BL_ArmatureActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef BL_ArmatureActuator::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("constraint", BL_ArmatureActuator, pyattr_get_constraint),
- KX_PYATTRIBUTE_RW_FUNCTION("target", BL_ArmatureActuator, pyattr_get_object, pyattr_set_object),
- KX_PYATTRIBUTE_RW_FUNCTION("subtarget", BL_ArmatureActuator, pyattr_get_object, pyattr_set_object),
- KX_PYATTRIBUTE_FLOAT_RW("weight",0.0f,1.0f,BL_ArmatureActuator,m_weight),
- KX_PYATTRIBUTE_FLOAT_RW("influence",0.0f,1.0f,BL_ArmatureActuator,m_influence),
- KX_PYATTRIBUTE_INT_RW("type",0,ACT_ARM_MAXTYPE,false,BL_ArmatureActuator,m_type),
- { NULL } //Sentinel
-};
-
-PyObject *BL_ArmatureActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ArmatureActuator* actuator = static_cast<BL_ArmatureActuator*>(self);
- KX_GameObject *target = (!strcmp(attrdef->m_name, "target")) ? actuator->m_gametarget : actuator->m_gamesubtarget;
- if (!target)
- Py_RETURN_NONE;
- else
- return target->GetProxy();
-}
-
-int BL_ArmatureActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ArmatureActuator* actuator = static_cast<BL_ArmatureActuator*>(self);
- KX_GameObject* &target = (!strcmp(attrdef->m_name, "target")) ? actuator->m_gametarget : actuator->m_gamesubtarget;
- KX_GameObject *gameobj;
-
- if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: BL_ArmatureActuator"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
-
- if (target != NULL)
- target->UnregisterActuator(actuator);
-
- target = gameobj;
-
- if (target)
- target->RegisterActuator(actuator);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *BL_ArmatureActuator::pyattr_get_constraint(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ArmatureActuator* actuator = static_cast<BL_ArmatureActuator*>(self);
- BL_ArmatureConstraint* constraint = actuator->m_constraint;
- if (!constraint)
- Py_RETURN_NONE;
- else
- return constraint->GetProxy();
-}
-
-#endif // WITH_PYTHON
-
diff --git a/source/gameengine/Converter/BL_ArmatureActuator.h b/source/gameengine/Converter/BL_ArmatureActuator.h
deleted file mode 100644
index 3c455498508..00000000000
--- a/source/gameengine/Converter/BL_ArmatureActuator.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ArmatureActuator.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_ARMATUREACTUATOR_H__
-#define __BL_ARMATUREACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "BL_ArmatureConstraint.h"
-
-/**
- * This class is the conversion of the Pose channel constraint.
- * It makes a link between the pose constraint and the KX scene.
- * The main purpose is to give access to the constraint target
- * to link it to a game object.
- * It also allows to activate/deactivate constraints during the game.
- * Later it will also be possible to create constraint on the fly
- */
-
-class BL_ArmatureActuator : public SCA_IActuator
-{
- Py_Header
-public:
- BL_ArmatureActuator(SCA_IObject* gameobj,
- int type,
- const char *posechannel,
- const char *constraintname,
- KX_GameObject* targetobj,
- KX_GameObject* subtargetobj,
- float weight,
- float influence);
-
- virtual ~BL_ArmatureActuator();
-
- virtual CValue* GetReplica() {
- BL_ArmatureActuator* replica = new BL_ArmatureActuator(*this);
- replica->ProcessReplica();
- return replica;
- };
- virtual void ProcessReplica();
- virtual bool UnlinkObject(SCA_IObject* clientobj);
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
- virtual bool Update(double curtime, bool frame);
- virtual void ReParent(SCA_IObject* parent);
-
-#ifdef WITH_PYTHON
-
- /* These are used to get and set m_target */
- static PyObject *pyattr_get_constraint(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
-#endif /* WITH_PYTHON */
-
-private:
- // identify the constraint that this actuator controls
- void FindConstraint();
-
- BL_ArmatureConstraint* m_constraint;
- KX_GameObject* m_gametarget;
- KX_GameObject* m_gamesubtarget;
- STR_String m_posechannel;
- STR_String m_constraintname;
- float m_weight;
- float m_influence;
- int m_type;
-};
-
-#endif /* __BL_ARMATUREACTUATOR_H__ */
diff --git a/source/gameengine/Converter/BL_ArmatureChannel.cpp b/source/gameengine/Converter/BL_ArmatureChannel.cpp
deleted file mode 100644
index 711c96e32c1..00000000000
--- a/source/gameengine/Converter/BL_ArmatureChannel.cpp
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ArmatureChannel.cpp
- * \ingroup bgeconv
- */
-
-
-#include "DNA_armature_types.h"
-#include "BL_ArmatureChannel.h"
-#include "BL_ArmatureObject.h"
-#include "BL_ArmatureConstraint.h"
-#include "BLI_math.h"
-#include "BLI_string.h"
-#include <stddef.h>
-
-#ifdef WITH_PYTHON
-
-PyTypeObject BL_ArmatureChannel::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ArmatureChannel",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyObject *BL_ArmatureChannel::py_repr(void)
-{
- return PyUnicode_FromString(m_posechannel->name);
-}
-
-PyObject *BL_ArmatureChannel::GetProxy()
-{
- return GetProxyPlus_Ext(this, &Type, m_posechannel);
-}
-
-PyObject *BL_ArmatureChannel::NewProxy(bool py_owns)
-{
- return NewProxyPlus_Ext(this, &Type, m_posechannel, py_owns);
-}
-
-#endif // WITH_PYTHON
-
-BL_ArmatureChannel::BL_ArmatureChannel(
- BL_ArmatureObject *armature,
- bPoseChannel *posechannel)
- : PyObjectPlus(), m_posechannel(posechannel), m_armature(armature)
-{
-}
-
-BL_ArmatureChannel::~BL_ArmatureChannel()
-{
-}
-
-#ifdef WITH_PYTHON
-
-// PYTHON
-
-PyMethodDef BL_ArmatureChannel::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-// order of definition of attributes, must match Attributes[] array
-#define BCA_BONE 0
-#define BCA_PARENT 1
-
-PyAttributeDef BL_ArmatureChannel::Attributes[] = {
- // Keep these attributes in order of BCA_ defines!!! used by py_attr_getattr and py_attr_setattr
- KX_PYATTRIBUTE_RO_FUNCTION("bone",BL_ArmatureChannel,py_attr_getattr),
- KX_PYATTRIBUTE_RO_FUNCTION("parent",BL_ArmatureChannel,py_attr_getattr),
-
- { NULL } //Sentinel
-};
-
-/* attributes directly taken from bPoseChannel */
-PyAttributeDef BL_ArmatureChannel::AttributesPtr[] = {
- KX_PYATTRIBUTE_CHAR_RO("name",bPoseChannel,name),
- KX_PYATTRIBUTE_FLAG_RO("has_ik",bPoseChannel,flag, POSE_CHAIN),
- KX_PYATTRIBUTE_FLAG_NEGATIVE_RO("ik_dof_x",bPoseChannel,ikflag, BONE_IK_NO_XDOF),
- KX_PYATTRIBUTE_FLAG_NEGATIVE_RO("ik_dof_y",bPoseChannel,ikflag, BONE_IK_NO_YDOF),
- KX_PYATTRIBUTE_FLAG_NEGATIVE_RO("ik_dof_z",bPoseChannel,ikflag, BONE_IK_NO_ZDOF),
- KX_PYATTRIBUTE_FLAG_RO("ik_limit_x",bPoseChannel,ikflag, BONE_IK_XLIMIT),
- KX_PYATTRIBUTE_FLAG_RO("ik_limit_y",bPoseChannel,ikflag, BONE_IK_YLIMIT),
- KX_PYATTRIBUTE_FLAG_RO("ik_limit_z",bPoseChannel,ikflag, BONE_IK_ZLIMIT),
- KX_PYATTRIBUTE_FLAG_RO("ik_rot_control",bPoseChannel,ikflag, BONE_IK_ROTCTL),
- KX_PYATTRIBUTE_FLAG_RO("ik_lin_control",bPoseChannel,ikflag, BONE_IK_LINCTL),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RW("location",-FLT_MAX,FLT_MAX,bPoseChannel,loc,3),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RW("scale",-FLT_MAX,FLT_MAX,bPoseChannel,size,3),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RW("rotation_quaternion",-1.0f,1.0f,bPoseChannel,quat,4),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RW("rotation_euler",-10.f,10.f,bPoseChannel,eul,3),
- KX_PYATTRIBUTE_SHORT_RW("rotation_mode",ROT_MODE_MIN,ROT_MODE_MAX,false,bPoseChannel,rotmode),
- KX_PYATTRIBUTE_FLOAT_MATRIX_RO("channel_matrix",bPoseChannel,chan_mat,4),
- KX_PYATTRIBUTE_FLOAT_MATRIX_RO("pose_matrix",bPoseChannel,pose_mat,4),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("pose_head",bPoseChannel,pose_head,3),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("pose_tail",bPoseChannel,pose_tail,3),
- KX_PYATTRIBUTE_FLOAT_RO("ik_min_x",bPoseChannel,limitmin[0]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_max_x",bPoseChannel,limitmax[0]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_min_y",bPoseChannel,limitmin[1]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_max_y",bPoseChannel,limitmax[1]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_min_z",bPoseChannel,limitmin[2]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_max_z",bPoseChannel,limitmax[2]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_stiffness_x",bPoseChannel,stiffness[0]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_stiffness_y",bPoseChannel,stiffness[1]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_stiffness_z",bPoseChannel,stiffness[2]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_stretch",bPoseChannel,ikstretch),
- KX_PYATTRIBUTE_FLOAT_RW("ik_rot_weight",0,1.0f,bPoseChannel,ikrotweight),
- KX_PYATTRIBUTE_FLOAT_RW("ik_lin_weight",0,1.0f,bPoseChannel,iklinweight),
- KX_PYATTRIBUTE_RW_FUNCTION("joint_rotation",BL_ArmatureChannel,py_attr_get_joint_rotation,py_attr_set_joint_rotation),
- { NULL } //Sentinel
-};
-
-PyObject *BL_ArmatureChannel::py_attr_getattr(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ArmatureChannel* self = static_cast<BL_ArmatureChannel*>(self_v);
- bPoseChannel* channel = self->m_posechannel;
- int attr_order = attrdef-Attributes;
-
- if (!channel) {
- PyErr_SetString(PyExc_AttributeError, "channel is NULL");
- return NULL;
- }
-
- switch (attr_order) {
- case BCA_BONE:
- // bones are standalone proxy
- return NewProxyPlus_Ext(NULL,&BL_ArmatureBone::Type,channel->bone,false);
- case BCA_PARENT:
- {
- BL_ArmatureChannel* parent = self->m_armature->GetChannel(channel->parent);
- if (parent)
- return parent->GetProxy();
- else
- Py_RETURN_NONE;
- }
- }
- PyErr_SetString(PyExc_AttributeError, "channel unknown attribute");
- return NULL;
-}
-
-int BL_ArmatureChannel::py_attr_setattr(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ArmatureChannel* self = static_cast<BL_ArmatureChannel*>(self_v);
- bPoseChannel* channel = self->m_posechannel;
- int attr_order = attrdef-Attributes;
-
-// int ival;
-// double dval;
-// char* sval;
-// KX_GameObject *oval;
-
- if (!channel) {
- PyErr_SetString(PyExc_AttributeError, "channel is NULL");
- return PY_SET_ATTR_FAIL;
- }
-
- switch (attr_order) {
- default:
- break;
- }
-
- PyErr_SetString(PyExc_AttributeError, "channel unknown attribute");
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *BL_ArmatureChannel::py_attr_get_joint_rotation(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- bPoseChannel* pchan = static_cast<bPoseChannel*>(self_v);
- // decompose the pose matrix in euler rotation
- float rest_mat[3][3];
- float pose_mat[3][3];
- float joint_mat[3][3];
- float joints[3];
- float norm;
- double sa, ca;
- // get rotation in armature space
- copy_m3_m4(pose_mat, pchan->pose_mat);
- normalize_m3(pose_mat);
- if (pchan->parent) {
- // bone has a parent, compute the rest pose of the bone taking actual pose of parent
- mul_m3_m3m4(rest_mat, pchan->parent->pose_mat, pchan->bone->bone_mat);
- normalize_m3(rest_mat);
- } else {
- // otherwise, the bone matrix in armature space is the rest pose
- copy_m3_m4(rest_mat, pchan->bone->arm_mat);
- }
- // remove the rest pose to get the joint movement
- transpose_m3(rest_mat);
- mul_m3_m3m3(joint_mat, rest_mat, pose_mat);
- joints[0] = joints[1] = joints[2] = 0.f;
- // returns a 3 element list that gives corresponding joint
- int flag = 0;
- if (!(pchan->ikflag & BONE_IK_NO_XDOF))
- flag |= 1;
- if (!(pchan->ikflag & BONE_IK_NO_YDOF))
- flag |= 2;
- if (!(pchan->ikflag & BONE_IK_NO_ZDOF))
- flag |= 4;
- switch (flag) {
- case 0: // fixed joint
- break;
- case 1: // X only
- mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat);
- joints[1] = joints[2] = 0.f;
- break;
- case 2: // Y only
- mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat);
- joints[0] = joints[2] = 0.f;
- break;
- case 3: // X+Y
- mat3_to_eulO( joints, EULER_ORDER_ZYX,joint_mat);
- joints[2] = 0.f;
- break;
- case 4: // Z only
- mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat);
- joints[0] = joints[1] = 0.f;
- break;
- case 5: // X+Z
- // decompose this as an equivalent rotation vector in X/Z plane
- joints[0] = joint_mat[1][2];
- joints[2] = -joint_mat[1][0];
- norm = normalize_v3(joints);
- if (norm < FLT_EPSILON) {
- norm = (joint_mat[1][1] < 0.0f) ? (float)M_PI : 0.0f;
- } else {
- norm = acos(joint_mat[1][1]);
- }
- mul_v3_fl(joints, norm);
- break;
- case 6: // Y+Z
- mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat);
- joints[0] = 0.f;
- break;
- case 7: // X+Y+Z
- // equivalent axis
- joints[0] = (joint_mat[1][2]-joint_mat[2][1])*0.5f;
- joints[1] = (joint_mat[2][0]-joint_mat[0][2])*0.5f;
- joints[2] = (joint_mat[0][1]-joint_mat[1][0])*0.5f;
- sa = len_v3(joints);
- ca = (joint_mat[0][0]+joint_mat[1][1]+joint_mat[1][1]-1.0f)*0.5f;
- if (sa > (double)FLT_EPSILON) {
- norm = atan2(sa,ca)/sa;
- } else {
- if (ca < 0.0) {
- norm = M_PI;
- mul_v3_fl(joints,0.f);
- if (joint_mat[0][0] > 0.f) {
- joints[0] = 1.0f;
- } else if (joint_mat[1][1] > 0.f) {
- joints[1] = 1.0f;
- } else {
- joints[2] = 1.0f;
- }
- } else {
- norm = 0.0;
- }
- }
- mul_v3_fl(joints,norm);
- break;
- }
- return Vector_CreatePyObject(joints, 3, NULL);
-}
-
-int BL_ArmatureChannel::py_attr_set_joint_rotation(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ArmatureChannel* self = static_cast<BL_ArmatureChannel*>(self_v);
- bPoseChannel* pchan = self->m_posechannel;
- PyObject *item;
- float joints[3];
- float quat[4];
-
- if (!PySequence_Check(value) || PySequence_Size(value) != 3) {
- PyErr_SetString(PyExc_AttributeError, "expected a sequence of 3 floats");
- return PY_SET_ATTR_FAIL;
- }
- for (int i=0; i<3; i++) {
- item = PySequence_GetItem(value, i); /* new ref */
- joints[i] = PyFloat_AsDouble(item);
- Py_DECREF(item);
- if (joints[i] == -1.0f && PyErr_Occurred()) {
- PyErr_SetString(PyExc_AttributeError, "expected a sequence of 3 floats");
- return PY_SET_ATTR_FAIL;
- }
- }
-
- int flag = 0;
- if (!(pchan->ikflag & BONE_IK_NO_XDOF))
- flag |= 1;
- if (!(pchan->ikflag & BONE_IK_NO_YDOF))
- flag |= 2;
- if (!(pchan->ikflag & BONE_IK_NO_ZDOF))
- flag |= 4;
- unit_qt(quat);
- switch (flag) {
- case 0: // fixed joint
- break;
- case 1: // X only
- joints[1] = joints[2] = 0.f;
- eulO_to_quat( quat,joints, EULER_ORDER_XYZ);
- break;
- case 2: // Y only
- joints[0] = joints[2] = 0.f;
- eulO_to_quat( quat,joints, EULER_ORDER_XYZ);
- break;
- case 3: // X+Y
- joints[2] = 0.f;
- eulO_to_quat( quat,joints, EULER_ORDER_ZYX);
- break;
- case 4: // Z only
- joints[0] = joints[1] = 0.f;
- eulO_to_quat( quat,joints, EULER_ORDER_XYZ);
- break;
- case 5: // X+Z
- // X and Z are components of an equivalent rotation axis
- joints[1] = 0;
- axis_angle_to_quat( quat,joints, len_v3(joints));
- break;
- case 6: // Y+Z
- joints[0] = 0.f;
- eulO_to_quat( quat,joints, EULER_ORDER_XYZ);
- break;
- case 7: // X+Y+Z
- // equivalent axis
- axis_angle_to_quat( quat,joints, len_v3(joints));
- break;
- }
- if (pchan->rotmode > 0) {
- quat_to_eulO( joints, pchan->rotmode,quat);
- copy_v3_v3(pchan->eul, joints);
- } else
- copy_qt_qt(pchan->quat, quat);
- return PY_SET_ATTR_SUCCESS;
-}
-
-// *************************
-// BL_ArmatureBone
-//
-// Access to Bone structure
-PyTypeObject BL_ArmatureBone::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ArmatureBone",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_bone_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-// not used since this class is never instantiated
-PyObject *BL_ArmatureBone::GetProxy()
-{
- return NULL;
-}
-PyObject *BL_ArmatureBone::NewProxy(bool py_owns)
-{
- return NULL;
-}
-
-PyObject *BL_ArmatureBone::py_bone_repr(PyObject *self)
-{
- Bone* bone = static_cast<Bone*>BGE_PROXY_PTR(self);
- return PyUnicode_FromString(bone->name);
-}
-
-PyMethodDef BL_ArmatureBone::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-/* no attributes on C++ class since it is never instantiated */
-PyAttributeDef BL_ArmatureBone::Attributes[] = {
- { NULL } //Sentinel
-};
-
-// attributes that work on proxy ptr (points to a Bone structure)
-PyAttributeDef BL_ArmatureBone::AttributesPtr[] = {
- KX_PYATTRIBUTE_CHAR_RO("name",Bone,name),
- KX_PYATTRIBUTE_FLAG_RO("connected",Bone,flag, BONE_CONNECTED),
- KX_PYATTRIBUTE_FLAG_RO("hinge",Bone,flag, BONE_HINGE),
- KX_PYATTRIBUTE_FLAG_NEGATIVE_RO("inherit_scale",Bone,flag, BONE_NO_SCALE),
- KX_PYATTRIBUTE_SHORT_RO("bbone_segments",Bone,segments),
- KX_PYATTRIBUTE_FLOAT_RO("roll",Bone,roll),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("head",Bone,head,3),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("tail",Bone,tail,3),
- KX_PYATTRIBUTE_FLOAT_RO("length",Bone,length),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("arm_head",Bone,arm_head,3),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("arm_tail",Bone,arm_tail,3),
- KX_PYATTRIBUTE_FLOAT_MATRIX_RO("arm_mat",Bone,arm_mat,4),
- KX_PYATTRIBUTE_FLOAT_MATRIX_RO("bone_mat",Bone,bone_mat,3),
- KX_PYATTRIBUTE_RO_FUNCTION("parent",BL_ArmatureBone,py_bone_get_parent),
- KX_PYATTRIBUTE_RO_FUNCTION("children",BL_ArmatureBone,py_bone_get_children),
- { NULL } //Sentinel
-};
-
-PyObject *BL_ArmatureBone::py_bone_get_parent(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- Bone* bone = reinterpret_cast<Bone*>(self);
- if (bone->parent) {
- // create a proxy unconnected to any GE object
- return NewProxyPlus_Ext(NULL,&Type,bone->parent,false);
- }
- Py_RETURN_NONE;
-}
-
-PyObject *BL_ArmatureBone::py_bone_get_children(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- Bone* bone = reinterpret_cast<Bone*>(self);
- Bone* child;
- int count = 0;
- for (child = (Bone *)bone->childbase.first; child; child = child->next)
- count++;
-
- PyObject *childrenlist = PyList_New(count);
-
- for (count = 0, child = (Bone *)bone->childbase.first; child; child = child->next, ++count)
- PyList_SET_ITEM(childrenlist,count,NewProxyPlus_Ext(NULL,&Type,child,false));
-
- return childrenlist;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/BL_ArmatureChannel.h b/source/gameengine/Converter/BL_ArmatureChannel.h
deleted file mode 100644
index 8e6bc94c488..00000000000
--- a/source/gameengine/Converter/BL_ArmatureChannel.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ArmatureChannel.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_ARMATURECHANNEL_H__
-#define __BL_ARMATURECHANNEL_H__
-
-#include "DNA_action_types.h"
-#include "CTR_HashedPtr.h"
-#include "CTR_Map.h"
-#include "EXP_PyObjectPlus.h"
-
-class SCA_IObject;
-class KX_GameObject;
-class BL_ArmatureObject;
-struct bConstraint;
-struct bPoseChannel;
-struct Object;
-struct bPose;
-
-class BL_ArmatureChannel : public PyObjectPlus
-{
- // use Py_HeaderPtr since we use generic pointer in proxy
- Py_HeaderPtr;
-
-private:
- friend class BL_ArmatureObject;
- struct bPoseChannel* m_posechannel;
- BL_ArmatureObject* m_armature;
-
-public:
- BL_ArmatureChannel(class BL_ArmatureObject *armature,
- struct bPoseChannel *posechannel);
- virtual ~BL_ArmatureChannel();
-
- inline const char *GetName()
- {
- return m_posechannel->name;
- }
-
-#ifdef WITH_PYTHON
- // Python access
- virtual PyObject *py_repr(void);
-
- static PyObject *py_attr_getattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int py_attr_setattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *py_attr_get_joint_rotation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int py_attr_set_joint_rotation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif /* WITH_PYTHON */
-};
-
-/* this is a factory class to access bBone data field in the GE.
- * It's not supposed to be instantiated, we only need it for the Attributes and Method array.
- * The actual proxy object will be manually created using NewProxyPtr */
-class BL_ArmatureBone : public PyObjectPlus
-{
- // use Py_HeaderPtr since we use generic pointer in proxy
- Py_HeaderPtr;
-private:
- // make constructor private to make sure no one tries to instantiate this class
- BL_ArmatureBone() {}
- virtual ~BL_ArmatureBone() {}
-
-public:
-
-#ifdef WITH_PYTHON
- static PyObject *py_bone_repr(PyObject *self);
- static PyObject *py_bone_get_parent(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *py_bone_get_children(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
-#endif
-
-};
-
-#endif /* __BL_ARMATURECHANNEL_H__ */
diff --git a/source/gameengine/Converter/BL_ArmatureConstraint.cpp b/source/gameengine/Converter/BL_ArmatureConstraint.cpp
deleted file mode 100644
index 224ae259fa2..00000000000
--- a/source/gameengine/Converter/BL_ArmatureConstraint.cpp
+++ /dev/null
@@ -1,456 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ArmatureConstraint.cpp
- * \ingroup bgeconv
- */
-
-
-#include "DNA_constraint_types.h"
-#include "DNA_action_types.h"
-#include "BL_ArmatureConstraint.h"
-#include "BL_ArmatureObject.h"
-#include "BLI_math.h"
-#include "BLI_string.h"
-#include "KX_PythonInit.h"
-
-#ifdef WITH_PYTHON
-
-PyTypeObject BL_ArmatureConstraint::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ArmatureConstraint",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyObject *BL_ArmatureConstraint::py_repr(void)
-{
- return PyUnicode_FromString(m_name);
-}
-
-#endif // WITH_PYTHON
-
-BL_ArmatureConstraint::BL_ArmatureConstraint(
- BL_ArmatureObject *armature,
- bPoseChannel *posechannel,
- bConstraint *constraint,
- KX_GameObject* target,
- KX_GameObject* subtarget)
- : PyObjectPlus(), m_constraint(constraint), m_posechannel(posechannel), m_armature(armature)
-{
- m_target = target;
- m_blendtarget = (target) ? target->GetBlenderObject() : NULL;
- m_subtarget = subtarget;
- m_blendsubtarget = (subtarget) ? subtarget->GetBlenderObject() : NULL;
- m_pose = m_subpose = NULL;
- if (m_blendtarget) {
- copy_m4_m4(m_blendmat, m_blendtarget->obmat);
- if (m_blendtarget->type == OB_ARMATURE)
- m_pose = m_blendtarget->pose;
- }
- if (m_blendsubtarget) {
- copy_m4_m4(m_blendsubmat, m_blendsubtarget->obmat);
- if (m_blendsubtarget->type == OB_ARMATURE)
- m_subpose = m_blendsubtarget->pose;
- }
- if (m_target)
- m_target->RegisterObject(m_armature);
- if (m_subtarget)
- m_subtarget->RegisterObject(m_armature);
- BLI_snprintf(m_name, sizeof(m_name), "%s:%s", m_posechannel->name, m_constraint->name);
-}
-
-BL_ArmatureConstraint::~BL_ArmatureConstraint()
-{
- if (m_target)
- m_target->UnregisterObject(m_armature);
- if (m_subtarget)
- m_subtarget->UnregisterObject(m_armature);
-}
-
-BL_ArmatureConstraint* BL_ArmatureConstraint::GetReplica() const
-{
- BL_ArmatureConstraint* replica = new BL_ArmatureConstraint(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-void BL_ArmatureConstraint::ReParent(BL_ArmatureObject* armature)
-{
- m_armature = armature;
- if (m_target)
- m_target->RegisterObject(armature);
- if (m_subtarget)
- m_subtarget->RegisterObject(armature);
- // find the corresponding constraint in the new armature object
- if (m_constraint) {
- bPose* newpose = armature->GetOrigPose();
- char* constraint = m_constraint->name;
- char* posechannel = m_posechannel->name;
- bPoseChannel* pchan;
- bConstraint* pcon;
- m_constraint = NULL;
- m_posechannel = NULL;
- // and locate the constraint
- for (pchan = (bPoseChannel*)newpose->chanbase.first; pchan; pchan = (bPoseChannel*)pchan->next) {
- if (!strcmp(pchan->name, posechannel)) {
- // now locate the constraint
- for (pcon = (bConstraint *)pchan->constraints.first; pcon; pcon = (bConstraint *)pcon->next) {
- if (!strcmp(pcon->name, constraint)) {
- m_constraint = pcon;
- m_posechannel = pchan;
- break;
- }
- }
- break;
- }
- }
- }
-}
-
-void BL_ArmatureConstraint::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_target];
- if (h_obj) {
- m_target->UnregisterObject(m_armature);
- m_target = (KX_GameObject*)(*h_obj);
- m_target->RegisterObject(m_armature);
- }
- h_obj = (*obj_map)[m_subtarget];
- if (h_obj) {
- m_subtarget->UnregisterObject(m_armature);
- m_subtarget = (KX_GameObject*)(*h_obj);
- m_subtarget->RegisterObject(m_armature);
- }
-}
-
-bool BL_ArmatureConstraint::UnlinkObject(SCA_IObject* clientobj)
-{
- bool res=false;
- if (clientobj == m_target) {
- m_target = NULL;
- res = true;
- }
- if (clientobj == m_subtarget) {
- m_subtarget = NULL;
- res = true;
- }
- return res;
-}
-
-void BL_ArmatureConstraint::UpdateTarget()
-{
- if (m_constraint && !(m_constraint->flag&CONSTRAINT_OFF) && (!m_blendtarget || m_target)) {
- if (m_blendtarget) {
- // external target, must be updated
- m_target->UpdateBlenderObjectMatrix(m_blendtarget);
- if (m_pose && m_target->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
- // update the pose in case a bone is specified in the constraint target
- m_blendtarget->pose = ((BL_ArmatureObject*)m_target)->GetOrigPose();
- }
- if (m_blendsubtarget && m_subtarget) {
- m_subtarget->UpdateBlenderObjectMatrix(m_blendsubtarget);
- if (m_subpose && m_subtarget->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
- m_blendsubtarget->pose = ((BL_ArmatureObject*)m_subtarget)->GetOrigPose();
- }
- }
-}
-
-void BL_ArmatureConstraint::RestoreTarget()
-{
- if (m_constraint && !(m_constraint->flag&CONSTRAINT_OFF) && (!m_blendtarget || m_target)) {
- if (m_blendtarget) {
- copy_m4_m4(m_blendtarget->obmat, m_blendmat);
- if (m_pose)
- m_blendtarget->pose = m_pose;
- }
- if (m_blendsubtarget && m_subtarget) {
- copy_m4_m4(m_blendsubtarget->obmat, m_blendsubmat);
- if (m_subpose)
- m_blendsubtarget->pose = m_subpose;
- }
- }
-}
-
-bool BL_ArmatureConstraint::Match(const char* posechannel, const char* constraint)
-{
- return (!strcmp(m_posechannel->name, posechannel) && !strcmp(m_constraint->name, constraint));
-}
-
-void BL_ArmatureConstraint::SetTarget(KX_GameObject* target)
-{
- if (m_blendtarget) {
- if (target != m_target) {
- m_target->UnregisterObject(m_armature);
- m_target = target;
- if (m_target)
- m_target->RegisterObject(m_armature);
- }
- }
-
-}
-
-void BL_ArmatureConstraint::SetSubtarget(KX_GameObject* subtarget)
-{
- if (m_blendsubtarget) {
- if (subtarget != m_subtarget) {
- m_subtarget->UnregisterObject(m_armature);
- m_subtarget = subtarget;
- if (m_subtarget)
- m_subtarget->RegisterObject(m_armature);
- }
- }
-
-}
-
-#ifdef WITH_PYTHON
-
-// PYTHON
-
-PyMethodDef BL_ArmatureConstraint::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-// order of definition of attributes, must match Attributes[] array
-#define BCA_TYPE 0
-#define BCA_NAME 1
-#define BCA_ENFORCE 2
-#define BCA_HEADTAIL 3
-#define BCA_LINERROR 4
-#define BCA_ROTERROR 5
-#define BCA_TARGET 6
-#define BCA_SUBTARGET 7
-#define BCA_ACTIVE 8
-#define BCA_IKWEIGHT 9
-#define BCA_IKTYPE 10
-#define BCA_IKFLAG 11
-#define BCA_IKDIST 12
-#define BCA_IKMODE 13
-
-PyAttributeDef BL_ArmatureConstraint::Attributes[] = {
- // Keep these attributes in order of BCA_ defines!!! used by py_attr_getattr and py_attr_setattr
- KX_PYATTRIBUTE_RO_FUNCTION("type",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RO_FUNCTION("name",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RW_FUNCTION("enforce",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RW_FUNCTION("headtail",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RO_FUNCTION("lin_error",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RO_FUNCTION("rot_error",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RW_FUNCTION("target",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RW_FUNCTION("subtarget",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RW_FUNCTION("active",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RW_FUNCTION("ik_weight",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RO_FUNCTION("ik_type",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RO_FUNCTION("ik_flag",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RW_FUNCTION("ik_dist",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RW_FUNCTION("ik_mode",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
-
- { NULL } //Sentinel
-};
-
-
-PyObject *BL_ArmatureConstraint::py_attr_getattr(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ArmatureConstraint* self = static_cast<BL_ArmatureConstraint*>(self_v);
- bConstraint* constraint = self->m_constraint;
- bKinematicConstraint* ikconstraint = (constraint && constraint->type == CONSTRAINT_TYPE_KINEMATIC) ? (bKinematicConstraint*)constraint->data : NULL;
- int attr_order = attrdef-Attributes;
-
- if (!constraint) {
- PyErr_SetString(PyExc_AttributeError, "constraint is NULL");
- return NULL;
- }
-
- switch (attr_order) {
- case BCA_TYPE:
- return PyLong_FromLong(constraint->type);
- case BCA_NAME:
- return PyUnicode_FromString(constraint->name);
- case BCA_ENFORCE:
- return PyFloat_FromDouble(constraint->enforce);
- case BCA_HEADTAIL:
- return PyFloat_FromDouble(constraint->headtail);
- case BCA_LINERROR:
- return PyFloat_FromDouble(constraint->lin_error);
- case BCA_ROTERROR:
- return PyFloat_FromDouble(constraint->rot_error);
- case BCA_TARGET:
- if (!self->m_target)
- Py_RETURN_NONE;
- else
- return self->m_target->GetProxy();
- case BCA_SUBTARGET:
- if (!self->m_subtarget)
- Py_RETURN_NONE;
- else
- return self->m_subtarget->GetProxy();
- case BCA_ACTIVE:
- return PyBool_FromLong((constraint->flag & CONSTRAINT_OFF) == 0);
- case BCA_IKWEIGHT:
- case BCA_IKTYPE:
- case BCA_IKFLAG:
- case BCA_IKDIST:
- case BCA_IKMODE:
- if (!ikconstraint) {
- PyErr_SetString(PyExc_AttributeError, "constraint is not of IK type");
- return NULL;
- }
- switch (attr_order) {
- case BCA_IKWEIGHT:
- return PyFloat_FromDouble(ikconstraint->weight);
- case BCA_IKTYPE:
- return PyLong_FromLong(ikconstraint->type);
- case BCA_IKFLAG:
- return PyLong_FromLong(ikconstraint->flag);
- case BCA_IKDIST:
- return PyFloat_FromDouble(ikconstraint->dist);
- case BCA_IKMODE:
- return PyLong_FromLong(ikconstraint->mode);
- }
- // should not come here
- break;
- }
- PyErr_SetString(PyExc_AttributeError, "constraint unknown attribute");
- return NULL;
-}
-
-int BL_ArmatureConstraint::py_attr_setattr(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ArmatureConstraint* self = static_cast<BL_ArmatureConstraint*>(self_v);
- bConstraint* constraint = self->m_constraint;
- bKinematicConstraint* ikconstraint = (constraint && constraint->type == CONSTRAINT_TYPE_KINEMATIC) ? (bKinematicConstraint*)constraint->data : NULL;
- int attr_order = attrdef-Attributes;
- int ival;
- double dval;
-// char* sval;
- SCA_LogicManager *logicmgr = KX_GetActiveScene()->GetLogicManager();
- KX_GameObject *oval;
-
- if (!constraint) {
- PyErr_SetString(PyExc_AttributeError, "constraint is NULL");
- return PY_SET_ATTR_FAIL;
- }
-
- switch (attr_order) {
- case BCA_ENFORCE:
- dval = PyFloat_AsDouble(value);
- if (dval < 0.0 || dval > 1.0) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "constraint.enforce = float: BL_ArmatureConstraint, expected a float between 0 and 1");
- return PY_SET_ATTR_FAIL;
- }
- constraint->enforce = dval;
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_HEADTAIL:
- dval = PyFloat_AsDouble(value);
- if (dval < 0.0 || dval > 1.0) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "constraint.headtail = float: BL_ArmatureConstraint, expected a float between 0 and 1");
- return PY_SET_ATTR_FAIL;
- }
- constraint->headtail = dval;
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_TARGET:
- if (!ConvertPythonToGameObject(logicmgr, value, &oval, true, "constraint.target = value: BL_ArmatureConstraint"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
- self->SetTarget(oval);
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_SUBTARGET:
- if (!ConvertPythonToGameObject(logicmgr, value, &oval, true, "constraint.subtarget = value: BL_ArmatureConstraint"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
- self->SetSubtarget(oval);
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_ACTIVE:
- ival = PyObject_IsTrue( value );
- if (ival == -1) {
- PyErr_SetString(PyExc_AttributeError, "constraint.active = bool: BL_ArmatureConstraint, expected True or False");
- return PY_SET_ATTR_FAIL;
- }
- self->m_constraint->flag = (self->m_constraint->flag & ~CONSTRAINT_OFF) | ((ival)?0:CONSTRAINT_OFF);
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_IKWEIGHT:
- case BCA_IKDIST:
- case BCA_IKMODE:
- if (!ikconstraint) {
- PyErr_SetString(PyExc_AttributeError, "constraint is not of IK type");
- return PY_SET_ATTR_FAIL;
- }
- switch (attr_order) {
- case BCA_IKWEIGHT:
- dval = PyFloat_AsDouble(value);
- if (dval < 0.0 || dval > 1.0) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "constraint.weight = float: BL_ArmatureConstraint, expected a float between 0 and 1");
- return PY_SET_ATTR_FAIL;
- }
- ikconstraint->weight = dval;
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_IKDIST:
- dval = PyFloat_AsDouble(value);
- if (dval < 0.0) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "constraint.ik_dist = float: BL_ArmatureConstraint, expected a positive float");
- return PY_SET_ATTR_FAIL;
- }
- ikconstraint->dist = dval;
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_IKMODE:
- ival = PyLong_AsLong(value);
- if (ival < 0) {
- PyErr_SetString(PyExc_AttributeError, "constraint.ik_mode = integer: BL_ArmatureConstraint, expected a positive integer");
- return PY_SET_ATTR_FAIL;
- }
- ikconstraint->mode = ival;
- return PY_SET_ATTR_SUCCESS;
- }
- // should not come here
- break;
-
- }
-
- PyErr_SetString(PyExc_AttributeError, "constraint unknown attribute");
- return PY_SET_ATTR_FAIL;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/BL_ArmatureConstraint.h b/source/gameengine/Converter/BL_ArmatureConstraint.h
deleted file mode 100644
index a2c70f37902..00000000000
--- a/source/gameengine/Converter/BL_ArmatureConstraint.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ArmatureConstraint.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_ARMATURECONSTRAINT_H__
-#define __BL_ARMATURECONSTRAINT_H__
-
-#include "DNA_constraint_types.h"
-#include "CTR_HashedPtr.h"
-#include "CTR_Map.h"
-#include "EXP_PyObjectPlus.h"
-
-class SCA_IObject;
-class KX_GameObject;
-class BL_ArmatureObject;
-struct bConstraint;
-struct bPoseChannel;
-struct Object;
-struct bPose;
-
-/**
- * SG_DList : element of controlled constraint list
- * head = BL_ArmatureObject::m_controlledConstraints
- * SG_QList : not used
- */
-class BL_ArmatureConstraint : public PyObjectPlus
-{
- Py_Header
-
-private:
- struct bConstraint* m_constraint;
- struct bPoseChannel* m_posechannel;
- class BL_ArmatureObject* m_armature;
- char m_name[64];
- KX_GameObject* m_target;
- KX_GameObject* m_subtarget;
- struct Object* m_blendtarget;
- struct Object* m_blendsubtarget;
- float m_blendmat[4][4];
- float m_blendsubmat[4][4];
- struct bPose* m_pose;
- struct bPose* m_subpose;
-
-public:
- BL_ArmatureConstraint(class BL_ArmatureObject *armature,
- struct bPoseChannel *posechannel,
- struct bConstraint *constraint,
- KX_GameObject* target,
- KX_GameObject* subtarget);
- virtual ~BL_ArmatureConstraint();
-
- BL_ArmatureConstraint* GetReplica() const;
- void ReParent(BL_ArmatureObject* armature);
- void Relink(CTR_Map<CTR_HashedPtr, void*> *map);
- bool UnlinkObject(SCA_IObject* clientobj);
-
- void UpdateTarget();
- void RestoreTarget();
-
- bool Match(const char* posechannel, const char* constraint);
- const char* GetName() { return m_name; }
-
- void SetConstraintFlag(int flag)
- {
- if (m_constraint)
- m_constraint->flag |= flag;
- }
- void ClrConstraintFlag(int flag)
- {
- if (m_constraint)
- m_constraint->flag &= ~flag;
- }
- void SetWeight(float weight)
- {
- if (m_constraint && m_constraint->type == CONSTRAINT_TYPE_KINEMATIC && m_constraint->data) {
- bKinematicConstraint* con = (bKinematicConstraint*)m_constraint->data;
- con->weight = weight;
- }
- }
- void SetInfluence(float influence)
- {
- if (m_constraint)
- m_constraint->enforce = influence;
- }
- void SetTarget(KX_GameObject* target);
- void SetSubtarget(KX_GameObject* subtarget);
-
-#ifdef WITH_PYTHON
-
- // Python access
- virtual PyObject *py_repr(void);
-
- static PyObject *py_attr_getattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int py_attr_setattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif /* WITH_PYTHON */
-};
-
-#endif /* __BL_ARMATURECONSTRAINT_H__ */
diff --git a/source/gameengine/Converter/BL_ArmatureObject.cpp b/source/gameengine/Converter/BL_ArmatureObject.cpp
deleted file mode 100644
index d9ecfd1cbee..00000000000
--- a/source/gameengine/Converter/BL_ArmatureObject.cpp
+++ /dev/null
@@ -1,687 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ArmatureObject.cpp
- * \ingroup bgeconv
- */
-
-
-#include "BL_ArmatureObject.h"
-#include "BL_ActionActuator.h"
-#include "BL_Action.h"
-#include "KX_BlenderSceneConverter.h"
-#include "MEM_guardedalloc.h"
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-#include "BLI_ghash.h"
-#include "BIK_api.h"
-#include "BKE_action.h"
-#include "BKE_armature.h"
-#include "BKE_object.h"
-#include "BKE_library.h"
-#include "BKE_global.h"
-
-extern "C" {
-#include "BKE_animsys.h"
-}
-
-#include "BKE_constraint.h"
-#include "CTR_Map.h"
-#include "CTR_HashedPtr.h"
-#include "MEM_guardedalloc.h"
-#include "DNA_action_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_constraint_types.h"
-#include "RNA_access.h"
-#include "KX_PythonInit.h"
-#include "KX_KetsjiEngine.h"
-
-#include "EXP_ListWrapper.h"
-
-#include "MT_Matrix4x4.h"
-
-/**
- * Move here pose function for game engine so that we can mix with GE objects
- * Principle is as follow:
- * Use Blender structures so that BKE_pose_where_is can be used unchanged
- * Copy the constraint so that they can be enabled/disabled/added/removed at runtime
- * Don't copy the constraints for the pose used by the Action actuator, it does not need them.
- * Scan the constraint structures so that the KX equivalent of target objects are identified and
- * stored in separate list.
- * When it is about to evaluate the pose, set the KX object position in the obmat of the corresponding
- * Blender objects and restore after the evaluation.
- */
-static void game_copy_pose(bPose **dst, bPose *src, int copy_constraint)
-{
- bPose *out;
- bPoseChannel *pchan, *outpchan;
- GHash *ghash;
-
- /* the game engine copies the current armature pose and then swaps
- * the object pose pointer. this makes it possible to change poses
- * without affecting the original blender data. */
-
- if (!src) {
- *dst=NULL;
- return;
- }
- else if (*dst==src) {
- printf("game_copy_pose source and target are the same\n");
- *dst=NULL;
- return;
- }
-
- out= (bPose*)MEM_dupallocN(src);
- out->chanhash = NULL;
- out->agroups.first= out->agroups.last= NULL;
- out->ikdata = NULL;
- out->ikparam = MEM_dupallocN(src->ikparam);
- out->flag |= POSE_GAME_ENGINE;
- BLI_duplicatelist(&out->chanbase, &src->chanbase);
-
- /* remap pointers */
- ghash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "game_copy_pose gh");
-
- pchan= (bPoseChannel *)src->chanbase.first;
- outpchan= (bPoseChannel *)out->chanbase.first;
- for (; pchan; pchan=pchan->next, outpchan=outpchan->next)
- BLI_ghash_insert(ghash, pchan, outpchan);
-
- for (pchan = (bPoseChannel *)out->chanbase.first; pchan; pchan = pchan->next) {
- pchan->parent= (bPoseChannel *)BLI_ghash_lookup(ghash, pchan->parent);
- pchan->child= (bPoseChannel *)BLI_ghash_lookup(ghash, pchan->child);
-
- if (copy_constraint) {
- ListBase listb;
- // copy all constraint for backward compatibility
- // BKE_constraints_copy NULLs listb, no need to make extern for this operation.
- BKE_constraints_copy(&listb, &pchan->constraints, false);
- pchan->constraints= listb;
- }
- else {
- BLI_listbase_clear(&pchan->constraints);
- }
-
- if (pchan->custom) {
- id_us_plus(&pchan->custom->id);
- }
-
- // fails to link, props are not used in the BGE yet.
-#if 0
- if (pchan->prop)
- pchan->prop= IDP_CopyProperty(pchan->prop);
-#endif
- pchan->prop= NULL;
- }
-
- BLI_ghash_free(ghash, NULL, NULL);
- // set acceleration structure for channel lookup
- BKE_pose_channels_hash_make(out);
- *dst=out;
-}
-
-
-
-/* Only allowed for Poses with identical channels */
-static void game_blend_poses(bPose *dst, bPose *src, float srcweight, short mode)
-{
- bPoseChannel *dchan;
- const bPoseChannel *schan;
- bConstraint *dcon, *scon;
- float dstweight;
- int i;
-
- if (mode == BL_Action::ACT_BLEND_BLEND)
- {
- dstweight = 1.0f - srcweight;
- } else if (mode == BL_Action::ACT_BLEND_ADD)
- {
- dstweight = 1.0f;
- } else {
- dstweight = 1.0f;
- }
-
- schan= (bPoseChannel *)src->chanbase.first;
- for (dchan = (bPoseChannel *)dst->chanbase.first; dchan; dchan=(bPoseChannel *)dchan->next, schan= (bPoseChannel *)schan->next) {
- // always blend on all channels since we don't know which one has been set
- /* quat interpolation done separate */
- if (schan->rotmode == ROT_MODE_QUAT) {
- float dquat[4], squat[4];
-
- copy_qt_qt(dquat, dchan->quat);
- copy_qt_qt(squat, schan->quat);
- // Normalize quaternions so that interpolation/multiplication result is correct.
- normalize_qt(dquat);
- normalize_qt(squat);
-
- if (mode==BL_Action::ACT_BLEND_BLEND)
- interp_qt_qtqt(dchan->quat, dquat, squat, srcweight);
- else {
- mul_fac_qt_fl(squat, srcweight);
- mul_qt_qtqt(dchan->quat, dquat, squat);
- }
-
- normalize_qt(dchan->quat);
- }
-
- for (i=0; i<3; i++) {
- /* blending for loc and scale are pretty self-explanatory... */
- dchan->loc[i] = (dchan->loc[i]*dstweight) + (schan->loc[i]*srcweight);
- dchan->size[i] = 1.0f + ((dchan->size[i]-1.0f)*dstweight) + ((schan->size[i]-1.0f)*srcweight);
-
- /* euler-rotation interpolation done here instead... */
- // FIXME: are these results decent?
- if (schan->rotmode)
- dchan->eul[i] = (dchan->eul[i]*dstweight) + (schan->eul[i]*srcweight);
- }
- for (dcon= (bConstraint *)dchan->constraints.first, scon= (bConstraint *)schan->constraints.first;
- dcon && scon;
- dcon = dcon->next, scon = scon->next)
- {
- /* no 'add' option for constraint blending */
- dcon->enforce= dcon->enforce*(1.0f-srcweight) + scon->enforce*srcweight;
- }
- }
-
- /* this pose is now in src time */
- dst->ctime= src->ctime;
-}
-
-BL_ArmatureObject::BL_ArmatureObject(
- void* sgReplicationInfo,
- SG_Callbacks callbacks,
- Object *armature,
- Scene *scene,
- int vert_deform_type)
-
-: KX_GameObject(sgReplicationInfo,callbacks),
- m_controlledConstraints(),
- m_poseChannels(),
- m_scene(scene), // maybe remove later. needed for BKE_pose_where_is
- m_lastframe(0.0),
- m_timestep(0.040),
- m_vert_deform_type(vert_deform_type),
- m_constraintNumber(0),
- m_channelNumber(0),
- m_lastapplyframe(0.0)
-{
- m_origObjArma = armature; // Keep a copy of the original armature so we can fix drivers later
- m_objArma = BKE_object_copy(G.main, armature);
- m_objArma->data = BKE_armature_copy(G.main, (bArmature *)armature->data);
- // During object replication ob->data is increase, we decrease it now because we get a copy.
- id_us_min(&((bArmature *)m_origObjArma->data)->id);
- m_pose = m_objArma->pose;
- // need this to get iTaSC working ok in the BGE
- m_pose->flag |= POSE_GAME_ENGINE;
- memcpy(m_obmat, m_objArma->obmat, sizeof(m_obmat));
-
- // The side-effect of this method registers this object as "animatable" with the KX_Scene.
- GetActionManager();
-}
-
-BL_ArmatureObject::~BL_ArmatureObject()
-{
- BL_ArmatureConstraint* constraint;
- while ((constraint = m_controlledConstraints.Remove()) != NULL) {
- delete constraint;
- }
- BL_ArmatureChannel* channel;
- while ((channel = static_cast<BL_ArmatureChannel*>(m_poseChannels.Remove())) != NULL) {
- delete channel;
- }
-
- if (m_objArma) {
- BKE_libblock_free(G.main, m_objArma->data);
- BKE_libblock_free(G.main, m_objArma);
- }
-}
-
-
-void BL_ArmatureObject::LoadConstraints(KX_BlenderSceneConverter* converter)
-{
- // first delete any existing constraint (should not have any)
- while (!m_controlledConstraints.Empty()) {
- BL_ArmatureConstraint* constraint = m_controlledConstraints.Remove();
- delete constraint;
- }
- m_constraintNumber = 0;
-
- // list all the constraint and convert them to BL_ArmatureConstraint
- // get the persistent pose structure
- bPoseChannel* pchan;
- bConstraint* pcon;
- const bConstraintTypeInfo* cti;
- Object* blendtarget;
- KX_GameObject* gametarget;
- KX_GameObject* gamesubtarget;
-
- // and locate the constraint
- for (pchan = (bPoseChannel *)m_pose->chanbase.first; pchan; pchan = pchan->next) {
- for (pcon = (bConstraint *)pchan->constraints.first; pcon; pcon = pcon->next) {
- if (pcon->flag & CONSTRAINT_DISABLE)
- continue;
- // which constraint should we support?
- switch (pcon->type) {
- case CONSTRAINT_TYPE_TRACKTO:
- case CONSTRAINT_TYPE_DAMPTRACK:
- case CONSTRAINT_TYPE_KINEMATIC:
- case CONSTRAINT_TYPE_ROTLIKE:
- case CONSTRAINT_TYPE_LOCLIKE:
- case CONSTRAINT_TYPE_MINMAX:
- case CONSTRAINT_TYPE_SIZELIKE:
- case CONSTRAINT_TYPE_LOCKTRACK:
- case CONSTRAINT_TYPE_STRETCHTO:
- case CONSTRAINT_TYPE_CLAMPTO:
- case CONSTRAINT_TYPE_TRANSFORM:
- case CONSTRAINT_TYPE_DISTLIMIT:
- case CONSTRAINT_TYPE_TRANSLIKE:
- cti = BKE_constraint_typeinfo_get(pcon);
- gametarget = gamesubtarget = NULL;
- if (cti && cti->get_constraint_targets) {
- ListBase listb = { NULL, NULL };
- cti->get_constraint_targets(pcon, &listb);
- if (listb.first) {
- bConstraintTarget* target = (bConstraintTarget*)listb.first;
- if (target->tar && target->tar != m_objArma) {
- // only remember external objects, self target is handled automatically
- blendtarget = target->tar;
- gametarget = converter->FindGameObject(blendtarget);
- }
- if (target->next != NULL) {
- // secondary target
- target = target->next;
- if (target->tar && target->tar != m_objArma) {
- // only track external object
- blendtarget = target->tar;
- gamesubtarget = converter->FindGameObject(blendtarget);
- }
- }
- }
- if (cti->flush_constraint_targets)
- cti->flush_constraint_targets(pcon, &listb, 1);
- }
- BL_ArmatureConstraint* constraint = new BL_ArmatureConstraint(this, pchan, pcon, gametarget, gamesubtarget);
- m_controlledConstraints.AddBack(constraint);
- m_constraintNumber++;
- }
- }
- }
-
- // If we have constraints, make sure we get treated as an "animated" object
- if (m_constraintNumber > 0)
- GetActionManager();
-}
-
-BL_ArmatureConstraint* BL_ArmatureObject::GetConstraint(const char* posechannel, const char* constraintname)
-{
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- BL_ArmatureConstraint* constraint = *cit;
- if (constraint->Match(posechannel, constraintname))
- return constraint;
- }
- return NULL;
-}
-
-BL_ArmatureConstraint* BL_ArmatureObject::GetConstraint(const char* posechannelconstraint)
-{
- // performance: use hash string instead of plain string compare
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- BL_ArmatureConstraint* constraint = *cit;
- if (!strcmp(constraint->GetName(), posechannelconstraint))
- return constraint;
- }
- return NULL;
-}
-
-BL_ArmatureConstraint* BL_ArmatureObject::GetConstraint(int index)
-{
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end() && index; ++cit, --index);
- return (cit.end()) ? NULL : *cit;
-}
-
-/* this function is called to populate the m_poseChannels list */
-void BL_ArmatureObject::LoadChannels()
-{
- if (m_poseChannels.Empty()) {
- bPoseChannel* pchan;
- BL_ArmatureChannel* proxy;
-
- m_channelNumber = 0;
- for (pchan = (bPoseChannel *)m_pose->chanbase.first; pchan; pchan=(bPoseChannel *)pchan->next) {
- proxy = new BL_ArmatureChannel(this, pchan);
- m_poseChannels.AddBack(proxy);
- m_channelNumber++;
- }
- }
-}
-
-BL_ArmatureChannel* BL_ArmatureObject::GetChannel(bPoseChannel* pchan)
-{
- LoadChannels();
- SG_DList::iterator<BL_ArmatureChannel> cit(m_poseChannels);
- for (cit.begin(); !cit.end(); ++cit)
- {
- BL_ArmatureChannel* channel = *cit;
- if (channel->m_posechannel == pchan)
- return channel;
- }
- return NULL;
-}
-
-BL_ArmatureChannel* BL_ArmatureObject::GetChannel(const char* str)
-{
- LoadChannels();
- SG_DList::iterator<BL_ArmatureChannel> cit(m_poseChannels);
- for (cit.begin(); !cit.end(); ++cit)
- {
- BL_ArmatureChannel* channel = *cit;
- if (!strcmp(channel->m_posechannel->name, str))
- return channel;
- }
- return NULL;
-}
-
-BL_ArmatureChannel* BL_ArmatureObject::GetChannel(int index)
-{
- LoadChannels();
- if (index < 0 || index >= m_channelNumber)
- return NULL;
- SG_DList::iterator<BL_ArmatureChannel> cit(m_poseChannels);
- for (cit.begin(); !cit.end() && index; ++cit, --index);
- return (cit.end()) ? NULL : *cit;
-}
-
-CValue* BL_ArmatureObject::GetReplica()
-{
- BL_ArmatureObject* replica = new BL_ArmatureObject(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-void BL_ArmatureObject::ProcessReplica()
-{
- KX_GameObject::ProcessReplica();
-
- bArmature* tmp = (bArmature*)m_objArma->data;
- m_objArma = BKE_object_copy(G.main, m_objArma);
- m_objArma->data = BKE_armature_copy(G.main, tmp);
- m_pose = m_objArma->pose;
-}
-
-void BL_ArmatureObject::ReParentLogic()
-{
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- (*cit)->ReParent(this);
- }
- KX_GameObject::ReParentLogic();
-}
-
-void BL_ArmatureObject::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- (*cit)->Relink(obj_map);
- }
- KX_GameObject::Relink(obj_map);
-}
-
-bool BL_ArmatureObject::UnlinkObject(SCA_IObject* clientobj)
-{
- // clientobj is being deleted, make sure we don't hold any reference to it
- bool res = false;
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- res |= (*cit)->UnlinkObject(clientobj);
- }
- return res;
-}
-
-void BL_ArmatureObject::ApplyPose()
-{
- m_armpose = m_objArma->pose;
- m_objArma->pose = m_pose;
- // in the GE, we use ctime to store the timestep
- m_pose->ctime = (float)m_timestep;
- //m_scene->r.cfra++;
- if (m_lastapplyframe != m_lastframe) {
- // update the constraint if any, first put them all off so that only the active ones will be updated
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- (*cit)->UpdateTarget();
- }
- // update ourself
- UpdateBlenderObjectMatrix(m_objArma);
- BKE_pose_where_is(m_scene, m_objArma); // XXX
- // restore ourself
- memcpy(m_objArma->obmat, m_obmat, sizeof(m_obmat));
- // restore active targets
- for (cit.begin(); !cit.end(); ++cit) {
- (*cit)->RestoreTarget();
- }
- m_lastapplyframe = m_lastframe;
- }
-}
-
-void BL_ArmatureObject::RestorePose()
-{
- m_objArma->pose = m_armpose;
- m_armpose = NULL;
-}
-
-void BL_ArmatureObject::SetPose(bPose *pose)
-{
- extract_pose_from_pose(m_pose, pose);
- m_lastapplyframe = -1.0;
-}
-
-void BL_ArmatureObject::SetPoseByAction(bAction *action, float localtime)
-{
- Object *arm = GetArmatureObject();
-
- PointerRNA ptrrna;
- RNA_id_pointer_create(&arm->id, &ptrrna);
-
- animsys_evaluate_action(&ptrrna, action, NULL, localtime);
-}
-
-void BL_ArmatureObject::BlendInPose(bPose *blend_pose, float weight, short mode)
-{
- game_blend_poses(m_pose, blend_pose, weight, mode);
-}
-
-bool BL_ArmatureObject::UpdateTimestep(double curtime)
-{
- if (curtime != m_lastframe) {
- // compute the timestep for the underlying IK algorithm
- m_timestep = curtime-m_lastframe;
- m_lastframe= curtime;
- }
-
- return false;
-}
-
-void BL_ArmatureObject::GetPose(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 */
-
- if (!*pose) {
- /* probably not to good of an idea to
- * duplicate everything, but it clears up
- * a crash and memory leakage when
- * &BL_ActionActuator::m_pose is freed
- */
- game_copy_pose(pose, m_pose, 0);
- }
- else {
- if (*pose == m_pose)
- // no need to copy if the pointers are the same
- return;
-
- extract_pose_from_pose(*pose, m_pose);
- }
-}
-
-double BL_ArmatureObject::GetLastFrame()
-{
- return m_lastframe;
-}
-
-bool BL_ArmatureObject::GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix)
-{
- bPoseChannel *pchan;
-
- ApplyPose();
- pchan = BKE_pose_channel_find_name(m_objArma->pose, bone->name);
- if (pchan)
- matrix.setValue(&pchan->pose_mat[0][0]);
- RestorePose();
-
- return (pchan != NULL);
-}
-
-float BL_ArmatureObject::GetBoneLength(Bone* bone) const
-{
- return (float)(MT_Point3(bone->head) - MT_Point3(bone->tail)).length();
-}
-
-#ifdef WITH_PYTHON
-
-// PYTHON
-
-PyTypeObject BL_ArmatureObject::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ArmatureObject",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,
- &KX_GameObject::Sequence,
- &KX_GameObject::Mapping,
- 0,0,0,
- NULL,
- NULL,
- 0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &KX_GameObject::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef BL_ArmatureObject::Methods[] = {
- KX_PYMETHODTABLE_NOARGS(BL_ArmatureObject, update),
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef BL_ArmatureObject::Attributes[] = {
-
- KX_PYATTRIBUTE_RO_FUNCTION("constraints", BL_ArmatureObject, pyattr_get_constraints),
- KX_PYATTRIBUTE_RO_FUNCTION("channels", BL_ArmatureObject, pyattr_get_channels),
- {NULL} //Sentinel
-};
-
-static int bl_armature_object_get_constraints_size_cb(void *self_v)
-{
- return ((BL_ArmatureObject *)self_v)->GetConstraintNumber();
-}
-
-static PyObject *bl_armature_object_get_constraints_item_cb(void *self_v, int index)
-{
- return ((BL_ArmatureObject *)self_v)->GetConstraint(index)->GetProxy();
-}
-
-static const char *bl_armature_object_get_constraints_item_name_cb(void *self_v, int index)
-{
- return ((BL_ArmatureObject *)self_v)->GetConstraint(index)->GetName();
-}
-
-PyObject *BL_ArmatureObject::pyattr_get_constraints(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- return (new CListWrapper(self_v,
- ((BL_ArmatureObject *)self_v)->GetProxy(),
- NULL,
- bl_armature_object_get_constraints_size_cb,
- bl_armature_object_get_constraints_item_cb,
- bl_armature_object_get_constraints_item_name_cb,
- NULL))->NewProxy(true);
-}
-
-static int bl_armature_object_get_channels_size_cb(void *self_v)
-{
- return ((BL_ArmatureObject *)self_v)->GetChannelNumber();
-}
-
-static PyObject *bl_armature_object_get_channels_item_cb(void *self_v, int index)
-{
- return ((BL_ArmatureObject *)self_v)->GetChannel(index)->GetProxy();
-}
-
-static const char *bl_armature_object_get_channels_item_name_cb(void *self_v, int index)
-{
- return ((BL_ArmatureObject *)self_v)->GetChannel(index)->GetName();
-}
-
-PyObject *BL_ArmatureObject::pyattr_get_channels(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ArmatureObject *self = static_cast<BL_ArmatureObject *>(self_v);
- self->LoadChannels(); // make sure we have the channels
- return (new CListWrapper(self_v,
- self->GetProxy(),
- NULL,
- bl_armature_object_get_channels_size_cb,
- bl_armature_object_get_channels_item_cb,
- bl_armature_object_get_channels_item_name_cb,
- NULL))->NewProxy(true);
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(BL_ArmatureObject, update,
- "update()\n"
- "Make sure that the armature will be updated on next graphic frame.\n"
- "This is automatically done if a KX_ArmatureActuator with mode run is active\n"
- "or if an action is playing. This function is useful in other cases.\n")
-{
- UpdateTimestep(KX_GetActiveEngine()->GetFrameTime());
- Py_RETURN_NONE;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/BL_ArmatureObject.h b/source/gameengine/Converter/BL_ArmatureObject.h
deleted file mode 100644
index 65513aa579c..00000000000
--- a/source/gameengine/Converter/BL_ArmatureObject.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ArmatureObject.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_ARMATUREOBJECT_H__
-#define __BL_ARMATUREOBJECT_H__
-
-#include "KX_GameObject.h"
-#include "BL_ArmatureConstraint.h"
-#include "BL_ArmatureChannel.h"
-
-#include "SG_IObject.h"
-#include <vector>
-#include <algorithm>
-
-struct bArmature;
-struct Bone;
-struct bConstraint;
-class BL_ActionActuator;
-class BL_ArmatureActuator;
-class MT_Matrix4x4;
-struct Object;
-class KX_BlenderSceneConverter;
-
-class BL_ArmatureObject : public KX_GameObject
-{
- Py_Header
-public:
-
- double GetLastFrame ();
- virtual void ProcessReplica();
- virtual void ReParentLogic();
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
- virtual bool UnlinkObject(SCA_IObject* clientobj);
-
- BL_ArmatureObject(
- void* sgReplicationInfo,
- SG_Callbacks callbacks,
- Object *armature,
- Scene *scene,
- int vert_deform_type
- );
- virtual ~BL_ArmatureObject();
-
- virtual CValue* GetReplica();
- void GetPose(struct bPose **pose);
- void SetPose (struct bPose *pose);
- struct bPose *GetOrigPose() {return m_pose;} // never edit this, only for accessing names
-
- void ApplyPose();
- void SetPoseByAction(struct bAction* action, float localtime);
- void BlendInPose(struct bPose *blend_pose, float weight, short mode);
- void RestorePose();
-
- bool UpdateTimestep(double curtime);
-
- struct bArmature *GetArmature() { return (bArmature*)m_objArma->data; }
- const struct bArmature * GetArmature() const { return (bArmature*)m_objArma->data; }
- const struct Scene * GetScene() const { return m_scene; }
-
- Object* GetArmatureObject() {return m_objArma;}
- Object* GetOrigArmatureObject() {return m_origObjArma;}
-
- int GetVertDeformType() {return m_vert_deform_type;}
-
- // for constraint python API
- void LoadConstraints(KX_BlenderSceneConverter* converter);
- size_t GetConstraintNumber() const { return m_constraintNumber; }
- BL_ArmatureConstraint* GetConstraint(const char* posechannel, const char* constraint);
- BL_ArmatureConstraint* GetConstraint(const char* posechannelconstraint);
- BL_ArmatureConstraint* GetConstraint(int index);
- // for pose channel python API
- void LoadChannels();
- size_t GetChannelNumber() const { return m_channelNumber; }
- BL_ArmatureChannel* GetChannel(bPoseChannel* channel);
- BL_ArmatureChannel* GetChannel(const char* channel);
- BL_ArmatureChannel* GetChannel(int index);
-
- /// Retrieve the pose matrix for the specified bone.
- /// Returns true on success.
- 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;
-
- virtual int GetGameObjectType() { return OBJ_ARMATURE; }
-
-#ifdef WITH_PYTHON
-
- // PYTHON
- static PyObject *pyattr_get_constraints(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_channels(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- KX_PYMETHOD_DOC_NOARGS(BL_ArmatureObject, update);
-
-#endif /* WITH_PYTHON */
-
-protected:
- /* list element: BL_ArmatureConstraint. Use SG_DListHead to have automatic list replication */
- SG_DListHead<BL_ArmatureConstraint> m_controlledConstraints;
- /* list element: BL_ArmatureChannel. Use SG_DList to avoid list replication */
- SG_DList m_poseChannels;
- Object *m_objArma;
- Object *m_origObjArma;
- struct bPose *m_pose;
- struct bPose *m_armpose;
- struct Scene *m_scene; // need for BKE_pose_where_is
- double m_lastframe;
- double m_timestep; // delta since last pose evaluation.
- int m_vert_deform_type;
- size_t m_constraintNumber;
- size_t m_channelNumber;
- // store the original armature object matrix
- float m_obmat[4][4];
-
- double m_lastapplyframe;
-};
-
-#endif /* __BL_ARMATUREOBJECT_H__ */
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
deleted file mode 100644
index e31ad6b5cc4..00000000000
--- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp
+++ /dev/null
@@ -1,2467 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Convert blender data to ketsji
- */
-
-/** \file gameengine/Converter/BL_BlenderDataConversion.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-/* Since threaded object update we've disabled in-place
- * curve evaluation (in cases when applying curve modifier
- * with target curve non-evaluated yet).
- *
- * This requires game engine to take care of DAG and object
- * evaluation (currently it's designed to export only objects
- * it able to render).
- *
- * This workaround will make sure that curve_cache for curves
- * is up-to-date.
- */
-#define THREADED_DAG_WORKAROUND
-
-#include <math.h>
-#include <vector>
-#include <algorithm>
-
-#include "BL_BlenderDataConversion.h"
-
-#include "MT_Transform.h"
-#include "MT_MinMax.h"
-
-#include "PHY_Pro.h"
-#include "PHY_IPhysicsEnvironment.h"
-
-#include "RAS_MeshObject.h"
-#include "RAS_IRasterizer.h"
-#include "RAS_ILightObject.h"
-
-#include "KX_ConvertActuators.h"
-#include "KX_ConvertControllers.h"
-#include "KX_ConvertSensors.h"
-#include "SCA_LogicManager.h"
-#include "SCA_TimeEventManager.h"
-
-#include "KX_ClientObjectInfo.h"
-#include "KX_Scene.h"
-#include "KX_GameObject.h"
-#include "KX_Light.h"
-#include "KX_Camera.h"
-#include "KX_EmptyObject.h"
-#include "KX_FontObject.h"
-
-#include "RAS_TexMatrix.h"
-#include "RAS_ICanvas.h"
-#include "RAS_Polygon.h"
-#include "RAS_TexVert.h"
-#include "RAS_BucketManager.h"
-#include "RAS_IPolygonMaterial.h"
-#include "BL_Material.h"
-#include "KX_BlenderMaterial.h"
-#include "BL_Texture.h"
-
-#include "BKE_main.h"
-#include "BKE_global.h"
-#include "BKE_object.h"
-#include "BL_ModifierDeformer.h"
-#include "BL_ShapeDeformer.h"
-#include "BL_SkinDeformer.h"
-#include "BL_MeshDeformer.h"
-#include "KX_SoftBodyDeformer.h"
-#include "BLI_utildefines.h"
-#include "BLI_listbase.h"
-
-#include "KX_WorldInfo.h"
-
-#include "KX_KetsjiEngine.h"
-#include "KX_BlenderSceneConverter.h"
-
-/* This little block needed for linking to Blender... */
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-/* This list includes only data type definitions */
-#include "DNA_object_types.h"
-#include "DNA_material_types.h"
-#include "DNA_texture_types.h"
-#include "DNA_image_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_group_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_camera_types.h"
-#include "DNA_property_types.h"
-#include "DNA_text_types.h"
-#include "DNA_sensor_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_actuator_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_world_types.h"
-#include "DNA_sound_types.h"
-#include "DNA_key_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_action_types.h"
-#include "DNA_object_force_types.h"
-#include "DNA_constraint_types.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "BKE_key.h"
-#include "BKE_mesh.h"
-
-#include "BLI_math.h"
-
-extern "C" {
-#include "BKE_scene.h"
-#include "BKE_customdata.h"
-#include "BKE_cdderivedmesh.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_material.h" /* give_current_material */
-#include "BKE_image.h"
-#include "IMB_imbuf_types.h"
-#include "BKE_displist.h"
-
-extern Material defmaterial; /* material.c */
-}
-
-/* end of blender include block */
-
-#include "KX_BlenderInputDevice.h"
-#include "KX_ConvertProperties.h"
-
-#include "SG_Node.h"
-#include "SG_BBox.h"
-#include "SG_Tree.h"
-#include "KX_SG_NodeRelationships.h"
-#include "KX_SG_BoneParentNodeRelationship.h"
-
-#ifdef WITH_BULLET
-#include "CcdPhysicsEnvironment.h"
-#include "CcdGraphicController.h"
-#endif
-
-#include "KX_MotionState.h"
-
-#include "BL_ArmatureObject.h"
-#include "BL_DeformableGameObject.h"
-
-#include "KX_NavMeshObject.h"
-#include "KX_ObstacleSimulation.h"
-
-#include "BLI_threads.h"
-
-
-static bool default_light_mode = 0;
-
-static std::map<int, SCA_IInputDevice::KX_EnumInputs> create_translate_table()
-{
- std::map<int, SCA_IInputDevice::KX_EnumInputs> m;
-
- /* The reverse table. In order to not confuse ourselves, we */
- /* immediately convert all events that come in to KX codes. */
- m[LEFTMOUSE ] = SCA_IInputDevice::KX_LEFTMOUSE;
- m[MIDDLEMOUSE ] = SCA_IInputDevice::KX_MIDDLEMOUSE;
- m[RIGHTMOUSE ] = SCA_IInputDevice::KX_RIGHTMOUSE;
- m[WHEELUPMOUSE ] = SCA_IInputDevice::KX_WHEELUPMOUSE;
- m[WHEELDOWNMOUSE ] = SCA_IInputDevice::KX_WHEELDOWNMOUSE;
- m[MOUSEX ] = SCA_IInputDevice::KX_MOUSEX;
- m[MOUSEY ] = SCA_IInputDevice::KX_MOUSEY;
-
- // TIMERS
-
- m[TIMER0 ] = SCA_IInputDevice::KX_TIMER0;
- m[TIMER1 ] = SCA_IInputDevice::KX_TIMER1;
- m[TIMER2 ] = SCA_IInputDevice::KX_TIMER2;
-
- // SYSTEM
-
-#if 0
- /* **** XXX **** */
- m[KEYBD ] = SCA_IInputDevice::KX_KEYBD;
- m[RAWKEYBD ] = SCA_IInputDevice::KX_RAWKEYBD;
- m[REDRAW ] = SCA_IInputDevice::KX_REDRAW;
- m[INPUTCHANGE ] = SCA_IInputDevice::KX_INPUTCHANGE;
- m[QFULL ] = SCA_IInputDevice::KX_QFULL;
- m[WINFREEZE ] = SCA_IInputDevice::KX_WINFREEZE;
- m[WINTHAW ] = SCA_IInputDevice::KX_WINTHAW;
- m[WINCLOSE ] = SCA_IInputDevice::KX_WINCLOSE;
- m[WINQUIT ] = SCA_IInputDevice::KX_WINQUIT;
- m[Q_FIRSTTIME ] = SCA_IInputDevice::KX_Q_FIRSTTIME;
- /* **** XXX **** */
-#endif
-
- // standard keyboard
-
- m[AKEY ] = SCA_IInputDevice::KX_AKEY;
- m[BKEY ] = SCA_IInputDevice::KX_BKEY;
- m[CKEY ] = SCA_IInputDevice::KX_CKEY;
- m[DKEY ] = SCA_IInputDevice::KX_DKEY;
- m[EKEY ] = SCA_IInputDevice::KX_EKEY;
- m[FKEY ] = SCA_IInputDevice::KX_FKEY;
- m[GKEY ] = SCA_IInputDevice::KX_GKEY;
- m[HKEY ] = SCA_IInputDevice::KX_HKEY;
- m[IKEY ] = SCA_IInputDevice::KX_IKEY;
- m[JKEY ] = SCA_IInputDevice::KX_JKEY;
- m[KKEY ] = SCA_IInputDevice::KX_KKEY;
- m[LKEY ] = SCA_IInputDevice::KX_LKEY;
- m[MKEY ] = SCA_IInputDevice::KX_MKEY;
- m[NKEY ] = SCA_IInputDevice::KX_NKEY;
- m[OKEY ] = SCA_IInputDevice::KX_OKEY;
- m[PKEY ] = SCA_IInputDevice::KX_PKEY;
- m[QKEY ] = SCA_IInputDevice::KX_QKEY;
- m[RKEY ] = SCA_IInputDevice::KX_RKEY;
- m[SKEY ] = SCA_IInputDevice::KX_SKEY;
- m[TKEY ] = SCA_IInputDevice::KX_TKEY;
- m[UKEY ] = SCA_IInputDevice::KX_UKEY;
- m[VKEY ] = SCA_IInputDevice::KX_VKEY;
- m[WKEY ] = SCA_IInputDevice::KX_WKEY;
- m[XKEY ] = SCA_IInputDevice::KX_XKEY;
- m[YKEY ] = SCA_IInputDevice::KX_YKEY;
- m[ZKEY ] = SCA_IInputDevice::KX_ZKEY;
-
- m[ZEROKEY ] = SCA_IInputDevice::KX_ZEROKEY;
- m[ONEKEY ] = SCA_IInputDevice::KX_ONEKEY;
- m[TWOKEY ] = SCA_IInputDevice::KX_TWOKEY;
- m[THREEKEY ] = SCA_IInputDevice::KX_THREEKEY;
- m[FOURKEY ] = SCA_IInputDevice::KX_FOURKEY;
- m[FIVEKEY ] = SCA_IInputDevice::KX_FIVEKEY;
- m[SIXKEY ] = SCA_IInputDevice::KX_SIXKEY;
- m[SEVENKEY ] = SCA_IInputDevice::KX_SEVENKEY;
- m[EIGHTKEY ] = SCA_IInputDevice::KX_EIGHTKEY;
- m[NINEKEY ] = SCA_IInputDevice::KX_NINEKEY;
-
- m[CAPSLOCKKEY ] = SCA_IInputDevice::KX_CAPSLOCKKEY;
-
- m[LEFTCTRLKEY ] = SCA_IInputDevice::KX_LEFTCTRLKEY;
- m[LEFTALTKEY ] = SCA_IInputDevice::KX_LEFTALTKEY;
- m[RIGHTALTKEY ] = SCA_IInputDevice::KX_RIGHTALTKEY;
- m[RIGHTCTRLKEY ] = SCA_IInputDevice::KX_RIGHTCTRLKEY;
- m[RIGHTSHIFTKEY ] = SCA_IInputDevice::KX_RIGHTSHIFTKEY;
- m[LEFTSHIFTKEY ] = SCA_IInputDevice::KX_LEFTSHIFTKEY;
-
- m[ESCKEY ] = SCA_IInputDevice::KX_ESCKEY;
- m[TABKEY ] = SCA_IInputDevice::KX_TABKEY;
- m[RETKEY ] = SCA_IInputDevice::KX_RETKEY;
- m[SPACEKEY ] = SCA_IInputDevice::KX_SPACEKEY;
- m[LINEFEEDKEY ] = SCA_IInputDevice::KX_LINEFEEDKEY;
- m[BACKSPACEKEY ] = SCA_IInputDevice::KX_BACKSPACEKEY;
- m[DELKEY ] = SCA_IInputDevice::KX_DELKEY;
- m[SEMICOLONKEY ] = SCA_IInputDevice::KX_SEMICOLONKEY;
- m[PERIODKEY ] = SCA_IInputDevice::KX_PERIODKEY;
- m[COMMAKEY ] = SCA_IInputDevice::KX_COMMAKEY;
- m[QUOTEKEY ] = SCA_IInputDevice::KX_QUOTEKEY;
- m[ACCENTGRAVEKEY ] = SCA_IInputDevice::KX_ACCENTGRAVEKEY;
- m[MINUSKEY ] = SCA_IInputDevice::KX_MINUSKEY;
- m[PLUSKEY ] = SCA_IInputDevice::KX_PLUSKEY;
- m[SLASHKEY ] = SCA_IInputDevice::KX_SLASHKEY;
- m[BACKSLASHKEY ] = SCA_IInputDevice::KX_BACKSLASHKEY;
- m[EQUALKEY ] = SCA_IInputDevice::KX_EQUALKEY;
- m[LEFTBRACKETKEY ] = SCA_IInputDevice::KX_LEFTBRACKETKEY;
- m[RIGHTBRACKETKEY ] = SCA_IInputDevice::KX_RIGHTBRACKETKEY;
-
- m[LEFTARROWKEY ] = SCA_IInputDevice::KX_LEFTARROWKEY;
- m[DOWNARROWKEY ] = SCA_IInputDevice::KX_DOWNARROWKEY;
- m[RIGHTARROWKEY ] = SCA_IInputDevice::KX_RIGHTARROWKEY;
- m[UPARROWKEY ] = SCA_IInputDevice::KX_UPARROWKEY;
-
- m[PAD2 ] = SCA_IInputDevice::KX_PAD2;
- m[PAD4 ] = SCA_IInputDevice::KX_PAD4;
- m[PAD6 ] = SCA_IInputDevice::KX_PAD6;
- m[PAD8 ] = SCA_IInputDevice::KX_PAD8;
-
- m[PAD1 ] = SCA_IInputDevice::KX_PAD1;
- m[PAD3 ] = SCA_IInputDevice::KX_PAD3;
- m[PAD5 ] = SCA_IInputDevice::KX_PAD5;
- m[PAD7 ] = SCA_IInputDevice::KX_PAD7;
- m[PAD9 ] = SCA_IInputDevice::KX_PAD9;
-
- m[PADPERIOD ] = SCA_IInputDevice::KX_PADPERIOD;
- m[PADSLASHKEY ] = SCA_IInputDevice::KX_PADSLASHKEY;
- m[PADASTERKEY ] = SCA_IInputDevice::KX_PADASTERKEY;
-
- m[PAD0 ] = SCA_IInputDevice::KX_PAD0;
- m[PADMINUS ] = SCA_IInputDevice::KX_PADMINUS;
- m[PADENTER ] = SCA_IInputDevice::KX_PADENTER;
- m[PADPLUSKEY ] = SCA_IInputDevice::KX_PADPLUSKEY;
-
-
- m[F1KEY ] = SCA_IInputDevice::KX_F1KEY;
- m[F2KEY ] = SCA_IInputDevice::KX_F2KEY;
- m[F3KEY ] = SCA_IInputDevice::KX_F3KEY;
- m[F4KEY ] = SCA_IInputDevice::KX_F4KEY;
- m[F5KEY ] = SCA_IInputDevice::KX_F5KEY;
- m[F6KEY ] = SCA_IInputDevice::KX_F6KEY;
- m[F7KEY ] = SCA_IInputDevice::KX_F7KEY;
- m[F8KEY ] = SCA_IInputDevice::KX_F8KEY;
- m[F9KEY ] = SCA_IInputDevice::KX_F9KEY;
- m[F10KEY ] = SCA_IInputDevice::KX_F10KEY;
- m[F11KEY ] = SCA_IInputDevice::KX_F11KEY;
- m[F12KEY ] = SCA_IInputDevice::KX_F12KEY;
- m[F13KEY ] = SCA_IInputDevice::KX_F13KEY;
- m[F14KEY ] = SCA_IInputDevice::KX_F14KEY;
- m[F15KEY ] = SCA_IInputDevice::KX_F15KEY;
- m[F16KEY ] = SCA_IInputDevice::KX_F16KEY;
- m[F17KEY ] = SCA_IInputDevice::KX_F17KEY;
- m[F18KEY ] = SCA_IInputDevice::KX_F18KEY;
- m[F19KEY ] = SCA_IInputDevice::KX_F19KEY;
-
- m[OSKEY ] = SCA_IInputDevice::KX_OSKEY;
-
- m[PAUSEKEY ] = SCA_IInputDevice::KX_PAUSEKEY;
- m[INSERTKEY ] = SCA_IInputDevice::KX_INSERTKEY;
- m[HOMEKEY ] = SCA_IInputDevice::KX_HOMEKEY;
- m[PAGEUPKEY ] = SCA_IInputDevice::KX_PAGEUPKEY;
- m[PAGEDOWNKEY ] = SCA_IInputDevice::KX_PAGEDOWNKEY;
- m[ENDKEY ] = SCA_IInputDevice::KX_ENDKEY;
-
- return m;
-}
-
-static std::map<int, SCA_IInputDevice::KX_EnumInputs> gReverseKeyTranslateTable = create_translate_table();
-
-SCA_IInputDevice::KX_EnumInputs ConvertKeyCode(int key_code)
-{
- return gReverseKeyTranslateTable[key_code];
-}
-
-static unsigned int KX_rgbaint2uint_new(unsigned int icol)
-{
- union
- {
- unsigned int integer;
- unsigned char cp[4];
- } out_color, in_color;
-
- in_color.integer = icol;
- out_color.cp[0] = in_color.cp[3]; // red
- out_color.cp[1] = in_color.cp[2]; // green
- out_color.cp[2] = in_color.cp[1]; // blue
- out_color.cp[3] = in_color.cp[0]; // alpha
-
- return out_color.integer;
-}
-
-/* Now the real converting starts... */
-static unsigned int KX_Mcol2uint_new(MCol col)
-{
- /* color has to be converted without endian sensitivity. So no shifting! */
- union
- {
- MCol col;
- unsigned int integer;
- unsigned char cp[4];
- } out_color, in_color;
-
- in_color.col = col;
- out_color.cp[0] = in_color.cp[3]; // red
- out_color.cp[1] = in_color.cp[2]; // green
- out_color.cp[2] = in_color.cp[1]; // blue
- out_color.cp[3] = in_color.cp[0]; // alpha
-
- return out_color.integer;
-}
-
-static void SetDefaultLightMode(Scene* scene)
-{
- default_light_mode = false;
- Scene *sce_iter;
- Base *base;
-
- for (SETLOOPER(scene, sce_iter, base))
- {
- if (base->object->type == OB_LAMP)
- {
- default_light_mode = true;
- return;
- }
- }
-}
-
-
-static bool GetMaterialUseVColor(Material *ma, const bool glslmat)
-{
- if (ma) {
- /* glsl uses vertex colors, otherwise use material setting
- * defmaterial doesn't have VERTEXCOLP as default [#34505] */
- return (glslmat || ma == &defmaterial || (ma->mode & MA_VERTEXCOLP) != 0);
- }
- else {
- /* no material, use vertex colors */
- return true;
- }
-}
-
-// --
-static void GetRGB(
- const bool use_vcol,
- MFace* mface,
- MCol* mmcol,
- Material *mat,
- unsigned int c[4])
-{
- unsigned int color = 0xFFFFFFFFL;
- if (use_vcol == true) {
- if (mmcol) {
- c[0] = KX_Mcol2uint_new(mmcol[0]);
- c[1] = KX_Mcol2uint_new(mmcol[1]);
- c[2] = KX_Mcol2uint_new(mmcol[2]);
- if (mface->v4)
- c[3] = KX_Mcol2uint_new(mmcol[3]);
- }
- else { // backup white
- c[0] = KX_rgbaint2uint_new(color);
- c[1] = KX_rgbaint2uint_new(color);
- c[2] = KX_rgbaint2uint_new(color);
- if (mface->v4)
- c[3] = KX_rgbaint2uint_new( color );
- }
- }
- else {
- /* material rgba */
- if (mat) {
- union {
- unsigned char cp[4];
- unsigned int integer;
- } col_converter;
- col_converter.cp[3] = (unsigned char) (mat->r * 255.0f);
- col_converter.cp[2] = (unsigned char) (mat->g * 255.0f);
- col_converter.cp[1] = (unsigned char) (mat->b * 255.0f);
- col_converter.cp[0] = (unsigned char) (mat->alpha * 255.0f);
- color = col_converter.integer;
- }
- c[0] = KX_rgbaint2uint_new(color);
- c[1] = KX_rgbaint2uint_new(color);
- c[2] = KX_rgbaint2uint_new(color);
- if (mface->v4) {
- c[3] = KX_rgbaint2uint_new(color);
- }
- }
-
-#if 0 /* white, unused */
- {
- c[0] = KX_rgbaint2uint_new(color);
- c[1] = KX_rgbaint2uint_new(color);
- c[2] = KX_rgbaint2uint_new(color);
- if (mface->v4)
- c[3] = KX_rgbaint2uint_new(color);
- }
-#endif
-}
-
-typedef struct MTF_localLayer {
- MTFace *face;
- const char *name;
-} MTF_localLayer;
-
-static void GetUVs(BL_Material *material, MTF_localLayer *layers, MFace *mface, MTFace *tface, MT_Point2 uvs[4][MAXTEX])
-{
- int unit = 0;
- if (tface)
- {
-
- uvs[0][0].setValue(tface->uv[0]);
- uvs[1][0].setValue(tface->uv[1]);
- uvs[2][0].setValue(tface->uv[2]);
-
- if (mface->v4)
- uvs[3][0].setValue(tface->uv[3]);
- }
- else
- {
- uvs[0][0] = uvs[1][0] = uvs[2][0] = uvs[3][0] = MT_Point2(0.f, 0.f);
- }
-
- vector<STR_String> found_layers;
-
- for (int vind = 0; vind<MAXTEX; vind++)
- {
- BL_Mapping &map = material->mapping[vind];
-
- if (!(map.mapping & USEUV)) continue;
-
- if (std::find(found_layers.begin(), found_layers.end(), map.uvCoName) != found_layers.end())
- continue;
-
- //If no UVSet is specified, try grabbing one from the UV/Image editor
- if (map.uvCoName.IsEmpty() && tface)
- {
- uvs[0][unit].setValue(tface->uv[0]);
- uvs[1][unit].setValue(tface->uv[1]);
- uvs[2][unit].setValue(tface->uv[2]);
-
- if (mface->v4)
- uvs[3][unit].setValue(tface->uv[3]);
-
- ++unit;
- continue;
- }
-
-
- for (int lay=0; lay<MAX_MTFACE; lay++)
- {
- MTF_localLayer& layer = layers[lay];
- if (layer.face == 0) break;
-
- if (map.uvCoName.IsEmpty() || strcmp(map.uvCoName.ReadPtr(), layer.name)==0)
- {
- uvs[0][unit].setValue(layer.face->uv[0]);
- uvs[1][unit].setValue(layer.face->uv[1]);
- uvs[2][unit].setValue(layer.face->uv[2]);
-
- if (mface->v4)
- uvs[3][unit].setValue(layer.face->uv[3]);
- else
- uvs[3][unit].setValue(0.0f, 0.0f);
-
- ++unit;
- found_layers.push_back(map.uvCoName);
- break;
- }
- }
- }
-}
-
-// ------------------------------------
-static bool ConvertMaterial(
- BL_Material *material,
- Material *mat,
- MTFace *tface,
- const char *tfaceName,
- MFace *mface,
- MCol *mmcol,
- bool glslmat)
-{
- material->Initialize();
- int texalpha = 0;
- const bool validmat = (mat != NULL);
- const bool validface = (tface != NULL);
- const bool use_vcol = GetMaterialUseVColor(mat, glslmat);
-
- material->IdMode = DEFAULT_BLENDER;
- material->glslmat = (validmat) ? glslmat: false;
- material->materialindex = mface->mat_nr;
-
- // --------------------------------
- if (validmat) {
-
- // use lighting?
- material->ras_mode |= (mat->mode & MA_SHLESS) ? 0 : USE_LIGHT;
- material->ras_mode |= (mat->game.flag & GEMAT_BACKCULL) ? 0 : TWOSIDED;
-
- // cast shadows?
- material->ras_mode |= ((mat->mode2 & MA_CASTSHADOW) && (mat->mode & MA_SHADBUF)) ? CAST_SHADOW : 0;
-
- // only shadows?
- material->ras_mode |= (mat->mode & MA_ONLYCAST) ? ONLY_SHADOW : 0;
-
- MTex *mttmp = NULL;
- int valid_index = 0;
-
- /* In Multitexture use the face texture if and only if
- * it is set in the buttons
- * In GLSL is not working yet :/ 3.2011 */
- bool facetex = false;
- if (validface && mat->mode & MA_FACETEXTURE) {
- facetex = true;
- }
-
- // foreach MTex
- for (int i = 0; i < MAXTEX; i++) {
- // use face tex
- if (i == 0 && facetex ) {
- facetex = false;
- Image *tmp = (Image *)(tface->tpage);
-
- if (tmp) {
- material->img[i] = tmp;
- material->texname[i] = material->img[i]->id.name;
- material->flag[i] |= MIPMAP;
-
- material->flag[i] |= (mat->game.alpha_blend & GEMAT_ALPHA_SORT) ? USEALPHA : 0;
- material->flag[i] |= (mat->game.alpha_blend & GEMAT_ALPHA) ? USEALPHA : 0;
- material->flag[i] |= (mat->game.alpha_blend & GEMAT_ADD) ? CALCALPHA : 0;
-
- if (material->img[i]->flag & IMA_REFLECT) {
- material->mapping[i].mapping |= USEREFL;
- }
- else {
- mttmp = getMTexFromMaterial(mat, i);
- if (mttmp && (mttmp->texco & TEXCO_UV)) {
- /* string may be "" but thats detected as empty after */
- material->mapping[i].uvCoName = mttmp->uvname;
- }
- material->mapping[i].mapping |= USEUV;
- }
-
- valid_index++;
- }
- else {
- material->img[i] = 0;
- material->texname[i] = "";
- }
- continue;
- }
-
- mttmp = getMTexFromMaterial(mat, i);
- if (mttmp) {
- if (mttmp->tex) {
- if (mttmp->tex->type == TEX_IMAGE) {
- material->mtexname[i] = mttmp->tex->id.name;
- material->img[i] = mttmp->tex->ima;
- if (material->img[i]) {
-
- material->texname[i] = material->img[i]->id.name;
- material->flag[i] |= (mttmp->tex->imaflag &TEX_MIPMAP) ? MIPMAP : 0;
- if (material->img[i] && (material->img[i]->flag & IMA_IGNORE_ALPHA) == 0) {
- material->flag[i] |= USEALPHA;
- }
- if (mttmp->tex->imaflag & TEX_CALCALPHA) {
- material->flag[i] |= CALCALPHA;
- }
- else if (mttmp->tex->flag & TEX_NEGALPHA) {
- material->flag[i] |= USENEGALPHA;
- }
-
- material->color_blend[i] = mttmp->colfac;
- material->flag[i] |= (mttmp->mapto & MAP_ALPHA) ? TEXALPHA : 0;
- material->flag[i] |= (mttmp->texflag & MTEX_NEGATIVE) ? TEXNEG : 0;
-
- if (!glslmat && (material->flag[i] & TEXALPHA)) {
- texalpha = 1;
- }
- }
- }
- else if (mttmp->tex->type == TEX_ENVMAP) {
- if (mttmp->tex->env->stype == ENV_LOAD) {
- material->mtexname[i] = mttmp->tex->id.name;
- EnvMap *env = mttmp->tex->env;
- env->ima = mttmp->tex->ima;
- material->cubemap[i] = env;
-
- if (material->cubemap[i]) {
- if (!material->cubemap[i]->cube[0]) {
- BL_Texture::SplitEnvMap(material->cubemap[i]);
- }
-
- material->texname[i] = material->cubemap[i]->ima->id.name;
- material->mapping[i].mapping |= USEENV;
- }
- }
- }
-#if 0 /* this flag isn't used anymore */
- material->flag[i] |= (BKE_animdata_from_id(mat->id) != NULL) ? HASIPO : 0;
-#endif
- /// --------------------------------
- // mapping methods
- if (mat->septex & (1 << i)) {
- // If this texture slot isn't in use, set it to disabled to prevent multi-uv problems
- material->mapping[i].mapping = DISABLE;
- }
- else {
- material->mapping[i].mapping |= (mttmp->texco & TEXCO_REFL) ? USEREFL : 0;
-
- if (mttmp->texco & TEXCO_OBJECT) {
- material->mapping[i].mapping |= USEOBJ;
- if (mttmp->object) {
- material->mapping[i].objconame = mttmp->object->id.name;
- }
- }
- else if (mttmp->texco & TEXCO_REFL) {
- material->mapping[i].mapping |= USEREFL;
- }
- else if (mttmp->texco & (TEXCO_ORCO | TEXCO_GLOB)) {
- material->mapping[i].mapping |= USEORCO;
- }
- else if (mttmp->texco & TEXCO_UV) {
- /* string may be "" but thats detected as empty after */
- material->mapping[i].uvCoName = mttmp->uvname;
- material->mapping[i].mapping |= USEUV;
- }
- else if (mttmp->texco & TEXCO_NORM) {
- material->mapping[i].mapping |= USENORM;
- }
- else if (mttmp->texco & TEXCO_TANGENT) {
- material->mapping[i].mapping |= USETANG;
- }
- else {
- material->mapping[i].mapping |= DISABLE;
- }
-
- material->mapping[i].scale[0] = mttmp->size[0];
- material->mapping[i].scale[1] = mttmp->size[1];
- material->mapping[i].scale[2] = mttmp->size[2];
- material->mapping[i].offsets[0] = mttmp->ofs[0];
- material->mapping[i].offsets[1] = mttmp->ofs[1];
- material->mapping[i].offsets[2] = mttmp->ofs[2];
-
- material->mapping[i].projplane[0] = mttmp->projx;
- material->mapping[i].projplane[1] = mttmp->projy;
- material->mapping[i].projplane[2] = mttmp->projz;
- }
- /// --------------------------------
-
- switch (mttmp->blendtype) {
- case MTEX_BLEND:
- material->blend_mode[i] = BLEND_MIX;
- break;
- case MTEX_MUL:
- material->blend_mode[i] = BLEND_MUL;
- break;
- case MTEX_ADD:
- material->blend_mode[i] = BLEND_ADD;
- break;
- case MTEX_SUB:
- material->blend_mode[i] = BLEND_SUB;
- break;
- case MTEX_SCREEN:
- material->blend_mode[i] = BLEND_SCR;
- break;
- }
- valid_index++;
- }
- }
- }
-
- // above one tex the switches here
- // are not used
- switch (valid_index) {
- case 0:
- material->IdMode = DEFAULT_BLENDER;
- break;
- case 1:
- material->IdMode = ONETEX;
- break;
- default:
- material->IdMode = GREATERTHAN2;
- break;
- }
- material->SetUsers(mat->id.us);
-
- material->num_enabled = valid_index;
-
- material->speccolor[0] = mat->specr;
- material->speccolor[1] = mat->specg;
- material->speccolor[2] = mat->specb;
- material->hard = (float)mat->har / 4.0f;
- material->matcolor[0] = mat->r;
- material->matcolor[1] = mat->g;
- material->matcolor[2] = mat->b;
- material->matcolor[3] = mat->alpha;
- material->alpha = mat->alpha;
- material->emit = mat->emit;
- material->spec_f = mat->spec;
- material->ref = mat->ref;
- material->amb = mat->amb;
-
- material->ras_mode |= (mat->material_type == MA_TYPE_WIRE) ? WIRE : 0;
- }
- else { // No Material
- int valid = 0;
-
- // check for tface tex to fallback on
- if (validface) {
- material->img[0] = (Image *)(tface->tpage);
- // ------------------------
- if (material->img[0]) {
- material->texname[0] = material->img[0]->id.name;
- material->mapping[0].mapping |= ((material->img[0]->flag & IMA_REFLECT) != 0) ? USEREFL : 0;
-
- /* see if depth of the image is 32bits */
- if (BKE_image_has_alpha(material->img[0])) {
- material->flag[0] |= USEALPHA;
- material->alphablend = GEMAT_ALPHA;
- }
- else {
- material->alphablend = GEMAT_SOLID;
- }
- valid++;
- }
- }
- else {
- material->alphablend = GEMAT_SOLID;
- }
-
- material->SetUsers(-1);
- material->num_enabled = valid;
- material->IdMode = TEXFACE;
- material->speccolor[0] = 1.0f;
- material->speccolor[1] = 1.0f;
- material->speccolor[2] = 1.0f;
- material->hard = 35.0f;
- material->matcolor[0] = 0.5f;
- material->matcolor[1] = 0.5f;
- material->matcolor[2] = 0.5f;
- material->spec_f = 0.5f;
- material->ref = 0.8f;
-
- // No material - old default TexFace properties
- material->ras_mode |= USE_LIGHT;
- }
-
- /* No material, what to do? let's see what is in the UV and set the material accordingly
- * light and visible is always on */
- if (validface) {
- material->tile = tface->tile;
- }
- else {
- // nothing at all
- material->alphablend = GEMAT_SOLID;
- material->tile = 0;
- }
-
- if (validmat && validface) {
- material->alphablend = mat->game.alpha_blend;
- }
-
- // with ztransp enabled, enforce alpha blending mode
- if (validmat && (mat->mode & MA_TRANSP) && (mat->mode & MA_ZTRANSP) && (material->alphablend == GEMAT_SOLID)) {
- material->alphablend = GEMAT_ALPHA;
- }
-
- // always zsort alpha + add
- if ((ELEM(material->alphablend, GEMAT_ALPHA, GEMAT_ALPHA_SORT, GEMAT_ADD) || texalpha) && (material->alphablend != GEMAT_CLIP)) {
- material->ras_mode |= ALPHA;
- material->ras_mode |= (mat && (mat->game.alpha_blend & GEMAT_ALPHA_SORT)) ? ZSORT : 0;
- }
-
- // XXX The RGB values here were meant to be temporary storage for the conversion process,
- // but fonts now make use of them too, so we leave them in for now.
- unsigned int rgb[4];
- GetRGB(use_vcol, mface, mmcol, mat, rgb);
-
- // swap the material color, so MCol on bitmap font works
- if (validmat && (use_vcol == false) && (mat->game.flag & GEMAT_TEXT)) {
- material->rgb[0] = KX_rgbaint2uint_new(rgb[0]);
- material->rgb[1] = KX_rgbaint2uint_new(rgb[1]);
- material->rgb[2] = KX_rgbaint2uint_new(rgb[2]);
- material->rgb[3] = KX_rgbaint2uint_new(rgb[3]);
- }
-
- if (validmat) {
- material->matname =(mat->id.name);
- }
-
- if (tface) {
- ME_MTEXFACE_CPY(&material->mtexpoly, tface);
- }
- else {
- memset(&material->mtexpoly, 0, sizeof(material->mtexpoly));
- }
- material->material = mat;
- return true;
-}
-
-static RAS_MaterialBucket *material_from_mesh(Material *ma, MFace *mface, MTFace *tface, MCol *mcol, MTF_localLayer *layers, int lightlayer, unsigned int *rgb, MT_Point2 uvs[4][RAS_TexVert::MAX_UNIT], const char *tfaceName, KX_Scene* scene, KX_BlenderSceneConverter *converter)
-{
- RAS_IPolyMaterial* polymat = converter->FindCachedPolyMaterial(scene, ma);
- BL_Material* bl_mat = converter->FindCachedBlenderMaterial(scene, ma);
- KX_BlenderMaterial* kx_blmat = NULL;
-
- /* first is the BL_Material */
- if (!bl_mat)
- {
- bl_mat = new BL_Material();
-
- ConvertMaterial(bl_mat, ma, tface, tfaceName, mface, mcol,
- converter->GetGLSLMaterials());
-
- if (ma && (ma->mode & MA_FACETEXTURE) == 0)
- converter->CacheBlenderMaterial(scene, ma, bl_mat);
- }
-
- const bool use_vcol = GetMaterialUseVColor(ma, bl_mat->glslmat);
- GetRGB(use_vcol, mface, mcol, ma, rgb);
-
- GetUVs(bl_mat, layers, mface, tface, uvs);
-
- /* then the KX_BlenderMaterial */
- if (polymat == NULL)
- {
- kx_blmat = new KX_BlenderMaterial();
-
- kx_blmat->Initialize(scene, bl_mat, (ma?&ma->game:NULL), lightlayer);
- polymat = static_cast<RAS_IPolyMaterial*>(kx_blmat);
- if (ma && (ma->mode & MA_FACETEXTURE) == 0)
- converter->CachePolyMaterial(scene, ma, polymat);
- }
-
- // 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;
- RAS_MaterialBucket* bucket = scene->FindBucket(polymat, bucketCreated);
-
- // this is needed to free up memory afterwards.
- // the converter will also prevent duplicates from being registered,
- // so just register everything.
- converter->RegisterPolyMaterial(polymat);
- converter->RegisterBlenderMaterial(bl_mat);
-
- return bucket;
-}
-
-/* blenderobj can be NULL, make sure its checked for */
-RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, KX_BlenderSceneConverter *converter, bool libloading)
-{
- RAS_MeshObject *meshobj;
- int lightlayer = blenderobj ? blenderobj->lay:(1<<20)-1; // all layers if no object.
-
- // Without checking names, we get some reuse we don't want that can cause
- // problems with material LoDs.
- if (blenderobj && ((meshobj = converter->FindGameMesh(mesh/*, ob->lay*/)) != NULL)) {
- const char *bge_name = meshobj->GetName().ReadPtr();
- const char *blender_name = ((ID *)blenderobj->data)->name + 2;
- if (STREQ(bge_name, blender_name)) {
- return meshobj;
- }
- }
-
- // Get DerivedMesh data
- DerivedMesh *dm = CDDM_from_mesh(mesh);
- DM_ensure_tessface(dm);
-
- MVert *mvert = dm->getVertArray(dm);
- int totvert = dm->getNumVerts(dm);
-
- MFace *mface = dm->getTessFaceArray(dm);
- MTFace *tface = static_cast<MTFace*>(dm->getTessFaceDataArray(dm, CD_MTFACE));
- MCol *mcol = static_cast<MCol*>(dm->getTessFaceDataArray(dm, CD_MCOL));
- float (*tangent)[4] = NULL;
- int totface = dm->getNumTessFaces(dm);
- const char *tfaceName = "";
-
- /* needs to be rewritten for loopdata */
- if (tface) {
- if (CustomData_get_layer_index(&dm->faceData, CD_TANGENT) == -1) {
- bool generate_data = false;
- if (CustomData_get_layer_index(&dm->loopData, CD_TANGENT) == -1) {
- DM_calc_loop_tangents(dm, true, NULL, 0);
- generate_data = true;
- }
- DM_generate_tangent_tessface_data(dm, generate_data);
- }
- tangent = (float(*)[4])dm->getTessFaceDataArray(dm, CD_TANGENT);
- }
-
- meshobj = new RAS_MeshObject(mesh);
-
- // Extract avaiable layers
- MTF_localLayer *layers = new MTF_localLayer[MAX_MTFACE];
- for (int lay=0; lay<MAX_MTFACE; lay++) {
- layers[lay].face = 0;
- layers[lay].name = "";
- }
-
- int validLayers = 0;
- for (int i=0; i<dm->faceData.totlayer; i++)
- {
- if (dm->faceData.layers[i].type == CD_MTFACE)
- {
- if (validLayers >= MAX_MTFACE) {
- printf("%s: corrupted mesh %s - too many CD_MTFACE layers\n", __func__, mesh->id.name);
- break;
- }
-
- layers[validLayers].face = (MTFace*)(dm->faceData.layers[i].data);
- layers[validLayers].name = dm->faceData.layers[i].name;
- if (tface == layers[validLayers].face)
- tfaceName = layers[validLayers].name;
- validLayers++;
- }
- }
-
- meshobj->SetName(mesh->id.name + 2);
- meshobj->m_sharedvertex_map.resize(totvert);
-
- Material* ma = 0;
- MT_Point2 uvs[4][RAS_TexVert::MAX_UNIT];
- unsigned int rgb[4] = {0};
-
- MT_Point3 pt[4];
- MT_Vector3 no[4];
- MT_Vector4 tan[4];
-
- /* ugh, if there is a less annoying way to do this please use that.
- * since these are converted from floats to floats, theres no real
- * advantage to use MT_ types - campbell */
- for (unsigned int i = 0; i < 4; i++) {
- const float zero_vec[4] = {0.0f};
- pt[i].setValue(zero_vec);
- no[i].setValue(zero_vec);
- tan[i].setValue(zero_vec);
- }
-
- /* we need to manually initialize the uvs (MoTo doesn't do that) [#34550] */
- for (unsigned int i = 0; i < RAS_TexVert::MAX_UNIT; i++) {
- uvs[0][i] = uvs[1][i] = uvs[2][i] = uvs[3][i] = MT_Point2(0.f, 0.f);
- }
-
- for (int f=0;f<totface;f++,mface++)
- {
- /* get coordinates, normals and tangents */
- pt[0].setValue(mvert[mface->v1].co);
- pt[1].setValue(mvert[mface->v2].co);
- pt[2].setValue(mvert[mface->v3].co);
- if (mface->v4) pt[3].setValue(mvert[mface->v4].co);
-
- if (mface->flag & ME_SMOOTH) {
- float n0[3], n1[3], n2[3], n3[3];
-
- normal_short_to_float_v3(n0, mvert[mface->v1].no);
- normal_short_to_float_v3(n1, mvert[mface->v2].no);
- normal_short_to_float_v3(n2, mvert[mface->v3].no);
- no[0] = n0;
- no[1] = n1;
- no[2] = n2;
-
- if (mface->v4) {
- normal_short_to_float_v3(n3, mvert[mface->v4].no);
- no[3] = n3;
- }
- }
- else {
- float fno[3];
-
- if (mface->v4)
- normal_quad_v3(fno,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co, mvert[mface->v4].co);
- else
- normal_tri_v3(fno,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co);
-
- no[0] = no[1] = no[2] = no[3] = MT_Vector3(fno);
- }
-
- if (tangent) {
- tan[0] = tangent[f*4 + 0];
- tan[1] = tangent[f*4 + 1];
- tan[2] = tangent[f*4 + 2];
-
- if (mface->v4)
- tan[3] = tangent[f*4 + 3];
- }
- if (blenderobj)
- ma = give_current_material(blenderobj, mface->mat_nr+1);
- else
- ma = mesh->mat ? mesh->mat[mface->mat_nr]:NULL;
-
- // Check for blender material
- if (ma == NULL) {
- ma= &defmaterial;
- }
-
- {
-
- RAS_MaterialBucket* bucket = material_from_mesh(ma, mface, tface, mcol, layers, lightlayer, rgb, uvs, tfaceName, scene, converter);
-
- // set render flags
- bool visible = ((ma->game.flag & GEMAT_INVISIBLE)==0);
- bool twoside = ((ma->game.flag & GEMAT_BACKCULL)==0);
- bool collider = ((ma->game.flag & GEMAT_NOPHYSICS)==0);
-
- /* mark face as flat, so vertices are split */
- bool flat = (mface->flag & ME_SMOOTH) == 0;
-
- int nverts = (mface->v4)? 4: 3;
-
- RAS_Polygon *poly = meshobj->AddPolygon(bucket, nverts);
-
- poly->SetVisible(visible);
- poly->SetCollider(collider);
- poly->SetTwoside(twoside);
- //poly->SetEdgeCode(mface->edcode);
-
- meshobj->AddVertex(poly,0,pt[0],uvs[0],tan[0],rgb[0],no[0],flat,mface->v1);
- meshobj->AddVertex(poly,1,pt[1],uvs[1],tan[1],rgb[1],no[1],flat,mface->v2);
- meshobj->AddVertex(poly,2,pt[2],uvs[2],tan[2],rgb[2],no[2],flat,mface->v3);
-
- if (nverts==4)
- meshobj->AddVertex(poly,3,pt[3],uvs[3],tan[3],rgb[3],no[3],flat,mface->v4);
- }
-
- if (tface)
- tface++;
- if (mcol)
- mcol+=4;
-
- for (int lay=0; lay<MAX_MTFACE; lay++)
- {
- MTF_localLayer &layer = layers[lay];
- if (layer.face == 0) break;
-
- layer.face++;
- }
- }
- // keep meshobj->m_sharedvertex_map for reinstance phys mesh.
- // 2.49a and before it did: meshobj->m_sharedvertex_map.clear();
- // but this didnt save much ram. - Campbell
- meshobj->EndConversion();
-
- // pre calculate texture generation
- // However, we want to delay this if we're libloading so we can make sure we have the right scene.
- if (!libloading) {
- for (list<RAS_MeshMaterial>::iterator mit = meshobj->GetFirstMaterial();
- mit != meshobj->GetLastMaterial(); ++ mit) {
- mit->m_bucket->GetPolyMaterial()->OnConstruction();
- }
- }
-
- if (layers)
- delete []layers;
-
- dm->release(dm);
-
- converter->RegisterGameMesh(meshobj, mesh);
- return meshobj;
-}
-
-
-
-static PHY_MaterialProps *CreateMaterialFromBlenderObject(struct Object* blenderobject)
-{
- PHY_MaterialProps *materialProps = new PHY_MaterialProps;
-
- MT_assert(materialProps && "Create physics material properties failed");
-
- Material* blendermat = give_current_material(blenderobject, 1);
-
- if (blendermat)
- {
- MT_assert(0.0f <= blendermat->reflect && blendermat->reflect <= 1.0f);
-
- materialProps->m_restitution = blendermat->reflect;
- materialProps->m_friction = blendermat->friction;
- materialProps->m_fh_spring = blendermat->fh;
- materialProps->m_fh_damping = blendermat->xyfrict;
- materialProps->m_fh_distance = blendermat->fhdist;
- materialProps->m_fh_normal = (blendermat->dynamode & MA_FH_NOR) != 0;
- }
- else {
- //give some defaults
- materialProps->m_restitution = 0.f;
- materialProps->m_friction = 0.5;
- materialProps->m_fh_spring = 0.f;
- materialProps->m_fh_damping = 0.f;
- materialProps->m_fh_distance = 0.f;
- materialProps->m_fh_normal = false;
-
- }
-
- return materialProps;
-}
-
-static PHY_ShapeProps *CreateShapePropsFromBlenderObject(struct Object* blenderobject)
-{
- PHY_ShapeProps *shapeProps = new PHY_ShapeProps;
-
- MT_assert(shapeProps);
-
- shapeProps->m_mass = blenderobject->mass;
-
-// This needs to be fixed in blender. For now, we use:
-
-// in Blender, inertia stands for the size value which is equivalent to
-// the sphere radius
- shapeProps->m_inertia = blenderobject->formfactor;
-
- MT_assert(0.0f <= blenderobject->damping && blenderobject->damping <= 1.0f);
- MT_assert(0.0f <= blenderobject->rdamping && blenderobject->rdamping <= 1.0f);
-
- shapeProps->m_lin_drag = 1.0f - blenderobject->damping;
- shapeProps->m_ang_drag = 1.0f - blenderobject->rdamping;
-
- shapeProps->m_friction_scaling[0] = blenderobject->anisotropicFriction[0];
- shapeProps->m_friction_scaling[1] = blenderobject->anisotropicFriction[1];
- shapeProps->m_friction_scaling[2] = blenderobject->anisotropicFriction[2];
- shapeProps->m_do_anisotropic = ((blenderobject->gameflag & OB_ANISOTROPIC_FRICTION) != 0);
-
- shapeProps->m_do_fh = (blenderobject->gameflag & OB_DO_FH) != 0;
- shapeProps->m_do_rot_fh = (blenderobject->gameflag & OB_ROT_FH) != 0;
-
-// velocity clamping XXX
- shapeProps->m_clamp_vel_min = blenderobject->min_vel;
- shapeProps->m_clamp_vel_max = blenderobject->max_vel;
- shapeProps->m_clamp_angvel_min = blenderobject->min_angvel;
- shapeProps->m_clamp_angvel_max = blenderobject->max_angvel;
-
-// Character physics properties
- shapeProps->m_step_height = blenderobject->step_height;
- shapeProps->m_jump_speed = blenderobject->jump_speed;
- shapeProps->m_fall_speed = blenderobject->fall_speed;
- shapeProps->m_max_jumps = blenderobject->max_jumps;
-
- return shapeProps;
-}
-
-
-
-
-
-//////////////////////////////////////////////////////////
-
-
-
-static float my_boundbox_mesh(Mesh *me, float *loc, float *size)
-{
- MVert *mvert;
- BoundBox *bb;
- float min[3], max[3];
- float mloc[3], msize[3];
- float radius_sq=0.0f, vert_radius_sq, *co;
- int a;
-
- if (me->bb==0) {
- me->bb = BKE_boundbox_alloc_unit();
- }
- bb= me->bb;
-
- INIT_MINMAX(min, max);
-
- if (!loc) loc= mloc;
- if (!size) size= msize;
-
- mvert= me->mvert;
- for (a = 0; a<me->totvert; a++, mvert++) {
- co = mvert->co;
-
- /* bounds */
- minmax_v3v3_v3(min, max, co);
-
- /* radius */
-
- vert_radius_sq = len_squared_v3(co);
- if (vert_radius_sq > radius_sq)
- radius_sq = vert_radius_sq;
- }
-
- if (me->totvert) {
- loc[0] = (min[0] + max[0]) / 2.0f;
- loc[1] = (min[1] + max[1]) / 2.0f;
- loc[2] = (min[2] + max[2]) / 2.0f;
-
- size[0] = (max[0] - min[0]) / 2.0f;
- size[1] = (max[1] - min[1]) / 2.0f;
- size[2] = (max[2] - min[2]) / 2.0f;
- }
- else {
- loc[0] = loc[1] = loc[2] = 0.0f;
- size[0] = size[1] = size[2] = 0.0f;
- }
-
- bb->vec[0][0] = bb->vec[1][0] = bb->vec[2][0] = bb->vec[3][0] = loc[0]-size[0];
- bb->vec[4][0] = bb->vec[5][0] = bb->vec[6][0] = bb->vec[7][0] = loc[0]+size[0];
-
- bb->vec[0][1] = bb->vec[1][1] = bb->vec[4][1] = bb->vec[5][1] = loc[1]-size[1];
- bb->vec[2][1] = bb->vec[3][1] = bb->vec[6][1] = bb->vec[7][1] = loc[1]+size[1];
-
- bb->vec[0][2] = bb->vec[3][2] = bb->vec[4][2] = bb->vec[7][2] = loc[2]-size[2];
- bb->vec[1][2] = bb->vec[2][2] = bb->vec[5][2] = bb->vec[6][2] = loc[2]+size[2];
-
- return sqrtf_signed(radius_sq);
-}
-
-//////////////////////////////////////////////////////
-
-
-static void BL_CreateGraphicObjectNew(KX_GameObject* gameobj,
- const MT_Point3& localAabbMin,
- const MT_Point3& localAabbMax,
- KX_Scene* kxscene,
- bool isActive,
- e_PhysicsEngine physics_engine)
-{
- if (gameobj->GetMeshCount() > 0)
- {
- switch (physics_engine)
- {
-#ifdef WITH_BULLET
- case UseBullet:
- {
- CcdPhysicsEnvironment* env = (CcdPhysicsEnvironment*)kxscene->GetPhysicsEnvironment();
- assert(env);
- PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
- CcdGraphicController* ctrl = new CcdGraphicController(env, motionstate);
- gameobj->SetGraphicController(ctrl);
- ctrl->SetNewClientInfo(gameobj->getClientInfo());
- ctrl->SetLocalAabb(localAabbMin, localAabbMax);
- if (isActive) {
- // add first, this will create the proxy handle, only if the object is visible
- if (gameobj->GetVisible())
- env->AddCcdGraphicController(ctrl);
- // update the mesh if there is a deformer, this will also update the bounding box for modifiers
- RAS_Deformer* deformer = gameobj->GetDeformer();
- if (deformer)
- deformer->UpdateBuckets();
- }
- }
- break;
-#endif
- default:
- break;
- }
- }
-}
-
-static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
- struct Object* blenderobject,
- RAS_MeshObject* meshobj,
- KX_Scene* kxscene,
- int activeLayerBitInfo,
- KX_BlenderSceneConverter *converter,
- bool processCompoundChildren
- )
-
-{
- //SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/
- //int userigidbody = SYS_GetCommandLineInt(syshandle,"norigidbody",0);
- //bool bRigidBody = (userigidbody == 0);
-
- // object has physics representation?
- if (!(blenderobject->gameflag & OB_COLLISION)) {
- // Respond to all collisions so that Near sensors work on No Collision
- // objects.
- gameobj->SetUserCollisionGroup(0xffff);
- gameobj->SetUserCollisionMask(0xffff);
- return;
- }
-
- gameobj->SetUserCollisionGroup(blenderobject->col_group);
- gameobj->SetUserCollisionMask(blenderobject->col_mask);
-
- // get Root Parent of blenderobject
- struct Object* parent= blenderobject->parent;
- while (parent && parent->parent) {
- parent= parent->parent;
- }
-
- bool isCompoundChild = false;
- bool hasCompoundChildren = !parent && (blenderobject->gameflag & OB_CHILD) && !(blenderobject->gameflag & OB_SOFT_BODY);
-
- /* When the parent is not OB_DYNAMIC and has no OB_COLLISION then it gets no bullet controller
- * and cant be apart of the parents compound shape, same goes for OB_SOFT_BODY */
- if (parent && (parent->gameflag & (OB_DYNAMIC | OB_COLLISION))) {
- if ((parent->gameflag & OB_CHILD)!=0 && (blenderobject->gameflag & OB_CHILD) && !(parent->gameflag & OB_SOFT_BODY)) {
- isCompoundChild = true;
- }
- }
- if (processCompoundChildren != isCompoundChild)
- return;
-
-
- PHY_ShapeProps* shapeprops =
- CreateShapePropsFromBlenderObject(blenderobject);
-
-
- PHY_MaterialProps* smmaterial =
- CreateMaterialFromBlenderObject(blenderobject);
-
- DerivedMesh* dm = NULL;
- if (gameobj->GetDeformer())
- dm = gameobj->GetDeformer()->GetPhysicsMesh();
-
- class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
-
- kxscene->GetPhysicsEnvironment()->ConvertObject(gameobj, meshobj, dm, kxscene, shapeprops, smmaterial, motionstate, activeLayerBitInfo, isCompoundChild, hasCompoundChildren);
-
- bool isActor = (blenderobject->gameflag & OB_ACTOR)!=0;
- bool isSensor = (blenderobject->gameflag & OB_SENSOR) != 0;
- gameobj->getClientInfo()->m_type =
- (isSensor) ? ((isActor) ? KX_ClientObjectInfo::OBACTORSENSOR : KX_ClientObjectInfo::OBSENSOR) :
- (isActor) ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC;
-
- // should we record animation for this object?
- if ((blenderobject->gameflag & OB_RECORD_ANIMATION) != 0)
- gameobj->SetRecordAnimation(true);
-
- delete shapeprops;
- delete smmaterial;
- if (dm) {
- dm->needsFree = 1;
- dm->release(dm);
- }
-}
-
-
-
-
-
-static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int layerflag, KX_Scene *kxscene, RAS_IRasterizer *rasterizer, KX_BlenderSceneConverter *converter)
-{
- RAS_ILightObject *lightobj = rasterizer->CreateLight();
- KX_LightObject *gamelight;
-
- lightobj->m_att1 = la->att1;
- lightobj->m_att2 = (la->mode & LA_QUAD) ? la->att2 : 0.0f;
- lightobj->m_coeff_const = la->coeff_const;
- lightobj->m_coeff_lin = la->coeff_lin;
- lightobj->m_coeff_quad = la->coeff_quad;
- lightobj->m_color[0] = la->r;
- lightobj->m_color[1] = la->g;
- lightobj->m_color[2] = la->b;
- lightobj->m_distance = la->dist;
- lightobj->m_energy = la->energy;
- lightobj->m_shadowclipstart = la->clipsta;
- lightobj->m_shadowclipend = la->clipend;
- lightobj->m_shadowbias = la->bias;
- lightobj->m_shadowbleedbias = la->bleedbias;
- lightobj->m_shadowmaptype = la->shadowmap_type;
- lightobj->m_shadowfrustumsize = la->shadow_frustum_size;
- lightobj->m_shadowcolor[0] = la->shdwr;
- lightobj->m_shadowcolor[1] = la->shdwg;
- lightobj->m_shadowcolor[2] = la->shdwb;
- lightobj->m_layer = layerflag;
- lightobj->m_spotblend = la->spotblend;
- lightobj->m_spotsize = la->spotsize;
-
- lightobj->m_nodiffuse = (la->mode & LA_NO_DIFF) != 0;
- lightobj->m_nospecular = (la->mode & LA_NO_SPEC) != 0;
-
- bool glslmat = converter->GetGLSLMaterials();
-
- // in GLSL NEGATIVE LAMP is handled inside the lamp update function
- if (glslmat==0) {
- if (la->mode & LA_NEG)
- {
- lightobj->m_color[0] = -lightobj->m_color[0];
- lightobj->m_color[1] = -lightobj->m_color[1];
- lightobj->m_color[2] = -lightobj->m_color[2];
- }
- }
-
- if (la->type==LA_SUN) {
- lightobj->m_type = RAS_ILightObject::LIGHT_SUN;
- } else if (la->type==LA_SPOT) {
- lightobj->m_type = RAS_ILightObject::LIGHT_SPOT;
- } else {
- lightobj->m_type = RAS_ILightObject::LIGHT_NORMAL;
- }
-
- gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rasterizer,
- lightobj, glslmat);
-
- return gamelight;
-}
-
-static KX_Camera *gamecamera_from_bcamera(Object *ob, KX_Scene *kxscene, KX_BlenderSceneConverter *converter)
-{
- Camera* ca = static_cast<Camera*>(ob->data);
- RAS_CameraData camdata(ca->lens, ca->ortho_scale, ca->sensor_x, ca->sensor_y, ca->sensor_fit, ca->shiftx, ca->shifty, ca->clipsta, ca->clipend, ca->type == CAM_PERSP, ca->YF_dofdist);
- KX_Camera *gamecamera;
-
- gamecamera= new KX_Camera(kxscene, KX_Scene::m_callbacks, camdata);
- gamecamera->SetName(ca->id.name + 2);
-
- return gamecamera;
-}
-
-static KX_GameObject *gameobject_from_blenderobject(
- Object *ob,
- KX_Scene *kxscene,
- RAS_IRasterizer *rendertools,
- KX_BlenderSceneConverter *converter,
- bool libloading)
-{
- KX_GameObject *gameobj = NULL;
- Scene *blenderscene = kxscene->GetBlenderScene();
-
- switch (ob->type) {
- case OB_LAMP:
- {
- KX_LightObject* gamelight = gamelight_from_blamp(ob, static_cast<Lamp*>(ob->data), ob->lay, kxscene, rendertools, converter);
- gameobj = gamelight;
-
- if (blenderscene->lay & ob->lay)
- {
- gamelight->AddRef();
- kxscene->GetLightList()->Add(gamelight);
- }
-
- break;
- }
-
- case OB_CAMERA:
- {
- KX_Camera* gamecamera = gamecamera_from_bcamera(ob, kxscene, converter);
- gameobj = gamecamera;
-
- //don't add a reference: the camera list in kxscene->m_cameras is not released at the end
- //gamecamera->AddRef();
- kxscene->AddCamera(gamecamera);
-
- break;
- }
-
- case OB_MESH:
- {
- Mesh* mesh = static_cast<Mesh*>(ob->data);
- float center[3], extents[3];
- float radius = my_boundbox_mesh((Mesh*) ob->data, center, extents);
- RAS_MeshObject* meshobj = BL_ConvertMesh(mesh,ob,kxscene,converter, libloading);
-
- // needed for python scripting
- kxscene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj);
-
- if (ob->gameflag & OB_NAVMESH)
- {
- gameobj = new KX_NavMeshObject(kxscene,KX_Scene::m_callbacks);
- gameobj->AddMesh(meshobj);
- break;
- }
-
- gameobj = new BL_DeformableGameObject(ob,kxscene,KX_Scene::m_callbacks);
-
- // set transformation
- gameobj->AddMesh(meshobj);
-
- // gather levels of detail
- if (BLI_listbase_count_at_most(&ob->lodlevels, 2) > 1) {
- LodLevel *lod = ((LodLevel*)ob->lodlevels.first)->next;
- Mesh* lodmesh = mesh;
- Object* lodmatob = ob;
- gameobj->AddLodMesh(meshobj);
- for (; lod; lod = lod->next) {
- if (!lod->source || lod->source->type != OB_MESH) continue;
- if (lod->flags & OB_LOD_USE_MESH) {
- lodmesh = static_cast<Mesh*>(lod->source->data);
- }
- if (lod->flags & OB_LOD_USE_MAT) {
- lodmatob = lod->source;
- }
- gameobj->AddLodMesh(BL_ConvertMesh(lodmesh, lodmatob, kxscene, converter, libloading));
- }
- if (blenderscene->gm.lodflag & SCE_LOD_USE_HYST) {
- kxscene->SetLodHysteresis(true);
- kxscene->SetLodHysteresisValue(blenderscene->gm.scehysteresis);
- }
- }
-
- // for all objects: check whether they want to
- // respond to updates
- bool ignoreActivityCulling =
- ((ob->gameflag2 & OB_NEVER_DO_ACTIVITY_CULLING)!=0);
- gameobj->SetIgnoreActivityCulling(ignoreActivityCulling);
- gameobj->SetOccluder((ob->gameflag & OB_OCCLUDER) != 0, false);
-
- // we only want obcolor used if there is a material in the mesh
- // that requires it
- Material *mat= NULL;
- bool bUseObjectColor=false;
-
- for (int i=0;i<mesh->totcol;i++) {
- mat=mesh->mat[i];
- if (!mat) break;
- if ((mat->shade_flag & MA_OBCOLOR)) {
- bUseObjectColor = true;
- break;
- }
- }
- if (bUseObjectColor)
- gameobj->SetObjectColor(ob->col);
-
- // two options exists for deform: shape keys and armature
- // only support relative shape key
- bool bHasShapeKey = mesh->key != NULL && mesh->key->type==KEY_RELATIVE;
- bool bHasDvert = mesh->dvert != NULL && ob->defbase.first;
- bool bHasArmature = (BL_ModifierDeformer::HasArmatureDeformer(ob) && ob->parent && ob->parent->type == OB_ARMATURE && bHasDvert);
- bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(ob);
-#ifdef WITH_BULLET
- bool bHasSoftBody = (!ob->parent && (ob->gameflag & OB_SOFT_BODY));
-#endif
- if (bHasModifier) {
- BL_ModifierDeformer *dcont = new BL_ModifierDeformer((BL_DeformableGameObject *)gameobj,
- kxscene->GetBlenderScene(), ob, meshobj);
- ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont);
- } else if (bHasShapeKey) {
- // not that we can have shape keys without dvert!
- BL_ShapeDeformer *dcont = new BL_ShapeDeformer((BL_DeformableGameObject*)gameobj,
- ob, meshobj);
- ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont);
- } else if (bHasArmature) {
- BL_SkinDeformer *dcont = new BL_SkinDeformer((BL_DeformableGameObject*)gameobj,
- ob, meshobj);
- ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont);
- } else if (bHasDvert) {
- // this case correspond to a mesh that can potentially deform but not with the
- // object to which it is attached for the moment. A skin mesh was created in
- // BL_ConvertMesh() so must create a deformer too!
- BL_MeshDeformer *dcont = new BL_MeshDeformer((BL_DeformableGameObject*)gameobj,
- ob, meshobj);
- ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont);
-#ifdef WITH_BULLET
- } else if (bHasSoftBody) {
- KX_SoftBodyDeformer *dcont = new KX_SoftBodyDeformer(meshobj, (BL_DeformableGameObject*)gameobj);
- ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont);
-#endif
- }
-
- MT_Point3 min = MT_Point3(center) - MT_Vector3(extents);
- MT_Point3 max = MT_Point3(center) + MT_Vector3(extents);
- SG_BBox bbox = SG_BBox(min, max);
- gameobj->GetSGNode()->SetBBox(bbox);
- gameobj->GetSGNode()->SetRadius(radius);
-
- break;
- }
-
- case OB_ARMATURE:
- {
- bArmature *arm = (bArmature*)ob->data;
- gameobj = new BL_ArmatureObject(
- kxscene,
- KX_Scene::m_callbacks,
- ob,
- kxscene->GetBlenderScene(), // handle
- arm->gevertdeformer
- );
- /* Get the current pose from the armature object and apply it as the rest pose */
- break;
- }
-
- case OB_EMPTY:
- {
- gameobj = new KX_EmptyObject(kxscene,KX_Scene::m_callbacks);
- // set transformation
- break;
- }
-
- case OB_FONT:
- {
- bool do_color_management = BKE_scene_check_color_management_enabled(blenderscene);
- /* font objects have no bounding box */
- gameobj = new KX_FontObject(kxscene,KX_Scene::m_callbacks, rendertools, ob, do_color_management);
-
- /* add to the list only the visible fonts */
- if ((ob->lay & kxscene->GetBlenderScene()->lay) != 0)
- kxscene->AddFont(static_cast<KX_FontObject*>(gameobj));
- break;
- }
-
-#ifdef THREADED_DAG_WORKAROUND
- case OB_CURVE:
- {
- if (ob->curve_cache == NULL) {
- BKE_displist_make_curveTypes(blenderscene, ob, false);
- }
- }
-#endif
-
- }
- if (gameobj)
- {
- gameobj->SetLayer(ob->lay);
- gameobj->SetBlenderObject(ob);
- /* set the visibility state based on the objects render option in the outliner */
- if (ob->restrictflag & OB_RESTRICT_RENDER) gameobj->SetVisible(0, 0);
- }
- return gameobj;
-}
-
-struct parentChildLink {
- struct Object* m_blenderchild;
- SG_Node* m_gamechildnode;
-};
-
-static bPoseChannel *get_active_posechannel2(Object *ob)
-{
- bArmature *arm= (bArmature*)ob->data;
- bPoseChannel *pchan;
-
- /* find active */
- for (pchan= (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan= pchan->next) {
- if (pchan->bone && (pchan->bone == arm->act_bone) && (pchan->bone->layer & arm->layer))
- return pchan;
- }
-
- return NULL;
-}
-
-static ListBase *get_active_constraints2(Object *ob)
-{
- if (!ob)
- return NULL;
-
- // XXX - shouldnt we care about the pose data and not the mode???
- if (ob->mode & OB_MODE_POSE) {
- bPoseChannel *pchan;
-
- pchan = get_active_posechannel2(ob);
- if (pchan)
- return &pchan->constraints;
- }
- else
- return &ob->constraints;
-
- return NULL;
-}
-
-static void UNUSED_FUNCTION(print_active_constraints2)(Object *ob) //not used, use to debug
-{
- bConstraint* curcon;
- ListBase* conlist = get_active_constraints2(ob);
-
- if (conlist) {
- for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) {
- printf("%i\n",curcon->type);
- }
- }
-}
-
-// Copy base layer to object layer like in BKE_scene_set_background
-static void blenderSceneSetBackground(Scene *blenderscene)
-{
- Scene *it;
- Base *base;
-
- for (SETLOOPER(blenderscene, it, base)) {
- base->object->lay = base->lay;
- base->object->flag = base->flag;
- }
-}
-
-static KX_GameObject* getGameOb(STR_String busc,CListValue* sumolist)
-{
-
- for (int j=0;j<sumolist->GetCount();j++)
- {
- KX_GameObject* gameobje = (KX_GameObject*) sumolist->GetValue(j);
- if (gameobje->GetName()==busc)
- return gameobje;
- }
-
- return 0;
-
-}
-
-static bool bl_isConstraintInList(KX_GameObject *gameobj, set<KX_GameObject*> convertedlist)
-{
- set<KX_GameObject*>::iterator gobit;
- for (gobit = convertedlist.begin(); gobit != convertedlist.end(); gobit++) {
- if ((*gobit)->GetName() == gameobj->GetName())
- return true;
- }
- return false;
-}
-
-/* helper for BL_ConvertBlenderObjects, avoids code duplication
- * note: all var names match args are passed from the caller */
-static void bl_ConvertBlenderObject_Single(
- KX_BlenderSceneConverter *converter,
- Object *blenderobject,
- vector<parentChildLink> &vec_parent_child,
- CListValue* logicbrick_conversionlist,
- CListValue* objectlist, CListValue* inactivelist, CListValue* sumolist,
- KX_Scene* kxscene, KX_GameObject* gameobj,
- SCA_LogicManager* logicmgr, SCA_TimeEventManager* timemgr,
- bool isInActiveLayer
- )
-{
- MT_Point3 pos(
- blenderobject->loc[0]+blenderobject->dloc[0],
- blenderobject->loc[1]+blenderobject->dloc[1],
- blenderobject->loc[2]+blenderobject->dloc[2]
- );
-
- MT_Matrix3x3 rotation;
- float rotmat[3][3];
- BKE_object_rot_to_mat3(blenderobject, rotmat, false);
- rotation.setValue3x3((float*)rotmat);
-
- MT_Vector3 scale(blenderobject->size);
-
- gameobj->NodeSetLocalPosition(pos);
- gameobj->NodeSetLocalOrientation(rotation);
- gameobj->NodeSetLocalScale(scale);
- gameobj->NodeUpdateGS(0);
-
- sumolist->Add(gameobj->AddRef());
-
- BL_ConvertProperties(blenderobject,gameobj,timemgr,kxscene,isInActiveLayer);
-
- gameobj->SetName(blenderobject->id.name + 2);
-
- // update children/parent hierarchy
- if (blenderobject->parent != 0)
- {
- // blender has an additional 'parentinverse' offset in each object
- SG_Callbacks callback(NULL,NULL,NULL,KX_Scene::KX_ScenegraphUpdateFunc,KX_Scene::KX_ScenegraphRescheduleFunc);
- SG_Node* parentinversenode = new SG_Node(NULL,kxscene,callback);
-
- // define a normal parent relationship for this node.
- KX_NormalParentRelation * parent_relation = KX_NormalParentRelation::New();
- parentinversenode->SetParentRelation(parent_relation);
-
- parentChildLink pclink;
- pclink.m_blenderchild = blenderobject;
- pclink.m_gamechildnode = parentinversenode;
- vec_parent_child.push_back(pclink);
-
- float* fl = (float*) blenderobject->parentinv;
- MT_Transform parinvtrans(fl);
- parentinversenode->SetLocalPosition(parinvtrans.getOrigin());
- // problem here: the parent inverse transform combines scaling and rotation
- // in the basis but the scenegraph needs separate rotation and scaling.
- // This is not important for OpenGL (it uses 4x4 matrix) but it is important
- // for the physic engine that needs a separate scaling
- //parentinversenode->SetLocalOrientation(parinvtrans.getBasis());
-
- // Extract the rotation and the scaling from the basis
- MT_Matrix3x3 ori(parinvtrans.getBasis());
- MT_Vector3 x(ori.getColumn(0));
- MT_Vector3 y(ori.getColumn(1));
- MT_Vector3 z(ori.getColumn(2));
- MT_Vector3 parscale(x.length(), y.length(), z.length());
- if (!MT_fuzzyZero(parscale[0]))
- x /= parscale[0];
- if (!MT_fuzzyZero(parscale[1]))
- y /= parscale[1];
- if (!MT_fuzzyZero(parscale[2]))
- z /= parscale[2];
- ori.setColumn(0, x);
- ori.setColumn(1, y);
- ori.setColumn(2, z);
- parentinversenode->SetLocalOrientation(ori);
- parentinversenode->SetLocalScale(parscale);
-
- parentinversenode->AddChild(gameobj->GetSGNode());
- }
-
- // needed for python scripting
- logicmgr->RegisterGameObjectName(gameobj->GetName(),gameobj);
-
- // needed for group duplication
- logicmgr->RegisterGameObj(blenderobject, gameobj);
- for (int i = 0; i < gameobj->GetMeshCount(); i++)
- logicmgr->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), blenderobject);
-
- converter->RegisterGameObject(gameobj, blenderobject);
- // this was put in rapidly, needs to be looked at more closely
- // only draw/use objects in active 'blender' layers
-
- logicbrick_conversionlist->Add(gameobj->AddRef());
-
- if (isInActiveLayer)
- {
- objectlist->Add(gameobj->AddRef());
- //tf.Add(gameobj->GetSGNode());
-
- gameobj->NodeUpdateGS(0);
- gameobj->AddMeshUser();
- }
- else
- {
- //we must store this object otherwise it will be deleted
- //at the end of this function if it is not a root object
- inactivelist->Add(gameobj->AddRef());
- }
-}
-
-
-// convert blender objects into ketsji gameobjects
-void BL_ConvertBlenderObjects(struct Main* maggie,
- KX_Scene* kxscene,
- KX_KetsjiEngine* ketsjiEngine,
- e_PhysicsEngine physics_engine,
- RAS_IRasterizer* rendertools,
- RAS_ICanvas* canvas,
- KX_BlenderSceneConverter* converter,
- bool alwaysUseExpandFraming,
- bool libloading
- )
-{
-
-#define BL_CONVERTBLENDEROBJECT_SINGLE \
- bl_ConvertBlenderObject_Single(converter, \
- blenderobject, \
- vec_parent_child, \
- logicbrick_conversionlist, \
- objectlist, inactivelist, sumolist, \
- kxscene, gameobj, \
- logicmgr, timemgr, \
- isInActiveLayer \
- )
-
-
-
- Scene *blenderscene = kxscene->GetBlenderScene();
- // for SETLOOPER
- Scene *sce_iter;
- Base *base;
-
- // Get the frame settings of the canvas.
- // Get the aspect ratio of the canvas as designed by the user.
-
- RAS_FrameSettings::RAS_FrameType frame_type;
- int aspect_width;
- int aspect_height;
- set<Group*> grouplist; // list of groups to be converted
- set<Object*> allblobj; // all objects converted
- set<Object*> groupobj; // objects from groups (never in active layer)
-
- // This is bad, but we use this to make sure the first time this is called
- // is not in a separate thread.
- BL_Texture::GetMaxUnits();
-
- /* We have to ensure that group definitions are only converted once
- * push all converted group members to this set.
- * This will happen when a group instance is made from a linked group instance
- * and both are on the active layer. */
- set<KX_GameObject*> convertedlist;
-
- if (alwaysUseExpandFraming) {
- frame_type = RAS_FrameSettings::e_frame_extend;
- aspect_width = canvas->GetWidth();
- aspect_height = canvas->GetHeight();
- } else {
- if (blenderscene->gm.framing.type == SCE_GAMEFRAMING_BARS) {
- frame_type = RAS_FrameSettings::e_frame_bars;
- } else if (blenderscene->gm.framing.type == SCE_GAMEFRAMING_EXTEND) {
- frame_type = RAS_FrameSettings::e_frame_extend;
- } else {
- frame_type = RAS_FrameSettings::e_frame_scale;
- }
-
- aspect_width = (int)(blenderscene->r.xsch * blenderscene->r.xasp);
- aspect_height = (int)(blenderscene->r.ysch * blenderscene->r.yasp);
- }
-
- RAS_FrameSettings frame_settings(
- frame_type,
- blenderscene->gm.framing.col[0],
- blenderscene->gm.framing.col[1],
- blenderscene->gm.framing.col[2],
- aspect_width,
- aspect_height
- );
- kxscene->SetFramingType(frame_settings);
-
- kxscene->SetGravity(MT_Vector3(0,0, -blenderscene->gm.gravity));
-
- /* set activity culling parameters */
- kxscene->SetActivityCulling( (blenderscene->gm.mode & WO_ACTIVITY_CULLING) != 0);
- kxscene->SetActivityCullingRadius(blenderscene->gm.activityBoxRadius);
- kxscene->SetDbvtCulling((blenderscene->gm.mode & WO_DBVT_CULLING) != 0);
-
- // no occlusion culling by default
- kxscene->SetDbvtOcclusionRes(0);
-
- int activeLayerBitInfo = blenderscene->lay;
-
- // list of all object converted, active and inactive
- CListValue* sumolist = new CListValue();
-
- vector<parentChildLink> vec_parent_child;
-
- CListValue* objectlist = kxscene->GetObjectList();
- CListValue* inactivelist = kxscene->GetInactiveList();
- CListValue* parentlist = kxscene->GetRootParentList();
-
- SCA_LogicManager* logicmgr = kxscene->GetLogicManager();
- SCA_TimeEventManager* timemgr = kxscene->GetTimeEventManager();
-
- CListValue* logicbrick_conversionlist = new CListValue();
-
- //SG_TreeFactory tf;
-
- // Convert actions to actionmap
- bAction *curAct;
- for (curAct = (bAction*)maggie->action.first; curAct; curAct=(bAction*)curAct->id.next)
- {
- logicmgr->RegisterActionName(curAct->id.name + 2, curAct);
- }
-
- SetDefaultLightMode(blenderscene);
-
- blenderSceneSetBackground(blenderscene);
-
- // Let's support scene set.
- // Beware of name conflict in linked data, it will not crash but will create confusion
- // in Python scripting and in certain actuators (replace mesh). Linked scene *should* have
- // no conflicting name for Object, Object data and Action.
- for (SETLOOPER(blenderscene, sce_iter, base))
- {
- Object* blenderobject = base->object;
- allblobj.insert(blenderobject);
-
- KX_GameObject* gameobj = gameobject_from_blenderobject(
- base->object,
- kxscene,
- rendertools,
- converter,
- libloading);
-
- bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) !=0;
- if (gameobj)
- {
- /* macro calls object conversion funcs */
- BL_CONVERTBLENDEROBJECT_SINGLE;
-
- if (gameobj->IsDupliGroup()) {
- grouplist.insert(blenderobject->dup_group);
- }
-
- /* Note about memory leak issues:
- * When a CValue derived class is created, m_refcount is initialized to 1
- * so the class must be released after being used to make sure that it won't
- * hang in memory. If the object needs to be stored for a long time,
- * use AddRef() so that this Release() does not free the object.
- * Make sure that for any AddRef() there is a Release()!!!!
- * Do the same for any object derived from CValue, CExpression and NG_NetworkMessage
- */
- gameobj->Release();
- }
- }
-
- if (!grouplist.empty())
- {
- // now convert the group referenced by dupli group object
- // keep track of all groups already converted
- set<Group*> allgrouplist = grouplist;
- set<Group*> tempglist;
- // recurse
- while (!grouplist.empty())
- {
- set<Group*>::iterator git;
- tempglist.clear();
- tempglist.swap(grouplist);
- for (git=tempglist.begin(); git!=tempglist.end(); git++)
- {
- Group* group = *git;
- GroupObject* go;
- for (go=(GroupObject*)group->gobject.first; go; go=(GroupObject*)go->next)
- {
- Object* blenderobject = go->ob;
- if (converter->FindGameObject(blenderobject) == NULL)
- {
- allblobj.insert(blenderobject);
- groupobj.insert(blenderobject);
- KX_GameObject* gameobj = gameobject_from_blenderobject(
- blenderobject,
- kxscene,
- rendertools,
- converter,
- libloading);
-
- bool isInActiveLayer = false;
- if (gameobj) {
- /* Insert object to the constraint game object list
- * so we can check later if there is a instance in the scene or
- * an instance and its actual group definition. */
- convertedlist.insert((KX_GameObject*)gameobj->AddRef());
-
- /* macro calls object conversion funcs */
- BL_CONVERTBLENDEROBJECT_SINGLE;
-
- if (gameobj->IsDupliGroup())
- {
- if (allgrouplist.insert(blenderobject->dup_group).second)
- {
- grouplist.insert(blenderobject->dup_group);
- }
- }
-
- /* see comment above re: mem leaks */
- gameobj->Release();
- }
- }
- }
- }
- }
- }
-
- // non-camera objects not supported as camera currently
- if (blenderscene->camera && blenderscene->camera->type == OB_CAMERA) {
- KX_Camera *gamecamera= (KX_Camera*) converter->FindGameObject(blenderscene->camera);
-
- if (gamecamera)
- kxscene->SetActiveCamera(gamecamera);
- }
-
- // Set up armatures
- set<Object*>::iterator oit;
- for (oit=allblobj.begin(); oit!=allblobj.end(); oit++)
- {
- Object* blenderobj = *oit;
- if (blenderobj->type==OB_MESH) {
- Mesh *me = (Mesh*)blenderobj->data;
-
- if (me->dvert) {
- BL_DeformableGameObject *obj = (BL_DeformableGameObject*)converter->FindGameObject(blenderobj);
-
- if (obj && BL_ModifierDeformer::HasArmatureDeformer(blenderobj) && blenderobj->parent && blenderobj->parent->type==OB_ARMATURE) {
- KX_GameObject *par = converter->FindGameObject(blenderobj->parent);
- if (par && obj->GetDeformer())
- ((BL_SkinDeformer*)obj->GetDeformer())->SetArmature((BL_ArmatureObject*) par);
- }
- }
- }
- }
-
- // create hierarchy information
- int i;
- vector<parentChildLink>::iterator pcit;
-
- for (pcit = vec_parent_child.begin();!(pcit==vec_parent_child.end());++pcit)
- {
-
- struct Object* blenderchild = pcit->m_blenderchild;
- struct Object* blenderparent = blenderchild->parent;
- KX_GameObject* parentobj = converter->FindGameObject(blenderparent);
- KX_GameObject* childobj = converter->FindGameObject(blenderchild);
-
- assert(childobj);
-
- if (!parentobj || objectlist->SearchValue(childobj) != objectlist->SearchValue(parentobj))
- {
- // special case: the parent and child object are not in the same layer.
- // This weird situation is used in Apricot for test purposes.
- // Resolve it by not converting the child
- childobj->GetSGNode()->DisconnectFromParent();
- delete pcit->m_gamechildnode;
- // Now destroy the child object but also all its descendent that may already be linked
- // Remove the child reference in the local list!
- // Note: there may be descendents already if the children of the child were processed
- // by this loop before the child. In that case, we must remove the children also
- CListValue* childrenlist = childobj->GetChildrenRecursive();
- childrenlist->Add(childobj->AddRef());
- for ( i=0;i<childrenlist->GetCount();i++)
- {
- KX_GameObject* obj = static_cast<KX_GameObject*>(childrenlist->GetValue(i));
- if (sumolist->RemoveValue(obj))
- obj->Release();
- if (logicbrick_conversionlist->RemoveValue(obj))
- obj->Release();
- }
- childrenlist->Release();
-
- // now destroy recursively
- converter->UnregisterGameObject(childobj); // removing objects during conversion make sure this runs too
- kxscene->RemoveObject(childobj);
-
- continue;
- }
-
- switch (blenderchild->partype)
- {
- case PARVERT1:
- {
- // creat a new vertex parent relationship for this node.
- KX_VertexParentRelation * vertex_parent_relation = KX_VertexParentRelation::New();
- pcit->m_gamechildnode->SetParentRelation(vertex_parent_relation);
- break;
- }
- case PARSLOW:
- {
- // creat a new slow parent relationship for this node.
- KX_SlowParentRelation * slow_parent_relation = KX_SlowParentRelation::New(blenderchild->sf);
- pcit->m_gamechildnode->SetParentRelation(slow_parent_relation);
- break;
- }
- case PARBONE:
- {
- // parent this to a bone
- Bone *parent_bone = BKE_armature_find_bone_name(BKE_armature_from_object(blenderchild->parent),
- blenderchild->parsubstr);
-
- if (parent_bone) {
- KX_BoneParentRelation *bone_parent_relation = KX_BoneParentRelation::New(parent_bone);
- pcit->m_gamechildnode->SetParentRelation(bone_parent_relation);
- }
-
- break;
- }
- case PARSKEL: // skinned - ignore
- break;
- case PAROBJECT:
- case PARVERT3:
- default:
- // unhandled
- break;
- }
-
- parentobj-> GetSGNode()->AddChild(pcit->m_gamechildnode);
- }
- vec_parent_child.clear();
-
- // find 'root' parents (object that has not parents in SceneGraph)
- for (i=0;i<sumolist->GetCount();++i)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- if (gameobj->GetSGNode()->GetSGParent() == 0)
- {
- parentlist->Add(gameobj->AddRef());
- gameobj->NodeUpdateGS(0);
- }
- }
-
- // create graphic controller for culling
- if (kxscene->GetDbvtCulling())
- {
- bool occlusion = false;
- for (i=0; i<sumolist->GetCount();i++)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- if (gameobj->GetMeshCount() > 0)
- {
- MT_Point3 box[2];
- gameobj->GetSGNode()->BBox().getmm(box, MT_Transform::Identity());
- // box[0] is the min, box[1] is the max
- bool isactive = objectlist->SearchValue(gameobj);
- BL_CreateGraphicObjectNew(gameobj,box[0],box[1],kxscene,isactive,physics_engine);
- if (gameobj->GetOccluder())
- occlusion = true;
- }
- }
- if (occlusion)
- kxscene->SetDbvtOcclusionRes(blenderscene->gm.occlusionRes);
- }
- if (blenderscene->world)
- kxscene->GetPhysicsEnvironment()->SetNumTimeSubSteps(blenderscene->gm.physubstep);
-
- // now that the scenegraph is complete, let's instantiate the deformers.
- // We need that to create reusable derived mesh and physic shapes
- for (i=0;i<sumolist->GetCount();++i)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- if (gameobj->GetDeformer())
- gameobj->GetDeformer()->UpdateBuckets();
- }
-
- // Set up armature constraints and shapekey drivers
- for (i=0;i<sumolist->GetCount();++i)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
- {
- BL_ArmatureObject *armobj = (BL_ArmatureObject*)gameobj;
- armobj->LoadConstraints(converter);
-
- CListValue *children = armobj->GetChildren();
- for (int j=0; j<children->GetCount();++j)
- {
- BL_ShapeDeformer *deform = dynamic_cast<BL_ShapeDeformer*>(((KX_GameObject*)children->GetValue(j))->GetDeformer());
- if (deform)
- deform->LoadShapeDrivers(armobj);
- }
-
- children->Release();
- }
- }
-
- bool processCompoundChildren = false;
- // create physics information
- for (i=0;i<sumolist->GetCount();i++)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- struct Object* blenderobject = gameobj->GetBlenderObject();
- int nummeshes = gameobj->GetMeshCount();
- RAS_MeshObject* meshobj = 0;
- if (nummeshes > 0)
- {
- meshobj = gameobj->GetMesh(0);
- }
- int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0;
- BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,converter,processCompoundChildren);
- }
-
- processCompoundChildren = true;
- // create physics information
- for (i=0;i<sumolist->GetCount();i++)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- struct Object* blenderobject = gameobj->GetBlenderObject();
- int nummeshes = gameobj->GetMeshCount();
- RAS_MeshObject* meshobj = 0;
- if (nummeshes > 0)
- {
- meshobj = gameobj->GetMesh(0);
- }
- int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0;
- BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,converter,processCompoundChildren);
- }
-
- // create physics joints
- for (i=0;i<sumolist->GetCount();i++)
- {
- PHY_IPhysicsEnvironment *physEnv = kxscene->GetPhysicsEnvironment();
- KX_GameObject *gameobj = (KX_GameObject *)sumolist->GetValue(i);
- struct Object *blenderobject = gameobj->GetBlenderObject();
- ListBase *conlist = get_active_constraints2(blenderobject);
- bConstraint *curcon;
-
- if (!conlist)
- continue;
-
- for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) {
- if (curcon->type != CONSTRAINT_TYPE_RIGIDBODYJOINT)
- continue;
-
- bRigidBodyJointConstraint *dat = (bRigidBodyJointConstraint *)curcon->data;
-
- /* Skip if no target or a child object is selected or constraints are deactivated */
- if (!dat->tar || dat->child || (curcon->flag & CONSTRAINT_OFF))
- continue;
-
- /* Store constraints of grouped and instanced objects for all layers */
- gameobj->AddConstraint(dat);
-
- /** if it's during libload we only add constraints in the object but
- * doesn't create it. Constraint will be replicated later in scene->MergeScene
- */
- if (libloading)
- continue;
-
- /* Skipped already converted constraints.
- * This will happen when a group instance is made from a linked group instance
- * and both are on the active layer. */
- if (bl_isConstraintInList(gameobj, convertedlist))
- continue;
-
- KX_GameObject *gotar = getGameOb(dat->tar->id.name + 2, sumolist);
-
- if (gotar && (gotar->GetLayer()&activeLayerBitInfo) && gotar->GetPhysicsController() &&
- (gameobj->GetLayer()&activeLayerBitInfo) && gameobj->GetPhysicsController())
- {
- physEnv->SetupObjectConstraints(gameobj, gotar, dat);
- }
- }
- }
-
- /* cleanup converted set of group objects */
- set<KX_GameObject*>::iterator gobit;
- for (gobit = convertedlist.begin(); gobit != convertedlist.end(); gobit++)
- (*gobit)->Release();
-
- convertedlist.clear();
- sumolist->Release();
-
- // convert world
- KX_WorldInfo* worldinfo = new KX_WorldInfo(blenderscene, blenderscene->world);
- converter->RegisterWorldInfo(worldinfo);
- kxscene->SetWorldInfo(worldinfo);
-
- //create object representations for obstacle simulation
- KX_ObstacleSimulation* obssimulation = kxscene->GetObstacleSimulation();
- if (obssimulation)
- {
- for ( i=0;i<objectlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(objectlist->GetValue(i));
- struct Object* blenderobject = gameobj->GetBlenderObject();
- if (blenderobject->gameflag & OB_HASOBSTACLE)
- {
- obssimulation->AddObstacleForObj(gameobj);
- }
- }
- }
-
- //process navigation mesh objects
- for ( i=0; i<objectlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(objectlist->GetValue(i));
- struct Object* blenderobject = gameobj->GetBlenderObject();
- if (blenderobject->type==OB_MESH && (blenderobject->gameflag & OB_NAVMESH))
- {
- KX_NavMeshObject* navmesh = static_cast<KX_NavMeshObject*>(gameobj);
- navmesh->SetVisible(0, true);
- navmesh->BuildNavMesh();
- if (obssimulation)
- obssimulation->AddObstaclesForNavMesh(navmesh);
- }
- }
- for ( i=0; i<inactivelist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(inactivelist->GetValue(i));
- struct Object* blenderobject = gameobj->GetBlenderObject();
- if (blenderobject->type==OB_MESH && (blenderobject->gameflag & OB_NAVMESH))
- {
- KX_NavMeshObject* navmesh = static_cast<KX_NavMeshObject*>(gameobj);
- navmesh->SetVisible(0, true);
- }
- }
-
- // convert logic bricks, sensors, controllers and actuators
- for (i=0;i<logicbrick_conversionlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
- struct Object* blenderobj = gameobj->GetBlenderObject();
- int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0;
- bool isInActiveLayer = (blenderobj->lay & layerMask)!=0;
- BL_ConvertActuators(maggie->name, blenderobj,gameobj,logicmgr,kxscene,ketsjiEngine,layerMask,isInActiveLayer,converter);
- }
- for ( i=0;i<logicbrick_conversionlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
- struct Object* blenderobj = gameobj->GetBlenderObject();
- int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0;
- bool isInActiveLayer = (blenderobj->lay & layerMask)!=0;
- BL_ConvertControllers(blenderobj,gameobj,logicmgr, layerMask,isInActiveLayer,converter, libloading);
- }
- for ( i=0;i<logicbrick_conversionlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
- struct Object* blenderobj = gameobj->GetBlenderObject();
- int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0;
- bool isInActiveLayer = (blenderobj->lay & layerMask)!=0;
- BL_ConvertSensors(blenderobj,gameobj,logicmgr,kxscene,ketsjiEngine,layerMask,isInActiveLayer,canvas,converter);
- // set the init state to all objects
- gameobj->SetInitState((blenderobj->init_state)?blenderobj->init_state:blenderobj->state);
- }
- // apply the initial state to controllers, only on the active objects as this registers the sensors
- for ( i=0;i<objectlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(objectlist->GetValue(i));
- gameobj->ResetState();
- }
-
- logicbrick_conversionlist->Release();
-
- // Calculate the scene btree -
- // too slow - commented out.
- //kxscene->SetNodeTree(tf.MakeTree());
-
- // instantiate dupli group, we will loop trough the object
- // that are in active layers. Note that duplicating group
- // has the effect of adding objects at the end of objectlist.
- // Only loop through the first part of the list.
- int objcount = objectlist->GetCount();
- for (i=0;i<objcount;i++)
- {
- KX_GameObject* gameobj = (KX_GameObject*) objectlist->GetValue(i);
- if (gameobj->IsDupliGroup())
- {
- 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_BlenderDataConversion.h b/source/gameengine/Converter/BL_BlenderDataConversion.h
deleted file mode 100644
index c120de85d74..00000000000
--- a/source/gameengine/Converter/BL_BlenderDataConversion.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_BlenderDataConversion.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_BLENDERDATACONVERSION_H__
-#define __BL_BLENDERDATACONVERSION_H__
-
-#include "CTR_HashedPtr.h"
-#include "STR_String.h"
-#include "EXP_Python.h"
-#include "KX_PhysicsEngineEnums.h"
-#include "SCA_IInputDevice.h"
-
-class RAS_MeshObject* BL_ConvertMesh(struct Mesh* mesh,struct Object* lightobj,class KX_Scene* scene, class KX_BlenderSceneConverter *converter, bool libloading);
-
-void BL_ConvertBlenderObjects(struct Main* maggie,
- class KX_Scene* kxscene,
- class KX_KetsjiEngine* ketsjiEngine,
- e_PhysicsEngine physics_engine,
- class RAS_IRasterizer* rendertools,
- class RAS_ICanvas* canvas,
- class KX_BlenderSceneConverter* sceneconverter,
- bool alwaysUseExpandFraming,
- bool libloading=false
- );
-
-SCA_IInputDevice::KX_EnumInputs ConvertKeyCode(int key_code);
-
-#endif /* __BL_BLENDERDATACONVERSION_H__ */
diff --git a/source/gameengine/Converter/BL_DeformableGameObject.cpp b/source/gameengine/Converter/BL_DeformableGameObject.cpp
deleted file mode 100644
index bd29ac4d72e..00000000000
--- a/source/gameengine/Converter/BL_DeformableGameObject.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_DeformableGameObject.cpp
- * \ingroup bgeconv
- */
-
-
-#include "BL_DeformableGameObject.h"
-#include "BL_ShapeDeformer.h"
-#include "BL_ShapeActionActuator.h"
-#include "RAS_MaterialBucket.h"
-
-
-BL_DeformableGameObject::~BL_DeformableGameObject()
-{
- if (m_pDeformer)
- delete m_pDeformer; // __NLA : Temporary until we decide where to put this
-}
-
-void BL_DeformableGameObject::ProcessReplica()
-{
- KX_GameObject::ProcessReplica();
-
- if (m_pDeformer)
- m_pDeformer= (BL_MeshDeformer*)m_pDeformer->GetReplica();
-}
-
-CValue* BL_DeformableGameObject::GetReplica()
-{
-
- BL_DeformableGameObject* replica = new BL_DeformableGameObject(*this);//m_float,GetName());
- replica->ProcessReplica();
- return replica;
-}
-
-bool BL_DeformableGameObject::SetActiveAction(BL_ShapeActionActuator *act, short priority, double curtime)
-{
- if (curtime != m_lastframe) {
- m_activePriority = 9999;
- m_lastframe= curtime;
- m_activeAct = NULL;
- }
-
- if (priority<=m_activePriority)
- {
- if (m_activeAct && (m_activeAct!=act))
- m_activeAct->SetBlendTime(0.0f); /* Reset the blend timer */
- m_activeAct = act;
- m_activePriority = priority;
- m_lastframe = curtime;
-
- return true;
- }
- else {
- act->SetBlendTime(0.0f);
- return false;
- }
-}
-
-bool BL_DeformableGameObject::GetShape(vector<float> &shape)
-{
- shape.clear();
- BL_ShapeDeformer* shape_deformer = dynamic_cast<BL_ShapeDeformer*>(m_pDeformer);
- if (shape_deformer)
- {
- // this check is normally superfluous: a shape deformer can only be created if the mesh
- // has relative keys
- Key* key = shape_deformer->GetKey();
- if (key && key->type==KEY_RELATIVE)
- {
- KeyBlock *kb;
- for (kb = (KeyBlock *)key->block.first; kb; kb = (KeyBlock *)kb->next)
- {
- shape.push_back(kb->curval);
- }
- }
- }
- return !shape.empty();
-}
-
-void BL_DeformableGameObject::SetDeformer(class RAS_Deformer* deformer)
-{
- m_pDeformer = deformer;
-
- SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
- for (mit.begin(); !mit.end(); ++mit)
- {
- (*mit)->SetDeformer(deformer);
- }
-}
-
diff --git a/source/gameengine/Converter/BL_DeformableGameObject.h b/source/gameengine/Converter/BL_DeformableGameObject.h
deleted file mode 100644
index 6a97e57e477..00000000000
--- a/source/gameengine/Converter/BL_DeformableGameObject.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_DeformableGameObject.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_DEFORMABLEGAMEOBJECT_H__
-#define __BL_DEFORMABLEGAMEOBJECT_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
-#endif
-
-#include "DNA_mesh_types.h"
-#include "KX_GameObject.h"
-#include "BL_MeshDeformer.h"
-#include "KX_SoftBodyDeformer.h"
-#include <vector>
-
-class BL_ShapeActionActuator;
-struct Key;
-
-class BL_DeformableGameObject : public KX_GameObject
-{
-public:
- CValue* GetReplica();
-
- double GetLastFrame ()
- {
- return m_lastframe;
- }
- Object* GetBlendObject()
- {
- return m_blendobj;
- }
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*>*map)
- {
- if (m_pDeformer)
- m_pDeformer->Relink (map);
- KX_GameObject::Relink(map);
- };
- void ProcessReplica();
-
- BL_DeformableGameObject(Object* blendobj, void* sgReplicationInfo, SG_Callbacks callbacks) :
- KX_GameObject(sgReplicationInfo,callbacks),
- m_pDeformer(NULL),
- m_activeAct(NULL),
- m_lastframe(0.0),
- m_blendobj(blendobj),
- m_activePriority(9999)
- {
- m_isDeformable = true;
- };
- virtual ~BL_DeformableGameObject();
- bool SetActiveAction(class BL_ShapeActionActuator *act, short priority, double curtime);
-
- bool GetShape(vector<float> &shape);
-
- virtual void SetDeformer(class RAS_Deformer* deformer);
- virtual class RAS_Deformer* GetDeformer()
- {
- return m_pDeformer;
- }
-
-public:
-
-protected:
-
- RAS_Deformer *m_pDeformer;
-
- class BL_ShapeActionActuator *m_activeAct;
- double m_lastframe;
- Object* m_blendobj;
- short m_activePriority;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_DeformableGameObject")
-#endif
-};
-
-#endif /* __BL_DEFORMABLEGAMEOBJECT_H__ */
diff --git a/source/gameengine/Converter/BL_MeshDeformer.cpp b/source/gameengine/Converter/BL_MeshDeformer.cpp
deleted file mode 100644
index 3b5f12d7b29..00000000000
--- a/source/gameengine/Converter/BL_MeshDeformer.cpp
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Simple deformation controller that restores a mesh to its rest position
- */
-
-/** \file gameengine/Converter/BL_MeshDeformer.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
- /* This warning tells us about truncation of __long__ stl-generated names.
- * It can occasionally cause DevStudio to have internal compiler warnings. */
-# pragma warning( disable:4786 )
-#endif
-
-#include "RAS_IPolygonMaterial.h"
-#include "BL_DeformableGameObject.h"
-#include "BL_MeshDeformer.h"
-#include "RAS_MeshObject.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-
-#include "CTR_Map.h"
-#include "STR_HashedString.h"
-#include "BLI_math.h"
-
-bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*)
-{
- size_t i;
-
- // only apply once per frame if the mesh is actually modified
- if (m_pMeshObject->MeshModified() &&
- m_lastDeformUpdate != m_gameobj->GetLastFrame())
- {
- // For each material
- for (list<RAS_MeshMaterial>::iterator mit= m_pMeshObject->GetFirstMaterial();
- mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
- if (!mit->m_slots[(void*)m_gameobj])
- continue;
-
- RAS_MeshSlot *slot = *mit->m_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 (i=it.startvertex; i<it.endvertex; i++) {
- RAS_TexVert& v = it.vertex[i];
- v.SetXYZ(m_bmesh->mvert[v.getOrigIndex()].co);
- }
- }
- }
-
- m_lastDeformUpdate = m_gameobj->GetLastFrame();
-
- return true;
- }
-
- return false;
-}
-
-BL_MeshDeformer::~BL_MeshDeformer()
-{
- if (m_transverts)
- delete [] m_transverts;
- if (m_transnors)
- delete [] m_transnors;
-}
-
-void BL_MeshDeformer::ProcessReplica()
-{
- m_transverts = NULL;
- m_transnors = NULL;
- m_tvtot = 0;
- m_bDynamic=false;
- m_lastDeformUpdate = -1;
-}
-
-void BL_MeshDeformer::Relink(CTR_Map<class CTR_HashedPtr, void*>*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!
- */
-void BL_MeshDeformer::RecalcNormals()
-{
- /* We don't normalize for performance, not doing it for faces normals
- * 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 */
- list<RAS_MeshMaterial>::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 (mit = m_pMeshObject->GetFirstMaterial();
- mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
- if (!mit->m_slots[(void*)m_gameobj])
- continue;
-
- RAS_MeshSlot *slot = *mit->m_slots[(void*)m_gameobj];
-
- for (slot->begin(it); !slot->end(it); slot->next(it)) {
- int nvert = (int)it.array->m_type;
-
- for (i=0; i<it.totindex; i+=nvert) {
- RAS_TexVert& v1 = it.vertex[it.index[i]];
- RAS_TexVert& v2 = it.vertex[it.index[i+1]];
- RAS_TexVert& v3 = it.vertex[it.index[i+2]];
- RAS_TexVert *v4 = NULL;
-
- const float *co1 = m_transverts[v1.getOrigIndex()];
- const float *co2 = m_transverts[v2.getOrigIndex()];
- const float *co3 = m_transverts[v3.getOrigIndex()];
- const float *co4 = NULL;
-
- /* compute face normal */
- float fnor[3], n1[3], n2[3];
-
- if (nvert == 4) {
- v4 = &it.vertex[it.index[i+3]];
- co4 = m_transverts[v4->getOrigIndex()];
-
- n1[0] = co1[0] - co3[0];
- n1[1] = co1[1] - co3[1];
- n1[2] = co1[2] - co3[2];
-
- n2[0] = co2[0] - co4[0];
- n2[1] = co2[1] - co4[1];
- n2[2] = co2[2] - co4[2];
- }
- else {
- n1[0] = co1[0] - co2[0];
- n2[0] = co2[0] - co3[0];
- n1[1] = co1[1] - co2[1];
-
- n2[1] = co2[1] - co3[1];
- n1[2] = co1[2] - co2[2];
- n2[2] = co2[2] - co3[2];
- }
-
- fnor[0] = n1[1] * n2[2] - n1[2] * n2[1];
- fnor[1] = n1[2] * n2[0] - n1[0] * n2[2];
- fnor[2] = n1[0] * n2[1] - n1[1] * n2[0];
- normalize_v3(fnor);
-
- /* add to vertices for smooth normals */
- float *vn1 = m_transnors[v1.getOrigIndex()];
- float *vn2 = m_transnors[v2.getOrigIndex()];
- float *vn3 = m_transnors[v3.getOrigIndex()];
-
- vn1[0] += fnor[0]; vn1[1] += fnor[1]; vn1[2] += fnor[2];
- vn2[0] += fnor[0]; vn2[1] += fnor[1]; vn2[2] += fnor[2];
- vn3[0] += fnor[0]; vn3[1] += fnor[1]; vn3[2] += fnor[2];
-
- if (v4) {
- float *vn4 = m_transnors[v4->getOrigIndex()];
- vn4[0] += fnor[0]; vn4[1] += fnor[1]; vn4[2] += fnor[2];
- }
-
- /* in case of flat - just assign, the vertices are split */
- if (v1.getFlag() & RAS_TexVert::FLAT) {
- v1.SetNormal(fnor);
- v2.SetNormal(fnor);
- v3.SetNormal(fnor);
- if (v4)
- v4->SetNormal(fnor);
- }
- }
- }
- }
-
- /* assign smooth vertex normals */
- for (mit = m_pMeshObject->GetFirstMaterial();
- mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
- if (!mit->m_slots[(void*)m_gameobj])
- continue;
-
- RAS_MeshSlot *slot = *mit->m_slots[(void*)m_gameobj];
-
- for (slot->begin(it); !slot->end(it); slot->next(it)) {
- for (i=it.startvertex; i<it.endvertex; i++) {
- RAS_TexVert& v = it.vertex[i];
-
- if (!(v.getFlag() & RAS_TexVert::FLAT))
- v.SetNormal(m_transnors[v.getOrigIndex()]); //.safe_normalized()
- }
- }
- }
-}
-
-void BL_MeshDeformer::VerifyStorage()
-{
- /* Ensure that we have the right number of verts assigned */
- if (m_tvtot!=m_bmesh->totvert) {
- if (m_transverts)
- delete [] m_transverts;
- if (m_transnors)
- delete [] m_transnors;
-
- m_transverts=new float[m_bmesh->totvert][3];
- m_transnors=new float[m_bmesh->totvert][3];
- m_tvtot = m_bmesh->totvert;
- }
-}
-
diff --git a/source/gameengine/Converter/BL_MeshDeformer.h b/source/gameengine/Converter/BL_MeshDeformer.h
deleted file mode 100644
index f2073994a4a..00000000000
--- a/source/gameengine/Converter/BL_MeshDeformer.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_MeshDeformer.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_MESHDEFORMER_H__
-#define __BL_MESHDEFORMER_H__
-
-#include "RAS_Deformer.h"
-#include "DNA_object_types.h"
-#include "DNA_key_types.h"
-#include "MT_Point3.h"
-#include <stdlib.h>
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* get rid of stupid stl-visual compiler debug warning */
-#endif
-
-class BL_DeformableGameObject;
-
-class BL_MeshDeformer : public RAS_Deformer
-{
-public:
- void VerifyStorage();
- void RecalcNormals();
- virtual void Relink(CTR_Map<class CTR_HashedPtr, void*>*map);
- BL_MeshDeformer(BL_DeformableGameObject *gameobj,
- struct Object* obj,
- class RAS_MeshObject *meshobj ):
- m_pMeshObject(meshobj),
- m_bmesh((struct Mesh*)(obj->data)),
- m_transverts(0),
- m_transnors(0),
- m_objMesh(obj),
- m_tvtot(0),
- m_gameobj(gameobj),
- m_lastDeformUpdate(-1)
- {};
- virtual ~BL_MeshDeformer();
- virtual void SetSimulatedTime(double time) {}
- virtual bool Apply(class RAS_IPolyMaterial *mat);
- virtual bool Update(void) { return false; }
- virtual bool UpdateBuckets(void) { return false; }
- virtual RAS_Deformer* GetReplica() {return NULL;}
- virtual void ProcessReplica();
- struct Mesh* GetMesh() { return m_bmesh; }
- virtual class RAS_MeshObject* GetRasMesh() { return m_pMeshObject; }
- virtual float (* GetTransVerts(int *tot))[3] { *tot= m_tvtot; return m_transverts; }
- // virtual void InitDeform(double time) {}
-
-protected:
- class RAS_MeshObject* m_pMeshObject;
- struct Mesh* m_bmesh;
-
- // this is so m_transverts doesn't need to be converted
- // before deformation
- float (*m_transverts)[3];
- float (*m_transnors)[3];
- struct Object* m_objMesh;
- // --
- int m_tvtot;
- BL_DeformableGameObject* m_gameobj;
- double m_lastDeformUpdate;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_MeshDeformer")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Converter/BL_ModifierDeformer.cpp b/source/gameengine/Converter/BL_ModifierDeformer.cpp
deleted file mode 100644
index 44b24927843..00000000000
--- a/source/gameengine/Converter/BL_ModifierDeformer.cpp
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ModifierDeformer.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include "MEM_guardedalloc.h"
-#include "BL_ModifierDeformer.h"
-#include "CTR_Map.h"
-#include "STR_HashedString.h"
-#include "RAS_IPolygonMaterial.h"
-#include "RAS_MeshObject.h"
-#include "PHY_IGraphicController.h"
-
-#include "DNA_armature_types.h"
-#include "DNA_action_types.h"
-#include "DNA_key_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_curve_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_scene_types.h"
-#include "BLI_utildefines.h"
-#include "BKE_armature.h"
-#include "BKE_action.h"
-#include "BKE_key.h"
-#include "BKE_ipo.h"
-#include "MT_Point3.h"
-
-extern "C"{
- #include "BKE_customdata.h"
- #include "BKE_DerivedMesh.h"
- #include "BKE_lattice.h"
- #include "BKE_modifier.h"
-}
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-
-BL_ModifierDeformer::~BL_ModifierDeformer()
-{
- if (m_dm) {
- // deformedOnly is used as a user counter
- if (--m_dm->deformedOnly == 0) {
- m_dm->needsFree = 1;
- m_dm->release(m_dm);
- }
- }
-};
-
-RAS_Deformer *BL_ModifierDeformer::GetReplica()
-{
- BL_ModifierDeformer *result;
-
- result = new BL_ModifierDeformer(*this);
- result->ProcessReplica();
- return result;
-}
-
-void BL_ModifierDeformer::ProcessReplica()
-{
- /* Note! - This is not inherited from PyObjectPlus */
- BL_ShapeDeformer::ProcessReplica();
- if (m_dm)
- // by default try to reuse mesh, deformedOnly is used as a user count
- m_dm->deformedOnly++;
- // this will force an update and if the mesh cannot be reused, a new one will be created
- m_lastModifierUpdate = -1;
-}
-
-bool BL_ModifierDeformer::HasCompatibleDeformer(Object *ob)
-{
- if (!ob->modifiers.first)
- return false;
- // soft body cannot use mesh modifiers
- if ((ob->gameflag & OB_SOFT_BODY) != 0)
- return false;
- ModifierData* md;
- for (md = (ModifierData *)ob->modifiers.first; md; md = md->next) {
- if (modifier_dependsOnTime(md))
- continue;
- if (!(md->mode & eModifierMode_Realtime))
- continue;
- /* armature modifier are handled by SkinDeformer, not ModifierDeformer */
- if (md->type == eModifierType_Armature )
- continue;
- return true;
- }
- return false;
-}
-
-bool BL_ModifierDeformer::HasArmatureDeformer(Object *ob)
-{
- if (!ob->modifiers.first)
- return false;
-
- ModifierData* md = (ModifierData*)ob->modifiers.first;
- if (md->type == eModifierType_Armature )
- return true;
-
- return false;
-}
-
-// return a deformed mesh that supports mapping (with a valid CD_ORIGINDEX layer)
-struct DerivedMesh* BL_ModifierDeformer::GetPhysicsMesh()
-{
- /* we need to compute the deformed mesh taking into account the current
- * shape and skin deformers, we cannot just call mesh_create_derived_physics()
- * because that would use the m_transvers already deformed previously by BL_ModifierDeformer::Update(),
- * so restart from scratch by forcing a full update the shape/skin deformers
- * (will do nothing if there is no such deformer) */
- BL_ShapeDeformer::ForceUpdate();
- BL_ShapeDeformer::Update();
- // now apply the modifiers but without those that don't support mapping
- Object* blendobj = m_gameobj->GetBlendObject();
- /* hack: the modifiers require that the mesh is attached to the object
- * It may not be the case here because of replace mesh actuator */
- Mesh *oldmesh = (Mesh*)blendobj->data;
- blendobj->data = m_bmesh;
- DerivedMesh *dm = mesh_create_derived_physics(m_scene, blendobj, m_transverts, CD_MASK_MESH);
- /* restore object data */
- blendobj->data = oldmesh;
- /* m_transverts is correct here (takes into account deform only modifiers) */
- /* the derived mesh returned by this function must be released by the caller !!! */
- return dm;
-}
-
-bool BL_ModifierDeformer::Update(void)
-{
- bool bShapeUpdate = BL_ShapeDeformer::Update();
-
- if (bShapeUpdate || m_lastModifierUpdate != m_gameobj->GetLastFrame()) {
- // static derived mesh are not updated
- if (m_dm == NULL || m_bDynamic) {
- /* execute the modifiers */
- Object* blendobj = m_gameobj->GetBlendObject();
- /* hack: the modifiers require that the mesh is attached to the object
- * It may not be the case here because of replace mesh actuator */
- Mesh *oldmesh = (Mesh*)blendobj->data;
- blendobj->data = m_bmesh;
- /* execute the modifiers */
- DerivedMesh *dm = mesh_create_derived_no_virtual(m_scene, blendobj, m_transverts, CD_MASK_MESH);
- /* restore object data */
- blendobj->data = oldmesh;
- /* free the current derived mesh and replace, (dm should never be NULL) */
- if (m_dm != NULL) {
- // HACK! use deformedOnly as a user counter
- if (--m_dm->deformedOnly == 0) {
- m_dm->needsFree = 1;
- m_dm->release(m_dm);
- }
- }
- m_dm = dm;
- // get rid of temporary data
- m_dm->needsFree = 0;
- m_dm->release(m_dm);
- // HACK! use deformedOnly as a user counter
- m_dm->deformedOnly = 1;
- DM_update_materials(m_dm, blendobj);
- /* update the graphic controller */
- PHY_IGraphicController *ctrl = m_gameobj->GetGraphicController();
- if (ctrl) {
- float min[3], max[3];
- INIT_MINMAX(min, max);
- m_dm->getMinMax(m_dm, min, max);
- ctrl->SetLocalAabb(min, max);
- }
- }
- m_lastModifierUpdate=m_gameobj->GetLastFrame();
- bShapeUpdate = true;
-
- int nmat = m_pMeshObject->NumMaterials();
- for (int imat=0; imat<nmat; imat++) {
- RAS_MeshMaterial *mmat = m_pMeshObject->GetMeshMaterial(imat);
- RAS_MeshSlot **slot = mmat->m_slots[(void*)m_gameobj];
- if (!slot || !*slot)
- continue;
- (*slot)->m_pDerivedMesh = m_dm;
- }
- }
- return bShapeUpdate;
-}
-
-bool BL_ModifierDeformer::Apply(RAS_IPolyMaterial *mat)
-{
- if (!Update())
- return false;
-
- return true;
-}
diff --git a/source/gameengine/Converter/BL_ModifierDeformer.h b/source/gameengine/Converter/BL_ModifierDeformer.h
deleted file mode 100644
index 7de64745534..00000000000
--- a/source/gameengine/Converter/BL_ModifierDeformer.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ModifierDeformer.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_MODIFIERDEFORMER_H__
-#define __BL_MODIFIERDEFORMER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* get rid of stupid stl-visual compiler debug warning */
-#endif
-
-#include "BL_ShapeDeformer.h"
-#include "BL_DeformableGameObject.h"
-#include <vector>
-
-struct DerivedMesh;
-struct Object;
-
-class BL_ModifierDeformer : public BL_ShapeDeformer
-{
-public:
- static bool HasCompatibleDeformer(Object *ob);
- static bool HasArmatureDeformer(Object *ob);
-
-
- BL_ModifierDeformer(BL_DeformableGameObject *gameobj,
- Scene *scene,
- Object *bmeshobj,
- RAS_MeshObject *mesh)
- :
- BL_ShapeDeformer(gameobj,bmeshobj, mesh),
- m_lastModifierUpdate(-1),
- m_scene(scene),
- m_dm(NULL)
- {
- m_recalcNormal = false;
- }
-
- /* this second constructor is needed for making a mesh deformable on the fly. */
- BL_ModifierDeformer(BL_DeformableGameObject *gameobj,
- struct Scene *scene,
- struct Object *bmeshobj_old,
- struct Object *bmeshobj_new,
- class RAS_MeshObject *mesh,
- bool release_object,
- BL_ArmatureObject* arma = NULL)
- :
- BL_ShapeDeformer(gameobj, bmeshobj_old, bmeshobj_new, mesh, release_object, false, arma),
- m_lastModifierUpdate(-1),
- m_scene(scene),
- m_dm(NULL)
- {
- /* pass */
- }
-
- virtual void ProcessReplica();
- virtual RAS_Deformer *GetReplica();
- virtual ~BL_ModifierDeformer();
- virtual bool UseVertexArray()
- {
- return false;
- }
-
- bool Update (void);
- bool Apply(RAS_IPolyMaterial *mat);
- void ForceUpdate()
- {
- m_lastModifierUpdate = -1.0;
- };
- virtual struct DerivedMesh* GetFinalMesh()
- {
- return m_dm;
- }
- // The derived mesh returned by this function must be released!
- virtual struct DerivedMesh* GetPhysicsMesh();
-
-protected:
- double m_lastModifierUpdate;
- Scene *m_scene;
- DerivedMesh *m_dm;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_ModifierDeformer")
-#endif
-};
-
-#endif /* __BL_MODIFIERDEFORMER_H__ */
diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp
deleted file mode 100644
index 38eab7d5c30..00000000000
--- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp
+++ /dev/null
@@ -1,563 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ShapeActionActuator.cpp
- * \ingroup bgeconv
- */
-
-
-#include <cmath>
-
-#include "SCA_LogicManager.h"
-#include "BL_ShapeActionActuator.h"
-#include "BL_ShapeDeformer.h"
-#include "KX_GameObject.h"
-#include "STR_HashedString.h"
-#include "DNA_nla_types.h"
-#include "DNA_action_types.h"
-#include "DNA_anim_types.h"
-#include "DNA_scene_types.h"
-#include "BKE_action.h"
-#include "DNA_armature_types.h"
-#include "MEM_guardedalloc.h"
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "MT_Matrix4x4.h"
-
-#include "EXP_FloatValue.h"
-#include "EXP_PyObjectPlus.h"
-
-extern "C" {
- #include "BKE_animsys.h"
- #include "BKE_key.h"
- #include "RNA_access.h"
-}
-
-BL_ShapeActionActuator::BL_ShapeActionActuator(SCA_IObject* gameobj,
- const STR_String& propname,
- const STR_String& framepropname,
- float starttime,
- float endtime,
- struct bAction *action,
- short playtype,
- short blendin,
- short priority,
- float stride)
- : SCA_IActuator(gameobj, KX_ACT_SHAPEACTION),
-
- m_lastpos(0, 0, 0),
- m_blendframe(0),
- m_flag(0),
- m_startframe (starttime),
- m_endframe(endtime) ,
- m_starttime(0),
- m_localtime(starttime),
- m_lastUpdate(-1),
- m_blendin(blendin),
- m_blendstart(0),
- m_stridelength(stride),
- m_playtype(playtype),
- m_priority(priority),
- m_action(action),
- m_framepropname(framepropname),
- m_propname(propname)
-{
- m_idptr = new PointerRNA();
- BL_DeformableGameObject *obj = (BL_DeformableGameObject*)GetParent();
- BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer());
- RNA_id_pointer_create(&shape_deformer->GetKey()->id, m_idptr);
-};
-
-BL_ShapeActionActuator::~BL_ShapeActionActuator()
-{
- if (m_idptr)
- delete m_idptr;
-}
-
-void BL_ShapeActionActuator::ProcessReplica()
-{
- SCA_IActuator::ProcessReplica();
- m_localtime=m_startframe;
- m_lastUpdate=-1;
-}
-
-void BL_ShapeActionActuator::SetBlendTime(float newtime)
-{
- m_blendframe = newtime;
-}
-
-CValue* BL_ShapeActionActuator::GetReplica()
-{
- BL_ShapeActionActuator* replica = new BL_ShapeActionActuator(*this);//m_float,GetName());
- replica->ProcessReplica();
- return replica;
-}
-
-bool BL_ShapeActionActuator::ClampLocalTime()
-{
- if (m_startframe < m_endframe) {
- if (m_localtime < m_startframe)
- {
- m_localtime = m_startframe;
- return true;
- }
- else if (m_localtime > m_endframe)
- {
- m_localtime = m_endframe;
- return true;
- }
- } else {
- if (m_localtime > m_startframe)
- {
- m_localtime = m_startframe;
- return true;
- }
- else if (m_localtime < m_endframe)
- {
- m_localtime = m_endframe;
- return true;
- }
- }
- return false;
-}
-
-void BL_ShapeActionActuator::SetStartTime(float curtime)
-{
- float direction = m_startframe < m_endframe ? 1.0 : -1.0;
-
- if (!(m_flag & ACT_FLAG_REVERSE))
- m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate();
- else
- m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate();
-}
-
-void BL_ShapeActionActuator::SetLocalTime(float curtime)
-{
- float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate();
-
- if (m_endframe < m_startframe)
- delta_time = -delta_time;
-
- if (!(m_flag & ACT_FLAG_REVERSE))
- m_localtime = m_startframe + delta_time;
- else
- m_localtime = m_endframe - delta_time;
-}
-
-void BL_ShapeActionActuator::BlendShape(Key* key, float srcweight)
-{
- vector<float>::const_iterator it;
- float dstweight;
- KeyBlock *kb;
-
- dstweight = 1.0F - srcweight;
-
- for (it=m_blendshape.begin(), kb = (KeyBlock *)key->block.first;
- kb && it != m_blendshape.end();
- kb = (KeyBlock *)kb->next, it++)
- {
- kb->curval = kb->curval * dstweight + (*it) * srcweight;
- }
-}
-
-bool BL_ShapeActionActuator::Update(double curtime, bool frame)
-{
- bool bNegativeEvent = false;
- bool bPositiveEvent = false;
- bool keepgoing = true;
- bool wrap = false;
- bool apply=true;
- int priority;
- float newweight;
-
- curtime -= KX_KetsjiEngine::GetSuspendedDelta();
-
- // result = true if animation has to be continued, false if animation stops
- // maybe there are events for us in the queue !
- if (frame)
- {
- bNegativeEvent = m_negevent;
- bPositiveEvent = m_posevent;
- RemoveAllEvents();
-
- if (bPositiveEvent)
- m_flag |= ACT_FLAG_ACTIVE;
-
- if (bNegativeEvent)
- {
- if (!(m_flag & ACT_FLAG_ACTIVE))
- return false;
- m_flag &= ~ACT_FLAG_ACTIVE;
- }
- }
-
- /* This action can only be attached to a deform object */
- BL_DeformableGameObject *obj = (BL_DeformableGameObject*)GetParent();
- float length = m_endframe - m_startframe;
-
- priority = m_priority;
-
- /* Determine pre-incrementation behavior and set appropriate flags */
- switch (m_playtype) {
- case ACT_ACTION_MOTION:
- if (bNegativeEvent) {
- keepgoing=false;
- apply=false;
- };
- break;
- case ACT_ACTION_FROM_PROP:
- if (bNegativeEvent) {
- apply=false;
- keepgoing=false;
- }
- break;
- case ACT_ACTION_LOOP_END:
- if (bPositiveEvent) {
- if (!(m_flag & ACT_FLAG_LOCKINPUT)) {
- m_flag &= ~ACT_FLAG_KEYUP;
- m_flag &= ~ACT_FLAG_REVERSE;
- m_flag |= ACT_FLAG_LOCKINPUT;
- m_localtime = m_startframe;
- m_starttime = curtime;
- }
- }
- if (bNegativeEvent) {
- m_flag |= ACT_FLAG_KEYUP;
- }
- break;
- case ACT_ACTION_LOOP_STOP:
- if (bPositiveEvent) {
- if (!(m_flag & ACT_FLAG_LOCKINPUT)) {
- m_flag &= ~ACT_FLAG_REVERSE;
- m_flag &= ~ACT_FLAG_KEYUP;
- m_flag |= ACT_FLAG_LOCKINPUT;
- SetStartTime(curtime);
- }
- }
- if (bNegativeEvent) {
- m_flag |= ACT_FLAG_KEYUP;
- m_flag &= ~ACT_FLAG_LOCKINPUT;
- keepgoing=false;
- apply=false;
- }
- break;
- case ACT_ACTION_PINGPONG:
- if (bPositiveEvent) {
- if (!(m_flag & ACT_FLAG_LOCKINPUT)) {
- m_flag &= ~ACT_FLAG_KEYUP;
- m_localtime = m_starttime;
- m_starttime = curtime;
- m_flag |= ACT_FLAG_LOCKINPUT;
- }
- }
- break;
- case ACT_ACTION_FLIPPER:
- if (bPositiveEvent) {
- if (!(m_flag & ACT_FLAG_LOCKINPUT)) {
- m_flag &= ~ACT_FLAG_REVERSE;
- m_flag |= ACT_FLAG_LOCKINPUT;
- SetStartTime(curtime);
- }
- }
- else if (bNegativeEvent) {
- m_flag |= ACT_FLAG_REVERSE;
- m_flag &= ~ACT_FLAG_LOCKINPUT;
- SetStartTime(curtime);
- }
- break;
- case ACT_ACTION_PLAY:
- if (bPositiveEvent) {
- if (!(m_flag & ACT_FLAG_LOCKINPUT)) {
- m_flag &= ~ACT_FLAG_REVERSE;
- m_localtime = m_starttime;
- m_starttime = curtime;
- m_flag |= ACT_FLAG_LOCKINPUT;
- }
- }
- break;
- default:
- break;
- }
-
- /* Perform increment */
- if (keepgoing) {
- if (m_playtype == ACT_ACTION_MOTION) {
- MT_Point3 newpos;
- MT_Point3 deltapos;
-
- newpos = obj->NodeGetWorldPosition();
-
- /* Find displacement */
- deltapos = newpos-m_lastpos;
- m_localtime += (length/m_stridelength) * deltapos.length();
- m_lastpos = newpos;
- }
- else {
- SetLocalTime(curtime);
- }
- }
-
- /* Check if a wrapping response is needed */
- if (length) {
- if (m_localtime < m_startframe || m_localtime > m_endframe)
- {
- m_localtime = m_startframe + fmod(m_localtime, length);
- wrap = true;
- }
- }
- else
- m_localtime = m_startframe;
-
- /* Perform post-increment tasks */
- switch (m_playtype) {
- case ACT_ACTION_FROM_PROP:
- {
- CValue* propval = GetParent()->GetProperty(m_propname);
- if (propval)
- m_localtime = propval->GetNumber();
-
- if (bNegativeEvent) {
- keepgoing=false;
- }
- }
- break;
- case ACT_ACTION_MOTION:
- break;
- case ACT_ACTION_LOOP_STOP:
- break;
- case ACT_ACTION_PINGPONG:
- if (wrap) {
- if (!(m_flag & ACT_FLAG_REVERSE))
- m_localtime = m_endframe;
- else
- m_localtime = m_startframe;
-
- m_flag &= ~ACT_FLAG_LOCKINPUT;
- m_flag ^= ACT_FLAG_REVERSE; //flip direction
- keepgoing = false;
- }
- break;
- case ACT_ACTION_FLIPPER:
- if (wrap) {
- if (!(m_flag & ACT_FLAG_REVERSE)) {
- m_localtime=m_endframe;
- //keepgoing = false;
- }
- else {
- m_localtime=m_startframe;
- keepgoing = false;
- }
- }
- break;
- case ACT_ACTION_LOOP_END:
- if (wrap) {
- if (m_flag & ACT_FLAG_KEYUP) {
- keepgoing = false;
- m_localtime = m_endframe;
- m_flag &= ~ACT_FLAG_LOCKINPUT;
- }
- SetStartTime(curtime);
- }
- break;
- case ACT_ACTION_PLAY:
- if (wrap) {
- m_localtime = m_endframe;
- keepgoing = false;
- m_flag &= ~ACT_FLAG_LOCKINPUT;
- }
- break;
- default:
- keepgoing = false;
- break;
- }
-
- /* Set the property if its defined */
- if (m_framepropname[0] != '\0') {
- CValue* propowner = GetParent();
- CValue* oldprop = propowner->GetProperty(m_framepropname);
- CValue* newval = new CFloatValue(m_localtime);
- if (oldprop) {
- oldprop->SetValue(newval);
- } else {
- propowner->SetProperty(m_framepropname, newval);
- }
- newval->Release();
- }
-
- if (bNegativeEvent)
- m_blendframe=0.0f;
-
- /* Apply the pose if necessary*/
- if (apply) {
-
- /* Priority test */
- if (obj->SetActiveAction(this, priority, curtime)) {
- BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer());
- Key *key = NULL;
-
- if (shape_deformer)
- key = shape_deformer->GetKey();
-
- if (!key) {
- // this could happen if the mesh was changed in the middle of an action
- // and the new mesh has no key, stop the action
- keepgoing = false;
- }
- else {
- ListBase tchanbase= {NULL, NULL};
-
- if (m_blendin && m_blendframe==0.0f) {
- // this is the start of the blending, remember the startup shape
- obj->GetShape(m_blendshape);
- m_blendstart = curtime;
- }
-
- KeyBlock *kb;
- // We go through and clear out the keyblocks so there isn't any interference
- // from other shape actions
- for (kb=(KeyBlock *)key->block.first; kb; kb=(KeyBlock *)kb->next)
- kb->curval = 0.f;
-
- animsys_evaluate_action(m_idptr, m_action, NULL, m_localtime);
-
- // XXX - in 2.5 theres no way to do this. possibly not that important to support - Campbell
- if (0) { // XXX !execute_ipochannels(&tchanbase)) {
- // no update, this is possible if action does not match the keys, stop the action
- keepgoing = false;
- }
- else {
- // the key have changed, apply blending if needed
- if (m_blendin && (m_blendframe<m_blendin)) {
- newweight = (m_blendframe/(float)m_blendin);
-
- BlendShape(key, 1.0f - newweight);
-
- /* Increment current blending percentage */
- m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate();
- if (m_blendframe>m_blendin)
- m_blendframe = m_blendin;
- }
- m_lastUpdate = m_localtime;
- }
- BLI_freelistN(&tchanbase);
- }
- }
- else {
- m_blendframe = 0.0f;
- }
- }
-
- if (!keepgoing) {
- m_blendframe = 0.0f;
- }
- return keepgoing;
-};
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-
-PyTypeObject BL_ShapeActionActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ShapeActionActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-
-PyMethodDef BL_ShapeActionActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef BL_ShapeActionActuator::Attributes[] = {
- KX_PYATTRIBUTE_FLOAT_RW("frameStart", 0, MAXFRAMEF, BL_ShapeActionActuator, m_startframe),
- KX_PYATTRIBUTE_FLOAT_RW("frameEnd", 0, MAXFRAMEF, BL_ShapeActionActuator, m_endframe),
- KX_PYATTRIBUTE_FLOAT_RW("blendIn", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendin),
- KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ShapeActionActuator, pyattr_get_action, pyattr_set_action),
- KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ShapeActionActuator, m_priority),
- KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ShapeActionActuator, m_localtime, CheckFrame),
- KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, BL_ShapeActionActuator, m_propname),
- KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, BL_ShapeActionActuator, m_framepropname),
- KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendframe, CheckBlendTime),
- KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ShapeActionActuator,m_playtype,CheckType),
- { NULL } //Sentinel
-};
-
-PyObject *BL_ShapeActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ShapeActionActuator* self = static_cast<BL_ShapeActionActuator*>(self_v);
- return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
-}
-
-int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ShapeActionActuator* self = static_cast<BL_ShapeActionActuator*>(self_v);
- /* exact copy of BL_ActionActuator's function from here down */
- if (!PyUnicode_Check(value))
- {
- PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, expected the string name of the action");
- return PY_SET_ATTR_FAIL;
- }
-
- bAction *action= NULL;
- STR_String val = _PyUnicode_AsString(value);
-
- if (val != "")
- {
- action= (bAction*)self->GetLogicManager()->GetActionByName(val);
- if (action==NULL)
- {
- PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, action not found!");
- return PY_SET_ATTR_FAIL;
- }
- }
-
- self->SetAction(action);
- return PY_SET_ATTR_SUCCESS;
-
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h
deleted file mode 100644
index 899bbbc616d..00000000000
--- a/source/gameengine/Converter/BL_ShapeActionActuator.h
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ShapeActionActuator.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_SHAPEACTIONACTUATOR_H__
-#define __BL_SHAPEACTIONACTUATOR_H__
-
-#include "CTR_HashedPtr.h"
-#include "SCA_IActuator.h"
-#include "BL_ActionActuator.h"
-#include "MT_Point3.h"
-#include <vector>
-
-struct Key;
-class BL_ShapeActionActuator : public SCA_IActuator
-{
-public:
- Py_Header
- BL_ShapeActionActuator(SCA_IObject* gameobj,
- const STR_String& propname,
- const STR_String& framepropname,
- float starttime,
- float endtime,
- struct bAction *action,
- short playtype,
- short blendin,
- short priority,
- float stride);
- virtual ~BL_ShapeActionActuator();
- virtual bool Update(double curtime, bool frame);
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
-
- void SetBlendTime (float newtime);
- void BlendShape(struct Key* key, float weight);
-
- bAction* GetAction() { return m_action; }
- void SetAction(bAction* act) { m_action= act; }
-
-#ifdef WITH_PYTHON
-
- static PyObject* pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static int CheckBlendTime(void *self, const PyAttributeDef*)
- {
- BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self);
-
- if (act->m_blendframe > act->m_blendin)
- act->m_blendframe = act->m_blendin;
-
- return 0;
- }
- static int CheckFrame(void *self, const PyAttributeDef*)
- {
- BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self);
-
- if (act->m_localtime < act->m_startframe)
- act->m_localtime = act->m_startframe;
- else if (act->m_localtime > act->m_endframe)
- act->m_localtime = act->m_endframe;
-
- return 0;
- }
- static int CheckType(void *self, const PyAttributeDef*)
- {
- BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self);
-
- switch (act->m_playtype) {
- case ACT_ACTION_PLAY:
- case ACT_ACTION_PINGPONG:
- case ACT_ACTION_FLIPPER:
- case ACT_ACTION_LOOP_STOP:
- case ACT_ACTION_LOOP_END:
- case ACT_ACTION_FROM_PROP:
- return 0;
- default:
- PyErr_SetString(PyExc_ValueError, "Shape Action Actuator, invalid play type supplied");
- return 1;
- }
-
- }
-
-#endif /* WITH_PYTHON */
-
-protected:
-
- void SetStartTime(float curtime);
- void SetLocalTime(float curtime);
- bool ClampLocalTime();
-
- MT_Point3 m_lastpos;
- float m_blendframe;
- int m_flag;
- /** The frame this action starts */
- float m_startframe;
- /** The frame this action ends */
- float m_endframe;
- /** The time this action started */
- float m_starttime;
- /** The current time of the action */
- float m_localtime;
-
- float m_lastUpdate;
- float m_blendin;
- float m_blendstart;
- float m_stridelength;
- short m_playtype;
- short m_priority;
- struct bAction *m_action;
- STR_String m_framepropname;
- STR_String m_propname;
- vector<float> m_blendshape;
- struct PointerRNA *m_idptr;
-};
-
-#endif /* __BL_SHAPEACTIONACTUATOR_H__ */
diff --git a/source/gameengine/Converter/BL_ShapeDeformer.cpp b/source/gameengine/Converter/BL_ShapeDeformer.cpp
deleted file mode 100644
index 7653bb3f99b..00000000000
--- a/source/gameengine/Converter/BL_ShapeDeformer.cpp
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ShapeDeformer.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include "MEM_guardedalloc.h"
-#include "BL_ShapeDeformer.h"
-#include "CTR_Map.h"
-#include "STR_HashedString.h"
-#include "RAS_IPolygonMaterial.h"
-#include "RAS_MeshObject.h"
-
-#include "DNA_anim_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_action_types.h"
-#include "DNA_key_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "BKE_armature.h"
-#include "BKE_action.h"
-#include "BKE_global.h"
-#include "BKE_main.h"
-#include "BKE_key.h"
-#include "BKE_fcurve.h"
-#include "BKE_ipo.h"
-#include "BKE_library.h"
-#include "MT_Point3.h"
-
-extern "C"{
- #include "BKE_lattice.h"
- #include "BKE_animsys.h"
-}
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-
-#define __NLA_DEFNORMALS
-//#undef __NLA_DEFNORMALS
-
-BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
- Object *bmeshobj,
- RAS_MeshObject *mesh)
- :
- BL_SkinDeformer(gameobj,bmeshobj, mesh),
- m_useShapeDrivers(false),
- m_lastShapeUpdate(-1)
-{
- m_key = m_bmesh->key ? BKE_key_copy(G.main, m_bmesh->key) : NULL;
-};
-
-/* this second constructor is needed for making a mesh deformable on the fly. */
-BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
- Object *bmeshobj_old,
- Object *bmeshobj_new,
- RAS_MeshObject *mesh,
- bool release_object,
- bool recalc_normal,
- BL_ArmatureObject* arma)
- :
- BL_SkinDeformer(gameobj, bmeshobj_old, bmeshobj_new, mesh, release_object, recalc_normal, arma),
- m_useShapeDrivers(false),
- m_lastShapeUpdate(-1)
-{
- m_key = m_bmesh->key ? BKE_key_copy(G.main, m_bmesh->key) : NULL;
-};
-
-BL_ShapeDeformer::~BL_ShapeDeformer()
-{
- if (m_key)
- {
- BKE_libblock_free(G.main, m_key);
- m_key = NULL;
- }
-};
-
-RAS_Deformer *BL_ShapeDeformer::GetReplica()
-{
- BL_ShapeDeformer *result;
-
- result = new BL_ShapeDeformer(*this);
- result->ProcessReplica();
- return result;
-}
-
-void BL_ShapeDeformer::ProcessReplica()
-{
- BL_SkinDeformer::ProcessReplica();
- m_lastShapeUpdate = -1;
-
- m_key = m_key ? BKE_key_copy(G.main, m_key) : NULL;
-}
-
-bool BL_ShapeDeformer::LoadShapeDrivers(KX_GameObject* parent)
-{
- // Only load shape drivers if we have a key
- if (GetKey() == NULL) {
- m_useShapeDrivers = false;
- return false;
- }
-
- // Fix drivers since BL_ArmatureObject makes copies
- if (parent->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE && GetKey()->adt) {
- BL_ArmatureObject *arma = (BL_ArmatureObject*)parent;
- FCurve *fcu;
-
- for (fcu = (FCurve*)GetKey()->adt->drivers.first; fcu; fcu = (FCurve*)fcu->next) {
-
- DriverVar *dvar;
- for (dvar = (DriverVar*)fcu->driver->variables.first; dvar; dvar = (DriverVar*)dvar->next) {
- DRIVER_TARGETS_USED_LOOPER(dvar)
- {
- if (dtar->id) {
- if ((Object*)dtar->id == arma->GetOrigArmatureObject())
- dtar->id = (ID*)arma->GetArmatureObject();
- }
- }
- DRIVER_TARGETS_LOOPER_END
- }
- }
- }
-
- // This used to check if we had drivers from this armature,
- // now we just assume we want to use shape drivers
- // and let the animsys handle things.
- m_useShapeDrivers = true;
-
- return true;
-}
-
-bool BL_ShapeDeformer::ExecuteShapeDrivers(void)
-{
- if (m_useShapeDrivers && PoseUpdated()) {
- // We don't need an actual time, just use 0
- BKE_animsys_evaluate_animdata(NULL, &GetKey()->id, GetKey()->adt, 0.f, ADT_RECALC_DRIVERS);
-
- ForceUpdate();
- m_bDynamic = true;
- return true;
- }
- return false;
-}
-
-bool BL_ShapeDeformer::Update(void)
-{
- bool bShapeUpdate = false;
- bool bSkinUpdate = false;
-
- ExecuteShapeDrivers();
-
- /* See if the object shape has changed */
- if (m_lastShapeUpdate != m_gameobj->GetLastFrame()) {
- /* the key coefficient have been set already, we just need to blend the keys */
- Object* blendobj = m_gameobj->GetBlendObject();
-
- /* we will blend the key directly in m_transverts array: it is used by armature as the start position */
- /* m_key can be NULL in case of Modifier deformer */
- if (m_key) {
- WeightsArrayCache cache = {0, NULL};
- float **per_keyblock_weights;
-
- /* store verts locally */
- VerifyStorage();
-
- per_keyblock_weights = BKE_keyblock_get_per_block_weights(blendobj, m_key, &cache);
- BKE_key_evaluate_relative(0, m_bmesh->totvert, m_bmesh->totvert, (char *)(float *)m_transverts,
- m_key, NULL, per_keyblock_weights, 0); /* last arg is ignored */
- BKE_keyblock_free_per_block_weights(m_key, per_keyblock_weights, &cache);
-
- m_bDynamic = true;
- }
-
- // Don't release the weight array as in Blender, it will most likely be reusable on next frame
- // The weight array are ultimately deleted when the skin mesh is destroyed
-
- /* Update the current frame */
- m_lastShapeUpdate=m_gameobj->GetLastFrame();
-
- // As we have changed, the mesh, the skin deformer must update as well.
- // This will force the update
- BL_SkinDeformer::ForceUpdate();
- bShapeUpdate = true;
- }
- // check for armature deform
- bSkinUpdate = BL_SkinDeformer::UpdateInternal(bShapeUpdate && m_bDynamic);
-
- // non dynamic deformer = Modifer without armature and shape keys, no need to create storage
- if (!bSkinUpdate && bShapeUpdate && m_bDynamic) {
- // this means that there is no armature, we still need to
- // update the normal (was not done after shape key calculation)
-
-#ifdef __NLA_DEFNORMALS
- if (m_recalcNormal)
- RecalcNormals();
-#endif
-
- // We also need to handle transverts now (used to be in BL_SkinDeformer::Apply())
- UpdateTransverts();
- bSkinUpdate = true;
- }
-
- return bSkinUpdate;
-}
-
-Key *BL_ShapeDeformer::GetKey()
-{
- return m_key;
-}
diff --git a/source/gameengine/Converter/BL_ShapeDeformer.h b/source/gameengine/Converter/BL_ShapeDeformer.h
deleted file mode 100644
index 80a6f908db5..00000000000
--- a/source/gameengine/Converter/BL_ShapeDeformer.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ShapeDeformer.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_SHAPEDEFORMER_H__
-#define __BL_SHAPEDEFORMER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* get rid of stupid stl-visual compiler debug warning */
-#endif
-
-#include "BL_SkinDeformer.h"
-#include "BL_DeformableGameObject.h"
-#include <vector>
-
-class BL_ShapeDeformer : public BL_SkinDeformer
-{
-public:
- BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
- Object *bmeshobj,
- RAS_MeshObject *mesh);
-
- /* this second constructor is needed for making a mesh deformable on the fly. */
- BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
- struct Object *bmeshobj_old,
- struct Object *bmeshobj_new,
- class RAS_MeshObject *mesh,
- bool release_object,
- bool recalc_normal,
- BL_ArmatureObject* arma = NULL);
-
- virtual RAS_Deformer *GetReplica();
- virtual void ProcessReplica();
- virtual ~BL_ShapeDeformer();
-
- bool Update (void);
- bool LoadShapeDrivers(KX_GameObject* parent);
- bool ExecuteShapeDrivers(void);
-
- struct Key *GetKey();
-
- void ForceUpdate()
- {
- m_lastShapeUpdate = -1.0;
- };
-
-protected:
- bool m_useShapeDrivers;
- double m_lastShapeUpdate;
- struct Key* m_key;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_ShapeDeformer")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Converter/BL_SkinDeformer.cpp b/source/gameengine/Converter/BL_SkinDeformer.cpp
deleted file mode 100644
index 16700859ebe..00000000000
--- a/source/gameengine/Converter/BL_SkinDeformer.cpp
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_SkinDeformer.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-// Eigen3 stuff used for BGEDeformVerts
-#include <Eigen/Core>
-#include <Eigen/LU>
-
-#include "BL_SkinDeformer.h"
-#include "CTR_Map.h"
-#include "STR_HashedString.h"
-#include "RAS_IPolygonMaterial.h"
-#include "RAS_MeshObject.h"
-
-//#include "BL_ArmatureController.h"
-#include "DNA_armature_types.h"
-#include "DNA_action_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_modifier_types.h"
-#include "BLI_utildefines.h"
-#include "BKE_armature.h"
-#include "BKE_action.h"
-#include "MT_Point3.h"
-
-extern "C"{
- #include "BKE_lattice.h"
- #include "BKE_deform.h"
-}
-
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-
-#define __NLA_DEFNORMALS
-//#undef __NLA_DEFNORMALS
-
-static short get_deformflags(struct Object *bmeshobj)
-{
- short flags = ARM_DEF_VGROUP;
-
- ModifierData *md;
- for (md = (ModifierData *)bmeshobj->modifiers.first; md; md = md->next)
- {
- if (md->type == eModifierType_Armature)
- {
- flags |= ((ArmatureModifierData*)md)->deformflag;
- break;
- }
- }
-
- return flags;
-}
-
-BL_SkinDeformer::BL_SkinDeformer(BL_DeformableGameObject *gameobj,
- struct Object *bmeshobj,
- class RAS_MeshObject *mesh,
- BL_ArmatureObject* arma)
- : //
- BL_MeshDeformer(gameobj, bmeshobj, mesh),
- m_armobj(arma),
- m_lastArmaUpdate(-1),
- //m_defbase(&bmeshobj->defbase),
- m_releaseobject(false),
- m_poseApplied(false),
- m_recalcNormal(true),
- m_copyNormals(false),
- m_dfnrToPC(NULL)
-{
- copy_m4_m4(m_obmat, bmeshobj->obmat);
- m_deformflags = get_deformflags(bmeshobj);
-};
-
-BL_SkinDeformer::BL_SkinDeformer(
- BL_DeformableGameObject *gameobj,
- struct Object *bmeshobj_old, // Blender object that owns the new mesh
- struct Object *bmeshobj_new, // Blender object that owns the original mesh
- class RAS_MeshObject *mesh,
- bool release_object,
- bool recalc_normal,
- BL_ArmatureObject* arma) :
- BL_MeshDeformer(gameobj, bmeshobj_old, mesh),
- m_armobj(arma),
- m_lastArmaUpdate(-1),
- //m_defbase(&bmeshobj_old->defbase),
- m_releaseobject(release_object),
- m_recalcNormal(recalc_normal),
- m_copyNormals(false),
- m_dfnrToPC(NULL)
- {
- // this is needed to ensure correct deformation of mesh:
- // the deformation is done with Blender's armature_deform_verts() function
- // that takes an object as parameter and not a mesh. The object matrice is used
- // in the calculation, so we must use the matrix of the original object to
- // simulate a pure replacement of the mesh.
- copy_m4_m4(m_obmat, bmeshobj_new->obmat);
- m_deformflags = get_deformflags(bmeshobj_new);
- }
-
-BL_SkinDeformer::~BL_SkinDeformer()
-{
- if (m_releaseobject && m_armobj)
- m_armobj->Release();
- if (m_dfnrToPC)
- delete [] m_dfnrToPC;
-}
-
-void BL_SkinDeformer::Relink(CTR_Map<class CTR_HashedPtr, void*>*map)
-{
- if (m_armobj) {
- void **h_obj = (*map)[m_armobj];
-
- if (h_obj)
- m_armobj = (BL_ArmatureObject*)(*h_obj);
- else
- m_armobj=NULL;
- }
-
- BL_MeshDeformer::Relink(map);
-}
-
-bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *mat)
-{
- // We do everything in UpdateInternal() now so we can thread it.
- // All that is left is telling the rasterizer if we've changed the mesh
- bool retval = !m_poseApplied;
- m_poseApplied = true;
- return retval;
-}
-
-RAS_Deformer *BL_SkinDeformer::GetReplica()
-{
- BL_SkinDeformer *result;
-
- result = new BL_SkinDeformer(*this);
- /* there is m_armobj that must be fixed but we cannot do it now, it will be done in Relink */
- result->ProcessReplica();
- return result;
-}
-
-void BL_SkinDeformer::ProcessReplica()
-{
- BL_MeshDeformer::ProcessReplica();
- m_lastArmaUpdate = -1;
- m_releaseobject = false;
- m_dfnrToPC = NULL;
-}
-
-void BL_SkinDeformer::BlenderDeformVerts()
-{
- float obmat[4][4]; // the original object matrix
- Object* par_arma = m_armobj->GetArmatureObject();
-
- // save matrix first
- copy_m4_m4(obmat, m_objMesh->obmat);
- // set reference matrix
- copy_m4_m4(m_objMesh->obmat, m_obmat);
-
- armature_deform_verts( par_arma, m_objMesh, NULL, m_transverts, NULL, m_bmesh->totvert, m_deformflags, NULL, NULL );
-
- // restore matrix
- copy_m4_m4(m_objMesh->obmat, obmat);
-
-#ifdef __NLA_DEFNORMALS
- if (m_recalcNormal)
- RecalcNormals();
-#endif
-}
-
-void BL_SkinDeformer::BGEDeformVerts()
-{
- Object *par_arma = m_armobj->GetArmatureObject();
- MDeformVert *dverts = m_bmesh->dvert;
- bDeformGroup *dg;
- int defbase_tot;
- Eigen::Matrix4f pre_mat, post_mat, chan_mat, norm_chan_mat;
-
- if (!dverts)
- return;
-
- defbase_tot = BLI_listbase_count(&m_objMesh->defbase);
-
- if (m_dfnrToPC == NULL)
- {
- m_dfnrToPC = new bPoseChannel*[defbase_tot];
- int i;
- for (i=0, dg=(bDeformGroup*)m_objMesh->defbase.first;
- dg;
- ++i, dg = dg->next)
- {
- m_dfnrToPC[i] = BKE_pose_channel_find_name(par_arma->pose, dg->name);
-
- if (m_dfnrToPC[i] && m_dfnrToPC[i]->bone->flag & BONE_NO_DEFORM)
- m_dfnrToPC[i] = NULL;
- }
- }
-
- post_mat = Eigen::Matrix4f::Map((float*)m_obmat).inverse() * Eigen::Matrix4f::Map((float*)m_armobj->GetArmatureObject()->obmat);
- pre_mat = post_mat.inverse();
-
- MDeformVert *dv= dverts;
- MDeformWeight *dw;
-
- for (int i=0; i<m_bmesh->totvert; ++i, dv++)
- {
- float contrib = 0.f, weight, max_weight=-1.f;
- bPoseChannel *pchan=NULL;
- Eigen::Map<Eigen::Vector3f> norm = Eigen::Vector3f::Map(m_transnors[i]);
- Eigen::Vector4f vec(0, 0, 0, 1);
- Eigen::Vector4f co(m_transverts[i][0],
- m_transverts[i][1],
- m_transverts[i][2],
- 1.f);
-
- if (!dv->totweight)
- continue;
-
- co = pre_mat * co;
-
- dw= dv->dw;
-
- for (unsigned int j= dv->totweight; j != 0; j--, dw++)
- {
- const int index = dw->def_nr;
-
- if (index < defbase_tot && (pchan=m_dfnrToPC[index]))
- {
- weight = dw->weight;
-
- if (weight)
- {
- chan_mat = Eigen::Matrix4f::Map((float*)pchan->chan_mat);
-
- // Update Vertex Position
- vec.noalias() += (chan_mat*co - co)*weight;
-
- // Save the most influential channel so we can use it to update the vertex normal
- if (weight > max_weight)
- {
- max_weight = weight;
- norm_chan_mat = chan_mat;
- }
-
- contrib += weight;
- }
- }
- }
-
- // Update Vertex Normal
- norm = norm_chan_mat.topLeftCorner<3, 3>()*norm;
-
- co.noalias() += vec/contrib;
- co[3] = 1.f; // Make sure we have a 1 for the w component!
-
- co = post_mat * co;
-
- m_transverts[i][0] = co[0];
- m_transverts[i][1] = co[1];
- m_transverts[i][2] = co[2];
- }
- m_copyNormals = true;
-}
-
-void BL_SkinDeformer::UpdateTransverts()
-{
- RAS_MeshSlot::iterator it;
- RAS_MeshMaterial *mmat;
- RAS_MeshSlot *slot;
- size_t i, nmat, imat;
-
- if (m_transverts) {
- // the vertex cache is unique to this deformer, no need to update it
- // if it wasn't updated! We must update all the materials at once
- // because we will not get here again for the other material
- nmat = m_pMeshObject->NumMaterials();
- for (imat=0; imat<nmat; imat++) {
- mmat = m_pMeshObject->GetMeshMaterial(imat);
- if (!mmat->m_slots[(void*)m_gameobj])
- continue;
-
- slot = *mmat->m_slots[(void*)m_gameobj];
-
- // 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 (i=it.startvertex; i<it.endvertex; i++) {
- RAS_TexVert& v = it.vertex[i];
- v.SetXYZ(m_transverts[v.getOrigIndex()]);
- if (m_copyNormals)
- v.SetNormal(m_transnors[v.getOrigIndex()]);
- }
- }
- }
-
- if (m_copyNormals)
- m_copyNormals = false;
- }
-}
-
-bool BL_SkinDeformer::UpdateInternal(bool shape_applied)
-{
- /* See if the armature has been updated for this frame */
- if (PoseUpdated()) {
-
- if (!shape_applied) {
- /* store verts locally */
- VerifyStorage();
-
- /* duplicate */
- for (int v =0; v<m_bmesh->totvert; v++)
- {
- copy_v3_v3(m_transverts[v], m_bmesh->mvert[v].co);
- normal_short_to_float_v3(m_transnors[v], m_bmesh->mvert[v].no);
- }
- }
-
- m_armobj->ApplyPose();
-
- if (m_armobj->GetVertDeformType() == ARM_VDEF_BGE_CPU)
- BGEDeformVerts();
- else
- BlenderDeformVerts();
-
- /* Update the current frame */
- m_lastArmaUpdate=m_armobj->GetLastFrame();
-
- m_armobj->RestorePose();
- /* dynamic vertex, cannot use display list */
- m_bDynamic = true;
-
- UpdateTransverts();
-
- m_poseApplied = false;
-
- /* indicate that the m_transverts and normals are up to date */
- return true;
- }
-
- return false;
-}
-
-bool BL_SkinDeformer::Update(void)
-{
- return UpdateInternal(false);
-}
-
-/* XXX note: I propose to drop this function */
-void BL_SkinDeformer::SetArmature(BL_ArmatureObject *armobj)
-{
- // only used to set the object now
- m_armobj = armobj;
-}
diff --git a/source/gameengine/Converter/BL_SkinDeformer.h b/source/gameengine/Converter/BL_SkinDeformer.h
deleted file mode 100644
index 1feed3c3d16..00000000000
--- a/source/gameengine/Converter/BL_SkinDeformer.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_SkinDeformer.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_SKINDEFORMER_H__
-#define __BL_SKINDEFORMER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* get rid of stupid stl-visual compiler debug warning */
-#endif /* WIN32 */
-
-#include "CTR_HashedPtr.h"
-#include "BL_MeshDeformer.h"
-#include "BL_ArmatureObject.h"
-
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_object_types.h"
-#include "BKE_armature.h"
-
-#include "RAS_Deformer.h"
-
-
-class BL_SkinDeformer : public BL_MeshDeformer
-{
-public:
-// void SetArmatureController (BL_ArmatureController *cont);
- virtual void Relink(CTR_Map<class CTR_HashedPtr, void*>*map);
- void SetArmature (class BL_ArmatureObject *armobj);
-
- BL_SkinDeformer(BL_DeformableGameObject *gameobj,
- struct Object *bmeshobj,
- class RAS_MeshObject *mesh,
- BL_ArmatureObject* arma = NULL);
-
- /* this second constructor is needed for making a mesh deformable on the fly. */
- BL_SkinDeformer(BL_DeformableGameObject *gameobj,
- struct Object *bmeshobj_old,
- struct Object *bmeshobj_new,
- class RAS_MeshObject *mesh,
- bool release_object,
- bool recalc_normal,
- BL_ArmatureObject* arma = NULL);
-
- virtual RAS_Deformer *GetReplica();
- virtual void ProcessReplica();
-
- virtual ~BL_SkinDeformer();
- bool Update (void);
- bool UpdateInternal (bool shape_applied);
- bool Apply (class RAS_IPolyMaterial *polymat);
- bool UpdateBuckets(void)
- {
- // update the deformer and all the mesh slots; Apply() does it well, so just call it.
- return Apply(NULL);
- }
- bool PoseUpdated(void)
- {
- if (m_armobj && m_lastArmaUpdate!=m_armobj->GetLastFrame()) {
- return true;
- }
- return false;
- }
-
- void ForceUpdate()
- {
- m_lastArmaUpdate = -1.0;
- };
- virtual bool ShareVertexArray()
- {
- return false;
- }
-
-protected:
- BL_ArmatureObject* m_armobj; // Our parent object
- float m_time;
- double m_lastArmaUpdate;
- //ListBase* m_defbase;
- float m_obmat[4][4]; // the reference matrix for skeleton deform
- bool m_releaseobject;
- bool m_poseApplied;
- bool m_recalcNormal;
- bool m_copyNormals; // dirty flag so we know if Apply() needs to copy normal information (used for BGEDeformVerts())
- struct bPoseChannel** m_dfnrToPC;
- short m_deformflags;
-
- void BlenderDeformVerts();
- void BGEDeformVerts();
-
- void UpdateTransverts();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_SkinDeformer")
-#endif
-};
-
-#endif /* __BL_SKINDEFORMER_H__ */
diff --git a/source/gameengine/Converter/CMakeLists.txt b/source/gameengine/Converter/CMakeLists.txt
deleted file mode 100644
index 4db9fcebd06..00000000000
--- a/source/gameengine/Converter/CMakeLists.txt
+++ /dev/null
@@ -1,123 +0,0 @@
-# ***** BEGIN GPL LICENSE BLOCK *****
-#
-# 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
-# of the License, or (at your option) any later version.
-#
-# 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,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ../BlenderRoutines
- ../Expressions
- ../GameLogic
- ../Ketsji
- ../Ketsji/KXNetwork
- ../Network
- ../Network/LoopBackNetwork
- ../Physics/Bullet
- ../Physics/Dummy
- ../Physics/common
- ../Rasterizer
- ../Rasterizer/RAS_OpenGLRasterizer
- ../SceneGraph
- ../../blender
- ../../blender/blenkernel
- ../../blender/blenlib
- ../../blender/blenloader
- ../../blender/gpu
- ../../blender/ikplugin
- ../../blender/imbuf
- ../../blender/makesdna
- ../../blender/makesrna
- ../../blender/windowmanager
- ../../../intern/container
- ../../../intern/guardedalloc
- ../../../intern/string
-)
-
-set(INC_SYS
- ../../../intern/moto/include
- ../../../extern/recastnavigation/Detour/Include
- ${EIGEN3_INCLUDE_DIRS}
- ${PTHREADS_INCLUDE_DIRS}
- ${BOOST_INCLUDE_DIR}
-)
-
-set(SRC
- BL_ActionActuator.cpp
- BL_ArmatureActuator.cpp
- BL_ArmatureChannel.cpp
- BL_ArmatureConstraint.cpp
- BL_ArmatureObject.cpp
- BL_BlenderDataConversion.cpp
- BL_DeformableGameObject.cpp
- BL_MeshDeformer.cpp
- BL_ModifierDeformer.cpp
- BL_ShapeActionActuator.cpp
- BL_ShapeDeformer.cpp
- BL_SkinDeformer.cpp
- KX_BlenderScalarInterpolator.cpp
- KX_BlenderSceneConverter.cpp
- KX_ConvertActuators.cpp
- KX_ConvertControllers.cpp
- KX_ConvertProperties.cpp
- KX_ConvertSensors.cpp
- KX_LibLoadStatus.cpp
- KX_SoftBodyDeformer.cpp
-
- BL_ActionActuator.h
- BL_ArmatureActuator.h
- BL_ArmatureChannel.h
- BL_ArmatureConstraint.h
- BL_ArmatureObject.h
- BL_BlenderDataConversion.h
- BL_DeformableGameObject.h
- BL_MeshDeformer.h
- BL_ModifierDeformer.h
- BL_ShapeActionActuator.h
- BL_ShapeDeformer.h
- BL_SkinDeformer.h
- KX_BlenderScalarInterpolator.h
- KX_BlenderSceneConverter.h
- KX_ConvertActuators.h
- KX_ConvertControllers.h
- KX_ConvertProperties.h
- KX_ConvertSensors.h
- KX_LibLoadStatus.h
- KX_SoftBodyDeformer.h
-)
-
-if(WITH_BULLET)
- list(APPEND INC_SYS
- ${BULLET_INCLUDE_DIRS}
- )
- add_definitions(-DWITH_BULLET)
-endif()
-
-if(WITH_AUDASPACE)
- add_definitions(${AUDASPACE_DEFINITIONS})
-
- list(APPEND INC_SYS
- ${AUDASPACE_C_INCLUDE_DIRS}
- )
-endif()
-
-blender_add_lib(ge_converter "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp b/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp
deleted file mode 100644
index 434f5753396..00000000000
--- a/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_BlenderScalarInterpolator.cpp
- * \ingroup bgeconv
- */
-
-
-#include "KX_BlenderScalarInterpolator.h"
-
-#include <cstring>
-
-extern "C" {
-#include "DNA_action_types.h"
-#include "DNA_anim_types.h"
-#include "BKE_fcurve.h"
-}
-
-float BL_ScalarInterpolator::GetValue(float currentTime) const
-{
- // XXX 2.4x IPO_GetFloatValue(m_blender_adt, m_channel, currentTime);
- return evaluate_fcurve(m_fcu, currentTime);
-}
-
-BL_InterpolatorList::BL_InterpolatorList(bAction *action)
-{
- if (action==NULL)
- return;
-
- for (FCurve *fcu = (FCurve *)action->curves.first; fcu; fcu = fcu->next) {
- if (fcu->rna_path) {
- BL_ScalarInterpolator *new_ipo = new BL_ScalarInterpolator(fcu);
- //assert(new_ipo);
- push_back(new_ipo);
- }
- }
-}
-
-BL_InterpolatorList::~BL_InterpolatorList()
-{
- BL_InterpolatorList::iterator i;
- for (i = begin(); !(i == end()); ++i) {
- delete *i;
- }
-}
-
-KX_IScalarInterpolator *BL_InterpolatorList::GetScalarInterpolator(const char *rna_path, int array_index)
-{
- for (BL_InterpolatorList::iterator i = begin(); (i != end()) ; i++ )
- {
- FCurve *fcu= (static_cast<BL_ScalarInterpolator *>(*i))->GetFCurve();
- if (array_index==fcu->array_index && strcmp(rna_path, fcu->rna_path)==0)
- return *i;
- }
- return NULL;
-}
-
diff --git a/source/gameengine/Converter/KX_BlenderScalarInterpolator.h b/source/gameengine/Converter/KX_BlenderScalarInterpolator.h
deleted file mode 100644
index a82688cea20..00000000000
--- a/source/gameengine/Converter/KX_BlenderScalarInterpolator.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_BlenderScalarInterpolator.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_BLENDERSCALARINTERPOLATOR_H__
-#define __KX_BLENDERSCALARINTERPOLATOR_H__
-
-#include <vector>
-
-#include "KX_IScalarInterpolator.h"
-
-typedef unsigned short BL_IpoChannel;
-
-class BL_ScalarInterpolator : public KX_IScalarInterpolator {
-public:
- BL_ScalarInterpolator() {} // required for use in STL list
- BL_ScalarInterpolator(struct FCurve* fcu) :
- m_fcu(fcu)
- {}
-
- virtual ~BL_ScalarInterpolator() {}
-
- virtual float GetValue(float currentTime) const;
- struct FCurve *GetFCurve() { return m_fcu; }
-
-private:
- struct FCurve *m_fcu;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_ScalarInterpolator")
-#endif
-};
-
-
-class BL_InterpolatorList : public std::vector<KX_IScalarInterpolator *> {
-public:
- BL_InterpolatorList(struct bAction *action);
- ~BL_InterpolatorList();
-
- KX_IScalarInterpolator *GetScalarInterpolator(const char *rna_path, int array_index);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_InterpolatorList")
-#endif
-};
-
-#endif /* __KX_BLENDERSCALARINTERPOLATOR_H__ */
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
deleted file mode 100644
index 5d9f32a0969..00000000000
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
+++ /dev/null
@@ -1,1477 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_BlenderSceneConverter.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* suppress stl-MSVC debug info warning */
-#endif
-
-#include "KX_Scene.h"
-#include "KX_GameObject.h"
-#include "KX_IpoConvert.h"
-#include "RAS_MeshObject.h"
-#include "KX_PhysicsEngineEnums.h"
-#include "PHY_IPhysicsEnvironment.h"
-#include "KX_KetsjiEngine.h"
-#include "KX_PythonInit.h" // So we can handle adding new text datablocks for Python to import
-#include "BL_Material.h"
-#include "BL_ActionActuator.h"
-#include "KX_BlenderMaterial.h"
-
-
-#include "BL_System.h"
-
-#include "DummyPhysicsEnvironment.h"
-
-
-#ifdef WITH_BULLET
-#include "CcdPhysicsEnvironment.h"
-#endif
-
-#include "KX_LibLoadStatus.h"
-#include "KX_BlenderScalarInterpolator.h"
-#include "BL_BlenderDataConversion.h"
-#include "KX_WorldInfo.h"
-
-/* This little block needed for linking to Blender... */
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-/* This list includes only data type definitions */
-#include "DNA_scene_types.h"
-#include "DNA_world_types.h"
-#include "BKE_main.h"
-#include "BKE_fcurve.h"
-
-#include "BLI_math.h"
-
-extern "C"
-{
-#include "DNA_object_types.h"
-#include "DNA_curve_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_material_types.h"
-#include "BLI_blenlib.h"
-#include "MEM_guardedalloc.h"
-#include "BKE_global.h"
-#include "BKE_animsys.h"
-#include "BKE_library.h"
-#include "BKE_material.h" // BKE_material_copy
-#include "BKE_mesh.h" // BKE_mesh_copy
-#include "DNA_space_types.h"
-#include "DNA_anim_types.h"
-#include "DNA_action_types.h"
-#include "RNA_define.h"
-#include "../../blender/editors/include/ED_keyframing.h"
-}
-
-/* Only for dynamic loading and merging */
-#include "RAS_BucketManager.h" // XXX cant stay
-#include "KX_BlenderSceneConverter.h"
-#include "KX_MeshProxy.h"
-extern "C" {
- #include "PIL_time.h"
- #include "BKE_context.h"
- #include "BLO_readfile.h"
- #include "BKE_idcode.h"
- #include "BKE_report.h"
- #include "DNA_space_types.h"
- #include "DNA_windowmanager_types.h" /* report api */
- #include "../../blender/blenlib/BLI_linklist.h"
-}
-
-#include "BLI_task.h"
-
-// This is used to avoid including BLI_task.h in KX_BlenderSceneConverter.h
-typedef struct ThreadInfo {
- TaskPool *m_pool;
- ThreadMutex m_mutex;
-} ThreadInfo;
-
-KX_BlenderSceneConverter::KX_BlenderSceneConverter(
- Main *maggie,
- KX_KetsjiEngine *engine)
- :m_maggie(maggie),
- m_ketsjiEngine(engine),
- m_alwaysUseExpandFraming(false),
- m_usemat(false),
- m_useglslmat(false),
- m_use_mat_cache(true)
-{
- BKE_main_id_tag_all(maggie, LIB_TAG_DOIT, false); /* avoid re-tagging later on */
- m_newfilename = "";
- m_threadinfo = new ThreadInfo();
- m_threadinfo->m_pool = BLI_task_pool_create(engine->GetTaskScheduler(), NULL);
- BLI_mutex_init(&m_threadinfo->m_mutex);
-}
-
-KX_BlenderSceneConverter::~KX_BlenderSceneConverter()
-{
- // clears meshes, and hashmaps from blender to gameengine data
- // delete sumoshapes
-
- int numAdtLists = m_map_blender_to_gameAdtList.size();
- for (int i = 0; i < numAdtLists; i++) {
- BL_InterpolatorList *adtList = *m_map_blender_to_gameAdtList.at(i);
-
- delete (adtList);
- }
-
- vector<pair<KX_Scene *, KX_WorldInfo *> >::iterator itw = m_worldinfos.begin();
- while (itw != m_worldinfos.end()) {
- delete itw->second;
- itw++;
- }
- m_worldinfos.clear();
-
- vector<pair<KX_Scene *,RAS_IPolyMaterial *> >::iterator itp = m_polymaterials.begin();
- while (itp != m_polymaterials.end()) {
- delete itp->second;
- itp++;
- }
- m_polymaterials.clear();
-
- // delete after RAS_IPolyMaterial
- vector<pair<KX_Scene *,BL_Material *> >::iterator itmat = m_materials.begin();
- while (itmat != m_materials.end()) {
- delete itmat->second;
- itmat++;
- }
- m_materials.clear();
-
- vector<pair<KX_Scene *,RAS_MeshObject *> >::iterator itm = m_meshobjects.begin();
- while (itm != m_meshobjects.end()) {
- delete itm->second;
- itm++;
- }
- m_meshobjects.clear();
-
- /* free any data that was dynamically loaded */
- while (m_DynamicMaggie.size() != 0) {
- FreeBlendFile(m_DynamicMaggie[0]);
- }
-
- m_DynamicMaggie.clear();
-
- if (m_threadinfo) {
- /* Thread infos like mutex must be freed after FreeBlendFile function.
- Because it needs to lock the mutex, even if there's no active task when it's
- in the scene converter destructor. */
- BLI_task_pool_free(m_threadinfo->m_pool);
- BLI_mutex_end(&m_threadinfo->m_mutex);
- delete m_threadinfo;
- }
-}
-
-void KX_BlenderSceneConverter::SetNewFileName(const STR_String &filename)
-{
- m_newfilename = filename;
-}
-
-bool KX_BlenderSceneConverter::TryAndLoadNewFile()
-{
- bool result = false;
-
- return result;
-}
-
-Scene *KX_BlenderSceneConverter::GetBlenderSceneForName(const STR_String &name)
-{
- Scene *sce;
-
- /**
- * Find the specified scene by name, or NULL if nothing matches.
- */
- if ((sce = (Scene *)BLI_findstring(&m_maggie->scene, name.ReadPtr(), offsetof(ID, name) + 2)))
- return sce;
-
- for (vector<Main *>::iterator it=m_DynamicMaggie.begin(); !(it == m_DynamicMaggie.end()); it++) {
- Main *main = *it;
-
- if ((sce= (Scene *)BLI_findstring(&main->scene, name.ReadPtr(), offsetof(ID, name) + 2)))
- return sce;
- }
-
- return NULL;
-}
-
-void KX_BlenderSceneConverter::ConvertScene(KX_Scene *destinationscene, RAS_IRasterizer *rendertools,
- RAS_ICanvas *canvas, bool libloading)
-{
- //find out which physics engine
- Scene *blenderscene = destinationscene->GetBlenderScene();
-
- PHY_IPhysicsEnvironment *phy_env = NULL;
-
- e_PhysicsEngine physics_engine = UseBullet;
- // hook for registration function during conversion.
- m_currentScene = destinationscene;
- destinationscene->SetSceneConverter(this);
-
- // This doesn't really seem to do anything except cause potential issues
- // when doing threaded conversion, so it's disabled for now.
- // SG_SetActiveStage(SG_STAGE_CONVERTER);
-
- switch (blenderscene->gm.physicsEngine) {
-#ifdef WITH_BULLET
- case WOPHY_BULLET:
- {
- SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/
- int visualizePhysics = SYS_GetCommandLineInt(syshandle, "show_physics", 0);
-
- phy_env = CcdPhysicsEnvironment::Create(blenderscene, visualizePhysics);
- physics_engine = UseBullet;
- break;
- }
-#endif
- default:
- case WOPHY_NONE:
- {
- // We should probably use some sort of factory here
- phy_env = new DummyPhysicsEnvironment();
- physics_engine = UseNone;
- break;
- }
- }
-
- destinationscene->SetPhysicsEnvironment(phy_env);
-
- BL_ConvertBlenderObjects(
- m_maggie,
- destinationscene,
- m_ketsjiEngine,
- physics_engine,
- rendertools,
- canvas,
- this,
- m_alwaysUseExpandFraming,
- libloading);
-
- //These lookup are not needed during game
- m_map_blender_to_gameactuator.clear();
- m_map_blender_to_gamecontroller.clear();
- m_map_blender_to_gameobject.clear();
-
- //Clearing this lookup table has the effect of disabling the cache of meshes
- //between scenes, even if they are shared in the blend file.
- //This cache mecanism is buggy so I leave it disable and the memory leak
- //that would result from this is fixed in RemoveScene()
- m_map_mesh_to_gamemesh.clear();
-}
-
-// This function removes all entities stored in the converter for that scene
-// It should be used instead of direct delete scene
-// Note that there was some provision for sharing entities (meshes...) between
-// scenes but that is now disabled so all scene will have their own copy
-// and we can delete them here. If the sharing is reactivated, change this code too..
-// (see KX_BlenderSceneConverter::ConvertScene)
-void KX_BlenderSceneConverter::RemoveScene(KX_Scene *scene)
-{
- int i, size;
- // delete the scene first as it will stop the use of entities
- delete scene;
- // delete the entities of this scene
- vector<pair<KX_Scene *, KX_WorldInfo *> >::iterator worldit;
- size = m_worldinfos.size();
- for (i = 0, worldit = m_worldinfos.begin(); i < size; ) {
- if (worldit->first == scene) {
- delete worldit->second;
- *worldit = m_worldinfos.back();
- m_worldinfos.pop_back();
- size--;
- }
- else {
- i++;
- worldit++;
- }
- }
-
- vector<pair<KX_Scene *, RAS_IPolyMaterial *> >::iterator polymit;
- size = m_polymaterials.size();
- for (i = 0, polymit = m_polymaterials.begin(); i < size; ) {
- if (polymit->first == scene) {
- m_polymat_cache[scene].erase(polymit->second->GetBlenderMaterial());
- delete polymit->second;
- *polymit = m_polymaterials.back();
- m_polymaterials.pop_back();
- size--;
- }
- else {
- i++;
- polymit++;
- }
- }
-
- m_polymat_cache.erase(scene);
-
- vector<pair<KX_Scene *, BL_Material *> >::iterator matit;
- size = m_materials.size();
- for (i = 0, matit = m_materials.begin(); i < size; ) {
- if (matit->first == scene) {
- m_mat_cache[scene].erase(matit->second->material);
- delete matit->second;
- *matit = m_materials.back();
- m_materials.pop_back();
- size--;
- }
- else {
- i++;
- matit++;
- }
- }
-
- m_mat_cache.erase(scene);
-
- vector<pair<KX_Scene *, RAS_MeshObject *> >::iterator meshit;
- size = m_meshobjects.size();
- for (i = 0, meshit = m_meshobjects.begin(); i < size; ) {
- if (meshit->first == scene) {
- delete meshit->second;
- *meshit = m_meshobjects.back();
- m_meshobjects.pop_back();
- size--;
- }
- else {
- i++;
- meshit++;
- }
- }
-}
-
-// use blender materials
-void KX_BlenderSceneConverter::SetMaterials(bool val)
-{
- m_usemat = val;
- m_useglslmat = false;
-}
-
-void KX_BlenderSceneConverter::SetGLSLMaterials(bool val)
-{
- m_usemat = val;
- m_useglslmat = val;
-}
-
-void KX_BlenderSceneConverter::SetCacheMaterials(bool val)
-{
- m_use_mat_cache = val;
-}
-
-bool KX_BlenderSceneConverter::GetMaterials()
-{
- return m_usemat;
-}
-
-bool KX_BlenderSceneConverter::GetGLSLMaterials()
-{
- return m_useglslmat;
-}
-
-bool KX_BlenderSceneConverter::GetCacheMaterials()
-{
- return m_use_mat_cache;
-}
-
-void KX_BlenderSceneConverter::RegisterBlenderMaterial(BL_Material *mat)
-{
- // First make sure we don't register the material twice
- vector<pair<KX_Scene *, BL_Material *> >::iterator it;
- for (it = m_materials.begin(); it != m_materials.end(); ++it)
- if (it->second == mat)
- return;
-
- m_materials.push_back(pair<KX_Scene *, BL_Material *> (m_currentScene, mat));
-}
-
-void KX_BlenderSceneConverter::SetAlwaysUseExpandFraming(bool to_what)
-{
- m_alwaysUseExpandFraming= to_what;
-}
-
-void KX_BlenderSceneConverter::RegisterGameObject(KX_GameObject *gameobject, Object *for_blenderobject)
-{
- /* only maintained while converting, freed during game runtime */
- m_map_blender_to_gameobject.insert(CHashedPtr(for_blenderobject), gameobject);
-}
-
-/* only need to run this during conversion since
- * m_map_blender_to_gameobject is freed after conversion */
-void KX_BlenderSceneConverter::UnregisterGameObject(KX_GameObject *gameobject)
-{
- Object *bobp = gameobject->GetBlenderObject();
- if (bobp) {
- CHashedPtr bptr(bobp);
- KX_GameObject **gobp = m_map_blender_to_gameobject[bptr];
- if (gobp && *gobp == gameobject) {
- // also maintain m_map_blender_to_gameobject if the gameobject
- // being removed is matching the blender object
- m_map_blender_to_gameobject.remove(bptr);
- }
- }
-}
-
-KX_GameObject *KX_BlenderSceneConverter::FindGameObject(Object *for_blenderobject)
-{
- KX_GameObject **obp = m_map_blender_to_gameobject[CHashedPtr(for_blenderobject)];
-
- return obp ? *obp : NULL;
-}
-
-void KX_BlenderSceneConverter::RegisterGameMesh(RAS_MeshObject *gamemesh, Mesh *for_blendermesh)
-{
- if (for_blendermesh) { /* dynamically loaded meshes we don't want to keep lookups for */
- m_map_mesh_to_gamemesh.insert(CHashedPtr(for_blendermesh),gamemesh);
- }
- m_meshobjects.push_back(pair<KX_Scene *, RAS_MeshObject *> (m_currentScene,gamemesh));
-}
-
-RAS_MeshObject *KX_BlenderSceneConverter::FindGameMesh(Mesh *for_blendermesh)
-{
- RAS_MeshObject **meshp = m_map_mesh_to_gamemesh[CHashedPtr(for_blendermesh)];
-
- if (meshp) {
- return *meshp;
- }
- else {
- return NULL;
- }
-}
-
-void KX_BlenderSceneConverter::RegisterPolyMaterial(RAS_IPolyMaterial *polymat)
-{
- // First make sure we don't register the material twice
- vector<pair<KX_Scene *, RAS_IPolyMaterial *> >::iterator it;
- for (it = m_polymaterials.begin(); it != m_polymaterials.end(); ++it)
- if (it->second == polymat)
- return;
- m_polymaterials.push_back(pair<KX_Scene *, RAS_IPolyMaterial *> (m_currentScene, polymat));
-}
-
-void KX_BlenderSceneConverter::CachePolyMaterial(KX_Scene *scene, Material *mat, RAS_IPolyMaterial *polymat)
-{
- if (m_use_mat_cache && mat)
- m_polymat_cache[scene][mat] = polymat;
-}
-
-RAS_IPolyMaterial *KX_BlenderSceneConverter::FindCachedPolyMaterial(KX_Scene *scene, Material *mat)
-{
- return (m_use_mat_cache) ? m_polymat_cache[scene][mat] : NULL;
-}
-
-void KX_BlenderSceneConverter::CacheBlenderMaterial(KX_Scene *scene, Material *mat, BL_Material *blmat)
-{
- if (m_use_mat_cache && mat)
- m_mat_cache[scene][mat] = blmat;
-}
-
-BL_Material *KX_BlenderSceneConverter::FindCachedBlenderMaterial(KX_Scene *scene, Material *mat)
-{
- return (m_use_mat_cache) ? m_mat_cache[scene][mat] : NULL;
-}
-
-void KX_BlenderSceneConverter::RegisterInterpolatorList(BL_InterpolatorList *actList, bAction *for_act)
-{
- m_map_blender_to_gameAdtList.insert(CHashedPtr(for_act), actList);
-}
-
-BL_InterpolatorList *KX_BlenderSceneConverter::FindInterpolatorList(bAction *for_act)
-{
- BL_InterpolatorList **listp = m_map_blender_to_gameAdtList[CHashedPtr(for_act)];
- return listp ? *listp : NULL;
-}
-
-void KX_BlenderSceneConverter::RegisterGameActuator(SCA_IActuator *act, bActuator *for_actuator)
-{
- m_map_blender_to_gameactuator.insert(CHashedPtr(for_actuator), act);
-}
-
-SCA_IActuator *KX_BlenderSceneConverter::FindGameActuator(bActuator *for_actuator)
-{
- SCA_IActuator **actp = m_map_blender_to_gameactuator[CHashedPtr(for_actuator)];
- return actp ? *actp : NULL;
-}
-
-void KX_BlenderSceneConverter::RegisterGameController(SCA_IController *cont, bController *for_controller)
-{
- m_map_blender_to_gamecontroller.insert(CHashedPtr(for_controller), cont);
-}
-
-SCA_IController *KX_BlenderSceneConverter::FindGameController(bController *for_controller)
-{
- SCA_IController **contp = m_map_blender_to_gamecontroller[CHashedPtr(for_controller)];
- return contp ? *contp : NULL;
-}
-
-void KX_BlenderSceneConverter::RegisterWorldInfo(KX_WorldInfo *worldinfo)
-{
- m_worldinfos.push_back(pair<KX_Scene *, KX_WorldInfo *> (m_currentScene, worldinfo));
-}
-
-void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
-{
- //TODO this entire function is deprecated, written for 2.4x
- //the functionality should be rewritten, currently it does nothing
-
- KX_SceneList *scenes = m_ketsjiEngine->CurrentScenes();
- int numScenes = scenes->size();
- int i;
- for (i = 0; i < numScenes; i++) {
- KX_Scene *scene = scenes->at(i);
- CListValue *parentList = scene->GetRootParentList();
- int numObjects = parentList->GetCount();
- int g;
- for (g = 0; g < numObjects; g++) {
- KX_GameObject *gameObj = (KX_GameObject *)parentList->GetValue(g);
- if (gameObj->IsRecordAnimation()) {
- Object *blenderObject = gameObj->GetBlenderObject();
- if (blenderObject) {
-#if 0
- //erase existing ipo's
- Ipo* ipo = blenderObject->ipo;//findIpoForName(blenderObject->id.name+2);
- if (ipo) { //clear the curve data
- if (clearIpo) {//rcruiz
- IpoCurve *icu1;
-
- int numCurves = 0;
- for ( icu1 = (IpoCurve*)ipo->curve.first; icu1; ) {
-
- IpoCurve* tmpicu = icu1;
-
- /*int i;
- BezTriple *bezt;
- for ( bezt = tmpicu->bezt, i = 0; i < tmpicu->totvert; i++, bezt++) {
- printf("(%f,%f,%f),(%f,%f,%f),(%f,%f,%f)\n",bezt->vec[0][0],bezt->vec[0][1],bezt->vec[0][2],bezt->vec[1][0],bezt->vec[1][1],bezt->vec[1][2],bezt->vec[2][0],bezt->vec[2][1],bezt->vec[2][2]);
- }*/
-
- icu1 = icu1->next;
- numCurves++;
-
- BLI_remlink( &( blenderObject->ipo->curve ), tmpicu );
- if ( tmpicu->bezt )
- MEM_freeN( tmpicu->bezt );
- MEM_freeN( tmpicu );
- localDel_ipoCurve( tmpicu );
- }
- }
- }
- else {
- ipo = NULL; // XXX add_ipo(blenderObject->id.name+2, ID_OB);
- blenderObject->ipo = ipo;
- }
-#endif
- }
- }
- }
- }
-}
-
-void KX_BlenderSceneConverter::resetNoneDynamicObjectToIpo()
-{
- //TODO the functionality should be rewritten
-}
-
-// this generates ipo curves for position, rotation, allowing to use game physics in animation
-void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber)
-{
- KX_SceneList *scenes = m_ketsjiEngine->CurrentScenes();
- int numScenes = scenes->size();
- int i;
- for (i = 0; i < numScenes; i++) {
- KX_Scene *scene = scenes->at(i);
- //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment();
- CListValue *parentList = scene->GetObjectList();
- int numObjects = parentList->GetCount();
- int g;
- for (g = 0; g < numObjects; g++) {
- KX_GameObject *gameObj = (KX_GameObject *)parentList->GetValue(g);
- Object *blenderObject = gameObj->GetBlenderObject();
- if (blenderObject && blenderObject->parent == NULL && gameObj->IsRecordAnimation()) {
- if (blenderObject->adt == NULL)
- BKE_animdata_add_id(&blenderObject->id);
-
- if (blenderObject->adt) {
- const MT_Point3 &position = gameObj->NodeGetWorldPosition();
- //const MT_Vector3& scale = gameObj->NodeGetWorldScaling();
- const MT_Matrix3x3 &orn = gameObj->NodeGetWorldOrientation();
-
- position.getValue(blenderObject->loc);
-
- float tmat[3][3];
- for (int r = 0; r < 3; r++)
- for (int c = 0; c < 3; c++)
- tmat[r][c] = (float)orn[c][r];
-
- mat3_to_compatible_eul(blenderObject->rot, blenderObject->rot, tmat);
-
- insert_keyframe(G.main, NULL, &blenderObject->id, NULL, NULL, "location", -1, (float)frameNumber, BEZT_KEYTYPE_JITTER, INSERTKEY_FAST);
- insert_keyframe(G.main, NULL, &blenderObject->id, NULL, NULL, "rotation_euler", -1, (float)frameNumber, BEZT_KEYTYPE_JITTER, INSERTKEY_FAST);
-
-#if 0
- const MT_Point3& position = gameObj->NodeGetWorldPosition();
- //const MT_Vector3& scale = gameObj->NodeGetWorldScaling();
- const MT_Matrix3x3& orn = gameObj->NodeGetWorldOrientation();
-
- float eulerAngles[3];
- float eulerAnglesOld[3] = {0.0f, 0.0f, 0.0f};
- float tmat[3][3];
-
- // XXX animato
- Ipo* ipo = blenderObject->ipo;
-
- //create the curves, if not existing, set linear if new
-
- IpoCurve *icu_lx = findIpoCurve((IpoCurve *)ipo->curve.first,"LocX");
- if (!icu_lx) {
- icu_lx = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_LOC_X, 1);
- if (icu_lx) icu_lx->ipo = IPO_LIN;
- }
- IpoCurve *icu_ly = findIpoCurve((IpoCurve *)ipo->curve.first,"LocY");
- if (!icu_ly) {
- icu_ly = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_LOC_Y, 1);
- if (icu_ly) icu_ly->ipo = IPO_LIN;
- }
- IpoCurve *icu_lz = findIpoCurve((IpoCurve *)ipo->curve.first,"LocZ");
- if (!icu_lz) {
- icu_lz = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_LOC_Z, 1);
- if (icu_lz) icu_lz->ipo = IPO_LIN;
- }
- IpoCurve *icu_rx = findIpoCurve((IpoCurve *)ipo->curve.first,"RotX");
- if (!icu_rx) {
- icu_rx = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_ROT_X, 1);
- if (icu_rx) icu_rx->ipo = IPO_LIN;
- }
- IpoCurve *icu_ry = findIpoCurve((IpoCurve *)ipo->curve.first,"RotY");
- if (!icu_ry) {
- icu_ry = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_ROT_Y, 1);
- if (icu_ry) icu_ry->ipo = IPO_LIN;
- }
- IpoCurve *icu_rz = findIpoCurve((IpoCurve *)ipo->curve.first,"RotZ");
- if (!icu_rz) {
- icu_rz = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_ROT_Z, 1);
- if (icu_rz) icu_rz->ipo = IPO_LIN;
- }
-
- if (icu_rx) eulerAnglesOld[0] = eval_icu( icu_rx, frameNumber - 1 ) / ((180 / 3.14159265f) / 10);
- if (icu_ry) eulerAnglesOld[1] = eval_icu( icu_ry, frameNumber - 1 ) / ((180 / 3.14159265f) / 10);
- if (icu_rz) eulerAnglesOld[2] = eval_icu( icu_rz, frameNumber - 1 ) / ((180 / 3.14159265f) / 10);
-
- // orn.getValue((float *)tmat); // uses the wrong ordering, cant use this
- for (int r = 0; r < 3; r++)
- for (int c = 0; c < 3; c++)
- tmat[r][c] = orn[c][r];
-
- // mat3_to_eul( eulerAngles,tmat); // better to use Mat3ToCompatibleEul
- mat3_to_compatible_eul( eulerAngles, eulerAnglesOld,tmat);
-
- //eval_icu
- for (int x = 0; x < 3; x++)
- eulerAngles[x] *= (float) ((180 / 3.14159265f) / 10.0);
-
- //fill the curves with data
- if (icu_lx) insert_vert_icu(icu_lx, frameNumber, position.x(), 1);
- if (icu_ly) insert_vert_icu(icu_ly, frameNumber, position.y(), 1);
- if (icu_lz) insert_vert_icu(icu_lz, frameNumber, position.z(), 1);
- if (icu_rx) insert_vert_icu(icu_rx, frameNumber, eulerAngles[0], 1);
- if (icu_ry) insert_vert_icu(icu_ry, frameNumber, eulerAngles[1], 1);
- if (icu_rz) insert_vert_icu(icu_rz, frameNumber, eulerAngles[2], 1);
-
- // Handles are corrected at the end, testhandles_ipocurve isn't needed yet
-#endif
- }
- }
- }
- }
-}
-
-void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo()
-{
- KX_SceneList *scenes = m_ketsjiEngine->CurrentScenes();
- int numScenes = scenes->size();
- int i;
- for (i = 0; i < numScenes; i++) {
- KX_Scene *scene = scenes->at(i);
- //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment();
- CListValue *parentList = scene->GetRootParentList();
- int numObjects = parentList->GetCount();
- int g;
- for (g = 0; g < numObjects; g++) {
- KX_GameObject *gameObj = (KX_GameObject *)parentList->GetValue(g);
- if (gameObj->IsRecordAnimation()) {
- Object *blenderObject = gameObj->GetBlenderObject();
- if (blenderObject && blenderObject->adt) {
- bAction *act = verify_adt_action(G.main, &blenderObject->id, false);
- FCurve *fcu;
-
- if (!act) {
- continue;
- }
-
- /* for now, not much choice but to run this on all curves... */
- for (fcu = (FCurve *)act->curves.first; fcu; fcu = fcu->next) {
- /* Note: calling `sort_time_fcurve()` here is not needed, since
- * all keys have been added in 'right' order. */
- calchandles_fcurve(fcu);
- }
-#if 0
- // XXX animato
- Ipo* ipo = blenderObject->ipo;
-
- //create the curves, if not existing
- //testhandles_ipocurve checks for NULL
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocX"));
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocY"));
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocZ"));
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotX"));
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotY"));
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotZ"));
-#endif
- }
- }
- }
- }
-}
-
-#ifdef WITH_PYTHON
-PyObject *KX_BlenderSceneConverter::GetPyNamespace()
-{
- return m_ketsjiEngine->GetPyNamespace();
-}
-#endif
-
-vector<Main *> &KX_BlenderSceneConverter::GetMainDynamic()
-{
- return m_DynamicMaggie;
-}
-
-Main *KX_BlenderSceneConverter::GetMainDynamicPath(const char *path)
-{
- for (vector<Main *>::iterator it = m_DynamicMaggie.begin(); !(it == m_DynamicMaggie.end()); it++)
- if (BLI_path_cmp((*it)->name, path) == 0)
- return *it;
-
- return NULL;
-}
-
-void KX_BlenderSceneConverter::MergeAsyncLoads()
-{
- vector<KX_Scene *> *merge_scenes;
-
- vector<KX_LibLoadStatus *>::iterator mit;
- vector<KX_Scene *>::iterator sit;
-
- BLI_mutex_lock(&m_threadinfo->m_mutex);
-
- for (mit = m_mergequeue.begin(); mit != m_mergequeue.end(); ++mit) {
- merge_scenes = (vector<KX_Scene *> *)(*mit)->GetData();
-
- for (sit=merge_scenes->begin(); sit!=merge_scenes->end(); ++sit) {
- (*mit)->GetMergeScene()->MergeScene(*sit);
- delete (*sit);
- }
-
- delete merge_scenes;
- (*mit)->SetData(NULL);
-
- (*mit)->Finish();
- }
-
- m_mergequeue.clear();
-
- BLI_mutex_unlock(&m_threadinfo->m_mutex);
-}
-
-void KX_BlenderSceneConverter::FinalizeAsyncLoads()
-{
- // Finish all loading libraries.
- if (m_threadinfo) {
- BLI_task_pool_work_and_wait(m_threadinfo->m_pool);
- }
- // Merge all libraries data in the current scene, to avoid memory leak of unmerged scenes.
- MergeAsyncLoads();
-}
-
-void KX_BlenderSceneConverter::AddScenesToMergeQueue(KX_LibLoadStatus *status)
-{
- BLI_mutex_lock(&m_threadinfo->m_mutex);
- m_mergequeue.push_back(status);
- BLI_mutex_unlock(&m_threadinfo->m_mutex);
-}
-
-static void async_convert(TaskPool *pool, void *ptr, int UNUSED(threadid))
-{
- KX_Scene *new_scene = NULL;
- KX_LibLoadStatus *status = (KX_LibLoadStatus *)ptr;
- vector<Scene *> *scenes = (vector<Scene *> *)status->GetData();
- vector<KX_Scene *> *merge_scenes = new vector<KX_Scene *>(); // Deleted in MergeAsyncLoads
-
- for (unsigned int i = 0; i < scenes->size(); ++i) {
- new_scene = status->GetEngine()->CreateScene((*scenes)[i], true);
-
- if (new_scene)
- merge_scenes->push_back(new_scene);
-
- status->AddProgress((1.0f / scenes->size()) * 0.9f); // We'll call conversion 90% and merging 10% for now
- }
-
- delete scenes;
- status->SetData(merge_scenes);
-
- status->GetConverter()->AddScenesToMergeQueue(status);
-}
-
-KX_LibLoadStatus *KX_BlenderSceneConverter::LinkBlendFileMemory(void *data, int length, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options)
-{
- BlendHandle *bpy_openlib = BLO_blendhandle_from_memory(data, length);
-
- // Error checking is done in LinkBlendFile
- return LinkBlendFile(bpy_openlib, path, group, scene_merge, err_str, options);
-}
-
-KX_LibLoadStatus *KX_BlenderSceneConverter::LinkBlendFilePath(const char *filepath, char *group, KX_Scene *scene_merge, char **err_str, short options)
-{
- BlendHandle *bpy_openlib = BLO_blendhandle_from_file(filepath, NULL);
-
- // Error checking is done in LinkBlendFile
- return LinkBlendFile(bpy_openlib, filepath, group, scene_merge, err_str, options);
-}
-
-static void load_datablocks(Main *main_tmp, BlendHandle *bpy_openlib, const char *path, int idcode)
-{
- LinkNode *names = NULL;
-
- int totnames_dummy;
- names = BLO_blendhandle_get_datablock_names(bpy_openlib, idcode, &totnames_dummy);
-
- int i = 0;
- LinkNode *n = names;
- while (n) {
- BLO_library_link_named_part(main_tmp, &bpy_openlib, idcode, (char *)n->link);
- n = (LinkNode *)n->next;
- i++;
- }
- BLI_linklist_free(names, free); /* free linklist *and* each node's data */
-}
-
-KX_LibLoadStatus *KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options)
-{
- Main *main_newlib; /* stored as a dynamic 'main' until we free it */
- const int idcode = BKE_idcode_from_name(group);
- ReportList reports;
- static char err_local[255];
-
-// TIMEIT_START(bge_link_blend_file);
-
- KX_LibLoadStatus *status;
-
- /* only scene and mesh supported right now */
- if (idcode != ID_SCE && idcode != ID_ME && idcode != ID_AC) {
- snprintf(err_local, sizeof(err_local), "invalid ID type given \"%s\"\n", group);
- *err_str = err_local;
- BLO_blendhandle_close(bpy_openlib);
- return NULL;
- }
-
- if (GetMainDynamicPath(path)) {
- snprintf(err_local, sizeof(err_local), "blend file already open \"%s\"\n", path);
- *err_str = err_local;
- BLO_blendhandle_close(bpy_openlib);
- return NULL;
- }
-
- if (bpy_openlib == NULL) {
- snprintf(err_local, sizeof(err_local), "could not open blendfile \"%s\"\n", path);
- *err_str = err_local;
- return NULL;
- }
-
- main_newlib = BKE_main_new();
- BKE_reports_init(&reports, RPT_STORE);
-
- short flag = 0; /* don't need any special options */
- /* created only for linking, then freed */
- Main *main_tmp = BLO_library_link_begin(main_newlib, &bpy_openlib, (char *)path);
-
- load_datablocks(main_tmp, bpy_openlib, path, idcode);
-
- if (idcode == ID_SCE && options & LIB_LOAD_LOAD_SCRIPTS) {
- load_datablocks(main_tmp, bpy_openlib, path, ID_TXT);
- }
-
- /* now do another round of linking for Scenes so all actions are properly loaded */
- if (idcode == ID_SCE && options & LIB_LOAD_LOAD_ACTIONS) {
- load_datablocks(main_tmp, bpy_openlib, path, ID_AC);
- }
-
- BLO_library_link_end(main_tmp, &bpy_openlib, flag, NULL, NULL);
-
- BLO_blendhandle_close(bpy_openlib);
-
- BKE_reports_clear(&reports);
- /* done linking */
-
- /* needed for lookups*/
- GetMainDynamic().push_back(main_newlib);
- BLI_strncpy(main_newlib->name, path, sizeof(main_newlib->name));
-
-
- status = new KX_LibLoadStatus(this, m_ketsjiEngine, scene_merge, path);
-
- if (idcode == ID_ME) {
- /* Convert all new meshes into BGE meshes */
- ID *mesh;
-
- for (mesh = (ID *)main_newlib->mesh.first; mesh; mesh = (ID *)mesh->next ) {
- if (options & LIB_LOAD_VERBOSE)
- printf("MeshName: %s\n", mesh->name + 2);
- RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)mesh, NULL, scene_merge, this, false); // For now only use the libloading option for scenes, which need to handle materials/shaders
- scene_merge->GetLogicManager()->RegisterMeshName(meshobj->GetName(), meshobj);
- }
- }
- else if (idcode == ID_AC) {
- /* Convert all actions */
- ID *action;
-
- for (action= (ID *)main_newlib->action.first; action; action = (ID *)action->next) {
- if (options & LIB_LOAD_VERBOSE)
- printf("ActionName: %s\n", action->name + 2);
- scene_merge->GetLogicManager()->RegisterActionName(action->name + 2, action);
- }
- }
- else if (idcode == ID_SCE) {
- /* Merge all new linked in scene into the existing one */
- ID *scene;
- // scenes gets deleted by the thread when it's done using it (look in async_convert())
- vector<Scene *> *scenes = (options & LIB_LOAD_ASYNC) ? new vector<Scene *>() : NULL;
-
- for (scene = (ID *)main_newlib->scene.first; scene; scene = (ID *)scene->next ) {
- if (options & LIB_LOAD_VERBOSE)
- printf("SceneName: %s\n", scene->name + 2);
-
- if (options & LIB_LOAD_ASYNC) {
- scenes->push_back((Scene *)scene);
- }
- else {
- /* merge into the base scene */
- KX_Scene* other = m_ketsjiEngine->CreateScene((Scene *)scene, true);
- scene_merge->MergeScene(other);
-
- // RemoveScene(other); // Don't run this, it frees the entire scene converter data, just delete the scene
- delete other;
- }
- }
-
- if (options & LIB_LOAD_ASYNC) {
- status->SetData(scenes);
- BLI_task_pool_push(m_threadinfo->m_pool, async_convert, (void *)status, false, TASK_PRIORITY_LOW);
- }
-
-#ifdef WITH_PYTHON
- /* Handle any text datablocks */
- if (options & LIB_LOAD_LOAD_SCRIPTS)
- addImportMain(main_newlib);
-#endif
-
- /* Now handle all the actions */
- if (options & LIB_LOAD_LOAD_ACTIONS) {
- ID *action;
-
- for (action = (ID *)main_newlib->action.first; action; action = (ID *)action->next) {
- if (options & LIB_LOAD_VERBOSE)
- printf("ActionName: %s\n", action->name + 2);
- scene_merge->GetLogicManager()->RegisterActionName(action->name + 2, action);
- }
- }
- }
-
- if (!(options & LIB_LOAD_ASYNC))
- status->Finish();
-
-// TIMEIT_END(bge_link_blend_file);
-
- m_status_map[main_newlib->name] = status;
- return status;
-}
-
-/* Note m_map_*** are all ok and don't need to be freed
- * most are temp and NewRemoveObject frees m_map_gameobject_to_blender */
-bool KX_BlenderSceneConverter::FreeBlendFile(Main *maggie)
-{
- int maggie_index = -1;
- int i = 0;
-
- if (maggie == NULL)
- return false;
-
- // If the given library is currently in loading, we do nothing.
- if (m_status_map.count(maggie->name)) {
- BLI_mutex_lock(&m_threadinfo->m_mutex);
- const bool finished = m_status_map[maggie->name]->IsFinished();
- BLI_mutex_unlock(&m_threadinfo->m_mutex);
-
- if (!finished) {
- printf("Library (%s) is currently being loaded asynchronously, and cannot be freed until this process is done\n", maggie->name);
- return false;
- }
- }
-
- /* tag all false except the one we remove */
- for (vector<Main *>::iterator it = m_DynamicMaggie.begin(); !(it == m_DynamicMaggie.end()); it++) {
- Main *main = *it;
- if (main != maggie) {
- BKE_main_id_tag_all(main, LIB_TAG_DOIT, false);
- }
- else {
- maggie_index = i;
- }
- i++;
- }
-
- /* should never happen but just to be safe */
- if (maggie_index == -1)
- return false;
-
- m_DynamicMaggie.erase(m_DynamicMaggie.begin() + maggie_index);
- BKE_main_id_tag_all(maggie, LIB_TAG_DOIT, true);
-
- /* free all tagged objects */
- KX_SceneList *scenes = m_ketsjiEngine->CurrentScenes();
- int numScenes = scenes->size();
-
- for (int scene_idx = 0; scene_idx < numScenes; scene_idx++) {
- KX_Scene *scene = scenes->at(scene_idx);
- if (IS_TAGGED(scene->GetBlenderScene())) {
- m_ketsjiEngine->RemoveScene(scene->GetName());
- m_mat_cache.erase(scene);
- m_polymat_cache.erase(scene);
- scene_idx--;
- numScenes--;
- }
- else {
- /* in case the mesh might be refered to later */
- {
- CTR_Map<STR_HashedString, void *> &mapStringToMeshes = scene->GetLogicManager()->GetMeshMap();
-
- for (int i = 0; i < mapStringToMeshes.size(); i++) {
- RAS_MeshObject *meshobj = (RAS_MeshObject *) *mapStringToMeshes.at(i);
- if (meshobj && IS_TAGGED(meshobj->GetMesh())) {
- STR_HashedString mn = meshobj->GetName();
- mapStringToMeshes.remove(mn);
- m_map_mesh_to_gamemesh.remove(CHashedPtr(meshobj->GetMesh()));
- i--;
- }
- }
- }
-
- /* Now unregister actions */
- {
- CTR_Map<STR_HashedString, void *> &mapStringToActions = scene->GetLogicManager()->GetActionMap();
-
- for (int i = 0; i < mapStringToActions.size(); i++) {
- ID *action = (ID*) *mapStringToActions.at(i);
-
- if (IS_TAGGED(action)) {
- STR_HashedString an = action->name + 2;
- mapStringToActions.remove(an);
- m_map_blender_to_gameAdtList.remove(CHashedPtr(action));
- i--;
- }
- }
- }
-
- //scene->FreeTagged(); /* removed tagged objects and meshes*/
- CListValue *obj_lists[] = {scene->GetObjectList(), scene->GetInactiveList(), NULL};
-
- for (int ob_ls_idx = 0; obj_lists[ob_ls_idx]; ob_ls_idx++) {
- CListValue *obs = obj_lists[ob_ls_idx];
- RAS_MeshObject *mesh;
-
- for (int ob_idx = 0; ob_idx < obs->GetCount(); ob_idx++) {
- KX_GameObject *gameobj = (KX_GameObject*)obs->GetValue(ob_idx);
- if (IS_TAGGED(gameobj->GetBlenderObject())) {
- int size_before = obs->GetCount();
-
- /* Eventually calls RemoveNodeDestructObject
- * frees m_map_gameobject_to_blender from UnregisterGameObject */
- scene->RemoveObject(gameobj);
-
- if (size_before != obs->GetCount())
- ob_idx--;
- else {
- printf("ERROR COULD NOT REMOVE \"%s\"\n", gameobj->GetName().ReadPtr());
- }
- }
- else {
- gameobj->RemoveTaggedActions();
- /* free the mesh, we could be referecing a linked one! */
- int mesh_index = gameobj->GetMeshCount();
- while (mesh_index--) {
- mesh = gameobj->GetMesh(mesh_index);
- if (IS_TAGGED(mesh->GetMesh())) {
- gameobj->RemoveMeshes(); /* XXX - slack, should only remove meshes that are library items but mostly objects only have 1 mesh */
- break;
- }
- else {
- /* also free the mesh if it's using a tagged material */
- int mat_index = mesh->NumMaterials();
- while (mat_index--) {
- if (IS_TAGGED(mesh->GetMeshMaterial(mat_index)->m_bucket->GetPolyMaterial()->GetBlenderMaterial())) {
- gameobj->RemoveMeshes(); /* XXX - slack, same as above */
- break;
- }
- }
- }
- }
-
- /* make sure action actuators are not referencing tagged actions */
- for (unsigned int act_idx = 0; act_idx < gameobj->GetActuators().size(); act_idx++) {
- if (gameobj->GetActuators()[act_idx]->IsType(SCA_IActuator::KX_ACT_ACTION)) {
- BL_ActionActuator *act = (BL_ActionActuator *)gameobj->GetActuators()[act_idx];
- if (IS_TAGGED(act->GetAction()))
- act->SetAction(NULL);
- }
- }
- }
- }
- }
- }
- }
-
- int size;
-
- // delete the entities of this scene
- /* TODO - */
-#if 0
- vector<pair<KX_Scene*,KX_WorldInfo*> >::iterator worldit;
- size = m_worldinfos.size();
- for (i=0, worldit=m_worldinfos.begin(); i<size; ) {
- if ((*worldit).second) {
- delete (*worldit).second;
- *worldit = m_worldinfos.back();
- m_worldinfos.pop_back();
- size--;
- } else {
- i++;
- worldit++;
- }
- }
-#endif
-
-
- /* Worlds don't reference original blender data so we need to make a set from them */
- typedef std::set<KX_WorldInfo *> KX_WorldInfoSet;
- KX_WorldInfoSet worldset;
- for (int scene_idx = 0; scene_idx < numScenes; scene_idx++) {
- KX_Scene *scene = scenes->at(scene_idx);
- if (scene->GetWorldInfo())
- worldset.insert(scene->GetWorldInfo());
- }
-
- vector<pair<KX_Scene *, KX_WorldInfo *> >::iterator worldit;
- size = m_worldinfos.size();
- for (i = 0, worldit = m_worldinfos.begin(); i < size;) {
- if (worldit->second && (worldset.count(worldit->second)) == 0) {
- delete worldit->second;
- *worldit = m_worldinfos.back();
- m_worldinfos.pop_back();
- size--;
- }
- else {
- i++;
- worldit++;
- }
- }
- worldset.clear();
- /* done freeing the worlds */
-
- vector<pair<KX_Scene *, RAS_IPolyMaterial *> >::iterator polymit;
- size = m_polymaterials.size();
-
- for (i = 0, polymit = m_polymaterials.begin(); i < size; ) {
- RAS_IPolyMaterial *mat = polymit->second;
- Material *bmat = NULL;
-
- KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial *>(mat);
- bmat = bl_mat->GetBlenderMaterial();
-
- if (IS_TAGGED(bmat)) {
- /* only remove from bucket */
- polymit->first->GetBucketManager()->RemoveMaterial(mat);
- }
-
- i++;
- polymit++;
- }
-
- for (i = 0, polymit = m_polymaterials.begin(); i < size; ) {
- RAS_IPolyMaterial *mat = polymit->second;
- Material *bmat = NULL;
-
- KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial*>(mat);
- bmat = bl_mat->GetBlenderMaterial();
-
- if (IS_TAGGED(bmat)) {
- // Remove the poly material coresponding to this Blender Material.
- m_polymat_cache[polymit->first].erase(bmat);
- delete polymit->second;
- *polymit = m_polymaterials.back();
- m_polymaterials.pop_back();
- size--;
- } else {
- i++;
- polymit++;
- }
- }
-
- vector<pair<KX_Scene *, BL_Material *> >::iterator matit;
- size = m_materials.size();
- for (i = 0, matit = m_materials.begin(); i < size; ) {
- BL_Material *mat = matit->second;
- if (IS_TAGGED(mat->material)) {
- // Remove the bl material coresponding to this Blender Material.
- m_mat_cache[matit->first].erase(mat->material);
- delete matit->second;
- *matit = m_materials.back();
- m_materials.pop_back();
- size--;
- }
- else {
- i++;
- matit++;
- }
- }
-
- vector<pair<KX_Scene *, RAS_MeshObject *> >::iterator meshit;
- RAS_BucketManager::BucketList::iterator bit;
- list<RAS_MeshSlot>::iterator msit;
- RAS_BucketManager::BucketList buckets;
-
- size = m_meshobjects.size();
- for (i = 0, meshit = m_meshobjects.begin(); i < size;) {
- RAS_MeshObject *me = meshit->second;
- if (IS_TAGGED(me->GetMesh())) {
- // Before deleting the mesh object, make sure the rasterizer is
- // no longer referencing it.
- buckets = meshit->first->GetBucketManager()->GetSolidBuckets();
- for (bit = buckets.begin(); bit != buckets.end(); bit++) {
- msit = (*bit)->msBegin();
-
- while (msit != (*bit)->msEnd()) {
- if (msit->m_mesh == meshit->second)
- (*bit)->RemoveMesh(&(*msit++));
- else
- msit++;
- }
- }
-
- // And now the alpha buckets
- buckets = meshit->first->GetBucketManager()->GetAlphaBuckets();
- for (bit = buckets.begin(); bit != buckets.end(); bit++) {
- msit = (*bit)->msBegin();
-
- while (msit != (*bit)->msEnd()) {
- if (msit->m_mesh == meshit->second)
- (*bit)->RemoveMesh(&(*msit++));
- else
- msit++;
- }
- }
-
- // Now it should be safe to delete
- delete meshit->second;
- *meshit = m_meshobjects.back();
- m_meshobjects.pop_back();
- size--;
- }
- else {
- i++;
- meshit++;
- }
- }
-
-#ifdef WITH_PYTHON
- /* make sure this maggie is removed from the import list if it's there
- * (this operation is safe if it isn't in the list) */
- removeImportMain(maggie);
-#endif
-
- delete m_status_map[maggie->name];
- m_status_map.erase(maggie->name);
-
- BKE_main_free(maggie);
-
- return true;
-}
-
-bool KX_BlenderSceneConverter::FreeBlendFile(const char *path)
-{
- return FreeBlendFile(GetMainDynamicPath(path));
-}
-
-bool KX_BlenderSceneConverter::MergeScene(KX_Scene *to, KX_Scene *from)
-{
- {
- vector<pair<KX_Scene *, KX_WorldInfo *> >::iterator itp = m_worldinfos.begin();
- while (itp != m_worldinfos.end()) {
- if (itp->first == from)
- itp->first = to;
- itp++;
- }
- }
-
- {
- vector<pair<KX_Scene *, RAS_IPolyMaterial *> >::iterator itp = m_polymaterials.begin();
- while (itp != m_polymaterials.end()) {
- if (itp->first == from) {
- itp->first = to;
-
- /* also switch internal data */
- RAS_IPolyMaterial *mat = itp->second;
- mat->Replace_IScene(to);
- }
- itp++;
- }
- }
-
- {
- vector<pair<KX_Scene *, RAS_MeshObject *> >::iterator itp = m_meshobjects.begin();
- while (itp != m_meshobjects.end()) {
- if (itp->first == from)
- itp->first = to;
- itp++;
- }
- }
-
- {
- vector<pair<KX_Scene *, BL_Material *> >::iterator itp = m_materials.begin();
- while (itp != m_materials.end()) {
- if (itp->first == from)
- itp->first = to;
- itp++;
- }
- }
-
- MaterialCache::iterator matcacheit = m_mat_cache.find(from);
- if (matcacheit != m_mat_cache.end()) {
- // Merge cached BL_Material map.
- m_mat_cache[to].insert(matcacheit->second.begin(), matcacheit->second.end());
- m_mat_cache.erase(matcacheit);
- }
-
- PolyMaterialCache::iterator polymatcacheit = m_polymat_cache.find(from);
- if (polymatcacheit != m_polymat_cache.end()) {
- // Merge cached RAS_IPolyMaterial map.
- m_polymat_cache[to].insert(polymatcacheit->second.begin(), polymatcacheit->second.end());
- m_polymat_cache.erase(polymatcacheit);
- }
-
- return true;
-}
-
-/* This function merges a mesh from the current scene into another main
- * it does not convert */
-RAS_MeshObject *KX_BlenderSceneConverter::ConvertMeshSpecial(KX_Scene *kx_scene, Main *maggie, const char *name)
-{
- /* Find a mesh in the current main */
- ID *me= static_cast<ID *>(BLI_findstring(&m_maggie->mesh, name, offsetof(ID, name) + 2));
- Main *from_maggie = m_maggie;
-
- if (me == NULL) {
- // The mesh wasn't in the current main, try any dynamic (i.e., LibLoaded) ones
- vector<Main *>::iterator it;
-
- for (it = GetMainDynamic().begin(); it != GetMainDynamic().end(); it++) {
- me = static_cast<ID *>(BLI_findstring(&(*it)->mesh, name, offsetof(ID, name) + 2));
- from_maggie = *it;
-
- if (me)
- break;
- }
- }
-
- if (me == NULL) {
- printf("Could not be found \"%s\"\n", name);
- return NULL;
- }
-
- /* Watch this!, if its used in the original scene can cause big troubles */
- if (me->us > 0) {
-#ifdef DEBUG
- printf("Mesh has a user \"%s\"\n", name);
-#endif
- me = (ID*)BKE_mesh_copy(from_maggie, (Mesh*)me);
- id_us_min(me);
- }
- BLI_remlink(&from_maggie->mesh, me); /* even if we made the copy it needs to be removed */
- BLI_addtail(&maggie->mesh, me);
-
- /* Must copy the materials this uses else we cant free them */
- {
- Mesh *mesh = (Mesh *)me;
-
- /* ensure all materials are tagged */
- for (int i = 0; i < mesh->totcol; i++) {
- if (mesh->mat[i])
- mesh->mat[i]->id.tag &= ~LIB_TAG_DOIT;
- }
-
- for (int i = 0; i < mesh->totcol; i++) {
- Material *mat_old = mesh->mat[i];
-
- /* if its tagged its a replaced material */
- if (mat_old && (mat_old->id.tag & LIB_TAG_DOIT) == 0) {
- Material *mat_old = mesh->mat[i];
- Material *mat_new = BKE_material_copy(from_maggie, mat_old);
-
- mat_new->id.tag |= LIB_TAG_DOIT;
- id_us_min(&mat_old->id);
-
- BLI_remlink(&from_maggie->mat, mat_new); // BKE_material_copy uses G.main, and there is no BKE_material_copy_ex
- BLI_addtail(&maggie->mat, mat_new);
-
- mesh->mat[i] = mat_new;
-
- /* the same material may be used twice */
- for (int j = i + 1; j < mesh->totcol; j++) {
- if (mesh->mat[j] == mat_old) {
- mesh->mat[j] = mat_new;
- id_us_plus(&mat_new->id);
- id_us_min(&mat_old->id);
- }
- }
- }
- }
- }
-
- m_currentScene = kx_scene; // This needs to be set in case we LibLoaded earlier
- RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)me, NULL, kx_scene, this, false);
- kx_scene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj);
- m_map_mesh_to_gamemesh.clear(); /* This is at runtime so no need to keep this, BL_ConvertMesh adds */
- return meshobj;
-}
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h
deleted file mode 100644
index 3379f00c38a..00000000000
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.h
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_BlenderSceneConverter.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_BLENDERSCENECONVERTER_H__
-#define __KX_BLENDERSCENECONVERTER_H__
-
-#include "EXP_HashedPtr.h"
-#include "CTR_Map.h"
-#include <stdio.h>
-
-#include "KX_ISceneConverter.h"
-#include "KX_IpoConvert.h"
-
-#include <map>
-
-using namespace std;
-
-class KX_WorldInfo;
-class SCA_IActuator;
-class SCA_IController;
-class RAS_MeshObject;
-class RAS_IPolyMaterial;
-class BL_InterpolatorList;
-class BL_Material;
-struct Main;
-struct Scene;
-struct ThreadInfo;
-struct Material;
-
-typedef map<KX_Scene*, map<Material*, BL_Material*> > MaterialCache;
-typedef map<KX_Scene*, map<Material*, RAS_IPolyMaterial*> > PolyMaterialCache;
-
-class KX_BlenderSceneConverter : public KX_ISceneConverter
-{
- // Use vector of pairs to allow removal of entities between scene switch
- vector<pair<KX_Scene*,KX_WorldInfo*> > m_worldinfos;
- vector<pair<KX_Scene*,RAS_IPolyMaterial*> > m_polymaterials;
- vector<pair<KX_Scene*,RAS_MeshObject*> > m_meshobjects;
- vector<pair<KX_Scene*,BL_Material *> > m_materials;
-
- vector<class KX_LibLoadStatus*> m_mergequeue;
- ThreadInfo *m_threadinfo;
-
- // Cached material conversions
- MaterialCache m_mat_cache;
- PolyMaterialCache m_polymat_cache;
-
- // Saved KX_LibLoadStatus objects
- map<char *, class KX_LibLoadStatus*> m_status_map;
-
- // Should also have a list of collision shapes.
- // For the time being this is held in KX_Scene::m_shapes
-
- CTR_Map<CHashedPtr,KX_GameObject*> m_map_blender_to_gameobject; /* cleared after conversion */
- CTR_Map<CHashedPtr,RAS_MeshObject*> m_map_mesh_to_gamemesh; /* cleared after conversion */
- CTR_Map<CHashedPtr,SCA_IActuator*> m_map_blender_to_gameactuator; /* cleared after conversion */
- CTR_Map<CHashedPtr,SCA_IController*>m_map_blender_to_gamecontroller; /* cleared after conversion */
-
- CTR_Map<CHashedPtr,BL_InterpolatorList*> m_map_blender_to_gameAdtList;
-
- Main* m_maggie;
- vector<struct Main*> m_DynamicMaggie;
-
- STR_String m_newfilename;
- class KX_KetsjiEngine* m_ketsjiEngine;
- class KX_Scene* m_currentScene; // Scene being converted
- bool m_alwaysUseExpandFraming;
- bool m_usemat;
- bool m_useglslmat;
- bool m_use_mat_cache;
-
-public:
- KX_BlenderSceneConverter(
- Main* maggie,
- class KX_KetsjiEngine* engine
- );
-
- virtual ~KX_BlenderSceneConverter();
-
- /* Scenename: name of the scene to be converted.
- * destinationscene: pass an empty scene, everything goes into this
- * dictobj: python dictionary (for pythoncontrollers)
- */
- virtual void ConvertScene(
- class KX_Scene* destinationscene,
- class RAS_IRasterizer* rendertools,
- class RAS_ICanvas* canvas,
- bool libloading=false
- );
- virtual void RemoveScene(class KX_Scene *scene);
-
- void SetNewFileName(const STR_String& filename);
- bool TryAndLoadNewFile();
-
- void SetAlwaysUseExpandFraming(bool to_what);
-
- void RegisterGameObject(KX_GameObject *gameobject, struct Object *for_blenderobject);
- void UnregisterGameObject(KX_GameObject *gameobject);
- KX_GameObject *FindGameObject(struct Object *for_blenderobject);
-
- void RegisterGameMesh(RAS_MeshObject *gamemesh, struct Mesh *for_blendermesh);
- RAS_MeshObject *FindGameMesh(struct Mesh *for_blendermesh/*, unsigned int onlayer*/);
-
- void RegisterPolyMaterial(RAS_IPolyMaterial *polymat);
- void CachePolyMaterial(KX_Scene *scene, Material *mat, RAS_IPolyMaterial *polymat);
- RAS_IPolyMaterial *FindCachedPolyMaterial(KX_Scene *scene, Material *mat);
-
- void RegisterBlenderMaterial(BL_Material *mat);
- void CacheBlenderMaterial(KX_Scene *scene, Material *mat, BL_Material *blmat);
- BL_Material *FindCachedBlenderMaterial(KX_Scene *scene, Material *mat);
-
- void RegisterInterpolatorList(BL_InterpolatorList *actList, struct bAction *for_act);
- BL_InterpolatorList *FindInterpolatorList(struct bAction *for_act);
-
- void RegisterGameActuator(SCA_IActuator *act, struct bActuator *for_actuator);
- SCA_IActuator *FindGameActuator(struct bActuator *for_actuator);
-
- void RegisterGameController(SCA_IController *cont, struct bController *for_controller);
- SCA_IController *FindGameController(struct bController *for_controller);
-
- void RegisterWorldInfo(KX_WorldInfo *worldinfo);
-
- virtual void ResetPhysicsObjectsAnimationIpo(bool clearIpo);
-
- ///this is for reseting the position,rotation and scale of the gameobjet that is not dynamic
- virtual void resetNoneDynamicObjectToIpo();
-
- ///this generates ipo curves for position, rotation, allowing to use game physics in animation
- virtual void WritePhysicsObjectToAnimationIpo(int frameNumber);
- virtual void TestHandlesPhysicsObjectToAnimationIpo();
-
- // use blender materials
- virtual void SetMaterials(bool val);
- virtual bool GetMaterials();
-
- // use blender glsl materials
- virtual void SetGLSLMaterials(bool val);
- virtual bool GetGLSLMaterials();
-
- // cache materials during conversion
- virtual void SetCacheMaterials(bool val);
- virtual bool GetCacheMaterials();
-
- struct Scene* GetBlenderSceneForName(const STR_String& name);
-
-// struct Main* GetMain() { return m_maggie; }
- struct Main* GetMainDynamicPath(const char *path);
- vector<struct Main*> &GetMainDynamic();
-
- class KX_LibLoadStatus *LinkBlendFileMemory(void *data, int length, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options);
- class KX_LibLoadStatus *LinkBlendFilePath(const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options);
- class KX_LibLoadStatus *LinkBlendFile(struct BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options);
- bool MergeScene(KX_Scene *to, KX_Scene *from);
- RAS_MeshObject *ConvertMeshSpecial(KX_Scene* kx_scene, Main *maggie, const char *name);
- bool FreeBlendFile(struct Main *maggie);
- bool FreeBlendFile(const char *path);
-
- virtual void MergeAsyncLoads();
- virtual void FinalizeAsyncLoads();
- void AddScenesToMergeQueue(class KX_LibLoadStatus *status);
-
- void PrintStats() {
- printf("BGE STATS!\n");
-
- printf("\nAssets...\n");
- printf("\t m_worldinfos: %d\n", (int)m_worldinfos.size());
- printf("\t m_polymaterials: %d\n", (int)m_polymaterials.size());
- printf("\t m_meshobjects: %d\n", (int)m_meshobjects.size());
- printf("\t m_materials: %d\n", (int)m_materials.size());
-
- printf("\nMappings...\n");
- printf("\t m_map_blender_to_gameobject: %d\n", m_map_blender_to_gameobject.size());
- printf("\t m_map_mesh_to_gamemesh: %d\n", m_map_mesh_to_gamemesh.size());
- printf("\t m_map_blender_to_gameactuator: %d\n", m_map_blender_to_gameactuator.size());
- printf("\t m_map_blender_to_gamecontroller: %d\n", m_map_blender_to_gamecontroller.size());
- printf("\t m_map_blender_to_gameAdtList: %d\n", m_map_blender_to_gameAdtList.size());
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_printmemlist_pydict();
-#endif
-// /printf("\t m_ketsjiEngine->m_scenes: %d\n", m_ketsjiEngine->CurrentScenes()->size());
- }
-
- /* LibLoad Options */
- enum
- {
- LIB_LOAD_LOAD_ACTIONS = 1,
- LIB_LOAD_VERBOSE = 2,
- LIB_LOAD_LOAD_SCRIPTS = 4,
- LIB_LOAD_ASYNC = 8,
- };
-
-
-
-#ifdef WITH_PYTHON
- PyObject *GetPyNamespace();
-#endif
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_BlenderSceneConverter")
-#endif
-};
-
-#endif /* __KX_BLENDERSCENECONVERTER_H__ */
diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp
deleted file mode 100644
index d4582425b36..00000000000
--- a/source/gameengine/Converter/KX_ConvertActuators.cpp
+++ /dev/null
@@ -1,1146 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Convert Blender actuators for use in the GameEngine
- */
-
-/** \file gameengine/Converter/KX_ConvertActuators.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include <math.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "KX_BlenderSceneConverter.h"
-#include "KX_ConvertActuators.h"
-
-#ifdef WITH_AUDASPACE
-# include AUD_SOUND_H
-#endif
-
-// Actuators
-//SCA logiclibrary native logicbricks
-#include "SCA_PropertyActuator.h"
-#include "SCA_LogicManager.h"
-#include "SCA_RandomActuator.h"
-#include "SCA_2DFilterActuator.h"
-
-// Ketsji specific logicbricks
-#include "KX_SceneActuator.h"
-#include "KX_SoundActuator.h"
-#include "KX_ObjectActuator.h"
-#include "KX_TrackToActuator.h"
-#include "KX_ConstraintActuator.h"
-#include "KX_CameraActuator.h"
-#include "KX_GameActuator.h"
-#include "KX_StateActuator.h"
-#include "KX_VisibilityActuator.h"
-#include "KX_SCA_AddObjectActuator.h"
-#include "KX_SCA_EndObjectActuator.h"
-#include "KX_SCA_ReplaceMeshActuator.h"
-#include "KX_ParentActuator.h"
-#include "KX_SCA_DynamicActuator.h"
-#include "KX_SteeringActuator.h"
-#include "KX_MouseActuator.h"
-
-#include "KX_Scene.h"
-#include "KX_KetsjiEngine.h"
-
-#include "EXP_IntValue.h"
-#include "KX_GameObject.h"
-
-/* This little block needed for linking to Blender... */
-#include "BKE_text.h"
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_path_util.h"
-
-#include "KX_NetworkMessageActuator.h"
-
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-#include "DNA_object_types.h"
-#include "DNA_sound_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_actuator_types.h"
-#include "DNA_packedFile_types.h"
-#include "BL_ActionActuator.h"
-#include "BL_ShapeActionActuator.h"
-#include "BL_ArmatureActuator.h"
-#include "RNA_access.h"
-#include "BL_Action.h"
-/* end of blender include block */
-
-#include "BL_BlenderDataConversion.h"
-
-/**
- * KX_flt_trunc needed to round 'almost' zero values to zero, else velocities etc. are incorrectly set
- */
-
-BLI_INLINE float KX_flt_trunc(const float x)
-{
- return ( x < 0.0001f && x > -0.0001f ) ? 0.0f : x;
-}
-
-void BL_ConvertActuators(const char* maggiename,
- struct Object* blenderobject,
- KX_GameObject* gameobj,
- SCA_LogicManager* logicmgr,
- KX_Scene* scene,
- KX_KetsjiEngine* ketsjiEngine,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- KX_BlenderSceneConverter* converter
- )
-{
-
- int uniqueint = 0;
- int actcount = 0;
- int executePriority = 0;
- bActuator* bact = (bActuator*) blenderobject->actuators.first;
- while (bact)
- {
- actcount++;
- bact = bact->next;
- }
- gameobj->ReserveActuator(actcount);
- bact = (bActuator*) blenderobject->actuators.first;
- while (bact)
- {
- STR_String uniquename = bact->name;
- STR_String& objectname = gameobj->GetName();
-
- SCA_IActuator* baseact = NULL;
- switch (bact->type)
- {
- case ACT_OBJECT:
- {
- bObjectActuator* obact = (bObjectActuator*) bact->data;
- KX_GameObject* obref = NULL;
- MT_Vector3 forcevec(KX_flt_trunc(obact->forceloc[0]),
- KX_flt_trunc(obact->forceloc[1]),
- KX_flt_trunc(obact->forceloc[2]));
- MT_Vector3 torquevec(obact->forcerot[0],
- obact->forcerot[1],
- obact->forcerot[2]);
- MT_Vector3 dlocvec(KX_flt_trunc(obact->dloc[0]),
- KX_flt_trunc(obact->dloc[1]),
- KX_flt_trunc(obact->dloc[2]));
- MT_Vector3 drotvec(KX_flt_trunc(obact->drot[0]),
- obact->drot[1],obact->drot[2]);
- MT_Vector3 linvelvec(KX_flt_trunc(obact->linearvelocity[0]),
- KX_flt_trunc(obact->linearvelocity[1]),
- KX_flt_trunc(obact->linearvelocity[2]));
- MT_Vector3 angvelvec(KX_flt_trunc(obact->angularvelocity[0]),
- KX_flt_trunc(obact->angularvelocity[1]),
- KX_flt_trunc(obact->angularvelocity[2]));
- short damping = obact->damping;
-
- /* Blender uses a bit vector internally for the local-flags. In */
- /* KX, we have four bools. The compiler should be smart enough */
- /* to do the right thing. We need to explicitly convert here! */
-
- KX_LocalFlags bitLocalFlag;
-
- bitLocalFlag.Force = bool((obact->flag & ACT_FORCE_LOCAL)!=0);
- bitLocalFlag.Torque = bool((obact->flag & ACT_TORQUE_LOCAL) !=0);//rlocal;
- bitLocalFlag.DLoc = bool((obact->flag & ACT_DLOC_LOCAL)!=0);
- bitLocalFlag.DRot = bool((obact->flag & ACT_DROT_LOCAL)!=0);
- bitLocalFlag.LinearVelocity = bool((obact->flag & ACT_LIN_VEL_LOCAL)!=0);
- bitLocalFlag.AngularVelocity = bool((obact->flag & ACT_ANG_VEL_LOCAL)!=0);
- bitLocalFlag.ServoControl = bool(obact->type == ACT_OBJECT_SERVO);
- bitLocalFlag.CharacterMotion = bool(obact->type == ACT_OBJECT_CHARACTER);
- bitLocalFlag.CharacterJump = bool((obact->flag & ACT_CHAR_JUMP)!=0);
- bitLocalFlag.AddOrSetLinV = bool((obact->flag & ACT_ADD_LIN_VEL)!=0);
- bitLocalFlag.AddOrSetCharLoc = bool((obact->flag & ACT_ADD_CHAR_LOC)!=0);
- if (obact->reference && bitLocalFlag.ServoControl)
- {
- obref = converter->FindGameObject(obact->reference);
- }
-
- KX_ObjectActuator* tmpbaseact = new KX_ObjectActuator(
- gameobj,
- obref,
- forcevec.getValue(),
- torquevec.getValue(),
- dlocvec.getValue(),
- drotvec.getValue(),
- linvelvec.getValue(),
- angvelvec.getValue(),
- damping,
- bitLocalFlag);
- baseact = tmpbaseact;
- break;
- }
- case ACT_ACTION:
- {
- bActionActuator* actact = (bActionActuator*) bact->data;
- STR_String propname = actact->name;
- STR_String propframe = actact->frameProp;
-
- short ipo_flags = 0;
-
- // Convert flags
- if (actact->flag & ACT_IPOFORCE) ipo_flags |= BL_Action::ACT_IPOFLAG_FORCE;
- if (actact->flag & ACT_IPOLOCAL) ipo_flags |= BL_Action::ACT_IPOFLAG_LOCAL;
- if (actact->flag & ACT_IPOADD) ipo_flags |= BL_Action::ACT_IPOFLAG_ADD;
- if (actact->flag & ACT_IPOCHILD) ipo_flags |= BL_Action::ACT_IPOFLAG_CHILD;
-
- BL_ActionActuator* tmpbaseact = new BL_ActionActuator(
- gameobj,
- propname,
- propframe,
- actact->sta,
- actact->end,
- actact->act,
- actact->type, // + 1, because Blender starts to count at zero,
- actact->blend_mode,
- actact->blendin,
- actact->priority,
- actact->layer,
- actact->layer_weight,
- ipo_flags,
- actact->end_reset,
- actact->stridelength
- // Ketsji at 1, because zero is reserved for "NoDef"
- );
- baseact= tmpbaseact;
- break;
- }
- case ACT_SHAPEACTION:
- {
- if (blenderobject->type==OB_MESH) {
- bActionActuator* actact = (bActionActuator*) bact->data;
- STR_String propname = actact->name;
- STR_String propframe = actact->frameProp;
-
- BL_ShapeActionActuator* tmpbaseact = new BL_ShapeActionActuator(
- gameobj,
- propname,
- propframe,
- actact->sta,
- actact->end,
- actact->act,
- actact->type, // + 1, because Blender starts to count at zero,
- actact->blendin,
- actact->priority,
- actact->stridelength);
- // Ketsji at 1, because zero is reserved for "NoDef"
- baseact= tmpbaseact;
- break;
- }
- else
- printf ("Discarded shape action actuator from non-mesh object [%s]\n", blenderobject->id.name+2);
- }
- case ACT_LAMP:
- {
- break;
- }
- case ACT_CAMERA:
- {
- bCameraActuator *camact = (bCameraActuator *) bact->data;
- if (camact->ob) {
- KX_GameObject *tmpgob = converter->FindGameObject(camact->ob);
-
- /* visifac, fac and axis are not copied from the struct... */
- /* that's some internal state... */
- KX_CameraActuator *tmpcamact = new KX_CameraActuator(
- gameobj,
- tmpgob,
- camact->height,
- camact->min,
- camact->max,
- camact->axis,
- camact->damping);
- baseact = tmpcamact;
- }
- break;
- }
- case ACT_MESSAGE:
- {
- bMessageActuator *msgAct = (bMessageActuator *) bact->data;
-
- /* Get the name of the properties that objects must own that
- * we're sending to, if present
- */
- STR_String toPropName = msgAct->toPropName;
-
- /* Get the Message Subject to send.
- */
- STR_String subject = msgAct->subject;
-
- /* Get the bodyType
- */
- int bodyType = msgAct->bodyType;
-
- /* Get the body (text message or property name whose value
- * we'll be sending, might be empty
- */
- const STR_String body = msgAct->body;
-
- KX_NetworkMessageActuator *tmpmsgact = new KX_NetworkMessageActuator(
- gameobj, // actuator controlling object
- scene->GetNetworkScene(), // needed for replication
- toPropName,
- subject,
- bodyType,
- body);
- baseact = tmpmsgact;
- break;
- }
- case ACT_MATERIAL:
- {
- break;
- }
- case ACT_SOUND:
- {
- bSoundActuator* soundact = (bSoundActuator*) bact->data;
- /* get type, and possibly a start and end frame */
- KX_SoundActuator::KX_SOUNDACT_TYPE
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
-
- switch (soundact->type) {
- case ACT_SND_PLAY_STOP_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYSTOP;
- break;
- case ACT_SND_PLAY_END_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYEND;
- break;
- case ACT_SND_LOOP_STOP_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPSTOP;
- break;
- case ACT_SND_LOOP_END_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPEND;
- break;
- case ACT_SND_LOOP_BIDIRECTIONAL_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL;
- break;
- case ACT_SND_LOOP_BIDIRECTIONAL_STOP_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP;
- break;
-
- default:
- /* This is an error!!! */
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
- }
-
- if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF)
- {
- bSound* sound = soundact->sound;
- bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false;
- AUD_Sound* snd_sound = NULL;
- KX_3DSoundSettings settings;
- settings.cone_inner_angle = RAD2DEGF(soundact->sound3D.cone_inner_angle);
- settings.cone_outer_angle = RAD2DEGF(soundact->sound3D.cone_outer_angle);
- settings.cone_outer_gain = soundact->sound3D.cone_outer_gain;
- settings.max_distance = soundact->sound3D.max_distance;
- settings.max_gain = soundact->sound3D.max_gain;
- settings.min_gain = soundact->sound3D.min_gain;
- settings.reference_distance = soundact->sound3D.reference_distance;
- settings.rolloff_factor = soundact->sound3D.rolloff_factor;
-
- if (!sound)
- {
- std::cout << "WARNING: Sound actuator \"" << bact->name <<
- "\" from object \"" << blenderobject->id.name+2 <<
- "\" has no sound datablock." << std::endl;
- }
- else
- {
- snd_sound = sound->playback_handle;
-
- // if sound shall be 3D but isn't mono, we have to make it mono!
- if (is3d)
- {
- snd_sound = AUD_Sound_rechannel(snd_sound, AUD_CHANNELS_MONO);
- }
- }
- KX_SoundActuator* tmpsoundact =
- new KX_SoundActuator(gameobj,
- snd_sound,
- soundact->volume,
- (float)(expf((soundact->pitch / 12.0f) * (float)M_LN2)),
- is3d,
- settings,
- soundActuatorType);
-
- // if we made it mono, we have to free it
- if (sound && snd_sound && snd_sound != sound->playback_handle) {
- AUD_Sound_free(snd_sound);
- }
-
- tmpsoundact->SetName(bact->name);
- baseact = tmpsoundact;
- }
- break;
- }
- case ACT_PROPERTY:
- {
- bPropertyActuator* propact = (bPropertyActuator*) bact->data;
- SCA_IObject* destinationObj = NULL;
-
- /*
- * here the destinationobject is searched. problem with multiple scenes: other scenes
- * have not been converted yet, so the destobj will not be found, so the prop will
- * not be copied.
- * possible solutions:
- * - convert everything when possible and not realtime only when needed.
- * - let the object-with-property report itself to the act when converted
- */
- if (propact->ob)
- destinationObj = converter->FindGameObject(propact->ob);
-
- SCA_PropertyActuator* tmppropact = new SCA_PropertyActuator(
- gameobj,
- destinationObj,
- propact->name,
- propact->value,
- propact->type + 1); // + 1 because Ketsji Logic starts
- // with 0 for KX_ACT_PROP_NODEF
- baseact = tmppropact;
- break;
- }
- case ACT_EDIT_OBJECT:
- {
- bEditObjectActuator *editobact
- = (bEditObjectActuator *) bact->data;
- /* There are four different kinds of 'edit object' thingies */
- /* The alternative to this lengthy conversion is packing */
- /* several actuators in one, which is not very nice design.. */
- switch (editobact->type) {
- case ACT_EDOB_ADD_OBJECT:
- {
-
- // does the 'original' for replication exists, and
- // is it in a non-active layer ?
- SCA_IObject* originalval = NULL;
- if (editobact->ob)
- {
- if (editobact->ob->lay & activeLayerBitInfo)
- {
- fprintf(stderr, "Warning, object \"%s\" from AddObject actuator \"%s\" is not in a hidden layer.\n", objectname.Ptr(), uniquename.Ptr());
- }
- else {
- originalval = converter->FindGameObject(editobact->ob);
- }
- }
-
- KX_SCA_AddObjectActuator* tmpaddact = new KX_SCA_AddObjectActuator(
- gameobj,
- originalval,
- editobact->time,
- scene,
- editobact->linVelocity,
- (editobact->localflag & ACT_EDOB_LOCAL_LINV) != 0,
- editobact->angVelocity,
- (editobact->localflag & ACT_EDOB_LOCAL_ANGV) != 0);
-
- //editobact->ob to gameobj
- baseact = tmpaddact;
- }
- break;
- case ACT_EDOB_END_OBJECT:
- {
- KX_SCA_EndObjectActuator* tmpendact
- = new KX_SCA_EndObjectActuator(gameobj,scene);
- baseact = tmpendact;
- }
- break;
- case ACT_EDOB_REPLACE_MESH:
- {
- RAS_MeshObject *tmpmesh = converter->FindGameMesh(editobact->me);
-
- if (!tmpmesh) {
- std::cout << "Warning: object \"" << objectname <<
- "\" from ReplaceMesh actuator \"" << uniquename <<
- "\" uses a mesh not owned by an object in scene \"" <<
- scene->GetName() << "\"." << std::endl;
- }
-
- KX_SCA_ReplaceMeshActuator* tmpreplaceact = new KX_SCA_ReplaceMeshActuator(
- gameobj,
- tmpmesh,
- scene,
- (editobact->flag & ACT_EDOB_REPLACE_MESH_NOGFX) == 0,
- (editobact->flag & ACT_EDOB_REPLACE_MESH_PHYS) != 0);
-
- baseact = tmpreplaceact;
- }
- break;
- case ACT_EDOB_TRACK_TO:
- {
- SCA_IObject* originalval = NULL;
- if (editobact->ob)
- originalval = converter->FindGameObject(editobact->ob);
-
- KX_TrackToActuator* tmptrackact = new KX_TrackToActuator(
- gameobj,
- originalval,
- editobact->time,
- editobact->flag,
- editobact->trackflag,
- editobact->upflag);
- baseact = tmptrackact;
- break;
- }
- case ACT_EDOB_DYNAMICS:
- {
- KX_SCA_DynamicActuator* tmpdynact = new KX_SCA_DynamicActuator(
- gameobj,
- editobact->dyn_operation,
- editobact->mass);
- baseact = tmpdynact;
- }
- }
- break;
- }
- case ACT_CONSTRAINT:
- {
- float min = 0.0, max = 0.0;
- char *prop = NULL;
- KX_ConstraintActuator::KX_CONSTRAINTTYPE locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF;
- bConstraintActuator *conact
- = (bConstraintActuator*) bact->data;
- /* convert settings... degrees in the ui become radians */
- /* internally */
- if (conact->type == ACT_CONST_TYPE_ORI) {
- min = conact->minloc[0];
- max = conact->maxloc[0];
- switch (conact->mode) {
- case ACT_CONST_DIRPX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX;
- break;
- case ACT_CONST_DIRPY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY;
- break;
- case ACT_CONST_DIRPZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ;
- break;
- }
- } else if (conact->type == ACT_CONST_TYPE_DIST) {
- switch (conact->mode) {
- case ACT_CONST_DIRPX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX;
- min = conact->minloc[0];
- max = conact->maxloc[0];
- break;
- case ACT_CONST_DIRPY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY;
- min = conact->minloc[1];
- max = conact->maxloc[1];
- break;
- case ACT_CONST_DIRPZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ;
- min = conact->minloc[2];
- max = conact->maxloc[2];
- break;
- case ACT_CONST_DIRNX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX;
- min = conact->minloc[0];
- max = conact->maxloc[0];
- break;
- case ACT_CONST_DIRNY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY;
- min = conact->minloc[1];
- max = conact->maxloc[1];
- break;
- case ACT_CONST_DIRNZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ;
- min = conact->minloc[2];
- max = conact->maxloc[2];
- break;
- }
- prop = conact->matprop;
- } else if (conact->type == ACT_CONST_TYPE_FH) {
- switch (conact->mode) {
- case ACT_CONST_DIRPX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX;
- min = conact->minloc[0];
- max = conact->maxloc[0];
- break;
- case ACT_CONST_DIRPY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY;
- min = conact->minloc[1];
- max = conact->maxloc[1];
- break;
- case ACT_CONST_DIRPZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ;
- min = conact->minloc[2];
- max = conact->maxloc[2];
- break;
- case ACT_CONST_DIRNX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX;
- min = conact->minloc[0];
- max = conact->maxloc[0];
- break;
- case ACT_CONST_DIRNY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY;
- min = conact->minloc[1];
- max = conact->maxloc[1];
- break;
- case ACT_CONST_DIRNZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ;
- min = conact->minloc[2];
- max = conact->maxloc[2];
- break;
- }
- prop = conact->matprop;
- } else {
- switch (conact->flag) {
- case ACT_CONST_LOCX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX;
- min = conact->minloc[0];
- max = conact->maxloc[0];
- break;
- case ACT_CONST_LOCY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY;
- min = conact->minloc[1];
- max = conact->maxloc[1];
- break;
- case ACT_CONST_LOCZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ;
- min = conact->minloc[2];
- max = conact->maxloc[2];
- break;
- case ACT_CONST_ROTX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX;
- min = conact->minrot[0] * (float)MT_RADS_PER_DEG;
- max = conact->maxrot[0] * (float)MT_RADS_PER_DEG;
- break;
- case ACT_CONST_ROTY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY;
- min = conact->minrot[1] * (float)MT_RADS_PER_DEG;
- max = conact->maxrot[1] * (float)MT_RADS_PER_DEG;
- break;
- case ACT_CONST_ROTZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ;
- min = conact->minrot[2] * (float)MT_RADS_PER_DEG;
- max = conact->maxrot[2] * (float)MT_RADS_PER_DEG;
- break;
- default:
- ; /* error */
- }
- }
- KX_ConstraintActuator *tmpconact = new KX_ConstraintActuator(
- gameobj,
- conact->damp,
- conact->rotdamp,
- min,
- max,
- conact->maxrot,
- locrot,
- conact->time,
- conact->flag,
- prop);
- baseact = tmpconact;
- break;
- }
- case ACT_GROUP:
- {
- // deprecated
- }
- break;
- case ACT_SCENE:
- {
- bSceneActuator *sceneact = (bSceneActuator *) bact->data;
- STR_String nextSceneName("");
-
- KX_SceneActuator* tmpsceneact;
- int mode = KX_SceneActuator::KX_SCENE_NODEF;
- KX_Camera *cam = NULL;
- //KX_Scene* scene = NULL;
- switch (sceneact->type)
- {
- case ACT_SCENE_RESUME:
- case ACT_SCENE_SUSPEND:
- case ACT_SCENE_ADD_FRONT:
- case ACT_SCENE_ADD_BACK:
- case ACT_SCENE_REMOVE:
- case ACT_SCENE_SET:
- {
- switch (sceneact->type)
- {
- case ACT_SCENE_RESUME:
- mode = KX_SceneActuator::KX_SCENE_RESUME;
- break;
- case ACT_SCENE_SUSPEND:
- mode = KX_SceneActuator::KX_SCENE_SUSPEND;
- break;
- case ACT_SCENE_ADD_FRONT:
- mode = KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE;
- break;
- case ACT_SCENE_ADD_BACK:
- mode = KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE;
- break;
- case ACT_SCENE_REMOVE:
- mode = KX_SceneActuator::KX_SCENE_REMOVE_SCENE;
- break;
- case ACT_SCENE_SET:
- default:
- mode = KX_SceneActuator::KX_SCENE_SET_SCENE;
- break;
- };
-
- if (sceneact->scene) {
- nextSceneName = sceneact->scene->id.name + 2;
- }
-
- break;
- }
- case ACT_SCENE_CAMERA:
- mode = KX_SceneActuator::KX_SCENE_SET_CAMERA;
- if (sceneact->camera)
- {
- KX_GameObject *tmp = converter->FindGameObject(sceneact->camera);
- if (tmp && tmp->GetGameObjectType() == SCA_IObject::OBJ_CAMERA)
- cam = (KX_Camera*)tmp;
- }
- break;
- case ACT_SCENE_RESTART:
- {
-
- mode = KX_SceneActuator::KX_SCENE_RESTART;
- break;
- }
- default:
- ; /* flag error */
- }
- tmpsceneact = new KX_SceneActuator(
- gameobj,
- mode,
- scene,
- ketsjiEngine,
- nextSceneName,
- cam);
- baseact = tmpsceneact;
- break;
- }
- case ACT_GAME:
- {
- bGameActuator *gameact = (bGameActuator *) bact->data;
- KX_GameActuator* tmpgameact;
- STR_String filename = maggiename;
- STR_String loadinganimationname = "";
- int mode = KX_GameActuator::KX_GAME_NODEF;
- switch (gameact->type)
- {
- case ACT_GAME_LOAD:
- {
- mode = KX_GameActuator::KX_GAME_LOAD;
- filename = gameact->filename;
- loadinganimationname = gameact->loadaniname;
- break;
- }
- case ACT_GAME_START:
- {
- mode = KX_GameActuator::KX_GAME_START;
- filename = gameact->filename;
- loadinganimationname = gameact->loadaniname;
- break;
- }
- case ACT_GAME_RESTART:
- {
- mode = KX_GameActuator::KX_GAME_RESTART;
- break;
- }
- case ACT_GAME_QUIT:
- {
- mode = KX_GameActuator::KX_GAME_QUIT;
- break;
- }
- case ACT_GAME_SAVECFG:
- {
- mode = KX_GameActuator::KX_GAME_SAVECFG;
- break;
- }
- case ACT_GAME_LOADCFG:
- {
- mode = KX_GameActuator::KX_GAME_LOADCFG;
- break;
- }
- case ACT_GAME_SCREENSHOT:
- {
- mode = KX_GameActuator::KX_GAME_SCREENSHOT;
- filename = gameact->filename;
- break;
- }
- default:
- ; /* flag error */
- }
- tmpgameact = new KX_GameActuator(
- gameobj,
- mode,
- filename,
- loadinganimationname,
- scene,
- ketsjiEngine);
- baseact = tmpgameact;
-
- break;
- }
- case ACT_RANDOM:
- {
- bRandomActuator *randAct
- = (bRandomActuator *) bact->data;
-
- unsigned long seedArg = randAct->seed;
- if (seedArg == 0)
- {
- seedArg = (int)(ketsjiEngine->GetRealTime()*100000.0);
- seedArg ^= (intptr_t)randAct;
- }
- SCA_RandomActuator::KX_RANDOMACT_MODE modeArg
- = SCA_RandomActuator::KX_RANDOMACT_NODEF;
- SCA_RandomActuator *tmprandomact;
- float paraArg1 = 0.0;
- float paraArg2 = 0.0;
-
- switch (randAct->distribution) {
- case ACT_RANDOM_BOOL_CONST:
- modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST;
- paraArg1 = (float) randAct->int_arg_1;
- break;
- case ACT_RANDOM_BOOL_UNIFORM:
- modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM;
- break;
- case ACT_RANDOM_BOOL_BERNOUILLI:
- paraArg1 = randAct->float_arg_1;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI;
- break;
- case ACT_RANDOM_INT_CONST:
- modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_CONST;
- paraArg1 = (float) randAct->int_arg_1;
- break;
- case ACT_RANDOM_INT_UNIFORM:
- paraArg1 = (float) randAct->int_arg_1;
- paraArg2 = (float) randAct->int_arg_2;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM;
- break;
- case ACT_RANDOM_INT_POISSON:
- paraArg1 = randAct->float_arg_1;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_POISSON;
- break;
- case ACT_RANDOM_FLOAT_CONST:
- paraArg1 = randAct->float_arg_1;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST;
- break;
- case ACT_RANDOM_FLOAT_UNIFORM:
- paraArg1 = randAct->float_arg_1;
- paraArg2 = randAct->float_arg_2;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM;
- break;
- case ACT_RANDOM_FLOAT_NORMAL:
- paraArg1 = randAct->float_arg_1;
- paraArg2 = randAct->float_arg_2;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL;
- break;
- case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
- paraArg1 = randAct->float_arg_1;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL;
- break;
- default:
- ; /* error */
- }
- tmprandomact = new SCA_RandomActuator(
- gameobj,
- seedArg,
- modeArg,
- paraArg1,
- paraArg2,
- randAct->propname);
- baseact = tmprandomact;
- }
- break;
-
- case ACT_VISIBILITY:
- {
- bVisibilityActuator *vis_act = (bVisibilityActuator *) bact->data;
- KX_VisibilityActuator * tmp_vis_act = NULL;
- bool v = ((vis_act->flag & ACT_VISIBILITY_INVISIBLE) != 0);
- bool o = ((vis_act->flag & ACT_VISIBILITY_OCCLUSION) != 0);
- bool recursive = ((vis_act->flag & ACT_VISIBILITY_RECURSIVE) != 0);
-
- tmp_vis_act = new KX_VisibilityActuator(gameobj, !v, o, recursive);
-
- baseact = tmp_vis_act;
- }
- break;
-
- case ACT_STATE:
- {
- bStateActuator *sta_act = (bStateActuator *) bact->data;
- KX_StateActuator * tmp_sta_act = NULL;
-
- tmp_sta_act =
- new KX_StateActuator(gameobj, sta_act->type, sta_act->mask);
-
- baseact = tmp_sta_act;
- }
- break;
-
- case ACT_2DFILTER:
- {
- bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data;
- SCA_2DFilterActuator *tmp = NULL;
-
- RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode;
- switch (_2dfilter->type) {
- case ACT_2DFILTER_MOTIONBLUR:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR;
- break;
- case ACT_2DFILTER_BLUR:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR;
- break;
- case ACT_2DFILTER_SHARPEN:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN;
- break;
- case ACT_2DFILTER_DILATION:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION;
- break;
- case ACT_2DFILTER_EROSION:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION;
- break;
- case ACT_2DFILTER_LAPLACIAN:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN;
- break;
- case ACT_2DFILTER_SOBEL:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL;
- break;
- case ACT_2DFILTER_PREWITT:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT;
- break;
- case ACT_2DFILTER_GRAYSCALE:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE;
- break;
- case ACT_2DFILTER_SEPIA:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA;
- break;
- case ACT_2DFILTER_INVERT:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT;
- break;
- case ACT_2DFILTER_CUSTOMFILTER:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER;
- break;
- case ACT_2DFILTER_NOFILTER:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
- break;
- case ACT_2DFILTER_DISABLED:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_DISABLED;
- break;
- case ACT_2DFILTER_ENABLED:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_ENABLED;
- break;
- default:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
- break;
- }
-
- tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
- _2dfilter->float_arg, _2dfilter->int_arg,
- ketsjiEngine->GetRasterizer(), scene);
-
- if (_2dfilter->text)
- {
- char *buf;
- // this is some blender specific code
- buf = txt_to_buf(_2dfilter->text);
- if (buf)
- {
- tmp->SetShaderText(buf);
- MEM_freeN(buf);
- }
- }
-
- baseact = tmp;
-
- }
- break;
- case ACT_PARENT:
- {
- bParentActuator *parAct = (bParentActuator *) bact->data;
- int mode = KX_ParentActuator::KX_PARENT_NODEF;
- bool addToCompound = true;
- bool ghost = true;
- KX_GameObject *tmpgob = NULL;
-
- switch (parAct->type) {
- case ACT_PARENT_SET:
- mode = KX_ParentActuator::KX_PARENT_SET;
- tmpgob = converter->FindGameObject(parAct->ob);
- addToCompound = !(parAct->flag & ACT_PARENT_COMPOUND);
- ghost = !(parAct->flag & ACT_PARENT_GHOST);
- break;
- case ACT_PARENT_REMOVE:
- mode = KX_ParentActuator::KX_PARENT_REMOVE;
- tmpgob = NULL;
- break;
- }
-
- KX_ParentActuator *tmpparact
- = new KX_ParentActuator(gameobj,
- mode,
- addToCompound,
- ghost,
- tmpgob);
- baseact = tmpparact;
- break;
- }
-
- case ACT_ARMATURE:
- {
- bArmatureActuator* armAct = (bArmatureActuator*) bact->data;
- KX_GameObject *tmpgob = converter->FindGameObject(armAct->target);
- KX_GameObject *subgob = converter->FindGameObject(armAct->subtarget);
- BL_ArmatureActuator* tmparmact = new BL_ArmatureActuator(
- gameobj,
- armAct->type,
- armAct->posechannel,
- armAct->constraint,
- tmpgob,
- subgob,
- armAct->weight,
- armAct->influence);
- baseact = tmparmact;
- break;
- }
- case ACT_STEERING:
- {
- bSteeringActuator *stAct = (bSteeringActuator *) bact->data;
- KX_GameObject *navmeshob = NULL;
- if (stAct->navmesh)
- {
- PointerRNA settings_ptr;
- RNA_pointer_create((ID *)stAct->navmesh, &RNA_GameObjectSettings, stAct->navmesh, &settings_ptr);
- if (RNA_enum_get(&settings_ptr, "physics_type") == OB_BODY_TYPE_NAVMESH)
- navmeshob = converter->FindGameObject(stAct->navmesh);
- }
- KX_GameObject *targetob = converter->FindGameObject(stAct->target);
-
- int mode = KX_SteeringActuator::KX_STEERING_NODEF;
- switch (stAct->type) {
- case ACT_STEERING_SEEK:
- mode = KX_SteeringActuator::KX_STEERING_SEEK;
- break;
- case ACT_STEERING_FLEE:
- mode = KX_SteeringActuator::KX_STEERING_FLEE;
- break;
- case ACT_STEERING_PATHFOLLOWING:
- mode = KX_SteeringActuator::KX_STEERING_PATHFOLLOWING;
- break;
- }
-
- bool selfTerminated = (stAct->flag & ACT_STEERING_SELFTERMINATED) !=0;
- bool enableVisualization = (stAct->flag & ACT_STEERING_ENABLEVISUALIZATION) !=0;
- short facingMode = (stAct->flag & ACT_STEERING_AUTOMATICFACING) ? stAct->facingaxis : 0;
- bool normalup = (stAct->flag & ACT_STEERING_NORMALUP) !=0;
- bool lockzvel = (stAct->flag & ACT_STEERING_LOCKZVEL) !=0;
- KX_SteeringActuator *tmpstact
- = new KX_SteeringActuator(gameobj, mode, targetob, navmeshob,stAct->dist,
- stAct->velocity, stAct->acceleration, stAct->turnspeed,
- selfTerminated, stAct->updateTime,
- scene->GetObstacleSimulation(), facingMode, normalup, enableVisualization, lockzvel);
- baseact = tmpstact;
- break;
- }
- case ACT_MOUSE:
- {
- bMouseActuator* mouAct = (bMouseActuator*) bact->data;
- int mode = KX_MouseActuator::KX_ACT_MOUSE_NODEF;
-
- switch (mouAct->type) {
- case ACT_MOUSE_VISIBILITY:
- {
- mode = KX_MouseActuator::KX_ACT_MOUSE_VISIBILITY;
- break;
- }
- case ACT_MOUSE_LOOK:
- {
- mode = KX_MouseActuator::KX_ACT_MOUSE_LOOK;
- break;
- }
- }
-
- bool visible = (mouAct->flag & ACT_MOUSE_VISIBLE) != 0;
- bool use_axis[2] = {(mouAct->flag & ACT_MOUSE_USE_AXIS_X) != 0, (mouAct->flag & ACT_MOUSE_USE_AXIS_Y) != 0};
- bool reset[2] = {(mouAct->flag & ACT_MOUSE_RESET_X) != 0, (mouAct->flag & ACT_MOUSE_RESET_Y) != 0};
- bool local[2] = {(mouAct->flag & ACT_MOUSE_LOCAL_X) != 0, (mouAct->flag & ACT_MOUSE_LOCAL_Y) != 0};
-
- SCA_MouseManager* eventmgr = (SCA_MouseManager*) logicmgr->FindEventManager(SCA_EventManager::MOUSE_EVENTMGR);
- if (eventmgr) {
- KX_MouseActuator* tmpbaseact = new KX_MouseActuator(gameobj,
- ketsjiEngine,
- eventmgr,
- mode,
- visible,
- use_axis,
- mouAct->threshold,
- reset,
- mouAct->object_axis,
- local,
- mouAct->sensitivity,
- mouAct->limit_x,
- mouAct->limit_y);
- baseact = tmpbaseact;
- } else {
- //cout << "\n Couldn't find mouse event manager..."; - should throw an error here...
- }
- break;
- }
- default:
- ; /* generate some error */
- }
-
- if (baseact && !(bact->flag & ACT_DEACTIVATE))
- {
- baseact->SetExecutePriority(executePriority++);
- uniquename += "#ACT#";
- uniqueint++;
- CIntValue* uniqueval = new CIntValue(uniqueint);
- uniquename += uniqueval->GetText();
- uniqueval->Release();
- baseact->SetName(bact->name);
- baseact->SetLogicManager(logicmgr);
- //gameobj->SetProperty(uniquename,baseact);
- gameobj->AddActuator(baseact);
-
- converter->RegisterGameActuator(baseact, bact);
- // done with baseact, release it
- baseact->Release();
- }
- else if (baseact)
- baseact->Release();
-
- bact = bact->next;
- }
-}
-
-
diff --git a/source/gameengine/Converter/KX_ConvertActuators.h b/source/gameengine/Converter/KX_ConvertActuators.h
deleted file mode 100644
index 688b5db50ce..00000000000
--- a/source/gameengine/Converter/KX_ConvertActuators.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ConvertActuators.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_CONVERTACTUATORS_H__
-#define __KX_CONVERTACTUATORS_H__
-
-void BL_ConvertActuators(const char* maggiename,
- struct Object* blenderobject,
- class KX_GameObject* gameobj,
- class SCA_LogicManager* logicmgr,
- class KX_Scene* scene,
- class KX_KetsjiEngine* ketsjiEngine,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- class KX_BlenderSceneConverter* converter);
-
-#endif /* __KX_CONVERTACTUATORS_H__ */
diff --git a/source/gameengine/Converter/KX_ConvertControllers.cpp b/source/gameengine/Converter/KX_ConvertControllers.cpp
deleted file mode 100644
index a00a90428da..00000000000
--- a/source/gameengine/Converter/KX_ConvertControllers.cpp
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_ConvertControllers.cpp
- * \ingroup bgeconv
- */
-
-
-#include "MEM_guardedalloc.h"
-
-#include "KX_BlenderSceneConverter.h"
-#include "KX_ConvertControllers.h"
-#include "EXP_Python.h"
-
-// Controller
-#include "SCA_ANDController.h"
-#include "SCA_ORController.h"
-#include "SCA_NANDController.h"
-#include "SCA_NORController.h"
-#include "SCA_XORController.h"
-#include "SCA_XNORController.h"
-#include "SCA_PythonController.h"
-#include "SCA_ExpressionController.h"
-
-#include "SCA_LogicManager.h"
-#include "KX_GameObject.h"
-#include "EXP_IntValue.h"
-
-/* This little block needed for linking to Blender... */
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-#include "DNA_object_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_text_types.h"
-
-#include "BKE_text.h"
-
-#include "BLI_blenlib.h"
-
-/* end of blender include block */
-
-
- static void
-LinkControllerToActuators(
- SCA_IController *game_controller,
- bController* bcontr,
- SCA_LogicManager* logicmgr,
- KX_BlenderSceneConverter* converter
-) {
- // Iterate through the actuators of the game blender
- // controller and find the corresponding ketsji actuator.
-
- game_controller->ReserveActuator(bcontr->totlinks);
- for (int i=0;i<bcontr->totlinks;i++)
- {
- bActuator* bact = (bActuator*) bcontr->links[i];
- SCA_IActuator *game_actuator = converter->FindGameActuator(bact);
- if (game_actuator) {
- logicmgr->RegisterToActuator(game_controller, game_actuator);
- }
- }
-}
-
-
-void BL_ConvertControllers(
- struct Object* blenderobject,
- class KX_GameObject* gameobj,
- SCA_LogicManager* logicmgr,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- KX_BlenderSceneConverter* converter,
- bool libloading
-) {
- int uniqueint=0;
- int count = 0;
- int executePriority=0;
- bController* bcontr = (bController*)blenderobject->controllers.first;
- while (bcontr)
- {
- bcontr = bcontr->next;
- count++;
- }
- gameobj->ReserveController(count);
- bcontr = (bController*)blenderobject->controllers.first;
- while (bcontr)
- {
- SCA_IController* gamecontroller = NULL;
- switch (bcontr->type) {
- case CONT_LOGIC_AND:
- {
- gamecontroller = new SCA_ANDController(gameobj);
- break;
- }
- case CONT_LOGIC_OR:
- {
- gamecontroller = new SCA_ORController(gameobj);
- break;
- }
- case CONT_LOGIC_NAND:
- {
- gamecontroller = new SCA_NANDController(gameobj);
- break;
- }
- case CONT_LOGIC_NOR:
- {
- gamecontroller = new SCA_NORController(gameobj);
- break;
- }
- case CONT_LOGIC_XOR:
- {
- gamecontroller = new SCA_XORController(gameobj);
- break;
- }
- case CONT_LOGIC_XNOR:
- {
- gamecontroller = new SCA_XNORController(gameobj);
- break;
- }
- case CONT_EXPRESSION:
- {
- bExpressionCont* bexpcont = (bExpressionCont*) bcontr->data;
- STR_String expressiontext = STR_String(bexpcont->str);
- if (expressiontext.Length() > 0)
- {
- gamecontroller = new SCA_ExpressionController(gameobj,expressiontext);
- }
- break;
- }
- case CONT_PYTHON:
- {
- bPythonCont* pycont = (bPythonCont*) bcontr->data;
- SCA_PythonController* pyctrl = new SCA_PythonController(gameobj, pycont->mode);
- gamecontroller = pyctrl;
-#ifdef WITH_PYTHON
- // When libloading, this is delayed to KX_Scene::MergeScene_LogicBrick to avoid GIL issues
- if (!libloading)
- pyctrl->SetNamespace(converter->GetPyNamespace());
-
- if (pycont->mode==SCA_PythonController::SCA_PYEXEC_SCRIPT) {
- if (pycont->text)
- {
- char *buf;
- // this is some blender specific code
- buf= txt_to_buf(pycont->text);
- if (buf)
- {
- pyctrl->SetScriptText(STR_String(buf));
- pyctrl->SetScriptName(pycont->text->id.name+2);
- MEM_freeN(buf);
- }
-
- }
- }
- else {
- /* let the controller print any warnings here when importing */
- pyctrl->SetScriptText(STR_String(pycont->module));
- pyctrl->SetScriptName(pycont->module); /* will be something like module.func so using it as the name is OK */
-
- if (pycont->flag & CONT_PY_DEBUG) {
- printf("\nDebuging \"%s\", module for object %s\n\texpect worse performance.\n", pycont->module, blenderobject->id.name+2);
- pyctrl->SetDebug(true);
- }
- }
-#endif // WITH_PYTHON
-
- break;
- }
- default:
- {
-
- }
- }
-
- if (gamecontroller && !(bcontr->flag & CONT_DEACTIVATE))
- {
- LinkControllerToActuators(gamecontroller,bcontr,logicmgr,converter);
- gamecontroller->SetExecutePriority(executePriority++);
- gamecontroller->SetBookmark((bcontr->flag & CONT_PRIO) != 0);
- gamecontroller->SetState(bcontr->state_mask);
- STR_String uniquename = bcontr->name;
- uniquename += "#CONTR#";
- uniqueint++;
- CIntValue* uniqueval = new CIntValue(uniqueint);
- uniquename += uniqueval->GetText();
- uniqueval->Release();
- //unique name was never implemented for sensors and actuators, only for controllers
- //and it's producing difference in the keys for the lists: obj.controllers/sensors/actuators
- //at some point it should either be implemented globally (and saved as a separate var) or removed.
- //gamecontroller->SetName(uniquename);
- gamecontroller->SetName(bcontr->name);
- gamecontroller->SetLogicManager(logicmgr);
- gameobj->AddController(gamecontroller);
-
- converter->RegisterGameController(gamecontroller, bcontr);
-
-#ifdef WITH_PYTHON
- // When libloading, this is delayed to KX_Scene::MergeScene_LogicBrick to avoid GIL issues
- if (!libloading && bcontr->type==CONT_PYTHON) {
- SCA_PythonController *pyctrl= static_cast<SCA_PythonController*>(gamecontroller);
- /* not strictly needed but gives syntax errors early on and
- * gives more predictable performance for larger scripts */
- if (pyctrl->m_mode==SCA_PythonController::SCA_PYEXEC_SCRIPT)
- pyctrl->Compile();
- else {
- /* We cant do this because importing runs the script which could end up accessing
- * internal BGE functions, this is unstable while we're converting the scene.
- * This is a pity because its useful to see errors at startup but cant help it */
-
- // pyctrl->Import();
- }
- }
-
-#endif // WITH_PYTHON
-
- //done with gamecontroller
- gamecontroller->Release();
- }
- else if (gamecontroller)
- gamecontroller->Release();
-
- bcontr = bcontr->next;
- }
-
-}
diff --git a/source/gameengine/Converter/KX_ConvertControllers.h b/source/gameengine/Converter/KX_ConvertControllers.h
deleted file mode 100644
index b5bc4148e1a..00000000000
--- a/source/gameengine/Converter/KX_ConvertControllers.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ConvertControllers.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_CONVERTCONTROLLERS_H__
-#define __KX_CONVERTCONTROLLERS_H__
-
-#include "EXP_Python.h"
-
-void BL_ConvertControllers(
- struct Object* blenderobject,
- class KX_GameObject* gameobj,
- class SCA_LogicManager* logicmgr,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- class KX_BlenderSceneConverter* converter,
- bool libloading
-);
-
-#endif /* __KX_CONVERTCONTROLLERS_H__ */
diff --git a/source/gameengine/Converter/KX_ConvertProperties.cpp b/source/gameengine/Converter/KX_ConvertProperties.cpp
deleted file mode 100644
index 5dd7d0e4066..00000000000
--- a/source/gameengine/Converter/KX_ConvertProperties.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_ConvertProperties.cpp
- * \ingroup bgeconv
- */
-
-
-#include "KX_ConvertProperties.h"
-
-
-#include "DNA_object_types.h"
-#include "DNA_property_types.h"
-/* end of blender include block */
-
-
-#include "EXP_Value.h"
-#include "EXP_VectorValue.h"
-#include "EXP_BoolValue.h"
-#include "EXP_StringValue.h"
-#include "EXP_FloatValue.h"
-#include "KX_GameObject.h"
-#include "EXP_IntValue.h"
-#include "SCA_TimeEventManager.h"
-#include "SCA_IScene.h"
-
-#include "KX_FontObject.h"
-#include "DNA_curve_types.h"
-
-/* This little block needed for linking to Blender... */
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-extern "C" {
- #include "BKE_property.h"
-}
-
-/* prototype */
-void BL_ConvertTextProperty(Object* object, KX_FontObject* fontobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer);
-
-void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer)
-{
-
- bProperty* prop = (bProperty*)object->prop.first;
- CValue* propval;
- bool show_debug_info;
-
- while (prop) {
- propval = NULL;
- show_debug_info = bool (prop->flag & PROP_DEBUG);
-
- switch (prop->type) {
- case GPROP_BOOL:
- {
- propval = new CBoolValue((bool)(prop->data != 0));
- gameobj->SetProperty(prop->name,propval);
- //promp->poin= &prop->data;
- break;
- }
- case GPROP_INT:
- {
- propval = new CIntValue((int)prop->data);
- gameobj->SetProperty(prop->name,propval);
- break;
- }
- case GPROP_FLOAT:
- {
- //prop->poin= &prop->data;
- float floatprop = *((float*)&prop->data);
- propval = new CFloatValue(floatprop);
- gameobj->SetProperty(prop->name,propval);
- }
- break;
- case GPROP_STRING:
- {
- //prop->poin= callocN(MAX_PROPSTRING, "property string");
- propval = new CStringValue((char*)prop->poin,"");
- gameobj->SetProperty(prop->name,propval);
- break;
- }
- case GPROP_TIME:
- {
- float floatprop = *((float*)&prop->data);
-
- CValue* timeval = new CFloatValue(floatprop);
- // set a subproperty called 'timer' so that
- // we can register the replica of this property
- // at the time a game object is replicated (AddObjectActuator triggers this)
- CValue *bval = new CBoolValue(true);
- timeval->SetProperty("timer",bval);
- bval->Release();
- if (isInActiveLayer)
- {
- timemgr->AddTimeProperty(timeval);
- }
-
- propval = timeval;
- gameobj->SetProperty(prop->name,timeval);
-
- }
- default:
- {
- // todo make an assert etc.
- }
- }
-
- if (propval)
- {
- if (show_debug_info && isInActiveLayer)
- {
- scene->AddDebugProperty(gameobj,STR_String(prop->name));
- }
- // done with propval, release it
- propval->Release();
- }
-
-#ifdef WITH_PYTHON
- /* Warn if we double up on attributes, this isn't quite right since it wont find inherited attributes however there arnt many */
- for (PyAttributeDef *attrdef = KX_GameObject::Attributes; attrdef->m_name; attrdef++) {
- if (strcmp(prop->name, attrdef->m_name)==0) {
- printf("Warning! user defined property name \"%s\" is also a python attribute for object \"%s\"\n\tUse ob[\"%s\"] syntax to avoid conflict\n", prop->name, object->id.name+2, prop->name);
- break;
- }
- }
- for (PyMethodDef *methdef = KX_GameObject::Methods; methdef->ml_name; methdef++) {
- if (strcmp(prop->name, methdef->ml_name)==0) {
- printf("Warning! user defined property name \"%s\" is also a python method for object \"%s\"\n\tUse ob[\"%s\"] syntax to avoid conflict\n", prop->name, object->id.name+2, prop->name);
- break;
- }
- }
- /* end warning check */
-#endif // WITH_PYTHON
-
- prop = prop->next;
- }
- // check if state needs to be debugged
- if (object->scaflag & OB_DEBUGSTATE && isInActiveLayer)
- {
- // reserve name for object state
- scene->AddDebugProperty(gameobj,STR_String("__state__"));
- }
-
- /* Font Objects need to 'copy' the Font Object data body to ["Text"] */
- if (object->type == OB_FONT)
- {
- BL_ConvertTextProperty(object, (KX_FontObject *)gameobj, timemgr, scene, isInActiveLayer);
- }
-}
-
-void BL_ConvertTextProperty(Object* object, KX_FontObject* fontobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer)
-{
- CValue* tprop = fontobj->GetProperty("Text");
- if (!tprop) return;
- bProperty* prop = BKE_bproperty_object_get(object, "Text");
- if (!prop) return;
-
- Curve *curve = static_cast<Curve *>(object->data);
- STR_String str = curve->str;
- CValue* propval = NULL;
-
- switch (prop->type) {
- case GPROP_BOOL:
- {
- int value = atoi(str);
- propval = new CBoolValue((bool)(value != 0));
- tprop->SetValue(propval);
- break;
- }
- case GPROP_INT:
- {
- int value = atoi(str);
- propval = new CIntValue(value);
- tprop->SetValue(propval);
- break;
- }
- case GPROP_FLOAT:
- {
- float floatprop = (float)atof(str);
- propval = new CFloatValue(floatprop);
- tprop->SetValue(propval);
- break;
- }
- case GPROP_STRING:
- {
- propval = new CStringValue(str, "");
- tprop->SetValue(propval);
- break;
- }
- case GPROP_TIME:
- {
- float floatprop = (float)atof(str);
-
- CValue* timeval = new CFloatValue(floatprop);
- // set a subproperty called 'timer' so that
- // we can register the replica of this property
- // at the time a game object is replicated (AddObjectActuator triggers this)
- CValue *bval = new CBoolValue(true);
- timeval->SetProperty("timer",bval);
- bval->Release();
- if (isInActiveLayer)
- {
- timemgr->AddTimeProperty(timeval);
- }
-
- propval = timeval;
- tprop->SetValue(timeval);
- }
- default:
- {
- // todo make an assert etc.
- }
- }
-
- if (propval) {
- propval->Release();
- }
-}
-
diff --git a/source/gameengine/Converter/KX_ConvertProperties.h b/source/gameengine/Converter/KX_ConvertProperties.h
deleted file mode 100644
index 8f96cc21af6..00000000000
--- a/source/gameengine/Converter/KX_ConvertProperties.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ConvertProperties.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_CONVERTPROPERTIES_H__
-#define __KX_CONVERTPROPERTIES_H__
-
-void BL_ConvertProperties(struct Object* object,
- class KX_GameObject* gameobj,
- class SCA_TimeEventManager* timemgr,
- class SCA_IScene* scene,
- bool isInActiveLayer);
-
-#endif /* __KX_CONVERTPROPERTIES_H__ */
diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp
deleted file mode 100644
index 618be1e1c9b..00000000000
--- a/source/gameengine/Converter/KX_ConvertSensors.cpp
+++ /dev/null
@@ -1,663 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_ConvertSensors.cpp
- * \ingroup bgeconv
- *
- * Conversion of Blender data blocks to KX sensor system
- */
-
-#include <stdio.h>
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include "wm_event_types.h"
-#include "KX_BlenderSceneConverter.h"
-#include "KX_ConvertSensors.h"
-
-/* This little block needed for linking to Blender... */
-#ifdef _MSC_VER
-# include "BLI_winstuff.h"
-#endif
-
-#include "DNA_object_types.h"
-#include "DNA_material_types.h"
-#include "DNA_sensor_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_actuator_types.h" /* for SENS_ALL_KEYS ? this define is
- * probably misplaced */
-/* end of blender include block */
-
-#include "RAS_IPolygonMaterial.h"
-// Sensors
-#include "KX_GameObject.h"
-#include "RAS_MeshObject.h"
-#include "SCA_KeyboardSensor.h"
-#include "SCA_MouseSensor.h"
-#include "SCA_AlwaysSensor.h"
-#include "KX_TouchSensor.h"
-#include "KX_NearSensor.h"
-#include "KX_RadarSensor.h"
-#include "KX_MouseFocusSensor.h"
-#include "KX_ArmatureSensor.h"
-#include "SCA_JoystickSensor.h"
-#include "KX_NetworkMessageSensor.h"
-#include "SCA_ActuatorSensor.h"
-#include "SCA_DelaySensor.h"
-
-
-#include "SCA_PropertySensor.h"
-#include "SCA_RandomSensor.h"
-#include "KX_RaySensor.h"
-#include "SCA_EventManager.h"
-#include "SCA_LogicManager.h"
-#include "KX_BlenderInputDevice.h"
-#include "KX_Scene.h"
-#include "EXP_IntValue.h"
-#include "KX_BlenderKeyboardDevice.h"
-#include "RAS_ICanvas.h"
-#include "PHY_IPhysicsEnvironment.h"
-
-#include "KX_KetsjiEngine.h"
-#include "BL_BlenderDataConversion.h"
-
-void BL_ConvertSensors(struct Object* blenderobject,
- class KX_GameObject* gameobj,
- SCA_LogicManager* logicmgr,
- KX_Scene* kxscene,
- KX_KetsjiEngine* kxengine,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- RAS_ICanvas* canvas,
- KX_BlenderSceneConverter* converter
- )
-{
-
- int executePriority = 0;
- int uniqueint = 0;
- int count = 0;
- bSensor* sens = (bSensor*)blenderobject->sensors.first;
- bool pos_pulsemode = false;
- bool neg_pulsemode = false;
- int skipped_ticks = 0;
- bool invert = false;
- bool level = false;
- bool tap = false;
-
- while (sens)
- {
- sens = sens->next;
- count++;
- }
- gameobj->ReserveSensor(count);
- sens = (bSensor*)blenderobject->sensors.first;
-
- while (sens) {
- if (!(sens->flag & SENS_DEACTIVATE)) {
- SCA_ISensor* gamesensor=NULL;
- /* All sensors have a pulse toggle, skipped ticks parameter, and invert field. */
- /* These are extracted here, and set when the sensor is added to the */
- /* list. */
- pos_pulsemode = (sens->pulse & SENS_PULSE_REPEAT)!=0;
- neg_pulsemode = (sens->pulse & SENS_NEG_PULSE_MODE)!=0;
-
- skipped_ticks = sens->freq;
- invert = !(sens->invert == 0);
- level = !(sens->level == 0);
- tap = !(sens->tap == 0);
-
- switch (sens->type)
- {
- case SENS_ALWAYS:
- {
-
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- gamesensor = new SCA_AlwaysSensor(eventmgr, gameobj);
- }
-
- break;
- }
-
- case SENS_DELAY:
- {
- // we can reuse the Always event manager for the delay sensor
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- bDelaySensor* delaysensor = (bDelaySensor*)sens->data;
- gamesensor = new SCA_DelaySensor(eventmgr,
- gameobj,
- delaysensor->delay,
- delaysensor->duration,
- (delaysensor->flag & SENS_DELAY_REPEAT) != 0);
- }
- break;
- }
-
- case SENS_COLLISION:
- {
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
- if (eventmgr)
- {
- // collision sensor can sense both materials and properties.
-
- bool bFindMaterial = false, bTouchPulse = false;
-
- bCollisionSensor* blendertouchsensor = (bCollisionSensor*)sens->data;
-
- bFindMaterial = (blendertouchsensor->mode & SENS_COLLISION_MATERIAL);
- bTouchPulse = (blendertouchsensor->mode & SENS_COLLISION_PULSE);
-
-
- const STR_String touchPropOrMatName = bFindMaterial ?
- blendertouchsensor->materialName : blendertouchsensor->name;
-
-
- if (gameobj->GetPhysicsController())
- {
- gamesensor = new KX_TouchSensor(eventmgr,
- gameobj,
- bFindMaterial,
- bTouchPulse,
- touchPropOrMatName);
- }
-
- }
-
- break;
- }
- case SENS_MESSAGE:
- {
- KX_NetworkEventManager* eventmgr = (KX_NetworkEventManager*)
- logicmgr->FindEventManager(SCA_EventManager::NETWORK_EVENTMGR);
- if (eventmgr) {
- bMessageSensor* msgSens = (bMessageSensor*) sens->data;
-
- /* Get our NetworkScene */
- NG_NetworkScene *NetworkScene = kxscene->GetNetworkScene();
- /* filter on the incoming subjects, might be empty */
- const STR_String subject = msgSens->subject;
-
- gamesensor = new KX_NetworkMessageSensor(
- eventmgr, // our eventmanager
- NetworkScene, // our NetworkScene
- gameobj, // the sensor controlling object
- subject); // subject to filter on
- }
- break;
- }
- case SENS_NEAR:
- {
-
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
- if (eventmgr)
- {
- bNearSensor* blendernearsensor = (bNearSensor*)sens->data;
- const STR_String nearpropertyname = (char *)blendernearsensor->name;
-
- //DT_ShapeHandle shape = DT_Sphere(0.0);
-
- // this sumoObject is not deleted by a gameobj, so delete it ourself
- // later (memleaks)!
- float radius = blendernearsensor->dist;
- const MT_Vector3& wpos = gameobj->NodeGetWorldPosition();
- bool bFindMaterial = false;
- PHY_IPhysicsController* physCtrl = kxscene->GetPhysicsEnvironment()->CreateSphereController(radius,wpos);
-
- //will be done in KX_TouchEventManager::RegisterSensor()
- //if (isInActiveLayer)
- // kxscene->GetPhysicsEnvironment()->addSensor(physCtrl);
-
-
-
- gamesensor = new KX_NearSensor(eventmgr,gameobj,
- blendernearsensor->dist,
- blendernearsensor->resetdist,
- bFindMaterial,
- nearpropertyname,
- physCtrl);
-
- }
- break;
- }
-
-
- case SENS_KEYBOARD:
- {
- /* temporary input device, for converting the code for the keyboard sensor */
-
- bKeyboardSensor* blenderkeybdsensor = (bKeyboardSensor*)sens->data;
- SCA_KeyboardManager* eventmgr = (SCA_KeyboardManager*) logicmgr->FindEventManager(SCA_EventManager::KEYBOARD_EVENTMGR);
- if (eventmgr)
- {
- gamesensor = new SCA_KeyboardSensor(eventmgr,
- ConvertKeyCode(blenderkeybdsensor->key),
- ConvertKeyCode(blenderkeybdsensor->qual),
- ConvertKeyCode(blenderkeybdsensor->qual2),
- (blenderkeybdsensor->type == SENS_ALL_KEYS),
- blenderkeybdsensor->targetName,
- blenderkeybdsensor->toggleName,
- gameobj,
- KX_KetsjiEngine::GetExitKey()); // blenderkeybdsensor->pad);
-
- }
-
- break;
- }
- case SENS_MOUSE:
- {
- int keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_NODEF;
- int trackfocus = 0;
- bMouseSensor *bmouse = (bMouseSensor *)sens->data;
-
- /* There are two main types of mouse sensors. If there is
- * no focus-related behavior requested, we can make do
- * with a basic sensor. This cuts down memory usage and
- * gives a slight performance gain. */
-
- SCA_MouseManager *eventmgr
- = (SCA_MouseManager*) logicmgr->FindEventManager(SCA_EventManager::MOUSE_EVENTMGR);
- if (eventmgr) {
-
- /* Determine key mode. There is at most one active mode. */
- switch (bmouse->type) {
- case BL_SENS_MOUSE_LEFT_BUTTON:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_LEFTBUTTON;
- break;
- case BL_SENS_MOUSE_MIDDLE_BUTTON:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_MIDDLEBUTTON;
- break;
- case BL_SENS_MOUSE_RIGHT_BUTTON:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_RIGHTBUTTON;
- break;
- case BL_SENS_MOUSE_WHEEL_UP:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_WHEELUP;
- break;
- case BL_SENS_MOUSE_WHEEL_DOWN:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_WHEELDOWN;
- break;
- case BL_SENS_MOUSE_MOVEMENT:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_MOVEMENT;
- break;
- case BL_SENS_MOUSE_MOUSEOVER:
- trackfocus = 1;
- break;
- case BL_SENS_MOUSE_MOUSEOVER_ANY:
- trackfocus = 2;
- break;
-
- default:
- ; /* error */
- }
-
- /* initial mouse position */
- int startx = canvas->GetWidth()/2;
- int starty = canvas->GetHeight()/2;
-
- if (!trackfocus) {
- /* plain, simple mouse sensor */
- gamesensor = new SCA_MouseSensor(eventmgr,
- startx,starty,
- keytype,
- gameobj);
- } else {
- /* give us a focus-aware sensor */
- bool bFindMaterial = (bmouse->mode & SENS_COLLISION_MATERIAL);
- bool bXRay = (bmouse->flag & SENS_RAY_XRAY);
- STR_String checkname = (bFindMaterial? bmouse->matname : bmouse->propname);
-
- gamesensor = new KX_MouseFocusSensor(eventmgr,
- startx,
- starty,
- keytype,
- trackfocus,
- (bmouse->flag & SENS_MOUSE_FOCUS_PULSE) ? true:false,
- checkname,
- bFindMaterial,
- bXRay,
- kxscene,
- kxengine,
- gameobj);
- }
- } else {
- // cout << "\n Could't find mouse event manager..."; - should throw an error here...
- }
- break;
- }
- case SENS_PROPERTY:
- {
- bPropertySensor* blenderpropsensor = (bPropertySensor*) sens->data;
- SCA_EventManager* eventmgr
- = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- STR_String propname=blenderpropsensor->name;
- STR_String propval=blenderpropsensor->value;
- STR_String propmaxval=blenderpropsensor->maxvalue;
-
- SCA_PropertySensor::KX_PROPSENSOR_TYPE
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_NODEF;
-
- /* Better do an explicit conversion here! (was implicit */
- /* before...) */
- switch (blenderpropsensor->type) {
- case SENS_PROP_EQUAL:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_EQUAL;
- break;
- case SENS_PROP_NEQUAL:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_NOTEQUAL;
- break;
- case SENS_PROP_INTERVAL:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_INTERVAL;
- break;
- case SENS_PROP_CHANGED:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_CHANGED;
- break;
- case SENS_PROP_EXPRESSION:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION;
- /* error */
- break;
- case SENS_PROP_LESSTHAN:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_LESSTHAN;
- break;
- case SENS_PROP_GREATERTHAN:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_GREATERTHAN;
- break;
- default:
- ; /* error */
- }
- gamesensor = new SCA_PropertySensor(eventmgr,gameobj,propname,propval,propmaxval,propchecktype);
- }
-
- break;
- }
- case SENS_ACTUATOR:
- {
- bActuatorSensor* blenderactsensor = (bActuatorSensor*) sens->data;
- // we will reuse the property event manager, there is nothing special with this sensor
- SCA_EventManager* eventmgr
- = logicmgr->FindEventManager(SCA_EventManager::ACTUATOR_EVENTMGR);
- if (eventmgr)
- {
- STR_String propname=blenderactsensor->name;
- gamesensor = new SCA_ActuatorSensor(eventmgr,gameobj,propname);
- }
- break;
- }
-
- case SENS_ARMATURE:
- {
- bArmatureSensor* blenderarmsensor = (bArmatureSensor*) sens->data;
- // we will reuse the property event manager, there is nothing special with this sensor
- SCA_EventManager* eventmgr
- = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- STR_String bonename=blenderarmsensor->posechannel;
- STR_String constraintname=blenderarmsensor->constraint;
- gamesensor = new KX_ArmatureSensor(eventmgr,gameobj,bonename,constraintname, blenderarmsensor->type, blenderarmsensor->value);
- }
- break;
- }
-
- case SENS_RADAR:
- {
-
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
- if (eventmgr)
- {
- bRadarSensor* blenderradarsensor = (bRadarSensor*) sens->data;
- const STR_String radarpropertyname = blenderradarsensor->name;
-
- int radaraxis = blenderradarsensor->axis;
-
- MT_Scalar coneheight = blenderradarsensor->range;
-
- // janco: the angle was doubled, so should I divide the factor in 2
- // or the blenderradarsensor->angle?
- // nzc: the angle is the opening angle. We need to init with
- // the axis-hull angle,so /2.0.
- MT_Scalar factor = tan(blenderradarsensor->angle * 0.5f);
- //MT_Scalar coneradius = coneheight * (factor / 2);
- MT_Scalar coneradius = coneheight * factor;
-
-
- // this sumoObject is not deleted by a gameobj, so delete it ourself
- // later (memleaks)!
- MT_Scalar smallmargin = 0.0;
- MT_Scalar largemargin = 0.0;
-
- bool bFindMaterial = false;
- PHY_IPhysicsController* ctrl = kxscene->GetPhysicsEnvironment()->CreateConeController((float)coneradius, (float)coneheight);
-
- gamesensor = new KX_RadarSensor(
- eventmgr,
- gameobj,
- ctrl,
- coneradius,
- coneheight,
- radaraxis,
- smallmargin,
- largemargin,
- bFindMaterial,
- radarpropertyname);
-
- }
-
- break;
- }
- case SENS_RAY:
- {
- bRaySensor* blenderraysensor = (bRaySensor*) sens->data;
-
- //blenderradarsensor->angle;
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- bool bFindMaterial = (blenderraysensor->mode & SENS_COLLISION_MATERIAL);
- bool bXRay = (blenderraysensor->mode & SENS_RAY_XRAY);
-
- STR_String checkname = (bFindMaterial? blenderraysensor->matname : blenderraysensor->propname);
-
- // don't want to get rays of length 0.0 or so
- double distance = (blenderraysensor->range < 0.01f ? 0.01f : blenderraysensor->range);
- int axis = blenderraysensor->axisflag;
-
-
- gamesensor = new KX_RaySensor(eventmgr,
- gameobj,
- checkname,
- bFindMaterial,
- bXRay,
- distance,
- axis,
- kxscene);
-
- }
- break;
- }
-
- case SENS_RANDOM:
- {
- bRandomSensor* blenderrndsensor = (bRandomSensor*) sens->data;
- // some files didn't write randomsensor, avoid crash now for NULL ptr's
- if (blenderrndsensor)
- {
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- int randomSeed = blenderrndsensor->seed;
- if (randomSeed == 0)
- {
- randomSeed = (int)(kxengine->GetRealTime()*100000.0);
- randomSeed ^= (intptr_t)blenderrndsensor;
- }
- gamesensor = new SCA_RandomSensor(eventmgr, gameobj, randomSeed);
- }
- }
- break;
- }
- case SENS_JOYSTICK:
- {
- int joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_NODEF;
-
- bJoystickSensor* bjoy = (bJoystickSensor*) sens->data;
-
- SCA_JoystickManager *eventmgr
- = (SCA_JoystickManager*) logicmgr->FindEventManager(SCA_EventManager::JOY_EVENTMGR);
- if (eventmgr)
- {
- int axis =0;
- int axisf =0;
- int button =0;
- int hat =0;
- int hatf =0;
- int prec =0;
-
- switch (bjoy->type) {
- case SENS_JOY_AXIS:
- axis = bjoy->axis;
- axisf = bjoy->axisf;
- prec = bjoy->precision;
- joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_AXIS;
- break;
- case SENS_JOY_BUTTON:
- button = bjoy->button;
- joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_BUTTON;
- break;
- case SENS_JOY_HAT:
- hat = bjoy->hat;
- hatf = bjoy->hatf;
- joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_HAT;
- break;
- case SENS_JOY_AXIS_SINGLE:
- axis = bjoy->axis_single;
- prec = bjoy->precision;
- joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_AXIS_SINGLE;
- break;
- default:
- printf("Error: bad case statement\n");
- break;
- }
- gamesensor = new SCA_JoystickSensor(
- eventmgr,
- gameobj,
- bjoy->joyindex,
- joysticktype,
- axis,axisf,
- prec,
- button,
- hat,hatf,
- (bjoy->flag & SENS_JOY_ANY_EVENT));
- }
- else
- {
- printf("Error there was a problem finding the event manager\n");
- }
-
- break;
- }
- default:
- {
- }
- }
-
- if (gamesensor)
- {
- gamesensor->SetExecutePriority(executePriority++);
- STR_String uniquename = sens->name;
- uniquename += "#SENS#";
- uniqueint++;
- CIntValue* uniqueval = new CIntValue(uniqueint);
- uniquename += uniqueval->GetText();
- uniqueval->Release();
-
- /* Conversion succeeded, so we can set the generic props here. */
- gamesensor->SetPulseMode(pos_pulsemode,
- neg_pulsemode,
- skipped_ticks);
- gamesensor->SetInvert(invert);
- gamesensor->SetLevel(level);
- gamesensor->SetTap(tap);
- gamesensor->SetName(sens->name);
- gamesensor->SetLogicManager(logicmgr);
-
- gameobj->AddSensor(gamesensor);
-
- // only register to manager if it's in an active layer
- // Make registration dynamic: only when sensor is activated
- //if (isInActiveLayer)
- // gamesensor->RegisterToManager();
-
- gamesensor->ReserveController(sens->totlinks);
- for (int i=0;i<sens->totlinks;i++)
- {
- bController* linkedcont = (bController*) sens->links[i];
- if (linkedcont) {
- // If the controller is deactived doesn't register it
- if (!(linkedcont->flag & CONT_DEACTIVATE)) {
- SCA_IController* gamecont = converter->FindGameController(linkedcont);
-
- if (gamecont) {
- logicmgr->RegisterToSensor(gamecont,gamesensor);
- }
- else {
- printf("Warning, sensor \"%s\" could not find its controller "
- "(link %d of %d) from object \"%s\"\n"
- "\tthere has been an error converting the blender controller for the game engine,"
- "logic may be incorrect\n", sens->name, i+1, sens->totlinks, blenderobject->id.name+2);
- }
- }
- }
- else {
- printf("Warning, sensor \"%s\" has lost a link to a controller "
- "(link %d of %d) from object \"%s\"\n"
- "\tpossible causes are partially appended objects or an error reading the file,"
- "logic may be incorrect\n", sens->name, i+1, sens->totlinks, blenderobject->id.name+2);
- }
- }
- // special case: Keyboard sensor with no link
- // this combination is usually used for key logging.
- if (sens->type == SENS_KEYBOARD && sens->totlinks == 0) {
- // Force the registration so that the sensor runs
- gamesensor->IncLink();
- }
-
- // done with gamesensor
- gamesensor->Release();
-
- }
- }
-
- sens=sens->next;
- }
-}
-
diff --git a/source/gameengine/Converter/KX_ConvertSensors.h b/source/gameengine/Converter/KX_ConvertSensors.h
deleted file mode 100644
index 2ed2c9b3226..00000000000
--- a/source/gameengine/Converter/KX_ConvertSensors.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ConvertSensors.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_CONVERTSENSORS_H__
-#define __KX_CONVERTSENSORS_H__
-
-void BL_ConvertSensors(struct Object* blenderobject,
- class KX_GameObject* gameobj,
- class SCA_LogicManager* logicmgr,
- class KX_Scene* kxscene,
- class KX_KetsjiEngine* kxengine,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- class RAS_ICanvas* canvas,
- class KX_BlenderSceneConverter* converter);
-
-#endif /* __KX_CONVERTSENSORS_H__ */
diff --git a/source/gameengine/Converter/KX_LibLoadStatus.cpp b/source/gameengine/Converter/KX_LibLoadStatus.cpp
deleted file mode 100644
index c43958ebc85..00000000000
--- a/source/gameengine/Converter/KX_LibLoadStatus.cpp
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Mitchell Stokes
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_LibLoadStatus.cpp
- * \ingroup bgeconv
- */
-
-#include "KX_LibLoadStatus.h"
-#include "PIL_time.h"
-
-KX_LibLoadStatus::KX_LibLoadStatus(class KX_BlenderSceneConverter* kx_converter,
- class KX_KetsjiEngine* kx_engine,
- class KX_Scene* merge_scene,
- const char *path) :
- m_converter(kx_converter),
- m_engine(kx_engine),
- m_mergescene(merge_scene),
- m_data(NULL),
- m_libname(path),
- m_progress(0.0f),
- m_finished(false)
-#ifdef WITH_PYTHON
- ,
- m_finish_cb(NULL),
- m_progress_cb(NULL)
-#endif
-{
- m_endtime = m_starttime = PIL_check_seconds_timer();
-}
-
-void KX_LibLoadStatus::Finish()
-{
- m_finished = true;
- m_progress = 1.f;
- m_endtime = PIL_check_seconds_timer();
-
- RunFinishCallback();
- RunProgressCallback();
-}
-
-void KX_LibLoadStatus::RunFinishCallback()
-{
-#ifdef WITH_PYTHON
- if (m_finish_cb) {
- PyObject* args = Py_BuildValue("(O)", GetProxy());
-
- if (!PyObject_Call(m_finish_cb, args, NULL)) {
- PyErr_Print();
- PyErr_Clear();
- }
-
- Py_DECREF(args);
- }
-#endif
-}
-
-void KX_LibLoadStatus::RunProgressCallback()
-{
-// Progess callbacks are causing threading problems with Python, so they're disabled for now
-#if 0
-#ifdef WITH_PYTHON
- if (m_progress_cb) {
- //PyGILState_STATE gstate = PyGILState_Ensure();
- PyObject* args = Py_BuildValue("(O)", GetProxy());
-
- if (!PyObject_Call(m_progress_cb, args, NULL)) {
- PyErr_Print();
- PyErr_Clear();
- }
-
- Py_DECREF(args);
- //PyGILState_Release(gstate);
- }
-#endif
-#endif
-}
-
-class KX_BlenderSceneConverter *KX_LibLoadStatus::GetConverter()
-{
- return m_converter;
-}
-
-class KX_KetsjiEngine *KX_LibLoadStatus::GetEngine()
-{
- return m_engine;
-}
-
-class KX_Scene *KX_LibLoadStatus::GetMergeScene()
-{
- return m_mergescene;
-}
-
-void KX_LibLoadStatus::SetLibName(const char *name)
-{
- m_libname = name;
-}
-
-const char *KX_LibLoadStatus::GetLibName()
-{
- return m_libname;
-}
-
-void KX_LibLoadStatus::SetData(void *data)
-{
- m_data = data;
-}
-
-void *KX_LibLoadStatus::GetData()
-{
- return m_data;
-}
-
-void KX_LibLoadStatus::SetProgress(float progress)
-{
- m_progress = progress;
- RunProgressCallback();
-}
-
-float KX_LibLoadStatus::GetProgress()
-{
- return m_progress;
-}
-
-void KX_LibLoadStatus::AddProgress(float progress)
-{
- m_progress += progress;
- RunProgressCallback();
-}
-
-#ifdef WITH_PYTHON
-
-PyMethodDef KX_LibLoadStatus::Methods[] =
-{
- {NULL} //Sentinel
-};
-
-PyAttributeDef KX_LibLoadStatus::Attributes[] = {
- KX_PYATTRIBUTE_RW_FUNCTION("onFinish", KX_LibLoadStatus, pyattr_get_onfinish, pyattr_set_onfinish),
- // KX_PYATTRIBUTE_RW_FUNCTION("onProgress", KX_LibLoadStatus, pyattr_get_onprogress, pyattr_set_onprogress),
- KX_PYATTRIBUTE_FLOAT_RO("progress", KX_LibLoadStatus, m_progress),
- KX_PYATTRIBUTE_STRING_RO("libraryName", KX_LibLoadStatus, m_libname),
- KX_PYATTRIBUTE_RO_FUNCTION("timeTaken", KX_LibLoadStatus, pyattr_get_timetaken),
- KX_PYATTRIBUTE_BOOL_RO("finished", KX_LibLoadStatus, m_finished),
- { NULL } //Sentinel
-};
-
-PyTypeObject KX_LibLoadStatus::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_LibLoadStatus",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-
-PyObject* KX_LibLoadStatus::pyattr_get_onfinish(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LibLoadStatus* self = static_cast<KX_LibLoadStatus*>(self_v);
-
- if (self->m_finish_cb) {
- Py_INCREF(self->m_finish_cb);
- return self->m_finish_cb;
- }
-
- Py_RETURN_NONE;
-}
-
-int KX_LibLoadStatus::pyattr_set_onfinish(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LibLoadStatus* self = static_cast<KX_LibLoadStatus*>(self_v);
-
- if (!PyCallable_Check(value)) {
- PyErr_SetString(PyExc_TypeError, "KX_LibLoadStatus.onFinished requires a callable object");
- return PY_SET_ATTR_FAIL;
- }
-
- if (self->m_finish_cb)
- Py_DECREF(self->m_finish_cb);
-
- Py_INCREF(value);
- self->m_finish_cb = value;
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject* KX_LibLoadStatus::pyattr_get_onprogress(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LibLoadStatus* self = static_cast<KX_LibLoadStatus*>(self_v);
-
- if (self->m_progress_cb) {
- Py_INCREF(self->m_progress_cb);
- return self->m_progress_cb;
- }
-
- Py_RETURN_NONE;
-}
-
-int KX_LibLoadStatus::pyattr_set_onprogress(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LibLoadStatus* self = static_cast<KX_LibLoadStatus*>(self_v);
-
- if (!PyCallable_Check(value)) {
- PyErr_SetString(PyExc_TypeError, "KX_LibLoadStatus.onProgress requires a callable object");
- return PY_SET_ATTR_FAIL;
- }
-
- if (self->m_progress_cb)
- Py_DECREF(self->m_progress_cb);
-
- Py_INCREF(value);
- self->m_progress_cb = value;
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject* KX_LibLoadStatus::pyattr_get_timetaken(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LibLoadStatus* self = static_cast<KX_LibLoadStatus*>(self_v);
-
- return PyFloat_FromDouble(self->m_endtime - self->m_starttime);
-}
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/KX_LibLoadStatus.h b/source/gameengine/Converter/KX_LibLoadStatus.h
deleted file mode 100644
index fd51bfddd85..00000000000
--- a/source/gameengine/Converter/KX_LibLoadStatus.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Mitchell Stokes
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_LibLoadStatus.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_LIBLOADSTATUS_H__
-#define __KX_LIBLOADSTATUS_H__
-
-#include "EXP_PyObjectPlus.h"
-
-class KX_LibLoadStatus : public PyObjectPlus
-{
- Py_Header
-private:
- class KX_BlenderSceneConverter* m_converter;
- class KX_KetsjiEngine* m_engine;
- class KX_Scene* m_mergescene;
- void* m_data;
- STR_String m_libname;
-
- float m_progress;
- double m_starttime;
- double m_endtime;
-
- // The current status of this libload, used by the scene converter.
- bool m_finished;
-
-#ifdef WITH_PYTHON
- PyObject* m_finish_cb;
- PyObject* m_progress_cb;
-#endif
-
-public:
- KX_LibLoadStatus(class KX_BlenderSceneConverter* kx_converter,
- class KX_KetsjiEngine* kx_engine,
- class KX_Scene* merge_scene,
- const char *path);
-
- void Finish(); // Called when the libload is done
- void RunFinishCallback();
- void RunProgressCallback();
-
- class KX_BlenderSceneConverter *GetConverter();
- class KX_KetsjiEngine *GetEngine();
- class KX_Scene *GetMergeScene();
-
- void SetLibName(const char *name);
- const char *GetLibName();
-
- void SetData(void *data);
- void *GetData();
-
- inline bool IsFinished() const
- {
- return m_finished;
- }
-
- void SetProgress(float progress);
- float GetProgress();
- void AddProgress(float progress);
-
-#ifdef WITH_PYTHON
- static PyObject* pyattr_get_onfinish(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_onfinish(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_onprogress(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_onprogress(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static PyObject* pyattr_get_timetaken(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-#endif
-};
-
-#endif // __KX_LIBLOADSTATUS_H__
diff --git a/source/gameengine/Converter/KX_SoftBodyDeformer.cpp b/source/gameengine/Converter/KX_SoftBodyDeformer.cpp
deleted file mode 100644
index 6c8b7fc3e29..00000000000
--- a/source/gameengine/Converter/KX_SoftBodyDeformer.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_SoftBodyDeformer.cpp
- * \ingroup bgeconv
- */
-
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif //WIN32
-
-#include "MT_assert.h"
-
-#include "KX_SoftBodyDeformer.h"
-#include "RAS_MeshObject.h"
-#include "CTR_Map.h"
-#include "CTR_HashedPtr.h"
-
-#ifdef WITH_BULLET
-
-#include "CcdPhysicsEnvironment.h"
-#include "CcdPhysicsController.h"
-#include "BulletSoftBody/btSoftBody.h"
-
-#include "btBulletDynamicsCommon.h"
-
-void KX_SoftBodyDeformer::Relink(CTR_Map<class CTR_HashedPtr, void*>*map)
-{
- void **h_obj = (*map)[m_gameobj];
-
- if (h_obj) {
- m_gameobj = (BL_DeformableGameObject*)(*h_obj);
- m_pMeshObject = m_gameobj->GetMesh(0);
- } else {
- m_gameobj = NULL;
- m_pMeshObject = NULL;
- }
-}
-
-bool KX_SoftBodyDeformer::Apply(class RAS_IPolyMaterial *polymat)
-{
- CcdPhysicsController* ctrl = (CcdPhysicsController*) m_gameobj->GetPhysicsController();
- if (!ctrl)
- return false;
-
- btSoftBody* softBody= ctrl->GetSoftBody();
- if (!softBody)
- return false;
-
- //printf("apply\n");
- RAS_MeshSlot::iterator it;
- RAS_MeshMaterial *mmat;
- RAS_MeshSlot *slot;
- size_t i;
-
- // update the vertex in m_transverts
- Update();
-
- // The vertex cache can only be updated for this deformer:
- // 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.
- mmat = m_pMeshObject->GetMeshMaterial(polymat);
- if (!mmat->m_slots[(void*)m_gameobj])
- return true;
-
- slot = *mmat->m_slots[(void*)m_gameobj];
-
- // for each array
- for (slot->begin(it); !slot->end(it); slot->next(it))
- {
- btSoftBody::tNodeArray& nodes(softBody->m_nodes);
-
- int index = 0;
- for (i=it.startvertex; i<it.endvertex; i++,index++) {
- RAS_TexVert& v = it.vertex[i];
- btAssert(v.getSoftBodyIndex() >= 0);
-
- MT_Point3 pt (
- nodes[v.getSoftBodyIndex()].m_x.getX(),
- nodes[v.getSoftBodyIndex()].m_x.getY(),
- nodes[v.getSoftBodyIndex()].m_x.getZ());
- v.SetXYZ(pt);
-
- MT_Vector3 normal (
- nodes[v.getSoftBodyIndex()].m_n.getX(),
- nodes[v.getSoftBodyIndex()].m_n.getY(),
- nodes[v.getSoftBodyIndex()].m_n.getZ());
- v.SetNormal(normal);
-
- }
- }
- return true;
-}
-
-#endif
diff --git a/source/gameengine/Converter/KX_SoftBodyDeformer.h b/source/gameengine/Converter/KX_SoftBodyDeformer.h
deleted file mode 100644
index cc7f81ce0c7..00000000000
--- a/source/gameengine/Converter/KX_SoftBodyDeformer.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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
- * of the License, or (at your option) any later version.
- *
- * 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,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_SoftBodyDeformer.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_SOFTBODYDEFORMER_H__
-#define __KX_SOFTBODYDEFORMER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* get rid of stupid stl-visual compiler debug warning */
-#endif
-
-#include "RAS_Deformer.h"
-#include "BL_DeformableGameObject.h"
-#include <vector>
-
-
-class KX_SoftBodyDeformer : public RAS_Deformer
-{
- class RAS_MeshObject* m_pMeshObject;
- class BL_DeformableGameObject* m_gameobj;
-
-public:
- KX_SoftBodyDeformer(RAS_MeshObject* pMeshObject,BL_DeformableGameObject* gameobj)
- :m_pMeshObject(pMeshObject),
- m_gameobj(gameobj)
- {
- //printf("KX_SoftBodyDeformer\n");
- };
-
- virtual ~KX_SoftBodyDeformer()
- {
- //printf("~KX_SoftBodyDeformer\n");
- };
- virtual void Relink(CTR_Map<class CTR_HashedPtr, void*>*map);
- virtual bool Apply(class RAS_IPolyMaterial *polymat);
- virtual bool Update(void)
- {
- //printf("update\n");
- m_bDynamic = true;
- return true;//??
- }
- virtual bool UpdateBuckets(void)
- {
- // this is to update the mesh slots outside the rasterizer,
- // no need to do it for this deformer, it's done in any case in Apply()
- return false;
- }
-
- virtual RAS_Deformer *GetReplica()
- {
- KX_SoftBodyDeformer* deformer = new KX_SoftBodyDeformer(*this);
- deformer->ProcessReplica();
- return deformer;
- }
- virtual void ProcessReplica()
- {
- // we have two pointers to deal with but we cannot do it now, will be done in Relink
- m_bDynamic = false;
- }
- virtual bool SkipVertexTransform()
- {
- return true;
- }
-
-protected:
- //class RAS_MeshObject *m_pMesh;
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_ShapeDeformer")
-#endif
-};
-
-
-#endif
-