Post

Replies

Boosts

Views

Created

Per-vertex color. in a custom RealityKit mesh? (macOS)
I'm working on an application for viewing AMF models on macOS, using RealityKit. AMF supports several different ways to color models, including per-vertex color (where the color of a triangle is interpolated from vertex to vertex) as well as per-face color (where the color of the triangle is the same across the entire face). I'm trying to figure out how to support those color models using a RealityKit mesh. Apple's documentation (https://developer.apple.com/documentation/realitykit/modifying-realitykit-rendering-using-custom-materials) talks about per-vertex colors, but I haven't found a way to create a mesh that includes per-vertex colors, other than use a texture map (which might be the correct solution). Can someone give me some pointers?
6
2
2k
Jun ’23
[SwiftUI] How to properly support selections within an outline view using DisclosureGroup?
I'm using DisclosureGroups to display a hierarchy in outline form, and added code to make the lines selectable. This works, except that the root entry cannot be selected. The root and branch lines can be expanded as expected, and all lines other than the root line can be selected. I'm developing this as a MacOS application, but running it in the iPhone simulator revealed another odd behavior. When the "Root" line is clicked (anywhere within the line), its disclosure state is toggled. When other lines are clicked, only their disclosure triangles alter their disclosure state. @main struct DisclosureApp: App { @State var selection: UUID? var root = OutlineNode.newOutline() var body: some Scene { WindowGroup { List(selection: $selection) { OutlineView(node: root) } } } } struct OutlineView: View { let node: OutlineNode @State var isExpanded: Bool = true var body: some View { if node.children.isEmpty { Text(node.description) } else { DisclosureGroup( isExpanded: $isExpanded, content: { if isExpanded { ForEach(node.children) { childNode in OutlineView(node: childNode, isExpanded: isExpanded) } } }, label: { Text(node.description) }) } } } struct OutlineNode: Identifiable { let id = UUID() var name: String var children: [OutlineNode] var description: String { let localName = NSLocalizedString(name.capitalized, tableName: "OutlineView", comment: "") return children.isEmpty ? String(format:"📄 %@", localName) : String(format:"📁 %@", localName) } init(_ name: String, _ children: [OutlineNode] = []) { self.name = name self.children = children } static func newOutline() -> OutlineNode { return OutlineNode("root", [OutlineNode("branch1", [OutlineNode ("leaf1"), OutlineNode("leaf2")]), OutlineNode("branch2", [OutlineNode ("leaf3"), OutlineNode("leaf4")])]) } }
0
0
512
Apr ’23
Per-vertex color. in a custom RealityKit mesh? (macOS)
I'm working on an application for viewing AMF models on macOS, using RealityKit. AMF supports several different ways to color models, including per-vertex color (where the color of a triangle is interpolated from vertex to vertex) as well as per-face color (where the color of the triangle is the same across the entire face). I'm trying to figure out how to support those color models using a RealityKit mesh. Apple's documentation (https://developer.apple.com/documentation/realitykit/modifying-realitykit-rendering-using-custom-materials) talks about per-vertex colors, but I haven't found a way to create a mesh that includes per-vertex colors, other than use a texture map (which might be the correct solution). Can someone give me some pointers?
Replies
6
Boosts
2
Views
2k
Activity
Jun ’23
[SwiftUI] How to properly support selections within an outline view using DisclosureGroup?
I'm using DisclosureGroups to display a hierarchy in outline form, and added code to make the lines selectable. This works, except that the root entry cannot be selected. The root and branch lines can be expanded as expected, and all lines other than the root line can be selected. I'm developing this as a MacOS application, but running it in the iPhone simulator revealed another odd behavior. When the "Root" line is clicked (anywhere within the line), its disclosure state is toggled. When other lines are clicked, only their disclosure triangles alter their disclosure state. @main struct DisclosureApp: App { @State var selection: UUID? var root = OutlineNode.newOutline() var body: some Scene { WindowGroup { List(selection: $selection) { OutlineView(node: root) } } } } struct OutlineView: View { let node: OutlineNode @State var isExpanded: Bool = true var body: some View { if node.children.isEmpty { Text(node.description) } else { DisclosureGroup( isExpanded: $isExpanded, content: { if isExpanded { ForEach(node.children) { childNode in OutlineView(node: childNode, isExpanded: isExpanded) } } }, label: { Text(node.description) }) } } } struct OutlineNode: Identifiable { let id = UUID() var name: String var children: [OutlineNode] var description: String { let localName = NSLocalizedString(name.capitalized, tableName: "OutlineView", comment: "") return children.isEmpty ? String(format:"📄 %@", localName) : String(format:"📁 %@", localName) } init(_ name: String, _ children: [OutlineNode] = []) { self.name = name self.children = children } static func newOutline() -> OutlineNode { return OutlineNode("root", [OutlineNode("branch1", [OutlineNode ("leaf1"), OutlineNode("leaf2")]), OutlineNode("branch2", [OutlineNode ("leaf3"), OutlineNode("leaf4")])]) } }
Replies
0
Boosts
0
Views
512
Activity
Apr ’23