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.cpp163
1 files changed, 67 insertions, 96 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
index 7e0588fc7d0..3da0863508b 100644
--- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp
+++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
@@ -98,7 +98,7 @@
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
-#include "BlenderWorldInfo.h"
+#include "KX_WorldInfo.h"
#include "KX_KetsjiEngine.h"
#include "KX_BlenderSceneConverter.h"
@@ -995,7 +995,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};
@@ -1065,29 +1064,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;
@@ -1347,8 +1336,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;
}
@@ -1554,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
@@ -1647,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);
@@ -1741,6 +1734,16 @@ 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(
@@ -1900,6 +1903,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();
@@ -2031,6 +2040,11 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
converter,
libloading);
+ /* 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());
+
bool isInActiveLayer = false;
if (gameobj)
{
@@ -2270,97 +2284,54 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
// 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;
- if ((gameobj->GetLayer()&activeLayerBitInfo)==0)
+ if (!conlist)
continue;
- conlist = get_active_constraints2(blenderobject);
- if (conlist) {
- for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) {
- if (curcon->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) {
-
- bRigidBodyJointConstraint *dat=(bRigidBodyJointConstraint *)curcon->data;
+ for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) {
+ if (curcon->type != CONSTRAINT_TYPE_RIGIDBODYJOINT)
+ continue;
- if (!dat->child && !(curcon->flag & CONSTRAINT_OFF)) {
+ 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;
- PHY_IPhysicsController* physctr2 = 0;
+ /* Store constraints of grouped and instanced objects for all layers */
+ gameobj->AddConstraint(dat);
+
+ /* 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 (dat->tar) {
- KX_GameObject *gotar=getGameOb(dat->tar->id.name+2,sumolist);
- if (gotar && ((gotar->GetLayer()&activeLayerBitInfo)!=0) && gotar->GetPhysicsController())
- physctr2 = gotar->GetPhysicsController();
- }
+ KX_GameObject *gotar = getGameOb(dat->tar->id.name + 2, sumolist);
- 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);
- }
- }
- }
- }
- }
- }
+ 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);