Post not yet marked as solved
Hi,
My app has a volumetric window displaying some 3D content for the user. I would like the user to be able to control the color of the material using a color picker displayed below the model in the same window, but unfortunately neither ColorPicker nor Picker are functional in volumetric scenes.
Attempting to use them causes the app to crash with NSInternalInconsistencyException: Presentations are not permitted within volumetric window scenes.
This seems rather limiting. Is there a way either of these components can be utilized? I could build a different "control panel" window but it would not be attached to the model window and it would get confusing if user has multiple 3d windows open.
Thank you
Post not yet marked as solved
Hi,
I'm trying to display an STL model file in visionOS. I import the STL file using SceneKit's ModelIO extension, add it to an empty scene USDA and then export the finished scene into a temporary USDZ file. From there I load the USDZ file as an Entity and add it onto the content.
However, the model in the resulting USDZ file has no lighting and appears as an unlit solid. Please see the screenshot below:
Top one is created from directly importing a USDA scene with the model already added using Reality Composer through in an Entity and works as expected.
Middle one is created from importing the STL model as an MDLAsset using ModelIO, adding onto the empty scene, exporting as USDZ. Then importing USDZ into an Entity. This is what I want to be able to do and is broken.
Bottom one is just for me to debug the USDZ import/export. It was added to the empty scene using Reality Composer and works as expected, therefore the USDZ export/import is not broken as far as I can tell.
Full code:
import SwiftUI
import ARKit
import SceneKit.ModelIO
import RealityKit
import RealityKitContent
struct ContentView: View {
@State private var enlarge = false
@State private var showImmersiveSpace = false
@State private var immersiveSpaceIsShown = false
@Environment(\.openImmersiveSpace) var openImmersiveSpace
@Environment(\.dismissImmersiveSpace) var dismissImmersiveSpace
var modelUrl: URL? = {
if let url = Bundle.main.url(forResource: "Trent 900 STL", withExtension: "stl") {
let asset = MDLAsset(url: url)
asset.loadTextures()
let object = asset.object(at: 0) as! MDLMesh
let emptyScene = SCNScene(named: "EmptyScene.usda")!
let scene = SCNScene(mdlAsset: asset)
// Position node in scene and scale
let node = SCNNode(mdlObject: object)
node.position = SCNVector3(0.0, 0.1, 0.0)
node.scale = SCNVector3(0.02, 0.02, 0.02)
// Copy materials from the test model in the empty scene to our new object (doesn't really change anything)
node.geometry?.materials = emptyScene.rootNode.childNodes[0].childNodes[0].childNodes[0].childNodes[0].geometry!.materials
// Add new node to our empty scene
emptyScene.rootNode.addChildNode(node)
let fileManager = FileManager.default
let appSupportDirectory = try! fileManager.url(for: .applicationSupportDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let permanentUrl = appSupportDirectory.appendingPathComponent("converted.usdz")
if emptyScene.write(to: permanentUrl, delegate: nil) {
// We exported, now load and display
return permanentUrl
}
}
return nil
}()
var body: some View {
VStack {
RealityView { content in
// Add the initial RealityKit content
if let scene = try? await Entity(contentsOf: modelUrl!) {
// Displays middle and bottom models
content.add(scene)
}
if let scene2 = try? await Entity(named: "JetScene", in: realityKitContentBundle) {
// Displays top model using premade scene and exported as USDA.
content.add(scene2)
}
} update: { content in
// Update the RealityKit content when SwiftUI state changes
if let scene = content.entities.first {
let uniformScale: Float = enlarge ? 1.4 : 1.0
scene.transform.scale = [uniformScale, uniformScale, uniformScale]
}
}
.gesture(TapGesture().targetedToAnyEntity().onEnded { _ in
enlarge.toggle()
})
VStack (spacing: 12) {
Toggle("Enlarge RealityView Content", isOn: $enlarge)
.font(.title)
Toggle("Show ImmersiveSpace", isOn: $showImmersiveSpace)
.font(.title)
}
.frame(width: 360)
.padding(36)
.glassBackgroundEffect()
}
.onChange(of: showImmersiveSpace) { _, newValue in
Task {
if newValue {
switch await openImmersiveSpace(id: "ImmersiveSpace") {
case .opened:
immersiveSpaceIsShown = true
case .error, .userCancelled:
fallthrough
@unknown default:
immersiveSpaceIsShown = false
showImmersiveSpace = false
}
} else if immersiveSpaceIsShown {
await dismissImmersiveSpace()
immersiveSpaceIsShown = false
}
}
}
}
}
#Preview(windowStyle: .volumetric) {
ContentView()
}
To test this even further, I exported the generated USDZ and opened in Reality Composer. The added model was still broken while the test model in the scene was fine. This also further proved that import/export is fine and RealityKit is not doing something weird with the imported model.
I am convinced this has to be something with the way I'm using ModelIO to import the STL file.
Any help is appreciated. Thank you
I have a project with a fairly complex storyboard (~13k lines). The project builds fine with Xcode 14, both locally and on Xcode Cloud. However, on Xcode 15 Release (And also the last Beta version) opening the storyboard causes Xcode to crash, while trying to compile the project fails with a crash in ibtool.
I've tried a few solutions to no avail.
I've tried to isolate the build issue and try running ibtool locally to see if I get more output. This is what I get:
/Applications/Xcode.app/Contents/Developer/usr/bin/ibtool --errors --warnings --notices --output-format human-readable-text Main.storyboard
2023-09-20 18:54:17.690 ibtoold[289:56283117] [MT] DVTAssertions: ASSERTION FAILURE in /System/Volumes/Data/SWE/Apps/DT/BuildRoots/BuildRoot11/ActiveBuildRoot/Library/Caches/com.apple.xbs/Sources/IDEInterfaceBuilderCocoaTouch/IDEInterfaceBuilderCocoaTouch-22130/InterfaceBuilder/WidgetIntegration/IBUIAutolayoutGuide/IBUIViewAutolayoutGuideIntegration.m:481
Details: code which should be unreachable has been reached
Object: <IBUIViewAutolayoutGuide: 0x6000068a6d00>
Method: -ibPrimitiveAddConstraintsToCandidateListOnly:thatAreAlreadyInDocument:
Thread: <_NSMainThread: 0x600001e241c0>{number = 1, name = main}
Hints:
Backtrace:
0 -[DVTAssertionHandler handleFailureInMethod:object:fileName:lineNumber:assertionSignature:messageFormat:arguments:] (in DVTFoundation)
1 _DVTAssertionHandler (in DVTFoundation)
2 _DVTAssertionFailureHandler (in DVTFoundation)
3 -[IBUIViewAutolayoutGuide(IBUIViewAutolayoutGuideIntegration) ibPrimitiveRemoveConstraintsFromCandidateListOnly:keepingInDocument:] (in IDEInterfaceBuilderCocoaTouchIntegration)
4 -[NSView(IBViewIntegration) ibMoveCandidateConstraint:toParent:alreadyInDocument:] (in IDEInterfaceBuilderKit)
5 -[NSView(IBViewIntegration) ibVerifyConstraintsAreWellFormedInDocument:subarbitrationUnitCache:andPopulateMessages:] (in IDEInterfaceBuilderKit)
6 -[IBDocumentVerifier _verifyConstraintsAndPopulateMessages:] (in IDEInterfaceBuilderKit)
7 -[IBDocumentVerifier verifyAndPopulateMessages:] (in IDEInterfaceBuilderKit)
8 -[IBCocoaTouchDocumentVerifier verifyAndPopulateMessages:] (in IDEInterfaceBuilderCocoaTouchIntegration)
9 -[IBiOSDocumentVerifier verifyAndPopulateMessages:] (in IDEInterfaceBuilderiOSIntegration)
10 -[IBiOSStoryboardDocumentVerifier verifyAndPopulateMessages:] (in IDEInterfaceBuilderiOSIntegration)
11 __41-[IBDocumentVerifier performVerification]_block_invoke (in IDEInterfaceBuilderKit)
12 -[IBDocumentAutolayoutManager ignoreAutolayoutStatusInvalidationDuring:] (in IDEInterfaceBuilderKit)
13 -[IBDocument ignoreAutolayoutStatusInvalidationDuring:] (in IDEInterfaceBuilderKit)
14 -[IBDocumentVerifier performVerification] (in IDEInterfaceBuilderKit)
15 -[IBDocument performVerification] (in IDEInterfaceBuilderKit)
16 -[IBDocument readFromURL:ofType:error:] (in IDEInterfaceBuilderKit)
17 IBLoadDocument (in ibtoold)
18 -[IBCLIInterfaceBuilderToolPersona invokeArguments:outputDictionary:] (in ibtoold)
19 -[IBCLIInterfaceBuilderToolPersona runSingleInvocation:outputtingToFileHandle:andVerifyingEnvironment:] (in ibtoold)
20 IBCLIServerRunSingleInvocation (in ibtoold)
21 __IBCLIServerRunSingleInvocationWithIODirectedAtPipesAndUnlinkOnSuccess_block_invoke_2 (in ibtoold)
22 __IBCLIServerRunSingleInvocationWithIODirectedAtPipesAndUnlinkOnSuccess_block_invoke (in ibtoold)
23 -[IBCLIErrorForwarder forwardErrorOutputToDescriptor:whileInvokingBlock:] (in ibtoold)
24 IBCLIServerRunSingleInvocationWithIODirectedAtPipesAndUnlinkOnSuccess (in ibtoold)
25 main (in ibtoold)
26 start (in dyld)
Post not yet marked as solved
I have a simple project where I replace the NSLayoutManager for a UITextView initialized in a storyboard using UITextView.textContainer.replaceLayoutManager(…).
On iOS 14.5, the layout manager is correctly replaced and the overridden drawUnderline function is called to correctly render the text using the subclassed NSLayoutManager.
On iOS 15.2, none of the overridden functions in the NSLayoutManager subclass are being called, and no text is rendered in the UITextView.
Custom NSLayoutManager:
CaptionTextLayoutManager.swift
ViewController:
ViewController.swift
Result (iOS 14.5 on the left, iOS 15.2 on the right):
I think this is a regression in iOS 15 and not from my code, however I could be missing something.