HomeiOS Developmentios - Can we create again facet texture in RealityKit, ARKit and...

ios – Can we create again facet texture in RealityKit, ARKit and Swift utility in a single go?


I’m utilizing the code beneath to create a flat object utilizing coordinates we generate in TwoPointCircleView class.

It’s OK we see object simply as we needed however once we rotate object like 180 diploma round x axis again facet is invisible.

We tried severals technics we utilized in SpriteKit or unity to see bottom with completely different texture however we noticed the identical texture, black floor or nothing.

How can we do it in RealityKit apart from creating the identical object twice and texturing second one with completely different picture and transferring the thing round as if they’re the identical object.

func createMetalMeshEntity(from dots: [TwoPointCircleView.Dots]) -> ModelEntity {
    
    
    let flatVertices: [Double] = dots.flatMap { [Double($0.x), Double($0.y)] }
    let frontIndices = Earcut.tessellate(knowledge: flatVertices)
    var positions: [SIMD3] = []
    var indices: [UInt32] = []
    
    
    
    // Entrance face (z = 0)
    for dot in dots {
        positions.append(SIMD3(Float(dot.x), Float(dot.y), posZ))
       
    }
    
    
    let dx = maxX - minX
    let dy = maxY - minY
    var uvs: [SIMD2] = []
    let maxDim = max(dx, dy)
    
    
    // Generate entrance face UVs
    for dot in dots {
        let u = (Float(dot.x) - Float(minX)) / Float(maxDim)
        let v = (Float(dot.y) - Float(minY)) / Float(maxDim)
        uvs.append(SIMD2(u, v))
    }
    
    
    // Entrance face
    indices += frontIndices.map { UInt32($0) }
    
    
    // Assortment middle factors of items.
    let middle = centroid(of: positions)
    facilities.append(middle)
    
    // Descriptor
    var descriptor = MeshDescriptor(title: "MetalSemicircle")
    descriptor.positions = MeshBuffers.Positions(positions)
    descriptor.primitives = .triangles(indices)
    
    let tileFactor: Float = 1.0
    
    let scaledUVs = uvs.map { uv in
        SIMD2(uv.x * tileFactor, uv.y * tileFactor)
    }
    
    descriptor.textureCoordinates = MeshBuffers.TextureCoordinates(scaledUVs)
 
    // Create mesh + entity
    let meshResource = strive! MeshResource.generate(from: [descriptor])
    var applidedMaterial = PhysicallyBasedMaterial()
    var solvedMaterial = PhysicallyBasedMaterial()
    
    
    solvedMaterial.baseColor = .init(texture: .init(texture))
    solvedMaterial.metallic = 0.5
    solvedMaterial.roughness = 0.5
    solvedMaterial.faceCulling = .none
    face0Materials.append(solvedMaterial)
    
    
    if faces[0].pieceModel.depend 

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments