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:
authorBenoit Bolsee <benoit.bolsee@online.be>2009-04-21 15:01:09 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2009-04-21 15:01:09 +0400
commitd11a5bbef2750c9e95c0657eb9d965de375b2982 (patch)
treea81482dbc11cdac8be2748ada47b4f59ff204ea2 /source/gameengine/Ketsji
parent3e7cbd5388426a612b4066fbe7f2964c976fb23e (diff)
BGE: Support mesh modifiers in the game engine.
Realtime modifiers applied on mesh objects will be supported in the game engine with the following limitations: - Only real time modifiers are supported (basically all of them!) - Virtual modifiers resulting from parenting are not supported: armature, curve, lattice. You can still use these modifiers (armature is really not recommended) but in non parent mode. The BGE has it's own parenting capability for armature. - Modifiers are computed on the host (using blender modifier stack). - Modifiers are statically evaluated: any possible time dependency in the modifiers is not supported (don't know enough about modifiers to be more specific). - Modifiers are reevaluated if the underlying mesh is deformed due to shape action or armature action. Beware that this is very CPU intensive; modifiers should really be used for static objects only. - Physics is still based on the original mesh: if you have a mirror modifier, the physic shape will be limited to one half of the resulting object. Therefore, the modifiers should preferably be used on graphic objects. - Scripts have no access to the modified mesh. - Modifiers that are based on objects interaction (boolean,..) will not be dependent on the objects position in the GE. What you see in the 3D view is what you get in the GE regardless on the object position, velocity, etc. Besides that, the feature is compatible with all the BGE features that affect meshes: armature action, shape action, relace mesh, VideoTexture, add object, dupligroup. Known problems: - This feature is a bit hacky: the BGE uses the derived mesh draw functions to display the object. This drawing method is a bit slow and is not 100% compatible with the BGE. There may be some problems in multi-texture mode: the multi-texture coordinates are not sent to the GPU. Texface and GLSL on the other hand should be fully supported. - Culling is still based on the extend of the original mesh. If you have a modifer that extends the size of the mesh, the object may disappear while still in the view frustrum. - Derived mesh is not shared between replicas. The derived mesh is allocated and computed for each object with modifiers, regardless if they are static replicas. - Display list are not created on objects with modifiers. I should be able to fix the above problems before release. However, the feature is already useful for game development. Once you are ready to release the game, you can apply the modifiers to get back display list support and mesh sharing capability. MSVC, scons, Cmake, makefile updated. Enjoy /benoit
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r--source/gameengine/Ketsji/BL_Material.cpp2
-rw-r--r--source/gameengine/Ketsji/BL_Material.h3
-rw-r--r--source/gameengine/Ketsji/KX_BlenderMaterial.cpp24
-rw-r--r--source/gameengine/Ketsji/KX_BlenderMaterial.h4
-rw-r--r--source/gameengine/Ketsji/KX_PolygonMaterial.cpp14
-rw-r--r--source/gameengine/Ketsji/KX_PolygonMaterial.h6
-rw-r--r--source/gameengine/Ketsji/KX_Scene.cpp36
7 files changed, 79 insertions, 10 deletions
diff --git a/source/gameengine/Ketsji/BL_Material.cpp b/source/gameengine/Ketsji/BL_Material.cpp
index 7e3d6984f19..022ed71ef7b 100644
--- a/source/gameengine/Ketsji/BL_Material.cpp
+++ b/source/gameengine/Ketsji/BL_Material.cpp
@@ -52,7 +52,7 @@ BL_Material::BL_Material()
mode = 0;
material = 0;
tface = 0;
- material_index = 0;
+ materialindex = 0;
amb=0.5f;
num_enabled = 0;
num_users = 1;
diff --git a/source/gameengine/Ketsji/BL_Material.h b/source/gameengine/Ketsji/BL_Material.h
index 0eaa234566c..a0ce37aace0 100644
--- a/source/gameengine/Ketsji/BL_Material.h
+++ b/source/gameengine/Ketsji/BL_Material.h
@@ -54,6 +54,7 @@ public:
int tile,tilexrep[MAXTEX],tileyrep[MAXTEX];
STR_String matname;
STR_String mtexname[MAXTEX];
+ int materialindex;
float matcolor[4];
float speccolor[3];
@@ -68,8 +69,6 @@ public:
int mode;
int num_enabled;
- int material_index;
-
BL_Mapping mapping[MAXTEX];
STR_String imageId[MAXTEX];
diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
index 2edfe4b718c..7378113bc31 100644
--- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
+++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
@@ -53,6 +53,7 @@ KX_BlenderMaterial::KX_BlenderMaterial(
RAS_IPolyMaterial(
STR_String( data->texname[0] ),
STR_String( data->matname ), // needed for physics!
+ data->materialindex,
data->tile,
data->tilexrep[0],
data->tileyrep[0],
@@ -120,6 +121,27 @@ unsigned int* KX_BlenderMaterial::GetMCol(void) const
return mMaterial->rgb;
}
+void KX_BlenderMaterial::GetMaterialRGBAColor(unsigned char *rgba) const
+{
+ if (mMaterial) {
+ *rgba++ = (unsigned char) (mMaterial->matcolor[0]*255.0);
+ *rgba++ = (unsigned char) (mMaterial->matcolor[1]*255.0);
+ *rgba++ = (unsigned char) (mMaterial->matcolor[2]*255.0);
+ *rgba++ = (unsigned char) (mMaterial->matcolor[3]*255.0);
+ } else
+ RAS_IPolyMaterial::GetMaterialRGBAColor(rgba);
+}
+
+Material *KX_BlenderMaterial::GetBlenderMaterial() const
+{
+ return mMaterial->material;
+}
+
+Scene* KX_BlenderMaterial::GetBlenderScene() const
+{
+ return mScene->GetBlenderScene();
+}
+
void KX_BlenderMaterial::OnConstruction()
{
if (mConstructed)
@@ -863,7 +885,7 @@ void KX_BlenderMaterial::SetBlenderGLSLShader(void)
KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getMaterialIndex, "getMaterialIndex()")
{
- return PyInt_FromLong( mMaterial->material_index );
+ return PyInt_FromLong( GetMaterialIndex() );
}
KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getTexture, "getTexture( index )" )
diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h
index 57cdde3c947..eeb919a1bf1 100644
--- a/source/gameengine/Ketsji/KX_BlenderMaterial.h
+++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h
@@ -73,7 +73,6 @@ public:
Image * getImage (unsigned int idx) {
return (idx < MAXTEX && mMaterial) ? mMaterial->img[idx] : NULL;
}
-
// for ipos
void UpdateIPO(
MT_Vector4 rgba, MT_Vector3 specrgb,
@@ -117,6 +116,9 @@ private:
void ActivateTexGen( RAS_IRasterizer *ras ) const;
bool UsesLighting(RAS_IRasterizer *rasty) const;
+ void GetMaterialRGBAColor(unsigned char *rgba) const;
+ Material* GetBlenderMaterial() const;
+ Scene* GetBlenderScene() const;
// message centers
void setTexData( bool enable,RAS_IRasterizer *ras);
diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
index 2d5a5f99cea..a8105c1e4f3 100644
--- a/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
+++ b/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
@@ -53,6 +53,7 @@
KX_PolygonMaterial::KX_PolygonMaterial(const STR_String &texname,
Material *material,
+ int materialindex,
int tile,
int tilexrep,
int tileyrep,
@@ -67,6 +68,7 @@ KX_PolygonMaterial::KX_PolygonMaterial(const STR_String &texname,
: PyObjectPlus(T),
RAS_IPolyMaterial(texname,
STR_String(material?material->id.name:""),
+ materialindex,
tile,
tilexrep,
tileyrep,
@@ -167,6 +169,18 @@ void KX_PolygonMaterial::DefaultActivate(RAS_IRasterizer* rasty, TCachingInfo& c
rasty->SetPolygonOffset(-m_material->zoffs, 0.0);
}
+void KX_PolygonMaterial::GetMaterialRGBAColor(unsigned char *rgba) const
+{
+ if (m_material) {
+ *rgba++ = (unsigned char) (m_material->r*255.0);
+ *rgba++ = (unsigned char) (m_material->g*255.0);
+ *rgba++ = (unsigned char) (m_material->b*255.0);
+ *rgba++ = (unsigned char) (m_material->alpha*255.0);
+ } else
+ RAS_IPolyMaterial::GetMaterialRGBAColor(rgba);
+}
+
+
//----------------------------------------------------------------------------
//Python
diff --git a/source/gameengine/Ketsji/KX_PolygonMaterial.h b/source/gameengine/Ketsji/KX_PolygonMaterial.h
index e5816058bbf..b6f5f373335 100644
--- a/source/gameengine/Ketsji/KX_PolygonMaterial.h
+++ b/source/gameengine/Ketsji/KX_PolygonMaterial.h
@@ -53,7 +53,6 @@ private:
MTFace* m_tface;
unsigned int* m_mcol;
Material* m_material;
-
PyObject* m_pymaterial;
mutable int m_pass;
@@ -61,6 +60,7 @@ public:
KX_PolygonMaterial(const STR_String &texname,
Material* ma,
+ int materialindex,
int tile,
int tilexrep,
int tileyrep,
@@ -107,8 +107,8 @@ public:
{
return m_mcol;
}
-
-
+ virtual void GetMaterialRGBAColor(unsigned char *rgba) const;
+
KX_PYMETHOD_DOC(KX_PolygonMaterial, updateTexture);
KX_PYMETHOD_DOC(KX_PolygonMaterial, setTexture);
KX_PYMETHOD_DOC(KX_PolygonMaterial, activate);
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp
index f91c4674113..f57a38d290d 100644
--- a/source/gameengine/Ketsji/KX_Scene.cpp
+++ b/source/gameengine/Ketsji/KX_Scene.cpp
@@ -80,6 +80,7 @@
#include "KX_BlenderSceneConverter.h"
#include "KX_MotionState.h"
+#include "BL_ModifierDeformer.h"
#include "BL_ShapeDeformer.h"
#include "BL_DeformableGameObject.h"
@@ -1038,6 +1039,7 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj)
Object* oldblendobj = static_cast<struct Object*>(m_logicmgr->FindBlendObjByGameMeshName(mesh->GetName()));
Mesh* blendmesh = mesh->GetMesh();
+ bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(blendobj);
bool bHasShapeKey = blendmesh->key != NULL && blendmesh->key->type==KEY_RELATIVE;
bool bHasDvert = blendmesh->dvert != NULL;
bool bHasArmature =
@@ -1053,10 +1055,37 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj)
if (oldblendobj==NULL) {
std::cout << "warning: ReplaceMesh() new mesh is not used in an object from the current scene, you will get incorrect behavior" << std::endl;
- bHasShapeKey= bHasDvert= bHasArmature= false;
+ bHasShapeKey= bHasDvert= bHasArmature=bHasModifier= false;
}
- if (bHasShapeKey)
+ if (bHasModifier)
+ {
+ BL_ModifierDeformer* modifierDeformer;
+ if (bHasShapeKey || bHasArmature)
+ {
+ modifierDeformer = new BL_ModifierDeformer(
+ newobj,
+ oldblendobj, blendobj,
+ static_cast<BL_SkinMeshObject*>(mesh),
+ true,
+ static_cast<BL_ArmatureObject*>( parentobj )
+ );
+ releaseParent= false;
+ modifierDeformer->LoadShapeDrivers(blendobj->parent);
+ }
+ else
+ {
+ modifierDeformer = new BL_ModifierDeformer(
+ newobj,
+ oldblendobj, blendobj,
+ static_cast<BL_SkinMeshObject*>(mesh),
+ false,
+ NULL
+ );
+ }
+ newobj->SetDeformer(modifierDeformer);
+ }
+ else if (bHasShapeKey)
{
BL_ShapeDeformer* shapeDeformer;
if (bHasArmature)
@@ -1066,6 +1095,7 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj)
oldblendobj, blendobj,
static_cast<BL_SkinMeshObject*>(mesh),
true,
+ true,
static_cast<BL_ArmatureObject*>( parentobj )
);
releaseParent= false;
@@ -1078,6 +1108,7 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj)
oldblendobj, blendobj,
static_cast<BL_SkinMeshObject*>(mesh),
false,
+ true,
NULL
);
}
@@ -1090,6 +1121,7 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj)
oldblendobj, blendobj,
static_cast<BL_SkinMeshObject*>(mesh),
true,
+ true,
static_cast<BL_ArmatureObject*>( parentobj )
);
releaseParent= false;