@@ -657,7 +657,7 @@ static core::smart_refctd_ptr<ICPUMesh> createMeshFromGeomCreatorReturnType(IGeo
657
657
658
658
SContext::shape_ass_type CMitsubaLoader::loadBasicShape (SContext& ctx, uint32_t hierarchyLevel, CElementShape* shape, const core::matrix3x4SIMD& relTform)
659
659
{
660
- constexpr uint32_t UV_ATTRIB_ID = 2U ;
660
+ constexpr uint32_t UV_ATTRIB_ID = 2u ;
661
661
662
662
auto addInstance = [shape,&ctx,&relTform,this ](SContext::shape_ass_type& mesh)
663
663
{
@@ -777,14 +777,17 @@ SContext::shape_ass_type CMitsubaLoader::loadBasicShape(SContext& ctx, uint32_t
777
777
maxSmoothAngle = shape->obj .maxSmoothAngle ;
778
778
if (mesh && shape->obj .flipTexCoords )
779
779
{
780
- newMesh = core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(mesh->clone (~ 0u ));// clone everything (for the texcoords)
781
- for (auto meshbuffer : newMesh-> getMeshBuffers ())
780
+ newMesh = core::smart_refctd_ptr_static_cast<asset::ICPUMesh> (mesh->clone (1u ));
781
+ for (auto & meshbuffer : mesh-> getMeshBufferVector ())
782
782
{
783
+ auto binding = meshbuffer->getVertexBufferBindings ()[UV_ATTRIB_ID];
784
+ binding.buffer = core::smart_refctd_ptr_static_cast<ICPUBuffer>(binding.buffer ->clone (0u ));
785
+ meshbuffer->setVertexBufferBinding (std::move (binding),UV_ATTRIB_ID);
783
786
core::vectorSIMDf uv;
784
- for (uint32_t i=0u ; meshbuffer->getAttribute (uv, UV_ATTRIB_ID, i); i++)
787
+ for (uint32_t i=0u ; meshbuffer->getAttribute (uv,UV_ATTRIB_ID,i); i++)
785
788
{
786
789
uv.y = -uv.y ;
787
- meshbuffer->setAttribute (uv, UV_ATTRIB_ID, i);
790
+ meshbuffer->setAttribute (uv,UV_ATTRIB_ID,i);
788
791
}
789
792
}
790
793
}
@@ -806,12 +809,11 @@ SContext::shape_ass_type CMitsubaLoader::loadBasicShape(SContext& ctx, uint32_t
806
809
constexpr uint32_t hidefRGBSize = 4u ;
807
810
auto newRGB = core::make_smart_refctd_ptr<asset::ICPUBuffer>(hidefRGBSize*totalVertexCount);
808
811
uint32_t * it = reinterpret_cast <uint32_t *>(newRGB->getPointer ());
809
- newMesh = core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(mesh->clone (~ 0u ));// clone everything
810
- for (auto meshbuffer : newMesh-> getMeshBuffers ())
812
+ newMesh = core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(mesh->clone (1u ));
813
+ for (auto & meshbuffer : mesh-> getMeshBufferVector ())
811
814
{
812
- uint32_t offset = reinterpret_cast <uint8_t *>(it)-reinterpret_cast <uint8_t *>(newRGB->getPointer ());
813
815
core::vectorSIMDf rgb;
814
- for (uint32_t i=0u ; meshbuffer->getAttribute (rgb, 1u , i); i++,it++)
816
+ for (uint32_t i=0u ; meshbuffer->getAttribute (rgb,1u ,i); i++,it++)
815
817
{
816
818
for (auto i=0 ; i<3u ; i++)
817
819
rgb[i] = core::srgb2lin (rgb[i]);
@@ -849,20 +851,21 @@ SContext::shape_ass_type CMitsubaLoader::loadBasicShape(SContext& ctx, uint32_t
849
851
if (!mesh)
850
852
return nullptr ;
851
853
854
+ // mesh including meshbuffers needs to be cloned because instance counts and base instances will be changed
855
+ if (!newMesh)
856
+ newMesh = core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(mesh->clone (1u ));
852
857
// flip normals if necessary
853
858
if (flipNormals)
854
859
{
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
- }
860
-
861
- if (!newMesh)
862
- {
863
- newMesh = core::make_smart_refctd_ptr<ICPUMesh>();
864
- newMesh->getMeshBufferVector () = mesh->getMeshBufferVector ();
860
+ for (auto & meshbuffer : mesh->getMeshBufferVector ())
861
+ {
862
+ auto binding = meshbuffer->getIndexBufferBinding ();
863
+ binding.buffer = core::smart_refctd_ptr_static_cast<ICPUBuffer>(binding.buffer ->clone (0u ));
864
+ meshbuffer->setIndexBufferBinding (std::move (binding));
865
+ ctx.manipulator ->flipSurfaces (meshbuffer.get ());
866
+ }
865
867
}
868
+ // recompute normalis if necessary
866
869
if (faceNormals || !std::isnan (maxSmoothAngle))
867
870
for (auto & meshbuffer : mesh->getMeshBufferVector ())
868
871
{
0 commit comments