Skip to content

Commit e12a315

Browse files
committed
Calculate the number of segments for round roofs based on their height
1 parent 15033ac commit e12a315

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

core/src/main/java/org/osm2world/world/modules/building/BuildingPart.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
import static java.util.Arrays.asList;
55
import static java.util.Collections.*;
66
import static org.osm2world.math.shapes.SimplePolygonXZ.asSimplePolygon;
7+
import static org.osm2world.scene.color.ColorNameDefinitions.CSS_COLORS;
78
import static org.osm2world.scene.mesh.LevelOfDetail.LOD3;
89
import static org.osm2world.scene.mesh.LevelOfDetail.LOD4;
910
import static org.osm2world.util.ValueParseUtil.parseColor;
1011
import static org.osm2world.util.ValueParseUtil.parseLevels;
11-
import static org.osm2world.scene.color.ColorNameDefinitions.CSS_COLORS;
1212
import static org.osm2world.world.modules.common.WorldModuleParseUtil.inheritTags;
1313

1414
import java.awt.*;
15-
import java.util.List;
1615
import java.util.*;
16+
import java.util.List;
1717
import java.util.stream.IntStream;
1818

1919
import javax.annotation.Nullable;
@@ -51,7 +51,7 @@
5151
*/
5252
public class BuildingPart implements AreaWorldObject, ProceduralWorldObject {
5353

54-
static final double DEFAULT_RIDGE_HEIGHT = 5;
54+
public static final double DEFAULT_RIDGE_HEIGHT = 5;
5555
static final LevelOfDetail INDOOR_MIN_LOD = LOD3;
5656

5757
final Building building;

core/src/main/java/org/osm2world/world/modules/building/roof/RoundRoof.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
import java.util.ArrayList;
88
import java.util.Collection;
99
import java.util.List;
10+
import java.util.Objects;
1011

1112
import org.osm2world.map_data.data.TagSet;
1213
import org.osm2world.math.VectorXZ;
1314
import org.osm2world.math.shapes.LineSegmentXZ;
1415
import org.osm2world.math.shapes.PolygonWithHolesXZ;
1516
import org.osm2world.math.shapes.SimplePolygonXZ;
1617
import org.osm2world.scene.material.Material;
18+
import org.osm2world.world.modules.building.BuildingPart;
1719

1820
public class RoundRoof extends RoofWithRidge {
1921

20-
private final static double ROOF_SUBDIVISION_METER = 2.5;
22+
private final static double ROOF_SUBDIVISIONS_PER_HEIGHT_METER = 1;
2123

2224
private final List<LineSegmentXZ> capParts;
2325
private final int rings;
@@ -26,9 +28,14 @@ public RoundRoof(PolygonWithHolesXZ originalPolygon, TagSet tags, Material mater
2628

2729
super(0, originalPolygon, tags, material);
2830

29-
rings = (int)max(3, maxDistanceToRidge/ROOF_SUBDIVISION_METER);
31+
/* determine how many segments to use to simulate a round surface */
32+
33+
double height = Objects.requireNonNullElse(super.calculatePreliminaryHeight(), BuildingPart.DEFAULT_RIDGE_HEIGHT);
34+
rings = (int)max(3, height / ROOF_SUBDIVISIONS_PER_HEIGHT_METER);
35+
36+
/* decide where to place the segments */
37+
3038
capParts = new ArrayList<>(rings*2);
31-
// TODO: would be good to vary step size with slope
3239
float step = 0.5f / (rings + 1);
3340
for (int i = 1; i <= rings; i++) {
3441
capParts.add(new LineSegmentXZ(

0 commit comments

Comments
 (0)