Updated: June 08, 2021.
There are 6 types of materials in RealityKit 2.0 and RealityFoundation at the moment:
So you can use the following code with a SimpleMaterial()
class:
@IBOutlet var arView: ARView!
let sceneObjects = try! Experience.loadAllMyObjects()
var simpleMaterial = SimpleMaterial()
simpleMaterial.baseColor = try! MaterialColorParameter.texture(
TextureResource.load(named: "img.jpg"))
simpleMaterial.metallic = MaterialScalarParameter(floatLiteral: 0.9)
simpleMaterial.roughness = MaterialScalarParameter(floatLiteral: 0.1)
simpleMaterial.tintColor = UIColor.yellow
/*
simpleMaterial.baseColor = MaterialColorParameter.color(UIColor(red: 0.7,
green: 0.5,
blue: 0.2,
alpha: 1.0))
*/
And at the moment there are 5 methods in RealityKit 2.0 to create 3D primitives:
generateBox(...)
generateSphere(...)
generatePlane(...)
generateText(...)
generate(...)
– Create a mesh resource from a list of mesh descriptors
So let's use one of them:
let mesh: MeshResource = .generateBox(size: 2.5)
let component = ModelComponent(mesh: mesh,
materials: [simpleMaterial])
sceneObjects.components.set(component)
arView.scene.anchors.append(sceneObjects)
How to generate SceneKit's shaders in RealityKit
We know that in SceneKit there are 5 different shading models, so we can use RealityKit's SimpleMaterial
, PhysicallyBasedMaterial
and UnlitMaterial
to generate all these five shaders that we've been accustomed to.
Let's see how it looks like:
SCNMaterial.LightingModel.blinn – SimpleMaterial(color: . gray,
roughness: .float(0.5),
isMetallic: false)
SCNMaterial.LightingModel.lambert – SimpleMaterial(color: . gray,
roughness: .float(1.0),
isMetallic: false)
SCNMaterial.LightingModel.phong – SimpleMaterial(color: . gray,
roughness: .float(0.0),
isMetallic: false)
SCNMaterial.LightingModel.physicallyBased – PhysicallyBasedMaterial()
SCNMaterial.LightingModel.constant – UnlitMaterial(color: .gray)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…