Skip to content

Commit 6bd82a0

Browse files
authored
Add aabb example (#86)
1 parent 40c2a2c commit 6bd82a0

File tree

14 files changed

+563
-0
lines changed

14 files changed

+563
-0
lines changed

model/aabb/all.texture_profiles

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
path_settings {
2+
path: "**"
3+
profile: "Default"
4+
}
5+
profiles {
6+
name: "Default"
7+
platforms {
8+
os: OS_ID_GENERIC
9+
formats {
10+
format: TEXTURE_FORMAT_RGBA
11+
compression_level: BEST
12+
compression_type: COMPRESSION_TYPE_DEFAULT
13+
}
14+
mipmaps: false
15+
max_texture_size: 0
16+
premultiply_alpha: true
17+
}
18+
}

model/aabb/assets/materials/unlit.fp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#version 140
2+
3+
// Inputs should match the vertex shader's outputs.
4+
in vec2 var_texcoord0;
5+
6+
// The texture to sample.
7+
uniform lowp sampler2D texture0;
8+
9+
// The final color of the fragment.
10+
out lowp vec4 final_color;
11+
12+
uniform fs_uniforms
13+
{
14+
mediump vec4 tint;
15+
};
16+
17+
void main()
18+
{
19+
// Pre-multiply alpha since all runtime textures already are
20+
vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
21+
22+
// Sample the texture at the fragment's texture coordinates.
23+
vec4 color = texture(texture0, var_texcoord0.xy) * tint_pm;
24+
25+
// Output the sampled color.
26+
final_color = color;
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "unlit"
2+
tags: "model"
3+
vertex_program: "/assets/materials/unlit.vp"
4+
fragment_program: "/assets/materials/unlit.fp"
5+
vertex_space: VERTEX_SPACE_LOCAL
6+
vertex_constants {
7+
name: "mtx_view"
8+
type: CONSTANT_TYPE_VIEW
9+
}
10+
vertex_constants {
11+
name: "mtx_proj"
12+
type: CONSTANT_TYPE_PROJECTION
13+
}
14+
fragment_constants {
15+
name: "tint"
16+
type: CONSTANT_TYPE_USER
17+
value {
18+
x: 1.0
19+
y: 1.0
20+
z: 1.0
21+
w: 1.0
22+
}
23+
}
24+
samplers {
25+
name: "texture0"
26+
wrap_u: WRAP_MODE_CLAMP_TO_EDGE
27+
wrap_v: WRAP_MODE_CLAMP_TO_EDGE
28+
filter_min: FILTER_MODE_MIN_LINEAR
29+
filter_mag: FILTER_MODE_MAG_LINEAR
30+
max_anisotropy: 0.0
31+
}

model/aabb/assets/materials/unlit.vp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#version 140
2+
3+
// The model's vertex position and texture coordinates.
4+
in vec4 position;
5+
in vec2 texcoord0;
6+
7+
// The model's world matrix.
8+
in mat4 mtx_world;
9+
10+
// The projection and view matrices.
11+
uniform general_vp
12+
{
13+
mat4 mtx_view;
14+
mat4 mtx_proj;
15+
};
16+
17+
// The output of a vertex shader are passed to the fragment shader.
18+
// The texture coordinates of the vertex.
19+
out vec2 var_texcoord0;
20+
21+
void main()
22+
{
23+
// Pass the texture coordinates to the fragment shader.
24+
var_texcoord0 = texcoord0;
25+
26+
// Transform the vertex position to clip space.
27+
gl_Position = mtx_proj * mtx_view * mtx_world * vec4(position.xyz, 1.0);
28+
}

model/aabb/assets/models/License.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
Prototype Kit (1.0)
4+
5+
Created/distributed by Kenney (www.kenney.nl)
6+
Creation date: 28-08-2024 09:59
7+
8+
------------------------------
9+
10+
License: (Creative Commons Zero, CC0)
11+
http://creativecommons.org/publicdomain/zero/1.0/
12+
13+
You can use this content for personal, educational, and commercial purposes.
14+
15+
Support by crediting 'Kenney' or 'www.kenney.nl' (this is not a requirement)
16+
17+
------------------------------
18+
19+
• Website : www.kenney.nl
20+
• Donate : www.kenney.nl/donate
21+
22+
• Patreon : patreon.com/kenney
23+
24+
Follow on social media for updates:
25+
26+
• Twitter: twitter.com/KenneyNL
27+
• Instagram: instagram.com/kenney_nl
28+
• Mastodon: mastodon.gamedev.place/@kenney
8.5 KB
Loading
17.7 KB
Binary file not shown.

model/aabb/assets/models/crate.glb

17.6 KB
Binary file not shown.

model/aabb/example.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
tags: model
3+
title: AABB
4+
brief: This example demonstrates how to use the `model.get_aabb()` function in a 3D scene.
5+
scripts: aabb.script
6+
author: Artsiom Trubchyk
7+
---
8+
9+
This example shows how to work with Axis-Aligned Bounding Boxes (AABB) in a 3D scene. The setup consists of falling cubes that are dynamically tracked by a camera using their combined bounding box. The example demonstrates:
10+
11+
* How to create and manage a dynamic bounding box that updates with moving objects
12+
* Using `model.get_aabb()` to get object bounds
13+
* Camera positioning based on bounding box size
14+
* Dynamic object spawning with factory
15+
* Smooth camera transitions
16+
17+
Press SPACE or click to spawn new cubes. The camera will automatically adjust to keep all objects in view based on their combined bounding box.
18+
19+
The models used in this example are from Kenney's [Prototype Kit](https://kenney.nl/assets/prototype-kit), licensed under CC0.

model/aabb/example/aabb.collection

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: "gltf"
2+
scale_along_z: 1
3+
embedded_instances {
4+
id: "camera"
5+
data: "embedded_components {\n"
6+
" id: \"camera\"\n"
7+
" type: \"camera\"\n"
8+
" data: \"aspect_ratio: 1.0\\n"
9+
"fov: 0.7854\\n"
10+
"near_z: 0.1\\n"
11+
"far_z: 1000.0\\n"
12+
"auto_aspect_ratio: 1\\n"
13+
"\"\n"
14+
"}\n"
15+
""
16+
position {
17+
x: 1.6733184
18+
y: 0.87541014
19+
z: -2.2133834
20+
}
21+
rotation {
22+
x: -0.041512698
23+
y: 0.93996596
24+
z: 0.12374887
25+
w: 0.31532025
26+
}
27+
}
28+
embedded_instances {
29+
id: "main"
30+
data: "components {\n"
31+
" id: \"aabb\"\n"
32+
" component: \"/example/aabb.script\"\n"
33+
"}\n"
34+
"embedded_components {\n"
35+
" id: \"factory_box1\"\n"
36+
" type: \"factory\"\n"
37+
" data: \"prototype: \\\"/example/box1.go\\\"\\n"
38+
"\"\n"
39+
"}\n"
40+
"embedded_components {\n"
41+
" id: \"factory_box2\"\n"
42+
" type: \"factory\"\n"
43+
" data: \"prototype: \\\"/example/box2.go\\\"\\n"
44+
"\"\n"
45+
"}\n"
46+
""
47+
}
48+
embedded_instances {
49+
id: "ground"
50+
data: "embedded_components {\n"
51+
" id: \"sprite\"\n"
52+
" type: \"sprite\"\n"
53+
" data: \"default_animation: \\\"anim\\\"\\n"
54+
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
55+
"size {\\n"
56+
" x: 40.0\\n"
57+
" y: 40.0\\n"
58+
"}\\n"
59+
"size_mode: SIZE_MODE_MANUAL\\n"
60+
"textures {\\n"
61+
" sampler: \\\"texture_sampler\\\"\\n"
62+
" texture: \\\"/builtins/graphics/particle_blob.tilesource\\\"\\n"
63+
"}\\n"
64+
"\"\n"
65+
" rotation {\n"
66+
" x: 0.70710677\n"
67+
" w: 0.70710677\n"
68+
" }\n"
69+
"}\n"
70+
"embedded_components {\n"
71+
" id: \"collisionobject\"\n"
72+
" type: \"collisionobject\"\n"
73+
" data: \"type: COLLISION_OBJECT_TYPE_STATIC\\n"
74+
"mass: 0.0\\n"
75+
"friction: 0.8\\n"
76+
"restitution: 0.2\\n"
77+
"group: \\\"default\\\"\\n"
78+
"mask: \\\"default\\\"\\n"
79+
"embedded_collision_shape {\\n"
80+
" shapes {\\n"
81+
" shape_type: TYPE_BOX\\n"
82+
" position {\\n"
83+
" y: -0.25\\n"
84+
" }\\n"
85+
" rotation {\\n"
86+
" }\\n"
87+
" index: 0\\n"
88+
" count: 3\\n"
89+
" }\\n"
90+
" data: 50.0\\n"
91+
" data: 0.25\\n"
92+
" data: 50.0\\n"
93+
"}\\n"
94+
"\"\n"
95+
"}\n"
96+
""
97+
}

0 commit comments

Comments
 (0)