From 5e9f1b743b8dd66760f9d71e1b9f514b812b7075 Mon Sep 17 00:00:00 2001 From: sigurdp Date: Tue, 18 Sep 2018 16:23:58 +0200 Subject: [PATCH] #3345 HoloLens: Account for scaling stored in part's transformation --- .../HoloLensCommands/VdeArrayDataPacket.h | 1 + .../HoloLensCommands/VdeFileExporter.cpp | 30 +++++++++++++++---- .../HoloLensCommands/VdeFileExporter.h | 6 ++-- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ApplicationCode/Commands/HoloLensCommands/VdeArrayDataPacket.h b/ApplicationCode/Commands/HoloLensCommands/VdeArrayDataPacket.h index 7cdfefeb4f..28b4a91e07 100644 --- a/ApplicationCode/Commands/HoloLensCommands/VdeArrayDataPacket.h +++ b/ApplicationCode/Commands/HoloLensCommands/VdeArrayDataPacket.h @@ -18,6 +18,7 @@ #pragma once +#include #include diff --git a/ApplicationCode/Commands/HoloLensCommands/VdeFileExporter.cpp b/ApplicationCode/Commands/HoloLensCommands/VdeFileExporter.cpp index ed5067b80a..7e348e5735 100644 --- a/ApplicationCode/Commands/HoloLensCommands/VdeFileExporter.cpp +++ b/ApplicationCode/Commands/HoloLensCommands/VdeFileExporter.cpp @@ -37,6 +37,7 @@ #include "cvfScene.h" #include "cvfDrawableGeo.h" #include "cvfPrimitiveSet.h" +#include "cvfTransform.h" #include "cvfTrace.h" #include @@ -67,14 +68,14 @@ bool VdeFileExporter::exportViewContents(const RimGridView& view) cvf::Collection allPartsColl; RicHoloLensExportImpl::partsForExport(&view, &allPartsColl); - std::vector meshArr; + std::vector meshArr; for (size_t i = 0; i < allPartsColl.size(); i++) { const cvf::Part* part = allPartsColl.at(i); if (part) { - RicHoloLensMesh mesh; + VdeMesh mesh; if (extractMeshFromPart(view, *part, &mesh)) { meshArr.push_back(mesh); @@ -102,7 +103,7 @@ bool VdeFileExporter::exportViewContents(const RimGridView& view) int nextArrayId = 0; for (size_t i = 0; i < meshArr.size(); i++) { - const RicHoloLensMesh& mesh = meshArr[i]; + const VdeMesh& mesh = meshArr[i]; const size_t primCount = mesh.connArr.size()/3; cvf::Trace::show("%d: primCount=%d meshSourceObjName='%s'", i, primCount, mesh.meshSourceObjName.toLatin1().constData()); @@ -179,7 +180,7 @@ bool VdeFileExporter::exportViewContents(const RimGridView& view) for (size_t i = 0; i < meshArr.size(); i++) { - const RicHoloLensMesh& mesh = meshArr[i]; + const VdeMesh& mesh = meshArr[i]; const MeshIds& meshIds = meshIdsArr[i]; QMap meshMeta; @@ -260,7 +261,7 @@ bool VdeFileExporter::exportViewContents(const RimGridView& view) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool VdeFileExporter::extractMeshFromPart(const RimGridView& view, const cvf::Part& part, RicHoloLensMesh* mesh) +bool VdeFileExporter::extractMeshFromPart(const RimGridView& view, const cvf::Part& part, VdeMesh* mesh) { const cvf::DrawableGeo* geo = dynamic_cast(part.drawable()); if (!geo) @@ -281,7 +282,24 @@ bool VdeFileExporter::extractMeshFromPart(const RimGridView& view, const cvf::Pa } mesh->verticesPerPrimitive = 3; - mesh->vertexArr = vertexArr; + + if (part.transform()) + { + const size_t vertexCount = vertexArr->size(); + cvf::ref transVertexArr = new cvf::Vec3fArray(vertexArr->size()); + + cvf::Mat4f m = cvf::Mat4f(part.transform()->worldTransform()); + for (size_t i = 0; i < vertexCount; i++) + { + transVertexArr->set(i, vertexArr->get(i).getTransformedPoint(m)); + } + + mesh->vertexArr = transVertexArr.p(); + } + else + { + mesh->vertexArr = vertexArr; + } cvf::UIntArray faceConn; const size_t faceCount = primSet->faceCount(); diff --git a/ApplicationCode/Commands/HoloLensCommands/VdeFileExporter.h b/ApplicationCode/Commands/HoloLensCommands/VdeFileExporter.h index efca85fc86..abbf23b0ac 100644 --- a/ApplicationCode/Commands/HoloLensCommands/VdeFileExporter.h +++ b/ApplicationCode/Commands/HoloLensCommands/VdeFileExporter.h @@ -38,7 +38,7 @@ class Part; // // //================================================================================================== -struct RicHoloLensMesh +struct VdeMesh { QString meshSourceObjName; @@ -46,7 +46,7 @@ struct RicHoloLensMesh cvf::cref vertexArr; std::vector connArr; - RicHoloLensMesh() + VdeMesh() : verticesPerPrimitive(-1) {} }; @@ -66,7 +66,7 @@ public: bool exportViewContents(const RimGridView& view); private: - static bool extractMeshFromPart(const RimGridView& view, const cvf::Part& part, RicHoloLensMesh* mesh); + static bool extractMeshFromPart(const RimGridView& view, const cvf::Part& part, VdeMesh* mesh); private: QString m_absOutputFolder;