Skip to content

Commit 12f6598

Browse files
committed
Expose new experimental modelElevationReference property
1 parent 0e6ebac commit 12f6598

File tree

11 files changed

+103
-4
lines changed

11 files changed

+103
-4
lines changed

Sources/Examples/SwiftUI Examples/Testing Examples/PuckPlayground.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import SwiftUI
2-
import MapboxMaps
2+
@_spi(Experimental) import MapboxMaps
33

44
struct PuckPlayground: View {
55
enum PuckType: String, CaseIterable, CustomStringConvertible {
@@ -45,6 +45,7 @@ struct PuckPlayground: View {
4545
.modelScale(x: scale, y: scale, z: scale)
4646
.modelOpacity(opacity)
4747
.modelEmissiveStrength(puck3dSettings.emission)
48+
.modelElevationReference(puck3dSettings.elevationReference)
4849
.slot(slot)
4950
}
5051
}
@@ -85,6 +86,7 @@ struct PuckPlayground: View {
8586
SliderSettingView(title: "Light emission", value: $puck3dSettings.emission, range: 0...2, step: 0.1)
8687
RadioButtonSettingView(title: "Bearing", value: $bearingType)
8788
SliderSettingView(title: "Opacity", value: $opacity, range: 0...1, step: 0.1)
89+
RadioButtonSettingView(title: "Elevation Reference", value: $puck3dSettings.elevationReference)
8890
slotSettings
8991
case .none:
9092
EmptyView()
@@ -177,6 +179,7 @@ private struct Puck3DSettings {
177179
var scale = 1.0
178180
var modelType = ModelType.sportcar
179181
var emission = 1.0
182+
var elevationReference = ModelElevationReference.ground
180183
}
181184

182185
private struct Puck2DSettings {
@@ -223,6 +226,13 @@ extension PuckBearing: CaseIterable {
223226
public static var allCases: [PuckBearing] = [.course, .heading]
224227
}
225228

229+
extension ModelElevationReference: CaseIterable, CustomStringConvertible {
230+
public static var allCases: [ModelElevationReference] = [.ground, .sea]
231+
public var description: String {
232+
return rawValue
233+
}
234+
}
235+
226236
private extension Model {
227237
static let sportcar = Model(
228238
uri: Bundle.main.url(forResource: "sportcar", withExtension: "glb"),

Sources/MapboxMaps/ContentBuilders/MapContent/Puck3D.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ public struct Puck3D: MapContent, PrimitiveMapContent {
5454
copyAssigned(self, \.configuration.modelScaleMode, .constant(modelScaleMode))
5555
}
5656

57+
/// Selects the base of the model. Some modes might require precomputed elevation data in the tileset.
58+
/// Default value: "ground".
59+
@_documentation(visibility: public)
60+
@_spi(Experimental)
61+
public func modelElevationReference(_ value: ModelElevationReference) -> Puck3D {
62+
copyAssigned(self, \.configuration.modelElevationReference, .constant(value))
63+
}
64+
5765
/// Strength of the emission.
5866
///
5967
/// There is no emission for value 0. For value 1.0, only emissive component (no shading) is displayed and values above 1.0 produce light contribution to surrounding area, for some of the parts (e.g. windows).

Sources/MapboxMaps/Documentation.docc/API Catalogs/Layer Property Values.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- ``FillElevationReference``
4949
- ``LineElevationReference``
5050
- ``LineWidthUnit``
51+
- ``ModelElevationReference``
5152

5253
<!-- Next two are arguable regarding it's category -->
5354
- ``ImageContent``

Sources/MapboxMaps/Location/Puck/Puck3DRenderer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ final class Puck3DRenderer: PuckRenderer {
8888
modelLayer.modelReceiveShadows = newConfiguration.modelReceiveShadows
8989
modelLayer.modelScaleMode = newConfiguration.modelScaleMode
9090
modelLayer.modelEmissiveStrength = newConfiguration.modelEmissiveStrength
91+
modelLayer.modelElevationReference = newConfiguration.modelElevationReference
9192
modelLayer.slot = newConfiguration.slot
9293

9394
do {

Sources/MapboxMaps/Location/Puck/PuckType.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,24 @@ public struct Puck3DConfiguration: Equatable, Sendable {
170170
///
171171
/// - Note: Shadows may impose extra performance costs and lead to extra rendering.
172172
@_documentation(visibility: public)
173-
@_spi(Experimental) public var modelCastShadows: Value<Bool>?
173+
@_spi(Experimental)
174+
public var modelCastShadows: Value<Bool>?
174175

175176
/// Enable/disable shadow receiving for the puck model
176177
@_documentation(visibility: public)
177-
@_spi(Experimental) public var modelReceiveShadows: Value<Bool>?
178+
@_spi(Experimental)
179+
public var modelReceiveShadows: Value<Bool>?
178180

179181
/// Defines scaling mode. Only applies to location-indicator type layers. Default to ``ModelScaleMode/viewport``.
180182
@_documentation(visibility: public)
181-
@_spi(Experimental) public var modelScaleMode: Value<ModelScaleMode>?
183+
@_spi(Experimental)
184+
public var modelScaleMode: Value<ModelScaleMode>?
185+
186+
/// Selects the base of the model. Some modes might require precomputed elevation data in the tileset.
187+
/// Default value: "ground".
188+
@_documentation(visibility: public)
189+
@_spi(Experimental)
190+
public var modelElevationReference: Value<ModelElevationReference>?
182191

183192
/// Strength of the emission.
184193
///

Sources/MapboxMaps/Style/Generated/Layers/ModelLayer.swift

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/MapboxMaps/Style/Generated/Properties/Properties.swift

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/MapboxMapsTests/Location/Puck/Puck3DRendererTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ final class Puck3DRendererTests: XCTestCase {
148148
XCTAssertEqual(actualLayer.modelCastShadows, configuration.modelCastShadows)
149149
XCTAssertEqual(actualLayer.modelReceiveShadows, configuration.modelReceiveShadows)
150150
XCTAssertEqual(actualLayer.modelEmissiveStrength, configuration.modelEmissiveStrength)
151+
XCTAssertEqual(actualLayer.modelElevationReference, configuration.modelElevationReference)
151152
XCTAssertEqual(actualLayer.slot, configuration.slot)
152153
}
153154

Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/ModelLayerIntegrationTests.swift

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/MapboxMapsTests/Style/Generated/Layers/ModelLayerTests.swift

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)