15 #ifndef SCENE_LAB_SCENE_LAB_H_
16 #define SCENE_LAB_SCENE_LAB_H_
23 #include "flatui/flatui.h"
24 #include "fplbase/asset_manager.h"
25 #include "fplbase/input.h"
26 #include "fplbase/renderer.h"
27 #include "fplbase/utilities.h"
28 #include "mathfu/vector.h"
31 #include "scene_lab/entity_system_adapter.h"
32 #include "scene_lab_config_generated.h"
36 typedef std::function<void(const GenericEntityId& entity)> EntityCallback;
37 typedef std::function<void()> EditorCallback;
47 fplbase::AssetManager* asset_manager,
48 fplbase::InputSystem* input, fplbase::Renderer* renderer,
49 flatui::FontManager* font_manager);
56 return entity_system_adapter_.get();
72 void Render(fplbase::Renderer* renderer);
174 const std::string& version() {
return version_; }
177 const SceneLabConfig*
config() {
return config_; }
182 MATHFU_DEFINE_CLASS_SIMD_AWARE_NEW_DELETE
194 static const char kVersion[];
196 enum InputMode { kMoving, kEditing, kDragging };
213 bool PreciseMovement()
const;
217 mathfu::vec3 GlobalFromHorizontal(
float forward,
float right,
float up,
218 const mathfu::vec3& plane_normal)
const;
221 mathfu::vec3 GetMovement()
const;
224 bool ModifyTransformBasedOnInput(GenericTransform* transform);
230 static bool IntersectRayToPlane(
const mathfu::vec3& ray_origin,
231 const mathfu::vec3& ray_direction,
232 const mathfu::vec3& point_on_plane,
233 const mathfu::vec3& plane_normal,
234 mathfu::vec3* intersection_point);
239 static bool ProjectPointToPlane(
const mathfu::vec3& point_to_project,
240 const mathfu::vec3& point_on_plane,
241 const mathfu::vec3& plane_normal,
242 mathfu::vec3* point_projected);
246 bool SerializeEntitiesFromFile(
const std::string& filename,
247 std::vector<uint8_t>* output);
251 void LoadSchemaFiles();
258 void WriteEntityFile(
const std::string& filename,
259 const std::vector<uint8_t>& data);
264 const char* BinaryEntityFileExtension()
const;
266 const SceneLabConfig* config_;
267 std::unique_ptr<EntitySystemAdapter> entity_system_adapter_;
269 fplbase::AssetManager* asset_manager_;
270 fplbase::Renderer* renderer_;
271 fplbase::InputSystem* input_system_;
272 flatui::FontManager* font_manager_;
274 GenericEntityId selected_entity_;
276 InputMode input_mode_;
277 MouseMode mouse_mode_;
279 std::unique_ptr<EditorController> controller_;
280 std::unique_ptr<EditorGui> gui_;
281 GenericCamera initial_camera_;
285 mathfu::vec3 horizontal_forward_;
286 mathfu::vec3 horizontal_right_;
288 mathfu::vec3 drag_point_;
289 mathfu::vec3 drag_plane_normal_;
290 mathfu::vec3 drag_offset_;
291 mathfu::vec3 drag_prev_intersect_;
292 mathfu::vec3 drag_orig_scale_;
294 bool initial_camera_set_;
295 bool exit_requested_;
297 bool entities_modified_;
301 std::vector<EditorCallback> on_enter_editor_callbacks_;
302 std::vector<EditorCallback> on_exit_editor_callbacks_;
303 std::vector<EntityCallback> on_create_entity_callbacks_;
304 std::vector<EntityCallback> on_update_entity_callbacks_;
305 std::vector<EntityCallback> on_delete_entity_callbacks_;
308 std::string version_;
313 #endif // SCENE_LAB_SCENE_LAB_H_
void GetCamera(GenericCamera *camera)
Get the Scene Lab camera, so you can render the scene properly or change its position.
void SetEntitySystemAdapter(std::unique_ptr< EntitySystemAdapter > adapter)
Set which entity system adapter to use.
Definition: editor_gui.h:38
void AddOnDeleteEntityCallback(EntityCallback callback)
Specify a callback to call when an entity is deleted.
void RequestExit()
Request that Scene Lab exit.
void AddOnUpdateEntityCallback(EntityCallback callback)
Specify a callback to call when an entity's data is updated.
void AbortExit()
Abort a previously-requested exit, which hides the confirmation dialog.
EditorGui is a FlatUI-based GUI overlay for Scene Lab to the edit window and on-screen menu buttons...
void set_entities_modified(bool b)
Externally mark that some entities have been modified.
Definition: scene_lab.h:139
void MoveEntityToCamera(const GenericEntityId &entity)
Move the specified entity to directly in front of the camera.
void Render(fplbase::Renderer *renderer)
Render Scene Lab and its GUI; only call this when Scene Lab is active.
void AddOnEnterEditorCallback(EditorCallback callback)
Specify a callback to call when the editor is opened.
void AddOnExitEditorCallback(EditorCallback callback)
Specify a callback to call when the editor is exited.
void SetInitialCamera(const GenericCamera &initial_camera)
When you activate the editor, you can pass in your game's camera so the user can seamlessly be positi...
void NotifyDeleteEntity(const GenericEntityId &entity) const
Call all 'EntityDeleted' callbacks.
Definition: scene_lab.h:40
void Activate()
Activate Scene Lab.
void SelectEntity(const GenericEntityId &entity)
Highlight the specified entity, so that you can change its properties.
void Initialize(const SceneLabConfig *config, fplbase::AssetManager *asset_manager, fplbase::InputSystem *input, fplbase::Renderer *renderer, flatui::FontManager *font_manager)
Initialize Scene Lab once, when starting your game.
void NotifyCreateEntity(const GenericEntityId &entity) const
Call all 'EntityCreated' callbacks.
Pointer and keyboard controls for Scene Lab.
void Deactivate()
Immediately deactivate Scene Lab.
EditorGui * gui()
GUI accessor, so you can poke into the EditorGui.
Definition: scene_lab.h:180
void NotifyExitEditor() const
Call all 'EditorExit' callbacks.
void AdvanceFrame(double delta_time_seconds)
While Scene Lab is active, you must call this once a frame, every frame.
void SaveScene()
Save the current positions and properties to disk.
Definition: scene_lab.h:114
bool entities_modified() const
Have entities been modified? If so, prompt the user to save before exit.
Definition: scene_lab.h:142
const SceneLabConfig * config()
Config accessor, so you can access config options.
Definition: scene_lab.h:177
bool IsReadyToExit()
Returns true if we are ready to exit Scene Lab (everything is saved or discarded, etc)...
void NotifyEnterEditor() const
Call all 'EditorEnter' callbacks.
void AddOnCreateEntityCallback(EntityCallback callback)
Specify a callback to call when an entity is created.
EntitySystemAdapter * entity_system_adapter() const
Accessor for entity system adapter, don't hold onto this pointer.
Definition: scene_lab.h:55
void NotifyUpdateEntity(const GenericEntityId &entity) const
Call all 'EntityUpdated' callbacks.