diff --git a/Editor/AnimationWindow.cpp b/Editor/AnimationWindow.cpp index a0995e2b3..4a773bd92 100644 --- a/Editor/AnimationWindow.cpp +++ b/Editor/AnimationWindow.cpp @@ -1,7 +1,8 @@ #include "stdafx.h" #include "AnimationWindow.h" -using namespace wiSceneComponents; +using namespace wiECS; +using namespace wiSceneSystem; AnimationWindow::AnimationWindow(wiGUI* gui) :GUI(gui) { @@ -21,189 +22,189 @@ AnimationWindow::AnimationWindow(wiGUI* gui) :GUI(gui) //////////////////////////////////// - actionsComboBox = new wiComboBox("Primary Action: "); - actionsComboBox->SetSize(XMFLOAT2(300, 20)); - actionsComboBox->SetPos(XMFLOAT2(x, y += step)); - actionsComboBox->OnSelect([&](wiEventArgs args) { - if (armature != nullptr && args.iValue >= 0) - { - armature->ChangeAction(args.sValue, blendSlider->GetValue()); - } - }); - actionsComboBox->SetEnabled(false); - actionsComboBox->SetTooltip("Choose an animation clip..."); - animWindow->AddWidget(actionsComboBox); + //actionsComboBox = new wiComboBox("Primary Action: "); + //actionsComboBox->SetSize(XMFLOAT2(300, 20)); + //actionsComboBox->SetPos(XMFLOAT2(x, y += step)); + //actionsComboBox->OnSelect([&](wiEventArgs args) { + // if (armature != nullptr && args.iValue >= 0) + // { + // armature->ChangeAction(args.sValue, blendSlider->GetValue()); + // } + //}); + //actionsComboBox->SetEnabled(false); + //actionsComboBox->SetTooltip("Choose an animation clip..."); + //animWindow->AddWidget(actionsComboBox); - blendSlider = new wiSlider(0.0f, 60, 0, 100000, "Blend Frames: "); - blendSlider->SetSize(XMFLOAT2(100, 30)); - blendSlider->SetPos(XMFLOAT2(x, y += step)); - blendSlider->OnSlide([&](wiEventArgs args) { - if (armature != nullptr) - { - AnimationLayer* layer = armature->GetPrimaryAnimation(); - if (layer != nullptr) - { - layer->blendFrames = args.fValue; - } - } - }); - blendSlider->SetEnabled(false); - blendSlider->SetTooltip("Adjust the blend length in frames when changing actions..."); - animWindow->AddWidget(blendSlider); + //blendSlider = new wiSlider(0.0f, 60, 0, 100000, "Blend Frames: "); + //blendSlider->SetSize(XMFLOAT2(100, 30)); + //blendSlider->SetPos(XMFLOAT2(x, y += step)); + //blendSlider->OnSlide([&](wiEventArgs args) { + // if (armature != nullptr) + // { + // AnimationLayer* layer = armature->GetPrimaryAnimation(); + // if (layer != nullptr) + // { + // layer->blendFrames = args.fValue; + // } + // } + //}); + //blendSlider->SetEnabled(false); + //blendSlider->SetTooltip("Adjust the blend length in frames when changing actions..."); + //animWindow->AddWidget(blendSlider); - loopedCheckBox = new wiCheckBox("Looped: "); - loopedCheckBox->SetTooltip("Toggle animation looping behaviour."); - loopedCheckBox->SetPos(XMFLOAT2(470, y)); - loopedCheckBox->OnClick([&](wiEventArgs args) { - if (armature != nullptr) - { - AnimationLayer* layer = armature->GetPrimaryAnimation(); - if (layer != nullptr) - { - layer->looped = args.bValue; - } - } - }); - animWindow->AddWidget(loopedCheckBox); + //loopedCheckBox = new wiCheckBox("Looped: "); + //loopedCheckBox->SetTooltip("Toggle animation looping behaviour."); + //loopedCheckBox->SetPos(XMFLOAT2(470, y)); + //loopedCheckBox->OnClick([&](wiEventArgs args) { + // if (armature != nullptr) + // { + // AnimationLayer* layer = armature->GetPrimaryAnimation(); + // if (layer != nullptr) + // { + // layer->looped = args.bValue; + // } + // } + //}); + //animWindow->AddWidget(loopedCheckBox); - ///////////////////////////////////// + /////////////////////////////////////// - actionsComboBox1 = new wiComboBox("Secondary Action 1: "); - actionsComboBox1->SetSize(XMFLOAT2(300, 20)); - actionsComboBox1->SetPos(XMFLOAT2(x, y += step*2)); - actionsComboBox1->OnSelect([&](wiEventArgs args) { - if (armature != nullptr && args.iValue >= 0) - { - armature->ChangeAction(args.sValue, blendSlider1->GetValue(), "SECONDARY1", weightSlider1->GetValue()); - } - }); - actionsComboBox1->SetEnabled(false); - actionsComboBox1->SetTooltip("Choose an animation clip for a secondary slot..."); - animWindow->AddWidget(actionsComboBox1); + //actionsComboBox1 = new wiComboBox("Secondary Action 1: "); + //actionsComboBox1->SetSize(XMFLOAT2(300, 20)); + //actionsComboBox1->SetPos(XMFLOAT2(x, y += step*2)); + //actionsComboBox1->OnSelect([&](wiEventArgs args) { + // if (armature != nullptr && args.iValue >= 0) + // { + // armature->ChangeAction(args.sValue, blendSlider1->GetValue(), "SECONDARY1", weightSlider1->GetValue()); + // } + //}); + //actionsComboBox1->SetEnabled(false); + //actionsComboBox1->SetTooltip("Choose an animation clip for a secondary slot..."); + //animWindow->AddWidget(actionsComboBox1); - blendSlider1 = new wiSlider(0.0f, 60, 0, 100000, "Blend Frames 1: "); - blendSlider1->SetSize(XMFLOAT2(100, 30)); - blendSlider1->SetPos(XMFLOAT2(x, y += step)); - blendSlider1->OnSlide([&](wiEventArgs args) { - if (armature != nullptr) - { - AnimationLayer* layer1 = armature->GetAnimLayer("SECONDARY1"); - if (layer1 != nullptr) - { - layer1->blendFrames = args.fValue; - } - } - }); - blendSlider1->SetEnabled(false); - blendSlider1->SetTooltip("Adjust the blend length in frames when changing actions..."); - animWindow->AddWidget(blendSlider1); + //blendSlider1 = new wiSlider(0.0f, 60, 0, 100000, "Blend Frames 1: "); + //blendSlider1->SetSize(XMFLOAT2(100, 30)); + //blendSlider1->SetPos(XMFLOAT2(x, y += step)); + //blendSlider1->OnSlide([&](wiEventArgs args) { + // if (armature != nullptr) + // { + // AnimationLayer* layer1 = armature->GetAnimLayer("SECONDARY1"); + // if (layer1 != nullptr) + // { + // layer1->blendFrames = args.fValue; + // } + // } + //}); + //blendSlider1->SetEnabled(false); + //blendSlider1->SetTooltip("Adjust the blend length in frames when changing actions..."); + //animWindow->AddWidget(blendSlider1); - loopedCheckBox1 = new wiCheckBox("Looped: "); - loopedCheckBox1->SetTooltip("Toggle animation looping behaviour."); - loopedCheckBox1->SetPos(XMFLOAT2(470, y)); - loopedCheckBox1->OnClick([&](wiEventArgs args) { - if (armature != nullptr) - { - AnimationLayer* layer1 = armature->GetAnimLayer("SECONDARY1"); - if (layer1 != nullptr) - { - layer1->looped = args.bValue; - } - } - }); - animWindow->AddWidget(loopedCheckBox1); + //loopedCheckBox1 = new wiCheckBox("Looped: "); + //loopedCheckBox1->SetTooltip("Toggle animation looping behaviour."); + //loopedCheckBox1->SetPos(XMFLOAT2(470, y)); + //loopedCheckBox1->OnClick([&](wiEventArgs args) { + // if (armature != nullptr) + // { + // AnimationLayer* layer1 = armature->GetAnimLayer("SECONDARY1"); + // if (layer1 != nullptr) + // { + // layer1->looped = args.bValue; + // } + // } + //}); + //animWindow->AddWidget(loopedCheckBox1); - weightSlider1 = new wiSlider(0.0f, 1.0f, 1.0f, 100000, "Blend Weight 1: "); - weightSlider1->SetSize(XMFLOAT2(100, 30)); - weightSlider1->SetPos(XMFLOAT2(x, y += step)); - weightSlider1->OnSlide([&](wiEventArgs args) { - if (armature != nullptr) - { - AnimationLayer* layer1 = armature->GetAnimLayer("SECONDARY1"); - if (layer1 != nullptr) - { - layer1->weight = args.fValue; - } - } - }); - weightSlider1->SetEnabled(false); - weightSlider1->SetTooltip("Adjust the blend weight for the secondary action..."); - animWindow->AddWidget(weightSlider1); + //weightSlider1 = new wiSlider(0.0f, 1.0f, 1.0f, 100000, "Blend Weight 1: "); + //weightSlider1->SetSize(XMFLOAT2(100, 30)); + //weightSlider1->SetPos(XMFLOAT2(x, y += step)); + //weightSlider1->OnSlide([&](wiEventArgs args) { + // if (armature != nullptr) + // { + // AnimationLayer* layer1 = armature->GetAnimLayer("SECONDARY1"); + // if (layer1 != nullptr) + // { + // layer1->weight = args.fValue; + // } + // } + //}); + //weightSlider1->SetEnabled(false); + //weightSlider1->SetTooltip("Adjust the blend weight for the secondary action..."); + //animWindow->AddWidget(weightSlider1); - ///////////////////////////////////// + /////////////////////////////////////// - actionsComboBox2 = new wiComboBox("Secondary Action 2: "); - actionsComboBox2->SetSize(XMFLOAT2(300, 20)); - actionsComboBox2->SetPos(XMFLOAT2(x, y += step * 2)); - actionsComboBox2->OnSelect([&](wiEventArgs args) { - if (armature != nullptr && args.iValue >= 0) - { - armature->ChangeAction(args.sValue, blendSlider2->GetValue(), "SECONDARY2", weightSlider2->GetValue()); - } - }); - actionsComboBox2->SetEnabled(false); - actionsComboBox2->SetTooltip("Choose an animation clip for a secondary slot..."); - animWindow->AddWidget(actionsComboBox2); + //actionsComboBox2 = new wiComboBox("Secondary Action 2: "); + //actionsComboBox2->SetSize(XMFLOAT2(300, 20)); + //actionsComboBox2->SetPos(XMFLOAT2(x, y += step * 2)); + //actionsComboBox2->OnSelect([&](wiEventArgs args) { + // if (armature != nullptr && args.iValue >= 0) + // { + // armature->ChangeAction(args.sValue, blendSlider2->GetValue(), "SECONDARY2", weightSlider2->GetValue()); + // } + //}); + //actionsComboBox2->SetEnabled(false); + //actionsComboBox2->SetTooltip("Choose an animation clip for a secondary slot..."); + //animWindow->AddWidget(actionsComboBox2); - blendSlider2 = new wiSlider(0.0f, 60, 0, 100000, "Blend Frames 2: "); - blendSlider2->SetSize(XMFLOAT2(100, 30)); - blendSlider2->SetPos(XMFLOAT2(x, y += step)); - blendSlider2->OnSlide([&](wiEventArgs args) { - if (armature != nullptr) - { - AnimationLayer* layer2 = armature->GetAnimLayer("SECONDARY2"); - if (layer2 != nullptr) - { - layer2->blendFrames = args.fValue; - } - } - }); - blendSlider2->SetEnabled(false); - blendSlider2->SetTooltip("Adjust the blend length in frames when changing actions..."); - animWindow->AddWidget(blendSlider2); + //blendSlider2 = new wiSlider(0.0f, 60, 0, 100000, "Blend Frames 2: "); + //blendSlider2->SetSize(XMFLOAT2(100, 30)); + //blendSlider2->SetPos(XMFLOAT2(x, y += step)); + //blendSlider2->OnSlide([&](wiEventArgs args) { + // if (armature != nullptr) + // { + // AnimationLayer* layer2 = armature->GetAnimLayer("SECONDARY2"); + // if (layer2 != nullptr) + // { + // layer2->blendFrames = args.fValue; + // } + // } + //}); + //blendSlider2->SetEnabled(false); + //blendSlider2->SetTooltip("Adjust the blend length in frames when changing actions..."); + //animWindow->AddWidget(blendSlider2); - loopedCheckBox2 = new wiCheckBox("Looped: "); - loopedCheckBox2->SetTooltip("Toggle animation looping behaviour."); - loopedCheckBox2->SetPos(XMFLOAT2(470, y)); - loopedCheckBox2->OnClick([&](wiEventArgs args) { - if (armature != nullptr) - { - AnimationLayer* layer2 = armature->GetAnimLayer("SECONDARY2"); - if (layer2 != nullptr) - { - layer2->looped = args.bValue; - } - } - }); - animWindow->AddWidget(loopedCheckBox2); + //loopedCheckBox2 = new wiCheckBox("Looped: "); + //loopedCheckBox2->SetTooltip("Toggle animation looping behaviour."); + //loopedCheckBox2->SetPos(XMFLOAT2(470, y)); + //loopedCheckBox2->OnClick([&](wiEventArgs args) { + // if (armature != nullptr) + // { + // AnimationLayer* layer2 = armature->GetAnimLayer("SECONDARY2"); + // if (layer2 != nullptr) + // { + // layer2->looped = args.bValue; + // } + // } + //}); + //animWindow->AddWidget(loopedCheckBox2); - weightSlider2 = new wiSlider(0.0f, 1.0f, 1.0f, 100000, "Blend Weight 2: "); - weightSlider2->SetSize(XMFLOAT2(100, 30)); - weightSlider2->SetPos(XMFLOAT2(x, y += step)); - weightSlider2->OnSlide([&](wiEventArgs args) { - if (armature != nullptr) - { - AnimationLayer* layer2 = armature->GetAnimLayer("SECONDARY2"); - if (layer2 != nullptr) - { - layer2->weight = args.fValue; - } - } - }); - weightSlider2->SetEnabled(false); - weightSlider2->SetTooltip("Adjust the blend weight for the secondary action..."); - animWindow->AddWidget(weightSlider2); + //weightSlider2 = new wiSlider(0.0f, 1.0f, 1.0f, 100000, "Blend Weight 2: "); + //weightSlider2->SetSize(XMFLOAT2(100, 30)); + //weightSlider2->SetPos(XMFLOAT2(x, y += step)); + //weightSlider2->OnSlide([&](wiEventArgs args) { + // if (armature != nullptr) + // { + // AnimationLayer* layer2 = armature->GetAnimLayer("SECONDARY2"); + // if (layer2 != nullptr) + // { + // layer2->weight = args.fValue; + // } + // } + //}); + //weightSlider2->SetEnabled(false); + //weightSlider2->SetTooltip("Adjust the blend weight for the secondary action..."); + //animWindow->AddWidget(weightSlider2); - /////////////////////////////////////////////////// + ///////////////////////////////////////////////////// - animWindow->Translate(XMFLOAT3(100, 50, 0)); - animWindow->SetVisible(false); + //animWindow->Translate(XMFLOAT3(100, 50, 0)); + //animWindow->SetVisible(false); - SetArmature(nullptr); + //SetArmature(nullptr); } @@ -215,79 +216,81 @@ AnimationWindow::~AnimationWindow() SAFE_DELETE(animWindow); } -void AnimationWindow::SetArmature(Armature* armature) +void AnimationWindow::SetEntity(Entity entity) { - if (this->armature == armature) - return; + this->entity = entity; - this->armature = armature; + //if (this->armature == armature) + // return; - if (armature != nullptr) - { - actionsComboBox->ClearItems(); - actionsComboBox->SetEnabled(true); - for (auto& x : armature->actions) - { - actionsComboBox->AddItem(x.name); - } - actionsComboBox->SetSelected(armature->GetPrimaryAnimation()->activeAction); - blendSlider->SetEnabled(true); - AnimationLayer* layer = armature->GetPrimaryAnimation(); - if (layer != nullptr) - { - loopedCheckBox->SetCheck(layer->looped); - } - loopedCheckBox->SetEnabled(true); + //this->armature = armature; - actionsComboBox1->ClearItems(); - actionsComboBox1->SetEnabled(true); - for (auto& x : armature->actions) - { - actionsComboBox1->AddItem(x.name); - } - actionsComboBox1->SetSelected(0); - blendSlider1->SetEnabled(true); - weightSlider1->SetEnabled(true); - AnimationLayer* layer1 = armature->GetAnimLayer("SECONDARY1"); - if (layer1 != nullptr) - { - loopedCheckBox1->SetCheck(layer1->looped); - } - loopedCheckBox1->SetEnabled(true); + //if (armature != nullptr) + //{ + // actionsComboBox->ClearItems(); + // actionsComboBox->SetEnabled(true); + // for (auto& x : armature->actions) + // { + // actionsComboBox->AddItem(x.name); + // } + // actionsComboBox->SetSelected(armature->GetPrimaryAnimation()->activeAction); + // blendSlider->SetEnabled(true); + // AnimationLayer* layer = armature->GetPrimaryAnimation(); + // if (layer != nullptr) + // { + // loopedCheckBox->SetCheck(layer->looped); + // } + // loopedCheckBox->SetEnabled(true); - actionsComboBox2->ClearItems(); - actionsComboBox2->SetEnabled(true); - for (auto& x : armature->actions) - { - actionsComboBox2->AddItem(x.name); - } - actionsComboBox2->SetSelected(0); - blendSlider2->SetEnabled(true); - weightSlider2->SetEnabled(true); - AnimationLayer* layer2 = armature->GetAnimLayer("SECONDARY2"); - if (layer2 != nullptr) - { - loopedCheckBox2->SetCheck(layer2->looped); - } - loopedCheckBox2->SetEnabled(true); - } - else - { - actionsComboBox->ClearItems(); - actionsComboBox->SetEnabled(false); - blendSlider->SetEnabled(false); - loopedCheckBox->SetEnabled(false); + // actionsComboBox1->ClearItems(); + // actionsComboBox1->SetEnabled(true); + // for (auto& x : armature->actions) + // { + // actionsComboBox1->AddItem(x.name); + // } + // actionsComboBox1->SetSelected(0); + // blendSlider1->SetEnabled(true); + // weightSlider1->SetEnabled(true); + // AnimationLayer* layer1 = armature->GetAnimLayer("SECONDARY1"); + // if (layer1 != nullptr) + // { + // loopedCheckBox1->SetCheck(layer1->looped); + // } + // loopedCheckBox1->SetEnabled(true); - actionsComboBox1->ClearItems(); - actionsComboBox1->SetEnabled(false); - blendSlider1->SetEnabled(false); - weightSlider1->SetEnabled(false); - loopedCheckBox1->SetEnabled(false); + // actionsComboBox2->ClearItems(); + // actionsComboBox2->SetEnabled(true); + // for (auto& x : armature->actions) + // { + // actionsComboBox2->AddItem(x.name); + // } + // actionsComboBox2->SetSelected(0); + // blendSlider2->SetEnabled(true); + // weightSlider2->SetEnabled(true); + // AnimationLayer* layer2 = armature->GetAnimLayer("SECONDARY2"); + // if (layer2 != nullptr) + // { + // loopedCheckBox2->SetCheck(layer2->looped); + // } + // loopedCheckBox2->SetEnabled(true); + //} + //else + //{ + // actionsComboBox->ClearItems(); + // actionsComboBox->SetEnabled(false); + // blendSlider->SetEnabled(false); + // loopedCheckBox->SetEnabled(false); - actionsComboBox2->ClearItems(); - actionsComboBox2->SetEnabled(false); - blendSlider2->SetEnabled(false); - weightSlider2->SetEnabled(false); - loopedCheckBox2->SetEnabled(false); - } + // actionsComboBox1->ClearItems(); + // actionsComboBox1->SetEnabled(false); + // blendSlider1->SetEnabled(false); + // weightSlider1->SetEnabled(false); + // loopedCheckBox1->SetEnabled(false); + + // actionsComboBox2->ClearItems(); + // actionsComboBox2->SetEnabled(false); + // blendSlider2->SetEnabled(false); + // weightSlider2->SetEnabled(false); + // loopedCheckBox2->SetEnabled(false); + //} } diff --git a/Editor/AnimationWindow.h b/Editor/AnimationWindow.h index 13865b124..7e1a73f58 100644 --- a/Editor/AnimationWindow.h +++ b/Editor/AnimationWindow.h @@ -1,10 +1,5 @@ #pragma once -namespace wiSceneComponents -{ - struct Armature; -} - class wiGUI; class wiWindow; class wiLabel; @@ -19,8 +14,9 @@ public: ~AnimationWindow(); wiGUI* GUI; - wiSceneComponents::Armature* armature; - void SetArmature(wiSceneComponents::Armature* armature); + + wiECS::Entity entity = wiECS::INVALID_ENTITY; + void SetEntity(wiECS::Entity entity); wiWindow* animWindow; wiComboBox* actionsComboBox; diff --git a/Editor/CameraWindow.cpp b/Editor/CameraWindow.cpp index 2c28f8d22..49f24c178 100644 --- a/Editor/CameraWindow.cpp +++ b/Editor/CameraWindow.cpp @@ -1,12 +1,25 @@ #include "stdafx.h" #include "CameraWindow.h" -using namespace wiSceneComponents; +using namespace wiECS; +using namespace wiSceneSystem; void CameraWindow::ResetCam() { - wiRenderer::getCamera()->ClearTransform(); - wiRenderer::getCamera()->Translate(XMFLOAT3(0, 2, -10)); + Scene& scene = wiRenderer::GetScene(); + + TransformComponent* camera = scene.transforms.GetComponent(entity); + if (camera != nullptr) + { + camera->ClearTransform(); + camera->Translate(XMFLOAT3(0, 2, -10)); + } + + TransformComponent* camera_target = scene.transforms.GetComponent(target); + if (camera_target != nullptr) + { + camera_target->ClearTransform(); + } } CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) @@ -16,8 +29,6 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) float screenW = (float)wiRenderer::GetDevice()->GetScreenWidth(); float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight(); - orbitalCamTarget = new Transform; - cameraWindow = new wiWindow(GUI, "Camera Window"); cameraWindow->SetSize(XMFLOAT2(600, 420)); GUI->AddWidget(cameraWindow); @@ -69,7 +80,6 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) resetButton->SetSize(XMFLOAT2(140, 30)); resetButton->SetPos(XMFLOAT2(x, y += inc)); resetButton->OnClick([&](wiEventArgs args) { - orbitalCamTarget->ClearTransform(); ResetCam(); }); cameraWindow->AddWidget(resetButton); @@ -86,12 +96,22 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) proxyButton->SetSize(XMFLOAT2(140, 30)); proxyButton->SetPos(XMFLOAT2(x, y += inc * 2)); proxyButton->OnClick([&](wiEventArgs args) { - Camera* cam = new Camera(*wiRenderer::getCamera()); - cam->name = "cam"; - wiRenderer::Add(cam); + Scene& scene = wiRenderer::GetScene(); - //SetProxy(cam); + Entity proxy = CreateEntity(); + + auto node_ref = scene.nodes.Create(proxy); + auto transform_ref = scene.transforms.Create(proxy); + auto camera_ref = scene.cameras.Create(proxy); + + auto& node = scene.nodes.GetComponent(node_ref); + auto& transform = scene.transforms.GetComponent(transform_ref); + auto& camera = scene.cameras.GetComponent(camera_ref); + + node.name = "cam"; + camera = *wiRenderer::getCamera(); + transform.MatrixTransform(camera.InvView); }); cameraWindow->AddWidget(proxyButton); @@ -99,9 +119,11 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) proxyNameField->SetSize(XMFLOAT2(140, 30)); proxyNameField->SetPos(XMFLOAT2(x + 200, y)); proxyNameField->OnInputAccepted([&](wiEventArgs args) { - if (proxy != nullptr) + Scene& scene = wiRenderer::GetScene(); + NodeComponent* camera = scene.nodes.GetComponent(entity); + if (camera != nullptr) { - proxy->name = args.sValue; + camera->name = args.sValue; } }); cameraWindow->AddWidget(proxyNameField); @@ -118,7 +140,7 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) cameraWindow->AddWidget(followSlider); - SetProxy(nullptr); + SetEntity(INVALID_ENTITY); cameraWindow->Translate(XMFLOAT3(800, 500, 0)); @@ -128,24 +150,26 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui) CameraWindow::~CameraWindow() { - - SAFE_DELETE(orbitalCamTarget); - cameraWindow->RemoveWidgets(true); GUI->RemoveWidget(cameraWindow); SAFE_DELETE(cameraWindow); } -void CameraWindow::SetProxy(Camera* camera) +void CameraWindow::SetEntity(Entity entity) { - proxy = camera; + this->entity = entity; + Scene& scene = wiRenderer::GetScene(); - if (proxy != nullptr) + if (scene.cameras.Find(entity)) { followCheckBox->SetEnabled(true); followSlider->SetEnabled(true); - proxyNameField->SetValue(proxy->name); + NodeComponent* camera = scene.nodes.GetComponent(entity); + if (camera != nullptr) + { + proxyNameField->SetValue(camera->name); + } } else { diff --git a/Editor/CameraWindow.h b/Editor/CameraWindow.h index 2e9a4bad9..e2ae5c9f3 100644 --- a/Editor/CameraWindow.h +++ b/Editor/CameraWindow.h @@ -1,11 +1,5 @@ #pragma once -namespace wiSceneComponents -{ - struct Camera; - struct Transform; -} - class wiGUI; class wiWindow; class wiLabel; @@ -21,10 +15,12 @@ public: void ResetCam(); - wiSceneComponents::Camera* proxy = nullptr; - void SetProxy(wiSceneComponents::Camera* camera); - wiSceneComponents::Transform* orbitalCamTarget; + wiECS::Entity entity = wiECS::INVALID_ENTITY; + void SetEntity(wiECS::Entity entity); + + wiECS::Entity target = wiECS::INVALID_ENTITY; + void SetTargetEntity(wiECS::Entity target); wiGUI* GUI; diff --git a/Editor/DecalWindow.cpp b/Editor/DecalWindow.cpp index f2d789d9e..eca83e606 100644 --- a/Editor/DecalWindow.cpp +++ b/Editor/DecalWindow.cpp @@ -1,7 +1,8 @@ #include "stdafx.h" #include "DecalWindow.h" -using namespace wiSceneComponents; +using namespace wiECS; +using namespace wiSceneSystem; DecalWindow::DecalWindow(wiGUI* gui) : GUI(gui) @@ -19,33 +20,33 @@ DecalWindow::DecalWindow(wiGUI* gui) : GUI(gui) float x = 200; float y = 0; - opacitySlider = new wiSlider(0, 1, 1, 100000, "Opacity: "); - opacitySlider->SetSize(XMFLOAT2(100, 30)); - opacitySlider->SetPos(XMFLOAT2(x, y += 30)); - opacitySlider->OnSlide([&](wiEventArgs args) { - if (decal != nullptr) - { - decal->color.w = args.fValue; - } - }); - decalWindow->AddWidget(opacitySlider); + //opacitySlider = new wiSlider(0, 1, 1, 100000, "Opacity: "); + //opacitySlider->SetSize(XMFLOAT2(100, 30)); + //opacitySlider->SetPos(XMFLOAT2(x, y += 30)); + //opacitySlider->OnSlide([&](wiEventArgs args) { + // if (decal != nullptr) + // { + // decal->color.w = args.fValue; + // } + //}); + //decalWindow->AddWidget(opacitySlider); - emissiveSlider = new wiSlider(0, 100, 0, 100000, "Emissive: "); - emissiveSlider->SetSize(XMFLOAT2(100, 30)); - emissiveSlider->SetPos(XMFLOAT2(x, y += 30)); - emissiveSlider->OnSlide([&](wiEventArgs args) { - if (decal != nullptr) - { - decal->emissive = args.fValue; - } - }); - decalWindow->AddWidget(emissiveSlider); + //emissiveSlider = new wiSlider(0, 100, 0, 100000, "Emissive: "); + //emissiveSlider->SetSize(XMFLOAT2(100, 30)); + //emissiveSlider->SetPos(XMFLOAT2(x, y += 30)); + //emissiveSlider->OnSlide([&](wiEventArgs args) { + // if (decal != nullptr) + // { + // decal->emissive = args.fValue; + // } + //}); + //decalWindow->AddWidget(emissiveSlider); decalWindow->Translate(XMFLOAT3(30, 30, 0)); decalWindow->SetVisible(false); - SetDecal(nullptr); + SetEntity(INVALID_ENTITY); } @@ -56,20 +57,22 @@ DecalWindow::~DecalWindow() SAFE_DELETE(decalWindow); } -void DecalWindow::SetDecal(Decal* decal) +void DecalWindow::SetEntity(Entity entity) { - if (this->decal == decal) - return; + this->entity = entity; - this->decal = decal; - if (decal != nullptr) - { - opacitySlider->SetValue(decal->color.w); - emissiveSlider->SetValue(decal->emissive); - decalWindow->SetEnabled(true); - } - else - { - decalWindow->SetEnabled(false); - } + //if (this->decal == decal) + // return; + + //this->decal = decal; + //if (decal != nullptr) + //{ + // opacitySlider->SetValue(decal->color.w); + // emissiveSlider->SetValue(decal->emissive); + // decalWindow->SetEnabled(true); + //} + //else + //{ + // decalWindow->SetEnabled(false); + //} } diff --git a/Editor/DecalWindow.h b/Editor/DecalWindow.h index f60592ce2..8511b253d 100644 --- a/Editor/DecalWindow.h +++ b/Editor/DecalWindow.h @@ -1,10 +1,5 @@ #pragma once -namespace wiSceneComponents -{ - struct Decal; -} - class wiGUI; class wiWindow; class wiLabel; @@ -19,9 +14,8 @@ public: wiGUI* GUI; - void SetDecal(wiSceneComponents::Decal* decal); - - wiSceneComponents::Decal* decal; + wiECS::Entity entity; + void SetEntity(wiECS::Entity entity); wiWindow* decalWindow; wiSlider* opacitySlider; diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 038a6cfec..2e37843a0 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -25,7 +25,8 @@ using namespace std; using namespace wiGraphicsTypes; using namespace wiRectPacker; -using namespace wiSceneComponents; +using namespace wiSceneSystem; +using namespace wiECS; Editor::Editor() { @@ -137,14 +138,7 @@ void ConsumeHistoryOperation(bool undo); struct Picked { - Transform* transform; - Object* object; - Light* light; - Decal* decal; - EnvironmentProbe* envProbe; - ForceField* forceField; - Camera* camera; - Armature* armature; + Entity entity; XMFLOAT3 position, normal; float distance; int subsetIndex; @@ -157,29 +151,13 @@ struct Picked // Subset index, position, normal, distance don't distinguish between pickeds! bool operator==(const Picked& other) { - return - transform == other.transform && - object == other.object && - light == other.light && - decal == other.decal && - envProbe == other.envProbe && - forceField == other.forceField && - camera == other.camera && - armature == other.armature - ; + return entity == other.entity; } void Clear() { distance = FLT_MAX; subsetIndex = -1; - SAFE_INIT(transform); - SAFE_INIT(object); - SAFE_INIT(light); - SAFE_INIT(decal); - SAFE_INIT(envProbe); - SAFE_INIT(forceField); - SAFE_INIT(camera); - SAFE_INIT(armature); + entity = INVALID_ENTITY; } }; @@ -188,26 +166,27 @@ struct Picked Translator* translator = nullptr; bool translator_active = false; list selected; -std::map savedParents; +std::map savedParents; Picked hovered; void BeginTranslate() { translator_active = true; translator->ClearTransform(); - set uniqueTransforms; + set uniqueTransforms; for (auto& x : selected) { - uniqueTransforms.insert(x->transform); + uniqueTransforms.insert(x->entity); } XMVECTOR centerV = XMVectorSet(0, 0, 0, 0); float count = 0; for (auto& x : uniqueTransforms) { - if (x != nullptr) + TransformComponent* transform = wiRenderer::GetScene().transforms.GetComponent(x); + if (transform != nullptr) { - centerV = XMVectorAdd(centerV, XMLoadFloat3(&x->translation)); + centerV = XMVectorAdd(centerV, XMLoadFloat3(&transform->translation)); count += 1.0f; } } @@ -219,10 +198,11 @@ void BeginTranslate() translator->Translate(center); for (auto& x : selected) { - if (x->transform != nullptr) + TransformComponent* transform = wiRenderer::GetScene().transforms.GetComponent(x->entity); + if (transform != nullptr) { - x->transform->detach(); - x->transform->attachTo(translator); + //transform->detach(); + transform->AttachTo(translator); // TODO } } } @@ -230,17 +210,22 @@ void BeginTranslate() void EndTranslate() { translator_active = false; - translator->detach(); + //translator->detach(); for (auto& x : selected) { - if (x->transform != nullptr) + TransformComponent* transform = wiRenderer::GetScene().transforms.GetComponent(x->entity); + if (transform != nullptr) { - x->transform->detach(); - std::map::iterator it = savedParents.find(x->transform); + //transform->detach(); + auto it = savedParents.find(x->entity); if (it != savedParents.end()) { - x->transform->attachTo(it->second); + TransformComponent* other = wiRenderer::GetScene().transforms.GetComponent(it->second); + if (other != nullptr) + { + transform->AttachTo(other); + } } } } @@ -270,22 +255,33 @@ void AddSelected(Picked* picked, bool deselectIfAlreadySelected = false) if (it == selected.end()) { selected.push_back(picked); - savedParents.insert(pair(picked->transform, picked->transform->parent)); + TransformComponent* transform = wiRenderer::GetScene().transforms.GetComponent(picked->entity); + if (transform != nullptr) + { + savedParents.insert(make_pair(picked->entity, transform->parentID)); + } } else if (deselectIfAlreadySelected) { { - picked->transform->detach(); - std::map::iterator it = savedParents.find(picked->transform); + //picked->transform->detach(); + auto it = savedParents.find(picked->entity); if (it != savedParents.end()) { - picked->transform->attachTo(it->second); + //picked->transform->attachTo(it->second); + + TransformComponent* transform = wiRenderer::GetScene().transforms.GetComponent(picked->entity); + TransformComponent* other = wiRenderer::GetScene().transforms.GetComponent(it->second); + if (transform != nullptr && other != nullptr) + { + transform->AttachTo(other); + } } } SAFE_DELETE(*it); selected.erase(it); - savedParents.erase(picked->transform); + savedParents.erase(picked->entity); SAFE_DELETE(picked); } } @@ -688,26 +684,26 @@ void EditorComponent::Load() { const Scene& scene = wiRenderer::GetScene(); - Model* fullModel = new Model; - for(auto& x : scene.models) - { - if (x != nullptr) - { - fullModel->Add(x); - } - } - fullModel->Serialize(archive); + //Model* fullModel = new Model; + //for(auto& x : scene.models) + //{ + // if (x != nullptr) + // { + // fullModel->Add(x); + // } + //} + //fullModel->Serialize(archive); - // Clear out the temporary model so that resources won't be deleted on destruction: - fullModel->objects.clear(); - fullModel->lights.clear(); - fullModel->decals.clear(); - fullModel->meshes.clear(); - fullModel->materials.clear(); - fullModel->armatures.clear(); - fullModel->forces.clear(); - fullModel->environmentProbes.clear(); - SAFE_DELETE(fullModel); + //// Clear out the temporary model so that resources won't be deleted on destruction: + //fullModel->objects.clear(); + //fullModel->lights.clear(); + //fullModel->decals.clear(); + //fullModel->meshes.clear(); + //fullModel->materials.clear(); + //fullModel->armatures.clear(); + //fullModel->forces.clear(); + //fullModel->environmentProbes.clear(); + //SAFE_DELETE(fullModel); ResetHistory(); } @@ -747,54 +743,54 @@ void EditorComponent::Load() ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if (GetOpenFileNameA(&ofn) == TRUE) { - string fileName = ofn.lpstrFile; + //string fileName = ofn.lpstrFile; - loader->addLoadingFunction([=] { - string extension = wiHelper::toUpper(wiHelper::GetExtensionFromFileName(fileName)); + //loader->addLoadingFunction([=] { + // string extension = wiHelper::toUpper(wiHelper::GetExtensionFromFileName(fileName)); - if (!extension.compare("WIMF")) // serializer (.wimf) - { - wiRenderer::LoadModel(fileName); - } - else if (!extension.compare("WIO")) // blender-exporter - { - Model* model = ImportModel_WIO(fileName); - if (model != nullptr) - { - wiRenderer::AddModel(model); - } - } - else if (!extension.compare("OBJ")) // wavefront-obj - { - Model* model = ImportModel_OBJ(fileName); - if (model != nullptr) - { - wiRenderer::AddModel(model); - } - } - else if (!extension.compare("GLTF")) // text-based gltf - { - Model* model = ImportModel_GLTF(fileName); - if (model != nullptr) - { - wiRenderer::AddModel(model); - } - } - else if (!extension.compare("GLB")) // binary gltf - { - Model* model = ImportModel_GLTF(fileName); - if (model != nullptr) - { - wiRenderer::AddModel(model); - } - } - }); - loader->onFinished([=] { - main->activateComponent(this, 10, wiColor::Black); - worldWnd->UpdateFromRenderer(); - }); - main->activateComponent(loader,10,wiColor::Black); - ResetHistory(); + // if (!extension.compare("WIMF")) // serializer (.wimf) + // { + // wiRenderer::LoadModel(fileName); + // } + // else if (!extension.compare("WIO")) // blender-exporter + // { + // Model* model = ImportModel_WIO(fileName); + // if (model != nullptr) + // { + // wiRenderer::AddModel(model); + // } + // } + // else if (!extension.compare("OBJ")) // wavefront-obj + // { + // Model* model = ImportModel_OBJ(fileName); + // if (model != nullptr) + // { + // wiRenderer::AddModel(model); + // } + // } + // else if (!extension.compare("GLTF")) // text-based gltf + // { + // Model* model = ImportModel_GLTF(fileName); + // if (model != nullptr) + // { + // wiRenderer::AddModel(model); + // } + // } + // else if (!extension.compare("GLB")) // binary gltf + // { + // Model* model = ImportModel_GLTF(fileName); + // if (model != nullptr) + // { + // wiRenderer::AddModel(model); + // } + // } + //}); + //loader->onFinished([=] { + // main->activateComponent(this, 10, wiColor::Black); + // worldWnd->UpdateFromRenderer(); + //}); + //main->activateComponent(loader,10,wiColor::Black); + //ResetHistory(); } }).detach(); }); @@ -883,14 +879,15 @@ void EditorComponent::Load() selected.clear(); EndTranslate(); wiRenderer::ClearWorld(); - objectWnd->SetObject(nullptr); - meshWnd->SetMesh(nullptr); - lightWnd->SetLight(nullptr); - decalWnd->SetDecal(nullptr); - envProbeWnd->SetProbe(nullptr); - materialWnd->SetMaterial(nullptr); - emitterWnd->SetObject(nullptr); - forceFieldWnd->SetForceField(nullptr); + objectWnd->SetEntity(INVALID_ENTITY); + meshWnd->SetEntity(INVALID_ENTITY); + lightWnd->SetEntity(INVALID_ENTITY); + decalWnd->SetEntity(INVALID_ENTITY); + envProbeWnd->SetEntity(INVALID_ENTITY); + materialWnd->SetEntity(INVALID_ENTITY); + emitterWnd->SetEntity(INVALID_ENTITY); + forceFieldWnd->SetEntity(INVALID_ENTITY); + cameraWnd->SetEntity(INVALID_ENTITY); }); GetGUI().AddWidget(clearButton); @@ -983,15 +980,16 @@ void EditorComponent::FixedUpdate() } void EditorComponent::Update(float dt) { - Camera* cam = wiRenderer::getCamera(); - cam->hasChanged = false; + Scene& scene = wiRenderer::GetScene(); + CameraComponent* cam = wiRenderer::getCamera(); + //cam->hasChanged = false; // Follow camera proxy: // Outside of the next if, because we want to animate while hovering on GUI... (just better user experience) if (cameraWnd->followCheckBox->IsEnabled() && cameraWnd->followCheckBox->GetCheck()) { - cam->detach(); - cam->Lerp(cam, cameraWnd->proxy, 1.0f - cameraWnd->followSlider->GetValue()); + //cam->detach(); + //cam->Lerp(cam, cameraWnd->proxy, 1.0f - cameraWnd->followSlider->GetValue()); } // Exit cinema mode: @@ -1050,67 +1048,67 @@ void EditorComponent::Update(float dt) yDif *= cameraWnd->rotationspeedSlider->GetValue(); - if (cameraWnd->fpsCheckBox->GetCheck()) - { - // FPS Camera - cam->detach(); + //if (cameraWnd->fpsCheckBox->GetCheck()) + //{ + // // FPS Camera + // //cam->detach(); - const float clampedDT = min(dt, 0.1f); // if dt > 100 millisec, don't allow the camera to jump too far... + // const float clampedDT = min(dt, 0.1f); // if dt > 100 millisec, don't allow the camera to jump too far... - const float speed = (wiInputManager::GetInstance()->down(VK_SHIFT) ? 10.0f : 1.0f) * cameraWnd->movespeedSlider->GetValue() * clampedDT; - static XMVECTOR move = XMVectorSet(0, 0, 0, 0); - XMVECTOR moveNew = XMVectorSet(0, 0, 0, 0); + // const float speed = (wiInputManager::GetInstance()->down(VK_SHIFT) ? 10.0f : 1.0f) * cameraWnd->movespeedSlider->GetValue() * clampedDT; + // static XMVECTOR move = XMVectorSet(0, 0, 0, 0); + // XMVECTOR moveNew = XMVectorSet(0, 0, 0, 0); - if (!wiInputManager::GetInstance()->down(VK_CONTROL)) - { - // Only move camera if control not pressed - if (wiInputManager::GetInstance()->down('A')) { moveNew += XMVectorSet(-1, 0, 0, 0); } - if (wiInputManager::GetInstance()->down('D')) { moveNew += XMVectorSet(1, 0, 0, 0); } - if (wiInputManager::GetInstance()->down('W')) { moveNew += XMVectorSet(0, 0, 1, 0); } - if (wiInputManager::GetInstance()->down('S')) { moveNew += XMVectorSet(0, 0, -1, 0); } - if (wiInputManager::GetInstance()->down('E')) { moveNew += XMVectorSet(0, 1, 0, 0); } - if (wiInputManager::GetInstance()->down('Q')) { moveNew += XMVectorSet(0, -1, 0, 0); } - moveNew = XMVector3Normalize(moveNew) * speed; - } + // if (!wiInputManager::GetInstance()->down(VK_CONTROL)) + // { + // // Only move camera if control not pressed + // if (wiInputManager::GetInstance()->down('A')) { moveNew += XMVectorSet(-1, 0, 0, 0); } + // if (wiInputManager::GetInstance()->down('D')) { moveNew += XMVectorSet(1, 0, 0, 0); } + // if (wiInputManager::GetInstance()->down('W')) { moveNew += XMVectorSet(0, 0, 1, 0); } + // if (wiInputManager::GetInstance()->down('S')) { moveNew += XMVectorSet(0, 0, -1, 0); } + // if (wiInputManager::GetInstance()->down('E')) { moveNew += XMVectorSet(0, 1, 0, 0); } + // if (wiInputManager::GetInstance()->down('Q')) { moveNew += XMVectorSet(0, -1, 0, 0); } + // moveNew = XMVector3Normalize(moveNew) * speed; + // } - move = XMVectorLerp(move, moveNew, 0.18f * clampedDT / 0.0166f); // smooth the movement a bit - float moveLength = XMVectorGetX(XMVector3Length(move)); + // move = XMVectorLerp(move, moveNew, 0.18f * clampedDT / 0.0166f); // smooth the movement a bit + // float moveLength = XMVectorGetX(XMVector3Length(move)); - if (moveLength < 0.0001f) - { - move = XMVectorSet(0, 0, 0, 0); - } - - if (abs(xDif) + abs(yDif) > 0 || moveLength > 0.0001f) - { - cam->Move(move); - cam->RotateRollPitchYaw(XMFLOAT3(yDif, xDif, 0)); - } - } - else - { - // Orbital Camera - if (cam->parent == nullptr) - { - cam->attachTo(cameraWnd->orbitalCamTarget); - } - if (wiInputManager::GetInstance()->down(VK_LSHIFT)) - { - XMVECTOR V = XMVectorAdd(cam->GetRight() * xDif, cam->GetUp() * yDif) * 10; - XMFLOAT3 vec; - XMStoreFloat3(&vec, V); - cameraWnd->orbitalCamTarget->Translate(vec); - } - else if (wiInputManager::GetInstance()->down(VK_LCONTROL)) - { - cam->Translate(XMFLOAT3(0, 0, yDif * 4)); - } - else if(abs(xDif) + abs(yDif) > 0) - { - cameraWnd->orbitalCamTarget->RotateRollPitchYaw(XMFLOAT3(yDif*2, xDif*2, 0)); - } - } + // if (moveLength < 0.0001f) + // { + // move = XMVectorSet(0, 0, 0, 0); + // } + // + // if (abs(xDif) + abs(yDif) > 0 || moveLength > 0.0001f) + // { + // cam->Move(move); + // cam->RotateRollPitchYaw(XMFLOAT3(yDif, xDif, 0)); + // } + //} + //else + //{ + // // Orbital Camera + // if (cam->parent == nullptr) + // { + // cam->attachTo(cameraWnd->orbitalCamTarget); + // } + // if (wiInputManager::GetInstance()->down(VK_LSHIFT)) + // { + // XMVECTOR V = XMVectorAdd(cam->GetRight() * xDif, cam->GetUp() * yDif) * 10; + // XMFLOAT3 vec; + // XMStoreFloat3(&vec, V); + // cameraWnd->orbitalCamTarget->Translate(vec); + // } + // else if (wiInputManager::GetInstance()->down(VK_LCONTROL)) + // { + // cam->Translate(XMFLOAT3(0, 0, yDif * 4)); + // } + // else if(abs(xDif) + abs(yDif) > 0) + // { + // cameraWnd->orbitalCamTarget->RotateRollPitchYaw(XMFLOAT3(yDif*2, xDif*2, 0)); + // } + //} // Begin picking: UINT pickMask = rendererWnd->GetPickType(); @@ -1123,590 +1121,588 @@ void EditorComponent::Update(float dt) { auto& picked = wiRenderer::RayIntersectWorld(pickRay, pickMask); - hovered.object = picked.object; + hovered.entity = picked.entity; hovered.distance = picked.distance; hovered.subsetIndex = picked.subsetIndex; hovered.position = picked.position; hovered.normal = picked.normal; - - hovered.transform = picked.object; } - for (auto& model : wiRenderer::GetScene().models) - { - if (pickMask & PICK_LIGHT) - { - for (auto& light : model->lights) - { - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&light->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(light->translation, pickRay.origin) * 0.05f && dis < hovered.distance) - { - hovered.Clear(); - hovered.transform = light; - hovered.light = light; - hovered.distance = dis; - } - } - } - if (pickMask & PICK_DECAL) - { - for (auto& decal : model->decals) - { - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&decal->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(decal->translation, pickRay.origin) * 0.05f && dis < hovered.distance) - { - hovered.Clear(); - hovered.transform = decal; - hovered.decal = decal; - hovered.distance = dis; - } - } - } - if (pickMask & PICK_FORCEFIELD) - { - for (auto& force : model->forces) - { - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&force->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(force->translation, pickRay.origin) * 0.05f && dis < hovered.distance) - { - hovered.Clear(); - hovered.transform = force; - hovered.forceField = force; - hovered.distance = dis; - } - } - } - if (pickMask & PICK_EMITTER) - { - for (auto& object : model->objects) - { - if (object->eParticleSystems.empty()) - { - continue; - } + //for (auto& model : wiRenderer::GetScene().models) + //{ + // if (pickMask & PICK_LIGHT) + // { + // for (auto& light : model->lights) + // { + // XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&light->translation)); + // float dis = XMVectorGetX(disV); + // if (dis < wiMath::Distance(light->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + // { + // hovered.Clear(); + // hovered.transform = light; + // hovered.light = light; + // hovered.distance = dis; + // } + // } + // } + // if (pickMask & PICK_DECAL) + // { + // for (auto& decal : model->decals) + // { + // XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&decal->translation)); + // float dis = XMVectorGetX(disV); + // if (dis < wiMath::Distance(decal->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + // { + // hovered.Clear(); + // hovered.transform = decal; + // hovered.decal = decal; + // hovered.distance = dis; + // } + // } + // } + // if (pickMask & PICK_FORCEFIELD) + // { + // for (auto& force : model->forces) + // { + // XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&force->translation)); + // float dis = XMVectorGetX(disV); + // if (dis < wiMath::Distance(force->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + // { + // hovered.Clear(); + // hovered.transform = force; + // hovered.forceField = force; + // hovered.distance = dis; + // } + // } + // } + // if (pickMask & PICK_EMITTER) + // { + // for (auto& object : model->objects) + // { + // if (object->eParticleSystems.empty()) + // { + // continue; + // } - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&object->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(object->translation, pickRay.origin) * 0.05f && dis < hovered.distance) - { - hovered.Clear(); - hovered.transform = object; - hovered.object = object; - hovered.distance = dis; - } - } - } + // XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&object->translation)); + // float dis = XMVectorGetX(disV); + // if (dis < wiMath::Distance(object->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + // { + // hovered.Clear(); + // hovered.transform = object; + // hovered.object = object; + // hovered.distance = dis; + // } + // } + // } - if (pickMask & PICK_ENVPROBE) - { - for (auto& x : model->environmentProbes) - { - if (SPHERE(x->translation, 1).intersects(pickRay)) - { - float dis = wiMath::Distance(x->translation, pickRay.origin); - if (dis < hovered.distance) - { - hovered.Clear(); - hovered.transform = x; - hovered.envProbe = x; - hovered.distance = dis; - } - } - } - } - if (pickMask & PICK_CAMERA) - { - for (auto& camera : model->cameras) - { - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&camera->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(camera->translation, pickRay.origin) * 0.05f && dis < hovered.distance) - { - hovered.Clear(); - hovered.transform = camera; - hovered.camera = camera; - hovered.distance = dis; - } - } - } - if (pickMask & PICK_ARMATURE) - { - for (auto& armature : model->armatures) - { - XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&armature->translation)); - float dis = XMVectorGetX(disV); - if (dis < wiMath::Distance(armature->translation, pickRay.origin) * 0.05f && dis < hovered.distance) - { - hovered.Clear(); - hovered.transform = armature; - hovered.armature = armature; - hovered.distance = dis; - } - } - } - } + // if (pickMask & PICK_ENVPROBE) + // { + // for (auto& x : model->environmentProbes) + // { + // if (SPHERE(x->translation, 1).intersects(pickRay)) + // { + // float dis = wiMath::Distance(x->translation, pickRay.origin); + // if (dis < hovered.distance) + // { + // hovered.Clear(); + // hovered.transform = x; + // hovered.envProbe = x; + // hovered.distance = dis; + // } + // } + // } + // } + // if (pickMask & PICK_CAMERA) + // { + // for (auto& camera : model->cameras) + // { + // XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&camera->translation)); + // float dis = XMVectorGetX(disV); + // if (dis < wiMath::Distance(camera->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + // { + // hovered.Clear(); + // hovered.transform = camera; + // hovered.camera = camera; + // hovered.distance = dis; + // } + // } + // } + // if (pickMask & PICK_ARMATURE) + // { + // for (auto& armature : model->armatures) + // { + // XMVECTOR disV = XMVector3LinePointDistance(XMLoadFloat3(&pickRay.origin), XMLoadFloat3(&pickRay.origin) + XMLoadFloat3(&pickRay.direction), XMLoadFloat3(&armature->translation)); + // float dis = XMVectorGetX(disV); + // if (dis < wiMath::Distance(armature->translation, pickRay.origin) * 0.05f && dis < hovered.distance) + // { + // hovered.Clear(); + // hovered.transform = armature; + // hovered.armature = armature; + // hovered.distance = dis; + // } + // } + // } + //} } - // Interact: - if (hovered.object != nullptr && selected.empty()) - { - if (hovered.object->GetRenderTypes() & RENDERTYPE_WATER) - { - if (wiInputManager::GetInstance()->down(VK_LBUTTON)) - { - // if water, then put a water ripple onto it: - wiRenderer::PutWaterRipple(wiHelper::GetOriginalWorkingDirectory() + "images/ripple.png", hovered.position); - } - } - else - { - if (wiInputManager::GetInstance()->press(VK_LBUTTON)) - { - // if not water, put a decal instead: - static int decalselector = 0; - decalselector = (decalselector + 1) % 2; - Decal* decal = new Decal(hovered.position, XMFLOAT3(4,4,4), wiRenderer::getCamera()->rotation, - wiHelper::GetOriginalWorkingDirectory() + (decalselector == 0 ? "images/leaf.dds" : "images/blood1.png")); - decal->attachTo(hovered.object); - wiRenderer::PutDecal(decal); - } - } - } + //// Interact: + //if (hovered.object != nullptr && selected.empty()) + //{ + // if (hovered.object->GetRenderTypes() & RENDERTYPE_WATER) + // { + // if (wiInputManager::GetInstance()->down(VK_LBUTTON)) + // { + // // if water, then put a water ripple onto it: + // wiRenderer::PutWaterRipple(wiHelper::GetOriginalWorkingDirectory() + "images/ripple.png", hovered.position); + // } + // } + // else + // { + // if (wiInputManager::GetInstance()->press(VK_LBUTTON)) + // { + // // if not water, put a decal instead: + // static int decalselector = 0; + // decalselector = (decalselector + 1) % 2; + // Decal* decal = new Decal(hovered.position, XMFLOAT3(4,4,4), wiRenderer::getCamera()->rotation, + // wiHelper::GetOriginalWorkingDirectory() + (decalselector == 0 ? "images/leaf.dds" : "images/blood1.png")); + // decal->attachTo(hovered.object); + // wiRenderer::PutDecal(decal); + // } + // } + //} - // Select... - static bool selectAll = false; - if (wiInputManager::GetInstance()->press(VK_RBUTTON) || selectAll) - { + //// Select... + //static bool selectAll = false; + //if (wiInputManager::GetInstance()->press(VK_RBUTTON) || selectAll) + //{ - wiArchive* archive = AdvanceHistory(); - *archive << HISTORYOP_SELECTION; - // record PREVIOUS selection state... - *archive << selected.size(); - for (auto& x : selected) - { - *archive << x->transform->GetID(); - *archive << x->position; - *archive << x->normal; - *archive << x->subsetIndex; - *archive << x->distance; - } - *archive << savedParents.size(); - for (auto& x : savedParents) - { - *archive << x.first->GetID(); - if (x.second == nullptr) - { - *archive << Transform::INVALID_ID; - } - else - { - *archive << x.second->GetID(); - } - } + // wiArchive* archive = AdvanceHistory(); + // *archive << HISTORYOP_SELECTION; + // // record PREVIOUS selection state... + // *archive << selected.size(); + // for (auto& x : selected) + // { + // *archive << x->transform->GetID(); + // *archive << x->position; + // *archive << x->normal; + // *archive << x->subsetIndex; + // *archive << x->distance; + // } + // *archive << savedParents.size(); + // for (auto& x : savedParents) + // { + // *archive << x.first->GetID(); + // if (x.second == nullptr) + // { + // *archive << Transform::INVALID_ID; + // } + // else + // { + // *archive << x.second->GetID(); + // } + // } - if (selectAll) - { - // Add everything to selection: - selectAll = false; + // if (selectAll) + // { + // // Add everything to selection: + // selectAll = false; - EndTranslate(); - ClearSelected(); + // EndTranslate(); + // ClearSelected(); - for (Model* model : wiRenderer::GetScene().models) - { - for (auto& x : model->objects) - { - Picked* picked = new Picked; - picked->object = x; - picked->transform = x; + // for (Model* model : wiRenderer::GetScene().models) + // { + // for (auto& x : model->objects) + // { + // Picked* picked = new Picked; + // picked->object = x; + // picked->transform = x; - AddSelected(picked); - } - for (auto& x : model->lights) - { - Picked* picked = new Picked; - picked->light = x; - picked->transform = x; + // AddSelected(picked); + // } + // for (auto& x : model->lights) + // { + // Picked* picked = new Picked; + // picked->light = x; + // picked->transform = x; - AddSelected(picked); - } - for (auto& x : model->forces) - { - Picked* picked = new Picked; - picked->forceField = x; - picked->transform = x; + // AddSelected(picked); + // } + // for (auto& x : model->forces) + // { + // Picked* picked = new Picked; + // picked->forceField = x; + // picked->transform = x; - AddSelected(picked); - } - for (auto& x : model->armatures) - { - Picked* picked = new Picked; - picked->armature = x; - picked->transform = x; + // AddSelected(picked); + // } + // for (auto& x : model->armatures) + // { + // Picked* picked = new Picked; + // picked->armature = x; + // picked->transform = x; - AddSelected(picked); - } - for (auto& x : model->cameras) - { - Picked* picked = new Picked; - picked->camera = x; - picked->transform = x; + // AddSelected(picked); + // } + // for (auto& x : model->cameras) + // { + // Picked* picked = new Picked; + // picked->camera = x; + // picked->transform = x; - AddSelected(picked); - } - for (auto& x : model->environmentProbes) - { - Picked* picked = new Picked; - picked->envProbe = x; - picked->transform = x; + // AddSelected(picked); + // } + // for (auto& x : model->environmentProbes) + // { + // Picked* picked = new Picked; + // picked->envProbe = x; + // picked->transform = x; - AddSelected(picked); - } - for (auto& x : model->decals) - { - Picked* picked = new Picked; - picked->decal = x; - picked->transform = x; + // AddSelected(picked); + // } + // for (auto& x : model->decals) + // { + // Picked* picked = new Picked; + // picked->decal = x; + // picked->transform = x; - AddSelected(picked); - } - } + // AddSelected(picked); + // } + // } - BeginTranslate(); - } - else if (hovered.transform != nullptr) - { - // Add the hovered item to the selection: - Picked* picked = new Picked(hovered); - if (!selected.empty() && wiInputManager::GetInstance()->down(VK_LSHIFT)) - { - AddSelected(picked, true); - } - else - { - EndTranslate(); - ClearSelected(); - selected.push_back(picked); - savedParents.insert(pair(picked->transform, picked->transform->parent)); - } + // BeginTranslate(); + // } + // else if (hovered.transform != nullptr) + // { + // // Add the hovered item to the selection: + // Picked* picked = new Picked(hovered); + // if (!selected.empty() && wiInputManager::GetInstance()->down(VK_LSHIFT)) + // { + // AddSelected(picked, true); + // } + // else + // { + // EndTranslate(); + // ClearSelected(); + // selected.push_back(picked); + // savedParents.insert(pair(picked->transform, picked->transform->parent)); + // } - EndTranslate(); - BeginTranslate(); - } - else - { - // Clear selection: - EndTranslate(); - ClearSelected(); - } + // EndTranslate(); + // BeginTranslate(); + // } + // else + // { + // // Clear selection: + // EndTranslate(); + // ClearSelected(); + // } - // record NEW selection state... - *archive << selected.size(); - for (auto& x : selected) - { - *archive << x->transform->GetID(); - *archive << x->position; - *archive << x->normal; - *archive << x->subsetIndex; - *archive << x->distance; - } - *archive << savedParents.size(); - for (auto& x : savedParents) - { - *archive << x.first->GetID(); - if (x.second == nullptr) - { - *archive << Transform::INVALID_ID; - } - else - { - *archive << x.second->GetID(); - } - } - } + // // record NEW selection state... + // *archive << selected.size(); + // for (auto& x : selected) + // { + // *archive << x->transform->GetID(); + // *archive << x->position; + // *archive << x->normal; + // *archive << x->subsetIndex; + // *archive << x->distance; + // } + // *archive << savedParents.size(); + // for (auto& x : savedParents) + // { + // *archive << x.first->GetID(); + // if (x.second == nullptr) + // { + // *archive << Transform::INVALID_ID; + // } + // else + // { + // *archive << x.second->GetID(); + // } + // } + //} - // Update window data bindings... - if (selected.empty()) - { - objectWnd->SetObject(nullptr); - emitterWnd->SetObject(nullptr); - meshWnd->SetMesh(nullptr); - materialWnd->SetMaterial(nullptr); - lightWnd->SetLight(nullptr); - decalWnd->SetDecal(nullptr); - envProbeWnd->SetProbe(nullptr); - animWnd->SetArmature(nullptr); - forceFieldWnd->SetForceField(nullptr); - cameraWnd->SetProxy(nullptr); - } - else - { - Picked* picked = selected.back(); + //// Update window data bindings... + //if (selected.empty()) + //{ + // objectWnd->SetObject(nullptr); + // emitterWnd->SetObject(nullptr); + // meshWnd->SetMesh(nullptr); + // materialWnd->SetMaterial(nullptr); + // lightWnd->SetLight(nullptr); + // decalWnd->SetDecal(nullptr); + // envProbeWnd->SetProbe(nullptr); + // animWnd->SetArmature(nullptr); + // forceFieldWnd->SetForceField(nullptr); + // cameraWnd->SetProxy(nullptr); + //} + //else + //{ + // Picked* picked = selected.back(); - assert(picked->transform != nullptr); + // assert(picked->transform != nullptr); - if (picked->object != nullptr) - { - meshWnd->SetMesh(picked->object->mesh); - if (picked->subsetIndex >= 0 && picked->subsetIndex < (int)picked->object->mesh->subsets.size()) - { - Material* material = picked->object->mesh->subsets[picked->subsetIndex].material; + // if (picked->object != nullptr) + // { + // meshWnd->SetMesh(picked->object->mesh); + // if (picked->subsetIndex >= 0 && picked->subsetIndex < (int)picked->object->mesh->subsets.size()) + // { + // Material* material = picked->object->mesh->subsets[picked->subsetIndex].material; - materialWnd->SetMaterial(material); + // materialWnd->SetMaterial(material); - material->SetUserStencilRef(EDITORSTENCILREF_HIGHLIGHT); - } - //if (picked->object->isArmatureDeformed()) - //{ - // animWnd->SetArmature(picked->object->mesh->armature); - //} - } - else - { - meshWnd->SetMesh(nullptr); - materialWnd->SetMaterial(nullptr); - //animWnd->SetArmature(nullptr); - } + // material->SetUserStencilRef(EDITORSTENCILREF_HIGHLIGHT); + // } + // //if (picked->object->isArmatureDeformed()) + // //{ + // // animWnd->SetArmature(picked->object->mesh->armature); + // //} + // } + // else + // { + // meshWnd->SetMesh(nullptr); + // materialWnd->SetMaterial(nullptr); + // //animWnd->SetArmature(nullptr); + // } - if (picked->light != nullptr) - { - } - lightWnd->SetLight(picked->light); - if (picked->decal != nullptr) - { - } - decalWnd->SetDecal(picked->decal); - if (picked->envProbe != nullptr) - { - } - envProbeWnd->SetProbe(picked->envProbe); - forceFieldWnd->SetForceField(picked->forceField); - if (picked->camera != nullptr) - { - cameraWnd->SetProxy(picked->camera); - } + // if (picked->light != nullptr) + // { + // } + // lightWnd->SetLight(picked->light); + // if (picked->decal != nullptr) + // { + // } + // decalWnd->SetDecal(picked->decal); + // if (picked->envProbe != nullptr) + // { + // } + // envProbeWnd->SetProbe(picked->envProbe); + // forceFieldWnd->SetForceField(picked->forceField); + // if (picked->camera != nullptr) + // { + // cameraWnd->SetProxy(picked->camera); + // } - if (picked->armature != nullptr) - { - animWnd->SetArmature(picked->armature); - } - else - { - animWnd->SetArmature(nullptr); - } + // if (picked->armature != nullptr) + // { + // animWnd->SetArmature(picked->armature); + // } + // else + // { + // animWnd->SetArmature(nullptr); + // } - objectWnd->SetObject(picked->object); - emitterWnd->SetObject(picked->object); - } + // objectWnd->SetObject(picked->object); + // emitterWnd->SetObject(picked->object); + //} - // Delete - if (wiInputManager::GetInstance()->press(VK_DELETE)) - { - wiArchive* archive = AdvanceHistory(); - *archive << HISTORYOP_DELETE; - *archive << selected.size(); - for (auto& x : selected) - { - *archive << x->transform->GetID(); + //// Delete + //if (wiInputManager::GetInstance()->press(VK_DELETE)) + //{ + // wiArchive* archive = AdvanceHistory(); + // *archive << HISTORYOP_DELETE; + // *archive << selected.size(); + // for (auto& x : selected) + // { + // *archive << x->transform->GetID(); - if (x->object != nullptr) - { - *archive << true; - x->object->Serialize(*archive); - x->object->mesh->Serialize(*archive); - *archive << x->object->mesh->subsets.size(); - for (auto& y : x->object->mesh->subsets) - { - y.material->Serialize(*archive); - } + // if (x->object != nullptr) + // { + // *archive << true; + // x->object->Serialize(*archive); + // x->object->mesh->Serialize(*archive); + // *archive << x->object->mesh->subsets.size(); + // for (auto& y : x->object->mesh->subsets) + // { + // y.material->Serialize(*archive); + // } - wiRenderer::Remove(x->object); - SAFE_DELETE(x->object); - x->transform = nullptr; - } - else - { - *archive << false; - } + // wiRenderer::Remove(x->object); + // SAFE_DELETE(x->object); + // x->transform = nullptr; + // } + // else + // { + // *archive << false; + // } - if (x->light != nullptr) - { - *archive << true; - x->light->Serialize(*archive); + // if (x->light != nullptr) + // { + // *archive << true; + // x->light->Serialize(*archive); - wiRenderer::Remove(x->light); - SAFE_DELETE(x->light); - x->transform = nullptr; - } - else - { - *archive << false; - } + // wiRenderer::Remove(x->light); + // SAFE_DELETE(x->light); + // x->transform = nullptr; + // } + // else + // { + // *archive << false; + // } - if (x->decal != nullptr) - { - *archive << true; - x->decal->Serialize(*archive); + // if (x->decal != nullptr) + // { + // *archive << true; + // x->decal->Serialize(*archive); - wiRenderer::Remove(x->decal); - SAFE_DELETE(x->decal); - x->transform = nullptr; - } - else - { - *archive << false; - } + // wiRenderer::Remove(x->decal); + // SAFE_DELETE(x->decal); + // x->transform = nullptr; + // } + // else + // { + // *archive << false; + // } - if (x->forceField != nullptr) - { - *archive << true; - x->forceField->Serialize(*archive); + // if (x->forceField != nullptr) + // { + // *archive << true; + // x->forceField->Serialize(*archive); - wiRenderer::Remove(x->forceField); - SAFE_DELETE(x->forceField); - x->transform = nullptr; - } - else - { - *archive << false; - } + // wiRenderer::Remove(x->forceField); + // SAFE_DELETE(x->forceField); + // x->transform = nullptr; + // } + // else + // { + // *archive << false; + // } - if (x->camera != nullptr) - { - *archive << true; - x->camera->Serialize(*archive); + // if (x->camera != nullptr) + // { + // *archive << true; + // x->camera->Serialize(*archive); - wiRenderer::Remove(x->camera); - SAFE_DELETE(x->camera); - x->camera = nullptr; - } - else - { - *archive << false; - } + // wiRenderer::Remove(x->camera); + // SAFE_DELETE(x->camera); + // x->camera = nullptr; + // } + // else + // { + // *archive << false; + // } - EnvironmentProbe* envProbe = dynamic_cast(x->transform); - if (envProbe != nullptr) - { - wiRenderer::Remove(envProbe); - SAFE_DELETE(envProbe); - } - } - ClearSelected(); - } - // Control operations... - if (wiInputManager::GetInstance()->down(VK_CONTROL)) - { - // Select All - if (wiInputManager::GetInstance()->press('A')) - { - selectAll = true; - } - // Copy - if (wiInputManager::GetInstance()->press('C')) - { - SAFE_DELETE(clipboard); - clipboard = new wiArchive(); - *clipboard << CLIPBOARD_MODEL; - Model* model = new Model; - for (auto& x : selected) - { - model->Add(x->object); - model->Add(x->light); - model->Add(x->decal); - model->Add(x->forceField); - model->Add(x->camera); - } - model->Serialize(*clipboard); + // EnvironmentProbe* envProbe = dynamic_cast(x->transform); + // if (envProbe != nullptr) + // { + // wiRenderer::Remove(envProbe); + // SAFE_DELETE(envProbe); + // } + // } + // ClearSelected(); + //} + //// Control operations... + //if (wiInputManager::GetInstance()->down(VK_CONTROL)) + //{ + // // Select All + // if (wiInputManager::GetInstance()->press('A')) + // { + // selectAll = true; + // } + // // Copy + // if (wiInputManager::GetInstance()->press('C')) + // { + // SAFE_DELETE(clipboard); + // clipboard = new wiArchive(); + // *clipboard << CLIPBOARD_MODEL; + // Model* model = new Model; + // for (auto& x : selected) + // { + // model->Add(x->object); + // model->Add(x->light); + // model->Add(x->decal); + // model->Add(x->forceField); + // model->Add(x->camera); + // } + // model->Serialize(*clipboard); - model->objects.clear(); - model->lights.clear(); - model->decals.clear(); - model->meshes.clear(); - model->materials.clear(); - model->forces.clear(); - model->armatures.clear(); - model->cameras.clear(); - SAFE_DELETE(model); - } - // Paste - if (wiInputManager::GetInstance()->press('V')) - { - clipboard->SetReadModeAndResetPos(true); - int tmp; - *clipboard >> tmp; - ClipboardItemType type = (ClipboardItemType)tmp; - switch (type) - { - case CLIPBOARD_MODEL: - { - Model* model = new Model; - model->Serialize(*clipboard); - wiRenderer::AddModel(model); - } - break; - case CLIPBOARD_EMPTY: - break; - default: - break; - } - } - // Duplicate Instances - if (wiInputManager::GetInstance()->press('D')) - { - EndTranslate(); + // model->objects.clear(); + // model->lights.clear(); + // model->decals.clear(); + // model->meshes.clear(); + // model->materials.clear(); + // model->forces.clear(); + // model->armatures.clear(); + // model->cameras.clear(); + // SAFE_DELETE(model); + // } + // // Paste + // if (wiInputManager::GetInstance()->press('V')) + // { + // clipboard->SetReadModeAndResetPos(true); + // int tmp; + // *clipboard >> tmp; + // ClipboardItemType type = (ClipboardItemType)tmp; + // switch (type) + // { + // case CLIPBOARD_MODEL: + // { + // Model* model = new Model; + // model->Serialize(*clipboard); + // wiRenderer::AddModel(model); + // } + // break; + // case CLIPBOARD_EMPTY: + // break; + // default: + // break; + // } + // } + // // Duplicate Instances + // if (wiInputManager::GetInstance()->press('D')) + // { + // EndTranslate(); - for (auto& x : selected) - { - if (x->object != nullptr) - { - Object* o = new Object(*x->object); - wiRenderer::Add(o); - x->transform = o; - x->object = o; - } - if (x->light != nullptr) - { - Light* l = new Light(*x->light); - wiRenderer::Add(l); - x->transform = l; - x->light = l; - } - if (x->forceField != nullptr) - { - ForceField* l = new ForceField(*x->forceField); - wiRenderer::Add(l); - x->transform = l; - x->forceField = l; - } - if (x->camera != nullptr) - { - Camera* l = new Camera(*x->camera); - wiRenderer::Add(l); - x->transform = l; - x->camera = l; - } - } + // for (auto& x : selected) + // { + // if (x->object != nullptr) + // { + // Object* o = new Object(*x->object); + // wiRenderer::Add(o); + // x->transform = o; + // x->object = o; + // } + // if (x->light != nullptr) + // { + // Light* l = new Light(*x->light); + // wiRenderer::Add(l); + // x->transform = l; + // x->light = l; + // } + // if (x->forceField != nullptr) + // { + // ForceField* l = new ForceField(*x->forceField); + // wiRenderer::Add(l); + // x->transform = l; + // x->forceField = l; + // } + // if (x->camera != nullptr) + // { + // Camera* l = new Camera(*x->camera); + // wiRenderer::Add(l); + // x->transform = l; + // x->camera = l; + // } + // } - BeginTranslate(); - } - // Undo - if (wiInputManager::GetInstance()->press('Z')) - { - ConsumeHistoryOperation(true); - } - // Redo - if (wiInputManager::GetInstance()->press('Y')) - { - ConsumeHistoryOperation(false); - } - } + // BeginTranslate(); + // } + // // Undo + // if (wiInputManager::GetInstance()->press('Z')) + // { + // ConsumeHistoryOperation(true); + // } + // // Redo + // if (wiInputManager::GetInstance()->press('Y')) + // { + // ConsumeHistoryOperation(false); + // } + //} } @@ -1728,55 +1724,55 @@ void EditorComponent::Update(float dt) } void EditorComponent::Render() { - // hover box - if (!cinemaModeCheckBox->GetCheck()) - { - if (hovered.object != nullptr) - { - XMFLOAT4X4 hoverBox; - XMStoreFloat4x4(&hoverBox, hovered.object->bounds.getAsBoxMatrix()); - wiRenderer::AddRenderableBox(hoverBox, XMFLOAT4(0.5f, 0.5f, 0.5f, 0.5f)); - } - if (hovered.light != nullptr) - { - XMFLOAT4X4 hoverBox; - XMStoreFloat4x4(&hoverBox, hovered.light->bounds.getAsBoxMatrix()); - wiRenderer::AddRenderableBox(hoverBox, XMFLOAT4(0.5f, 0.5f, 0, 0.5f)); - } - if (hovered.decal != nullptr) - { - wiRenderer::AddRenderableBox(hovered.decal->world, XMFLOAT4(0.5f, 0, 0.5f, 0.5f)); - } + //// hover box + //if (!cinemaModeCheckBox->GetCheck()) + //{ + // if (hovered.object != nullptr) + // { + // XMFLOAT4X4 hoverBox; + // XMStoreFloat4x4(&hoverBox, hovered.object->bounds.getAsBoxMatrix()); + // wiRenderer::AddRenderableBox(hoverBox, XMFLOAT4(0.5f, 0.5f, 0.5f, 0.5f)); + // } + // if (hovered.light != nullptr) + // { + // XMFLOAT4X4 hoverBox; + // XMStoreFloat4x4(&hoverBox, hovered.light->bounds.getAsBoxMatrix()); + // wiRenderer::AddRenderableBox(hoverBox, XMFLOAT4(0.5f, 0.5f, 0, 0.5f)); + // } + // if (hovered.decal != nullptr) + // { + // wiRenderer::AddRenderableBox(hovered.decal->world, XMFLOAT4(0.5f, 0, 0.5f, 0.5f)); + // } - } + //} - if (!cinemaModeCheckBox->GetCheck() && !selected.empty()) - { - AABB selectedAABB = AABB(XMFLOAT3(FLOAT32_MAX, FLOAT32_MAX, FLOAT32_MAX),XMFLOAT3(-FLOAT32_MAX, -FLOAT32_MAX, -FLOAT32_MAX)); - for (auto& picked : selected) - { - if (picked->object != nullptr) - { - selectedAABB = AABB::Merge(selectedAABB, picked->object->bounds); - } - if (picked->light != nullptr) - { - selectedAABB = AABB::Merge(selectedAABB, picked->light->bounds); - } - if (picked->decal != nullptr) - { - selectedAABB = AABB::Merge(selectedAABB, picked->decal->bounds); + //if (!cinemaModeCheckBox->GetCheck() && !selected.empty()) + //{ + // AABB selectedAABB = AABB(XMFLOAT3(FLOAT32_MAX, FLOAT32_MAX, FLOAT32_MAX),XMFLOAT3(-FLOAT32_MAX, -FLOAT32_MAX, -FLOAT32_MAX)); + // for (auto& picked : selected) + // { + // if (picked->object != nullptr) + // { + // selectedAABB = AABB::Merge(selectedAABB, picked->object->bounds); + // } + // if (picked->light != nullptr) + // { + // selectedAABB = AABB::Merge(selectedAABB, picked->light->bounds); + // } + // if (picked->decal != nullptr) + // { + // selectedAABB = AABB::Merge(selectedAABB, picked->decal->bounds); - XMFLOAT4X4 selectionBox; - selectionBox = picked->decal->world; - wiRenderer::AddRenderableBox(selectionBox, XMFLOAT4(1, 0, 1, 1)); - } - } + // XMFLOAT4X4 selectionBox; + // selectionBox = picked->decal->world; + // wiRenderer::AddRenderableBox(selectionBox, XMFLOAT4(1, 0, 1, 1)); + // } + // } - XMFLOAT4X4 selectionBox; - XMStoreFloat4x4(&selectionBox, selectedAABB.getAsBoxMatrix()); - wiRenderer::AddRenderableBox(selectionBox, XMFLOAT4(1, 1, 1, 1)); - } + // XMFLOAT4X4 selectionBox; + // XMStoreFloat4x4(&selectionBox, selectedAABB.getAsBoxMatrix()); + // wiRenderer::AddRenderableBox(selectionBox, XMFLOAT4(1, 1, 1, 1)); + //} renderPath->Render(); @@ -1792,217 +1788,217 @@ void EditorComponent::Compose() return; } - Camera* camera = wiRenderer::getCamera(); + CameraComponent* camera = wiRenderer::getCamera(); - for (auto& x : wiRenderer::GetScene().models) - { - if (rendererWnd->GetPickType() & PICK_LIGHT) - { - for (auto& y : x->lights) - { - float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; + //for (auto& x : wiRenderer::GetScene().models) + //{ + // if (rendererWnd->GetPickType() & PICK_LIGHT) + // { + // for (auto& y : x->lights) + // { + // float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; - wiImageEffects fx; - fx.pos = y->translation; - fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; - fx.pivot = XMFLOAT2(0.5f, 0.5f); - fx.col = XMFLOAT4(1, 1, 1, 0.5f); + // wiImageEffects fx; + // fx.pos = y->translation; + // fx.siz = XMFLOAT2(dist, dist); + // fx.typeFlag = ImageType::WORLD; + // fx.pivot = XMFLOAT2(0.5f, 0.5f); + // fx.col = XMFLOAT4(1, 1, 1, 0.5f); - if (hovered.light == y) - { - fx.col = XMFLOAT4(1, 1, 1, 1); - } - for (auto& picked : selected) - { - if (picked->light == y) - { - fx.col = XMFLOAT4(1, 1, 0, 1); - break; - } - } + // if (hovered.light == y) + // { + // fx.col = XMFLOAT4(1, 1, 1, 1); + // } + // for (auto& picked : selected) + // { + // if (picked->light == y) + // { + // fx.col = XMFLOAT4(1, 1, 0, 1); + // break; + // } + // } - switch (y->GetType()) - { - case Light::POINT: - wiImage::Draw(&pointLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); - break; - case Light::SPOT: - wiImage::Draw(&spotLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); - break; - case Light::DIRECTIONAL: - wiImage::Draw(&dirLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); - break; - default: - wiImage::Draw(&areaLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); - break; - } - } - } + // switch (y->GetType()) + // { + // case Light::POINT: + // wiImage::Draw(&pointLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); + // break; + // case Light::SPOT: + // wiImage::Draw(&spotLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); + // break; + // case Light::DIRECTIONAL: + // wiImage::Draw(&dirLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); + // break; + // default: + // wiImage::Draw(&areaLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); + // break; + // } + // } + // } - if (rendererWnd->GetPickType() & PICK_DECAL) - { - for (auto& y : x->decals) - { - float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; + // if (rendererWnd->GetPickType() & PICK_DECAL) + // { + // for (auto& y : x->decals) + // { + // float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; - wiImageEffects fx; - fx.pos = y->translation; - fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; - fx.pivot = XMFLOAT2(0.5f, 0.5f); - fx.col = XMFLOAT4(1, 1, 1, 0.5f); + // wiImageEffects fx; + // fx.pos = y->translation; + // fx.siz = XMFLOAT2(dist, dist); + // fx.typeFlag = ImageType::WORLD; + // fx.pivot = XMFLOAT2(0.5f, 0.5f); + // fx.col = XMFLOAT4(1, 1, 1, 0.5f); - if (hovered.decal == y) - { - fx.col = XMFLOAT4(1, 1, 1, 1); - } - for (auto& picked : selected) - { - if (picked->decal == y) - { - fx.col = XMFLOAT4(1, 1, 0, 1); - break; - } - } + // if (hovered.decal == y) + // { + // fx.col = XMFLOAT4(1, 1, 1, 1); + // } + // for (auto& picked : selected) + // { + // if (picked->decal == y) + // { + // fx.col = XMFLOAT4(1, 1, 0, 1); + // break; + // } + // } - wiImage::Draw(&decalTex, fx, GRAPHICSTHREAD_IMMEDIATE); + // wiImage::Draw(&decalTex, fx, GRAPHICSTHREAD_IMMEDIATE); - } - } + // } + // } - if (rendererWnd->GetPickType() & PICK_FORCEFIELD) - { - for (auto& y : x->forces) - { - float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; + // if (rendererWnd->GetPickType() & PICK_FORCEFIELD) + // { + // for (auto& y : x->forces) + // { + // float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; - wiImageEffects fx; - fx.pos = y->translation; - fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; - fx.pivot = XMFLOAT2(0.5f, 0.5f); - fx.col = XMFLOAT4(1, 1, 1, 0.5f); + // wiImageEffects fx; + // fx.pos = y->translation; + // fx.siz = XMFLOAT2(dist, dist); + // fx.typeFlag = ImageType::WORLD; + // fx.pivot = XMFLOAT2(0.5f, 0.5f); + // fx.col = XMFLOAT4(1, 1, 1, 0.5f); - if (hovered.forceField == y) - { - fx.col = XMFLOAT4(1, 1, 1, 1); - } - for (auto& picked : selected) - { - if (picked->forceField == y) - { - fx.col = XMFLOAT4(1, 1, 0, 1); - break; - } - } + // if (hovered.forceField == y) + // { + // fx.col = XMFLOAT4(1, 1, 1, 1); + // } + // for (auto& picked : selected) + // { + // if (picked->forceField == y) + // { + // fx.col = XMFLOAT4(1, 1, 0, 1); + // break; + // } + // } - wiImage::Draw(&forceFieldTex, fx, GRAPHICSTHREAD_IMMEDIATE); - } - } + // wiImage::Draw(&forceFieldTex, fx, GRAPHICSTHREAD_IMMEDIATE); + // } + // } - if (rendererWnd->GetPickType() & PICK_CAMERA) - { - for (auto& y : x->cameras) - { - float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; + // if (rendererWnd->GetPickType() & PICK_CAMERA) + // { + // for (auto& y : x->cameras) + // { + // float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; - wiImageEffects fx; - fx.pos = y->translation; - fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; - fx.pivot = XMFLOAT2(0.5f, 0.5f); - fx.col = XMFLOAT4(1, 1, 1, 0.5f); + // wiImageEffects fx; + // fx.pos = y->translation; + // fx.siz = XMFLOAT2(dist, dist); + // fx.typeFlag = ImageType::WORLD; + // fx.pivot = XMFLOAT2(0.5f, 0.5f); + // fx.col = XMFLOAT4(1, 1, 1, 0.5f); - if (hovered.camera == y) - { - fx.col = XMFLOAT4(1, 1, 1, 1); - } - for (auto& picked : selected) - { - if (picked->camera == y) - { - fx.col = XMFLOAT4(1, 1, 0, 1); - break; - } - } + // if (hovered.camera == y) + // { + // fx.col = XMFLOAT4(1, 1, 1, 1); + // } + // for (auto& picked : selected) + // { + // if (picked->camera == y) + // { + // fx.col = XMFLOAT4(1, 1, 0, 1); + // break; + // } + // } - wiImage::Draw(&cameraTex, fx, GRAPHICSTHREAD_IMMEDIATE); - } - } + // wiImage::Draw(&cameraTex, fx, GRAPHICSTHREAD_IMMEDIATE); + // } + // } - if (rendererWnd->GetPickType() & PICK_ARMATURE) - { - for (auto& y : x->armatures) - { - float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; + // if (rendererWnd->GetPickType() & PICK_ARMATURE) + // { + // for (auto& y : x->armatures) + // { + // float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; - wiImageEffects fx; - fx.pos = y->translation; - fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; - fx.pivot = XMFLOAT2(0.5f, 0.5f); - fx.col = XMFLOAT4(1, 1, 1, 0.5f); + // wiImageEffects fx; + // fx.pos = y->translation; + // fx.siz = XMFLOAT2(dist, dist); + // fx.typeFlag = ImageType::WORLD; + // fx.pivot = XMFLOAT2(0.5f, 0.5f); + // fx.col = XMFLOAT4(1, 1, 1, 0.5f); - if (hovered.armature == y) - { - fx.col = XMFLOAT4(1, 1, 1, 1); - } - for (auto& picked : selected) - { - if (picked->armature == y) - { - fx.col = XMFLOAT4(1, 1, 0, 1); - break; - } - } + // if (hovered.armature == y) + // { + // fx.col = XMFLOAT4(1, 1, 1, 1); + // } + // for (auto& picked : selected) + // { + // if (picked->armature == y) + // { + // fx.col = XMFLOAT4(1, 1, 0, 1); + // break; + // } + // } - wiImage::Draw(&armatureTex, fx, GRAPHICSTHREAD_IMMEDIATE); - } - } + // wiImage::Draw(&armatureTex, fx, GRAPHICSTHREAD_IMMEDIATE); + // } + // } - if (rendererWnd->GetPickType() & PICK_EMITTER) - { - for (auto& y : x->objects) - { - if (y->eParticleSystems.empty()) - { - continue; - } + // if (rendererWnd->GetPickType() & PICK_EMITTER) + // { + // for (auto& y : x->objects) + // { + // if (y->eParticleSystems.empty()) + // { + // continue; + // } - float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; + // float dist = wiMath::Distance(y->translation, camera->translation) * 0.08f; - wiImageEffects fx; - fx.pos = y->translation; - fx.siz = XMFLOAT2(dist, dist); - fx.typeFlag = ImageType::WORLD; - fx.pivot = XMFLOAT2(0.5f, 0.5f); - fx.col = XMFLOAT4(1, 1, 1, 0.5f); + // wiImageEffects fx; + // fx.pos = y->translation; + // fx.siz = XMFLOAT2(dist, dist); + // fx.typeFlag = ImageType::WORLD; + // fx.pivot = XMFLOAT2(0.5f, 0.5f); + // fx.col = XMFLOAT4(1, 1, 1, 0.5f); - if (hovered.object == y) - { - fx.col = XMFLOAT4(1, 1, 1, 1); - } - for (auto& picked : selected) - { - if (picked->object == y) - { - fx.col = XMFLOAT4(1, 1, 0, 1); - break; - } - } + // if (hovered.object == y) + // { + // fx.col = XMFLOAT4(1, 1, 1, 1); + // } + // for (auto& picked : selected) + // { + // if (picked->object == y) + // { + // fx.col = XMFLOAT4(1, 1, 0, 1); + // break; + // } + // } - wiImage::Draw(&emitterTex, fx, GRAPHICSTHREAD_IMMEDIATE); - } - } + // wiImage::Draw(&emitterTex, fx, GRAPHICSTHREAD_IMMEDIATE); + // } + // } - } + //} if (translator_active && translator->enabled) @@ -2050,227 +2046,227 @@ wiArchive* AdvanceHistory() } void ConsumeHistoryOperation(bool undo) { - if ((undo && historyPos >= 0) || (!undo && historyPos < (int)history.size() - 1)) - { - if (!undo) - { - historyPos++; - } + //if ((undo && historyPos >= 0) || (!undo && historyPos < (int)history.size() - 1)) + //{ + // if (!undo) + // { + // historyPos++; + // } - wiArchive* archive = history[historyPos]; - archive->SetReadModeAndResetPos(true); + // wiArchive* archive = history[historyPos]; + // archive->SetReadModeAndResetPos(true); - int temp; - *archive >> temp; - HistoryOperationType type = (HistoryOperationType)temp; + // int temp; + // *archive >> temp; + // HistoryOperationType type = (HistoryOperationType)temp; - switch (type) - { - case HISTORYOP_TRANSLATOR: - { - XMFLOAT4X4 start, end; - *archive >> start >> end; - translator->enabled = true; - translator->ClearTransform(); - if (undo) - { - translator->transform(XMLoadFloat4x4(&start)); - } - else - { - translator->transform(XMLoadFloat4x4(&end)); - } - } - break; - case HISTORYOP_DELETE: - { - Model* model = nullptr; - if (undo) - { - model = new Model; - } + // switch (type) + // { + // case HISTORYOP_TRANSLATOR: + // { + // XMFLOAT4X4 start, end; + // *archive >> start >> end; + // translator->enabled = true; + // translator->ClearTransform(); + // if (undo) + // { + // translator->MatrixTransform(XMLoadFloat4x4(&start)); + // } + // else + // { + // translator->MatrixTransform(XMLoadFloat4x4(&end)); + // } + // } + // break; + // case HISTORYOP_DELETE: + // { + // Model* model = nullptr; + // if (undo) + // { + // model = new Model; + // } - size_t count; - *archive >> count; - for (size_t i = 0; i < count; ++i) - { - // Entity ID - uint64_t id; - *archive >> id; + // size_t count; + // *archive >> count; + // for (size_t i = 0; i < count; ++i) + // { + // // Entity ID + // uint64_t id; + // *archive >> id; - bool tmp; + // bool tmp; - // object - *archive >> tmp; - if (tmp) - { - if (undo) - { - Object* object = new Object; - object->Serialize(*archive); - object->SetID(id); - object->mesh = new Mesh; - object->mesh->Serialize(*archive); - size_t subsetCount; - *archive >> subsetCount; - for (size_t i = 0; i < subsetCount; ++i) - { - object->mesh->subsets[i].material = new Material; - object->mesh->subsets[i].material->Serialize(*archive); - } - object->mesh->CreateRenderData(); - model->Add(object); - } - } + // // object + // *archive >> tmp; + // if (tmp) + // { + // if (undo) + // { + // Object* object = new Object; + // object->Serialize(*archive); + // object->SetID(id); + // object->mesh = new Mesh; + // object->mesh->Serialize(*archive); + // size_t subsetCount; + // *archive >> subsetCount; + // for (size_t i = 0; i < subsetCount; ++i) + // { + // object->mesh->subsets[i].material = new Material; + // object->mesh->subsets[i].material->Serialize(*archive); + // } + // object->mesh->CreateRenderData(); + // model->Add(object); + // } + // } - // light - *archive >> tmp; - if (tmp) - { - Light* light = new Light; - light->Serialize(*archive); - light->SetID(id); - model->Add(light); - } + // // light + // *archive >> tmp; + // if (tmp) + // { + // Light* light = new Light; + // light->Serialize(*archive); + // light->SetID(id); + // model->Add(light); + // } - // decal - *archive >> tmp; - if (tmp) - { - Decal* decal = new Decal; - decal->Serialize(*archive); - decal->SetID(id); - model->Add(decal); - } + // // decal + // *archive >> tmp; + // if (tmp) + // { + // Decal* decal = new Decal; + // decal->Serialize(*archive); + // decal->SetID(id); + // model->Add(decal); + // } - // force field - *archive >> tmp; - if (tmp) - { - ForceField* force = new ForceField; - force->Serialize(*archive); - force->SetID(id); - model->Add(force); - } - } + // // force field + // *archive >> tmp; + // if (tmp) + // { + // ForceField* force = new ForceField; + // force->Serialize(*archive); + // force->SetID(id); + // model->Add(force); + // } + // } - if (undo) - { - wiRenderer::AddModel(model); - } - } - break; - case HISTORYOP_SELECTION: - { - EndTranslate(); - ClearSelected(); + // if (undo) + // { + // wiRenderer::AddModel(model); + // } + // } + // break; + // case HISTORYOP_SELECTION: + // { + // EndTranslate(); + // ClearSelected(); - // Read selections states from archive: + // // Read selections states from archive: - list selectedBEFORE; - size_t selectionCountBEFORE; - *archive >> selectionCountBEFORE; - for (size_t i = 0; i < selectionCountBEFORE; ++i) - { - uint64_t id; - *archive >> id; + // list selectedBEFORE; + // size_t selectionCountBEFORE; + // *archive >> selectionCountBEFORE; + // for (size_t i = 0; i < selectionCountBEFORE; ++i) + // { + // uint64_t id; + // *archive >> id; - Picked* sel = new Picked; - sel->transform = wiRenderer::getTransformByID(id); - assert(sel->transform != nullptr); - *archive >> sel->position; - *archive >> sel->normal; - *archive >> sel->subsetIndex; - *archive >> sel->distance; + // Picked* sel = new Picked; + // sel->transform = wiRenderer::getTransformByID(id); + // assert(sel->transform != nullptr); + // *archive >> sel->position; + // *archive >> sel->normal; + // *archive >> sel->subsetIndex; + // *archive >> sel->distance; - selectedBEFORE.push_back(sel); - } - std::map savedParentsBEFORE; - size_t savedParentsCountBEFORE; - *archive >> savedParentsCountBEFORE; - for (size_t i = 0; i < savedParentsCountBEFORE; ++i) - { - uint64_t id1, id2; - *archive >> id1; - *archive >> id2; + // selectedBEFORE.push_back(sel); + // } + // std::map savedParentsBEFORE; + // size_t savedParentsCountBEFORE; + // *archive >> savedParentsCountBEFORE; + // for (size_t i = 0; i < savedParentsCountBEFORE; ++i) + // { + // uint64_t id1, id2; + // *archive >> id1; + // *archive >> id2; - Transform* t1 = wiRenderer::getTransformByID(id1); - Transform* t2 = wiRenderer::getTransformByID(id2); - savedParentsBEFORE.insert(pair(t1, t2)); - } + // Transform* t1 = wiRenderer::getTransformByID(id1); + // Transform* t2 = wiRenderer::getTransformByID(id2); + // savedParentsBEFORE.insert(pair(t1, t2)); + // } - list selectedAFTER; - size_t selectionCountAFTER; - *archive >> selectionCountAFTER; - for (size_t i = 0; i < selectionCountAFTER; ++i) - { - uint64_t id; - *archive >> id; + // list selectedAFTER; + // size_t selectionCountAFTER; + // *archive >> selectionCountAFTER; + // for (size_t i = 0; i < selectionCountAFTER; ++i) + // { + // uint64_t id; + // *archive >> id; - Picked* sel = new Picked; - sel->transform = wiRenderer::getTransformByID(id); - assert(sel->transform != nullptr); - *archive >> sel->position; - *archive >> sel->normal; - *archive >> sel->subsetIndex; - *archive >> sel->distance; + // Picked* sel = new Picked; + // sel->transform = wiRenderer::getTransformByID(id); + // assert(sel->transform != nullptr); + // *archive >> sel->position; + // *archive >> sel->normal; + // *archive >> sel->subsetIndex; + // *archive >> sel->distance; - selectedAFTER.push_back(sel); - } - std::map savedParentsAFTER; - size_t savedParentsCountAFTER; - *archive >> savedParentsCountAFTER; - for (size_t i = 0; i < savedParentsCountAFTER; ++i) - { - uint64_t id1, id2; - *archive >> id1; - *archive >> id2; + // selectedAFTER.push_back(sel); + // } + // std::map savedParentsAFTER; + // size_t savedParentsCountAFTER; + // *archive >> savedParentsCountAFTER; + // for (size_t i = 0; i < savedParentsCountAFTER; ++i) + // { + // uint64_t id1, id2; + // *archive >> id1; + // *archive >> id2; - Transform* t1 = wiRenderer::getTransformByID(id1); - Transform* t2 = wiRenderer::getTransformByID(id2); - savedParentsAFTER.insert(pair(t1, t2)); - } + // Transform* t1 = wiRenderer::getTransformByID(id1); + // Transform* t2 = wiRenderer::getTransformByID(id2); + // savedParentsAFTER.insert(pair(t1, t2)); + // } - // Restore proper selection state: + // // Restore proper selection state: - list* selectedCURRENT = nullptr; - if (undo) - { - selectedCURRENT = &selectedBEFORE; - savedParents = savedParentsBEFORE; - } - else - { - selectedCURRENT = &selectedAFTER; - savedParents = savedParentsAFTER; - } + // list* selectedCURRENT = nullptr; + // if (undo) + // { + // selectedCURRENT = &selectedBEFORE; + // savedParents = savedParentsBEFORE; + // } + // else + // { + // selectedCURRENT = &selectedAFTER; + // savedParents = savedParentsAFTER; + // } - selected.insert(selected.end(), selectedCURRENT->begin(), selectedCURRENT->end()); + // selected.insert(selected.end(), selectedCURRENT->begin(), selectedCURRENT->end()); - for (auto& x : selected) - { - x->object = dynamic_cast(x->transform); - x->light = dynamic_cast(x->transform); - x->decal = dynamic_cast(x->transform); - x->envProbe = dynamic_cast(x->transform); - x->forceField = dynamic_cast(x->transform); - } + // for (auto& x : selected) + // { + // x->object = dynamic_cast(x->transform); + // x->light = dynamic_cast(x->transform); + // x->decal = dynamic_cast(x->transform); + // x->envProbe = dynamic_cast(x->transform); + // x->forceField = dynamic_cast(x->transform); + // } - BeginTranslate(); - } - break; - case HISTORYOP_NONE: - assert(0); - break; - default: - break; - } + // BeginTranslate(); + // } + // break; + // case HISTORYOP_NONE: + // assert(0); + // break; + // default: + // break; + // } - if (undo) - { - historyPos--; - } - } + // if (undo) + // { + // historyPos--; + // } + //} } diff --git a/Editor/EmitterWindow.cpp b/Editor/EmitterWindow.cpp index 6c30dc0f6..536cd7933 100644 --- a/Editor/EmitterWindow.cpp +++ b/Editor/EmitterWindow.cpp @@ -5,13 +5,13 @@ #include using namespace std; -using namespace wiSceneComponents; +using namespace wiECS; +using namespace wiSceneSystem; EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) { assert(GUI && "Invalid GUI!"); - object = nullptr; materialWnd = nullptr; @@ -28,352 +28,352 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) float step = 35; - emitterComboBox = new wiComboBox("Emitter: "); - emitterComboBox->SetPos(XMFLOAT2(x, y += step)); - emitterComboBox->SetSize(XMFLOAT2(360, 25)); - emitterComboBox->OnSelect([&](wiEventArgs args) { - if (object != nullptr && args.iValue >= 0) - { - SetObject(object); - } - }); - emitterComboBox->SetEnabled(false); - emitterComboBox->SetTooltip("Choose an emitter associated with the selected object"); - emitterWindow->AddWidget(emitterComboBox); + //emitterComboBox = new wiComboBox("Emitter: "); + //emitterComboBox->SetPos(XMFLOAT2(x, y += step)); + //emitterComboBox->SetSize(XMFLOAT2(360, 25)); + //emitterComboBox->OnSelect([&](wiEventArgs args) { + // if (object != nullptr && args.iValue >= 0) + // { + // SetObject(object); + // } + //}); + //emitterComboBox->SetEnabled(false); + //emitterComboBox->SetTooltip("Choose an emitter associated with the selected object"); + //emitterWindow->AddWidget(emitterComboBox); - shaderTypeComboBox = new wiComboBox("ShaderType: "); - shaderTypeComboBox->SetPos(XMFLOAT2(x, y += step)); - shaderTypeComboBox->SetSize(XMFLOAT2(200, 25)); - shaderTypeComboBox->AddItem("SOFT"); - shaderTypeComboBox->AddItem("SOFT + DISTORTION"); - shaderTypeComboBox->AddItem("SIMPLEST"); - shaderTypeComboBox->OnSelect([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->shaderType = (wiEmittedParticle::PARTICLESHADERTYPE)args.iValue; - } - }); - shaderTypeComboBox->SetEnabled(false); - shaderTypeComboBox->SetTooltip("Choose a shader type for the particles. This is responsible of how they will be rendered."); - emitterWindow->AddWidget(shaderTypeComboBox); + //shaderTypeComboBox = new wiComboBox("ShaderType: "); + //shaderTypeComboBox->SetPos(XMFLOAT2(x, y += step)); + //shaderTypeComboBox->SetSize(XMFLOAT2(200, 25)); + //shaderTypeComboBox->AddItem("SOFT"); + //shaderTypeComboBox->AddItem("SOFT + DISTORTION"); + //shaderTypeComboBox->AddItem("SIMPLEST"); + //shaderTypeComboBox->OnSelect([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->shaderType = (wiEmittedParticle::PARTICLESHADERTYPE)args.iValue; + // } + //}); + //shaderTypeComboBox->SetEnabled(false); + //shaderTypeComboBox->SetTooltip("Choose a shader type for the particles. This is responsible of how they will be rendered."); + //emitterWindow->AddWidget(shaderTypeComboBox); - sortCheckBox = new wiCheckBox("Sorting Enabled: "); - sortCheckBox->SetPos(XMFLOAT2(x, y += step)); - sortCheckBox->OnClick([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->SORTING = args.bValue; - } - }); - sortCheckBox->SetCheck(false); - sortCheckBox->SetTooltip("Enable sorting of the particles. This might slow down performance."); - emitterWindow->AddWidget(sortCheckBox); + //sortCheckBox = new wiCheckBox("Sorting Enabled: "); + //sortCheckBox->SetPos(XMFLOAT2(x, y += step)); + //sortCheckBox->OnClick([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->SORTING = args.bValue; + // } + //}); + //sortCheckBox->SetCheck(false); + //sortCheckBox->SetTooltip("Enable sorting of the particles. This might slow down performance."); + //emitterWindow->AddWidget(sortCheckBox); - depthCollisionsCheckBox = new wiCheckBox("Depth Buffer Collisions Enabled: "); - depthCollisionsCheckBox->SetPos(XMFLOAT2(x + 250, y)); - depthCollisionsCheckBox->OnClick([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->DEPTHCOLLISIONS = args.bValue; - } - }); - depthCollisionsCheckBox->SetCheck(false); - depthCollisionsCheckBox->SetTooltip("Enable particle collisions with the depth buffer."); - emitterWindow->AddWidget(depthCollisionsCheckBox); + //depthCollisionsCheckBox = new wiCheckBox("Depth Buffer Collisions Enabled: "); + //depthCollisionsCheckBox->SetPos(XMFLOAT2(x + 250, y)); + //depthCollisionsCheckBox->OnClick([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->DEPTHCOLLISIONS = args.bValue; + // } + //}); + //depthCollisionsCheckBox->SetCheck(false); + //depthCollisionsCheckBox->SetTooltip("Enable particle collisions with the depth buffer."); + //emitterWindow->AddWidget(depthCollisionsCheckBox); - sphCheckBox = new wiCheckBox("SPH - FluidSim: "); - sphCheckBox->SetPos(XMFLOAT2(x + 400, y)); - sphCheckBox->OnClick([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->SPH_FLUIDSIMULATION = args.bValue; - } - }); - sphCheckBox->SetCheck(false); - sphCheckBox->SetTooltip("Enable particle collisions with each other. Simulate with Smooth Particle Hydrodynamics (SPH) solver."); - emitterWindow->AddWidget(sphCheckBox); + //sphCheckBox = new wiCheckBox("SPH - FluidSim: "); + //sphCheckBox->SetPos(XMFLOAT2(x + 400, y)); + //sphCheckBox->OnClick([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->SPH_FLUIDSIMULATION = args.bValue; + // } + //}); + //sphCheckBox->SetCheck(false); + //sphCheckBox->SetTooltip("Enable particle collisions with each other. Simulate with Smooth Particle Hydrodynamics (SPH) solver."); + //emitterWindow->AddWidget(sphCheckBox); - pauseCheckBox = new wiCheckBox("PAUSE: "); - pauseCheckBox->SetPos(XMFLOAT2(x, y += step)); - pauseCheckBox->OnClick([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->PAUSED = args.bValue; - } - }); - pauseCheckBox->SetCheck(false); - pauseCheckBox->SetTooltip("Stop simulation update."); - emitterWindow->AddWidget(pauseCheckBox); + //pauseCheckBox = new wiCheckBox("PAUSE: "); + //pauseCheckBox->SetPos(XMFLOAT2(x, y += step)); + //pauseCheckBox->OnClick([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->PAUSED = args.bValue; + // } + //}); + //pauseCheckBox->SetCheck(false); + //pauseCheckBox->SetTooltip("Stop simulation update."); + //emitterWindow->AddWidget(pauseCheckBox); - debugCheckBox = new wiCheckBox("DEBUG: "); - debugCheckBox->SetPos(XMFLOAT2(x + 120, y)); - debugCheckBox->OnClick([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->DEBUG = args.bValue; - } - }); - debugCheckBox->SetCheck(false); - debugCheckBox->SetTooltip("Enable debug info for the emitter. This involves reading back GPU data, so rendering can slow down."); - emitterWindow->AddWidget(debugCheckBox); + //debugCheckBox = new wiCheckBox("DEBUG: "); + //debugCheckBox->SetPos(XMFLOAT2(x + 120, y)); + //debugCheckBox->OnClick([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->DEBUG = args.bValue; + // } + //}); + //debugCheckBox->SetCheck(false); + //debugCheckBox->SetTooltip("Enable debug info for the emitter. This involves reading back GPU data, so rendering can slow down."); + //emitterWindow->AddWidget(debugCheckBox); - infoLabel = new wiLabel("EmitterInfo"); - infoLabel->SetSize(XMFLOAT2(380, 140)); - infoLabel->SetPos(XMFLOAT2(x, y += step)); - emitterWindow->AddWidget(infoLabel); + //infoLabel = new wiLabel("EmitterInfo"); + //infoLabel->SetSize(XMFLOAT2(380, 140)); + //infoLabel->SetPos(XMFLOAT2(x, y += step)); + //emitterWindow->AddWidget(infoLabel); - maxParticlesSlider = new wiSlider(100.0f, 1000000.0f, 10000, 100000, "Max particle count: "); - maxParticlesSlider->SetSize(XMFLOAT2(360, 30)); - maxParticlesSlider->SetPos(XMFLOAT2(x, y += step + 140)); - maxParticlesSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->SetMaxParticleCount((uint32_t)args.iValue); - } - }); - maxParticlesSlider->SetEnabled(false); - maxParticlesSlider->SetTooltip("Set the maximum amount of particles this system can handle. This has an effect on the memory budget."); - emitterWindow->AddWidget(maxParticlesSlider); + //maxParticlesSlider = new wiSlider(100.0f, 1000000.0f, 10000, 100000, "Max particle count: "); + //maxParticlesSlider->SetSize(XMFLOAT2(360, 30)); + //maxParticlesSlider->SetPos(XMFLOAT2(x, y += step + 140)); + //maxParticlesSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->SetMaxParticleCount((uint32_t)args.iValue); + // } + //}); + //maxParticlesSlider->SetEnabled(false); + //maxParticlesSlider->SetTooltip("Set the maximum amount of particles this system can handle. This has an effect on the memory budget."); + //emitterWindow->AddWidget(maxParticlesSlider); - y += 30; + //y += 30; - ////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////// - emitCountSlider = new wiSlider(0.0f, 10000.0f, 1.0f, 100000, "Emit count per sec: "); - emitCountSlider->SetSize(XMFLOAT2(360, 30)); - emitCountSlider->SetPos(XMFLOAT2(x, y += step)); - emitCountSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->count = args.fValue; - } - }); - emitCountSlider->SetEnabled(false); - emitCountSlider->SetTooltip("Set the number of particles to emit per second."); - emitterWindow->AddWidget(emitCountSlider); + //emitCountSlider = new wiSlider(0.0f, 10000.0f, 1.0f, 100000, "Emit count per sec: "); + //emitCountSlider->SetSize(XMFLOAT2(360, 30)); + //emitCountSlider->SetPos(XMFLOAT2(x, y += step)); + //emitCountSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->count = args.fValue; + // } + //}); + //emitCountSlider->SetEnabled(false); + //emitCountSlider->SetTooltip("Set the number of particles to emit per second."); + //emitterWindow->AddWidget(emitCountSlider); - emitSizeSlider = new wiSlider(0.01f, 10.0f, 1.0f, 100000, "Size: "); - emitSizeSlider->SetSize(XMFLOAT2(360, 30)); - emitSizeSlider->SetPos(XMFLOAT2(x, y += step)); - emitSizeSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->size = args.fValue; - } - }); - emitSizeSlider->SetEnabled(false); - emitSizeSlider->SetTooltip("Set the size of the emitted particles."); - emitterWindow->AddWidget(emitSizeSlider); + //emitSizeSlider = new wiSlider(0.01f, 10.0f, 1.0f, 100000, "Size: "); + //emitSizeSlider->SetSize(XMFLOAT2(360, 30)); + //emitSizeSlider->SetPos(XMFLOAT2(x, y += step)); + //emitSizeSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->size = args.fValue; + // } + //}); + //emitSizeSlider->SetEnabled(false); + //emitSizeSlider->SetTooltip("Set the size of the emitted particles."); + //emitterWindow->AddWidget(emitSizeSlider); - emitRotationSlider = new wiSlider(0.0f, 1.0f, 0.0f, 100000, "Rotation: "); - emitRotationSlider->SetSize(XMFLOAT2(360, 30)); - emitRotationSlider->SetPos(XMFLOAT2(x, y += step)); - emitRotationSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->rotation = args.fValue; - } - }); - emitRotationSlider->SetEnabled(false); - emitRotationSlider->SetTooltip("Set the rotation velocity of the emitted particles."); - emitterWindow->AddWidget(emitRotationSlider); + //emitRotationSlider = new wiSlider(0.0f, 1.0f, 0.0f, 100000, "Rotation: "); + //emitRotationSlider->SetSize(XMFLOAT2(360, 30)); + //emitRotationSlider->SetPos(XMFLOAT2(x, y += step)); + //emitRotationSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->rotation = args.fValue; + // } + //}); + //emitRotationSlider->SetEnabled(false); + //emitRotationSlider->SetTooltip("Set the rotation velocity of the emitted particles."); + //emitterWindow->AddWidget(emitRotationSlider); - emitNormalSlider = new wiSlider(0.0f, 100.0f, 1.0f, 100000, "Normal factor: "); - emitNormalSlider->SetSize(XMFLOAT2(360, 30)); - emitNormalSlider->SetPos(XMFLOAT2(x, y += step)); - emitNormalSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->normal_factor = args.fValue; - } - }); - emitNormalSlider->SetEnabled(false); - emitNormalSlider->SetTooltip("Set the velocity of the emitted particles based on the normal vector of the emitter surface."); - emitterWindow->AddWidget(emitNormalSlider); + //emitNormalSlider = new wiSlider(0.0f, 100.0f, 1.0f, 100000, "Normal factor: "); + //emitNormalSlider->SetSize(XMFLOAT2(360, 30)); + //emitNormalSlider->SetPos(XMFLOAT2(x, y += step)); + //emitNormalSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->normal_factor = args.fValue; + // } + //}); + //emitNormalSlider->SetEnabled(false); + //emitNormalSlider->SetTooltip("Set the velocity of the emitted particles based on the normal vector of the emitter surface."); + //emitterWindow->AddWidget(emitNormalSlider); - emitScalingSlider = new wiSlider(0.0f, 100.0f, 1.0f, 100000, "Scaling: "); - emitScalingSlider->SetSize(XMFLOAT2(360, 30)); - emitScalingSlider->SetPos(XMFLOAT2(x, y += step)); - emitScalingSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->scaleX = args.fValue; - } - }); - emitScalingSlider->SetEnabled(false); - emitScalingSlider->SetTooltip("Set the scaling of the particles based on their lifetime."); - emitterWindow->AddWidget(emitScalingSlider); + //emitScalingSlider = new wiSlider(0.0f, 100.0f, 1.0f, 100000, "Scaling: "); + //emitScalingSlider->SetSize(XMFLOAT2(360, 30)); + //emitScalingSlider->SetPos(XMFLOAT2(x, y += step)); + //emitScalingSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->scaleX = args.fValue; + // } + //}); + //emitScalingSlider->SetEnabled(false); + //emitScalingSlider->SetTooltip("Set the scaling of the particles based on their lifetime."); + //emitterWindow->AddWidget(emitScalingSlider); - emitLifeSlider = new wiSlider(0.0f, 1000.0f, 1.0f, 100000, "Life span: "); - emitLifeSlider->SetSize(XMFLOAT2(360, 30)); - emitLifeSlider->SetPos(XMFLOAT2(x, y += step)); - emitLifeSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->life = args.fValue; - } - }); - emitLifeSlider->SetEnabled(false); - emitLifeSlider->SetTooltip("Set the lifespan of the emitted particles."); - emitterWindow->AddWidget(emitLifeSlider); + //emitLifeSlider = new wiSlider(0.0f, 1000.0f, 1.0f, 100000, "Life span: "); + //emitLifeSlider->SetSize(XMFLOAT2(360, 30)); + //emitLifeSlider->SetPos(XMFLOAT2(x, y += step)); + //emitLifeSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->life = args.fValue; + // } + //}); + //emitLifeSlider->SetEnabled(false); + //emitLifeSlider->SetTooltip("Set the lifespan of the emitted particles."); + //emitterWindow->AddWidget(emitLifeSlider); - emitRandomnessSlider = new wiSlider(0.0f, 1.0f, 1.0f, 100000, "Randomness: "); - emitRandomnessSlider->SetSize(XMFLOAT2(360, 30)); - emitRandomnessSlider->SetPos(XMFLOAT2(x, y += step)); - emitRandomnessSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->random_factor = args.fValue; - } - }); - emitRandomnessSlider->SetEnabled(false); - emitRandomnessSlider->SetTooltip("Set the general randomness of the emitter."); - emitterWindow->AddWidget(emitRandomnessSlider); + //emitRandomnessSlider = new wiSlider(0.0f, 1.0f, 1.0f, 100000, "Randomness: "); + //emitRandomnessSlider->SetSize(XMFLOAT2(360, 30)); + //emitRandomnessSlider->SetPos(XMFLOAT2(x, y += step)); + //emitRandomnessSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->random_factor = args.fValue; + // } + //}); + //emitRandomnessSlider->SetEnabled(false); + //emitRandomnessSlider->SetTooltip("Set the general randomness of the emitter."); + //emitterWindow->AddWidget(emitRandomnessSlider); - emitLifeRandomnessSlider = new wiSlider(0.0f, 2.0f, 0.0f, 100000, "Life randomness: "); - emitLifeRandomnessSlider->SetSize(XMFLOAT2(360, 30)); - emitLifeRandomnessSlider->SetPos(XMFLOAT2(x, y += step)); - emitLifeRandomnessSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->random_life = args.fValue; - } - }); - emitLifeRandomnessSlider->SetEnabled(false); - emitLifeRandomnessSlider->SetTooltip("Set the randomness of lifespans for the emitted particles."); - emitterWindow->AddWidget(emitLifeRandomnessSlider); + //emitLifeRandomnessSlider = new wiSlider(0.0f, 2.0f, 0.0f, 100000, "Life randomness: "); + //emitLifeRandomnessSlider->SetSize(XMFLOAT2(360, 30)); + //emitLifeRandomnessSlider->SetPos(XMFLOAT2(x, y += step)); + //emitLifeRandomnessSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->random_life = args.fValue; + // } + //}); + //emitLifeRandomnessSlider->SetEnabled(false); + //emitLifeRandomnessSlider->SetTooltip("Set the randomness of lifespans for the emitted particles."); + //emitterWindow->AddWidget(emitLifeRandomnessSlider); - emitMotionBlurSlider = new wiSlider(0.0f, 1.0f, 1.0f, 100000, "Motion blur: "); - emitMotionBlurSlider->SetSize(XMFLOAT2(360, 30)); - emitMotionBlurSlider->SetPos(XMFLOAT2(x, y += step)); - emitMotionBlurSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->motionBlurAmount = args.fValue; - } - }); - emitMotionBlurSlider->SetEnabled(false); - emitMotionBlurSlider->SetTooltip("Set the motion blur amount for the particle system."); - emitterWindow->AddWidget(emitMotionBlurSlider); + //emitMotionBlurSlider = new wiSlider(0.0f, 1.0f, 1.0f, 100000, "Motion blur: "); + //emitMotionBlurSlider->SetSize(XMFLOAT2(360, 30)); + //emitMotionBlurSlider->SetPos(XMFLOAT2(x, y += step)); + //emitMotionBlurSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->motionBlurAmount = args.fValue; + // } + //}); + //emitMotionBlurSlider->SetEnabled(false); + //emitMotionBlurSlider->SetTooltip("Set the motion blur amount for the particle system."); + //emitterWindow->AddWidget(emitMotionBlurSlider); - emitMassSlider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "Mass: "); - emitMassSlider->SetSize(XMFLOAT2(360, 30)); - emitMassSlider->SetPos(XMFLOAT2(x, y += step)); - emitMassSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->mass = args.fValue; - } - }); - emitMassSlider->SetEnabled(false); - emitMassSlider->SetTooltip("Set the mass per particle."); - emitterWindow->AddWidget(emitMassSlider); + //emitMassSlider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "Mass: "); + //emitMassSlider->SetSize(XMFLOAT2(360, 30)); + //emitMassSlider->SetPos(XMFLOAT2(x, y += step)); + //emitMassSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->mass = args.fValue; + // } + //}); + //emitMassSlider->SetEnabled(false); + //emitMassSlider->SetTooltip("Set the mass per particle."); + //emitterWindow->AddWidget(emitMassSlider); - timestepSlider = new wiSlider(-1, 0.016f, -1, 100000, "Timestep: "); - timestepSlider->SetSize(XMFLOAT2(360, 30)); - timestepSlider->SetPos(XMFLOAT2(x, y += step*2)); - timestepSlider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->FIXED_TIMESTEP = args.fValue; - } - }); - timestepSlider->SetEnabled(false); - timestepSlider->SetTooltip("Adjust timestep for emitter simulation. -1 means variable timestep, positive means fixed timestep."); - emitterWindow->AddWidget(timestepSlider); + //timestepSlider = new wiSlider(-1, 0.016f, -1, 100000, "Timestep: "); + //timestepSlider->SetSize(XMFLOAT2(360, 30)); + //timestepSlider->SetPos(XMFLOAT2(x, y += step*2)); + //timestepSlider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->FIXED_TIMESTEP = args.fValue; + // } + //}); + //timestepSlider->SetEnabled(false); + //timestepSlider->SetTooltip("Adjust timestep for emitter simulation. -1 means variable timestep, positive means fixed timestep."); + //emitterWindow->AddWidget(timestepSlider); - //////////////// SPH //////////////////////////// + ////////////////// SPH //////////////////////////// - y += step; + //y += step; - sph_h_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Smoothing Radius (h): "); - sph_h_Slider->SetSize(XMFLOAT2(360, 30)); - sph_h_Slider->SetPos(XMFLOAT2(x, y += step)); - sph_h_Slider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->SPH_h = args.fValue; - } - }); - sph_h_Slider->SetEnabled(false); - sph_h_Slider->SetTooltip("Set the SPH parameter: smoothing radius"); - emitterWindow->AddWidget(sph_h_Slider); + //sph_h_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Smoothing Radius (h): "); + //sph_h_Slider->SetSize(XMFLOAT2(360, 30)); + //sph_h_Slider->SetPos(XMFLOAT2(x, y += step)); + //sph_h_Slider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->SPH_h = args.fValue; + // } + //}); + //sph_h_Slider->SetEnabled(false); + //sph_h_Slider->SetTooltip("Set the SPH parameter: smoothing radius"); + //emitterWindow->AddWidget(sph_h_Slider); - sph_K_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Pressure Constant (K): "); - sph_K_Slider->SetSize(XMFLOAT2(360, 30)); - sph_K_Slider->SetPos(XMFLOAT2(x, y += step)); - sph_K_Slider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->SPH_K = args.fValue; - } - }); - sph_K_Slider->SetEnabled(false); - sph_K_Slider->SetTooltip("Set the SPH parameter: pressure constant"); - emitterWindow->AddWidget(sph_K_Slider); + //sph_K_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Pressure Constant (K): "); + //sph_K_Slider->SetSize(XMFLOAT2(360, 30)); + //sph_K_Slider->SetPos(XMFLOAT2(x, y += step)); + //sph_K_Slider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->SPH_K = args.fValue; + // } + //}); + //sph_K_Slider->SetEnabled(false); + //sph_K_Slider->SetTooltip("Set the SPH parameter: pressure constant"); + //emitterWindow->AddWidget(sph_K_Slider); - sph_p0_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Reference Density (p0): "); - sph_p0_Slider->SetSize(XMFLOAT2(360, 30)); - sph_p0_Slider->SetPos(XMFLOAT2(x, y += step)); - sph_p0_Slider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->SPH_p0 = args.fValue; - } - }); - sph_p0_Slider->SetEnabled(false); - sph_p0_Slider->SetTooltip("Set the SPH parameter: reference density"); - emitterWindow->AddWidget(sph_p0_Slider); + //sph_p0_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Reference Density (p0): "); + //sph_p0_Slider->SetSize(XMFLOAT2(360, 30)); + //sph_p0_Slider->SetPos(XMFLOAT2(x, y += step)); + //sph_p0_Slider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->SPH_p0 = args.fValue; + // } + //}); + //sph_p0_Slider->SetEnabled(false); + //sph_p0_Slider->SetTooltip("Set the SPH parameter: reference density"); + //emitterWindow->AddWidget(sph_p0_Slider); - sph_e_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Viscosity (e): "); - sph_e_Slider->SetSize(XMFLOAT2(360, 30)); - sph_e_Slider->SetPos(XMFLOAT2(x, y += step)); - sph_e_Slider->OnSlide([&](wiEventArgs args) { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->SPH_e = args.fValue; - } - }); - sph_e_Slider->SetEnabled(false); - sph_e_Slider->SetTooltip("Set the SPH parameter: viscosity constant"); - emitterWindow->AddWidget(sph_e_Slider); + //sph_e_Slider = new wiSlider(0.1f, 100.0f, 1.0f, 100000, "SPH Viscosity (e): "); + //sph_e_Slider->SetSize(XMFLOAT2(360, 30)); + //sph_e_Slider->SetPos(XMFLOAT2(x, y += step)); + //sph_e_Slider->OnSlide([&](wiEventArgs args) { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->SPH_e = args.fValue; + // } + //}); + //sph_e_Slider->SetEnabled(false); + //sph_e_Slider->SetTooltip("Set the SPH parameter: viscosity constant"); + //emitterWindow->AddWidget(sph_e_Slider); @@ -382,43 +382,43 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) - ////// UTIL ///////////////// + //////// UTIL ///////////////// - y += step; + //y += step; - materialSelectButton = new wiButton("Select Material"); - materialSelectButton->SetPos(XMFLOAT2(x, y += step)); - materialSelectButton->SetSize(XMFLOAT2(150, 30)); - materialSelectButton->OnClick([&](wiEventArgs args) { - if (materialWnd != nullptr) - { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - materialWnd->SetMaterial(emitter->material); - } - } - }); - materialSelectButton->SetTooltip("Select corresponding material in the Material Window."); - emitterWindow->AddWidget(materialSelectButton); + //materialSelectButton = new wiButton("Select Material"); + //materialSelectButton->SetPos(XMFLOAT2(x, y += step)); + //materialSelectButton->SetSize(XMFLOAT2(150, 30)); + //materialSelectButton->OnClick([&](wiEventArgs args) { + // if (materialWnd != nullptr) + // { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // materialWnd->SetMaterial(emitter->material); + // } + // } + //}); + //materialSelectButton->SetTooltip("Select corresponding material in the Material Window."); + //emitterWindow->AddWidget(materialSelectButton); - restartButton = new wiButton("Restart Emitter"); - restartButton->SetPos(XMFLOAT2(x + 200, y)); - restartButton->SetSize(XMFLOAT2(150, 30)); - restartButton->OnClick([&](wiEventArgs args) { - if (materialWnd != nullptr) - { - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - emitter->Restart(); - } - } - }); - restartButton->SetTooltip("Restart particle system emitter"); - emitterWindow->AddWidget(restartButton); + //restartButton = new wiButton("Restart Emitter"); + //restartButton->SetPos(XMFLOAT2(x + 200, y)); + //restartButton->SetSize(XMFLOAT2(150, 30)); + //restartButton->OnClick([&](wiEventArgs args) { + // if (materialWnd != nullptr) + // { + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // emitter->Restart(); + // } + // } + //}); + //restartButton->SetTooltip("Restart particle system emitter"); + //emitterWindow->AddWidget(restartButton); @@ -426,7 +426,7 @@ EmitterWindow::EmitterWindow(wiGUI* gui) : GUI(gui) emitterWindow->Translate(XMFLOAT3(200, 50, 0)); emitterWindow->SetVisible(false); - SetObject(nullptr); + SetEntity(entity); } @@ -437,65 +437,67 @@ EmitterWindow::~EmitterWindow() SAFE_DELETE(emitterWindow); } -void EmitterWindow::SetObject(Object* obj) +void EmitterWindow::SetEntity(Entity entity) { - if (this->object == obj) - return; + this->entity = entity; - // first try to turn off any debug readbacks for emitters: - if (GetEmitter() != nullptr) - { - GetEmitter()->DEBUG = false; - } - debugCheckBox->SetCheck(false); + //if (this->object == obj) + // return; - object = obj; + //// first try to turn off any debug readbacks for emitters: + //if (GetEmitter() != nullptr) + //{ + // GetEmitter()->DEBUG = false; + //} + //debugCheckBox->SetCheck(false); - emitterComboBox->ClearItems(); + //object = obj; - if (object != nullptr) - { - for (auto& x : object->eParticleSystems) - { - emitterComboBox->AddItem(x->name); - emitterComboBox->SetEnabled(true); - } + //emitterComboBox->ClearItems(); - auto emitter = GetEmitter(); - if (emitter != nullptr) - { - sortCheckBox->SetCheck(emitter->SORTING); - depthCollisionsCheckBox->SetCheck(emitter->DEPTHCOLLISIONS); - sphCheckBox->SetCheck(emitter->SPH_FLUIDSIMULATION); - pauseCheckBox->SetCheck(emitter->PAUSED); - maxParticlesSlider->SetValue((float)emitter->GetMaxParticleCount()); + //if (object != nullptr) + //{ + // for (auto& x : object->eParticleSystems) + // { + // emitterComboBox->AddItem(x->name); + // emitterComboBox->SetEnabled(true); + // } - emitCountSlider->SetValue(emitter->count); - emitSizeSlider->SetValue(emitter->size); - emitRotationSlider->SetValue(emitter->rotation); - emitNormalSlider->SetValue(emitter->normal_factor); - emitScalingSlider->SetValue(emitter->scaleX); - emitLifeSlider->SetValue(emitter->life); - emitRandomnessSlider->SetValue(emitter->random_factor); - emitLifeRandomnessSlider->SetValue(emitter->random_life); - emitMotionBlurSlider->SetValue(emitter->motionBlurAmount); - emitMassSlider->SetValue(emitter->mass); - timestepSlider->SetValue(emitter->FIXED_TIMESTEP); + // auto emitter = GetEmitter(); + // if (emitter != nullptr) + // { + // sortCheckBox->SetCheck(emitter->SORTING); + // depthCollisionsCheckBox->SetCheck(emitter->DEPTHCOLLISIONS); + // sphCheckBox->SetCheck(emitter->SPH_FLUIDSIMULATION); + // pauseCheckBox->SetCheck(emitter->PAUSED); + // maxParticlesSlider->SetValue((float)emitter->GetMaxParticleCount()); - sph_h_Slider->SetValue(emitter->SPH_h); - sph_K_Slider->SetValue(emitter->SPH_K); - sph_p0_Slider->SetValue(emitter->SPH_p0); - sph_e_Slider->SetValue(emitter->SPH_e); - } + // emitCountSlider->SetValue(emitter->count); + // emitSizeSlider->SetValue(emitter->size); + // emitRotationSlider->SetValue(emitter->rotation); + // emitNormalSlider->SetValue(emitter->normal_factor); + // emitScalingSlider->SetValue(emitter->scaleX); + // emitLifeSlider->SetValue(emitter->life); + // emitRandomnessSlider->SetValue(emitter->random_factor); + // emitLifeRandomnessSlider->SetValue(emitter->random_life); + // emitMotionBlurSlider->SetValue(emitter->motionBlurAmount); + // emitMassSlider->SetValue(emitter->mass); + // timestepSlider->SetValue(emitter->FIXED_TIMESTEP); - emitterWindow->SetEnabled(true); - } - else - { - infoLabel->SetText("No emitter object selected."); + // sph_h_Slider->SetValue(emitter->SPH_h); + // sph_K_Slider->SetValue(emitter->SPH_K); + // sph_p0_Slider->SetValue(emitter->SPH_p0); + // sph_e_Slider->SetValue(emitter->SPH_e); + // } - emitterWindow->SetEnabled(false); - } + // emitterWindow->SetEnabled(true); + //} + //else + //{ + // infoLabel->SetText("No emitter object selected."); + + // emitterWindow->SetEnabled(false); + //} } @@ -506,55 +508,55 @@ void EmitterWindow::SetMaterialWnd(MaterialWindow* wnd) wiEmittedParticle* EmitterWindow::GetEmitter() { - if (object == nullptr) - { - return nullptr; - } + //if (object == nullptr) + //{ + // return nullptr; + //} - int sel = emitterComboBox->GetSelected(); + //int sel = emitterComboBox->GetSelected(); - if (sel < 0) - { - return nullptr; - } + //if (sel < 0) + //{ + // return nullptr; + //} - if ((int)object->eParticleSystems.size() > sel) - { - return object->eParticleSystems[sel]; - } + //if ((int)object->eParticleSystems.size() > sel) + //{ + // return object->eParticleSystems[sel]; + //} return nullptr; } void EmitterWindow::UpdateData() { - auto emitter = GetEmitter(); - if (emitter == nullptr) - { - return; - } + //auto emitter = GetEmitter(); + //if (emitter == nullptr) + //{ + // return; + //} - stringstream ss(""); - ss.precision(2); - ss << "Emitter name: " << emitter->name << endl; - ss << "Emitter Object: " << (emitter->object != nullptr ? emitter->object->name : "ERROR: NO EMITTER OBJECT") << endl; - ss << "Emitter Material: " << (emitter->material != nullptr ? emitter->material->name : "ERROR: NO EMITTER MATERIAL") << endl; - ss << "Memort Budget: " << emitter->GetMemorySizeInBytes() / 1024.0f / 1024.0f << " MB" << endl; - ss << endl; + //stringstream ss(""); + //ss.precision(2); + //ss << "Emitter name: " << emitter->name << endl; + //ss << "Emitter Object: " << (emitter->object != nullptr ? emitter->object->name : "ERROR: NO EMITTER OBJECT") << endl; + //ss << "Emitter Material: " << (emitter->material != nullptr ? emitter->material->name : "ERROR: NO EMITTER MATERIAL") << endl; + //ss << "Memort Budget: " << emitter->GetMemorySizeInBytes() / 1024.0f / 1024.0f << " MB" << endl; + //ss << endl; - if (emitter->DEBUG) - { - auto data = emitter->GetDebugData(); + //if (emitter->DEBUG) + //{ + // auto data = emitter->GetDebugData(); - ss << "Alive Particle Count = " << data.aliveCount << endl; - ss << "Dead Particle Count = " << data.deadCount << endl; - ss << "GPU Emit count = " << data.realEmitCount << endl; - } - else - { - ss << "For additional data, enable [DEBUG]" << endl; - } + // ss << "Alive Particle Count = " << data.aliveCount << endl; + // ss << "Dead Particle Count = " << data.deadCount << endl; + // ss << "GPU Emit count = " << data.realEmitCount << endl; + //} + //else + //{ + // ss << "For additional data, enable [DEBUG]" << endl; + //} - infoLabel->SetText(ss.str()); + //infoLabel->SetText(ss.str()); } diff --git a/Editor/EmitterWindow.h b/Editor/EmitterWindow.h index 6d8ca9707..a1f842771 100644 --- a/Editor/EmitterWindow.h +++ b/Editor/EmitterWindow.h @@ -1,10 +1,5 @@ #pragma once -namespace wiSceneComponents -{ - struct Object; -} - class wiEmittedParticle; class wiGUI; @@ -23,11 +18,12 @@ public: EmitterWindow(wiGUI* gui); ~EmitterWindow(); - void SetObject(wiSceneComponents::Object* obj); + wiECS::Entity entity; + void SetEntity(wiECS::Entity entity); + void SetMaterialWnd(MaterialWindow* wnd); void UpdateData(); - wiSceneComponents::Object* object; wiEmittedParticle* GetEmitter(); wiGUI* GUI; diff --git a/Editor/EnvProbeWindow.cpp b/Editor/EnvProbeWindow.cpp index 7ac018ef7..fdc9f58a4 100644 --- a/Editor/EnvProbeWindow.cpp +++ b/Editor/EnvProbeWindow.cpp @@ -1,12 +1,11 @@ #include "stdafx.h" #include "EnvProbeWindow.h" -using namespace wiSceneComponents; +using namespace wiECS; +using namespace wiSceneSystem; EnvProbeWindow::EnvProbeWindow(wiGUI* gui) : GUI(gui) { - probe = nullptr; - assert(GUI && "Invalid GUI!"); float screenW = (float)wiRenderer::GetDevice()->GetScreenWidth(); @@ -19,58 +18,60 @@ EnvProbeWindow::EnvProbeWindow(wiGUI* gui) : GUI(gui) float x = 250, y = 0, step = 45; - realTimeCheckBox = new wiCheckBox("RealTime: "); - realTimeCheckBox->SetPos(XMFLOAT2(x, y += step)); - realTimeCheckBox->SetEnabled(false); - realTimeCheckBox->OnClick([&](wiEventArgs args) { - if (probe != nullptr) - { - probe->realTime = args.bValue; - probe->isUpToDate = false; - } - }); - envProbeWindow->AddWidget(realTimeCheckBox); + //realTimeCheckBox = new wiCheckBox("RealTime: "); + //realTimeCheckBox->SetPos(XMFLOAT2(x, y += step)); + //realTimeCheckBox->SetEnabled(false); + //realTimeCheckBox->OnClick([&](wiEventArgs args) { + // if (probe != nullptr) + // { + // probe->realTime = args.bValue; + // probe->isUpToDate = false; + // } + //}); + //envProbeWindow->AddWidget(realTimeCheckBox); - generateButton = new wiButton("Put"); - generateButton->SetPos(XMFLOAT2(x, y += step)); - generateButton->OnClick([](wiEventArgs args) { - XMFLOAT3 pos; - XMStoreFloat3(&pos, XMVectorAdd(wiRenderer::getCamera()->GetEye(), wiRenderer::getCamera()->GetAt() * 4)); - wiRenderer::PutEnvProbe(pos); - }); - envProbeWindow->AddWidget(generateButton); + //generateButton = new wiButton("Put"); + //generateButton->SetPos(XMFLOAT2(x, y += step)); + //generateButton->OnClick([](wiEventArgs args) { + // XMFLOAT3 pos; + // XMStoreFloat3(&pos, XMVectorAdd(wiRenderer::getCamera()->GetEye(), wiRenderer::getCamera()->GetAt() * 4)); + // wiRenderer::PutEnvProbe(pos); + //}); + //envProbeWindow->AddWidget(generateButton); - refreshButton = new wiButton("Refresh"); - refreshButton->SetPos(XMFLOAT2(x, y += step)); - refreshButton->SetEnabled(false); - refreshButton->OnClick([&](wiEventArgs args) { - if (probe != nullptr) - { - probe->isUpToDate = false; - } - }); - envProbeWindow->AddWidget(refreshButton); + //refreshButton = new wiButton("Refresh"); + //refreshButton->SetPos(XMFLOAT2(x, y += step)); + //refreshButton->SetEnabled(false); + //refreshButton->OnClick([&](wiEventArgs args) { + // if (probe != nullptr) + // { + // probe->isUpToDate = false; + // } + //}); + //envProbeWindow->AddWidget(refreshButton); - refreshAllButton = new wiButton("Refresh All"); - refreshAllButton->SetPos(XMFLOAT2(x, y += step)); - refreshAllButton->SetEnabled(true); - refreshAllButton->OnClick([&](wiEventArgs args) { - const Scene& scene = wiRenderer::GetScene(); - for (Model* x : scene.models) - { - for (EnvironmentProbe* probe : x->environmentProbes) - { - probe->isUpToDate = false; - } - } - }); - envProbeWindow->AddWidget(refreshAllButton); + //refreshAllButton = new wiButton("Refresh All"); + //refreshAllButton->SetPos(XMFLOAT2(x, y += step)); + //refreshAllButton->SetEnabled(true); + //refreshAllButton->OnClick([&](wiEventArgs args) { + // const Scene& scene = wiRenderer::GetScene(); + // for (Model* x : scene.models) + // { + // for (EnvironmentProbe* probe : x->environmentProbes) + // { + // probe->isUpToDate = false; + // } + // } + //}); + //envProbeWindow->AddWidget(refreshAllButton); envProbeWindow->Translate(XMFLOAT3(30, 30, 0)); envProbeWindow->SetVisible(false); + + SetEntity(INVALID_ENTITY); } @@ -81,19 +82,21 @@ EnvProbeWindow::~EnvProbeWindow() SAFE_DELETE(envProbeWindow); } -void EnvProbeWindow::SetProbe(EnvironmentProbe* value) +void EnvProbeWindow::SetEntity(Entity entity) { - probe = value; - if (probe == nullptr) - { - realTimeCheckBox->SetEnabled(false); - refreshButton->SetEnabled(false); - } - else - { - realTimeCheckBox->SetCheck(probe->realTime); - realTimeCheckBox->SetEnabled(true); - refreshButton->SetEnabled(true); - } + this->entity = entity; + + //probe = value; + //if (probe == nullptr) + //{ + // realTimeCheckBox->SetEnabled(false); + // refreshButton->SetEnabled(false); + //} + //else + //{ + // realTimeCheckBox->SetCheck(probe->realTime); + // realTimeCheckBox->SetEnabled(true); + // refreshButton->SetEnabled(true); + //} } diff --git a/Editor/EnvProbeWindow.h b/Editor/EnvProbeWindow.h index 9f0096bcb..68cc43b52 100644 --- a/Editor/EnvProbeWindow.h +++ b/Editor/EnvProbeWindow.h @@ -1,10 +1,5 @@ #pragma once -namespace wiSceneComponents -{ - struct EnvironmentProbe; -} - class wiGUI; class wiWindow; class wiLabel; @@ -19,8 +14,8 @@ public: wiGUI* GUI; - wiSceneComponents::EnvironmentProbe* probe; - void SetProbe(wiSceneComponents::EnvironmentProbe* value); + wiECS::Entity entity; + void SetEntity(wiECS::Entity entity); wiWindow* envProbeWindow; diff --git a/Editor/ForceFieldWindow.cpp b/Editor/ForceFieldWindow.cpp index e9c96a009..1ddd5013f 100644 --- a/Editor/ForceFieldWindow.cpp +++ b/Editor/ForceFieldWindow.cpp @@ -1,15 +1,14 @@ #include "stdafx.h" #include "ForceFieldWindow.h" -using namespace wiSceneComponents; +using namespace wiECS; +using namespace wiSceneSystem; ForceFieldWindow::ForceFieldWindow(wiGUI* gui) : GUI(gui) { assert(GUI && "Invalid GUI!"); - force = nullptr; - float screenW = (float)wiRenderer::GetDevice()->GetScreenWidth(); float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight(); @@ -23,77 +22,77 @@ ForceFieldWindow::ForceFieldWindow(wiGUI* gui) : GUI(gui) float y = 10; float step = 35; - typeComboBox = new wiComboBox("Force Field type: "); - typeComboBox->SetPos(XMFLOAT2(x, y += step)); - typeComboBox->SetSize(XMFLOAT2(300, 25)); - typeComboBox->OnSelect([&](wiEventArgs args) { - if (force != nullptr && args.iValue >= 0) - { - switch (args.iValue) - { - case 0: - force->type = ENTITY_TYPE_FORCEFIELD_POINT; - break; - case 1: - force->type = ENTITY_TYPE_FORCEFIELD_PLANE; - break; - default: - assert(0); // error - break; - } - } - }); - typeComboBox->AddItem("Point"); - typeComboBox->AddItem("Plane"); - typeComboBox->SetEnabled(false); - typeComboBox->SetTooltip("Choose the force field type."); - forceFieldWindow->AddWidget(typeComboBox); + //typeComboBox = new wiComboBox("Force Field type: "); + //typeComboBox->SetPos(XMFLOAT2(x, y += step)); + //typeComboBox->SetSize(XMFLOAT2(300, 25)); + //typeComboBox->OnSelect([&](wiEventArgs args) { + // if (force != nullptr && args.iValue >= 0) + // { + // switch (args.iValue) + // { + // case 0: + // force->type = ENTITY_TYPE_FORCEFIELD_POINT; + // break; + // case 1: + // force->type = ENTITY_TYPE_FORCEFIELD_PLANE; + // break; + // default: + // assert(0); // error + // break; + // } + // } + //}); + //typeComboBox->AddItem("Point"); + //typeComboBox->AddItem("Plane"); + //typeComboBox->SetEnabled(false); + //typeComboBox->SetTooltip("Choose the force field type."); + //forceFieldWindow->AddWidget(typeComboBox); - gravitySlider = new wiSlider(-10, 10, 0, 100000, "Gravity: "); - gravitySlider->SetSize(XMFLOAT2(200, 30)); - gravitySlider->SetPos(XMFLOAT2(x, y += step)); - gravitySlider->OnSlide([&](wiEventArgs args) { - if (force != nullptr) - { - force->gravity = args.fValue; - } - }); - gravitySlider->SetEnabled(false); - gravitySlider->SetTooltip("Set the amount of gravity. Positive values attract, negatives deflect."); - forceFieldWindow->AddWidget(gravitySlider); + //gravitySlider = new wiSlider(-10, 10, 0, 100000, "Gravity: "); + //gravitySlider->SetSize(XMFLOAT2(200, 30)); + //gravitySlider->SetPos(XMFLOAT2(x, y += step)); + //gravitySlider->OnSlide([&](wiEventArgs args) { + // if (force != nullptr) + // { + // force->gravity = args.fValue; + // } + //}); + //gravitySlider->SetEnabled(false); + //gravitySlider->SetTooltip("Set the amount of gravity. Positive values attract, negatives deflect."); + //forceFieldWindow->AddWidget(gravitySlider); - rangeSlider = new wiSlider(0.0f, 100.0f, 10, 100000, "Range: "); - rangeSlider->SetSize(XMFLOAT2(200, 30)); - rangeSlider->SetPos(XMFLOAT2(x, y += step)); - rangeSlider->OnSlide([&](wiEventArgs args) { - if (force != nullptr) - { - force->range = args.fValue; - } - }); - rangeSlider->SetEnabled(false); - rangeSlider->SetTooltip("Set the range of affection."); - forceFieldWindow->AddWidget(rangeSlider); + //rangeSlider = new wiSlider(0.0f, 100.0f, 10, 100000, "Range: "); + //rangeSlider->SetSize(XMFLOAT2(200, 30)); + //rangeSlider->SetPos(XMFLOAT2(x, y += step)); + //rangeSlider->OnSlide([&](wiEventArgs args) { + // if (force != nullptr) + // { + // force->range = args.fValue; + // } + //}); + //rangeSlider->SetEnabled(false); + //rangeSlider->SetTooltip("Set the range of affection."); + //forceFieldWindow->AddWidget(rangeSlider); - addButton = new wiButton("Add Force Field"); - addButton->SetSize(XMFLOAT2(150, 30)); - addButton->SetPos(XMFLOAT2(x, y += step * 2)); - addButton->OnClick([](wiEventArgs args) { - wiRenderer::Add(new ForceField); - }); - addButton->SetEnabled(true); - addButton->SetTooltip("Add new Force Field to the simulation."); - forceFieldWindow->AddWidget(addButton); + //addButton = new wiButton("Add Force Field"); + //addButton->SetSize(XMFLOAT2(150, 30)); + //addButton->SetPos(XMFLOAT2(x, y += step * 2)); + //addButton->OnClick([](wiEventArgs args) { + // wiRenderer::Add(new ForceField); + //}); + //addButton->SetEnabled(true); + //addButton->SetTooltip("Add new Force Field to the simulation."); + //forceFieldWindow->AddWidget(addButton); forceFieldWindow->Translate(XMFLOAT3(810, 50, 0)); forceFieldWindow->SetVisible(false); - SetForceField(nullptr); + SetEntity(INVALID_ENTITY); } @@ -101,25 +100,27 @@ ForceFieldWindow::~ForceFieldWindow() { } -void ForceFieldWindow::SetForceField(ForceField* force) +void ForceFieldWindow::SetEntity(Entity entity) { - if (this->force == force) - return; + this->entity = entity; - this->force = force; + //if (this->force == force) + // return; - if (force != nullptr) - { - typeComboBox->SetSelected(force->type == ENTITY_TYPE_FORCEFIELD_POINT ? 0 : 1); - gravitySlider->SetValue(force->gravity); - rangeSlider->SetValue(force->range); + //this->force = force; - forceFieldWindow->SetEnabled(true); - } - else - { - forceFieldWindow->SetEnabled(false); - } + //if (force != nullptr) + //{ + // typeComboBox->SetSelected(force->type == ENTITY_TYPE_FORCEFIELD_POINT ? 0 : 1); + // gravitySlider->SetValue(force->gravity); + // rangeSlider->SetValue(force->range); - addButton->SetEnabled(true); + // forceFieldWindow->SetEnabled(true); + //} + //else + //{ + // forceFieldWindow->SetEnabled(false); + //} + + //addButton->SetEnabled(true); } diff --git a/Editor/ForceFieldWindow.h b/Editor/ForceFieldWindow.h index 38a3a02ed..08d5f4e37 100644 --- a/Editor/ForceFieldWindow.h +++ b/Editor/ForceFieldWindow.h @@ -1,10 +1,5 @@ #pragma once -namespace wiSceneComponents -{ - struct ForceField; -} - class wiGUI; class wiWindow; class wiLabel; @@ -19,9 +14,8 @@ public: ForceFieldWindow(wiGUI* gui); ~ForceFieldWindow(); - void SetForceField(wiSceneComponents::ForceField* force); - - wiSceneComponents::ForceField* force; + wiECS::Entity entity; + void SetEntity(wiECS::Entity entity); wiGUI* GUI; diff --git a/Editor/LightWindow.cpp b/Editor/LightWindow.cpp index eac495a3a..c247f14e8 100644 --- a/Editor/LightWindow.cpp +++ b/Editor/LightWindow.cpp @@ -1,10 +1,11 @@ #include "stdafx.h" #include "LightWindow.h" -using namespace wiSceneComponents; +using namespace wiECS; +using namespace wiSceneSystem; -LightWindow::LightWindow(wiGUI* gui) : GUI(gui), light(nullptr) +LightWindow::LightWindow(wiGUI* gui) : GUI(gui) { assert(GUI && "Invalid GUI!"); @@ -20,185 +21,185 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui), light(nullptr) float y = 0; float step = 35; - energySlider = new wiSlider(0.1f, 64, 0, 100000, "Energy: "); - energySlider->SetSize(XMFLOAT2(100, 30)); - energySlider->SetPos(XMFLOAT2(x, y += step)); - energySlider->OnSlide([&](wiEventArgs args) { - if (light != nullptr) - { - light->enerDis.x = args.fValue; - } - }); - energySlider->SetEnabled(false); - energySlider->SetTooltip("Adjust the light radiation amount inside the maximum range"); - lightWindow->AddWidget(energySlider); + //energySlider = new wiSlider(0.1f, 64, 0, 100000, "Energy: "); + //energySlider->SetSize(XMFLOAT2(100, 30)); + //energySlider->SetPos(XMFLOAT2(x, y += step)); + //energySlider->OnSlide([&](wiEventArgs args) { + // if (light != nullptr) + // { + // light->enerDis.x = args.fValue; + // } + //}); + //energySlider->SetEnabled(false); + //energySlider->SetTooltip("Adjust the light radiation amount inside the maximum range"); + //lightWindow->AddWidget(energySlider); - distanceSlider = new wiSlider(1, 1000, 0, 100000, "Distance: "); - distanceSlider->SetSize(XMFLOAT2(100, 30)); - distanceSlider->SetPos(XMFLOAT2(x, y += step)); - distanceSlider->OnSlide([&](wiEventArgs args) { - if (light != nullptr) - { - light->enerDis.y = args.fValue; - } - }); - distanceSlider->SetEnabled(false); - distanceSlider->SetTooltip("Adjust the maximum range the light can affect."); - lightWindow->AddWidget(distanceSlider); + //distanceSlider = new wiSlider(1, 1000, 0, 100000, "Distance: "); + //distanceSlider->SetSize(XMFLOAT2(100, 30)); + //distanceSlider->SetPos(XMFLOAT2(x, y += step)); + //distanceSlider->OnSlide([&](wiEventArgs args) { + // if (light != nullptr) + // { + // light->enerDis.y = args.fValue; + // } + //}); + //distanceSlider->SetEnabled(false); + //distanceSlider->SetTooltip("Adjust the maximum range the light can affect."); + //lightWindow->AddWidget(distanceSlider); - radiusSlider = new wiSlider(0.01f, 10, 0, 100000, "Radius: "); - radiusSlider->SetSize(XMFLOAT2(100, 30)); - radiusSlider->SetPos(XMFLOAT2(x, y += step)); - radiusSlider->OnSlide([&](wiEventArgs args) { - if (light != nullptr) - { - light->radius = args.fValue; - } - }); - radiusSlider->SetEnabled(false); - radiusSlider->SetTooltip("Adjust the radius of an area light."); - lightWindow->AddWidget(radiusSlider); + //radiusSlider = new wiSlider(0.01f, 10, 0, 100000, "Radius: "); + //radiusSlider->SetSize(XMFLOAT2(100, 30)); + //radiusSlider->SetPos(XMFLOAT2(x, y += step)); + //radiusSlider->OnSlide([&](wiEventArgs args) { + // if (light != nullptr) + // { + // light->radius = args.fValue; + // } + //}); + //radiusSlider->SetEnabled(false); + //radiusSlider->SetTooltip("Adjust the radius of an area light."); + //lightWindow->AddWidget(radiusSlider); - widthSlider = new wiSlider(1, 10, 0, 100000, "Width: "); - widthSlider->SetSize(XMFLOAT2(100, 30)); - widthSlider->SetPos(XMFLOAT2(x, y += step)); - widthSlider->OnSlide([&](wiEventArgs args) { - if (light != nullptr) - { - light->width = args.fValue; - } - }); - widthSlider->SetEnabled(false); - widthSlider->SetTooltip("Adjust the width of an area light."); - lightWindow->AddWidget(widthSlider); + //widthSlider = new wiSlider(1, 10, 0, 100000, "Width: "); + //widthSlider->SetSize(XMFLOAT2(100, 30)); + //widthSlider->SetPos(XMFLOAT2(x, y += step)); + //widthSlider->OnSlide([&](wiEventArgs args) { + // if (light != nullptr) + // { + // light->width = args.fValue; + // } + //}); + //widthSlider->SetEnabled(false); + //widthSlider->SetTooltip("Adjust the width of an area light."); + //lightWindow->AddWidget(widthSlider); - heightSlider = new wiSlider(1, 10, 0, 100000, "Height: "); - heightSlider->SetSize(XMFLOAT2(100, 30)); - heightSlider->SetPos(XMFLOAT2(x, y += step)); - heightSlider->OnSlide([&](wiEventArgs args) { - if (light != nullptr) - { - light->height = args.fValue; - } - }); - heightSlider->SetEnabled(false); - heightSlider->SetTooltip("Adjust the height of an area light."); - lightWindow->AddWidget(heightSlider); + //heightSlider = new wiSlider(1, 10, 0, 100000, "Height: "); + //heightSlider->SetSize(XMFLOAT2(100, 30)); + //heightSlider->SetPos(XMFLOAT2(x, y += step)); + //heightSlider->OnSlide([&](wiEventArgs args) { + // if (light != nullptr) + // { + // light->height = args.fValue; + // } + //}); + //heightSlider->SetEnabled(false); + //heightSlider->SetTooltip("Adjust the height of an area light."); + //lightWindow->AddWidget(heightSlider); - fovSlider = new wiSlider(0.1f, XM_PI - 0.01f, 0, 100000, "FOV: "); - fovSlider->SetSize(XMFLOAT2(100, 30)); - fovSlider->SetPos(XMFLOAT2(x, y += step)); - fovSlider->OnSlide([&](wiEventArgs args) { - if (light != nullptr) - { - light->enerDis.z = args.fValue; - } - }); - fovSlider->SetEnabled(false); - fovSlider->SetTooltip("Adjust the cone aperture for spotlight."); - lightWindow->AddWidget(fovSlider); + //fovSlider = new wiSlider(0.1f, XM_PI - 0.01f, 0, 100000, "FOV: "); + //fovSlider->SetSize(XMFLOAT2(100, 30)); + //fovSlider->SetPos(XMFLOAT2(x, y += step)); + //fovSlider->OnSlide([&](wiEventArgs args) { + // if (light != nullptr) + // { + // light->enerDis.z = args.fValue; + // } + //}); + //fovSlider->SetEnabled(false); + //fovSlider->SetTooltip("Adjust the cone aperture for spotlight."); + //lightWindow->AddWidget(fovSlider); - biasSlider = new wiSlider(0.0f, 0.2f, 0, 100000, "ShadowBias: "); - biasSlider->SetSize(XMFLOAT2(100, 30)); - biasSlider->SetPos(XMFLOAT2(x, y += step)); - biasSlider->OnSlide([&](wiEventArgs args) { - if (light != nullptr) - { - light->shadowBias = args.fValue; - } - }); - biasSlider->SetEnabled(false); - biasSlider->SetTooltip("Adjust the shadow bias if shadow artifacts occur."); - lightWindow->AddWidget(biasSlider); + //biasSlider = new wiSlider(0.0f, 0.2f, 0, 100000, "ShadowBias: "); + //biasSlider->SetSize(XMFLOAT2(100, 30)); + //biasSlider->SetPos(XMFLOAT2(x, y += step)); + //biasSlider->OnSlide([&](wiEventArgs args) { + // if (light != nullptr) + // { + // light->shadowBias = args.fValue; + // } + //}); + //biasSlider->SetEnabled(false); + //biasSlider->SetTooltip("Adjust the shadow bias if shadow artifacts occur."); + //lightWindow->AddWidget(biasSlider); - shadowCheckBox = new wiCheckBox("Shadow: "); - shadowCheckBox->SetPos(XMFLOAT2(x, y += step)); - shadowCheckBox->OnClick([&](wiEventArgs args) { - if (light != nullptr) - { - light->shadow = args.bValue; - } - }); - shadowCheckBox->SetEnabled(false); - shadowCheckBox->SetTooltip("Set light as shadow caster. Many shadow casters can affect performance!"); - lightWindow->AddWidget(shadowCheckBox); + //shadowCheckBox = new wiCheckBox("Shadow: "); + //shadowCheckBox->SetPos(XMFLOAT2(x, y += step)); + //shadowCheckBox->OnClick([&](wiEventArgs args) { + // if (light != nullptr) + // { + // light->shadow = args.bValue; + // } + //}); + //shadowCheckBox->SetEnabled(false); + //shadowCheckBox->SetTooltip("Set light as shadow caster. Many shadow casters can affect performance!"); + //lightWindow->AddWidget(shadowCheckBox); - volumetricsCheckBox = new wiCheckBox("Volumetric Scattering: "); - volumetricsCheckBox->SetPos(XMFLOAT2(x, y += step)); - volumetricsCheckBox->OnClick([&](wiEventArgs args) { - if (light != nullptr) - { - light->volumetrics = args.bValue; - } - }); - volumetricsCheckBox->SetEnabled(false); - volumetricsCheckBox->SetTooltip("Compute volumetric light scattering effect. The scattering is modulated by fog settings!"); - lightWindow->AddWidget(volumetricsCheckBox); + //volumetricsCheckBox = new wiCheckBox("Volumetric Scattering: "); + //volumetricsCheckBox->SetPos(XMFLOAT2(x, y += step)); + //volumetricsCheckBox->OnClick([&](wiEventArgs args) { + // if (light != nullptr) + // { + // light->volumetrics = args.bValue; + // } + //}); + //volumetricsCheckBox->SetEnabled(false); + //volumetricsCheckBox->SetTooltip("Compute volumetric light scattering effect. The scattering is modulated by fog settings!"); + //lightWindow->AddWidget(volumetricsCheckBox); - haloCheckBox = new wiCheckBox("Visualizer: "); - haloCheckBox->SetPos(XMFLOAT2(x, y += step)); - haloCheckBox->OnClick([&](wiEventArgs args) { - if (light != nullptr) - { - light->noHalo = !args.bValue; - } - }); - haloCheckBox->SetEnabled(false); - haloCheckBox->SetTooltip("Visualize light source emission"); - lightWindow->AddWidget(haloCheckBox); + //haloCheckBox = new wiCheckBox("Visualizer: "); + //haloCheckBox->SetPos(XMFLOAT2(x, y += step)); + //haloCheckBox->OnClick([&](wiEventArgs args) { + // if (light != nullptr) + // { + // light->noHalo = !args.bValue; + // } + //}); + //haloCheckBox->SetEnabled(false); + //haloCheckBox->SetTooltip("Visualize light source emission"); + //lightWindow->AddWidget(haloCheckBox); - addLightButton = new wiButton("Add Light"); - addLightButton->SetPos(XMFLOAT2(x, y += step)); - addLightButton->SetSize(XMFLOAT2(150, 30)); - addLightButton->OnClick([&](wiEventArgs args) { - Light* light = new Light; - light->enerDis = XMFLOAT4(2, 60, XM_PIDIV4, 0); - light->color = XMFLOAT4(1, 1, 1, 1); - light->Translate(XMFLOAT3(0, 3, 0)); - light->SetType(Light::POINT); - wiRenderer::Add(light); - }); - addLightButton->SetTooltip("Add a light to the scene."); - lightWindow->AddWidget(addLightButton); + //addLightButton = new wiButton("Add Light"); + //addLightButton->SetPos(XMFLOAT2(x, y += step)); + //addLightButton->SetSize(XMFLOAT2(150, 30)); + //addLightButton->OnClick([&](wiEventArgs args) { + // Light* light = new Light; + // light->enerDis = XMFLOAT4(2, 60, XM_PIDIV4, 0); + // light->color = XMFLOAT4(1, 1, 1, 1); + // light->Translate(XMFLOAT3(0, 3, 0)); + // light->SetType(Light::POINT); + // wiRenderer::Add(light); + //}); + //addLightButton->SetTooltip("Add a light to the scene."); + //lightWindow->AddWidget(addLightButton); - colorPicker = new wiColorPicker(GUI, "Light Color"); - colorPicker->SetPos(XMFLOAT2(10, 30)); - colorPicker->RemoveWidgets(); - colorPicker->SetVisible(true); - colorPicker->SetEnabled(true); - colorPicker->OnColorChanged([&](wiEventArgs args) { - if(light!=nullptr) - light->color = XMFLOAT4(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f), 1); - }); - lightWindow->AddWidget(colorPicker); + //colorPicker = new wiColorPicker(GUI, "Light Color"); + //colorPicker->SetPos(XMFLOAT2(10, 30)); + //colorPicker->RemoveWidgets(); + //colorPicker->SetVisible(true); + //colorPicker->SetEnabled(true); + //colorPicker->OnColorChanged([&](wiEventArgs args) { + // if(light!=nullptr) + // light->color = XMFLOAT4(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f), 1); + //}); + //lightWindow->AddWidget(colorPicker); - typeSelectorComboBox = new wiComboBox("Type: "); - typeSelectorComboBox->SetPos(XMFLOAT2(x, y += step)); - typeSelectorComboBox->OnSelect([&](wiEventArgs args) { - if (light != nullptr && args.iValue >= 0) - { - light->SetType((Light::LightType)args.iValue); - SetLightType(light->GetType()); - biasSlider->SetValue(light->shadowBias); - } - }); - typeSelectorComboBox->SetEnabled(false); - typeSelectorComboBox->AddItem("Directional"); - typeSelectorComboBox->AddItem("Point"); - typeSelectorComboBox->AddItem("Spot"); - typeSelectorComboBox->AddItem("Sphere"); - typeSelectorComboBox->AddItem("Disc"); - typeSelectorComboBox->AddItem("Rectangle"); - typeSelectorComboBox->AddItem("Tube"); - typeSelectorComboBox->SetTooltip("Choose the light source type..."); - lightWindow->AddWidget(typeSelectorComboBox); + //typeSelectorComboBox = new wiComboBox("Type: "); + //typeSelectorComboBox->SetPos(XMFLOAT2(x, y += step)); + //typeSelectorComboBox->OnSelect([&](wiEventArgs args) { + // if (light != nullptr && args.iValue >= 0) + // { + // light->SetType((Light::LightType)args.iValue); + // SetLightType(light->GetType()); + // biasSlider->SetValue(light->shadowBias); + // } + //}); + //typeSelectorComboBox->SetEnabled(false); + //typeSelectorComboBox->AddItem("Directional"); + //typeSelectorComboBox->AddItem("Point"); + //typeSelectorComboBox->AddItem("Spot"); + //typeSelectorComboBox->AddItem("Sphere"); + //typeSelectorComboBox->AddItem("Disc"); + //typeSelectorComboBox->AddItem("Rectangle"); + //typeSelectorComboBox->AddItem("Tube"); + //typeSelectorComboBox->SetTooltip("Choose the light source type..."); + //lightWindow->AddWidget(typeSelectorComboBox); lightWindow->Translate(XMFLOAT3(30, 30, 0)); lightWindow->SetVisible(false); - SetLight(nullptr); + SetEntity(INVALID_ENTITY); } @@ -209,63 +210,65 @@ LightWindow::~LightWindow() SAFE_DELETE(lightWindow); } -void LightWindow::SetLight(Light* light) +void LightWindow::SetEntity(Entity entity) { - if (this->light == light) - return; + this->entity = entity; - this->light = light; - if (light != nullptr) - { - //lightWindow->SetEnabled(true); - energySlider->SetEnabled(true); - energySlider->SetValue(light->enerDis.x); - distanceSlider->SetValue(light->enerDis.y); - radiusSlider->SetValue(light->radius); - widthSlider->SetValue(light->width); - heightSlider->SetValue(light->height); - fovSlider->SetValue(light->enerDis.z); - biasSlider->SetEnabled(true); - biasSlider->SetValue(light->shadowBias); - shadowCheckBox->SetEnabled(true); - shadowCheckBox->SetCheck(light->shadow); - haloCheckBox->SetEnabled(true); - haloCheckBox->SetCheck(!light->noHalo); - volumetricsCheckBox->SetEnabled(true); - volumetricsCheckBox->SetCheck(light->volumetrics); - colorPicker->SetEnabled(true); - typeSelectorComboBox->SetEnabled(true); - typeSelectorComboBox->SetSelected((int)light->GetType()); - - SetLightType(light->GetType()); - } - else - { - distanceSlider->SetEnabled(false); - radiusSlider->SetEnabled(false); - widthSlider->SetEnabled(false); - heightSlider->SetEnabled(false); - fovSlider->SetEnabled(false); - biasSlider->SetEnabled(false); - shadowCheckBox->SetEnabled(false); - haloCheckBox->SetEnabled(false); - volumetricsCheckBox->SetEnabled(false); - energySlider->SetEnabled(false); - colorPicker->SetEnabled(false); - typeSelectorComboBox->SetEnabled(false); - //lightWindow->SetEnabled(false); - } + //if (this->light == light) + // return; + + //this->light = light; + //if (light != nullptr) + //{ + // //lightWindow->SetEnabled(true); + // energySlider->SetEnabled(true); + // energySlider->SetValue(light->enerDis.x); + // distanceSlider->SetValue(light->enerDis.y); + // radiusSlider->SetValue(light->radius); + // widthSlider->SetValue(light->width); + // heightSlider->SetValue(light->height); + // fovSlider->SetValue(light->enerDis.z); + // biasSlider->SetEnabled(true); + // biasSlider->SetValue(light->shadowBias); + // shadowCheckBox->SetEnabled(true); + // shadowCheckBox->SetCheck(light->shadow); + // haloCheckBox->SetEnabled(true); + // haloCheckBox->SetCheck(!light->noHalo); + // volumetricsCheckBox->SetEnabled(true); + // volumetricsCheckBox->SetCheck(light->volumetrics); + // colorPicker->SetEnabled(true); + // typeSelectorComboBox->SetEnabled(true); + // typeSelectorComboBox->SetSelected((int)light->GetType()); + // + // SetLightType(light->GetType()); + //} + //else + //{ + // distanceSlider->SetEnabled(false); + // radiusSlider->SetEnabled(false); + // widthSlider->SetEnabled(false); + // heightSlider->SetEnabled(false); + // fovSlider->SetEnabled(false); + // biasSlider->SetEnabled(false); + // shadowCheckBox->SetEnabled(false); + // haloCheckBox->SetEnabled(false); + // volumetricsCheckBox->SetEnabled(false); + // energySlider->SetEnabled(false); + // colorPicker->SetEnabled(false); + // typeSelectorComboBox->SetEnabled(false); + // //lightWindow->SetEnabled(false); + //} } -void LightWindow::SetLightType(Light::LightType type) +void LightWindow::SetLightType(LightComponent::LightType type) { - if (type == Light::DIRECTIONAL) + if (type == LightComponent::DIRECTIONAL) { distanceSlider->SetEnabled(false); fovSlider->SetEnabled(false); } else { - if (type == Light::SPHERE || type == Light::DISC || type == Light::RECTANGLE || type == Light::TUBE) + if (type == LightComponent::SPHERE || type == LightComponent::DISC || type == LightComponent::RECTANGLE || type == LightComponent::TUBE) { distanceSlider->SetEnabled(false); radiusSlider->SetEnabled(true); @@ -279,7 +282,7 @@ void LightWindow::SetLightType(Light::LightType type) radiusSlider->SetEnabled(false); widthSlider->SetEnabled(false); heightSlider->SetEnabled(false); - if (type == Light::SPOT) + if (type == LightComponent::SPOT) { fovSlider->SetEnabled(true); } diff --git a/Editor/LightWindow.h b/Editor/LightWindow.h index e4175a8d4..796e0aaed 100644 --- a/Editor/LightWindow.h +++ b/Editor/LightWindow.h @@ -1,11 +1,5 @@ #pragma once - -namespace wiSceneComponents -{ - struct Light; -} - class wiGUI; class wiWindow; class wiLabel; @@ -23,10 +17,10 @@ public: wiGUI* GUI; - void SetLight(wiSceneComponents::Light* light); - void SetLightType(wiSceneComponents::Light::LightType type); + wiECS::Entity entity; + void SetEntity(wiECS::Entity entity); - wiSceneComponents::Light* light; + void SetLightType(wiSceneSystem::LightComponent::LightType type); wiWindow* lightWindow; wiSlider* energySlider; diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index cb418b929..a12cea86f 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -6,14 +6,13 @@ using namespace std; using namespace wiGraphicsTypes; -using namespace wiSceneComponents; +using namespace wiECS; +using namespace wiSceneSystem; MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) { assert(GUI && "Invalid GUI!"); - material = nullptr; - float screenW = (float)wiRenderer::GetDevice()->GetScreenWidth(); float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight(); @@ -22,454 +21,454 @@ MaterialWindow::MaterialWindow(wiGUI* gui) : GUI(gui) materialWindow->SetEnabled(false); GUI->AddWidget(materialWindow); - materialNameField = new wiTextInputField("MaterialName"); - materialNameField->SetPos(XMFLOAT2(10, 30)); - materialNameField->SetSize(XMFLOAT2(300, 20)); - materialNameField->OnInputAccepted([&](wiEventArgs args) { - if (material != nullptr) - material->name = args.sValue; - }); - materialWindow->AddWidget(materialNameField); + //materialNameField = new wiTextInputField("MaterialName"); + //materialNameField->SetPos(XMFLOAT2(10, 30)); + //materialNameField->SetSize(XMFLOAT2(300, 20)); + //materialNameField->OnInputAccepted([&](wiEventArgs args) { + // if (material != nullptr) + // material->name = args.sValue; + //}); + //materialWindow->AddWidget(materialNameField); - float x = 540, y = 0; - float step = 35; + //float x = 540, y = 0; + //float step = 35; - waterCheckBox = new wiCheckBox("Water: "); - waterCheckBox->SetTooltip("Set material as special water material."); - waterCheckBox->SetPos(XMFLOAT2(570, y += step)); - waterCheckBox->OnClick([&](wiEventArgs args) { - if (material != nullptr) - material->water = args.bValue; - }); - materialWindow->AddWidget(waterCheckBox); + //waterCheckBox = new wiCheckBox("Water: "); + //waterCheckBox->SetTooltip("Set material as special water material."); + //waterCheckBox->SetPos(XMFLOAT2(570, y += step)); + //waterCheckBox->OnClick([&](wiEventArgs args) { + // if (material != nullptr) + // material->water = args.bValue; + //}); + //materialWindow->AddWidget(waterCheckBox); - planarReflCheckBox = new wiCheckBox("Planar Reflections: "); - planarReflCheckBox->SetTooltip("Enable planar reflections. The mesh should be a single plane for best results."); - planarReflCheckBox->SetPos(XMFLOAT2(570, y += step)); - planarReflCheckBox->OnClick([&](wiEventArgs args) { - if (material != nullptr) - material->planar_reflections = args.bValue; - }); - materialWindow->AddWidget(planarReflCheckBox); + //planarReflCheckBox = new wiCheckBox("Planar Reflections: "); + //planarReflCheckBox->SetTooltip("Enable planar reflections. The mesh should be a single plane for best results."); + //planarReflCheckBox->SetPos(XMFLOAT2(570, y += step)); + //planarReflCheckBox->OnClick([&](wiEventArgs args) { + // if (material != nullptr) + // material->planar_reflections = args.bValue; + //}); + //materialWindow->AddWidget(planarReflCheckBox); - shadowCasterCheckBox = new wiCheckBox("Cast Shadow: "); - shadowCasterCheckBox->SetTooltip("The subset will contribute to the scene shadows if enabled."); - shadowCasterCheckBox->SetPos(XMFLOAT2(570, y += step)); - shadowCasterCheckBox->OnClick([&](wiEventArgs args) { - if (material != nullptr) - material->cast_shadow = args.bValue; - }); - materialWindow->AddWidget(shadowCasterCheckBox); + //shadowCasterCheckBox = new wiCheckBox("Cast Shadow: "); + //shadowCasterCheckBox->SetTooltip("The subset will contribute to the scene shadows if enabled."); + //shadowCasterCheckBox->SetPos(XMFLOAT2(570, y += step)); + //shadowCasterCheckBox->OnClick([&](wiEventArgs args) { + // if (material != nullptr) + // material->cast_shadow = args.bValue; + //}); + //materialWindow->AddWidget(shadowCasterCheckBox); - normalMapSlider = new wiSlider(0, 4, 1, 4000, "Normalmap: "); - normalMapSlider->SetTooltip("How much the normal map should distort the face normals (bumpiness)."); - normalMapSlider->SetSize(XMFLOAT2(100, 30)); - normalMapSlider->SetPos(XMFLOAT2(x, y += step)); - normalMapSlider->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->normalMapStrength = args.fValue; - }); - materialWindow->AddWidget(normalMapSlider); + //normalMapSlider = new wiSlider(0, 4, 1, 4000, "Normalmap: "); + //normalMapSlider->SetTooltip("How much the normal map should distort the face normals (bumpiness)."); + //normalMapSlider->SetSize(XMFLOAT2(100, 30)); + //normalMapSlider->SetPos(XMFLOAT2(x, y += step)); + //normalMapSlider->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->normalMapStrength = args.fValue; + //}); + //materialWindow->AddWidget(normalMapSlider); - roughnessSlider = new wiSlider(0, 1, 0.5f, 1000, "Roughness: "); - roughnessSlider->SetTooltip("Adjust the surface roughness. Rough surfaces are less shiny, more matte."); - roughnessSlider->SetSize(XMFLOAT2(100, 30)); - roughnessSlider->SetPos(XMFLOAT2(x, y += step)); - roughnessSlider->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->roughness = args.fValue; - }); - materialWindow->AddWidget(roughnessSlider); + //roughnessSlider = new wiSlider(0, 1, 0.5f, 1000, "Roughness: "); + //roughnessSlider->SetTooltip("Adjust the surface roughness. Rough surfaces are less shiny, more matte."); + //roughnessSlider->SetSize(XMFLOAT2(100, 30)); + //roughnessSlider->SetPos(XMFLOAT2(x, y += step)); + //roughnessSlider->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->roughness = args.fValue; + //}); + //materialWindow->AddWidget(roughnessSlider); - reflectanceSlider = new wiSlider(0, 1, 0.5f, 1000, "Reflectance: "); - reflectanceSlider->SetTooltip("Adjust the overall surface reflectivity."); - reflectanceSlider->SetSize(XMFLOAT2(100, 30)); - reflectanceSlider->SetPos(XMFLOAT2(x, y += step)); - reflectanceSlider->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->reflectance = args.fValue; - }); - materialWindow->AddWidget(reflectanceSlider); + //reflectanceSlider = new wiSlider(0, 1, 0.5f, 1000, "Reflectance: "); + //reflectanceSlider->SetTooltip("Adjust the overall surface reflectivity."); + //reflectanceSlider->SetSize(XMFLOAT2(100, 30)); + //reflectanceSlider->SetPos(XMFLOAT2(x, y += step)); + //reflectanceSlider->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->reflectance = args.fValue; + //}); + //materialWindow->AddWidget(reflectanceSlider); - metalnessSlider = new wiSlider(0, 1, 0.0f, 1000, "Metalness: "); - metalnessSlider->SetTooltip("The more metal-like the surface is, the more the its color will contribute to the reflection color."); - metalnessSlider->SetSize(XMFLOAT2(100, 30)); - metalnessSlider->SetPos(XMFLOAT2(x, y += step)); - metalnessSlider->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->metalness = args.fValue; - }); - materialWindow->AddWidget(metalnessSlider); + //metalnessSlider = new wiSlider(0, 1, 0.0f, 1000, "Metalness: "); + //metalnessSlider->SetTooltip("The more metal-like the surface is, the more the its color will contribute to the reflection color."); + //metalnessSlider->SetSize(XMFLOAT2(100, 30)); + //metalnessSlider->SetPos(XMFLOAT2(x, y += step)); + //metalnessSlider->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->metalness = args.fValue; + //}); + //materialWindow->AddWidget(metalnessSlider); - alphaSlider = new wiSlider(0, 1, 1.0f, 1000, "Alpha: "); - alphaSlider->SetTooltip("Adjusts the overall transparency of the surface."); - alphaSlider->SetSize(XMFLOAT2(100, 30)); - alphaSlider->SetPos(XMFLOAT2(x, y += step)); - alphaSlider->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->alpha = args.fValue; - }); - materialWindow->AddWidget(alphaSlider); + //alphaSlider = new wiSlider(0, 1, 1.0f, 1000, "Alpha: "); + //alphaSlider->SetTooltip("Adjusts the overall transparency of the surface."); + //alphaSlider->SetSize(XMFLOAT2(100, 30)); + //alphaSlider->SetPos(XMFLOAT2(x, y += step)); + //alphaSlider->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->alpha = args.fValue; + //}); + //materialWindow->AddWidget(alphaSlider); - alphaRefSlider = new wiSlider(0, 1, 1.0f, 1000, "AlphaRef: "); - alphaRefSlider->SetTooltip("Adjust the alpha cutoff threshold. This disables some optimizations so performance can be affected."); - alphaRefSlider->SetSize(XMFLOAT2(100, 30)); - alphaRefSlider->SetPos(XMFLOAT2(x, y += step)); - alphaRefSlider->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->alphaRef = args.fValue; - }); - materialWindow->AddWidget(alphaRefSlider); + //alphaRefSlider = new wiSlider(0, 1, 1.0f, 1000, "AlphaRef: "); + //alphaRefSlider->SetTooltip("Adjust the alpha cutoff threshold. This disables some optimizations so performance can be affected."); + //alphaRefSlider->SetSize(XMFLOAT2(100, 30)); + //alphaRefSlider->SetPos(XMFLOAT2(x, y += step)); + //alphaRefSlider->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->alphaRef = args.fValue; + //}); + //materialWindow->AddWidget(alphaRefSlider); - refractionIndexSlider = new wiSlider(0, 1.0f, 0.02f, 1000, "Refraction Index: "); - refractionIndexSlider->SetTooltip("Adjust the IOR (index of refraction). It controls the amount of distortion of the scene visible through the transparent object."); - refractionIndexSlider->SetSize(XMFLOAT2(100, 30)); - refractionIndexSlider->SetPos(XMFLOAT2(x, y += step)); - refractionIndexSlider->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->refractionIndex = args.fValue; - }); - materialWindow->AddWidget(refractionIndexSlider); + //refractionIndexSlider = new wiSlider(0, 1.0f, 0.02f, 1000, "Refraction Index: "); + //refractionIndexSlider->SetTooltip("Adjust the IOR (index of refraction). It controls the amount of distortion of the scene visible through the transparent object."); + //refractionIndexSlider->SetSize(XMFLOAT2(100, 30)); + //refractionIndexSlider->SetPos(XMFLOAT2(x, y += step)); + //refractionIndexSlider->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->refractionIndex = args.fValue; + //}); + //materialWindow->AddWidget(refractionIndexSlider); - emissiveSlider = new wiSlider(0, 1, 0.0f, 1000, "Emissive: "); - emissiveSlider->SetTooltip("Adjust the light emission of the surface. The color of the light emitted is that of the color of the material."); - emissiveSlider->SetSize(XMFLOAT2(100, 30)); - emissiveSlider->SetPos(XMFLOAT2(x, y += step)); - emissiveSlider->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->emissive = args.fValue; - }); - materialWindow->AddWidget(emissiveSlider); + //emissiveSlider = new wiSlider(0, 1, 0.0f, 1000, "Emissive: "); + //emissiveSlider->SetTooltip("Adjust the light emission of the surface. The color of the light emitted is that of the color of the material."); + //emissiveSlider->SetSize(XMFLOAT2(100, 30)); + //emissiveSlider->SetPos(XMFLOAT2(x, y += step)); + //emissiveSlider->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->emissive = args.fValue; + //}); + //materialWindow->AddWidget(emissiveSlider); - sssSlider = new wiSlider(0, 1, 0.0f, 1000, "Subsurface Scattering: "); - sssSlider->SetTooltip("Adjust how much the light is scattered when entered inside the surface of the object. (SSS postprocess must be enabled)"); - sssSlider->SetSize(XMFLOAT2(100, 30)); - sssSlider->SetPos(XMFLOAT2(x, y += step)); - sssSlider->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->subsurfaceScattering = args.fValue; - }); - materialWindow->AddWidget(sssSlider); + //sssSlider = new wiSlider(0, 1, 0.0f, 1000, "Subsurface Scattering: "); + //sssSlider->SetTooltip("Adjust how much the light is scattered when entered inside the surface of the object. (SSS postprocess must be enabled)"); + //sssSlider->SetSize(XMFLOAT2(100, 30)); + //sssSlider->SetPos(XMFLOAT2(x, y += step)); + //sssSlider->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->subsurfaceScattering = args.fValue; + //}); + //materialWindow->AddWidget(sssSlider); - pomSlider = new wiSlider(0, 0.1f, 0.0f, 1000, "Parallax Occlusion Mapping: "); - pomSlider->SetTooltip("Adjust how much the bump map should affect the object (slow)."); - pomSlider->SetSize(XMFLOAT2(100, 30)); - pomSlider->SetPos(XMFLOAT2(x, y += step)); - pomSlider->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->parallaxOcclusionMapping = args.fValue; - }); - materialWindow->AddWidget(pomSlider); + //pomSlider = new wiSlider(0, 0.1f, 0.0f, 1000, "Parallax Occlusion Mapping: "); + //pomSlider->SetTooltip("Adjust how much the bump map should affect the object (slow)."); + //pomSlider->SetSize(XMFLOAT2(100, 30)); + //pomSlider->SetPos(XMFLOAT2(x, y += step)); + //pomSlider->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->parallaxOcclusionMapping = args.fValue; + //}); + //materialWindow->AddWidget(pomSlider); - movingTexSliderU = new wiSlider(-0.05f, 0.05f, 0, 1000, "Texcoord anim U: "); - movingTexSliderU->SetTooltip("Adjust the texture animation speed along the U direction in texture space."); - movingTexSliderU->SetSize(XMFLOAT2(100, 30)); - movingTexSliderU->SetPos(XMFLOAT2(x, y += step)); - movingTexSliderU->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->movingTex.x = args.fValue; - }); - materialWindow->AddWidget(movingTexSliderU); + //movingTexSliderU = new wiSlider(-0.05f, 0.05f, 0, 1000, "Texcoord anim U: "); + //movingTexSliderU->SetTooltip("Adjust the texture animation speed along the U direction in texture space."); + //movingTexSliderU->SetSize(XMFLOAT2(100, 30)); + //movingTexSliderU->SetPos(XMFLOAT2(x, y += step)); + //movingTexSliderU->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->movingTex.x = args.fValue; + //}); + //materialWindow->AddWidget(movingTexSliderU); - movingTexSliderV = new wiSlider(-0.05f, 0.05f, 0, 1000, "Texcoord anim V: "); - movingTexSliderV->SetTooltip("Adjust the texture animation speed along the V direction in texture space."); - movingTexSliderV->SetSize(XMFLOAT2(100, 30)); - movingTexSliderV->SetPos(XMFLOAT2(x, y += step)); - movingTexSliderV->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->movingTex.y = args.fValue; - }); - materialWindow->AddWidget(movingTexSliderV); + //movingTexSliderV = new wiSlider(-0.05f, 0.05f, 0, 1000, "Texcoord anim V: "); + //movingTexSliderV->SetTooltip("Adjust the texture animation speed along the V direction in texture space."); + //movingTexSliderV->SetSize(XMFLOAT2(100, 30)); + //movingTexSliderV->SetPos(XMFLOAT2(x, y += step)); + //movingTexSliderV->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->movingTex.y = args.fValue; + //}); + //materialWindow->AddWidget(movingTexSliderV); - texMulSliderX = new wiSlider(0.01f, 10.0f, 0, 1000, "Texture TileSize X: "); - texMulSliderX->SetTooltip("Adjust the texture mapping size."); - texMulSliderX->SetSize(XMFLOAT2(100, 30)); - texMulSliderX->SetPos(XMFLOAT2(x, y += step)); - texMulSliderX->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->texMulAdd.x = args.fValue; - }); - materialWindow->AddWidget(texMulSliderX); + //texMulSliderX = new wiSlider(0.01f, 10.0f, 0, 1000, "Texture TileSize X: "); + //texMulSliderX->SetTooltip("Adjust the texture mapping size."); + //texMulSliderX->SetSize(XMFLOAT2(100, 30)); + //texMulSliderX->SetPos(XMFLOAT2(x, y += step)); + //texMulSliderX->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->texMulAdd.x = args.fValue; + //}); + //materialWindow->AddWidget(texMulSliderX); - texMulSliderY = new wiSlider(0.01f, 10.0f, 0, 1000, "Texture TileSize Y: "); - texMulSliderY->SetTooltip("Adjust the texture mapping size."); - texMulSliderY->SetSize(XMFLOAT2(100, 30)); - texMulSliderY->SetPos(XMFLOAT2(x, y += step)); - texMulSliderY->OnSlide([&](wiEventArgs args) { - if (material != nullptr) - material->texMulAdd.y = args.fValue; - }); - materialWindow->AddWidget(texMulSliderY); + //texMulSliderY = new wiSlider(0.01f, 10.0f, 0, 1000, "Texture TileSize Y: "); + //texMulSliderY->SetTooltip("Adjust the texture mapping size."); + //texMulSliderY->SetSize(XMFLOAT2(100, 30)); + //texMulSliderY->SetPos(XMFLOAT2(x, y += step)); + //texMulSliderY->OnSlide([&](wiEventArgs args) { + // if (material != nullptr) + // material->texMulAdd.y = args.fValue; + //}); + //materialWindow->AddWidget(texMulSliderY); - colorPicker = new wiColorPicker(GUI, "Material Color"); - colorPicker->SetPos(XMFLOAT2(10, 400)); - colorPicker->RemoveWidgets(); - colorPicker->SetVisible(true); - colorPicker->SetEnabled(true); - colorPicker->OnColorChanged([&](wiEventArgs args) { - if (material != nullptr) - material->baseColor = XMFLOAT3(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f)); - }); - materialWindow->AddWidget(colorPicker); + //colorPicker = new wiColorPicker(GUI, "Material Color"); + //colorPicker->SetPos(XMFLOAT2(10, 400)); + //colorPicker->RemoveWidgets(); + //colorPicker->SetVisible(true); + //colorPicker->SetEnabled(true); + //colorPicker->OnColorChanged([&](wiEventArgs args) { + // if (material != nullptr) + // material->baseColor = XMFLOAT3(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f)); + //}); + //materialWindow->AddWidget(colorPicker); - blendModeComboBox = new wiComboBox("Blend mode: "); - blendModeComboBox->SetPos(XMFLOAT2(x, y += step)); - blendModeComboBox->SetSize(XMFLOAT2(100, 25)); - blendModeComboBox->OnSelect([&](wiEventArgs args) { - if (material != nullptr && args.iValue >= 0) - { - material->blendFlag = static_cast(args.iValue); - } - }); - blendModeComboBox->AddItem("Opaque"); - blendModeComboBox->AddItem("Alpha"); - blendModeComboBox->AddItem("Premultiplied"); - blendModeComboBox->AddItem("Additive"); - blendModeComboBox->SetEnabled(false); - blendModeComboBox->SetTooltip("Set the blend mode of the material."); - materialWindow->AddWidget(blendModeComboBox); + //blendModeComboBox = new wiComboBox("Blend mode: "); + //blendModeComboBox->SetPos(XMFLOAT2(x, y += step)); + //blendModeComboBox->SetSize(XMFLOAT2(100, 25)); + //blendModeComboBox->OnSelect([&](wiEventArgs args) { + // if (material != nullptr && args.iValue >= 0) + // { + // material->blendFlag = static_cast(args.iValue); + // } + //}); + //blendModeComboBox->AddItem("Opaque"); + //blendModeComboBox->AddItem("Alpha"); + //blendModeComboBox->AddItem("Premultiplied"); + //blendModeComboBox->AddItem("Additive"); + //blendModeComboBox->SetEnabled(false); + //blendModeComboBox->SetTooltip("Set the blend mode of the material."); + //materialWindow->AddWidget(blendModeComboBox); - shaderTypeComboBox = new wiComboBox("Custom Shader: "); - shaderTypeComboBox->SetPos(XMFLOAT2(x, y += step)); - shaderTypeComboBox->SetSize(XMFLOAT2(100, 25)); - shaderTypeComboBox->OnSelect([&](wiEventArgs args) { - if (material != nullptr) - { - if (args.iValue == 0) - { - material->customShader = nullptr; - } - else if (args.iValue > 0) - { - material->customShader = Material::customShaderPresets[args.iValue - 1]; - } - } - }); - shaderTypeComboBox->AddItem("None"); - for (auto& x : Material::customShaderPresets) - { - shaderTypeComboBox->AddItem(x->name); - } - shaderTypeComboBox->SetEnabled(false); - shaderTypeComboBox->SetTooltip("Set the custom shader of the material."); - materialWindow->AddWidget(shaderTypeComboBox); + //shaderTypeComboBox = new wiComboBox("Custom Shader: "); + //shaderTypeComboBox->SetPos(XMFLOAT2(x, y += step)); + //shaderTypeComboBox->SetSize(XMFLOAT2(100, 25)); + //shaderTypeComboBox->OnSelect([&](wiEventArgs args) { + // if (material != nullptr) + // { + // if (args.iValue == 0) + // { + // material->customShader = nullptr; + // } + // else if (args.iValue > 0) + // { + // material->customShader = Material::customShaderPresets[args.iValue - 1]; + // } + // } + //}); + //shaderTypeComboBox->AddItem("None"); + //for (auto& x : Material::customShaderPresets) + //{ + // shaderTypeComboBox->AddItem(x->name); + //} + //shaderTypeComboBox->SetEnabled(false); + //shaderTypeComboBox->SetTooltip("Set the custom shader of the material."); + //materialWindow->AddWidget(shaderTypeComboBox); - // Textures: + //// Textures: - x = 10; - y = 60; + //x = 10; + //y = 60; - texture_baseColor_Label = new wiLabel("BaseColorMap: "); - texture_baseColor_Label->SetPos(XMFLOAT2(x, y += step)); - texture_baseColor_Label->SetSize(XMFLOAT2(120, 20)); - materialWindow->AddWidget(texture_baseColor_Label); + //texture_baseColor_Label = new wiLabel("BaseColorMap: "); + //texture_baseColor_Label->SetPos(XMFLOAT2(x, y += step)); + //texture_baseColor_Label->SetSize(XMFLOAT2(120, 20)); + //materialWindow->AddWidget(texture_baseColor_Label); - texture_baseColor_Button = new wiButton("BaseColor"); - texture_baseColor_Button->SetText(""); - texture_baseColor_Button->SetTooltip("Load the basecolor texture. RGB: Albedo Base Color, A: Opacity"); - texture_baseColor_Button->SetPos(XMFLOAT2(x + 122, y)); - texture_baseColor_Button->SetSize(XMFLOAT2(260, 20)); - texture_baseColor_Button->OnClick([&](wiEventArgs args) { - if (material == nullptr) - return; + //texture_baseColor_Button = new wiButton("BaseColor"); + //texture_baseColor_Button->SetText(""); + //texture_baseColor_Button->SetTooltip("Load the basecolor texture. RGB: Albedo Base Color, A: Opacity"); + //texture_baseColor_Button->SetPos(XMFLOAT2(x + 122, y)); + //texture_baseColor_Button->SetSize(XMFLOAT2(260, 20)); + //texture_baseColor_Button->OnClick([&](wiEventArgs args) { + // if (material == nullptr) + // return; - if (material->texture != nullptr) - { - material->texture = nullptr; - material->textureName = ""; - texture_baseColor_Button->SetText(""); - } - else - { - char szFile[260]; + // if (material->texture != nullptr) + // { + // material->texture = nullptr; + // material->textureName = ""; + // texture_baseColor_Button->SetText(""); + // } + // else + // { + // char szFile[260]; - OPENFILENAMEA ofn; - ZeroMemory(&ofn, sizeof(ofn)); - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = nullptr; - ofn.lpstrFile = szFile; - // Set lpstrFile[0] to '\0' so that GetOpenFileName does not - // use the contents of szFile to initialize itself. - ofn.lpstrFile[0] = '\0'; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; - ofn.nFilterIndex = 1; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.Flags = 0; - if (GetSaveFileNameA(&ofn) == TRUE) { - string fileName = ofn.lpstrFile; - material->texture = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); - material->textureName = fileName; - texture_baseColor_Button->SetText(wiHelper::GetFileNameFromPath(material->textureName)); - } - } - }); - materialWindow->AddWidget(texture_baseColor_Button); + // OPENFILENAMEA ofn; + // ZeroMemory(&ofn, sizeof(ofn)); + // ofn.lStructSize = sizeof(ofn); + // ofn.hwndOwner = nullptr; + // ofn.lpstrFile = szFile; + // // Set lpstrFile[0] to '\0' so that GetOpenFileName does not + // // use the contents of szFile to initialize itself. + // ofn.lpstrFile[0] = '\0'; + // ofn.nMaxFile = sizeof(szFile); + // ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; + // ofn.nFilterIndex = 1; + // ofn.lpstrFileTitle = NULL; + // ofn.nMaxFileTitle = 0; + // ofn.lpstrInitialDir = NULL; + // ofn.Flags = 0; + // if (GetSaveFileNameA(&ofn) == TRUE) { + // string fileName = ofn.lpstrFile; + // material->texture = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + // material->textureName = fileName; + // texture_baseColor_Button->SetText(wiHelper::GetFileNameFromPath(material->textureName)); + // } + // } + //}); + //materialWindow->AddWidget(texture_baseColor_Button); - texture_normal_Label = new wiLabel("NormalMap: "); - texture_normal_Label->SetPos(XMFLOAT2(x, y += step)); - texture_normal_Label->SetSize(XMFLOAT2(120, 20)); - materialWindow->AddWidget(texture_normal_Label); + //texture_normal_Label = new wiLabel("NormalMap: "); + //texture_normal_Label->SetPos(XMFLOAT2(x, y += step)); + //texture_normal_Label->SetSize(XMFLOAT2(120, 20)); + //materialWindow->AddWidget(texture_normal_Label); - texture_normal_Button = new wiButton("NormalMap"); - texture_normal_Button->SetText(""); - texture_normal_Button->SetTooltip("Load the normalmap texture. RGB: Normal, A: Roughness"); - texture_normal_Button->SetPos(XMFLOAT2(x + 122, y)); - texture_normal_Button->SetSize(XMFLOAT2(260, 20)); - texture_normal_Button->OnClick([&](wiEventArgs args) { - if (material == nullptr) - return; + //texture_normal_Button = new wiButton("NormalMap"); + //texture_normal_Button->SetText(""); + //texture_normal_Button->SetTooltip("Load the normalmap texture. RGB: Normal, A: Roughness"); + //texture_normal_Button->SetPos(XMFLOAT2(x + 122, y)); + //texture_normal_Button->SetSize(XMFLOAT2(260, 20)); + //texture_normal_Button->OnClick([&](wiEventArgs args) { + // if (material == nullptr) + // return; - if (material->normalMap != nullptr) - { - material->normalMap = nullptr; - material->normalMapName = ""; - texture_normal_Button->SetText(""); - } - else - { - char szFile[260]; + // if (material->normalMap != nullptr) + // { + // material->normalMap = nullptr; + // material->normalMapName = ""; + // texture_normal_Button->SetText(""); + // } + // else + // { + // char szFile[260]; - OPENFILENAMEA ofn; - ZeroMemory(&ofn, sizeof(ofn)); - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = nullptr; - ofn.lpstrFile = szFile; - // Set lpstrFile[0] to '\0' so that GetOpenFileName does not - // use the contents of szFile to initialize itself. - ofn.lpstrFile[0] = '\0'; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; - ofn.nFilterIndex = 1; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.Flags = 0; - if (GetSaveFileNameA(&ofn) == TRUE) { - string fileName = ofn.lpstrFile; - material->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); - material->normalMapName = fileName; - texture_normal_Button->SetText(wiHelper::GetFileNameFromPath(material->normalMapName)); - } - } - }); - materialWindow->AddWidget(texture_normal_Button); + // OPENFILENAMEA ofn; + // ZeroMemory(&ofn, sizeof(ofn)); + // ofn.lStructSize = sizeof(ofn); + // ofn.hwndOwner = nullptr; + // ofn.lpstrFile = szFile; + // // Set lpstrFile[0] to '\0' so that GetOpenFileName does not + // // use the contents of szFile to initialize itself. + // ofn.lpstrFile[0] = '\0'; + // ofn.nMaxFile = sizeof(szFile); + // ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; + // ofn.nFilterIndex = 1; + // ofn.lpstrFileTitle = NULL; + // ofn.nMaxFileTitle = 0; + // ofn.lpstrInitialDir = NULL; + // ofn.Flags = 0; + // if (GetSaveFileNameA(&ofn) == TRUE) { + // string fileName = ofn.lpstrFile; + // material->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + // material->normalMapName = fileName; + // texture_normal_Button->SetText(wiHelper::GetFileNameFromPath(material->normalMapName)); + // } + // } + //}); + //materialWindow->AddWidget(texture_normal_Button); - texture_surface_Label = new wiLabel("SurfaceMap: "); - texture_surface_Label->SetPos(XMFLOAT2(x, y += step)); - texture_surface_Label->SetSize(XMFLOAT2(120, 20)); - materialWindow->AddWidget(texture_surface_Label); + //texture_surface_Label = new wiLabel("SurfaceMap: "); + //texture_surface_Label->SetPos(XMFLOAT2(x, y += step)); + //texture_surface_Label->SetSize(XMFLOAT2(120, 20)); + //materialWindow->AddWidget(texture_surface_Label); - texture_surface_Button = new wiButton("SurfaceMap"); - texture_surface_Button->SetText(""); - texture_surface_Button->SetTooltip("Load the surface property texture: R: Reflectance, G: Metalness, B: Emissive, A: SSS"); - texture_surface_Button->SetPos(XMFLOAT2(x + 122, y)); - texture_surface_Button->SetSize(XMFLOAT2(260, 20)); - texture_surface_Button->OnClick([&](wiEventArgs args) { - if (material == nullptr) - return; + //texture_surface_Button = new wiButton("SurfaceMap"); + //texture_surface_Button->SetText(""); + //texture_surface_Button->SetTooltip("Load the surface property texture: R: Reflectance, G: Metalness, B: Emissive, A: SSS"); + //texture_surface_Button->SetPos(XMFLOAT2(x + 122, y)); + //texture_surface_Button->SetSize(XMFLOAT2(260, 20)); + //texture_surface_Button->OnClick([&](wiEventArgs args) { + // if (material == nullptr) + // return; - if (material->surfaceMap != nullptr) - { - material->surfaceMap = nullptr; - material->surfaceMapName = ""; - texture_surface_Button->SetText(""); - } - else - { - char szFile[260]; + // if (material->surfaceMap != nullptr) + // { + // material->surfaceMap = nullptr; + // material->surfaceMapName = ""; + // texture_surface_Button->SetText(""); + // } + // else + // { + // char szFile[260]; - OPENFILENAMEA ofn; - ZeroMemory(&ofn, sizeof(ofn)); - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = nullptr; - ofn.lpstrFile = szFile; - // Set lpstrFile[0] to '\0' so that GetOpenFileName does not - // use the contents of szFile to initialize itself. - ofn.lpstrFile[0] = '\0'; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; - ofn.nFilterIndex = 1; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.Flags = 0; - if (GetSaveFileNameA(&ofn) == TRUE) { - string fileName = ofn.lpstrFile; - material->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); - material->surfaceMapName = fileName; - texture_surface_Button->SetText(wiHelper::GetFileNameFromPath(material->surfaceMapName)); - } - } - }); - materialWindow->AddWidget(texture_surface_Button); + // OPENFILENAMEA ofn; + // ZeroMemory(&ofn, sizeof(ofn)); + // ofn.lStructSize = sizeof(ofn); + // ofn.hwndOwner = nullptr; + // ofn.lpstrFile = szFile; + // // Set lpstrFile[0] to '\0' so that GetOpenFileName does not + // // use the contents of szFile to initialize itself. + // ofn.lpstrFile[0] = '\0'; + // ofn.nMaxFile = sizeof(szFile); + // ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; + // ofn.nFilterIndex = 1; + // ofn.lpstrFileTitle = NULL; + // ofn.nMaxFileTitle = 0; + // ofn.lpstrInitialDir = NULL; + // ofn.Flags = 0; + // if (GetSaveFileNameA(&ofn) == TRUE) { + // string fileName = ofn.lpstrFile; + // material->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + // material->surfaceMapName = fileName; + // texture_surface_Button->SetText(wiHelper::GetFileNameFromPath(material->surfaceMapName)); + // } + // } + //}); + //materialWindow->AddWidget(texture_surface_Button); - texture_displacement_Label = new wiLabel("DisplacementMap: "); - texture_displacement_Label->SetPos(XMFLOAT2(x, y += step)); - texture_displacement_Label->SetSize(XMFLOAT2(120, 20)); - materialWindow->AddWidget(texture_displacement_Label); + //texture_displacement_Label = new wiLabel("DisplacementMap: "); + //texture_displacement_Label->SetPos(XMFLOAT2(x, y += step)); + //texture_displacement_Label->SetSize(XMFLOAT2(120, 20)); + //materialWindow->AddWidget(texture_displacement_Label); - texture_displacement_Button = new wiButton("DisplacementMap"); - texture_displacement_Button->SetText(""); - texture_displacement_Button->SetTooltip("Load the displacement map texture."); - texture_displacement_Button->SetPos(XMFLOAT2(x + 122, y)); - texture_displacement_Button->SetSize(XMFLOAT2(260, 20)); - texture_displacement_Button->OnClick([&](wiEventArgs args) { - if (material == nullptr) - return; + //texture_displacement_Button = new wiButton("DisplacementMap"); + //texture_displacement_Button->SetText(""); + //texture_displacement_Button->SetTooltip("Load the displacement map texture."); + //texture_displacement_Button->SetPos(XMFLOAT2(x + 122, y)); + //texture_displacement_Button->SetSize(XMFLOAT2(260, 20)); + //texture_displacement_Button->OnClick([&](wiEventArgs args) { + // if (material == nullptr) + // return; - if (material->displacementMap != nullptr) - { - material->displacementMap = nullptr; - material->displacementMapName = ""; - texture_displacement_Button->SetText(""); - } - else - { - char szFile[260]; + // if (material->displacementMap != nullptr) + // { + // material->displacementMap = nullptr; + // material->displacementMapName = ""; + // texture_displacement_Button->SetText(""); + // } + // else + // { + // char szFile[260]; - OPENFILENAMEA ofn; - ZeroMemory(&ofn, sizeof(ofn)); - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = nullptr; - ofn.lpstrFile = szFile; - // Set lpstrFile[0] to '\0' so that GetOpenFileName does not - // use the contents of szFile to initialize itself. - ofn.lpstrFile[0] = '\0'; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; - ofn.nFilterIndex = 1; - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.Flags = 0; - if (GetSaveFileNameA(&ofn) == TRUE) { - string fileName = ofn.lpstrFile; - material->displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); - material->displacementMapName = fileName; - texture_displacement_Button->SetText(wiHelper::GetFileNameFromPath(material->displacementMapName)); - } - } - }); - materialWindow->AddWidget(texture_displacement_Button); + // OPENFILENAMEA ofn; + // ZeroMemory(&ofn, sizeof(ofn)); + // ofn.lStructSize = sizeof(ofn); + // ofn.hwndOwner = nullptr; + // ofn.lpstrFile = szFile; + // // Set lpstrFile[0] to '\0' so that GetOpenFileName does not + // // use the contents of szFile to initialize itself. + // ofn.lpstrFile[0] = '\0'; + // ofn.nMaxFile = sizeof(szFile); + // ofn.lpstrFilter = "Texture\0*.dds;*.png;*.jpg;*.tga;\0"; + // ofn.nFilterIndex = 1; + // ofn.lpstrFileTitle = NULL; + // ofn.nMaxFileTitle = 0; + // ofn.lpstrInitialDir = NULL; + // ofn.Flags = 0; + // if (GetSaveFileNameA(&ofn) == TRUE) { + // string fileName = ofn.lpstrFile; + // material->displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(fileName); + // material->displacementMapName = fileName; + // texture_displacement_Button->SetText(wiHelper::GetFileNameFromPath(material->displacementMapName)); + // } + // } + //}); + //materialWindow->AddWidget(texture_displacement_Button); materialWindow->Translate(XMFLOAT3(screenW - 760, 50, 0)); materialWindow->SetVisible(false); - SetMaterial(nullptr); + SetEntity(INVALID_ENTITY); } MaterialWindow::~MaterialWindow() @@ -481,55 +480,57 @@ MaterialWindow::~MaterialWindow() -void MaterialWindow::SetMaterial(Material* mat) +void MaterialWindow::SetEntity(Entity entity) { - if (this->material == mat) - return; + this->entity = entity; - if (material != nullptr) - { - material->SetUserStencilRef(0); - } + //if (this->material == mat) + // return; - material = mat; - if (material != nullptr) - { - materialNameField->SetValue(material->name); - waterCheckBox->SetCheck(material->water); - planarReflCheckBox->SetCheck(material->planar_reflections); - shadowCasterCheckBox->SetCheck(material->cast_shadow); - normalMapSlider->SetValue(material->normalMapStrength); - roughnessSlider->SetValue(material->roughness); - reflectanceSlider->SetValue(material->reflectance); - metalnessSlider->SetValue(material->metalness); - alphaSlider->SetValue(material->alpha); - refractionIndexSlider->SetValue(material->refractionIndex); - emissiveSlider->SetValue(material->emissive); - sssSlider->SetValue(material->subsurfaceScattering); - pomSlider->SetValue(material->parallaxOcclusionMapping); - movingTexSliderU->SetValue(material->movingTex.x); - movingTexSliderU->SetValue(material->movingTex.x); - texMulSliderX->SetValue(material->texMulAdd.x); - texMulSliderY->SetValue(material->texMulAdd.y); - alphaRefSlider->SetValue(material->alphaRef); - materialWindow->SetEnabled(true); - colorPicker->SetEnabled(true); - blendModeComboBox->SetSelected((int)material->blendFlag); + //if (material != nullptr) + //{ + // material->SetUserStencilRef(0); + //} - texture_baseColor_Button->SetText(wiHelper::GetFileNameFromPath(material->textureName)); - texture_normal_Button->SetText(wiHelper::GetFileNameFromPath(material->normalMapName)); - texture_surface_Button->SetText(wiHelper::GetFileNameFromPath(material->surfaceMapName)); - texture_displacement_Button->SetText(wiHelper::GetFileNameFromPath(material->displacementMapName)); - } - else - { - materialNameField->SetValue("No material selected"); - materialWindow->SetEnabled(false); - colorPicker->SetEnabled(false); + //material = mat; + //if (material != nullptr) + //{ + // materialNameField->SetValue(material->name); + // waterCheckBox->SetCheck(material->water); + // planarReflCheckBox->SetCheck(material->planar_reflections); + // shadowCasterCheckBox->SetCheck(material->cast_shadow); + // normalMapSlider->SetValue(material->normalMapStrength); + // roughnessSlider->SetValue(material->roughness); + // reflectanceSlider->SetValue(material->reflectance); + // metalnessSlider->SetValue(material->metalness); + // alphaSlider->SetValue(material->alpha); + // refractionIndexSlider->SetValue(material->refractionIndex); + // emissiveSlider->SetValue(material->emissive); + // sssSlider->SetValue(material->subsurfaceScattering); + // pomSlider->SetValue(material->parallaxOcclusionMapping); + // movingTexSliderU->SetValue(material->movingTex.x); + // movingTexSliderU->SetValue(material->movingTex.x); + // texMulSliderX->SetValue(material->texMulAdd.x); + // texMulSliderY->SetValue(material->texMulAdd.y); + // alphaRefSlider->SetValue(material->alphaRef); + // materialWindow->SetEnabled(true); + // colorPicker->SetEnabled(true); + // blendModeComboBox->SetSelected((int)material->blendFlag); - texture_baseColor_Button->SetText(""); - texture_normal_Button->SetText(""); - texture_surface_Button->SetText(""); - texture_displacement_Button->SetText(""); - } + // texture_baseColor_Button->SetText(wiHelper::GetFileNameFromPath(material->textureName)); + // texture_normal_Button->SetText(wiHelper::GetFileNameFromPath(material->normalMapName)); + // texture_surface_Button->SetText(wiHelper::GetFileNameFromPath(material->surfaceMapName)); + // texture_displacement_Button->SetText(wiHelper::GetFileNameFromPath(material->displacementMapName)); + //} + //else + //{ + // materialNameField->SetValue("No material selected"); + // materialWindow->SetEnabled(false); + // colorPicker->SetEnabled(false); + + // texture_baseColor_Button->SetText(""); + // texture_normal_Button->SetText(""); + // texture_surface_Button->SetText(""); + // texture_displacement_Button->SetText(""); + //} } diff --git a/Editor/MaterialWindow.h b/Editor/MaterialWindow.h index 7225a06d6..71d86bc44 100644 --- a/Editor/MaterialWindow.h +++ b/Editor/MaterialWindow.h @@ -1,10 +1,5 @@ #pragma once -namespace wiSceneComponents -{ - struct Material; -} - class wiGUI; class wiWindow; class wiLabel; @@ -21,12 +16,11 @@ public: MaterialWindow(wiGUI* gui); ~MaterialWindow(); - void SetMaterial(wiSceneComponents::Material* mat); + wiECS::Entity entity; + void SetEntity(wiECS::Entity entity); wiGUI* GUI; - wiSceneComponents::Material* material; - wiWindow* materialWindow; wiTextInputField* materialNameField; wiCheckBox* waterCheckBox; diff --git a/Editor/MeshWindow.cpp b/Editor/MeshWindow.cpp index ce20d12d0..5b9c3f4a6 100644 --- a/Editor/MeshWindow.cpp +++ b/Editor/MeshWindow.cpp @@ -4,7 +4,8 @@ #include using namespace std; -using namespace wiSceneComponents; +using namespace wiECS; +using namespace wiSceneSystem; MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) { @@ -30,128 +31,128 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) y += 160; - doubleSidedCheckBox = new wiCheckBox("Double Sided: "); - doubleSidedCheckBox->SetTooltip("If enabled, the inside of the mesh will be visible."); - doubleSidedCheckBox->SetPos(XMFLOAT2(x, y += step)); - doubleSidedCheckBox->OnClick([&](wiEventArgs args) { - if (mesh != nullptr) - { - mesh->doubleSided = args.bValue; - } - }); - meshWindow->AddWidget(doubleSidedCheckBox); + //doubleSidedCheckBox = new wiCheckBox("Double Sided: "); + //doubleSidedCheckBox->SetTooltip("If enabled, the inside of the mesh will be visible."); + //doubleSidedCheckBox->SetPos(XMFLOAT2(x, y += step)); + //doubleSidedCheckBox->OnClick([&](wiEventArgs args) { + // if (mesh != nullptr) + // { + // mesh->doubleSided = args.bValue; + // } + //}); + //meshWindow->AddWidget(doubleSidedCheckBox); - massSlider = new wiSlider(0, 5000, 0, 100000, "Mass: "); - massSlider->SetTooltip("Set the mass amount for the physics engine."); - massSlider->SetSize(XMFLOAT2(100, 30)); - massSlider->SetPos(XMFLOAT2(x, y += step)); - massSlider->OnSlide([&](wiEventArgs args) { - if (mesh != nullptr) - { - mesh->mass = args.fValue; - } - }); - meshWindow->AddWidget(massSlider); + //massSlider = new wiSlider(0, 5000, 0, 100000, "Mass: "); + //massSlider->SetTooltip("Set the mass amount for the physics engine."); + //massSlider->SetSize(XMFLOAT2(100, 30)); + //massSlider->SetPos(XMFLOAT2(x, y += step)); + //massSlider->OnSlide([&](wiEventArgs args) { + // if (mesh != nullptr) + // { + // mesh->mass = args.fValue; + // } + //}); + //meshWindow->AddWidget(massSlider); - frictionSlider = new wiSlider(0, 5000, 0, 100000, "Friction: "); - frictionSlider->SetTooltip("Set the friction amount for the physics engine."); - frictionSlider->SetSize(XMFLOAT2(100, 30)); - frictionSlider->SetPos(XMFLOAT2(x, y += step)); - frictionSlider->OnSlide([&](wiEventArgs args) { - if (mesh != nullptr) - { - mesh->friction = args.fValue; - } - }); - meshWindow->AddWidget(frictionSlider); + //frictionSlider = new wiSlider(0, 5000, 0, 100000, "Friction: "); + //frictionSlider->SetTooltip("Set the friction amount for the physics engine."); + //frictionSlider->SetSize(XMFLOAT2(100, 30)); + //frictionSlider->SetPos(XMFLOAT2(x, y += step)); + //frictionSlider->OnSlide([&](wiEventArgs args) { + // if (mesh != nullptr) + // { + // mesh->friction = args.fValue; + // } + //}); + //meshWindow->AddWidget(frictionSlider); - impostorCreateButton = new wiButton("Create Impostor"); - impostorCreateButton->SetTooltip("Create an impostor image of the mesh. The mesh will be replaced by this image when far away, to render faster."); - impostorCreateButton->SetSize(XMFLOAT2(240, 30)); - impostorCreateButton->SetPos(XMFLOAT2(x - 50, y += step)); - impostorCreateButton->OnClick([&](wiEventArgs args) { - if (mesh != nullptr) - { - wiRenderer::CreateImpostor(mesh, GRAPHICSTHREAD_IMMEDIATE); - } - }); - meshWindow->AddWidget(impostorCreateButton); + //impostorCreateButton = new wiButton("Create Impostor"); + //impostorCreateButton->SetTooltip("Create an impostor image of the mesh. The mesh will be replaced by this image when far away, to render faster."); + //impostorCreateButton->SetSize(XMFLOAT2(240, 30)); + //impostorCreateButton->SetPos(XMFLOAT2(x - 50, y += step)); + //impostorCreateButton->OnClick([&](wiEventArgs args) { + // if (mesh != nullptr) + // { + // wiRenderer::CreateImpostor(mesh, GRAPHICSTHREAD_IMMEDIATE); + // } + //}); + //meshWindow->AddWidget(impostorCreateButton); - impostorDistanceSlider = new wiSlider(0, 1000, 100, 10000, "Impostor Distance: "); - impostorDistanceSlider->SetTooltip("Assign the distance where the mesh geometry should be switched to the impostor image."); - impostorDistanceSlider->SetSize(XMFLOAT2(100, 30)); - impostorDistanceSlider->SetPos(XMFLOAT2(x, y += step)); - impostorDistanceSlider->OnSlide([&](wiEventArgs args) { - if (mesh != nullptr) - { - mesh->impostorDistance = args.fValue; - } - }); - meshWindow->AddWidget(impostorDistanceSlider); + //impostorDistanceSlider = new wiSlider(0, 1000, 100, 10000, "Impostor Distance: "); + //impostorDistanceSlider->SetTooltip("Assign the distance where the mesh geometry should be switched to the impostor image."); + //impostorDistanceSlider->SetSize(XMFLOAT2(100, 30)); + //impostorDistanceSlider->SetPos(XMFLOAT2(x, y += step)); + //impostorDistanceSlider->OnSlide([&](wiEventArgs args) { + // if (mesh != nullptr) + // { + // mesh->impostorDistance = args.fValue; + // } + //}); + //meshWindow->AddWidget(impostorDistanceSlider); - tessellationFactorSlider = new wiSlider(0, 16, 0, 10000, "Tessellation Factor: "); - tessellationFactorSlider->SetTooltip("Set the dynamic tessellation amount. Tessellation should be enabled in the Renderer window and your GPU must support it!"); - tessellationFactorSlider->SetSize(XMFLOAT2(100, 30)); - tessellationFactorSlider->SetPos(XMFLOAT2(x, y += step)); - tessellationFactorSlider->OnSlide([&](wiEventArgs args) { - if (mesh != nullptr) - { - mesh->tessellationFactor = args.fValue; - } - }); - meshWindow->AddWidget(tessellationFactorSlider); + //tessellationFactorSlider = new wiSlider(0, 16, 0, 10000, "Tessellation Factor: "); + //tessellationFactorSlider->SetTooltip("Set the dynamic tessellation amount. Tessellation should be enabled in the Renderer window and your GPU must support it!"); + //tessellationFactorSlider->SetSize(XMFLOAT2(100, 30)); + //tessellationFactorSlider->SetPos(XMFLOAT2(x, y += step)); + //tessellationFactorSlider->OnSlide([&](wiEventArgs args) { + // if (mesh != nullptr) + // { + // mesh->tessellationFactor = args.fValue; + // } + //}); + //meshWindow->AddWidget(tessellationFactorSlider); - flipCullingButton = new wiButton("Flip Culling"); - flipCullingButton->SetTooltip("Flip faces to reverse triangle culling order."); - flipCullingButton->SetSize(XMFLOAT2(240, 30)); - flipCullingButton->SetPos(XMFLOAT2(x - 50, y += step)); - flipCullingButton->OnClick([&](wiEventArgs args) { - if (mesh != nullptr) - { - mesh->FlipCulling(); - SetMesh(mesh); - } - }); - meshWindow->AddWidget(flipCullingButton); + //flipCullingButton = new wiButton("Flip Culling"); + //flipCullingButton->SetTooltip("Flip faces to reverse triangle culling order."); + //flipCullingButton->SetSize(XMFLOAT2(240, 30)); + //flipCullingButton->SetPos(XMFLOAT2(x - 50, y += step)); + //flipCullingButton->OnClick([&](wiEventArgs args) { + // if (mesh != nullptr) + // { + // mesh->FlipCulling(); + // SetMesh(mesh); + // } + //}); + //meshWindow->AddWidget(flipCullingButton); - flipNormalsButton = new wiButton("Flip Normals"); - flipNormalsButton->SetTooltip("Flip surface normals."); - flipNormalsButton->SetSize(XMFLOAT2(240, 30)); - flipNormalsButton->SetPos(XMFLOAT2(x - 50, y += step)); - flipNormalsButton->OnClick([&](wiEventArgs args) { - if (mesh != nullptr) - { - mesh->FlipNormals(); - SetMesh(mesh); - } - }); - meshWindow->AddWidget(flipNormalsButton); + //flipNormalsButton = new wiButton("Flip Normals"); + //flipNormalsButton->SetTooltip("Flip surface normals."); + //flipNormalsButton->SetSize(XMFLOAT2(240, 30)); + //flipNormalsButton->SetPos(XMFLOAT2(x - 50, y += step)); + //flipNormalsButton->OnClick([&](wiEventArgs args) { + // if (mesh != nullptr) + // { + // mesh->FlipNormals(); + // SetMesh(mesh); + // } + //}); + //meshWindow->AddWidget(flipNormalsButton); - computeNormalsSmoothButton = new wiButton("Compute Normals [SMOOTH]"); - computeNormalsSmoothButton->SetTooltip("Compute surface normals of the mesh. Resulting normals will be unique per vertex."); - computeNormalsSmoothButton->SetSize(XMFLOAT2(240, 30)); - computeNormalsSmoothButton->SetPos(XMFLOAT2(x - 50, y += step)); - computeNormalsSmoothButton->OnClick([&](wiEventArgs args) { - if (mesh != nullptr) - { - mesh->ComputeNormals(true); - SetMesh(mesh); - } - }); - meshWindow->AddWidget(computeNormalsSmoothButton); + //computeNormalsSmoothButton = new wiButton("Compute Normals [SMOOTH]"); + //computeNormalsSmoothButton->SetTooltip("Compute surface normals of the mesh. Resulting normals will be unique per vertex."); + //computeNormalsSmoothButton->SetSize(XMFLOAT2(240, 30)); + //computeNormalsSmoothButton->SetPos(XMFLOAT2(x - 50, y += step)); + //computeNormalsSmoothButton->OnClick([&](wiEventArgs args) { + // if (mesh != nullptr) + // { + // mesh->ComputeNormals(true); + // SetMesh(mesh); + // } + //}); + //meshWindow->AddWidget(computeNormalsSmoothButton); - computeNormalsHardButton = new wiButton("Compute Normals [HARD]"); - computeNormalsHardButton->SetTooltip("Compute surface normals of the mesh. Resulting normals will be unique per face."); - computeNormalsHardButton->SetSize(XMFLOAT2(240, 30)); - computeNormalsHardButton->SetPos(XMFLOAT2(x - 50, y += step)); - computeNormalsHardButton->OnClick([&](wiEventArgs args) { - if (mesh != nullptr) - { - mesh->ComputeNormals(false); - SetMesh(mesh); - } - }); - meshWindow->AddWidget(computeNormalsHardButton); + //computeNormalsHardButton = new wiButton("Compute Normals [HARD]"); + //computeNormalsHardButton->SetTooltip("Compute surface normals of the mesh. Resulting normals will be unique per face."); + //computeNormalsHardButton->SetSize(XMFLOAT2(240, 30)); + //computeNormalsHardButton->SetPos(XMFLOAT2(x - 50, y += step)); + //computeNormalsHardButton->OnClick([&](wiEventArgs args) { + // if (mesh != nullptr) + // { + // mesh->ComputeNormals(false); + // SetMesh(mesh); + // } + //}); + //meshWindow->AddWidget(computeNormalsHardButton); @@ -159,7 +160,7 @@ MeshWindow::MeshWindow(wiGUI* gui) : GUI(gui) meshWindow->Translate(XMFLOAT3(1300, 520, 0)); meshWindow->SetVisible(false); - SetMesh(nullptr); + SetEntity(INVALID_ENTITY); } @@ -170,28 +171,30 @@ MeshWindow::~MeshWindow() SAFE_DELETE(meshWindow); } -void MeshWindow::SetMesh(Mesh* mesh) +void MeshWindow::SetEntity(Entity entity) { - this->mesh = mesh; - if (mesh != nullptr) - { - stringstream ss(""); - ss << "Mesh name: " << mesh->name << endl; - ss << "Vertex count: " << mesh->vertices_POS.size() << endl; - ss << "Index count: " << mesh->indices.size() << endl; - ss << "Subset count: " << mesh->subsets.size() << endl; - meshInfoLabel->SetText(ss.str()); + this->entity = entity; - doubleSidedCheckBox->SetCheck(mesh->doubleSided); - massSlider->SetValue(mesh->mass); - frictionSlider->SetValue(mesh->friction); - impostorDistanceSlider->SetValue(mesh->impostorDistance); - tessellationFactorSlider->SetValue(mesh->getTessellationFactor()); - meshWindow->SetEnabled(true); - } - else - { - meshInfoLabel->SetText("Select a mesh..."); - meshWindow->SetEnabled(false); - } + //this->mesh = mesh; + //if (mesh != nullptr) + //{ + // stringstream ss(""); + // ss << "Mesh name: " << mesh->name << endl; + // ss << "Vertex count: " << mesh->vertices_POS.size() << endl; + // ss << "Index count: " << mesh->indices.size() << endl; + // ss << "Subset count: " << mesh->subsets.size() << endl; + // meshInfoLabel->SetText(ss.str()); + + // doubleSidedCheckBox->SetCheck(mesh->doubleSided); + // massSlider->SetValue(mesh->mass); + // frictionSlider->SetValue(mesh->friction); + // impostorDistanceSlider->SetValue(mesh->impostorDistance); + // tessellationFactorSlider->SetValue(mesh->getTessellationFactor()); + // meshWindow->SetEnabled(true); + //} + //else + //{ + // meshInfoLabel->SetText("Select a mesh..."); + // meshWindow->SetEnabled(false); + //} } diff --git a/Editor/MeshWindow.h b/Editor/MeshWindow.h index a34c3cb96..46b579042 100644 --- a/Editor/MeshWindow.h +++ b/Editor/MeshWindow.h @@ -1,10 +1,5 @@ #pragma once -namespace wiSceneComponents -{ - struct Mesh; -} - class wiGUI; class wiWindow; class wiLabel; @@ -20,9 +15,8 @@ public: wiGUI* GUI; - void SetMesh(wiSceneComponents::Mesh* mesh); - - wiSceneComponents::Mesh* mesh; + wiECS::Entity entity; + void SetEntity(wiECS::Entity entity); wiWindow* meshWindow; wiLabel* meshInfoLabel; diff --git a/Editor/ModelImporter.h b/Editor/ModelImporter.h index 3f7e2fd91..111a19307 100644 --- a/Editor/ModelImporter.h +++ b/Editor/ModelImporter.h @@ -1,12 +1,9 @@ #pragma once +#include "wiECS.h" + #include -namespace wiSceneComponents -{ - struct Model; -} - -wiSceneComponents::Model* ImportModel_WIO(const std::string& fileName); -wiSceneComponents::Model* ImportModel_OBJ(const std::string& fileName); -wiSceneComponents::Model* ImportModel_GLTF(const std::string& fileName); +wiECS::Entity ImportModel_WIO(const std::string& fileName); +wiECS::Entity ImportModel_OBJ(const std::string& fileName); +wiECS::Entity ImportModel_GLTF(const std::string& fileName); diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index 4cdd06a8c..66b650438 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -13,7 +13,8 @@ using namespace std; using namespace wiGraphicsTypes; -using namespace wiSceneComponents; +using namespace wiSceneSystem; +using namespace wiECS; // Transform the data from glTF space to engine-space: @@ -220,303 +221,303 @@ void RegisterTexture2D(tinygltf::Image *image) } } -void LoadNode(tinygltf::Node* node, tinygltf::Node* parent, Model* model, tinygltf::Model& gltfModel, vector& meshArray, vector& armatureArray) -{ - if (node == nullptr) - { - return; - } +//void LoadNode(tinygltf::Node* node, tinygltf::Node* parent, Model* model, tinygltf::Model& gltfModel, vector& meshArray, vector& armatureArray) +//{ +// if (node == nullptr) +// { +// return; +// } +// +// Transform transform; +// if (!node->scale.empty()) +// { +// transform.scale_rest = XMFLOAT3((float)node->scale[0], (float)node->scale[1], (float)node->scale[2]); +// } +// if (!node->rotation.empty()) +// { +// transform.rotation_rest = XMFLOAT4((float)node->rotation[0], (float)node->rotation[1], (float)node->rotation[2], (float)node->rotation[3]); +// } +// if (!node->translation.empty()) +// { +// transform.translation_rest = XMFLOAT3((float)node->translation[0], (float)node->translation[1], (float)node->translation[2]); +// } +// transform.UpdateTransform(); +// +// if (parent != nullptr) +// { +// transform.parentName = parent->name; +// } +// +// if(node->mesh >= 0) +// { +// Object* object = new Object(node->name); +// model->objects.insert(object); +// +// *(Transform*)object = transform; +// +// if (node->mesh < meshArray.size()) +// { +// object->mesh = meshArray[node->mesh]; +// object->meshName = object->mesh->name; +// } +// else +// { +// auto& x = gltfModel.meshes[node->mesh]; +// Mesh* mesh = new Mesh(x.name); +// meshArray.push_back(mesh); +// +// object->mesh = mesh; +// object->meshName = mesh->name; +// +// mesh->renderable = true; +// +// XMFLOAT3 min = XMFLOAT3(FLT_MAX, FLT_MAX, FLT_MAX); +// XMFLOAT3 max = XMFLOAT3(-FLT_MAX, -FLT_MAX, -FLT_MAX); +// +// for (auto& prim : x.primitives) +// { +// assert(prim.indices >= 0); +// +// // Fill indices: +// const tinygltf::Accessor& accessor = gltfModel.accessors[prim.indices]; +// const tinygltf::BufferView& bufferView = gltfModel.bufferViews[accessor.bufferView]; +// const tinygltf::Buffer& buffer = gltfModel.buffers[bufferView.buffer]; +// +// int stride = accessor.ByteStride(bufferView); +// size_t count = accessor.count; +// +// size_t offset = mesh->indices.size(); +// mesh->indices.resize(offset + count); +// +// const unsigned char* data = buffer.data.data() + accessor.byteOffset + bufferView.byteOffset; +// +// if (stride == 1) +// { +// for (size_t i = 0; i < count; i += 3) +// { +// mesh->indices[offset + i + 0] = data[i + 0]; +// mesh->indices[offset + i + 1] = data[i + 1]; +// mesh->indices[offset + i + 2] = data[i + 2]; +// } +// } +// else if (stride == 2) +// { +// for (size_t i = 0; i < count; i += 3) +// { +// mesh->indices[offset + i + 0] = ((uint16_t*)data)[i + 0]; +// mesh->indices[offset + i + 1] = ((uint16_t*)data)[i + 1]; +// mesh->indices[offset + i + 2] = ((uint16_t*)data)[i + 2]; +// } +// } +// else if (stride == 4) +// { +// for (size_t i = 0; i < count; i += 3) +// { +// mesh->indices[offset + i + 0] = ((uint32_t*)data)[i + 0]; +// mesh->indices[offset + i + 1] = ((uint32_t*)data)[i + 1]; +// mesh->indices[offset + i + 2] = ((uint32_t*)data)[i + 2]; +// } +// } +// else +// { +// assert(0 && "unsupported index stride!"); +// } +// +// +// // Create mesh subset: +// MeshSubset subset; +// +// if (prim.material >= 0) +// { +// const string& mat_name = gltfModel.materials[prim.material].name; +// auto& found_mat = model->materials.find(mat_name); +// if (found_mat != model->materials.end()) +// { +// subset.material = found_mat->second; +// } +// } +// +// if (subset.material == nullptr) +// { +// subset.material = new Material("gltfLoader_defaultMat"); +// } +// +// mesh->subsets.push_back(subset); +// mesh->materialNames.push_back(subset.material->name); +// } +// +// bool hasBoneWeights = false; +// bool hasBoneIndices = false; +// +// int matIndex = -1; +// for (auto& prim : x.primitives) +// { +// matIndex++; +// size_t offset = mesh->vertices_FULL.size(); +// +// for (auto& attr : prim.attributes) +// { +// const string& attr_name = attr.first; +// int attr_data = attr.second; +// +// const tinygltf::Accessor& accessor = gltfModel.accessors[attr_data]; +// const tinygltf::BufferView& bufferView = gltfModel.bufferViews[accessor.bufferView]; +// const tinygltf::Buffer& buffer = gltfModel.buffers[bufferView.buffer]; +// +// int stride = accessor.ByteStride(bufferView); +// size_t count = accessor.count; +// +// if (mesh->vertices_FULL.size() == offset) +// { +// mesh->vertices_FULL.resize(offset + count); +// } +// +// const unsigned char* data = buffer.data.data() + accessor.byteOffset + bufferView.byteOffset; +// +// if (!attr_name.compare("POSITION")) +// { +// assert(stride == 12); +// for (size_t i = 0; i < count; ++i) +// { +// XMFLOAT3 pos = ((XMFLOAT3*)data)[i]; +// +// if (transform_to_LH) +// { +// pos.z = -pos.z; +// } +// +// mesh->vertices_FULL[offset + i].pos = XMFLOAT4(pos.x, pos.y, pos.z, 0); +// +// min = wiMath::Min(min, pos); +// max = wiMath::Max(max, pos); +// } +// } +// else if (!attr_name.compare("NORMAL")) +// { +// assert(stride == 12); +// for (size_t i = 0; i < count; ++i) +// { +// const XMFLOAT3& nor = ((XMFLOAT3*)data)[i]; +// +// mesh->vertices_FULL[offset + i].nor.x = nor.x; +// mesh->vertices_FULL[offset + i].nor.y = nor.y; +// mesh->vertices_FULL[offset + i].nor.z = -nor.z; +// } +// } +// else if (!attr_name.compare("TEXCOORD_0")) +// { +// assert(stride == 8); +// for (size_t i = 0; i < count; ++i) +// { +// const XMFLOAT2& tex = ((XMFLOAT2*)data)[i]; +// +// mesh->vertices_FULL[offset + i].tex.x = tex.x; +// mesh->vertices_FULL[offset + i].tex.y = tex.y; +// mesh->vertices_FULL[offset + i].tex.z = (float)matIndex /*prim.material*/; +// } +// } +// else if (!attr_name.compare("JOINTS_0")) +// { +// if (stride == 4) +// { +// hasBoneIndices = true; +// struct JointTmp +// { +// uint8_t ind[4]; +// }; +// +// for (size_t i = 0; i < count; ++i) +// { +// const JointTmp& joint = ((JointTmp*)data)[i]; +// +// mesh->vertices_FULL[offset + i].ind.x = (float)joint.ind[0]; +// mesh->vertices_FULL[offset + i].ind.y = (float)joint.ind[1]; +// mesh->vertices_FULL[offset + i].ind.z = (float)joint.ind[2]; +// mesh->vertices_FULL[offset + i].ind.w = (float)joint.ind[3]; +// } +// } +// else if (stride == 8) +// { +// hasBoneIndices = true; +// struct JointTmp +// { +// uint16_t ind[4]; +// }; +// +// for (size_t i = 0; i < count; ++i) +// { +// const JointTmp& joint = ((JointTmp*)data)[i]; +// +// mesh->vertices_FULL[offset + i].ind.x = (float)joint.ind[0]; +// mesh->vertices_FULL[offset + i].ind.y = (float)joint.ind[1]; +// mesh->vertices_FULL[offset + i].ind.z = (float)joint.ind[2]; +// mesh->vertices_FULL[offset + i].ind.w = (float)joint.ind[3]; +// } +// } +// else +// { +// assert(0); +// } +// } +// else if (!attr_name.compare("WEIGHTS_0")) +// { +// hasBoneWeights = true; +// assert(stride == 16); +// for (size_t i = 0; i < count; ++i) +// { +// mesh->vertices_FULL[offset + i].wei = ((XMFLOAT4*)data)[i]; +// } +// } +// +// } +// +// } +// +// mesh->aabb.create(min, max); +// +// model->meshes.insert(make_pair(mesh->name, mesh)); +// +// +// if (!armatureArray.empty() && hasBoneIndices && hasBoneWeights) +// { +// mesh->armature = armatureArray[0]; // How to resolve? +// mesh->armatureName = mesh->armature->name; +// } +// +// } +// } +// +// if (node->camera >= 0) +// { +// Camera* camera = new Camera; +// camera->SetUp((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800); +// model->cameras.push_back(camera); +// +// *(Transform*)camera = transform; +// +// camera->name = gltfModel.cameras[node->camera].name; +// if (camera->name.empty()) +// { +// static int camID = 0; +// stringstream ss(""); +// ss << "cam" << camID++; +// camera->name = ss.str(); +// } +// node->name = camera->name; +// +// camera->UpdateProps(); +// } +// +// if (!node->children.empty()) +// { +// for (int child : node->children) +// { +// LoadNode(&gltfModel.nodes[child], node, model, gltfModel, meshArray, armatureArray); +// } +// } +//} - Transform transform; - if (!node->scale.empty()) - { - transform.scale_rest = XMFLOAT3((float)node->scale[0], (float)node->scale[1], (float)node->scale[2]); - } - if (!node->rotation.empty()) - { - transform.rotation_rest = XMFLOAT4((float)node->rotation[0], (float)node->rotation[1], (float)node->rotation[2], (float)node->rotation[3]); - } - if (!node->translation.empty()) - { - transform.translation_rest = XMFLOAT3((float)node->translation[0], (float)node->translation[1], (float)node->translation[2]); - } - transform.UpdateTransform(); - - if (parent != nullptr) - { - transform.parentName = parent->name; - } - - if(node->mesh >= 0) - { - Object* object = new Object(node->name); - model->objects.insert(object); - - *(Transform*)object = transform; - - if (node->mesh < meshArray.size()) - { - object->mesh = meshArray[node->mesh]; - object->meshName = object->mesh->name; - } - else - { - auto& x = gltfModel.meshes[node->mesh]; - Mesh* mesh = new Mesh(x.name); - meshArray.push_back(mesh); - - object->mesh = mesh; - object->meshName = mesh->name; - - mesh->renderable = true; - - XMFLOAT3 min = XMFLOAT3(FLT_MAX, FLT_MAX, FLT_MAX); - XMFLOAT3 max = XMFLOAT3(-FLT_MAX, -FLT_MAX, -FLT_MAX); - - for (auto& prim : x.primitives) - { - assert(prim.indices >= 0); - - // Fill indices: - const tinygltf::Accessor& accessor = gltfModel.accessors[prim.indices]; - const tinygltf::BufferView& bufferView = gltfModel.bufferViews[accessor.bufferView]; - const tinygltf::Buffer& buffer = gltfModel.buffers[bufferView.buffer]; - - int stride = accessor.ByteStride(bufferView); - size_t count = accessor.count; - - size_t offset = mesh->indices.size(); - mesh->indices.resize(offset + count); - - const unsigned char* data = buffer.data.data() + accessor.byteOffset + bufferView.byteOffset; - - if (stride == 1) - { - for (size_t i = 0; i < count; i += 3) - { - mesh->indices[offset + i + 0] = data[i + 0]; - mesh->indices[offset + i + 1] = data[i + 1]; - mesh->indices[offset + i + 2] = data[i + 2]; - } - } - else if (stride == 2) - { - for (size_t i = 0; i < count; i += 3) - { - mesh->indices[offset + i + 0] = ((uint16_t*)data)[i + 0]; - mesh->indices[offset + i + 1] = ((uint16_t*)data)[i + 1]; - mesh->indices[offset + i + 2] = ((uint16_t*)data)[i + 2]; - } - } - else if (stride == 4) - { - for (size_t i = 0; i < count; i += 3) - { - mesh->indices[offset + i + 0] = ((uint32_t*)data)[i + 0]; - mesh->indices[offset + i + 1] = ((uint32_t*)data)[i + 1]; - mesh->indices[offset + i + 2] = ((uint32_t*)data)[i + 2]; - } - } - else - { - assert(0 && "unsupported index stride!"); - } - - - // Create mesh subset: - MeshSubset subset; - - if (prim.material >= 0) - { - const string& mat_name = gltfModel.materials[prim.material].name; - auto& found_mat = model->materials.find(mat_name); - if (found_mat != model->materials.end()) - { - subset.material = found_mat->second; - } - } - - if (subset.material == nullptr) - { - subset.material = new Material("gltfLoader_defaultMat"); - } - - mesh->subsets.push_back(subset); - mesh->materialNames.push_back(subset.material->name); - } - - bool hasBoneWeights = false; - bool hasBoneIndices = false; - - int matIndex = -1; - for (auto& prim : x.primitives) - { - matIndex++; - size_t offset = mesh->vertices_FULL.size(); - - for (auto& attr : prim.attributes) - { - const string& attr_name = attr.first; - int attr_data = attr.second; - - const tinygltf::Accessor& accessor = gltfModel.accessors[attr_data]; - const tinygltf::BufferView& bufferView = gltfModel.bufferViews[accessor.bufferView]; - const tinygltf::Buffer& buffer = gltfModel.buffers[bufferView.buffer]; - - int stride = accessor.ByteStride(bufferView); - size_t count = accessor.count; - - if (mesh->vertices_FULL.size() == offset) - { - mesh->vertices_FULL.resize(offset + count); - } - - const unsigned char* data = buffer.data.data() + accessor.byteOffset + bufferView.byteOffset; - - if (!attr_name.compare("POSITION")) - { - assert(stride == 12); - for (size_t i = 0; i < count; ++i) - { - XMFLOAT3 pos = ((XMFLOAT3*)data)[i]; - - if (transform_to_LH) - { - pos.z = -pos.z; - } - - mesh->vertices_FULL[offset + i].pos = XMFLOAT4(pos.x, pos.y, pos.z, 0); - - min = wiMath::Min(min, pos); - max = wiMath::Max(max, pos); - } - } - else if (!attr_name.compare("NORMAL")) - { - assert(stride == 12); - for (size_t i = 0; i < count; ++i) - { - const XMFLOAT3& nor = ((XMFLOAT3*)data)[i]; - - mesh->vertices_FULL[offset + i].nor.x = nor.x; - mesh->vertices_FULL[offset + i].nor.y = nor.y; - mesh->vertices_FULL[offset + i].nor.z = -nor.z; - } - } - else if (!attr_name.compare("TEXCOORD_0")) - { - assert(stride == 8); - for (size_t i = 0; i < count; ++i) - { - const XMFLOAT2& tex = ((XMFLOAT2*)data)[i]; - - mesh->vertices_FULL[offset + i].tex.x = tex.x; - mesh->vertices_FULL[offset + i].tex.y = tex.y; - mesh->vertices_FULL[offset + i].tex.z = (float)matIndex /*prim.material*/; - } - } - else if (!attr_name.compare("JOINTS_0")) - { - if (stride == 4) - { - hasBoneIndices = true; - struct JointTmp - { - uint8_t ind[4]; - }; - - for (size_t i = 0; i < count; ++i) - { - const JointTmp& joint = ((JointTmp*)data)[i]; - - mesh->vertices_FULL[offset + i].ind.x = (float)joint.ind[0]; - mesh->vertices_FULL[offset + i].ind.y = (float)joint.ind[1]; - mesh->vertices_FULL[offset + i].ind.z = (float)joint.ind[2]; - mesh->vertices_FULL[offset + i].ind.w = (float)joint.ind[3]; - } - } - else if (stride == 8) - { - hasBoneIndices = true; - struct JointTmp - { - uint16_t ind[4]; - }; - - for (size_t i = 0; i < count; ++i) - { - const JointTmp& joint = ((JointTmp*)data)[i]; - - mesh->vertices_FULL[offset + i].ind.x = (float)joint.ind[0]; - mesh->vertices_FULL[offset + i].ind.y = (float)joint.ind[1]; - mesh->vertices_FULL[offset + i].ind.z = (float)joint.ind[2]; - mesh->vertices_FULL[offset + i].ind.w = (float)joint.ind[3]; - } - } - else - { - assert(0); - } - } - else if (!attr_name.compare("WEIGHTS_0")) - { - hasBoneWeights = true; - assert(stride == 16); - for (size_t i = 0; i < count; ++i) - { - mesh->vertices_FULL[offset + i].wei = ((XMFLOAT4*)data)[i]; - } - } - - } - - } - - mesh->aabb.create(min, max); - - model->meshes.insert(make_pair(mesh->name, mesh)); - - - if (!armatureArray.empty() && hasBoneIndices && hasBoneWeights) - { - mesh->armature = armatureArray[0]; // How to resolve? - mesh->armatureName = mesh->armature->name; - } - - } - } - - if (node->camera >= 0) - { - Camera* camera = new Camera; - camera->SetUp((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800); - model->cameras.push_back(camera); - - *(Transform*)camera = transform; - - camera->name = gltfModel.cameras[node->camera].name; - if (camera->name.empty()) - { - static int camID = 0; - stringstream ss(""); - ss << "cam" << camID++; - camera->name = ss.str(); - } - node->name = camera->name; - - camera->UpdateProps(); - } - - if (!node->children.empty()) - { - for (int child : node->children) - { - LoadNode(&gltfModel.nodes[child], node, model, gltfModel, meshArray, armatureArray); - } - } -} - -Model* ImportModel_GLTF(const std::string& fileName) +Entity ImportModel_GLTF(const std::string& fileName) { string directory, name; wiHelper::SplitPath(fileName, directory, name); @@ -524,10 +525,6 @@ Model* ImportModel_GLTF(const std::string& fileName) wiHelper::RemoveExtensionFromFileName(name); - vector armatureArray; - vector meshArray; - - tinygltf::Model gltfModel; tinygltf::TinyGLTF loader; std::string err; @@ -547,493 +544,499 @@ Model* ImportModel_GLTF(const std::string& fileName) } if (!ret) { wiHelper::messageBox(err, "GLTF error!"); - return nullptr; + return INVALID_ENTITY; } - Model* model = new Model; - model->name = name; - - for (auto& x : gltfModel.materials) - { - Material* material = new Material(x.name); - model->materials.insert(make_pair(material->name, material)); - - material->baseColor = XMFLOAT3(1, 1, 1); - material->roughness = 1.0f; - material->metalness = 1.0f; - material->reflectance = 0.02f; - material->emissive = 0; - - auto& baseColorTexture = x.values.find("baseColorTexture"); - auto& metallicRoughnessTexture = x.values.find("metallicRoughnessTexture"); - auto& normalTexture = x.additionalValues.find("normalTexture"); - auto& emissiveTexture = x.additionalValues.find("emissiveTexture"); - auto& occlusionTexture = x.additionalValues.find("occlusionTexture"); - - auto& baseColorFactor = x.values.find("baseColorFactor"); - auto& roughnessFactor = x.values.find("roughnessFactor"); - auto& metallicFactor = x.values.find("metallicFactor"); - auto& emissiveFactor = x.additionalValues.find("emissiveFactor"); - auto& alphaCutoff = x.additionalValues.find("alphaCutoff"); - - if (baseColorTexture != x.values.end()) - { - auto& tex = gltfModel.textures[baseColorTexture->second.TextureIndex()]; - auto& img = gltfModel.images[tex.source]; - RegisterTexture2D(&img); - material->textureName = img.name; - } - else if(!gltfModel.images.empty()) - { - // For some reason, we don't have diffuse texture, but have other textures - // I have a problem, because one model viewer displays textures on a model which has no basecolor set in its material... - // This is probably not how it should be (todo) - RegisterTexture2D(&gltfModel.images[0]); - material->textureName = gltfModel.images[0].name; - } - - tinygltf::Image* img_nor = nullptr; - tinygltf::Image* img_met_rough = nullptr; - tinygltf::Image* img_emissive = nullptr; - - if (normalTexture != x.additionalValues.end()) - { - auto& tex = gltfModel.textures[normalTexture->second.TextureIndex()]; - img_nor = &gltfModel.images[tex.source]; - } - if (metallicRoughnessTexture != x.values.end()) - { - auto& tex = gltfModel.textures[metallicRoughnessTexture->second.TextureIndex()]; - img_met_rough = &gltfModel.images[tex.source]; - } - if (emissiveTexture != x.additionalValues.end()) - { - auto& tex = gltfModel.textures[emissiveTexture->second.TextureIndex()]; - img_emissive = &gltfModel.images[tex.source]; - } - - // Now we will begin interleaving texture data to match engine layout: - - if (img_nor != nullptr) - { - uint32_t* data32_roughness = nullptr; - if (img_met_rough != nullptr && img_met_rough->width == img_nor->width && img_met_rough->height == img_nor->height) - { - data32_roughness = (uint32_t*)img_met_rough->image.data(); - } - else if (img_met_rough != nullptr) - { - wiBackLog::post("[gltf] Warning: there is a normalmap and roughness texture, but not the same size! Roughness will not be baked in!"); - } - - // Convert normal map: - uint32_t* data32 = (uint32_t*)img_nor->image.data(); - for (int i = 0; i < img_nor->width * img_nor->height; ++i) - { - uint32_t pixel = data32[i]; - float r = ((pixel >> 0) & 255) / 255.0f; - float g = ((pixel >> 8) & 255) / 255.0f; - float b = ((pixel >> 16) & 255) / 255.0f; - float a = ((pixel >> 24) & 255) / 255.0f; - - // swap normal y direction: - g = 1 - g; - - // reset roughness: - a = 1; - - if (data32_roughness != nullptr) - { - // add roughness from texture (G): - a = ((data32_roughness[i] >> 8) & 255) / 255.0f; - a = max(1.0f / 255.0f, a); // disallow 0 roughness (but is it really a good idea to do it here???) - } - - uint32_t rgba8 = 0; - rgba8 |= (uint32_t)(r * 255.0f) << 0; - rgba8 |= (uint32_t)(g * 255.0f) << 8; - rgba8 |= (uint32_t)(b * 255.0f) << 16; - rgba8 |= (uint32_t)(a * 255.0f) << 24; - - data32[i] = rgba8; - } - - RegisterTexture2D(img_nor); - material->normalMapName = img_nor->name; - } - - if (img_met_rough != nullptr) - { - uint32_t* data32_emissive = nullptr; - if (img_emissive != nullptr && img_emissive->width == img_met_rough->width && img_emissive->height == img_met_rough->height) - { - data32_emissive = (uint32_t*)img_emissive->image.data(); - } - - uint32_t* data32 = (uint32_t*)img_met_rough->image.data(); - for (int i = 0; i < img_met_rough->width * img_met_rough->height; ++i) - { - uint32_t pixel = data32[i]; - float r = ((pixel >> 0) & 255) / 255.0f; - float g = ((pixel >> 8) & 255) / 255.0f; - float b = ((pixel >> 16) & 255) / 255.0f; - float a = ((pixel >> 24) & 255) / 255.0f; - - float reflectance = 1; - float metalness = b; - float emissive = 0; - float sss = 1; - - if (data32_emissive != nullptr) - { - // add emissive from texture (R): - // (Currently only supporting single channel emissive) - emissive = ((data32_emissive[i] >> 0) & 255) / 255.0f; - } - - uint32_t rgba8 = 0; - rgba8 |= (uint32_t)(reflectance * 255.0f) << 0; - rgba8 |= (uint32_t)(metalness * 255.0f) << 8; - rgba8 |= (uint32_t)(emissive * 255.0f) << 16; - rgba8 |= (uint32_t)(sss * 255.0f) << 24; - - data32[i] = rgba8; - } - - RegisterTexture2D(img_met_rough); - material->surfaceMapName = img_met_rough->name; - } - else if (img_emissive != nullptr) - { - // No metalness texture, just emissive... - uint32_t* data32 = (uint32_t*)img_emissive->image.data(); - - if (data32 != nullptr) - { - for (int i = 0; i < img_emissive->width * img_emissive->height; ++i) - { - uint32_t pixel = data32[i]; - float r = ((pixel >> 0) & 255) / 255.0f; - float g = ((pixel >> 8) & 255) / 255.0f; - float b = ((pixel >> 16) & 255) / 255.0f; - float a = ((pixel >> 24) & 255) / 255.0f; - - float reflectance = 1; - float metalness = 1; - float emissive = r; - float sss = 1; - - uint32_t rgba8 = 0; - rgba8 |= (uint32_t)(reflectance * 255.0f) << 0; - rgba8 |= (uint32_t)(metalness * 255.0f) << 8; - rgba8 |= (uint32_t)(emissive * 255.0f) << 16; - rgba8 |= (uint32_t)(sss * 255.0f) << 24; - - data32[i] = rgba8; - } - - RegisterTexture2D(img_emissive); - material->surfaceMapName = img_emissive->name; - } - } - - // Retrieve textures by name: - if (!material->textureName.empty()) - material->texture = (Texture2D*)wiResourceManager::GetGlobal()->add(material->textureName); - if (!material->normalMapName.empty()) - material->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->normalMapName); - if (!material->surfaceMapName.empty()) - material->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->surfaceMapName); - - if (baseColorFactor != x.values.end()) - { - material->baseColor.x = static_cast(baseColorFactor->second.ColorFactor()[0]); - material->baseColor.y = static_cast(baseColorFactor->second.ColorFactor()[1]); - material->baseColor.z = static_cast(baseColorFactor->second.ColorFactor()[2]); - } - if (roughnessFactor != x.values.end()) - { - material->roughness = static_cast(roughnessFactor->second.Factor()); - } - if (metallicFactor != x.values.end()) - { - material->metalness = static_cast(metallicFactor->second.Factor()); - } - if (emissiveFactor != x.additionalValues.end()) - { - material->emissive = static_cast(emissiveFactor->second.ColorFactor()[0]); - } - if (alphaCutoff != x.additionalValues.end()) - { - material->alphaRef = 1 - static_cast(alphaCutoff->second.Factor()); - } - - } - - for(auto& skin : gltfModel.skins) - { - Armature* armature = new Armature(skin.name); - model->armatures.insert(armature); - - armatureArray.push_back(armature); - - const tinygltf::Node& skeleton_node = gltfModel.nodes[skin.skeleton]; - - const size_t jointCount = skin.joints.size(); - - armature->boneCollection.resize(jointCount); - - // Create bone collection: - for (size_t i = 0; i < jointCount; ++i) - { - int jointIndex = skin.joints[i]; - const tinygltf::Node& joint_node = gltfModel.nodes[jointIndex]; - - Bone* bone = new Bone(joint_node.name); - if (bone->name.empty()) - { - // GLTF might not contain bone names... - stringstream ss(""); - ss << "Bone_" << i; - bone->name = ss.str(); - } - - armature->boneCollection[i] = bone; - - if (!joint_node.scale.empty()) - { - bone->scale_rest = XMFLOAT3((float)joint_node.scale[0], (float)joint_node.scale[1], (float)joint_node.scale[2]); - } - if (!joint_node.rotation.empty()) - { - bone->rotation_rest = XMFLOAT4((float)joint_node.rotation[0], (float)joint_node.rotation[1], (float)joint_node.rotation[2], (float)joint_node.rotation[3]); - } - if (!joint_node.translation.empty()) - { - bone->translation_rest = XMFLOAT3((float)joint_node.translation[0], (float)joint_node.translation[1], (float)joint_node.translation[2]); - } - - XMVECTOR s = XMLoadFloat3(&bone->scale_rest); - XMVECTOR r = XMLoadFloat4(&bone->rotation_rest); - XMVECTOR t = XMLoadFloat3(&bone->translation_rest); - XMMATRIX w = - XMMatrixScalingFromVector(s)* - XMMatrixRotationQuaternion(r)* - XMMatrixTranslationFromVector(t) - ; - XMStoreFloat4x4(&bone->world_rest, w); - } - - // Create bone name hierarchy: - for (size_t i = 0; i < jointCount; ++i) - { - int jointIndex = skin.joints[i]; - const tinygltf::Node& joint_node = gltfModel.nodes[jointIndex]; - - for (int childJointIndex : joint_node.children) - { - for (size_t j = 0; j < jointCount; ++j) - { - if (skin.joints[j] == childJointIndex) - { - armature->boneCollection[j]->parentName = armature->boneCollection[i]->name; - break; - } - } - } - } - - if (transform_to_LH) - { - XMStoreFloat4x4(&armature->skinningRemap, XMMatrixScaling(1, 1, -1)); - } - - // Final hierarchy and extra matrices created here: - armature->CreateFamily(); - - } - - const tinygltf::Scene &scene = gltfModel.scenes[gltfModel.defaultScene]; - for (size_t i = 0; i < scene.nodes.size(); i++) - { - LoadNode(&gltfModel.nodes[scene.nodes[i]], nullptr, model, gltfModel, meshArray, armatureArray); - } - - int animID = 0; - for (auto& anim : gltfModel.animations) - { - if (armatureArray.empty()) - { - break; - } - Armature* armature = armatureArray[0]; - - for (Bone* bone : armature->boneCollection) - { - bone->actionFrames.push_back(ActionFrames()); - } - - Action action; - action.name = anim.name; - if (action.name.empty()) - { - stringstream ss(""); - ss << "Action_" << animID++; - action.name = ss.str(); - } - - for (auto& channel : anim.channels) - { - const tinygltf::Node& target_node = gltfModel.nodes[channel.target_node]; - const tinygltf::AnimationSampler& sam = anim.samplers[channel.sampler]; - - Bone* bone = nullptr; - - // Search for the armature + bone this animation belongs to: - { - const auto& skin = gltfModel.skins[0]; - - const size_t jointCount = skin.joints.size(); - assert(armature->boneCollection.size() == jointCount); - - for (size_t i = 0; i < jointCount; ++i) - { - int jointIndex = skin.joints[i]; - - if (jointIndex == channel.target_node) - { - bone = armature->boneCollection[i]; - break; - } - } - } - - if (bone == nullptr) - { - assert(0 && "Corresponding bone not found!"); - continue; - } - - - vector keyframes; - - // AnimationSampler input = keyframe times - { - const tinygltf::Accessor& accessor = gltfModel.accessors[sam.input]; - const tinygltf::BufferView& bufferView = gltfModel.bufferViews[accessor.bufferView]; - const tinygltf::Buffer& buffer = gltfModel.buffers[bufferView.buffer]; - - assert(accessor.componentType == TINYGLTF_COMPONENT_TYPE_FLOAT); - - int stride = accessor.ByteStride(bufferView); - size_t count = accessor.count; - - keyframes.resize(count); - - const unsigned char* data = buffer.data.data() + accessor.byteOffset + bufferView.byteOffset; - - int firstFrame = INT_MAX; - - assert(stride == 4); - for (size_t i = 0; i < count; ++i) - { - keyframes[i].frameI = (int)(((float*)data)[i] * 60); // !!! converting from time-base to frame-based !!! - - action.frameCount = max(action.frameCount, keyframes[i].frameI); - firstFrame = min(firstFrame, keyframes[i].frameI); - } - - // Cut out the empty part of the animation at the beginning: - firstFrame = min(firstFrame, action.frameCount); - for (size_t i = 0; i < count; ++i) - { - keyframes[i].frameI -= firstFrame; - } - action.frameCount -= firstFrame; - - } - - // AnimationSampler output = keyframe data - { - const tinygltf::Accessor& accessor = gltfModel.accessors[sam.output]; - const tinygltf::BufferView& bufferView = gltfModel.bufferViews[accessor.bufferView]; - const tinygltf::Buffer& buffer = gltfModel.buffers[bufferView.buffer]; - - int stride = accessor.ByteStride(bufferView); - size_t count = accessor.count; - - // Unfortunately, GLTF stores absolute values for animation nodes, but the engine needs relative - // Absolute = animation * rest (so the rest matrix is baked into animation, this can't be blended like we do now) - // Relative = animation (so we can blend all animation tracks however we want, then post multiply with the rest matrix after blending) - const XMMATRIX invRest = XMMatrixInverse(nullptr, XMLoadFloat4x4(&bone->world_rest)); - - const unsigned char* data = buffer.data.data() + accessor.byteOffset + bufferView.byteOffset; - - if (!channel.target_path.compare("scale")) - { - assert(stride == sizeof(XMFLOAT3)); - for (size_t i = 0; i < count; ++i) - { - const XMFLOAT3& sca = ((XMFLOAT3*)data)[i]; - //keyframes[i].data = XMFLOAT4(sca.x, sca.y, sca.z, 0); - - // Remove rest matrix from animation track: - XMMATRIX mat = XMMatrixScalingFromVector(XMLoadFloat3(&sca)); - mat = mat * invRest; - XMVECTOR s, r, t; - XMMatrixDecompose(&s, &r, &t, mat); - XMStoreFloat4(&keyframes[i].data, s); - } - bone->actionFrames.back().keyframesSca.insert(bone->actionFrames.back().keyframesSca.end(), keyframes.begin(), keyframes.end()); - } - else if (!channel.target_path.compare("rotation")) - { - assert(stride == sizeof(XMFLOAT4)); - for (size_t i = 0; i < count; ++i) - { - const XMFLOAT4& rot = ((XMFLOAT4*)data)[i]; - //keyframes[i].data = rot; - - // Remove rest matrix from animation track: - XMMATRIX mat = XMMatrixRotationQuaternion(XMLoadFloat4(&rot)); - mat = mat * invRest; - XMVECTOR s, r, t; - XMMatrixDecompose(&s, &r, &t, mat); - XMStoreFloat4(&keyframes[i].data, r); - } - bone->actionFrames.back().keyframesRot.insert(bone->actionFrames.back().keyframesRot.end(), keyframes.begin(), keyframes.end()); - } - else if (!channel.target_path.compare("translation")) - { - assert(stride == sizeof(XMFLOAT3)); - for (size_t i = 0; i < count; ++i) - { - const XMFLOAT3& tra = ((XMFLOAT3*)data)[i]; - //keyframes[i].data = XMFLOAT4(tra.x, tra.y, tra.z, 1); - - // Remove rest matrix from animation track: - XMMATRIX mat = XMMatrixTranslationFromVector(XMLoadFloat3(&tra)); - mat = mat * invRest; - XMVECTOR s, r, t; - XMMatrixDecompose(&s, &r, &t, mat); - XMStoreFloat4(&keyframes[i].data, t); - } - bone->actionFrames.back().keyframesPos.insert(bone->actionFrames.back().keyframesPos.end(), keyframes.begin(), keyframes.end()); - } - else - { - assert(0); - } - } - - - } - - armature->actions.push_back(action); - - } - - model->FinishLoading(); - - return model; + + return INVALID_ENTITY; + + //vector armatureArray; + //vector meshArray; + + //Model* model = new Model; + //model->name = name; + + //for (auto& x : gltfModel.materials) + //{ + // Material* material = new Material(x.name); + // model->materials.insert(make_pair(material->name, material)); + + // material->baseColor = XMFLOAT3(1, 1, 1); + // material->roughness = 1.0f; + // material->metalness = 1.0f; + // material->reflectance = 0.02f; + // material->emissive = 0; + + // auto& baseColorTexture = x.values.find("baseColorTexture"); + // auto& metallicRoughnessTexture = x.values.find("metallicRoughnessTexture"); + // auto& normalTexture = x.additionalValues.find("normalTexture"); + // auto& emissiveTexture = x.additionalValues.find("emissiveTexture"); + // auto& occlusionTexture = x.additionalValues.find("occlusionTexture"); + + // auto& baseColorFactor = x.values.find("baseColorFactor"); + // auto& roughnessFactor = x.values.find("roughnessFactor"); + // auto& metallicFactor = x.values.find("metallicFactor"); + // auto& emissiveFactor = x.additionalValues.find("emissiveFactor"); + // auto& alphaCutoff = x.additionalValues.find("alphaCutoff"); + + // if (baseColorTexture != x.values.end()) + // { + // auto& tex = gltfModel.textures[baseColorTexture->second.TextureIndex()]; + // auto& img = gltfModel.images[tex.source]; + // RegisterTexture2D(&img); + // material->textureName = img.name; + // } + // else if(!gltfModel.images.empty()) + // { + // // For some reason, we don't have diffuse texture, but have other textures + // // I have a problem, because one model viewer displays textures on a model which has no basecolor set in its material... + // // This is probably not how it should be (todo) + // RegisterTexture2D(&gltfModel.images[0]); + // material->textureName = gltfModel.images[0].name; + // } + + // tinygltf::Image* img_nor = nullptr; + // tinygltf::Image* img_met_rough = nullptr; + // tinygltf::Image* img_emissive = nullptr; + + // if (normalTexture != x.additionalValues.end()) + // { + // auto& tex = gltfModel.textures[normalTexture->second.TextureIndex()]; + // img_nor = &gltfModel.images[tex.source]; + // } + // if (metallicRoughnessTexture != x.values.end()) + // { + // auto& tex = gltfModel.textures[metallicRoughnessTexture->second.TextureIndex()]; + // img_met_rough = &gltfModel.images[tex.source]; + // } + // if (emissiveTexture != x.additionalValues.end()) + // { + // auto& tex = gltfModel.textures[emissiveTexture->second.TextureIndex()]; + // img_emissive = &gltfModel.images[tex.source]; + // } + + // // Now we will begin interleaving texture data to match engine layout: + + // if (img_nor != nullptr) + // { + // uint32_t* data32_roughness = nullptr; + // if (img_met_rough != nullptr && img_met_rough->width == img_nor->width && img_met_rough->height == img_nor->height) + // { + // data32_roughness = (uint32_t*)img_met_rough->image.data(); + // } + // else if (img_met_rough != nullptr) + // { + // wiBackLog::post("[gltf] Warning: there is a normalmap and roughness texture, but not the same size! Roughness will not be baked in!"); + // } + + // // Convert normal map: + // uint32_t* data32 = (uint32_t*)img_nor->image.data(); + // for (int i = 0; i < img_nor->width * img_nor->height; ++i) + // { + // uint32_t pixel = data32[i]; + // float r = ((pixel >> 0) & 255) / 255.0f; + // float g = ((pixel >> 8) & 255) / 255.0f; + // float b = ((pixel >> 16) & 255) / 255.0f; + // float a = ((pixel >> 24) & 255) / 255.0f; + + // // swap normal y direction: + // g = 1 - g; + + // // reset roughness: + // a = 1; + + // if (data32_roughness != nullptr) + // { + // // add roughness from texture (G): + // a = ((data32_roughness[i] >> 8) & 255) / 255.0f; + // a = max(1.0f / 255.0f, a); // disallow 0 roughness (but is it really a good idea to do it here???) + // } + + // uint32_t rgba8 = 0; + // rgba8 |= (uint32_t)(r * 255.0f) << 0; + // rgba8 |= (uint32_t)(g * 255.0f) << 8; + // rgba8 |= (uint32_t)(b * 255.0f) << 16; + // rgba8 |= (uint32_t)(a * 255.0f) << 24; + + // data32[i] = rgba8; + // } + + // RegisterTexture2D(img_nor); + // material->normalMapName = img_nor->name; + // } + + // if (img_met_rough != nullptr) + // { + // uint32_t* data32_emissive = nullptr; + // if (img_emissive != nullptr && img_emissive->width == img_met_rough->width && img_emissive->height == img_met_rough->height) + // { + // data32_emissive = (uint32_t*)img_emissive->image.data(); + // } + + // uint32_t* data32 = (uint32_t*)img_met_rough->image.data(); + // for (int i = 0; i < img_met_rough->width * img_met_rough->height; ++i) + // { + // uint32_t pixel = data32[i]; + // float r = ((pixel >> 0) & 255) / 255.0f; + // float g = ((pixel >> 8) & 255) / 255.0f; + // float b = ((pixel >> 16) & 255) / 255.0f; + // float a = ((pixel >> 24) & 255) / 255.0f; + + // float reflectance = 1; + // float metalness = b; + // float emissive = 0; + // float sss = 1; + + // if (data32_emissive != nullptr) + // { + // // add emissive from texture (R): + // // (Currently only supporting single channel emissive) + // emissive = ((data32_emissive[i] >> 0) & 255) / 255.0f; + // } + + // uint32_t rgba8 = 0; + // rgba8 |= (uint32_t)(reflectance * 255.0f) << 0; + // rgba8 |= (uint32_t)(metalness * 255.0f) << 8; + // rgba8 |= (uint32_t)(emissive * 255.0f) << 16; + // rgba8 |= (uint32_t)(sss * 255.0f) << 24; + + // data32[i] = rgba8; + // } + + // RegisterTexture2D(img_met_rough); + // material->surfaceMapName = img_met_rough->name; + // } + // else if (img_emissive != nullptr) + // { + // // No metalness texture, just emissive... + // uint32_t* data32 = (uint32_t*)img_emissive->image.data(); + + // if (data32 != nullptr) + // { + // for (int i = 0; i < img_emissive->width * img_emissive->height; ++i) + // { + // uint32_t pixel = data32[i]; + // float r = ((pixel >> 0) & 255) / 255.0f; + // float g = ((pixel >> 8) & 255) / 255.0f; + // float b = ((pixel >> 16) & 255) / 255.0f; + // float a = ((pixel >> 24) & 255) / 255.0f; + + // float reflectance = 1; + // float metalness = 1; + // float emissive = r; + // float sss = 1; + + // uint32_t rgba8 = 0; + // rgba8 |= (uint32_t)(reflectance * 255.0f) << 0; + // rgba8 |= (uint32_t)(metalness * 255.0f) << 8; + // rgba8 |= (uint32_t)(emissive * 255.0f) << 16; + // rgba8 |= (uint32_t)(sss * 255.0f) << 24; + + // data32[i] = rgba8; + // } + + // RegisterTexture2D(img_emissive); + // material->surfaceMapName = img_emissive->name; + // } + // } + + // // Retrieve textures by name: + // if (!material->textureName.empty()) + // material->texture = (Texture2D*)wiResourceManager::GetGlobal()->add(material->textureName); + // if (!material->normalMapName.empty()) + // material->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->normalMapName); + // if (!material->surfaceMapName.empty()) + // material->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->surfaceMapName); + + // if (baseColorFactor != x.values.end()) + // { + // material->baseColor.x = static_cast(baseColorFactor->second.ColorFactor()[0]); + // material->baseColor.y = static_cast(baseColorFactor->second.ColorFactor()[1]); + // material->baseColor.z = static_cast(baseColorFactor->second.ColorFactor()[2]); + // } + // if (roughnessFactor != x.values.end()) + // { + // material->roughness = static_cast(roughnessFactor->second.Factor()); + // } + // if (metallicFactor != x.values.end()) + // { + // material->metalness = static_cast(metallicFactor->second.Factor()); + // } + // if (emissiveFactor != x.additionalValues.end()) + // { + // material->emissive = static_cast(emissiveFactor->second.ColorFactor()[0]); + // } + // if (alphaCutoff != x.additionalValues.end()) + // { + // material->alphaRef = 1 - static_cast(alphaCutoff->second.Factor()); + // } + + //} + + //for(auto& skin : gltfModel.skins) + //{ + // Armature* armature = new Armature(skin.name); + // model->armatures.insert(armature); + + // armatureArray.push_back(armature); + + // const tinygltf::Node& skeleton_node = gltfModel.nodes[skin.skeleton]; + + // const size_t jointCount = skin.joints.size(); + + // armature->boneCollection.resize(jointCount); + + // // Create bone collection: + // for (size_t i = 0; i < jointCount; ++i) + // { + // int jointIndex = skin.joints[i]; + // const tinygltf::Node& joint_node = gltfModel.nodes[jointIndex]; + + // Bone* bone = new Bone(joint_node.name); + // if (bone->name.empty()) + // { + // // GLTF might not contain bone names... + // stringstream ss(""); + // ss << "Bone_" << i; + // bone->name = ss.str(); + // } + + // armature->boneCollection[i] = bone; + + // if (!joint_node.scale.empty()) + // { + // bone->scale_rest = XMFLOAT3((float)joint_node.scale[0], (float)joint_node.scale[1], (float)joint_node.scale[2]); + // } + // if (!joint_node.rotation.empty()) + // { + // bone->rotation_rest = XMFLOAT4((float)joint_node.rotation[0], (float)joint_node.rotation[1], (float)joint_node.rotation[2], (float)joint_node.rotation[3]); + // } + // if (!joint_node.translation.empty()) + // { + // bone->translation_rest = XMFLOAT3((float)joint_node.translation[0], (float)joint_node.translation[1], (float)joint_node.translation[2]); + // } + + // XMVECTOR s = XMLoadFloat3(&bone->scale_rest); + // XMVECTOR r = XMLoadFloat4(&bone->rotation_rest); + // XMVECTOR t = XMLoadFloat3(&bone->translation_rest); + // XMMATRIX w = + // XMMatrixScalingFromVector(s)* + // XMMatrixRotationQuaternion(r)* + // XMMatrixTranslationFromVector(t) + // ; + // XMStoreFloat4x4(&bone->world_rest, w); + // } + + // // Create bone name hierarchy: + // for (size_t i = 0; i < jointCount; ++i) + // { + // int jointIndex = skin.joints[i]; + // const tinygltf::Node& joint_node = gltfModel.nodes[jointIndex]; + + // for (int childJointIndex : joint_node.children) + // { + // for (size_t j = 0; j < jointCount; ++j) + // { + // if (skin.joints[j] == childJointIndex) + // { + // armature->boneCollection[j]->parentName = armature->boneCollection[i]->name; + // break; + // } + // } + // } + // } + + // if (transform_to_LH) + // { + // XMStoreFloat4x4(&armature->skinningRemap, XMMatrixScaling(1, 1, -1)); + // } + + // // Final hierarchy and extra matrices created here: + // armature->CreateFamily(); + + //} + + //const tinygltf::Scene &scene = gltfModel.scenes[gltfModel.defaultScene]; + //for (size_t i = 0; i < scene.nodes.size(); i++) + //{ + // LoadNode(&gltfModel.nodes[scene.nodes[i]], nullptr, model, gltfModel, meshArray, armatureArray); + //} + + //int animID = 0; + //for (auto& anim : gltfModel.animations) + //{ + // if (armatureArray.empty()) + // { + // break; + // } + // Armature* armature = armatureArray[0]; + + // for (Bone* bone : armature->boneCollection) + // { + // bone->actionFrames.push_back(ActionFrames()); + // } + + // Action action; + // action.name = anim.name; + // if (action.name.empty()) + // { + // stringstream ss(""); + // ss << "Action_" << animID++; + // action.name = ss.str(); + // } + + // for (auto& channel : anim.channels) + // { + // const tinygltf::Node& target_node = gltfModel.nodes[channel.target_node]; + // const tinygltf::AnimationSampler& sam = anim.samplers[channel.sampler]; + + // Bone* bone = nullptr; + + // // Search for the armature + bone this animation belongs to: + // { + // const auto& skin = gltfModel.skins[0]; + + // const size_t jointCount = skin.joints.size(); + // assert(armature->boneCollection.size() == jointCount); + + // for (size_t i = 0; i < jointCount; ++i) + // { + // int jointIndex = skin.joints[i]; + + // if (jointIndex == channel.target_node) + // { + // bone = armature->boneCollection[i]; + // break; + // } + // } + // } + + // if (bone == nullptr) + // { + // assert(0 && "Corresponding bone not found!"); + // continue; + // } + + + // vector keyframes; + + // // AnimationSampler input = keyframe times + // { + // const tinygltf::Accessor& accessor = gltfModel.accessors[sam.input]; + // const tinygltf::BufferView& bufferView = gltfModel.bufferViews[accessor.bufferView]; + // const tinygltf::Buffer& buffer = gltfModel.buffers[bufferView.buffer]; + + // assert(accessor.componentType == TINYGLTF_COMPONENT_TYPE_FLOAT); + + // int stride = accessor.ByteStride(bufferView); + // size_t count = accessor.count; + + // keyframes.resize(count); + + // const unsigned char* data = buffer.data.data() + accessor.byteOffset + bufferView.byteOffset; + + // int firstFrame = INT_MAX; + + // assert(stride == 4); + // for (size_t i = 0; i < count; ++i) + // { + // keyframes[i].frameI = (int)(((float*)data)[i] * 60); // !!! converting from time-base to frame-based !!! + + // action.frameCount = max(action.frameCount, keyframes[i].frameI); + // firstFrame = min(firstFrame, keyframes[i].frameI); + // } + + // // Cut out the empty part of the animation at the beginning: + // firstFrame = min(firstFrame, action.frameCount); + // for (size_t i = 0; i < count; ++i) + // { + // keyframes[i].frameI -= firstFrame; + // } + // action.frameCount -= firstFrame; + + // } + + // // AnimationSampler output = keyframe data + // { + // const tinygltf::Accessor& accessor = gltfModel.accessors[sam.output]; + // const tinygltf::BufferView& bufferView = gltfModel.bufferViews[accessor.bufferView]; + // const tinygltf::Buffer& buffer = gltfModel.buffers[bufferView.buffer]; + + // int stride = accessor.ByteStride(bufferView); + // size_t count = accessor.count; + + // // Unfortunately, GLTF stores absolute values for animation nodes, but the engine needs relative + // // Absolute = animation * rest (so the rest matrix is baked into animation, this can't be blended like we do now) + // // Relative = animation (so we can blend all animation tracks however we want, then post multiply with the rest matrix after blending) + // const XMMATRIX invRest = XMMatrixInverse(nullptr, XMLoadFloat4x4(&bone->world_rest)); + + // const unsigned char* data = buffer.data.data() + accessor.byteOffset + bufferView.byteOffset; + + // if (!channel.target_path.compare("scale")) + // { + // assert(stride == sizeof(XMFLOAT3)); + // for (size_t i = 0; i < count; ++i) + // { + // const XMFLOAT3& sca = ((XMFLOAT3*)data)[i]; + // //keyframes[i].data = XMFLOAT4(sca.x, sca.y, sca.z, 0); + + // // Remove rest matrix from animation track: + // XMMATRIX mat = XMMatrixScalingFromVector(XMLoadFloat3(&sca)); + // mat = mat * invRest; + // XMVECTOR s, r, t; + // XMMatrixDecompose(&s, &r, &t, mat); + // XMStoreFloat4(&keyframes[i].data, s); + // } + // bone->actionFrames.back().keyframesSca.insert(bone->actionFrames.back().keyframesSca.end(), keyframes.begin(), keyframes.end()); + // } + // else if (!channel.target_path.compare("rotation")) + // { + // assert(stride == sizeof(XMFLOAT4)); + // for (size_t i = 0; i < count; ++i) + // { + // const XMFLOAT4& rot = ((XMFLOAT4*)data)[i]; + // //keyframes[i].data = rot; + + // // Remove rest matrix from animation track: + // XMMATRIX mat = XMMatrixRotationQuaternion(XMLoadFloat4(&rot)); + // mat = mat * invRest; + // XMVECTOR s, r, t; + // XMMatrixDecompose(&s, &r, &t, mat); + // XMStoreFloat4(&keyframes[i].data, r); + // } + // bone->actionFrames.back().keyframesRot.insert(bone->actionFrames.back().keyframesRot.end(), keyframes.begin(), keyframes.end()); + // } + // else if (!channel.target_path.compare("translation")) + // { + // assert(stride == sizeof(XMFLOAT3)); + // for (size_t i = 0; i < count; ++i) + // { + // const XMFLOAT3& tra = ((XMFLOAT3*)data)[i]; + // //keyframes[i].data = XMFLOAT4(tra.x, tra.y, tra.z, 1); + + // // Remove rest matrix from animation track: + // XMMATRIX mat = XMMatrixTranslationFromVector(XMLoadFloat3(&tra)); + // mat = mat * invRest; + // XMVECTOR s, r, t; + // XMMatrixDecompose(&s, &r, &t, mat); + // XMStoreFloat4(&keyframes[i].data, t); + // } + // bone->actionFrames.back().keyframesPos.insert(bone->actionFrames.back().keyframesPos.end(), keyframes.begin(), keyframes.end()); + // } + // else + // { + // assert(0); + // } + // } + + + // } + + // armature->actions.push_back(action); + + //} + + //model->FinishLoading(); + + //return model; } diff --git a/Editor/ModelImporter_OBJ.cpp b/Editor/ModelImporter_OBJ.cpp index 205508195..2d440158a 100644 --- a/Editor/ModelImporter_OBJ.cpp +++ b/Editor/ModelImporter_OBJ.cpp @@ -8,9 +8,10 @@ using namespace std; using namespace wiGraphicsTypes; -using namespace wiSceneComponents; +using namespace wiSceneSystem; +using namespace wiECS; -Model* ImportModel_OBJ(const std::string& fileName) +Entity ImportModel_OBJ(const std::string& fileName) { string directory, name; wiHelper::SplitPath(fileName, directory, name); @@ -27,199 +28,199 @@ Model* ImportModel_OBJ(const std::string& fileName) if (success) { - Model* model = new Model; - model->name = name; + //Model* model = new Model; + //model->name = name; - // Load material library: - vector materialLibrary = {}; - for (auto& obj_material : obj_materials) - { - Material* material = new Material(obj_material.name); + //// Load material library: + //vector materialLibrary = {}; + //for (auto& obj_material : obj_materials) + //{ + // Material* material = new Material(obj_material.name); - material->diffuseColor = XMFLOAT3(obj_material.diffuse[0], obj_material.diffuse[1], obj_material.diffuse[2]); - material->textureName = obj_material.diffuse_texname; - material->displacementMapName = obj_material.displacement_texname; - if (material->displacementMapName.empty()) - { - material->displacementMapName = obj_material.bump_texname; - } - material->emissive = max(obj_material.emission[0], max(obj_material.emission[1], obj_material.emission[2])); - //obj_material.emissive_texname; - material->refractionIndex = obj_material.ior; - material->metalness = obj_material.metallic; - //obj_material.metallic_texname; - material->normalMapName = obj_material.normal_texname; - material->surfaceMapName = obj_material.reflection_texname; - material->roughness = obj_material.roughness; - //obj_material.roughness_texname; - material->specular_power = (int)obj_material.shininess; - material->specular = XMFLOAT4(obj_material.specular[0], obj_material.specular[1], obj_material.specular[2], 1); - material->specularMapName = obj_material.specular_texname; + // material->diffuseColor = XMFLOAT3(obj_material.diffuse[0], obj_material.diffuse[1], obj_material.diffuse[2]); + // material->textureName = obj_material.diffuse_texname; + // material->displacementMapName = obj_material.displacement_texname; + // if (material->displacementMapName.empty()) + // { + // material->displacementMapName = obj_material.bump_texname; + // } + // material->emissive = max(obj_material.emission[0], max(obj_material.emission[1], obj_material.emission[2])); + // //obj_material.emissive_texname; + // material->refractionIndex = obj_material.ior; + // material->metalness = obj_material.metallic; + // //obj_material.metallic_texname; + // material->normalMapName = obj_material.normal_texname; + // material->surfaceMapName = obj_material.reflection_texname; + // material->roughness = obj_material.roughness; + // //obj_material.roughness_texname; + // material->specular_power = (int)obj_material.shininess; + // material->specular = XMFLOAT4(obj_material.specular[0], obj_material.specular[1], obj_material.specular[2], 1); + // material->specularMapName = obj_material.specular_texname; - if (!material->surfaceMapName.empty()) - { - material->surfaceMapName = directory + material->surfaceMapName; - material->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->surfaceMapName); - } - if (!material->textureName.empty()) - { - material->textureName = directory + material->textureName; - material->texture = (Texture2D*)wiResourceManager::GetGlobal()->add(material->textureName); - } - if (!material->normalMapName.empty()) - { - material->normalMapName = directory + material->normalMapName; - material->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->normalMapName); - } - if (!material->displacementMapName.empty()) - { - material->displacementMapName = directory + material->displacementMapName; - material->displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->displacementMapName); - } - if (!material->specularMapName.empty()) - { - material->specularMapName = directory + material->specularMapName; - material->specularMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->specularMapName); - } + // if (!material->surfaceMapName.empty()) + // { + // material->surfaceMapName = directory + material->surfaceMapName; + // material->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->surfaceMapName); + // } + // if (!material->textureName.empty()) + // { + // material->textureName = directory + material->textureName; + // material->texture = (Texture2D*)wiResourceManager::GetGlobal()->add(material->textureName); + // } + // if (!material->normalMapName.empty()) + // { + // material->normalMapName = directory + material->normalMapName; + // material->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->normalMapName); + // } + // if (!material->displacementMapName.empty()) + // { + // material->displacementMapName = directory + material->displacementMapName; + // material->displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->displacementMapName); + // } + // if (!material->specularMapName.empty()) + // { + // material->specularMapName = directory + material->specularMapName; + // material->specularMap = (Texture2D*)wiResourceManager::GetGlobal()->add(material->specularMapName); + // } - material->ConvertToPhysicallyBasedMaterial(); + // material->ConvertToPhysicallyBasedMaterial(); - materialLibrary.push_back(material); // for subset-indexing... - model->materials.insert(make_pair(material->name, material)); - } + // materialLibrary.push_back(material); // for subset-indexing... + // model->materials.insert(make_pair(material->name, material)); + //} - if (materialLibrary.empty()) - { - // Create default material if nothing was found: - Material* material = new Material("OBJImport_defaultMaterial"); - materialLibrary.push_back(material); - model->materials.insert(make_pair(material->name, material)); - } + //if (materialLibrary.empty()) + //{ + // // Create default material if nothing was found: + // Material* material = new Material("OBJImport_defaultMaterial"); + // materialLibrary.push_back(material); + // model->materials.insert(make_pair(material->name, material)); + //} - // Load objects, meshes: - for (auto& shape : obj_shapes) - { - Object* object = new Object(shape.name); - Mesh* mesh = new Mesh(shape.name + "_mesh"); + //// Load objects, meshes: + //for (auto& shape : obj_shapes) + //{ + // Object* object = new Object(shape.name); + // Mesh* mesh = new Mesh(shape.name + "_mesh"); - object->mesh = mesh; - mesh->renderable = true; + // object->mesh = mesh; + // mesh->renderable = true; - XMFLOAT3 min = XMFLOAT3(FLT_MAX, FLT_MAX, FLT_MAX); - XMFLOAT3 max = XMFLOAT3(-FLT_MAX, -FLT_MAX, -FLT_MAX); + // XMFLOAT3 min = XMFLOAT3(FLT_MAX, FLT_MAX, FLT_MAX); + // XMFLOAT3 max = XMFLOAT3(-FLT_MAX, -FLT_MAX, -FLT_MAX); - unordered_map registered_materialIndices = {}; - unordered_map uniqueVertices = {}; + // unordered_map registered_materialIndices = {}; + // unordered_map uniqueVertices = {}; - for (size_t i = 0; i < shape.mesh.indices.size(); i += 3) - { - tinyobj::index_t reordered_indices[] = { - shape.mesh.indices[i + 0], - shape.mesh.indices[i + 1], - shape.mesh.indices[i + 2], - }; + // for (size_t i = 0; i < shape.mesh.indices.size(); i += 3) + // { + // tinyobj::index_t reordered_indices[] = { + // shape.mesh.indices[i + 0], + // shape.mesh.indices[i + 1], + // shape.mesh.indices[i + 2], + // }; - // todo: option param would be better - bool flipCulling = false; - if (flipCulling) - { - reordered_indices[1] = shape.mesh.indices[i + 2]; - reordered_indices[2] = shape.mesh.indices[i + 1]; - } + // // todo: option param would be better + // bool flipCulling = false; + // if (flipCulling) + // { + // reordered_indices[1] = shape.mesh.indices[i + 2]; + // reordered_indices[2] = shape.mesh.indices[i + 1]; + // } - for (auto& index : reordered_indices) - { - Mesh::Vertex_FULL vert; + // for (auto& index : reordered_indices) + // { + // Mesh::Vertex_FULL vert; - vert.pos = XMFLOAT4( - obj_attrib.vertices[index.vertex_index * 3 + 0], - obj_attrib.vertices[index.vertex_index * 3 + 1], - obj_attrib.vertices[index.vertex_index * 3 + 2], - 0 - ); + // vert.pos = XMFLOAT4( + // obj_attrib.vertices[index.vertex_index * 3 + 0], + // obj_attrib.vertices[index.vertex_index * 3 + 1], + // obj_attrib.vertices[index.vertex_index * 3 + 2], + // 0 + // ); - if (!obj_attrib.normals.empty()) - { - vert.nor = XMFLOAT4( - obj_attrib.normals[index.normal_index * 3 + 0], - obj_attrib.normals[index.normal_index * 3 + 1], - obj_attrib.normals[index.normal_index * 3 + 2], - 0 - ); - } + // if (!obj_attrib.normals.empty()) + // { + // vert.nor = XMFLOAT4( + // obj_attrib.normals[index.normal_index * 3 + 0], + // obj_attrib.normals[index.normal_index * 3 + 1], + // obj_attrib.normals[index.normal_index * 3 + 2], + // 0 + // ); + // } - if (index.texcoord_index >= 0 && !obj_attrib.texcoords.empty()) - { - vert.tex = XMFLOAT4( - obj_attrib.texcoords[index.texcoord_index * 2 + 0], - 1 - obj_attrib.texcoords[index.texcoord_index * 2 + 1], - 0, 0 - ); - } + // if (index.texcoord_index >= 0 && !obj_attrib.texcoords.empty()) + // { + // vert.tex = XMFLOAT4( + // obj_attrib.texcoords[index.texcoord_index * 2 + 0], + // 1 - obj_attrib.texcoords[index.texcoord_index * 2 + 1], + // 0, 0 + // ); + // } - int materialIndex = max(0, shape.mesh.material_ids[i / 3]); // this indexes the material library - if (registered_materialIndices.count(materialIndex) == 0) - { - registered_materialIndices[materialIndex] = (int)mesh->subsets.size(); - mesh->subsets.push_back(MeshSubset()); - Material* material = materialLibrary[materialIndex]; - mesh->subsets.back().material = material; - mesh->materialNames.push_back(material->name); - } - vert.tex.z = (float)registered_materialIndices[materialIndex]; // this indexes a mesh subset + // int materialIndex = max(0, shape.mesh.material_ids[i / 3]); // this indexes the material library + // if (registered_materialIndices.count(materialIndex) == 0) + // { + // registered_materialIndices[materialIndex] = (int)mesh->subsets.size(); + // mesh->subsets.push_back(MeshSubset()); + // Material* material = materialLibrary[materialIndex]; + // mesh->subsets.back().material = material; + // mesh->materialNames.push_back(material->name); + // } + // vert.tex.z = (float)registered_materialIndices[materialIndex]; // this indexes a mesh subset - // todo: option parameter would be better - const bool flipZ = true; - if (flipZ) - { - vert.pos.z *= -1; - vert.nor.z *= -1; - } + // // todo: option parameter would be better + // const bool flipZ = true; + // if (flipZ) + // { + // vert.pos.z *= -1; + // vert.nor.z *= -1; + // } - // eliminate duplicate vertices by means of hashing: - size_t hashes[] = { - hash{}(index.vertex_index), - hash{}(index.normal_index), - hash{}(index.texcoord_index), - hash{}(materialIndex), - }; - size_t vertexHash = (((hashes[0] ^ (hashes[1] << 1) >> 1) ^ (hashes[2] << 1)) >> 1) ^ (hashes[3] << 1); + // // eliminate duplicate vertices by means of hashing: + // size_t hashes[] = { + // hash{}(index.vertex_index), + // hash{}(index.normal_index), + // hash{}(index.texcoord_index), + // hash{}(materialIndex), + // }; + // size_t vertexHash = (((hashes[0] ^ (hashes[1] << 1) >> 1) ^ (hashes[2] << 1)) >> 1) ^ (hashes[3] << 1); - if (uniqueVertices.count(vertexHash) == 0) - { - uniqueVertices[vertexHash] = (uint32_t)mesh->vertices_FULL.size(); - mesh->vertices_FULL.push_back(vert); - } - mesh->indices.push_back(uniqueVertices[vertexHash]); + // if (uniqueVertices.count(vertexHash) == 0) + // { + // uniqueVertices[vertexHash] = (uint32_t)mesh->vertices_FULL.size(); + // mesh->vertices_FULL.push_back(vert); + // } + // mesh->indices.push_back(uniqueVertices[vertexHash]); - min = wiMath::Min(min, XMFLOAT3(vert.pos.x, vert.pos.y, vert.pos.z)); - max = wiMath::Max(max, XMFLOAT3(vert.pos.x, vert.pos.y, vert.pos.z)); - } - } - mesh->aabb.create(min, max); + // min = wiMath::Min(min, XMFLOAT3(vert.pos.x, vert.pos.y, vert.pos.z)); + // max = wiMath::Max(max, XMFLOAT3(vert.pos.x, vert.pos.y, vert.pos.z)); + // } + // } + // mesh->aabb.create(min, max); - // We need to eliminate colliding mesh names, because objects can reference them by names: - // Note: in engine, object is decoupled from mesh, for instancing support. OBJ file have only meshes and names can collide there. - string meshName = mesh->name; - uint32_t unique_counter = 0; - bool meshNameCollision = model->meshes.count(meshName) != 0; - while (meshNameCollision) - { - meshName = mesh->name + to_string(unique_counter); - meshNameCollision = model->meshes.count(meshName) != 0; - unique_counter++; - } - mesh->name = meshName; + // // We need to eliminate colliding mesh names, because objects can reference them by names: + // // Note: in engine, object is decoupled from mesh, for instancing support. OBJ file have only meshes and names can collide there. + // string meshName = mesh->name; + // uint32_t unique_counter = 0; + // bool meshNameCollision = model->meshes.count(meshName) != 0; + // while (meshNameCollision) + // { + // meshName = mesh->name + to_string(unique_counter); + // meshNameCollision = model->meshes.count(meshName) != 0; + // unique_counter++; + // } + // mesh->name = meshName; - object->meshName = mesh->name; + // object->meshName = mesh->name; - model->objects.insert(object); - model->meshes.insert(make_pair(mesh->name, mesh)); - } + // model->objects.insert(object); + // model->meshes.insert(make_pair(mesh->name, mesh)); + //} - model->FinishLoading(); + //model->FinishLoading(); - return model; + //return model; } if (!obj_errors.empty()) @@ -228,5 +229,5 @@ Model* ImportModel_OBJ(const std::string& fileName) wiHelper::messageBox("OBJ import failed! Check backlog for errors!", "Error!"); } - return nullptr; + return INVALID_ENTITY; } diff --git a/Editor/ModelImporter_WIO.cpp b/Editor/ModelImporter_WIO.cpp index f73865ab3..11f08b70f 100644 --- a/Editor/ModelImporter_WIO.cpp +++ b/Editor/ModelImporter_WIO.cpp @@ -6,1236 +6,1239 @@ using namespace std; using namespace wiGraphicsTypes; -using namespace wiSceneComponents; - - -Mesh* LoadMeshFromBinaryFile(const std::string& newName, const std::string& fname, const std::map& materialColl, const unordered_set& armatures) -{ - Mesh* mesh = new Mesh(newName); - - BYTE* buffer; - size_t fileSize; - if (wiHelper::readByteData(fname, &buffer, fileSize)) { - - int offset = 0; - - int VERSION; - memcpy(&VERSION, buffer, sizeof(int)); - offset += sizeof(int); - - if (VERSION >= 1001) { - int doubleside; - memcpy(&doubleside, buffer + offset, sizeof(int)); - offset += sizeof(int); - if (doubleside) { - mesh->doubleSided = true; - } - } - - int billboard; - memcpy(&billboard, buffer + offset, sizeof(int)); - offset += sizeof(int); - if (billboard) { - char axis; - memcpy(&axis, buffer + offset, 1); - offset += 1; - - if (toupper(axis) == 'Y') - mesh->billboardAxis = XMFLOAT3(0, 1, 0); - else if (toupper(axis) == 'X') - mesh->billboardAxis = XMFLOAT3(1, 0, 0); - else if (toupper(axis) == 'Z') - mesh->billboardAxis = XMFLOAT3(0, 0, 1); - else - mesh->billboardAxis = XMFLOAT3(0, 0, 0); - mesh->isBillboarded = true; - } - - int parented; //parentnamelength - memcpy(&parented, buffer + offset, sizeof(int)); - offset += sizeof(int); - if (parented) { - char* pName = new char[parented + 1](); - memcpy(pName, buffer + offset, parented); - offset += parented; - mesh->parent = pName; - delete[] pName; - - stringstream identified_parent(""); - identified_parent << mesh->parent; - for (Armature* a : armatures) { - if (!a->name.compare(identified_parent.str())) { - mesh->armatureName = identified_parent.str(); - mesh->armature = a; - } - } - } - - int materialCount; - memcpy(&materialCount, buffer + offset, sizeof(int)); - offset += sizeof(int); - for (int i = 0; isubsets.push_back(MeshSubset()); - mesh->subsets.back().material = iter->second; - //materials.push_back(iter->second); - } - - mesh->materialNames.push_back(identified_matname.str()); - delete[] matName; - } - int rendermesh, vertexCount; - memcpy(&rendermesh, buffer + offset, sizeof(int)); - offset += sizeof(int); - memcpy(&vertexCount, buffer + offset, sizeof(int)); - offset += sizeof(int); - - mesh->vertices_FULL.resize(vertexCount); - - for (int i = 0; ivertices_FULL[i].pos.x = v[0]; - mesh->vertices_FULL[i].pos.y = v[1]; - mesh->vertices_FULL[i].pos.z = v[2]; - mesh->vertices_FULL[i].pos.w = 0; - if (!mesh->isBillboarded) { - mesh->vertices_FULL[i].nor.x = v[3]; - mesh->vertices_FULL[i].nor.y = v[4]; - mesh->vertices_FULL[i].nor.z = v[5]; - } - else { - mesh->vertices_FULL[i].nor.x = mesh->billboardAxis.x; - mesh->vertices_FULL[i].nor.y = mesh->billboardAxis.y; - mesh->vertices_FULL[i].nor.z = mesh->billboardAxis.z; - } - mesh->vertices_FULL[i].tex.x = v[6]; - mesh->vertices_FULL[i].tex.y = v[7]; - int matIndex; - memcpy(&matIndex, buffer + offset, sizeof(int)); - offset += sizeof(int); - mesh->vertices_FULL[i].tex.z = (float)matIndex; - - int weightCount = 0; - memcpy(&weightCount, buffer + offset, sizeof(int)); - offset += sizeof(int); - for (int j = 0; jarmature) { - bool gotBone = false; - int BONEINDEX = 0; - int b = 0; - while (!gotBone && b<(int)mesh->armature->boneCollection.size()) { - if (!mesh->armature->boneCollection[b]->name.compare(nameB)) { - gotBone = true; - BONEINDEX = b; //GOT INDEX OF BONE OF THE WEIGHT IN THE PARENT ARMATURE - } - b++; - } - if (gotBone) { //ONLY PROCEED IF CORRESPONDING BONE WAS FOUND - if (!mesh->vertices_FULL[i].wei.x) { - mesh->vertices_FULL[i].wei.x = weightValue; - mesh->vertices_FULL[i].ind.x = (float)BONEINDEX; - } - else if (!mesh->vertices_FULL[i].wei.y) { - mesh->vertices_FULL[i].wei.y = weightValue; - mesh->vertices_FULL[i].ind.y = (float)BONEINDEX; - } - else if (!mesh->vertices_FULL[i].wei.z) { - mesh->vertices_FULL[i].wei.z = weightValue; - mesh->vertices_FULL[i].ind.z = (float)BONEINDEX; - } - else if (!mesh->vertices_FULL[i].wei.w) { - mesh->vertices_FULL[i].wei.w = weightValue; - mesh->vertices_FULL[i].ind.w = (float)BONEINDEX; - } - } - } - - //(+RIBBONTRAIL SETUP)(+VERTEXGROUP SETUP) - - if (nameB.find("trailbase") != string::npos) - mesh->trailInfo.base = i; - else if (nameB.find("trailtip") != string::npos) - mesh->trailInfo.tip = i; - - bool windAffection = false; - if (nameB.find("wind") != string::npos) - windAffection = true; - bool gotvg = false; - for (unsigned int v = 0; vvertexGroups.size(); ++v) - if (!nameB.compare(mesh->vertexGroups[v].name)) { - gotvg = true; - mesh->vertexGroups[v].addVertex(VertexRef(i, weightValue)); - if (windAffection) - mesh->vertices_FULL[i].pos.w = weightValue; - } - if (!gotvg) { - mesh->vertexGroups.push_back(VertexGroup(nameB)); - mesh->vertexGroups.back().addVertex(VertexRef(i, weightValue)); - if (windAffection) - mesh->vertices_FULL[i].pos.w = weightValue; - } -#pragma endregion - - delete[] weightName; - - - } - - } - - if (rendermesh) { - int indexCount; - memcpy(&indexCount, buffer + offset, sizeof(int)); - offset += sizeof(int); - unsigned int* indexArray = new unsigned int[indexCount]; - memcpy(indexArray, buffer + offset, sizeof(unsigned int)*indexCount); - offset += sizeof(unsigned int)*indexCount; - mesh->indices.reserve(indexCount); - for (int i = 0; iindices.push_back(indexArray[i]); - } - delete[] indexArray; - - int softBody; - memcpy(&softBody, buffer + offset, sizeof(int)); - offset += sizeof(int); - if (softBody) { - int softCount[2]; //ind,vert - memcpy(softCount, buffer + offset, sizeof(int) * 2); - offset += sizeof(int) * 2; - unsigned int* softind = new unsigned int[softCount[0]]; - memcpy(softind, buffer + offset, sizeof(unsigned int)*softCount[0]); - offset += sizeof(unsigned int)*softCount[0]; - float* softvert = new float[softCount[1]]; - memcpy(softvert, buffer + offset, sizeof(float)*softCount[1]); - offset += sizeof(float)*softCount[1]; - - mesh->physicsindices.reserve(softCount[0]); - mesh->physicsverts.reserve(softCount[1] / 3); - for (int i = 0; iphysicsindices.push_back(softind[i]); - } - for (int i = 0; iphysicsverts.push_back(XMFLOAT3(softvert[i], softvert[i + 1], softvert[i + 2])); - } - - delete[] softind; - delete[] softvert; - } - else { - - } - } - else { - - } - - memcpy(mesh->aabb.corners, buffer + offset, sizeof(mesh->aabb.corners)); - offset += sizeof(mesh->aabb.corners); - - int isSoftbody; - memcpy(&isSoftbody, buffer + offset, sizeof(int)); - offset += sizeof(int); - if (isSoftbody) { - float prop[2]; //mass,friction - memcpy(prop, buffer + offset, sizeof(float) * 2); - offset += sizeof(float) * 2; - mesh->softBody = true; - mesh->mass = prop[0]; - mesh->friction = prop[1]; - int vglenghts[3]; //goal,mass,soft - memcpy(vglenghts, buffer + offset, sizeof(int) * 3); - offset += sizeof(int) * 3; - - char* vgg = new char[vglenghts[0] + 1](); - char* vgm = new char[vglenghts[1] + 1](); - char* vgs = new char[vglenghts[2] + 1](); - - memcpy(vgg, buffer + offset, vglenghts[0]); - offset += vglenghts[0]; - memcpy(vgm, buffer + offset, vglenghts[1]); - offset += vglenghts[1]; - memcpy(vgs, buffer + offset, vglenghts[2]); - offset += vglenghts[2]; - - for (unsigned int v = 0; vvertexGroups.size(); ++v) { - if (!strcmp(vgm, mesh->vertexGroups[v].name.c_str())) - mesh->massVG = v; - if (!strcmp(vgg, mesh->vertexGroups[v].name.c_str())) - mesh->goalVG = v; - if (!strcmp(vgs, mesh->vertexGroups[v].name.c_str())) - mesh->softVG = v; - } - - delete[]vgg; - delete[]vgm; - delete[]vgs; - } - - delete[] buffer; - - mesh->renderable = rendermesh == 0 ? false : true; - } - - return mesh; -} - -void LoadWiArmatures(const std::string& directory, const std::string& name, unordered_set& armatures) -{ - stringstream filename(""); - filename << directory << name; - - ifstream file(filename.str().c_str()); - if (file) - { - Armature* armature = nullptr; - while (!file.eof()) - { - float trans[] = { 0,0,0,0 }; - string line = ""; - file >> line; - if (line[0] == '/' && line.substr(2, 8) == "ARMATURE") - { - armature = new Armature(line.substr(11, strlen(line.c_str()) - 11)); - armatures.insert(armature); - } - else - { - switch (line[0]) - { - case 'r': - file >> trans[0] >> trans[1] >> trans[2] >> trans[3]; - armature->rotation_rest = XMFLOAT4(trans[0], trans[1], trans[2], trans[3]); - break; - case 's': - file >> trans[0] >> trans[1] >> trans[2]; - armature->scale_rest = XMFLOAT3(trans[0], trans[1], trans[2]); - break; - case 't': - file >> trans[0] >> trans[1] >> trans[2]; - armature->translation_rest = XMFLOAT3(trans[0], trans[1], trans[2]); - //{ - // XMMATRIX world = XMMatrixScalingFromVector(XMLoadFloat3(&armature->scale))*XMMatrixRotationQuaternion(XMLoadFloat4(&armature->rotation))*XMMatrixTranslationFromVector(XMLoadFloat3(&armature->translation)); - // XMStoreFloat4x4(&armature->world_rest, world); - //} - break; - case 'b': - { - string boneName; - file >> boneName; - armature->boneCollection.push_back(new Bone(boneName)); - } - break; - case 'p': - file >> armature->boneCollection.back()->parentName; - break; - case 'l': - { - float x = 0, y = 0, z = 0, w = 0; - file >> x >> y >> z >> w; - XMVECTOR quaternion = XMVectorSet(x, y, z, w); - file >> x >> y >> z; - XMVECTOR translation = XMVectorSet(x, y, z, 0); - - XMMATRIX frame; - frame = XMMatrixRotationQuaternion(quaternion) * XMMatrixTranslationFromVector(translation); - - XMStoreFloat3(&armature->boneCollection.back()->translation_rest, translation); - XMStoreFloat4(&armature->boneCollection.back()->rotation_rest, quaternion); - XMStoreFloat4x4(&armature->boneCollection.back()->world_rest, frame); - //XMStoreFloat4x4(&armature->boneCollection.back()->restInv,XMMatrixInverse(0,frame)); - - } - break; - case 'c': - armature->boneCollection.back()->connected = true; - break; - case 'h': - file >> armature->boneCollection.back()->length; - break; - default: break; - } - } - } - } - file.close(); - - - - //CREATE FAMILY - for (Armature* armature : armatures) - { - armature->UpdateTransform(); - armature->CreateFamily(); - } - -} -void LoadWiMaterialLibrary(const std::string& directory, const std::string& name, const std::string& texturesDir, std::map& materials) -{ - int materialI = (int)(materials.size() - 1); - - Material* currentMat = NULL; - - stringstream filename(""); - filename << directory << name; - - ifstream file(filename.str().c_str()); - if (file) { - while (!file.eof()) { - string line = ""; - file >> line; - if (line[0] == '/' && !strcmp(line.substr(2, 8).c_str(), "MATERIAL")) { - if (currentMat) - { - currentMat->ConvertToPhysicallyBasedMaterial(); - materials.insert(pair(currentMat->name, currentMat)); - } - - currentMat = new Material(line.substr(11, strlen(line.c_str()) - 11)); - materialI++; - } - else { - switch (line[0]) { - case 'd': - file >> currentMat->diffuseColor.x; - file >> currentMat->diffuseColor.y; - file >> currentMat->diffuseColor.z; - break; - case 'X': - currentMat->cast_shadow = false; - break; - case 'r': - { - string resourceName = ""; - file >> resourceName; - stringstream ss(""); - ss << directory << texturesDir << resourceName.c_str(); - currentMat->surfaceMapName = ss.str(); - currentMat->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); - } - break; - case 'n': - { - string resourceName = ""; - file >> resourceName; - stringstream ss(""); - ss << directory << texturesDir << resourceName.c_str(); - currentMat->normalMapName = ss.str(); - currentMat->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); - } - break; - case 't': - { - string resourceName = ""; - file >> resourceName; - stringstream ss(""); - ss << directory << texturesDir << resourceName.c_str(); - currentMat->textureName = ss.str(); - currentMat->texture = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); - } - file >> currentMat->premultipliedTexture; - break; - case 'D': - { - string resourceName = ""; - file >> resourceName; - stringstream ss(""); - ss << directory << texturesDir << resourceName.c_str(); - currentMat->displacementMapName = ss.str(); - currentMat->displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); - } - break; - case 'S': - { - string resourceName = ""; - file >> resourceName; - stringstream ss(""); - ss << directory << texturesDir << resourceName.c_str(); - currentMat->specularMapName = ss.str(); - currentMat->specularMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); - } - break; - case 'a': - file >> currentMat->alpha; - break; - case 'h': - currentMat->shadeless = true; - break; - case 'R': - file >> currentMat->refractionIndex; - break; - case 'e': - file >> currentMat->enviroReflection; - break; - case 's': - file >> currentMat->specular.x; - file >> currentMat->specular.y; - file >> currentMat->specular.z; - file >> currentMat->specular.w; - break; - case 'p': - file >> currentMat->specular_power; - break; - case 'k': - currentMat->isSky = true; - break; - case 'm': - file >> currentMat->movingTex.x; - file >> currentMat->movingTex.y; - file >> currentMat->movingTex.z; - currentMat->framesToWaitForTexCoordOffset = currentMat->movingTex.z; - break; - case 'w': - currentMat->water = true; - break; - case 'u': - currentMat->subsurfaceScattering = true; - break; - case 'b': - { - string blend; - file >> blend; - if (!blend.compare("ADD")) - currentMat->blendFlag = BLENDMODE_ADDITIVE; - } - break; - case 'i': - { - file >> currentMat->emissive; - } - break; - default:break; - } - } - } - } - file.close(); - - if (currentMat) - { - currentMat->ConvertToPhysicallyBasedMaterial(); - materials.insert(pair(currentMat->name, currentMat)); - } - -} -void LoadWiObjects(const std::string& directory, const std::string& name, unordered_set& objects - , unordered_set& armatures - , std::map& meshes, const std::map& materials) -{ - - stringstream filename(""); - filename << directory << name; - - ifstream file(filename.str().c_str()); - if (file) - { - Object* object = nullptr; - while (!file.eof()) - { - float trans[] = { 0,0,0,0 }; - string line = ""; - file >> line; - if (line[0] == '/' && !strcmp(line.substr(2, 6).c_str(), "OBJECT")) - { - object = new Object(line.substr(9, strlen(line.c_str()) - 9)); - objects.insert(object); - } - else - { - switch (line[0]) - { - case 'm': - { - string meshName = ""; - file >> meshName; - object->meshName = meshName; - auto& iter = meshes.find(meshName); - - if (line[1] == 'b') - { - //binary load mesh in place if not present - if (iter == meshes.end()) - { - stringstream meshFileName(""); - meshFileName << directory << meshName << ".wimesh"; - Mesh* mesh = LoadMeshFromBinaryFile(meshName, meshFileName.str(), materials, armatures); - object->mesh = mesh; - meshes.insert(pair(meshName, mesh)); - } - else - { - object->mesh = iter->second; - } - } - else - { - if (iter != meshes.end()) - { - object->mesh = iter->second; - } - } - } - break; - case 'p': - { - file >> object->parentName; - } - break; - case 'b': - { - file >> object->boneParent; - } - break; - case 'I': - { - XMFLOAT3 s, t; - XMFLOAT4 r; - file >> t.x >> t.y >> t.z >> r.x >> r.y >> r.z >> r.w >> s.x >> s.y >> s.z; - XMStoreFloat4x4(&object->parent_inv_rest - , XMMatrixScalingFromVector(XMLoadFloat3(&s)) * - XMMatrixRotationQuaternion(XMLoadFloat4(&r)) * - XMMatrixTranslationFromVector(XMLoadFloat3(&t)) - ); - } - break; - case 'r': - file >> trans[0] >> trans[1] >> trans[2] >> trans[3]; - object->Rotate(XMFLOAT4(trans[0], trans[1], trans[2], trans[3])); - break; - case 's': - file >> trans[0] >> trans[1] >> trans[2]; - object->Scale(XMFLOAT3(trans[0], trans[1], trans[2])); - break; - case 't': - file >> trans[0] >> trans[1] >> trans[2]; - object->Translate(XMFLOAT3(trans[0], trans[1], trans[2])); - break; - case 'E': - { - string systemName, materialName; - bool visibleEmitter; - float size, randfac, norfac; - float count, life, randlife; - float scaleX, scaleY, rot; - file >> systemName >> visibleEmitter >> materialName >> size >> randfac >> norfac >> count >> life >> randlife; - file >> scaleX >> scaleY >> rot; - - if (object->mesh) - { - object->eParticleSystems.push_back( - new wiEmittedParticle(systemName, materialName, object, size, randfac, norfac, count, life, randlife, scaleX, scaleY, rot) - ); - } - } - break; - case 'H': - { - string name, mat, densityG, lenG; - float len; - int count; - file >> name >> mat >> len >> count >> densityG >> lenG; - - object->hParticleSystems.push_back(new wiHairParticle(name, len, count, mat, object, densityG, lenG)); - } - break; - case 'P': - object->rigidBody = true; - file >> object->collisionShape >> object->mass >> - object->friction >> object->restitution >> object->damping >> object->physicsType >> - object->kinematic; - break; - case 'T': - file >> object->transparency; - break; - default: break; - } - } - } - } - file.close(); - -} -void LoadWiMeshes(const std::string& directory, const std::string& name, std::map& meshes, - const unordered_set& armatures, const std::map& materials) -{ - int meshI = (int)(meshes.size() - 1); - Mesh* currentMesh = NULL; - - stringstream filename(""); - filename << directory << name; - - ifstream file(filename.str().c_str()); - if (file) { - while (!file.eof()) - { - float trans[] = { 0,0,0,0 }; - string line = ""; - file >> line; - if (line[0] == '/' && !line.substr(2, 4).compare("MESH")) { - currentMesh = new Mesh(line.substr(7, strlen(line.c_str()) - 7)); - meshes.insert(pair(currentMesh->name, currentMesh)); - meshI++; - } - else - { - switch (line[0]) - { - case 'p': - { - file >> currentMesh->parent; - for (auto& a : armatures) - { - if (!a->name.compare(currentMesh->parent)) - { - currentMesh->armature = a; - break; - } - } - } - break; - case 'v': - currentMesh->vertices_FULL.push_back(Mesh::Vertex_FULL()); - file >> currentMesh->vertices_FULL.back().pos.x; - file >> currentMesh->vertices_FULL.back().pos.y; - file >> currentMesh->vertices_FULL.back().pos.z; - break; - case 'n': - if (currentMesh->isBillboarded) { - currentMesh->vertices_FULL.back().nor.x = currentMesh->billboardAxis.x; - currentMesh->vertices_FULL.back().nor.y = currentMesh->billboardAxis.y; - currentMesh->vertices_FULL.back().nor.z = currentMesh->billboardAxis.z; - } - else { - file >> currentMesh->vertices_FULL.back().nor.x; - file >> currentMesh->vertices_FULL.back().nor.y; - file >> currentMesh->vertices_FULL.back().nor.z; - } - break; - case 'u': - file >> currentMesh->vertices_FULL.back().tex.x; - file >> currentMesh->vertices_FULL.back().tex.y; - break; - case 'w': - { - string nameB; - float weight = 0; - int BONEINDEX = 0; - file >> nameB >> weight; - bool gotBone = false; - if (currentMesh->armature != nullptr) { - int j = 0; - for (auto& b : currentMesh->armature->boneCollection) - { - if (!b->name.compare(nameB)) - { - BONEINDEX = j; - break; - } - j++; - } - } - if (gotBone) - { - //ONLY PROCEED IF CORRESPONDING BONE WAS FOUND - if (!currentMesh->vertices_FULL.back().wei.x) { - currentMesh->vertices_FULL.back().wei.x = weight; - currentMesh->vertices_FULL.back().ind.x = (float)BONEINDEX; - } - else if (!currentMesh->vertices_FULL.back().wei.y) { - currentMesh->vertices_FULL.back().wei.y = weight; - currentMesh->vertices_FULL.back().ind.y = (float)BONEINDEX; - } - else if (!currentMesh->vertices_FULL.back().wei.z) { - currentMesh->vertices_FULL.back().wei.z = weight; - currentMesh->vertices_FULL.back().ind.z = (float)BONEINDEX; - } - else if (!currentMesh->vertices_FULL.back().wei.w) { - currentMesh->vertices_FULL.back().wei.w = weight; - currentMesh->vertices_FULL.back().ind.w = (float)BONEINDEX; - } - } - - //(+RIBBONTRAIL SETUP)(+VERTEXGROUP SETUP) - - if (nameB.find("trailbase") != string::npos) - currentMesh->trailInfo.base = (int)(currentMesh->vertices_FULL.size() - 1); - else if (nameB.find("trailtip") != string::npos) - currentMesh->trailInfo.tip = (int)(currentMesh->vertices_FULL.size() - 1); - - bool windAffection = false; - if (nameB.find("wind") != string::npos) - windAffection = true; - bool gotvg = false; - for (unsigned int v = 0; vvertexGroups.size(); ++v) - if (!nameB.compare(currentMesh->vertexGroups[v].name)) { - gotvg = true; - currentMesh->vertexGroups[v].addVertex(VertexRef((int)(currentMesh->vertices_FULL.size() - 1), weight)); - if (windAffection) - currentMesh->vertices_FULL.back().pos.w = weight; - } - if (!gotvg) { - currentMesh->vertexGroups.push_back(VertexGroup(nameB)); - currentMesh->vertexGroups.back().addVertex(VertexRef((int)(currentMesh->vertices_FULL.size() - 1), weight)); - if (windAffection) - currentMesh->vertices_FULL.back().pos.w = weight; - } - } - break; - case 'i': - { - int count; - file >> count; - for (int i = 0; i> index; - currentMesh->indices.push_back(index); - } - break; - } - case 'V': - { - XMFLOAT3 pos; - file >> pos.x >> pos.y >> pos.z; - currentMesh->physicsverts.push_back(pos); - } - break; - case 'I': - { - int count; - file >> count; - for (int i = 0; i> index; - currentMesh->physicsindices.push_back(index); - } - break; - } - case 'm': - { - string mName = ""; - file >> mName; - currentMesh->materialNames.push_back(mName); - auto& iter = materials.find(mName); - if (iter != materials.end()) { - currentMesh->subsets.push_back(MeshSubset()); - currentMesh->renderable = true; - currentMesh->subsets.back().material = (iter->second); - } - } - break; - case 'a': - file >> currentMesh->vertices_FULL.back().tex.z; - break; - case 'B': - for (int corner = 0; corner<8; ++corner) { - file >> currentMesh->aabb.corners[corner].x; - file >> currentMesh->aabb.corners[corner].y; - file >> currentMesh->aabb.corners[corner].z; - } - break; - case 'b': - { - currentMesh->isBillboarded = true; - string read = ""; - file >> read; - transform(read.begin(), read.end(), read.begin(), toupper); - if (read.find(toupper('y')) != string::npos) currentMesh->billboardAxis = XMFLOAT3(0, 1, 0); - else if (read.find(toupper('x')) != string::npos) currentMesh->billboardAxis = XMFLOAT3(1, 0, 0); - else if (read.find(toupper('z')) != string::npos) currentMesh->billboardAxis = XMFLOAT3(0, 0, 1); - else currentMesh->billboardAxis = XMFLOAT3(0, 0, 0); - } - break; - case 'S': - { - currentMesh->softBody = true; - string mvgi = "", gvgi = "", svgi = ""; - file >> currentMesh->mass >> currentMesh->friction >> gvgi >> mvgi >> svgi; - for (unsigned int v = 0; vvertexGroups.size(); ++v) { - if (!strcmp(mvgi.c_str(), currentMesh->vertexGroups[v].name.c_str())) - currentMesh->massVG = v; - if (!strcmp(gvgi.c_str(), currentMesh->vertexGroups[v].name.c_str())) - currentMesh->goalVG = v; - if (!strcmp(svgi.c_str(), currentMesh->vertexGroups[v].name.c_str())) - currentMesh->softVG = v; - } - } - break; - default: break; - } - } - } - } - file.close(); - - if (currentMesh) - meshes.insert(pair(currentMesh->name, currentMesh)); - -} -void LoadWiActions(const std::string& directory, const std::string& name, unordered_set& armatures) -{ - Armature* armatureI = nullptr; - Bone* boneI = nullptr; - int firstFrame = INT_MAX; - - stringstream filename(""); - filename << directory << name; - - ifstream file(filename.str().c_str()); - if (file) { - while (!file.eof()) { - string line = ""; - file >> line; - if (line[0] == '/' && !strcmp(line.substr(2, 8).c_str(), "ARMATURE")) { - string armaturename = line.substr(11, strlen(line.c_str()) - 11); - for (auto& a : armatures) - { - if (!a->name.compare(armaturename)) { - armatureI = a; - break; - } - } - } - else { - switch (line[0]) { - case 'C': - armatureI->actions.push_back(Action()); - file >> armatureI->actions.back().name; - break; - case 'A': - file >> armatureI->actions.back().frameCount; - break; - case 'b': - { - string boneName; - file >> boneName; - boneI = armatureI->GetBone(boneName); - if (boneI != nullptr) - { - boneI->actionFrames.resize(armatureI->actions.size()); - } - } - break; - case 'r': - { - int f = 0; - float x = 0, y = 0, z = 0, w = 0; - file >> f >> x >> y >> z >> w; - if (boneI != nullptr) - { - boneI->actionFrames.back().keyframesRot.push_back(KeyFrame(f, x, y, z, w)); - } - } - break; - case 't': - { - int f = 0; - float x = 0, y = 0, z = 0; - file >> f >> x >> y >> z; - if (boneI != nullptr) - { - boneI->actionFrames.back().keyframesPos.push_back(KeyFrame(f, x, y, z, 0)); - } - } - break; - case 's': - { - int f = 0; - float x = 0, y = 0, z = 0; - file >> f >> x >> y >> z; - if (boneI != nullptr) - { - boneI->actionFrames.back().keyframesSca.push_back(KeyFrame(f, x, y, z, 0)); - } - } - break; - default: break; - } - } - } - } - file.close(); -} -void LoadWiLights(const std::string& directory, const std::string& name, unordered_set& lights) -{ - - stringstream filename(""); - filename << directory << name; - - ifstream file(filename.str().c_str()); - if (file) - { - Light* light = nullptr; - while (!file.eof()) - { - string line = ""; - file >> line; - switch (line[0]) - { - case 'P': - { - light = new Light(); - lights.insert(light); - light->SetType(Light::POINT); - file >> light->name >> light->shadow; - } - break; - case 'D': - { - light = new Light(); - lights.insert(light); - light->SetType(Light::DIRECTIONAL); - file >> light->name; - light->shadow = true; - } - break; - case 'S': - { - light = new Light(); - lights.insert(light); - light->SetType(Light::SPOT); - file >> light->name; - file >> light->shadow >> light->enerDis.z; - } - break; - case 'p': - { - file >> light->parentName; - } - break; - case 'b': - { - file >> light->boneParent; - } - break; - case 'I': - { - XMFLOAT3 s, t; - XMFLOAT4 r; - file >> t.x >> t.y >> t.z >> r.x >> r.y >> r.z >> r.w >> s.x >> s.y >> s.z; - XMStoreFloat4x4(&light->parent_inv_rest - , XMMatrixScalingFromVector(XMLoadFloat3(&s)) * - XMMatrixRotationQuaternion(XMLoadFloat4(&r)) * - XMMatrixTranslationFromVector(XMLoadFloat3(&t)) - ); - } - break; - case 't': - { - float x, y, z; - file >> x >> y >> z; - light->Translate(XMFLOAT3(x, y, z)); - break; - } - case 'r': - { - float x, y, z, w; - file >> x >> y >> z >> w; - light->Rotate(XMFLOAT4(x, y, z, w)); - break; - } - case 'c': - { - float r, g, b; - file >> r >> g >> b; - light->color = XMFLOAT4(r, g, b, 0); - break; - } - case 'e': - file >> light->enerDis.x; - break; - case 'd': - file >> light->enerDis.y; - break; - case 'n': - light->noHalo = true; - break; - case 'l': - { - string t = ""; - file >> t; - stringstream rim(""); - rim << directory << "rims/" << t; - Texture2D* tex = nullptr; - if ((tex = (Texture2D*)wiResourceManager::GetGlobal()->add(rim.str())) != nullptr) { - light->lensFlareRimTextures.push_back(tex); - light->lensFlareNames.push_back(rim.str()); - } - } - break; - default: break; - } - } - - } - file.close(); -} -void LoadWiCameras(const std::string&directory, const std::string& name, std::list& cameras - , const unordered_set& armatures) -{ - stringstream filename(""); - filename << directory << name; - - ifstream file(filename.str().c_str()); - if (file) - { - string voidStr(""); - file >> voidStr; - while (!file.eof()) { - string line = ""; - file >> line; - switch (line[0]) { - - case 'c': - { - XMFLOAT3 trans; - XMFLOAT4 rot; - string name(""), parentA(""), parentB(""); - file >> name >> parentA >> parentB >> trans.x >> trans.y >> trans.z >> rot.x >> rot.y >> rot.z >> rot.w; - - cameras.push_back(new Camera( - trans, rot - , name) - ); - - for (auto& a : armatures) - { - Bone* b = a->GetBone(parentB); - if (b != nullptr) - { - cameras.back()->attachTo(b); - } - } - - } - break; - case 'I': - { - XMFLOAT3 s, t; - XMFLOAT4 r; - file >> t.x >> t.y >> t.z >> r.x >> r.y >> r.z >> r.w >> s.x >> s.y >> s.z; - XMStoreFloat4x4(&cameras.back()->parent_inv_rest - , XMMatrixScalingFromVector(XMLoadFloat3(&s)) * - XMMatrixRotationQuaternion(XMLoadFloat4(&r)) * - XMMatrixTranslationFromVector(XMLoadFloat3(&t)) - ); - } - break; - default:break; - } - } - } - file.close(); -} -void LoadWiDecals(const std::string&directory, const std::string& name, const std::string& texturesDir, unordered_set& decals) -{ - stringstream filename(""); - filename << directory << name; - - ifstream file(filename.str().c_str()); - if (file) - { - Decal* decal = nullptr; - string voidStr = ""; - file >> voidStr; - while (!file.eof()) - { - string line = ""; - file >> line; - switch (line[0]) - { - case 'd': - { - string name; - XMFLOAT3 loc, scale; - XMFLOAT4 rot; - file >> name >> scale.x >> scale.y >> scale.z >> loc.x >> loc.y >> loc.z >> rot.x >> rot.y >> rot.z >> rot.w; - decal = new Decal(loc, scale, rot); - decal->name = name; - decals.insert(decal); - } - break; - case 't': - { - string tex = ""; - file >> tex; - stringstream ss(""); - ss << directory << texturesDir << tex; - decal->addTexture(ss.str()); - } - break; - case 'n': - { - string tex = ""; - file >> tex; - stringstream ss(""); - ss << directory << texturesDir << tex; - decal->addNormal(ss.str()); - } - break; - default:break; - }; - } - } - file.close(); -} - -Model* ImportModel_WIO(const std::string& fileName) +using namespace wiSceneSystem; +using namespace wiECS; + + +//Mesh* LoadMeshFromBinaryFile(const std::string& newName, const std::string& fname, const std::map& materialColl, const unordered_set& armatures) +//{ +// Mesh* mesh = new Mesh(newName); +// +// BYTE* buffer; +// size_t fileSize; +// if (wiHelper::readByteData(fname, &buffer, fileSize)) { +// +// int offset = 0; +// +// int VERSION; +// memcpy(&VERSION, buffer, sizeof(int)); +// offset += sizeof(int); +// +// if (VERSION >= 1001) { +// int doubleside; +// memcpy(&doubleside, buffer + offset, sizeof(int)); +// offset += sizeof(int); +// if (doubleside) { +// mesh->doubleSided = true; +// } +// } +// +// int billboard; +// memcpy(&billboard, buffer + offset, sizeof(int)); +// offset += sizeof(int); +// if (billboard) { +// char axis; +// memcpy(&axis, buffer + offset, 1); +// offset += 1; +// +// if (toupper(axis) == 'Y') +// mesh->billboardAxis = XMFLOAT3(0, 1, 0); +// else if (toupper(axis) == 'X') +// mesh->billboardAxis = XMFLOAT3(1, 0, 0); +// else if (toupper(axis) == 'Z') +// mesh->billboardAxis = XMFLOAT3(0, 0, 1); +// else +// mesh->billboardAxis = XMFLOAT3(0, 0, 0); +// mesh->isBillboarded = true; +// } +// +// int parented; //parentnamelength +// memcpy(&parented, buffer + offset, sizeof(int)); +// offset += sizeof(int); +// if (parented) { +// char* pName = new char[parented + 1](); +// memcpy(pName, buffer + offset, parented); +// offset += parented; +// mesh->parent = pName; +// delete[] pName; +// +// stringstream identified_parent(""); +// identified_parent << mesh->parent; +// for (Armature* a : armatures) { +// if (!a->name.compare(identified_parent.str())) { +// mesh->armatureName = identified_parent.str(); +// mesh->armature = a; +// } +// } +// } +// +// int materialCount; +// memcpy(&materialCount, buffer + offset, sizeof(int)); +// offset += sizeof(int); +// for (int i = 0; isubsets.push_back(MeshSubset()); +// mesh->subsets.back().material = iter->second; +// //materials.push_back(iter->second); +// } +// +// mesh->materialNames.push_back(identified_matname.str()); +// delete[] matName; +// } +// int rendermesh, vertexCount; +// memcpy(&rendermesh, buffer + offset, sizeof(int)); +// offset += sizeof(int); +// memcpy(&vertexCount, buffer + offset, sizeof(int)); +// offset += sizeof(int); +// +// mesh->vertices_FULL.resize(vertexCount); +// +// for (int i = 0; ivertices_FULL[i].pos.x = v[0]; +// mesh->vertices_FULL[i].pos.y = v[1]; +// mesh->vertices_FULL[i].pos.z = v[2]; +// mesh->vertices_FULL[i].pos.w = 0; +// if (!mesh->isBillboarded) { +// mesh->vertices_FULL[i].nor.x = v[3]; +// mesh->vertices_FULL[i].nor.y = v[4]; +// mesh->vertices_FULL[i].nor.z = v[5]; +// } +// else { +// mesh->vertices_FULL[i].nor.x = mesh->billboardAxis.x; +// mesh->vertices_FULL[i].nor.y = mesh->billboardAxis.y; +// mesh->vertices_FULL[i].nor.z = mesh->billboardAxis.z; +// } +// mesh->vertices_FULL[i].tex.x = v[6]; +// mesh->vertices_FULL[i].tex.y = v[7]; +// int matIndex; +// memcpy(&matIndex, buffer + offset, sizeof(int)); +// offset += sizeof(int); +// mesh->vertices_FULL[i].tex.z = (float)matIndex; +// +// int weightCount = 0; +// memcpy(&weightCount, buffer + offset, sizeof(int)); +// offset += sizeof(int); +// for (int j = 0; jarmature) { +// bool gotBone = false; +// int BONEINDEX = 0; +// int b = 0; +// while (!gotBone && b<(int)mesh->armature->boneCollection.size()) { +// if (!mesh->armature->boneCollection[b]->name.compare(nameB)) { +// gotBone = true; +// BONEINDEX = b; //GOT INDEX OF BONE OF THE WEIGHT IN THE PARENT ARMATURE +// } +// b++; +// } +// if (gotBone) { //ONLY PROCEED IF CORRESPONDING BONE WAS FOUND +// if (!mesh->vertices_FULL[i].wei.x) { +// mesh->vertices_FULL[i].wei.x = weightValue; +// mesh->vertices_FULL[i].ind.x = (float)BONEINDEX; +// } +// else if (!mesh->vertices_FULL[i].wei.y) { +// mesh->vertices_FULL[i].wei.y = weightValue; +// mesh->vertices_FULL[i].ind.y = (float)BONEINDEX; +// } +// else if (!mesh->vertices_FULL[i].wei.z) { +// mesh->vertices_FULL[i].wei.z = weightValue; +// mesh->vertices_FULL[i].ind.z = (float)BONEINDEX; +// } +// else if (!mesh->vertices_FULL[i].wei.w) { +// mesh->vertices_FULL[i].wei.w = weightValue; +// mesh->vertices_FULL[i].ind.w = (float)BONEINDEX; +// } +// } +// } +// +// //(+RIBBONTRAIL SETUP)(+VERTEXGROUP SETUP) +// +// if (nameB.find("trailbase") != string::npos) +// mesh->trailInfo.base = i; +// else if (nameB.find("trailtip") != string::npos) +// mesh->trailInfo.tip = i; +// +// bool windAffection = false; +// if (nameB.find("wind") != string::npos) +// windAffection = true; +// bool gotvg = false; +// for (unsigned int v = 0; vvertexGroups.size(); ++v) +// if (!nameB.compare(mesh->vertexGroups[v].name)) { +// gotvg = true; +// mesh->vertexGroups[v].addVertex(VertexRef(i, weightValue)); +// if (windAffection) +// mesh->vertices_FULL[i].pos.w = weightValue; +// } +// if (!gotvg) { +// mesh->vertexGroups.push_back(VertexGroup(nameB)); +// mesh->vertexGroups.back().addVertex(VertexRef(i, weightValue)); +// if (windAffection) +// mesh->vertices_FULL[i].pos.w = weightValue; +// } +//#pragma endregion +// +// delete[] weightName; +// +// +// } +// +// } +// +// if (rendermesh) { +// int indexCount; +// memcpy(&indexCount, buffer + offset, sizeof(int)); +// offset += sizeof(int); +// unsigned int* indexArray = new unsigned int[indexCount]; +// memcpy(indexArray, buffer + offset, sizeof(unsigned int)*indexCount); +// offset += sizeof(unsigned int)*indexCount; +// mesh->indices.reserve(indexCount); +// for (int i = 0; iindices.push_back(indexArray[i]); +// } +// delete[] indexArray; +// +// int softBody; +// memcpy(&softBody, buffer + offset, sizeof(int)); +// offset += sizeof(int); +// if (softBody) { +// int softCount[2]; //ind,vert +// memcpy(softCount, buffer + offset, sizeof(int) * 2); +// offset += sizeof(int) * 2; +// unsigned int* softind = new unsigned int[softCount[0]]; +// memcpy(softind, buffer + offset, sizeof(unsigned int)*softCount[0]); +// offset += sizeof(unsigned int)*softCount[0]; +// float* softvert = new float[softCount[1]]; +// memcpy(softvert, buffer + offset, sizeof(float)*softCount[1]); +// offset += sizeof(float)*softCount[1]; +// +// mesh->physicsindices.reserve(softCount[0]); +// mesh->physicsverts.reserve(softCount[1] / 3); +// for (int i = 0; iphysicsindices.push_back(softind[i]); +// } +// for (int i = 0; iphysicsverts.push_back(XMFLOAT3(softvert[i], softvert[i + 1], softvert[i + 2])); +// } +// +// delete[] softind; +// delete[] softvert; +// } +// else { +// +// } +// } +// else { +// +// } +// +// memcpy(mesh->aabb.corners, buffer + offset, sizeof(mesh->aabb.corners)); +// offset += sizeof(mesh->aabb.corners); +// +// int isSoftbody; +// memcpy(&isSoftbody, buffer + offset, sizeof(int)); +// offset += sizeof(int); +// if (isSoftbody) { +// float prop[2]; //mass,friction +// memcpy(prop, buffer + offset, sizeof(float) * 2); +// offset += sizeof(float) * 2; +// mesh->softBody = true; +// mesh->mass = prop[0]; +// mesh->friction = prop[1]; +// int vglenghts[3]; //goal,mass,soft +// memcpy(vglenghts, buffer + offset, sizeof(int) * 3); +// offset += sizeof(int) * 3; +// +// char* vgg = new char[vglenghts[0] + 1](); +// char* vgm = new char[vglenghts[1] + 1](); +// char* vgs = new char[vglenghts[2] + 1](); +// +// memcpy(vgg, buffer + offset, vglenghts[0]); +// offset += vglenghts[0]; +// memcpy(vgm, buffer + offset, vglenghts[1]); +// offset += vglenghts[1]; +// memcpy(vgs, buffer + offset, vglenghts[2]); +// offset += vglenghts[2]; +// +// for (unsigned int v = 0; vvertexGroups.size(); ++v) { +// if (!strcmp(vgm, mesh->vertexGroups[v].name.c_str())) +// mesh->massVG = v; +// if (!strcmp(vgg, mesh->vertexGroups[v].name.c_str())) +// mesh->goalVG = v; +// if (!strcmp(vgs, mesh->vertexGroups[v].name.c_str())) +// mesh->softVG = v; +// } +// +// delete[]vgg; +// delete[]vgm; +// delete[]vgs; +// } +// +// delete[] buffer; +// +// mesh->renderable = rendermesh == 0 ? false : true; +// } +// +// return mesh; +//} +// +//void LoadWiArmatures(const std::string& directory, const std::string& name, unordered_set& armatures) +//{ +// stringstream filename(""); +// filename << directory << name; +// +// ifstream file(filename.str().c_str()); +// if (file) +// { +// Armature* armature = nullptr; +// while (!file.eof()) +// { +// float trans[] = { 0,0,0,0 }; +// string line = ""; +// file >> line; +// if (line[0] == '/' && line.substr(2, 8) == "ARMATURE") +// { +// armature = new Armature(line.substr(11, strlen(line.c_str()) - 11)); +// armatures.insert(armature); +// } +// else +// { +// switch (line[0]) +// { +// case 'r': +// file >> trans[0] >> trans[1] >> trans[2] >> trans[3]; +// armature->rotation_rest = XMFLOAT4(trans[0], trans[1], trans[2], trans[3]); +// break; +// case 's': +// file >> trans[0] >> trans[1] >> trans[2]; +// armature->scale_rest = XMFLOAT3(trans[0], trans[1], trans[2]); +// break; +// case 't': +// file >> trans[0] >> trans[1] >> trans[2]; +// armature->translation_rest = XMFLOAT3(trans[0], trans[1], trans[2]); +// //{ +// // XMMATRIX world = XMMatrixScalingFromVector(XMLoadFloat3(&armature->scale))*XMMatrixRotationQuaternion(XMLoadFloat4(&armature->rotation))*XMMatrixTranslationFromVector(XMLoadFloat3(&armature->translation)); +// // XMStoreFloat4x4(&armature->world_rest, world); +// //} +// break; +// case 'b': +// { +// string boneName; +// file >> boneName; +// armature->boneCollection.push_back(new Bone(boneName)); +// } +// break; +// case 'p': +// file >> armature->boneCollection.back()->parentName; +// break; +// case 'l': +// { +// float x = 0, y = 0, z = 0, w = 0; +// file >> x >> y >> z >> w; +// XMVECTOR quaternion = XMVectorSet(x, y, z, w); +// file >> x >> y >> z; +// XMVECTOR translation = XMVectorSet(x, y, z, 0); +// +// XMMATRIX frame; +// frame = XMMatrixRotationQuaternion(quaternion) * XMMatrixTranslationFromVector(translation); +// +// XMStoreFloat3(&armature->boneCollection.back()->translation_rest, translation); +// XMStoreFloat4(&armature->boneCollection.back()->rotation_rest, quaternion); +// XMStoreFloat4x4(&armature->boneCollection.back()->world_rest, frame); +// //XMStoreFloat4x4(&armature->boneCollection.back()->restInv,XMMatrixInverse(0,frame)); +// +// } +// break; +// case 'c': +// armature->boneCollection.back()->connected = true; +// break; +// case 'h': +// file >> armature->boneCollection.back()->length; +// break; +// default: break; +// } +// } +// } +// } +// file.close(); +// +// +// +// //CREATE FAMILY +// for (Armature* armature : armatures) +// { +// armature->UpdateTransform(); +// armature->CreateFamily(); +// } +// +//} +//void LoadWiMaterialLibrary(const std::string& directory, const std::string& name, const std::string& texturesDir, std::map& materials) +//{ +// int materialI = (int)(materials.size() - 1); +// +// Material* currentMat = NULL; +// +// stringstream filename(""); +// filename << directory << name; +// +// ifstream file(filename.str().c_str()); +// if (file) { +// while (!file.eof()) { +// string line = ""; +// file >> line; +// if (line[0] == '/' && !strcmp(line.substr(2, 8).c_str(), "MATERIAL")) { +// if (currentMat) +// { +// currentMat->ConvertToPhysicallyBasedMaterial(); +// materials.insert(pair(currentMat->name, currentMat)); +// } +// +// currentMat = new Material(line.substr(11, strlen(line.c_str()) - 11)); +// materialI++; +// } +// else { +// switch (line[0]) { +// case 'd': +// file >> currentMat->diffuseColor.x; +// file >> currentMat->diffuseColor.y; +// file >> currentMat->diffuseColor.z; +// break; +// case 'X': +// currentMat->cast_shadow = false; +// break; +// case 'r': +// { +// string resourceName = ""; +// file >> resourceName; +// stringstream ss(""); +// ss << directory << texturesDir << resourceName.c_str(); +// currentMat->surfaceMapName = ss.str(); +// currentMat->surfaceMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); +// } +// break; +// case 'n': +// { +// string resourceName = ""; +// file >> resourceName; +// stringstream ss(""); +// ss << directory << texturesDir << resourceName.c_str(); +// currentMat->normalMapName = ss.str(); +// currentMat->normalMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); +// } +// break; +// case 't': +// { +// string resourceName = ""; +// file >> resourceName; +// stringstream ss(""); +// ss << directory << texturesDir << resourceName.c_str(); +// currentMat->textureName = ss.str(); +// currentMat->texture = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); +// } +// file >> currentMat->premultipliedTexture; +// break; +// case 'D': +// { +// string resourceName = ""; +// file >> resourceName; +// stringstream ss(""); +// ss << directory << texturesDir << resourceName.c_str(); +// currentMat->displacementMapName = ss.str(); +// currentMat->displacementMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); +// } +// break; +// case 'S': +// { +// string resourceName = ""; +// file >> resourceName; +// stringstream ss(""); +// ss << directory << texturesDir << resourceName.c_str(); +// currentMat->specularMapName = ss.str(); +// currentMat->specularMap = (Texture2D*)wiResourceManager::GetGlobal()->add(ss.str()); +// } +// break; +// case 'a': +// file >> currentMat->alpha; +// break; +// case 'h': +// currentMat->shadeless = true; +// break; +// case 'R': +// file >> currentMat->refractionIndex; +// break; +// case 'e': +// file >> currentMat->enviroReflection; +// break; +// case 's': +// file >> currentMat->specular.x; +// file >> currentMat->specular.y; +// file >> currentMat->specular.z; +// file >> currentMat->specular.w; +// break; +// case 'p': +// file >> currentMat->specular_power; +// break; +// case 'k': +// currentMat->isSky = true; +// break; +// case 'm': +// file >> currentMat->movingTex.x; +// file >> currentMat->movingTex.y; +// file >> currentMat->movingTex.z; +// currentMat->framesToWaitForTexCoordOffset = currentMat->movingTex.z; +// break; +// case 'w': +// currentMat->water = true; +// break; +// case 'u': +// currentMat->subsurfaceScattering = true; +// break; +// case 'b': +// { +// string blend; +// file >> blend; +// if (!blend.compare("ADD")) +// currentMat->blendFlag = BLENDMODE_ADDITIVE; +// } +// break; +// case 'i': +// { +// file >> currentMat->emissive; +// } +// break; +// default:break; +// } +// } +// } +// } +// file.close(); +// +// if (currentMat) +// { +// currentMat->ConvertToPhysicallyBasedMaterial(); +// materials.insert(pair(currentMat->name, currentMat)); +// } +// +//} +//void LoadWiObjects(const std::string& directory, const std::string& name, unordered_set& objects +// , unordered_set& armatures +// , std::map& meshes, const std::map& materials) +//{ +// +// stringstream filename(""); +// filename << directory << name; +// +// ifstream file(filename.str().c_str()); +// if (file) +// { +// Object* object = nullptr; +// while (!file.eof()) +// { +// float trans[] = { 0,0,0,0 }; +// string line = ""; +// file >> line; +// if (line[0] == '/' && !strcmp(line.substr(2, 6).c_str(), "OBJECT")) +// { +// object = new Object(line.substr(9, strlen(line.c_str()) - 9)); +// objects.insert(object); +// } +// else +// { +// switch (line[0]) +// { +// case 'm': +// { +// string meshName = ""; +// file >> meshName; +// object->meshName = meshName; +// auto& iter = meshes.find(meshName); +// +// if (line[1] == 'b') +// { +// //binary load mesh in place if not present +// if (iter == meshes.end()) +// { +// stringstream meshFileName(""); +// meshFileName << directory << meshName << ".wimesh"; +// Mesh* mesh = LoadMeshFromBinaryFile(meshName, meshFileName.str(), materials, armatures); +// object->mesh = mesh; +// meshes.insert(pair(meshName, mesh)); +// } +// else +// { +// object->mesh = iter->second; +// } +// } +// else +// { +// if (iter != meshes.end()) +// { +// object->mesh = iter->second; +// } +// } +// } +// break; +// case 'p': +// { +// file >> object->parentName; +// } +// break; +// case 'b': +// { +// file >> object->boneParent; +// } +// break; +// case 'I': +// { +// XMFLOAT3 s, t; +// XMFLOAT4 r; +// file >> t.x >> t.y >> t.z >> r.x >> r.y >> r.z >> r.w >> s.x >> s.y >> s.z; +// XMStoreFloat4x4(&object->parent_inv_rest +// , XMMatrixScalingFromVector(XMLoadFloat3(&s)) * +// XMMatrixRotationQuaternion(XMLoadFloat4(&r)) * +// XMMatrixTranslationFromVector(XMLoadFloat3(&t)) +// ); +// } +// break; +// case 'r': +// file >> trans[0] >> trans[1] >> trans[2] >> trans[3]; +// object->Rotate(XMFLOAT4(trans[0], trans[1], trans[2], trans[3])); +// break; +// case 's': +// file >> trans[0] >> trans[1] >> trans[2]; +// object->Scale(XMFLOAT3(trans[0], trans[1], trans[2])); +// break; +// case 't': +// file >> trans[0] >> trans[1] >> trans[2]; +// object->Translate(XMFLOAT3(trans[0], trans[1], trans[2])); +// break; +// case 'E': +// { +// string systemName, materialName; +// bool visibleEmitter; +// float size, randfac, norfac; +// float count, life, randlife; +// float scaleX, scaleY, rot; +// file >> systemName >> visibleEmitter >> materialName >> size >> randfac >> norfac >> count >> life >> randlife; +// file >> scaleX >> scaleY >> rot; +// +// if (object->mesh) +// { +// object->eParticleSystems.push_back( +// new wiEmittedParticle(systemName, materialName, object, size, randfac, norfac, count, life, randlife, scaleX, scaleY, rot) +// ); +// } +// } +// break; +// case 'H': +// { +// string name, mat, densityG, lenG; +// float len; +// int count; +// file >> name >> mat >> len >> count >> densityG >> lenG; +// +// object->hParticleSystems.push_back(new wiHairParticle(name, len, count, mat, object, densityG, lenG)); +// } +// break; +// case 'P': +// object->rigidBody = true; +// file >> object->collisionShape >> object->mass >> +// object->friction >> object->restitution >> object->damping >> object->physicsType >> +// object->kinematic; +// break; +// case 'T': +// file >> object->transparency; +// break; +// default: break; +// } +// } +// } +// } +// file.close(); +// +//} +//void LoadWiMeshes(const std::string& directory, const std::string& name, std::map& meshes, +// const unordered_set& armatures, const std::map& materials) +//{ +// int meshI = (int)(meshes.size() - 1); +// Mesh* currentMesh = NULL; +// +// stringstream filename(""); +// filename << directory << name; +// +// ifstream file(filename.str().c_str()); +// if (file) { +// while (!file.eof()) +// { +// float trans[] = { 0,0,0,0 }; +// string line = ""; +// file >> line; +// if (line[0] == '/' && !line.substr(2, 4).compare("MESH")) { +// currentMesh = new Mesh(line.substr(7, strlen(line.c_str()) - 7)); +// meshes.insert(pair(currentMesh->name, currentMesh)); +// meshI++; +// } +// else +// { +// switch (line[0]) +// { +// case 'p': +// { +// file >> currentMesh->parent; +// for (auto& a : armatures) +// { +// if (!a->name.compare(currentMesh->parent)) +// { +// currentMesh->armature = a; +// break; +// } +// } +// } +// break; +// case 'v': +// currentMesh->vertices_FULL.push_back(Mesh::Vertex_FULL()); +// file >> currentMesh->vertices_FULL.back().pos.x; +// file >> currentMesh->vertices_FULL.back().pos.y; +// file >> currentMesh->vertices_FULL.back().pos.z; +// break; +// case 'n': +// if (currentMesh->isBillboarded) { +// currentMesh->vertices_FULL.back().nor.x = currentMesh->billboardAxis.x; +// currentMesh->vertices_FULL.back().nor.y = currentMesh->billboardAxis.y; +// currentMesh->vertices_FULL.back().nor.z = currentMesh->billboardAxis.z; +// } +// else { +// file >> currentMesh->vertices_FULL.back().nor.x; +// file >> currentMesh->vertices_FULL.back().nor.y; +// file >> currentMesh->vertices_FULL.back().nor.z; +// } +// break; +// case 'u': +// file >> currentMesh->vertices_FULL.back().tex.x; +// file >> currentMesh->vertices_FULL.back().tex.y; +// break; +// case 'w': +// { +// string nameB; +// float weight = 0; +// int BONEINDEX = 0; +// file >> nameB >> weight; +// bool gotBone = false; +// if (currentMesh->armature != nullptr) { +// int j = 0; +// for (auto& b : currentMesh->armature->boneCollection) +// { +// if (!b->name.compare(nameB)) +// { +// BONEINDEX = j; +// break; +// } +// j++; +// } +// } +// if (gotBone) +// { +// //ONLY PROCEED IF CORRESPONDING BONE WAS FOUND +// if (!currentMesh->vertices_FULL.back().wei.x) { +// currentMesh->vertices_FULL.back().wei.x = weight; +// currentMesh->vertices_FULL.back().ind.x = (float)BONEINDEX; +// } +// else if (!currentMesh->vertices_FULL.back().wei.y) { +// currentMesh->vertices_FULL.back().wei.y = weight; +// currentMesh->vertices_FULL.back().ind.y = (float)BONEINDEX; +// } +// else if (!currentMesh->vertices_FULL.back().wei.z) { +// currentMesh->vertices_FULL.back().wei.z = weight; +// currentMesh->vertices_FULL.back().ind.z = (float)BONEINDEX; +// } +// else if (!currentMesh->vertices_FULL.back().wei.w) { +// currentMesh->vertices_FULL.back().wei.w = weight; +// currentMesh->vertices_FULL.back().ind.w = (float)BONEINDEX; +// } +// } +// +// //(+RIBBONTRAIL SETUP)(+VERTEXGROUP SETUP) +// +// if (nameB.find("trailbase") != string::npos) +// currentMesh->trailInfo.base = (int)(currentMesh->vertices_FULL.size() - 1); +// else if (nameB.find("trailtip") != string::npos) +// currentMesh->trailInfo.tip = (int)(currentMesh->vertices_FULL.size() - 1); +// +// bool windAffection = false; +// if (nameB.find("wind") != string::npos) +// windAffection = true; +// bool gotvg = false; +// for (unsigned int v = 0; vvertexGroups.size(); ++v) +// if (!nameB.compare(currentMesh->vertexGroups[v].name)) { +// gotvg = true; +// currentMesh->vertexGroups[v].addVertex(VertexRef((int)(currentMesh->vertices_FULL.size() - 1), weight)); +// if (windAffection) +// currentMesh->vertices_FULL.back().pos.w = weight; +// } +// if (!gotvg) { +// currentMesh->vertexGroups.push_back(VertexGroup(nameB)); +// currentMesh->vertexGroups.back().addVertex(VertexRef((int)(currentMesh->vertices_FULL.size() - 1), weight)); +// if (windAffection) +// currentMesh->vertices_FULL.back().pos.w = weight; +// } +// } +// break; +// case 'i': +// { +// int count; +// file >> count; +// for (int i = 0; i> index; +// currentMesh->indices.push_back(index); +// } +// break; +// } +// case 'V': +// { +// XMFLOAT3 pos; +// file >> pos.x >> pos.y >> pos.z; +// currentMesh->physicsverts.push_back(pos); +// } +// break; +// case 'I': +// { +// int count; +// file >> count; +// for (int i = 0; i> index; +// currentMesh->physicsindices.push_back(index); +// } +// break; +// } +// case 'm': +// { +// string mName = ""; +// file >> mName; +// currentMesh->materialNames.push_back(mName); +// auto& iter = materials.find(mName); +// if (iter != materials.end()) { +// currentMesh->subsets.push_back(MeshSubset()); +// currentMesh->renderable = true; +// currentMesh->subsets.back().material = (iter->second); +// } +// } +// break; +// case 'a': +// file >> currentMesh->vertices_FULL.back().tex.z; +// break; +// case 'B': +// for (int corner = 0; corner<8; ++corner) { +// file >> currentMesh->aabb.corners[corner].x; +// file >> currentMesh->aabb.corners[corner].y; +// file >> currentMesh->aabb.corners[corner].z; +// } +// break; +// case 'b': +// { +// currentMesh->isBillboarded = true; +// string read = ""; +// file >> read; +// transform(read.begin(), read.end(), read.begin(), toupper); +// if (read.find(toupper('y')) != string::npos) currentMesh->billboardAxis = XMFLOAT3(0, 1, 0); +// else if (read.find(toupper('x')) != string::npos) currentMesh->billboardAxis = XMFLOAT3(1, 0, 0); +// else if (read.find(toupper('z')) != string::npos) currentMesh->billboardAxis = XMFLOAT3(0, 0, 1); +// else currentMesh->billboardAxis = XMFLOAT3(0, 0, 0); +// } +// break; +// case 'S': +// { +// currentMesh->softBody = true; +// string mvgi = "", gvgi = "", svgi = ""; +// file >> currentMesh->mass >> currentMesh->friction >> gvgi >> mvgi >> svgi; +// for (unsigned int v = 0; vvertexGroups.size(); ++v) { +// if (!strcmp(mvgi.c_str(), currentMesh->vertexGroups[v].name.c_str())) +// currentMesh->massVG = v; +// if (!strcmp(gvgi.c_str(), currentMesh->vertexGroups[v].name.c_str())) +// currentMesh->goalVG = v; +// if (!strcmp(svgi.c_str(), currentMesh->vertexGroups[v].name.c_str())) +// currentMesh->softVG = v; +// } +// } +// break; +// default: break; +// } +// } +// } +// } +// file.close(); +// +// if (currentMesh) +// meshes.insert(pair(currentMesh->name, currentMesh)); +// +//} +//void LoadWiActions(const std::string& directory, const std::string& name, unordered_set& armatures) +//{ +// Armature* armatureI = nullptr; +// Bone* boneI = nullptr; +// int firstFrame = INT_MAX; +// +// stringstream filename(""); +// filename << directory << name; +// +// ifstream file(filename.str().c_str()); +// if (file) { +// while (!file.eof()) { +// string line = ""; +// file >> line; +// if (line[0] == '/' && !strcmp(line.substr(2, 8).c_str(), "ARMATURE")) { +// string armaturename = line.substr(11, strlen(line.c_str()) - 11); +// for (auto& a : armatures) +// { +// if (!a->name.compare(armaturename)) { +// armatureI = a; +// break; +// } +// } +// } +// else { +// switch (line[0]) { +// case 'C': +// armatureI->actions.push_back(Action()); +// file >> armatureI->actions.back().name; +// break; +// case 'A': +// file >> armatureI->actions.back().frameCount; +// break; +// case 'b': +// { +// string boneName; +// file >> boneName; +// boneI = armatureI->GetBone(boneName); +// if (boneI != nullptr) +// { +// boneI->actionFrames.resize(armatureI->actions.size()); +// } +// } +// break; +// case 'r': +// { +// int f = 0; +// float x = 0, y = 0, z = 0, w = 0; +// file >> f >> x >> y >> z >> w; +// if (boneI != nullptr) +// { +// boneI->actionFrames.back().keyframesRot.push_back(KeyFrame(f, x, y, z, w)); +// } +// } +// break; +// case 't': +// { +// int f = 0; +// float x = 0, y = 0, z = 0; +// file >> f >> x >> y >> z; +// if (boneI != nullptr) +// { +// boneI->actionFrames.back().keyframesPos.push_back(KeyFrame(f, x, y, z, 0)); +// } +// } +// break; +// case 's': +// { +// int f = 0; +// float x = 0, y = 0, z = 0; +// file >> f >> x >> y >> z; +// if (boneI != nullptr) +// { +// boneI->actionFrames.back().keyframesSca.push_back(KeyFrame(f, x, y, z, 0)); +// } +// } +// break; +// default: break; +// } +// } +// } +// } +// file.close(); +//} +//void LoadWiLights(const std::string& directory, const std::string& name, unordered_set& lights) +//{ +// +// stringstream filename(""); +// filename << directory << name; +// +// ifstream file(filename.str().c_str()); +// if (file) +// { +// Light* light = nullptr; +// while (!file.eof()) +// { +// string line = ""; +// file >> line; +// switch (line[0]) +// { +// case 'P': +// { +// light = new Light(); +// lights.insert(light); +// light->SetType(Light::POINT); +// file >> light->name >> light->shadow; +// } +// break; +// case 'D': +// { +// light = new Light(); +// lights.insert(light); +// light->SetType(Light::DIRECTIONAL); +// file >> light->name; +// light->shadow = true; +// } +// break; +// case 'S': +// { +// light = new Light(); +// lights.insert(light); +// light->SetType(Light::SPOT); +// file >> light->name; +// file >> light->shadow >> light->enerDis.z; +// } +// break; +// case 'p': +// { +// file >> light->parentName; +// } +// break; +// case 'b': +// { +// file >> light->boneParent; +// } +// break; +// case 'I': +// { +// XMFLOAT3 s, t; +// XMFLOAT4 r; +// file >> t.x >> t.y >> t.z >> r.x >> r.y >> r.z >> r.w >> s.x >> s.y >> s.z; +// XMStoreFloat4x4(&light->parent_inv_rest +// , XMMatrixScalingFromVector(XMLoadFloat3(&s)) * +// XMMatrixRotationQuaternion(XMLoadFloat4(&r)) * +// XMMatrixTranslationFromVector(XMLoadFloat3(&t)) +// ); +// } +// break; +// case 't': +// { +// float x, y, z; +// file >> x >> y >> z; +// light->Translate(XMFLOAT3(x, y, z)); +// break; +// } +// case 'r': +// { +// float x, y, z, w; +// file >> x >> y >> z >> w; +// light->Rotate(XMFLOAT4(x, y, z, w)); +// break; +// } +// case 'c': +// { +// float r, g, b; +// file >> r >> g >> b; +// light->color = XMFLOAT4(r, g, b, 0); +// break; +// } +// case 'e': +// file >> light->enerDis.x; +// break; +// case 'd': +// file >> light->enerDis.y; +// break; +// case 'n': +// light->noHalo = true; +// break; +// case 'l': +// { +// string t = ""; +// file >> t; +// stringstream rim(""); +// rim << directory << "rims/" << t; +// Texture2D* tex = nullptr; +// if ((tex = (Texture2D*)wiResourceManager::GetGlobal()->add(rim.str())) != nullptr) { +// light->lensFlareRimTextures.push_back(tex); +// light->lensFlareNames.push_back(rim.str()); +// } +// } +// break; +// default: break; +// } +// } +// +// } +// file.close(); +//} +//void LoadWiCameras(const std::string&directory, const std::string& name, std::list& cameras +// , const unordered_set& armatures) +//{ +// stringstream filename(""); +// filename << directory << name; +// +// ifstream file(filename.str().c_str()); +// if (file) +// { +// string voidStr(""); +// file >> voidStr; +// while (!file.eof()) { +// string line = ""; +// file >> line; +// switch (line[0]) { +// +// case 'c': +// { +// XMFLOAT3 trans; +// XMFLOAT4 rot; +// string name(""), parentA(""), parentB(""); +// file >> name >> parentA >> parentB >> trans.x >> trans.y >> trans.z >> rot.x >> rot.y >> rot.z >> rot.w; +// +// cameras.push_back(new Camera( +// trans, rot +// , name) +// ); +// +// for (auto& a : armatures) +// { +// Bone* b = a->GetBone(parentB); +// if (b != nullptr) +// { +// cameras.back()->attachTo(b); +// } +// } +// +// } +// break; +// case 'I': +// { +// XMFLOAT3 s, t; +// XMFLOAT4 r; +// file >> t.x >> t.y >> t.z >> r.x >> r.y >> r.z >> r.w >> s.x >> s.y >> s.z; +// XMStoreFloat4x4(&cameras.back()->parent_inv_rest +// , XMMatrixScalingFromVector(XMLoadFloat3(&s)) * +// XMMatrixRotationQuaternion(XMLoadFloat4(&r)) * +// XMMatrixTranslationFromVector(XMLoadFloat3(&t)) +// ); +// } +// break; +// default:break; +// } +// } +// } +// file.close(); +//} +//void LoadWiDecals(const std::string&directory, const std::string& name, const std::string& texturesDir, unordered_set& decals) +//{ +// stringstream filename(""); +// filename << directory << name; +// +// ifstream file(filename.str().c_str()); +// if (file) +// { +// Decal* decal = nullptr; +// string voidStr = ""; +// file >> voidStr; +// while (!file.eof()) +// { +// string line = ""; +// file >> line; +// switch (line[0]) +// { +// case 'd': +// { +// string name; +// XMFLOAT3 loc, scale; +// XMFLOAT4 rot; +// file >> name >> scale.x >> scale.y >> scale.z >> loc.x >> loc.y >> loc.z >> rot.x >> rot.y >> rot.z >> rot.w; +// decal = new Decal(loc, scale, rot); +// decal->name = name; +// decals.insert(decal); +// } +// break; +// case 't': +// { +// string tex = ""; +// file >> tex; +// stringstream ss(""); +// ss << directory << texturesDir << tex; +// decal->addTexture(ss.str()); +// } +// break; +// case 'n': +// { +// string tex = ""; +// file >> tex; +// stringstream ss(""); +// ss << directory << texturesDir << tex; +// decal->addNormal(ss.str()); +// } +// break; +// default:break; +// }; +// } +// } +// file.close(); +//} + +Entity ImportModel_WIO(const std::string& fileName) { string directory, name; wiHelper::SplitPath(fileName, directory, name); string extension = wiHelper::toUpper(wiHelper::GetExtensionFromFileName(name)); wiHelper::RemoveExtensionFromFileName(name); - Model* model = new Model; - model->name = name; + return INVALID_ENTITY; - stringstream armatureFilePath(""), materialLibFilePath(""), meshesFilePath(""), objectsFilePath("") - , actionsFilePath(""), lightsFilePath(""), decalsFilePath(""), camerasFilePath(""); + //Model* model = new Model; + //model->name = name; - armatureFilePath << name << ".wia"; - materialLibFilePath << name << ".wim"; - meshesFilePath << name << ".wi"; - objectsFilePath << name << ".wio"; - actionsFilePath << name << ".wiact"; - lightsFilePath << name << ".wil"; - decalsFilePath << name << ".wid"; - camerasFilePath << name << ".wic"; + //stringstream armatureFilePath(""), materialLibFilePath(""), meshesFilePath(""), objectsFilePath("") + // , actionsFilePath(""), lightsFilePath(""), decalsFilePath(""), camerasFilePath(""); - LoadWiArmatures(directory, armatureFilePath.str(), model->armatures); - LoadWiMaterialLibrary(directory, materialLibFilePath.str(), "textures/", model->materials); - LoadWiMeshes(directory, meshesFilePath.str(), model->meshes, model->armatures, model->materials); - LoadWiObjects(directory, objectsFilePath.str(), model->objects, model->armatures, model->meshes, model->materials); - LoadWiActions(directory, actionsFilePath.str(), model->armatures); - LoadWiLights(directory, lightsFilePath.str(), model->lights); - LoadWiDecals(directory, decalsFilePath.str(), "textures/", model->decals); - LoadWiCameras(directory, camerasFilePath.str(), model->cameras, model->armatures); + //armatureFilePath << name << ".wia"; + //materialLibFilePath << name << ".wim"; + //meshesFilePath << name << ".wi"; + //objectsFilePath << name << ".wio"; + //actionsFilePath << name << ".wiact"; + //lightsFilePath << name << ".wil"; + //decalsFilePath << name << ".wid"; + //camerasFilePath << name << ".wic"; - model->FinishLoading(); + //LoadWiArmatures(directory, armatureFilePath.str(), model->armatures); + //LoadWiMaterialLibrary(directory, materialLibFilePath.str(), "textures/", model->materials); + //LoadWiMeshes(directory, meshesFilePath.str(), model->meshes, model->armatures, model->materials); + //LoadWiObjects(directory, objectsFilePath.str(), model->objects, model->armatures, model->meshes, model->materials); + //LoadWiActions(directory, actionsFilePath.str(), model->armatures); + //LoadWiLights(directory, lightsFilePath.str(), model->lights); + //LoadWiDecals(directory, decalsFilePath.str(), "textures/", model->decals); + //LoadWiCameras(directory, camerasFilePath.str(), model->cameras, model->armatures); - return model; + //model->FinishLoading(); + + //return model; } diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp index 39da363cd..d2ab4fd48 100644 --- a/Editor/ObjectWindow.cpp +++ b/Editor/ObjectWindow.cpp @@ -1,15 +1,15 @@ #include "stdafx.h" #include "ObjectWindow.h" -using namespace wiSceneComponents; + +using namespace wiECS; +using namespace wiSceneSystem; ObjectWindow::ObjectWindow(wiGUI* gui) : GUI(gui) { assert(GUI && "Invalid GUI!"); - object = nullptr; - float screenW = (float)wiRenderer::GetDevice()->GetScreenWidth(); float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight(); @@ -22,210 +22,210 @@ ObjectWindow::ObjectWindow(wiGUI* gui) : GUI(gui) float x = 450; float y = 0; - renderableCheckBox = new wiCheckBox("Renderable: "); - renderableCheckBox->SetTooltip("Set object to be participating in rendering."); - renderableCheckBox->SetPos(XMFLOAT2(x, y += 30)); - renderableCheckBox->SetCheck(true); - renderableCheckBox->OnClick([&](wiEventArgs args) { - if (object != nullptr) - { - object->renderable = args.bValue; - } - }); - objectWindow->AddWidget(renderableCheckBox); + //renderableCheckBox = new wiCheckBox("Renderable: "); + //renderableCheckBox->SetTooltip("Set object to be participating in rendering."); + //renderableCheckBox->SetPos(XMFLOAT2(x, y += 30)); + //renderableCheckBox->SetCheck(true); + //renderableCheckBox->OnClick([&](wiEventArgs args) { + // if (object != nullptr) + // { + // object->renderable = args.bValue; + // } + //}); + //objectWindow->AddWidget(renderableCheckBox); - ditherSlider = new wiSlider(0, 1, 0, 1000, "Dither: "); - ditherSlider->SetTooltip("Adjust dithered transparency of the object. This disables some optimizations so performance can be affected."); - ditherSlider->SetSize(XMFLOAT2(100, 30)); - ditherSlider->SetPos(XMFLOAT2(x, y += 30)); - ditherSlider->OnSlide([&](wiEventArgs args) { - if (object != nullptr) - { - object->transparency = args.fValue; - } - }); - objectWindow->AddWidget(ditherSlider); + //ditherSlider = new wiSlider(0, 1, 0, 1000, "Dither: "); + //ditherSlider->SetTooltip("Adjust dithered transparency of the object. This disables some optimizations so performance can be affected."); + //ditherSlider->SetSize(XMFLOAT2(100, 30)); + //ditherSlider->SetPos(XMFLOAT2(x, y += 30)); + //ditherSlider->OnSlide([&](wiEventArgs args) { + // if (object != nullptr) + // { + // object->transparency = args.fValue; + // } + //}); + //objectWindow->AddWidget(ditherSlider); - cascadeMaskSlider = new wiSlider(0, 3, 0, 3, "Cascade Mask: "); - cascadeMaskSlider->SetTooltip("How many shadow cascades to skip when rendering this object into shadow maps? (0: skip none, it will be in all cascades, 1: skip first (biggest cascade), ...etc..."); - cascadeMaskSlider->SetSize(XMFLOAT2(100, 30)); - cascadeMaskSlider->SetPos(XMFLOAT2(x, y += 30)); - cascadeMaskSlider->OnSlide([&](wiEventArgs args) { - if (object != nullptr) - { - object->cascadeMask = args.iValue; - } - }); - objectWindow->AddWidget(cascadeMaskSlider); + //cascadeMaskSlider = new wiSlider(0, 3, 0, 3, "Cascade Mask: "); + //cascadeMaskSlider->SetTooltip("How many shadow cascades to skip when rendering this object into shadow maps? (0: skip none, it will be in all cascades, 1: skip first (biggest cascade), ...etc..."); + //cascadeMaskSlider->SetSize(XMFLOAT2(100, 30)); + //cascadeMaskSlider->SetPos(XMFLOAT2(x, y += 30)); + //cascadeMaskSlider->OnSlide([&](wiEventArgs args) { + // if (object != nullptr) + // { + // object->cascadeMask = args.iValue; + // } + //}); + //objectWindow->AddWidget(cascadeMaskSlider); - colorPicker = new wiColorPicker(GUI, "Object Color"); - colorPicker->SetPos(XMFLOAT2(10, 30)); - colorPicker->RemoveWidgets(); - colorPicker->SetVisible(true); - colorPicker->SetEnabled(true); - colorPicker->OnColorChanged([&](wiEventArgs args) { - if (object != nullptr) - { - object->color = XMFLOAT3(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f)); - } - }); - objectWindow->AddWidget(colorPicker); + //colorPicker = new wiColorPicker(GUI, "Object Color"); + //colorPicker->SetPos(XMFLOAT2(10, 30)); + //colorPicker->RemoveWidgets(); + //colorPicker->SetVisible(true); + //colorPicker->SetEnabled(true); + //colorPicker->OnColorChanged([&](wiEventArgs args) { + // if (object != nullptr) + // { + // object->color = XMFLOAT3(powf(args.color.x, 1.f / 2.2f), powf(args.color.y, 1.f / 2.2f), powf(args.color.z, 1.f / 2.2f)); + // } + //}); + //objectWindow->AddWidget(colorPicker); - y += 60; + //y += 60; - physicsLabel = new wiLabel("PHYSICSLABEL"); - physicsLabel->SetText("PHYSICS SETTINGS"); - physicsLabel->SetPos(XMFLOAT2(x - 30, y += 30)); - physicsLabel->SetSize(XMFLOAT2(150, 20)); - objectWindow->AddWidget(physicsLabel); + //physicsLabel = new wiLabel("PHYSICSLABEL"); + //physicsLabel->SetText("PHYSICS SETTINGS"); + //physicsLabel->SetPos(XMFLOAT2(x - 30, y += 30)); + //physicsLabel->SetSize(XMFLOAT2(150, 20)); + //objectWindow->AddWidget(physicsLabel); - simulationTypeComboBox = new wiComboBox("Simulation Type:"); - simulationTypeComboBox->SetSize(XMFLOAT2(100, 20)); - simulationTypeComboBox->SetPos(XMFLOAT2(x, y += 30)); - simulationTypeComboBox->AddItem("None"); - simulationTypeComboBox->AddItem("Rigid Body"); - simulationTypeComboBox->AddItem("Soft Body"); - simulationTypeComboBox->OnSelect([&](wiEventArgs args) { - if (object != nullptr) - { - wiRenderer::physicsEngine->removeObject(object); + //simulationTypeComboBox = new wiComboBox("Simulation Type:"); + //simulationTypeComboBox->SetSize(XMFLOAT2(100, 20)); + //simulationTypeComboBox->SetPos(XMFLOAT2(x, y += 30)); + //simulationTypeComboBox->AddItem("None"); + //simulationTypeComboBox->AddItem("Rigid Body"); + //simulationTypeComboBox->AddItem("Soft Body"); + //simulationTypeComboBox->OnSelect([&](wiEventArgs args) { + // if (object != nullptr) + // { + // wiRenderer::physicsEngine->removeObject(object); - switch (args.iValue) - { - case 0: - object->rigidBody = false; - if (object->mesh != nullptr) - { - object->mesh->softBody = false; - } + // switch (args.iValue) + // { + // case 0: + // object->rigidBody = false; + // if (object->mesh != nullptr) + // { + // object->mesh->softBody = false; + // } - kinematicCheckBox->SetEnabled(false); - physicsTypeComboBox->SetEnabled(false); - collisionShapeComboBox->SetEnabled(false); - break; - case 1: - object->rigidBody = true; - if (object->mesh != nullptr) - { - object->mesh->softBody = false; - } + // kinematicCheckBox->SetEnabled(false); + // physicsTypeComboBox->SetEnabled(false); + // collisionShapeComboBox->SetEnabled(false); + // break; + // case 1: + // object->rigidBody = true; + // if (object->mesh != nullptr) + // { + // object->mesh->softBody = false; + // } - kinematicCheckBox->SetEnabled(true); - physicsTypeComboBox->SetEnabled(true); - collisionShapeComboBox->SetEnabled(true); - break; - case 2: - object->rigidBody = false; - if (object->mesh != nullptr) - { - object->mesh->softBody = true; - } + // kinematicCheckBox->SetEnabled(true); + // physicsTypeComboBox->SetEnabled(true); + // collisionShapeComboBox->SetEnabled(true); + // break; + // case 2: + // object->rigidBody = false; + // if (object->mesh != nullptr) + // { + // object->mesh->softBody = true; + // } - kinematicCheckBox->SetEnabled(false); - physicsTypeComboBox->SetEnabled(true); - collisionShapeComboBox->SetEnabled(false); - break; - default: - break; - } + // kinematicCheckBox->SetEnabled(false); + // physicsTypeComboBox->SetEnabled(true); + // collisionShapeComboBox->SetEnabled(false); + // break; + // default: + // break; + // } - wiRenderer::physicsEngine->registerObject(object); + // wiRenderer::physicsEngine->registerObject(object); - } - }); - simulationTypeComboBox->SetSelected(0); - simulationTypeComboBox->SetEnabled(true); - simulationTypeComboBox->SetTooltip("Set simulation type."); - objectWindow->AddWidget(simulationTypeComboBox); + // } + //}); + //simulationTypeComboBox->SetSelected(0); + //simulationTypeComboBox->SetEnabled(true); + //simulationTypeComboBox->SetTooltip("Set simulation type."); + //objectWindow->AddWidget(simulationTypeComboBox); - kinematicCheckBox = new wiCheckBox("Kinematic: "); - kinematicCheckBox->SetTooltip("Toggle kinematic behaviour."); - kinematicCheckBox->SetPos(XMFLOAT2(x, y += 30)); - kinematicCheckBox->SetCheck(false); - kinematicCheckBox->OnClick([&](wiEventArgs args) { - if (object != nullptr) - { - wiRenderer::physicsEngine->removeObject(object); + //kinematicCheckBox = new wiCheckBox("Kinematic: "); + //kinematicCheckBox->SetTooltip("Toggle kinematic behaviour."); + //kinematicCheckBox->SetPos(XMFLOAT2(x, y += 30)); + //kinematicCheckBox->SetCheck(false); + //kinematicCheckBox->OnClick([&](wiEventArgs args) { + // if (object != nullptr) + // { + // wiRenderer::physicsEngine->removeObject(object); - object->kinematic = args.bValue; + // object->kinematic = args.bValue; - wiRenderer::physicsEngine->registerObject(object); - } - }); - objectWindow->AddWidget(kinematicCheckBox); + // wiRenderer::physicsEngine->registerObject(object); + // } + //}); + //objectWindow->AddWidget(kinematicCheckBox); - physicsTypeComboBox = new wiComboBox("Contribution Type:"); - physicsTypeComboBox->SetSize(XMFLOAT2(100, 20)); - physicsTypeComboBox->SetPos(XMFLOAT2(x, y += 30)); - physicsTypeComboBox->AddItem("Active"); - physicsTypeComboBox->AddItem("Passive"); - physicsTypeComboBox->OnSelect([&](wiEventArgs args) { - if (object != nullptr) - { - wiRenderer::physicsEngine->removeObject(object); + //physicsTypeComboBox = new wiComboBox("Contribution Type:"); + //physicsTypeComboBox->SetSize(XMFLOAT2(100, 20)); + //physicsTypeComboBox->SetPos(XMFLOAT2(x, y += 30)); + //physicsTypeComboBox->AddItem("Active"); + //physicsTypeComboBox->AddItem("Passive"); + //physicsTypeComboBox->OnSelect([&](wiEventArgs args) { + // if (object != nullptr) + // { + // wiRenderer::physicsEngine->removeObject(object); - switch (args.iValue) - { - case 0: - object->physicsType = "ACTIVE"; - break; - case 1: - object->physicsType = "PASSIVE"; - break; - default: - break; - } + // switch (args.iValue) + // { + // case 0: + // object->physicsType = "ACTIVE"; + // break; + // case 1: + // object->physicsType = "PASSIVE"; + // break; + // default: + // break; + // } - wiRenderer::physicsEngine->registerObject(object); - } - }); - physicsTypeComboBox->SetSelected(0); - physicsTypeComboBox->SetEnabled(true); - physicsTypeComboBox->SetTooltip("Set physics type."); - objectWindow->AddWidget(physicsTypeComboBox); + // wiRenderer::physicsEngine->registerObject(object); + // } + //}); + //physicsTypeComboBox->SetSelected(0); + //physicsTypeComboBox->SetEnabled(true); + //physicsTypeComboBox->SetTooltip("Set physics type."); + //objectWindow->AddWidget(physicsTypeComboBox); - collisionShapeComboBox = new wiComboBox("Collision Shape:"); - collisionShapeComboBox->SetSize(XMFLOAT2(100, 20)); - collisionShapeComboBox->SetPos(XMFLOAT2(x, y += 30)); - collisionShapeComboBox->AddItem("Box"); - collisionShapeComboBox->AddItem("Sphere"); - collisionShapeComboBox->AddItem("Capsule"); - collisionShapeComboBox->AddItem("Convex Hull"); - collisionShapeComboBox->AddItem("Triangle Mesh"); - collisionShapeComboBox->OnSelect([&](wiEventArgs args) { - if (object != nullptr) - { - wiRenderer::physicsEngine->removeObject(object); + //collisionShapeComboBox = new wiComboBox("Collision Shape:"); + //collisionShapeComboBox->SetSize(XMFLOAT2(100, 20)); + //collisionShapeComboBox->SetPos(XMFLOAT2(x, y += 30)); + //collisionShapeComboBox->AddItem("Box"); + //collisionShapeComboBox->AddItem("Sphere"); + //collisionShapeComboBox->AddItem("Capsule"); + //collisionShapeComboBox->AddItem("Convex Hull"); + //collisionShapeComboBox->AddItem("Triangle Mesh"); + //collisionShapeComboBox->OnSelect([&](wiEventArgs args) { + // if (object != nullptr) + // { + // wiRenderer::physicsEngine->removeObject(object); - switch (args.iValue) - { - case 0: - object->collisionShape = "BOX"; - break; - case 1: - object->collisionShape = "SPHERE"; - break; - case 2: - object->collisionShape = "CAPSULE"; - break; - case 3: - object->collisionShape = "CONVEX_HULL"; - break; - case 4: - object->collisionShape = "MESH"; - break; - default: - break; - } + // switch (args.iValue) + // { + // case 0: + // object->collisionShape = "BOX"; + // break; + // case 1: + // object->collisionShape = "SPHERE"; + // break; + // case 2: + // object->collisionShape = "CAPSULE"; + // break; + // case 3: + // object->collisionShape = "CONVEX_HULL"; + // break; + // case 4: + // object->collisionShape = "MESH"; + // break; + // default: + // break; + // } - wiRenderer::physicsEngine->registerObject(object); - } - }); - collisionShapeComboBox->SetSelected(0); - collisionShapeComboBox->SetEnabled(true); - collisionShapeComboBox->SetTooltip("Set rigid body collision shape."); - objectWindow->AddWidget(collisionShapeComboBox); + // wiRenderer::physicsEngine->registerObject(object); + // } + //}); + //collisionShapeComboBox->SetSelected(0); + //collisionShapeComboBox->SetEnabled(true); + //collisionShapeComboBox->SetTooltip("Set rigid body collision shape."); + //objectWindow->AddWidget(collisionShapeComboBox); @@ -233,7 +233,7 @@ ObjectWindow::ObjectWindow(wiGUI* gui) : GUI(gui) objectWindow->Translate(XMFLOAT3(1300, 100, 0)); objectWindow->SetVisible(false); - SetObject(nullptr); + SetEntity(INVALID_ENTITY); } @@ -245,99 +245,101 @@ ObjectWindow::~ObjectWindow() } -void ObjectWindow::SetObject(Object* obj) +void ObjectWindow::SetEntity(Entity entity) { - if (this->object == obj) - return; + this->entity = entity; - object = obj; + //if (this->object == obj) + // return; - if (object != nullptr) - { - renderableCheckBox->SetCheck(object->renderable); - cascadeMaskSlider->SetValue((float)object->cascadeMask); - ditherSlider->SetValue(object->transparency); + //object = obj; - if (object->rigidBody) - { - simulationTypeComboBox->SetSelected(1); - } - else - { - if (object->mesh != nullptr) - { - if (object->mesh->softBody) - { - simulationTypeComboBox->SetSelected(2); - } - else - { - simulationTypeComboBox->SetSelected(0); - } - } - else - { - simulationTypeComboBox->SetSelected(0); - } - } + //if (object != nullptr) + //{ + // renderableCheckBox->SetCheck(object->renderable); + // cascadeMaskSlider->SetValue((float)object->cascadeMask); + // ditherSlider->SetValue(object->transparency); - kinematicCheckBox->SetCheck(object->kinematic); + // if (object->rigidBody) + // { + // simulationTypeComboBox->SetSelected(1); + // } + // else + // { + // if (object->mesh != nullptr) + // { + // if (object->mesh->softBody) + // { + // simulationTypeComboBox->SetSelected(2); + // } + // else + // { + // simulationTypeComboBox->SetSelected(0); + // } + // } + // else + // { + // simulationTypeComboBox->SetSelected(0); + // } + // } - if (!object->physicsType.compare("ACTIVE")) - { - physicsTypeComboBox->SetSelected(0); - } - else if (!object->physicsType.compare("PASSIVE")) - { - physicsTypeComboBox->SetSelected(1); - } + // kinematicCheckBox->SetCheck(object->kinematic); - if (!object->collisionShape.compare("BOX")) - { - collisionShapeComboBox->SetSelected(0); - } - else if (!object->collisionShape.compare("SPHERE")) - { - collisionShapeComboBox->SetSelected(1); - } - else if (!object->collisionShape.compare("CAPSULE")) - { - collisionShapeComboBox->SetSelected(2); - } - else if (!object->collisionShape.compare("CONVEX_HULL")) - { - collisionShapeComboBox->SetSelected(3); - } - else if (!object->collisionShape.compare("MESH")) - { - collisionShapeComboBox->SetSelected(4); - } + // if (!object->physicsType.compare("ACTIVE")) + // { + // physicsTypeComboBox->SetSelected(0); + // } + // else if (!object->physicsType.compare("PASSIVE")) + // { + // physicsTypeComboBox->SetSelected(1); + // } - objectWindow->SetEnabled(true); + // if (!object->collisionShape.compare("BOX")) + // { + // collisionShapeComboBox->SetSelected(0); + // } + // else if (!object->collisionShape.compare("SPHERE")) + // { + // collisionShapeComboBox->SetSelected(1); + // } + // else if (!object->collisionShape.compare("CAPSULE")) + // { + // collisionShapeComboBox->SetSelected(2); + // } + // else if (!object->collisionShape.compare("CONVEX_HULL")) + // { + // collisionShapeComboBox->SetSelected(3); + // } + // else if (!object->collisionShape.compare("MESH")) + // { + // collisionShapeComboBox->SetSelected(4); + // } + + // objectWindow->SetEnabled(true); - switch (simulationTypeComboBox->GetSelected()) - { - case 1: - kinematicCheckBox->SetEnabled(true); - physicsTypeComboBox->SetEnabled(true); - collisionShapeComboBox->SetEnabled(true); - break; - case 2: - kinematicCheckBox->SetEnabled(false); - physicsTypeComboBox->SetEnabled(true); - collisionShapeComboBox->SetEnabled(false); - break; - default: - kinematicCheckBox->SetEnabled(false); - physicsTypeComboBox->SetEnabled(false); - collisionShapeComboBox->SetEnabled(false); - break; - } - } - else - { - objectWindow->SetEnabled(false); - } + // switch (simulationTypeComboBox->GetSelected()) + // { + // case 1: + // kinematicCheckBox->SetEnabled(true); + // physicsTypeComboBox->SetEnabled(true); + // collisionShapeComboBox->SetEnabled(true); + // break; + // case 2: + // kinematicCheckBox->SetEnabled(false); + // physicsTypeComboBox->SetEnabled(true); + // collisionShapeComboBox->SetEnabled(false); + // break; + // default: + // kinematicCheckBox->SetEnabled(false); + // physicsTypeComboBox->SetEnabled(false); + // collisionShapeComboBox->SetEnabled(false); + // break; + // } + //} + //else + //{ + // objectWindow->SetEnabled(false); + //} } diff --git a/Editor/ObjectWindow.h b/Editor/ObjectWindow.h index 43ba8527a..f5895fa26 100644 --- a/Editor/ObjectWindow.h +++ b/Editor/ObjectWindow.h @@ -1,10 +1,5 @@ #pragma once -namespace wiSceneComponents -{ - struct Object; -} - class wiGUI; class wiWindow; class wiLabel; @@ -19,9 +14,8 @@ public: ObjectWindow(wiGUI* gui); ~ObjectWindow(); - void SetObject(wiSceneComponents::Object* obj); - - wiSceneComponents::Object* object; + wiECS::Entity entity; + void SetEntity(wiECS::Entity entity); wiGUI* GUI; diff --git a/Editor/Translator.cpp b/Editor/Translator.cpp index fe0bfba99..11c615898 100644 --- a/Editor/Translator.cpp +++ b/Editor/Translator.cpp @@ -5,7 +5,7 @@ #include "wiMath.h" using namespace wiGraphicsTypes; -using namespace wiSceneComponents; +using namespace wiSceneSystem; GraphicsPSO* pso_solidpart = nullptr; GraphicsPSO* pso_wirepart = nullptr; @@ -17,7 +17,7 @@ int vertexCount_Plane = 0; int vertexCount_Origin = 0; -Translator::Translator() :Transform() +Translator::Translator() :TransformComponent() { prevPointer = XMFLOAT4(0, 0, 0, 0); @@ -191,7 +191,7 @@ void Translator::Update() dragEnded = false; XMFLOAT4 pointer = wiInputManager::GetInstance()->getpointer(); - Camera* cam = wiRenderer::getCamera(); + CameraComponent* cam = wiRenderer::getCamera(); XMVECTOR pos = XMLoadFloat3(&translation); if (enabled) @@ -203,7 +203,7 @@ void Translator::Update() XMMATRIX V = cam->GetView(); XMMATRIX W = XMMatrixIdentity(); - dist = wiMath::Distance(translation, cam->translation) * 0.05f; + dist = wiMath::Distance(translation, cam->Eye) * 0.05f; XMVECTOR o, x, y, z, p, xy, xz, yz; @@ -378,9 +378,9 @@ void Translator::Update() transf *= XMMatrixScaling((1.0f / scale.x) * (scale.x + delta.x), (1.0f / scale.y) * (scale.y + delta.y), (1.0f / scale.z) * (scale.z + delta.z)); } - Transform::transform(transf); + TransformComponent::MatrixTransform(transf); - Transform::applyTransform(); + //TransformComponent::ApplyTransform(); if (!dragging) { @@ -399,7 +399,7 @@ void Translator::Update() dragEnd = world; } dragging = false; - Transform::UpdateTransform(); + TransformComponent::UpdateTransform(); } } @@ -411,12 +411,12 @@ void Translator::Update() dragEnd = world; } dragging = false; - Transform::UpdateTransform(); + TransformComponent::UpdateTransform(); } prevPointer = pointer; } -void Translator::Draw(Camera* camera, GRAPHICSTHREAD threadID) +void Translator::Draw(CameraComponent* camera, GRAPHICSTHREAD threadID) { GraphicsDevice* device = wiRenderer::GetDevice(); diff --git a/Editor/Translator.h b/Editor/Translator.h index 819efca42..31d29744e 100644 --- a/Editor/Translator.h +++ b/Editor/Translator.h @@ -1,13 +1,8 @@ #pragma once #include "CommonInclude.h" -#include "wiSceneComponents.h" +#include "wiSceneSystem.h" -namespace wiSceneComponents -{ - struct Camera; -} - -class Translator : public wiSceneComponents::Transform +class Translator : public wiSceneSystem::TransformComponent { private: XMFLOAT4 prevPointer; @@ -20,7 +15,7 @@ public: ~Translator(); void Update(); - void Draw(wiSceneComponents::Camera* camera, GRAPHICSTHREAD threadID); + void Draw(wiSceneSystem::CameraComponent* camera, GRAPHICSTHREAD threadID); bool enabled; diff --git a/Editor/WorldWindow.cpp b/Editor/WorldWindow.cpp index f0537a456..67bf797ee 100644 --- a/Editor/WorldWindow.cpp +++ b/Editor/WorldWindow.cpp @@ -7,7 +7,7 @@ using namespace std; using namespace wiGraphicsTypes; -using namespace wiSceneComponents; +using namespace wiSceneSystem; WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) { @@ -29,7 +29,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) fogStartSlider->SetSize(XMFLOAT2(100, 30)); fogStartSlider->SetPos(XMFLOAT2(x, y += step)); fogStartSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.fogSEH.x = args.fValue; + wiRenderer::GetScene().fogSEH.x = args.fValue; }); worldWindow->AddWidget(fogStartSlider); @@ -37,7 +37,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) fogEndSlider->SetSize(XMFLOAT2(100, 30)); fogEndSlider->SetPos(XMFLOAT2(x, y += step)); fogEndSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.fogSEH.y = args.fValue; + wiRenderer::GetScene().fogSEH.y = args.fValue; }); worldWindow->AddWidget(fogEndSlider); @@ -45,7 +45,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) fogHeightSlider->SetSize(XMFLOAT2(100, 30)); fogHeightSlider->SetPos(XMFLOAT2(x, y += step)); fogHeightSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.fogSEH.z = args.fValue; + wiRenderer::GetScene().fogSEH.z = args.fValue; }); worldWindow->AddWidget(fogHeightSlider); @@ -53,7 +53,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) cloudinessSlider->SetSize(XMFLOAT2(100, 30)); cloudinessSlider->SetPos(XMFLOAT2(x, y += step)); cloudinessSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.cloudiness = args.fValue; + wiRenderer::GetScene().cloudiness = args.fValue; }); worldWindow->AddWidget(cloudinessSlider); @@ -61,7 +61,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) cloudScaleSlider->SetSize(XMFLOAT2(100, 30)); cloudScaleSlider->SetPos(XMFLOAT2(x, y += step)); cloudScaleSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.cloudScale = args.fValue; + wiRenderer::GetScene().cloudScale = args.fValue; }); worldWindow->AddWidget(cloudScaleSlider); @@ -69,7 +69,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) cloudSpeedSlider->SetSize(XMFLOAT2(100, 30)); cloudSpeedSlider->SetPos(XMFLOAT2(x, y += step)); cloudSpeedSlider->OnSlide([&](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.cloudSpeed = args.fValue; + wiRenderer::GetScene().cloudSpeed = args.fValue; }); worldWindow->AddWidget(cloudSpeedSlider); @@ -113,13 +113,10 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) } // Also, we invalidate all environment probes to reflect the sky changes. - const Scene& scene = wiRenderer::GetScene(); - for (Model* x : scene.models) + Scene& scene = wiRenderer::GetScene(); + for (size_t i = 0; i < scene.probes.GetCount(); ++i) { - for (EnvironmentProbe* probe : x->environmentProbes) - { - probe->isUpToDate = false; - } + scene.probes[i].isUpToDate = false; } }); @@ -136,18 +133,17 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) preset1Button->SetPos(XMFLOAT2(x - 100, y += step * 2)); preset1Button->OnClick([=](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.ambient = XMFLOAT3(0.1f, 0.1f, 0.1f); - wiRenderer::GetScene().worldInfo.horizon = XMFLOAT3(0.3f, 0.3f, 0.4f); - wiRenderer::GetScene().worldInfo.zenith = XMFLOAT3(0.05f, 0.05f, 0.5f); - wiRenderer::GetScene().worldInfo.cloudiness = 0.4f; - wiRenderer::GetScene().worldInfo.fogSEH = XMFLOAT3(100, 1000, 0); + wiRenderer::GetScene().ambient = XMFLOAT3(0.1f, 0.1f, 0.1f); + wiRenderer::GetScene().horizon = XMFLOAT3(0.3f, 0.3f, 0.4f); + wiRenderer::GetScene().zenith = XMFLOAT3(0.05f, 0.05f, 0.5f); + wiRenderer::GetScene().cloudiness = 0.4f; + wiRenderer::GetScene().fogSEH = XMFLOAT3(100, 1000, 0); - for (auto& model : wiRenderer::GetScene().models) + // Also, we invalidate all environment probes to reflect the sky changes. + Scene& scene = wiRenderer::GetScene(); + for (size_t i = 0; i < scene.probes.GetCount(); ++i) { - for (auto& probe : model->environmentProbes) - { - probe->isUpToDate = false; - } + scene.probes[i].isUpToDate = false; } }); @@ -159,18 +155,17 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) preset2Button->SetPos(XMFLOAT2(x - 100, y += step)); preset2Button->OnClick([=](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.ambient = XMFLOAT3(0.02f, 0.02f, 0.02f); - wiRenderer::GetScene().worldInfo.horizon = XMFLOAT3(0.2f, 0.05f, 0.15f); - wiRenderer::GetScene().worldInfo.zenith = XMFLOAT3(0.4f, 0.05f, 0.1f); - wiRenderer::GetScene().worldInfo.cloudiness = 0.36f; - wiRenderer::GetScene().worldInfo.fogSEH = XMFLOAT3(50, 600, 0); + wiRenderer::GetScene().ambient = XMFLOAT3(0.02f, 0.02f, 0.02f); + wiRenderer::GetScene().horizon = XMFLOAT3(0.2f, 0.05f, 0.15f); + wiRenderer::GetScene().zenith = XMFLOAT3(0.4f, 0.05f, 0.1f); + wiRenderer::GetScene().cloudiness = 0.36f; + wiRenderer::GetScene().fogSEH = XMFLOAT3(50, 600, 0); - for (auto& model : wiRenderer::GetScene().models) + // Also, we invalidate all environment probes to reflect the sky changes. + Scene& scene = wiRenderer::GetScene(); + for (size_t i = 0; i < scene.probes.GetCount(); ++i) { - for (auto& probe : model->environmentProbes) - { - probe->isUpToDate = false; - } + scene.probes[i].isUpToDate = false; } }); @@ -182,18 +177,17 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) preset3Button->SetPos(XMFLOAT2(x - 100, y += step)); preset3Button->OnClick([=](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.ambient = XMFLOAT3(0.1f, 0.1f, 0.1f); - wiRenderer::GetScene().worldInfo.horizon = XMFLOAT3(0.38f, 0.38f, 0.38f); - wiRenderer::GetScene().worldInfo.zenith = XMFLOAT3(0.42f, 0.42f, 0.42f); - wiRenderer::GetScene().worldInfo.cloudiness = 0.75f; - wiRenderer::GetScene().worldInfo.fogSEH = XMFLOAT3(0, 500, 0); + wiRenderer::GetScene().ambient = XMFLOAT3(0.1f, 0.1f, 0.1f); + wiRenderer::GetScene().horizon = XMFLOAT3(0.38f, 0.38f, 0.38f); + wiRenderer::GetScene().zenith = XMFLOAT3(0.42f, 0.42f, 0.42f); + wiRenderer::GetScene().cloudiness = 0.75f; + wiRenderer::GetScene().fogSEH = XMFLOAT3(0, 500, 0); - for (auto& model : wiRenderer::GetScene().models) + // Also, we invalidate all environment probes to reflect the sky changes. + Scene& scene = wiRenderer::GetScene(); + for (size_t i = 0; i < scene.probes.GetCount(); ++i) { - for (auto& probe : model->environmentProbes) - { - probe->isUpToDate = false; - } + scene.probes[i].isUpToDate = false; } }); @@ -205,18 +199,17 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) preset4Button->SetPos(XMFLOAT2(x - 100, y += step)); preset4Button->OnClick([=](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.ambient = XMFLOAT3(0.01f, 0.01f, 0.02f); - wiRenderer::GetScene().worldInfo.horizon = XMFLOAT3(0.02f, 0.05f, 0.1f); - wiRenderer::GetScene().worldInfo.zenith = XMFLOAT3(0.01f, 0.02f, 0.04f); - wiRenderer::GetScene().worldInfo.cloudiness = 0.28f; - wiRenderer::GetScene().worldInfo.fogSEH = XMFLOAT3(10, 400, 0); + wiRenderer::GetScene().ambient = XMFLOAT3(0.01f, 0.01f, 0.02f); + wiRenderer::GetScene().horizon = XMFLOAT3(0.02f, 0.05f, 0.1f); + wiRenderer::GetScene().zenith = XMFLOAT3(0.01f, 0.02f, 0.04f); + wiRenderer::GetScene().cloudiness = 0.28f; + wiRenderer::GetScene().fogSEH = XMFLOAT3(10, 400, 0); - for (auto& model : wiRenderer::GetScene().models) + // Also, we invalidate all environment probes to reflect the sky changes. + Scene& scene = wiRenderer::GetScene(); + for (size_t i = 0; i < scene.probes.GetCount(); ++i) { - for (auto& probe : model->environmentProbes) - { - probe->isUpToDate = false; - } + scene.probes[i].isUpToDate = false; } }); @@ -280,13 +273,10 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) eliminateCoarseCascadesButton->SetPos(XMFLOAT2(x - 100, y += step * 3)); eliminateCoarseCascadesButton->OnClick([=](wiEventArgs args) { - const Scene& scene = wiRenderer::GetScene(); - for (Model* x : scene.models) + Scene& scene = wiRenderer::GetScene(); + for (size_t i = 0; i < scene.objects.GetCount(); ++i) { - for (auto& y : x->objects) - { - y->cascadeMask = 1; - } + scene.objects[i].cascadeMask = 1; } }); @@ -301,7 +291,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) ambientColorPicker->SetVisible(false); ambientColorPicker->SetEnabled(true); ambientColorPicker->OnColorChanged([&](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.ambient = XMFLOAT3(args.color.x, args.color.y, args.color.z); + wiRenderer::GetScene().ambient = XMFLOAT3(args.color.x, args.color.y, args.color.z); }); worldWindow->AddWidget(ambientColorPicker); @@ -312,7 +302,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) horizonColorPicker->SetVisible(false); horizonColorPicker->SetEnabled(true); horizonColorPicker->OnColorChanged([&](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.horizon = XMFLOAT3(args.color.x, args.color.y, args.color.z); + wiRenderer::GetScene().horizon = XMFLOAT3(args.color.x, args.color.y, args.color.z); }); worldWindow->AddWidget(horizonColorPicker); @@ -324,7 +314,7 @@ WorldWindow::WorldWindow(wiGUI* gui) : GUI(gui) zenithColorPicker->SetVisible(false); zenithColorPicker->SetEnabled(true); zenithColorPicker->OnColorChanged([&](wiEventArgs args) { - wiRenderer::GetScene().worldInfo.zenith = XMFLOAT3(args.color.x, args.color.y, args.color.z); + wiRenderer::GetScene().zenith = XMFLOAT3(args.color.x, args.color.y, args.color.z); }); worldWindow->AddWidget(zenithColorPicker); @@ -345,7 +335,7 @@ WorldWindow::~WorldWindow() void WorldWindow::UpdateFromRenderer() { - auto& w = wiRenderer::GetScene().worldInfo; + auto& w = wiRenderer::GetScene(); fogStartSlider->SetValue(w.fogSEH.x); fogEndSlider->SetValue(w.fogSEH.y); diff --git a/Editor/config.ini b/Editor/config.ini index ec54bb12e..02369148f 100644 --- a/Editor/config.ini +++ b/Editor/config.ini @@ -1,7 +1,7 @@ enabled 0 x 0 y 0 -w 1920 -h 1080 +w 3840 +h 2160 fullscreen 0 borderless 1 \ No newline at end of file diff --git a/Editor/startup.lua b/Editor/startup.lua index e6f5f9514..d2dfe2e37 100644 --- a/Editor/startup.lua +++ b/Editor/startup.lua @@ -28,6 +28,11 @@ -- end -- end) +--LoadModel("C:/PROJECTS/glTF-Sample-Models-master/2.0/CesiumMan/glTF/CesiumMan.gltf") +--LoadModel("C:/PROJECTS/WickedEngine/models/girl/girl.wimf", matrix.Translation(Vector(5))) +--LoadModel("C:/PROJECTS/WickedEngine/models/girl/girl", matrix.Translation(Vector(10))) +--SetDebugBonesEnabled(true) + main.SetResolutionDisplay(true); runProcess(function() while true do diff --git a/WickedEngine/wiECS.h b/WickedEngine/wiECS.h index 87c4eb085..d55cde85f 100644 --- a/WickedEngine/wiECS.h +++ b/WickedEngine/wiECS.h @@ -10,6 +10,11 @@ namespace wiECS { typedef uint64_t Entity; static const Entity INVALID_ENTITY = 0; + inline Entity CreateEntity() + { + static Entity id = 0; + return ++id; + } template class ComponentManager @@ -37,6 +42,7 @@ namespace wiECS inline ref operator++(int v) { ref temp = *this; ++*this; return temp; } inline ref& operator--() { value--; return *this; } inline ref operator--(int v) { ref temp = *this; --*this; return temp; } + inline operator bool() const { return value != ~0; } }; // Clear the whole container, invalidate all refs @@ -174,6 +180,17 @@ namespace wiECS return ref(); } + // Retrieve a component specified by an entity (if it exists, otherwise nullptr): + inline T* GetComponent(Entity entity) + { + ref it = Find(entity); + if (it) + { + return &components[indices[it.value]]; + } + return nullptr; + } + // Retrieve a component specified by an ref (ref is safe but uses indirection): inline T& GetComponent(ref it) { @@ -190,14 +207,6 @@ namespace wiECS // Retrieve the number of existing entries: inline size_t GetCount() const { return components.size(); } - // Directly index a specific component without indirection: - // 0 <= index < GetCount() - inline T& GetComponent(size_t index) { return components[index]; } - - // Directly index a specific component without indirection: - // 0 <= index < GetCount() - inline const T& GetComponent(size_t index) const { return components[index]; } - // Directly index a specific component without indirection: // 0 <= index < GetCount() inline Entity GetEntity(size_t index) const { return entities[index]; } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index d57c6b1cb..04477f252 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -482,7 +482,7 @@ public: struct RayIntersectWorldResult { - wiECS::ComponentManager::ref object_ref; + wiECS::Entity entity; XMFLOAT3 position = XMFLOAT3(0, 0, 0); XMFLOAT3 normal = XMFLOAT3(0, 0, 0); float distance = FLT_MAX; diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index 76a3d88fa..22400e2da 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -51,6 +51,14 @@ namespace wiSceneSystem XMStoreFloat4x4(&world, W); } } + void TransformComponent::ApplyTransform() + { + dirty = true; + + scale_local = scale; + rotation_local = rotation; + translation_local = translation; + } void TransformComponent::ClearTransform() { dirty = true; @@ -94,9 +102,32 @@ namespace wiSceneSystem { dirty = true; - scale_local.x += value.x; - scale_local.y += value.y; - scale_local.z += value.z; + scale_local.x *= value.x; + scale_local.y *= value.y; + scale_local.z *= value.z; + } + void TransformComponent::MatrixTransform(const XMFLOAT4X4& matrix) + { + MatrixTransform(XMLoadFloat4x4(&matrix)); + } + void TransformComponent::MatrixTransform(const XMMATRIX& matrix) + { + dirty = true; + + XMVECTOR S_local = XMLoadFloat3(&scale_local); + XMVECTOR R_local = XMLoadFloat4(&rotation_local); + XMVECTOR T_local = XMLoadFloat3(&translation_local); + XMMATRIX W = + XMMatrixScalingFromVector(S_local) * + XMMatrixRotationQuaternion(R_local) * + XMMatrixTranslationFromVector(T_local); + + W = W * matrix; + + XMMatrixDecompose(&S_local, &R_local, &T_local, W); + XMStoreFloat3(&scale_local, S_local); + XMStoreFloat4(&rotation_local, R_local); + XMStoreFloat3(&translation_local, T_local); } void TransformComponent::Lerp(const TransformComponent& a, const TransformComponent& b, float t) { @@ -186,6 +217,26 @@ namespace wiSceneSystem return wiTextureHelper::getInstance()->getWhite(); } + void CameraComponent::UpdateProjection() + { + XMMATRIX P = XMMatrixPerspectiveFovLH(fov, width / height, zFarP, zNearP); // reverse zbuffer! + XMStoreFloat4x4(&realProjection, XMMatrixPerspectiveFovLH(fov, width / height, zNearP, zFarP)); + XMMATRIX InvP = XMMatrixInverse(nullptr, P); + XMStoreFloat4x4(&Projection, P); + XMStoreFloat4x4(&InvProjection, InvP); + } + void CameraComponent::BakeMatrices() + { + XMMATRIX V = XMLoadFloat4x4(&View); + XMMATRIX P = XMLoadFloat4x4(&Projection); + XMMATRIX VP = XMMatrixMultiply(V, P); + XMStoreFloat4x4(&this->VP, VP); + XMStoreFloat4x4(&InvView, XMMatrixInverse(nullptr, V)); + XMStoreFloat4x4(&InvVP, XMMatrixInverse(nullptr, VP)); + XMStoreFloat4x4(&Projection, P); + XMStoreFloat4x4(&InvProjection, XMMatrixInverse(nullptr, P)); + } + void Scene::Update(float dt) { // Update Transform components: @@ -193,9 +244,7 @@ namespace wiSceneSystem { auto& transform = transforms[i]; - const bool parented = transforms.IsValid(transform.parent_ref); - const TransformComponent* parent = parented ? &transforms.GetComponent(transform.parent_ref) : nullptr; - + const TransformComponent* parent = transform.parentID != INVALID_ENTITY ? transforms.GetComponent(transform.parentID) : nullptr; transform.UpdateTransform(parent); //if (transform.dirty || parented) diff --git a/WickedEngine/wiSceneSystem.h b/WickedEngine/wiSceneSystem.h index 7b91a0f3a..1366357e6 100644 --- a/WickedEngine/wiSceneSystem.h +++ b/WickedEngine/wiSceneSystem.h @@ -26,7 +26,7 @@ namespace wiSceneSystem struct TransformComponent { - wiECS::ComponentManager::ref parent_ref; + wiECS::Entity parentID = wiECS::INVALID_ENTITY; XMFLOAT3 scale_local = XMFLOAT3(1, 1, 1); XMFLOAT4 rotation_local = XMFLOAT4(0, 0, 0, 1); @@ -42,11 +42,14 @@ namespace wiSceneSystem void AttachTo(const TransformComponent* const parent); void UpdateTransform(const TransformComponent* const parent = nullptr); + void ApplyTransform(); void ClearTransform(); void Translate(const XMFLOAT3& value); void RotateRollPitchYaw(const XMFLOAT3& value); void Rotate(const XMFLOAT4& quaternion); void Scale(const XMFLOAT3& value); + void MatrixTransform(const XMFLOAT4X4& matrix); + void MatrixTransform(const XMMATRIX& matrix); void Lerp(const TransformComponent& a, const TransformComponent& b, float t); void CatmullRom(const TransformComponent& a, const TransformComponent& b, const TransformComponent& c, const TransformComponent& d, float t); }; @@ -435,6 +438,9 @@ namespace wiSceneSystem XMFLOAT4X4 InvView, InvProjection, InvVP; XMFLOAT4X4 realProjection; // because reverse zbuffering projection complicates things... + void UpdateProjection(); + void BakeMatrices(); + inline XMVECTOR GetEye() const { return XMLoadFloat3(&Eye); } inline XMVECTOR GetAt() const { return XMLoadFloat3(&At); } inline XMVECTOR GetUp() const { return XMLoadFloat3(&Up); }