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