BGE modifier: generate correct physic shape, share static derived mesh, share display...
authorBenoit Bolsee <benoit.bolsee@online.be>
Thu, 14 May 2009 13:47:08 +0000 (13:47 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Thu, 14 May 2009 13:47:08 +0000 (13:47 +0000)
This commit completes the support for modifiers in the BGE.
- The physic shape is generated according to the derived mesh.
  This is true for all types of shapes and all types of
  objects except soft body.
- Optimization for static derived mesh (mesh with modifiers
  but no armature and no shape keys). Replicas will share
  the derived mesh and the display list: less memory and
  faster rendering. With this optimization, the static
  derived mesh will render as fast as if the modifiers were
  applied.

Known Limits:
- Sharing of mesh and display list is only possible between
  in-game replicas or dupligroup. If you want to instantiate
  multiple objects with modifiers, use dupligroup to ensure
  best memory and GPU utilization.
- rayCast() will interact with the derived mesh as follow:
  Hit position and hit normal are the real values according
  to the derived mesh but the KX_PolyProxy object refers to
  the original mesh. You should use it only to retrieve the
  material.
- Dynamic derived mesh have very poor performance:
  They use direct openGL calls for rendering (no support
  for display list and vertex array) and they dont't share
  the derived mesh memory. Always apply modifiers on dynamic
  mesh for best performance.
- Time dependent modifiers are not supported.
- Modifiers are not supported for Bullet soft body.

20 files changed:
projectfiles_vc9/gameengine/physics/PHY_Physics/PHY_Bullet/PHY_Bullet.vcproj
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/BL_MeshDeformer.cpp
source/gameengine/Converter/BL_MeshDeformer.h
source/gameengine/Converter/BL_ModifierDeformer.cpp
source/gameengine/Converter/BL_ModifierDeformer.h
source/gameengine/Converter/BL_ShapeDeformer.cpp
source/gameengine/Converter/BL_ShapeDeformer.h
source/gameengine/Converter/BL_SkinDeformer.cpp
source/gameengine/Converter/BL_SkinDeformer.h
source/gameengine/Ketsji/KX_ConvertPhysicsObject.h
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Physics/Bullet/CMakeLists.txt
source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
source/gameengine/Physics/Bullet/CcdPhysicsController.h
source/gameengine/Physics/Bullet/Makefile
source/gameengine/Physics/Bullet/SConscript
source/gameengine/Rasterizer/RAS_Deformer.h
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h

index e6991592d4028f1500219b694ac8a7d9c26cdaa7..9f16283e1cd9013eb86367f2a2a0b01aca0ed451 100644 (file)
@@ -42,7 +42,7 @@
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna"\r
+                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna;..\..\..\..\..\source\blender\blenkernel;..\..\..\..\..\source\blender\blenlib"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB"\r
                                MinimalRebuild="false"\r
                                BasicRuntimeChecks="3"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB"\r
                                MinimalRebuild="false"\r
                                BasicRuntimeChecks="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna"\r
+                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna;..\..\..\..\..\source\blender\blenkernel;..\..\..\..\..\source\blender\blenlib"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB"\r
                                RuntimeLibrary="0"\r
                                UsePrecompiledHeader="0"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB"\r
                                RuntimeLibrary="0"\r
                                UsePrecompiledHeader="0"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna"\r
+                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna;..\..\..\..\..\source\blender\blenkernel;..\..\..\..\..\source\blender\blenlib"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB"\r
                                RuntimeLibrary="0"\r
                                UsePrecompiledHeader="0"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB"\r
                                RuntimeLibrary="0"\r
                                UsePrecompiledHeader="0"\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna"\r
+                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna;..\..\..\..\..\source\blender\blenkernel;..\..\..\..\..\source\blender\blenlib"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB"\r
                                MinimalRebuild="false"\r
                                BasicRuntimeChecks="3"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB"\r
                                MinimalRebuild="false"\r
                                BasicRuntimeChecks="3"\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna"\r
+                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna;..\..\..\..\..\source\blender\blenkernel;..\..\..\..\..\source\blender\blenlib"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB"\r
                                MinimalRebuild="false"\r
                                BasicRuntimeChecks="3"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB"\r
                                MinimalRebuild="false"\r
                                BasicRuntimeChecks="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna"\r
+                               AdditionalIncludeDirectories="..\..\..\..\..\..\lib\windows\python\include\python2.5;..\..\..\..\..\..\build\msvc_9\intern\moto\include;..\..\..\..\..\..\build\msvc_9\intern\string\include;..\..\..\..\..\..\build\msvc_9\extern\bullet\include;..\..\..\..\..\..\build\msvc_9\extern\glew\include;..\..\..\..\..\..\build\msvc_9\intern\SoundSystem\include;..\..\..\..\..\..\build\msvc_9\intern\guardedalloc\include;..\..\..\..\..\source\gameengine\Physics\common;..\..\..\..\..\source\gameengine\Physics\Bullet;..\..\..\..\..\source\gameengine\Rasterizer;..\..\..\..\..\source\gameengine\Ketsji;..\..\..\..\..\source\gameengine\Expressions;..\..\..\..\..\source\gameengine\GameLogic;..\..\..\..\..\source\gameengine\SceneGraph;..\..\..\..\..\source\kernel\gen_system;..\..\..\..\..\source\blender\makesdna;..\..\..\..\..\source\blender\blenkernel;..\..\..\..\..\source\blender\blenlib"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB"\r
                                RuntimeLibrary="2"\r
                                UsePrecompiledHeader="0"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB"\r
                                RuntimeLibrary="2"\r
                                UsePrecompiledHeader="0"\r
index 09604e5c2e37cdc06d42ee499d1417cee8d6c837..9ea623f17e42bf9671320399237c0b09233c17d9 100644 (file)
@@ -1249,18 +1249,34 @@ static void my_tex_space_mesh(Mesh *me)
        
 }
 
        
 }
 
