Skip to content

Latest commit

 

History

History

Day002

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Display 3D Object

You can display 3D objects from .usdz or .reality files using RealityView or Model3D. Find a list of sample models here.

RealityView

You can use the RealityView view from RealityKit to display 3D objects.

RealityView { content in
          let model = ModelEntity(
                       mesh: .generateSphere(radius: 0.1),
                       materials: [SimpleMaterial(color: .white, isMetallic: true)])
          content.add(model)
}

You can update the mesh property to create all sorts of shapes.

mesh: .generateCone(height: 1, radius: 0.2),

mesh: .generateSphere(radius: 0.1),

mesh: .generateCylinder(height: 1, radius: 0.1),

mesh: .generatePlane(width: 4, depth: 0.1),

image

You can also choose from several material types to change how the 3D shape is displayed:

You can read the official documentation on Adding 3D content to your app for more information.

You can display a 3D model from a URL or from your app's assets. To display one from a URL, link directly to the .usdz file:

private let url = URL(string: "https://developer.apple.com/augmented-reality/quick-look/models/teapot/teapot.usdz")!
       
Model3D(url: url) { model in
   model
       .resizable()
       .aspectRatio(contentMode: .fit)
       .frame(width: 200, height: 200)
       } placeholder: {
   ProgressView()
}

To display on object from your app's assets, first add the file to your app by selecting File > Add Files To... and then selecting your models. You can add these models to a nested Assets folder to stay organized. If you do this, follow the steps here to add these nested assets to your app's Bundle. In your app you can reference the models by name:

Model3D(named: "Globe") { model in
  model
      .resizable()
      .aspectRatio(contentMode: .fit)
      .frame(width: 200, height: 200)
      } placeholder: {
  ProgressView()
}