Merged 15170:15635 from trunk (no conflicts or even merges)
[blender.git] / source / gameengine / Converter / KX_BlenderSceneConverter.h
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29 #ifndef __KX_BLENDERSCENECONVERTER_H
30 #define __KX_BLENDERSCENECONVERTER_H
31
32 #include "KX_HashedPtr.h"
33 #include "GEN_Map.h"
34
35 #include "KX_ISceneConverter.h"
36 #include "KX_IpoConvert.h"
37
38 class KX_WorldInfo;
39 class SCA_IActuator;
40 class SCA_IController;
41 class RAS_MeshObject;
42 class RAS_IPolyMaterial;
43 class BL_InterpolatorList;
44 class BL_Material;
45 struct IpoCurve;
46 struct Main;
47 struct SpaceIpo;
48
49 class KX_BlenderSceneConverter : public KX_ISceneConverter
50 {
51         // Use vector of pairs to allow removal of entities between scene switch
52         vector<pair<KX_Scene*,KX_WorldInfo*> >  m_worldinfos;
53         vector<pair<KX_Scene*,RAS_IPolyMaterial*> > m_polymaterials;
54         vector<pair<KX_Scene*,RAS_MeshObject*> > m_meshobjects;
55         vector<pair<KX_Scene*,BL_Material *> >  m_materials;
56         // Should also have a list of collision shapes. 
57         // For the time being this is held in KX_Scene::m_shapes
58
59         GEN_Map<CHashedPtr,struct Object*> m_map_gameobject_to_blender;
60         GEN_Map<CHashedPtr,KX_GameObject*> m_map_blender_to_gameobject;
61
62         GEN_Map<CHashedPtr,RAS_MeshObject*> m_map_mesh_to_gamemesh;
63 //      GEN_Map<CHashedPtr,DT_ShapeHandle> m_map_gamemesh_to_sumoshape;
64         
65         GEN_Map<CHashedPtr,SCA_IActuator*> m_map_blender_to_gameactuator;
66         GEN_Map<CHashedPtr,SCA_IController*> m_map_blender_to_gamecontroller;
67         
68         GEN_Map<CHashedPtr,BL_InterpolatorList*> m_map_blender_to_gameipolist;
69         
70         Main*                                   m_maggie;
71         SpaceIpo*                               m_sipo;
72
73         STR_String                              m_newfilename;
74         class KX_KetsjiEngine*  m_ketsjiEngine;
75         class KX_Scene*                 m_currentScene; // Scene being converted
76         bool                                    m_alwaysUseExpandFraming;
77         bool                                    m_usemat;
78         bool                                    m_useglslmat;
79
80         void localDel_ipoCurve ( IpoCurve * icu ,struct SpaceIpo*       sipo);
81 //      struct Ipo* findIpoForName(char* objName);
82
83 public:
84         KX_BlenderSceneConverter(
85                 Main* maggie,
86                 SpaceIpo *sipo,
87                 class KX_KetsjiEngine* engine
88         );
89
90         virtual ~KX_BlenderSceneConverter();
91
92         /* Scenename: name of the scene to be converted.
93          * destinationscene: pass an empty scene, everything goes into this
94          * dictobj: python dictionary (for pythoncontrollers)
95          */
96         virtual void    ConvertScene(
97                                                 const STR_String& scenename,
98                                                 class KX_Scene* destinationscene,
99                                                 PyObject* dictobj,
100                                                 class SCA_IInputDevice* keyinputdev,
101                                                 class RAS_IRenderTools* rendertools,
102                                                 class RAS_ICanvas* canvas
103                                         );
104         virtual void RemoveScene(class KX_Scene *scene);
105
106         void SetNewFileName(const STR_String& filename);
107         bool TryAndLoadNewFile();
108
109         void SetAlwaysUseExpandFraming(bool to_what);
110         
111         void RegisterGameObject(KX_GameObject *gameobject, struct Object *for_blenderobject);
112         void UnregisterGameObject(KX_GameObject *gameobject);
113         KX_GameObject *FindGameObject(struct Object *for_blenderobject);
114         struct Object *FindBlenderObject(KX_GameObject *for_gameobject);
115
116         void RegisterGameMesh(RAS_MeshObject *gamemesh, struct Mesh *for_blendermesh);
117         RAS_MeshObject *FindGameMesh(struct Mesh *for_blendermesh, unsigned int onlayer);
118
119 //      void RegisterSumoShape(DT_ShapeHandle shape, RAS_MeshObject *for_gamemesh);
120 //      DT_ShapeHandle FindSumoShape(RAS_MeshObject *for_gamemesh);
121
122         void RegisterPolyMaterial(RAS_IPolyMaterial *polymat);
123
124         void RegisterBlenderMaterial(BL_Material *mat);
125         
126         void RegisterInterpolatorList(BL_InterpolatorList *ipoList, struct Ipo *for_ipo);
127         BL_InterpolatorList *FindInterpolatorList(struct Ipo *for_ipo);
128
129         void RegisterGameActuator(SCA_IActuator *act, struct bActuator *for_actuator);
130         SCA_IActuator *FindGameActuator(struct bActuator *for_actuator);
131
132         void RegisterGameController(SCA_IController *cont, struct bController *for_controller);
133         SCA_IController *FindGameController(struct bController *for_controller);
134
135         void RegisterWorldInfo(KX_WorldInfo *worldinfo);
136
137         virtual void    ResetPhysicsObjectsAnimationIpo(bool clearIpo);
138
139         ///this is for reseting the position,rotation and scale of the gameobjet that is not dynamic
140         virtual void    resetNoneDynamicObjectToIpo();
141         
142         ///this generates ipo curves for position, rotation, allowing to use game physics in animation
143         virtual void    WritePhysicsObjectToAnimationIpo(int frameNumber);
144         virtual void    TestHandlesPhysicsObjectToAnimationIpo();
145
146         // use blender materials
147         virtual void SetMaterials(bool val);
148         virtual bool GetMaterials();
149
150         // use blender glsl materials
151         virtual void SetGLSLMaterials(bool val);
152         virtual bool GetGLSLMaterials();
153
154 };
155
156 #endif //__KX_BLENDERSCENECONVERTER_H
157