annotate tests/test_mesh.nim @ 866:0ae619ecc4bf

del: debug echos
author Sam <sam@basx.dev>
date Mon, 01 Jan 2024 17:40:29 +0700
parents 6001037da8c2
children 91e018270832
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 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 = [
834
6001037da8c2 fix: make tests working again
Sam <sam@basx.dev>
parents: 832
diff changeset
5 Scene(name: "Donut", meshes: loadMeshes("donut.glb", COLORED_SINGLE_TEXTURE_MATERIAL)[0].toSeq),
700
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
6 ]
683
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
7
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
8 var engine = initEngine("Test meshes")
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
9 const
794
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
10 shaderConfiguration = createShaderConfiguration(
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
11 inputs=[
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
12 attr[Vec3f]("position", memoryPerformanceHint=PreferFastRead),
832
388c4b35a6e3 fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents: 814
diff changeset
13 attr[uint16]("materialIndex", memoryPerformanceHint=PreferFastRead, perInstance=true),
794
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
14 attr[Vec2f]("texcoord_0", memoryPerformanceHint=PreferFastRead),
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
15 attr[Mat4]("transform", memoryPerformanceHint=PreferFastWrite, perInstance=true),
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
16 ],
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
17 intermediates=[
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
18 attr[Vec4f]("vertexColor"),
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
19 attr[Vec2f]("colorTexCoord"),
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
20 attr[uint16]("materialIndexOut", noInterpolation=true)
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
21 ],
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
22 outputs=[attr[Vec4f]("color")],
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
23 uniforms=[
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
24 attr[Mat4]("projection"),
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
25 attr[Mat4]("view"),
832
388c4b35a6e3 fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents: 814
diff changeset
26 attr[Vec4f]("color", arrayCount=4),
794
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
27 ],
832
388c4b35a6e3 fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents: 814
diff changeset
28 samplers=[attr[Texture]("baseTexture", arrayCount=4)],
730
88ab3e6dcaa0 add: simpler shader construction
Sam <sam@basx.dev>
parents: 729
diff changeset
29 vertexCode="""
794
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
30 gl_Position = vec4(position, 1.0) * (transform * Uniforms.view * Uniforms.projection);
832
388c4b35a6e3 fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents: 814
diff changeset
31 vertexColor = Uniforms.color[materialIndex];
794
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
32 colorTexCoord = texcoord_0;
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
33 materialIndexOut = materialIndex;
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
34 """,
832
388c4b35a6e3 fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents: 814
diff changeset
35 fragmentCode="color = texture(baseTexture[materialIndexOut], colorTexCoord) * vertexColor;"
683
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
36 )
832
388c4b35a6e3 fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents: 814
diff changeset
37 engine.initRenderer({COLORED_SINGLE_TEXTURE_MATERIAL: shaderConfiguration})
794
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
38
700
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
39 for scene in scenes.mitems:
794
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
40 scene.addShaderGlobal("projection", Unit4F32)
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
41 scene.addShaderGlobal("view", Unit4F32)
832
388c4b35a6e3 fix: tests, test_materials and test_mesh still needs to be done
Sam <sam@basx.dev>
parents: 814
diff changeset
42 engine.loadScene(scene)
794
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
43
700
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
44 var
708
3bb199dd45ba fix: gltf loading
Sam <sam@basx.dev>
parents: 707
diff changeset
45 size = 1'f32
707
3742bba2293f fix: better defaults
Sam <sam@basx.dev>
parents: 706
diff changeset
46 elevation = 0'f32
700
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
47 azimut = 0'f32
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
683
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
50 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
51 if engine.keyWasPressed(`1`):
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
52 currentScene = 0
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
53 elif engine.keyWasPressed(`2`):
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
54 currentScene = 1
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
55 elif engine.keyWasPressed(`3`):
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
56 currentScene = 2
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
57 elif engine.keyWasPressed(`4`):
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
58 currentScene = 3
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
59 elif engine.keyWasPressed(`5`):
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
60 currentScene = 4
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
61 elif engine.keyWasPressed(`6`):
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
62 currentScene = 5
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
63
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
64 if engine.keyWasPressed(NumberRowExtra3):
707
3742bba2293f fix: better defaults
Sam <sam@basx.dev>
parents: 706
diff changeset
65 size = 0.3'f32
3742bba2293f fix: better defaults
Sam <sam@basx.dev>
parents: 706
diff changeset
66 elevation = 0'f32
700
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
67 azimut = 0'f32
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
68
707
3742bba2293f fix: better defaults
Sam <sam@basx.dev>
parents: 706
diff changeset
69 let ratio = engine.getWindow().size[0] / engine.getWindow().size[1]
700
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
70 size *= 1'f32 + engine.mouseWheel() * 0.05
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
71 azimut += engine.mouseMove().x / 180'f32
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
72 elevation -= engine.mouseMove().y / 180'f32
706
0936ae49f0c4 add: correct camera calculations
Sam <sam@basx.dev>
parents: 705
diff changeset
73 scenes[currentScene].setShaderGlobal("projection", ortho(-ratio, ratio, -1, 1, -1, 1))
700
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
74 scenes[currentScene].setShaderGlobal(
706
0936ae49f0c4 add: correct camera calculations
Sam <sam@basx.dev>
parents: 705
diff changeset
75 "view",
794
59c54c4486c4 fix: material handling, gltf loading, loader example
Sam <sam@basx.dev>
parents: 779
diff changeset
76 scale(size, size, size) * rotate(elevation, newVec3f(1, 0, 0)) * rotate(azimut, Yf32)
691
9182a5d2ea3a add: test mesh
Sam <sam@basx.dev>
parents: 683
diff changeset
77 )
700
abc0d97392cb did: nicer test example, scene switching still problematic
Sam <sam@basx.dev>
parents: 691
diff changeset
78 engine.renderScene(scenes[currentScene])
683
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
79 engine.destroy()
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
80
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
81 when isMainModule:
2ca938595aea add: basic loading of glTF files (*.glb), no materials yet
Sam <sam@basx.dev>
parents:
diff changeset
82 main()