Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Converter/KX_BlenderSceneConverter.cpp
| Show First 20 Lines • Show All 318 Lines • ▼ Show 20 Lines | |||||
| // Note that there was some provision for sharing entities (meshes...) between | // Note that there was some provision for sharing entities (meshes...) between | ||||
| // scenes but that is now disabled so all scene will have their own copy | // scenes but that is now disabled so all scene will have their own copy | ||||
| // and we can delete them here. If the sharing is reactivated, change this code too.. | // and we can delete them here. If the sharing is reactivated, change this code too.. | ||||
| // (see KX_BlenderSceneConverter::ConvertScene) | // (see KX_BlenderSceneConverter::ConvertScene) | ||||
| void KX_BlenderSceneConverter::RemoveScene(KX_Scene *scene) | void KX_BlenderSceneConverter::RemoveScene(KX_Scene *scene) | ||||
| { | { | ||||
| int i, size; | int i, size; | ||||
| // delete the scene first as it will stop the use of entities | // delete the scene first as it will stop the use of entities | ||||
| delete scene; | scene->Release(); | ||||
| // delete the entities of this scene | // delete the entities of this scene | ||||
| vector<pair<KX_Scene*,KX_WorldInfo*> >::iterator worldit; | vector<pair<KX_Scene*,KX_WorldInfo*> >::iterator worldit; | ||||
| size = m_worldinfos.size(); | size = m_worldinfos.size(); | ||||
| for (i=0, worldit=m_worldinfos.begin(); i<size; ) { | for (i=0, worldit=m_worldinfos.begin(); i<size; ) { | ||||
| if ((*worldit).first == scene) { | if ((*worldit).first == scene) { | ||||
| delete (*worldit).second; | delete (*worldit).second; | ||||
| *worldit = m_worldinfos.back(); | *worldit = m_worldinfos.back(); | ||||
| m_worldinfos.pop_back(); | m_worldinfos.pop_back(); | ||||
| ▲ Show 20 Lines • Show All 242 Lines • ▼ Show 20 Lines | void KX_BlenderSceneConverter::RegisterWorldInfo(KX_WorldInfo *worldinfo) | ||||
| m_worldinfos.push_back(pair<KX_Scene*,KX_WorldInfo*>(m_currentScene,worldinfo)); | m_worldinfos.push_back(pair<KX_Scene*,KX_WorldInfo*>(m_currentScene,worldinfo)); | ||||
| } | } | ||||
| void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo) | void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo) | ||||
| { | { | ||||
| //TODO this entire function is deprecated, written for 2.4x | //TODO this entire function is deprecated, written for 2.4x | ||||
| //the functionality should be rewritten, currently it does nothing | //the functionality should be rewritten, currently it does nothing | ||||
| KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes(); | CListValue* scenes = m_ketsjiEngine->CurrentScenes(); | ||||
| int numScenes = scenes->size(); | for (unsigned int sce_idx = 0; sce_idx < scenes->GetCount(); ++sce_idx) | ||||
| int i; | |||||
| for (i=0;i<numScenes;i++) | |||||
| { | { | ||||
| KX_Scene* scene = scenes->at(i); | KX_Scene* scene = (KX_Scene*)scenes->GetValue(sce_idx); | ||||
| //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment(); | //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment(); | ||||
| CListValue* parentList = scene->GetRootParentList(); | CListValue* parentList = scene->GetRootParentList(); | ||||
| int numObjects = parentList->GetCount(); | int numObjects = parentList->GetCount(); | ||||
| int g; | int g; | ||||
| for (g=0;g<numObjects;g++) | for (g=0;g<numObjects;g++) | ||||
| { | { | ||||
| KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g); | KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g); | ||||
| if (gameObj->IsRecordAnimation()) { | if (gameObj->IsRecordAnimation()) { | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | void KX_BlenderSceneConverter::resetNoneDynamicObjectToIpo() | ||||
| //TODO the functionality should be rewritten | //TODO the functionality should be rewritten | ||||
| } | } | ||||
| ///this generates ipo curves for position, rotation, allowing to use game physics in animation | ///this generates ipo curves for position, rotation, allowing to use game physics in animation | ||||
| void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) | void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) | ||||
| { | { | ||||
| KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes(); | CListValue* scenes = m_ketsjiEngine->CurrentScenes(); | ||||
| int numScenes = scenes->size(); | for (unsigned int sce_idx = 0; sce_idx < scenes->GetCount(); ++sce_idx) | ||||
| int i; | |||||
| for (i=0;i<numScenes;i++) | |||||
| { | { | ||||
| KX_Scene* scene = scenes->at(i); | KX_Scene* scene = (KX_Scene*)scenes->GetValue(sce_idx); | ||||
| //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment(); | //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment(); | ||||
| CListValue* parentList = scene->GetObjectList(); | CListValue* parentList = scene->GetObjectList(); | ||||
| int numObjects = parentList->GetCount(); | int numObjects = parentList->GetCount(); | ||||
| int g; | int g; | ||||
| for (g=0;g<numObjects;g++) | for (g=0;g<numObjects;g++) | ||||
| { | { | ||||
| KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g); | KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g); | ||||
| Object* blenderObject = gameObj->GetBlenderObject(); | Object* blenderObject = gameObj->GetBlenderObject(); | ||||
| ▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | #endif | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo() | void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo() | ||||
| { | { | ||||
| KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes(); | CListValue* scenes = m_ketsjiEngine->CurrentScenes(); | ||||
| int numScenes = scenes->size(); | for (unsigned int sce_idx = 0; sce_idx < scenes->GetCount(); ++sce_idx) | ||||
| int i; | |||||
| for (i=0;i<numScenes;i++) | |||||
| { | { | ||||
| KX_Scene* scene = scenes->at(i); | KX_Scene* scene = (KX_Scene*)scenes->GetValue(sce_idx); | ||||
| //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment(); | //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment(); | ||||
| CListValue* parentList = scene->GetRootParentList(); | CListValue* parentList = scene->GetRootParentList(); | ||||
| int numObjects = parentList->GetCount(); | int numObjects = parentList->GetCount(); | ||||
| int g; | int g; | ||||
| for (g=0;g<numObjects;g++) | for (g=0;g<numObjects;g++) | ||||
| { | { | ||||
| KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g); | KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g); | ||||
| if (gameObj->IsRecordAnimation()) { | if (gameObj->IsRecordAnimation()) { | ||||
| ▲ Show 20 Lines • Show All 315 Lines • ▼ Show 20 Lines | bool KX_BlenderSceneConverter::FreeBlendFile(struct Main *maggie) | ||||
| if (maggie_index == -1) | if (maggie_index == -1) | ||||
| return false; | return false; | ||||
| m_DynamicMaggie.erase(m_DynamicMaggie.begin() + maggie_index); | m_DynamicMaggie.erase(m_DynamicMaggie.begin() + maggie_index); | ||||
| BKE_main_id_tag_all(maggie, true); | BKE_main_id_tag_all(maggie, true); | ||||
| /* free all tagged objects */ | /* free all tagged objects */ | ||||
| KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes(); | CListValue* scenes = m_ketsjiEngine->CurrentScenes(); | ||||
| int numScenes = scenes->size(); | int numScenes = scenes->GetCount(); | ||||
| for (int scene_idx=0;scene_idx<numScenes;scene_idx++) | for (unsigned int sce_idx = 0; sce_idx < numScenes; ++sce_idx) | ||||
| { | { | ||||
| KX_Scene* scene = scenes->at(scene_idx); | KX_Scene* scene = (KX_Scene*)scenes->GetValue(sce_idx); | ||||
| if (IS_TAGGED(scene->GetBlenderScene())) { | if (IS_TAGGED(scene->GetBlenderScene())) { | ||||
| m_ketsjiEngine->RemoveScene(scene->GetName()); | m_ketsjiEngine->RemoveScene(scene->GetName()); | ||||
| m_mat_cache.erase(scene); | m_mat_cache.erase(scene); | ||||
| m_polymat_cache.erase(scene); | m_polymat_cache.erase(scene); | ||||
| scene_idx--; | sce_idx--; | ||||
| numScenes--; | numScenes--; | ||||
| } | } | ||||
| else { | else { | ||||
| /* in case the mesh might be refered to later */ | /* in case the mesh might be refered to later */ | ||||
| { | { | ||||
| CTR_Map<STR_HashedString,void*> &mapStringToMeshes = scene->GetLogicManager()->GetMeshMap(); | CTR_Map<STR_HashedString,void*> &mapStringToMeshes = scene->GetLogicManager()->GetMeshMap(); | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | for (i=0, worldit=m_worldinfos.begin(); i<size; ) { | ||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Worlds don't reference original blender data so we need to make a set from them */ | /* Worlds don't reference original blender data so we need to make a set from them */ | ||||
| typedef std::set<KX_WorldInfo*> KX_WorldInfoSet; | typedef std::set<KX_WorldInfo*> KX_WorldInfoSet; | ||||
| KX_WorldInfoSet worldset; | KX_WorldInfoSet worldset; | ||||
| for (int scene_idx=0;scene_idx<numScenes;scene_idx++) | for (unsigned int sce_idx = 0; sce_idx < numScenes; ++sce_idx) | ||||
| { | { | ||||
| KX_Scene* scene = scenes->at(scene_idx); | KX_Scene* scene = (KX_Scene*)scenes->GetValue(sce_idx); | ||||
| if (scene->GetWorldInfo()) | if (scene->GetWorldInfo()) | ||||
| worldset.insert( scene->GetWorldInfo() ); | worldset.insert( scene->GetWorldInfo() ); | ||||
| } | } | ||||
| vector<pair<KX_Scene*,KX_WorldInfo*> >::iterator worldit; | vector<pair<KX_Scene*,KX_WorldInfo*> >::iterator worldit; | ||||
| size = m_worldinfos.size(); | size = m_worldinfos.size(); | ||||
| for (i=0, worldit=m_worldinfos.begin(); i<size; ) { | for (i=0, worldit=m_worldinfos.begin(); i<size; ) { | ||||
| if ((*worldit).second && (worldset.count((*worldit).second)) == 0) { | if ((*worldit).second && (worldset.count((*worldit).second)) == 0) { | ||||
| ▲ Show 20 Lines • Show All 276 Lines • Show Last 20 Lines | |||||