diff --git a/Content/Documentation/WickedEngine-Documentation.md b/Content/Documentation/WickedEngine-Documentation.md
index e9fd94831..20ee36c2b 100644
--- a/Content/Documentation/WickedEngine-Documentation.md
+++ b/Content/Documentation/WickedEngine-Documentation.md
@@ -244,7 +244,7 @@ Entity is a number, it can reference components through ComponentManager contain
[[Header]](../../WickedEngine/wiScene.h) [[Cpp]](../../WickedEngine/wiScene.cpp)
The logical scene representation using the Entity-Component System
- GetScene
-Returns a global scene instance. The wi::renderer will use this scene instance to render the scene. The user can create multiple scenes as well, and merge those into the global scene so that those will be rendered as well.
+Returns a global scene instance. This is a convenience feature for simple applications that need a single scene. The RenderPath3D will use the global scene by default, but it can be set to a custom scene if needed.
- LoadModel()
There are two flavours to this. One of them immediately loads into the global scene. The other loads into a custom scene, which is usefult to manage the contents separately. This function will return an Entity that represents the root transform of the scene - if the attached parameter was true, otherwise it will return INVALID_ENTITY and no root transform will be created.
- Pick
diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp
index f3f306ded..b991eeaaa 100644
--- a/Editor/AnimationWindow.cpp
+++ b/Editor/AnimationWindow.cpp
@@ -5,8 +5,9 @@
using namespace wi::ecs;
using namespace wi::scene;
-void AnimationWindow::Create(EditorComponent* editor)
+void AnimationWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Animation Window");
SetSize(XMFLOAT2(520, 140));
@@ -21,7 +22,7 @@ void AnimationWindow::Create(EditorComponent* editor)
animationsComboBox.SetPos(XMFLOAT2(x, y));
animationsComboBox.SetEnabled(false);
animationsComboBox.OnSelect([&](wi::gui::EventArgs args) {
- entity = wi::scene::GetScene().animations.GetEntity(args.iValue);
+ entity = editor->GetCurrentScene().animations.GetEntity(args.iValue);
});
animationsComboBox.SetTooltip("Choose an animation clip...");
AddWidget(&animationsComboBox);
@@ -31,7 +32,7 @@ void AnimationWindow::Create(EditorComponent* editor)
loopedCheckBox.SetSize(XMFLOAT2(hei, hei));
loopedCheckBox.SetPos(XMFLOAT2(150, y += step));
loopedCheckBox.OnClick([&](wi::gui::EventArgs args) {
- AnimationComponent* animation = wi::scene::GetScene().animations.GetComponent(entity);
+ AnimationComponent* animation = editor->GetCurrentScene().animations.GetComponent(entity);
if (animation != nullptr)
{
animation->SetLooped(args.bValue);
@@ -44,7 +45,7 @@ void AnimationWindow::Create(EditorComponent* editor)
playButton.SetSize(XMFLOAT2(100, hei));
playButton.SetPos(XMFLOAT2(200, y));
playButton.OnClick([&](wi::gui::EventArgs args) {
- AnimationComponent* animation = wi::scene::GetScene().animations.GetComponent(entity);
+ AnimationComponent* animation = editor->GetCurrentScene().animations.GetComponent(entity);
if (animation != nullptr)
{
if (animation->IsPlaying())
@@ -64,7 +65,7 @@ void AnimationWindow::Create(EditorComponent* editor)
stopButton.SetSize(XMFLOAT2(100, hei));
stopButton.SetPos(XMFLOAT2(310, y));
stopButton.OnClick([&](wi::gui::EventArgs args) {
- AnimationComponent* animation = wi::scene::GetScene().animations.GetComponent(entity);
+ AnimationComponent* animation = editor->GetCurrentScene().animations.GetComponent(entity);
if (animation != nullptr)
{
animation->Stop();
@@ -76,7 +77,7 @@ void AnimationWindow::Create(EditorComponent* editor)
timerSlider.SetSize(XMFLOAT2(250, hei));
timerSlider.SetPos(XMFLOAT2(x, y += step));
timerSlider.OnSlide([&](wi::gui::EventArgs args) {
- AnimationComponent* animation = wi::scene::GetScene().animations.GetComponent(entity);
+ AnimationComponent* animation = editor->GetCurrentScene().animations.GetComponent(entity);
if (animation != nullptr)
{
animation->timer = args.fValue;
@@ -90,7 +91,7 @@ void AnimationWindow::Create(EditorComponent* editor)
amountSlider.SetSize(XMFLOAT2(250, hei));
amountSlider.SetPos(XMFLOAT2(x, y += step));
amountSlider.OnSlide([&](wi::gui::EventArgs args) {
- AnimationComponent* animation = wi::scene::GetScene().animations.GetComponent(entity);
+ AnimationComponent* animation = editor->GetCurrentScene().animations.GetComponent(entity);
if (animation != nullptr)
{
animation->amount = args.fValue;
@@ -104,7 +105,7 @@ void AnimationWindow::Create(EditorComponent* editor)
speedSlider.SetSize(XMFLOAT2(250, hei));
speedSlider.SetPos(XMFLOAT2(x, y += step));
speedSlider.OnSlide([&](wi::gui::EventArgs args) {
- AnimationComponent* animation = wi::scene::GetScene().animations.GetComponent(entity);
+ AnimationComponent* animation = editor->GetCurrentScene().animations.GetComponent(entity);
if (animation != nullptr)
{
animation->speed = args.fValue;
@@ -125,7 +126,7 @@ void AnimationWindow::Update()
{
animationsComboBox.ClearItems();
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
if (!scene.animations.Contains(entity))
{
diff --git a/Editor/AnimationWindow.h b/Editor/AnimationWindow.h
index e3425d59c..c1444dd5b 100644
--- a/Editor/AnimationWindow.h
+++ b/Editor/AnimationWindow.h
@@ -7,7 +7,8 @@ class AnimationWindow : public wi::gui::Window
{
public:
void Create(EditorComponent* editor);
-
+
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity = wi::ecs::INVALID_ENTITY;
wi::gui::ComboBox animationsComboBox;
diff --git a/Editor/CameraWindow.cpp b/Editor/CameraWindow.cpp
index 3e4989f6a..7a8c4d87c 100644
--- a/Editor/CameraWindow.cpp
+++ b/Editor/CameraWindow.cpp
@@ -7,32 +7,35 @@ using namespace wi::scene;
void CameraWindow::ResetCam()
{
- move = {};
+ if (editor == nullptr)
+ return;
+ auto& editorscene = editor->GetCurrentEditorScene();
- Scene& scene = wi::scene::GetScene();
+ editorscene.cam_move = {};
- CameraComponent& camera = wi::scene::GetCamera();
+ CameraComponent& camera = editorscene.camera;
float width = camera.width;
float height = camera.height;
camera = CameraComponent();
camera.width = width;
camera.height = height;
- camera_transform.ClearTransform();
- camera_transform.Translate(XMFLOAT3(0, 2, -10));
- camera_transform.UpdateTransform();
- camera.TransformCamera(camera_transform);
+ editorscene.camera_transform.ClearTransform();
+ editorscene.camera_transform.Translate(XMFLOAT3(0, 2, -10));
+ editorscene.camera_transform.UpdateTransform();
+ camera.TransformCamera(editorscene.camera_transform);
camera.UpdateCamera();
- camera_target.ClearTransform();
- camera_target.UpdateTransform();
+ editorscene.camera_target.ClearTransform();
+ editorscene.camera_target.UpdateTransform();
}
-void CameraWindow::Create(EditorComponent* editor)
+void CameraWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Camera Window");
- camera_transform.MatrixTransform(wi::scene::GetCamera().GetInvView());
- camera_transform.UpdateTransform();
+ editor->GetCurrentEditorScene().camera_transform.MatrixTransform(editor->GetCurrentEditorScene().camera.GetInvView());
+ editor->GetCurrentEditorScene().camera_transform.UpdateTransform();
SetSize(XMFLOAT2(380, 360));
@@ -45,10 +48,10 @@ void CameraWindow::Create(EditorComponent* editor)
farPlaneSlider.SetTooltip("Controls the camera's far clip plane, geometry farther than this will be clipped.");
farPlaneSlider.SetSize(XMFLOAT2(100, hei));
farPlaneSlider.SetPos(XMFLOAT2(x, y));
- farPlaneSlider.SetValue(wi::scene::GetCamera().zFarP);
+ farPlaneSlider.SetValue(editor->GetCurrentEditorScene().camera.zFarP);
farPlaneSlider.OnSlide([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
- CameraComponent& camera = wi::scene::GetCamera();
+ Scene& scene = editor->GetCurrentScene();
+ CameraComponent& camera = editor->GetCurrentEditorScene().camera;
camera.zFarP = args.fValue;
camera.UpdateCamera();
camera.SetDirty();
@@ -59,10 +62,10 @@ void CameraWindow::Create(EditorComponent* editor)
nearPlaneSlider.SetTooltip("Controls the camera's near clip plane, geometry closer than this will be clipped.");
nearPlaneSlider.SetSize(XMFLOAT2(100, hei));
nearPlaneSlider.SetPos(XMFLOAT2(x, y += step));
- nearPlaneSlider.SetValue(wi::scene::GetCamera().zNearP);
+ nearPlaneSlider.SetValue(editor->GetCurrentEditorScene().camera.zNearP);
nearPlaneSlider.OnSlide([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
- CameraComponent& camera = wi::scene::GetCamera();
+ Scene& scene = editor->GetCurrentScene();
+ CameraComponent& camera = editor->GetCurrentEditorScene().camera;
camera.zNearP = args.fValue;
camera.UpdateCamera();
camera.SetDirty();
@@ -74,8 +77,8 @@ void CameraWindow::Create(EditorComponent* editor)
fovSlider.SetSize(XMFLOAT2(100, hei));
fovSlider.SetPos(XMFLOAT2(x, y += step));
fovSlider.OnSlide([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
- CameraComponent& camera = wi::scene::GetCamera();
+ Scene& scene = editor->GetCurrentScene();
+ CameraComponent& camera = editor->GetCurrentEditorScene().camera;
camera.fov = args.fValue / 180.f * XM_PI;
camera.UpdateCamera();
camera.SetDirty();
@@ -87,8 +90,8 @@ void CameraWindow::Create(EditorComponent* editor)
focalLengthSlider.SetSize(XMFLOAT2(100, hei));
focalLengthSlider.SetPos(XMFLOAT2(x, y += step));
focalLengthSlider.OnSlide([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
- CameraComponent& camera = wi::scene::GetCamera();
+ Scene& scene = editor->GetCurrentScene();
+ CameraComponent& camera = editor->GetCurrentEditorScene().camera;
camera.focal_length = args.fValue;
camera.UpdateCamera();
camera.SetDirty();
@@ -100,8 +103,8 @@ void CameraWindow::Create(EditorComponent* editor)
apertureSizeSlider.SetSize(XMFLOAT2(100, hei));
apertureSizeSlider.SetPos(XMFLOAT2(x, y += step));
apertureSizeSlider.OnSlide([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
- CameraComponent& camera = wi::scene::GetCamera();
+ Scene& scene = editor->GetCurrentScene();
+ CameraComponent& camera = editor->GetCurrentEditorScene().camera;
camera.aperture_size = args.fValue;
camera.UpdateCamera();
camera.SetDirty();
@@ -113,8 +116,8 @@ void CameraWindow::Create(EditorComponent* editor)
apertureShapeXSlider.SetSize(XMFLOAT2(100, hei));
apertureShapeXSlider.SetPos(XMFLOAT2(x, y += step));
apertureShapeXSlider.OnSlide([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
- CameraComponent& camera = wi::scene::GetCamera();
+ Scene& scene = editor->GetCurrentScene();
+ CameraComponent& camera = editor->GetCurrentEditorScene().camera;
camera.aperture_shape.x = args.fValue;
camera.UpdateCamera();
camera.SetDirty();
@@ -126,8 +129,8 @@ void CameraWindow::Create(EditorComponent* editor)
apertureShapeYSlider.SetSize(XMFLOAT2(100, hei));
apertureShapeYSlider.SetPos(XMFLOAT2(x, y += step));
apertureShapeYSlider.OnSlide([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
- CameraComponent& camera = wi::scene::GetCamera();
+ Scene& scene = editor->GetCurrentScene();
+ CameraComponent& camera = editor->GetCurrentEditorScene().camera;
camera.aperture_shape.y = args.fValue;
camera.UpdateCamera();
camera.SetDirty();
@@ -171,9 +174,9 @@ void CameraWindow::Create(EditorComponent* editor)
proxyButton.SetPos(XMFLOAT2(x, y += step * 2));
proxyButton.OnClick([=](wi::gui::EventArgs args) {
- const CameraComponent& camera = wi::scene::GetCamera();
+ const CameraComponent& camera = editor->GetCurrentEditorScene().camera;
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
static int camcounter = 0;
Entity entity = scene.Entity_CreateCamera("cam" + std::to_string(camcounter), camera.width, camera.height, camera.zNearP, camera.zFarP, camera.fov);
@@ -195,7 +198,7 @@ void CameraWindow::Create(EditorComponent* editor)
editor->RecordSelection(archive);
editor->RecordAddedEntity(archive, entity);
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
SetEntity(entity);
});
AddWidget(&proxyButton);
@@ -224,7 +227,7 @@ void CameraWindow::SetEntity(Entity entity)
{
proxy = entity;
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
if (scene.cameras.GetComponent(entity) != nullptr)
{
@@ -241,7 +244,7 @@ void CameraWindow::SetEntity(Entity entity)
void CameraWindow::Update()
{
- CameraComponent& camera = wi::scene::GetCamera();
+ CameraComponent& camera = editor->GetCurrentEditorScene().camera;
farPlaneSlider.SetValue(camera.zFarP);
nearPlaneSlider.SetValue(camera.zNearP);
@@ -256,7 +259,7 @@ void CameraWindow::Update()
// however this only works well for fps camera
if (fpsCheckBox.GetCheck())
{
- camera_transform.ClearTransform();
- camera_transform.MatrixTransform(camera.InvView);
+ editor->GetCurrentEditorScene().camera_transform.ClearTransform();
+ editor->GetCurrentEditorScene().camera_transform.MatrixTransform(camera.InvView);
}
}
diff --git a/Editor/CameraWindow.h b/Editor/CameraWindow.h
index b80ef7f9f..e17cf4984 100644
--- a/Editor/CameraWindow.h
+++ b/Editor/CameraWindow.h
@@ -10,15 +10,11 @@ public:
void ResetCam();
+ EditorComponent* editor = nullptr;
wi::ecs::Entity proxy = wi::ecs::INVALID_ENTITY;
void SetEntity(wi::ecs::Entity entity);
void Update();
- XMFLOAT3 move = {};
-
-
- wi::scene::TransformComponent camera_transform;
- wi::scene::TransformComponent camera_target;
wi::gui::Slider farPlaneSlider;
wi::gui::Slider nearPlaneSlider;
diff --git a/Editor/DecalWindow.cpp b/Editor/DecalWindow.cpp
index 5c6515d3c..6e93a551c 100644
--- a/Editor/DecalWindow.cpp
+++ b/Editor/DecalWindow.cpp
@@ -6,8 +6,9 @@ using namespace wi::ecs;
using namespace wi::scene;
-void DecalWindow::Create(EditorComponent* editor)
+void DecalWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Decal Window");
SetSize(XMFLOAT2(420, 200));
@@ -37,12 +38,12 @@ void DecalWindow::Create(EditorComponent* editor)
decalNameField.SetPos(XMFLOAT2(10, y+=step));
decalNameField.SetSize(XMFLOAT2(300, hei));
decalNameField.OnInputAccepted([=](wi::gui::EventArgs args) {
- NameComponent* name = wi::scene::GetScene().names.GetComponent(entity);
+ NameComponent* name = editor->GetCurrentScene().names.GetComponent(entity);
if (name != nullptr)
{
*name = args.sValue;
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
}
});
AddWidget(&decalNameField);
@@ -57,7 +58,7 @@ void DecalWindow::SetEntity(Entity entity)
{
this->entity = entity;
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
const DecalComponent* decal = scene.decals.GetComponent(entity);
if (decal != nullptr)
diff --git a/Editor/DecalWindow.h b/Editor/DecalWindow.h
index 97d42a803..b8668b8b1 100644
--- a/Editor/DecalWindow.h
+++ b/Editor/DecalWindow.h
@@ -8,6 +8,7 @@ class DecalWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp
index 3c19c02b9..adc27b5ed 100644
--- a/Editor/Editor.cpp
+++ b/Editor/Editor.cpp
@@ -1,6 +1,7 @@
#include "stdafx.h"
#include "Editor.h"
#include "wiRenderer.h"
+#include "wiScene_BindLua.h"
#include "ModelImporter.h"
#include "Translator.h"
@@ -91,6 +92,11 @@ void EditorComponent::ChangeRenderPath(RENDERPATH path)
break;
}
+ if (scenes.empty())
+ {
+ NewScene();
+ }
+
renderPath->resolutionScale = resolutionScale;
renderPath->setBloomThreshold(3.0f);
@@ -302,62 +308,62 @@ void EditorComponent::ResizeLayout()
////////////////////////////////////////////////////////////////////////////////////
- translatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 4 - 25, 0));
+ translatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 3 - 25, 0));
translatorCheckBox.SetSize(XMFLOAT2(18, 18));
- isScalatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 4 - 25 - 40 * 2, 22));
+ isScalatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 3 - 25 - 40 * 2, 22));
isScalatorCheckBox.SetSize(XMFLOAT2(18, 18));
- isRotatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 4 - 25 - 40 * 1, 22));
+ isRotatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 3 - 25 - 40 * 1, 22));
isRotatorCheckBox.SetSize(XMFLOAT2(18, 18));
- isTranslatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 4 - 25, 22));
+ isTranslatorCheckBox.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 3 - 25, 22));
isTranslatorCheckBox.SetSize(XMFLOAT2(18, 18));
- saveButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 4, 0));
+ saveButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 3, 0));
saveButton.SetSize(XMFLOAT2(100, 40));
- modelButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 3, 0));
- modelButton.SetSize(XMFLOAT2(100, 40));
+ openButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 2, 0));
+ openButton.SetSize(XMFLOAT2(100, 40));
- scriptButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 2, 0));
- scriptButton.SetSize(XMFLOAT2(100, 40));
+ closeButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 1, 0));
+ closeButton.SetSize(XMFLOAT2(100, 40));
- clearButton.SetPos(XMFLOAT2(screenW - 50 - 55 - 105 * 1, 0));
- clearButton.SetSize(XMFLOAT2(100, 40));
+ aboutButton.SetPos(XMFLOAT2(screenW - 50 - 55, 0));
+ aboutButton.SetSize(XMFLOAT2(50, 40));
- helpButton.SetPos(XMFLOAT2(screenW - 50 - 55, 0));
- helpButton.SetSize(XMFLOAT2(50, 40));
-
- helpLabel.SetSize(XMFLOAT2(screenW / 2.0f, screenH / 1.5f));
- helpLabel.SetPos(XMFLOAT2(screenW / 2.0f - helpLabel.scale.x / 2.0f, screenH / 2.0f - helpLabel.scale.y / 2.0f));
+ aboutLabel.SetSize(XMFLOAT2(screenW / 2.0f, screenH / 1.5f));
+ aboutLabel.SetPos(XMFLOAT2(screenW / 2.0f - aboutLabel.scale.x / 2.0f, screenH / 2.0f - aboutLabel.scale.y / 2.0f));
exitButton.SetPos(XMFLOAT2(screenW - 50, 0));
exitButton.SetSize(XMFLOAT2(50, 40));
- profilerEnabledCheckBox.SetSize(XMFLOAT2(20, 20));
- profilerEnabledCheckBox.SetPos(XMFLOAT2(screenW - 530, 45));
+ profilerEnabledCheckBox.SetSize(XMFLOAT2(18, 18));
+ profilerEnabledCheckBox.SetPos(XMFLOAT2(screenW - 485, 45));
- physicsEnabledCheckBox.SetSize(XMFLOAT2(20, 20));
- physicsEnabledCheckBox.SetPos(XMFLOAT2(screenW - 370, 45));
+ physicsEnabledCheckBox.SetSize(XMFLOAT2(18, 18));
+ physicsEnabledCheckBox.SetPos(XMFLOAT2(screenW - 390, 45));
- cinemaModeCheckBox.SetSize(XMFLOAT2(20, 20));
- cinemaModeCheckBox.SetPos(XMFLOAT2(screenW - 240, 45));
+ cinemaModeCheckBox.SetSize(XMFLOAT2(18, 18));
+ cinemaModeCheckBox.SetPos(XMFLOAT2(screenW - 260, 45));
- renderPathComboBox.SetSize(XMFLOAT2(100, 20));
- renderPathComboBox.SetPos(XMFLOAT2(screenW - 120, 45));
+ renderPathComboBox.SetSize(XMFLOAT2(120, 18));
+ renderPathComboBox.SetPos(XMFLOAT2(screenW - 140, 45));
- saveModeComboBox.SetSize(XMFLOAT2(120, 20));
- saveModeComboBox.SetPos(XMFLOAT2(screenW - 140, 70));
+ sceneComboBox.SetSize(XMFLOAT2(120, 18));
+ sceneComboBox.SetPos(XMFLOAT2(screenW - 140, 70));
- pathTraceTargetSlider.SetSize(XMFLOAT2(200, 20));
+ saveModeComboBox.SetSize(XMFLOAT2(120, 18));
+ saveModeComboBox.SetPos(XMFLOAT2(screenW - 140, 95));
+
+ pathTraceTargetSlider.SetSize(XMFLOAT2(200, 18));
pathTraceTargetSlider.SetPos(XMFLOAT2(screenW - 240, 100));
pathTraceStatisticsLabel.SetSize(XMFLOAT2(240, 60));
pathTraceStatisticsLabel.SetPos(XMFLOAT2(screenW - 240, 125));
- sceneGraphView.SetSize(XMFLOAT2(260, 300));
- sceneGraphView.SetPos(XMFLOAT2(0, screenH - sceneGraphView.scale_local.y));
+ entityTree.SetSize(XMFLOAT2(260, 300));
+ entityTree.SetPos(XMFLOAT2(0, screenH - entityTree.scale_local.y));
}
void EditorComponent::Load()
{
@@ -365,7 +371,6 @@ void EditorComponent::Load()
wi::jobsystem::Execute(ctx, [this](wi::jobsystem::JobArgs args) { pointLightTex = wi::resourcemanager::Load("images/pointlight.dds"); });
wi::jobsystem::Execute(ctx, [this](wi::jobsystem::JobArgs args) { spotLightTex = wi::resourcemanager::Load("images/spotlight.dds"); });
wi::jobsystem::Execute(ctx, [this](wi::jobsystem::JobArgs args) { dirLightTex = wi::resourcemanager::Load("images/directional_light.dds"); });
- wi::jobsystem::Execute(ctx, [this](wi::jobsystem::JobArgs args) { areaLightTex = wi::resourcemanager::Load("images/arealight.dds"); });
wi::jobsystem::Execute(ctx, [this](wi::jobsystem::JobArgs args) { decalTex = wi::resourcemanager::Load("images/decal.dds"); });
wi::jobsystem::Execute(ctx, [this](wi::jobsystem::JobArgs args) { forceFieldTex = wi::resourcemanager::Load("images/forcefield.dds"); });
wi::jobsystem::Execute(ctx, [this](wi::jobsystem::JobArgs args) { emitterTex = wi::resourcemanager::Load("images/emitter.dds"); });
@@ -376,7 +381,6 @@ void EditorComponent::Load()
// wait for ctx is at the end of this function!
-
rendererWnd_Toggle.Create("Renderer");
rendererWnd_Toggle.SetTooltip("Renderer settings window");
rendererWnd_Toggle.OnClick([&](wi::gui::EventArgs args) {
@@ -458,7 +462,7 @@ void EditorComponent::Load()
//prop.object.cascadeMask = 1; // they won't be rendered into the largest shadow cascade
}
props_scene.Entity_Remove(object_entity); // The objects will be placed by terrain generator, we don't need the default object that the scene has anymore
- wi::scene::GetScene().Merge(props_scene);
+ GetCurrentScene().Merge(props_scene);
}
// Rock prop:
{
@@ -488,7 +492,7 @@ void EditorComponent::Load()
prop.object.draw_distance = 400;
}
props_scene.Entity_Remove(object_entity); // The objects will be placed by terrain generator, we don't need the default object that the scene has anymore
- wi::scene::GetScene().Merge(props_scene);
+ GetCurrentScene().Merge(props_scene);
}
// Bush prop:
{
@@ -518,17 +522,17 @@ void EditorComponent::Load()
prop.object.draw_distance = 200;
}
props_scene.Entity_Remove(object_entity); // The objects will be placed by terrain generator, we don't need the default object that the scene has anymore
- wi::scene::GetScene().Merge(props_scene);
+ GetCurrentScene().Merge(props_scene);
}
terragen.init();
- RefreshSceneGraphView();
+ RefreshEntityTree();
}
terragen.SetVisible(!terragen.IsVisible());
- if (terragen.IsVisible() && !wi::scene::GetScene().transforms.Contains(terragen.terrainEntity))
+ if (terragen.IsVisible() && !GetCurrentScene().transforms.Contains(terragen.terrainEntity))
{
terragen.Generation_Restart();
- RefreshSceneGraphView();
+ RefreshEntityTree();
}
});
@@ -537,8 +541,8 @@ void EditorComponent::Load()
///////////////////////
- wi::Color option_color_idle = wi::Color(255, 145, 145, 100);
- wi::Color option_color_focus = wi::Color(255, 197, 193, 200);
+ wi::Color option_color_idle = wi::Color(100, 150, 150, 100);
+ wi::Color option_color_focus = wi::Color(100, 200, 200, 200);
weatherWnd_Toggle.Create("Weather");
@@ -708,7 +712,7 @@ void EditorComponent::Load()
translatorCheckBox.Create("Transform: ");
- translatorCheckBox.SetTooltip("Enable the transform tool.\nTip: hold Left Ctrl to enable snap transform.\nYou can configure snap mode units in the Transform settings.");
+ translatorCheckBox.SetTooltip("Enable the transform tool (Ctrl + T).\nTip: hold Left Ctrl to enable snap transform.\nYou can configure snap mode units in the Transform settings.");
translatorCheckBox.OnClick([&](wi::gui::EventArgs args) {
translator.enabled = args.bValue;
});
@@ -754,160 +758,110 @@ void EditorComponent::Load()
saveButton.Create("Save");
- saveButton.SetTooltip("Save the current scene");
- saveButton.SetColor(wi::Color(0, 198, 101, 180), wi::gui::WIDGETSTATE::IDLE);
- saveButton.SetColor(wi::Color(0, 255, 140, 255), wi::gui::WIDGETSTATE::FOCUS);
+ saveButton.SetTooltip("Save the current scene to a new file (Ctrl + Shift + S)");
+ saveButton.SetColor(wi::Color(50, 180, 100, 180), wi::gui::WIDGETSTATE::IDLE);
+ saveButton.SetColor(wi::Color(50, 220, 140, 255), wi::gui::WIDGETSTATE::FOCUS);
saveButton.OnClick([&](wi::gui::EventArgs args) {
-
- const bool dump_to_header = saveModeComboBox.GetSelected() == 2;
-
- wi::helper::FileDialogParams params;
- params.type = wi::helper::FileDialogParams::SAVE;
- if (dump_to_header)
- {
- params.description = "C++ header (.h)";
- params.extensions.push_back("h");
- }
- else
- {
- params.description = "Wicked Scene (.wiscene)";
- params.extensions.push_back("wiscene");
- }
- wi::helper::FileDialog(params, [=](std::string fileName) {
- wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) {
- std::string filename = wi::helper::ReplaceExtension(fileName, params.extensions.front());
- wi::Archive archive = dump_to_header ? wi::Archive() : wi::Archive(filename, false);
- if (archive.IsOpen())
- {
- Scene& scene = wi::scene::GetScene();
-
- wi::resourcemanager::Mode embed_mode = (wi::resourcemanager::Mode)saveModeComboBox.GetItemUserData(saveModeComboBox.GetSelected());
- wi::resourcemanager::SetMode(embed_mode);
-
- terragen.BakeVirtualTexturesToFiles();
- scene.Serialize(archive);
-
- if (dump_to_header)
- {
- archive.SaveHeaderFile(filename, wi::helper::RemoveExtension(wi::helper::GetFileNameFromPath(filename)));
- }
-
- ResetHistory();
- }
- else
- {
- wi::helper::messageBox("Could not create " + fileName + "!");
- }
- });
- });
+ SaveAs();
});
GetGUI().AddWidget(&saveButton);
- modelButton.Create("Load Model");
- modelButton.SetTooltip("Load a scene / import model into the editor...");
- modelButton.SetColor(wi::Color(0, 89, 255, 180), wi::gui::WIDGETSTATE::IDLE);
- modelButton.SetColor(wi::Color(112, 155, 255, 255), wi::gui::WIDGETSTATE::FOCUS);
- modelButton.OnClick([&](wi::gui::EventArgs args) {
+ openButton.Create("Open");
+ openButton.SetTooltip("Open a scene, import a model or execute a Lua script...");
+ openButton.SetColor(wi::Color(50, 100, 255, 180), wi::gui::WIDGETSTATE::IDLE);
+ openButton.SetColor(wi::Color(120, 160, 255, 255), wi::gui::WIDGETSTATE::FOCUS);
+ openButton.OnClick([&](wi::gui::EventArgs args) {
wi::helper::FileDialogParams params;
params.type = wi::helper::FileDialogParams::OPEN;
- params.description = "Model formats (.wiscene, .obj, .gltf, .glb)";
+ params.description = ".wiscene, .obj, .gltf, .glb, .lua";
params.extensions.push_back("wiscene");
params.extensions.push_back("obj");
params.extensions.push_back("gltf");
params.extensions.push_back("glb");
+ params.extensions.push_back("lua");
wi::helper::FileDialog(params, [&](std::string fileName) {
wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) {
- size_t camera_count_prev = wi::scene::GetScene().cameras.GetCount();
+ std::string extension = wi::helper::toUpper(wi::helper::GetExtensionFromFileName(fileName));
+ if (!extension.compare("LUA"))
+ {
+ wi::lua::RunFile(fileName);
+ return;
+ }
+
+ size_t camera_count_prev = GetCurrentScene().cameras.GetCount();
main->loader.addLoadingFunction([=](wi::jobsystem::JobArgs args) {
- std::string extension = wi::helper::toUpper(wi::helper::GetExtensionFromFileName(fileName));
if (!extension.compare("WISCENE")) // engine-serialized
{
- wi::scene::LoadModel(fileName);
+ wi::scene::LoadModel(GetCurrentScene(), fileName);
+ GetCurrentEditorScene().path = fileName;
}
else if (!extension.compare("OBJ")) // wavefront-obj
{
Scene scene;
ImportModel_OBJ(fileName, scene);
- wi::scene::GetScene().Merge(scene);
+ GetCurrentScene().Merge(scene);
}
else if (!extension.compare("GLTF")) // text-based gltf
{
Scene scene;
ImportModel_GLTF(fileName, scene);
- wi::scene::GetScene().Merge(scene);
+ GetCurrentScene().Merge(scene);
}
else if (!extension.compare("GLB")) // binary gltf
{
Scene scene;
ImportModel_GLTF(fileName, scene);
- wi::scene::GetScene().Merge(scene);
+ GetCurrentScene().Merge(scene);
}
});
main->loader.onFinished([=] {
// Detect when the new scene contains a new camera, and snap the camera onto it:
- size_t camera_count = wi::scene::GetScene().cameras.GetCount();
+ size_t camera_count = GetCurrentScene().cameras.GetCount();
if (camera_count > 0 && camera_count > camera_count_prev)
{
- Entity entity = wi::scene::GetScene().cameras.GetEntity(camera_count_prev);
+ Entity entity = GetCurrentScene().cameras.GetEntity(camera_count_prev);
if (entity != INVALID_ENTITY)
{
- TransformComponent* camera_transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* camera_transform = GetCurrentScene().transforms.GetComponent(entity);
if (camera_transform != nullptr)
{
- cameraWnd.camera_transform = *camera_transform;
+ GetCurrentEditorScene().camera_transform = *camera_transform;
}
- CameraComponent* cam = wi::scene::GetScene().cameras.GetComponent(entity);
+ CameraComponent* cam = GetCurrentScene().cameras.GetComponent(entity);
if (cam != nullptr)
{
- wi::scene::GetCamera() = *cam;
+ GetCurrentEditorScene().camera = *cam;
// camera aspect should be always for the current screen
- wi::scene::GetCamera().width = (float)renderPath->GetInternalResolution().x;
- wi::scene::GetCamera().height = (float)renderPath->GetInternalResolution().y;
+ GetCurrentEditorScene().camera.width = (float)renderPath->GetInternalResolution().x;
+ GetCurrentEditorScene().camera.height = (float)renderPath->GetInternalResolution().y;
}
}
}
main->ActivatePath(this, 0.2f, wi::Color::Black());
weatherWnd.Update();
- RefreshSceneGraphView();
+ RefreshEntityTree();
+ RefreshSceneList();
});
main->ActivatePath(&main->loader, 0.2f, wi::Color::Black());
ResetHistory();
});
});
});
- GetGUI().AddWidget(&modelButton);
+ GetGUI().AddWidget(&openButton);
- scriptButton.Create("Load Script");
- scriptButton.SetTooltip("Load a Lua script...");
- scriptButton.SetColor(wi::Color(255, 33, 140, 180), wi::gui::WIDGETSTATE::IDLE);
- scriptButton.SetColor(wi::Color(255, 100, 140, 255), wi::gui::WIDGETSTATE::FOCUS);
- scriptButton.OnClick([&](wi::gui::EventArgs args) {
- wi::helper::FileDialogParams params;
- params.type = wi::helper::FileDialogParams::OPEN;
- params.description = "Lua script";
- params.extensions.push_back("lua");
- wi::helper::FileDialog(params, [](std::string fileName) {
- wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) {
- wi::lua::RunFile(fileName);
- });
- });
- });
- GetGUI().AddWidget(&scriptButton);
-
-
- clearButton.Create("Clear World");
- clearButton.SetTooltip("Delete everything from the scene. This operation is not undoable!");
- clearButton.SetColor(wi::Color(255, 173, 43, 180), wi::gui::WIDGETSTATE::IDLE);
- clearButton.SetColor(wi::Color(255, 235, 173, 255), wi::gui::WIDGETSTATE::FOCUS);
- clearButton.OnClick([&](wi::gui::EventArgs args) {
+ closeButton.Create("Close");
+ closeButton.SetTooltip("Close the current scene.\nThis will clear everything from the currently selected scene, and delete the scene.\nThis operation cannot be undone!");
+ closeButton.SetColor(wi::Color(255, 130, 100, 180), wi::gui::WIDGETSTATE::IDLE);
+ closeButton.SetColor(wi::Color(255, 200, 150, 255), wi::gui::WIDGETSTATE::FOCUS);
+ closeButton.OnClick([&](wi::gui::EventArgs args) {
terragen.Generation_Cancel();
// This is to recreate the terragen from scratch, but it has implicitly deleted copy ctor so it's weird:
@@ -915,7 +869,7 @@ void EditorComponent::Load()
new (&terragen) TerrainGenerator;
translator.selected.clear();
- wi::scene::Scene& scene = wi::scene::GetScene();
+ wi::scene::Scene& scene = GetCurrentScene();
wi::renderer::ClearWorld(scene);
objectWnd.SetEntity(INVALID_ENTITY);
meshWnd.SetEntity(INVALID_ENTITY, -1);
@@ -935,65 +889,88 @@ void EditorComponent::Load()
layerWnd.SetEntity(INVALID_ENTITY);
nameWnd.SetEntity(INVALID_ENTITY);
- RefreshSceneGraphView();
+ RefreshEntityTree();
ResetHistory();
+ GetCurrentEditorScene().path.clear();
+
+ wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) {
+ if (scenes.size() > 1)
+ {
+ scenes.erase(scenes.begin() + current_scene);
+ }
+ SetCurrentScene(std::max(0, current_scene - 1));
+ });
});
- GetGUI().AddWidget(&clearButton);
+ GetGUI().AddWidget(&closeButton);
- helpButton.Create("?");
- helpButton.SetTooltip("Help");
- helpButton.SetColor(wi::Color(34, 158, 214, 180), wi::gui::WIDGETSTATE::IDLE);
- helpButton.SetColor(wi::Color(113, 183, 214, 255), wi::gui::WIDGETSTATE::FOCUS);
- helpButton.OnClick([&](wi::gui::EventArgs args) {
- helpLabel.SetVisible(!helpLabel.IsVisible());
+ aboutButton.Create("?");
+ aboutButton.SetTooltip("About...");
+ aboutButton.SetColor(wi::Color(50, 160, 200, 180), wi::gui::WIDGETSTATE::IDLE);
+ aboutButton.SetColor(wi::Color(120, 200, 200, 255), wi::gui::WIDGETSTATE::FOCUS);
+ aboutButton.OnClick([&](wi::gui::EventArgs args) {
+ aboutLabel.SetVisible(!aboutLabel.IsVisible());
});
- GetGUI().AddWidget(&helpButton);
+ GetGUI().AddWidget(&aboutButton);
{
std::string ss;
- ss += "Help:\n";
+ ss += "Wicked Engine Editor v";
+ ss += wi::version::GetVersionString();
+ ss += "\nCreated by Turánszki János";
+ ss += "\n\nWebsite: https://wickedengine.net/";
+ ss += "\nGithub page: https://github.com/turanszkij/WickedEngine";
+ ss += "\nDiscord chat: https://discord.gg/CFjRYmE";
+ ss += "\nYou can support the project on Patreon: https://www.patreon.com/wickedengine";
+ ss += "\n\nControls\n";
+ ss += "------------\n";
ss += "Move camera: WASD, or Contoller left stick or D-pad\n";
ss += "Look: Middle mouse button / arrow keys / controller right stick\n";
ss += "Select: Right mouse button\n";
ss += "Interact with water: Left mouse button when nothing is selected\n";
- ss += "Camera speed: Left Shift button or controller R2/RT\n";
+ ss += "Faster camera: Left Shift button or controller R2/RT\n";
ss += "Snap transform: Left Ctrl (hold while transforming)\n";
- ss += "Camera up: E, down: Q\n";
+ ss += "Camera up: E\n";
+ ss += "Camera down: Q\n";
ss += "Duplicate entity: Ctrl + D\n";
ss += "Select All: Ctrl + A\n";
- ss += "Deselect All: Escape\n";
+ ss += "Deselect All: Esc\n";
ss += "Undo: Ctrl + Z\n";
ss += "Redo: Ctrl + Y\n";
ss += "Copy: Ctrl + C\n";
ss += "Cut: Ctrl + X\n";
ss += "Paste: Ctrl + V\n";
ss += "Delete: Delete button\n";
+ ss += "Save As: Ctrl + Shift + S\n";
+ ss += "Save: Ctrl + S\n";
+ ss += "Transform: Ctrl + T\n";
ss += "Inspector mode: I button (hold), hovered entity information will be displayed near mouse position.\n";
ss += "Place Instances: Ctrl + Shift + Left mouse click (place clipboard onto clicked surface)\n";
ss += "Script Console / backlog: HOME button\n";
ss += "\n";
+ ss += "\nTips\n";
+ ss += "-------\n";
ss += "You can find sample scenes in the Content/models directory. Try to load one.\n";
ss += "You can also import models from .OBJ, .GLTF, .GLB files.\n";
+#ifndef PLATFORM_UWP
ss += "You can find a program configuration file at Editor/config.ini\n";
+#endif // PLATFORM_UWP
ss += "You can find sample LUA scripts in the Content/scripts directory. Try to load one.\n";
ss += "You can find a startup script at Editor/startup.lua (this will be executed on program start, if exists)\n";
ss += "\nFor questions, bug reports, feedback, requests, please open an issue at:\n";
- ss += "https://github.com/turanszkij/WickedEngine\n";
- ss += "\nDevblog: https://wickedengine.net/\n";
- ss += "Discord: https://discord.gg/CFjRYmE\n";
+ ss += "https://github.com/turanszkij/WickedEngine/issues\n";
- helpLabel.Create("HelpLabel");
- helpLabel.SetText(ss);
- helpLabel.SetVisible(false);
- helpLabel.SetColor(wi::Color(113, 183, 214, 100));
- GetGUI().AddWidget(&helpLabel);
+ aboutLabel.Create("AboutLabel");
+ aboutLabel.SetText(ss);
+ aboutLabel.SetVisible(false);
+ aboutLabel.SetColor(wi::Color(113, 183, 214, 100));
+ GetGUI().AddWidget(&aboutLabel);
}
exitButton.Create("X");
exitButton.SetTooltip("Exit");
- exitButton.SetColor(wi::Color(190, 0, 0, 180), wi::gui::WIDGETSTATE::IDLE);
- exitButton.SetColor(wi::Color(255, 0, 0, 255), wi::gui::WIDGETSTATE::FOCUS);
+ exitButton.SetColor(wi::Color(160, 50, 50, 180), wi::gui::WIDGETSTATE::IDLE);
+ exitButton.SetColor(wi::Color(200, 50, 50, 255), wi::gui::WIDGETSTATE::FOCUS);
exitButton.OnClick([this](wi::gui::EventArgs args) {
terragen.Generation_Cancel();
wi::platform::Exit();
@@ -1001,7 +978,7 @@ void EditorComponent::Load()
GetGUI().AddWidget(&exitButton);
- profilerEnabledCheckBox.Create("Profiler Enabled: ");
+ profilerEnabledCheckBox.Create("Profiler: ");
profilerEnabledCheckBox.SetTooltip("Toggle Profiler On/Off");
profilerEnabledCheckBox.OnClick([&](wi::gui::EventArgs args) {
wi::profiler::SetEnabled(args.bValue);
@@ -1009,7 +986,7 @@ void EditorComponent::Load()
profilerEnabledCheckBox.SetCheck(wi::profiler::IsEnabled());
GetGUI().AddWidget(&profilerEnabledCheckBox);
- physicsEnabledCheckBox.Create("Physics Simulation: ");
+ physicsEnabledCheckBox.Create("Physics: ");
physicsEnabledCheckBox.SetTooltip("Toggle Physics Simulation On/Off");
physicsEnabledCheckBox.OnClick([&](wi::gui::EventArgs args) {
wi::physics::SetSimulationEnabled(args.bValue);
@@ -1031,8 +1008,8 @@ void EditorComponent::Load()
GetGUI().AddWidget(&cinemaModeCheckBox);
- sceneGraphView.Create("Scene graph view");
- sceneGraphView.OnSelect([this](wi::gui::EventArgs args) {
+ entityTree.Create("Entities");
+ entityTree.OnSelect([this](wi::gui::EventArgs args) {
if (args.iValue < 0)
return;
@@ -1044,9 +1021,9 @@ void EditorComponent::Load()
translator.selected.clear();
- for (int i = 0; i < sceneGraphView.GetItemCount(); ++i)
+ for (int i = 0; i < entityTree.GetItemCount(); ++i)
{
- const wi::gui::TreeList::Item& item = sceneGraphView.GetItem(i);
+ const wi::gui::TreeList::Item& item = entityTree.GetItem(i);
if (item.selected)
{
wi::scene::PickResult pick;
@@ -1059,7 +1036,7 @@ void EditorComponent::Load()
RecordSelection(archive);
});
- GetGUI().AddWidget(&sceneGraphView);
+ GetGUI().AddWidget(&entityTree);
renderPathComboBox.Create("Render Path: ");
@@ -1074,9 +1051,23 @@ void EditorComponent::Load()
GetGUI().AddWidget(&renderPathComboBox);
+ sceneComboBox.Create("Scene: ");
+ sceneComboBox.OnSelect([&](wi::gui::EventArgs args) {
+ if (args.iValue >= int(scenes.size()))
+ {
+ NewScene();
+ }
+ SetCurrentScene(args.iValue);
+ });
+ sceneComboBox.SetEnabled(true);
+ sceneComboBox.SetColor(wi::Color(50, 100, 255, 180), wi::gui::WIDGETSTATE::IDLE);
+ sceneComboBox.SetColor(wi::Color(120, 160, 255, 255), wi::gui::WIDGETSTATE::FOCUS);
+ GetGUI().AddWidget(&sceneComboBox);
+
+
saveModeComboBox.Create("Save Mode: ");
- saveModeComboBox.SetColor(wi::Color(0, 198, 101, 180), wi::gui::WIDGETSTATE::IDLE);
- saveModeComboBox.SetColor(wi::Color(0, 255, 140, 255), wi::gui::WIDGETSTATE::FOCUS);
+ saveModeComboBox.SetColor(wi::Color(50, 180, 100, 180), wi::gui::WIDGETSTATE::IDLE);
+ saveModeComboBox.SetColor(wi::Color(50, 220, 140, 255), wi::gui::WIDGETSTATE::FOCUS);
saveModeComboBox.AddItem("Embed resources", (uint64_t)wi::resourcemanager::Mode::ALLOW_RETAIN_FILEDATA);
saveModeComboBox.AddItem("No embedding", (uint64_t)wi::resourcemanager::Mode::ALLOW_RETAIN_FILEDATA_BUT_DISABLE_EMBEDDING);
saveModeComboBox.AddItem("Dump to header", (uint64_t)wi::resourcemanager::Mode::ALLOW_RETAIN_FILEDATA);
@@ -1139,7 +1130,7 @@ void EditorComponent::Load()
wi::jobsystem::Wait(ctx);
- RenderPath2D::Load();
+ RenderPath2D::Load();
}
void EditorComponent::Start()
{
@@ -1161,10 +1152,12 @@ void EditorComponent::Update(float dt)
{
wi::profiler::range_id profrange = wi::profiler::BeginRangeCPU("Editor Update");
- Scene& scene = wi::scene::GetScene();
- CameraComponent& camera = wi::scene::GetCamera();
+ Scene& scene = GetCurrentScene();
+ EditorScene& editorscene = GetCurrentEditorScene();
+ CameraComponent& camera = editorscene.camera;
- translator.Update(camera, *this);
+ terragen.scene = &scene;
+ translator.scene = &scene;
if (scene.forces.Contains(grass_interaction_entity))
{
@@ -1202,9 +1195,9 @@ void EditorComponent::Update(float dt)
bool deleting = wi::input::Press(wi::input::KEYBOARD_BUTTON_DELETE);
// Camera control:
- XMFLOAT4 currentMouse = wi::input::GetPointer();
if (!wi::backlog::isActive() && !GetGUI().HasFocus())
{
+ XMFLOAT4 currentMouse = wi::input::GetPointer();
static XMFLOAT4 originalMouse = XMFLOAT4(0, 0, 0, 0);
static bool camControlStart = true;
if (camControlStart)
@@ -1273,7 +1266,7 @@ void EditorComponent::Update(float dt)
const float clampedDT = std::min(dt, 0.1f); // if dt > 100 millisec, don't allow the camera to jump too far...
const float speed = ((wi::input::Down(wi::input::KEYBOARD_BUTTON_LSHIFT) ? 10.0f : 1.0f) + rightTrigger.x * 10.0f) * cameraWnd.movespeedSlider.GetValue() * clampedDT;
- XMVECTOR move = XMLoadFloat3(&cameraWnd.move);
+ XMVECTOR move = XMLoadFloat3(&editorscene.cam_move);
XMVECTOR moveNew = XMVectorSet(leftStick.x, 0, leftStick.y, 0);
if (!wi::input::Down(wi::input::KEYBOARD_BUTTON_LCONTROL))
@@ -1299,17 +1292,17 @@ void EditorComponent::Update(float dt)
if (abs(xDif) + abs(yDif) > 0 || moveLength > 0.0001f)
{
- XMMATRIX camRot = XMMatrixRotationQuaternion(XMLoadFloat4(&cameraWnd.camera_transform.rotation_local));
+ XMMATRIX camRot = XMMatrixRotationQuaternion(XMLoadFloat4(&editorscene.camera_transform.rotation_local));
XMVECTOR move_rot = XMVector3TransformNormal(move, camRot);
XMFLOAT3 _move;
XMStoreFloat3(&_move, move_rot);
- cameraWnd.camera_transform.Translate(_move);
- cameraWnd.camera_transform.RotateRollPitchYaw(XMFLOAT3(yDif, xDif, 0));
+ editorscene.camera_transform.Translate(_move);
+ editorscene.camera_transform.RotateRollPitchYaw(XMFLOAT3(yDif, xDif, 0));
camera.SetDirty();
}
- cameraWnd.camera_transform.UpdateTransform();
- XMStoreFloat3(&cameraWnd.move, move);
+ editorscene.camera_transform.UpdateTransform();
+ XMStoreFloat3(&editorscene.cam_move, move);
}
else
{
@@ -1320,29 +1313,29 @@ void EditorComponent::Update(float dt)
XMVECTOR V = XMVectorAdd(camera.GetRight() * xDif, camera.GetUp() * yDif) * 10;
XMFLOAT3 vec;
XMStoreFloat3(&vec, V);
- cameraWnd.camera_target.Translate(vec);
+ editorscene.camera_target.Translate(vec);
}
else if (wi::input::Down(wi::input::KEYBOARD_BUTTON_LCONTROL) || currentMouse.z != 0.0f)
{
- cameraWnd.camera_transform.Translate(XMFLOAT3(0, 0, yDif * 4 + currentMouse.z));
- cameraWnd.camera_transform.translation_local.z = std::min(0.0f, cameraWnd.camera_transform.translation_local.z);
+ editorscene.camera_transform.Translate(XMFLOAT3(0, 0, yDif * 4 + currentMouse.z));
+ editorscene.camera_transform.translation_local.z = std::min(0.0f, editorscene.camera_transform.translation_local.z);
camera.SetDirty();
}
else if (abs(xDif) + abs(yDif) > 0)
{
- cameraWnd.camera_target.RotateRollPitchYaw(XMFLOAT3(yDif * 2, xDif * 2, 0));
+ editorscene.camera_target.RotateRollPitchYaw(XMFLOAT3(yDif * 2, xDif * 2, 0));
camera.SetDirty();
}
- cameraWnd.camera_target.UpdateTransform();
- cameraWnd.camera_transform.UpdateTransform_Parented(cameraWnd.camera_target);
+ editorscene.camera_target.UpdateTransform();
+ editorscene.camera_transform.UpdateTransform_Parented(editorscene.camera_target);
}
inspector_mode = wi::input::Down((wi::input::BUTTON)'I');
// Begin picking:
unsigned int pickMask = rendererWnd.GetPickType();
- Ray pickRay = wi::renderer::GetPickRay((long)currentMouse.x, (long)currentMouse.y, *this);
+ Ray pickRay = wi::renderer::GetPickRay((long)currentMouse.x, (long)currentMouse.y, *this, camera);
{
hovered = wi::scene::PickResult();
@@ -1513,7 +1506,7 @@ void EditorComponent::Update(float dt)
inspector_mode
)
{
- hovered = wi::scene::Pick(pickRay, pickMask);
+ hovered = wi::scene::Pick(pickRay, pickMask, ~0u, scene);
}
}
}
@@ -1537,14 +1530,14 @@ void EditorComponent::Update(float dt)
// if not water or softbody, put a decal on it:
static int decalselector = 0;
decalselector = (decalselector + 1) % 2;
- Entity entity = scene.Entity_CreateDecal("editorDecal", (decalselector == 0 ? "images/leaf.dds" : "images/blood1.png"));
+ Entity entity = scene.Entity_CreateDecal("editorDecal", (decalselector == 0 ? "images/leaf.dds" : "images/logo_small.png"));
TransformComponent& transform = *scene.transforms.GetComponent(entity);
transform.MatrixTransform(hovered.orientation);
transform.RotateRollPitchYaw(XMFLOAT3(XM_PIDIV2, 0, 0));
transform.Scale(XMFLOAT3(2, 2, 2));
scene.Component_Attach(entity, hovered.entity);
- RefreshSceneGraphView();
+ RefreshEntityTree();
}
else
{
@@ -1636,12 +1629,30 @@ void EditorComponent::Update(float dt)
// record NEW selection state...
RecordSelection(archive);
- RefreshSceneGraphView();
+ RefreshEntityTree();
}
// Control operations...
if (wi::input::Down(wi::input::KEYBOARD_BUTTON_LCONTROL))
{
+ // Enable transform tool
+ if (wi::input::Press((wi::input::BUTTON)'T'))
+ {
+ translator.enabled = !translator.enabled;
+ translatorCheckBox.SetCheck(translator.enabled);
+ }
+ // Save
+ if (wi::input::Press((wi::input::BUTTON)'S'))
+ {
+ if (wi::input::Down(wi::input::KEYBOARD_BUTTON_LSHIFT) || GetCurrentEditorScene().path.empty())
+ {
+ SaveAs();
+ }
+ else
+ {
+ Save(GetCurrentEditorScene().path);
+ }
+ }
// Select All
if (wi::input::Press((wi::input::BUTTON)'A'))
{
@@ -1682,7 +1693,7 @@ void EditorComponent::Update(float dt)
for (size_t i = 0; i < count; ++i)
{
wi::scene::PickResult picked;
- picked.entity = scene.Entity_Serialize(clipboard, seri, INVALID_ENTITY, Scene::EntitySerializeFlags::RECURSIVE | Scene::EntitySerializeFlags::KEEP_INTERNAL_ENTITY_REFERENCES);
+ picked.entity = scene.Entity_Serialize(clipboard, seri, INVALID_ENTITY, Scene::EntitySerializeFlags::RECURSIVE);
AddSelected(picked);
addedEntities.push_back(picked.entity);
}
@@ -1690,7 +1701,7 @@ void EditorComponent::Update(float dt)
RecordSelection(archive);
RecordAddedEntity(archive, addedEntities);
- RefreshSceneGraphView();
+ RefreshEntityTree();
}
// Duplicate Instances
if (wi::input::Press((wi::input::BUTTON)'D'))
@@ -1718,7 +1729,7 @@ void EditorComponent::Update(float dt)
RecordSelection(archive);
RecordAddedEntity(archive, addedEntities);
- RefreshSceneGraphView();
+ RefreshEntityTree();
}
// Put Instances
if (clipboard.IsOpen() && hovered.subsetIndex >= 0 && wi::input::Down(wi::input::KEYBOARD_BUTTON_LSHIFT) && wi::input::Press(wi::input::MOUSE_BUTTON_LEFT))
@@ -1764,21 +1775,21 @@ void EditorComponent::Update(float dt)
RecordSelection(archive);
RecordAddedEntity(archive, addedEntities);
- RefreshSceneGraphView();
+ RefreshEntityTree();
}
// Undo
if (wi::input::Press((wi::input::BUTTON)'Z'))
{
ConsumeHistoryOperation(true);
- RefreshSceneGraphView();
+ RefreshEntityTree();
}
// Redo
if (wi::input::Press((wi::input::BUTTON)'Y'))
{
ConsumeHistoryOperation(false);
- RefreshSceneGraphView();
+ RefreshEntityTree();
}
}
@@ -1804,7 +1815,7 @@ void EditorComponent::Update(float dt)
ClearSelected();
- RefreshSceneGraphView();
+ RefreshEntityTree();
}
// Update window data bindings...
@@ -1931,12 +1942,12 @@ void EditorComponent::Update(float dt)
TransformComponent* proxy = scene.transforms.GetComponent(cameraWnd.proxy);
if (proxy != nullptr)
{
- cameraWnd.camera_transform.Lerp(cameraWnd.camera_transform, *proxy, 1.0f - cameraWnd.followSlider.GetValue());
- cameraWnd.camera_transform.UpdateTransform();
+ editorscene.camera_transform.Lerp(editorscene.camera_transform, *proxy, 1.0f - cameraWnd.followSlider.GetValue());
+ editorscene.camera_transform.UpdateTransform();
}
}
- camera.TransformCamera(cameraWnd.camera_transform);
+ camera.TransformCamera(editorscene.camera_transform);
camera.UpdateCamera();
wi::RenderPath3D_PathTracing* pathtracer = dynamic_cast(renderPath.get());
@@ -1956,7 +1967,7 @@ void EditorComponent::Update(float dt)
}
else
{
- ss += "Denoiser not available\n";
+ ss += "Denoiser not available!\nTo find out how to enable the denoiser, visit the documentation.";
}
pathTraceStatisticsLabel.SetText(ss);
}
@@ -1967,6 +1978,8 @@ void EditorComponent::Update(float dt)
RenderPath2D::Update(dt);
+ translator.Update(camera, *this);
+
renderPath->colorspace = colorspace;
renderPath->Update(dt);
}
@@ -1978,7 +1991,7 @@ void EditorComponent::PostUpdate()
}
void EditorComponent::Render() const
{
- Scene& scene = wi::scene::GetScene();
+ const Scene& scene = GetCurrentScene();
// Hovered item boxes:
if (!cinemaModeCheckBox.GetCheck())
@@ -2187,9 +2200,9 @@ void EditorComponent::Render() const
const XMFLOAT4 glow = wi::math::Lerp(wi::math::Lerp(XMFLOAT4(1, 1, 1, 1), selectionColor, 0.4f), selectionColor, selectionColorIntensity);
const wi::Color selectedEntityColor = wi::Color::fromFloat4(glow);
- const CameraComponent& camera = wi::scene::GetCamera();
+ const CameraComponent& camera = GetCurrentEditorScene().camera;
- Scene& scene = wi::scene::GetScene();
+ const Scene& scene = GetCurrentScene();
// remove camera jittering
CameraComponent cam = *renderPath->camera;
@@ -2243,7 +2256,6 @@ void EditorComponent::Render() const
wi::image::Draw(&dirLightTex.GetTexture(), fx, cmd);
break;
default:
- wi::image::Draw(&areaLightTex.GetTexture(), fx, cmd);
break;
}
}
@@ -2554,7 +2566,7 @@ void EditorComponent::Render() const
}
- translator.Draw(wi::scene::GetCamera(), cmd);
+ translator.Draw(GetCurrentEditorScene().camera, cmd);
device->RenderPassEnd(cmd);
}
@@ -2572,19 +2584,19 @@ void EditorComponent::Compose(CommandList cmd) const
RenderPath2D::Compose(cmd);
}
-void EditorComponent::PushToSceneGraphView(wi::ecs::Entity entity, int level)
+void EditorComponent::PushToEntityTree(wi::ecs::Entity entity, int level)
{
- if (scenegraphview_added_items.count(entity) != 0)
+ if (entitytree_added_items.count(entity) != 0)
{
return;
}
- const Scene& scene = wi::scene::GetScene();
+ const Scene& scene = GetCurrentScene();
wi::gui::TreeList::Item item;
item.level = level;
item.userdata = entity;
item.selected = IsSelected(entity);
- item.open = scenegraphview_opened_items.count(entity) != 0;
+ item.open = entitytree_opened_items.count(entity) != 0;
const NameComponent* name = scene.names.GetComponent(entity);
if (name == nullptr)
{
@@ -2598,50 +2610,50 @@ void EditorComponent::PushToSceneGraphView(wi::ecs::Entity entity, int level)
{
item.name = name->name;
}
- sceneGraphView.AddItem(item);
+ entityTree.AddItem(item);
- scenegraphview_added_items.insert(entity);
+ entitytree_added_items.insert(entity);
for (size_t i = 0; i < scene.hierarchy.GetCount(); ++i)
{
if (scene.hierarchy[i].parentID == entity)
{
- PushToSceneGraphView(scene.hierarchy.GetEntity(i), level + 1);
+ PushToEntityTree(scene.hierarchy.GetEntity(i), level + 1);
}
}
}
-void EditorComponent::RefreshSceneGraphView()
+void EditorComponent::RefreshEntityTree()
{
- const Scene& scene = wi::scene::GetScene();
+ const Scene& scene = GetCurrentScene();
- for (int i = 0; i < sceneGraphView.GetItemCount(); ++i)
+ for (int i = 0; i < entityTree.GetItemCount(); ++i)
{
- const wi::gui::TreeList::Item& item = sceneGraphView.GetItem(i);
+ const wi::gui::TreeList::Item& item = entityTree.GetItem(i);
if (item.open)
{
- scenegraphview_opened_items.insert((Entity)item.userdata);
+ entitytree_opened_items.insert((Entity)item.userdata);
}
}
- sceneGraphView.ClearItems();
+ entityTree.ClearItems();
// Add hierarchy:
for (size_t i = 0; i < scene.hierarchy.GetCount(); ++i)
{
- PushToSceneGraphView(scene.hierarchy[i].parentID, 0);
+ PushToEntityTree(scene.hierarchy[i].parentID, 0);
}
// Any transform left that is not part of a hierarchy:
for (size_t i = 0; i < scene.transforms.GetCount(); ++i)
{
- PushToSceneGraphView(scene.transforms.GetEntity(i), 0);
+ PushToEntityTree(scene.transforms.GetEntity(i), 0);
}
// Add materials:
for (size_t i = 0; i < scene.materials.GetCount(); ++i)
{
Entity entity = scene.materials.GetEntity(i);
- if (scenegraphview_added_items.count(entity) != 0)
+ if (entitytree_added_items.count(entity) != 0)
{
continue;
}
@@ -2649,19 +2661,19 @@ void EditorComponent::RefreshSceneGraphView()
wi::gui::TreeList::Item item;
item.userdata = entity;
item.selected = IsSelected(entity);
- item.open = scenegraphview_opened_items.count(entity) != 0;
+ item.open = entitytree_opened_items.count(entity) != 0;
const NameComponent* name = scene.names.GetComponent(entity);
item.name = name == nullptr ? std::to_string(entity) : name->name;
- sceneGraphView.AddItem(item);
+ entityTree.AddItem(item);
- scenegraphview_added_items.insert(entity);
+ entitytree_added_items.insert(entity);
}
// Add meshes:
for (size_t i = 0; i < scene.meshes.GetCount(); ++i)
{
Entity entity = scene.meshes.GetEntity(i);
- if (scenegraphview_added_items.count(entity) != 0)
+ if (entitytree_added_items.count(entity) != 0)
{
continue;
}
@@ -2669,16 +2681,16 @@ void EditorComponent::RefreshSceneGraphView()
wi::gui::TreeList::Item item;
item.userdata = entity;
item.selected = IsSelected(entity);
- item.open = scenegraphview_opened_items.count(entity) != 0;
+ item.open = entitytree_opened_items.count(entity) != 0;
const NameComponent* name = scene.names.GetComponent(entity);
item.name = name == nullptr ? std::to_string(entity) : name->name;
- sceneGraphView.AddItem(item);
+ entityTree.AddItem(item);
- scenegraphview_added_items.insert(entity);
+ entitytree_added_items.insert(entity);
}
- scenegraphview_added_items.clear();
- scenegraphview_opened_items.clear();
+ entitytree_added_items.clear();
+ entitytree_opened_items.clear();
}
void EditorComponent::ClearSelected()
@@ -2735,14 +2747,14 @@ void EditorComponent::RecordSelection(wi::Archive& archive) const
archive << x.distance;
}
}
-void EditorComponent::RecordAddedEntity(wi::Archive& archive, wi::ecs::Entity entity) const
+void EditorComponent::RecordAddedEntity(wi::Archive& archive, wi::ecs::Entity entity)
{
const wi::vector entities = { entity };
RecordAddedEntity(archive, entities);
}
-void EditorComponent::RecordAddedEntity(wi::Archive& archive, const wi::vector& entities) const
+void EditorComponent::RecordAddedEntity(wi::Archive& archive, const wi::vector& entities)
{
- Scene& scene = GetScene();
+ Scene& scene = GetCurrentScene();
EntitySerializer seri;
archive << entities;
@@ -2754,35 +2766,39 @@ void EditorComponent::RecordAddedEntity(wi::Archive& archive, const wi::vector(history.size()) > historyPos)
+ while (static_cast(editorscene.history.size()) > editorscene.historyPos)
{
- history.pop_back();
+ editorscene.history.pop_back();
}
- history.emplace_back();
- history.back().SetReadModeAndResetPos(false);
+ editorscene.history.emplace_back();
+ editorscene.history.back().SetReadModeAndResetPos(false);
- return history.back();
+ return editorscene.history.back();
}
void EditorComponent::ConsumeHistoryOperation(bool undo)
{
- if ((undo && historyPos >= 0) || (!undo && historyPos < (int)history.size() - 1))
+ EditorScene& editorscene = GetCurrentEditorScene();
+
+ if ((undo && editorscene.historyPos >= 0) || (!undo && editorscene.historyPos < (int)editorscene.history.size() - 1))
{
if (!undo)
{
- historyPos++;
+ editorscene.historyPos++;
}
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = GetCurrentScene();
- wi::Archive& archive = history[historyPos];
+ wi::Archive& archive = editorscene.history[editorscene.historyPos];
archive.SetReadModeAndResetPos(true);
int temp;
@@ -2977,11 +2993,67 @@ void EditorComponent::ConsumeHistoryOperation(bool undo)
if (undo)
{
- historyPos--;
+ editorscene.historyPos--;
}
scene.Update(0);
}
- RefreshSceneGraphView();
+ RefreshEntityTree();
+}
+
+void EditorComponent::Save(const std::string& filename)
+{
+ const bool dump_to_header = saveModeComboBox.GetSelected() == 2;
+
+ wi::Archive archive = dump_to_header ? wi::Archive() : wi::Archive(filename, false);
+ if (archive.IsOpen())
+ {
+ Scene& scene = GetCurrentScene();
+
+ wi::resourcemanager::Mode embed_mode = (wi::resourcemanager::Mode)saveModeComboBox.GetItemUserData(saveModeComboBox.GetSelected());
+ wi::resourcemanager::SetMode(embed_mode);
+
+ terragen.BakeVirtualTexturesToFiles();
+ scene.Serialize(archive);
+
+ if (dump_to_header)
+ {
+ archive.SaveHeaderFile(filename, wi::helper::RemoveExtension(wi::helper::GetFileNameFromPath(filename)));
+ }
+
+ GetCurrentEditorScene().path = filename;
+ }
+ else
+ {
+ wi::helper::messageBox("Could not create " + filename + "!");
+ return;
+ }
+
+ RefreshSceneList();
+
+ wi::backlog::post("Scene " + std::to_string(current_scene) + " saved: " + GetCurrentEditorScene().path);
+}
+void EditorComponent::SaveAs()
+{
+ const bool dump_to_header = saveModeComboBox.GetSelected() == 2;
+
+ wi::helper::FileDialogParams params;
+ params.type = wi::helper::FileDialogParams::SAVE;
+ if (dump_to_header)
+ {
+ params.description = "C++ header (.h)";
+ params.extensions.push_back("h");
+ }
+ else
+ {
+ params.description = "Wicked Scene (.wiscene)";
+ params.extensions.push_back("wiscene");
+ }
+ wi::helper::FileDialog(params, [=](std::string fileName) {
+ wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) {
+ std::string filename = wi::helper::ReplaceExtension(fileName, params.extensions.front());
+ Save(filename);
+ });
+ });
}
diff --git a/Editor/Editor.h b/Editor/Editor.h
index 1803110de..665ecdca6 100644
--- a/Editor/Editor.h
+++ b/Editor/Editor.h
@@ -2,6 +2,7 @@
#include "WickedEngine.h"
#include "Translator.h"
#include "TerrainGenerator.h"
+#include "wiScene_BindLua.h"
#include "MaterialWindow.h"
#include "PostprocessWindow.h"
@@ -39,7 +40,7 @@ class Editor;
class EditorComponent : public wi::RenderPath2D
{
private:
- wi::Resource pointLightTex, spotLightTex, dirLightTex, areaLightTex, decalTex, forceFieldTex, emitterTex, hairTex, cameraTex, armatureTex, soundTex;
+ wi::Resource pointLightTex, spotLightTex, dirLightTex, decalTex, forceFieldTex, emitterTex, hairTex, cameraTex, armatureTex, soundTex;
public:
MaterialWindow materialWnd;
PostprocessWindow postprocessWnd;
@@ -94,22 +95,22 @@ public:
wi::gui::CheckBox isTranslatorCheckBox;
wi::gui::Button saveButton;
wi::gui::ComboBox saveModeComboBox;
- wi::gui::Button modelButton;
- wi::gui::Button scriptButton;
- wi::gui::Button clearButton;
- wi::gui::Button helpButton;
+ wi::gui::Button openButton;
+ wi::gui::Button closeButton;
+ wi::gui::Button aboutButton;
wi::gui::Button exitButton;
wi::gui::CheckBox profilerEnabledCheckBox;
wi::gui::CheckBox physicsEnabledCheckBox;
wi::gui::CheckBox cinemaModeCheckBox;
wi::gui::ComboBox renderPathComboBox;
- wi::gui::Label helpLabel;
+ wi::gui::ComboBox sceneComboBox;
+ wi::gui::Label aboutLabel;
- wi::gui::TreeList sceneGraphView;
- wi::unordered_set scenegraphview_added_items;
- wi::unordered_set scenegraphview_opened_items;
- void PushToSceneGraphView(wi::ecs::Entity entity, int level);
- void RefreshSceneGraphView();
+ wi::gui::TreeList entityTree;
+ wi::unordered_set entitytree_added_items;
+ wi::unordered_set entitytree_opened_items;
+ void PushToEntityTree(wi::ecs::Entity entity, int level);
+ void RefreshEntityTree();
wi::gui::Slider pathTraceTargetSlider;
wi::gui::Label pathTraceStatisticsLabel;
@@ -165,8 +166,6 @@ public:
wi::Archive clipboard;
- wi::vector history;
- int historyPos = -1;
enum HistoryOperationType
{
HISTORYOP_TRANSLATOR,
@@ -178,12 +177,73 @@ public:
};
void RecordSelection(wi::Archive& archive) const;
- void RecordAddedEntity(wi::Archive& archive, wi::ecs::Entity entity) const;
- void RecordAddedEntity(wi::Archive& archive, const wi::vector& entities) const;
+ void RecordAddedEntity(wi::Archive& archive, wi::ecs::Entity entity);
+ void RecordAddedEntity(wi::Archive& archive, const wi::vector& entities);
void ResetHistory();
wi::Archive& AdvanceHistory();
void ConsumeHistoryOperation(bool undo);
+
+ void Save(const std::string& filename);
+ void SaveAs();
+
+ struct EditorScene
+ {
+ std::string path;
+ wi::scene::Scene scene;
+ XMFLOAT3 cam_move = {};
+ wi::scene::CameraComponent camera;
+ wi::scene::TransformComponent camera_transform;
+ wi::scene::TransformComponent camera_target;
+ wi::vector history;
+ int historyPos = -1;
+ };
+ wi::vector> scenes;
+ int current_scene = 0;
+ EditorScene& GetCurrentEditorScene() { return *scenes[current_scene].get(); }
+ const EditorScene& GetCurrentEditorScene() const { return *scenes[current_scene].get(); }
+ wi::scene::Scene& GetCurrentScene() { return scenes[current_scene].get()->scene; }
+ const wi::scene::Scene& GetCurrentScene() const { return scenes[current_scene].get()->scene; }
+ void SetCurrentScene(int index)
+ {
+ current_scene = index;
+ this->renderPath->scene = &scenes[current_scene].get()->scene;
+ this->renderPath->camera = &scenes[current_scene].get()->camera;
+ wi::lua::scene::SetGlobalScene(this->renderPath->scene);
+ wi::lua::scene::SetGlobalCamera(this->renderPath->camera);
+ RefreshEntityTree();
+ RefreshSceneList();
+ }
+ void RefreshSceneList()
+ {
+ sceneComboBox.ClearItems();
+ for (int i = 0; i < int(scenes.size()); ++i)
+ {
+ if (scenes[i]->path.empty())
+ {
+ sceneComboBox.AddItem("Untitled");
+ }
+ else
+ {
+ sceneComboBox.AddItem(wi::helper::RemoveExtension(wi::helper::GetFileNameFromPath(scenes[i]->path)));
+ }
+ }
+ sceneComboBox.AddItem("[New]");
+ sceneComboBox.SetSelectedWithoutCallback(current_scene);
+ std::string tooltip = "Choose a scene";
+ if (!GetCurrentEditorScene().path.empty())
+ {
+ tooltip += "\nCurrent path: " + GetCurrentEditorScene().path;
+ }
+ sceneComboBox.SetTooltip(tooltip);
+ }
+ void NewScene()
+ {
+ scenes.push_back(std::make_unique());
+ SetCurrentScene(int(scenes.size()) - 1);
+ RefreshSceneList();
+ cameraWnd.ResetCam();
+ }
};
class Editor : public wi::Application
diff --git a/Editor/Editor_SOURCE.vcxitems b/Editor/Editor_SOURCE.vcxitems
index ffc0758de..15601d3d8 100644
--- a/Editor/Editor_SOURCE.vcxitems
+++ b/Editor/Editor_SOURCE.vcxitems
@@ -179,18 +179,10 @@
-
- true
- true
-
true
true
-
- true
- true
-
true
true
diff --git a/Editor/Editor_SOURCE.vcxitems.filters b/Editor/Editor_SOURCE.vcxitems.filters
index 7f48632cb..8736a0717 100644
--- a/Editor/Editor_SOURCE.vcxitems.filters
+++ b/Editor/Editor_SOURCE.vcxitems.filters
@@ -134,15 +134,9 @@
-
- images
-
images
-
- images
-
images
diff --git a/Editor/EmitterWindow.cpp b/Editor/EmitterWindow.cpp
index 643f9a025..0e4f99ad1 100644
--- a/Editor/EmitterWindow.cpp
+++ b/Editor/EmitterWindow.cpp
@@ -7,8 +7,9 @@
using namespace wi::ecs;
using namespace wi::scene;
-void EmitterWindow::Create(EditorComponent* editor)
+void EmitterWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Emitter Window");
SetSize(XMFLOAT2(680, 420));
@@ -22,12 +23,12 @@ void EmitterWindow::Create(EditorComponent* editor)
emitterNameField.SetPos(XMFLOAT2(x, y));
emitterNameField.SetSize(XMFLOAT2(300, itemheight));
emitterNameField.OnInputAccepted([=](wi::gui::EventArgs args) {
- NameComponent* name = wi::scene::GetScene().names.GetComponent(entity);
+ NameComponent* name = editor->GetCurrentScene().names.GetComponent(entity);
if (name != nullptr)
{
*name = args.sValue;
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
}
});
AddWidget(&emitterNameField);
@@ -36,7 +37,7 @@ void EmitterWindow::Create(EditorComponent* editor)
addButton.SetPos(XMFLOAT2(x, y += step));
addButton.SetSize(XMFLOAT2(150, itemheight));
addButton.OnClick([=](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
Entity entity = scene.Entity_CreateEmitter("editorEmitter");
wi::Archive& archive = editor->AdvanceHistory();
@@ -49,7 +50,7 @@ void EmitterWindow::Create(EditorComponent* editor)
editor->RecordSelection(archive);
editor->RecordAddedEntity(archive, entity);
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
SetEntity(entity);
});
addButton.SetTooltip("Add new emitter particle system.");
@@ -82,7 +83,7 @@ void EmitterWindow::Create(EditorComponent* editor)
}
else
{
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
emitter->meshID = scene.meshes.GetEntity(args.iValue - 1);
}
}
@@ -746,7 +747,7 @@ wi::EmittedParticleSystem* EmitterWindow::GetEmitter()
return nullptr;
}
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
wi::EmittedParticleSystem* emitter = scene.emitters.GetComponent(entity);
return emitter;
@@ -760,7 +761,7 @@ void EmitterWindow::UpdateData()
return;
}
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
meshComboBox.ClearItems();
meshComboBox.AddItem("NO MESH");
diff --git a/Editor/EmitterWindow.h b/Editor/EmitterWindow.h
index f150a4ba6..bbe9425fd 100644
--- a/Editor/EmitterWindow.h
+++ b/Editor/EmitterWindow.h
@@ -10,6 +10,7 @@ class EmitterWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/EnvProbeWindow.cpp b/Editor/EnvProbeWindow.cpp
index eff080aca..58aaf7dd2 100644
--- a/Editor/EnvProbeWindow.cpp
+++ b/Editor/EnvProbeWindow.cpp
@@ -5,8 +5,9 @@
using namespace wi::ecs;
using namespace wi::scene;
-void EnvProbeWindow::Create(EditorComponent* editor)
+void EnvProbeWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Environment Probe Window");
SetSize(XMFLOAT2(420, 220));
@@ -25,7 +26,7 @@ void EnvProbeWindow::Create(EditorComponent* editor)
realTimeCheckBox.SetPos(XMFLOAT2(x + 100, y));
realTimeCheckBox.SetEnabled(false);
realTimeCheckBox.OnClick([&](wi::gui::EventArgs args) {
- EnvironmentProbeComponent* probe = wi::scene::GetScene().probes.GetComponent(entity);
+ EnvironmentProbeComponent* probe = editor->GetCurrentScene().probes.GetComponent(entity);
if (probe != nullptr)
{
probe->SetRealTime(args.bValue);
@@ -39,7 +40,7 @@ void EnvProbeWindow::Create(EditorComponent* editor)
msaaCheckBox.SetPos(XMFLOAT2(x + 200, y));
msaaCheckBox.SetEnabled(false);
msaaCheckBox.OnClick([&](wi::gui::EventArgs args) {
- EnvironmentProbeComponent* probe = wi::scene::GetScene().probes.GetComponent(entity);
+ EnvironmentProbeComponent* probe = editor->GetCurrentScene().probes.GetComponent(entity);
if (probe != nullptr)
{
probe->SetMSAA(args.bValue);
@@ -53,8 +54,8 @@ void EnvProbeWindow::Create(EditorComponent* editor)
generateButton.SetPos(XMFLOAT2(x, y += step));
generateButton.OnClick([=](wi::gui::EventArgs args) {
XMFLOAT3 pos;
- XMStoreFloat3(&pos, XMVectorAdd(wi::scene::GetCamera().GetEye(), wi::scene::GetCamera().GetAt() * 4));
- Entity entity = wi::scene::GetScene().Entity_CreateEnvironmentProbe("editorProbe", pos);
+ XMStoreFloat3(&pos, XMVectorAdd(editor->GetCurrentEditorScene().camera.GetEye(), editor->GetCurrentEditorScene().camera.GetAt() * 4));
+ Entity entity = editor->GetCurrentScene().Entity_CreateEnvironmentProbe("editorProbe", pos);
wi::Archive& archive = editor->AdvanceHistory();
archive << EditorComponent::HISTORYOP_ADD;
@@ -66,7 +67,7 @@ void EnvProbeWindow::Create(EditorComponent* editor)
editor->RecordSelection(archive);
editor->RecordAddedEntity(archive, entity);
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
SetEntity(entity);
});
AddWidget(&generateButton);
@@ -76,7 +77,7 @@ void EnvProbeWindow::Create(EditorComponent* editor)
refreshButton.SetPos(XMFLOAT2(x + 120, y));
refreshButton.SetEnabled(false);
refreshButton.OnClick([&](wi::gui::EventArgs args) {
- EnvironmentProbeComponent* probe = wi::scene::GetScene().probes.GetComponent(entity);
+ EnvironmentProbeComponent* probe = editor->GetCurrentScene().probes.GetComponent(entity);
if (probe != nullptr)
{
probe->SetDirty();
@@ -89,7 +90,7 @@ void EnvProbeWindow::Create(EditorComponent* editor)
refreshAllButton.SetPos(XMFLOAT2(x + 240, y));
refreshAllButton.SetEnabled(true);
refreshAllButton.OnClick([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
for (size_t i = 0; i < scene.probes.GetCount(); ++i)
{
EnvironmentProbeComponent& probe = scene.probes[i];
@@ -111,7 +112,7 @@ void EnvProbeWindow::SetEntity(Entity entity)
{
this->entity = entity;
- const EnvironmentProbeComponent* probe = wi::scene::GetScene().probes.GetComponent(entity);
+ const EnvironmentProbeComponent* probe = editor->GetCurrentScene().probes.GetComponent(entity);
if (probe == nullptr)
{
diff --git a/Editor/EnvProbeWindow.h b/Editor/EnvProbeWindow.h
index ccfc7e533..7434e4368 100644
--- a/Editor/EnvProbeWindow.h
+++ b/Editor/EnvProbeWindow.h
@@ -8,6 +8,7 @@ class EnvProbeWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/ForceFieldWindow.cpp b/Editor/ForceFieldWindow.cpp
index a67fef5e6..67f31ee87 100644
--- a/Editor/ForceFieldWindow.cpp
+++ b/Editor/ForceFieldWindow.cpp
@@ -6,8 +6,9 @@ using namespace wi::ecs;
using namespace wi::scene;
-void ForceFieldWindow::Create(EditorComponent* editor)
+void ForceFieldWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Force Field Window");
SetSize(XMFLOAT2(420, 120));
@@ -20,8 +21,8 @@ void ForceFieldWindow::Create(EditorComponent* editor)
addButton.SetSize(XMFLOAT2(150, hei));
addButton.SetPos(XMFLOAT2(x, y));
addButton.OnClick([=](wi::gui::EventArgs args) {
- Entity entity = wi::scene::GetScene().Entity_CreateForce("editorForce");
- ForceFieldComponent* force = wi::scene::GetScene().forces.GetComponent(entity);
+ Entity entity = editor->GetCurrentScene().Entity_CreateForce("editorForce");
+ ForceFieldComponent* force = editor->GetCurrentScene().forces.GetComponent(entity);
if (force != nullptr)
{
switch (typeComboBox.GetSelected())
@@ -47,7 +48,7 @@ void ForceFieldWindow::Create(EditorComponent* editor)
editor->RecordSelection(archive);
editor->RecordAddedEntity(archive, entity);
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
SetEntity(entity);
}
else
@@ -63,7 +64,7 @@ void ForceFieldWindow::Create(EditorComponent* editor)
typeComboBox.SetPos(XMFLOAT2(x, y += step));
typeComboBox.SetSize(XMFLOAT2(200, hei));
typeComboBox.OnSelect([&](wi::gui::EventArgs args) {
- ForceFieldComponent* force = wi::scene::GetScene().forces.GetComponent(entity);
+ ForceFieldComponent* force = editor->GetCurrentScene().forces.GetComponent(entity);
if (force != nullptr && args.iValue >= 0)
{
switch (args.iValue)
@@ -91,7 +92,7 @@ void ForceFieldWindow::Create(EditorComponent* editor)
gravitySlider.SetSize(XMFLOAT2(200, hei));
gravitySlider.SetPos(XMFLOAT2(x, y += step));
gravitySlider.OnSlide([&](wi::gui::EventArgs args) {
- ForceFieldComponent* force = wi::scene::GetScene().forces.GetComponent(entity);
+ ForceFieldComponent* force = editor->GetCurrentScene().forces.GetComponent(entity);
if (force != nullptr)
{
force->gravity = args.fValue;
@@ -106,7 +107,7 @@ void ForceFieldWindow::Create(EditorComponent* editor)
rangeSlider.SetSize(XMFLOAT2(200, hei));
rangeSlider.SetPos(XMFLOAT2(x, y += step));
rangeSlider.OnSlide([&](wi::gui::EventArgs args) {
- ForceFieldComponent* force = wi::scene::GetScene().forces.GetComponent(entity);
+ ForceFieldComponent* force = editor->GetCurrentScene().forces.GetComponent(entity);
if (force != nullptr)
{
force->range = args.fValue;
@@ -128,7 +129,7 @@ void ForceFieldWindow::SetEntity(Entity entity)
{
this->entity = entity;
- const ForceFieldComponent* force = wi::scene::GetScene().forces.GetComponent(entity);
+ const ForceFieldComponent* force = editor->GetCurrentScene().forces.GetComponent(entity);
if (force != nullptr)
{
diff --git a/Editor/ForceFieldWindow.h b/Editor/ForceFieldWindow.h
index ac9d326a6..9aa3b1099 100644
--- a/Editor/ForceFieldWindow.h
+++ b/Editor/ForceFieldWindow.h
@@ -8,6 +8,7 @@ class ForceFieldWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/HairParticleWindow.cpp b/Editor/HairParticleWindow.cpp
index e3444de6b..3185bedfe 100644
--- a/Editor/HairParticleWindow.cpp
+++ b/Editor/HairParticleWindow.cpp
@@ -5,8 +5,9 @@
using namespace wi::ecs;
using namespace wi::scene;
-void HairParticleWindow::Create(EditorComponent* editor)
+void HairParticleWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Hair Particle System Window");
SetSize(XMFLOAT2(600, 260));
@@ -20,7 +21,7 @@ void HairParticleWindow::Create(EditorComponent* editor)
addButton.SetPos(XMFLOAT2(x, y));
addButton.SetSize(XMFLOAT2(200, hei));
addButton.OnClick([=](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
Entity entity = scene.Entity_CreateHair("editorHair");
wi::Archive& archive = editor->AdvanceHistory();
@@ -33,7 +34,7 @@ void HairParticleWindow::Create(EditorComponent* editor)
editor->RecordSelection(archive);
editor->RecordAddedEntity(archive, entity);
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
SetEntity(entity);
});
addButton.SetTooltip("Add new hair particle system.");
@@ -53,7 +54,7 @@ void HairParticleWindow::Create(EditorComponent* editor)
}
else
{
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
hair->meshID = scene.meshes.GetEntity(args.iValue - 1);
}
}
@@ -267,7 +268,7 @@ wi::HairParticleSystem* HairParticleWindow::GetHair()
return nullptr;
}
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
wi::HairParticleSystem* hair = scene.hairs.GetComponent(entity);
return hair;
@@ -281,7 +282,7 @@ void HairParticleWindow::UpdateData()
return;
}
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
meshComboBox.ClearItems();
meshComboBox.AddItem("NO MESH");
diff --git a/Editor/HairParticleWindow.h b/Editor/HairParticleWindow.h
index a972fd223..346638adb 100644
--- a/Editor/HairParticleWindow.h
+++ b/Editor/HairParticleWindow.h
@@ -10,6 +10,7 @@ class HairParticleWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/IKWindow.cpp b/Editor/IKWindow.cpp
index 285966e1d..25f46af73 100644
--- a/Editor/IKWindow.cpp
+++ b/Editor/IKWindow.cpp
@@ -6,8 +6,9 @@ using namespace wi::ecs;
using namespace wi::scene;
-void IKWindow::Create(EditorComponent* editor)
+void IKWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Inverse Kinematics (IK) Window");
SetSize(XMFLOAT2(400, 150));
@@ -28,7 +29,7 @@ void IKWindow::Create(EditorComponent* editor)
targetCombo.SetPos(XMFLOAT2(x, y += step));
targetCombo.SetEnabled(false);
targetCombo.OnSelect([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
InverseKinematicsComponent* ik = scene.inverse_kinematics.GetComponent(entity);
if (ik != nullptr)
{
@@ -50,7 +51,7 @@ void IKWindow::Create(EditorComponent* editor)
disabledCheckBox.SetPos(XMFLOAT2(x, y += step));
disabledCheckBox.SetSize(XMFLOAT2(hei, hei));
disabledCheckBox.OnClick([=](wi::gui::EventArgs args) {
- wi::scene::GetScene().inverse_kinematics.GetComponent(entity)->SetDisabled(args.bValue);
+ editor->GetCurrentScene().inverse_kinematics.GetComponent(entity)->SetDisabled(args.bValue);
});
AddWidget(&disabledCheckBox);
@@ -59,7 +60,7 @@ void IKWindow::Create(EditorComponent* editor)
chainLengthSlider.SetPos(XMFLOAT2(x, y += step));
chainLengthSlider.SetSize(XMFLOAT2(siz, hei));
chainLengthSlider.OnSlide([&](wi::gui::EventArgs args) {
- wi::scene::GetScene().inverse_kinematics.GetComponent(entity)->chain_length = args.iValue;
+ editor->GetCurrentScene().inverse_kinematics.GetComponent(entity)->chain_length = args.iValue;
});
AddWidget(&chainLengthSlider);
@@ -68,7 +69,7 @@ void IKWindow::Create(EditorComponent* editor)
iterationCountSlider.SetPos(XMFLOAT2(x, y += step));
iterationCountSlider.SetSize(XMFLOAT2(siz, hei));
iterationCountSlider.OnSlide([&](wi::gui::EventArgs args) {
- wi::scene::GetScene().inverse_kinematics.GetComponent(entity)->iteration_count = args.iValue;
+ editor->GetCurrentScene().inverse_kinematics.GetComponent(entity)->iteration_count = args.iValue;
});
AddWidget(&iterationCountSlider);
@@ -82,7 +83,7 @@ void IKWindow::SetEntity(Entity entity)
{
this->entity = entity;
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
const InverseKinematicsComponent* ik = scene.inverse_kinematics.GetComponent(entity);
if (ik != nullptr)
@@ -112,7 +113,7 @@ void IKWindow::SetEntity(Entity entity)
SetEnabled(false);
}
- const TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ const TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
createButton.SetEnabled(true);
@@ -121,7 +122,7 @@ void IKWindow::SetEntity(Entity entity)
{
createButton.SetText("Create");
createButton.OnClick([=](wi::gui::EventArgs args) {
- wi::scene::GetScene().inverse_kinematics.Create(entity).chain_length = 1;
+ editor->GetCurrentScene().inverse_kinematics.Create(entity).chain_length = 1;
SetEntity(entity);
});
}
@@ -129,7 +130,7 @@ void IKWindow::SetEntity(Entity entity)
{
createButton.SetText("Remove");
createButton.OnClick([=](wi::gui::EventArgs args) {
- wi::scene::GetScene().inverse_kinematics.Remove_KeepSorted(entity);
+ editor->GetCurrentScene().inverse_kinematics.Remove_KeepSorted(entity);
SetEntity(entity);
});
}
diff --git a/Editor/IKWindow.h b/Editor/IKWindow.h
index dfd71acc1..4a3b216cd 100644
--- a/Editor/IKWindow.h
+++ b/Editor/IKWindow.h
@@ -8,6 +8,7 @@ class IKWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/LayerWindow.cpp b/Editor/LayerWindow.cpp
index 9e8dd71dc..ab30cd44f 100644
--- a/Editor/LayerWindow.cpp
+++ b/Editor/LayerWindow.cpp
@@ -6,8 +6,9 @@ using namespace wi::ecs;
using namespace wi::scene;
-void LayerWindow::Create(EditorComponent* editor)
+void LayerWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Layer Window");
SetSize(XMFLOAT2(420, 290));
@@ -31,10 +32,10 @@ void LayerWindow::Create(EditorComponent* editor)
layers[i].SetPos(XMFLOAT2(x + (i % 8) * 50, y + (i / 8) * step));
layers[i].OnClick([=](wi::gui::EventArgs args) {
- LayerComponent* layer = wi::scene::GetScene().layers.GetComponent(entity);
+ LayerComponent* layer = editor->GetCurrentScene().layers.GetComponent(entity);
if (layer == nullptr)
{
- layer = &wi::scene::GetScene().layers.Create(entity);
+ layer = &editor->GetCurrentScene().layers.Create(entity);
}
if (args.bValue)
@@ -55,10 +56,10 @@ void LayerWindow::Create(EditorComponent* editor)
enableAllButton.Create("Enable ALL");
enableAllButton.SetPos(XMFLOAT2(x, y));
enableAllButton.OnClick([this](wi::gui::EventArgs args) {
- LayerComponent* layer = wi::scene::GetScene().layers.GetComponent(entity);
+ LayerComponent* layer = editor->GetCurrentScene().layers.GetComponent(entity);
if (layer == nullptr)
{
- layer = &wi::scene::GetScene().layers.Create(entity);
+ layer = &editor->GetCurrentScene().layers.Create(entity);
}
if (layer == nullptr)
return;
@@ -69,10 +70,10 @@ void LayerWindow::Create(EditorComponent* editor)
enableNoneButton.Create("Enable NONE");
enableNoneButton.SetPos(XMFLOAT2(x + 120, y));
enableNoneButton.OnClick([this](wi::gui::EventArgs args) {
- LayerComponent* layer = wi::scene::GetScene().layers.GetComponent(entity);
+ LayerComponent* layer = editor->GetCurrentScene().layers.GetComponent(entity);
if (layer == nullptr)
{
- layer = &wi::scene::GetScene().layers.Create(entity);
+ layer = &editor->GetCurrentScene().layers.Create(entity);
}
if (layer == nullptr)
return;
@@ -94,7 +95,7 @@ void LayerWindow::SetEntity(Entity entity)
{
SetEnabled(true);
- LayerComponent* layer = wi::scene::GetScene().layers.GetComponent(entity);
+ LayerComponent* layer = editor->GetCurrentScene().layers.GetComponent(entity);
if (layer == nullptr)
{
for (uint32_t i = 0; i < 32; ++i)
@@ -109,13 +110,13 @@ void LayerWindow::SetEntity(Entity entity)
layers[i].SetCheck(layer->GetLayerMask() & 1 << i);
}
- HierarchyComponent* hier = wi::scene::GetScene().hierarchy.GetComponent(entity);
+ HierarchyComponent* hier = editor->GetCurrentScene().hierarchy.GetComponent(entity);
if (hier != nullptr)
{
hier->layerMask_bind = layer->layerMask;
}
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
material->SetDirty();
diff --git a/Editor/LayerWindow.h b/Editor/LayerWindow.h
index 215680fb7..7a1ce0079 100644
--- a/Editor/LayerWindow.h
+++ b/Editor/LayerWindow.h
@@ -8,6 +8,7 @@ class LayerWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/LightWindow.cpp b/Editor/LightWindow.cpp
index ddd4f1e4b..1a056c38d 100644
--- a/Editor/LightWindow.cpp
+++ b/Editor/LightWindow.cpp
@@ -9,8 +9,9 @@ using namespace wi::graphics;
using namespace wi::scene;
-void LightWindow::Create(EditorComponent* editor)
+void LightWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Light Window");
SetSize(XMFLOAT2(650, 300));
@@ -23,7 +24,7 @@ void LightWindow::Create(EditorComponent* editor)
intensitySlider.SetSize(XMFLOAT2(100, hei));
intensitySlider.SetPos(XMFLOAT2(x, y));
intensitySlider.OnSlide([&](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr)
{
light->intensity = args.fValue;
@@ -37,7 +38,7 @@ void LightWindow::Create(EditorComponent* editor)
rangeSlider.SetSize(XMFLOAT2(100, hei));
rangeSlider.SetPos(XMFLOAT2(x, y += step));
rangeSlider.OnSlide([&](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr)
{
light->range = args.fValue;
@@ -51,7 +52,7 @@ void LightWindow::Create(EditorComponent* editor)
outerConeAngleSlider.SetSize(XMFLOAT2(100, hei));
outerConeAngleSlider.SetPos(XMFLOAT2(x, y += step));
outerConeAngleSlider.OnSlide([&](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr)
{
light->outerConeAngle = args.fValue;
@@ -65,7 +66,7 @@ void LightWindow::Create(EditorComponent* editor)
innerConeAngleSlider.SetSize(XMFLOAT2(100, hei));
innerConeAngleSlider.SetPos(XMFLOAT2(x, y += step));
innerConeAngleSlider.OnSlide([&](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr)
{
light->innerConeAngle = args.fValue;
@@ -79,7 +80,7 @@ void LightWindow::Create(EditorComponent* editor)
shadowCheckBox.SetSize(XMFLOAT2(hei, hei));
shadowCheckBox.SetPos(XMFLOAT2(x, y += step));
shadowCheckBox.OnClick([&](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr)
{
light->SetCastShadow(args.bValue);
@@ -93,7 +94,7 @@ void LightWindow::Create(EditorComponent* editor)
volumetricsCheckBox.SetSize(XMFLOAT2(hei, hei));
volumetricsCheckBox.SetPos(XMFLOAT2(x, y += step));
volumetricsCheckBox.OnClick([&](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr)
{
light->SetVolumetricsEnabled(args.bValue);
@@ -107,7 +108,7 @@ void LightWindow::Create(EditorComponent* editor)
haloCheckBox.SetSize(XMFLOAT2(hei, hei));
haloCheckBox.SetPos(XMFLOAT2(x, y += step));
haloCheckBox.OnClick([&](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr)
{
light->SetVisualizerEnabled(args.bValue);
@@ -121,7 +122,7 @@ void LightWindow::Create(EditorComponent* editor)
staticCheckBox.SetSize(XMFLOAT2(hei, hei));
staticCheckBox.SetPos(XMFLOAT2(x, y += step));
staticCheckBox.OnClick([&](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr)
{
light->SetStatic(args.bValue);
@@ -135,8 +136,8 @@ void LightWindow::Create(EditorComponent* editor)
addLightButton.SetPos(XMFLOAT2(x, y += step));
addLightButton.SetSize(XMFLOAT2(150, hei));
addLightButton.OnClick([=](wi::gui::EventArgs args) {
- Entity entity = wi::scene::GetScene().Entity_CreateLight("editorLight", XMFLOAT3(0, 3, 0), XMFLOAT3(1, 1, 1), 2, 60);
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ Entity entity = editor->GetCurrentScene().Entity_CreateLight("editorLight", XMFLOAT3(0, 3, 0), XMFLOAT3(1, 1, 1), 2, 60);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr)
{
light->type = (LightComponent::LightType)typeSelectorComboBox.GetSelected();
@@ -166,7 +167,7 @@ void LightWindow::Create(EditorComponent* editor)
editor->RecordSelection(archive);
editor->RecordAddedEntity(archive, entity);
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
SetEntity(entity);
}
else
@@ -183,7 +184,7 @@ void LightWindow::Create(EditorComponent* editor)
colorPicker.SetVisible(true);
colorPicker.SetEnabled(false);
colorPicker.OnColorChanged([&](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr)
{
light->color = args.color.toFloat3();
@@ -195,7 +196,7 @@ void LightWindow::Create(EditorComponent* editor)
typeSelectorComboBox.SetSize(XMFLOAT2(150, hei));
typeSelectorComboBox.SetPos(XMFLOAT2(x, y += step));
typeSelectorComboBox.OnSelect([&](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr && args.iValue >= 0)
{
light->SetType((LightComponent::LightType)args.iValue);
@@ -226,7 +227,7 @@ void LightWindow::Create(EditorComponent* editor)
shadowResolutionComboBox.AddItem("1024", 1024);
shadowResolutionComboBox.AddItem("2048", 2048);
shadowResolutionComboBox.OnSelect([&](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light == nullptr)
return;
light->forced_shadow_resolution = int(args.userdata);
@@ -250,7 +251,7 @@ void LightWindow::Create(EditorComponent* editor)
lensflare_Button[i].SetPos(XMFLOAT2(x, y += step));
lensflare_Button[i].SetSize(XMFLOAT2(260, hei));
lensflare_Button[i].OnClick([=](wi::gui::EventArgs args) {
- LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light == nullptr)
return;
@@ -295,7 +296,7 @@ void LightWindow::SetEntity(Entity entity)
{
this->entity = entity;
- const LightComponent* light = wi::scene::GetScene().lights.GetComponent(entity);
+ const LightComponent* light = editor->GetCurrentScene().lights.GetComponent(entity);
if (light != nullptr)
{
diff --git a/Editor/LightWindow.h b/Editor/LightWindow.h
index 972524b8a..75c2a3775 100644
--- a/Editor/LightWindow.h
+++ b/Editor/LightWindow.h
@@ -8,6 +8,7 @@ class LightWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp
index 7d0c294ec..7864a0ba2 100644
--- a/Editor/MaterialWindow.cpp
+++ b/Editor/MaterialWindow.cpp
@@ -6,8 +6,9 @@ using namespace wi::graphics;
using namespace wi::ecs;
using namespace wi::scene;
-void MaterialWindow::Create(EditorComponent* editor)
+void MaterialWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Material Window");
SetSize(XMFLOAT2(730, 620));
@@ -20,7 +21,7 @@ void MaterialWindow::Create(EditorComponent* editor)
shadowReceiveCheckBox.SetPos(XMFLOAT2(540, y));
shadowReceiveCheckBox.SetSize(XMFLOAT2(hei, hei));
shadowReceiveCheckBox.OnClick([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetReceiveShadow(args.bValue);
});
@@ -31,7 +32,7 @@ void MaterialWindow::Create(EditorComponent* editor)
shadowCasterCheckBox.SetPos(XMFLOAT2(670, y));
shadowCasterCheckBox.SetSize(XMFLOAT2(hei, hei));
shadowCasterCheckBox.OnClick([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetCastShadow(args.bValue);
});
@@ -42,7 +43,7 @@ void MaterialWindow::Create(EditorComponent* editor)
useVertexColorsCheckBox.SetPos(XMFLOAT2(670, y += step));
useVertexColorsCheckBox.SetSize(XMFLOAT2(hei, hei));
useVertexColorsCheckBox.OnClick([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetUseVertexColors(args.bValue);
});
@@ -53,7 +54,7 @@ void MaterialWindow::Create(EditorComponent* editor)
specularGlossinessCheckBox.SetPos(XMFLOAT2(670, y += step));
specularGlossinessCheckBox.SetSize(XMFLOAT2(hei, hei));
specularGlossinessCheckBox.OnClick([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetUseSpecularGlossinessWorkflow(args.bValue);
SetEntity(entity);
@@ -65,7 +66,7 @@ void MaterialWindow::Create(EditorComponent* editor)
occlusionPrimaryCheckBox.SetPos(XMFLOAT2(670, y += step));
occlusionPrimaryCheckBox.SetSize(XMFLOAT2(hei, hei));
occlusionPrimaryCheckBox.OnClick([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetOcclusionEnabled_Primary(args.bValue);
});
@@ -76,7 +77,7 @@ void MaterialWindow::Create(EditorComponent* editor)
occlusionSecondaryCheckBox.SetPos(XMFLOAT2(670, y += step));
occlusionSecondaryCheckBox.SetSize(XMFLOAT2(hei, hei));
occlusionSecondaryCheckBox.OnClick([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetOcclusionEnabled_Secondary(args.bValue);
});
@@ -87,7 +88,7 @@ void MaterialWindow::Create(EditorComponent* editor)
windCheckBox.SetPos(XMFLOAT2(670, y += step));
windCheckBox.SetSize(XMFLOAT2(hei, hei));
windCheckBox.OnClick([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetUseWind(args.bValue);
});
@@ -98,7 +99,7 @@ void MaterialWindow::Create(EditorComponent* editor)
doubleSidedCheckBox.SetPos(XMFLOAT2(540, y));
doubleSidedCheckBox.SetSize(XMFLOAT2(hei, hei));
doubleSidedCheckBox.OnClick([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetDoubleSided(args.bValue);
});
@@ -115,7 +116,7 @@ void MaterialWindow::Create(EditorComponent* editor)
shaderTypeComboBox.SetPos(XMFLOAT2(x, y += step));
shaderTypeComboBox.SetSize(XMFLOAT2(wid, hei));
shaderTypeComboBox.OnSelect([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
if (args.iValue >= MaterialComponent::SHADERTYPE_COUNT)
@@ -153,7 +154,7 @@ void MaterialWindow::Create(EditorComponent* editor)
blendModeComboBox.SetPos(XMFLOAT2(x, y += step));
blendModeComboBox.SetSize(XMFLOAT2(wid, hei));
blendModeComboBox.OnSelect([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr && args.iValue >= 0)
{
material->userBlendMode = (wi::enums::BLENDMODE)args.iValue;
@@ -173,7 +174,7 @@ void MaterialWindow::Create(EditorComponent* editor)
shadingRateComboBox.SetPos(XMFLOAT2(x, y += step));
shadingRateComboBox.SetSize(XMFLOAT2(wid, hei));
shadingRateComboBox.OnSelect([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
material->shadingRate = (ShadingRate)args.iValue;
@@ -201,7 +202,7 @@ void MaterialWindow::Create(EditorComponent* editor)
normalMapSlider.SetSize(XMFLOAT2(wid, hei));
normalMapSlider.SetPos(XMFLOAT2(x, y += step));
normalMapSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetNormalMapStrength(args.fValue);
});
@@ -212,7 +213,7 @@ void MaterialWindow::Create(EditorComponent* editor)
roughnessSlider.SetSize(XMFLOAT2(wid, hei));
roughnessSlider.SetPos(XMFLOAT2(x, y += step));
roughnessSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetRoughness(args.fValue);
});
@@ -223,7 +224,7 @@ void MaterialWindow::Create(EditorComponent* editor)
reflectanceSlider.SetSize(XMFLOAT2(wid, hei));
reflectanceSlider.SetPos(XMFLOAT2(x, y += step));
reflectanceSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetReflectance(args.fValue);
});
@@ -234,7 +235,7 @@ void MaterialWindow::Create(EditorComponent* editor)
metalnessSlider.SetSize(XMFLOAT2(wid, hei));
metalnessSlider.SetPos(XMFLOAT2(x, y += step));
metalnessSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetMetalness(args.fValue);
});
@@ -245,7 +246,7 @@ void MaterialWindow::Create(EditorComponent* editor)
alphaRefSlider.SetSize(XMFLOAT2(wid, hei));
alphaRefSlider.SetPos(XMFLOAT2(x, y += step));
alphaRefSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetAlphaRef(args.fValue);
});
@@ -256,7 +257,7 @@ void MaterialWindow::Create(EditorComponent* editor)
emissiveSlider.SetSize(XMFLOAT2(wid, hei));
emissiveSlider.SetPos(XMFLOAT2(x, y += step));
emissiveSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetEmissiveStrength(args.fValue);
});
@@ -267,7 +268,7 @@ void MaterialWindow::Create(EditorComponent* editor)
transmissionSlider.SetSize(XMFLOAT2(wid, hei));
transmissionSlider.SetPos(XMFLOAT2(x, y += step));
transmissionSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetTransmissionAmount(args.fValue);
});
@@ -278,7 +279,7 @@ void MaterialWindow::Create(EditorComponent* editor)
refractionSlider.SetSize(XMFLOAT2(wid, hei));
refractionSlider.SetPos(XMFLOAT2(x, y += step));
refractionSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetRefractionAmount(args.fValue);
});
@@ -289,7 +290,7 @@ void MaterialWindow::Create(EditorComponent* editor)
pomSlider.SetSize(XMFLOAT2(wid, hei));
pomSlider.SetPos(XMFLOAT2(x, y += step));
pomSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetParallaxOcclusionMapping(args.fValue);
});
@@ -300,7 +301,7 @@ void MaterialWindow::Create(EditorComponent* editor)
displacementMappingSlider.SetSize(XMFLOAT2(wid, hei));
displacementMappingSlider.SetPos(XMFLOAT2(x, y += step));
displacementMappingSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetDisplacementMapping(args.fValue);
});
@@ -311,7 +312,7 @@ void MaterialWindow::Create(EditorComponent* editor)
subsurfaceScatteringSlider.SetSize(XMFLOAT2(wid, hei));
subsurfaceScatteringSlider.SetPos(XMFLOAT2(x, y += step));
subsurfaceScatteringSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
material->SetSubsurfaceScatteringAmount(args.fValue);
});
@@ -322,7 +323,7 @@ void MaterialWindow::Create(EditorComponent* editor)
texAnimFrameRateSlider.SetSize(XMFLOAT2(wid, hei));
texAnimFrameRateSlider.SetPos(XMFLOAT2(x, y += step));
texAnimFrameRateSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
material->texAnimFrameRate = args.fValue;
@@ -335,7 +336,7 @@ void MaterialWindow::Create(EditorComponent* editor)
texAnimDirectionSliderU.SetSize(XMFLOAT2(wid, hei));
texAnimDirectionSliderU.SetPos(XMFLOAT2(x, y += step));
texAnimDirectionSliderU.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
material->texAnimDirection.x = args.fValue;
@@ -348,7 +349,7 @@ void MaterialWindow::Create(EditorComponent* editor)
texAnimDirectionSliderV.SetSize(XMFLOAT2(wid, hei));
texAnimDirectionSliderV.SetPos(XMFLOAT2(x, y += step));
texAnimDirectionSliderV.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
material->texAnimDirection.y = args.fValue;
@@ -361,7 +362,7 @@ void MaterialWindow::Create(EditorComponent* editor)
texMulSliderX.SetSize(XMFLOAT2(wid, hei));
texMulSliderX.SetPos(XMFLOAT2(x, y += step));
texMulSliderX.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
material->SetDirty();
@@ -375,7 +376,7 @@ void MaterialWindow::Create(EditorComponent* editor)
texMulSliderY.SetSize(XMFLOAT2(wid, hei));
texMulSliderY.SetPos(XMFLOAT2(x, y += step));
texMulSliderY.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
material->SetDirty();
@@ -390,7 +391,7 @@ void MaterialWindow::Create(EditorComponent* editor)
sheenRoughnessSlider.SetSize(XMFLOAT2(wid, hei));
sheenRoughnessSlider.SetPos(XMFLOAT2(x, y += step));
sheenRoughnessSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
material->SetSheenRoughness(args.fValue);
@@ -403,7 +404,7 @@ void MaterialWindow::Create(EditorComponent* editor)
clearcoatSlider.SetSize(XMFLOAT2(wid, hei));
clearcoatSlider.SetPos(XMFLOAT2(x, y += step));
clearcoatSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
material->SetClearcoatFactor(args.fValue);
@@ -416,7 +417,7 @@ void MaterialWindow::Create(EditorComponent* editor)
clearcoatRoughnessSlider.SetSize(XMFLOAT2(wid, hei));
clearcoatRoughnessSlider.SetPos(XMFLOAT2(x, y += step));
clearcoatRoughnessSlider.OnSlide([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
material->SetClearcoatRoughness(args.fValue);
@@ -436,12 +437,12 @@ void MaterialWindow::Create(EditorComponent* editor)
materialNameField.SetPos(XMFLOAT2(10, y));
materialNameField.SetSize(XMFLOAT2(300, hei));
materialNameField.OnInputAccepted([=](wi::gui::EventArgs args) {
- NameComponent* name = wi::scene::GetScene().names.GetComponent(entity);
+ NameComponent* name = editor->GetCurrentScene().names.GetComponent(entity);
if (name != nullptr)
{
*name = args.sValue;
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
}
});
AddWidget(&materialNameField);
@@ -450,7 +451,7 @@ void MaterialWindow::Create(EditorComponent* editor)
newMaterialButton.SetPos(XMFLOAT2(10 + 5 + 300, y));
newMaterialButton.SetSize(XMFLOAT2(100, hei));
newMaterialButton.OnClick([=](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
Entity entity = scene.Entity_CreateMaterial("editorMaterial");
wi::Archive& archive = editor->AdvanceHistory();
@@ -459,7 +460,7 @@ void MaterialWindow::Create(EditorComponent* editor)
editor->ClearSelected();
editor->AddSelected(entity);
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
editor->RecordSelection(archive);
editor->RecordAddedEntity(archive, entity);
@@ -484,7 +485,7 @@ void MaterialWindow::Create(EditorComponent* editor)
colorPicker.SetVisible(true);
colorPicker.SetEnabled(true);
colorPicker.OnColorChanged([&](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
switch (colorComboBox.GetSelected())
@@ -616,7 +617,7 @@ void MaterialWindow::Create(EditorComponent* editor)
break;
}
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material == nullptr)
return;
textureSlotButton.SetImage(material->textures[args.iValue].resource);
@@ -634,7 +635,7 @@ void MaterialWindow::Create(EditorComponent* editor)
textureSlotButton.sprites[wi::gui::ACTIVE].params.color = wi::Color::White();
textureSlotButton.sprites[wi::gui::DEACTIVATING].params.color = wi::Color::Gray();
textureSlotButton.OnClick([this](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material == nullptr)
return;
@@ -678,7 +679,7 @@ void MaterialWindow::Create(EditorComponent* editor)
textureSlotUvsetField.SetPos(XMFLOAT2(x + textureSlotLabel.GetScale().x + 2, y));
textureSlotUvsetField.SetSize(XMFLOAT2(hei, hei));
textureSlotUvsetField.OnInputAccepted([this](wi::gui::EventArgs args) {
- MaterialComponent* material = wi::scene::GetScene().materials.GetComponent(entity);
+ MaterialComponent* material = editor->GetCurrentScene().materials.GetComponent(entity);
if (material != nullptr)
{
int slot = textureSlotComboBox.GetSelected();
@@ -700,7 +701,7 @@ void MaterialWindow::SetEntity(Entity entity)
{
this->entity = entity;
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
MaterialComponent* material = scene.materials.GetComponent(entity);
if (material != nullptr)
diff --git a/Editor/MaterialWindow.h b/Editor/MaterialWindow.h
index 34dc1fcb3..d58203c7e 100644
--- a/Editor/MaterialWindow.h
+++ b/Editor/MaterialWindow.h
@@ -8,6 +8,7 @@ class MaterialWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/MeshWindow.cpp b/Editor/MeshWindow.cpp
index bf78a02b9..975e89a22 100644
--- a/Editor/MeshWindow.cpp
+++ b/Editor/MeshWindow.cpp
@@ -11,8 +11,9 @@
using namespace wi::ecs;
using namespace wi::scene;
-void MeshWindow::Create(EditorComponent* editor)
+void MeshWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Mesh Window");
SetSize(XMFLOAT2(580, 380));
@@ -36,7 +37,7 @@ void MeshWindow::Create(EditorComponent* editor)
subsetComboBox.SetPos(XMFLOAT2(x, y));
subsetComboBox.SetEnabled(false);
subsetComboBox.OnSelect([=](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
MeshComponent* mesh = scene.meshes.GetComponent(entity);
if (mesh != nullptr)
{
@@ -55,7 +56,7 @@ void MeshWindow::Create(EditorComponent* editor)
doubleSidedCheckBox.SetSize(XMFLOAT2(hei, hei));
doubleSidedCheckBox.SetPos(XMFLOAT2(x, y += step));
doubleSidedCheckBox.OnClick([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
mesh->SetDoubleSided(args.bValue);
@@ -69,7 +70,7 @@ void MeshWindow::Create(EditorComponent* editor)
softbodyCheckBox.SetPos(XMFLOAT2(x, y += step));
softbodyCheckBox.OnClick([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
SoftBodyPhysicsComponent* physicscomponent = scene.softbodies.GetComponent(entity);
if (args.bValue)
@@ -87,7 +88,7 @@ void MeshWindow::Create(EditorComponent* editor)
if (physicscomponent != nullptr)
{
scene.softbodies.Remove(entity);
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
mesh->CreateRenderData();
@@ -103,7 +104,7 @@ void MeshWindow::Create(EditorComponent* editor)
massSlider.SetSize(XMFLOAT2(100, hei));
massSlider.SetPos(XMFLOAT2(x, y += step));
massSlider.OnSlide([&](wi::gui::EventArgs args) {
- SoftBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().softbodies.GetComponent(entity);
+ SoftBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().softbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
physicscomponent->mass = args.fValue;
@@ -116,7 +117,7 @@ void MeshWindow::Create(EditorComponent* editor)
frictionSlider.SetSize(XMFLOAT2(100, hei));
frictionSlider.SetPos(XMFLOAT2(x, y += step));
frictionSlider.OnSlide([&](wi::gui::EventArgs args) {
- SoftBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().softbodies.GetComponent(entity);
+ SoftBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().softbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
physicscomponent->friction = args.fValue;
@@ -129,7 +130,7 @@ void MeshWindow::Create(EditorComponent* editor)
restitutionSlider.SetSize(XMFLOAT2(100, hei));
restitutionSlider.SetPos(XMFLOAT2(x, y += step));
restitutionSlider.OnSlide([&](wi::gui::EventArgs args) {
- SoftBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().softbodies.GetComponent(entity);
+ SoftBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().softbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
physicscomponent->restitution = args.fValue;
@@ -142,7 +143,7 @@ void MeshWindow::Create(EditorComponent* editor)
impostorCreateButton.SetSize(XMFLOAT2(200, hei));
impostorCreateButton.SetPos(XMFLOAT2(x - 50, y += step));
impostorCreateButton.OnClick([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
ImpostorComponent* impostor = scene.impostors.GetComponent(entity);
if (impostor == nullptr)
{
@@ -162,7 +163,7 @@ void MeshWindow::Create(EditorComponent* editor)
impostorDistanceSlider.SetSize(XMFLOAT2(100, hei));
impostorDistanceSlider.SetPos(XMFLOAT2(x, y += step));
impostorDistanceSlider.OnSlide([&](wi::gui::EventArgs args) {
- ImpostorComponent* impostor = wi::scene::GetScene().impostors.GetComponent(entity);
+ ImpostorComponent* impostor = editor->GetCurrentScene().impostors.GetComponent(entity);
if (impostor != nullptr)
{
impostor->swapInDistance = args.fValue;
@@ -175,7 +176,7 @@ void MeshWindow::Create(EditorComponent* editor)
tessellationFactorSlider.SetSize(XMFLOAT2(100, hei));
tessellationFactorSlider.SetPos(XMFLOAT2(x, y += step));
tessellationFactorSlider.OnSlide([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
mesh->tessellationFactor = args.fValue;
@@ -188,7 +189,7 @@ void MeshWindow::Create(EditorComponent* editor)
flipCullingButton.SetSize(XMFLOAT2(200, hei));
flipCullingButton.SetPos(XMFLOAT2(x - 50, y += step));
flipCullingButton.OnClick([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
mesh->FlipCulling();
@@ -202,7 +203,7 @@ void MeshWindow::Create(EditorComponent* editor)
flipNormalsButton.SetSize(XMFLOAT2(200, hei));
flipNormalsButton.SetPos(XMFLOAT2(x - 50, y += step));
flipNormalsButton.OnClick([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
mesh->FlipNormals();
@@ -216,7 +217,7 @@ void MeshWindow::Create(EditorComponent* editor)
computeNormalsSmoothButton.SetSize(XMFLOAT2(200, hei));
computeNormalsSmoothButton.SetPos(XMFLOAT2(x - 50, y += step));
computeNormalsSmoothButton.OnClick([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
mesh->ComputeNormals(MeshComponent::COMPUTE_NORMALS_SMOOTH);
@@ -230,7 +231,7 @@ void MeshWindow::Create(EditorComponent* editor)
computeNormalsHardButton.SetSize(XMFLOAT2(200, hei));
computeNormalsHardButton.SetPos(XMFLOAT2(x - 50, y += step));
computeNormalsHardButton.OnClick([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
mesh->ComputeNormals(MeshComponent::COMPUTE_NORMALS_HARD);
@@ -244,7 +245,7 @@ void MeshWindow::Create(EditorComponent* editor)
recenterButton.SetSize(XMFLOAT2(200, hei));
recenterButton.SetPos(XMFLOAT2(x - 50, y += step));
recenterButton.OnClick([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
mesh->Recenter();
@@ -258,7 +259,7 @@ void MeshWindow::Create(EditorComponent* editor)
recenterToBottomButton.SetSize(XMFLOAT2(200, hei));
recenterToBottomButton.SetPos(XMFLOAT2(x - 50, y += step));
recenterToBottomButton.OnClick([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
mesh->RecenterToBottom();
@@ -272,7 +273,7 @@ void MeshWindow::Create(EditorComponent* editor)
mergeButton.SetSize(XMFLOAT2(200, hei));
mergeButton.SetPos(XMFLOAT2(x - 50, y += step));
mergeButton.OnClick([=](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
MeshComponent merged_mesh;
bool valid_normals = false;
bool valid_uvset_0 = false;
@@ -454,7 +455,7 @@ void MeshWindow::Create(EditorComponent* editor)
optimizeButton.SetSize(XMFLOAT2(200, hei));
optimizeButton.SetPos(XMFLOAT2(x - 50, y += step));
optimizeButton.OnClick([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
// https://github.com/zeux/meshoptimizer#vertex-cache-optimization
@@ -486,7 +487,7 @@ void MeshWindow::Create(EditorComponent* editor)
subsetMaterialComboBox.SetPos(XMFLOAT2(x + 180, y));
subsetMaterialComboBox.SetEnabled(false);
subsetMaterialComboBox.OnSelect([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
MeshComponent* mesh = scene.meshes.GetComponent(entity);
if (mesh != nullptr && subset >= 0 && subset < mesh->subsets.size())
{
@@ -510,7 +511,7 @@ void MeshWindow::Create(EditorComponent* editor)
morphTargetCombo.SetSize(XMFLOAT2(100, hei));
morphTargetCombo.SetPos(XMFLOAT2(x + 280, y += step));
morphTargetCombo.OnSelect([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr && args.iValue < (int)mesh->targets.size())
{
morphTargetSlider.SetValue(mesh->targets[args.iValue].weight);
@@ -524,7 +525,7 @@ void MeshWindow::Create(EditorComponent* editor)
morphTargetSlider.SetSize(XMFLOAT2(100, hei));
morphTargetSlider.SetPos(XMFLOAT2(x + 280, y += step));
morphTargetSlider.OnSlide([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr && morphTargetCombo.GetSelected() < (int)mesh->targets.size())
{
mesh->targets[morphTargetCombo.GetSelected()].weight = args.fValue;
@@ -538,7 +539,7 @@ void MeshWindow::Create(EditorComponent* editor)
lodgenButton.SetSize(XMFLOAT2(200, hei));
lodgenButton.SetPos(XMFLOAT2(x + 180, y += step));
lodgenButton.OnClick([&](wi::gui::EventArgs args) {
- MeshComponent* mesh = wi::scene::GetScene().meshes.GetComponent(entity);
+ MeshComponent* mesh = editor->GetCurrentScene().meshes.GetComponent(entity);
if (mesh != nullptr)
{
if (mesh->subsets_per_lod == 0)
@@ -682,7 +683,7 @@ void MeshWindow::SetEntity(Entity entity, int subset)
this->entity = entity;
this->subset = subset;
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
const MeshComponent* mesh = scene.meshes.GetComponent(entity);
@@ -748,7 +749,7 @@ void MeshWindow::SetEntity(Entity entity, int subset)
softbodyCheckBox.SetCheck(false);
- SoftBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().softbodies.GetComponent(entity);
+ SoftBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().softbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
softbodyCheckBox.SetCheck(true);
diff --git a/Editor/MeshWindow.h b/Editor/MeshWindow.h
index 98f64e865..1d31c4092 100644
--- a/Editor/MeshWindow.h
+++ b/Editor/MeshWindow.h
@@ -8,6 +8,7 @@ class MeshWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
int subset = -1;
void SetEntity(wi::ecs::Entity entity, int subset);
diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp
index 14a4df57e..d305e4217 100644
--- a/Editor/ModelImporter_GLTF.cpp
+++ b/Editor/ModelImporter_GLTF.cpp
@@ -190,7 +190,7 @@ void LoadNode(int nodeIndex, Entity parent, LoaderState& state)
node.name = "cam" + std::to_string(camID++);
}
- entity = scene.Entity_CreateCamera(node.name, wi::scene::GetCamera().width, wi::scene::GetCamera().height);
+ entity = scene.Entity_CreateCamera(node.name, 16, 9);
}
auto ext_lights_punctual = node.extensions.find("KHR_lights_punctual");
diff --git a/Editor/NameWindow.cpp b/Editor/NameWindow.cpp
index d5a6e32c1..5d09c2194 100644
--- a/Editor/NameWindow.cpp
+++ b/Editor/NameWindow.cpp
@@ -6,8 +6,9 @@ using namespace wi::ecs;
using namespace wi::scene;
-void NameWindow::Create(EditorComponent* editor)
+void NameWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Name Window");
SetSize(XMFLOAT2(360, 80));
@@ -22,14 +23,14 @@ void NameWindow::Create(EditorComponent* editor)
nameInput.SetPos(XMFLOAT2(x, y));
nameInput.SetSize(XMFLOAT2(siz, hei));
nameInput.OnInputAccepted([=](wi::gui::EventArgs args) {
- NameComponent* name = wi::scene::GetScene().names.GetComponent(entity);
+ NameComponent* name = editor->GetCurrentScene().names.GetComponent(entity);
if (name == nullptr)
{
- name = &wi::scene::GetScene().names.Create(entity);
+ name = &editor->GetCurrentScene().names.Create(entity);
}
name->name = args.sValue;
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
});
AddWidget(&nameInput);
@@ -47,7 +48,7 @@ void NameWindow::SetEntity(Entity entity)
{
SetEnabled(true);
- NameComponent* name = wi::scene::GetScene().names.GetComponent(entity);
+ NameComponent* name = editor->GetCurrentScene().names.GetComponent(entity);
if (name != nullptr)
{
nameInput.SetValue(name->name);
diff --git a/Editor/NameWindow.h b/Editor/NameWindow.h
index 2935dbeb0..a9636b9c2 100644
--- a/Editor/NameWindow.h
+++ b/Editor/NameWindow.h
@@ -8,6 +8,7 @@ class NameWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp
index 3959b6724..0d9adfa1e 100644
--- a/Editor/ObjectWindow.cpp
+++ b/Editor/ObjectWindow.cpp
@@ -256,9 +256,9 @@ static Atlas_Dim GenerateMeshAtlas(MeshComponent& meshcomponent, uint32_t resolu
}
-void ObjectWindow::Create(EditorComponent* editor)
+void ObjectWindow::Create(EditorComponent* _editor)
{
- this->editor = editor;
+ editor = _editor;
wi::gui::Window::Create("Object Window");
SetSize(XMFLOAT2(670, 320));
@@ -280,7 +280,7 @@ void ObjectWindow::Create(EditorComponent* editor)
renderableCheckBox.SetPos(XMFLOAT2(x, y += step));
renderableCheckBox.SetCheck(true);
renderableCheckBox.OnClick([&](wi::gui::EventArgs args) {
- ObjectComponent* object = wi::scene::GetScene().objects.GetComponent(entity);
+ ObjectComponent* object = editor->GetCurrentScene().objects.GetComponent(entity);
if (object != nullptr)
{
object->SetRenderable(args.bValue);
@@ -294,7 +294,7 @@ void ObjectWindow::Create(EditorComponent* editor)
shadowCheckBox.SetPos(XMFLOAT2(x, y += step));
shadowCheckBox.SetCheck(true);
shadowCheckBox.OnClick([&](wi::gui::EventArgs args) {
- ObjectComponent* object = wi::scene::GetScene().objects.GetComponent(entity);
+ ObjectComponent* object = editor->GetCurrentScene().objects.GetComponent(entity);
if (object != nullptr)
{
object->SetCastShadow(args.bValue);
@@ -307,7 +307,7 @@ void ObjectWindow::Create(EditorComponent* editor)
ditherSlider.SetSize(XMFLOAT2(100, hei));
ditherSlider.SetPos(XMFLOAT2(x, y += step));
ditherSlider.OnSlide([&](wi::gui::EventArgs args) {
- ObjectComponent* object = wi::scene::GetScene().objects.GetComponent(entity);
+ ObjectComponent* object = editor->GetCurrentScene().objects.GetComponent(entity);
if (object != nullptr)
{
object->color.w = 1 - args.fValue;
@@ -320,7 +320,7 @@ void ObjectWindow::Create(EditorComponent* editor)
cascadeMaskSlider.SetSize(XMFLOAT2(100, hei));
cascadeMaskSlider.SetPos(XMFLOAT2(x, y += step));
cascadeMaskSlider.OnSlide([&](wi::gui::EventArgs args) {
- ObjectComponent* object = wi::scene::GetScene().objects.GetComponent(entity);
+ ObjectComponent* object = editor->GetCurrentScene().objects.GetComponent(entity);
if (object != nullptr)
{
object->cascadeMask = (uint32_t)args.iValue;
@@ -333,7 +333,7 @@ void ObjectWindow::Create(EditorComponent* editor)
lodSlider.SetSize(XMFLOAT2(100, hei));
lodSlider.SetPos(XMFLOAT2(x, y += step));
lodSlider.OnSlide([&](wi::gui::EventArgs args) {
- ObjectComponent* object = wi::scene::GetScene().objects.GetComponent(entity);
+ ObjectComponent* object = editor->GetCurrentScene().objects.GetComponent(entity);
if (object != nullptr)
{
object->lod_distance_multiplier = args.fValue;
@@ -364,7 +364,7 @@ void ObjectWindow::Create(EditorComponent* editor)
if (entity == INVALID_ENTITY)
return;
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
RigidBodyPhysicsComponent* physicscomponent = scene.rigidbodies.GetComponent(entity);
if (args.iValue == 0)
@@ -465,7 +465,7 @@ void ObjectWindow::Create(EditorComponent* editor)
XSlider.SetSize(XMFLOAT2(100, hei));
XSlider.SetPos(XMFLOAT2(x, y += step));
XSlider.OnSlide([&](wi::gui::EventArgs args) {
- RigidBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().rigidbodies.GetComponent(entity);
+ RigidBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().rigidbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
switch (physicscomponent->shape)
@@ -490,7 +490,7 @@ void ObjectWindow::Create(EditorComponent* editor)
YSlider.SetSize(XMFLOAT2(100, hei));
YSlider.SetPos(XMFLOAT2(x, y += step));
YSlider.OnSlide([&](wi::gui::EventArgs args) {
- RigidBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().rigidbodies.GetComponent(entity);
+ RigidBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().rigidbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
switch (physicscomponent->shape)
@@ -512,7 +512,7 @@ void ObjectWindow::Create(EditorComponent* editor)
ZSlider.SetSize(XMFLOAT2(100, hei));
ZSlider.SetPos(XMFLOAT2(x, y += step));
ZSlider.OnSlide([&](wi::gui::EventArgs args) {
- RigidBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().rigidbodies.GetComponent(entity);
+ RigidBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().rigidbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
switch (physicscomponent->shape)
@@ -532,7 +532,7 @@ void ObjectWindow::Create(EditorComponent* editor)
massSlider.SetSize(XMFLOAT2(100, hei));
massSlider.SetPos(XMFLOAT2(x, y += step));
massSlider.OnSlide([&](wi::gui::EventArgs args) {
- RigidBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().rigidbodies.GetComponent(entity);
+ RigidBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().rigidbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
physicscomponent->mass = args.fValue;
@@ -545,7 +545,7 @@ void ObjectWindow::Create(EditorComponent* editor)
frictionSlider.SetSize(XMFLOAT2(100, hei));
frictionSlider.SetPos(XMFLOAT2(x, y += step));
frictionSlider.OnSlide([&](wi::gui::EventArgs args) {
- RigidBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().rigidbodies.GetComponent(entity);
+ RigidBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().rigidbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
physicscomponent->friction = args.fValue;
@@ -558,7 +558,7 @@ void ObjectWindow::Create(EditorComponent* editor)
restitutionSlider.SetSize(XMFLOAT2(100, hei));
restitutionSlider.SetPos(XMFLOAT2(x, y += step));
restitutionSlider.OnSlide([&](wi::gui::EventArgs args) {
- RigidBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().rigidbodies.GetComponent(entity);
+ RigidBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().rigidbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
physicscomponent->restitution = args.fValue;
@@ -571,7 +571,7 @@ void ObjectWindow::Create(EditorComponent* editor)
lineardampingSlider.SetSize(XMFLOAT2(100, hei));
lineardampingSlider.SetPos(XMFLOAT2(x, y += step));
lineardampingSlider.OnSlide([&](wi::gui::EventArgs args) {
- RigidBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().rigidbodies.GetComponent(entity);
+ RigidBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().rigidbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
physicscomponent->damping_linear = args.fValue;
@@ -584,7 +584,7 @@ void ObjectWindow::Create(EditorComponent* editor)
angulardampingSlider.SetSize(XMFLOAT2(100, hei));
angulardampingSlider.SetPos(XMFLOAT2(x, y += step));
angulardampingSlider.OnSlide([&](wi::gui::EventArgs args) {
- RigidBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().rigidbodies.GetComponent(entity);
+ RigidBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().rigidbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
physicscomponent->damping_angular = args.fValue;
@@ -597,7 +597,7 @@ void ObjectWindow::Create(EditorComponent* editor)
physicsMeshLODSlider.SetSize(XMFLOAT2(100, hei));
physicsMeshLODSlider.SetPos(XMFLOAT2(x, y += step));
physicsMeshLODSlider.OnSlide([&](wi::gui::EventArgs args) {
- RigidBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().rigidbodies.GetComponent(entity);
+ RigidBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().rigidbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
if (physicscomponent->mesh_lod != uint32_t(args.iValue))
@@ -616,7 +616,7 @@ void ObjectWindow::Create(EditorComponent* editor)
kinematicCheckBox.SetPos(XMFLOAT2(x, y += step));
kinematicCheckBox.SetCheck(false);
kinematicCheckBox.OnClick([&](wi::gui::EventArgs args) {
- RigidBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().rigidbodies.GetComponent(entity);
+ RigidBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().rigidbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
physicscomponent->SetKinematic(args.bValue);
@@ -630,7 +630,7 @@ void ObjectWindow::Create(EditorComponent* editor)
disabledeactivationCheckBox.SetPos(XMFLOAT2(x, y += step));
disabledeactivationCheckBox.SetCheck(false);
disabledeactivationCheckBox.OnClick([&](wi::gui::EventArgs args) {
- RigidBodyPhysicsComponent* physicscomponent = wi::scene::GetScene().rigidbodies.GetComponent(entity);
+ RigidBodyPhysicsComponent* physicscomponent = editor->GetCurrentScene().rigidbodies.GetComponent(entity);
if (physicscomponent != nullptr)
{
physicscomponent->SetDisableDeactivation(args.bValue);
@@ -669,7 +669,7 @@ void ObjectWindow::Create(EditorComponent* editor)
generateLightmapButton.SetSize(XMFLOAT2(140, hei));
generateLightmapButton.OnClick([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
enum UV_GEN_TYPE
{
@@ -750,7 +750,7 @@ void ObjectWindow::Create(EditorComponent* editor)
stopLightmapGenButton.SetSize(XMFLOAT2(140, hei));
stopLightmapGenButton.OnClick([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
for (auto& x : this->editor->translator.selected)
{
@@ -771,7 +771,7 @@ void ObjectWindow::Create(EditorComponent* editor)
clearLightmapButton.SetSize(XMFLOAT2(140, hei));
clearLightmapButton.OnClick([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
for (auto& x : this->editor->translator.selected)
{
@@ -800,7 +800,7 @@ void ObjectWindow::Create(EditorComponent* editor)
colorPicker.SetVisible(true);
colorPicker.SetEnabled(true);
colorPicker.OnColorChanged([&](wi::gui::EventArgs args) {
- ObjectComponent* object = wi::scene::GetScene().objects.GetComponent(entity);
+ ObjectComponent* object = editor->GetCurrentScene().objects.GetComponent(entity);
if (object != nullptr)
{
switch (colorComboBox.GetSelected())
@@ -835,7 +835,7 @@ void ObjectWindow::SetEntity(Entity entity)
this->entity = entity;
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
const ObjectComponent* object = scene.objects.GetComponent(entity);
diff --git a/Editor/ObjectWindow.h b/Editor/ObjectWindow.h
index 32c2e9ee0..422800b1d 100644
--- a/Editor/ObjectWindow.h
+++ b/Editor/ObjectWindow.h
@@ -8,7 +8,7 @@ class ObjectWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
- EditorComponent* editor;
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/PaintToolWindow.cpp b/Editor/PaintToolWindow.cpp
index 0ef772d1b..617c47bc9 100644
--- a/Editor/PaintToolWindow.cpp
+++ b/Editor/PaintToolWindow.cpp
@@ -9,9 +9,9 @@ using namespace wi::ecs;
using namespace wi::scene;
using namespace wi::graphics;
-void PaintToolWindow::Create(EditorComponent* editor)
+void PaintToolWindow::Create(EditorComponent* _editor)
{
- this->editor = editor;
+ editor = _editor;
wi::gui::Window::Create("Paint Tool Window");
SetSize(XMFLOAT2(360, 540));
@@ -162,7 +162,7 @@ void PaintToolWindow::Create(EditorComponent* editor)
saveTextureButton.SetPos(XMFLOAT2(x, y += step));
saveTextureButton.OnClick([this] (wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
ObjectComponent* object = scene.objects.GetComponent(entity);
if (object == nullptr || object->meshID == INVALID_ENTITY)
return;
@@ -321,8 +321,8 @@ void PaintToolWindow::Update(float dt)
const bool backfaces = backfaceCheckBox.GetCheck();
const bool wireframe = wireCheckBox.GetCheck();
- Scene& scene = wi::scene::GetScene();
- const CameraComponent& camera = wi::scene::GetCamera();
+ Scene& scene = editor->GetCurrentScene();
+ const CameraComponent& camera = editor->GetCurrentEditorScene().camera;
const XMVECTOR C = XMLoadFloat2(&pos);
const XMMATRIX VP = camera.GetViewProjection();
const XMVECTOR MUL = XMVectorSet(0.5f, -0.5f, 1, 1);
@@ -1044,7 +1044,7 @@ void PaintToolWindow::RecordHistory(bool start, CommandList cmd)
}
wi::Archive& archive = *currentHistory;
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
switch (GetMode())
{
@@ -1177,7 +1177,7 @@ void PaintToolWindow::ConsumeHistoryOperation(wi::Archive& archive, bool undo)
modeComboBox.SetSelected(historymode);
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
switch (historymode)
{
diff --git a/Editor/PostprocessWindow.cpp b/Editor/PostprocessWindow.cpp
index ce4975def..dcbabe5bf 100644
--- a/Editor/PostprocessWindow.cpp
+++ b/Editor/PostprocessWindow.cpp
@@ -6,8 +6,9 @@
using namespace wi::graphics;
-void PostprocessWindow::Create(EditorComponent* editor)
+void PostprocessWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("PostProcess Window");
SetSize(XMFLOAT2(420, 400));
diff --git a/Editor/PostprocessWindow.h b/Editor/PostprocessWindow.h
index cccad26ff..cf338f7af 100644
--- a/Editor/PostprocessWindow.h
+++ b/Editor/PostprocessWindow.h
@@ -8,6 +8,8 @@ class PostprocessWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
+
wi::gui::Slider exposureSlider;
wi::gui::CheckBox lensFlareCheckBox;
wi::gui::CheckBox lightShaftsCheckBox;
diff --git a/Editor/RendererWindow.cpp b/Editor/RendererWindow.cpp
index 9f20c5aa5..6f0e84360 100644
--- a/Editor/RendererWindow.cpp
+++ b/Editor/RendererWindow.cpp
@@ -3,8 +3,9 @@
#include "Editor.h"
#include "shaders/ShaderInterop_DDGI.h"
-void RendererWindow::Create(EditorComponent* editor)
+void RendererWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Renderer Window");
wi::renderer::SetToDrawDebugEnvProbes(true);
@@ -67,7 +68,7 @@ void RendererWindow::Create(EditorComponent* editor)
resolutionScaleSlider.SetSize(XMFLOAT2(100, itemheight));
resolutionScaleSlider.SetPos(XMFLOAT2(x, y += step));
resolutionScaleSlider.SetValue(editor->resolutionScale);
- resolutionScaleSlider.OnSlide([editor](wi::gui::EventArgs args) {
+ resolutionScaleSlider.OnSlide([=](wi::gui::EventArgs args) {
if (editor->resolutionScale != args.fValue)
{
editor->renderPath->resolutionScale = args.fValue;
@@ -82,7 +83,7 @@ void RendererWindow::Create(EditorComponent* editor)
GIBoostSlider.SetSize(XMFLOAT2(100, itemheight));
GIBoostSlider.SetPos(XMFLOAT2(x, y += step));
GIBoostSlider.SetValue(wi::renderer::GetGIBoost());
- GIBoostSlider.OnSlide([editor](wi::gui::EventArgs args) {
+ GIBoostSlider.OnSlide([=](wi::gui::EventArgs args) {
wi::renderer::SetGIBoost(args.fValue);
});
AddWidget(&GIBoostSlider);
@@ -237,7 +238,7 @@ void RendererWindow::Create(EditorComponent* editor)
variableRateShadingClassificationCheckBox.SetTooltip("Enable classification of variable rate shading on the screen. Less important parts will be shaded with lesser resolution.\nRequires Tier2 support for variable shading rate");
variableRateShadingClassificationCheckBox.SetPos(XMFLOAT2(x, y += step));
variableRateShadingClassificationCheckBox.SetSize(XMFLOAT2(itemheight, itemheight));
- variableRateShadingClassificationCheckBox.OnClick([editor](wi::gui::EventArgs args) {
+ variableRateShadingClassificationCheckBox.OnClick([=](wi::gui::EventArgs args) {
wi::renderer::SetVariableRateShadingClassification(args.bValue);
editor->ResizeBuffers();
});
diff --git a/Editor/RendererWindow.h b/Editor/RendererWindow.h
index 59fb8f169..3ca245e9e 100644
--- a/Editor/RendererWindow.h
+++ b/Editor/RendererWindow.h
@@ -21,7 +21,9 @@ enum PICKTYPE
class RendererWindow : public wi::gui::Window
{
public:
- void Create(EditorComponent* editorcomponent);
+ void Create(EditorComponent* editor);
+
+ EditorComponent* editor = nullptr;
wi::gui::CheckBox vsyncCheckBox;
wi::gui::ComboBox swapchainComboBox;
diff --git a/Editor/SoundWindow.cpp b/Editor/SoundWindow.cpp
index c408795b7..591debca6 100644
--- a/Editor/SoundWindow.cpp
+++ b/Editor/SoundWindow.cpp
@@ -7,8 +7,9 @@ using namespace wi::graphics;
using namespace wi::ecs;
using namespace wi::scene;
-void SoundWindow::Create(EditorComponent* editor)
+void SoundWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Sound Window");
SetSize(XMFLOAT2(440, 220));
@@ -69,7 +70,7 @@ void SoundWindow::Create(EditorComponent* editor)
params.extensions = wi::resourcemanager::GetSupportedSoundExtensions();
wi::helper::FileDialog(params, [=](std::string fileName) {
wi::eventhandler::Subscribe_Once(wi::eventhandler::EVENT_THREAD_SAFE_POINT, [=](uint64_t userdata) {
- Entity entity = GetScene().Entity_CreateSound("editorSound", fileName);
+ Entity entity = editor->GetCurrentScene().Entity_CreateSound("editorSound", fileName);
wi::Archive& archive = editor->AdvanceHistory();
archive << EditorComponent::HISTORYOP_ADD;
@@ -81,7 +82,7 @@ void SoundWindow::Create(EditorComponent* editor)
editor->RecordSelection(archive);
editor->RecordAddedEntity(archive, entity);
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
SetEntity(entity);
});
});
@@ -98,14 +99,14 @@ void SoundWindow::Create(EditorComponent* editor)
nameField.SetPos(XMFLOAT2(x, y += step));
nameField.SetSize(XMFLOAT2(300, hei));
nameField.OnInputAccepted([=](wi::gui::EventArgs args) {
- NameComponent* name = wi::scene::GetScene().names.GetComponent(entity);
+ NameComponent* name = editor->GetCurrentScene().names.GetComponent(entity);
if (name == nullptr)
{
- name = &wi::scene::GetScene().names.Create(entity);
+ name = &editor->GetCurrentScene().names.Create(entity);
}
*name = args.sValue;
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
});
AddWidget(&nameField);
nameField.SetEnabled(false);
@@ -115,7 +116,7 @@ void SoundWindow::Create(EditorComponent* editor)
playstopButton.SetPos(XMFLOAT2(x, y += step));
playstopButton.SetSize(XMFLOAT2(80, hei));
playstopButton.OnClick([&](wi::gui::EventArgs args) {
- SoundComponent* sound = GetScene().sounds.GetComponent(entity);
+ SoundComponent* sound = editor->GetCurrentScene().sounds.GetComponent(entity);
if (sound != nullptr)
{
if (sound->IsPlaying())
@@ -138,7 +139,7 @@ void SoundWindow::Create(EditorComponent* editor)
loopedCheckbox.SetPos(XMFLOAT2(x + 150, y));
loopedCheckbox.SetSize(XMFLOAT2(hei, hei));
loopedCheckbox.OnClick([&](wi::gui::EventArgs args) {
- SoundComponent* sound = GetScene().sounds.GetComponent(entity);
+ SoundComponent* sound = editor->GetCurrentScene().sounds.GetComponent(entity);
if (sound != nullptr)
{
sound->SetLooped(args.bValue);
@@ -152,7 +153,7 @@ void SoundWindow::Create(EditorComponent* editor)
reverbCheckbox.SetPos(XMFLOAT2(x + 240, y));
reverbCheckbox.SetSize(XMFLOAT2(hei, hei));
reverbCheckbox.OnClick([&](wi::gui::EventArgs args) {
- SoundComponent* sound = GetScene().sounds.GetComponent(entity);
+ SoundComponent* sound = editor->GetCurrentScene().sounds.GetComponent(entity);
if (sound != nullptr)
{
sound->soundinstance.SetEnableReverb(args.bValue);
@@ -167,7 +168,7 @@ void SoundWindow::Create(EditorComponent* editor)
disable3dCheckbox.SetPos(XMFLOAT2(x + 300, y));
disable3dCheckbox.SetSize(XMFLOAT2(hei, hei));
disable3dCheckbox.OnClick([&](wi::gui::EventArgs args) {
- SoundComponent* sound = GetScene().sounds.GetComponent(entity);
+ SoundComponent* sound = editor->GetCurrentScene().sounds.GetComponent(entity);
if (sound != nullptr)
{
sound->SetDisable3D(args.bValue);
@@ -182,7 +183,7 @@ void SoundWindow::Create(EditorComponent* editor)
volumeSlider.SetPos(XMFLOAT2(x + 60, y += step));
volumeSlider.SetSize(XMFLOAT2(240, hei));
volumeSlider.OnSlide([&](wi::gui::EventArgs args) {
- SoundComponent* sound = GetScene().sounds.GetComponent(entity);
+ SoundComponent* sound = editor->GetCurrentScene().sounds.GetComponent(entity);
if (sound != nullptr)
{
sound->volume = args.fValue;
@@ -195,7 +196,7 @@ void SoundWindow::Create(EditorComponent* editor)
submixComboBox.SetPos(XMFLOAT2(x + 80, y += step));
submixComboBox.SetSize(XMFLOAT2(180, hei));
submixComboBox.OnSelect([&](wi::gui::EventArgs args) {
- SoundComponent* sound = GetScene().sounds.GetComponent(entity);
+ SoundComponent* sound = editor->GetCurrentScene().sounds.GetComponent(entity);
if (sound != nullptr)
{
sound->soundinstance.type = (wi::audio::SUBMIX_TYPE)args.iValue;
@@ -222,7 +223,7 @@ void SoundWindow::SetEntity(Entity entity)
{
this->entity = entity;
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
SoundComponent* sound = scene.sounds.GetComponent(entity);
NameComponent* name = scene.names.GetComponent(entity);
diff --git a/Editor/SoundWindow.h b/Editor/SoundWindow.h
index 326d3fcd9..137aa85ee 100644
--- a/Editor/SoundWindow.h
+++ b/Editor/SoundWindow.h
@@ -8,6 +8,7 @@ class SoundWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity = wi::ecs::INVALID_ENTITY;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/SpringWindow.cpp b/Editor/SpringWindow.cpp
index 0e3a36f1a..8f3d53f67 100644
--- a/Editor/SpringWindow.cpp
+++ b/Editor/SpringWindow.cpp
@@ -6,8 +6,9 @@ using namespace wi::ecs;
using namespace wi::scene;
-void SpringWindow::Create(EditorComponent* editor)
+void SpringWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Spring Window");
SetSize(XMFLOAT2(460, 200));
@@ -34,7 +35,7 @@ void SpringWindow::Create(EditorComponent* editor)
disabledCheckBox.SetPos(XMFLOAT2(x, y += step));
disabledCheckBox.SetSize(XMFLOAT2(hei, hei));
disabledCheckBox.OnClick([=](wi::gui::EventArgs args) {
- wi::scene::GetScene().springs.GetComponent(entity)->SetDisabled(args.bValue);
+ editor->GetCurrentScene().springs.GetComponent(entity)->SetDisabled(args.bValue);
});
AddWidget(&disabledCheckBox);
@@ -43,7 +44,7 @@ void SpringWindow::Create(EditorComponent* editor)
stretchCheckBox.SetPos(XMFLOAT2(x, y += step));
stretchCheckBox.SetSize(XMFLOAT2(hei, hei));
stretchCheckBox.OnClick([=](wi::gui::EventArgs args) {
- wi::scene::GetScene().springs.GetComponent(entity)->SetStretchEnabled(args.bValue);
+ editor->GetCurrentScene().springs.GetComponent(entity)->SetStretchEnabled(args.bValue);
});
AddWidget(&stretchCheckBox);
@@ -52,7 +53,7 @@ void SpringWindow::Create(EditorComponent* editor)
gravityCheckBox.SetPos(XMFLOAT2(x, y += step));
gravityCheckBox.SetSize(XMFLOAT2(hei, hei));
gravityCheckBox.OnClick([=](wi::gui::EventArgs args) {
- wi::scene::GetScene().springs.GetComponent(entity)->SetGravityEnabled(args.bValue);
+ editor->GetCurrentScene().springs.GetComponent(entity)->SetGravityEnabled(args.bValue);
});
AddWidget(&gravityCheckBox);
@@ -61,7 +62,7 @@ void SpringWindow::Create(EditorComponent* editor)
stiffnessSlider.SetPos(XMFLOAT2(x, y += step));
stiffnessSlider.SetSize(XMFLOAT2(siz, hei));
stiffnessSlider.OnSlide([&](wi::gui::EventArgs args) {
- wi::scene::GetScene().springs.GetComponent(entity)->stiffness = args.fValue;
+ editor->GetCurrentScene().springs.GetComponent(entity)->stiffness = args.fValue;
});
AddWidget(&stiffnessSlider);
@@ -70,7 +71,7 @@ void SpringWindow::Create(EditorComponent* editor)
dampingSlider.SetPos(XMFLOAT2(x, y += step));
dampingSlider.SetSize(XMFLOAT2(siz, hei));
dampingSlider.OnSlide([&](wi::gui::EventArgs args) {
- wi::scene::GetScene().springs.GetComponent(entity)->damping = args.fValue;
+ editor->GetCurrentScene().springs.GetComponent(entity)->damping = args.fValue;
});
AddWidget(&dampingSlider);
@@ -79,7 +80,7 @@ void SpringWindow::Create(EditorComponent* editor)
windSlider.SetPos(XMFLOAT2(x, y += step));
windSlider.SetSize(XMFLOAT2(siz, hei));
windSlider.OnSlide([&](wi::gui::EventArgs args) {
- wi::scene::GetScene().springs.GetComponent(entity)->wind_affection = args.fValue;
+ editor->GetCurrentScene().springs.GetComponent(entity)->wind_affection = args.fValue;
});
AddWidget(&windSlider);
@@ -93,7 +94,7 @@ void SpringWindow::SetEntity(Entity entity)
{
this->entity = entity;
- const SpringComponent* spring = wi::scene::GetScene().springs.GetComponent(entity);
+ const SpringComponent* spring = editor->GetCurrentScene().springs.GetComponent(entity);
if (spring != nullptr)
{
@@ -111,7 +112,7 @@ void SpringWindow::SetEntity(Entity entity)
SetEnabled(false);
}
- const TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ const TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
createButton.SetEnabled(true);
@@ -120,7 +121,7 @@ void SpringWindow::SetEntity(Entity entity)
{
createButton.SetText("Create");
createButton.OnClick([=](wi::gui::EventArgs args) {
- wi::scene::GetScene().springs.Create(entity);
+ editor->GetCurrentScene().springs.Create(entity);
SetEntity(entity);
});
}
@@ -128,7 +129,7 @@ void SpringWindow::SetEntity(Entity entity)
{
createButton.SetText("Remove");
createButton.OnClick([=](wi::gui::EventArgs args) {
- wi::scene::GetScene().springs.Remove_KeepSorted(entity);
+ editor->GetCurrentScene().springs.Remove_KeepSorted(entity);
SetEntity(entity);
});
}
diff --git a/Editor/SpringWindow.h b/Editor/SpringWindow.h
index d1a40efec..00f828367 100644
--- a/Editor/SpringWindow.h
+++ b/Editor/SpringWindow.h
@@ -8,6 +8,7 @@ class SpringWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/TerrainGenerator.h b/Editor/TerrainGenerator.h
index 4c4033cc0..f36e8c193 100644
--- a/Editor/TerrainGenerator.h
+++ b/Editor/TerrainGenerator.h
@@ -52,7 +52,7 @@ struct ChunkData
struct TerrainGenerator : public wi::gui::Window
{
wi::ecs::Entity terrainEntity = wi::ecs::INVALID_ENTITY;
- wi::scene::Scene* scene = &wi::scene::GetScene(); // by default it uses the global scene, but this can be changed
+ wi::scene::Scene* scene = nullptr;
wi::scene::MaterialComponent material_Base;
wi::scene::MaterialComponent material_Slope;
wi::scene::MaterialComponent material_LowAltitude;
diff --git a/Editor/TransformWindow.cpp b/Editor/TransformWindow.cpp
index 2c1dd6831..e53b5b890 100644
--- a/Editor/TransformWindow.cpp
+++ b/Editor/TransformWindow.cpp
@@ -6,8 +6,9 @@ using namespace wi::ecs;
using namespace wi::scene;
-void TransformWindow::Create(EditorComponent* editor)
+void TransformWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Transform Window");
SetSize(XMFLOAT2(480, 200));
@@ -23,7 +24,7 @@ void TransformWindow::Create(EditorComponent* editor)
createButton.SetSize(XMFLOAT2(350, hei));
createButton.OnClick([=](wi::gui::EventArgs args) {
Entity entity = CreateEntity();
- wi::scene::GetScene().transforms.Create(entity);
+ editor->GetCurrentScene().transforms.Create(entity);
wi::Archive& archive = editor->AdvanceHistory();
archive << EditorComponent::HISTORYOP_ADD;
@@ -35,7 +36,7 @@ void TransformWindow::Create(EditorComponent* editor)
editor->RecordSelection(archive);
editor->RecordAddedEntity(archive, entity);
- editor->RefreshSceneGraphView();
+ editor->RefreshEntityTree();
SetEntity(entity);
});
AddWidget(&createButton);
@@ -45,7 +46,7 @@ void TransformWindow::Create(EditorComponent* editor)
clearButton.SetPos(XMFLOAT2(x, y += step));
clearButton.SetSize(XMFLOAT2(350, hei));
clearButton.OnClick([=](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
transform->ClearTransform();
@@ -58,7 +59,7 @@ void TransformWindow::Create(EditorComponent* editor)
parentCombo.SetPos(XMFLOAT2(x, y += step));
parentCombo.SetEnabled(false);
parentCombo.OnSelect([&](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
if (args.iValue == 0)
{
@@ -79,7 +80,7 @@ void TransformWindow::Create(EditorComponent* editor)
txInput.SetPos(XMFLOAT2(x, y += step));
txInput.SetSize(XMFLOAT2(siz, hei));
txInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
transform->translation_local.x = args.fValue;
@@ -94,7 +95,7 @@ void TransformWindow::Create(EditorComponent* editor)
tyInput.SetPos(XMFLOAT2(x, y += step));
tyInput.SetSize(XMFLOAT2(siz, hei));
tyInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
transform->translation_local.y = args.fValue;
@@ -109,7 +110,7 @@ void TransformWindow::Create(EditorComponent* editor)
tzInput.SetPos(XMFLOAT2(x, y += step));
tzInput.SetSize(XMFLOAT2(siz, hei));
tzInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
transform->translation_local.z = args.fValue;
@@ -131,7 +132,7 @@ void TransformWindow::Create(EditorComponent* editor)
rollInput.SetPos(XMFLOAT2(x, y += step));
rollInput.SetSize(XMFLOAT2(siz, hei));
rollInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
float roll = float(std::atof(rollInput.GetValue().c_str())) / 180.0f * XM_PI;
@@ -152,7 +153,7 @@ void TransformWindow::Create(EditorComponent* editor)
pitchInput.SetPos(XMFLOAT2(x, y += step));
pitchInput.SetSize(XMFLOAT2(siz, hei));
pitchInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
float roll = float(std::atof(rollInput.GetValue().c_str())) / 180.0f * XM_PI;
@@ -173,7 +174,7 @@ void TransformWindow::Create(EditorComponent* editor)
yawInput.SetPos(XMFLOAT2(x, y += step));
yawInput.SetSize(XMFLOAT2(siz, hei));
yawInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
float roll = float(std::atof(rollInput.GetValue().c_str())) / 180.0f * XM_PI;
@@ -197,7 +198,7 @@ void TransformWindow::Create(EditorComponent* editor)
rxInput.SetPos(XMFLOAT2(x, y += step));
rxInput.SetSize(XMFLOAT2(siz, hei));
rxInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
transform->rotation_local.x = args.fValue;
@@ -214,7 +215,7 @@ void TransformWindow::Create(EditorComponent* editor)
ryInput.SetPos(XMFLOAT2(x, y += step));
ryInput.SetSize(XMFLOAT2(siz, hei));
ryInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
transform->rotation_local.y = args.fValue;
@@ -231,7 +232,7 @@ void TransformWindow::Create(EditorComponent* editor)
rzInput.SetPos(XMFLOAT2(x, y += step));
rzInput.SetSize(XMFLOAT2(siz, hei));
rzInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
transform->rotation_local.z = args.fValue;
@@ -248,7 +249,7 @@ void TransformWindow::Create(EditorComponent* editor)
rwInput.SetPos(XMFLOAT2(x, y += step));
rwInput.SetSize(XMFLOAT2(siz, hei));
rwInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
transform->rotation_local.w = args.fValue;
@@ -271,7 +272,7 @@ void TransformWindow::Create(EditorComponent* editor)
sxInput.SetPos(XMFLOAT2(x, y += step));
sxInput.SetSize(XMFLOAT2(siz, hei));
sxInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
transform->scale_local.x = args.fValue;
@@ -286,7 +287,7 @@ void TransformWindow::Create(EditorComponent* editor)
syInput.SetPos(XMFLOAT2(x, y += step));
syInput.SetSize(XMFLOAT2(siz, hei));
syInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
transform->scale_local.y = args.fValue;
@@ -301,7 +302,7 @@ void TransformWindow::Create(EditorComponent* editor)
szInput.SetPos(XMFLOAT2(x, y += step));
szInput.SetSize(XMFLOAT2(siz, hei));
szInput.OnInputAccepted([&](wi::gui::EventArgs args) {
- TransformComponent* transform = wi::scene::GetScene().transforms.GetComponent(entity);
+ TransformComponent* transform = editor->GetCurrentScene().transforms.GetComponent(entity);
if (transform != nullptr)
{
transform->scale_local.z = args.fValue;
@@ -357,7 +358,7 @@ void TransformWindow::SetEntity(Entity entity)
{
this->entity = entity;
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
const TransformComponent* transform = scene.transforms.GetComponent(entity);
if (transform != nullptr)
diff --git a/Editor/TransformWindow.h b/Editor/TransformWindow.h
index bf4cc7054..86876bd64 100644
--- a/Editor/TransformWindow.h
+++ b/Editor/TransformWindow.h
@@ -8,6 +8,7 @@ class TransformWindow : public wi::gui::Window
public:
void Create(EditorComponent* editor);
+ EditorComponent* editor = nullptr;
wi::ecs::Entity entity;
void SetEntity(wi::ecs::Entity entity);
diff --git a/Editor/Translator.cpp b/Editor/Translator.cpp
index 79b9ed943..cdd091014 100644
--- a/Editor/Translator.cpp
+++ b/Editor/Translator.cpp
@@ -122,7 +122,7 @@ void Translator::Update(const CameraComponent& camera, const wi::Canvas& canvas)
// Non recursive selection will be computed to not apply recursive operations two times
// A recursive operation is for example translating a parent transform
// An other recursive operation is serializing selected parent entities
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = *this->scene;
selectedEntitiesLookup.clear();
for (auto& x : selected)
{
@@ -504,7 +504,7 @@ void Translator::Draw(const CameraComponent& camera, CommandList cmd) const
Translator_Internal::LoadShaders();
}
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = *this->scene;
GraphicsDevice* device = wi::graphics::GetDevice();
@@ -1055,7 +1055,7 @@ void Translator::Draw(const CameraComponent& camera, CommandList cmd) const
void Translator::PreTranslate()
{
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = *this->scene;
if (!dragging)
{
@@ -1101,7 +1101,7 @@ void Translator::PreTranslate()
}
void Translator::PostTranslate()
{
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = *this->scene;
int i = 0;
for (auto& x : selectedEntitiesNonRecursive)
diff --git a/Editor/Translator.h b/Editor/Translator.h
index 6eb52c91e..f3b6f3ea4 100644
--- a/Editor/Translator.h
+++ b/Editor/Translator.h
@@ -24,6 +24,7 @@ public:
// Apply translator to selection
void PostTranslate();
+ wi::scene::Scene* scene = nullptr;
wi::scene::TransformComponent transform;
wi::vector selected; // all the selected picks
wi::unordered_set selectedEntitiesLookup; // fast lookup for selected entities
diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp
index 667c1b37f..94a149851 100644
--- a/Editor/WeatherWindow.cpp
+++ b/Editor/WeatherWindow.cpp
@@ -6,8 +6,9 @@ using namespace wi::ecs;
using namespace wi::scene;
using namespace wi::graphics;
-void WeatherWindow::Create(EditorComponent* editor)
+void WeatherWindow::Create(EditorComponent* _editor)
{
+ editor = _editor;
wi::gui::Window::Create("Weather Window");
SetSize(XMFLOAT2(660, 300));
@@ -277,7 +278,7 @@ void WeatherWindow::Create(EditorComponent* editor)
weather.SetOceanEnabled(args.bValue);
if (!weather.IsOceanEnabled())
{
- GetScene().ocean = {};
+ editor->GetCurrentScene().ocean = {};
}
});
AddWidget(&ocean_enabledCheckBox);
@@ -286,31 +287,31 @@ void WeatherWindow::Create(EditorComponent* editor)
ocean_patchSizeSlider.Create(1, 1000, 1000, 100000, "Patch size: ");
ocean_patchSizeSlider.SetSize(XMFLOAT2(100, hei));
ocean_patchSizeSlider.SetPos(XMFLOAT2(x, y += step));
- ocean_patchSizeSlider.SetValue(wi::scene::GetScene().weather.oceanParameters.patch_length);
+ ocean_patchSizeSlider.SetValue(editor->GetCurrentScene().weather.oceanParameters.patch_length);
ocean_patchSizeSlider.SetTooltip("Adjust water tiling patch size");
ocean_patchSizeSlider.OnSlide([&](wi::gui::EventArgs args) {
auto& weather = GetWeather();
weather.oceanParameters.patch_length = args.fValue;
- GetScene().ocean = {};
+ editor->GetCurrentScene().ocean = {};
});
AddWidget(&ocean_patchSizeSlider);
ocean_waveAmplitudeSlider.Create(0, 1000, 1000, 100000, "Wave amplitude: ");
ocean_waveAmplitudeSlider.SetSize(XMFLOAT2(100, hei));
ocean_waveAmplitudeSlider.SetPos(XMFLOAT2(x, y += step));
- ocean_waveAmplitudeSlider.SetValue(wi::scene::GetScene().weather.oceanParameters.wave_amplitude);
+ ocean_waveAmplitudeSlider.SetValue(editor->GetCurrentScene().weather.oceanParameters.wave_amplitude);
ocean_waveAmplitudeSlider.SetTooltip("Adjust wave size");
ocean_waveAmplitudeSlider.OnSlide([&](wi::gui::EventArgs args) {
auto& weather = GetWeather();
weather.oceanParameters.wave_amplitude = args.fValue;
- GetScene().ocean = {};
+ editor->GetCurrentScene().ocean = {};
});
AddWidget(&ocean_waveAmplitudeSlider);
ocean_choppyScaleSlider.Create(0, 10, 1000, 100000, "Choppiness: ");
ocean_choppyScaleSlider.SetSize(XMFLOAT2(100, hei));
ocean_choppyScaleSlider.SetPos(XMFLOAT2(x, y += step));
- ocean_choppyScaleSlider.SetValue(wi::scene::GetScene().weather.oceanParameters.choppy_scale);
+ ocean_choppyScaleSlider.SetValue(editor->GetCurrentScene().weather.oceanParameters.choppy_scale);
ocean_choppyScaleSlider.SetTooltip("Adjust wave choppiness");
ocean_choppyScaleSlider.OnSlide([&](wi::gui::EventArgs args) {
auto& weather = GetWeather();
@@ -321,19 +322,19 @@ void WeatherWindow::Create(EditorComponent* editor)
ocean_windDependencySlider.Create(0, 1, 1000, 100000, "Wind dependency: ");
ocean_windDependencySlider.SetSize(XMFLOAT2(100, hei));
ocean_windDependencySlider.SetPos(XMFLOAT2(x, y += step));
- ocean_windDependencySlider.SetValue(wi::scene::GetScene().weather.oceanParameters.wind_dependency);
+ ocean_windDependencySlider.SetValue(editor->GetCurrentScene().weather.oceanParameters.wind_dependency);
ocean_windDependencySlider.SetTooltip("Adjust wind contribution");
ocean_windDependencySlider.OnSlide([&](wi::gui::EventArgs args) {
auto& weather = GetWeather();
weather.oceanParameters.wind_dependency = args.fValue;
- GetScene().ocean = {};
+ editor->GetCurrentScene().ocean = {};
});
AddWidget(&ocean_windDependencySlider);
ocean_timeScaleSlider.Create(0, 4, 1000, 100000, "Time scale: ");
ocean_timeScaleSlider.SetSize(XMFLOAT2(100, hei));
ocean_timeScaleSlider.SetPos(XMFLOAT2(x, y += step));
- ocean_timeScaleSlider.SetValue(wi::scene::GetScene().weather.oceanParameters.time_scale);
+ ocean_timeScaleSlider.SetValue(editor->GetCurrentScene().weather.oceanParameters.time_scale);
ocean_timeScaleSlider.SetTooltip("Adjust simulation speed");
ocean_timeScaleSlider.OnSlide([&](wi::gui::EventArgs args) {
auto& weather = GetWeather();
@@ -382,7 +383,7 @@ void WeatherWindow::Create(EditorComponent* editor)
ocean_resetButton.OnClick([=](wi::gui::EventArgs args) {
auto& weather = GetWeather();
weather.oceanParameters = wi::Ocean::OceanParameters();
- GetScene().ocean = {};
+ editor->GetCurrentScene().ocean = {};
});
AddWidget(&ocean_resetButton);
@@ -477,7 +478,7 @@ void WeatherWindow::Create(EditorComponent* editor)
preset0Button.SetPos(XMFLOAT2(x, y += step));
preset0Button.OnClick([=](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
scene.weathers.Clear();
scene.weather = WeatherComponent();
@@ -594,7 +595,7 @@ void WeatherWindow::Create(EditorComponent* editor)
eliminateCoarseCascadesButton.SetPos(XMFLOAT2(x, y += step * 2));
eliminateCoarseCascadesButton.OnClick([=](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
for (size_t i = 0; i < scene.objects.GetCount(); ++i)
{
scene.objects[i].cascadeMask = 1;
@@ -610,7 +611,7 @@ void WeatherWindow::Create(EditorComponent* editor)
ktxConvButton.SetPos(XMFLOAT2(x, y += step));
ktxConvButton.OnClick([=](wi::gui::EventArgs args) {
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
wi::unordered_map conv;
for (uint32_t i = 0; i < scene.materials.GetCount(); ++i)
@@ -664,7 +665,7 @@ void WeatherWindow::Create(EditorComponent* editor)
void WeatherWindow::Update()
{
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
if (scene.weathers.GetCount() > 0)
{
auto& weather = scene.weathers[0];
@@ -739,7 +740,7 @@ void WeatherWindow::Update()
WeatherComponent& WeatherWindow::GetWeather() const
{
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
if (scene.weathers.GetCount() == 0)
{
scene.weathers.Create(CreateEntity());
@@ -749,7 +750,7 @@ WeatherComponent& WeatherWindow::GetWeather() const
void WeatherWindow::InvalidateProbes() const
{
- Scene& scene = wi::scene::GetScene();
+ Scene& scene = editor->GetCurrentScene();
// Also, we invalidate all environment probes to reflect the sky changes.
for (size_t i = 0; i < scene.probes.GetCount(); ++i)
diff --git a/Editor/WeatherWindow.h b/Editor/WeatherWindow.h
index 33aa849ff..eaea29b01 100644
--- a/Editor/WeatherWindow.h
+++ b/Editor/WeatherWindow.h
@@ -11,6 +11,8 @@ public:
void Update();
+ EditorComponent* editor = nullptr;
+
wi::scene::WeatherComponent& GetWeather() const;
void InvalidateProbes() const;
diff --git a/Editor/images/arealight.dds b/Editor/images/arealight.dds
deleted file mode 100644
index d115f7256..000000000
Binary files a/Editor/images/arealight.dds and /dev/null differ
diff --git a/Editor/images/blood1.png b/Editor/images/blood1.png
deleted file mode 100644
index 63da0fc7a..000000000
Binary files a/Editor/images/blood1.png and /dev/null differ
diff --git a/Editor/images/directional_light.dds b/Editor/images/directional_light.dds
index 95e043615..b2e5d5b8e 100644
Binary files a/Editor/images/directional_light.dds and b/Editor/images/directional_light.dds differ
diff --git a/Editor/images/pointlight.dds b/Editor/images/pointlight.dds
index b273e6c37..940a11a5f 100644
Binary files a/Editor/images/pointlight.dds and b/Editor/images/pointlight.dds differ
diff --git a/Editor/images/spotlight.dds b/Editor/images/spotlight.dds
index 31eda76f6..a92d25f5c 100644
Binary files a/Editor/images/spotlight.dds and b/Editor/images/spotlight.dds differ
diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp
index 21f7bcbe7..debd8ac6f 100644
--- a/WickedEngine/wiGUI.cpp
+++ b/WickedEngine/wiGUI.cpp
@@ -1924,6 +1924,14 @@ namespace wi::gui
}
}
}
+ void ComboBox::SetItemText(int index, const std::string& text)
+ {
+ items[index].name = text;
+ }
+ void ComboBox::SetItemUserdata(int index, uint64_t userdata)
+ {
+ items[index].userdata = userdata;
+ }
std::string ComboBox::GetItemText(int index) const
{
if (index >= 0)
diff --git a/WickedEngine/wiGUI.h b/WickedEngine/wiGUI.h
index 5203d58ac..d53de821a 100644
--- a/WickedEngine/wiGUI.h
+++ b/WickedEngine/wiGUI.h
@@ -336,6 +336,8 @@ namespace wi::gui
void SetSelectedByUserdata(uint64_t userdata);
void SetSelectedByUserdataWithoutCallback(uint64_t userdata); // SetSelectedByUserdata() but the OnSelect callback will not be executed
int GetSelected() const;
+ void SetItemText(int index, const std::string& text);
+ void SetItemUserdata(int index, uint64_t userdata);
std::string GetItemText(int index) const;
uint64_t GetItemUserData(int index) const;
size_t GetItemCount() const { return items.size(); }
diff --git a/WickedEngine/wiPhysics.h b/WickedEngine/wiPhysics.h
index 1a5f71c04..7602a0883 100644
--- a/WickedEngine/wiPhysics.h
+++ b/WickedEngine/wiPhysics.h
@@ -37,30 +37,30 @@ namespace wi::physics
// Apply force at body center
void ApplyForce(
- const wi::scene::RigidBodyPhysicsComponent& physicscomponent,
+ wi::scene::RigidBodyPhysicsComponent& physicscomponent,
const XMFLOAT3& force
);
// Apply force at body local position
void ApplyForceAt(
- const wi::scene::RigidBodyPhysicsComponent& physicscomponent,
+ wi::scene::RigidBodyPhysicsComponent& physicscomponent,
const XMFLOAT3& force,
const XMFLOAT3& at
);
// Apply impulse at body center
void ApplyImpulse(
- const wi::scene::RigidBodyPhysicsComponent& physicscomponent,
+ wi::scene::RigidBodyPhysicsComponent& physicscomponent,
const XMFLOAT3& impulse
);
// Apply impulse at body local position
void ApplyImpulseAt(
- const wi::scene::RigidBodyPhysicsComponent& physicscomponent,
+ wi::scene::RigidBodyPhysicsComponent& physicscomponent,
const XMFLOAT3& impulse,
const XMFLOAT3& at
);
void ApplyTorque(
- const wi::scene::RigidBodyPhysicsComponent& physicscomponent,
+ wi::scene::RigidBodyPhysicsComponent& physicscomponent,
const XMFLOAT3& torque
);
}
diff --git a/WickedEngine/wiPhysics_Bullet.cpp b/WickedEngine/wiPhysics_Bullet.cpp
index dab1f1c73..b6bc9ffbc 100644
--- a/WickedEngine/wiPhysics_Bullet.cpp
+++ b/WickedEngine/wiPhysics_Bullet.cpp
@@ -20,79 +20,141 @@ using namespace wi::scene;
namespace wi::physics
{
- bool ENABLED = true;
- bool SIMULATION_ENABLED = true;
- bool DEBUGDRAW_ENABLED = false;
- int ACCURACY = 10;
- std::mutex physicsLock;
-
- btVector3 gravity(0, -10, 0);
- int softbodyIterationCount = 5;
- btSoftBodyRigidBodyCollisionConfiguration collisionConfiguration;
- btDbvtBroadphase overlappingPairCache;
- btSequentialImpulseConstraintSolver solver;
- btCollisionDispatcher dispatcher(&collisionConfiguration);
- btSoftRigidDynamicsWorld dynamicsWorld(&dispatcher, &overlappingPairCache, &solver, &collisionConfiguration);
-
- class DebugDraw : public btIDebugDraw
+ namespace bullet
{
- void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override
+ bool ENABLED = true;
+ bool SIMULATION_ENABLED = true;
+ bool DEBUGDRAW_ENABLED = false;
+ int ACCURACY = 10;
+ int softbodyIterationCount = 5;
+ std::mutex physicsLock;
+
+ class DebugDraw : public btIDebugDraw
{
- wi::renderer::RenderableLine line;
- line.start = XMFLOAT3(from.x(), from.y(), from.z());
- line.end = XMFLOAT3(to.x(), to.y(), to.z());
- line.color_start = line.color_end = XMFLOAT4(color.x(), color.y(), color.z(), 1.0f);
- wi::renderer::DrawLine(line);
- }
- void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color) override
+ void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override
+ {
+ wi::renderer::RenderableLine line;
+ line.start = XMFLOAT3(from.x(), from.y(), from.z());
+ line.end = XMFLOAT3(to.x(), to.y(), to.z());
+ line.color_start = line.color_end = XMFLOAT4(color.x(), color.y(), color.z(), 1.0f);
+ wi::renderer::DrawLine(line);
+ }
+ void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color) override
+ {
+ }
+ void reportErrorWarning(const char* warningString) override
+ {
+ wi::backlog::post(warningString);
+ }
+ void draw3dText(const btVector3& location, const char* textString) override
+ {
+ wi::renderer::DebugTextParams params;
+ params.position.x = location.x();
+ params.position.y = location.y();
+ params.position.z = location.z();
+ params.scaling = 0.6f;
+ params.flags |= wi::renderer::DebugTextParams::CAMERA_FACING;
+ params.flags |= wi::renderer::DebugTextParams::CAMERA_SCALING;
+ wi::renderer::DrawDebugText(textString, params);
+ }
+ void setDebugMode(int debugMode) override
+ {
+ }
+ int getDebugMode() const override
+ {
+ int retval = 0;
+ retval |= DBG_DrawWireframe;
+ retval |= DBG_DrawText;
+ return retval;
+ }
+ };
+ DebugDraw debugDraw;
+
+ struct PhysicsScene
{
- }
- void reportErrorWarning(const char* warningString) override
+ btVector3 gravity = btVector3(0, -10, 0);
+ btSoftBodyRigidBodyCollisionConfiguration collisionConfiguration;
+ btDbvtBroadphase overlappingPairCache;
+ btSequentialImpulseConstraintSolver solver;
+ btCollisionDispatcher dispatcher = btCollisionDispatcher(&collisionConfiguration);
+ btSoftRigidDynamicsWorld dynamicsWorld = btSoftRigidDynamicsWorld(&dispatcher, &overlappingPairCache, &solver, &collisionConfiguration);
+ };
+ PhysicsScene& GetPhysicsScene(Scene& scene)
{
- wi::backlog::post(warningString);
+ if (scene.physics_scene == nullptr)
+ {
+ auto physics_scene = std::make_shared();
+
+ physics_scene->dynamicsWorld.getSolverInfo().m_solverMode |= SOLVER_RANDMIZE_ORDER;
+ physics_scene->dynamicsWorld.getDispatchInfo().m_enableSatConvex = true;
+ physics_scene->dynamicsWorld.getSolverInfo().m_splitImpulse = true;
+ physics_scene->dynamicsWorld.setGravity(physics_scene->gravity);
+ physics_scene->dynamicsWorld.setDebugDrawer(&debugDraw);
+
+ btSoftBodyWorldInfo& softWorldInfo = physics_scene->dynamicsWorld.getWorldInfo();
+ softWorldInfo.air_density = btScalar(1.2f);
+ softWorldInfo.water_density = 0;
+ softWorldInfo.water_offset = 0;
+ softWorldInfo.water_normal = btVector3(0, 0, 0);
+ softWorldInfo.m_gravity.setValue(physics_scene->gravity.x(), physics_scene->gravity.y(), physics_scene->gravity.z());
+ softWorldInfo.m_sparsesdf.Initialize();
+
+ scene.physics_scene = physics_scene;
+ }
+ return *(PhysicsScene*)scene.physics_scene.get();
}
- void draw3dText(const btVector3& location, const char* textString) override
+
+ struct RigidBody
{
- wi::renderer::DebugTextParams params;
- params.position.x = location.x();
- params.position.y = location.y();
- params.position.z = location.z();
- params.scaling = 0.6f;
- params.flags |= wi::renderer::DebugTextParams::CAMERA_FACING;
- params.flags |= wi::renderer::DebugTextParams::CAMERA_SCALING;
- wi::renderer::DrawDebugText(textString, params);
- }
- void setDebugMode(int debugMode) override
+ std::shared_ptr physics_scene;
+ std::unique_ptr shape;
+ std::unique_ptr rigidBody;
+ btDefaultMotionState motionState;
+ btTriangleIndexVertexArray triangles;
+ ~RigidBody()
+ {
+ if (physics_scene == nullptr)
+ return;
+ btSoftRigidDynamicsWorld& dynamicsWorld = ((PhysicsScene*)physics_scene.get())->dynamicsWorld;
+ dynamicsWorld.removeRigidBody(rigidBody.get());
+ }
+ };
+ struct SoftBody
{
- }
- int getDebugMode() const override
+ std::shared_ptr physics_scene;
+ std::unique_ptr softBody;
+ ~SoftBody()
+ {
+ if (physics_scene == nullptr)
+ return;
+ btSoftRigidDynamicsWorld& dynamicsWorld = ((PhysicsScene*)physics_scene.get())->dynamicsWorld;
+ dynamicsWorld.removeSoftBody(softBody.get());
+ }
+ };
+
+ RigidBody& GetRigidBody(wi::scene::RigidBodyPhysicsComponent& physicscomponent)
{
- int retval = 0;
- retval |= DBG_DrawWireframe;
- retval |= DBG_DrawText;
- return retval;
+ if (physicscomponent.physicsobject == nullptr)
+ {
+ physicscomponent.physicsobject = std::make_shared();
+ }
+ return *(RigidBody*)physicscomponent.physicsobject.get();
}
- };
- DebugDraw debugDraw;
+ SoftBody& GetSoftBody(wi::scene::SoftBodyPhysicsComponent& physicscomponent)
+ {
+ if (physicscomponent.physicsobject == nullptr)
+ {
+ physicscomponent.physicsobject = std::make_shared();
+ }
+ return *(SoftBody*)physicscomponent.physicsobject.get();
+ }
+ }
+ using namespace bullet;
void Initialize()
{
wi::Timer timer;
- dynamicsWorld.getSolverInfo().m_solverMode |= SOLVER_RANDMIZE_ORDER;
- dynamicsWorld.getDispatchInfo().m_enableSatConvex = true;
- dynamicsWorld.getSolverInfo().m_splitImpulse = true;
- dynamicsWorld.setGravity(gravity);
- dynamicsWorld.setDebugDrawer(&debugDraw);
-
- btSoftBodyWorldInfo& softWorldInfo = dynamicsWorld.getWorldInfo();
- softWorldInfo.air_density = btScalar(1.2f);
- softWorldInfo.water_density = 0;
- softWorldInfo.water_offset = 0;
- softWorldInfo.water_normal = btVector3(0, 0, 0);
- softWorldInfo.m_gravity.setValue(gravity.x(), gravity.y(), gravity.z());
- softWorldInfo.m_sparsesdf.Initialize();
-
wi::backlog::post("wi::physics Initialized [Bullet] (" + std::to_string((int)std::round(timer.elapsed())) + " ms)");
}
@@ -108,38 +170,39 @@ namespace wi::physics
int GetAccuracy() { return ACCURACY; }
void SetAccuracy(int value) { ACCURACY = value; }
- void AddRigidBody(Entity entity, wi::scene::RigidBodyPhysicsComponent& physicscomponent, const wi::scene::TransformComponent& transform, const wi::scene::MeshComponent* mesh)
+ void AddRigidBody(
+ wi::scene::Scene& scene,
+ Entity entity,
+ wi::scene::RigidBodyPhysicsComponent& physicscomponent,
+ const wi::scene::TransformComponent& transform,
+ const wi::scene::MeshComponent* mesh
+ )
{
- btCollisionShape* shape = nullptr;
+ RigidBody& physicsobject = GetRigidBody(physicscomponent);
switch (physicscomponent.shape)
{
case RigidBodyPhysicsComponent::CollisionShape::BOX:
- {
- shape = new btBoxShape(btVector3(physicscomponent.box.halfextents.x, physicscomponent.box.halfextents.y, physicscomponent.box.halfextents.z));
- }
- break;
-
+ physicsobject.shape = std::make_unique(btVector3(physicscomponent.box.halfextents.x, physicscomponent.box.halfextents.y, physicscomponent.box.halfextents.z));
+ break;
case RigidBodyPhysicsComponent::CollisionShape::SPHERE:
- {
- shape = new btSphereShape(btScalar(physicscomponent.sphere.radius));
- }
- break;
-
+ physicsobject.shape = std::make_unique(btScalar(physicscomponent.sphere.radius));
+ break;
case RigidBodyPhysicsComponent::CollisionShape::CAPSULE:
- shape = new btCapsuleShape(btScalar(physicscomponent.capsule.radius), btScalar(physicscomponent.capsule.height));
+ physicsobject.shape = std::make_unique(btScalar(physicscomponent.capsule.radius), btScalar(physicscomponent.capsule.height));
break;
case RigidBodyPhysicsComponent::CollisionShape::CONVEX_HULL:
if(mesh != nullptr)
{
- shape = new btConvexHullShape();
+ physicsobject.shape = std::make_unique();
+ btConvexHullShape* convexHull = (btConvexHullShape*)physicsobject.shape.get();
for (auto& pos : mesh->vertex_positions)
{
- ((btConvexHullShape*)shape)->addPoint(btVector3(pos.x, pos.y, pos.z));
+ convexHull->addPoint(btVector3(pos.x, pos.y, pos.z));
}
btVector3 S(transform.scale_local.x, transform.scale_local.y, transform.scale_local.z);
- shape->setLocalScaling(S);
+ physicsobject.shape->setLocalScaling(S);
}
else
{
@@ -166,20 +229,19 @@ namespace wi::physics
totalTriangles += int(subset.indexCount / 3);
}
- btTriangleIndexVertexArray* indexVertexArrays = new btTriangleIndexVertexArray(
+ physicsobject.triangles = btTriangleIndexVertexArray(
totalTriangles,
indices,
- 3 * sizeof(int),
+ 3 * int(sizeof(int)),
int(mesh->vertex_positions.size()),
(btScalar*)mesh->vertex_positions.data(),
- sizeof(XMFLOAT3)
+ int(sizeof(XMFLOAT3))
);
bool useQuantizedAabbCompression = true;
- shape = new btBvhTriangleMeshShape(indexVertexArrays, useQuantizedAabbCompression);
+ physicsobject.shape = std::make_unique(&physicsobject.triangles, useQuantizedAabbCompression);
btVector3 S(transform.scale_local.x, transform.scale_local.y, transform.scale_local.z);
- shape->setLocalScaling(S);
- shape->setUserPointer(indexVertexArrays);
+ physicsobject.shape->setLocalScaling(S);
}
else
{
@@ -189,7 +251,12 @@ namespace wi::physics
break;
}
- if (shape != nullptr)
+ if (physicsobject.shape == nullptr)
+ {
+ physicscomponent.physicsobject = nullptr;
+ return;
+ }
+ else
{
// Use default margin for now
//shape->setMargin(btScalar(0.01));
@@ -206,7 +273,7 @@ namespace wi::physics
btVector3 localInertia(0, 0, 0);
if (isDynamic)
{
- shape->calculateLocalInertia(mass, localInertia);
+ physicsobject.shape->calculateLocalInertia(mass, localInertia);
}
else
{
@@ -218,36 +285,42 @@ namespace wi::physics
shapeTransform.setIdentity();
shapeTransform.setOrigin(btVector3(transform.translation_local.x, transform.translation_local.y, transform.translation_local.z));
shapeTransform.setRotation(btQuaternion(transform.rotation_local.x, transform.rotation_local.y, transform.rotation_local.z, transform.rotation_local.w));
- btDefaultMotionState* myMotionState = new btDefaultMotionState(shapeTransform);
+ physicsobject.motionState = btDefaultMotionState(shapeTransform);
- btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, shape, localInertia);
+ btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, &physicsobject.motionState, physicsobject.shape.get(), localInertia);
//rbInfo.m_friction = physicscomponent.friction;
//rbInfo.m_restitution = physicscomponent.restitution;
//rbInfo.m_linearDamping = physicscomponent.damping;
//rbInfo.m_angularDamping = physicscomponent.damping;
- btRigidBody* rigidbody = new btRigidBody(rbInfo);
- rigidbody->setUserIndex(entity);
+ physicsobject.rigidBody = std::make_unique(rbInfo);
+ physicsobject.rigidBody->setUserIndex(entity);
if (physicscomponent.IsKinematic())
{
- rigidbody->setCollisionFlags(rigidbody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
+ physicsobject.rigidBody->setCollisionFlags(physicsobject.rigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
}
if (physicscomponent.IsDisableDeactivation())
{
- rigidbody->setActivationState(DISABLE_DEACTIVATION);
+ physicsobject.rigidBody->setActivationState(DISABLE_DEACTIVATION);
}
if (physicscomponent.shape == RigidBodyPhysicsComponent::CollisionShape::TRIANGLE_MESH)
{
- rigidbody->setActivationState(DISABLE_DEACTIVATION);
+ physicsobject.rigidBody->setActivationState(DISABLE_DEACTIVATION);
}
- dynamicsWorld.addRigidBody(rigidbody);
- physicscomponent.physicsobject = rigidbody;
+ physicsobject.physics_scene = scene.physics_scene;
+ GetPhysicsScene(scene).dynamicsWorld.addRigidBody(physicsobject.rigidBody.get());
}
}
- void AddSoftBody(Entity entity, wi::scene::SoftBodyPhysicsComponent& physicscomponent, const wi::scene::MeshComponent& mesh)
+ void AddSoftBody(
+ wi::scene::Scene& scene,
+ Entity entity,
+ wi::scene::SoftBodyPhysicsComponent& physicscomponent,
+ const wi::scene::MeshComponent& mesh
+ )
{
+ SoftBody& physicsobject = GetSoftBody(physicscomponent);
physicscomponent.CreateFromMesh(mesh);
XMMATRIX worldMatrix = XMLoadFloat4x4(&physicscomponent.worldMatrix);
@@ -283,14 +356,67 @@ namespace wi::physics
}
}
- // This function uses new to allocate btSoftbody internally:
- btSoftBody* softbody = btSoftBodyHelpers::CreateFromTriMesh(
- dynamicsWorld.getWorldInfo(),
- btVerts.data(),
- btInd.data(),
- int(btInd.size() / 3),
- false
- );
+ //// This function uses new to allocate btSoftbody internally:
+ //btSoftBody* softbody = btSoftBodyHelpers::CreateFromTriMesh(
+ // GetPhysicsScene(scene).dynamicsWorld.getWorldInfo(),
+ // btVerts.data(),
+ // btInd.data(),
+ // int(btInd.size() / 3),
+ // false
+ //);
+
+ // Modified version of btSoftBodyHelpers::CreateFromTriMesh:
+ // This version does not allocate btSoftbody with new
+ btSoftBody* softbody = nullptr;
+ {
+ btSoftBodyWorldInfo& worldInfo = GetPhysicsScene(scene).dynamicsWorld.getWorldInfo();
+ const btScalar* vertices = btVerts.data();
+ const int* triangles = btInd.data();
+ int ntriangles = int(btInd.size() / 3);
+ bool randomizeConstraints = false;
+
+ int maxidx = 0;
+ int i, j, ni;
+
+ for (i = 0, ni = ntriangles * 3; i < ni; ++i)
+ {
+ maxidx = btMax(triangles[i], maxidx);
+ }
+ ++maxidx;
+ btAlignedObjectArray chks;
+ btAlignedObjectArray vtx;
+ chks.resize(maxidx * maxidx, false);
+ vtx.resize(maxidx);
+ for (i = 0, j = 0, ni = maxidx * 3; i < ni; ++j, i += 3)
+ {
+ vtx[j] = btVector3(vertices[i], vertices[i + 1], vertices[i + 2]);
+ }
+ //btSoftBody* psb = new btSoftBody(&worldInfo, vtx.size(), &vtx[0], 0);
+ physicsobject.softBody = std::make_unique(&worldInfo, vtx.size(), &vtx[0], nullptr);
+ softbody = physicsobject.softBody.get();
+ btSoftBody* psb = softbody;
+ for (i = 0, ni = ntriangles * 3; i < ni; i += 3)
+ {
+ const int idx[] = { triangles[i],triangles[i + 1],triangles[i + 2] };
+#define IDX(_x_,_y_) ((_y_)*maxidx+(_x_))
+ for (int j = 2, k = 0; k < 3; j = k++)
+ {
+ if (!chks[IDX(idx[j], idx[k])])
+ {
+ chks[IDX(idx[j], idx[k])] = true;
+ chks[IDX(idx[k], idx[j])] = true;
+ psb->appendLink(idx[j], idx[k]);
+ }
+ }
+#undef IDX
+ psb->appendFace(idx[0], idx[1], idx[2]);
+ }
+
+ if (randomizeConstraints)
+ {
+ psb->randomizeConstraints();
+ }
+ }
if (softbody)
{
@@ -342,8 +468,8 @@ namespace wi::physics
softbody->setPose(true, true);
- dynamicsWorld.addSoftBody(softbody);
- physicscomponent.physicsobject = softbody;
+ physicsobject.physics_scene = scene.physics_scene;
+ GetPhysicsScene(scene).dynamicsWorld.addSoftBody(softbody);
}
}
@@ -358,6 +484,8 @@ namespace wi::physics
auto range = wi::profiler::BeginRangeCPU("Physics");
+ btSoftRigidDynamicsWorld& dynamicsWorld = GetPhysicsScene(scene).dynamicsWorld;
+
btVector3 wind = btVector3(scene.weather.windDirection.x, scene.weather.windDirection.y, scene.weather.windDirection.z);
// System will register rigidbodies to objects, and update physics engine state for kinematics:
@@ -376,13 +504,13 @@ namespace wi::physics
mesh = scene.meshes.GetComponent(object->meshID);
}
physicsLock.lock();
- AddRigidBody(entity, physicscomponent, transform, mesh);
+ AddRigidBody(scene, entity, physicscomponent, transform, mesh);
physicsLock.unlock();
}
if (physicscomponent.physicsobject != nullptr)
{
- btRigidBody* rigidbody = (btRigidBody*)physicscomponent.physicsobject;
+ btRigidBody* rigidbody = GetRigidBody(physicscomponent).rigidBody.get();
int activationState = rigidbody->getActivationState();
if (physicscomponent.IsDisableDeactivation())
@@ -444,24 +572,18 @@ namespace wi::physics
if (physicscomponent._flags & SoftBodyPhysicsComponent::FORCE_RESET)
{
physicscomponent._flags &= ~SoftBodyPhysicsComponent::FORCE_RESET;
- if (physicscomponent.physicsobject != nullptr)
- {
- btSoftBody* softbody = (btSoftBody*)physicscomponent.physicsobject;
- delete softbody;
- dynamicsWorld.removeSoftBody(softbody);
- physicscomponent.physicsobject = nullptr;
- }
+ physicscomponent.physicsobject = nullptr;
}
if (physicscomponent._flags & SoftBodyPhysicsComponent::SAFE_TO_REGISTER && physicscomponent.physicsobject == nullptr)
{
physicsLock.lock();
- AddSoftBody(entity, physicscomponent, mesh);
+ AddSoftBody(scene, entity, physicscomponent, mesh);
physicsLock.unlock();
}
if (physicscomponent.physicsobject != nullptr)
{
- btSoftBody* softbody = (btSoftBody*)physicscomponent.physicsobject;
+ btSoftBody* softbody = GetSoftBody(physicscomponent).softBody.get();
softbody->m_cfg.kDF = physicscomponent.friction;
softbody->setWindVelocity(wind);
@@ -508,19 +630,6 @@ namespace wi::physics
if (rigidbody != nullptr)
{
RigidBodyPhysicsComponent* physicscomponent = scene.rigidbodies.GetComponent(entity);
- if (physicscomponent == nullptr || physicscomponent->physicsobject != rigidbody)
- {
- btCollisionShape* shape = rigidbody->getCollisionShape();
- btTriangleIndexVertexArray* triangleinfo = (btTriangleIndexVertexArray*)shape->getUserPointer();
- delete triangleinfo;
- delete shape;
- btMotionState* motionstate = rigidbody->getMotionState();
- delete motionstate;
- dynamicsWorld.removeRigidBody(rigidbody);
- delete rigidbody;
- i--;
- continue;
- }
// Feedback non-kinematic objects to system:
if (IsSimulationEnabled() && !physicscomponent->IsKinematic())
@@ -543,13 +652,6 @@ namespace wi::physics
if (softbody != nullptr)
{
SoftBodyPhysicsComponent* physicscomponent = scene.softbodies.GetComponent(entity);
- if (physicscomponent == nullptr || physicscomponent->physicsobject != softbody)
- {
- dynamicsWorld.removeSoftBody(softbody);
- delete softbody;
- i--;
- continue;
- }
// If you need it, you can enable soft body node debug strings here:
#if 0
@@ -685,62 +787,57 @@ namespace wi::physics
void ApplyForce(
- const wi::scene::RigidBodyPhysicsComponent& physicscomponent,
+ wi::scene::RigidBodyPhysicsComponent& physicscomponent,
const XMFLOAT3& force
)
{
if (physicscomponent.physicsobject != nullptr)
{
- btRigidBody* rigidbody = (btRigidBody*)physicscomponent.physicsobject;
- rigidbody->applyCentralForce(btVector3(force.x, force.y, force.z));
+ GetRigidBody(physicscomponent).rigidBody->applyCentralForce(btVector3(force.x, force.y, force.z));
}
}
void ApplyForceAt(
- const wi::scene::RigidBodyPhysicsComponent& physicscomponent,
+ wi::scene::RigidBodyPhysicsComponent& physicscomponent,
const XMFLOAT3& force,
const XMFLOAT3& at
)
{
if (physicscomponent.physicsobject != nullptr)
{
- btRigidBody* rigidbody = (btRigidBody*)physicscomponent.physicsobject;
- rigidbody->applyForce(btVector3(force.x, force.y, force.z), btVector3(at.x, at.y, at.z));
+ GetRigidBody(physicscomponent).rigidBody->applyForce(btVector3(force.x, force.y, force.z), btVector3(at.x, at.y, at.z));
}
}
void ApplyImpulse(
- const wi::scene::RigidBodyPhysicsComponent& physicscomponent,
+ wi::scene::RigidBodyPhysicsComponent& physicscomponent,
const XMFLOAT3& impulse
)
{
if (physicscomponent.physicsobject != nullptr)
{
- btRigidBody* rigidbody = (btRigidBody*)physicscomponent.physicsobject;
- rigidbody->applyCentralImpulse(btVector3(impulse.x, impulse.y, impulse.z));
+ GetRigidBody(physicscomponent).rigidBody->applyCentralImpulse(btVector3(impulse.x, impulse.y, impulse.z));
}
}
void ApplyImpulseAt(
- const wi::scene::RigidBodyPhysicsComponent& physicscomponent,
+ wi::scene::RigidBodyPhysicsComponent& physicscomponent,
const XMFLOAT3& impulse,
const XMFLOAT3& at
)
{
if (physicscomponent.physicsobject != nullptr)
{
- btRigidBody* rigidbody = (btRigidBody*)physicscomponent.physicsobject;
- rigidbody->applyImpulse(btVector3(impulse.x, impulse.y, impulse.z), btVector3(at.x, at.y, at.z));
+ GetRigidBody(physicscomponent).rigidBody->applyImpulse(btVector3(impulse.x, impulse.y, impulse.z), btVector3(at.x, at.y, at.z));
}
}
void ApplyTorque(
- const wi::scene::RigidBodyPhysicsComponent& physicscomponent,
+ wi::scene::RigidBodyPhysicsComponent& physicscomponent,
const XMFLOAT3& torque
)
{
if (physicscomponent.physicsobject != nullptr)
{
- btRigidBody* rigidbody = (btRigidBody*)physicscomponent.physicsobject;
- rigidbody->applyTorque(btVector3(torque.x, torque.y, torque.z));
+ GetRigidBody(physicscomponent).rigidBody->applyTorque(btVector3(torque.x, torque.y, torque.z));
}
}
}
diff --git a/WickedEngine/wiRenderPath3D_BindLua.h b/WickedEngine/wiRenderPath3D_BindLua.h
index 9e18d70c3..fb6d7ea91 100644
--- a/WickedEngine/wiRenderPath3D_BindLua.h
+++ b/WickedEngine/wiRenderPath3D_BindLua.h
@@ -3,6 +3,7 @@
#include "wiLuna.h"
#include "wiRenderPath3D.h"
#include "wiRenderPath2D_BindLua.h"
+#include "wiScene_BindLua.h"
namespace wi::lua
{
@@ -23,6 +24,8 @@ namespace wi::lua
}
RenderPath3D_BindLua(lua_State* L)
{
+ renderpath.scene = wi::lua::scene::GetGlobalScene();
+ renderpath.camera = wi::lua::scene::GetGlobalCamera();
this->component = &renderpath;
}
diff --git a/WickedEngine/wiRenderer_BindLua.cpp b/WickedEngine/wiRenderer_BindLua.cpp
index 0c51bd9a3..bb5a53e6f 100644
--- a/WickedEngine/wiRenderer_BindLua.cpp
+++ b/WickedEngine/wiRenderer_BindLua.cpp
@@ -360,7 +360,7 @@ namespace wi::lua::renderer
{
XMFLOAT3 pos;
XMStoreFloat3(&pos, XMLoadFloat4(v));
- wi::scene::GetScene().PutWaterRipple(wi::lua::GetScriptPath() + name, pos);
+ GetGlobalScene()->PutWaterRipple(wi::lua::GetScriptPath() + name, pos);
}
else
wi::lua::SError(L, "PutWaterRipple(String imagename, Vector position) argument is not a Vector!");
@@ -375,7 +375,7 @@ namespace wi::lua::renderer
Scene_BindLua* scene = Luna::lightcheck(L, 1);
if (scene == nullptr)
{
- wi::renderer::ClearWorld(wi::scene::GetScene());
+ wi::renderer::ClearWorld(*GetGlobalScene());
}
else
{
diff --git a/WickedEngine/wiScene.h b/WickedEngine/wiScene.h
index 1044ddb69..049173684 100644
--- a/WickedEngine/wiScene.h
+++ b/WickedEngine/wiScene.h
@@ -763,7 +763,7 @@ namespace wi::scene
uint32_t mesh_lod = 0;
// Non-serialized attributes:
- void* physicsobject = nullptr; // You can set to null to recreate the physics object the next time phsyics system will be running.
+ std::shared_ptr physicsobject = nullptr; // You can set to null to recreate the physics object the next time phsyics system will be running.
inline void SetDisableDeactivation(bool value) { if (value) { _flags |= DISABLE_DEACTIVATION; } else { _flags &= ~DISABLE_DEACTIVATION; } }
inline void SetKinematic(bool value) { if (value) { _flags |= KINEMATIC; } else { _flags &= ~KINEMATIC; } }
@@ -793,7 +793,7 @@ namespace wi::scene
wi::vector weights; // weight per physics vertex controlling the mass. (0: disable weight (no physics, only animation), 1: default weight)
// Non-serialized attributes:
- void* physicsobject = nullptr;
+ std::shared_ptr physicsobject = nullptr; // You can set to null to recreate the physics object the next time phsyics system will be running.
XMFLOAT4X4 worldMatrix = wi::math::IDENTITY_MATRIX;
wi::vector vertex_positions_simulation; // graphics vertices after simulation (world space)
wi::vectorvertex_tangents_tmp;
@@ -1338,7 +1338,7 @@ namespace wi::scene
};
uint32_t flags = EMPTY;
-
+ std::shared_ptr physics_scene;
wi::SpinLock locker;
wi::primitive::AABB bounds;
wi::vector parallel_bounds;
diff --git a/WickedEngine/wiScene_BindLua.cpp b/WickedEngine/wiScene_BindLua.cpp
index d74a3cc4d..426e806eb 100644
--- a/WickedEngine/wiScene_BindLua.cpp
+++ b/WickedEngine/wiScene_BindLua.cpp
@@ -12,6 +12,26 @@ using namespace wi::lua::primitive;
namespace wi::lua::scene
{
+static wi::scene::Scene* globalscene = &wi::scene::GetScene();
+static wi::scene::CameraComponent* globalcam = &wi::scene::GetCamera();
+
+void SetGlobalScene(wi::scene::Scene* scene)
+{
+ globalscene = scene;
+}
+void SetGlobalCamera(wi::scene::CameraComponent* camera)
+{
+ globalcam = camera;
+}
+wi::scene::Scene* GetGlobalScene()
+{
+ return globalscene;
+}
+wi::scene::CameraComponent* GetGlobalCamera()
+{
+ return globalcam;
+}
+
int CreateEntity_BindLua(lua_State* L)
{
Entity entity = CreateEntity();
@@ -21,12 +41,12 @@ int CreateEntity_BindLua(lua_State* L)
int GetCamera(lua_State* L)
{
- Luna::push(L, new CameraComponent_BindLua(&wi::scene::GetCamera()));
+ Luna::push(L, new CameraComponent_BindLua(GetGlobalCamera()));
return 1;
}
int GetScene(lua_State* L)
{
- Luna::push(L, new Scene_BindLua(&wi::scene::GetScene()));
+ Luna::push(L, new Scene_BindLua(GetGlobalScene()));
return 1;
}
int LoadModel(lua_State* L)
@@ -83,7 +103,9 @@ int LoadModel(lua_State* L)
wi::lua::SError(L, "LoadModel(string fileName, opt Matrix transform) argument is not a matrix!");
}
}
- Entity root = wi::scene::LoadModel(fileName, transform, true);
+ Scene scene;
+ Entity root = wi::scene::LoadModel(scene, fileName, transform, true);
+ GetGlobalScene()->Merge(scene);
wi::lua::SSetLongLong(L, root);
return 1;
}
@@ -104,7 +126,7 @@ int Pick(lua_State* L)
{
uint32_t renderTypeMask = wi::enums::RENDERTYPE_OPAQUE;
uint32_t layerMask = 0xFFFFFFFF;
- Scene* scene = &wi::scene::GetScene();
+ Scene* scene = GetGlobalScene();
if (argc > 1)
{
renderTypeMask = (uint32_t)wi::lua::SGetInt(L, 2);
@@ -154,7 +176,7 @@ int SceneIntersectSphere(lua_State* L)
{
uint32_t renderTypeMask = wi::enums::RENDERTYPE_OPAQUE;
uint32_t layerMask = 0xFFFFFFFF;
- Scene* scene = &wi::scene::GetScene();
+ Scene* scene = GetGlobalScene();
if (argc > 1)
{
renderTypeMask = (uint32_t)wi::lua::SGetInt(L, 2);
@@ -204,7 +226,7 @@ int SceneIntersectCapsule(lua_State* L)
{
uint32_t renderTypeMask = wi::enums::RENDERTYPE_OPAQUE;
uint32_t layerMask = 0xFFFFFFFF;
- Scene* scene = &wi::scene::GetScene();
+ Scene* scene = GetGlobalScene();
if (argc > 1)
{
renderTypeMask = (uint32_t)wi::lua::SGetInt(L, 2);
@@ -359,7 +381,6 @@ Luna::PropertyType Scene_BindLua::properties[] = {
{ NULL, NULL }
};
-
int Scene_BindLua::Update(lua_State* L)
{
int argc = wi::lua::SGetArgCount(L);
diff --git a/WickedEngine/wiScene_BindLua.h b/WickedEngine/wiScene_BindLua.h
index 28d8e45ae..12b2a4472 100644
--- a/WickedEngine/wiScene_BindLua.h
+++ b/WickedEngine/wiScene_BindLua.h
@@ -5,6 +5,15 @@
namespace wi::lua::scene
{
+ // If the application doesn't use the global scene, but manages it manually,
+ // Then this can be used to override the global GetScene() in lua scripts with a custom scene
+ void SetGlobalScene(wi::scene::Scene* scene);
+ // If the application doesn't use the global camera, but manages it manually,
+ // Then this can be used to override the global GetCamera() in lua scripts with a custom camera
+ void SetGlobalCamera(wi::scene::CameraComponent* camera);
+ wi::scene::Scene* GetGlobalScene();
+ wi::scene::CameraComponent* GetGlobalCamera();
+
void Bind();
class Scene_BindLua
diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp
index 7b89c0218..1c08d6824 100644
--- a/WickedEngine/wiVersion.cpp
+++ b/WickedEngine/wiVersion.cpp
@@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 70;
// minor bug fixes, alterations, refactors, updates
- const int revision = 10;
+ const int revision = 11;
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);