From 22d96efccd5385b1f46e013eafc829e8216e0555 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Thu, 13 Jun 2024 05:53:15 -0700 Subject: [PATCH] feat: fix broken editor planes (#120) * feat: fix broken editor planes Signed-off-by: Michael Pollind * copy in il library for linux and fix build for windows Signed-off-by: Michael Pollind * feat: tweak Signed-off-by: Michael Pollind * feat: fix viewport for window editor Signed-off-by: Michael Pollind * feat: build yml Signed-off-by: Michael Pollind --------- Signed-off-by: Michael Pollind --- .github/workflows/build.yml | 23 +-- HPL2/include/graphics/SubMesh.h | 22 +-- HPL2/include/physics/PhysicsWorld.h | 5 +- HPL2/include/scene/MeshEntity.h | 3 - HPL2/include/scene/SubMeshEntity.h | 149 ++++++++++-------- HPL2/sources/graphics/DebugDraw.cpp | 30 ++-- HPL2/sources/graphics/GeometrySet.cpp | 4 +- HPL2/sources/graphics/SubMesh.cpp | 18 --- HPL2/sources/impl/MeshLoaderMSH.cpp | 2 +- HPL2/sources/scene/MeshEntity.cpp | 7 +- HPL2/sources/scene/SubMeshEntity.cpp | 147 ++++++++++------- amnesia/CMakeLists.txt | 9 +- tools/editors/common/EditorWindowViewport.cpp | 2 +- tools/editors/common/EditorWorld.cpp | 106 +++++-------- tools/editors/common/EditorWorld.h | 2 +- tools/editors/common/EngineEntity.cpp | 4 +- tools/editors/common/EngineEntity.h | 86 +++++----- .../editors/common/EntityWrapperBodyShape.cpp | 2 +- tools/editors/common/EntityWrapperDecal.cpp | 2 +- tools/editors/common/EntityWrapperPrimitive.h | 1 - .../common/EntityWrapperPrimitivePlane.cpp | 95 +++++------ 21 files changed, 362 insertions(+), 357 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fbbd40d11..a4a02030a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,20 +21,17 @@ jobs: sudo apt-get install ninja-build cmake libdevil-dev mesa-common-dev libxmu-dev libxi-dev libgl-dev libx11-dev libxft-dev libxext-dev libwayland-dev libxkbcommon-dev libegl1-mesa-dev libglu1-mesa-dev libgtk-3-dev libvulkan-dev vulkan-tools glslang-tools - name: Configure run: | - mkdir ${{ github.workspace }}/build && cd ${{ github.workspace }}/build + cd ${{ github.workspace }} cmake ${{ github.workspace }} -DVCPKG_INSTALL_OPTIONS="--binarysource=clear\;x-gha,readwrite" -G Ninja - name: Build run: | - cd ${{ github.workspace }}/build + cd ${{ github.workspace }} ninja - - name: Package Amnesia - working-directory: ./build - run: tar -czvf ../amnesia-linux-x86-64-release.tar.gz * - name: Upload Amnesia artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: amnesia-linux-x86-64-release - path: amnesia-linux-x86-64-release.tar.gz + path: build windows: runs-on: windows-latest steps: @@ -53,17 +50,13 @@ jobs: uses: microsoft/setup-msbuild@v1.1 - name: Configure run: | - mkdir ${{ github.workspace }}\build && cd ${{ github.workspace }}\build cmake ${{ github.workspace }} -DVCPKG_INSTALL_OPTIONS="--binarysource=clear\;x-gha,readwrite" -DCMAKE_BUILD_TYPE:STRING=Release -DAMNESIA_GAME_DIRECTORY:STRING='' -G "Visual Studio 17 2022" -A x64 - name: Build run: | - cd ${{ github.workspace }}\build + cd ${{ github.workspace }} msbuild ALL_BUILD.vcxproj /property:Configuration=Release - - name: Package Amnesia - working-directory: .\build - run: 7z a ..\amnesia-win-x86-64-release.zip * - name: Upload Amnesia artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: amnesia-win-x86-64-release - path: amnesia-win-x86-64-release.zip \ No newline at end of file + name: amnesia-win32-x86-64-release + path: build \ No newline at end of file diff --git a/HPL2/include/graphics/SubMesh.h b/HPL2/include/graphics/SubMesh.h index 5c5ec767a..cae516497 100644 --- a/HPL2/include/graphics/SubMesh.h +++ b/HPL2/include/graphics/SubMesh.h @@ -48,6 +48,15 @@ namespace hpl { friend class cSubMeshEntity; public: + struct NotifyMesh { + uint32_t m_semanticSize; + ShaderSemantic m_semantic[12]; + uint32_t changeIndexData: 1; + }; + using NotifySubMeshChanged = hpl::Event; + NotifySubMeshChanged m_notify; + + // preset traits that are expected throughout the engine struct PostionTrait { using Type = float3; @@ -81,14 +90,12 @@ namespace hpl { } StreamBufferInfo(const StreamBufferInfo& other): - m_gpuBuffer(other.m_gpuBuffer), m_buffer(other.m_buffer), m_semantic(other.m_semantic), m_stride(other.m_stride), m_numberElements(other.m_numberElements){ } StreamBufferInfo(StreamBufferInfo&& other): - m_gpuBuffer(std::move(other.m_gpuBuffer)), m_buffer(std::move(other.m_buffer)), m_semantic(other.m_semantic), m_stride(other.m_stride), @@ -96,14 +103,12 @@ namespace hpl { } void operator=(const StreamBufferInfo& other) { - m_gpuBuffer = other.m_gpuBuffer; m_buffer = other.m_buffer; m_semantic = other.m_semantic; m_stride = other.m_stride; m_numberElements = other.m_numberElements; } void operator=(StreamBufferInfo&& other) { - m_gpuBuffer = std::move(other.m_gpuBuffer); m_buffer = std::move(other.m_buffer); m_semantic = other.m_semantic; m_stride = other.m_stride; @@ -124,9 +129,7 @@ namespace hpl { constexpr GraphicsBuffer::BufferStructuredView GetStructuredView(uint32_t byteOffset = 0) { return m_buffer.CreateStructuredView(byteOffset, m_stride); } - SharedBuffer CommitSharedBuffer(); - SharedBuffer m_gpuBuffer; GraphicsBuffer m_buffer; uint32_t m_stride = 0; uint32_t m_numberElements = 0; @@ -203,12 +206,14 @@ namespace hpl { void AddCollider(const MeshCollisionResource& def); std::span GetColliders(); - inline std::span streamBuffers() {return m_vertexStreams; } + inline std::span streamBuffers() { return m_vertexStreams; } inline std::span::iterator getStreamBySemantic(ShaderSemantic semantic) { return std::find_if(streamBuffers().begin(), streamBuffers().end(), [&](auto& stream) { return stream.m_semantic == semantic; }); } + + inline IndexBufferInfo& IndexStream() {return m_indexStream; } void SetIsCollideShape(bool abX) { m_collideShape = abX; @@ -257,9 +262,8 @@ namespace hpl { bool hasMesh(); void SetStreamBuffers(iVertexBuffer* buffer, std::vector&& vertexStreams, IndexBufferInfo&& indexStream); void Compile(); - - void CommitBuffer(ShaderSemantic semantic); private: + cMaterialManager* m_materialManager = nullptr; tString m_name; diff --git a/HPL2/include/physics/PhysicsWorld.h b/HPL2/include/physics/PhysicsWorld.h index 4ee0225a6..4127d153c 100644 --- a/HPL2/include/physics/PhysicsWorld.h +++ b/HPL2/include/physics/PhysicsWorld.h @@ -22,6 +22,7 @@ #include #include "graphics/DebugDraw.h" +#include "graphics/GraphicsBuffer.h" #include "system/SystemTypes.h" #include "math/MathTypes.h" #include "graphics/GraphicsTypes.h" @@ -127,8 +128,10 @@ namespace hpl { virtual iCollideShape* CreateSphereShape(const cVector3f &avRadii, cMatrixf* apOffsetMtx)=0; virtual iCollideShape* CreateCylinderShape(float afRadius, float afHeight, cMatrixf* apOffsetMtx)=0; virtual iCollideShape* CreateCapsuleShape(float afRadius, float afHeight, cMatrixf* apOffsetMtx)=0; - virtual iCollideShape* CreateMeshShape(iVertexBuffer *apVtxBuffer)=0; + //virtual iCollideShape* CreateMeshShape(size_t numberVerticies, + // GraphicsBuffer::BufferIndexView indexView, + // GraphicsBuffer::BufferStructuredView position)=0; /** * The buffer position must be pointing to where the data is saved! */ diff --git a/HPL2/include/scene/MeshEntity.h b/HPL2/include/scene/MeshEntity.h index fba3e00f8..ca62338f2 100644 --- a/HPL2/include/scene/MeshEntity.h +++ b/HPL2/include/scene/MeshEntity.h @@ -72,9 +72,6 @@ namespace hpl { class cMeshEntity : public iEntity3D { - #ifdef __GNUC__ - typedef iRenderable __super; - #endif friend class cSubMeshEntity; friend class cMeshEntityRootNodeUpdate; friend class cMesh; diff --git a/HPL2/include/scene/SubMeshEntity.h b/HPL2/include/scene/SubMeshEntity.h index dcdc446b9..1c87e31a7 100644 --- a/HPL2/include/scene/SubMeshEntity.h +++ b/HPL2/include/scene/SubMeshEntity.h @@ -19,109 +19,126 @@ #pragma once #include -#include #include +#include #include "Common_3/Graphics/Interfaces/IGraphics.h" #include "graphics/ForgeHandles.h" #include "graphics/GraphicsAllocator.h" -#include "math/MathTypes.h" #include "graphics/GraphicsTypes.h" -#include "system/SystemTypes.h" -#include "scene/Entity3D.h" #include "graphics/Renderable.h" +#include "graphics/SubMesh.h" +#include "math/MathTypes.h" #include "math/MeshTypes.h" +#include "scene/Entity3D.h" +#include "system/SystemTypes.h" namespace hpl { - class cMaterialManager; - class cMeshManager; - class cMesh; - class cSubMesh; - class cMeshEntity; - class cAnimationState; - class cNodeState; - class cBone; - class cNode3D; - class iPhysicsBody; - class cMaterial; - class cBoneState; - - class cSubMeshEntity final: public iRenderable - { - HPL_RTTI_IMPL_CLASS(iRenderable, cSubMeshEntity, "{285bbdb4-de5b-4960-bf44-ae543432ff40}") - friend class cMeshEntity; - public: + class cMaterialManager; + class cMeshManager; + class cMesh; + class cSubMesh; + class cMeshEntity; + class cAnimationState; + class cNodeState; + class cBone; + class cNode3D; + class iPhysicsBody; + class cMaterial; + class cBoneState; + + class cSubMeshEntity final : public iRenderable { + HPL_RTTI_IMPL_CLASS(iRenderable, cSubMeshEntity, "{285bbdb4-de5b-4960-bf44-ae543432ff40}") + friend class cMeshEntity; + + public: static constexpr uint32_t MaxVertexBindings = 15; - cSubMeshEntity(const tString &asName,cMeshEntity *apMeshEntity, cSubMesh * apSubMesh,cMaterialManager* apMaterialManager); - ~cSubMeshEntity(); + cSubMeshEntity(const tString& asName, cMeshEntity* apMeshEntity, cSubMesh* apSubMesh, cMaterialManager* apMaterialManager); + ~cSubMeshEntity(); - virtual cMaterial *GetMaterial() override; + virtual cMaterial* GetMaterial() override; - virtual void UpdateGraphicsForFrame(float afFrameTime) override; + virtual void UpdateGraphicsForFrame(float afFrameTime) override; - virtual iVertexBuffer* GetVertexBuffer() override; + virtual iVertexBuffer* GetVertexBuffer() override; virtual DrawPacket ResolveDrawPacket(const ForgeRenderer::Frame& frame) override; - virtual cBoundingVolume* GetBoundingVolume() override; + virtual cBoundingVolume* GetBoundingVolume() override; + + virtual cMatrixf* GetModelMatrix(cFrustum* apFrustum) override; - virtual cMatrixf* GetModelMatrix(cFrustum *apFrustum) override; + virtual int GetMatrixUpdateCount() override; - virtual int GetMatrixUpdateCount() override; + virtual eRenderableType GetRenderType() override { + return eRenderableType_SubMesh; + } - virtual eRenderableType GetRenderType() override { return eRenderableType_SubMesh;} + cSubMesh* GetSubMesh() const { + return m_subMesh; + } - cSubMesh* GetSubMesh() const { return mpSubMesh;} + void SetLocalNode(cNode3D* apNode); + cNode3D* GetLocalNode(); - void SetLocalNode(cNode3D *apNode); - cNode3D* GetLocalNode(); + void* GetUserData() { + return mpUserData; + } + void SetUserData(void* apData) { + mpUserData = apData; + } - void* GetUserData(){ return mpUserData;} - void SetUserData(void *apData){ mpUserData = apData;} + // Entity implementation + virtual tString GetEntityType() override { + return "SubMesh"; + } - //Entity implementation - virtual tString GetEntityType() override { return "SubMesh";} + virtual void UpdateLogic(float afTimeStep) override; - virtual void UpdateLogic(float afTimeStep) override; + void SetUpdateBody(bool abX); + bool GetUpdateBody(); - void SetUpdateBody(bool abX); - bool GetUpdateBody(); + void SetCustomMaterial(cMaterial* apMaterial, bool abDestroyOldCustom = true); + cMaterial* GetCustomMaterial() { + return mpMaterial; + } - void SetCustomMaterial(cMaterial *apMaterial, bool abDestroyOldCustom=true); - cMaterial* GetCustomMaterial(){ return mpMaterial;} + private: + bool isGeometryMismatch(cSubMesh* submesh); + void rebuildGpuVertexStreams(); + void updateVertexStream(cSubMesh::StreamBufferInfo& stream); + void updateIndexStream(cSubMesh::IndexBufferInfo& stream); - private: - virtual void OnTransformUpdated() override; + virtual void OnTransformUpdated() override; std::shared_ptr m_geometry; uint8_t m_activeCopy = 0; uint32_t m_numberIndecies = 0; uint32_t m_numberVertices = 0; - cSubMesh *mpSubMesh= nullptr; - cMeshEntity *mpMeshEntity= nullptr; - - cMaterial *mpMaterial= nullptr; - - cNode3D *mpLocalNode = nullptr; + cSubMesh* m_subMesh = nullptr; + cMeshEntity* mpMeshEntity = nullptr; + cMaterial* mpMaterial = nullptr; + cNode3D* mpLocalNode = nullptr; + cMaterialManager* mpMaterialManager = nullptr; - cMaterialManager* mpMaterialManager= nullptr; + cSubMesh::NotifySubMeshChanged::Handler m_subMeshChangeHandler; - bool mbUpdateBody = false; - bool mbGraphicsUpdated = false; + bool mbUpdateBody = false; + bool mbGraphicsUpdated = false; bool m_isSkinnedMesh = false; - //This is used to see if null should be returned. - // 0 = no check made, test if matrix is identity - // -1 = Matrix was not identity - // 1 = matrix was identiy - char mlStaticNullMatrixCount = 0; - void *mpUserData; - }; + // This is used to see if null should be returned. + // 0 = no check made, test if matrix is identity + // -1 = Matrix was not identity + // 1 = matrix was identiy + char mlStaticNullMatrixCount = 0; + void* mpUserData; + }; - typedef std::vector tSubMeshEntityVec; - typedef std::vector::iterator tSubMeshEntityVecIt; + typedef std::vector tSubMeshEntityVec; + typedef std::vector::iterator tSubMeshEntityVecIt; - typedef std::multimap tSubMeshEntityMap; - typedef tSubMeshEntityMap::iterator tSubMeshEntityMapIt; -}; + typedef std::multimap tSubMeshEntityMap; + typedef tSubMeshEntityMap::iterator tSubMeshEntityMapIt; +}; // namespace hpl diff --git a/HPL2/sources/graphics/DebugDraw.cpp b/HPL2/sources/graphics/DebugDraw.cpp index 4aab33d05..895a6aec8 100644 --- a/HPL2/sources/graphics/DebugDraw.cpp +++ b/HPL2/sources/graphics/DebugDraw.cpp @@ -808,7 +808,7 @@ namespace hpl { endUpdateResource(&indexUpdateDesc); } - if(!m_line2DSegments.empty()) { + if (!m_line2DSegments.empty()) { struct PositionColorVertex { float3 position; float4 color; @@ -816,25 +816,25 @@ namespace hpl { const size_t numVertices = m_line2DSegments.size() * 2; const size_t vbSize = sizeof(PositionColorVertex) * numVertices; const size_t ibSize = sizeof(uint16_t) * numVertices; - const uint32_t stride = sizeof(PositionColorVertex); - GPURingBufferOffset vb = graphicsAllocator->allocTransientVertexBuffer(vbSize); - GPURingBufferOffset ib = graphicsAllocator->allocTransientIndexBuffer(ibSize); + const uint32_t stride = sizeof(PositionColorVertex); + GPURingBufferOffset vb = graphicsAllocator->allocTransientVertexBuffer(vbSize); + GPURingBufferOffset ib = graphicsAllocator->allocTransientIndexBuffer(ibSize); uint32_t indexBufferOffset = 0; uint32_t vertexBufferOffset = 0; - BufferUpdateDesc vertexUpdateDesc = { vb.pBuffer, vb.mOffset, vbSize}; - BufferUpdateDesc indexUpdateDesc = { ib.pBuffer, ib.mOffset, ibSize}; + BufferUpdateDesc vertexUpdateDesc = { vb.pBuffer, vb.mOffset, vbSize }; + BufferUpdateDesc indexUpdateDesc = { ib.pBuffer, ib.mOffset, ibSize }; - beginUpdateResource(&vertexUpdateDesc); - beginUpdateResource(&indexUpdateDesc); - for(auto& segment: m_line2DSegments) { + beginUpdateResource(&vertexUpdateDesc); + beginUpdateResource(&indexUpdateDesc); + for (auto& segment : m_line2DSegments) { reinterpret_cast(indexUpdateDesc.pMappedData)[indexBufferOffset++] = vertexBufferOffset; - reinterpret_cast(vertexUpdateDesc.pMappedData)[vertexBufferOffset++] = PositionColorVertex { + reinterpret_cast(vertexUpdateDesc.pMappedData)[vertexBufferOffset++] = PositionColorVertex{ float3(segment.m_start.getX(), segment.m_start.getY(), 0.0f), float4(segment.m_color.getX(), segment.m_color.getY(), segment.m_color.getZ(), segment.m_color.getW()) }; reinterpret_cast(indexUpdateDesc.pMappedData)[indexBufferOffset++] = vertexBufferOffset; - reinterpret_cast(vertexUpdateDesc.pMappedData)[vertexBufferOffset++] = PositionColorVertex { + reinterpret_cast(vertexUpdateDesc.pMappedData)[vertexBufferOffset++] = PositionColorVertex{ float3(segment.m_end.getX(), segment.m_end.getY(), 0.0f), float4(segment.m_color.getX(), segment.m_color.getY(), segment.m_color.getZ(), segment.m_color.getW()) }; @@ -843,19 +843,19 @@ namespace hpl { endUpdateResource(&indexUpdateDesc); cmdBindPipeline(cmd, m_lineSegmentPipeline2D.m_handle); cmdBindDescriptorSet(cmd, m_frameIndex, m_perColorViewDescriptorSet.m_handle); - cmdBindVertexBuffer(cmd, 1, &vb.pBuffer, &stride, &vb.mOffset); - cmdBindIndexBuffer(cmd, ib.pBuffer, INDEX_TYPE_UINT16, ib.mOffset); + cmdBindVertexBuffer(cmd, 1, &vb.pBuffer, &stride, &vb.mOffset); + cmdBindIndexBuffer(cmd, ib.pBuffer, INDEX_TYPE_UINT16, ib.mOffset); cmdDrawIndexed(cmd, indexBufferOffset, 0, 0); } - if(!m_uvQuads.empty()) { + if (!m_uvQuads.empty()) { struct UVVertex { float3 position; float2 uv; float4 color; }; std::sort(m_uvQuads.begin(), m_uvQuads.end(), [](const UVQuadRequest& a, const UVQuadRequest& b) { - if(a.m_uvImage.m_handle != b.m_uvImage.m_handle) { + if (a.m_uvImage.m_handle != b.m_uvImage.m_handle) { return a.m_uvImage.m_handle < b.m_uvImage.m_handle; } return a.m_depthTest < b.m_depthTest; diff --git a/HPL2/sources/graphics/GeometrySet.cpp b/HPL2/sources/graphics/GeometrySet.cpp index 7c374ecfa..66753eb56 100644 --- a/HPL2/sources/graphics/GeometrySet.cpp +++ b/HPL2/sources/graphics/GeometrySet.cpp @@ -25,8 +25,8 @@ namespace hpl { auto vertexStorageReport = m_vertexStreamAllocator.storageReport(); auto indexStorageReport = m_indexStreamAllocator.storageReport(); - LOGF(LogLevel::eINFO, "vertex storage total free space: %d largest region: %d", vertexStorageReport.totalFreeSpace, vertexStorageReport.largestFreeRegion); - LOGF(LogLevel::eINFO, "index storage total free space: %d largest region: %d", indexStorageReport.totalFreeSpace, indexStorageReport.largestFreeRegion); + //LOGF(LogLevel::eDEBUG, "vertex storage total free space: %d largest region: %d", vertexStorageReport.totalFreeSpace, vertexStorageReport.largestFreeRegion); + //LOGF(LogLevel::eDEBUG, "index storage total free space: %d largest region: %d", indexStorageReport.totalFreeSpace, indexStorageReport.largestFreeRegion); ASSERT(subAllocation->m_indexAllocation.offset != OffsetAllocator::Allocation::NO_SPACE); ASSERT(subAllocation->m_indexAllocation.metadata != OffsetAllocator::Allocation::NO_SPACE); diff --git a/HPL2/sources/graphics/SubMesh.cpp b/HPL2/sources/graphics/SubMesh.cpp index fc52d6ab2..44e138355 100644 --- a/HPL2/sources/graphics/SubMesh.cpp +++ b/HPL2/sources/graphics/SubMesh.cpp @@ -268,24 +268,6 @@ namespace hpl { return NULL; } - // not an ideal solution - SharedBuffer cSubMesh::StreamBufferInfo::CommitSharedBuffer() { - if(!m_gpuBuffer.IsValid()) { - auto rawView = m_buffer.CreateViewRaw(); - m_gpuBuffer.Load([&](Buffer** buffer) { - BufferLoadDesc loadDesc = {}; - loadDesc.ppBuffer = buffer; - loadDesc.mDesc.mDescriptors = DESCRIPTOR_TYPE_VERTEX_BUFFER; - loadDesc.mDesc.mMemoryUsage = RESOURCE_MEMORY_USAGE_GPU_ONLY; - loadDesc.mDesc.mSize = rawView.NumBytes(); - loadDesc.pData = rawView.rawByteSpan().data(); - addResource(&loadDesc, nullptr); - return true; - }); - } - return m_gpuBuffer; - } - iCollideShape* cSubMesh::CreateCollideShape(iPhysicsWorld* apWorld, std::span colliders) { if (colliders.empty()) { return nullptr; diff --git a/HPL2/sources/impl/MeshLoaderMSH.cpp b/HPL2/sources/impl/MeshLoaderMSH.cpp index 8bb0a0412..df1070721 100644 --- a/HPL2/sources/impl/MeshLoaderMSH.cpp +++ b/HPL2/sources/impl/MeshLoaderMSH.cpp @@ -46,7 +46,7 @@ namespace hpl { - bool gbLogMSHLoad = false; + static constexpr bool gbLogMSHLoad = false; cMeshLoaderMSH::cMeshLoaderMSH(iLowLevelGraphics *apLowLevelGraphics) : iMeshLoader(apLowLevelGraphics) { diff --git a/HPL2/sources/scene/MeshEntity.cpp b/HPL2/sources/scene/MeshEntity.cpp index 7814f970c..a4863dbea 100644 --- a/HPL2/sources/scene/MeshEntity.cpp +++ b/HPL2/sources/scene/MeshEntity.cpp @@ -52,11 +52,6 @@ namespace hpl { - ////////////////////////////////////////////////////////////////////////// - // CONSTRUCTORS - ////////////////////////////////////////////////////////////////////////// - - //----------------------------------------------------------------------- cMeshEntity::cMeshEntity(const tString asName,cMesh* apMesh, cMaterialManager* apMaterialManager, cMeshManager* apMeshManager, cAnimationManager *apAnimationManager) : @@ -456,7 +451,7 @@ namespace hpl { while(BoneIt.HasNext()) { cBoneState *pBoneState = static_cast(BoneIt.Next()); - + SetBoneMatrixFromBodyRec(mpBoneStateRoot->GetWorldMatrix(),pBoneState); } diff --git a/HPL2/sources/scene/SubMeshEntity.cpp b/HPL2/sources/scene/SubMeshEntity.cpp index 78e3e3550..f12c7d237 100644 --- a/HPL2/sources/scene/SubMeshEntity.cpp +++ b/HPL2/sources/scene/SubMeshEntity.cpp @@ -53,61 +53,103 @@ #include namespace hpl { - cSubMeshEntity::cSubMeshEntity( - const tString& asName, cMeshEntity* apMeshEntity, cSubMesh* apSubMesh, cMaterialManager* apMaterialManager) - : iRenderable(asName) - , mpMeshEntity(apMeshEntity) - , mpSubMesh(apSubMesh) - , mpMaterialManager(apMaterialManager) { - mbIsOneSided = mpSubMesh->GetIsOneSided(); - mvOneSidedNormal = mpSubMesh->GetOneSidedNormal(); - m_isSkinnedMesh = (mpMeshEntity->GetMesh()->GetSkeleton() != nullptr); + + void cSubMeshEntity::updateVertexStream(cSubMesh::StreamBufferInfo& localStream) { + auto gpuStream = m_geometry->getStreamBySemantic(localStream.m_semantic); + ASSERT(gpuStream != m_geometry->vertexStreams().end()); + const uint32_t reservedVerticies = m_numberVertices * (m_isSkinnedMesh ? 2 : 1); + + BufferUpdateDesc updateDesc = { gpuStream->buffer().m_handle, + gpuStream->stride() * m_geometry->vertexOffset(), + gpuStream->stride() * reservedVerticies }; + beginUpdateResource(&updateDesc); + + GraphicsBuffer gpuBuffer(updateDesc); + auto dest = gpuBuffer.CreateViewRaw(); + auto src = localStream.m_buffer.CreateViewRaw(); + for (size_t i = 0; i < m_numberVertices; i++) { + auto sp = src.rawByteSpan().subspan(i * localStream.m_stride, std::min(gpuStream->stride(), localStream.m_stride)); + dest.WriteRaw(i * gpuStream->stride(), sp); + } + if (m_isSkinnedMesh) { + for (size_t i = 0; i < m_numberVertices; i++) { + auto sp = src.rawByteSpan().subspan(i * localStream.m_stride, std::min(gpuStream->stride(), localStream.m_stride)); + dest.WriteRaw(((i + m_numberVertices) * gpuStream->stride()), sp); + } + } + endUpdateResource(&updateDesc); + } + + void cSubMeshEntity::updateIndexStream(cSubMesh::IndexBufferInfo& stream) { + BufferUpdateDesc updateDesc = { m_geometry->indexBuffer().m_handle, + m_geometry->indexOffset() * GeometrySet::IndexBufferStride, + GeometrySet::IndexBufferStride * m_numberIndecies }; + beginUpdateResource(&updateDesc); + GraphicsBuffer gpuBuffer(updateDesc); + auto dest = gpuBuffer.CreateIndexView(); + auto src = stream.m_buffer.CreateIndexView(); + for (size_t i = 0; i < m_numberIndecies; i++) { + dest.Write(i, src.Get(i)); + } + endUpdateResource(&updateDesc); + } + void cSubMeshEntity::rebuildGpuVertexStreams() { auto* graphicsAllocator = Interface::Get(); ASSERT(graphicsAllocator); - - auto vertexStreams = mpSubMesh->streamBuffers(); - auto& indexStream = mpSubMesh->IndexStream(); auto& opaqueSet = graphicsAllocator->resolveSet(GraphicsAllocator::AllocationSet::OpaqueSet); + auto vertexStreams = m_subMesh->streamBuffers(); + auto& indexStream = m_subMesh->IndexStream(); m_numberVertices = vertexStreams.begin()->m_numberElements; m_numberIndecies = indexStream.m_numberElements; const uint32_t reservedVerticies = m_numberVertices * (m_isSkinnedMesh ? 2 : 1); m_geometry = opaqueSet.allocate(reservedVerticies, m_numberIndecies); for(auto& localStream: vertexStreams) { - auto gpuStream = m_geometry->getStreamBySemantic(localStream.m_semantic); - ASSERT(gpuStream != m_geometry->vertexStreams().end()); - - BufferUpdateDesc updateDesc = { gpuStream->buffer().m_handle, gpuStream->stride() * m_geometry->vertexOffset(), gpuStream->stride() * reservedVerticies}; - beginUpdateResource(&updateDesc); + updateVertexStream(localStream); + } + updateIndexStream(indexStream); + } - GraphicsBuffer gpuBuffer(updateDesc); - auto dest = gpuBuffer.CreateViewRaw(); - auto src = localStream.m_buffer.CreateViewRaw(); - for(size_t i = 0; i < m_numberVertices; i++) { - auto sp = src.rawByteSpan().subspan(i * localStream.m_stride, std::min(gpuStream->stride(), localStream.m_stride)); - dest.WriteRaw(i * gpuStream->stride(), sp); - } - if(m_isSkinnedMesh) { - for(size_t i = 0; i < m_numberVertices; i++) { - auto sp = src.rawByteSpan().subspan(i * localStream.m_stride, std::min(gpuStream->stride(), localStream.m_stride)); - dest.WriteRaw(((i + m_numberVertices) * gpuStream->stride()), sp); - } - } - endUpdateResource(&updateDesc); + bool cSubMeshEntity::isGeometryMismatch(cSubMesh* submesh) { + if (submesh->IndexStream().m_numberElements != m_numberIndecies) { + return true; } - { - BufferUpdateDesc updateDesc = { m_geometry->indexBuffer().m_handle, m_geometry->indexOffset() * GeometrySet::IndexBufferStride, GeometrySet::IndexBufferStride * m_numberIndecies}; - beginUpdateResource(&updateDesc); - GraphicsBuffer gpuBuffer(updateDesc); - auto dest = gpuBuffer.CreateIndexView(); - auto src = indexStream.m_buffer.CreateIndexView(); - for(size_t i = 0; i < m_numberIndecies; i++) { - dest.Write(i, src.Get(i)); + auto vertexStreams = m_subMesh->streamBuffers(); + for(auto& localStream: vertexStreams) { + if(localStream.m_numberElements != m_numberVertices) { + return true; } - endUpdateResource(&updateDesc); } + return false; + } + cSubMeshEntity::cSubMeshEntity( + const tString& asName, cMeshEntity* apMeshEntity, cSubMesh* apSubMesh, cMaterialManager* apMaterialManager) + : iRenderable(asName) + , mpMeshEntity(apMeshEntity) + , m_subMesh(apSubMesh) + , mpMaterialManager(apMaterialManager) { + mbIsOneSided = m_subMesh->GetIsOneSided(); + mvOneSidedNormal = m_subMesh->GetOneSidedNormal(); + m_isSkinnedMesh = (mpMeshEntity->GetMesh()->GetSkeleton() != nullptr); + auto* graphicsAllocator = Interface::Get(); + ASSERT(graphicsAllocator); + auto& opaqueSet = graphicsAllocator->resolveSet(GraphicsAllocator::AllocationSet::OpaqueSet); + m_subMeshChangeHandler = cSubMesh::NotifySubMeshChanged::Handler([&](cSubMesh::NotifyMesh notify) { + if (isGeometryMismatch(m_subMesh)) { + rebuildGpuVertexStreams(); + return; + } + if (notify.changeIndexData) { + updateIndexStream(m_subMesh->IndexStream()); + } + for (size_t i = 0; i < notify.m_semanticSize; i++) { + updateVertexStream(*m_subMesh->getStreamBySemantic(notify.m_semantic[i])); + } + }); + m_subMeshChangeHandler.Connect(m_subMesh->m_notify); + rebuildGpuVertexStreams(); } cSubMeshEntity::~cSubMeshEntity() { @@ -120,14 +162,14 @@ namespace hpl { } cMaterial* cSubMeshEntity::GetMaterial() { - if (mpMaterial == NULL && mpSubMesh->GetMaterial() == NULL) { + if (mpMaterial == NULL && m_subMesh->GetMaterial() == NULL) { // Error("Materials for sub entity %s are NULL!\n",GetName().c_str()); } if (mpMaterial) return mpMaterial; else - return mpSubMesh->GetMaterial(); + return m_subMesh->GetMaterial(); } static inline float3 WeightTransform(const cMatrixf& a_mtxA, float3 src, float weight) { @@ -147,7 +189,6 @@ namespace hpl { void cSubMeshEntity::UpdateGraphicsForFrame(float afFrameTime) { - //////////////////////////////////// // Update things in parent first. mpMeshEntity->UpdateGraphicsForFrame(afFrameTime); @@ -161,13 +202,13 @@ namespace hpl { m_activeCopy = (m_activeCopy + 1) % ForgeRenderer::SwapChainLength; mbGraphicsUpdated = true; - auto staticBindBuffers = mpSubMesh->streamBuffers(); - auto bindPositionIt = mpSubMesh->getStreamBySemantic(ShaderSemantic::SEMANTIC_POSITION); - auto bindNormalIt = mpSubMesh->getStreamBySemantic(ShaderSemantic::SEMANTIC_NORMAL); - auto bindTangentIt = mpSubMesh->getStreamBySemantic(ShaderSemantic::SEMANTIC_TANGENT); - ASSERT(bindPositionIt != mpSubMesh->streamBuffers().end() && - bindNormalIt != mpSubMesh->streamBuffers().end() && - bindTangentIt != mpSubMesh->streamBuffers().end() + auto staticBindBuffers = m_subMesh->streamBuffers(); + auto bindPositionIt = m_subMesh->getStreamBySemantic(ShaderSemantic::SEMANTIC_POSITION); + auto bindNormalIt = m_subMesh->getStreamBySemantic(ShaderSemantic::SEMANTIC_NORMAL); + auto bindTangentIt = m_subMesh->getStreamBySemantic(ShaderSemantic::SEMANTIC_TANGENT); + ASSERT(bindPositionIt != m_subMesh->streamBuffers().end() && + bindNormalIt != m_subMesh->streamBuffers().end() && + bindTangentIt != m_subMesh->streamBuffers().end() ); auto bindPositonView = bindPositionIt->GetStructuredView(); // the static buffer data is the fixed pose auto bindNormalView = bindNormalIt->GetStructuredView(); @@ -198,8 +239,8 @@ namespace hpl { ASSERT(bindPositionIt->m_numberElements == m_numberVertices); for(size_t i = 0; i < m_numberVertices; i++) { - const std::span weights = std::span(&mpSubMesh->m_vertexWeights[(i * 4)], 4); - const std::span boneIdxs = std::span(&mpSubMesh->m_vertexBones[(i * 4)], 4); + const std::span weights = std::span(&m_subMesh->m_vertexWeights[(i * 4)], 4); + const std::span boneIdxs = std::span(&m_subMesh->m_vertexBones[(i * 4)], 4); float3 bindPos = bindPositonView.Get(i); float3 bindNormal = bindNormalView.Get(i); @@ -247,7 +288,7 @@ namespace hpl { } iVertexBuffer* cSubMeshEntity::GetVertexBuffer() { - return mpSubMesh->GetVertexBuffer(); + return m_subMesh->GetVertexBuffer(); } cBoundingVolume* cSubMeshEntity::GetBoundingVolume() diff --git a/amnesia/CMakeLists.txt b/amnesia/CMakeLists.txt index fb3c2e114..3c329a051 100644 --- a/amnesia/CMakeLists.txt +++ b/amnesia/CMakeLists.txt @@ -76,9 +76,7 @@ ELSEIF(LINUX) ENDIF() hpl_set_output_dir(Amnesia "") -add_custom_target(GameRelease DEPENDS Amnesia) -set(AMNESIA_EXECUTABLE_OUTPUT_PATH ${INSTALL_OUTPUT_PATH}/Amnesia) -install(DIRECTORY DESTINATION ${AMNESIA_EXECUTABLE_OUTPUT_PATH}) + if(WIN32) add_custom_command ( TARGET Amnesia POST_BUILD @@ -93,6 +91,11 @@ if(WIN32) COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ ) +ELSEIF(LINUX) + add_custom_command(TARGET Amnesia POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${IL_LIBRARIES} + $) endif() ##add_custom_command( diff --git a/tools/editors/common/EditorWindowViewport.cpp b/tools/editors/common/EditorWindowViewport.cpp index 1424c8267..3a73d6013 100644 --- a/tools/editors/common/EditorWindowViewport.cpp +++ b/tools/editors/common/EditorWindowViewport.cpp @@ -282,7 +282,7 @@ void cEditorWindowViewport::SetEnlarged(bool abX) vPos = mvEnlargedPosition; vSize = mvEnlargedSize; vFBPos = cVector2l(0); - vFBSize = cVector2l(mpEngineViewport->GetSize().x, mpEngineViewport->GetSize().y); + vFBSize = cVector2l(mvEnlargedSize.x, mvEnlargedSize.y); } else { diff --git a/tools/editors/common/EditorWorld.cpp b/tools/editors/common/EditorWorld.cpp index 89b6f7e6f..8ee1e1b98 100644 --- a/tools/editors/common/EditorWorld.cpp +++ b/tools/editors/common/EditorWorld.cpp @@ -641,70 +641,58 @@ void iEditorWorld::AddEntityType(iEntityWrapperType* apType) //---------------------------------------------------------------------------- -iEntityWrapperType* iEditorWorld::GetEntityTypeByName(const tString& asX) -{ - tWString sName = cString::To16Char(asX); - iEntityWrapperType* pType = NULL; - tEntityTypeListIt it = mlstEntityTypes.begin(); - for(;it!=mlstEntityTypes.end();++it) - { - iEntityWrapperType* pType = *it; - if(pType->GetName()==sName) - return pType; - } +iEntityWrapperType* iEditorWorld::GetEntityTypeByName(const tString& asX) { + tWString sName = cString::To16Char(asX); + for (auto& pType : mlstEntityTypes) { + if (pType->GetName() == sName) + return pType; + } - Log("Type %s not created.\n", asX.c_str()); + Log("Type %s not created.\n", asX.c_str()); - return NULL; + return NULL; } //---------------------------------------------------------------------------- -iEntityWrapperType* iEditorWorld::GetEntityTypeByID(int alID) -{ - tEntityTypeListIt it = mlstEntityTypes.begin(); - for(;it!=mlstEntityTypes.end();++it) - { - iEntityWrapperType* pType = *it; - if(pType->GetID()==alID) - return pType; - } - - Error("Type with ID %d not created.\n", alID); +iEntityWrapperType* iEditorWorld::GetEntityTypeByID(int alID) { + for (auto& pType : mlstEntityTypes) { + if (pType->GetID() == alID) + return pType; + } - return NULL; + Error("Type with ID %d not created.\n", alID); + return NULL; } //---------------------------------------------------------------------------- -iEntityWrapperType* iEditorWorld::GetEntityTypeByElement(cXmlElement* apElement) -{ - iEntityWrapperType* pDefaultType = NULL; - tEntityTypeListIt it = mlstEntityTypes.begin(); - for(;it!=mlstEntityTypes.end();++it) - { - iEntityWrapperType* pType = *it; - if(pType->IsAppropriateType(apElement)) - return pType; - - if(pDefaultType==NULL && pType->IsAppropriateDefaultType(apElement)) - pDefaultType = pType; - } +iEntityWrapperType* iEditorWorld::GetEntityTypeByElement(cXmlElement* apElement) { + iEntityWrapperType* pDefaultType = NULL; + for (auto& pType : mlstEntityTypes) { + if (pType->IsAppropriateType(apElement)) + return pType; - SetShowLoadErrorPopUp(); - Error("No appropriate type found for %s \"%s\" with ID %d\n", apElement->GetValue().c_str(), apElement->GetAttributeString("Name").c_str(), - apElement->GetAttributeInt("ID")); - if(pDefaultType) - { - Log("Trying default...%s\n", pDefaultType->ToString().c_str()); - return pDefaultType; - } - else - Log("No default type found\n"); + if (pDefaultType == NULL && pType->IsAppropriateDefaultType(apElement)) + pDefaultType = pType; + } + SetShowLoadErrorPopUp(); + LOGF( + LogLevel::eERROR, + "No appropriate type found for %s \"%s\" with ID %d\n", + apElement->GetValue().c_str(), + apElement->GetAttributeString("Name").c_str(), + apElement->GetAttributeInt("ID")); + if (pDefaultType) { + LOGF(LogLevel::eINFO, "Trying default...%s\n", pDefaultType->ToString().c_str()); + return pDefaultType; + } else { + LOGF(LogLevel::eINFO, "No default type found\n"); + } - return NULL; + return NULL; } //---------------------------------------------------------------------------- @@ -716,20 +704,10 @@ int iEditorWorld::GetEntityTypeNum() //---------------------------------------------------------------------------- -iEntityWrapperType* iEditorWorld::GetEntityType(int alX) -{ - int i=0; - tEntityTypeListIt it = mlstEntityTypes.begin(); - for(;it!=mlstEntityTypes.end();++it, ++i) - { - if(i==alX) - return *it; - } - - return NULL; +iEntityWrapperType* iEditorWorld::GetEntityType(int alX) { + return mlstEntityTypes[alX]; } -//---------------------------------------------------------------------------- void iEditorWorld::SetTypeVisibility(int alTypeID, bool abX) { @@ -1353,11 +1331,11 @@ iEntityWrapper* iEditorWorld::CreateEntityWrapperFromXMLElement(cXmlElement* apE pEnt = CreateEntityWrapperFromData(pData); } - if(pEnt==NULL) - Log("Failed loading entity of type %s named %s with ID %d\n", apElement->GetValue().c_str(), + if(pEnt==NULL) { + LOGF(LogLevel::eDEBUG, "Failed loading entity of type %s named %s with ID %d\n", apElement->GetValue().c_str(), apElement->GetAttributeString("Name").c_str(), apElement->GetAttributeInt("ID")); - + } return pEnt; } diff --git a/tools/editors/common/EditorWorld.h b/tools/editors/common/EditorWorld.h index d25dfbd58..d2675a795 100644 --- a/tools/editors/common/EditorWorld.h +++ b/tools/editors/common/EditorWorld.h @@ -263,7 +263,7 @@ class iEditorWorld std::vector mvEntityCategories; std::vector mvEntityCategoryTypes; - tEntityTypeList mlstEntityTypes; + std::vector mlstEntityTypes; std::map mmapIDRedirectors; diff --git a/tools/editors/common/EngineEntity.cpp b/tools/editors/common/EngineEntity.cpp index b9e1e4096..98c30696e 100644 --- a/tools/editors/common/EngineEntity.cpp +++ b/tools/editors/common/EngineEntity.cpp @@ -419,9 +419,9 @@ bool cEngineEntityGeneratedMesh::ReCreate(cMesh* apMesh) return Create(sName); } -iVertexBuffer* cEngineEntityGeneratedMesh::GetVertexBuffer() +cSubMesh* cEngineEntityGeneratedMesh::GetSubMesh() { - return mpMesh->GetSubMesh(0)->GetVertexBuffer(); + return mpMesh->GetSubMesh(0); } //----------------------------------------------------------------------- diff --git a/tools/editors/common/EngineEntity.h b/tools/editors/common/EngineEntity.h index 602fe96d6..fca086075 100644 --- a/tools/editors/common/EngineEntity.h +++ b/tools/editors/common/EngineEntity.h @@ -89,48 +89,56 @@ class iEngineEntity //----------------------------------------------------------------------- -class iEngineEntityMesh : public iEngineEntity -{ +class iEngineEntityMesh : public iEngineEntity { public: - iEngineEntityMesh(iEntityWrapper* apParent); - ~iEngineEntityMesh(); - - void SetUpMesh(); - cMeshEntity* GetMeshEntity() { return (cMeshEntity*)mpEntity; } - - virtual bool Create(const tString& asName); - - bool CheckRayIntersect(cEditorWindowViewport* apViewport, cVector3f* apPos, tVector3fVec* apTriangle, float* apT=NULL); - - cBoundingVolume* GetPickBV(cEditorWindowViewport* apViewport) { return mpEntity->GetBoundingVolume(); } - - void Update(); - void UpdateVisibility(); - - virtual void Draw(cEditorWindowViewport* apViewport, - DebugDraw* apFunctions, - bool abIsSelected, - bool abIsActive, const cColor& aHighlightCol) override; - virtual void DrawSolid(cEditorWindowViewport* apViewport, - DebugDraw* apFunctions, - const cColor& aCol) override; - - // Own funcs - void SetCastShadows(bool abX); - void SetCoverage(float afX); - bool SetMaterial(const tString&); - bool SetCustomMaterial(const tString&, bool abDelete=true); - bool SetCustomMaterial(cMaterial*, bool abDelete=true); - - static void SetDisabledCoverage(float afX) { mfDisabledCoverage = afX; } - static float GetDisabledCoverage() { return mfDisabledCoverage; } + iEngineEntityMesh(iEntityWrapper* apParent); + ~iEngineEntityMesh(); + + void SetUpMesh(); + cMeshEntity* GetMeshEntity() override { + return (cMeshEntity*)mpEntity; + } + + virtual bool Create(const tString& asName) override; + + bool CheckRayIntersect(cEditorWindowViewport* apViewport, cVector3f* apPos, tVector3fVec* apTriangle, float* apT = NULL) override; + + cBoundingVolume* GetPickBV(cEditorWindowViewport* apViewport) override { + return mpEntity->GetBoundingVolume(); + } + + void Update() override; + void UpdateVisibility() override; + + virtual void Draw( + cEditorWindowViewport* apViewport, + DebugDraw* apFunctions, + bool abIsSelected, + bool abIsActive, + const cColor& aHighlightCol) override; + virtual void DrawSolid(cEditorWindowViewport* apViewport, DebugDraw* apFunctions, const cColor& aCol) override; + + // Own funcs + void SetCastShadows(bool abX); + void SetCoverage(float afX); + bool SetMaterial(const tString&); + bool SetCustomMaterial(const tString&, bool abDelete = true); + bool SetCustomMaterial(cMaterial*, bool abDelete = true); + + static void SetDisabledCoverage(float afX) { + mfDisabledCoverage = afX; + } + static float GetDisabledCoverage() { + return mfDisabledCoverage; + } protected: - void SetMesh(cMesh* apMesh) { mpMesh = apMesh; } - - cMesh* mpMesh; + void SetMesh(cMesh* apMesh) { + mpMesh = apMesh; + } - static float mfDisabledCoverage; + cMesh* mpMesh; + static float mfDisabledCoverage; }; //----------------------------------------------------------------------- @@ -179,7 +187,7 @@ class cEngineEntityGeneratedMesh : public iEngineEntityMesh bool ReCreate(cMesh* apMesh); - iVertexBuffer* GetVertexBuffer(); + cSubMesh* GetSubMesh(); }; //----------------------------------------------------------------------- diff --git a/tools/editors/common/EntityWrapperBodyShape.cpp b/tools/editors/common/EntityWrapperBodyShape.cpp index f782d2300..0b38a1dea 100644 --- a/tools/editors/common/EntityWrapperBodyShape.cpp +++ b/tools/editors/common/EntityWrapperBodyShape.cpp @@ -214,7 +214,7 @@ void cEntityWrapperBodyShape::Draw( cEditorWindowViewport* apViewport, DebugDraw options.m_transform = cMath::ToForgeMatrix4(*pMesh->GetMeshEntity()->GetSubMeshEntity(0)->GetModelMatrix(NULL)); cColor col = abIsSelected?cColor(1) : cColor(1,1,1,0.1f); - apFunctions->DebugWireFrameFromVertexBuffer(pMesh->GetVertexBuffer(), cMath::ToForgeVec4(col)); + apFunctions->DebugWireFrameFromVertexBuffer(pMesh->GetSubMesh()->GetVertexBuffer(), cMath::ToForgeVec4(col)); // apFunctions->SetMatrix(pMesh->GetMeshEntity()->GetSubMeshEntity(0)->GetModelMatrix(NULL)); diff --git a/tools/editors/common/EntityWrapperDecal.cpp b/tools/editors/common/EntityWrapperDecal.cpp index ee7c626ac..f9a9cebbc 100644 --- a/tools/editors/common/EntityWrapperDecal.cpp +++ b/tools/editors/common/EntityWrapperDecal.cpp @@ -163,7 +163,7 @@ bool cEntityWrapperDataDecal::SaveSpecific(cXmlElement* apElement) if(pDecalMesh) { - pVB = pDecalMesh->GetVertexBuffer(); + pVB = pDecalMesh->GetSubMesh()->GetVertexBuffer(); lVertexNum = pVB->GetVertexNum(); lIndexNum = pVB->GetIndexNum(); } diff --git a/tools/editors/common/EntityWrapperPrimitive.h b/tools/editors/common/EntityWrapperPrimitive.h index 4e6b3a890..f1abfbcc9 100644 --- a/tools/editors/common/EntityWrapperPrimitive.h +++ b/tools/editors/common/EntityWrapperPrimitive.h @@ -86,7 +86,6 @@ class iEntityWrapperPrimitive : public iEntityWrapper protected: iEngineEntity* CreateSpecificEngineEntity(); virtual cMesh* CreatePrimitiveMesh()=0; - //eEditorPrimitiveType mPType; tString msMaterial; bool mbCastShadows; diff --git a/tools/editors/common/EntityWrapperPrimitivePlane.cpp b/tools/editors/common/EntityWrapperPrimitivePlane.cpp index ade128d39..bf71f2866 100644 --- a/tools/editors/common/EntityWrapperPrimitivePlane.cpp +++ b/tools/editors/common/EntityWrapperPrimitivePlane.cpp @@ -403,16 +403,6 @@ void cEntityWrapperPrimitivePlane::SetEndCorner(const cVector3f& avX) mlNormalAxisIndex = ComputeNormalAxisIndex(); } -//------------------------------------------------------------------------ - -//------------------------------------------------------------------------ - -//////////////////////////////////////////////////////////////////// -// PROTECTED METHODS -//////////////////////////////////////////////////////////////////// - -//------------------------------------------------------------------------ - int cEntityWrapperPrimitivePlane::ComputeNormalAxisIndex() { //Log("\tComputing plane normal axis index...\n"); @@ -426,45 +416,45 @@ int cEntityWrapperPrimitivePlane::ComputeNormalAxisIndex() //------------------------------------------------------------------------ -void cEntityWrapperPrimitivePlane::UpdateUVMapping() -{ - ////////////////////////////////////////////////////////////// - // VERY IMPORTANT TO CLEAR THE CURRENT UVS (for god's sake) - mvUVCorners.clear(); - - iVertexBuffer* pVB = ((cEngineEntityGeneratedMesh*)mpEngineEntity)->GetVertexBuffer(); - - int lNumVertices = pVB->GetVertexNum(); - float* pVertexCoords = pVB->GetFloatArray(eVertexBufferElement_Position); - float* pTexCoords = pVB->GetFloatArray(eVertexBufferElement_Texture0); - - for(int i=0;iUpdateData(eVertexElementFlag_Texture0, false); +void cEntityWrapperPrimitivePlane::UpdateUVMapping() { + // VERY IMPORTANT TO CLEAR THE CURRENT UVS (for god's sake) + mvUVCorners.clear(); + + cSubMesh* pVB = ((cEngineEntityGeneratedMesh*)mpEngineEntity)->GetSubMesh(); + + auto posStream = pVB->getStreamBySemantic(ShaderSemantic::SEMANTIC_POSITION); + auto texStream = pVB->getStreamBySemantic(ShaderSemantic::SEMANTIC_TEXCOORD0); + auto posView = posStream->GetStructuredView(); + auto texView = texStream->GetStructuredView(); + + for (int i = 0; i < posStream->m_numberElements; ++i) { + cVector3 vCoords = cMath::FromForgeVector3(f3Tov3(posView.Get(i))); + if (mbAlignToWorldCoords) { + vCoords = cMath::MatrixMul(mmtxTransform, vCoords); + } else { + vCoords = cMath::MatrixMul(mmtxScale, vCoords); + } + vCoords = cMath::MatrixMul(cMath::MatrixRotateY(mfTextureAngle), vCoords); + + cVector2f res = cVector2f(0, 0); + if (mlNormalAxisIndex == 0) { + res.x = vCoords.v[1] * mvTileAmount.v[1] + mvTileOffset.v[1]; + } else { + res.x = vCoords.v[0] * mvTileAmount.v[0] + mvTileOffset.v[0]; + } + if (mlNormalAxisIndex == 2) { + res.y = vCoords.v[1] * mvTileAmount.v[1] + mvTileOffset.v[1]; + } else { + res.y = vCoords.v[2] * mvTileAmount.v[2] + mvTileOffset.v[2]; + } + + mvUVCorners.push_back(res); + texView.Write(i, float2(res.x, res.y)); + } + pVB->m_notify.Signal(cSubMesh::NotifyMesh{ + .m_semanticSize = 1, + .m_semantic = { ShaderSemantic::SEMANTIC_TEXCOORD0 }, + }); } //------------------------------------------------------------------------ @@ -496,8 +486,7 @@ cMesh* cEntityWrapperPrimitivePlane::CreatePrimitiveMesh() cSubMesh::StreamBufferInfo::InitializeBuffer(&textureInfo, &uv); cSubMesh::StreamBufferInfo::InitializeBuffer(&tangentInfo, &tangent); - MeshUtility::MeshCreateResult result; - MeshUtility::CreatePlane( + MeshUtility::MeshCreateResult result = MeshUtility::CreatePlane( Vector3(0,0,0), cMath::ToForgeVec3(vEndCorner), Vector2(1,0), Vector2(0,0), Vector2(0,1), Vector2(1,1), &index, @@ -527,10 +516,6 @@ cMesh* cEntityWrapperPrimitivePlane::CreatePrimitiveMesh() pSubMesh->SetMaterial(pMat); iVertexBuffer* pVtxBuffer = new LegacyVertexBuffer(eVertexBufferDrawType_Tri, eVertexBufferUsageType_Static, 0, 0); pSubMesh->SetStreamBuffers(pVtxBuffer, std::move(vertexStreams), std::move(indexInfo)); - //cMesh* pMesh = GetEditorWorld()->GetEditor()->GetEngine()->GetGraphics()->GetMeshCreator()->CreatePlane("", 0, vEndCorner, - // cVector2f(1,0), 0, - // cVector2f(0,1), 1, - // msMaterial); return pMesh; }