Create border or outline on ModelEntity?
Asked Answered
G

1

1

How can I create a border/outline on a ModelEntity in RealityKit?

Something like this blue border in Reality Composer:

enter image description here

Gravelblind answered 21/12, 2022 at 19:12 Comment(0)
G
2

You can achieve similar effect in two ways: either using Metal framework's features, or natively, in RealityKit (but sometimes with some visual artifacts). In RealityKit, such an outline could be rendered with faceCulling property for cloned model:

import UIKit
import RealityKit

class ViewController: UIViewController {
    
    @IBOutlet var arView: ARView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let scene = try! Experience2.loadScene()
        let scene2 = scene.clone(recursive: true)
        
        let outline = scene2.findEntity(named: "simpBld_root") as! ModelEntity
        outline.scale *= 1.02
        
        var material = PhysicallyBasedMaterial()
        material.emissiveColor.color = .white
        material.emissiveIntensity = 0.5

        // an outer surface doesn't contribute to the final image
        material.faceCulling = .front

        outline.model?.materials[0] = material
        
        arView.scene.anchors.append(scene)
        arView.scene.anchors.append(scene2)
    }
}

enter image description here

P. S.

In your case, the name of a rook is:

.findEntity(named: "chess_rook_white_base_iconic_lod0")
Gillis answered 21/12, 2022 at 22:37 Comment(2)
but issues with the solution are - it's creating a new entity & when I'm trying to move the entity it's separating the outline from the original entity.... any solution?Equilateral
@Shiru99, Post it as a new question, please.Gillis

© 2022 - 2024 — McMap. All rights reserved.