| 835 | } |
| 836 | |
| 837 | RenderBufferRef<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 | { |
nothing calls this directly
no test coverage detected