Mercurial > games > semicongine
comparison tests/test_mesh.nim @ 1139:114f395b9144
did: finish refactoring and updated all tests accordingly
author | sam <sam@basx.dev> |
---|---|
date | Sat, 08 Jun 2024 14:58:25 +0700 |
parents | 02e1d2658ff5 |
children |
comparison
equal
deleted
inserted
replaced
1138:02e1d2658ff5 | 1139:114f395b9144 |
---|---|
11 attributes: {"baseTexture": TextureType, "color": Vec4F32}.toTable | 11 attributes: {"baseTexture": TextureType, "color": Vec4F32}.toTable |
12 ) | 12 ) |
13 | 13 |
14 proc main() = | 14 proc main() = |
15 var scenes = [ | 15 var scenes = [ |
16 Scene(name: "Donut", meshes: loadMeshes("donut.glb", MeshMaterial)[0].toSeq), | 16 Scene(name: "Donut", meshes: LoadMeshes("donut.glb", MeshMaterial)[0].toSeq), |
17 ] | 17 ] |
18 | 18 |
19 var engine = InitEngine("Test meshes") | 19 var engine = InitEngine("Test meshes") |
20 const | 20 const |
21 shaderConfiguration = createShaderConfiguration( | 21 shaderConfiguration = CreateShaderConfiguration( |
22 name = "default shader", | 22 name = "default shader", |
23 inputs = [ | 23 inputs = [ |
24 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), | 24 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), |
25 Attr[uint16](MATERIALINDEX_ATTRIBUTE, memoryPerformanceHint = PreferFastRead, perInstance = true), | 25 Attr[uint16](MATERIALINDEX_ATTRIBUTE, memoryPerformanceHint = PreferFastRead, perInstance = true), |
26 Attr[Vec2f]("texcoord_0", memoryPerformanceHint = PreferFastRead), | 26 Attr[Vec2f]("texcoord_0", memoryPerformanceHint = PreferFastRead), |
47 fragmentCode = "color = texture(baseTexture[materialIndexOut], colorTexCoord) * vertexColor;" | 47 fragmentCode = "color = texture(baseTexture[materialIndexOut], colorTexCoord) * vertexColor;" |
48 ) | 48 ) |
49 engine.InitRenderer({MeshMaterial: shaderConfiguration}) | 49 engine.InitRenderer({MeshMaterial: shaderConfiguration}) |
50 | 50 |
51 for scene in scenes.mitems: | 51 for scene in scenes.mitems: |
52 scene.addShaderGlobal("projection", Unit4F32) | 52 scene.AddShaderGlobal("projection", Unit4F32) |
53 scene.addShaderGlobal("view", Unit4F32) | 53 scene.AddShaderGlobal("view", Unit4F32) |
54 engine.LoadScene(scene) | 54 engine.LoadScene(scene) |
55 | 55 |
56 var | 56 var |
57 size = 1'f32 | 57 size = 1'f32 |
58 elevation = 0'f32 | 58 elevation = 0'f32 |
76 if KeyWasPressed(NumberRowExtra3): | 76 if KeyWasPressed(NumberRowExtra3): |
77 size = 0.3'f32 | 77 size = 0.3'f32 |
78 elevation = 0'f32 | 78 elevation = 0'f32 |
79 azimut = 0'f32 | 79 azimut = 0'f32 |
80 | 80 |
81 let ratio = engine.GetWindow().size[0] / engine.GetWindow().size[1] | 81 let ratio = engine.GetWindow().Size[0] / engine.GetWindow().Size[1] |
82 size *= 1'f32 + MouseWheel() * 0.05 | 82 size *= 1'f32 + MouseWheel() * 0.05 |
83 azimut += MouseMove().x / 180'f32 | 83 azimut += MouseMove().x / 180'f32 |
84 elevation -= MouseMove().y / 180'f32 | 84 elevation -= MouseMove().y / 180'f32 |
85 scenes[currentScene].setShaderGlobal("projection", Perspective(PI / 2, ratio, -0.5, 1)) | 85 scenes[currentScene].SetShaderGlobal("projection", Perspective(PI / 2, ratio, -0.5, 1)) |
86 scenes[currentScene].setShaderGlobal( | 86 scenes[currentScene].SetShaderGlobal( |
87 "view", | 87 "view", |
88 Scale(size, size, size) * Rotate(elevation, NewVec3f(1, 0, 0)) * Rotate(azimut, Yf32) | 88 Scale(size, size, size) * Rotate(elevation, NewVec3f(1, 0, 0)) * Rotate(azimut, Yf32) |
89 ) | 89 ) |
90 engine.RenderScene(scenes[currentScene]) | 90 engine.RenderScene(scenes[currentScene]) |
91 engine.Destroy() | 91 engine.Destroy() |