Lighting revamp, Player::loadCharacter & Instance::getExplorerIcon

This commit is contained in:
floralrainfall 2023-07-19 20:16:39 -04:00
parent 21b4368778
commit 7b509a1393
20 changed files with 195 additions and 17 deletions

View File

@ -16,7 +16,6 @@ material materials/partinstanced
rtshader_system
{
transform_stage instanced
lighting_stage per_pixel
}
}

View File

@ -34,6 +34,7 @@ namespace RNR
Ogre::SceneManager* ogreSceneManager;
Ogre::Camera* ogreCamera;
Ogre::Viewport* ogreViewport;
Ogre::Light* ogreSceneLight;
Ogre::RTShader::ShaderGenerator* ogreShaderGen;
QCursor cursor;

View File

@ -6,6 +6,7 @@
#include <OGRE/Overlay/OgreOverlaySystem.h>
#include <OGRE/Overlay/OgreOverlayManager.h>
#include <OGRE/Overlay/OgreFontManager.h>
#include <App/V8/DataModel/Lighting.hpp>
#ifdef __unix__
#include <qpa/qplatformnativeinterface.h>
@ -90,19 +91,19 @@ namespace RNR
pFont->setTrueTypeSize(16);
pFont->load();
ogreSceneManager->setShadowTechnique(Ogre::ShadowTechnique::SHADOWTYPE_STENCIL_ADDITIVE);
ogreSceneManager->setShadowTechnique(Ogre::ShadowTechnique::SHADOWTYPE_STENCIL_MODULATIVE);
ogreSceneManager->setShadowFarDistance(500.f);
Ogre::Light* light = ogreSceneManager->createLight("SunLight");
ogreSceneLight = ogreSceneManager->createLight("SunLight");
Ogre::SceneNode* lightNode = ogreSceneManager->getRootSceneNode()->createChildSceneNode();
lightNode->setPosition(0, 10, 15);
lightNode->setDirection(-0.25, -0.5, -0.5);
lightNode->attachObject(light);
lightNode->attachObject(ogreSceneLight);
light->setCastShadows(true);
light->setDiffuseColour(0.9, 0.9, 1.0);
light->setSpecularColour(1.0, 1.0, 1.0);
light->setType(Ogre::Light::LT_DIRECTIONAL);
ogreSceneLight->setCastShadows(true);
ogreSceneLight->setDiffuseColour(0.9, 0.9, 1.0);
ogreSceneLight->setSpecularColour(1.0, 1.0, 1.0);
ogreSceneLight->setType(Ogre::Light::LT_DIRECTIONAL);
Ogre::MaterialManager::getSingletonPtr()->reloadAll();
Ogre::MaterialManager::getSingletonPtr()->load("sky/null_plainsky512", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
@ -126,6 +127,21 @@ namespace RNR
ogreCamera->getParentSceneNode()->setPosition(cam->getCFrame().getPosition());
ogreCamera->getParentSceneNode()->setOrientation(Ogre::Quaternion(cam->getCFrame().getRotation()));
}
RNR::Lighting* lighting = (RNR::Lighting*)world->getDatamodel()->getService("Lighting");
if(lighting)
{
Ogre::Vector3 clearColor = lighting->getClearColor();
ogreViewport->setBackgroundColour(Ogre::ColourValue(clearColor.x, clearColor.y, clearColor.z));
Ogre::Vector3 shadowColor = lighting->getShadowColor();
ogreSceneManager->setShadowColour(Ogre::ColourValue(shadowColor.x, shadowColor.y, shadowColor.z));
Ogre::Vector3 topAmbient = lighting->getTopAmbient();
ogreSceneLight->setDiffuseColour(Ogre::ColourValue(topAmbient.x, topAmbient.y, topAmbient.z));
Ogre::Vector3 bottomAmbient = lighting->getBottomAmbient();
ogreSceneManager->setAmbientLight(Ogre::ColourValue(bottomAmbient.x, bottomAmbient.y, bottomAmbient.z));
Ogre::Vector3 spotLight = lighting->getSpotLight();
ogreSceneLight->setSpecularColour(Ogre::ColourValue(spotLight.x, spotLight.y, spotLight.z));
}
if(isVisible())
ogreRoot->renderOneFrame(this->delta);

View File

