ecs serializers update + general refactors

This commit is contained in:
turanszkij
2018-09-19 18:16:36 +01:00
parent 9a2e810e2a
commit 26a12876bb
34 changed files with 1065 additions and 600 deletions
+9 -7
View File
@@ -11,7 +11,7 @@ void CameraWindow::ResetCam()
camera_transform.ClearTransform();
camera_transform.Translate(XMFLOAT3(0, 2, -10));
camera_transform.UpdateTransform();
wiRenderer::getCamera()->UpdateCamera(&camera_transform);
wiRenderer::GetCamera().UpdateCamera(&camera_transform);
camera_target.ClearTransform();
camera_target.UpdateTransform();
@@ -24,6 +24,8 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui)
float screenW = (float)wiRenderer::GetDevice()->GetScreenWidth();
float screenH = (float)wiRenderer::GetDevice()->GetScreenHeight();
camera_transform.MatrixTransform(wiRenderer::GetCamera().GetInvView());
cameraWindow = new wiWindow(GUI, "Camera Window");
cameraWindow->SetSize(XMFLOAT2(600, 420));
GUI->AddWidget(cameraWindow);
@@ -35,10 +37,10 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui)
farPlaneSlider = new wiSlider(1, 5000, 1000, 100000, "Far Plane: ");
farPlaneSlider->SetSize(XMFLOAT2(100, 30));
farPlaneSlider->SetPos(XMFLOAT2(x, y += inc));
farPlaneSlider->SetValue(wiRenderer::getCamera()->zFarP);
farPlaneSlider->SetValue(wiRenderer::GetCamera().zFarP);
farPlaneSlider->OnSlide([&](wiEventArgs args) {
Scene& scene = wiRenderer::GetScene();
CameraComponent& camera = *wiRenderer::getCamera();
CameraComponent& camera = wiRenderer::GetCamera();
camera.zFarP = args.fValue;
camera.UpdateProjection();
});
@@ -47,10 +49,10 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui)
nearPlaneSlider = new wiSlider(0.01f, 10, 0.1f, 10000, "Near Plane: ");
nearPlaneSlider->SetSize(XMFLOAT2(100, 30));
nearPlaneSlider->SetPos(XMFLOAT2(x, y += inc));
nearPlaneSlider->SetValue(wiRenderer::getCamera()->zNearP);
nearPlaneSlider->SetValue(wiRenderer::GetCamera().zNearP);
nearPlaneSlider->OnSlide([&](wiEventArgs args) {
Scene& scene = wiRenderer::GetScene();
CameraComponent& camera = *wiRenderer::getCamera();
CameraComponent& camera = wiRenderer::GetCamera();
camera.zNearP = args.fValue;
camera.UpdateProjection();
});
@@ -61,7 +63,7 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui)
fovSlider->SetPos(XMFLOAT2(x, y += inc));
fovSlider->OnSlide([&](wiEventArgs args) {
Scene& scene = wiRenderer::GetScene();
CameraComponent& camera = *wiRenderer::getCamera();
CameraComponent& camera = wiRenderer::GetCamera();
camera.fov = args.fValue / 180.f * XM_PI;
camera.UpdateProjection();
});
@@ -98,7 +100,7 @@ CameraWindow::CameraWindow(wiGUI* gui) :GUI(gui)
proxyButton->SetPos(XMFLOAT2(x, y += inc * 2));
proxyButton->OnClick([&](wiEventArgs args) {
CameraComponent& camera = *wiRenderer::getCamera();
const CameraComponent& camera = wiRenderer::GetCamera();
Scene& scene = wiRenderer::GetScene();
+87 -196
View File
@@ -565,8 +565,9 @@ void EditorComponent::Load()
wiArchive archive(fileName, true);
if (archive.IsOpen())
{
Scene& scene = wiRenderer::GetScene();
Scene scene;
scene.Serialize(archive);
wiRenderer::GetScene().Merge(scene);
}
}
else if (!extension.compare("OBJ")) // wavefront-obj
@@ -586,7 +587,7 @@ void EditorComponent::Load()
main->activateComponent(this, 10, wiColor::Black);
worldWnd->UpdateFromRenderer();
});
main->activateComponent(loader,10,wiColor::Black);
main->activateComponent(loader, 10, wiColor::Black);
ResetHistory();
}
}).detach();
@@ -696,9 +697,8 @@ void EditorComponent::Load()
ss << "Delete: DELETE button" << endl;
ss << "Script Console / backlog: HOME button" << endl;
ss << endl;
ss << "You can find sample models in the models directory. Try to load one." << endl;
ss << "You can also import models from .OBJ, .GLTF, .GLB, .WIO files." << endl;
ss << "You can also export models from Blender with the io_export_wicked_wi_bin.py script." << endl;
ss << "You can find sample scenes in the models directory. Try to load one." << endl;
ss << "You can also import models from .OBJ, .GLTF, .GLB files." << endl;
ss << "You can find a program configuration file at Editor/config.ini" << endl;
ss << "You can find sample LUA scripts in the scripts directory. Try to load one." << endl;
ss << "You can find a startup script at Editor/startup.lua (this will be executed on program start)" << endl;
@@ -759,7 +759,7 @@ void EditorComponent::FixedUpdate()
void EditorComponent::Update(float dt)
{
Scene& scene = wiRenderer::GetScene();
CameraComponent& camera = *wiRenderer::getCamera();
CameraComponent& camera = wiRenderer::GetCamera();
// Follow camera proxy:
if (cameraWnd->followCheckBox->IsEnabled() && cameraWnd->followCheckBox->GetCheck())
@@ -867,6 +867,7 @@ void EditorComponent::Update(float dt)
XMStoreFloat3(&_move, move_rot);
cameraWnd->camera_transform.Translate(_move);
cameraWnd->camera_transform.RotateRollPitchYaw(XMFLOAT3(yDif, xDif, 0));
camera.SetDirty();
}
cameraWnd->camera_transform.UpdateTransform();
@@ -885,20 +886,21 @@ void EditorComponent::Update(float dt)
else if (wiInputManager::GetInstance()->down(VK_LCONTROL))
{
cameraWnd->camera_transform.Translate(XMFLOAT3(0, 0, yDif * 4));
camera.SetDirty();
}
else if(abs(xDif) + abs(yDif) > 0)
{
cameraWnd->camera_target.RotateRollPitchYaw(XMFLOAT3(yDif*2, xDif*2, 0));
camera.SetDirty();
}
cameraWnd->camera_target.UpdateTransform();
cameraWnd->camera_transform.UpdateParentedTransform(cameraWnd->camera_target);
}
camera.UpdateCamera(&cameraWnd->camera_transform);
// Begin picking:
UINT pickMask = rendererWnd->GetPickType();
RAY pickRay = wiRenderer::getPickRay((long)currentMouse.x, (long)currentMouse.y);
RAY pickRay = wiRenderer::GetPickRay((long)currentMouse.x, (long)currentMouse.y);
{
hovered.Clear();
@@ -1083,7 +1085,7 @@ void EditorComponent::Update(float dt)
TransformComponent& transform = *scene.transforms.GetComponent(entity);
transform.Translate(hovered.position);
transform.Scale(XMFLOAT3(4, 4, 4));
transform.MatrixTransform(XMLoadFloat3x3(&wiRenderer::getCamera()->rotationMatrix));
transform.MatrixTransform(XMLoadFloat3x3(&wiRenderer::GetCamera().rotationMatrix));
scene.Component_Attach(entity, hovered.entity);
}
}
@@ -1192,7 +1194,6 @@ void EditorComponent::Update(float dt)
assert(picked.entity != INVALID_ENTITY);
objectWnd->SetEntity(picked.entity);
emitterWnd->SetEntity(picked.entity);
hairWnd->SetEntity(picked.entity);
@@ -1205,10 +1206,16 @@ void EditorComponent::Update(float dt)
if (picked.subsetIndex >= 0)
{
const ObjectComponent* object = scene.objects.GetComponent(picked.entity);
meshWnd->SetEntity(object->meshID);
if (object != nullptr) // maybe it was deleted...
{
meshWnd->SetEntity(object->meshID);
const MeshComponent* mesh = scene.meshes.GetComponent(object->meshID);
materialWnd->SetEntity(mesh->subsets[picked.subsetIndex].materialID);
const MeshComponent* mesh = scene.meshes.GetComponent(object->meshID);
if (mesh != nullptr && mesh->subsets.size() > picked.subsetIndex)
{
materialWnd->SetEntity(mesh->subsets[picked.subsetIndex].materialID);
}
}
}
else
{
@@ -1217,101 +1224,30 @@ void EditorComponent::Update(float dt)
}
//// 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))
{
// 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);
// }
wiArchive* archive = AdvanceHistory();
*archive << HISTORYOP_DELETE;
// wiRenderer::Remove(x->object);
// SAFE_DELETE(x->object);
// x->transform = nullptr;
// }
// else
// {
// *archive << false;
// }
*archive << selected.size();
for (auto& x : selected)
{
*archive << x.entity;
}
for (auto& x : selected)
{
scene.Entity_Serialize(*archive, x.entity);
}
for (auto& x : selected)
{
scene.Entity_Remove(x.entity);
savedHierarchy.Remove_KeepSorted(x.entity);
}
// if (x->light != nullptr)
// {
// *archive << true;
// x->light->Serialize(*archive);
// wiRenderer::Remove(x->light);
// SAFE_DELETE(x->light);
// x->transform = nullptr;
// }
// else
// {
// *archive << false;
// }
// if (x->decal != nullptr)
// {
// *archive << true;
// x->decal->Serialize(*archive);
// wiRenderer::Remove(x->decal);
// SAFE_DELETE(x->decal);
// x->transform = nullptr;
// }
// else
// {
// *archive << false;
// }
// if (x->forceField != nullptr)
// {
// *archive << true;
// x->forceField->Serialize(*archive);
// wiRenderer::Remove(x->forceField);
// SAFE_DELETE(x->forceField);
// x->transform = nullptr;
// }
// else
// {
// *archive << false;
// }
// if (x->camera != nullptr)
// {
// *archive << true;
// x->camera->Serialize(*archive);
// wiRenderer::Remove(x->camera);
// SAFE_DELETE(x->camera);
// x->camera = nullptr;
// }
// else
// {
// *archive << false;
// }
// EnvironmentProbe* envProbe = dynamic_cast<EnvironmentProbe*>(x->transform);
// if (envProbe != nullptr)
// {
// wiRenderer::Remove(envProbe);
// SAFE_DELETE(envProbe);
// }
// }
// ClearSelected();
//}
EndTranslate();
}
// Control operations...
if (wiInputManager::GetInstance()->down(VK_CONTROL))
@@ -1439,6 +1375,8 @@ void EditorComponent::Update(float dt)
__super::Update(dt);
renderPath->Update(dt);
camera.UpdateCamera(&cameraWnd->camera_transform);
}
void EditorComponent::Render()
{
@@ -1565,7 +1503,7 @@ void EditorComponent::Compose()
return;
}
CameraComponent* camera = wiRenderer::getCamera();
const CameraComponent& camera = wiRenderer::GetCamera();
Scene& scene = wiRenderer::GetScene();
@@ -1577,7 +1515,7 @@ void EditorComponent::Compose()
Entity entity = scene.lights.GetEntity(i);
const TransformComponent& transform = *scene.transforms.GetComponent(entity);
float dist = wiMath::Distance(transform.GetPosition(), camera->Eye) * 0.08f;
float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f;
wiImageEffects fx;
fx.pos = transform.GetPosition();
@@ -1625,7 +1563,7 @@ void EditorComponent::Compose()
Entity entity = scene.decals.GetEntity(i);
const TransformComponent& transform = *scene.transforms.GetComponent(entity);
float dist = wiMath::Distance(transform.GetPosition(), camera->Eye) * 0.08f;
float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f;
wiImageEffects fx;
fx.pos = transform.GetPosition();
@@ -1660,7 +1598,7 @@ void EditorComponent::Compose()
Entity entity = scene.forces.GetEntity(i);
const TransformComponent& transform = *scene.transforms.GetComponent(entity);
float dist = wiMath::Distance(transform.GetPosition(), camera->Eye) * 0.08f;
float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f;
wiImageEffects fx;
fx.pos = transform.GetPosition();
@@ -1695,7 +1633,7 @@ void EditorComponent::Compose()
const TransformComponent& transform = *scene.transforms.GetComponent(entity);
float dist = wiMath::Distance(transform.GetPosition(), camera->Eye) * 0.08f;
float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f;
wiImageEffects fx;
fx.pos = transform.GetPosition();
@@ -1729,7 +1667,7 @@ void EditorComponent::Compose()
Entity entity = scene.armatures.GetEntity(i);
const TransformComponent& transform = *scene.transforms.GetComponent(entity);
float dist = wiMath::Distance(transform.GetPosition(), camera->Eye) * 0.08f;
float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f;
wiImageEffects fx;
fx.pos = transform.GetPosition();
@@ -1763,7 +1701,7 @@ void EditorComponent::Compose()
Entity entity = scene.emitters.GetEntity(i);
const TransformComponent& transform = *scene.transforms.GetComponent(entity);
float dist = wiMath::Distance(transform.GetPosition(), camera->Eye) * 0.08f;
float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f;
wiImageEffects fx;
fx.pos = transform.GetPosition();
@@ -1797,7 +1735,7 @@ void EditorComponent::Compose()
Entity entity = scene.hairs.GetEntity(i);
const TransformComponent& transform = *scene.transforms.GetComponent(entity);
float dist = wiMath::Distance(transform.GetPosition(), camera->Eye) * 0.08f;
float dist = wiMath::Distance(transform.GetPosition(), camera.Eye) * 0.08f;
wiImageEffects fx;
fx.pos = transform.GetPosition();
@@ -1932,14 +1870,15 @@ void EditorComponent::EndTranslate()
{
// Save the parent's inverse worldmatrix:
XMStoreFloat4x4(&parent->world_parent_inverse_bind, XMMatrixInverse(nullptr, XMLoadFloat4x4(&transform_parent->world)));
TransformComponent* transform_child = scene.transforms.GetComponent(x.entity);
if (transform_child != nullptr)
{
// Child updated immediately, to that it can be immediately attached to afterwards:
transform_child->UpdateParentedTransform(*transform_parent, parent->world_parent_inverse_bind);
}
}
TransformComponent* transform_child = scene.transforms.GetComponent(x.entity);
if (transform_child != nullptr)
{
// Child updated immediately, to that it can be immediately attached to afterwards:
transform_child->UpdateParentedTransform(*transform_parent, parent->world_parent_inverse_bind);
}
}
}
@@ -2010,7 +1949,9 @@ void EditorComponent::ConsumeHistoryOperation(bool undo)
*archive >> start >> end;
translator.enabled = true;
TransformComponent& transform = *wiRenderer::GetScene().transforms.GetComponent(translator.entityID);
Scene& scene = wiRenderer::GetScene();
TransformComponent& transform = *scene.transforms.GetComponent(translator.entityID);
transform.ClearTransform();
if (undo)
{
@@ -2022,85 +1963,35 @@ void EditorComponent::ConsumeHistoryOperation(bool undo)
}
}
break;
//case HISTORYOP_DELETE:
// {
// Model* model = nullptr;
// if (undo)
// {
// model = new Model;
// }
case HISTORYOP_DELETE:
{
Scene& scene = wiRenderer::GetScene();
// 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;
vector<Entity> deletedEntities(count);
for (size_t i = 0; i < count; ++i)
{
*archive >> deletedEntities[i];
}
if (undo)
{
for (size_t i = 0; i < count; ++i)
{
scene.Entity_Serialize(*archive);
}
}
else
{
for (size_t i = 0; i < count; ++i)
{
scene.Entity_Remove(deletedEntities[i]);
}
}
// 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);
// }
// }
// // 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);
// }
// // 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;
}
break;
case HISTORYOP_SELECTION:
{
EndTranslate();
+1 -1
View File
@@ -35,7 +35,7 @@ EnvProbeWindow::EnvProbeWindow(wiGUI* gui) : GUI(gui)
generateButton->SetPos(XMFLOAT2(x, y += step));
generateButton->OnClick([](wiEventArgs args) {
XMFLOAT3 pos;
XMStoreFloat3(&pos, XMVectorAdd(wiRenderer::getCamera()->GetEye(), wiRenderer::getCamera()->GetAt() * 4));
XMStoreFloat3(&pos, XMVectorAdd(wiRenderer::GetCamera().GetEye(), wiRenderer::GetCamera().GetAt() * 4));
wiRenderer::GetScene().Entity_CreateEnvironmentProbe("editorProbe", pos);
});
envProbeWindow->AddWidget(generateButton);
+2 -4
View File
@@ -1,8 +1,6 @@
#pragma once
#include "wiECS.h"
#include <string>
wiECS::Entity ImportModel_OBJ(const std::string& fileName);
wiECS::Entity ImportModel_GLTF(const std::string& fileName);
void ImportModel_OBJ(const std::string& fileName);
void ImportModel_GLTF(const std::string& fileName);
+34 -31
View File
@@ -1,4 +1,5 @@
#include "stdafx.h"
#include "wiSceneSystem.h"
#include "ModelImporter.h"
#include "Utility/stb_image.h"
@@ -148,7 +149,7 @@ void RegisterTexture2D(tinygltf::Image *image)
struct LoaderState
{
tinygltf::Model gltfModel;
Entity modelEntity;
Scene scene;
unordered_map<const tinygltf::Node*, Entity> entityMap;
vector<Entity> materialArray;
vector<Entity> meshArray;
@@ -163,14 +164,12 @@ void LoadNode(tinygltf::Node* node, Entity parent, LoaderState& state)
return;
}
Scene& scene = wiRenderer::GetScene();
Entity entity = INVALID_ENTITY;
if(node->mesh >= 0)
{
entity = scene.Entity_CreateObject(node->name);
ObjectComponent& object = *scene.objects.GetComponent(entity);
entity = state.scene.Entity_CreateObject(node->name);
ObjectComponent& object = *state.scene.objects.GetComponent(entity);
if (node->mesh < state.meshArray.size())
{
@@ -178,7 +177,7 @@ void LoadNode(tinygltf::Node* node, Entity parent, LoaderState& state)
if (node->skin >= 0)
{
MeshComponent& mesh = *scene.meshes.GetComponent(object.meshID);
MeshComponent& mesh = *state.scene.meshes.GetComponent(object.meshID);
assert(!mesh.vertex_boneindices.empty());
mesh.armatureID = state.armatureArray[node->skin];
}
@@ -198,18 +197,18 @@ void LoadNode(tinygltf::Node* node, Entity parent, LoaderState& state)
node->name = ss.str();
}
entity = scene.Entity_CreateCamera(node->name, (float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800);
entity = state.scene.Entity_CreateCamera(node->name, (float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800);
}
if (entity == INVALID_ENTITY)
{
entity = CreateEntity();
scene.transforms.Create(entity);
state.scene.transforms.Create(entity);
}
state.entityMap[node] = entity;
TransformComponent& transform = *scene.transforms.GetComponent(entity);
TransformComponent& transform = *state.scene.transforms.GetComponent(entity);
if (!node->scale.empty())
{
transform.scale_local = XMFLOAT3((float)node->scale[0], (float)node->scale[1], (float)node->scale[2]);
@@ -229,7 +228,7 @@ void LoadNode(tinygltf::Node* node, Entity parent, LoaderState& state)
if (parent != INVALID_ENTITY)
{
scene.Component_Attach(entity, parent);
state.scene.Component_Attach(entity, parent);
}
if (!node->children.empty())
@@ -241,7 +240,7 @@ void LoadNode(tinygltf::Node* node, Entity parent, LoaderState& state)
}
}
Entity ImportModel_GLTF(const std::string& fileName)
void ImportModel_GLTF(const std::string& fileName)
{
string directory, name;
wiHelper::SplitPath(fileName, directory, name);
@@ -269,22 +268,19 @@ Entity ImportModel_GLTF(const std::string& fileName)
}
if (!ret) {
wiHelper::messageBox(err, "GLTF error!");
return INVALID_ENTITY;
}
Scene& scene = wiRenderer::GetScene();
state.modelEntity = scene.Entity_CreateModel(name);
TransformComponent& model_transform = *scene.transforms.GetComponent(state.modelEntity);
Entity rootEntity = CreateEntity();
state.scene.transforms.Create(rootEntity);
// Create materials:
for (auto& x : state.gltfModel.materials)
{
Entity materialEntity = scene.Entity_CreateMaterial(x.name);
Entity materialEntity = state.scene.Entity_CreateMaterial(x.name);
state.materialArray.push_back(materialEntity);
MaterialComponent& material = *scene.materials.GetComponent(materialEntity);
MaterialComponent& material = *state.scene.materials.GetComponent(materialEntity);
material.baseColor = XMFLOAT4(1, 1, 1, 1);
material.roughness = 1.0f;
@@ -500,18 +496,18 @@ Entity ImportModel_GLTF(const std::string& fileName)
if (state.materialArray.empty())
{
Entity materialEntity = scene.Entity_CreateMaterial("GLTFImport_defaultMaterial");
Entity materialEntity = state.scene.Entity_CreateMaterial("GLTFImport_defaultMaterial");
state.materialArray.push_back(materialEntity);
}
// Create meshes:
for (auto& x : state.gltfModel.meshes)
{
Entity meshEntity = scene.Entity_CreateMesh(x.name);
Entity meshEntity = state.scene.Entity_CreateMesh(x.name);
state.meshArray.push_back(meshEntity);
MeshComponent& mesh = *scene.meshes.GetComponent(meshEntity);
MeshComponent& mesh = *state.scene.meshes.GetComponent(meshEntity);
for (auto& prim : x.primitives)
{
@@ -676,10 +672,10 @@ Entity ImportModel_GLTF(const std::string& fileName)
for (auto& skin : state.gltfModel.skins)
{
Entity armatureEntity = CreateEntity();
scene.names.Create(armatureEntity) = skin.name;
scene.layers.Create(armatureEntity);
TransformComponent& transform = scene.transforms.Create(armatureEntity);
ArmatureComponent& armature = scene.armatures.Create(armatureEntity);
state.scene.names.Create(armatureEntity) = skin.name;
state.scene.layers.Create(armatureEntity);
TransformComponent& transform = state.scene.transforms.Create(armatureEntity);
ArmatureComponent& armature = state.scene.armatures.Create(armatureEntity);
state.armatureArray.push_back(armatureEntity);
@@ -706,7 +702,7 @@ Entity ImportModel_GLTF(const std::string& fileName)
const tinygltf::Scene &gltfScene = state.gltfModel.scenes[max(0, state.gltfModel.defaultScene)];
for (size_t i = 0; i < gltfScene.nodes.size(); i++)
{
LoadNode(&state.gltfModel.nodes[gltfScene.nodes[i]], state.modelEntity, state);
LoadNode(&state.gltfModel.nodes[gltfScene.nodes[i]], rootEntity, state);
}
// Create armature-bone mappings:
@@ -714,7 +710,7 @@ Entity ImportModel_GLTF(const std::string& fileName)
for (auto& skin : state.gltfModel.skins)
{
Entity entity = state.armatureArray[armatureIndex++];
ArmatureComponent& armature = *scene.armatures.GetComponent(entity);
ArmatureComponent& armature = *state.scene.armatures.GetComponent(entity);
const size_t jointCount = skin.joints.size();
@@ -736,8 +732,8 @@ Entity ImportModel_GLTF(const std::string& fileName)
for (auto& anim : state.gltfModel.animations)
{
Entity entity = CreateEntity();
scene.names.Create(entity) = anim.name;
AnimationComponent& animationcomponent = scene.animations.Create(entity);
state.scene.names.Create(entity) = anim.name;
AnimationComponent& animationcomponent = state.scene.animations.Create(entity);
for (auto& channel : anim.channels)
{
@@ -834,10 +830,17 @@ Entity ImportModel_GLTF(const std::string& fileName)
if (transform_to_LH)
{
TransformComponent& transform = *scene.transforms.GetComponent(state.modelEntity);
TransformComponent& transform = *state.scene.transforms.GetComponent(rootEntity);
transform.scale_local.z = -transform.scale_local.z;
transform.SetDirty();
}
return state.modelEntity;
// We parented everything to a root transform, but we actually don't need that after loading model.
// Apply every transformation according to root transform, then remove root all together.
// We could also keep it, but right now, it seems better to delete and have less hierarchy
state.scene.Update(0);
state.scene.Entity_Remove(rootEntity);
wiRenderer::GetScene().Merge(state.scene);
}
+10 -17
View File
@@ -1,4 +1,5 @@
#include "stdafx.h"
#include "wiSceneSystem.h"
#include "ModelImporter.h"
#define TINYOBJLOADER_IMPLEMENTATION
@@ -14,15 +15,13 @@ using namespace wiECS;
// Transform the data from OBJ space to engine-space:
static const bool transform_to_LH = true;
Entity ImportModel_OBJ(const std::string& fileName)
void ImportModel_OBJ(const std::string& fileName)
{
string directory, name;
wiHelper::SplitPath(fileName, directory, name);
wiHelper::RemoveExtensionFromFileName(name);
Scene& scene = wiRenderer::GetScene();
Scene scene;
tinyobj::attrib_t obj_attrib;
vector<tinyobj::shape_t> obj_shapes;
@@ -31,13 +30,13 @@ Entity ImportModel_OBJ(const std::string& fileName)
bool success = tinyobj::LoadObj(&obj_attrib, &obj_shapes, &obj_materials, &obj_errors, fileName.c_str(), directory.c_str(), true);
if (!obj_errors.empty())
{
wiBackLog::post(obj_errors.c_str());
}
if (success)
{
Entity modelEntity = scene.Entity_CreateModel(name);
TransformComponent& model_transform = *scene.transforms.GetComponent(modelEntity);
model_transform.UpdateTransform(); // everything will be attached to this, so values need to be up to date
// Load material library:
vector<Entity> materialLibrary = {};
for (auto& obj_material : obj_materials)
@@ -99,8 +98,6 @@ Entity ImportModel_OBJ(const std::string& fileName)
ObjectComponent& object = *scene.objects.GetComponent(objectEntity);
MeshComponent& mesh = *scene.meshes.GetComponent(meshEntity);
scene.Component_Attach(objectEntity, modelEntity);
object.meshID = meshEntity;
unordered_map<int, int> registered_materialIndices = {};
@@ -189,14 +186,10 @@ Entity ImportModel_OBJ(const std::string& fileName)
mesh.CreateRenderData();
}
return modelEntity;
wiRenderer::GetScene().Merge(scene);
}
if (!obj_errors.empty())
else
{
wiBackLog::post(obj_errors.c_str());
wiHelper::messageBox("OBJ import failed! Check backlog for errors!", "Error!");
}
return INVALID_ENTITY;
}
+21 -21
View File
@@ -211,7 +211,7 @@ void Translator::Update()
dragEnded = false;
XMFLOAT4 pointer = wiInputManager::GetInstance()->getpointer();
CameraComponent* cam = wiRenderer::getCamera();
const CameraComponent& cam = wiRenderer::GetCamera();
XMVECTOR pos = transform.GetPositionV();
if (enabled)
@@ -219,11 +219,11 @@ void Translator::Update()
if (!dragging)
{
XMMATRIX P = cam->GetProjection();
XMMATRIX V = cam->GetView();
XMMATRIX P = cam.GetProjection();
XMMATRIX V = cam.GetView();
XMMATRIX W = XMMatrixIdentity();
dist = wiMath::Distance(transform.GetPosition(), cam->Eye) * 0.05f;
dist = wiMath::Distance(transform.GetPosition(), cam.Eye) * 0.05f;
XMVECTOR o, x, y, z, p, xy, xz, yz;
@@ -237,13 +237,13 @@ void Translator::Update()
yz = o + XMVectorSet(0, 0.5f, 0.5f, 0) * dist;
o = XMVector3Project(o, 0, 0, cam->width, cam->height, 0, 1, P, V, W);
x = XMVector3Project(x, 0, 0, cam->width, cam->height, 0, 1, P, V, W);
y = XMVector3Project(y, 0, 0, cam->width, cam->height, 0, 1, P, V, W);
z = XMVector3Project(z, 0, 0, cam->width, cam->height, 0, 1, P, V, W);
xy = XMVector3Project(xy, 0, 0, cam->width, cam->height, 0, 1, P, V, W);
xz = XMVector3Project(xz, 0, 0, cam->width, cam->height, 0, 1, P, V, W);
yz = XMVector3Project(yz, 0, 0, cam->width, cam->height, 0, 1, P, V, W);
o = XMVector3Project(o, 0, 0, cam.width, cam.height, 0, 1, P, V, W);
x = XMVector3Project(x, 0, 0, cam.width, cam.height, 0, 1, P, V, W);
y = XMVector3Project(y, 0, 0, cam.width, cam.height, 0, 1, P, V, W);
z = XMVector3Project(z, 0, 0, cam.width, cam.height, 0, 1, P, V, W);
xy = XMVector3Project(xy, 0, 0, cam.width, cam.height, 0, 1, P, V, W);
xz = XMVector3Project(xz, 0, 0, cam.width, cam.height, 0, 1, P, V, W);
yz = XMVector3Project(yz, 0, 0, cam.width, cam.height, 0, 1, P, V, W);
XMVECTOR oDisV = XMVector3Length(o - p);
XMVECTOR xyDisV = XMVector3Length(xy - p);
@@ -298,19 +298,19 @@ void Translator::Update()
if (state == TRANSLATOR_X)
{
XMVECTOR axis = XMVectorSet(1, 0, 0, 0);
XMVECTOR wrong = XMVector3Cross(cam->GetAt(), axis);
XMVECTOR wrong = XMVector3Cross(cam.GetAt(), axis);
planeNormal = XMVector3Cross(wrong, axis);
}
else if (state == TRANSLATOR_Y)
{
XMVECTOR axis = XMVectorSet(0, 1, 0, 0);
XMVECTOR wrong = XMVector3Cross(cam->GetAt(), axis);
XMVECTOR wrong = XMVector3Cross(cam.GetAt(), axis);
planeNormal = XMVector3Cross(wrong, axis);
}
else if (state == TRANSLATOR_Z)
{
XMVECTOR axis = XMVectorSet(0, 0, 1, 0);
XMVECTOR wrong = XMVector3Cross(cam->GetAt(), axis);
XMVECTOR wrong = XMVector3Cross(cam.GetAt(), axis);
planeNormal = XMVector3Cross(wrong, axis);
}
else if (state == TRANSLATOR_XY)
@@ -328,19 +328,19 @@ void Translator::Update()
else
{
// xyz
planeNormal = cam->GetAt();
planeNormal = cam.GetAt();
}
plane = XMPlaneFromPointNormal(pos, XMVector3Normalize(planeNormal));
RAY ray = wiRenderer::getPickRay((long)pointer.x, (long)pointer.y);
RAY ray = wiRenderer::GetPickRay((long)pointer.x, (long)pointer.y);
XMVECTOR rayOrigin = XMLoadFloat3(&ray.origin);
XMVECTOR rayDir = XMLoadFloat3(&ray.direction);
XMVECTOR intersection = XMPlaneIntersectLine(plane, rayOrigin, rayOrigin + rayDir*cam->zFarP);
XMVECTOR intersection = XMPlaneIntersectLine(plane, rayOrigin, rayOrigin + rayDir*cam.zFarP);
ray = wiRenderer::getPickRay((long)prevPointer.x, (long)prevPointer.y);
ray = wiRenderer::GetPickRay((long)prevPointer.x, (long)prevPointer.y);
rayOrigin = XMLoadFloat3(&ray.origin);
rayDir = XMLoadFloat3(&ray.direction);
XMVECTOR intersectionPrev = XMPlaneIntersectLine(plane, rayOrigin, rayOrigin + rayDir*cam->zFarP);
XMVECTOR intersectionPrev = XMPlaneIntersectLine(plane, rayOrigin, rayOrigin + rayDir*cam.zFarP);
XMVECTOR deltaV;
if (state == TRANSLATOR_X)
@@ -433,7 +433,7 @@ void Translator::Update()
prevPointer = pointer;
}
void Translator::Draw(CameraComponent* camera, GRAPHICSTHREAD threadID)
void Translator::Draw(const CameraComponent& camera, GRAPHICSTHREAD threadID)
{
Scene& scene = wiRenderer::GetScene();
@@ -448,7 +448,7 @@ void Translator::Draw(CameraComponent* camera, GRAPHICSTHREAD threadID)
device->EventBegin("Editor - Translator", threadID);
XMMATRIX VP = camera->GetViewProjection();
XMMATRIX VP = camera.GetViewProjection();
wiRenderer::MiscCB sb;
+1 -1
View File
@@ -15,7 +15,7 @@ public:
~Translator();
void Update();
void Draw(wiSceneSystem::CameraComponent* camera, GRAPHICSTHREAD threadID);
void Draw(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID);
wiECS::Entity entityID = wiECS::INVALID_ENTITY;
+1 -1
View File
@@ -214,7 +214,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
int height = HIWORD(lParam);
wiRenderer::GetDevice()->SetResolution(width, height);
wiRenderer::getCamera()->CreatePerspective((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800);
wiRenderer::GetCamera().CreatePerspective((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800);
}
}
break;
+1 -1
View File
@@ -178,7 +178,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
int height = HIWORD(lParam);
wiRenderer::GetDevice()->SetResolution(width, height);
wiRenderer::getCamera()->CreatePerspective((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800);
wiRenderer::GetCamera().CreatePerspective((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800);
}
}
break;
+1 -1
View File
@@ -167,7 +167,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
int height = HIWORD(lParam);
wiRenderer::GetDevice()->SetResolution(width, height);
wiRenderer::getCamera()->CreatePerspective((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800);
wiRenderer::GetCamera().CreatePerspective((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 800);
}
}
break;
+4 -4
View File
@@ -99,7 +99,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
{
wiProfiler::GetInstance().BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID);
wiRenderer::UpdateCameraCB(wiRenderer::getCamera(), threadID);
wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID);
wiImageEffects fx((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y);
@@ -109,7 +109,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
rtGBuffer.Activate(threadID, 0, 0, 0, 0);
{
wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID);
wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEFERRED, getHairParticlesEnabled(), true, getLayerMask());
wiRenderer::DrawWorld(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEFERRED, getHairParticlesEnabled(), true, getLayerMask());
}
wiRenderer::GetDevice()->TransitionBarrier(dsv, ARRAYSIZE(dsv), RESOURCE_STATE_DEPTH_WRITE, RESOURCE_STATE_COPY_SOURCE, threadID);
@@ -139,7 +139,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
rtGBuffer.Set(threadID); {
wiRenderer::DrawDecals(wiRenderer::getCamera(), threadID);
wiRenderer::DrawDecals(wiRenderer::GetCamera(), threadID);
}
rtGBuffer.Deactivate(threadID);
@@ -149,7 +149,7 @@ void DeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
rtLight.Activate(threadID, rtGBuffer.depth); {
wiRenderer::GetDevice()->BindResource(PS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID);
wiRenderer::DrawLights(wiRenderer::getCamera(), threadID);
wiRenderer::DrawLights(wiRenderer::GetCamera(), threadID);
}
+2 -2
View File
@@ -81,7 +81,7 @@ void ForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
{
wiProfiler::GetInstance().BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID);
wiRenderer::UpdateCameraCB(wiRenderer::getCamera(), threadID);
wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID);
GPUResource* dsv[] = { rtMain.depth->GetTexture() };
wiRenderer::GetDevice()->TransitionBarrier(dsv, ARRAYSIZE(dsv), RESOURCE_STATE_DEPTH_READ, RESOURCE_STATE_DEPTH_WRITE, threadID);
@@ -93,7 +93,7 @@ void ForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID);
wiRenderer::GetDevice()->BindResource(PS, getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getInstance()->getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID);
wiRenderer::GetDevice()->BindResource(PS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID);
wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_FORWARD, getHairParticlesEnabled(), true, getLayerMask());
wiRenderer::DrawWorld(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, SHADERTYPE_FORWARD, getHairParticlesEnabled(), true, getLayerMask());
wiRenderer::DrawSky(threadID);
}
rtMain.Deactivate(threadID);
@@ -102,14 +102,21 @@ void PathTracingRenderableComponent::Update(float dt)
{
const Scene& scene = wiRenderer::GetScene();
for (size_t i = 0; i < scene.transforms.GetCount(); ++i)
if (wiRenderer::GetCamera().IsDirty())
{
const TransformComponent& transform = scene.transforms[i];
if (transform.IsDirty())
sam = -1;
}
else
{
for (size_t i = 0; i < scene.transforms.GetCount(); ++i)
{
sam = -1;
break;
const TransformComponent& transform = scene.transforms[i];
if (transform.IsDirty())
{
sam = -1;
break;
}
}
}
sam++;
@@ -132,9 +139,9 @@ void PathTracingRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
{
wiProfiler::GetInstance().BeginRange("Traced Scene", wiProfiler::DOMAIN_GPU, threadID);
wiRenderer::UpdateCameraCB(wiRenderer::getCamera(), threadID);
wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID);
wiRenderer::DrawTracedScene(wiRenderer::getCamera(), traceResult, threadID);
wiRenderer::DrawTracedScene(wiRenderer::GetCamera(), traceResult, threadID);
+12 -12
View File
@@ -275,12 +275,12 @@ void Renderable3DComponent::RenderReflections(GRAPHICSTHREAD threadID)
if (wiRenderer::IsRequestedReflectionRendering())
{
wiRenderer::UpdateCameraCB(wiRenderer::getRefCamera(), threadID);
wiRenderer::UpdateCameraCB(wiRenderer::GetRefCamera(), threadID);
rtReflection.Activate(threadID); {
// reverse clipping if underwater
XMFLOAT4 water = wiRenderer::GetWaterPlane();
if (XMVectorGetX(XMPlaneDot(XMLoadFloat4(&water), wiRenderer::getCamera()->GetEye())) < 0)
if (XMVectorGetX(XMPlaneDot(XMLoadFloat4(&water), wiRenderer::GetCamera().GetEye())) < 0)
{
water.x *= -1;
water.y *= -1;
@@ -289,7 +289,7 @@ void Renderable3DComponent::RenderReflections(GRAPHICSTHREAD threadID)
wiRenderer::SetClipPlane(water, threadID);
wiRenderer::DrawWorld(wiRenderer::getRefCamera(), false, threadID, SHADERTYPE_TEXTURE, getHairParticlesReflectionEnabled(), false, getLayerMask());
wiRenderer::DrawWorld(wiRenderer::GetRefCamera(), false, threadID, SHADERTYPE_TEXTURE, getHairParticlesReflectionEnabled(), false, getLayerMask());
wiRenderer::DrawSky(threadID);
wiRenderer::SetClipPlane(XMFLOAT4(0, 0, 0, 0), threadID);
@@ -341,7 +341,7 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende
}
wiRenderer::GetDevice()->EventEnd(threadID);
wiRenderer::UpdateCameraCB(wiRenderer::getCamera(), threadID);
wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID);
if (getStereogramEnabled())
{
@@ -351,7 +351,7 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende
wiProfiler::GetInstance().BeginRange("Secondary Scene", wiProfiler::DOMAIN_GPU, threadID);
XMVECTOR sunDirection = XMLoadFloat3(&wiRenderer::GetScene().sunDirection);
if (getLightShaftsEnabled() && XMVectorGetX(XMVector3Dot(sunDirection, wiRenderer::getCamera()->GetAt())) > 0)
if (getLightShaftsEnabled() && XMVectorGetX(XMVector3Dot(sunDirection, wiRenderer::GetCamera().GetAt())) > 0)
{
wiRenderer::GetDevice()->EventBegin("Light Shafts", threadID);
wiRenderer::GetDevice()->UnbindResources(TEXSLOT_ONDEMAND0, TEXSLOT_ONDEMAND_COUNT, threadID);
@@ -364,7 +364,7 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende
fxs.blendFlag = BLENDMODE_OPAQUE;
XMVECTOR sunPos = XMVector3Project(sunDirection * 100000, 0, 0,
(float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y, 0.1f, 1.0f,
wiRenderer::getCamera()->GetProjection(), wiRenderer::getCamera()->GetView(), XMMatrixIdentity());
wiRenderer::GetCamera().GetProjection(), wiRenderer::GetCamera().GetView(), XMMatrixIdentity());
{
XMStoreFloat2(&fxs.sunPos, sunPos);
wiImage::Draw(rtSun[0].GetTextureResolvedMSAA(threadID), fxs, threadID);
@@ -376,13 +376,13 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende
if (getVolumeLightsEnabled())
{
rtVolumetricLights.Activate(threadID, 0, 0, 0, 0);
wiRenderer::DrawVolumeLights(wiRenderer::getCamera(), threadID);
wiRenderer::DrawVolumeLights(wiRenderer::GetCamera(), threadID);
}
if (getEmittedParticlesEnabled())
{
rtParticle.Activate(threadID, 0, 0, 0, 0);
wiRenderer::DrawSoftParticles(wiRenderer::getCamera(), false, threadID);
wiRenderer::DrawSoftParticles(wiRenderer::GetCamera(), false, threadID);
}
rtWaterRipple.Activate(threadID, 0, 0, 0, 0); {
@@ -408,7 +408,7 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende
RenderTransparentScene(rtSceneCopy, threadID);
wiRenderer::DrawTrails(threadID, rtSceneCopy.GetTexture());
wiRenderer::DrawLightVisualizers(wiRenderer::getCamera(), threadID);
wiRenderer::DrawLightVisualizers(wiRenderer::GetCamera(), threadID);
fx.presentFullScreen = true;
@@ -439,14 +439,14 @@ void Renderable3DComponent::RenderSecondaryScene(wiRenderTarget& mainRT, wiRende
wiRenderer::DrawLensFlares(threadID);
}
wiRenderer::DrawDebugWorld(wiRenderer::getCamera(), threadID);
wiRenderer::DrawDebugWorld(wiRenderer::GetCamera(), threadID);
}
if (getEmittedParticlesEnabled())
{
wiRenderer::GetDevice()->UnbindResources(TEXSLOT_ONDEMAND0, 1, threadID);
rtParticle.Activate(threadID, 0, 0, 0, 0);
wiRenderer::DrawSoftParticles(wiRenderer::getCamera(), true, threadID);
wiRenderer::DrawSoftParticles(wiRenderer::GetCamera(), true, threadID);
}
wiProfiler::GetInstance().EndRange(threadID); // Secondary Scene
@@ -458,7 +458,7 @@ void Renderable3DComponent::RenderTransparentScene(wiRenderTarget& refractionRT,
wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID);
wiRenderer::GetDevice()->BindResource(PS, refractionRT.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_REFRACTION, threadID);
wiRenderer::GetDevice()->BindResource(PS, rtWaterRipple.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_WATERRIPPLES, threadID);
wiRenderer::DrawWorldTransparent(wiRenderer::getCamera(), SHADERTYPE_FORWARD, threadID, false, true, getLayerMask());
wiRenderer::DrawWorldTransparent(wiRenderer::GetCamera(), SHADERTYPE_FORWARD, threadID, false, true, getLayerMask());
wiProfiler::GetInstance().EndRange(threadID); // Transparent Scene
}
@@ -27,7 +27,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
{
wiProfiler::GetInstance().BeginRange("Opaque Scene", wiProfiler::DOMAIN_GPU, threadID);
wiRenderer::UpdateCameraCB(wiRenderer::getCamera(), threadID);
wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID);
wiImageEffects fx((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y);
@@ -37,7 +37,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
rtGBuffer.Activate(threadID, 0, 0, 0, 0);
{
wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID);
wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEFERRED, getHairParticlesEnabled(), true, getLayerMask());
wiRenderer::DrawWorld(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEFERRED, getHairParticlesEnabled(), true, getLayerMask());
}
@@ -69,7 +69,7 @@ void TiledDeferredRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
rtGBuffer.Set(threadID); {
wiRenderer::DrawDecals(wiRenderer::getCamera(), threadID);
wiRenderer::DrawDecals(wiRenderer::GetCamera(), threadID);
}
rtGBuffer.Deactivate(threadID);
@@ -200,7 +200,7 @@ void TiledDeferredRenderableComponent::RenderTransparentScene(wiRenderTarget& re
wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID);
wiRenderer::GetDevice()->BindResource(PS, refractionRT.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_REFRACTION, threadID);
wiRenderer::GetDevice()->BindResource(PS, rtWaterRipple.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_WATERRIPPLES, threadID);
wiRenderer::DrawWorldTransparent(wiRenderer::getCamera(), SHADERTYPE_TILEDFORWARD, threadID, getHairParticlesEnabled(), true, getLayerMask());
wiRenderer::DrawWorldTransparent(wiRenderer::GetCamera(), SHADERTYPE_TILEDFORWARD, threadID, getHairParticlesEnabled(), true, getLayerMask());
wiProfiler::GetInstance().EndRange(); // Transparent Scene
}
@@ -18,7 +18,7 @@ TiledForwardRenderableComponent::~TiledForwardRenderableComponent()
void TiledForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
{
wiRenderer::UpdateCameraCB(wiRenderer::getCamera(), threadID);
wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID);
GPUResource* dsv[] = { rtMain.depth->GetTexture() };
wiRenderer::GetDevice()->TransitionBarrier(dsv, ARRAYSIZE(dsv), RESOURCE_STATE_DEPTH_READ, RESOURCE_STATE_DEPTH_WRITE, threadID);
@@ -28,7 +28,7 @@ void TiledForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
wiProfiler::GetInstance().BeginRange("Z-Prepass", wiProfiler::DOMAIN_GPU, threadID);
rtMain.Activate(threadID, 0, 0, 0, 0, true); // depth prepass
{
wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEPTHONLY, getHairParticlesEnabled(), true, getLayerMask());
wiRenderer::DrawWorld(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, SHADERTYPE_DEPTHONLY, getHairParticlesEnabled(), true, getLayerMask());
}
wiProfiler::GetInstance().EndRange(threadID);
@@ -60,7 +60,7 @@ void TiledForwardRenderableComponent::RenderScene(GRAPHICSTHREAD threadID)
wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID);
wiRenderer::GetDevice()->BindResource(PS, getSSAOEnabled() ? rtSSAO.back().GetTexture() : wiTextureHelper::getInstance()->getWhite(), TEXSLOT_RENDERABLECOMPONENT_SSAO, threadID);
wiRenderer::GetDevice()->BindResource(PS, getSSREnabled() ? rtSSR.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_SSR, threadID);
wiRenderer::DrawWorld(wiRenderer::getCamera(), getTessellationEnabled(), threadID, SHADERTYPE_TILEDFORWARD, true, true);
wiRenderer::DrawWorld(wiRenderer::GetCamera(), getTessellationEnabled(), threadID, SHADERTYPE_TILEDFORWARD, true, true);
wiRenderer::DrawSky(threadID);
}
rtMain.Deactivate(threadID);
@@ -122,7 +122,7 @@ void TiledForwardRenderableComponent::RenderTransparentScene(wiRenderTarget& ref
wiRenderer::GetDevice()->BindResource(PS, getReflectionsEnabled() ? rtReflection.GetTexture() : wiTextureHelper::getInstance()->getTransparent(), TEXSLOT_RENDERABLECOMPONENT_REFLECTION, threadID);
wiRenderer::GetDevice()->BindResource(PS, refractionRT.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_REFRACTION, threadID);
wiRenderer::GetDevice()->BindResource(PS, rtWaterRipple.GetTexture(), TEXSLOT_RENDERABLECOMPONENT_WATERRIPPLES, threadID);
wiRenderer::DrawWorldTransparent(wiRenderer::getCamera(), SHADERTYPE_TILEDFORWARD, threadID, getHairParticlesEnabled(), true);
wiRenderer::DrawWorldTransparent(wiRenderer::GetCamera(), SHADERTYPE_TILEDFORWARD, threadID, getHairParticlesEnabled(), true);
wiProfiler::GetInstance().EndRange(threadID); // Transparent Scene
}
+33 -21
View File
@@ -2,6 +2,7 @@
#define _ENTITY_COMPONENT_SYSTEM_H_
#include "wiArchive.h"
#include "wiRandom.h"
#include <cstdint>
#include <cassert>
@@ -12,10 +13,27 @@ namespace wiECS
{
typedef uint32_t Entity;
static const Entity INVALID_ENTITY = 0;
// Runtime can create a new entity with this
inline Entity CreateEntity()
{
static Entity id = 0;
return ++id;
return wiRandom::getRandom(1, INT_MAX);
}
// This is the safe way to serialize an entity
// seed : ensures that entity will be unique after loading (specify seed = 0 to leave entity as-is)
inline void SerializeEntity(wiArchive& archive, Entity& entity, uint32_t seed)
{
if (archive.IsReadMode())
{
archive >> entity;
if (entity != INVALID_ENTITY && seed > 0)
{
entity = ((entity << 1) ^ seed) >> 1;
}
}
else
{
archive << entity;
}
}
template<typename Component>
@@ -60,7 +78,7 @@ namespace wiECS
for (size_t i = 0; i < other.GetCount(); ++i)
{
Entity entity = other.entities[i];
assert(Contains(entity));
assert(!Contains(entity));
entities.push_back(entity);
lookup[entity] = components.size();
components.push_back(std::move(other.components[i]));
@@ -70,33 +88,29 @@ namespace wiECS
}
// Read/Write everything to an archive depending on the archive state
inline void Serialize(wiArchive& archive)
// seed: needed when serializing from disk which might cause discrepancy in entity uniqueness
inline void Serialize(wiArchive& archive, uint32_t seed = 0)
{
if (archive.IsReadMode())
{
Clear(); // If we deserialize, we start from empty
size_t count;
archive >> count;
components.resize(count);
for (size_t i = 0; i < count; ++i)
{
components[i].Serialize(archive);
components[i].Serialize(archive, seed);
}
entities.resize(count);
for (size_t i = 0; i < count; ++i)
{
archive >> entities[i];
}
lookup.reserve(count);
for (size_t i = 0; i < count; ++i)
{
Entity entity;
size_t index;
archive >> entity;
archive >> index;
lookup[entity] = index;
SerializeEntity(archive, entity, seed);
entities[i] = entity;
lookup[entity] = i;
}
}
else
@@ -108,12 +122,7 @@ namespace wiECS
}
for (Entity entity : entities)
{
archive << entity;
}
for (auto it : lookup)
{
archive << it.first;
archive << it.second;
SerializeEntity(archive, entity, seed);
}
}
}
@@ -121,6 +130,9 @@ namespace wiECS
// Create a new component and retrieve a reference to it
inline Component& Create(Entity entity)
{
// INVALID_ENTITY is not allowed!
assert(entity != INVALID_ENTITY);
// Only one of this component type per entity is allowed!
assert(lookup.find(entity) == lookup.end());
+4 -4
View File
@@ -558,7 +558,7 @@ void wiEmittedParticle::UpdateRenderData(const TransformComponent& transform, co
}
void wiEmittedParticle::Draw(const MaterialComponent& material, GRAPHICSTHREAD threadID)
void wiEmittedParticle::Draw(const CameraComponent& camera, const MaterialComponent& material, GRAPHICSTHREAD threadID)
{
GraphicsDevice* device = wiRenderer::GetDevice();
device->EventBegin("EmittedParticle", threadID);
@@ -787,13 +787,13 @@ void wiEmittedParticle::CleanUpStatic()
}
void wiEmittedParticle::Serialize(wiArchive& archive)
void wiEmittedParticle::Serialize(wiArchive& archive, uint32_t seed)
{
if (archive.IsReadMode())
{
archive >> _flags;
archive >> (uint32_t&)shaderType;
archive >> meshID;
wiECS::SerializeEntity(archive, meshID, seed);
archive >> FIXED_TIMESTEP;
archive >> size;
archive >> random_factor;
@@ -815,7 +815,7 @@ void wiEmittedParticle::Serialize(wiArchive& archive)
{
archive << _flags;
archive << (uint32_t)shaderType;
archive << meshID;
wiECS::SerializeEntity(archive, meshID, seed);
archive << FIXED_TIMESTEP;
archive << size;
archive << random_factor;
+2 -2
View File
@@ -73,7 +73,7 @@ public:
// Must have a transform and material component, but mesh is optional
void UpdateRenderData(const TransformComponent& transform, const MaterialComponent& material, const MeshComponent* mesh, GRAPHICSTHREAD threadID);
void Draw(const MaterialComponent& material, GRAPHICSTHREAD threadID);
void Draw(const CameraComponent& camera, const MaterialComponent& material, GRAPHICSTHREAD threadID);
ParticleCounters GetDebugData() { return debugData; }
@@ -127,7 +127,7 @@ public:
inline void SetDepthCollisionEnabled(bool value) { if (value) { _flags |= DEPTHCOLLISION; } else { _flags &= ~DEPTHCOLLISION; } }
inline void SetSPHEnabled(bool value) { if (value) { _flags |= SPH_FLUIDSIMULATION; } else { _flags &= ~SPH_FLUIDSIMULATION; } }
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
}
+4 -4
View File
@@ -312,7 +312,7 @@ void wiHairParticle::UpdateRenderData(const MeshComponent& mesh, const MaterialC
device->EventEnd(threadID);
}
void wiHairParticle::Draw(CameraComponent* camera, const MaterialComponent& material, SHADERTYPE shaderType, bool transparent, GRAPHICSTHREAD threadID) const
void wiHairParticle::Draw(const CameraComponent& camera, const MaterialComponent& material, SHADERTYPE shaderType, bool transparent, GRAPHICSTHREAD threadID) const
{
if (strandCount == 0 || cb == nullptr)
{
@@ -352,12 +352,12 @@ void wiHairParticle::Draw(CameraComponent* camera, const MaterialComponent& mate
}
void wiHairParticle::Serialize(wiArchive& archive)
void wiHairParticle::Serialize(wiArchive& archive, uint32_t seed)
{
if (archive.IsReadMode())
{
archive >> _flags;
archive >> meshID;
wiECS::SerializeEntity(archive, meshID, seed);
archive >> strandCount;
archive >> segmentCount;
archive >> randomSeed;
@@ -369,7 +369,7 @@ void wiHairParticle::Serialize(wiArchive& archive)
else
{
archive << _flags;
archive << meshID;
wiECS::SerializeEntity(archive, meshID, seed);
archive << strandCount;
archive << segmentCount;
archive << randomSeed;
+2 -2
View File
@@ -32,7 +32,7 @@ public:
static void LoadShaders();
void UpdateRenderData(const MeshComponent& mesh, const MaterialComponent& material, GRAPHICSTHREAD threadID);
void Draw(CameraComponent* camera, const MaterialComponent& material, SHADERTYPE shaderType, bool transparent, GRAPHICSTHREAD threadID) const;
void Draw(const CameraComponent& camera, const MaterialComponent& material, SHADERTYPE shaderType, bool transparent, GRAPHICSTHREAD threadID) const;
static void CleanUpStatic();
static void SetUpStatic();
@@ -57,7 +57,7 @@ public:
XMFLOAT4X4 world;
AABB aabb;
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
}
+3 -3
View File
@@ -418,11 +418,11 @@ void wiImage::Draw(Texture2D* texture, const wiImageEffects& effects,GRAPHICSTHR
}
else
{
faceRot = XMLoadFloat3x3(&wiRenderer::getCamera()->rotationMatrix);
faceRot = XMLoadFloat3x3(&wiRenderer::GetCamera().rotationMatrix);
}
XMMATRIX view = wiRenderer::getCamera()->GetView();
XMMATRIX projection = wiRenderer::getCamera()->GetProjection();
XMMATRIX view = wiRenderer::GetCamera().GetView();
XMMATRIX projection = wiRenderer::GetCamera().GetProjection();
// Remove possible jittering from temporal camera:
projection.r[2] = XMVectorSetX(projection.r[2], 0);
projection.r[2] = XMVectorSetY(projection.r[2], 0);
+1 -1
View File
@@ -140,7 +140,7 @@ AABB AABB::Merge(const AABB& a, const AABB& b)
{
return AABB(wiMath::Min(a.getMin(), b.getMin()), wiMath::Max(a.getMax(), b.getMax()));
}
void AABB::Serialize(wiArchive& archive)
void AABB::Serialize(wiArchive& archive, uint32_t seed)
{
if (archive.IsReadMode())
{
+2 -9
View File
@@ -2,6 +2,7 @@
#define _INTERSECTABLES_H_
#include "CommonInclude.h"
#include "wiArchive.h"
#include "wiECS.h"
struct SPHERE;
struct RAY;
@@ -52,17 +53,9 @@ struct AABB
}
assert(0);
return XMFLOAT3(0, 0, 0);
//corners[0] = min;
//corners[1] = XMFLOAT3(min.x, max.y, min.z);
//corners[2] = XMFLOAT3(min.x, max.y, max.z);
//corners[3] = XMFLOAT3(min.x, min.y, max.z);
//corners[4] = XMFLOAT3(max.x, min.y, min.z);
//corners[5] = XMFLOAT3(max.x, max.y, min.z);
//corners[6] = max;
//corners[7] = XMFLOAT3(max.x, min.y, max.z);
}
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct SPHERE
{
+1 -1
View File
@@ -325,7 +325,7 @@ void wiOcean::UpdateDisplacementMap(float time, GRAPHICSTHREAD threadID)
}
void wiOcean::Render(const CameraComponent* camera, float time, GRAPHICSTHREAD threadID)
void wiOcean::Render(const CameraComponent& camera, float time, GRAPHICSTHREAD threadID)
{
GraphicsDevice* device = wiRenderer::GetDevice();
+1 -1
View File
@@ -61,7 +61,7 @@ public:
~wiOcean();
void UpdateDisplacementMap(float time, GRAPHICSTHREAD threadID);
void Render(const wiSceneSystem::CameraComponent* camera, float time, GRAPHICSTHREAD threadID);
void Render(const wiSceneSystem::CameraComponent& camera, float time, GRAPHICSTHREAD threadID);
wiGraphicsTypes::Texture2D* getDisplacementMap();
wiGraphicsTypes::Texture2D* getGradientMap();
+11 -11
View File
@@ -1,17 +1,17 @@
#include "wiRandom.h"
#include <random>
bool wiRandom::initialized = false;
int wiRandom::getRandom(int minValue, int maxValue)
namespace wiRandom
{
if (!initialized)
int wiRandom::getRandom(int minValue, int maxValue)
{
srand(unsigned(time(0)));
initialized = true;
static std::random_device rand_dev;
static std::mt19937 generator(rand_dev());
std::uniform_int_distribution<int> distr(minValue, maxValue);
return distr(generator);
}
int wiRandom::getRandom(int maxValue)
{
return getRandom(0, maxValue);
}
return minValue + rand() % (maxValue + 1 - minValue);
}
int wiRandom::getRandom(int maxValue)
{
return getRandom(0, maxValue);
}
+3 -8
View File
@@ -1,13 +1,8 @@
#pragma once
#include <cstdlib>
#include <ctime>
class wiRandom
namespace wiRandom
{
private:
static bool initialized;
public:
static int getRandom(int minValue, int maxValue);
static int getRandom(int maxValue);
int getRandom(int minValue, int maxValue);
int getRandom(int maxValue);
};
File diff suppressed because it is too large Load Diff
+14 -14
View File
@@ -370,7 +370,7 @@ public:
static void UpdateWorldCB(GRAPHICSTHREAD threadID);
static void UpdateFrameCB(GRAPHICSTHREAD threadID);
static void UpdateCameraCB(wiSceneSystem::CameraComponent* camera, GRAPHICSTHREAD threadID);
static void UpdateCameraCB(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID);
static void SetClipPlane(const XMFLOAT4& clipPlane, GRAPHICSTHREAD threadID);
static void SetAlphaRef(float alphaRef, GRAPHICSTHREAD threadID);
static void ResetAlphaRef(GRAPHICSTHREAD threadID) { SetAlphaRef(0.75f, threadID); }
@@ -381,17 +381,17 @@ public:
bool tessellation = false, bool occlusionCulling = false, uint32_t layerMask = 0xFFFFFFFF);
static void DrawSky(GRAPHICSTHREAD threadID);
static void DrawSun(GRAPHICSTHREAD threadID);
static void DrawWorld(wiSceneSystem::CameraComponent* camera, bool tessellation, GRAPHICSTHREAD threadID, SHADERTYPE shaderType, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF);
static void DrawWorld(const wiSceneSystem::CameraComponent& camera, bool tessellation, GRAPHICSTHREAD threadID, SHADERTYPE shaderType, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF);
static void DrawForShadowMap(GRAPHICSTHREAD threadID, uint32_t layerMask = 0xFFFFFFFF);
static void DrawWorldTransparent(wiSceneSystem::CameraComponent* camera, SHADERTYPE shaderType, GRAPHICSTHREAD threadID, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF);
static void DrawDebugWorld(wiSceneSystem::CameraComponent* camera, GRAPHICSTHREAD threadID);
static void DrawSoftParticles(wiSceneSystem::CameraComponent* camera, bool distortion, GRAPHICSTHREAD threadID);
static void DrawWorldTransparent(const wiSceneSystem::CameraComponent& camera, SHADERTYPE shaderType, GRAPHICSTHREAD threadID, bool grass, bool occlusionCulling, uint32_t layerMask = 0xFFFFFFFF);
static void DrawDebugWorld(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID);
static void DrawSoftParticles(const wiSceneSystem::CameraComponent& camera, bool distortion, GRAPHICSTHREAD threadID);
static void DrawTrails(GRAPHICSTHREAD threadID, wiGraphicsTypes::Texture2D* refracRes);
static void DrawLights(wiSceneSystem::CameraComponent* camera, GRAPHICSTHREAD threadID);
static void DrawLightVisualizers(wiSceneSystem::CameraComponent* camera, GRAPHICSTHREAD threadID);
static void DrawVolumeLights(wiSceneSystem::CameraComponent* camera, GRAPHICSTHREAD threadID);
static void DrawLights(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID);
static void DrawLightVisualizers(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID);
static void DrawVolumeLights(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID);
static void DrawLensFlares(GRAPHICSTHREAD threadID);
static void DrawDecals(wiSceneSystem::CameraComponent* camera, GRAPHICSTHREAD threadID);
static void DrawDecals(const wiSceneSystem::CameraComponent& camera, GRAPHICSTHREAD threadID);
static void RefreshEnvProbes(GRAPHICSTHREAD threadID);
static void VoxelRadiance(GRAPHICSTHREAD threadID);
@@ -399,7 +399,7 @@ public:
static void ResolveMSAADepthBuffer(wiGraphicsTypes::Texture2D* dst, wiGraphicsTypes::Texture2D* src, GRAPHICSTHREAD threadID);
static void BuildSceneBVH(GRAPHICSTHREAD threadID);
static void DrawTracedScene(wiSceneSystem::CameraComponent* camera, wiGraphicsTypes::Texture2D* result, GRAPHICSTHREAD threadID);
static void DrawTracedScene(const wiSceneSystem::CameraComponent& camera, wiGraphicsTypes::Texture2D* result, GRAPHICSTHREAD threadID);
enum MIPGENFILTER
{
@@ -436,11 +436,11 @@ public:
static std::deque<wiSprite*> waterRipples;
static void ClearWorld();
static wiSceneSystem::CameraComponent* getCamera();
static wiSceneSystem::CameraComponent* getPrevCamera();
static wiSceneSystem::CameraComponent* getRefCamera();
static wiSceneSystem::CameraComponent& GetCamera();
static wiSceneSystem::CameraComponent& GetPrevCamera();
static wiSceneSystem::CameraComponent& GetRefCamera();
static RAY getPickRay(long cursorX, long cursorY);
static RAY GetPickRay(long cursorX, long cursorY);
struct RayIntersectWorldResult
{
+59 -23
View File
@@ -694,6 +694,8 @@ namespace wiSceneSystem
}
void CameraComponent::UpdateCamera(const TransformComponent* transform)
{
SetDirty(false);
XMVECTOR _Eye;
XMVECTOR _At;
XMVECTOR _Up;
@@ -784,7 +786,7 @@ namespace wiSceneSystem
RunForceUpdateSystem(transforms, forces);
RunLightUpdateSystem(*wiRenderer::getCamera(), transforms, aabb_lights, lights, sunDirection, sunColor);
RunLightUpdateSystem(wiRenderer::GetCamera(), transforms, aabb_lights, lights, sunDirection, sunColor);
RunParticleUpdateSystem(transforms, meshes, emitters, hairs, dt);
@@ -817,6 +819,24 @@ namespace wiSceneSystem
}
void Scene::Merge(Scene& other)
{
if (CountEntities() == 0)
{
sunDirection = other.sunDirection;
sunColor = other.sunColor;
horizon = other.horizon;
zenith = other.zenith;
ambient = other.ambient;
fogStart = other.fogStart;
fogEnd = other.fogEnd;
fogHeight = other.fogHeight;
cloudiness = other.cloudiness;
cloudScale = other.cloudScale;
cloudSpeed = other.cloudSpeed;
windDirection = other.windDirection;
windRandomness = other.windRandomness;
windWaveSize = other.windWaveSize;
}
names.Merge(other.names);
layers.Merge(other.layers);
transforms.Merge(other.transforms);
@@ -843,6 +863,36 @@ namespace wiSceneSystem
bounds = AABB::Merge(bounds, other.bounds);
}
size_t Scene::CountEntities() const
{
// Entities are unique within a ComponentManager, so the most populated ComponentManager
// will actually give us how many entities there are in the scene
size_t entityCount = 0;
entityCount = max(entityCount, names.GetCount());
entityCount = max(entityCount, layers.GetCount());
entityCount = max(entityCount, transforms.GetCount());
entityCount = max(entityCount, prev_transforms.GetCount());
entityCount = max(entityCount, hierarchy.GetCount());
entityCount = max(entityCount, materials.GetCount());
entityCount = max(entityCount, meshes.GetCount());
entityCount = max(entityCount, objects.GetCount());
entityCount = max(entityCount, aabb_objects.GetCount());
entityCount = max(entityCount, rigidbodies.GetCount());
entityCount = max(entityCount, softbodies.GetCount());
entityCount = max(entityCount, armatures.GetCount());
entityCount = max(entityCount, lights.GetCount());
entityCount = max(entityCount, aabb_lights.GetCount());
entityCount = max(entityCount, cameras.GetCount());
entityCount = max(entityCount, probes.GetCount());
entityCount = max(entityCount, aabb_probes.GetCount());
entityCount = max(entityCount, forces.GetCount());
entityCount = max(entityCount, decals.GetCount());
entityCount = max(entityCount, aabb_decals.GetCount());
entityCount = max(entityCount, animations.GetCount());
entityCount = max(entityCount, emitters.GetCount());
entityCount = max(entityCount, hairs.GetCount());
return entityCount;
}
void Scene::Entity_Remove(Entity entity)
{
@@ -881,20 +931,6 @@ namespace wiSceneSystem
}
return INVALID_ENTITY;
}
Entity Scene::Entity_CreateModel(
const std::string& name
)
{
Entity entity = CreateEntity();
names.Create(entity) = name;
layers.Create(entity);
transforms.Create(entity);
return entity;
}
Entity Scene::Entity_CreateMaterial(
const std::string& name
)
@@ -1132,13 +1168,13 @@ namespace wiSceneSystem
{
// Save the parent's inverse worldmatrix:
XMStoreFloat4x4(&parentcomponent.world_parent_inverse_bind, XMMatrixInverse(nullptr, XMLoadFloat4x4(&transform_parent->world)));
}
TransformComponent* transform_child = transforms.GetComponent(entity);
if (transform_child != nullptr)
{
// Child updated immediately, to that it can be immediately attached to afterwards:
transform_child->UpdateParentedTransform(*transform_parent, parentcomponent.world_parent_inverse_bind);
TransformComponent* transform_child = transforms.GetComponent(entity);
if (transform_child != nullptr)
{
// Child updated immediately, to that it can be immediately attached to afterwards:
transform_child->UpdateParentedTransform(*transform_parent, parentcomponent.world_parent_inverse_bind);
}
}
LayerComponent* layer_child = layers.GetComponent(entity);
@@ -1738,7 +1774,7 @@ namespace wiSceneSystem
}
}
aabb.createFromHalfWidth(wiRenderer::getCamera()->Eye, XMFLOAT3(10000, 10000, 10000));
aabb.createFromHalfWidth(wiRenderer::GetCamera().Eye, XMFLOAT3(10000, 10000, 10000));
}
break;
case LightComponent::SPOT:
@@ -1793,7 +1829,7 @@ namespace wiSceneSystem
XMStoreFloat3(&light.right, XMVector3TransformNormal(XMVectorSet(-1, 0, 0, 0), W));
XMStoreFloat3(&light.front, XMVector3TransformNormal(XMVectorSet(0, 0, -1, 0), W));
// area lights have no bounds, just like directional lights (maybe todo)
aabb.createFromHalfWidth(wiRenderer::getCamera()->Eye, XMFLOAT3(10000, 10000, 10000));
aabb.createFromHalfWidth(wiRenderer::GetCamera().Eye, XMFLOAT3(10000, 10000, 10000));
}
}
break;
+28 -21
View File
@@ -28,7 +28,7 @@ namespace wiSceneSystem
inline void operator=(const std::string& str) { strcpy_s(name, str.c_str()); }
inline bool operator==(const std::string& str) const { return strcmp(name, str.c_str()) == 0; }
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct LayerComponent
@@ -37,7 +37,7 @@ namespace wiSceneSystem
inline uint32_t GetLayerMask() const { return layerMask; }
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct TransformComponent
@@ -78,7 +78,7 @@ namespace wiSceneSystem
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);
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct PreviousFrameTransformComponent
@@ -86,7 +86,7 @@ namespace wiSceneSystem
// Non-serialized attributes:
XMFLOAT4X4 world_prev;
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct HierarchyComponent
@@ -95,7 +95,7 @@ namespace wiSceneSystem
uint32_t layerMask_bind; // saved child layermask at the time of binding
XMFLOAT4X4 world_parent_inverse_bind; // saved parent inverse worldmatrix at the time of binding
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct MaterialComponent
@@ -187,7 +187,7 @@ namespace wiSceneSystem
inline void SetOpacity(float value) { SetDirty(); baseColor.w = value; }
inline void SetAlphaRef(float value) { alphaRef = value; }
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct MeshComponent
@@ -249,7 +249,7 @@ namespace wiSceneSystem
void FlipCulling();
void FlipNormals();
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
struct Vertex_POS
@@ -408,7 +408,7 @@ namespace wiSceneSystem
inline float GetTransparency() const { return 1 - color.w; }
inline uint32_t GetRenderTypes() const { return rendertypeMask; }
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct RigidBodyPhysicsComponent
@@ -440,7 +440,7 @@ namespace wiSceneSystem
// Non-serialized attributes:
int physicsObjectID = -1;
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct SoftBodyPhysicsComponent
@@ -460,7 +460,7 @@ namespace wiSceneSystem
// Non-serialized attributes:
int physicsObjectID = -1;
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct ArmatureComponent
@@ -496,7 +496,7 @@ namespace wiSceneSystem
std::vector<ShaderBoneType> boneData;
std::unique_ptr<wiGraphicsTypes::GPUBuffer> boneBuffer;
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct LightComponent
@@ -665,7 +665,7 @@ namespace wiSceneSystem
std::vector<SHCAM> shadowCam_dirLight;
std::vector<SHCAM> shadowCam_spotLight;
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct CameraComponent
@@ -673,6 +673,7 @@ namespace wiSceneSystem
enum FLAGS
{
EMPTY = 0,
DIRTY = 1 << 0,
};
uint32_t _flags = EMPTY;
@@ -707,7 +708,10 @@ namespace wiSceneSystem
inline XMMATRIX GetInvViewProjection() const { return XMLoadFloat4x4(&InvVP); }
inline XMMATRIX GetRealProjection() const { return XMLoadFloat4x4(&realProjection); }
void Serialize(wiArchive& archive);
inline void SetDirty(bool value = true) { if (value) { _flags |= DIRTY; } else { _flags &= ~DIRTY; } }
inline bool IsDirty() const { return _flags & DIRTY; }
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct EnvironmentProbeComponent
@@ -732,7 +736,7 @@ namespace wiSceneSystem
inline bool IsDirty() const { return _flags & DIRTY; }
inline bool IsRealTime() const { return _flags & REALTIME; }
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct ForceFieldComponent
@@ -751,7 +755,7 @@ namespace wiSceneSystem
XMFLOAT3 position;
XMFLOAT3 direction;
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct DecalComponent
@@ -776,7 +780,7 @@ namespace wiSceneSystem
inline float GetOpacity() const { return color.w; }
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct AnimationComponent
@@ -830,7 +834,7 @@ namespace wiSceneSystem
inline void Stop() { Pause(); timer = 0.0f; }
inline void SetLooped(bool value = true) { if (value) { _flags |= LOOPED; } else { _flags &= ~LOOPED; } }
void Serialize(wiArchive& archive);
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
struct Scene
@@ -882,17 +886,20 @@ namespace wiSceneSystem
void Update(float dt);
// Remove everything from the scene that it owns:
void Clear();
// Merge with an other scene (world properties like ambient, etc. are retained as-is). Other scene state is non-retained!
// Merge with an other scene. Other scene state is non-retained!
void Merge(Scene& other);
// Count how many entities there are in the scene:
size_t CountEntities() const;
// Removes a specific entity from the scene (if it exists):
void Entity_Remove(wiECS::Entity entity);
// Finds the first entity by the name (if it exists, otherwise returns INVALID_ENTITY):
wiECS::Entity Entity_FindByName(const std::string& name);
// Serializes entity and all of its components to archive:
// You can specify entity = INVALID_ENTITY when the entity needs to be created from archive
// You can specify seed = 0 when the archive is guaranteed to be storing persistent and unique entities
void Entity_Serialize(wiArchive& archive, wiECS::Entity entity = wiECS::INVALID_ENTITY, uint32_t seed = 0);
wiECS::Entity Entity_CreateModel(
const std::string& name
);
wiECS::Entity Entity_CreateMaterial(
const std::string& name
);
File diff suppressed because it is too large Load Diff