-static void my_get_local_bounds(Object *ob, float *center, float *size)
+static void my_get_local_bounds(Object *ob, DerivedMesh *dm, float *center, float *size)
 {
        BoundBox *bb= NULL;
        /* uses boundbox, function used by Ketsji */
        switch (ob->type)
        {
                case OB_MESH:
 {
        BoundBox *bb= NULL;
        /* uses boundbox, function used by Ketsji */
        switch (ob->type)
        {
                case OB_MESH:
-                       bb= ( (Mesh *)ob->data )->bb;
-                       if(bb==0) 
+                       if (dm)
+                       {
+                               float min_r[3], max_r[3];
+                               INIT_MINMAX(min_r, max_r);
+                               dm->getMinMax(dm, min_r, max_r);
+                               size[0]= 0.5*fabs(max_r[0] - min_r[0]);
+                               size[1]= 0.5*fabs(max_r[1] - min_r[1]);
+                               size[2]= 0.5*fabs(max_r[2] - min_r[2]);
+                                       
+                               center[0]= 0.5*(max_r[0] + min_r[0]);
+                               center[1]= 0.5*(max_r[1] + min_r[1]);
+                               center[2]= 0.5*(max_r[2] + min_r[2]);
+                               return;
+                       } else
                        {
                        {
-                               my_tex_space_mesh((struct Mesh *)ob->data);
                                bb= ( (Mesh *)ob->data )->bb;
                                bb= ( (Mesh *)ob->data )->bb;
+                               if(bb==0) 
+                               {
+                                       my_tex_space_mesh((struct Mesh *)ob->data);
+                                       bb= ( (Mesh *)ob->data )->bb;
+                               }
                        }
                        break;
                case OB_CURVE:
                        }
                        break;
                case OB_CURVE:
@@ -1498,7 +1514,10 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
        }
 
        KX_BoxBounds bb;
        }
 
        KX_BoxBounds bb;
-       my_get_local_bounds(blenderobject,objprop.m_boundobject.box.m_center,bb.m_extends);
+       DerivedMesh* dm = NULL;
+       if (gameobj->GetDeformer())
+               dm = gameobj->GetDeformer()->GetFinalMesh();
+       my_get_local_bounds(blenderobject,dm,objprop.m_boundobject.box.m_center,bb.m_extends);
        if (blenderobject->gameflag & OB_BOUNDS)
        {
                switch (blenderobject->boundtype)
        if (blenderobject->gameflag & OB_BOUNDS)
        {
                switch (blenderobject->boundtype)
@@ -1567,7 +1586,7 @@ void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
        {
 #ifdef USE_BULLET
                case UseBullet:
        {
 #ifdef USE_BULLET
                case UseBullet:
-                       KX_ConvertBulletObject(gameobj, meshobj, kxscene, shapeprops, smmaterial, &objprop);
+                       KX_ConvertBulletObject(gameobj, meshobj, dm, kxscene, shapeprops, smmaterial, &objprop);
                        break;
 
 #endif
                        break;
 
 #endif
@@ -1947,8 +1966,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
 
        int activeLayerBitInfo = blenderscene->lay;
        
 
        int activeLayerBitInfo = blenderscene->lay;
        
-       // templist to find Root Parents (object with no parents)
-       CListValue* templist = new CListValue();
+       // list of all object converted, active and inactive
        CListValue*     sumolist = new CListValue();
        
        vector<parentChildLink> vec_parent_child;
        CListValue*     sumolist = new CListValue();
        
        vector<parentChildLink> vec_parent_child;
@@ -2048,9 +2066,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        
                        gameobj->SetName(blenderobject->id.name);
        
        
                        gameobj->SetName(blenderobject->id.name);
        
-                       // templist to find Root Parents (object with no parents)
-                       templist->Add(gameobj->AddRef());
-                       
                        // update children/parent hierarchy
                        if ((blenderobject->parent != 0)&&(!converter->addInitFromFrame))
                        {
                        // update children/parent hierarchy
                        if ((blenderobject->parent != 0)&&(!converter->addInitFromFrame))
                        {
@@ -2243,9 +2258,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                        
                                                        gameobj->SetName(blenderobject->id.name);
                                        
                                        
                                                        gameobj->SetName(blenderobject->id.name);
                                        
-                                                       // templist to find Root Parents (object with no parents)
-                                                       templist->Add(gameobj->AddRef());
-                                                       
                                                        // update children/parent hierarchy
                                                        if ((blenderobject->parent != 0)&&(!converter->addInitFromFrame))
                                                        {
                                                        // update children/parent hierarchy
                                                        if ((blenderobject->parent != 0)&&(!converter->addInitFromFrame))
                                                        {
@@ -2398,8 +2410,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                        for ( i=0;i<childrenlist->GetCount();i++)
                        {
                                KX_GameObject* obj = static_cast<KX_GameObject*>(childrenlist->GetValue(i));
                        for ( i=0;i<childrenlist->GetCount();i++)
                        {
                                KX_GameObject* obj = static_cast<KX_GameObject*>(childrenlist->GetValue(i));
-                               if (templist->RemoveValue(obj))
-                                       obj->Release();
                                if (sumolist->RemoveValue(obj))
                                        obj->Release();
                                if (logicbrick_conversionlist->RemoveValue(obj))
                                if (sumolist->RemoveValue(obj))
                                        obj->Release();
                                if (logicbrick_conversionlist->RemoveValue(obj))
@@ -2455,16 +2465,47 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        vec_parent_child.clear();
        
        // find 'root' parents (object that has not parents in SceneGraph)
        vec_parent_child.clear();
        
        // find 'root' parents (object that has not parents in SceneGraph)
-       for (i=0;i<templist->GetCount();++i)
+       for (i=0;i<sumolist->GetCount();++i)
        {
        {
-               KX_GameObject* gameobj = (KX_GameObject*) templist->GetValue(i);
+               KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
                if (gameobj->GetSGNode()->GetSGParent() == 0)
                {
                        parentlist->Add(gameobj->AddRef());
                        gameobj->NodeUpdateGS(0);
                }
        }
                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->world->occlusionRes);
+       }
+
+       // 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();
+       }
+
        bool processCompoundChildren = false;
 
        // create physics information
        bool processCompoundChildren = false;
 
        // create physics information
@@ -2498,28 +2539,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,physics_engine,converter,processCompoundChildren);
        }
        
                BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,physics_engine,converter,processCompoundChildren);
        }
        
-       // 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->world->occlusionRes);
-       }
-       
        //set ini linearVel and int angularVel //rcruiz
        if (converter->addInitFromFrame)
                for (i=0;i<sumolist->GetCount();i++)
        //set ini linearVel and int angularVel //rcruiz
        if (converter->addInitFromFrame)
                for (i=0;i<sumolist->GetCount();i++)
@@ -2605,7 +2624,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                }
        }
 
                }
        }
 
-       templist->Release();
        sumolist->Release();    
 
        // convert global sound stuff
        sumolist->Release();    
 
        // convert global sound stuff
index b6a59774636b24df6df623f58f7c241d2c2e1e9b..b49544050d12660d69386efa0c948c9ac5452f39 100644 (file)
@@ -91,6 +91,15 @@ BL_MeshDeformer::~BL_MeshDeformer()
                delete [] 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(GEN_Map<class GEN_HashedPtr, void*>*map)
 {
        void **h_obj = (*map)[m_gameobj];
 void BL_MeshDeformer::Relink(GEN_Map<class GEN_HashedPtr, void*>*map)
 {
        void **h_obj = (*map)[m_gameobj];
index 11ca3b00a1dba7e1e1a42e43dc8b5bb43a838dfa..99ae5f9dea0aaba2ea89b4779edbce38d1378c33 100644 (file)
@@ -66,7 +66,7 @@ public:
        virtual bool Update(void){ return false; };
        virtual bool UpdateBuckets(void){ return false; };
        virtual RAS_Deformer*   GetReplica(){return NULL;};
        virtual bool Update(void){ return false; };
        virtual bool UpdateBuckets(void){ return false; };
        virtual RAS_Deformer*   GetReplica(){return NULL;};
-       virtual void ProcessReplica() {m_bDynamic=false;};
+       virtual void ProcessReplica();
        struct Mesh* GetMesh() { return m_bmesh; };
        //      virtual void InitDeform(double time){};
 
        struct Mesh* GetMesh() { return m_bmesh; };
        //      virtual void InitDeform(double time){};
 
index 3c4c0c5caadd5f8cf4f3707e453fa1682e3e5487..fe539f9a6c59803ad4398ce3b960e3f8eb4d4b02 100644 (file)
@@ -72,8 +72,11 @@ extern "C"{
 BL_ModifierDeformer::~BL_ModifierDeformer()
 {
        if (m_dm) {
 BL_ModifierDeformer::~BL_ModifierDeformer()
 {
        if (m_dm) {
-               m_dm->needsFree = 1;
-               m_dm->release(m_dm);
+               // deformedOnly is used as a user counter
+               if (--m_dm->deformedOnly == 0) {
+                       m_dm->needsFree = 1;
+                       m_dm->release(m_dm);
+               }
        }
 };
 
        }
 };
 
@@ -90,7 +93,10 @@ void BL_ModifierDeformer::ProcessReplica()
 {
        /* Note! - This is not inherited from PyObjectPlus */
        BL_ShapeDeformer::ProcessReplica();
 {
        /* Note! - This is not inherited from PyObjectPlus */
        BL_ShapeDeformer::ProcessReplica();
-       m_dm = NULL;
+       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;
 }
 
        m_lastModifierUpdate = -1;
 }
 
@@ -117,29 +123,40 @@ bool BL_ModifierDeformer::Update(void)
        bool bShapeUpdate = BL_ShapeDeformer::Update();
 
        if (bShapeUpdate || m_lastModifierUpdate != m_gameobj->GetLastFrame()) {
        bool bShapeUpdate = BL_ShapeDeformer::Update();
 
        if (bShapeUpdate || m_lastModifierUpdate != m_gameobj->GetLastFrame()) {
-               /* 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(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) {
-                       m_dm->needsFree = 1;
+               // 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(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);
                        m_dm->release(m_dm);
-               }
-               m_dm = dm;
-               /* update the graphic controller */
-               PHY_IGraphicController *ctrl = m_gameobj->GetGraphicController();
-               if (ctrl) {
-                       float min_r[3], max_r[3];
-                       INIT_MINMAX(min_r, max_r);
-                       m_dm->getMinMax(m_dm, min_r, max_r);
-                       ctrl->setLocalAabb(min_r, max_r);
+                       // HACK! use deformedOnly as a user counter
+                       m_dm->deformedOnly = 1;
+                       /* update the graphic controller */
+                       PHY_IGraphicController *ctrl = m_gameobj->GetGraphicController();
+                       if (ctrl) {
+                               float min_r[3], max_r[3];
+                               INIT_MINMAX(min_r, max_r);
+                               m_dm->getMinMax(m_dm, min_r, max_r);
+                               ctrl->setLocalAabb(min_r, max_r);
+                       }
                }
                m_lastModifierUpdate=m_gameobj->GetLastFrame();
                bShapeUpdate = true;
                }
                m_lastModifierUpdate=m_gameobj->GetLastFrame();
                bShapeUpdate = true;
@@ -156,10 +173,10 @@ bool BL_ModifierDeformer::Apply(RAS_IPolyMaterial *mat)
        int nmat = m_pMeshObject->NumMaterials();
        for (int imat=0; imat<nmat; imat++) {
                RAS_MeshMaterial *mmat = m_pMeshObject->GetMeshMaterial(imat);
        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)
+               RAS_MeshSlot **slot = mmat->m_slots[(void*)m_gameobj];
+               if(!slot || !*slot)
                        continue;
                        continue;
-               slot->m_pDerivedMesh = m_dm;
+               (*slot)->m_pDerivedMesh = m_dm;
        }
        return true;
 }
        }
        return true;
 }
index 465c287a88bcc1a4fe59f7f62ffb17b4f65095c2..d5a1caeb91f0b4f55ea7a5acba117b242bb456d1 100644 (file)
@@ -86,6 +86,11 @@ public:
        {
                m_lastModifierUpdate = -1.0;
        };
        {
                m_lastModifierUpdate = -1.0;
        };
+       virtual struct DerivedMesh* GetFinalMesh()
+       {
+               return m_dm;
+       }
+
 
 protected:
        double                                   m_lastModifierUpdate;
 
 protected:
        double                                   m_lastModifierUpdate;
index e04d4dad01500812d6bfb7c5cd21dda2fcef035d..12ef3ff84f159eed03af5e9c2846cd58e0b9b8f6 100644 (file)
@@ -77,6 +77,12 @@ RAS_Deformer *BL_ShapeDeformer::GetReplica()
        return result;
 }
 
        return result;
 }
 
