new rendering system and other additions

This commit is contained in:
Tim Nebel 2023-07-19 14:50:43 +02:00
commit 2e24e1714e
33 changed files with 1229 additions and 269 deletions

View file

@ -8,45 +8,9 @@
#include<imgui.h>
#include "IconsFontAwesome6.h"
#include "glm/gtx/string_cast.hpp"
#include <glm/gtx/rotate_vector.hpp>
#include<cmath>
const GLchar *vertexShader = "#version 460\n"
"layout (location = 0) in vec3 aPos;\n"
"layout (location = 1) in vec2 aTexCoord;\n"
"uniform mat4 VP;\n"
"uniform mat4 TransformationMatrix;\n"
"uniform mat4 TransformationMatrixNoYInv;\n"
"out vec2 TexCoord;\n"
"out vec4 WldPos;\n"
"void main(){\n"
" vec3 glPos = vec3(aPos.x,-aPos.y,aPos.z);\n"
" WldPos = TransformationMatrixNoYInv * vec4(aPos.xyz,1);\n"
" gl_Position = (VP * TransformationMatrix) * vec4(glPos.x,glPos.y,glPos.z,1);\n"
" TexCoord = aTexCoord;\n"
"}\n";
const GLchar *fragmentShader = "#version 460\n"
"in vec2 TexCoord;\n"
"in vec4 WldPos;\n"
"layout(location = 1) out vec4 FragColor;\n"
"layout(location = 2) out unsigned int ObjId;\n"
"layout(location = 3) out vec4 WorldPos;\n"
"uniform sampler2D tex;\n"
"uniform unsigned int ObjIdIn;\n"
"uniform vec4 ObjColor;\n"
"//out vec4 CamPos;\n"
"void main(){\n"
" ObjId = ObjIdIn;\n"
" WorldPos = vec4(WldPos.xyz,1);\n"
" //if(WldPos.w == 0) WorldPos=vec4(WldPos.xyz,1);\n"
" vec4 textel = texture(tex,TexCoord);\n"
" if(textel.a < 0.2) discard;\n"
" //textel.a = (CamPos.z / CamPos.w) / 100;\n"
" FragColor = textel * ObjColor;\n"
" //FragColor = vec4(1,1,1,1);\n"
"}";
MainViewport *MainVP;
glm::mat4 TransformToMatrix(Transform tf) {
@ -64,12 +28,13 @@ glm::mat4 TransformToMatrix(Transform tf) {
}
glm::vec3 ToGlmVec3(Vector3 Vec3) {
return glm::vec3(Vec3.X, Vec3.Y, Vec3.Z);
return {Vec3.X, Vec3.Y, Vec3.Z};
}
bool IsArea(std::string Type){
if( Type == "Area" ||
bool IsArea(const std::string& Type) {
if (Type == "Area" ||
Type == "Area_Yellow" ||
Type == "Area_Pink" ||
Type == "StageArea" ||
Type == "GeneralArea" ||
Type == "PaintedArea" ||
@ -81,20 +46,72 @@ bool IsArea(std::string Type){
return false;
}
MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true) {
MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true), VP(1.0f) {
MainVP = this;
shader = Graphics::Shader(vertexShader, fragmentShader);
m_internalFramebuf = std::make_unique<Graphics::Framebuffer>(
std::vector<Graphics::FramebufferTextureInfo>{
{GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GL_COLOR_ATTACHMENT0},
{GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_COLOR_ATTACHMENT1},
{GL_RGBA16F, GL_RGBA, GL_FLOAT, GL_COLOR_ATTACHMENT2},
{GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL_ATTACHMENT}
},
Graphics::Shader("ForwardPass"));
SunCam = std::make_unique<Graphics::Framebuffer>(
std::vector<Graphics::FramebufferTextureInfo>{
{GL_DEPTH_COMPONENT16,GL_DEPTH_COMPONENT,GL_FLOAT,GL_DEPTH_ATTACHMENT}
},
Graphics::Shader("ShadowPass"),
Math::Vector2i(16384,16384));
auto tex = SunCam->getFbTexByAttachment(GL_DEPTH_ATTACHMENT);
glBindTexture(GL_TEXTURE_2D, tex.m_texture.getId());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D,0);
//ObjMesh = Graphics::Mesh();
GLuint ObjColPos = glGetUniformLocation(shader.ShaderId, "ObjColor");
GLint ObjColPos = m_internalFramebuf->m_shader.getUniformLocation("ObjColor");
glUniform4f(ObjColPos, 1, 1, 1, 1);
}
void MainViewport::RenderRail(Rail *rail) {
static Model RailPointMdl = Model("St_RailPoint");
if (rail->Points.size() > 1) {
auto lastRailPoint = rail->Points.front();
for (RailPoint &railPoint: rail->Points) {
RailPointMdl.Draw(railPoint.TF, m_internalFramebuf->m_shader, VP);
}
}
}
void MainViewport::Draw() {
GLuint ObjIdPos = glGetUniformLocation(shader.ShaderId, "ObjIdIn");
GLuint ObjColPos = glGetUniformLocation(shader.ShaderId, "ObjColor");
#ifndef NDEBUG
glClearColor(.2, .2, .2, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#endif
m_internalFramebuf->m_shader.use();
GLint ObjIdPos = m_internalFramebuf->m_shader.getUniformLocation("ObjIdIn");
GLint ObjColPos = m_internalFramebuf->m_shader.getUniformLocation("ObjColor");
GLint TeamId = m_internalFramebuf->m_shader.getUniformLocation("TeamId");
GLint CamPosLoc = m_internalFramebuf->m_shader.getUniformLocation("CameraPosition");
static auto lasttime = boost::chrono::high_resolution_clock::now();
@ -151,30 +168,42 @@ void MainViewport::Draw() {
glm::mat4 projectionMatrix = glm::perspective(
glm::radians(
fov), // The vertical Field of View, in radians: the amount of "zoom". Think "camera lens". Usually between 90° (extra wide) and 30° (quite zoomed in)
(float) framewidth /
(float) frameheight, // Aspect Ratio. Depends on the size of your window. Notice that 4/3 == 800/600 == 1280/960, sounds familiar ?
0.1f, // Near clipping plane. Keep as big as possible, or you'll get precision issues.
10000.0f // Far clipping plane. Keep as little as possible.
(float) m_internalFramebuf->getSize().x /
(float) m_internalFramebuf->getSize().y, // Aspect Ratio. Depends on the size of your window. Notice that 4/3 == 800/600 == 1280/960, sounds familiar ?
NearClippingPlane, // Near clipping plane. Keep as big as possible, or you'll get precision issues.
FarClippingPlane // Far clipping plane. Keep as little as possible.
);
//glm::mat4 ViewMatrix = glm::translate(glm::mat4(1.0f), -camPos);
glm::mat4 ViewMatrix = glm::lookAt(camPos, camPos + cameraDirection, glm::vec3(0, 1, 0));
glm::mat4 ModelMat = glm::mat4(1.0f);
VP = projectionMatrix * ViewMatrix;// * ViewMatrix * ModelMat;
glUniform3f(CamPosLoc, camPos.x,camPos.y,camPos.z);
if (ImGui::BeginPopup("Main VP Debug")) {
ImGui::DragFloat3("Camera Postion", &camPos.x, 0.01);
ImGui::DragFloat2("Camera Rotation", &camrot.x, 0.01);
ImGui::SliderFloat("FOV", &fov, 0, 180);
ImGui::DragFloat("Speed", &speed, 1);
ImGui::DragFloat("Near Clipping Plane", &NearClippingPlane, 1);
ImGui::DragFloat("Far Clipping Plane", &FarClippingPlane, 1);
ImGui::DragFloat("Shadow Area", &shadowArea, 0.01);
//ImGui::SliderFloat("Shading Effectiveness", &ShadingEffectiveness, 0, 1);
ImGui::DragFloat3("Light Direction", &LightDir.x, 0.01);
ImGui::Checkbox("Draw All Areas", &drawAllAreas);
ImGui::EndPopup();
}
GLuint MatrixID = glGetUniformLocation(shader.ShaderId, "VP");
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, glm::value_ptr(VP));
m_internalFramebuf->m_shader.use();
GLint LightDirId = m_internalFramebuf->m_shader.getUniformLocation("LightDirection");
glUniform3f(LightDirId, LightDir.x , LightDir.y,LightDir.z);
auto &map = GetMainWindow()->loadedMap;
@ -183,25 +212,82 @@ void MainViewport::Draw() {
glClearBufferuiv(GL_COLOR, 0, ClearID);
glDrawBuffer(GL_COLOR_ATTACHMENT2);
GLfloat ClearPos[] = {0,0,0,0};
GLfloat ClearPos[] = {0, 0, 0, 0};
glClearBufferfv(GL_COLOR, 0, ClearPos);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
unsigned int ObjID = 16;
glm::vec3 SunPos = (glm::normalize(LightDir) * 1500.0f) + camPos;
glm::mat4 SunProj = glm::ortho(-shadowArea,shadowArea,-shadowArea,shadowArea,1.0f,4000.0f);
glm::mat4 SunView = glm::lookAt(SunPos,camPos,{0,1,0});
glm::mat4 SunVP = SunProj * SunView;
SunCam->bind();
SunCam->m_shader.use();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glClear(GL_DEPTH_BUFFER_BIT);
for (auto &obj: map.Objects) {
if(IsArea(obj.Type) && !drawAllAreas){
if (IsArea(obj.Type)) {
continue;
}
if (!MdlFromObj.contains(obj.Type)) {
if (boost::filesystem::exists(
boost::filesystem::current_path() / "Models" / obj.Type / (obj.Type + ".dae")))
MdlFromObj.insert({obj.Type, Model(obj.Type)});
else {
MdlFromObj.insert({obj.Type, Model("St_Default")});
std::cout << "Model missing: \n\t" << obj.Type << std::endl;
}
}
auto &mdl = MdlFromObj.find(obj.Type)->second;
mdl.Draw(obj.TF, SunCam->m_shader, SunVP);
}
m_internalFramebuf->bind();
m_internalFramebuf->m_shader.use();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
auto tex = SunCam->getFbTexByAttachment(GL_DEPTH_ATTACHMENT);
tex.m_texture.setActive(5);
GLint SunVpLoc = m_internalFramebuf->m_shader.getUniformLocation("SunVP");
glUniformMatrix4fv(SunVpLoc,1,GL_FALSE,&SunVP[0][0]);
for (auto &obj: map.Objects) {
glUniform1i(TeamId,(GLint)obj.Team);
if (IsArea(obj.Type) && !drawAllAreas) {
ObjID++;
continue;
} else if(IsArea(obj.Type) && drawAllAreas) {
} else if (IsArea(obj.Type) && drawAllAreas) {
static auto AreaMdl = Model("St_Area");
glUniform1ui(ObjIdPos, ObjID);
glUniform4f(ObjColPos, 1, 1, 1, 1);
AreaMdl.Draw(obj.TF);
AreaMdl.Draw(obj.TF, m_internalFramebuf->m_shader, VP);
ObjID++;
continue;
}
@ -217,45 +303,48 @@ void MainViewport::Draw() {
}
auto mdl = MdlFromObj.find(obj.Type)->second;
auto &mdl = MdlFromObj.find(obj.Type)->second;
glUniform1ui(ObjIdPos, ObjID);
glUniform4f(ObjColPos, 1, 1, 1, 1);
if(&obj == GetMainWindow()->selectedElem)
if (&obj == GetMainWindow()->selectedElem)
glUniform4f(ObjColPos, 1, .7, .7, 1);
mdl.Draw(obj.TF);
mdl.Draw(obj.TF, m_internalFramebuf->m_shader, VP);
ObjID++;
}
if (GetMainWindow()->selectedElem != nullptr) {
auto selobj = GetMainWindow()->selectedElem;
if(IsArea(selobj->Type)) {
if (IsArea(selobj->Type)) {
static auto AreaMdl = Model("St_Area");
glUniform1ui(ObjIdPos, 0);
AreaMdl.Draw(selobj->TF);
AreaMdl.Draw(selobj->TF, m_internalFramebuf->m_shader, VP);
}
glClear(GL_DEPTH_BUFFER_BIT);
if(Rail* rail = dynamic_cast<Rail*>(GetMainWindow()->selectedElem)){
static Model Arrow = Model("St_RailPoint");
for (Link &link: GetMainWindow()->selectedElem->Links) {
glUniform1ui(ObjIdPos, 0);
Element *elem = GetMainWindow()->loadedMap.GetElementById(link.Destination);
if (elem == nullptr)
continue;
if(rail->Points.size() > 1) {
auto lastRailPoint = rail->Points.front();
for (RailPoint &railPoint: rail->Points) {
Arrow.Draw(railPoint.TF);
}
if (Rail *rail = dynamic_cast<Rail *>(elem)) {
RenderRail(rail);
}
}
if (Rail *rail = dynamic_cast<Rail *>(GetMainWindow()->selectedElem)) {
glUniform1ui(ObjIdPos, 0);
RenderRail(rail);
}
//mdl.DrawSelection(selobj->TF);
glClear(GL_DEPTH_BUFFER_BIT);
@ -265,30 +354,30 @@ void MainViewport::Draw() {
auto tf = Transform();
tf.Position = selobj->TF.Position;
float size = glm::distance(glm::vec3(tf.Position.X,tf.Position.Y,tf.Position.Z),camPos);
// float size = glm::distance(glm::vec3(tf.Position.X, tf.Position.Y, tf.Position.Z), camPos);
//tf.Scale = {size/ 50, size/ 50, size/ 50};
tf.Scale = {1,1,1};
tf.Scale = {1, 1, 1};
tf.Rotation = {0, 0, 90};
glUniform4f(ObjColPos, 0.5, 0, 0, 1);
if(HoveredObjId == 1)
if (HoveredObjId == 1)
glUniform4f(ObjColPos, 1, 0, 0, 1);
glUniform1ui(ObjIdPos, 1);
Arrow.Draw(tf);
Arrow.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {0, 0, 0};
glUniform4f(ObjColPos, 0, 0.5, 0, 1);
if(HoveredObjId == 2)
if (HoveredObjId == 2)
glUniform4f(ObjColPos, 0, 1, 0, 1);
glUniform1ui(ObjIdPos, 2);
Arrow.Draw(tf);
Arrow.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {90, 0, 0};
glUniform4f(ObjColPos, 0, 0, 0.5, 1);
if(HoveredObjId == 3)
if (HoveredObjId == 3)
glUniform4f(ObjColPos, 0, 0, 1, 1);
glUniform1ui(ObjIdPos, 3);
Arrow.Draw(tf);
Arrow.Draw(tf, m_internalFramebuf->m_shader, VP);
glUniform4f(ObjColPos, 1, 1, 1, 1);
} else if (CurrentGizmoType == Scale) {
@ -296,30 +385,30 @@ void MainViewport::Draw() {
auto tf = Transform();
tf.Position = selobj->TF.Position;
float size = glm::distance(glm::vec3(tf.Position.X,tf.Position.Y,tf.Position.Z),camPos);
// float size = glm::distance(glm::vec3(tf.Position.X, tf.Position.Y, tf.Position.Z), camPos);
//tf.Scale = {size/ 50, size/ 50, size/ 50};
tf.Scale = {1,1,1};
tf.Scale = {1, 1, 1};
tf.Rotation = {selobj->TF.Rotation.X + 90, selobj->TF.Rotation.Y + 90, selobj->TF.Rotation.Z};
glUniform4f(ObjColPos, 0.5, 0, 0, 1);
if(HoveredObjId == 1)
if (HoveredObjId == 1)
glUniform4f(ObjColPos, 1, 0, 0, 1);
glUniform1ui(ObjIdPos, 1);
Scalar.Draw(tf);
Scalar.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {selobj->TF.Rotation.X, selobj->TF.Rotation.Y, selobj->TF.Rotation.Z};
glUniform4f(ObjColPos, 0, 0.5, 0, 1);
if(HoveredObjId == 2)
if (HoveredObjId == 2)
glUniform4f(ObjColPos, 0, 1, 0, 1);
glUniform1ui(ObjIdPos, 2);
Scalar.Draw(tf);
Scalar.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {selobj->TF.Rotation.X + 90 , selobj->TF.Rotation.Y, selobj->TF.Rotation.Z};
tf.Rotation = {selobj->TF.Rotation.X + 90, selobj->TF.Rotation.Y, selobj->TF.Rotation.Z};
glUniform4f(ObjColPos, 0, 0, 0.5, 1);
if(HoveredObjId == 3)
if (HoveredObjId == 3)
glUniform4f(ObjColPos, 0, 0, 1, 1);
glUniform1ui(ObjIdPos, 3);
Scalar.Draw(tf);
Scalar.Draw(tf, m_internalFramebuf->m_shader, VP);
glUniform4f(ObjColPos, 1, 1, 1, 1);
} else if (CurrentGizmoType == Rotate) {
@ -327,30 +416,30 @@ void MainViewport::Draw() {
auto tf = Transform();
tf.Position = selobj->TF.Position;
float size = glm::distance(glm::vec3(tf.Position.X,tf.Position.Y,tf.Position.Z),camPos);
// float size = glm::distance(glm::vec3(tf.Position.X, tf.Position.Y, tf.Position.Z), camPos);
//tf.Scale = {size/ 50, size/ 50, size/ 50};
tf.Scale = {1,1,1};
tf.Scale = {1, 1, 1};
tf.Rotation = {0, 0, 90};
glUniform4f(ObjColPos, 0.5, 0, 0, 1);
if(HoveredObjId == 1)
if (HoveredObjId == 1)
glUniform4f(ObjColPos, 1, 0, 0, 1);
glUniform1ui(ObjIdPos, 1);
Rotator.Draw(tf);
Rotator.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {0, 0, 0};
glUniform4f(ObjColPos, 0, 0.5, 0, 1);
if(HoveredObjId == 2)
if (HoveredObjId == 2)
glUniform4f(ObjColPos, 0, 1, 0, 1);
glUniform1ui(ObjIdPos, 2);
Rotator.Draw(tf);
Rotator.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {90, 0, 0};
glUniform4f(ObjColPos, 0, 0, 0.5, 1);
if(HoveredObjId == 3)
if (HoveredObjId == 3)
glUniform4f(ObjColPos, 0, 0, 1, 1);
glUniform1ui(ObjIdPos, 3);
Rotator.Draw(tf);
Rotator.Draw(tf, m_internalFramebuf->m_shader, VP);
glUniform4f(ObjColPos, 1, 1, 1, 1);
}
@ -369,23 +458,23 @@ inline float GetVecComponent(const t &v1, const t &v2) {
template<typename t>
inline t ProjectToRayNormalized(const t &v1, const t &ray) {
return glm::dot(v1, ray) / glm::dot(ray,ray) * ray;
return glm::dot(v1, ray) / glm::dot(ray, ray) * ray;
}
template<typename t>
inline t ProjectToRay(const t &v1,const t &rayStart, const t &ray) {
return ProjectToRayNormalized(v1-rayStart,ray - rayStart) + rayStart;
inline t ProjectToRay(const t &v1, const t &rayStart, const t &ray) {
return ProjectToRayNormalized(v1 - rayStart, ray - rayStart) + rayStart;
}
template<typename t>
inline t ProjectToRayNormDir(const t &v1,const t &rayStart, const t &RayDir) {
return ProjectToRayNormalized(v1-rayStart,RayDir) + rayStart;
inline t ProjectToRayNormDir(const t &v1, const t &rayStart, const t &RayDir) {
return ProjectToRayNormalized(v1 - rayStart, RayDir) + rayStart;
}
glm::vec3 MainViewport::ScreenSpaceToRay(glm::vec2 ScreenPos){
glm::vec3 MainViewport::ScreenSpaceToRay(glm::vec2 ScreenPos) {
auto InverseVP = glm::inverse(VP);
glm::vec4 worldPos = InverseVP * glm::vec4(ScreenPos,1.0,1.0);
glm::vec4 worldPos = InverseVP * glm::vec4(ScreenPos, 1.0, 1.0);
glm::vec3 dir = glm::normalize(glm::vec3(worldPos));
@ -401,7 +490,7 @@ void MainViewport::HandleInput(InputEvent event) {
glm::vec2 DeltaMousePos = currentMpos - lastMpos;
static glm::vec3 ObjBindingVec = {0,0,0};
static glm::vec3 ObjBindingVec = {0, 0, 0};
static float ObjScalingDist = 0.0f;
static glm::vec3 GizmoDir = glm::vec3(1, 1, 1);
@ -410,19 +499,19 @@ void MainViewport::HandleInput(InputEvent event) {
auto SelObj = GetMainWindow()->selectedElem;
switch (event.EventType) {
case (InputType::MouseHover):{
GLint y = event.y * frameheight;
GLint x = event.x * framewidth;
case (InputType::MouseHover): {
GLint y = event.y * m_internalFramebuf->getSize().y;
GLint x = event.x * m_internalFramebuf->getSize().x;
glReadBuffer(GL_COLOR_ATTACHMENT1);
glReadPixels(x,y,1,1, GL_RED_INTEGER, GL_UNSIGNED_INT, &HoveredObjId);
glReadPixels(x, y, 1, 1, GL_RED_INTEGER, GL_UNSIGNED_INT, &HoveredObjId);
}
break;
break;
case (InputType::MouseDownL): {
GLint y = event.y * frameheight;
GLint x = event.x * framewidth;
GLint y = event.y * m_internalFramebuf->getSize().y;
GLint x = event.x * m_internalFramebuf->getSize().x;
glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, m_internalFramebuf->getId());
glReadBuffer(GL_COLOR_ATTACHMENT1);
unsigned int obj = 0;
@ -432,7 +521,7 @@ void MainViewport::HandleInput(InputEvent event) {
if (obj < 16) {
SpecialObjCur = obj;
if (CurrentGizmoType == Move) {
if(0 < obj && obj <= 3 ) {
if (0 < obj && obj <= 3) {
if (obj == 1) {
GizmoDir = {1, 0, 0};
} else if (obj == 2) {
@ -442,19 +531,20 @@ void MainViewport::HandleInput(InputEvent event) {
}
glReadBuffer(GL_COLOR_ATTACHMENT2);
glm::vec4 CurWDirPos = {0,0,0,0};
glm::vec4 CurWDirPos = {0, 0, 0, 0};
glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, glm::value_ptr(CurWDirPos));
glm::vec3 GizmoDirPrePos = ProjectToRayNormalized({CurWDirPos.x,CurWDirPos.y,CurWDirPos.z},GizmoDir);
glm::vec3 objpos = {SelObj->TF.Position.X,SelObj->TF.Position.Y,SelObj->TF.Position.Z};
glm::vec3 GizmoDirPrePos = ProjectToRayNormalized({CurWDirPos.x, CurWDirPos.y, CurWDirPos.z},
GizmoDir);
glm::vec3 objpos = {SelObj->TF.Position.X, SelObj->TF.Position.Y, SelObj->TF.Position.Z};
ObjBindingVec = objpos - GizmoDirPrePos;
std::cout << glm::to_string(ObjBindingVec) << std::endl;
}
} else if(CurrentGizmoType == Scale){
if(0 < obj && obj <= 3 ) {
} else if (CurrentGizmoType == Scale) {
if (0 < obj && obj <= 3) {
if (obj == 1) {
GizmoDir = {1, 0, 0};
} else if (obj == 2) {
@ -465,23 +555,24 @@ void MainViewport::HandleInput(InputEvent event) {
auto TF = SelObj->TF;
TF.Scale = {1,1,1};
TF.Position = {0,0,0};
TF.Scale = {1, 1, 1};
TF.Position = {0, 0, 0};
auto mat = TransformToMatrix(TF);
GizmoDir = mat * glm::vec4(GizmoDir,1);
GizmoDir = mat * glm::vec4(GizmoDir, 1);
glReadBuffer(GL_COLOR_ATTACHMENT2);
glm::vec4 CurWDirPos = {0,0,0,0};
glm::vec4 CurWDirPos = {0, 0, 0, 0};
glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, glm::value_ptr(CurWDirPos));
glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, glm::value_ptr(CurWDirPos));
glm::vec3 GizmoDirPrePos = ProjectToRayNormalized({CurWDirPos.x,CurWDirPos.y,CurWDirPos.z},GizmoDir);
glm::vec3 GizmoDirPrePos = ProjectToRayNormalized({CurWDirPos.x, CurWDirPos.y, CurWDirPos.z},
GizmoDir);
glm::vec3 objpos = ToGlmVec3(SelObj->TF.Position);
ObjScalingDist = glm::distance(ProjectToRayNormalized(objpos,GizmoDir), GizmoDirPrePos);
ObjScalingDist = glm::distance(ProjectToRayNormalized(objpos, GizmoDir), GizmoDirPrePos);
ObjBindingVec = ToGlmVec3(SelObj->TF.Scale);
@ -518,17 +609,17 @@ void MainViewport::HandleInput(InputEvent event) {
}
break;
case (InputType::MouseHoldL): {
GLint y = event.y * frameheight;
GLint x = event.x * framewidth;
GLint y = event.y * m_internalFramebuf->getSize().y;
GLint x = event.x * m_internalFramebuf->getSize().x;
glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, m_internalFramebuf->getId());
glReadBuffer(GL_COLOR_ATTACHMENT1);
unsigned int obj = 0;
glReadPixels(x, y, 1, 1, GL_RED_INTEGER, GL_UNSIGNED_INT, &obj);
if (CurrentGizmoType == Move) {
if(SpecialObjCur == 0) {
if (SpecialObjCur == 0) {
return;
}
/*if(SpecialObjCur != obj){
@ -538,8 +629,8 @@ void MainViewport::HandleInput(InputEvent event) {
auto tf = SelObj->TF;
tf.Rotation = {0,0,0};
tf.Scale = {1,1,1};
tf.Rotation = {0, 0, 0};
tf.Scale = {1, 1, 1};
auto Tf = TransformToMatrix(tf);
@ -551,28 +642,34 @@ void MainViewport::HandleInput(InputEvent event) {
GizmoDir = {0, 0, 1};
}
auto ClipSpaceStart = (VP * Tf) * glm::vec4(0,0,0,1);
auto ClipSpaceEnd = (VP * Tf) * glm::vec4(GizmoDir,1);
auto ClipSpaceStart = (VP * Tf) * glm::vec4(0, 0, 0, 1);
auto ClipSpaceEnd = (VP * Tf) * glm::vec4(GizmoDir, 1);
glm::vec2 ScreenSpaceStart = {((ClipSpaceStart.x/ClipSpaceStart.w + 1 ) / 2) * framewidth, ((ClipSpaceStart.y/ClipSpaceStart.w + 1 ) / 2) * frameheight };
glm::vec2 ScreenSpaceEnd = {((ClipSpaceEnd.x/ClipSpaceEnd.w + 1 ) / 2) * framewidth, ((ClipSpaceEnd.y/ClipSpaceEnd.w + 1 ) / 2) * frameheight};
glm::vec2 ScreenSpaceStart = {
((ClipSpaceStart.x / ClipSpaceStart.w + 1) / 2) * (float)m_internalFramebuf->getSize().x,
((ClipSpaceStart.y / ClipSpaceStart.w + 1) / 2) * (float)m_internalFramebuf->getSize().y};
glm::vec2 ScreenSpaceEnd = {
((ClipSpaceEnd.x / ClipSpaceEnd.w + 1) / 2) * (float)m_internalFramebuf->getSize().x,
((ClipSpaceEnd.y / ClipSpaceEnd.w + 1) / 2) * (float)m_internalFramebuf->getSize().y};
glm::vec2 ScrenSpaceDir = ScreenSpaceEnd - ScreenSpaceStart;
glm::vec2 MousePos = {x,y};
glm::vec2 MousePos = {x, y};
glm::vec2 FixedMousePos = ProjectToRayNormDir(MousePos,ScreenSpaceStart,ScrenSpaceDir);
glm::vec2 FixedMousePos = ProjectToRayNormDir(MousePos, ScreenSpaceStart, ScrenSpaceDir);
//SpecialObjCur = obj;
if(0 < SpecialObjCur && SpecialObjCur <= 3 ) {
if (0 < SpecialObjCur && SpecialObjCur <= 3) {
glReadBuffer(GL_COLOR_ATTACHMENT2);
glm::vec4 CurWDirPos = {0,0,0,0};
glm::vec4 CurWDirPos = {0, 0, 0, 0};
glReadPixels(floorf(FixedMousePos.x), floorf(FixedMousePos.y), 1, 1, GL_RGBA, GL_FLOAT, glm::value_ptr(CurWDirPos));
glReadPixels((int)floorf(FixedMousePos.x), (int)floorf(FixedMousePos.y), 1, 1, GL_RGBA, GL_FLOAT,
glm::value_ptr(CurWDirPos));
//std::cout << glm::to_string(CurWDirPos) << std::endl;
auto DirProjectedTranslationPos = ProjectToRayNormalized({CurWDirPos.x,-CurWDirPos.y,CurWDirPos.z},GizmoDir);
auto DirProjectedTranslationPos = ProjectToRayNormalized(
{CurWDirPos.x, CurWDirPos.y, CurWDirPos.z}, GizmoDir);
if (SpecialObjCur == 1) {
SelObj->TF.Position.X = ObjBindingVec.x + DirProjectedTranslationPos.x;
@ -582,19 +679,19 @@ void MainViewport::HandleInput(InputEvent event) {
SelObj->TF.Position.Z = ObjBindingVec.z + DirProjectedTranslationPos.z;
}
glm::vec3 objpos = {SelObj->TF.Position.X,SelObj->TF.Position.Y,SelObj->TF.Position.Z};
glm::vec3 objpos = {SelObj->TF.Position.X, SelObj->TF.Position.Y, SelObj->TF.Position.Z};
ObjBindingVec = objpos - DirProjectedTranslationPos;
lastMpos = currentMpos;
}
} else if (CurrentGizmoType == Scale) {
if(SpecialObjCur == 0)
if (SpecialObjCur == 0)
return;
if(SpecialObjCur != obj){
if (SpecialObjCur != obj) {
SpecialObjCur = 0;
return;
}
if(0 < SpecialObjCur && SpecialObjCur <= 3 ) {
if (0 < SpecialObjCur && SpecialObjCur <= 3) {
SpecialObjCur = obj;
if (obj == 1) {
GizmoDir = {1, 0, 0};
@ -606,15 +703,15 @@ void MainViewport::HandleInput(InputEvent event) {
auto TF = SelObj->TF;
TF.Scale = {1,1,1};
TF.Position = {0,0,0};
TF.Scale = {1, 1, 1};
TF.Position = {0, 0, 0};
auto mat = TransformToMatrix(TF);
GizmoDir = mat * glm::vec4(GizmoDir,1);
GizmoDir = mat * glm::vec4(GizmoDir, 1);
glReadBuffer(GL_COLOR_ATTACHMENT2);
glm::vec4 CurWDirPos = {0,0,0,0};
glm::vec4 CurWDirPos = {0, 0, 0, 0};
//GizmoDir = glm::normalize( * GizmoDir)
glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, glm::value_ptr(CurWDirPos));
@ -623,31 +720,34 @@ void MainViewport::HandleInput(InputEvent event) {
ObjPos.y = -ObjPos.y;
CurWDirPos -= glm::vec4(ObjPos,1);
CurWDirPos -= glm::vec4(ObjPos, 1);
auto DirProjectedTranslationPos = ProjectToRayNormalized(
{CurWDirPos.x, CurWDirPos.y, CurWDirPos.z}, GizmoDir);
auto DirProjectedTranslationPos = ProjectToRayNormalized({CurWDirPos.x,-CurWDirPos.y,CurWDirPos.z},GizmoDir);
float VecComp = GetVecComponent(DirProjectedTranslationPos,GizmoDir);
float VecComp = GetVecComponent(DirProjectedTranslationPos, GizmoDir);
float DeltaInDir = 0;
if (SpecialObjCur == 1) {
DeltaInDir = (ObjBindingVec.x + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.x) - SelObj->TF.Scale.X;
DeltaInDir = (ObjBindingVec.x + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.x) -
SelObj->TF.Scale.X;
SelObj->TF.Scale.X = ObjBindingVec.x + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.x;
} else if (SpecialObjCur == 2) {
DeltaInDir = (ObjBindingVec.y + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.y) - SelObj->TF.Scale.Y;
DeltaInDir = (ObjBindingVec.y + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.y) -
SelObj->TF.Scale.Y;
SelObj->TF.Scale.Y = ObjBindingVec.y + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.y;
} else if (SpecialObjCur == 3) {
DeltaInDir = (ObjBindingVec.z + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.z) - SelObj->TF.Scale.Z;
DeltaInDir = (ObjBindingVec.z + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.z) -
SelObj->TF.Scale.Z;
SelObj->TF.Scale.Z = ObjBindingVec.z + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.z;
}
if(ImGui::IsKeyDown(ImGuiKey_LeftCtrl)){
if(SpecialObjCur != 1) SelObj->TF.Scale.X += DeltaInDir;
if(SpecialObjCur != 2) SelObj->TF.Scale.Y += DeltaInDir;
if(SpecialObjCur != 3) SelObj->TF.Scale.Z += DeltaInDir;
if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl)) {
if (SpecialObjCur != 1) SelObj->TF.Scale.X += DeltaInDir;
if (SpecialObjCur != 2) SelObj->TF.Scale.Y += DeltaInDir;
if (SpecialObjCur != 3) SelObj->TF.Scale.Z += DeltaInDir;
}
lastMpos = currentMpos;
@ -665,10 +765,12 @@ void MainViewport::HandleInput(InputEvent event) {
break;
case (InputType::MouseHoldR):
ImGui::SetWindowFocus();
camrot.x += (lastMpos.x - currentMpos.x) * (float) framewidth * .1f;
camrot.y -= (lastMpos.y - currentMpos.y) * (float) frameheight * .1f;
camrot.x += (lastMpos.x - currentMpos.x) * (float) m_internalFramebuf->getSize().x * .1f;
camrot.y += (lastMpos.y - currentMpos.y) * (float) m_internalFramebuf->getSize().y * .1f;
lastMpos = currentMpos;
break;
default:
break;
}
}

View file

@ -7,12 +7,14 @@
#include <queue>
#include "virintox/gcore/ViewportWidget.h"
#include "virintox/gcore/gui/ViewportWidget.h"
#include "virintox/gcore/Shader.h"
#include "glm/vec3.hpp"
#include "virintox/gcore/Mesh.h"
#include "Model.h"
#include "boost/thread.hpp"
#include "Rail.h"
#include "LevelObject.h"
enum GizmoType{
Move,Rotate,Scale
@ -22,14 +24,14 @@ class MainViewport : public Graphics::ViewportWidget {
public:
MainViewport();
Graphics::Shader shader;
glm::vec3 camPos = glm::vec3(0,0,0);
glm::vec2 camrot = glm::vec2(0,0);
float shadowArea = 750.0f;
float fov = 90.0f;
std::vector<std::vector<unsigned int>> PixelToObjNum;
//std::vector<std::vector<unsigned int>> PixelToObjNum;
float speed = 100.0f;
bool drawAllAreas = false;
@ -42,12 +44,23 @@ private:
std::map<std::string,Model> MdlFromObj;
float FarClippingPlane = 10000.0f;
float NearClippingPlane = 0.1f;
glm::mat4 VP;
glm::vec3 LightDir = {1,1,1};
float ShadingEffectiveness = 0.5f;
void RenderRail(Rail* rail);
//Graphics::Mesh ObjMesh;
glm::vec2 CalcGizmoDir(glm::vec3 dir);
glm::vec3 ScreenSpaceToRay(glm::vec2);
void DrawOver() override;
std::unique_ptr<Graphics::Framebuffer> SunCam;
public:
void HandleInput(InputEvent event) override;

View file

@ -3,7 +3,7 @@
#include "ObjectSelectWidget.h"
#include "RailSelectWidget.h"
#include "MainViewport.h"
#include <virintox/gcore/FileSelectDialog.h>
#include <virintox/gcore/gui/FileSelectDialog.h>
#include <virintox/gcore/Graphics.h>
#include<imgui.h>
#include <IconsFontAwesome6.h>
@ -85,6 +85,16 @@ MainWindow::MainWindow(): Graphics::Window("SpoonEdit") {
MainWindowInst->WidgetByName.find("Properties")->second->Active ^= true;
});
AddMenu("Game");
AddMenuItem("Game", "Gambit(1)", [&](){
gameSetting = GameMode::Gambit;
});
AddMenuItem("Game", "Blitz(2)", [&](){
gameSetting = GameMode::Blitz;
});
AddMenuItem("Game", "Thunder(3)", [&](){
gameSetting = GameMode::Thunder;
});
AddMenu("Object");
@ -108,6 +118,16 @@ MainWindow::MainWindow(): Graphics::Window("SpoonEdit") {
ObjCpy.TF.Rotation = {0, 0, 0};
ObjCpy.TF.Position = {0, 0, 0};
for(long &param: ObjCpy.Parameters){
param = -99;
}
for(float &param: ObjCpy.FloatParameters){
param = -99.0f;
}
ObjCpy.Layer = Common;
ExportObj(ObjCpy);
}
}
@ -127,6 +147,17 @@ MainWindow::MainWindow(): Graphics::Window("SpoonEdit") {
LevelObject ObjCpy = LevelObject(obj);
ObjCpy.Name = ObjCpy.Type;
ObjCpy.Links = std::vector<Link>();
for(long &param: ObjCpy.Parameters){
param = -99;
}
for(float &param: ObjCpy.FloatParameters){
param = -99.0f;
}
ObjCpy.Layer = Common;
ObjCpy.TF.Scale = {1, 1, 1};
ObjCpy.TF.Rotation = {0, 0, 0};
ObjCpy.TF.Position = {0, 0, 0};
@ -146,6 +177,11 @@ void MainWindow::Update() {
}
void MainWindow::MenuExtraRender() {
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - ImGui::CalcTextSize(("Game: " + GameMode::ToString(gameSetting) + " ").c_str()).x);
ImGui::Text("%s", ("Game: " + GameMode::ToString(gameSetting)).c_str());
}
MainWindow* GetMainWindow(){
return MainWindowInst;
}

View file

@ -5,8 +5,30 @@
#ifndef SPOONTOOL_MAINWINDOW_H
#define SPOONTOOL_MAINWINDOW_H
#include<virintox/gcore/Window.h>
#include<virintox/gcore/gui/Window.h>
#include<Map.h>
namespace GameMode {
enum GameMode {
Gambit,
Blitz,
Thunder
};
inline std::string ToString(GameMode gameMode){
switch(gameMode){
case Gambit:
return "Gambit";
case Blitz:
return "Blitz";
case Thunder:
return "Thunder";
default:
return "Invalid";
}
}
inline std::array<GameMode,3> gameModes = {Gambit, Blitz, Thunder};
}
class MainWindow : public Graphics::Window {
@ -18,6 +40,10 @@ public:
void Update() override;
Element* selectedElem = nullptr;
GameMode::GameMode gameSetting = GameMode::Gambit;
protected:
void MenuExtraRender() override;
};
MainWindow* GetMainWindow();

View file

@ -9,8 +9,17 @@
#include <assimp/postprocess.h>
#include <virintox/gcore/Graphics.h>
#include "Transform.h"
#include<glm/mat4x4.hpp>
#include "glm/ext/vector_float3.hpp"
#include "glm/ext/matrix_transform.hpp"
#include<glm/mat3x2.hpp>
#include<glm/mat3x3.hpp>
#include<glm/vec3.hpp>
#include<glm/vec2.hpp>
Model::Model(std::string modelname) {
CopyCount = new unsigned(1);
Model::Model(std::string modelname) {
auto modeltoload = boost::filesystem::current_path() / "Models" / modelname / (modelname + ".dae");
Assimp::Importer importer;
@ -19,6 +28,7 @@ Model::Model(std::string modelname) {
aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices |
// aiProcess_Debone |
aiProcess_GenNormals |
aiProcess_FlipUVs |
aiProcess_SortByPType);
@ -32,38 +42,33 @@ Model::Model(std::string modelname) {
auto mesh = scene->mMeshes[i];
auto mat = scene->mMaterials[mesh->mMaterialIndex];
std::string firsttex;
for(unsigned int currenttex = 0; currenttex < mat->GetTextureCount(aiTextureType_DIFFUSE); currenttex++){
aiString string;
mat->GetTexture(aiTextureType_DIFFUSE, 0, &string);
if(firsttex == "")
firsttex = string.C_Str();
else
Graphics::window->msgBoxes.push_back(new Graphics::MessageBox("SUS ඞ",Graphics::ErrorSeverity::Error));
Textures.emplace_back((boost::filesystem::current_path() / "Models" / modelname / string.C_Str()));
}
if(firsttex == ""){
Textures.emplace_back((boost::filesystem::current_path() / "Models" / "Missing.png"));
}
Materials.push_back(new Graphics::Material(mat,boost::filesystem::current_path() / "Models" / modelname));
auto vertices = std::vector<glm::vec3>();
auto texcoords = std::vector<glm::vec2>();
auto normals = std::vector<glm::vec3>();
auto tangents = std::vector<glm::vec3>();
auto bitangents = std::vector<glm::vec3>();
auto indices = std::vector<GLuint>();
for(unsigned int verticienum = 0; verticienum < mesh->mNumVertices; verticienum++){
vertices.emplace_back(mesh->mVertices[verticienum].x,mesh->mVertices[verticienum].y,mesh->mVertices[verticienum].z);
normals.emplace_back(mesh->mNormals[verticienum].x,mesh->mNormals[verticienum].y,mesh->mNormals[verticienum].z);
if (mesh->HasTextureCoords(0)) // Only slot [0] is in question.
{
texcoords.emplace_back(mesh->mTextureCoords[0][verticienum].x,mesh->mTextureCoords[0][verticienum].y);
tangents.emplace_back(mesh->mTangents[verticienum].x,mesh->mTangents[verticienum].y,mesh->mTangents[verticienum].z);
bitangents.emplace_back(mesh->mBitangents[verticienum].x,mesh->mBitangents[verticienum].y,mesh->mBitangents[verticienum].z);
}
else
else {
texcoords.emplace_back(0.0f, 0.0f);
tangents.emplace_back(mesh->mNormals[verticienum].x,mesh->mNormals[verticienum].y,mesh->mNormals[verticienum].z);
bitangents.emplace_back(mesh->mNormals[verticienum].x,mesh->mNormals[verticienum].y,mesh->mNormals[verticienum].z);
}
}
for (unsigned int i3 = 0; i3 < mesh->mNumFaces; ++i3) {
@ -73,40 +78,84 @@ Model::Model(std::string modelname) {
indices.push_back(mesh->mFaces[i3].mIndices[i4]);
}
Meshes.emplace_back(vertices,indices,texcoords,GetMainViewport()->shader);
Meshes.push_back(new Graphics::Mesh(vertices,indices,texcoords,normals,tangents,bitangents));
}
}
void Model::Draw(Transform tf) {
void Model::Draw(Transform tf, Graphics::Shader &shader, glm::mat4 VP) {
unsigned int texnum = 0;
for(auto mesh: Meshes){
for(auto& mesh: Meshes){
glm::vec3 pos(tf.Position.X,tf.Position.Y,tf.Position.Z);
glm::vec3 rot(-tf.Rotation.X,tf.Rotation.Y,-tf.Rotation.Z);
glm::vec3 rot(tf.Rotation.X,tf.Rotation.Y,tf.Rotation.Z);
glm::vec3 normalRot(tf.Rotation.X,tf.Rotation.Y,tf.Rotation.Z);
glm::vec3 scale(tf.Scale.X,tf.Scale.Y,tf.Scale.Z);
mesh.Draw(Textures[texnum],pos,scale,rot);
glm::mat4 translationMatrix = glm::translate(glm::mat4(1),glm::vec3(pos.x,pos.y,pos.z));
glm::mat4 translationNoYInvertMatrix = glm::translate(glm::mat4(1),glm::vec3(pos.x,pos.y,pos.z));
glm::mat4 rotationMatrixZ = glm::rotate(glm::mat4(1),glm::radians(rot.z), glm::vec3(0,0,1));
glm::mat4 rotationMatrixY = glm::rotate(rotationMatrixZ,glm::radians(rot.y), glm::vec3(0,1,0));
glm::mat4 rotationMatrix = glm::rotate(rotationMatrixY,glm::radians(rot.x), glm::vec3(1,0,0));
glm::mat4 nrmRotationMatrixZ = glm::rotate(glm::mat4(1),glm::radians(normalRot.z), glm::vec3(0,0,1));
glm::mat4 nrmRotationMatrixY = glm::rotate(nrmRotationMatrixZ,glm::radians(normalRot.y), glm::vec3(0,1,0));
glm::mat4 nrmRotationMatrix = glm::rotate(nrmRotationMatrixY,glm::radians(normalRot.x), glm::vec3(1,0,0));
glm::mat4 scaleMatrix = glm::scale(glm::mat4(1),scale);
glm::mat4 matrix = VP * translationMatrix * rotationMatrix * scaleMatrix;
glm::mat4 ModelMatrix = translationMatrix * rotationMatrix * scaleMatrix;
glm::mat4 noYInvertMatrix = translationNoYInvertMatrix * nrmRotationMatrix * scaleMatrix;
GLuint MatrixID = shader.getUniformLocation("MVP");
glUniformMatrix4fv(MatrixID,1,GL_FALSE,&matrix[0][0]);
GLuint ModelMatrixID = shader.getUniformLocation("ModelMatrix");
glUniformMatrix4fv(ModelMatrixID,1,GL_FALSE,&ModelMatrix[0][0]);
GLuint MatrixNoYInvID = shader.getUniformLocation("TransformationMatrixNoYInv");
glUniformMatrix4fv(MatrixNoYInvID,1,GL_FALSE,&noYInvertMatrix[0][0]);
GLuint RotationMatrixID = shader.getUniformLocation("NormalRotationMatrix");
glUniformMatrix4fv(RotationMatrixID,1,GL_FALSE,&nrmRotationMatrix[0][0]);
mesh->Draw(Materials[texnum]);
texnum++;
}
}
void Model::DrawSelection(Transform tf) {
void Model::DrawSelection(Transform tf, Graphics::Shader &shader, glm::mat4 VP) {
unsigned int texnum = 0;
static Graphics::Texture selectionTex = Graphics::Texture((boost::filesystem::current_path() / "Models" / "selected.png"));
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
for(auto mesh: Meshes){
for(auto &mesh: Meshes){
glm::vec3 pos(tf.Position.X,tf.Position.Y,tf.Position.Z);
glm::vec3 rot(-tf.Rotation.X,tf.Rotation.Y,tf.Rotation.Z);
glm::vec3 scale(tf.Scale.X,tf.Scale.Y,tf.Scale.Z);
glm::mat4 translationMatrix = glm::translate(glm::mat4(1),glm::vec3(pos.x,-pos.y,pos.z));
glm::mat4 translationNoYInvertMatrix = glm::translate(glm::mat4(1),glm::vec3(pos.x,pos.y,pos.z));
glm::mat4 rotationMatrixZ = glm::rotate(glm::mat4(1),glm::radians(rot.z), glm::vec3(0,0,1));
glm::mat4 rotationMatrixY = glm::rotate(rotationMatrixZ,glm::radians(rot.y), glm::vec3(0,1,0));
glm::mat4 rotationMatrix = glm::rotate(rotationMatrixY,glm::radians(rot.x), glm::vec3(1,0,0));
glm::mat4 scaleMatrix = glm::scale(glm::mat4(1),scale);
glm::mat4 matrix = VP * translationMatrix * rotationMatrix * scaleMatrix;
glm::mat4 noYInvertMatrix = translationNoYInvertMatrix * rotationMatrix * scaleMatrix;
GLuint MatrixID = shader.getUniformLocation("MVP");
glUniformMatrix4fv(MatrixID,1,GL_FALSE,&matrix[0][0]);
GLuint MatrixNoYInvID = shader.getUniformLocation("TransformationMatrixNoYInv");
glUniformMatrix4fv(MatrixNoYInvID,1,GL_FALSE,&noYInvertMatrix[0][0]);
mesh.Draw(selectionTex,pos,scale,rot);
mesh->Draw(Materials[texnum]);
texnum++;
}
@ -115,4 +164,20 @@ void Model::DrawSelection(Transform tf) {
}
Model::~Model() {
(*CopyCount)--;
if((*CopyCount) == 0) {
for (Graphics::Material *mat: Materials)
delete mat;
for (Graphics::Mesh *mesh: Meshes)
delete mesh;
}
}
Model::Model(const Model &mdl): CopyCount(mdl.CopyCount), Meshes(mdl.Meshes), Materials(mdl.Materials) {
(*CopyCount)++;
}

View file

@ -10,17 +10,24 @@
#include<map>
#include "virintox/gcore/Mesh.h"
#include "Transform.h"
#include "virintox/gcore/Material.h"
class Model {
public:
Model(std::string modelName);
void Draw(Transform tf);
Model(const Model& mdl);
void DrawSelection(Transform tf);
~Model();
unsigned *CopyCount;
void Draw(Transform tf, Graphics::Shader &shader, glm::mat4 VP);
void DrawSelection(Transform tf, Graphics::Shader &shader, glm::mat4 VP);
protected:
std::vector<Graphics::Mesh> Meshes;
std::vector<Graphics::Texture> Textures;
std::list<Graphics::Mesh*> Meshes;
std::vector<Graphics::Material*> Materials;
//std::map<std::string,Graphics::Texture> TexturesForName;
};

View file

@ -6,7 +6,7 @@
#define SPOONTOOL_OBJECTSELECTWIDGET_H
#include "virintox/gcore/Widget.h"
#include "virintox/gcore/gui/Widget.h"
class ObjectSelectWidget: public Graphics::Widget {
public:

View file

@ -110,6 +110,14 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){
ImGuiDrawSelection("Link Type##" + std::to_string(i) + Id, link.Name, LinkTypes.begin(), LinkTypes.end(),
[](std::string s) { return s; });
ImGui::InputText(("Destination##PropWindLink" + std::to_string(i) + Id).c_str(), &link.Destination);
if(Element* gotoElem = GetMainWindow()->loadedMap.GetElementById(link.Destination)) {
ImGui::SameLine();
if (ImGui::Button(ICON_FA_CHEVRON_RIGHT)) {
GetMainWindow()->selectedElem = gotoElem;
}
}
ImGui::InputText(("Unit File##PropWindLink" + std::to_string(i) + Id).c_str(), &link.UnitFile);
if(ImGui::Button((ICON_FA_TRASH "##PropWindLinkDelete" + std::to_string(i) + Id).c_str())) {
elem->Links.erase(linkIter);
@ -188,9 +196,9 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){
if(!elem->Parameters.empty()) {
if (ImGui::CollapsingHeader(("Parameters##" + Id).c_str())) {
ImGui::Indent();
for (int i = 1; i <= elem->Parameters.size(); i++) {
for (int i = 0; i < elem->Parameters.size(); i++) {
ImGui::InputInt(("Parameter " + std::to_string(i) + "##PropWind" + Id).c_str(),
(int *) &elem->Parameters[i - 1]);
(int *) &elem->Parameters[i]);
}
ImGui::Unindent();
}
@ -199,9 +207,9 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){
if(!elem->FloatParameters.empty()) {
if (ImGui::CollapsingHeader(("Float Parameters##" + Id).c_str())) {
ImGui::Indent();
for (int i = 1; i <= elem->FloatParameters.size(); i++) {
for (int i = 0; i < elem->FloatParameters.size(); i++) {
ImGui::InputFloat(("Float Parameter " + std::to_string(i) + "##PropWind" + Id).c_str(),
&elem->FloatParameters[i - 1]);
&elem->FloatParameters[i]);
}
ImGui::Unindent();
}

View file

@ -6,7 +6,7 @@
#define SPOONTOOL_PROPERTIESWIDGET_H
#include "virintox/gcore/Widget.h"
#include "virintox/gcore/gui/Widget.h"
class PropertiesWidget : public Graphics::Widget {
public:

View file

@ -5,7 +5,7 @@
#ifndef SPOONTOOL_RAILSELECTWIDGET_H
#define SPOONTOOL_RAILSELECTWIDGET_H
#include<virintox/gcore/Widget.h>
#include<virintox/gcore/gui/Widget.h>
class RailSelectWidget: public Graphics::Widget {