From a203911deea344edd0140ad5340a6e68e640f20a Mon Sep 17 00:00:00 2001 From: floralrainfall Date: Thu, 20 Jul 2023 05:11:08 -0400 Subject: [PATCH] fix corrupted mesh & fix instancing --- Content/RNR/materials/BackMaterial.material | 2 +- Content/RNR/materials/BottomMaterial.material | 2 +- Content/RNR/materials/FrontMaterial.material | 2 +- .../RNR/materials/InstancedMaterial.material | 16 ++++++++++++ Content/RNR/materials/LeftMaterial.material | 2 +- Content/RNR/materials/RightMaterial.material | 2 +- Content/RNR/materials/TopMaterial.material | 2 +- Content/RNR/materials/partinstanced.material | 18 +++++++++++++ Content/RNR/meshes/Cube.mesh | Bin 1638 -> 1290 bytes Content/RNR/meshes/Cube.scene | 16 ++++++------ Content/RNR/meshes/Cube_Instanced.mesh | Bin 0 -> 1057 bytes Content/RNR/meshes/Cube_Instanced.scene | 24 ++++++++++++++++++ Projects/Client/Studio/Source/main.cpp | 2 +- .../Source/App/V8/DataModel/PartInstance.cpp | 22 +++++++++++++--- .../Source/App/V8/DataModel/Workspace.cpp | 15 ++++++----- Projects/Engine/Source/App/V8/World/World.cpp | 23 ++++++++++------- 16 files changed, 114 insertions(+), 34 deletions(-) create mode 100644 Content/RNR/materials/InstancedMaterial.material create mode 100644 Content/RNR/meshes/Cube_Instanced.mesh create mode 100644 Content/RNR/meshes/Cube_Instanced.scene diff --git a/Content/RNR/materials/BackMaterial.material b/Content/RNR/materials/BackMaterial.material index dbd65f9..69d9665 100644 --- a/Content/RNR/materials/BackMaterial.material +++ b/Content/RNR/materials/BackMaterial.material @@ -1,5 +1,5 @@ // generated by blender2ogre 0.8.3 on 2023-07-17 02:58:22 -material materials/BackMaterial { +material BackMaterial { receive_shadows on technique { pass { diff --git a/Content/RNR/materials/BottomMaterial.material b/Content/RNR/materials/BottomMaterial.material index e0f377c..608d795 100644 --- a/Content/RNR/materials/BottomMaterial.material +++ b/Content/RNR/materials/BottomMaterial.material @@ -1,5 +1,5 @@ // generated by blender2ogre 0.8.3 on 2023-07-17 02:58:22 -material materials/BottomMaterial { +material BottomMaterial { receive_shadows on technique { pass { diff --git a/Content/RNR/materials/FrontMaterial.material b/Content/RNR/materials/FrontMaterial.material index bc14cdc..da97fcc 100644 --- a/Content/RNR/materials/FrontMaterial.material +++ b/Content/RNR/materials/FrontMaterial.material @@ -1,5 +1,5 @@ // generated by blender2ogre 0.8.3 on 2023-07-17 02:58:22 -material materials/FrontMaterial { +material FrontMaterial { receive_shadows on technique { pass { diff --git a/Content/RNR/materials/InstancedMaterial.material b/Content/RNR/materials/InstancedMaterial.material new file mode 100644 index 0000000..8d177d2 --- /dev/null +++ b/Content/RNR/materials/InstancedMaterial.material @@ -0,0 +1,16 @@ +// generated by blender2ogre 0.8.3 on 2023-07-20 04:32:47 +material InstancedMaterial { + receive_shadows on + technique { + pass { + diffuse 0.8 0.8 0.8 1.0 + specular 0.5 0.0 0 0 0 + rtshader_system { + lighting_stage metal_roughness + texturing_stage late_add_blend + transform_stage instanced + } + + } + } +} diff --git a/Content/RNR/materials/LeftMaterial.material b/Content/RNR/materials/LeftMaterial.material index ab2fd8f..eefafd4 100644 --- a/Content/RNR/materials/LeftMaterial.material +++ b/Content/RNR/materials/LeftMaterial.material @@ -1,5 +1,5 @@ // generated by blender2ogre 0.8.3 on 2023-07-17 02:58:22 -material materials/LeftMaterial { +material LeftMaterial { receive_shadows on technique { pass { diff --git a/Content/RNR/materials/RightMaterial.material b/Content/RNR/materials/RightMaterial.material index 6a9fdff..a33bdad 100644 --- a/Content/RNR/materials/RightMaterial.material +++ b/Content/RNR/materials/RightMaterial.material @@ -1,5 +1,5 @@ // generated by blender2ogre 0.8.3 on 2023-07-17 02:58:22 -material materials/RightMaterial { +material RightMaterial { receive_shadows on technique { pass { diff --git a/Content/RNR/materials/TopMaterial.material b/Content/RNR/materials/TopMaterial.material index d36aeac..91b3370 100644 --- a/Content/RNR/materials/TopMaterial.material +++ b/Content/RNR/materials/TopMaterial.material @@ -1,5 +1,5 @@ // generated by blender2ogre 0.8.3 on 2023-07-17 02:58:22 -material materials/TopMaterial { +material TopMaterial { receive_shadows on technique { pass { diff --git a/Content/RNR/materials/partinstanced.material b/Content/RNR/materials/partinstanced.material index ffd9e80..1d00859 100644 --- a/Content/RNR/materials/partinstanced.material +++ b/Content/RNR/materials/partinstanced.material @@ -1,9 +1,26 @@ +material materials/PartInstanced/shadow_caster +{ + technique + { + pass + { + rtshader_system + { + lighting_stage gbuffer depth + transform_stage instanced + } + } + } +} + material materials/PartInstanced { receive_shadows on technique { + shadow_caster_material materials/PartInstanced/shadow_caster + pass { specular 1 1 1 1 12.5 @@ -17,6 +34,7 @@ material materials/PartInstanced rtshader_system { lighting_stage per_pixel + transform_stage instanced } } } diff --git a/Content/RNR/meshes/Cube.mesh b/Content/RNR/meshes/Cube.mesh index d5d61b61aee3d4ed4f7197a2ec0bf1d0bf040125..618fb9bb1ca4093b89309520295930df7e836f63 100644 GIT binary patch literal 1290 zcmZ`(OHLa>5PkmO5Qo5!@X0dDnjo`b!(v)2vI-KI>>?CdkpU|qj*OK>RmI6~g5>GF(QP*QbOzfaBdSZ!oqkA~Nmr^Cr;@N@KcIQjNxZ+EZPJL{tN*aqYH zxCOjZce2kVJIU0eiH6l`-^L0N-#750boDd(f%nMz9qVwWF`Gx1t@Xm>6nw~8RW{C6MOYH(LS@g+k=TlV_%n*6{jE|go#53$1!j;l7=6p!} zDeqe0%ABbvqED@`gtuoBR#@*|YU|un=PzAR7vg+>hWzSlVe^D}vNcV?CfJ;?!}iPg z_t9W#m#*9B5I_rUEOC9ynuTQ|ynW$-^>93$j;|`YZW&&pi&t1fhIRIv+^u1oyUMyt zReyAGIjx-bpcTBvDzEAmYo-23_2=PvD(>(WFQbDE)=I3=pC;p9sT%xGXp(!wI#=I* zAi}t>rGK6L;qENQzZ>zhO)g6~9DM&Ve`CzH2sV>*l+xDX`(n0DX(Rnw<%D+fx|nTH Iy!bQx2Tua8yG{c!5Zp_S140A`l9gd!A3#N$wiDEKXE#Aoms`~tJL zw%5J{EXCfPotd?Lktw}88@vuL2IEoxar8bI-@NVb?sq!ZHR}9)ea3`weqJTo;HZ0m zDea~lQ-z{p)jXy;5SvFdFRES&J<%qmy`+c;&H#?gkBb-p8IedC8cEUeGN-UUMr|B8 z6OKA)gd!5jS>Q7T_2)8Ma@+SmruZ_`XCX%_2ugN1Oe#+0a7)bG*@fxNQ(S0(*}XbX zYvuUj={W^EHgv~US5f@!D@sqJoQnU^Y@T?kn^mY@dP^>` z<@gnKnB_Q|S?;0ksK}WCv9qMwBVZztT!<``TxPRdhZbU&P^N71|v)iR!`7FN~m1iI6~U0IgkEnA?3 z8dy~pwmTW;&t)CqjjX_Y4Xe}PZnl77$c_24yV>uL>m&Wx95o@BqvQVVgF6$$Ex;A; l>cUf7Vbx;<=VL+}7Li9N-M;M-dzA37%xJ*G|AhXB{{{A~x#R!< diff --git a/Content/RNR/meshes/Cube.scene b/Content/RNR/meshes/Cube.scene index 23da0db..e56d34d 100644 --- a/Content/RNR/meshes/Cube.scene +++ b/Content/RNR/meshes/Cube.scene @@ -1,7 +1,7 @@ - - + + @@ -15,22 +15,22 @@ - + - + - + - + - + - + diff --git a/Content/RNR/meshes/Cube_Instanced.mesh b/Content/RNR/meshes/Cube_Instanced.mesh new file mode 100644 index 0000000000000000000000000000000000000000..1ffbcc7bd09be4eeac640e9b84f68d7d72a2eba0 GIT binary patch literal 1057 zcmZ{jO-=$q5QQHwf+FhpZ(I@M+Q7!`^wxz5>e3iPltdE40*DJ&a|Dl|XYc?V!|V87 zO_#s~E2-(~`rfOVo}`i9Uk@fPcZ2b;|2ljhj33{+7u`yx z>q+EX%#-CGSDo>pT*X7=&Zt}T(pBum$uwh$hmya{<(JQs+{5OCh52G-&X)Pr&;H@g z#F?gNiJTeYeD_kj#3hS9dF^~!6*)6RPM`6}%p=aQbEvPBj`7Ds$zSHKRbQDg6?ycj zRIkMCoop+tb}zMyY}NS-SJZ_#-`^p>>V>d*>Upv>P0k|NoG@Z}HJVKOqo=|1b$@DC zuUR=~n^8d(H6&O=oi}J58)#yaH){*q*g=Y2YWAqAVV|lx4yf9|Ayq9LQMH3(s?xAd eT>^ZZY3Tf)%vk%kWk25!89v+MU#EJm_^w|Bbbe3( literal 0 HcmV?d00001 diff --git a/Content/RNR/meshes/Cube_Instanced.scene b/Content/RNR/meshes/Cube_Instanced.scene new file mode 100644 index 0000000..fca1513 --- /dev/null +++ b/Content/RNR/meshes/Cube_Instanced.scene @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Projects/Client/Studio/Source/main.cpp b/Projects/Client/Studio/Source/main.cpp index 35d0b41..0a1d5d2 100644 --- a/Projects/Client/Studio/Source/main.cpp +++ b/Projects/Client/Studio/Source/main.cpp @@ -32,7 +32,7 @@ int main(int argc, char** argv) while (window.isVisible()) { - window.statusBar()->showMessage(QString::asprintf("Dt=%f, Rt=%f, FPS=%f", window.ogreWidget->delta, window.ogreWidget->render_time, 1 / window.ogreWidget->delta)); + window.statusBar()->showMessage(QString::asprintf("Dt=%f, Rt=%f, Pt=%f, FPS=%f, pFPS=%f", window.ogreWidget->delta, window.ogreWidget->render_time, window.ogreWidget->world->getPhysicsTime(), 1 / window.ogreWidget->delta, 1 / window.ogreWidget->world->getLastPhysicsDelta())); app.processEvents(); window.ogreWidget->render(); world->update(); diff --git a/Projects/Engine/Source/App/V8/DataModel/PartInstance.cpp b/Projects/Engine/Source/App/V8/DataModel/PartInstance.cpp index f85de2b..f8a7cef 100644 --- a/Projects/Engine/Source/App/V8/DataModel/PartInstance.cpp +++ b/Projects/Engine/Source/App/V8/DataModel/PartInstance.cpp @@ -13,7 +13,7 @@ namespace RNR m_reflectance = 0.0; setNode(world->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode()); - setObject(world->getOgreSceneManager()->createEntity("meshes/cube.mesh")); + setObject(world->getOgreSceneManager()->createEntity("meshes/Cube.mesh")); getNode()->attachObject(getObject()); updateMatrix(); @@ -24,9 +24,23 @@ namespace RNR m_matrix = m_cframe.getMatrix(); m_position = m_cframe.getPosition(); - getNode()->setOrientation(Ogre::Quaternion(m_cframe.getRotation())); - getNode()->setPosition(m_position); - getNode()->setScale(m_size); + if(getNode()) + { + getNode()->setOrientation(Ogre::Quaternion(m_cframe.getRotation())); + getNode()->setPosition(m_position); + getNode()->setScale(m_size); + } + + if(getObject() && dynamic_cast(getObject())) + { + Ogre::InstancedEntity* object = (Ogre::InstancedEntity*)getObject(); + + object->setOrientation(Ogre::Quaternion(m_cframe.getRotation())); + object->setPosition(m_position); + object->setScale(m_size); + + object->updateTransforms(); + } Ogre::Entity* entity = (Ogre::Entity*)getObject(); for(auto& subentity : entity->getSubEntities()) diff --git a/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp b/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp index df38a78..9e545d5 100644 --- a/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp +++ b/Projects/Engine/Source/App/V8/DataModel/Workspace.cpp @@ -8,14 +8,14 @@ namespace RNR Workspace::Workspace() : ModelInstance() { setName("Workspace"); - m_batchMode = BATCH_STATIC_GEOMETRY; + m_batchMode = BATCH_INSTANCED; m_worldspawn = world->getOgreSceneManager()->getRootSceneNode()->createChildSceneNode(); - + switch(m_batchMode) { case BATCH_INSTANCED: - m_instanceManager = world->getOgreSceneManager()->createInstanceManager("workspaceInstanceManager", "fonts/Cube.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::InstanceManager::InstancingTechnique::HWInstancingBasic, 255); + m_instanceManager = world->getOgreSceneManager()->createInstanceManager("workspaceInstanceManager", "meshes/Cube_Instanced.mesh", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::InstanceManager::InstancingTechnique::HWInstancingBasic, 255); break; case BATCH_STATIC_GEOMETRY: m_geom = world->getOgreSceneManager()->createStaticGeometry("workspaceGeom"); @@ -37,11 +37,13 @@ namespace RNR { case BATCH_INSTANCED: { - Ogre::Entity* childEntity = (Ogre::Entity*)childAdded->getObject(); - Ogre::InstancedEntity* replica = m_instanceManager->createInstancedEntity("materials/PartInstanced"); - replica->setPosition(part->getPosition()); + Ogre::InstancedEntity* replica = m_instanceManager->createInstancedEntity(BrickColor::material(part->getBrickColor())->getName()); + part->updateMatrix(); + replica->setPosition(part->getCFrame().getPosition()); replica->setOrientation(part->getCFrame().getRotation()); replica->setScale(part->getSize()); + replica->setCastShadows(true); + m_worldspawn->attachObject(replica); childAdded->setObject(replica); child_node->setVisible(false); } @@ -55,6 +57,7 @@ namespace RNR m_geomDirty = true; break; case BATCH_DONT: + child_node->setVisible(true); break; } world->registerPhysicsPart(part); diff --git a/Projects/Engine/Source/App/V8/World/World.cpp b/Projects/Engine/Source/App/V8/World/World.cpp index 17f95d5..547f605 100644 --- a/Projects/Engine/Source/App/V8/World/World.cpp +++ b/Projects/Engine/Source/App/V8/World/World.cpp @@ -64,6 +64,7 @@ namespace RNR m_runPhysics = true; m_physicsTimer = new Ogre::Timer(); m_physicsThread = std::thread(physicsThread, this); + m_physicsTime = 0.0; m_tmb = new TopMenuBar(this); @@ -168,16 +169,20 @@ namespace RNR m_inputManager->frame(); m_tmb->frame(); m_lastDelta = timestep; - physicsIterateLock.lock(); - for(int j = m_dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--) + if(m_runService && m_runService->getRunning() && !m_runService->getPaused()) { - btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[j]; - if(!obj->isActive()) - continue; - PartInstance* part = (PartInstance*)obj->getUserPointer(); - part->updateMatrix(); + physicsIterateLock.lock(); + for(int j = m_dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--) + { + btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[j]; + if(!obj->isActive()) + continue; + PartInstance* part = (PartInstance*)obj->getUserPointer(); + part->updateMatrix(); + } + update(); + physicsIterateLock.unlock(); } - physicsIterateLock.unlock(); } void World::preStep() @@ -243,7 +248,7 @@ namespace RNR btVector3 localInertia = btVector3(0,0,0); if(mass) partShape->calculateLocalInertia(mass, localInertia); - + btDefaultMotionState* partMotionState = new btDefaultMotionState(partTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, partMotionState, partShape, localInertia); btRigidBody* body = new btRigidBody(rbInfo);