@@ -709,18 +709,13 @@ SContext::shape_ass_type CMitsubaLoader::loadBasicShape(SContext& ctx, uint32_t
709
709
auto asset = contentRange.begin ()[actualIndex];
710
710
if (!asset)
711
711
return nullptr ;
712
- // make a (shallow) copy because the mesh will get mutilated and abused for metadata NOT ANYMORE?
713
- auto mesh = core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(asset);
714
- auto copy = core::make_smart_refctd_ptr<asset::ICPUMesh>();
715
- copy->getMeshBufferVector () = mesh->getMeshBufferVector ();
716
- IMeshManipulator::recalculateBoundingBox (copy.get ());
717
- return copy;
712
+ return core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(asset);
718
713
}
719
714
else
720
715
return nullptr ;
721
716
};
722
717
723
- core::smart_refctd_ptr<asset::ICPUMesh> mesh;
718
+ core::smart_refctd_ptr<asset::ICPUMesh> mesh,newMesh ;
724
719
bool flipNormals = false ;
725
720
bool faceNormals = false ;
726
721
float maxSmoothAngle = NAN;
@@ -782,7 +777,8 @@ SContext::shape_ass_type CMitsubaLoader::loadBasicShape(SContext& ctx, uint32_t
782
777
maxSmoothAngle = shape->obj .maxSmoothAngle ;
783
778
if (mesh && shape->obj .flipTexCoords )
784
779
{
785
- for (auto meshbuffer : mesh->getMeshBuffers ())
780
+ newMesh = core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(mesh->clone (~0u ));// clone everything (for the texcoords)
781
+ for (auto meshbuffer : newMesh->getMeshBuffers ())
786
782
{
787
783
core::vectorSIMDf uv;
788
784
for (uint32_t i=0u ; meshbuffer->getAttribute (uv, UV_ATTRIB_ID, i); i++)
@@ -797,7 +793,6 @@ SContext::shape_ass_type CMitsubaLoader::loadBasicShape(SContext& ctx, uint32_t
797
793
case CElementShape::Type::PLY:
798
794
_NBL_DEBUG_BREAK_IF (true ); // this code has never been tested
799
795
mesh = loadModel (shape->ply .filename );
800
- mesh = core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(mesh->clone (~0u ));// clone everything
801
796
flipNormals = flipNormals!=shape->ply .flipNormals ;
802
797
faceNormals = shape->ply .faceNormals ;
803
798
maxSmoothAngle = shape->ply .maxSmoothAngle ;
@@ -811,7 +806,8 @@ SContext::shape_ass_type CMitsubaLoader::loadBasicShape(SContext& ctx, uint32_t
811
806
constexpr uint32_t hidefRGBSize = 4u ;
812
807
auto newRGB = core::make_smart_refctd_ptr<asset::ICPUBuffer>(hidefRGBSize*totalVertexCount);
813
808
uint32_t * it = reinterpret_cast <uint32_t *>(newRGB->getPointer ());
814
- for (auto meshbuffer : mesh->getMeshBuffers ())
809
+ newMesh = core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(mesh->clone (~0u ));// clone everything
810
+ for (auto meshbuffer : newMesh->getMeshBuffers ())
815
811
{
816
812
uint32_t offset = reinterpret_cast <uint8_t *>(it)-reinterpret_cast <uint8_t *>(newRGB->getPointer ());
817
813
core::vectorSIMDf rgb;
@@ -855,38 +851,35 @@ SContext::shape_ass_type CMitsubaLoader::loadBasicShape(SContext& ctx, uint32_t
855
851
856
852
// flip normals if necessary
857
853
if (flipNormals)
858
- for (auto meshbuffer : mesh->getMeshBuffers ())
859
- ctx.manipulator ->flipSurfaces (meshbuffer);
860
-
861
- // turned off by default, it's too slow (works though)
862
- // #define OPTIMIZE_MESHES
854
+ {
855
+ if (!newMesh)
856
+ newMesh = core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(mesh->clone (~0u ));// clone everything (for the index buffer)
857
+ for (auto meshbuffer : mesh->getMeshBuffers ())
858
+ ctx.manipulator ->flipSurfaces (meshbuffer);
859
+ }
863
860
864
- auto newMesh = core::make_smart_refctd_ptr<asset::ICPUMesh>();
865
- for (auto meshbuffer : mesh->getMeshBuffers ())
861
+ if (!newMesh)
866
862
{
867
- #ifdef OPTIMIZE_MESHES // TODO
868
- asset::IMeshManipulator::SErrorMetric metrics[asset::ICPUMeshBuffer::MAX_ATTR_BUF_BINDING_COUNT];
869
- metrics[3 ].method = asset::IMeshManipulator::EEM_ANGLES;
870
- auto newMeshBuffer = ctx.manipulator ->createOptimizedMeshBuffer (meshbuffer, metrics);
871
- #else
872
- auto newMeshBuffer = core::smart_refctd_ptr<asset::ICPUMeshBuffer>(meshbuffer);
873
- #endif
874
- if (faceNormals || !std::isnan (maxSmoothAngle))
875
- {
876
- const float smoothAngleCos = cos (core::radians (maxSmoothAngle));
863
+ newMesh = core::make_smart_refctd_ptr<ICPUMesh>();
864
+ newMesh->getMeshBufferVector () = mesh->getMeshBufferVector ();
865
+ }
866
+ if (faceNormals || !std::isnan (maxSmoothAngle))
867
+ for (auto & meshbuffer : mesh->getMeshBufferVector ())
868
+ {
869
+ const float smoothAngleCos = cos (core::radians (maxSmoothAngle));
877
870
878
- ctx. manipulator -> filterInvalidTriangles (meshbuffer);
879
- newMeshBuffer = ctx.manipulator ->createMeshBufferUniquePrimitives (meshbuffer);
880
- ctx.manipulator ->calculateSmoothNormals (newMeshBuffer.get (), false , 0 . f , newMeshBuffer-> getNormalAttributeIx (),
881
- [&]( const asset::IMeshManipulator::SSNGVertexData& a, const asset::IMeshManipulator::SSNGVertexData& b, asset::ICPUMeshBuffer* buffer)
882
- {
883
- if (faceNormals)
884
- return a. indexOffset == b. indexOffset ;
885
- else
886
- return core::dot (a. parentTriangleFaceNormal , b. parentTriangleFaceNormal ). x >= smoothAngleCos;
887
- }) ;
888
- }
889
- newMesh-> getMeshBufferVector (). push_back ( std::move (newMeshBuffer) );
871
+ // TODO: make these mesh manipulator functions const-correct
872
+ auto newMeshBuffer = ctx.manipulator ->createMeshBufferUniquePrimitives (meshbuffer. get () );
873
+ ctx.manipulator ->filterInvalidTriangles (newMeshBuffer.get ());
874
+ ctx. manipulator -> calculateSmoothNormals (newMeshBuffer. get (), false , 0 . f , newMeshBuffer-> getNormalAttributeIx (),
875
+ [&]( const asset::IMeshManipulator::SSNGVertexData& a, const asset::IMeshManipulator::SSNGVertexData& b, asset::ICPUMeshBuffer* buffer)
876
+ {
877
+ if (faceNormals)
878
+ return a. indexOffset == b. indexOffset ;
879
+ else
880
+ return core::dot (a. parentTriangleFaceNormal , b. parentTriangleFaceNormal ). x >= smoothAngleCos ;
881
+ });
882
+ meshbuffer = std::move (newMeshBuffer);
890
883
}
891
884
IMeshManipulator::recalculateBoundingBox (newMesh.get ());
892
885
mesh = std::move (newMesh);
0 commit comments