Mercurial > games > semicongine
annotate tests/test_mesh.nim @ 703:120a1baf2f8d
del: possible bad use of variable
author | Sam <sam@basx.dev> |
---|---|
date | Sun, 21 May 2023 01:04:55 +0700 |
parents | abc0d97392cb |
children | f52fccedf5ab |
rev | line source |
---|---|
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
1 import semicongine |
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 proc main() = |
700
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
4 var scenes = [ |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
5 loadScene("default_cube.glb", "1"), |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
6 loadScene("default_cube1.glb", "3"), |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
7 loadScene("default_cube2.glb", "4"), |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
8 loadScene("flat.glb", "5"), |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
9 loadScene("tutorialk-donat.glb", "6"), |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
10 loadScene("personv3.glb", "2"), |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
11 ] |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
12 |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
13 var engine = initEngine("Test meshes") |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
14 const |
700
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
15 vertexInput = @[ |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
16 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
17 attr[uint8]("material", memoryPerformanceHint=PreferFastRead), |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
18 ] |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
19 vertexOutput = @[attr[Vec4f]("vertexColor")] |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
20 fragOutput = @[attr[Vec4f]("color")] |
700
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
21 uniforms = @[attr[Mat4]("transform"), attr[Vec4f]("material_colors", arrayCount=16), ] |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
22 vertexCode = compileGlslShader( |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
23 stage=VK_SHADER_STAGE_VERTEX_BIT, |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
24 inputs=vertexInput, |
700
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
25 outputs=vertexOutput, |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
26 uniforms=uniforms, |
700
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
27 main="""gl_Position = vec4(position, 1.0) * Uniforms.transform; vertexColor = Uniforms.material_colors[material];""" |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
28 ) |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
29 fragmentCode = compileGlslShader( |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
30 stage=VK_SHADER_STAGE_FRAGMENT_BIT, |
700
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
31 inputs=vertexOutput, |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
32 outputs=fragOutput, |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
33 uniforms=uniforms, |
700
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
34 main="""color = vertexColor;""" |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
35 ) |
700
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
36 engine.setRenderer(engine.gpuDevice.simpleForwardRenderPass(vertexCode, fragmentCode, clearColor=newVec4f(0, 0, 0, 1))) |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
37 for scene in scenes.mitems: |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
38 engine.addScene(scene, vertexInput) |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
39 scene.addShaderGlobal("transform", Unit4) |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
40 var |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
41 size = 1'f32 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
42 elevation = -float32(PI) / 3'f32 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
43 azimut = 0'f32 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
44 currentScene = 0 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
45 |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
46 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
700
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
47 if engine.keyWasPressed(`1`): |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
48 currentScene = 0 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
49 elif engine.keyWasPressed(`2`): |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
50 currentScene = 1 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
51 elif engine.keyWasPressed(`3`): |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
52 currentScene = 2 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
53 elif engine.keyWasPressed(`4`): |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
54 currentScene = 3 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
55 elif engine.keyWasPressed(`5`): |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
56 currentScene = 4 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
57 elif engine.keyWasPressed(`6`): |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
58 currentScene = 5 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
59 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
60 if engine.keyWasPressed(NumberRowExtra3): |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
61 size = 1'f32 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
62 elevation = -float32(PI) / 3'f32 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
63 azimut = 0'f32 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
64 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
65 size *= 1'f32 + engine.mouseWheel() * 0.05 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
66 azimut += engine.mouseMove().x / 180'f32 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
67 elevation -= engine.mouseMove().y / 180'f32 |
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
68 scenes[currentScene].setShaderGlobal( |
691 | 69 "transform", |
700
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
70 scale3d(size, size, size) * rotate3d(elevation, newVec3f(1, 0, 0)) * rotate3d(azimut, Yf32) |
691 | 71 ) |
700
abc0d97392cb
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
691
diff
changeset
|
72 engine.renderScene(scenes[currentScene]) |
683
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
73 engine.destroy() |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
74 |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
75 |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
76 when isMainModule: |
2ca938595aea
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
77 main() |