workspace instancing (needs shader)

This commit is contained in:
floralrainfall 2023-07-11 12:42:38 -04:00
parent c37a4fbfcf
commit 0caf3b96b4
12 changed files with 70 additions and 82 deletions

View File

@ -1,4 +1,4 @@
// generated by blender2ogre 0.8.3 on 2023-07-10 17:26:00 // generated by blender2ogre 0.8.3 on 2023-07-10 20:18:50
material Material { material Material {
receive_shadows on receive_shadows on
technique { technique {
@ -6,6 +6,11 @@ material Material {
diffuse 0.8 0.8 0.8 1.0 diffuse 0.8 0.8 0.8 1.0
specular 0.512 0.512 0.512 1.0 64.0 specular 0.512 0.512 0.512 1.0 64.0
texture_unit {
texture fonts/brick_tex.PNG
tex_address_mode wrap
colour_op modulate
}
} }
} }
} }

View File

@ -1,21 +1,21 @@
17:26:00: XMLMeshSerializer reading mesh data from /home/caesium/projects/rbxnu/Content/fonts/Cube.mesh.xml... 20:18:50: XMLMeshSerializer reading mesh data from /home/caesium/projects/rbxnu/Content/fonts/Cube.mesh.xml...
17:26:00: Reading geometry... 20:18:50: Reading geometry...
17:26:00: Geometry done... 20:18:50: Geometry done...
17:26:00: Reading submeshes... 20:18:50: Reading submeshes...
17:26:00: Submeshes done. 20:18:50: Submeshes done.
17:26:00: Reading mesh names... 20:18:50: Reading mesh names...
17:26:00: Mesh names done. 20:18:50: Mesh names done.
17:26:00: XMLMeshSerializer import successful. 20:18:50: XMLMeshSerializer import successful.
17:26:00: MeshSerializer writing mesh data to stream /home/caesium/projects/rbxnu/Content/fonts/Cube.mesh... 20:18:50: MeshSerializer writing mesh data to stream /home/caesium/projects/rbxnu/Content/fonts/Cube.mesh...
17:26:00: File header written. 20:18:50: File header written.
17:26:00: Writing mesh data... 20:18:50: Writing mesh data...
17:26:00: Writing submesh... 20:18:50: Writing submesh...
17:26:00: Exporting submesh texture aliases... 20:18:50: Exporting submesh texture aliases...
17:26:00: Submesh texture aliases exported. 20:18:50: Submesh texture aliases exported.
17:26:00: Submesh exported. 20:18:50: Submesh exported.
17:26:00: Exporting bounds information.... 20:18:50: Exporting bounds information....
17:26:00: Bounds information exported. 20:18:50: Bounds information exported.
17:26:00: Exporting submesh name table... 20:18:50: Exporting submesh name table...
17:26:00: Submesh name table exported. 20:18:50: Submesh name table exported.
17:26:00: Mesh data exported. 20:18:50: Mesh data exported.
17:26:00: MeshSerializer export successful. 20:18:50: MeshSerializer export successful.

BIN
Content/fonts/brick_tex.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -21,10 +21,6 @@ int main(int argc, char** argv)
window.ogreWidget->initializeOgre(); window.ogreWidget->initializeOgre();
RNR::World* world = new RNR::World(window.ogreWidget->ogreRoot, window.ogreWidget->ogreSceneManager); RNR::World* world = new RNR::World(window.ogreWidget->ogreRoot, window.ogreWidget->ogreSceneManager);
Ogre::SceneNode* workspace_node = window.ogreWidget->ogreSceneManager->getRootSceneNode()->createChildSceneNode();
workspace_node->attachObject(world->getWorkspace());
workspace_node->setVisible(true);
printf("main: workspace = %p (%p)\n",workspace_node, world->getWorkspace());
window.updateTree(world->getDatamodel()); window.updateTree(world->getDatamodel());
while (window.isVisible()) while (window.isVisible())

View File

