-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGLTFViewerApp.swift
More file actions
66 lines (57 loc) · 2.3 KB
/
GLTFViewerApp.swift
File metadata and controls
66 lines (57 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2022 Feng Yang
//
// I am making my contributions/submissions to this project solely in my
// personal capacity and am not conveying any rights to any intellectual
// property of any third parties.
import Cocoa
import Math
import vox_render
import vox_toolkit
class GltfViewerApp: NSViewController {
var canvas: Canvas!
var engine: Engine!
var iblBaker: IBLBaker!
override func viewDidLoad() {
super.viewDidLoad()
canvas = Canvas(frame: view.frame)
canvas.setParentView(view)
engine = Engine(canvas: canvas)
iblBaker = IBLBaker()
let scene = Engine.sceneManager.activeScene!
scene.postprocessManager.manualExposure = 1
scene.shadowCascades = .FourCascades
let hdr = Engine.textureLoader.loadHDR(with: "assets/kloppenheim_06_4k.hdr")!
iblBaker.bake(scene, with: hdr, size: 256, level: 3)
let rootEntity = scene.createRootEntity()
let cameraEntity = rootEntity.createChild()
cameraEntity.transform.position = Vector3(3, 2, 3)
cameraEntity.transform.lookAt(targetPosition: Vector3())
let camera = cameraEntity.addComponent(Camera.self)
cameraEntity.addComponent(OrbitControl.self)
let light = rootEntity.createChild("light")
light.transform.position = Vector3(0.1, 5, 0.1)
light.transform.lookAt(targetPosition: Vector3())
let directLight = light.addComponent(DirectLight.self)
directLight.shadowType = .SoftLow
let planeEntity = rootEntity.createChild()
planeEntity.transform.position = Vector3(0, -1, 0)
let shadowPlane = planeEntity.addComponent(MeshRenderer.self)
shadowPlane.mesh = PrimitiveMesh.createPlane(width: 10, height: 10)
let shadowMtl = PBRMaterial()
shadowMtl.baseColor = Color(0.6, 0.6, 0.6, 1.0)
shadowMtl.roughness = 1
shadowMtl.metallic = 0
shadowMtl.setRenderFace(at: 0, .Double)
shadowPlane.setMaterial(shadowMtl)
shadowPlane.castShadows = false
let gltfRoot = rootEntity.createChild()
let gui = gltfRoot.addComponent(LoaderGUI.self)
gui.loaderItem = 8
gui.camera = camera
Engine.run()
}
override func viewDidDisappear() {
super.viewDidDisappear()
Engine.destroy()
}
}