static geometry

This commit is contained in:
floralrainfall 2023-07-16 00:35:42 -04:00
parent 5404460fce
commit 835e481330
3 changed files with 46 additions and 20 deletions

View File

@ -19,14 +19,19 @@ namespace RNR
virtual std::string getClassName() { return "Workspace"; } virtual std::string getClassName() { return "Workspace"; }
virtual void onChildAdded(RNR::Instance* childAdded); virtual void onChildAdded(RNR::Instance* childAdded);
virtual void onChildRemoved(RNR::Instance* childRemoved); virtual void onChildRemoved(RNR::Instance* childRemoved);
void buildLegacyGeom();
Camera* getCurrentCamera() const; Camera* getCurrentCamera() const;
void setCurrentCamera(Camera *value); void setCurrentCamera(Camera *value);
private: private:
bool m_instancingEnabled; bool m_instancingEnabled;
bool m_legacyDirty;
std::vector<Ogre::InstancedEntity*> m_objects; std::vector<Ogre::InstancedEntity*> m_objects;
Ogre::StaticGeometry* m_legacyGeom; // use in case of InstanceManager either not working or not being supported
Ogre::InstanceManager* m_instMan; Ogre::InstanceManager* m_instMan;
Ogre::SceneNode* m_worldspawn; Ogre::SceneNode* m_worldspawn;
Ogre::Entity* m_partEntity;
std::shared_ptr<Camera> currentCamera; std::shared_ptr<Camera> currentCamera;
}; };

View File

@ -7,11 +7,13 @@ namespace RNR
{ {
Workspace::Workspace() : ModelInstance() Workspace::Workspace() : ModelInstance()
{ {
m_instancingEnabled = true; m_instancingEnabled = false;
setName("Workspace"); setName("Workspace");
m_instMan = world->getOgreSceneManager()->createInstanceManager("workspacePartInstanceManager", "fonts/Cube.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::InstanceManager::InstancingTechnique::HWInstancingBasic, 255); m_instMan = world->getOgreSceneManager()->createInstanceManager("workspacePartInstanceManager", "fonts/Cube.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::InstanceManager::InstancingTechnique::HWInstancingBasic, 255);
m_instMan->setNumCustomParams(2); m_instMan->setNumCustomParams(2);
m_worldspawn = world->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode(); m_worldspawn = world->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode();
m_legacyGeom = world->getOgreSceneManager()->createStaticGeometry("workspaceGeom");
m_partEntity = world->getOgreSceneManager()->createEntity("fonts/Cube.mesh");
} }
void Workspace::onChildAdded(Instance* childAdded) void Workspace::onChildAdded(Instance* childAdded)
@ -19,29 +21,46 @@ namespace RNR
PartInstance* child_part = dynamic_cast<PartInstance*>(childAdded); PartInstance* child_part = dynamic_cast<PartInstance*>(childAdded);
if(child_part) if(child_part)
{ {
Ogre::InstancedEntity* child_ent = (Ogre::InstancedEntity*)childAdded->getObject(); if(m_instancingEnabled)
if(!child_ent)
{ {
child_ent = m_instMan->createInstancedEntity("materials/partinstanced"); Ogre::InstancedEntity* child_ent = (Ogre::InstancedEntity*)childAdded->getObject();
assert(child_ent != NULL); if(!child_ent)
childAdded->setObject(child_ent); {
m_objects.push_back(child_ent); child_ent = m_instMan->createInstancedEntity("materials/partinstanced");
assert(child_ent != NULL);
childAdded->setObject(child_ent);
m_objects.push_back(child_ent);
}
child_ent->setPosition(child_part->getCFrame().getPosition());
child_ent->setOrientation(Ogre::Quaternion(child_part->getCFrame().getRotation()));
Ogre::Vector3 size = child_part->getSize();
child_ent->setScale(size);
child_ent->setCustomParam(0, Ogre::Vector4(
size.x,
size.y,
size.z,
0.0f
));
child_ent->setCustomParam(1, child_part->getColor());
child_ent->setCastShadows(true);
}
else
{
m_legacyGeom->addEntity(m_partEntity,
child_part->getCFrame().getPosition(),
Ogre::Quaternion(child_part->getCFrame().getRotation()),
child_part->getSize());
m_legacyDirty = true;
} }
child_ent->setPosition(child_part->getCFrame().getPosition());
child_ent->setOrientation(Ogre::Quaternion(child_part->getCFrame().getRotation()));
Ogre::Vector3 size = child_part->getSize();
child_ent->setScale(size);
child_ent->setCustomParam(0, Ogre::Vector4(
size.x,
size.y,
size.z,
0.0f
));
child_ent->setCustomParam(1, child_part->getColor());
child_ent->setCastShadows(true);
} }
} }
void Workspace::buildLegacyGeom()
{
m_legacyGeom->build();
m_legacyDirty = false;
}
void Workspace::onChildRemoved(Instance* childRemoved) void Workspace::onChildRemoved(Instance* childRemoved)
{ {
Ogre::InstancedEntity* child_ent = (Ogre::InstancedEntity*)childRemoved->getObject(); Ogre::InstancedEntity* child_ent = (Ogre::InstancedEntity*)childRemoved->getObject();

View File

@ -15,6 +15,8 @@ namespace RNR
m_datamodel->setName("DataModel"); m_datamodel->setName("DataModel");
m_workspace = new Workspace(); m_workspace = new Workspace();
m_workspace->setParent(m_datamodel); m_workspace->setParent(m_datamodel);
load("/home/caesium/Downloads/Telegram Desktop/Destroy-History-1.rbxl");
} }
World::~World() World::~World()
@ -95,6 +97,6 @@ namespace RNR
void World::update() void World::update()
{ {
// m_workspace->buildLegacyGeom();
} }
} }