Skip to content

Commit

Permalink
[#169033983][#169109031][#164074964] Fixed several serious issues (#45)
Browse files Browse the repository at this point in the history
- Raw geometry was broken when queried against several objects. Recast
wasn't functional due to that.
- Recast rebuild was taking asset viewer entity into account, which is
now located highly above zero point, thus Recast geometry boundary was
enormous. Rebuild was triggerring generation for a huge area.

Ogre 2.1 plugin now utilises `Ogre::ManualObject`, support for that was added
to debug issues with recast.

Misc Changes
------------

- ImGuiDockspace splitter area was increased.
  • Loading branch information
Unix4ever authored Oct 12, 2019
1 parent 28eec2d commit d149270
Show file tree
Hide file tree
Showing 16 changed files with 407 additions and 75 deletions.
11 changes: 11 additions & 0 deletions Core/src/lua/LuaInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,17 @@ namespace Gsage {
}
return res;
},
"normals", [](Geom* geom){
float* normals;
int count;
std::tie(normals, count) = geom->getNormals();
std::vector<Gsage::Vector3> 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;
Expand Down
16 changes: 12 additions & 4 deletions PlugIns/ImGUI/Common/src/ImGuiDockspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion PlugIns/ImGUI/Common/src/ImguiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion PlugIns/ImGUI/OgreInterfaces/src/ImguiOgreRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions PlugIns/OgrePlugin/include/ogre/MaterialBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand Down
18 changes: 18 additions & 0 deletions PlugIns/OgrePlugin/include/ogre/v2/ManualObjectWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,31 @@ THE SOFTWARE.
#include "ogre/MovableObjectWrapper.h"

namespace Gsage {

class ManualObjectWrapper : public MovableObjectWrapper<Ogre::ManualObject>
{
public:
static const std::string TYPE;

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;
};
}

Expand Down
46 changes: 23 additions & 23 deletions PlugIns/OgrePlugin/src/MeshTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<unsigned char*>(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
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -265,18 +265,18 @@ namespace Ogre {
unsigned short* pShort = reinterpret_cast<unsigned short*>(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<Ogre::uint32>(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<Ogre::uint32>(pShort[k]) +
static_cast<Ogre::uint32>(offset);
Expand All @@ -286,7 +286,7 @@ namespace Ogre {
ibuf->unlock();
}

current_offset = next_offset;
currentOffset = nextOffset;
}
}

Expand Down
65 changes: 32 additions & 33 deletions PlugIns/OgrePlugin/src/OgreGeom.cpp
Original file line number Diff line number Diff line change
@@ -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 <OgreNode.h>
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -103,6 +100,8 @@ namespace Gsage {
normals[vertexOffset+2] = info.normals[j].z;
vertexOffset += 3;
}

offset += info.vertexCount;
}

delete[] meshData;
Expand Down
Loading

0 comments on commit d149270

Please sign in to comment.