+void BL_ShapeDeformer::ProcessReplica()
+{
+       BL_SkinDeformer::ProcessReplica();
+       m_lastShapeUpdate = -1;
+}
+
 bool BL_ShapeDeformer::LoadShapeDrivers(Object* arma)
 {
        IpoCurve *icu;
 bool BL_ShapeDeformer::LoadShapeDrivers(Object* arma)
 {
        IpoCurve *icu;
@@ -163,7 +169,8 @@ bool BL_ShapeDeformer::Update(void)
        // check for armature deform
        bSkinUpdate = BL_SkinDeformer::Update();
 
        // check for armature deform
        bSkinUpdate = BL_SkinDeformer::Update();
 
-       if (!bSkinUpdate && bShapeUpdate) {
+       // 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 copy the vertex to m_transverts
                // and update the normal (was not done after shape key calculation)
 
                // this means that there is no armature, we still need to copy the vertex to m_transverts
                // and update the normal (was not done after shape key calculation)
 
index 1ec7bfdf74a236de789b394ad7d81c1427eb9a05..949e5e1e3ad56afec78851c3b18609ed1c5a91d5 100644 (file)
@@ -67,6 +67,7 @@ public:
        };
 
        virtual RAS_Deformer *GetReplica();
        };
 
        virtual RAS_Deformer *GetReplica();
+       virtual void ProcessReplica();
        virtual ~BL_ShapeDeformer();
 
        bool Update (void);
        virtual ~BL_ShapeDeformer();
 
        bool Update (void);
index e92c3b29543a6d8e3e099ae541e2ce5b8361d655..a13f78e1b27ef5175bcd71b18221f9bc1495feca 100644 (file)
@@ -127,24 +127,26 @@ bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *mat)
        if (!Update())
                return false;
 
        if (!Update())
                return false;
 
-       // 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_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()]);
+                               }
                        }
                }
        }
                        }
                }
        }
@@ -161,6 +163,13 @@ RAS_Deformer *BL_SkinDeformer::GetReplica()
        return result;
 }
 
        return result;
 }
 
