|
Blender
V2.59
|
00001 /* 00002 * $Id: KX_BlenderSceneConverter.h 36523 2011-05-06 20:18:42Z blendix $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00034 #ifndef __KX_BLENDERSCENECONVERTER_H 00035 #define __KX_BLENDERSCENECONVERTER_H 00036 00037 #include "KX_HashedPtr.h" 00038 #include "CTR_Map.h" 00039 #include <stdio.h> 00040 00041 #include "KX_ISceneConverter.h" 00042 #include "KX_IpoConvert.h" 00043 00044 class KX_WorldInfo; 00045 class SCA_IActuator; 00046 class SCA_IController; 00047 class RAS_MeshObject; 00048 class RAS_IPolyMaterial; 00049 class BL_InterpolatorList; 00050 class BL_Material; 00051 struct Main; 00052 struct Scene; 00053 00054 class KX_BlenderSceneConverter : public KX_ISceneConverter 00055 { 00056 // Use vector of pairs to allow removal of entities between scene switch 00057 vector<pair<KX_Scene*,KX_WorldInfo*> > m_worldinfos; 00058 vector<pair<KX_Scene*,RAS_IPolyMaterial*> > m_polymaterials; 00059 vector<pair<KX_Scene*,RAS_MeshObject*> > m_meshobjects; 00060 vector<pair<KX_Scene*,BL_Material *> > m_materials; 00061 // Should also have a list of collision shapes. 00062 // For the time being this is held in KX_Scene::m_shapes 00063 00064 CTR_Map<CHashedPtr,KX_GameObject*> m_map_blender_to_gameobject; /* cleared after conversion */ 00065 CTR_Map<CHashedPtr,RAS_MeshObject*> m_map_mesh_to_gamemesh; /* cleared after conversion */ 00066 CTR_Map<CHashedPtr,SCA_IActuator*> m_map_blender_to_gameactuator; /* cleared after conversion */ 00067 CTR_Map<CHashedPtr,SCA_IController*>m_map_blender_to_gamecontroller; /* cleared after conversion */ 00068 00069 CTR_Map<CHashedPtr,BL_InterpolatorList*> m_map_blender_to_gameAdtList; 00070 00071 Main* m_maggie; 00072 vector<struct Main*> m_DynamicMaggie; 00073 00074 STR_String m_newfilename; 00075 class KX_KetsjiEngine* m_ketsjiEngine; 00076 class KX_Scene* m_currentScene; // Scene being converted 00077 bool m_alwaysUseExpandFraming; 00078 bool m_usemat; 00079 bool m_useglslmat; 00080 00081 public: 00082 KX_BlenderSceneConverter( 00083 Main* maggie, 00084 class KX_KetsjiEngine* engine 00085 ); 00086 00087 virtual ~KX_BlenderSceneConverter(); 00088 00089 /* Scenename: name of the scene to be converted. 00090 * destinationscene: pass an empty scene, everything goes into this 00091 * dictobj: python dictionary (for pythoncontrollers) 00092 */ 00093 virtual void ConvertScene( 00094 class KX_Scene* destinationscene, 00095 class RAS_IRenderTools* rendertools, 00096 class RAS_ICanvas* canvas 00097 ); 00098 virtual void RemoveScene(class KX_Scene *scene); 00099 00100 void SetNewFileName(const STR_String& filename); 00101 bool TryAndLoadNewFile(); 00102 00103 void SetAlwaysUseExpandFraming(bool to_what); 00104 00105 void RegisterGameObject(KX_GameObject *gameobject, struct Object *for_blenderobject); 00106 void UnregisterGameObject(KX_GameObject *gameobject); 00107 KX_GameObject *FindGameObject(struct Object *for_blenderobject); 00108 00109 void RegisterGameMesh(RAS_MeshObject *gamemesh, struct Mesh *for_blendermesh); 00110 RAS_MeshObject *FindGameMesh(struct Mesh *for_blendermesh/*, unsigned int onlayer*/); 00111 00112 void RegisterPolyMaterial(RAS_IPolyMaterial *polymat); 00113 00114 void RegisterBlenderMaterial(BL_Material *mat); 00115 00116 void RegisterInterpolatorList(BL_InterpolatorList *adtList, struct AnimData *for_adt); 00117 BL_InterpolatorList *FindInterpolatorList(struct AnimData *for_adt); 00118 00119 void RegisterGameActuator(SCA_IActuator *act, struct bActuator *for_actuator); 00120 SCA_IActuator *FindGameActuator(struct bActuator *for_actuator); 00121 00122 void RegisterGameController(SCA_IController *cont, struct bController *for_controller); 00123 SCA_IController *FindGameController(struct bController *for_controller); 00124 00125 void RegisterWorldInfo(KX_WorldInfo *worldinfo); 00126 00127 virtual void ResetPhysicsObjectsAnimationIpo(bool clearIpo); 00128 00130 virtual void resetNoneDynamicObjectToIpo(); 00131 00133 virtual void WritePhysicsObjectToAnimationIpo(int frameNumber); 00134 virtual void TestHandlesPhysicsObjectToAnimationIpo(); 00135 00136 // use blender materials 00137 virtual void SetMaterials(bool val); 00138 virtual bool GetMaterials(); 00139 00140 // use blender glsl materials 00141 virtual void SetGLSLMaterials(bool val); 00142 virtual bool GetGLSLMaterials(); 00143 00144 struct Scene* GetBlenderSceneForName(const STR_String& name); 00145 00146 // struct Main* GetMain() { return m_maggie; }; 00147 struct Main* GetMainDynamicPath(const char *path); 00148 vector<struct Main*> &GetMainDynamic(); 00149 00150 bool LinkBlendFileMemory(void *data, int length, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options); 00151 bool LinkBlendFilePath(const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options); 00152 bool LinkBlendFile(struct BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options); 00153 bool MergeScene(KX_Scene *to, KX_Scene *from); 00154 RAS_MeshObject *ConvertMeshSpecial(KX_Scene* kx_scene, Main *maggie, const char *name); 00155 bool FreeBlendFile(struct Main *maggie); 00156 bool FreeBlendFile(const char *path); 00157 00158 void PrintStats() { 00159 printf("BGE STATS!\n"); 00160 00161 printf("\nAssets...\n"); 00162 printf("\t m_worldinfos: %d\n", (int)m_worldinfos.size()); 00163 printf("\t m_polymaterials: %d\n", (int)m_polymaterials.size()); 00164 printf("\t m_meshobjects: %d\n", (int)m_meshobjects.size()); 00165 printf("\t m_materials: %d\n", (int)m_materials.size()); 00166 00167 printf("\nMappings...\n"); 00168 printf("\t m_map_blender_to_gameobject: %d\n", (int)m_map_blender_to_gameobject.size()); 00169 printf("\t m_map_mesh_to_gamemesh: %d\n", (int)m_map_mesh_to_gamemesh.size()); 00170 printf("\t m_map_blender_to_gameactuator: %d\n", (int)m_map_blender_to_gameactuator.size()); 00171 printf("\t m_map_blender_to_gamecontroller: %d\n", (int)m_map_blender_to_gamecontroller.size()); 00172 printf("\t m_map_blender_to_gameAdtList: %d\n", (int)m_map_blender_to_gameAdtList.size()); 00173 00174 #ifdef WITH_CXX_GUARDEDALLOC 00175 MEM_printmemlist_pydict(); 00176 #endif 00177 // /printf("\t m_ketsjiEngine->m_scenes: %d\n", m_ketsjiEngine->CurrentScenes()->size()); 00178 } 00179 00180 /* LibLoad Options */ 00181 enum 00182 { 00183 LIB_LOAD_LOAD_ACTIONS = 1, 00184 LIB_LOAD_VERBOSE = 2, 00185 }; 00186 00187 00188 00189 #ifdef WITH_PYTHON 00190 PyObject *GetPyNamespace(); 00191 #endif 00192 00193 #ifdef WITH_CXX_GUARDEDALLOC 00194 public: 00195 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:KX_BlenderSceneConverter"); } 00196 void operator delete( void *mem ) { MEM_freeN(mem); } 00197 #endif 00198 }; 00199 00200 #endif //__KX_BLENDERSCENECONVERTER_H 00201