MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / loadVertNormalsBuffer_

Method loadVertNormalsBuffer_

source/MRViewer/MRRenderMeshObject.cpp:837–905  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

835}
836
837RenderBufferRef<Vector3f> RenderMeshObject::loadVertNormalsBuffer_()
838{
839 auto& glBuffer = GLStaticHolder::getStaticGLBuffer();
840 if ( !( dirty_ & DIRTY_VERTS_RENDER_NORMAL ) || !objMesh_->mesh() )
841 return glBuffer.prepareBuffer<Vector3f>( vertNormalsSize_, false );
842
843 MR_TIMER;
844 dirty_ &= ~DIRTY_VERTS_RENDER_NORMAL;
845
846 const auto& mesh = objMesh_->mesh();
847 const auto& topology = mesh->topology;
848 auto numF = topology.lastValidFace() + 1;
849 const auto& creases = objMesh_->creases();
850
851 if ( creases.any() )
852 {
853 assert( cornerMode_ );
854
855 auto buffer = glBuffer.prepareBuffer<Vector3f>( vertNormalsSize_ = 3 * numF );
856
857 const auto cornerNormals = computePerCornerNormals( *mesh, &creases );
858 ParallelFor( 0_f, numF, [&] ( FaceId f )
859 {
860 if ( !mesh->topology.hasFace( f ) )
861 return;
862 auto ind = 3 * f;
863 const auto& cornerN = getAt( cornerNormals, f );
864 for ( int i = 0; i < 3; ++i )
865 buffer[ind + i] = cornerN[i];
866 } );
867
868 return buffer;
869 }
870
871 assert( creases.none() );
872 const auto vertNormals = computePerVertNormals( *mesh );
873 if ( cornerMode_ )
874 {
875 auto buffer = glBuffer.prepareBuffer<Vector3f>( vertNormalsSize_ = 3 * numF );
876
877 ParallelFor( 0_f, numF, [&] ( FaceId f )
878 {
879 if ( !mesh->topology.hasFace( f ) )
880 return;
881 auto ind = 3 * f;
882 VertId v[3];
883 topology.getTriVerts( f, v );
884 for ( int i = 0; i < 3; ++i )
885 {
886 const auto& norm = getAt( vertNormals, v[i] );
887 buffer[ind + i] = norm;
888 }
889 } );
890
891 return buffer;
892 }
893 else
894 {

Callers

nothing calls this directly

Calls 12

computePerCornerNormalsFunction · 0.85
ParallelForFunction · 0.85
computePerVertNormalsFunction · 0.85
lastValidFaceMethod · 0.80
hasFaceMethod · 0.80
noneMethod · 0.80
getTriVertsMethod · 0.80
getAtFunction · 0.50
anyMethod · 0.45
lastValidVertMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected