diff --git a/Projects/Engine/Header/App/V8/DataModel/Workspace.hpp b/Projects/Engine/Header/App/V8/DataModel/Workspace.hpp index b44ff0c..6beecc7 100644 --- a/Projects/Engine/Header/App/V8/DataModel/Workspace.hpp +++ b/Projects/Engine/Header/App/V8/DataModel/Workspace.hpp @@ -19,14 +19,19 @@ namespace RNR virtual std::string getClassName() { return "Workspace"; } virtual void onChildAdded(RNR::Instance* childAdded); virtual void onChildRemoved(RNR::Instance* childRemoved); + + void buildLegacyGeom(); Camera* getCurrentCamera() const; void setCurrentCamera(Camera *value); private: bool m_instancingEnabled; + bool m_legacyDirty; std::vector m_objects; + Ogre::StaticGeometry* m_legacyGeom; // use in case of InstanceManager either not working or not being supported Ogre::InstanceManager* m_instMan; Ogre::SceneNode* m_worldspawn; + Ogre::Entity* m_partEntity; std::shared_ptr currentCamera; }; diff --git a/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp b/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp index b1b2ca4..35c3781 100644 --- a/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp +++ b/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp @@ -7,11 +7,13 @@ namespace RNR { Workspace::Workspace() : ModelInstance() { - m_instancingEnabled = true; + m_instancingEnabled = false; setName("Workspace"); 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_worldspawn = world->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode(); + m_legacyGeom = world->getOgreSceneManager()->createStaticGeometry("workspaceGeom"); + m_partEntity = world->getOgreSceneManager()->createEntity("fonts/Cube.mesh"); } void Workspace::onChildAdded(Instance* childAdded) @@ -19,29 +21,46 @@ namespace RNR PartInstance* child_part = dynamic_cast(childAdded); if(child_part) { - Ogre::InstancedEntity* child_ent = (Ogre::InstancedEntity*)childAdded->getObject(); - if(!child_ent) + if(m_instancingEnabled) { - child_ent = m_instMan->createInstancedEntity("materials/partinstanced"); - assert(child_ent != NULL); - childAdded->setObject(child_ent); - m_objects.push_back(child_ent); + Ogre::InstancedEntity* child_ent = (Ogre::InstancedEntity*)childAdded->getObject(); + if(!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) { Ogre::InstancedEntity* child_ent = (Ogre::InstancedEntity*)childRemoved->getObject(); diff --git a/Projects/Engine/Source/App/V8/World/World.cpp b/Projects/Engine/Source/App/V8/World/World.cpp index b7e69d0..267bb1f 100644 --- a/Projects/Engine/Source/App/V8/World/World.cpp +++ b/Projects/Engine/Source/App/V8/World/World.cpp @@ -15,6 +15,8 @@ namespace RNR m_datamodel->setName("DataModel"); m_workspace = new Workspace(); m_workspace->setParent(m_datamodel); + + load("/home/caesium/Downloads/Telegram Desktop/Destroy-History-1.rbxl"); } World::~World() @@ -95,6 +97,6 @@ namespace RNR void World::update() { - // + m_workspace->buildLegacyGeom(); } } \ No newline at end of file