annotate tests/test_mesh.nim @ 684:3e81b82852b2

did: update progress
author Sam <sam@basx.dev>
date Mon, 15 May 2023 00:36:25 +0700
parents 2ca938595aea
children 027f6ff06585
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
683
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
1 import std/times
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
2
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
3 import semicongine
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
4
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
5 proc main() =
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
6 var scene = loadScene("test1.glb")
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
7 # var scene = loadScene("tutorialk-donat.glb")
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
8
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
9 var engine = initEngine("Test meshes")
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
10 const
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
11 vertexInput = @[attr[Vec3f]("POSITION", memoryPerformanceHint=PreferFastRead)]
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
12 fragOutput = @[attr[Vec4f]("color")]
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
13 uniforms = @[attr[Mat4]("transform")]
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
14 vertexCode = compileGlslShader(
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
15 stage=VK_SHADER_STAGE_VERTEX_BIT,
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
16 inputs=vertexInput,
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
17 uniforms=uniforms,
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
18 main="""gl_Position = vec4(POSITION * 0.2, 1.0) * Uniforms.transform;"""
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
19 )
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
20 fragmentCode = compileGlslShader(
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
21 stage=VK_SHADER_STAGE_FRAGMENT_BIT,
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
22 outputs=fragOutput,
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
23 uniforms=uniforms,
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
24 main="""
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
25 color = vec4(61/255, 43/255, 31/255, 1);
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
26 """
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
27 )
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
28 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode))
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
29 engine.addScene(scene, vertexInput)
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
30 let rotateAxis = newVec3f(1, 1, 1)
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
31 scene.addShaderGlobal("transform", rotate3d(0'f32, rotateAxis))
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
32 var t = cpuTime()
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
33 while engine.updateInputs() == Running and not engine.keyIsDown(Escape):
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
34 scene.setShaderGlobal("transform", rotate3d(float32(cpuTime() - t), rotateAxis))
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
35 engine.renderScene(scene)
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
36 engine.destroy()
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
37
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
38
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
39 when isMainModule:
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
40 main()