@ -6,6 +6,7 @@ namespace RNR
class CoordinateFrame class CoordinateFrame
{ {
Ogre::Vector3 m_position; Ogre::Vector3 m_position;
Ogre::Vector3 m_scale;
Ogre::Matrix3 m_rotation; Ogre::Matrix3 m_rotation;
public: public:
CoordinateFrame(); CoordinateFrame();

View File

@ -3,6 +3,7 @@
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <OGRE/Ogre.h>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <Helpers/Name.hpp> #include <Helpers/Name.hpp>
@ -18,6 +19,8 @@ namespace RNR
private: private:
Ogre::SceneNode* m_node;
Ogre::MovableObject* m_object;
std::string m_name; std::string m_name;
RNR::Instance* m_parent; RNR::Instance* m_parent;
std::vector<RNR::Instance*> m_children; std::vector<RNR::Instance*> m_children;
@ -44,6 +47,10 @@ namespace RNR
void setParent(RNR::Instance* newParent); void setParent(RNR::Instance* newParent);
void setName(std::string name); void setName(std::string name);
void setNode(Ogre::SceneNode* node) { m_node = node; };
Ogre::SceneNode* getNode() { return m_node; };
void setObject(Ogre::MovableObject* object) { m_object = object; };
Ogre::MovableObject* getObject() { return m_object; };
std::vector<RNR::Instance*>* getChildren() { return &this->m_children; }; std::vector<RNR::Instance*>* getChildren() { return &this->m_children; };
int numChildren() { return this->m_children.size(); }; int numChildren() { return this->m_children.size(); };

View File

@ -5,22 +5,16 @@
namespace RNR namespace RNR
{ {
// this acts as both an Instance to fit in the RNR graph, and as an Ogre MovableObject to fit in the Ogre graph class Workspace : public Instance
// all instances that are Renderable are stored in the children of this
class Workspace : public Instance, public Ogre::MovableObject
{ {
public: public:
Workspace(); Workspace();
virtual void _updateRenderQueue(Ogre::RenderQueue* queue); void build();
virtual const Ogre::String& getMovableType(void) const;
virtual const Ogre::AxisAlignedBox& getBoundingBox(void) const;
virtual Ogre::Real getBoundingRadius(void) const;
virtual void visitRenderables(Ogre::Renderable::Visitor* visitor, bool debugRenderables);
private: private:
Ogre::AxisAlignedBox m_bbox; Ogre::InstanceManager* m_instMan;
Ogre::String m_type; Ogre::SceneNode* m_worldspawn;
void renderQueueAddInstance(Ogre::RenderQueue* queue, Instance* instance); void buildChild(Instance* child);
}; };
} }

View File

@ -2,7 +2,7 @@
namespace RNR namespace RNR
{ {
CoordinateFrame::CoordinateFrame() : m_position(0.f,0.f,0.f), m_rotation() CoordinateFrame::CoordinateFrame() : m_position(0.f,0.f,0.f), m_scale(1.f,1.f,1.f), m_rotation()
{ {
m_rotation.FromEulerAnglesXYZ(Ogre::Radian(0.f), Ogre::Radian(0.f), Ogre::Radian(0.f)); m_rotation.FromEulerAnglesXYZ(Ogre::Radian(0.f), Ogre::Radian(0.f), Ogre::Radian(0.f));
} }
@ -10,7 +10,7 @@ namespace RNR
Ogre::Matrix4 CoordinateFrame::getMatrix() Ogre::Matrix4 CoordinateFrame::getMatrix()
{ {
Ogre::Matrix4 res = Ogre::Matrix4(); Ogre::Matrix4 res = Ogre::Matrix4();
res.makeTransform(m_position, Ogre::Vector3(1.f,1.f,1.f), Ogre::Quaternion(m_rotation)); res.makeTransform(m_position, m_scale, Ogre::Quaternion(m_rotation));
return res; return res;
} }

View File

@ -13,10 +13,10 @@ namespace RNR
m_nearbyLights = Ogre::LightList(); m_nearbyLights = Ogre::LightList();
m_nearbyLights.insert(m_nearbyLights.begin(), world->getOgreSceneManager()->getLight("SunLight")); m_nearbyLights.insert(m_nearbyLights.begin(), world->getOgreSceneManager()->getLight("SunLight"));
m_material = Ogre::MaterialManager::getSingletonPtr()->create("part", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if(m_partMesh == 0) if(m_partMesh == 0)
m_partMesh = Ogre::Root::getSingletonPtr()->getMeshManager()->load("fonts/Cube.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); m_partMesh = Ogre::Root::getSingletonPtr()->getMeshManager()->load("fonts/Cube.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
m_material = m_partMesh->getSubMesh(0)->getMaterial();
} }
void BasePart::updateMatrix() void BasePart::updateMatrix()
@ -27,8 +27,7 @@ namespace RNR
const Ogre::MaterialPtr& BasePart::getMaterial() const const Ogre::MaterialPtr& BasePart::getMaterial() const
{ {
Ogre::SubMesh* submesh = m_partMesh->getSubMesh(0); return m_material;
return submesh->getMaterial();
} }
void BasePart::getRenderOperation(Ogre::RenderOperation& op) void BasePart::getRenderOperation(Ogre::RenderOperation& op)

View File

@ -6,6 +6,8 @@ namespace RNR
Instance::Instance() Instance::Instance()
{ {
m_node = 0;
m_object = 0;
m_parent = 0; m_parent = 0;
setName("Instance"); setName("Instance");
} }

View File

@ -1,54 +1,36 @@
#include <App/V8/World/Workspace.hpp> #include <App/V8/World/Workspace.hpp>
#include <App/V8/World/World.hpp>
#include <App/V8/DataModel/BasePart.hpp> #include <App/V8/DataModel/BasePart.hpp>
namespace RNR namespace RNR
{ {
Workspace::Workspace() : Instance(), Ogre::MovableObject() Workspace::Workspace() : Instance()
{ {
setName("Workspace"); setName("Workspace");
m_type = Ogre::String("Entity"); m_instMan = world->getOgreSceneManager()->createInstanceManager("workspacePartInstanceManager", "fonts/Cube.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::InstanceManager::InstancingTechnique::HWInstancingBasic, 255);
m_bbox = Ogre::AxisAlignedBox(-1000,-1000,-1000, 1000,1000,1000); m_worldspawn = world->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode();
} }
void Workspace::_updateRenderQueue(Ogre::RenderQueue* queue) void Workspace::build()
{ {
std::vector<Instance*>* children = getChildren(); for(auto& child : *getChildren())
for(auto& child : *children) buildChild(child);
}
void Workspace::buildChild(Instance* child)
{
for(auto& child2 : *child->getChildren())
buildChild(child2);
BasePart* child_part = (BasePart*)child;
Ogre::InstancedEntity* child_ent = (Ogre::InstancedEntity*)child->getObject();
if(!child_ent)
{ {
renderQueueAddInstance(queue, child); child_ent = m_instMan->createInstancedEntity("fonts/Material");
child_ent->setUserAny(child);
child->setObject(child_ent);
} }
} child_ent->setPosition(child_part->getCFrame().getPosition());
child_ent->setOrientation(Ogre::Quaternion(child_part->getCFrame().getRotation()));
void Workspace::renderQueueAddInstance(Ogre::RenderQueue* queue, Instance* instance)
{
std::vector<Instance*>* children = instance->getChildren();
BasePart* rend = dynamic_cast<BasePart*>(instance);
queue->addRenderable(rend);
for(auto& child : *children)
{
renderQueueAddInstance(queue, child);
}
}
const Ogre::String& Workspace::getMovableType(void) const
{
printf("Workspace::getMovableType\n");
return m_type;
}
const Ogre::AxisAlignedBox& Workspace::getBoundingBox(void) const
{
return m_bbox;
}
Ogre::Real Workspace::getBoundingRadius(void) const
{
return 100;
}
void Workspace::visitRenderables(Ogre::Renderable::Visitor* visitor, bool debugRenderables)
{
} }
} }

View File

@ -18,6 +18,8 @@ namespace RNR
BasePart* test2 = new BasePart(); BasePart* test2 = new BasePart();
test->setParent(m_datamodel); test->setParent(m_datamodel);
test2->setParent(m_workspace); test2->setParent(m_workspace);
m_workspace->build();
} }
World::~World() World::~World()