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

0
1
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 wished 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 totally 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 totally different picture and shifting the article 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 heart factors of items.
    let heart = centroid(of: positions)
    facilities.append(heart)
    
    // 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 = attempt! 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 < puzzleNumber {

        var tempMaterial = PhysicallyBasedMaterial()
        tempMaterial.baseColor = .init(tint: .grey)
        tempMaterial.metallic = 0.5
        tempMaterial.roughness = 0.5
        
        applidedMaterial = tempMaterial
        
    } else {
        
        applidedMaterial = solvedMaterial
        
    }
   
    
    let entity = ModelEntity(mesh: meshResource, supplies: [applidedMaterial])
    entity.generateCollisionShapes(recursive: true)
    
    
    return entity
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here