@ -51,7 +51,7 @@ void MainWindow::widgetItemPrepare(QTreeWidgetItem* item, RNR::Instance* instanc
{
QString icon_path;
icon_path = "content/textures/studio/icons/";
icon_path += instance->getClassName();
icon_path += instance->getExplorerIcon();
icon_path += ".png";
QIcon icon;
if(QFile::exists(icon_path))
@ -139,6 +139,7 @@ void MainWindow::playSolo()
RNR::Players* players = (RNR::Players*)this->ogreWidget->world->getDatamodel()->getService("Players");
RNR::Player* player = players->createLocalPlayer(0);
player->setName(QInputDialog::getText(this, "Player Name", "Enter your player name").toLocal8Bit().data());
player->loadCharacter();
updateTree(ogreWidget->world->getDatamodel());
}

View File

@ -81,7 +81,7 @@ void PropertyViewer::view(RNR::Instance* instance)
QImage image;
QString icon_path;
icon_path = "content/textures/studio/icons/";
icon_path += instance_ref->getClassName();
icon_path += instance_ref->getExplorerIcon();
icon_path += ".png";
if(QFile::exists(icon_path))
image = QImage(icon_path);

View File

@ -16,6 +16,7 @@ add_library(Engine STATIC
Header/App/V8/DataModel/ForceField.hpp
Header/App/V8/DataModel/PartInstance.hpp
Header/App/V8/DataModel/Light.hpp
Header/App/V8/DataModel/Lighting.hpp
Header/App/V8/DataModel/FaceInstance.hpp
Header/App/V8/DataModel/RunService.hpp
Header/App/V8/DataModel/Workspace.hpp
@ -48,6 +49,7 @@ add_library(Engine STATIC
Source/App/V8/DataModel/ForceField.cpp
Source/App/V8/DataModel/PartInstance.cpp
Source/App/V8/DataModel/Light.cpp
Source/App/V8/DataModel/Lighting.cpp
Source/App/V8/DataModel/FaceInstance.cpp
Source/App/V8/DataModel/RunService.cpp
Source/App/V8/DataModel/Workspace.cpp

View File

@ -0,0 +1,36 @@
#pragma once
#include <App/V8/Tree/Instance.hpp>
namespace RNR
{
class Lighting : public Instance
{
float m_brightness;
float m_geographicLatitude;
Ogre::Vector3 m_bottomAmbient;
Ogre::Vector3 m_topAmbient;
Ogre::Vector3 m_spotLight;
Ogre::Vector3 m_shadowColor;
Ogre::Vector3 m_clearColor;
virtual void addProperties(std::vector<ReflectionProperty>& properties);
virtual void deserializeProperty(char* prop_name, pugi::xml_node prop);
public:
Lighting();
void setBottomAmbient(Ogre::Vector3 color) { m_bottomAmbient = color; }
Ogre::Vector3 getBottomAmbient() { return m_bottomAmbient; }
void setTopAmbient(Ogre::Vector3 color) { m_topAmbient = color; }
Ogre::Vector3 getTopAmbient() { return m_topAmbient; }
void setSpotLight(Ogre::Vector3 color) { m_spotLight = color; }
Ogre::Vector3 getSpotLight() { return m_spotLight; }
void setShadowColor(Ogre::Vector3 color) { m_shadowColor = color; }
Ogre::Vector3 getShadowColor() { return m_shadowColor; }
void setClearColor(Ogre::Vector3 color) { m_clearColor = color; }
Ogre::Vector3 getClearColor() { return m_clearColor; }
virtual std::string getClassName() { return "Lighting"; }
virtual std::string getExplorerIcon() { return "PointLight"; }
};
}

View File

@ -13,8 +13,10 @@ namespace RNR
enum WorkspaceBatchingMode
{
BATCH_DONT,
BATCH_INSTANCED,
BATCH_STATIC_GEOMETRY,
BATCH_DYNAMIC_RENDERABLE,
};
class Workspace : public ModelInstance

View File

@ -61,6 +61,7 @@ namespace RNR
RNR::Instance* getParent() { return this->m_parent; };
std::string getName() { return this->m_name; };
virtual std::string getClassName() { return "Instance"; }
virtual std::string getExplorerIcon() { return getClassName(); }
void setParent(RNR::Instance* newParent);
void setName(std::string name);

View File

@ -10,6 +10,7 @@ namespace RNR
{
public:
static Ogre::Vector3 getVector3(pugi::xml_node node);
static Ogre::Vector3 getColor(pugi::xml_node node);
static CoordinateFrame getCFrame(pugi::xml_node node);
};
}

View File

@ -10,10 +10,13 @@ namespace RNR
int m_userId;
public:
Player();
void initLocalPlayer();
void loadCharacter();
ModelInstance* getCharacter() { return m_character; }
void setCharacter(ModelInstance* model) { m_character = model; }
virtual std::string getClassName() { return "Player"; }
virtual void addProperties(std::vector<ReflectionProperty>& properties);
virtual void addProperties(std::vector<ReflectionProperty>& properties);
};
}

