I am looking for the property or option to disable the furniture items displayed in the usdz after a room is scanned via RoomCaptureView (replacing furniture items with solid blocks/blobs). I have done this in the past(I think), but I cannot seem to figure it out now to save my life and I am not coming up with a solution via google as well, so here I am. I do not think code is required to get to bottom of this "problem" but will share just in case:
RoomCapture Controller code:
import Foundation
import RoomPlan
class RoomCaptureController: ObservableObject, RoomCaptureViewDelegate, RoomCaptureSessionDelegate {
private let roomBuilder = RoomBuilder(options: [.beautifyObjects])
@Published var roomCaptureView: RoomCaptureView
@Published var finalResult: CapturedRoom?
var sessionConfig: RoomCaptureSession.Configuration
init() {
roomCaptureView = RoomCaptureView(frame: CGRect(x: 0, y: 0, width: 42, height: 42))
sessionConfig = RoomCaptureSession.Configuration()
roomCaptureView.captureSession.delegate = self
roomCaptureView.delegate = self
}
func startSession() {
roomCaptureView.captureSession.run(configuration: sessionConfig)
}
func stopSession() {
roomCaptureView.captureSession.stop()
}
func captureView(shouldPresent roomDataForProcessing: CapturedRoomData, error: Error?) -> Bool {
print("called captureView(shouldPresent")
// Return false because we want to present our own processed view.
return false
}
func captureSession(_ session: RoomCaptureSession, didEndWith data: CapturedRoomData, error: (Error)?) {
print("called captureSession(didEndWith)")
do {
finalResult = try await roomBuilder.capturedRoom(from: data)
saveAndViewCapturedRoom()
} catch {
// Handle the error
print("Error processing captured room: \(error.localizedDescription)")
}
}
func captureView(didPresent processedResult: CapturedRoom, error: Error?) {
if let error = error {
print("Error in captureView: \(error.localizedDescription)")
}
finalResult = processedResult
}
func saveAndViewCapturedRoom() {
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let exportedRoomsDirectory = documentsDirectory.appendingPathComponent(Constants.exportedRoomsDirectory)
let usdzURL = exportedRoomsDirectory
.appendingPathComponent("test.usdz")
let metadataURL = exportedRoomsDirectory
.appendingPathComponent("test.plist")
// Load the catalog 3D models
do {
let modelProvider: CapturedRoom.ModelProvider? = try CapturedRoom.ModelProvider.load()
// Export the captured room with the 3D models
guard let result = finalResult else {
print("finalResult is nil. Cannot export.")
return
}
do {
try result.export(
to: usdzURL,
metadataURL: metadataURL,
modelProvider: modelProvider,
exportOptions: .model)
print("Export successful to \(usdzURL.path)")
} catch {
print("Error during export: \(error.localizedDescription)")
}
} catch {
print("Error saving and viewing usdz scan: \(error.localizedDescription)")
}
}
required init?(coder: NSCoder) {
fatalError("Not needed.")
}
func encode(with coder: NSCoder) {
fatalError("Not needed.")
}
}
Displaying .usdz file in a SceneView after loading it in SCNScene. Code:
Creating SCNScene:
class SomeClass {
var scene: SCNScene?
func loadScene(_ exportedusdzURL: URL) {
scene = State(initialValue: try SCNScene(url: exportedusdzURL, options: []))
}
func getSceneView() -> SceneView {
if let scene = scene {
return SceneView(
scene: scene,
options: [.allowsCameraControl, .autoenablesDefaultLighting]
)
}
}
}
Apologies if there is a complier or like error in the code, I have pieced it together from various places in order to show only relevent code to the question.
If you want the default cuboids for objects don't use a
CapturedRoom.ModelProvideron export. That is, there's no need for the line:And line:
can be:
If you want to use custom models for objects on export you should watch the Explore enhancements to RoomPlan WWDC 2023 session for how to configure your
ModelProviderto vend custom models on export.