Model3D in Data Structure

I'm trying to use Model3D in a similar fashion to how I've used Image in the below data structure for my visionOS app and I keep getting the following error message.

Reference to generic type 'Model3D' requires arguments in <...>

Here is my data structure code.

import Foundation
import SwiftUI
import RealityKit

struct BrandEcommData: Hashable, Codable, Identifiable {
    var id: Int
    var brand: String
    var name: String
    var category: String
    var itemDetail: String
    var price: String
    var itemDescription: String
    var imageName: String
    var ThreeDitem: String
    
    var image: Image {
        Image(imageName)
    }
    var volume: Model3D {
        Model3D(ThreeDitem)
    }
}

Accepted Reply

Hello @meta_merritt,

Model3D is generic on its Content type: Model3D<Content>.

The String-based initializer constrains the Content type to ResolvedModel3D, so something like this will compile:

var volume: Model3D<ResolvedModel3D> {
    Model3D(named: ThreeDitem)
}

Replies

Hello @meta_merritt,

Model3D is generic on its Content type: Model3D<Content>.

The String-based initializer constrains the Content type to ResolvedModel3D, so something like this will compile:

var volume: Model3D<ResolvedModel3D> {
    Model3D(named: ThreeDitem)
}

Thanks! @gchiste

I believe this worked but now I'm having issues seeing the USDZ files load in Xcode simulator. All I'm seeing is the progress view spinner. Have you run into this issue?

  • I have not, I see that you started a new thread about this issue, so I will address it over there :)

Add a Comment

@gchiste All is functioning properly now with exception to one piece. The below code is a view that is intended to tie back to the data array and data structure with the intent that when a user taps on the left/right button the user can load the 3D asset that is associated with the specifics of the window's display. For example, a user is looking at a Burton snowboard, taps on the icon and loads the snowboard in front of them via volume window. Then the user taps to the right and is now viewing a sweater from Nike and taps on the icon to see the Nike sweater. The below code is only showing one 3D asset no matter which brand/product the user navigates to.

import RealityKit
import RealityKitContent

struct AssetLoad: View {
    @State private var currentIndex: Int = 0
    var volumeLoad: [BrandEcommData]
    
    var body: some View {
        Model3D(named: volumeLoad[currentIndex].ThreeDitem, bundle: realityKitContentBundle) { model in model
                .resizable()
                .aspectRatio(contentMode: .fit)
        } placeholder: {
            ProgressView()
        }
    }
}

#Preview {
    AssetLoad(volumeLoad: ecommdata ?? [])
}

Updated data structure for reference.

import SwiftUI
import RealityKit

struct BrandEcommData: Hashable, Codable, Identifiable {
    var id: Int
    var brand: String
    var name: String
    var category: String
    var itemDetail: String
    var price: String
    var itemDescription: String
    var imageName: String
    var ThreeDitem: String
    
    var image: Image {
        Image(imageName)
    }
    var volume: Model3D<ResolvedModel3D> {
        Model3D(named: ThreeDitem)
    }
}

Data array snippet for reference.

    {
        "brand": "Careste",
        "name": "Samantha",
        "category": "Spring 24",
        "itemDetail": "CASHMERE DEEP V NECK SWEATER | OATMEAL",
        "price": "$695",
        "id": 1001,
        "itemDescription": "Samantha's deep v-neck and oversize sleeves are an elevated approach to the basic cashmere pullover. Throw it on over a cami or tailored top for a cozy yet refined look.",
        "imageName": "SAMANTHA 1",
        "ThreeDitem": "Careste"
    },
    {
        "brand": "Careste",
        "name": "Samantha",
        "category": "Spring 24",
        "itemDetail": "CASHMERE DEEP V NECK SWEATER | OATMEAL",
        "price": "$695",
        "id": 1002,
        "itemDescription": "Samantha's deep v-neck and oversize sleeves are an elevated approach to the basic cashmere pullover. Throw it on over a cami or tailored top for a cozy yet refined look.",
        "imageName": "SAMANTHA 2",
        "ThreeDitem": "Careste"
    },
    {
        "brand": "Careste",
        "name": "Samantha",
        "category": "Spring 24",
        "itemDetail": "CASHMERE DEEP V NECK SWEATER | OATMEAL",
        "price": "$695",
        "id": 1003,
        "itemDescription": "Samantha's deep v-neck and oversize sleeves are an elevated approach to the basic cashmere pullover. Throw it on over a cami or tailored top for a cozy yet refined look.",
        "imageName": "SAMANTHA 3",
        "ThreeDitem": "Careste"
    },
    {
        "brand": "Careste",
        "name": "Samantha",
        "category": "Spring 24",
        "itemDetail": "CASHMERE DEEP V NECK SWEATER | OATMEAL",
        "price": "$695",
        "id": 1004,
        "itemDescription": "Samantha's deep v-neck and oversize sleeves are an elevated approach to the basic cashmere pullover. Throw it on over a cami or tailored top for a cozy yet refined look.",
        "imageName": "SAMANTHA 4",
        "ThreeDitem": "Careste"
    },
    {
        "brand": "Careste",
        "name": "Samantha",
        "category": "Spring 24",
        "itemDetail": "CASHMERE DEEP V NECK SWEATER | OATMEAL",
        "price": "$695",
        "id": 1005,
        "itemDescription": "Samantha's deep v-neck and oversize sleeves are an elevated approach to the basic cashmere pullover. Throw it on over a cami or tailored top for a cozy yet refined look.",
        "imageName": "SAMANTHA 5",
        "ThreeDitem": "Careste"
    },
    {
        "brand": "Careste",
        "name": "Callie",
        "category": "Spring 24",
        "itemDetail": "CASHMERE MAXI CARDIGAN | OATMEAL",
        "price": "$1,195",
        "id": 1006,
        "itemDescription": "This floor length Scottish Cashmere cardigan features a V-neckline, long sleeves and large patch pockets. A slightly oversized, yet refined fit.",
        "imageName": "CALLIE 1",
        "ThreeDitem": ""
    },
    {
        "brand": "Careste",
        "name": "Claudia",
        "category": "Spring 24",
        "itemDetail": "SILK RELIEF CASHMERE STRIPE TANK | OATMEAL",
        "price": "$525",
        "id": 1007,
        "itemDescription": "The Claudia cashmere racerback tank is **** and effortless. With subtle, tonal relief stripes and a deep v-neck, this slim silhouette is a standout on its own as well as your go-to baselayer.",
        "imageName": "CLAUDIA 1",
        "ThreeDitem": ""
    },
    {
        "brand": "Careste",
        "name": "Lottie",
        "category": "Spring 24",
        "itemDetail": "SILK VOLUMINOUS SLEEVE WRAP DRESS | CHOCOLATE",
        "price": "$1,195",
        "id": 1008,
        "itemDescription": "The subtle draped and exaggerated bell sleeves of the Lottie in Chocolate are generously cut in 100% Silk Double Georgette.",
        "imageName": "LOTTIE 1",
        "ThreeDitem": ""
    },
    {
        "brand": "Ray Ban",
        "name": "Mega Wayfarer",
        "category": "Optics",
        "itemDetail": "Polished Black",
        "price": "$200",
        "id": 1009,
        "itemDescription": "Own the room with the new Ray-Ban Mega Wayfarer Optics RB0840V eyeglasses. These oversized eyeglasses are designed to make a statement. The black frames make them perfect for those looking for a classic style.",
        "imageName": "Ray Ban 1",
        "ThreeDitem": "StormTrooper"
    },

Thank you :)

  • Figured it out, up-skilling myself with Open AI :)

Add a Comment