iOS RealityKit
Pity, but in RealityKit framework you have no possibility to explicitly define model's pivot point's position. Hence, the best solution is to set pivot in 3D authoring app (like Maya or Blender).
However, when prototyping a scene in iOS Reality Composer, Orbit
behavior allows you automatically position model's pivot in the center of another model.
Also, there's a similar implicit-pivot-positioning approach in RealityKit 2.0 when working with move(...)
methods. Use relativeTo
parameter to define pivot's position at the world origin (nil
) or at a center of another model (entity
), to commit a transform animation.
Or you can place a model inside an empty group (Entity) or AnchorEntity, and you'll get 2 independent pivots.
visionOS RealityKit
In visionOS, you can use SwiftUI's .scaleEffect(x:y:z:anchor:)
modifier with anchor
parameter to scale the whole view about chosen axis (pivot point position). The tap gesture works only when Collision and InputTarget components are assigned.
import SwiftUI
import RealityKit
import RealityKitContent
struct ContentView: View {
@State private var scaleCoef: CGFloat = 1.0
var body: some View {
Model3D(named: "Scene", bundle: realityKitContentBundle)
.onTapGesture {
withAnimation(.linear(duration: 1.0)) {
scaleCoef += 1.0
}
}
.scaleEffect(x: scaleCoef,
y: scaleCoef,
z: scaleCoef, anchor: .topFront)
}
}
#Preview {
ContentView()
}