View File

@ -5,7 +5,10 @@ namespace RNR
{
Humanoid::Humanoid()
{
//
setName("Humanoid");
m_maxHealth = 100.f;
m_health = 100.f;
}
Humanoid::~Humanoid()

View File

@ -1,6 +1,7 @@
#include <App/V8/DataModel/Camera.hpp>
#include <App/V8/World/World.hpp>
#include <App/InputManager.hpp>
#include <Network/Players.hpp>
#include <Helpers/XML.hpp>
namespace RNR

View File

@ -0,0 +1,67 @@
#include <App/V8/DataModel/Lighting.hpp>
#include <Helpers/XML.hpp>
namespace RNR
{
Lighting::Lighting()
{
setName("Lighting");
setClearColor(Ogre::Vector3(255.f/255.f,255.f/255.f,255.f/255.f));
setShadowColor(Ogre::Vector3(127.f/255.f,127.f/255.f,127.f/255.f));
setBottomAmbient(Ogre::Vector3(122.f/255.f,134.f/255.f,120.f/255.f));
setTopAmbient(Ogre::Vector3(209.f/255.f,208.f/255.f,217.f/255.f));
setSpotLight(Ogre::Vector3(191.f/255.f,191.f/255.f,191.f/255.f));
}
void Lighting::deserializeProperty(char* prop_name, pugi::xml_node node)
{
if(prop_name == std::string("ClearColor"))
{
setClearColor(XML::getColor(node));
}
else if(prop_name == std::string("ShadowColor"))
{
setShadowColor(XML::getColor(node));
}
else if(prop_name == std::string("SpotLightV9"))
{
setSpotLight(XML::getColor(node));
}
else if(prop_name == std::string("BottomAmbientV9"))
{
setBottomAmbient(XML::getColor(node));
}
else if(prop_name == std::string("TopAmbientV9"))
{
setTopAmbient(XML::getColor(node));
}
}
void Lighting::addProperties(std::vector<ReflectionProperty>& properties)
{
ReflectionProperty _properties[] = {
{ this, std::string("BottomAmbientV9"), std::string(""),
ACCESS_NONE, OPERATION_READWRITE, PROPERTY_VECTOR3,
REFLECTION_GETTER(Lighting* instance = (Lighting*)object; return &instance->m_bottomAmbient; ),
REFLECTION_SETTER(Lighting* instance = (Lighting*)object; instance->setBottomAmbient(*(Ogre::Vector3*)value); ) },
{ this, std::string("TopAmbientV9"), std::string(""),
ACCESS_NONE, OPERATION_READWRITE, PROPERTY_VECTOR3,
REFLECTION_GETTER(Lighting* instance = (Lighting*)object; return &instance->m_topAmbient; ),
REFLECTION_SETTER(Lighting* instance = (Lighting*)object; instance->setTopAmbient(*(Ogre::Vector3*)value); ) },
{ this, std::string("ClearColor"), std::string(""),
ACCESS_NONE, OPERATION_READWRITE, PROPERTY_VECTOR3,
REFLECTION_GETTER(Lighting* instance = (Lighting*)object; return &instance->m_clearColor; ),
REFLECTION_SETTER(Lighting* instance = (Lighting*)object; instance->setClearColor(*(Ogre::Vector3*)value); ) },
{ this, std::string("ShadowColor"), std::string(""),
ACCESS_NONE, OPERATION_READWRITE, PROPERTY_VECTOR3,
REFLECTION_GETTER(Lighting* instance = (Lighting*)object; return &instance->m_shadowColor; ),
REFLECTION_SETTER(Lighting* instance = (Lighting*)object; instance->setShadowColor(*(Ogre::Vector3*)value); ) },
{ this, std::string("SpotLightV9"), std::string(""),
ACCESS_NONE, OPERATION_READWRITE, PROPERTY_VECTOR3,
REFLECTION_GETTER(Lighting* instance = (Lighting*)object; return &instance->m_spotLight; ),
REFLECTION_SETTER(Lighting* instance = (Lighting*)object; instance->setSpotLight(*(Ogre::Vector3*)value); ) },
};
properties.insert(properties.end(), _properties, _properties+(sizeof(_properties)/sizeof(ReflectionProperty)));
}
}

View File

@ -19,9 +19,11 @@ namespace RNR
break;
case BATCH_STATIC_GEOMETRY:
m_geom = world->getOgreSceneManager()->createStaticGeometry("workspaceGeom");
m_geom->setRegionDimensions(Ogre::Vector3(512,512,512));
m_geom->setRegionDimensions(Ogre::Vector3(2048,2048,2048));
m_geom->setCastShadows(true);
break;
case BATCH_DONT:
break;
}
}
@ -36,11 +38,12 @@ namespace RNR
case BATCH_INSTANCED:
{
Ogre::Entity* childEntity = (Ogre::Entity*)childAdded->getObject();
Ogre::InstancedEntity* replica = m_instanceManager->createInstancedEntity(childEntity->getSubEntity(0)->getMaterialName());
Ogre::InstancedEntity* replica = m_instanceManager->createInstancedEntity("materials/partinstanced");
replica->setPosition(part->getPosition());
replica->setOrientation(part->getCFrame().getRotation());
replica->setScale(part->getSize());
childAdded->setObject(replica);
child_node->setVisible(false);
}
break;
case BATCH_STATIC_GEOMETRY:
@ -48,10 +51,12 @@ namespace RNR
part->getPosition(),
part->getCFrame().getRotation(),
part->getSize());
child_node->setVisible(false);
m_geomDirty = true;
break;
case BATCH_DONT:
break;
}
child_node->setVisible(false);
m_geomDirty = true;
}
}

