basic camera movement & reflection wip
This commit is contained in:
parent
0f37618354
commit
bcd5bd34c9
|
|
@ -23,6 +23,7 @@ namespace RNR
|
|||
this->setMouseTracking(true);
|
||||
this->setCursor(QCursor(Qt::BlankCursor));
|
||||
this->setFocusPolicy(Qt::StrongFocus);
|
||||
this->selectedInstance = 0;
|
||||
}
|
||||
|
||||
void OgreWidget::initializeOgre()
|
||||
|
|
@ -103,11 +104,15 @@ namespace RNR
|
|||
this->render_time += ogreRoot->getTimer()->getMilliseconds() / 1000.0;
|
||||
ogreRoot->getTimer()->reset();
|
||||
|
||||
Ogre::AxisAlignedBox boundingBox = world->getWorkspace()->getBoundingBox();
|
||||
if(!boundingBox.isNull() && !boundingBox.isInfinite())
|
||||
RNR::ModelInstance* sel_model = dynamic_cast<RNR::ModelInstance*>(selectedInstance);
|
||||
if(sel_model)
|
||||
{
|
||||
ogreCamera->getParentSceneNode()->setPosition(boundingBox.getCorner(Ogre::AxisAlignedBox::CornerEnum::NEAR_LEFT_TOP));
|
||||
ogreCamera->getParentSceneNode()->lookAt(boundingBox.getCenter(), Ogre::Node::TS_WORLD);
|
||||
Ogre::AxisAlignedBox boundingBox = sel_model->getBoundingBox();
|
||||
if(!boundingBox.isNull() && !boundingBox.isInfinite())
|
||||
{
|
||||
ogreCamera->getParentSceneNode()->setPosition(boundingBox.getCorner(Ogre::AxisAlignedBox::CornerEnum::NEAR_LEFT_TOP) * 1.1);
|
||||
ogreCamera->getParentSceneNode()->lookAt(boundingBox.getCenter(), Ogre::Node::TS_WORLD);
|
||||
}
|
||||
}
|
||||
|
||||
ogreRoot->renderOneFrame(this->delta);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ class MainWindow : public QMainWindow
|
|||
|
||||
public slots:
|
||||
void loadDatamodel();
|
||||
void selectInstance(QTreeWidgetItem *item, int column);
|
||||
protected:
|
||||
void widgetItemPrepare(QTreeWidgetItem* item, RNR::Instance* instance);
|
||||
void recurseTreeAddInstance(QTreeWidgetItem* parent, RNR::Instance* instance);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <MainWindow.hpp>
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <App/V8/Tree/ModelInstance.hpp>
|
||||
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
|
|
@ -28,13 +29,13 @@ MainWindow::MainWindow()
|
|||
grid->addWidget(this->ogreWidget, 2, 0, 1, 2);
|
||||
|
||||
explorer = new QTreeWidget();
|
||||
connect(explorer, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(selectInstance(QTreeWidgetItem*, int)));
|
||||
grid->addWidget(explorer, 2, 2, 1, 1);
|
||||
|
||||
content_widget->setLayout(grid);
|
||||
|
||||
grid->setContentsMargins(0, 0, 0, 0);
|
||||
grid->setSpacing(0);
|
||||
|
||||
setWindowTitle(QString("RNR Studio"));
|
||||
setWindowIcon(QIcon(pixmap));
|
||||
setCentralWidget(content_widget);
|
||||
|
|
@ -54,6 +55,15 @@ void MainWindow::widgetItemPrepare(QTreeWidgetItem* item, RNR::Instance* instanc
|
|||
item->setIcon(0, icon);
|
||||
}
|
||||
|
||||
void MainWindow::selectInstance(QTreeWidgetItem *item, int column)
|
||||
{
|
||||
RNR::Instance* instance = item->data(0, Qt::UserRole).value<RNR::Instance*>();
|
||||
if(dynamic_cast<RNR::ModelInstance*>(instance))
|
||||
{
|
||||
ogreWidget->selectedInstance = instance;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::recurseTreeAddInstance(QTreeWidgetItem* parent, RNR::Instance* instance)
|
||||
{
|
||||
for(auto& child : *instance->getChildren())
|
||||
|
|
@ -62,6 +72,7 @@ void MainWindow::recurseTreeAddInstance(QTreeWidgetItem* parent, RNR::Instance*
|
|||
widgetItemPrepare(instance_w, child);
|
||||
instance_w->setText(0, QString(child->getName().c_str()));
|
||||
instance_w->setData(0, Qt::UserRole, QVariant::fromValue(child));
|
||||
|
||||
recurseTreeAddInstance(instance_w, child);
|
||||
parent->addChild(instance_w);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ add_library(Engine STATIC
|
|||
Header/Helpers/Name.hpp
|
||||
Header/Helpers/Strings.hpp
|
||||
Header/Helpers/XML.hpp
|
||||
Header/App/Script/ReflectionProperty.hpp
|
||||
Header/App/GUI/GuiBase3d.hpp
|
||||
Header/App/GUI/InstanceAdornment.hpp
|
||||
Header/App/GUI/SelectionBox.hpp
|
||||
|
|
@ -22,6 +23,7 @@ add_library(Engine STATIC
|
|||
Source/Helpers/Name.cpp
|
||||
Source/Helpers/Strings.cpp
|
||||
Source/Helpers/XML.cpp
|
||||
Source/App/Script/ReflectionProperty.cpp
|
||||
Source/App/GUI/GuiBase3d.cpp
|
||||
Source/App/GUI/InstanceAdornment.cpp
|
||||
Source/App/GUI/SelectionBox.cpp
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ namespace RNR
|
|||
Ogre::Vector3 color_val;
|
||||
|
||||
Ogre::MaterialPtr color_material;
|
||||
|
||||
void buildMaterial();
|
||||
public:
|
||||
BrickColor(int color_id, std::string name, Ogre::Vector3 color);
|
||||
static Ogre::Vector3 color(int brickcolor);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <boost/type_index.hpp>
|
||||
|
||||
namespace RNR
|
||||
{
|
||||
enum ReflectionPropertyAccess
|
||||
{
|
||||
ACCESS_SCRIPT,
|
||||
ACCESS_CONSOLE,
|
||||
ACCESS_RNR,
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class ReflectionProperty
|
||||
{
|
||||
private:
|
||||
std::string m_name;
|
||||
ReflectionPropertyAccess m_access;
|
||||
public:
|
||||
ReflectionProperty(std::string name, ReflectionPropertyAccess access, T(*getter), T(*setter))
|
||||
{
|
||||
this->m_name = name;
|
||||
this->m_access = access;
|
||||
this->getter = getter;
|
||||
this->setter = setter;
|
||||
}
|
||||
|
||||
bool access(ReflectionPropertyAccess accessor)
|
||||
{
|
||||
return this->m_access <= accessor;
|
||||
}
|
||||
|
||||
char* class_name()
|
||||
{
|
||||
return boost::typeindex::type_id<T>().pretty_name();
|
||||
}
|
||||
|
||||
T (*getter)();
|
||||
void (*setter)(T val);
|
||||
};
|
||||
}
|
||||
|
|
@ -37,6 +37,7 @@ namespace RNR
|
|||
bool contains(RNR::Instance* child);
|
||||
bool isAncestorOf(RNR::Instance* instance);
|
||||
|
||||
static World* getWorld() { return Instance::world; }
|
||||
static void setWorld(World* world) { Instance::world = world; }
|
||||
|
||||
virtual bool askSetParent(RNR::Instance* instance); // derive this
|
||||
|
|
|
|||
|
|
@ -90,6 +90,17 @@ namespace RNR
|
|||
this->color_val = color;
|
||||
}
|
||||
|
||||
void BrickColor::buildMaterial()
|
||||
{
|
||||
color_material = Ogre::MaterialManager::getSingletonPtr()->getByName("materials/partinstanced");
|
||||
color_material = color_material->clone(Ogre::String("tmp_part/") + Ogre::StringConverter::toString(color_id));
|
||||
Ogre::Technique* mat_tech = color_material->getTechnique(0);
|
||||
Ogre::Pass* mat_pass = mat_tech->getPass(0);
|
||||
Ogre::TextureUnitState* part_texunit = mat_pass->getTextureUnitState(0);
|
||||
part_texunit->setColourOperationEx(Ogre::LayerBlendOperationEx::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(color_val.x, color_val.y, color_val.z));
|
||||
Ogre::RTShader::ShaderGenerator::getSingletonPtr()->validateScheme(mat_tech->getSchemeName());
|
||||
}
|
||||
|
||||
Ogre::Vector3 BrickColor::color(int brickcolor)
|
||||
{
|
||||
for(int i = 0; i < sizeof(brickcolors) / sizeof(BrickColor); i++)
|
||||
|
|
@ -109,26 +120,12 @@ namespace RNR
|
|||
if(brickcolors[i].color_id == brickcolor)
|
||||
{
|
||||
if(!brickcolors[i].color_material)
|
||||
{
|
||||
brickcolors[i].color_material = Ogre::MaterialManager::getSingletonPtr()->getByName("materials/partinstanced");
|
||||
brickcolors[i].color_material = brickcolors[i].color_material->clone(Ogre::String("tmp_part/") + Ogre::StringConverter::toString(brickcolor));
|
||||
Ogre::Technique* mat_tech = brickcolors[i].color_material->getTechnique(0);
|
||||
Ogre::Pass* mat_pass = mat_tech->getPass(0);
|
||||
Ogre::TextureUnitState* part_texunit = mat_pass->getTextureUnitState(0);
|
||||
part_texunit->setColourOperationEx(Ogre::LayerBlendOperationEx::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(brickcolors[i].color_val.x, brickcolors[i].color_val.y, brickcolors[i].color_val.z));
|
||||
}
|
||||
brickcolors[i].buildMaterial();
|
||||
return brickcolors[i].color_material;
|
||||
}
|
||||
}
|
||||
if(!brickcolors[0].color_material)
|
||||
{
|
||||
brickcolors[0].color_material = Ogre::MaterialManager::getSingletonPtr()->getByName("materials/partinstanced");
|
||||
brickcolors[0].color_material = brickcolors[0].color_material->clone(Ogre::String("tmp_part/") + Ogre::StringConverter::toString(brickcolor));
|
||||
Ogre::Technique* mat_tech = brickcolors[0].color_material->getTechnique(0);
|
||||
Ogre::Pass* mat_pass = mat_tech->getPass(0);
|
||||
Ogre::TextureUnitState* part_texunit = mat_pass->getTextureUnitState(0);
|
||||
part_texunit->setColourOperationEx(Ogre::LayerBlendOperationEx::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(brickcolors[0].color_val.x, brickcolors[0].color_val.y, brickcolors[0].color_val.z));
|
||||
}
|
||||
brickcolors[0].buildMaterial();
|
||||
return brickcolors[0].color_material;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
#include <App/Script/ReflectionProperty.hpp>
|
||||
|
||||
namespace RNR
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -29,7 +29,6 @@ namespace RNR
|
|||
bool skip = false;
|
||||
Instance* instance;
|
||||
pugi::xml_attribute class_attr = node.attribute("class");
|
||||
printf("World::xmlAddItem: adding class %s\n", class_attr.as_string());
|
||||
|
||||
if(class_attr.as_string() == std::string("Part"))
|
||||
{
|
||||
|
|
@ -61,6 +60,11 @@ namespace RNR
|
|||
{
|
||||
xmlAddItem(item, instance);
|
||||
}
|
||||
|
||||
if(class_attr.as_string() == std::string("Model"))
|
||||
{
|
||||
((ModelInstance*)instance)->build();
|
||||
}
|
||||
}
|
||||
|
||||
void World::load(char* path)
|
||||
|
|
|
|||
Loading…
Reference in New Issue