MCPcopy Create free account
hub / github.com/Auburn/FastNoise2 / BuildHeightMap2DMesh

Method BuildHeightMap2DMesh

tools/NodeEditor/MeshNoisePreview.cpp:955–1006  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

953}
954
955MeshNoisePreview::Chunk::MeshData MeshNoisePreview::Chunk::BuildHeightMap2DMesh( const BuildData& buildData, float* densityValues, std::vector<VertexData>& vertexData, std::vector<uint32_t>& indicies )
956{
957 static constexpr uint32_t SIZE_GEN = SIZE + 1;
958 static const GridPositions2D<SIZE_GEN> gridPos;
959
960 FastNoise::OutputMinMax minMax = buildData.generatorScaled->GenPositionArray2D( densityValues,
961 GridPositions2D<SIZE_GEN>::COUNT, gridPos.x.data(), gridPos.y.data(),
962 (float)buildData.pos.x(), (float)buildData.pos.z(), buildData.seed );
963 constexpr int32_t STEP_X = 1;
964 constexpr int32_t STEP_Y = SIZE_GEN;
965
966 int32_t noiseIdx = 0;
967
968 for( uint32_t y = 0; y < SIZE; y++ )
969 {
970 float yf = y + (float)buildData.pos.z();
971
972 for( uint32_t x = 0; x < SIZE; x++ )
973 {
974 float xf = x + (float)buildData.pos.x();
975
976 Vector3 v00( xf, densityValues[noiseIdx] * buildData.heightmapMultiplier, yf );
977 Vector3 v01( xf, densityValues[noiseIdx + STEP_Y] * buildData.heightmapMultiplier, yf + 1 );
978 Vector3 v10( xf + 1, densityValues[noiseIdx + STEP_X] * buildData.heightmapMultiplier, yf );
979 Vector3 v11( xf + 1, densityValues[noiseIdx + STEP_X + STEP_Y] * buildData.heightmapMultiplier, yf + 1 );
980
981 // Normal for quad
982 float light = ( LIGHT_DIR * ( Math::cross( v10 - v11, v00 - v11 ).normalized() + Math::cross( v01 - v00, v11 - v00 ).normalized() ).normalized() ).dot();
983
984 uint32_t vertIdx = (uint32_t)vertexData.size();
985 vertexData.emplace_back( v00, light );
986 vertexData.emplace_back( v01, light );
987 vertexData.emplace_back( v10, light );
988 vertexData.emplace_back( v11, light );
989
990 // Slice quad along longest split
991 uint32_t triRotation = 2 * ( ( v00 + v11 ).dot() < ( v01 + v10 ).dot() );
992 indicies.push_back( vertIdx );
993 indicies.push_back( vertIdx + 3 - triRotation );
994 indicies.push_back( vertIdx + 2 );
995 indicies.push_back( vertIdx + 3 );
996 indicies.push_back( vertIdx + triRotation );
997 indicies.push_back( vertIdx + 1 );
998
999 noiseIdx++;
1000 }
1001
1002 noiseIdx += STEP_X;
1003 }
1004
1005 return MeshData( buildData.pos, minMax, vertexData, indicies );
1006}
1007
1008MeshNoisePreview::Chunk::Chunk( MeshData& meshData )
1009{

Callers

nothing calls this directly

Calls 3

MeshDataClass · 0.85
dataMethod · 0.80
push_backMethod · 0.80

Tested by

no test coverage detected