Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions model/aabb/all.texture_profiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
path_settings {
path: "**"
profile: "Default"
}
profiles {
name: "Default"
platforms {
os: OS_ID_GENERIC
formats {
format: TEXTURE_FORMAT_RGBA
compression_level: BEST
compression_type: COMPRESSION_TYPE_DEFAULT
}
mipmaps: false
max_texture_size: 0
premultiply_alpha: true
}
}
27 changes: 27 additions & 0 deletions model/aabb/assets/materials/unlit.fp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#version 140

// Inputs should match the vertex shader's outputs.
in vec2 var_texcoord0;

// The texture to sample.
uniform lowp sampler2D texture0;

// The final color of the fragment.
out lowp vec4 final_color;

uniform fs_uniforms
{
mediump vec4 tint;
};

void main()
{
// Pre-multiply alpha since all runtime textures already are
vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);

// Sample the texture at the fragment's texture coordinates.
vec4 color = texture(texture0, var_texcoord0.xy) * tint_pm;

// Output the sampled color.
final_color = color;
}
31 changes: 31 additions & 0 deletions model/aabb/assets/materials/unlit.material
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "unlit"
tags: "model"
vertex_program: "/assets/materials/unlit.vp"
fragment_program: "/assets/materials/unlit.fp"
vertex_space: VERTEX_SPACE_LOCAL
vertex_constants {
name: "mtx_view"
type: CONSTANT_TYPE_VIEW
}
vertex_constants {
name: "mtx_proj"
type: CONSTANT_TYPE_PROJECTION
}
fragment_constants {
name: "tint"
type: CONSTANT_TYPE_USER
value {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
}
samplers {
name: "texture0"
wrap_u: WRAP_MODE_CLAMP_TO_EDGE
wrap_v: WRAP_MODE_CLAMP_TO_EDGE
filter_min: FILTER_MODE_MIN_LINEAR
filter_mag: FILTER_MODE_MAG_LINEAR
max_anisotropy: 0.0
}
28 changes: 28 additions & 0 deletions model/aabb/assets/materials/unlit.vp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#version 140

// The model's vertex position and texture coordinates.
in vec4 position;
in vec2 texcoord0;

// The model's world matrix.
in mat4 mtx_world;

// The projection and view matrices.
uniform general_vp
{
mat4 mtx_view;
mat4 mtx_proj;
};

// The output of a vertex shader are passed to the fragment shader.
// The texture coordinates of the vertex.
out vec2 var_texcoord0;

void main()
{
// Pass the texture coordinates to the fragment shader.
var_texcoord0 = texcoord0;

// Transform the vertex position to clip space.
gl_Position = mtx_proj * mtx_view * mtx_world * vec4(position.xyz, 1.0);
}
28 changes: 28 additions & 0 deletions model/aabb/assets/models/License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


Prototype Kit (1.0)

Created/distributed by Kenney (www.kenney.nl)
Creation date: 28-08-2024 09:59

------------------------------

License: (Creative Commons Zero, CC0)
http://creativecommons.org/publicdomain/zero/1.0/

You can use this content for personal, educational, and commercial purposes.

Support by crediting 'Kenney' or 'www.kenney.nl' (this is not a requirement)

------------------------------

• Website : www.kenney.nl
• Donate : www.kenney.nl/donate

• Patreon : patreon.com/kenney

Follow on social media for updates:

• Twitter: twitter.com/KenneyNL
• Instagram: instagram.com/kenney_nl
• Mastodon: mastodon.gamedev.place/@kenney
Binary file added model/aabb/assets/models/Textures/colormap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added model/aabb/assets/models/crate-color.glb
Binary file not shown.
Binary file added model/aabb/assets/models/crate.glb
Binary file not shown.
19 changes: 19 additions & 0 deletions model/aabb/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
tags: model
title: AABB
brief: This example demonstrates how to use the `model.get_aabb()` function in a 3D scene.
scripts: aabb.script
author: Artsiom Trubchyk
---

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:

* How to create and manage a dynamic bounding box that updates with moving objects
* Using `model.get_aabb()` to get object bounds
* Camera positioning based on bounding box size
* Dynamic object spawning with factory
* Smooth camera transitions

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.

The models used in this example are from Kenney's [Prototype Kit](https://kenney.nl/assets/prototype-kit), licensed under CC0.
97 changes: 97 additions & 0 deletions model/aabb/example/aabb.collection
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: "gltf"
scale_along_z: 1
embedded_instances {
id: "camera"
data: "embedded_components {\n"
" id: \"camera\"\n"
" type: \"camera\"\n"
" data: \"aspect_ratio: 1.0\\n"
"fov: 0.7854\\n"
"near_z: 0.1\\n"
"far_z: 1000.0\\n"
"auto_aspect_ratio: 1\\n"
"\"\n"
"}\n"
""
position {
x: 1.6733184
y: 0.87541014
z: -2.2133834
}
rotation {
x: -0.041512698
y: 0.93996596
z: 0.12374887
w: 0.31532025
}
}
embedded_instances {
id: "main"
data: "components {\n"
" id: \"aabb\"\n"
" component: \"/example/aabb.script\"\n"
"}\n"
"embedded_components {\n"
" id: \"factory_box1\"\n"
" type: \"factory\"\n"
" data: \"prototype: \\\"/example/box1.go\\\"\\n"
"\"\n"
"}\n"
"embedded_components {\n"
" id: \"factory_box2\"\n"
" type: \"factory\"\n"
" data: \"prototype: \\\"/example/box2.go\\\"\\n"
"\"\n"
"}\n"
""
}
embedded_instances {
id: "ground"
data: "embedded_components {\n"
" id: \"sprite\"\n"
" type: \"sprite\"\n"
" data: \"default_animation: \\\"anim\\\"\\n"
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
"size {\\n"
" x: 40.0\\n"
" y: 40.0\\n"
"}\\n"
"size_mode: SIZE_MODE_MANUAL\\n"
"textures {\\n"
" sampler: \\\"texture_sampler\\\"\\n"
" texture: \\\"/builtins/graphics/particle_blob.tilesource\\\"\\n"
"}\\n"
"\"\n"
" rotation {\n"
" x: 0.70710677\n"
" w: 0.70710677\n"
" }\n"
"}\n"
"embedded_components {\n"
" id: \"collisionobject\"\n"
" type: \"collisionobject\"\n"
" data: \"type: COLLISION_OBJECT_TYPE_STATIC\\n"
"mass: 0.0\\n"
"friction: 0.8\\n"
"restitution: 0.2\\n"
"group: \\\"default\\\"\\n"
"mask: \\\"default\\\"\\n"
"embedded_collision_shape {\\n"
" shapes {\\n"
" shape_type: TYPE_BOX\\n"
" position {\\n"
" y: -0.25\\n"
" }\\n"
" rotation {\\n"
" }\\n"
" index: 0\\n"
" count: 3\\n"
" }\\n"
" data: 50.0\\n"
" data: 0.25\\n"
" data: 50.0\\n"
"}\\n"
"\"\n"
"}\n"
""
}
Loading