added material editor
This commit is contained in:
parent
5aad6c7357
commit
494d984065
@ -91,13 +91,12 @@ void Engine::update()
|
||||
io.DeltaTime = float(getDeltaTime()) / 1000.;
|
||||
ImGui::NewFrame();
|
||||
|
||||
// test gui
|
||||
// settings gui
|
||||
{
|
||||
static bool testGuiOpen = true;
|
||||
if(testGuiOpen)
|
||||
static bool settingsGuiOpen = true;
|
||||
if(settingsGuiOpen)
|
||||
{
|
||||
ImGui::Begin("Test imgui Window", &testGuiOpen);
|
||||
ImGui::Text("Hello, world!");
|
||||
ImGui::Begin("Window Settings", &settingsGuiOpen);
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||
bool physicsDebugEnabled = (m_physicsDebugNode != nullptr);
|
||||
if(ImGui::Checkbox("Toggle physics debug", &physicsDebugEnabled))
|
||||
@ -110,11 +109,6 @@ void Engine::update()
|
||||
bool isMouseVisible = m_mouseVisible;
|
||||
if(ImGui::Checkbox("Mouse cursor ( shortcut : [M] )", &isMouseVisible))
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ public:
|
||||
void enablePhysicsDebug();
|
||||
void disablePhysicsDebug();
|
||||
|
||||
|
||||
void toggleMouseVisibility();
|
||||
bool isMouseGrabbed() const { return !m_mouseVisible; }
|
||||
|
||||
// special inputs
|
||||
void setTogglePhysicsDebugAction(int action);
|
||||
|
@ -1,18 +1,31 @@
|
||||
#include "guitools.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
#include "engine.h"
|
||||
#include "tools/scenepicker.h"
|
||||
#include "scene/scenetree.h"
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include <SparrowRenderer/mesh.h>
|
||||
#include <SparrowRenderer/pbrmaterial.h>
|
||||
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
GuiTools::GuiTools() :
|
||||
m_pickerNode(new ScenePicker()),
|
||||
m_pickerEnabled(false)
|
||||
m_selectedMesh(nullptr),
|
||||
m_pickerEnabled(false),
|
||||
m_materialEditorEnabled(false)
|
||||
{
|
||||
addChild(m_pickerNode);
|
||||
m_pickerNode->setVisible(false);
|
||||
}
|
||||
|
||||
GuiTools::~GuiTools()
|
||||
{
|
||||
delete m_pickerNode;
|
||||
}
|
||||
|
||||
void GuiTools::update()
|
||||
{
|
||||
// no automatic update of children, we want to update them manually
|
||||
@ -20,6 +33,52 @@ void GuiTools::update()
|
||||
|
||||
if(m_pickerEnabled)
|
||||
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()
|
||||
@ -27,3 +86,8 @@ void GuiTools::togglePicker()
|
||||
m_pickerEnabled = !m_pickerEnabled;
|
||||
m_pickerNode->setVisible(m_pickerEnabled);
|
||||
}
|
||||
|
||||
void GuiTools::toggleMaterialEditor()
|
||||
{
|
||||
m_materialEditorEnabled = !m_materialEditorEnabled;
|
||||
}
|
||||
|
@ -5,15 +5,21 @@
|
||||
|
||||
class Engine;
|
||||
class ScenePicker;
|
||||
class Mesh;
|
||||
|
||||
class GuiTools : public ContainerNode
|
||||
{
|
||||
ScenePicker* m_pickerNode;
|
||||
Mesh* m_selectedMesh;
|
||||
bool m_pickerEnabled;
|
||||
bool m_materialEditorEnabled;
|
||||
public:
|
||||
GuiTools();
|
||||
~GuiTools();
|
||||
void update();
|
||||
void materialGui();
|
||||
void togglePicker();
|
||||
void toggleMaterialEditor();
|
||||
};
|
||||
|
||||
#endif // GUITOOLS_H
|
||||
|
@ -119,32 +119,36 @@ void PlayerCharacterNode::update()
|
||||
Input *input = getEngine().getInput();
|
||||
float deltaTime = getEngine().getDeltaTime();
|
||||
|
||||
// get events
|
||||
int walk = 0;
|
||||
int strafe = 0;
|
||||
bool jump = 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
|
||||
glm::vec2 diff = input->getDeltaPosition();
|
||||
m_fpsCamera.rotate(diff.x, diff.y);
|
||||
if(getEngine().isMouseGrabbed())
|
||||
{
|
||||
// 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
|
||||
btVector3 pos = m_rigidBody->getCenterOfMassPosition();
|
||||
|
@ -20,6 +20,7 @@ ScriptNode::ScriptNode()
|
||||
LUA_SET_FUN(version);
|
||||
LUA_SET_FUN(clear);
|
||||
LUA_SET_FUN(picker);
|
||||
LUA_SET_FUN(materialEditor);
|
||||
}
|
||||
|
||||
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(){
|
||||
this->getEngine().getGuiTools()->togglePicker();
|
||||
}
|
||||
|
||||
void ScriptNode::materialEditor(){
|
||||
this->getEngine().getGuiTools()->toggleMaterialEditor();
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
float getDeltaTime();
|
||||
void testfunc(int, float,float,float);
|
||||
void picker();
|
||||
void materialEditor();
|
||||
|
||||
};
|
||||
|
||||
|
@ -27,7 +27,7 @@ Potator::Potator(PlayerCharacterNode * player,
|
||||
float density = 1.f;
|
||||
|
||||
// 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, 1));
|
||||
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()
|
||||
{
|
||||
GibGeneratorNode::update();
|
||||
Input *input = getEngine().getInput();
|
||||
for(Action action : input->getActions())
|
||||
|
||||
if(getEngine().isMouseGrabbed())
|
||||
{
|
||||
if(action.action == m_throwCubeAction)
|
||||
throwCube();
|
||||
else if(action.action == m_throwSphereAction)
|
||||
throwSphere();
|
||||
else if(action.action == m_throwObjectAction)
|
||||
throwSword();
|
||||
Input *input = getEngine().getInput();
|
||||
for(Action action : input->getActions())
|
||||
{
|
||||
if(action.action == m_throwCubeAction)
|
||||
throwCube();
|
||||
else if(action.action == m_throwSphereAction)
|
||||
throwSphere();
|
||||
else if(action.action == m_throwObjectAction)
|
||||
throwSword();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user