View File

@ -47,6 +47,8 @@ namespace RNR
pugi::xml_attribute prop_name = prop.attribute("name");
if(prop_name.as_string() == std::string("Name"))
setName(prop.text().as_string());
else if(prop_name.as_string() == std::string("archivable"))
m_archivable = prop.text().as_bool();
else
deserializeProperty((char*)prop_name.as_string(), prop);
}

View File

@ -1,6 +1,7 @@
#include <App/V8/World/World.hpp>
#include <App/V8/Tree/InstanceFactory.hpp>
#include <App/V8/DataModel/PartInstance.hpp>
#include <App/V8/DataModel/Lighting.hpp>
#include <App/GUI/SelectionBox.hpp>
#include <App/Humanoid/Humanoid.hpp>
#include <App/InputManager.hpp>
@ -27,6 +28,7 @@ namespace RNR
m_instanceFactory->registerInstance("RunService", InstanceFactory::instanceBuilder<RunService>);
m_instanceFactory->registerInstance("Players", InstanceFactory::instanceBuilder<Players>);
m_instanceFactory->registerInstance("Player", InstanceFactory::instanceBuilder<Player>);
m_instanceFactory->registerInstance("Lighting", InstanceFactory::instanceBuilder<Lighting>);
m_ogreRoot = ogre;
m_ogreSceneManager = ogreSceneManager;
@ -109,13 +111,14 @@ namespace RNR
WorldUndeserialized s = m_undeserialized.top();
m_undeserialized.pop();
s.instance->setParent(s.parent);
pugi::xml_node props = s.node.child("Properties");
for(pugi::xml_node prop : props.children())
{
s.instance->deserializeXmlProperty(prop);
}
s.instance->setParent(s.parent);
if(s.instance->getClassName() == "Model")
{
ModelInstance* m = (ModelInstance*)s.instance;

View File

@ -11,6 +11,16 @@ namespace RNR
);
}
Ogre::Vector3 XML::getColor(pugi::xml_node node)
{
Ogre::Vector3 rgb;
unsigned int hex = node.text().as_uint();
rgb.x = ((hex >> 16) & 0xff) / 255.0;
rgb.y = ((hex >> 8) & 0xff) / 255.0;
rgb.z = ((hex) & 0xff) / 255.0;
return rgb;
}
CoordinateFrame XML::getCFrame(pugi::xml_node node)
{
CoordinateFrame cframe;

View File

@ -1,4 +1,5 @@
#include <Network/Player.hpp>
#include <App/Humanoid/Humanoid.hpp>
#include <App/V8/World/World.hpp>
namespace RNR
@ -22,4 +23,27 @@ namespace RNR
properties.insert(properties.end(), _properties, _properties+(sizeof(_properties)/sizeof(ReflectionProperty)));
}
void Player::initLocalPlayer()
{
}
void Player::loadCharacter()
{
m_character = new ModelInstance();
m_character->setName(getName());
PartInstance* head = new PartInstance();
head->setName("Head");
head->setSize(Ogre::Vector3(2, 1, 1));
head->setParent(m_character);
Humanoid* character_humanoid = new Humanoid();
character_humanoid->setParent(m_character);
m_character->setParent(world->getWorkspace());
Camera* player_camera = world->getWorkspace()->getCurrentCamera();
player_camera->setCFrame(CoordinateFrame());
}
}

View File

@ -17,6 +17,7 @@ namespace RNR
}
printf("Players::createLocalPlayer: created player %i\n", userId);
m_localPlayer = new Player();
m_localPlayer->initLocalPlayer();
return m_localPlayer;
}