added material editor
This commit is contained in:
parent
5aad6c7357
commit
494d984065
@ -91,13 +91,12 @@ void Engine::update()
|
|||||||
io.DeltaTime = float(getDeltaTime()) / 1000.;
|
io.DeltaTime = float(getDeltaTime()) / 1000.;
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
// test gui
|
// settings gui
|
||||||
{
|
{
|
||||||
static bool testGuiOpen = true;
|
static bool settingsGuiOpen = true;
|
||||||
if(testGuiOpen)
|
if(settingsGuiOpen)
|
||||||
{
|
{
|
||||||
ImGui::Begin("Test imgui Window", &testGuiOpen);
|
ImGui::Begin("Window Settings", &settingsGuiOpen);
|
||||||
ImGui::Text("Hello, world!");
|
|
||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||||
bool physicsDebugEnabled = (m_physicsDebugNode != nullptr);
|
bool physicsDebugEnabled = (m_physicsDebugNode != nullptr);
|
||||||
if(ImGui::Checkbox("Toggle physics debug", &physicsDebugEnabled))
|
if(ImGui::Checkbox("Toggle physics debug", &physicsDebugEnabled))
|
||||||
@ -110,11 +109,6 @@ void Engine::update()
|
|||||||
bool isMouseVisible = m_mouseVisible;
|
bool isMouseVisible = m_mouseVisible;
|
||||||
if(ImGui::Checkbox("Mouse cursor ( shortcut : [M] )", &isMouseVisible))
|
if(ImGui::Checkbox("Mouse cursor ( shortcut : [M] )", &isMouseVisible))
|
||||||
toggleMouseVisibility();
|
toggleMouseVisibility();
|
||||||
if(ImGui::Button("EXIT GAME"))
|
|
||||||
stop();
|
|
||||||
float gravity = - m_world->getGravity().y();
|
|
||||||
if(ImGui::SliderFloat("Gravity", &gravity, 0.f, 100.f))
|
|
||||||
m_world->setGravity(btVector3(0, -gravity, 0));
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,8 @@ public:
|
|||||||
void enablePhysicsDebug();
|
void enablePhysicsDebug();
|
||||||
void disablePhysicsDebug();
|
void disablePhysicsDebug();
|
||||||
|
|
||||||
|
|
||||||
void toggleMouseVisibility();
|
void toggleMouseVisibility();
|
||||||
|
bool isMouseGrabbed() const { return !m_mouseVisible; }
|
||||||
|
|
||||||
// special inputs
|
// special inputs
|
||||||
void setTogglePhysicsDebugAction(int action);
|
void setTogglePhysicsDebugAction(int action);
|
||||||
|
@ -1,18 +1,31 @@
|
|||||||
#include "guitools.h"
|
#include "guitools.h"
|
||||||
#include "imgui/imgui.h"
|
|
||||||
|
|
||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "tools/scenepicker.h"
|
#include "tools/scenepicker.h"
|
||||||
#include "scene/scenetree.h"
|
#include "scene/scenetree.h"
|
||||||
|
|
||||||
|
#include <imgui/imgui.h>
|
||||||
|
|
||||||
|
#include <SparrowRenderer/mesh.h>
|
||||||
|
#include <SparrowRenderer/pbrmaterial.h>
|
||||||
|
|
||||||
|
#include <glm/ext.hpp>
|
||||||
|
|
||||||
GuiTools::GuiTools() :
|
GuiTools::GuiTools() :
|
||||||
m_pickerNode(new ScenePicker()),
|
m_pickerNode(new ScenePicker()),
|
||||||
m_pickerEnabled(false)
|
m_selectedMesh(nullptr),
|
||||||
|
m_pickerEnabled(false),
|
||||||
|
m_materialEditorEnabled(false)
|
||||||
{
|
{
|
||||||
addChild(m_pickerNode);
|
addChild(m_pickerNode);
|
||||||
m_pickerNode->setVisible(false);
|
m_pickerNode->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GuiTools::~GuiTools()
|
||||||
|
{
|
||||||
|
delete m_pickerNode;
|
||||||
|
}
|
||||||
|
|
||||||
void GuiTools::update()
|
void GuiTools::update()
|
||||||
{
|
{
|
||||||
// no automatic update of children, we want to update them manually
|
// no automatic update of children, we want to update them manually
|
||||||
@ -20,6 +33,52 @@ void GuiTools::update()
|
|||||||
|
|
||||||
if(m_pickerEnabled)
|
if(m_pickerEnabled)
|
||||||
m_pickerNode->update();
|
m_pickerNode->update();
|
||||||
|
|
||||||
|
if(m_materialEditorEnabled)
|
||||||
|
materialGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiTools::materialGui()
|
||||||
|
{
|
||||||
|
static int selectedOption = 0;
|
||||||
|
|
||||||
|
ImGui::Begin("Material Editor", &m_materialEditorEnabled);
|
||||||
|
std::string options;
|
||||||
|
std::vector<Mesh*> meshes;
|
||||||
|
options += "None\n";
|
||||||
|
meshes.push_back(nullptr);
|
||||||
|
int i = 1;
|
||||||
|
for(SceneIterator<GeometryNode*>* geometryIt = getEngine().getScene()->getGeometry(); geometryIt->isValid(); geometryIt->next())
|
||||||
|
{
|
||||||
|
options += geometryIt->getItem()->mesh->getName();
|
||||||
|
options += '\n';
|
||||||
|
meshes.push_back(geometryIt->getItem()->mesh);
|
||||||
|
if(geometryIt->getItem()->mesh == m_selectedMesh)
|
||||||
|
selectedOption = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(char &c : options)
|
||||||
|
{
|
||||||
|
if(c == '\n')
|
||||||
|
c = '\0';
|
||||||
|
}
|
||||||
|
if(ImGui::Combo("Mesh", &selectedOption, options.c_str()))
|
||||||
|
{
|
||||||
|
m_selectedMesh = meshes[selectedOption];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_selectedMesh == nullptr)
|
||||||
|
ImGui::Text("No mesh selected");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PBRMaterial* mat = dynamic_cast<PBRMaterial*>(m_selectedMesh->getMaterial());
|
||||||
|
ImGui::ColorEdit3("albedo", &mat->albedo.r);
|
||||||
|
ImGui::ColorEdit3("emission", &mat->emission.r);
|
||||||
|
ImGui::SliderFloat("metallic", &mat->metallic, 0, 1);
|
||||||
|
ImGui::SliderFloat("roughness", &mat->roughness, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiTools::togglePicker()
|
void GuiTools::togglePicker()
|
||||||
@ -27,3 +86,8 @@ void GuiTools::togglePicker()
|
|||||||
m_pickerEnabled = !m_pickerEnabled;
|
m_pickerEnabled = !m_pickerEnabled;
|
||||||
m_pickerNode->setVisible(m_pickerEnabled);
|
m_pickerNode->setVisible(m_pickerEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuiTools::toggleMaterialEditor()
|
||||||
|
{
|
||||||
|
m_materialEditorEnabled = !m_materialEditorEnabled;
|
||||||
|
}
|
||||||
|
@ -5,15 +5,21 @@
|
|||||||
|
|
||||||
class Engine;
|
class Engine;
|
||||||
class ScenePicker;
|
class ScenePicker;
|
||||||
|
class Mesh;
|
||||||
|
|
||||||
class GuiTools : public ContainerNode
|
class GuiTools : public ContainerNode
|
||||||
{
|
{
|
||||||
ScenePicker* m_pickerNode;
|
ScenePicker* m_pickerNode;
|
||||||
|
Mesh* m_selectedMesh;
|
||||||
bool m_pickerEnabled;
|
bool m_pickerEnabled;
|
||||||
|
bool m_materialEditorEnabled;
|
||||||
public:
|
public:
|
||||||
GuiTools();
|
GuiTools();
|
||||||
|
~GuiTools();
|
||||||
void update();
|
void update();
|
||||||
|
void materialGui();
|
||||||
void togglePicker();
|
void togglePicker();
|
||||||
|
void toggleMaterialEditor();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GUITOOLS_H
|
#endif // GUITOOLS_H
|
||||||
|
@ -119,32 +119,36 @@ void PlayerCharacterNode::update()
|
|||||||
Input *input = getEngine().getInput();
|
Input *input = getEngine().getInput();
|
||||||
float deltaTime = getEngine().getDeltaTime();
|
float deltaTime = getEngine().getDeltaTime();
|
||||||
|
|
||||||
// get events
|
|
||||||
int walk = 0;
|
int walk = 0;
|
||||||
int strafe = 0;
|
int strafe = 0;
|
||||||
bool jump = false;
|
bool jump = false;
|
||||||
bool run = false;
|
bool run = false;
|
||||||
for(Action action : input->getActions())
|
|
||||||
{
|
|
||||||
if(action.action == m_inputActions[FORWARD])
|
|
||||||
++walk;
|
|
||||||
else if(action.action == m_inputActions[BACKWARD])
|
|
||||||
--walk;
|
|
||||||
else if(action.action == m_inputActions[STRAFE_LEFT])
|
|
||||||
--strafe;
|
|
||||||
else if(action.action == m_inputActions[STRAFE_RIGHT])
|
|
||||||
++strafe;
|
|
||||||
else if(action.action == m_inputActions[JUMP])
|
|
||||||
jump = true;
|
|
||||||
else if(action.action == m_inputActions[RUN])
|
|
||||||
run=true;
|
|
||||||
else if(action.action == m_inputActions[TOGGLE_NOCLIP])
|
|
||||||
toggleNoClip();
|
|
||||||
}
|
|
||||||
|
|
||||||
// update camera rotation
|
if(getEngine().isMouseGrabbed())
|
||||||
glm::vec2 diff = input->getDeltaPosition();
|
{
|
||||||
m_fpsCamera.rotate(diff.x, diff.y);
|
// get events
|
||||||
|
for(Action action : input->getActions())
|
||||||
|
{
|
||||||
|
if(action.action == m_inputActions[FORWARD])
|
||||||
|
++walk;
|
||||||
|
else if(action.action == m_inputActions[BACKWARD])
|
||||||
|
--walk;
|
||||||
|
else if(action.action == m_inputActions[STRAFE_LEFT])
|
||||||
|
--strafe;
|
||||||
|
else if(action.action == m_inputActions[STRAFE_RIGHT])
|
||||||
|
++strafe;
|
||||||
|
else if(action.action == m_inputActions[JUMP])
|
||||||
|
jump = true;
|
||||||
|
else if(action.action == m_inputActions[RUN])
|
||||||
|
run = true;
|
||||||
|
else if(action.action == m_inputActions[TOGGLE_NOCLIP])
|
||||||
|
toggleNoClip();
|
||||||
|
}
|
||||||
|
|
||||||
|
// update camera rotation
|
||||||
|
glm::vec2 diff = input->getDeltaPosition();
|
||||||
|
m_fpsCamera.rotate(diff.x, diff.y);
|
||||||
|
}
|
||||||
|
|
||||||
// update camera position
|
// update camera position
|
||||||
btVector3 pos = m_rigidBody->getCenterOfMassPosition();
|
btVector3 pos = m_rigidBody->getCenterOfMassPosition();
|
||||||
|
@ -20,6 +20,7 @@ ScriptNode::ScriptNode()
|
|||||||
LUA_SET_FUN(version);
|
LUA_SET_FUN(version);
|
||||||
LUA_SET_FUN(clear);
|
LUA_SET_FUN(clear);
|
||||||
LUA_SET_FUN(picker);
|
LUA_SET_FUN(picker);
|
||||||
|
LUA_SET_FUN(materialEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptNode::update(){
|
void ScriptNode::update(){
|
||||||
@ -87,3 +88,7 @@ void ScriptNode::testfunc(int i, float x=0.f,float y=0.f, float z=0.f){
|
|||||||
void ScriptNode::picker(){
|
void ScriptNode::picker(){
|
||||||
this->getEngine().getGuiTools()->togglePicker();
|
this->getEngine().getGuiTools()->togglePicker();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptNode::materialEditor(){
|
||||||
|
this->getEngine().getGuiTools()->toggleMaterialEditor();
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@ public:
|
|||||||
float getDeltaTime();
|
float getDeltaTime();
|
||||||
void testfunc(int, float,float,float);
|
void testfunc(int, float,float,float);
|
||||||
void picker();
|
void picker();
|
||||||
|
void materialEditor();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ Potator::Potator(PlayerCharacterNode * player,
|
|||||||
float density = 1.f;
|
float density = 1.f;
|
||||||
|
|
||||||
// creating cube
|
// creating cube
|
||||||
m_cubeMesh = new Mesh();
|
m_cubeMesh = new Mesh("woodBox");
|
||||||
m_cubeMesh->addVertex(glm::vec3(-1*s.x, -1*s.y, 1*s.z),glm::vec3(0, 0, 1),glm::vec2(0, 0));
|
m_cubeMesh->addVertex(glm::vec3(-1*s.x, -1*s.y, 1*s.z),glm::vec3(0, 0, 1),glm::vec2(0, 0));
|
||||||
m_cubeMesh->addVertex(glm::vec3(-1*s.x, 1*s.y, 1*s.z),glm::vec3(0, 0, 1),glm::vec2(0, 1));
|
m_cubeMesh->addVertex(glm::vec3(-1*s.x, 1*s.y, 1*s.z),glm::vec3(0, 0, 1),glm::vec2(0, 1));
|
||||||
m_cubeMesh->addVertex(glm::vec3( 1*s.x, -1*s.y, 1*s.z),glm::vec3(0, 0, 1),glm::vec2(1, 0));
|
m_cubeMesh->addVertex(glm::vec3( 1*s.x, -1*s.y, 1*s.z),glm::vec3(0, 0, 1),glm::vec2(1, 0));
|
||||||
@ -164,14 +164,18 @@ void Potator::throwSword()
|
|||||||
void Potator::update()
|
void Potator::update()
|
||||||
{
|
{
|
||||||
GibGeneratorNode::update();
|
GibGeneratorNode::update();
|
||||||
Input *input = getEngine().getInput();
|
|
||||||
for(Action action : input->getActions())
|
if(getEngine().isMouseGrabbed())
|
||||||
{
|
{
|
||||||
if(action.action == m_throwCubeAction)
|
Input *input = getEngine().getInput();
|
||||||
throwCube();
|
for(Action action : input->getActions())
|
||||||
else if(action.action == m_throwSphereAction)
|
{
|
||||||
throwSphere();
|
if(action.action == m_throwCubeAction)
|
||||||
else if(action.action == m_throwObjectAction)
|
throwCube();
|
||||||
throwSword();
|
else if(action.action == m_throwSphereAction)
|
||||||
|
throwSphere();
|
||||||
|
else if(action.action == m_throwObjectAction)
|
||||||
|
throwSword();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user