+void BL_SkinDeformer::ProcessReplica()
+{
+       BL_MeshDeformer::ProcessReplica();
+       m_lastArmaUpdate = -1;
+       m_releaseobject = false;
+}
+
 //void where_is_pose (Object *ob);
 //void armature_deform_verts(Object *armOb, Object *target, float (*vertexCos)[3], int numVerts, int deformflag); 
 bool BL_SkinDeformer::Update(void)
 //void where_is_pose (Object *ob);
 //void armature_deform_verts(Object *armOb, Object *target, float (*vertexCos)[3], int numVerts, int deformflag); 
 bool BL_SkinDeformer::Update(void)
index 0a7b60788f90499c1c3a507cb220c4277e740c50..8d3167746beacc10ac5ea93263fadc8bed99c803 100644 (file)
@@ -68,6 +68,8 @@ public:
                                        BL_ArmatureObject* arma = NULL);
 
        virtual RAS_Deformer *GetReplica();
                                        BL_ArmatureObject* arma = NULL);
 
        virtual RAS_Deformer *GetReplica();
+       virtual void ProcessReplica();
+
        virtual ~BL_SkinDeformer();
        bool Update (void);
        bool Apply (class RAS_IPolyMaterial *polymat);
        virtual ~BL_SkinDeformer();
        bool Update (void);
        bool Apply (class RAS_IPolyMaterial *polymat);
index 40c715974f90fc7972dce70f631430bf2588941f..5b912a123fe67de992b80e082d5ec4d7e94d34db 100644 (file)
@@ -47,6 +47,7 @@
 
 class RAS_MeshObject;
 class KX_Scene;
 
 class RAS_MeshObject;
 class KX_Scene;
