diff --git a/Core/src/lua/LuaInterface.cpp b/Core/src/lua/LuaInterface.cpp index d268fa9..fc64075 100644 --- a/Core/src/lua/LuaInterface.cpp +++ b/Core/src/lua/LuaInterface.cpp @@ -425,6 +425,17 @@ namespace Gsage { } return res; }, + "normals", [](Geom* geom){ + float* normals; + int count; + std::tie(normals, count) = geom->getNormals(); + std::vector res; + res.reserve(count / 3); + for(int i = 0; i < count; i += 3) { + res.emplace_back(normals[i], normals[i + 1], normals[i + 2]); + } + return res; + }, "tris", [](Geom* geom){ int* tris; int count; diff --git a/PlugIns/ImGUI/Common/src/ImGuiDockspace.cpp b/PlugIns/ImGUI/Common/src/ImGuiDockspace.cpp index f9ef115..ee8840f 100644 --- a/PlugIns/ImGUI/Common/src/ImGuiDockspace.cpp +++ b/PlugIns/ImGUI/Common/src/ImGuiDockspace.cpp @@ -96,7 +96,7 @@ namespace Gsage { float lineHeight = ImGui::GetTextLineHeight(); ImGuiDockspaceStyle style; style.tabbarHeight = lineHeight * 1.2f; - style.splitterThickness = lineHeight / 6.5f; + style.splitterThickness = lineHeight / 5.0f; style.tabbarTextMargin = lineHeight / 1.7f; style.tabbarPadding = lineHeight / 26.0f; style.windowRounding = ImGui::GetStyle().WindowRounding; @@ -1361,6 +1361,7 @@ namespace Gsage { ImGuiIO& io = ImGui::GetIO(); float rounding = ImGui::GetStyle().WindowRounding; ImVec2 margin(rounding, rounding); + ImVec2 overlapMultiplier = ImVec2(0, 0); switch(dock->getLayout()) { case Dock::Horizontal: @@ -1372,6 +1373,7 @@ namespace Gsage { pos.x += child->getSize().x; size = ImVec2(mStyle.splitterThickness, dock->getSize().y); cursor = ImGuiMouseCursor_ResizeEW; + overlapMultiplier.x = 1; break; case Dock::Vertical: if(dock->mResized) { @@ -1382,6 +1384,7 @@ namespace Gsage { pos.y += child->getSize().y; size = ImVec2(dock->getSize().x, mStyle.splitterThickness); cursor = ImGuiMouseCursor_ResizeNS; + overlapMultiplier.y = 1; break; default: LOG(INFO) << "Can't draw splitters for layout " << dock->getLayout(); @@ -1393,10 +1396,13 @@ namespace Gsage { } ImVec2 screenPos = ImGui::GetCursorScreenPos(); - ImGui::SetCursorScreenPos(pos); if(size.x > 0 && size.y > 0) { - ImGui::InvisibleButton("split", size); + ImVec2 buttonPos = pos - overlapMultiplier * size; + ImVec2 buttonSize = size + size * overlapMultiplier * 2; + ImGui::SetCursorScreenPos(buttonPos); + ImGui::InvisibleButton("split", buttonSize); } + ImGui::SetCursorScreenPos(pos); if (ImGui::IsItemHovered() && !ImGui::IsMouseDragging()) { dock->mResized = ImGui::IsMouseDown(0); @@ -1412,8 +1418,10 @@ namespace Gsage { ImGui::SetMouseCursor(cursor); } + ImVec2 min = pos; + ImVec2 max = pos + size; canvas->AddRectFilled( - ImGui::GetItemRectMin() + margin, ImGui::GetItemRectMax() - margin, over ? mStyle.splitterHoveredColor : mStyle.splitterNormalColor); + min + margin, max - margin, over ? mStyle.splitterHoveredColor : mStyle.splitterNormalColor); ImGui::PopID(); ImGui::SetCursorScreenPos(screenPos); } diff --git a/PlugIns/ImGUI/Common/src/ImguiManager.cpp b/PlugIns/ImGUI/Common/src/ImguiManager.cpp index c2f6ca2..205e4e2 100644 --- a/PlugIns/ImGUI/Common/src/ImguiManager.cpp +++ b/PlugIns/ImGUI/Common/src/ImguiManager.cpp @@ -522,7 +522,7 @@ namespace Gsage { WindowPtr window = mFacade->getWindowManager()->getWindow(name); float scale = 1.0f; if(window) { - scale = std::max(1.0f, window->getScaleFactor() * .75f); + scale = std::max(1.0f, window->getScaleFactor() * .9f); } LOG(INFO) << "Creating ImGui context " << name; diff --git a/PlugIns/ImGUI/OgreInterfaces/src/ImguiOgreRenderer.cpp b/PlugIns/ImGUI/OgreInterfaces/src/ImguiOgreRenderer.cpp index 50ee195..c60b649 100644 --- a/PlugIns/ImGUI/OgreInterfaces/src/ImguiOgreRenderer.cpp +++ b/PlugIns/ImGUI/OgreInterfaces/src/ImguiOgreRenderer.cpp @@ -102,7 +102,8 @@ namespace Gsage { mFontTexHeight, 1, 1, - Ogre::PF_R8G8B8A8 + Ogre::PF_R8G8B8A8, + Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE ); const Ogre::PixelBox& lockBox = mFontTex->getBuffer()->lock(Ogre::Image::Box(0, 0, mFontTexWidth, mFontTexHeight), OgreV1::HardwareBuffer::HBL_DISCARD); diff --git a/PlugIns/OgrePlugin/include/ogre/MaterialBuilder.h b/PlugIns/OgrePlugin/include/ogre/MaterialBuilder.h index c1a8e0a..2da774d 100644 --- a/PlugIns/OgrePlugin/include/ogre/MaterialBuilder.h +++ b/PlugIns/OgrePlugin/include/ogre/MaterialBuilder.h @@ -45,6 +45,13 @@ namespace Gsage { * @return true if succeed */ static Ogre::MaterialPtr parse(const std::string& name, const DataProxy& data); + +#if OGRE_VERSION >= 0x020100 + /** + * Create hlms material from json data + */ + static Ogre::HlmsDatablock* parseHlms(const std::string& name, const DataProxy& data, bool rebuild = false); +#endif }; } diff --git a/PlugIns/OgrePlugin/include/ogre/v2/ManualObjectWrapper.h b/PlugIns/OgrePlugin/include/ogre/v2/ManualObjectWrapper.h index a327644..fc9dfe4 100644 --- a/PlugIns/OgrePlugin/include/ogre/v2/ManualObjectWrapper.h +++ b/PlugIns/OgrePlugin/include/ogre/v2/ManualObjectWrapper.h @@ -31,6 +31,7 @@ THE SOFTWARE. #include "ogre/MovableObjectWrapper.h" namespace Gsage { + class ManualObjectWrapper : public MovableObjectWrapper { public: @@ -38,6 +39,23 @@ namespace Gsage { ManualObjectWrapper(); virtual ~ManualObjectWrapper(); + + /** + * Set manual object data + * + * @param data to create manual object from + */ + void setData(const DataProxy& data); + + /** + * Get manual object data + * + * @return data + */ + const DataProxy& getData() const; + + private: + DataProxy mData; }; } diff --git a/PlugIns/OgrePlugin/src/MeshTools.cpp b/PlugIns/OgrePlugin/src/MeshTools.cpp index 49e9cb4..1b47faf 100644 --- a/PlugIns/OgrePlugin/src/MeshTools.cpp +++ b/PlugIns/OgrePlugin/src/MeshTools.cpp @@ -148,10 +148,10 @@ namespace Ogre { MeshInformation::Flags flags ) { - bool added_shared = false; - size_t current_offset = 0; - size_t shared_offset = 0; - size_t next_offset = 0; + bool addedShared = false; + size_t currentOffset = 0; + size_t sharedOffset = 0; + size_t nextOffset = 0; size_t index_offset = 0; size_t vertex_count = 0; @@ -165,10 +165,10 @@ namespace Ogre { // We only need to add the shared vertices once if(submesh->useSharedVertices) { - if( !added_shared ) + if( !addedShared ) { vertex_count += GET_IV_DATA(mesh->sharedVertexData)->vertexCount; - added_shared = true; + addedShared = true; } } else @@ -181,36 +181,36 @@ namespace Ogre { } dest.allocate(vertex_count, index_count, flags); - added_shared = false; + addedShared = false; // Run through the submeshes again, adding the data into the arrays for ( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i) { OgreV1::SubMesh* submesh = mesh->getSubMesh(i); - OgreV1::VertexData* vertex_data = submesh->useSharedVertices ? GET_IV_DATA(mesh->sharedVertexData) : GET_IV_DATA(submesh->vertexData); + OgreV1::VertexData* vertexData = submesh->useSharedVertices ? GET_IV_DATA(mesh->sharedVertexData) : GET_IV_DATA(submesh->vertexData); - if((!submesh->useSharedVertices)||(submesh->useSharedVertices && !added_shared)) + if((!submesh->useSharedVertices)||(submesh->useSharedVertices && !addedShared)) { if(submesh->useSharedVertices) { - added_shared = true; - shared_offset = current_offset; + addedShared = true; + sharedOffset = currentOffset; } // read vertices if(dest.vertices || dest.normals) { const OgreV1::VertexElement* normElem = nullptr; const OgreV1::VertexElement* posElem = - vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION); + vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION); OgreV1::HardwareVertexBufferSharedPtr vbuf = - vertex_data->vertexBufferBinding->getBuffer(posElem->getSource()); + vertexData->vertexBufferBinding->getBuffer(posElem->getSource()); unsigned char* vertex = static_cast(vbuf->lock(OgreV1::HardwareBuffer::HBL_READ_ONLY)); if(dest.normals) { - normElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_NORMAL); + normElem = vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_NORMAL); } // There is _no_ baseVertexPointerToElement() which takes an Ogre::Ogre::Real or a double @@ -222,7 +222,7 @@ namespace Ogre { // Read into short if using 16 bit floats for vertices unsigned short* pShort; - for( size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize()) + for( size_t j = 0; j < vertexData->vertexCount; ++j, vertex += vbuf->getVertexSize()) { Ogre::Vector3 pt; @@ -237,26 +237,26 @@ namespace Ogre { pt = Ogre::Vector3(pReal[0], pReal[1], pReal[2]); } - dest.vertices[current_offset + j] = transform * pt; + dest.vertices[currentOffset + j] = transform * pt; } if(dest.normals) { normElem->baseVertexPointerToElement(vertex, &pReal); pt = Ogre::Vector3(pReal[0], pReal[1], pReal[2]); - dest.normals[current_offset + j] = transform * pt; + dest.normals[currentOffset + j] = transform * pt; } } vbuf->unlock(); } - next_offset += vertex_data->vertexCount; + nextOffset += vertexData->vertexCount; } // read indices if(dest.indices) { OgreV1::IndexData* index_data = GET_IV_DATA(submesh->indexData); - size_t numTris = index_data->indexCount / 3; + size_t numTris = index_data->indexCount; OgreV1::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer; bool use32bitindexes = (ibuf->getType() == OgreV1::HardwareIndexBuffer::IT_32BIT); @@ -265,18 +265,18 @@ namespace Ogre { unsigned short* pShort = reinterpret_cast(pLong); - size_t offset = (submesh->useSharedVertices)? shared_offset : current_offset; + size_t offset = (submesh->useSharedVertices)? sharedOffset : currentOffset; if ( use32bitindexes ) { - for ( size_t k = 0; k < numTris*3; ++k) + for ( size_t k = 0; k < numTris; ++k) { dest.indices[index_offset++] = pLong[k] + static_cast(offset); } } else { - for ( size_t k = 0; k < numTris*3; ++k) + for ( size_t k = 0; k < numTris; ++k) { dest.indices[index_offset++] = static_cast(pShort[k]) + static_cast(offset); @@ -286,7 +286,7 @@ namespace Ogre { ibuf->unlock(); } - current_offset = next_offset; + currentOffset = nextOffset; } } diff --git a/PlugIns/OgrePlugin/src/OgreGeom.cpp b/PlugIns/OgrePlugin/src/OgreGeom.cpp index 32e65f7..1be059e 100644 --- a/PlugIns/OgrePlugin/src/OgreGeom.cpp +++ b/PlugIns/OgrePlugin/src/OgreGeom.cpp @@ -1,28 +1,28 @@ /* - ----------------------------------------------------------------------------- - This file is a part of Gsage engine - - Copyright (c) 2014-2018 Artem Chernyshev and contributors - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ----------------------------------------------------------------------------- - */ +----------------------------------------------------------------------------- +This file is a part of Gsage engine + +Copyright (c) 2014-2018 Artem Chernyshev and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +----------------------------------------------------------------------------- +*/ #include "OgreGeom.h" #include @@ -45,9 +45,7 @@ namespace Gsage { size_t vertexCount = 0; size_t indexCount = 0; size_t indexOffset = 0; - size_t currentOffset = 0; - size_t sharedOffset = 0; - size_t nextOffset = 0; + size_t vertexOffset = 0; Ogre::MeshInformation* meshData = new Ogre::MeshInformation[mSrcEntities.size()]; size_t meshCount = 0; @@ -78,21 +76,20 @@ namespace Gsage { vertexCount *= 3; - size_t vertexOffset = 0; - verts = new float[vertexCount]; nverts = vertexCount; tris = new int[indexCount]; ntris = indexCount; normals = new float[vertexCount]; + int offset = 0; - for(int i = 0; i < meshCount; ++i) { + for(size_t i = 0; i < meshCount; ++i) { Ogre::MeshInformation& info = meshData[i]; - for (size_t j = 0; j < info.indexCount; ++j) { - tris[indexOffset++] = (int)info.indices[j]; + for(size_t j = 0; j < info.indexCount; ++j) { + tris[indexOffset++] = (int)info.indices[j] + offset; } - for( size_t j = 0; j < info.vertexCount; ++j) + for(size_t j = 0; j < info.vertexCount; ++j) { verts[vertexOffset] = info.vertices[j].x; verts[vertexOffset+1] = info.vertices[j].y; @@ -103,6 +100,8 @@ namespace Gsage { normals[vertexOffset+2] = info.normals[j].z; vertexOffset += 3; } + + offset += info.vertexCount; } delete[] meshData; diff --git a/PlugIns/OgrePlugin/src/ogre/MaterialBuilder.cpp b/PlugIns/OgrePlugin/src/ogre/MaterialBuilder.cpp index c808c4a..e1f126d 100644 --- a/PlugIns/OgrePlugin/src/ogre/MaterialBuilder.cpp +++ b/PlugIns/OgrePlugin/src/ogre/MaterialBuilder.cpp @@ -28,6 +28,14 @@ THE SOFTWARE. #include #include #include +#include "OgreConverters.h" +#if OGRE_VERSION >= 0x020100 +#include +#include +#include +#include +#include +#endif namespace Gsage { @@ -113,4 +121,67 @@ namespace Gsage { return material; } +#if OGRE_VERSION >= 0x020100 + + Ogre::Vector3 colToVector(const Ogre::ColourValue& cv) + { + return Ogre::Vector3(cv.r, cv.g, cv.b) * cv.a; + } + + + Ogre::HlmsDatablock* MaterialBuilder::parseHlms(const std::string& name, const DataProxy& data, bool rebuild) + { + + Ogre::Root& root = Ogre::Root::getSingleton(); + + Ogre::HlmsPbs* pbs = static_cast(root.getHlmsManager()->getHlms(Ogre::HLMS_PBS)); + + Ogre::HlmsMacroblock macroblock; + Ogre::HlmsBlendblock blendblock; + Ogre::HlmsParamVec params; + Ogre::HlmsDatablock* db = pbs->getDatablock(name); + if(!db) { + db = pbs->createDatablock( + name, + name, + macroblock, + blendblock, + params + ); + } else if(!rebuild) { + return static_cast(db); + } + + int nPasses = 0; + int nTechs = 0; + Ogre::HlmsPbsDatablock* datablock = static_cast(db); + datablock->setReceiveShadows(data.get("receiveShadows", false)); + for(auto& t : data.get("techniques", DataProxy::create(DataWrapper::JSON_OBJECT))) { + if(nTechs++ == 1) { + LOG(WARNING) << "Only one technique is supported when converting old style material to Hlms"; + break; + } + for(auto& p : t.second.get("passes", DataProxy::create(DataWrapper::JSON_OBJECT))) { + if(nPasses++ == 1) { + LOG(WARNING) << "Only one pass is supported when converting old style material to Hlms"; + break; + } + + auto diffuse = p.second.get("colors.diffuse"); + auto selfIllumination = p.second.get("colors.illumination"); + + if(diffuse.second) { + datablock->setDiffuse(colToVector(diffuse.first)); + } + + if(selfIllumination.second) { + datablock->setEmissive(colToVector(selfIllumination.first)); + } + } + } + return datablock; + } + +#endif + } diff --git a/PlugIns/OgrePlugin/src/ogre/v2/ManualObjectWrapper.cpp b/PlugIns/OgrePlugin/src/ogre/v2/ManualObjectWrapper.cpp index bfe6817..94c4d08 100644 --- a/PlugIns/OgrePlugin/src/ogre/v2/ManualObjectWrapper.cpp +++ b/PlugIns/OgrePlugin/src/ogre/v2/ManualObjectWrapper.cpp @@ -24,7 +24,16 @@ THE SOFTWARE. ----------------------------------------------------------------------------- */ +#include +#include + +#include +#include + +#include + #include "ogre/v2/ManualObjectWrapper.h" +#include "ogre/MaterialBuilder.h" namespace Gsage { @@ -32,10 +41,137 @@ namespace Gsage { ManualObjectWrapper::ManualObjectWrapper() { + BIND_ACCESSOR("data", &ManualObjectWrapper::setData, &ManualObjectWrapper::getData); } ManualObjectWrapper::~ManualObjectWrapper() { } + const DataProxy& ManualObjectWrapper::getData() const + { + return mData; + } + + void ManualObjectWrapper::setData(const DataProxy& data) + { + auto ppoints = data.get("points"); + if(!ppoints.second) { + LOG(ERROR) << "Manual object \"" << mObjectId << "\" has no points defined"; + return; + } + + mData = data; + + Ogre::OperationType op = data.get("renderOperation", Ogre::OT_LINE_STRIP); + if(op != Ogre::OT_TRIANGLE_LIST && op != Ogre::OT_LINE_LIST && op != Ogre::OT_LINE_STRIP) { + return; + } + + if(mObject) { + mObject->detachFromParent(); + mSceneManager->destroyManualObject(mObject); + } + + Ogre::ManualObject* manualObject = mSceneManager->createManualObject(Ogre::SCENE_DYNAMIC); + mObject = manualObject; + + auto mat = data.get("material"); + + std::string materialName = mObjectId + "Material"; + if(mat.second) { + MaterialBuilder::parseHlms(materialName, mat.first); + } else { + LOG(WARNING) << "No material defined for manual object \"" << mObjectId << "\""; + } + + manualObject->begin(materialName, op); + size_t pc = 0; + + auto indices = data.get("indices"); + bool manualIndices = indices.second; + if(manualIndices) { + for(auto i : indices.first) { + auto e = i.second.getValue(); + if(!e.second) { + LOG(ERROR) << "Got malformed index " << i.second.getValueOptional(""); + return; + } + manualObject->index(e.first); + } + } + + auto manualNormals = data.get("normals"); + std::vector normals; + if(manualNormals.second) { + size_t index = 0; + for(auto p : manualNormals.first) { + Gsage::Vector3 normal(0, 0, 1); + if(!p.second.getValue(normal)) { + LOG(WARNING) << "Malformed normal definition " << p.second.getValueOptional(""); + } + normals.push_back(normal); + } + } + + std::vector points; + points.reserve(ppoints.first.size()); + for(auto p : ppoints.first) { + Gsage::Vector3 point(0, 0, 0); + if(!p.second.getValue(point)) { + LOG(WARNING) << "Malformed point definition " << p.second.getValueOptional(""); + } + points.push_back(point); + } + + Gsage::Vector3 generatedNormal; + size_t ni = 0; + // Points list was updated, redraw manual object + for(size_t i = 0; i < points.size(); ++i) { + Gsage::Vector3 point = points[i]; + manualObject->position(point.X, point.Y, point.Z); + if(ni < normals.size()) { + Gsage::Vector3 normal = normals[ni++]; + manualObject->normal(normal.X, normal.Y, normal.Z); + } else if(op == Ogre::OT_TRIANGLE_LIST) { + if(i == 0 && points.size() > 2) { + generatedNormal = Gsage::Vector3::Cross(points[i + 1] - points[i], points[i + 2] - points[i]); + } + manualObject->normal(generatedNormal.X, generatedNormal.Y, generatedNormal.Z); + + if(manualObject->currentVertexCount() % 3 == 0 && i + 3 < points.size()) { + generatedNormal = Gsage::Vector3::Cross(points[i + 2] - points[i + 1], points[i + 3] - points[i + 1]); + } + } else { + manualObject->normal(0, 0, 1); + } + + if(!manualIndices) { + switch(op) { + case Ogre::OT_TRIANGLE_LIST: + case Ogre::OT_TRIANGLE_STRIP: + if(manualObject->currentVertexCount() % 3 == 0) { + manualObject->triangle(pc, pc + 1, pc + 2); + pc = manualObject->currentVertexCount(); + } + break; + case Ogre::OT_LINE_LIST: + if(manualObject->currentVertexCount() % 2 == 0) { + manualObject->line(pc, pc + 1); + pc = manualObject->currentVertexCount(); + } + break; + default: + manualObject->index(i); + } + } + } + manualObject->end(); + attachObject(manualObject); + mObject = manualObject; + defineUserBindings(); + // disable query + mObject->setQueryFlags(0); + } + } diff --git a/PlugIns/RecastNavigation/src/RecastWrapper.cpp b/PlugIns/RecastNavigation/src/RecastWrapper.cpp index e242653..86a3628 100644 --- a/PlugIns/RecastNavigation/src/RecastWrapper.cpp +++ b/PlugIns/RecastNavigation/src/RecastWrapper.cpp @@ -110,6 +110,9 @@ namespace Gsage { float cellSize; int tileSize, maxTiles, maxPolys; + tileSize = 300; + cellSize = 0.3; + config.read("cellSize", cellSize); config.read("tileSize", tileSize); diff --git a/resources/locales/en_US.json b/resources/locales/en_US.json index deb7a44..841de99 100644 --- a/resources/locales/en_US.json +++ b/resources/locales/en_US.json @@ -361,6 +361,7 @@ "merge": "Merge Into Existing Mavmesh" }, "visualize": { + "show_rawgeom": "Show Raw Geometry (source)", "show_navmesh": "Show Navigation Mesh", "show_path": "Show Navigation Path" } diff --git a/resources/scripts/editor/plugins.lua b/resources/scripts/editor/plugins.lua index df4702d..f47ecf1 100644 --- a/resources/scripts/editor/plugins.lua +++ b/resources/scripts/editor/plugins.lua @@ -79,6 +79,7 @@ local function decorate(cls) local renderData = self.render.props renderData.root.children[1].children[1].children = {{ type = "model", + query = "dynamic", mesh = meshName, name = meshID, renderQueue = RENDER_QUEUE_ASSET_VIEWER, diff --git a/resources/scripts/helpers/recast.lua b/resources/scripts/helpers/recast.lua index 63c5422..e72d9bc 100644 --- a/resources/scripts/helpers/recast.lua +++ b/resources/scripts/helpers/recast.lua @@ -13,9 +13,9 @@ function recast.visualizePath(points, drawPoints, name) passes = {{ depthCheckEnabled = false, colors = { - diffuse = "0xFFCC00", - ambient = "0xffcc00", - illumination = "0xFFCC00", + diffuse = "0xFFFFCC00", + ambient = "0xFFffcc00", + illumination = "0xFFFFCC00", }, vertexProgram = "stdquad_vp", fragmentProgram = "stdquad_fp", @@ -63,6 +63,67 @@ function recast.visualizePath(points, drawPoints, name) }) end +function recast.visualizeGeom() + local bounds = BoundingBox.new(BoundingBox.EXTENT_INFINITE) + local geom = core:render():getGeometry(bounds, RenderComponent.STATIC) + + local verts = geom:verts() + local tris = geom:tris() + local norms = geom:normals() + + local points = {} + for i = 1,#verts do + points[i] = verts[i] + end + + local indices = {} + for i = 1,#tris do + indices[i] = tris[i] + end + + local normals = {} + for i = 1,#norms do + normals[i] = norms[i] + end + + return data:createEntity({ + id = "geom", + render = { + root = { + position = Vector3.new(0, 0, 0), + rotation = Quaternion.new(1, 0, 0, 0), + children = { + { + type = "manualObject", + name = "rawgeom", + data = { + material = { + techniques = {{ + passes = {{ + colors = { + diffuse = "0xFF335555", + ambient = "0xFF335555", + illumination = "0xFF114499", + }, + vertexProgram = "stdquad_vp", + fragmentProgram = "stdquad_fp", + },} + },} + }, + renderOperation = ogre.OT_TRIANGLE_LIST, + points = points, + indices = indices, + normals = normals, + } + } + } + }, + vertexProgram = "stdquad_vp", + fragmentProgram = "stdquad_fp", + } + }) +end + function recast.visualizeNavmesh() if core.navigation then local points = core:navigation():getNavMeshRawPoints() @@ -75,9 +136,9 @@ function recast.visualizeNavmesh() techniques = {{ passes = {{ colors = { - diffuse = "0x335555", - ambient = "0x335555", - illumination = "0x114499", + diffuse = "0xFF335555", + ambient = "0xFF335555", + illumination = "0xFF114499", }, vertexProgram = "stdquad_vp", fragmentProgram = "stdquad_fp", @@ -95,9 +156,9 @@ function recast.visualizeNavmesh() techniques = {{ passes = {{ colors = { - diffuse = "0x335555", - ambient = "0x335555", - illumination = "0x1199FF", + diffuse = "0xFF335555", + ambient = "0xFF335555", + illumination = "0xFF1199FF", }, vertexProgram = "stdquad_vp", fragmentProgram = "stdquad_fp", @@ -129,9 +190,9 @@ function recast.visualizeNavmesh() techniques = {{ passes = {{ colors = { - diffuse = "0x114444", - ambient = "0x114444", - illumination = "0x113355", + diffuse = "0xFF114444", + ambient = "0xFF114444", + illumination = "0xFF113355", }, vertexProgram = "stdquad_vp", fragmentProgram = "stdquad_fp", diff --git a/resources/scripts/imgui/components/webview.lua b/resources/scripts/imgui/components/webview.lua index 9dbb8b0..9e6baa5 100644 --- a/resources/scripts/imgui/components/webview.lua +++ b/resources/scripts/imgui/components/webview.lua @@ -182,7 +182,7 @@ function WebView:render(width, height) scalingFactor = 1.5 }, - usage = ogre.HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE + usage = ogre.TU_DYNAMIC_WRITE_ONLY_DISCARDABLE }) self.image:setTexture(self.textureID) diff --git a/resources/scripts/imgui/systems/recast.lua b/resources/scripts/imgui/systems/recast.lua index 0f78e1f..36f9571 100644 --- a/resources/scripts/imgui/systems/recast.lua +++ b/resources/scripts/imgui/systems/recast.lua @@ -67,6 +67,14 @@ local RecastEditorView = class(ImguiWindow, function(self, open, dockable) self.navmeshDraw = nil end end}, + showRawGeom = {"recast.visualize.show_rawgeom", function(enabled) + if enabled then + self.geomDraw = recast.visualizeGeom() + elseif self.geomDraw then + core:removeEntity(self.geomDraw.id) + self.geomDraw = nil + end + end}, showPath = {"recast.visualize.show_path", function(enabled) self:setShowNavPathEnabled(enabled) end}, @@ -161,6 +169,13 @@ function RecastEditorView:__call() end self.navmeshDraw = recast.visualizeNavmesh() end + if self.buildOptions.showRawGeom then + if self.geomDraw then + core:removeEntity(self.geomDraw.id) + self.geomDraw = nil + end + self.geomDraw = recast.visualizeGeom() + end end self:imguiEnd() end