Need to swipe 3D images in an app. This the code, but errors crop up.
//
// ContentView.swift
// Retro3DComics
//
// Created by Bob Schoenburg on 5/24/24.
//
import SwiftUI
import RealityKit
import RealityKitContent
struct ContentView: View {
@State private var error: Error?
@State private var isErrorPresented = false
@State private var rzja = ""
@State private var selectedImage: Int = 0
let jaimages = ["ja1", "ja2", "ja3"]
var body: some View {
TabView(selection: $selectedImage) {
RealityView { content in
do {
for rzja in jaimages {
ForEach(Array(zip(0..., jaimages)), id: \.0) { index, image in
Image(image)
.resizable()
.aspectRatio(contentMode: .fit)
.animation(.smooth(duration: 0.5), value: Image(image))
// .tag(index)
var anaglyphMaterial = try await ShaderGraphMaterial(named: "/AnaglyphMaterial", from: "Scene.usda", in: realityKitContentBundle)
let textureResource = try await TextureResource(contentsOf: Bundle.main.url(forResource: rzja, withExtension: "jpeg")!)
try anaglyphMaterial.setParameter(name: "inputImage", value: .textureResource(textureResource))
let entity = Entity()
let model = ModelComponent(mesh: .generatePlane(width: 0.5, height: 0.3), materials: [anaglyphMaterial])
entity.components.set(model)
content.add(entity)
}
}
// .tabViewStyle(.page)
.gesture(DragGesture(minimumDistance: 3.0, coordinateSpace: .local)
.onEnded { value in
print(value.translation)
switch(value.translation.width, value.translation.height) {
case (...0, -30...30):
withAnimation {
selectedImage += 1
if selectedImage > jaimages.count - 1 {
selectedImage = 0
}
}
case (0..., -30...30):
withAnimation {
selectedImage -= 1
if selectedImage < 0 {
selectedImage = jaimages.count - 1
}
}
case (-100...100, ...0): print("up swipe")
case (-100...100, 0...): print("down swipe")
default: print("default")
}
}
)
}
}
//#Preview(windowStyle: .automatic) {
// ContentView()
//}
}
}
}
Candidate has partially matching parameter list ([(PartialRangeFrom.Element, String)], id: KeyPath<(PartialRangeFrom.Element, String), Int>, content: @escaping ((PartialRangeFrom.Element, String)) -> _)
Post
Replies
Boosts
Views
Activity
How can I show a panorama photo as is done in the Photos app for Vision Pro?
simple question. how can I display an image in a vision pro scene? this does not work:
struct ContentView: View {
var body: some View {
VStack {
Image( "IMG_3984.jpg")
VStack {
Text( "Hello")
}
}
}