+struct DerivedMesh;
 
 typedef enum {
        KX_BOUNDBOX,
 
 typedef enum {
        KX_BOUNDBOX,
@@ -183,6 +184,7 @@ bool KX_ReInstanceShapeFromMesh(RAS_MeshObject* meshobj);
 
 void   KX_ConvertBulletObject( class   KX_GameObject* gameobj,
        class   RAS_MeshObject* meshobj,
 
 void   KX_ConvertBulletObject( class   KX_GameObject* gameobj,
        class   RAS_MeshObject* meshobj,
+       struct  DerivedMesh* dm,
        class   KX_Scene* kxscene,
        struct  PHY_ShapeProps* shapeprops,
        struct  PHY_MaterialProps*      smmaterial,
        class   KX_Scene* kxscene,
        struct  PHY_ShapeProps* shapeprops,
        struct  PHY_MaterialProps*      smmaterial,
index 07fdc8ec41b61aa0a352c1715eb29a4d83331557..f18ffb56ccb5da436b1727e4267ddc4f645c9769 100644 (file)
 
 #include "KX_MotionState.h" // bridge between motionstate and scenegraph node
 
 
 #include "KX_MotionState.h" // bridge between motionstate and scenegraph node
 
+extern "C"{
+       #include "BKE_DerivedMesh.h"
+}
+
 #ifdef USE_ODE
 
 #include "KX_OdePhysicsController.h"
 #ifdef USE_ODE
 
 #include "KX_OdePhysicsController.h"
@@ -792,6 +796,7 @@ void        KX_ConvertODEEngineObject(KX_GameObject* gameobj,
 
 void   KX_ConvertBulletObject( class   KX_GameObject* gameobj,
        class   RAS_MeshObject* meshobj,
 
 void   KX_ConvertBulletObject( class   KX_GameObject* gameobj,
        class   RAS_MeshObject* meshobj,
+       struct  DerivedMesh* dm,
        class   KX_Scene* kxscene,
        struct  PHY_ShapeProps* shapeprops,
        struct  PHY_MaterialProps*      smmaterial,
        class   KX_Scene* kxscene,
        struct  PHY_ShapeProps* shapeprops,
        struct  PHY_MaterialProps*      smmaterial,
@@ -884,42 +889,36 @@ void      KX_ConvertBulletObject( class   KX_GameObject* gameobj,
                }
        case KX_BOUNDPOLYTOPE:
                {
                }
        case KX_BOUNDPOLYTOPE:
                {
-                       shapeInfo->SetMesh(meshobj, true,false);
+                       shapeInfo->SetMesh(meshobj, dm,true,false);
                        bm = shapeInfo->CreateBulletShape();
                        break;
                }
        case KX_BOUNDMESH:
                {
                        bm = shapeInfo->CreateBulletShape();
                        break;
                }
        case KX_BOUNDMESH:
                {
-                       
-                       if (!ci.m_mass ||objprop->m_softbody)
-                       {                               
-                               // mesh shapes can be shared, check first if we already have a shape on that mesh
-                               class CcdShapeConstructionInfo *sharedShapeInfo = CcdShapeConstructionInfo::FindMesh(meshobj, false);
-                               if (sharedShapeInfo != NULL) 
-                               {
-                                       delete shapeInfo;
-                                       shapeInfo = sharedShapeInfo;
-                                       shapeInfo->AddRef();
-                               } else
-                               {
-                                       shapeInfo->SetMesh(meshobj, false,false);
-                               }
+                       bool useGimpact = (ci.m_mass && !objprop->m_softbody);
 
 
-                               // Soft bodies require welding. Only avoid remove doubles for non-soft bodies!
-                               if (objprop->m_softbody)
-                               {
-                                       shapeInfo->setVertexWeldingThreshold1(objprop->m_soft_welding); //todo: expose this to the UI
-                               }
-
-                               bm = shapeInfo->CreateBulletShape();
-                               //no moving concave meshes, so don't bother calculating inertia
-                               //bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
+                       // mesh shapes can be shared, check first if we already have a shape on that mesh
+                       class CcdShapeConstructionInfo *sharedShapeInfo = CcdShapeConstructionInfo::FindMesh(meshobj, dm, false,useGimpact);
+                       if (sharedShapeInfo != NULL) 
+                       {
+                               delete shapeInfo;
+                               shapeInfo = sharedShapeInfo;
+                               shapeInfo->AddRef();
                        } else
                        {
                        } else
                        {
-                               shapeInfo->SetMesh(meshobj, false,true);
-                               bm = shapeInfo->CreateBulletShape();
+                               shapeInfo->SetMesh(meshobj, dm, false,useGimpact);
                        }
 
                        }
 
+                       // Soft bodies require welding. Only avoid remove doubles for non-soft bodies!
+                       if (objprop->m_softbody)
+                       {
+                               shapeInfo->setVertexWeldingThreshold1(objprop->m_soft_welding); //todo: expose this to the UI
+                       }
+
+                       bm = shapeInfo->CreateBulletShape();
+                       //should we compute inertia for dynamic shape?
+                       //bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
+
                        break;
                }
        }
                        break;
                }
        }
index ec2cdede68327c5d9a7c22bca10714d54dac530b..02f2aa635af520da71537c16f85ce2cc0180d4ba 100644 (file)
@@ -32,6 +32,7 @@ SET(INC
   ../../../../extern/bullet2/src
   ../../../../extern/glew/include
   ../../../../intern/moto/include
   ../../../../extern/bullet2/src
   ../../../../extern/glew/include
   ../../../../intern/moto/include
+  ../../../../intern/guardedalloc
   ../../../kernel/gen_system
   ../../../../intern/string
   ../../../../intern/SoundSystem 
   ../../../kernel/gen_system
   ../../../../intern/string
   ../../../../intern/SoundSystem 
@@ -41,6 +42,8 @@ SET(INC
   ../../GameLogic
   ../../SceneGraph
   ../../../../source/blender/makesdna
   ../../GameLogic
   ../../SceneGraph
   ../../../../source/blender/makesdna
+  ../../../../source/blender/blenlib
+  ../../../../source/blender/blenkernel
   ${PYTHON_INC}
 )
 
   ${PYTHON_INC}
 )
 
index 961e9096442df287c4358290ab37fa0be345a7d4..01e8aa2560f4edda3ca4272a0e5772b4f7f2bad2 100644 (file)
@@ -35,6 +35,10 @@ subject to the following restrictions:
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 
+extern "C"{
+#include "BKE_cdderivedmesh.h"
+}
+
 class BP_Proxy;
 
 ///todo: fill all the empty CcdPhysicsController methods, hook them up to the btRigidBody class
 class BP_Proxy;
 
 ///todo: fill all the empty CcdPhysicsController methods, hook them up to the btRigidBody class
@@ -1312,9 +1316,9 @@ void      DefaultMotionState::calculateWorldTransformations()
 // Shape constructor
 std::map<RAS_MeshObject*, CcdShapeConstructionInfo*> CcdShapeConstructionInfo::m_meshShapeMap;
 
 // Shape constructor
 std::map<RAS_MeshObject*, CcdShapeConstructionInfo*> CcdShapeConstructionInfo::m_meshShapeMap;
 
-CcdShapeConstructionInfo* CcdShapeConstructionInfo::FindMesh(RAS_MeshObject* mesh, bool polytope)
+CcdShapeConstructionInfo* CcdShapeConstructionInfo::FindMesh(RAS_MeshObject* mesh, struct DerivedMesh* dm, bool polytope, bool gimpact)
 {
 {
-       if (polytope)
+       if (polytope || dm || gimpact)
                // not yet supported
                return NULL;
 
                // not yet supported
                return NULL;
 
@@ -1324,9 +1328,9 @@ CcdShapeConstructionInfo* CcdShapeConstructionInfo::FindMesh(RAS_MeshObject* mes
        return NULL;
 }
 
        return NULL;
 }
 
-bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bool useGimpact)
+bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, DerivedMesh* dm, bool polytope,bool useGimpact)
 {
 {
-       int numpolys;
+       int numpolys, numverts;
 
        m_useGimpact = useGimpact;
 
 
        m_useGimpact = useGimpact;
 
@@ -1335,6 +1339,7 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
        assert(IsUnused());
        m_shapeType = PHY_SHAPE_NONE;
        m_meshObject = NULL;
        assert(IsUnused());
        m_shapeType = PHY_SHAPE_NONE;
        m_meshObject = NULL;
+       bool free_dm = false;
 
        // No mesh object or mesh has no polys
        if (!meshobj || meshobj->HasColliderPolygon()==false) {
 
        // No mesh object or mesh has no polys
        if (!meshobj || meshobj->HasColliderPolygon()==false) {
@@ -1344,12 +1349,21 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
                return false;
        }
 
                return false;
        }
 
-       numpolys = meshobj->NumPolygons();
+       if (!dm) {
+               free_dm = true;
+               dm = CDDM_from_mesh(meshobj->GetMesh(), NULL);
+       }
+
+       MVert *mvert = dm->getVertArray(dm);
+       MFace *mface = dm->getFaceArray(dm);
+       numpolys = dm->getNumFaces(dm);
+       numverts = dm->getNumVerts(dm);
+       int* index = (int*)dm->getFaceDataArray(dm, CD_ORIGINDEX);
 
        m_shapeType = (polytope) ? PHY_SHAPE_POLYTOPE : PHY_SHAPE_MESH;
 
        /* Convert blender geometry into bullet mesh, need these vars for mapping */
 
        m_shapeType = (polytope) ? PHY_SHAPE_POLYTOPE : PHY_SHAPE_MESH;
 
        /* Convert blender geometry into bullet mesh, need these vars for mapping */
-       vector<bool> vert_tag_array(meshobj->GetMesh()->totvert, false);
+       vector<bool> vert_tag_array(numverts, false);
        unsigned int tot_bt_verts= 0;
        unsigned int orig_index;
        int i;
        unsigned int tot_bt_verts= 0;
        unsigned int orig_index;
        int i;
@@ -1359,19 +1373,16 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
                // Tag verts we're using
                for (int p2=0; p2<numpolys; p2++)
                {
                // Tag verts we're using
                for (int p2=0; p2<numpolys; p2++)
                {
-                       RAS_Polygon* poly= meshobj->GetPolygon(p2);
+                       MFace* mf = &mface[p2];
+                       RAS_Polygon* poly = meshobj->GetPolygon(index[p2]);
 
                        // only add polygons that have the collision flag set
                        if (poly->IsCollider())
                        {
 
                        // only add polygons that have the collision flag set
                        if (poly->IsCollider())
                        {
-                               for(i=0; i<poly->VertexCount(); i++) {
-                                       orig_index= poly->GetVertex(i)->getOrigIndex();
-                                       if (vert_tag_array[orig_index]==false)
-                                       {
-                                               vert_tag_array[orig_index]= true;
-                                               tot_bt_verts++;
-                                       }
-                               }
+                               if (vert_tag_array[mf->v1]==false) {vert_tag_array[mf->v1]= true;tot_bt_verts++;}
+                               if (vert_tag_array[mf->v2]==false) {vert_tag_array[mf->v2]= true;tot_bt_verts++;}
+                               if (vert_tag_array[mf->v3]==false) {vert_tag_array[mf->v3]= true;tot_bt_verts++;}
+                               if (mf->v4 && vert_tag_array[mf->v4]==false) {vert_tag_array[mf->v4]= true;tot_bt_verts++;}
                        }
                }
 
                        }
                }
 
@@ -1381,51 +1392,69 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
 
                for (int p2=0; p2<numpolys; p2++)
                {
 
                for (int p2=0; p2<numpolys; p2++)
                {
-                       RAS_Polygon* poly= meshobj->GetPolygon(p2);
+                       MFace* mf = &mface[p2];
+                       RAS_Polygon* poly= meshobj->GetPolygon(index[p2]);
 
                        // only add polygons that have the collisionflag set
                        if (poly->IsCollider())
                        {
 
                        // only add polygons that have the collisionflag set
                        if (poly->IsCollider())
                        {
-                               for(i=0; i<poly->VertexCount(); i++) {
-                                       RAS_TexVert *v= poly->GetVertex(i);
-                                       orig_index= v->getOrigIndex();
-
-                                       if (vert_tag_array[orig_index]==true)
-                                       {
-                                               const float* vtx = v->getXYZ();
-                                               vert_tag_array[orig_index]= false;
-
-                                               *bt++ = vtx[0];
-                                               *bt++ = vtx[1];
-                                               *bt++ = vtx[2];
-                                       }
+                               if (vert_tag_array[mf->v1]==true)
+                               {
+                                       const float* vtx = mvert[mf->v1].co;
+                                       vert_tag_array[mf->v1]= false;
+                                       *bt++ = vtx[0];
+                                       *bt++ = vtx[1];
+                                       *bt++ = vtx[2];
+                               }
+                               if (vert_tag_array[mf->v2]==true)
+                               {
+                                       const float* vtx = mvert[mf->v2].co;
+                                       vert_tag_array[mf->v2]= false;
+                                       *bt++ = vtx[0];
+                                       *bt++ = vtx[1];
+                                       *bt++ = vtx[2];
+                               }
+                               if (vert_tag_array[mf->v3]==true)
+                               {
+                                       const float* vtx = mvert[mf->v3].co;
+                                       vert_tag_array[mf->v3]= false;
+                                       *bt++ = vtx[0];
+                                       *bt++ = vtx[1];
+                                       *bt++ = vtx[2];
+                               }
+                               if (mf->v4 && vert_tag_array[mf->v4]==true)
+                               {
+                                       const float* vtx = mvert[mf->v4].co;
+                                       vert_tag_array[mf->v4]= false;
+                                       *bt++ = vtx[0];
+                                       *bt++ = vtx[1];
+                                       *bt++ = vtx[2];
                                }
                        }
                }
        }
        else {
                unsigned int tot_bt_tris= 0;
                                }
                        }
                }
        }
        else {
                unsigned int tot_bt_tris= 0;
-               vector<int> vert_remap_array(meshobj->GetMesh()->totvert, 0);
+               vector<int> vert_remap_array(numverts, 0);
                
                // Tag verts we're using
                for (int p2=0; p2<numpolys; p2++)
                {
                
                // Tag verts we're using
                for (int p2=0; p2<numpolys; p2++)
                {
-                       RAS_Polygon* poly= meshobj->GetPolygon(p2);
+                       MFace* mf = &mface[p2];
+                       RAS_Polygon* poly= meshobj->GetPolygon(index[p2]);
 
                        // only add polygons that have the collision flag set
                        if (poly->IsCollider())
                        {
 
                        // only add polygons that have the collision flag set
                        if (poly->IsCollider())
                        {
-                               for(i=0; i<poly->VertexCount(); i++) {
-                                       orig_index= poly->GetVertex(i)->getOrigIndex();
-                                       if (vert_tag_array[orig_index]==false)
-                                       {
-                                               vert_tag_array[orig_index]= true;
-                                               vert_remap_array[orig_index]= tot_bt_verts;
-                                               tot_bt_verts++;
-                                       }
-                               }
-
-                               tot_bt_tris += (i==4 ? 2:1); /* a quad or a tri */
+                               if (vert_tag_array[mf->v1]==false)
+                                       {vert_tag_array[mf->v1]= true;vert_remap_array[mf->v1]= tot_bt_verts;tot_bt_verts++;}
+                               if (vert_tag_array[mf->v2]==false)
+                                       {vert_tag_array[mf->v2]= true;vert_remap_array[mf->v2]= tot_bt_verts;tot_bt_verts++;}
+                               if (vert_tag_array[mf->v3]==false)
+                                       {vert_tag_array[mf->v3]= true;vert_remap_array[mf->v3]= tot_bt_verts;tot_bt_verts++;}
+                               if (mf->v4 && vert_tag_array[mf->v4]==false)
+                                       {vert_tag_array[mf->v4]= true;vert_remap_array[mf->v4]= tot_bt_verts;tot_bt_verts++;}
+                               tot_bt_tris += (mf->v4 ? 2:1); /* a quad or a tri */
                        }
                }
 
                        }
                }
 
@@ -1437,76 +1466,67 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
                int *poly_index_pt= &m_polygonIndexArray[0];
                int *tri_pt= &m_triFaceArray[0];
 
                int *poly_index_pt= &m_polygonIndexArray[0];
                int *tri_pt= &m_triFaceArray[0];
 
-
                for (int p2=0; p2<numpolys; p2++)
                {
                for (int p2=0; p2<numpolys; p2++)
                {
-                       RAS_Polygon* poly= meshobj->GetPolygon(p2);
+                       MFace* mf = &mface[p2];
+                       RAS_Polygon* poly= meshobj->GetPolygon(index[p2]);
 
                        // only add polygons that have the collisionflag set
                        if (poly->IsCollider())
                        {
 
                        // only add polygons that have the collisionflag set
                        if (poly->IsCollider())
                        {
-                               RAS_TexVert *v1= poly->GetVertex(0);
-                               RAS_TexVert *v2= poly->GetVertex(1);
-                               RAS_TexVert *v3= poly->GetVertex(2);
-                               int i1= v1->getOrigIndex();
-                               int i2= v2->getOrigIndex();
-                               int i3= v3->getOrigIndex();
-                               const float* vtx;
+                               MVert *v1= &mvert[mf->v1];
+                               MVert *v2= &mvert[mf->v2];
+                               MVert *v3= &mvert[mf->v3];
 
                                // the face indicies
 
                                // the face indicies
-                               tri_pt[0]= vert_remap_array[i1];
-                               tri_pt[1]= vert_remap_array[i2];
-                               tri_pt[2]= vert_remap_array[i3];
+                               tri_pt[0]= vert_remap_array[mf->v1];
+                               tri_pt[1]= vert_remap_array[mf->v2];
+                               tri_pt[2]= vert_remap_array[mf->v3];
                                tri_pt= tri_pt+3;
 
                                // m_polygonIndexArray
                                tri_pt= tri_pt+3;
 
                                // m_polygonIndexArray
-                               *poly_index_pt= p2;
+                               *poly_index_pt= index[p2];
                                poly_index_pt++;
 
                                // the vertex location
                                poly_index_pt++;
 
                                // the vertex location
-                               if (vert_tag_array[i1]==true) { /* *** v1 *** */
-                                       vert_tag_array[i1]= false;
-                                       vtx = v1->getXYZ();
-                                       *bt++ = vtx[0];
-                                       *bt++ = vtx[1];
-                                       *bt++ = vtx[2];
+                               if (vert_tag_array[mf->v1]==true) { /* *** v1 *** */
+                                       vert_tag_array[mf->v1]= false;
+                                       *bt++ = v1->co[0];
+                                       *bt++ = v1->co[1];
+                                       *bt++ = v1->co[2];
                                }
                                }
-                               if (vert_tag_array[i2]==true) { /* *** v2 *** */
-                                       vert_tag_array[i2]= false;
-                                       vtx = v2->getXYZ();
-                                       *bt++ = vtx[0];
-                                       *bt++ = vtx[1];
-                                       *bt++ = vtx[2];
+                               if (vert_tag_array[mf->v2]==true) { /* *** v2 *** */
+                                       vert_tag_array[mf->v2]= false;
+                                       *bt++ = v2->co[0];
+                                       *bt++ = v2->co[1];
+                                       *bt++ = v2->co[2];
                                }
                                }
-                               if (vert_tag_array[i3]==true) { /* *** v3 *** */
-                                       vert_tag_array[i3]= false;
-                                       vtx = v3->getXYZ();
-                                       *bt++ = vtx[0]; 
-                                       *bt++ = vtx[1];
-                                       *bt++ = vtx[2];
+                               if (vert_tag_array[mf->v3]==true) { /* *** v3 *** */
+                                       vert_tag_array[mf->v3]= false;
+                                       *bt++ = v3->co[0];      
+                                       *bt++ = v3->co[1];
+                                       *bt++ = v3->co[2];
                                }
 
                                }
 
-                               if (poly->VertexCount()==4)
+                               if (mf->v4)
                                {
                                {
-                                       RAS_TexVert *v4= poly->GetVertex(3);
-                                       int i4= v4->getOrigIndex();
+                                       MVert *v4= &mvert[mf->v4];
 
 
-                                       tri_pt[0]= vert_remap_array[i1];
-                                       tri_pt[1]= vert_remap_array[i3];
-                                       tri_pt[2]= vert_remap_array[i4];
+                                       tri_pt[0]= vert_remap_array[mf->v1];
+                                       tri_pt[1]= vert_remap_array[mf->v3];
+                                       tri_pt[2]= vert_remap_array[mf->v4];
                                        tri_pt= tri_pt+3;
 
                                        // m_polygonIndexArray
                                        tri_pt= tri_pt+3;
 
                                        // m_polygonIndexArray
-                                       *poly_index_pt= p2;
+                                       *poly_index_pt= index[p2];
                                        poly_index_pt++;
 
                                        // the vertex location
                                        poly_index_pt++;
 
                                        // the vertex location
-                                       if (vert_tag_array[i4]==true) { /* *** v4 *** */
-                                               vert_tag_array[i4]= false;
-                                               vtx = v4->getXYZ();
-                                               *bt++ = vtx[0];
-                                               *bt++ = vtx[1]; 
-                                               *bt++ = vtx[2];
+                                       if (vert_tag_array[mf->v4]==true) { /* *** v4 *** */
+                                               vert_tag_array[mf->v4]= false;
+                                               *bt++ = v4->co[0];
+                                               *bt++ = v4->co[1];      
+                                               *bt++ = v4->co[2];
                                        }
                                }
                        }
                                        }
                                }
                        }
@@ -1538,7 +1558,13 @@ bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject* meshobj, bool polytope,bo
 #endif
        
        m_meshObject = meshobj;
 #endif
        
        m_meshObject = meshobj;
-       if (!polytope)
+       if (free_dm) {
+               dm->release(dm);
+               dm = NULL;
+       }
+
+       // sharing only on static mesh at present, if you change that, you must also change in FindMesh
+       if (!polytope && !dm && !useGimpact)
        {
                // triangle shape can be shared, store the mesh object in the map
                m_meshShapeMap.insert(std::pair<RAS_MeshObject*,CcdShapeConstructionInfo*>(meshobj,this));
        {
                // triangle shape can be shared, store the mesh object in the map
                m_meshShapeMap.insert(std::pair<RAS_MeshObject*,CcdShapeConstructionInfo*>(meshobj,this));
index 4ab478b210646910846fe947a65e7bfbba90a238..315e2bdf429b1017ab9aefc3bd05caf9403eb007 100644 (file)
@@ -36,6 +36,7 @@ extern bool gDisableDeactivation;
 class CcdPhysicsEnvironment;
 class btMotionState;
 class RAS_MeshObject;
 class CcdPhysicsEnvironment;
 class btMotionState;
 class RAS_MeshObject;
+struct DerivedMesh;
 class btCollisionShape;
 
 
 class btCollisionShape;
 
 
@@ -59,7 +60,7 @@ class CcdShapeConstructionInfo
 public:
        
 
 public:
        
 
-       static CcdShapeConstructionInfo* FindMesh(RAS_MeshObject* mesh, bool polytope);
+       static CcdShapeConstructionInfo* FindMesh(class RAS_MeshObject* mesh, struct DerivedMesh* dm, bool polytope, bool gimpact);
 
        CcdShapeConstructionInfo() :
                m_shapeType(PHY_SHAPE_NONE),
 
        CcdShapeConstructionInfo() :
                m_shapeType(PHY_SHAPE_NONE),
@@ -139,7 +140,7 @@ public:
                return true;
        }
 
                return true;
        }
 
-       bool SetMesh(RAS_MeshObject* mesh, bool polytope,bool useGimpact);
+       bool SetMesh(class RAS_MeshObject* mesh, struct DerivedMesh* dm, bool polytope,bool useGimpact);
        RAS_MeshObject* GetMesh(void)
        {
                return m_meshObject;
        RAS_MeshObject* GetMesh(void)
        {
                return m_meshObject;
index 48e537bb6a35681c3cf3402ac919c409d71ae340..19b17de275aa0e2f40e54f6d807682c931c1c383 100644 (file)
@@ -51,4 +51,6 @@ CPPFLAGS += -I../../Expressions
 CPPFLAGS += -I../../GameLogic
 CPPFLAGS += -I../../SceneGraph
 CPPFLAGS += -I../../../../source/blender/makesdna
 CPPFLAGS += -I../../GameLogic
 CPPFLAGS += -I../../SceneGraph
 CPPFLAGS += -I../../../../source/blender/makesdna
+CPPFLAGS += -I../../../../source/blender/blenkernel
+CPPFLAGS += -I../../../../source/blender/blenlib
 
 
index 115ab8bf7303dc26a5a9b19f6f498fbe0f41a3e7..c517d8b5d9d7eef3c705703d5b29e9a29268afce 100644 (file)
@@ -14,7 +14,10 @@ incs += ' #source/gameengine/Expressions'
 incs += ' #source/gameengine/GameLogic'
 incs += ' #source/gameengine/SceneGraph'
 incs += ' #source/blender/makesdna'
 incs += ' #source/gameengine/GameLogic'
 incs += ' #source/gameengine/SceneGraph'
 incs += ' #source/blender/makesdna'
+incs += ' #source/blender/blenkernel'
+incs += ' #source/blender/blenlib'
 incs += ' #intern/SoundSystem'
 incs += ' #intern/SoundSystem'
+incs += ' #intern/guardedalloc'
 
 incs += ' ' + env['BF_BULLET_INC']
 incs += ' ' + env['BF_PYTHON_INC']
 
 incs += ' ' + env['BF_BULLET_INC']
 incs += ' ' + env['BF_PYTHON_INC']
index bb8e37504856864fdd800911f0377619a06110a9..9dc656ba56af33b530e4ecbd07c32c142a40cff8 100644 (file)
 #pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
 #endif //WIN32
 
 #pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
 #endif //WIN32
 
+#include <stdlib.h>
 #include "GEN_Map.h"
 
 #include "GEN_Map.h"
 
+struct DerivedMesh;
+
 class RAS_Deformer
 {
 public:
 class RAS_Deformer
 {
 public:
-       RAS_Deformer() : m_pMesh(0), m_bDynamic(false) {};
+       RAS_Deformer() : m_pMesh(NULL), m_bDynamic(false) {};
        virtual ~RAS_Deformer(){};
        virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map)=0;
        virtual bool Apply(class RAS_IPolyMaterial *polymat)=0;
        virtual ~RAS_Deformer(){};
        virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map)=0;
        virtual bool Apply(class RAS_IPolyMaterial *polymat)=0;
@@ -60,6 +63,11 @@ public:
        {
                return m_bDynamic;
        }
        {
                return m_bDynamic;
        }
+       virtual struct DerivedMesh* GetFinalMesh()
+       {
+               return NULL;
+       }
+
 protected:
        class RAS_MeshObject    *m_pMesh;
        bool  m_bDynamic;       
 protected:
        class RAS_MeshObject    *m_pMesh;
        bool  m_bDynamic;       
index f5324c6fbc93358b9f835f95bfffded679037f56..014169f8838f0d05938800edab2f51e4da9be414 100644 (file)
@@ -118,16 +118,24 @@ RAS_ListRasterizer::~RAS_ListRasterizer()
 
 void RAS_ListRasterizer::RemoveListSlot(RAS_ListSlot* list)
 {
 
 void RAS_ListRasterizer::RemoveListSlot(RAS_ListSlot* list)
 {
-       if (list->m_flag & LIST_STANDALONE)
-               return ;
-       
-       RAS_ArrayLists::iterator it = mArrayLists.begin();
-       while(it != mArrayLists.end()) {
-               if (it->second == list) {
-                       mArrayLists.erase(it);
-                       break;
+       if (list->m_flag & LIST_DERIVEDMESH) {
+               RAS_DerivedMeshLists::iterator it = mDerivedMeshLists.begin();
+               while(it != mDerivedMeshLists.end()) {
+                       if (it->second == list) {
+                               mDerivedMeshLists.erase(it);
+                               break;
+                       }
+                       it++;
+               }
+       } else {
+               RAS_ArrayLists::iterator it = mArrayLists.begin();
+               while(it != mArrayLists.end()) {
+                       if (it->second == list) {
+                               mArrayLists.erase(it);
+                               break;
+                       }
+                       it++;
                }
                }
-               it++;
        }
 }
 
        }
 }
 
@@ -143,9 +151,15 @@ RAS_ListSlot* RAS_ListRasterizer::FindOrAdd(RAS_MeshSlot& ms)
        if(!localSlot) {
                if (ms.m_pDerivedMesh) {
                        // that means that we draw based on derived mesh, a display list is possible
        if(!localSlot) {
                if (ms.m_pDerivedMesh) {
                        // that means that we draw based on derived mesh, a display list is possible
-                       // but it's unique to this mesh slot
-                       localSlot = new RAS_ListSlot(this);
-                       localSlot->m_flag |= LIST_STANDALONE;
+                       // Note that we come here only for static derived mesh
+                       RAS_DerivedMeshLists::iterator it = mDerivedMeshLists.find(ms.m_pDerivedMesh);
+                       if(it == mDerivedMeshLists.end()) {
+                               localSlot = new RAS_ListSlot(this);
+                               localSlot->m_flag |= LIST_DERIVEDMESH;
+                               mDerivedMeshLists.insert(std::pair<DerivedMesh*, RAS_ListSlot*>(ms.m_pDerivedMesh, localSlot));
+                       } else {
+                               localSlot = static_cast<RAS_ListSlot*>(it->second->AddRef());
+                       }
                } else {
                        RAS_ArrayLists::iterator it = mArrayLists.find(ms.m_displayArrays);
                        if(it == mArrayLists.end()) {
                } else {
                        RAS_ArrayLists::iterator it = mArrayLists.find(ms.m_displayArrays);
                        if(it == mArrayLists.end()) {
@@ -162,12 +176,12 @@ RAS_ListSlot* RAS_ListRasterizer::FindOrAdd(RAS_MeshSlot& ms)
 
 void RAS_ListRasterizer::ReleaseAlloc()
 {
 
 void RAS_ListRasterizer::ReleaseAlloc()
 {
-       RAS_ArrayLists::iterator it = mArrayLists.begin();
-       while(it != mArrayLists.end()) {
+       for(RAS_ArrayLists::iterator it = mArrayLists.begin();it != mArrayLists.end();++it)
                delete it->second;
                delete it->second;
-               it++;
-       }
        mArrayLists.clear();
        mArrayLists.clear();
+       for (RAS_DerivedMeshLists::iterator it = mDerivedMeshLists.begin();it != mDerivedMeshLists.end();++it)
+               delete it->second;
+       mDerivedMeshLists.clear();
 }
 
 void RAS_ListRasterizer::IndexPrimitives(RAS_MeshSlot& ms)
 }
 
 void RAS_ListRasterizer::IndexPrimitives(RAS_MeshSlot& ms)
index 912f28af6aa4fc3718d17d7b71d92b9ad4a7998f..fe358808e4a39af7a48602452286d7be3ef048b2 100644 (file)
@@ -34,16 +34,20 @@ enum RAS_ListSlotFlags      {
        LIST_BEGIN              =16,
        LIST_END                =32,
        LIST_REGEN              =64,
        LIST_BEGIN              =16,
        LIST_END                =32,
        LIST_REGEN              =64,
-       LIST_STANDALONE =128,
+       LIST_DERIVEDMESH=128,
 };
 
 };
 
+struct DerivedMesh;
+
 typedef std::map<RAS_DisplayArrayList, RAS_ListSlot*> RAS_ArrayLists;
 typedef std::map<RAS_DisplayArrayList, RAS_ListSlot*> RAS_ArrayLists;
+typedef std::map<DerivedMesh*, RAS_ListSlot*>            RAS_DerivedMeshLists;
 
 class RAS_ListRasterizer : public RAS_VAOpenGLRasterizer
 {
        bool mUseVertexArrays;
        bool mATI;
        RAS_ArrayLists mArrayLists;
 
 class RAS_ListRasterizer : public RAS_VAOpenGLRasterizer
 {
        bool mUseVertexArrays;
        bool mATI;
        RAS_ArrayLists mArrayLists;
+       RAS_DerivedMeshLists mDerivedMeshLists;
 
        RAS_ListSlot* FindOrAdd(class RAS_MeshSlot& ms);
        void ReleaseAlloc();
 
        RAS_ListSlot* FindOrAdd(class RAS_MeshSlot& ms);
        void ReleaseAlloc();