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/BL_BlenderDataConversion.cpp')
-rw-r--r--source/gameengine/Converter/BL_BlenderDataConversion.cpp442
1 files changed, 145 insertions, 297 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
index 87b64582e11..c74fd82a9f6 100644
--- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp
+++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
@@ -52,23 +52,13 @@
#include <algorithm>
#include "BL_BlenderDataConversion.h"
-#include "KX_BlenderScalarInterpolator.h"
-#include "RAS_IPolygonMaterial.h"
-
-// Expressions
-#include "ListValue.h"
-#include "IntValue.h"
-// Collision & Fuzzics LTD
+#include "MT_Transform.h"
+#include "MT_MinMax.h"
#include "PHY_Pro.h"
#include "PHY_IPhysicsEnvironment.h"
-#include "PHY_DynamicTypes.h"
-
-#include "KX_Scene.h"
-#include "KX_GameObject.h"
-#include "RAS_FramingManager.h"
#include "RAS_MeshObject.h"
#include "RAS_IRasterizer.h"
#include "RAS_ILightObject.h"
@@ -76,31 +66,27 @@
#include "KX_ConvertActuators.h"
#include "KX_ConvertControllers.h"
#include "KX_ConvertSensors.h"
-
#include "SCA_LogicManager.h"
-#include "SCA_EventManager.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_ClientObjectInfo.h"
#include "KX_EmptyObject.h"
#include "KX_FontObject.h"
-#include "MT_Point3.h"
-#include "MT_Transform.h"
-#include "MT_MinMax.h"
-#include "SCA_IInputDevice.h"
+
#include "RAS_TexMatrix.h"
#include "RAS_ICanvas.h"
-#include "RAS_MaterialBucket.h"
-//#include "KX_BlenderPolyMaterial.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 "DNA_action_types.h"
#include "BKE_main.h"
#include "BKE_global.h"
#include "BKE_object.h"
@@ -109,10 +95,10 @@
#include "BL_SkinDeformer.h"
#include "BL_MeshDeformer.h"
#include "KX_SoftBodyDeformer.h"
-//#include "BL_ArmatureController.h"
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
-#include "BlenderWorldInfo.h"
+
+#include "KX_WorldInfo.h"
#include "KX_KetsjiEngine.h"
#include "KX_BlenderSceneConverter.h"
@@ -143,13 +129,14 @@
#include "DNA_sound_types.h"
#include "DNA_key_types.h"
#include "DNA_armature_types.h"
+#include "DNA_action_types.h"
#include "DNA_object_force.h"
+#include "DNA_constraint_types.h"
#include "MEM_guardedalloc.h"
#include "BKE_key.h"
#include "BKE_mesh.h"
-#include "MT_Point3.h"
#include "BLI_math.h"
@@ -170,29 +157,19 @@ extern Material defmaterial; /* material.c */
#include "KX_BlenderInputDevice.h"
#include "KX_ConvertProperties.h"
-#include "KX_HashedPtr.h"
-
-
-#include "KX_ScalarInterpolator.h"
-
-#include "KX_IpoConvert.h"
-#include "BL_System.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"
-
-// This file defines relationships between parents and children
-// in the game engine.
-#include "KX_SG_NodeRelationships.h"
-#include "KX_SG_BoneParentNodeRelationship.h"
+#include "KX_MotionState.h"
#include "BL_ArmatureObject.h"
#include "BL_DeformableGameObject.h"
@@ -200,18 +177,9 @@ extern Material defmaterial; /* material.c */
#include "KX_NavMeshObject.h"
#include "KX_ObstacleSimulation.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-//XXX void update_for_newframe();
-//void BKE_scene_update_for_newframe(struct Scene *sce, unsigned int lay);
-//void do_all_data_ipos(void);
-#ifdef __cplusplus
-}
-#endif
-
#include "BLI_threads.h"
+
static bool default_light_mode = 0;
static std::map<int, SCA_IInputDevice::KX_EnumInputs> create_translate_table()
@@ -389,6 +357,11 @@ static std::map<int, SCA_IInputDevice::KX_EnumInputs> create_translate_table()
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
@@ -889,20 +862,20 @@ static bool ConvertMaterial(
// swap the material color, so MCol on bitmap font works
if (validmat && (use_vcol == false) && (mat->game.flag & GEMAT_TEXT))
{
- rgb[0] = KX_rgbaint2uint_new(rgb[0]);
- rgb[1] = KX_rgbaint2uint_new(rgb[1]);
- rgb[2] = KX_rgbaint2uint_new(rgb[2]);
- rgb[3] = KX_rgbaint2uint_new(rgb[3]);
+ 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) {
- material->tface = *tface;
+ ME_MTEXFACE_CPY(&material->mtexpoly, tface);
}
else {
- memset(&material->tface, 0, sizeof(material->tface));
+ memset(&material->mtexpoly, 0, sizeof(material->mtexpoly));
}
material->material = mat;
return true;
@@ -986,8 +959,16 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene,
int totface = dm->getNumTessFaces(dm);
const char *tfaceName = "";
+ /* needs to be rewritten for loopdata */
if (tface) {
- DM_add_tangent_layer(dm);
+ 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);
+ generate_data = true;
+ }
+ DM_generate_tangent_tessface_data(dm, generate_data);
+ }
tangent = (float(*)[4])dm->getTessFaceDataArray(dm, CD_TANGENT);
}
@@ -1022,7 +1003,6 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene,
meshobj->m_sharedvertex_map.resize(totvert);
Material* ma = 0;
- bool collider = true;
MT_Point2 uvs[4][RAS_TexVert::MAX_UNIT];
unsigned int rgb[4] = {0};
@@ -1092,29 +1072,19 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene,
else
ma = mesh->mat ? mesh->mat[mface->mat_nr]:NULL;
- /* ckeck for texface since texface _only_ is used as a fallback */
- if (ma == NULL && tface == NULL) {
+ // Check for blender material
+ if (ma == NULL) {
ma= &defmaterial;
}
{
- bool visible = true;
- bool twoside = false;
RAS_MaterialBucket* bucket = material_from_mesh(ma, mface, tface, mcol, layers, lightlayer, rgb, uvs, tfaceName, scene, converter);
// set render flags
- if (ma)
- {
- visible = ((ma->game.flag & GEMAT_INVISIBLE)==0);
- twoside = ((ma->game.flag & GEMAT_BACKCULL)==0);
- collider = ((ma->game.flag & GEMAT_NOPHYSICS)==0);
- }
- else {
- visible = true;
- twoside = false;
- collider = true;
- }
+ 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;
@@ -1238,7 +1208,9 @@ static PHY_ShapeProps *CreateShapePropsFromBlenderObject(struct Object* blendero
// 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;
@@ -1374,8 +1346,8 @@ static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
if (!(blenderobject->gameflag & OB_COLLISION)) {
// Respond to all collisions so that Near sensors work on No Collision
// objects.
- gameobj->SetUserCollisionGroup(0xff);
- gameobj->SetUserCollisionMask(0xff);
+ gameobj->SetUserCollisionGroup(0xffff);
+ gameobj->SetUserCollisionMask(0xffff);
return;
}
@@ -1389,16 +1361,14 @@ static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
}
bool isCompoundChild = false;
- bool hasCompoundChildren = !parent && (blenderobject->gameflag & OB_CHILD);
+ 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 */
+ * 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))
- {
+ if( (parent->gameflag & OB_CHILD)!=0 && (blenderobject->gameflag & OB_CHILD) && !(parent->gameflag & OB_SOFT_BODY)) {
isCompoundChild = true;
- }
+ }
}
if (processCompoundChildren != isCompoundChild)
return;
@@ -1429,16 +1399,6 @@ static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
if ((blenderobject->gameflag & OB_RECORD_ANIMATION) != 0)
gameobj->SetRecordAnimation(true);
- // store materialname in auxinfo, needed for touchsensors
- if (meshobj)
- {
- const STR_String& matname=meshobj->GetMaterialName(0);
- gameobj->getClientInfo()->m_auxilary_info = (matname.Length() ? (void*)(matname.ReadPtr()+2) : NULL);
- } else
- {
- gameobj->getClientInfo()->m_auxilary_info = 0;
- }
-
delete shapeprops;
delete smmaterial;
if (dm) {
@@ -1499,7 +1459,7 @@ static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int l
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->clipsta, ca->clipend, ca->type == CAM_PERSP, ca->YF_dofdist);
+ 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);
@@ -1568,7 +1528,7 @@ static KX_GameObject *gameobject_from_blenderobject(
gameobj->AddMesh(meshobj);
// gather levels of detail
- if (BLI_countlist(&ob->lodlevels) > 1) {
+ if (BLI_listbase_count_ex(&ob->lodlevels, 2) > 1) {
LodLevel *lod = ((LodLevel*)ob->lodlevels.first)->next;
Mesh* lodmesh = mesh;
Object* lodmatob = ob;
@@ -1583,6 +1543,10 @@ static KX_GameObject *gameobject_from_blenderobject(
}
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
@@ -1676,7 +1640,7 @@ static KX_GameObject *gameobject_from_blenderobject(
case OB_FONT:
{
- bool do_color_management = !(blenderscene->gm.flag & GAME_GLSL_NO_COLOR_MANAGEMENT);
+ 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);
@@ -1711,9 +1675,6 @@ struct parentChildLink {
SG_Node* m_gamechildnode;
};
-#include "DNA_constraint_types.h"
-//XXX #include "BIF_editconstraint.h"
-
static bPoseChannel *get_active_posechannel2(Object *ob)
{
bArmature *arm= (bArmature*)ob->data;
@@ -1747,20 +1708,27 @@ static ListBase *get_active_constraints2(Object *ob)
return NULL;
}
-static void UNUSED_FUNCTION(RBJconstraints)(Object *ob)//not used
+static void UNUSED_FUNCTION(print_active_constraints2)(Object *ob) //not used, use to debug
{
- ListBase *conlist;
- bConstraint *curcon;
-
- conlist = get_active_constraints2(ob);
+ 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;
}
}
@@ -1778,12 +1746,21 @@ static KX_GameObject* getGameOb(STR_String busc,CListValue* sumolist)
}
+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,
- Scene *blenderscene, Object *blenderobject,
- vector<MT_Vector3> &inivel, vector<MT_Vector3> &iniang,
+ Object *blenderobject,
vector<parentChildLink> &vec_parent_child,
CListValue* logicbrick_conversionlist,
CListValue* objectlist, CListValue* inactivelist, CListValue* sumolist,
@@ -1792,10 +1769,6 @@ static void bl_ConvertBlenderObject_Single(
bool isInActiveLayer
)
{
- MT_Point3 posPrev;
- MT_Matrix3x3 angor;
- if (converter->addInitFromFrame) blenderscene->r.cfra=blenderscene->r.sfra;
-
MT_Point3 pos(
blenderobject->loc[0]+blenderobject->dloc[0],
blenderobject->loc[1]+blenderobject->dloc[1],
@@ -1809,35 +1782,6 @@ static void bl_ConvertBlenderObject_Single(
MT_Vector3 scale(blenderobject->size);
- if (converter->addInitFromFrame) {//rcruiz
- blenderscene->r.cfra=blenderscene->r.sfra-1;
- //XXX update_for_newframe();
- MT_Vector3 tmp=pos-MT_Point3(blenderobject->loc[0]+blenderobject->dloc[0],
- blenderobject->loc[1]+blenderobject->dloc[1],
- blenderobject->loc[2]+blenderobject->dloc[2]
- );
-
- float rotmatPrev[3][3];
- BKE_object_rot_to_mat3(blenderobject, rotmatPrev, false);
-
- float eulxyz[3], eulxyzPrev[3];
- mat3_to_eul(eulxyz, rotmat);
- mat3_to_eul(eulxyzPrev, rotmatPrev);
-
- double fps = (double) blenderscene->r.frs_sec/
- (double) blenderscene->r.frs_sec_base;
-
- tmp.scale(fps, fps, fps);
- inivel.push_back(tmp);
- tmp[0]=eulxyz[0]-eulxyzPrev[0];
- tmp[1]=eulxyz[1]-eulxyzPrev[1];
- tmp[2]=eulxyz[2]-eulxyzPrev[2];
- tmp.scale(fps, fps, fps);
- iniang.push_back(tmp);
- blenderscene->r.cfra=blenderscene->r.sfra;
- //XXX update_for_newframe();
- }
-
gameobj->NodeSetLocalPosition(pos);
gameobj->NodeSetLocalOrientation(rotation);
gameobj->NodeSetLocalScale(scale);
@@ -1850,7 +1794,7 @@ static void bl_ConvertBlenderObject_Single(
gameobj->SetName(blenderobject->id.name + 2);
// update children/parent hierarchy
- if ((blenderobject->parent != 0)&&(!converter->addInitFromFrame))
+ 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);
@@ -1909,10 +1853,6 @@ static void bl_ConvertBlenderObject_Single(
logicbrick_conversionlist->Add(gameobj->AddRef());
- if (converter->addInitFromFrame) {
- posPrev=gameobj->NodeGetWorldPosition();
- angor=gameobj->NodeGetWorldOrientation();
- }
if (isInActiveLayer)
{
objectlist->Add(gameobj->AddRef());
@@ -1920,7 +1860,6 @@ static void bl_ConvertBlenderObject_Single(
gameobj->NodeUpdateGS(0);
gameobj->AddMeshUser();
-
}
else
{
@@ -1928,11 +1867,6 @@ static void bl_ConvertBlenderObject_Single(
//at the end of this function if it is not a root object
inactivelist->Add(gameobj->AddRef());
}
-
- if (converter->addInitFromFrame) {
- gameobj->NodeSetLocalPosition(posPrev);
- gameobj->NodeSetLocalOrientation(angor);
- }
}
@@ -1951,8 +1885,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
#define BL_CONVERTBLENDEROBJECT_SINGLE \
bl_ConvertBlenderObject_Single(converter, \
- blenderscene, blenderobject, \
- inivel, iniang, \
+ blenderobject, \
vec_parent_child, \
logicbrick_conversionlist, \
objectlist, inactivelist, sumolist, \
@@ -1974,7 +1907,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
RAS_FrameSettings::RAS_FrameType frame_type;
int aspect_width;
int aspect_height;
- vector<MT_Vector3> inivel,iniang;
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)
@@ -1983,6 +1915,12 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
// 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();
@@ -2046,6 +1984,9 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
}
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
@@ -2061,23 +2002,15 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
rendertools,
converter,
libloading);
-
- bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) !=0;
- bool addobj=true;
-
- if (converter->addInitFromFrame)
- if (!isInActiveLayer)
- addobj=false;
+ bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) !=0;
if (gameobj)
{
- if (addobj)
- { /* macro calls object conversion funcs */
- BL_CONVERTBLENDEROBJECT_SINGLE;
+ /* macro calls object conversion funcs */
+ BL_CONVERTBLENDEROBJECT_SINGLE;
- if (gameobj->IsDupliGroup()) {
- grouplist.insert(blenderobject->dup_group);
- }
+ if (gameobj->IsDupliGroup()) {
+ grouplist.insert(blenderobject->dup_group);
}
/* Note about memory leak issues:
@@ -2121,22 +2054,16 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
rendertools,
converter,
libloading);
-
- // this code is copied from above except that
- // object from groups are never in active layer
+
bool isInActiveLayer = false;
- bool addobj=true;
-
- if (converter->addInitFromFrame)
- if (!isInActiveLayer)
- addobj=false;
-
- if (gameobj)
- {
- if (addobj)
- { /* macro calls object conversion funcs */
- BL_CONVERTBLENDEROBJECT_SINGLE;
- }
+ 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())
{
@@ -2146,7 +2073,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
}
}
-
/* see comment above re: mem leaks */
gameobj->Release();
}
@@ -2260,8 +2186,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
case PARSKEL: // skinned - ignore
break;
case PAROBJECT:
- case PARCURVE:
- case PARKEY:
case PARVERT3:
default:
// unhandled
@@ -2338,7 +2262,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
}
bool processCompoundChildren = false;
-
// create physics information
for (i=0;i<sumolist->GetCount();i++)
{
@@ -2369,131 +2292,64 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0;
BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,converter,processCompoundChildren);
}
-
- //set ini linearVel and int angularVel //rcruiz
- if (converter->addInitFromFrame)
- for (i=0;i<sumolist->GetCount();i++)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- if (gameobj->IsDynamic()) {
- gameobj->setLinearVelocity(inivel[i],false);
- gameobj->setAngularVelocity(iniang[i],false);
- }
-
-
- }
- // create physics joints
+ // create physics joints
for (i=0;i<sumolist->GetCount();i++)
{
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- struct Object* blenderobject = gameobj->GetBlenderObject();
- ListBase *conlist;
+ 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;
- conlist = get_active_constraints2(blenderobject);
- if ((gameobj->GetLayer()&activeLayerBitInfo)==0)
+ if (!conlist)
continue;
- if (conlist) {
- for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) {
- if (curcon->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) {
+ for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) {
+ if (curcon->type != CONSTRAINT_TYPE_RIGIDBODYJOINT)
+ continue;
- bRigidBodyJointConstraint *dat=(bRigidBodyJointConstraint *)curcon->data;
+ 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;
- if (!dat->child && !(curcon->flag & CONSTRAINT_OFF)) {
+ /* Store constraints of grouped and instanced objects for all layers */
+ gameobj->AddConstraint(dat);
- PHY_IPhysicsController* physctr2 = 0;
+ /** 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;
- if (dat->tar)
- {
- KX_GameObject *gotar=getGameOb(dat->tar->id.name+2,sumolist);
- if (gotar && ((gotar->GetLayer()&activeLayerBitInfo)!=0) && gotar->GetPhysicsController())
- physctr2 = gotar->GetPhysicsController();
- }
+ /* 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;
- if (gameobj->GetPhysicsController())
- {
- PHY_IPhysicsController* physctrl = gameobj->GetPhysicsController();
- //we need to pass a full constraint frame, not just axis
-
- //localConstraintFrameBasis
- MT_Matrix3x3 localCFrame(MT_Vector3(dat->axX,dat->axY,dat->axZ));
- MT_Vector3 axis0 = localCFrame.getColumn(0);
- MT_Vector3 axis1 = localCFrame.getColumn(1);
- MT_Vector3 axis2 = localCFrame.getColumn(2);
-
- int constraintId = kxscene->GetPhysicsEnvironment()->CreateConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,
- (float)dat->pivY,(float)dat->pivZ,
- (float)axis0.x(),(float)axis0.y(),(float)axis0.z(),
- (float)axis1.x(),(float)axis1.y(),(float)axis1.z(),
- (float)axis2.x(),(float)axis2.y(),(float)axis2.z(),dat->flag);
- if (constraintId)
- {
- //if it is a generic 6DOF constraint, set all the limits accordingly
- if (dat->type == PHY_GENERIC_6DOF_CONSTRAINT)
- {
- int dof;
- int dofbit=1;
- for (dof=0;dof<6;dof++)
- {
- if (dat->flag & dofbit)
- {
- kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]);
- } else
- {
- //minLimit > maxLimit means free(disabled limit) for this degree of freedom
- kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,1,-1);
- }
- dofbit<<=1;
- }
- }
- else if (dat->type == PHY_CONE_TWIST_CONSTRAINT)
- {
- int dof;
- int dofbit = 1<<3; // bitflag use_angular_limit_x
-
- for (dof=3;dof<6;dof++)
- {
- if (dat->flag & dofbit)
- {
- kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]);
- }
- else
- {
- //maxLimit < 0 means free(disabled limit) for this degree of freedom
- kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,1,-1);
- }
- dofbit<<=1;
- }
- }
- else if (dat->type == PHY_LINEHINGE_CONSTRAINT)
- {
- int dof = 3; // dof for angular x
- int dofbit = 1<<3; // bitflag use_angular_limit_x
-
- if (dat->flag & dofbit)
- {
- kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,
- dat->minLimit[dof],dat->maxLimit[dof]);
- } else
- {
- //minLimit > maxLimit means free(disabled limit) for this degree of freedom
- kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,1,-1);
- }
- }
- }
- }
- }
- }
+ 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 BlenderWorldInfo(blenderscene, blenderscene->world);
+ KX_WorldInfo* worldinfo = new KX_WorldInfo(blenderscene, blenderscene->world);
converter->RegisterWorldInfo(worldinfo);
kxscene->SetWorldInfo(worldinfo);
@@ -2537,8 +2393,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
}
}
-#define CONVERT_LOGIC
-#ifdef CONVERT_LOGIC
// convert logic bricks, sensors, controllers and actuators
for (i=0;i<logicbrick_conversionlist->GetCount();i++)
{
@@ -2573,8 +2427,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
gameobj->ResetState();
}
-#endif //CONVERT_LOGIC
-
logicbrick_conversionlist->Release();
// Calculate the scene btree -
@@ -2601,7 +2453,3 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
bucketmanager->OptimizeBuckets(distance);
}
-SCA_IInputDevice::KX_EnumInputs ConvertKeyCode(int key_code)
-{
- return gReverseKeyTranslateTable[key_code];
-}