Mercurial > games > semicongine
annotate tests/test_mesh.nim @ 371:f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
author | Sam <sam@basx.dev> |
---|---|
date | Wed, 22 Nov 2023 23:24:47 +0700 |
parents | 61c5d5fe9d93 |
children | f4f1474dc70a |
rev | line source |
---|---|
333
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
1 import std/algorithm |
318
e656c0aad093
fix: test not running with temporary new material system
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
2 import std/sequtils |
e656c0aad093
fix: test not running with temporary new material system
Sam <sam@basx.dev>
parents:
316
diff
changeset
|
3 import std/tables |
222
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
4 import semicongine |
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
5 |
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
6 proc main() = |
239
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
7 var scenes = [ |
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
8 Scene(name: "Donut", meshes: loadMeshes("tutorialk-donat.glb", COLORED_SINGLE_TEXTURE_MATERIAL)[0].toSeq), |
239
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
9 ] |
222
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
10 |
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
11 var engine = initEngine("Test meshes") |
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
12 const |
333
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
13 shaderConfiguration = createShaderConfiguration( |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
14 inputs=[ |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
15 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead), |
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
16 attr[uint16]("materialIndex", memoryPerformanceHint=PreferFastRead, perInstance=true), |
333
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
17 attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead), |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
18 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true), |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
19 ], |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
20 intermediates=[ |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
21 attr[Vec4f]("vertexColor"), |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
22 attr[Vec2f]("colorTexCoord"), |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
23 attr[uint16]("materialIndexOut", noInterpolation=true) |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
24 ], |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
25 outputs=[attr[Vec4f]("color")], |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
26 uniforms=[ |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
27 attr[Mat4]("projection"), |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
28 attr[Mat4]("view"), |
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
29 attr[Vec4f]("color", arrayCount=4), |
333
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
30 ], |
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
31 samplers=[attr[Texture]("baseTexture", arrayCount=4)], |
269 | 32 vertexCode=""" |
333
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
33 gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection); |
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
34 vertexColor = Uniforms.color[materialIndex]; |
333
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
35 colorTexCoord = texcoord_0; |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
36 materialIndexOut = materialIndex; |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
37 """, |
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
38 fragmentCode="color = texture(baseTexture[materialIndexOut], colorTexCoord) * vertexColor;" |
222
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
39 ) |
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
40 engine.initRenderer({COLORED_SINGLE_TEXTURE_MATERIAL: shaderConfiguration}) |
333
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
41 |
239
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
42 for scene in scenes.mitems: |
333
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
43 scene.addShaderGlobal("projection", Unit4F32) |
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
44 scene.addShaderGlobal("view", Unit4F32) |
371
f054b8bacab8
fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents:
353
diff
changeset
|
45 engine.loadScene(scene) |
333
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
46 |
239
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
47 var |
247 | 48 size = 1'f32 |
246 | 49 elevation = 0'f32 |
239
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
50 azimut = 0'f32 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
51 currentScene = 0 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
52 |
222
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
53 while engine.updateInputs() == Running and not engine.keyIsDown(Escape): |
239
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
54 if engine.keyWasPressed(`1`): |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
55 currentScene = 0 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
56 elif engine.keyWasPressed(`2`): |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
57 currentScene = 1 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
58 elif engine.keyWasPressed(`3`): |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
59 currentScene = 2 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
60 elif engine.keyWasPressed(`4`): |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
61 currentScene = 3 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
62 elif engine.keyWasPressed(`5`): |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
63 currentScene = 4 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
64 elif engine.keyWasPressed(`6`): |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
65 currentScene = 5 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
66 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
67 if engine.keyWasPressed(NumberRowExtra3): |
246 | 68 size = 0.3'f32 |
69 elevation = 0'f32 | |
239
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
70 azimut = 0'f32 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
71 |
246 | 72 let ratio = engine.getWindow().size[0] / engine.getWindow().size[1] |
239
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
73 size *= 1'f32 + engine.mouseWheel() * 0.05 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
74 azimut += engine.mouseMove().x / 180'f32 |
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
75 elevation -= engine.mouseMove().y / 180'f32 |
245 | 76 scenes[currentScene].setShaderGlobal("projection", ortho(-ratio, ratio, -1, 1, -1, 1)) |
239
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
77 scenes[currentScene].setShaderGlobal( |
245 | 78 "view", |
333
27aaf43e18b4
fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents:
318
diff
changeset
|
79 scale(size, size, size) * rotate(elevation, newVec3f(1, 0, 0)) * rotate(azimut, Yf32) |
230 | 80 ) |
239
f05497ef8fd2
did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents:
230
diff
changeset
|
81 engine.renderScene(scenes[currentScene]) |
222
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
82 engine.destroy() |
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
83 |
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
84 when isMainModule: |
ddfc54036e00
add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff
changeset
|
85 main() |