Assets/Examples/Scripts/TerrainDeformer.cs
/// <summary>
/// Get a point on the flattening plane and flatten the terrain around it
/// </summary>
Get a point on the flattening plane and flatten the terrain around it
Get a point on the flattening plane and flatten the terrain around it
private void FlattenTerrain()
        {
            var result = Utils.PlaneLineIntersection(_flatteningOrigin, _flatteningNormal, playerCamera.position, playerCamera.forward, out float3 intersectionPoint);
            if (result != PlaneLineIntersectionResult.OneHit) { return; }
            int intRange = (int)math.ceil(deformRange);
            for (int x = -intRange; x <= intRange; x++)
            {
                for (int y = -intRange; y <= intRange; y++)
                {
                    for (int z = -intRange; z <= intRange; z++)
                    {
                        int3 localPosition = new int3(x, y, z);
                        float3 offsetPoint = intersectionPoint + localPosition;
                        float distance = math.distance(offsetPoint, intersectionPoint);
                        if (distance > deformRange)
                        {
                            continue;
                        }
                        int3 densityWorldPosition = (int3)offsetPoint;
                        float density = (math.dot(_flatteningNormal, densityWorldPosition) - math.dot(_flatteningNormal, _flatteningOrigin)) / deformRange;
                        float oldDensity = world.GetDensity(densityWorldPosition);
                        world.SetDensity((density + oldDensity) * 0.8f, densityWorldPosition);
                    }
                }
            }
        }
private void FlattenTerrain ( ) { var result = Utils . PlaneLineIntersection ( _flatteningOrigin , _flatteningNormal , playerCamera . position , playerCamera . forward , out float3 intersectionPoint ) ; if ( result != PlaneLineIntersectionResult . OneHit ) { return ; } int intRange = ( int ) math . ceil ( deformRange ) ; for ( int x = - intRange ; x <= intRange ; x ++ ) { for ( int y = - intRange ; y <= intRange ; y ++ ) { for ( int z = - intRange ; z <= intRange ; z ++ ) { int3 localPosition = new int3 ( x , y , z ) ; float3 offsetPoint = intersectionPoint + localPosition ; float distance = math . distance ( offsetPoint , intersectionPoint ) ; if ( distance > deformRange ) { continue ; } int3 densityWorldPosition = ( int3 ) offsetPoint ; float density = ( math . dot ( _flatteningNormal , densityWorldPosition ) - math . dot ( _flatteningNormal , _flatteningOrigin ) ) / deformRange ; float oldDensity = world . GetDensity ( densityWorldPosition ) ; world . SetDensity ( ( density + oldDensity ) * 0.8f , densityWorldPosition ) ; } } } }
Get a point on the flattening plane and flatten the terrain around it
Get a point on the flattening plane and flatten the terrain around it