try to load model on click
This commit is contained in:
1 parent
5c93de7764
commit
cc29a5fc93
5 files changed
+22
-9
No files matched your search
@@ -34,21 +34,13 @@ final class RenderGLView: NSOpenGLView {
|
||||
RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS,
|
||||
RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS,
|
||||
RENDER_CONFIG)
|
||||
loadModel()
|
||||
//loadModel()
|
||||
startTime = CACurrentMediaTime()
|
||||
ready = true
|
||||
|
||||
renderSet(F.willPrepareGLContext, true)
|
||||
}
|
||||
|
||||
private func loadModel() {
|
||||
guard let resources = Bundle.main.resourceURL else { return }
|
||||
let path = resources.appendingPathComponent("assets/cube.gltf").path
|
||||
if FileManager.default.fileExists(atPath: path) {
|
||||
sr_load_model(path)
|
||||
}
|
||||
}
|
||||
|
||||
override func reshape() {
|
||||
super.reshape()
|
||||
needsDisplay = true
|
||||
|
||||
@@ -11,6 +11,8 @@ let RENDER_CONFIG = sr_config(
|
||||
|
||||
let RENDER_FPS = 60.0
|
||||
|
||||
let RENDER_MODEL_CUBE = "/assets/cube.gltf"
|
||||
|
||||
let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [
|
||||
UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core),
|
||||
UInt32(NSOpenGLPFAColorSize), 24,
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import Foundation
|
||||
import RaylibBridge
|
||||
|
||||
func renderLoadCubeModel() {
|
||||
let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE
|
||||
print("ИГР renderLCB path: '\(path)'")
|
||||
sr_load_model(path)
|
||||
}
|
||||
|
||||
func renderStartTimer(_ vm: RenderVM) {
|
||||
// Schedule repaints every once in FPS seconds
|
||||
|
||||
@@ -8,6 +8,7 @@ RenderContext:
|
||||
type: context
|
||||
fields:
|
||||
backingPixelSize: [Int32]
|
||||
didClickIncrement: Bool
|
||||
didLaunch: Bool
|
||||
didSetup: Bool
|
||||
isReadyToRender: Bool
|
||||
@@ -18,6 +19,7 @@ RenderContext:
|
||||
RenderComponent:
|
||||
type: component
|
||||
oneliners:
|
||||
- didClickIncrement: renderLoadCubeModel()
|
||||
- isReadyToRender: print("ИГР isRTR: '\(c.isReadyToRender)'")
|
||||
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
|
||||
- willPrepareGLContext: renderStartTimer(RenderVM.shared!)
|
||||
@@ -50,6 +52,7 @@ RootComponent:
|
||||
type: component
|
||||
oneliners:
|
||||
- countText: RootVM.shared!.countText = c.countText
|
||||
- didClickIncrement: renderSet(F.didClickIncrement, true)
|
||||
shoulds:
|
||||
count:
|
||||
1. Upon hitting 10 the first time:
|
||||
|
||||
@@ -133,6 +133,7 @@ public struct F {
|
||||
}
|
||||
public struct RenderContext: DialectContext {
|
||||
public var backingPixelSize = [Int32]()
|
||||
public var didClickIncrement = Bool()
|
||||
public var didLaunch = Bool()
|
||||
public var didSetup = Bool()
|
||||
public var isReadyToRender = Bool()
|
||||
@@ -146,6 +147,9 @@ public struct RenderContext: DialectContext {
|
||||
if (name == "backingPixelSize") {
|
||||
return backingPixelSize as! T
|
||||
}
|
||||
else if (name == "didClickIncrement") {
|
||||
return didClickIncrement as! T
|
||||
}
|
||||
else if (name == "didLaunch") {
|
||||
return didLaunch as! T
|
||||
}
|
||||
@@ -175,6 +179,9 @@ public struct RenderContext: DialectContext {
|
||||
if (name == "backingPixelSize") {
|
||||
backingPixelSize = value as! [Int32]
|
||||
}
|
||||
else if (name == "didClickIncrement") {
|
||||
didClickIncrement = value as! Bool
|
||||
}
|
||||
else if (name == "didLaunch") {
|
||||
didLaunch = value as! Bool
|
||||
}
|
||||
@@ -410,6 +417,7 @@ func rootRegisterShoulds(_ ctrl: DialectController) {
|
||||
|
||||
func renderRegisterEffects(_ ctrl: DialectController) {
|
||||
let _: RenderContext? = registerOneliners(ctrl, [
|
||||
F.didClickIncrement, { (c: RenderContext) in renderLoadCubeModel() },
|
||||
F.isReadyToRender, { (c: RenderContext) in print("ИГР isRTR: '\(c.isReadyToRender)'") },
|
||||
F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },
|
||||
F.willPrepareGLContext, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) },
|
||||
@@ -420,6 +428,7 @@ func renderRegisterEffects(_ ctrl: DialectController) {
|
||||
func rootRegisterEffects(_ ctrl: DialectController) {
|
||||
let _: RootContext? = registerOneliners(ctrl, [
|
||||
F.countText, { (c: RootContext) in RootVM.shared!.countText = c.countText },
|
||||
F.didClickIncrement, { (c: RootContext) in renderSet(F.didClickIncrement, true) },
|
||||
|
||||
])
|
||||
}
|
||||
Reference in new issue
Block a user