Skip to content

Commit df9c8a8

Browse files
committed
models_heightmap.py example added.
1 parent fb0975e commit df9c8a8

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

examples/models/models_heightmap.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# *******************************************************************************************
2+
#
3+
# raylib [models] example - Heightmap loading and drawing
4+
#
5+
# This example has been created using raylib 1.8 (www.raylib.com)
6+
# raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
7+
#
8+
# Copyright (c) 2015 Ramon Santamaria (@raysan5)
9+
#
10+
# *******************************************************************************************
11+
12+
from raylibpy import *
13+
14+
def main() -> int:
15+
16+
# Initialization
17+
# -------------------------------------------------------------------------------------
18+
screen_width: int = 800
19+
screen_height: int = 450
20+
21+
init_window(screen_width, screen_height, "raylib [models] example - heightmap loading and drawing")
22+
23+
camera: Camera3D = Camera3D(Vector3(18., 16., 18.), Vector3.zero(), Vector3(0., 1., 0.), 45., 0)
24+
25+
image: Image = load_image("resources/heightmap.png")
26+
texture: Texture2D = load_texture_from_image(image)
27+
28+
mesh: Mesh = gen_mesh_heightmap(image, Vector3(16., 8., 16.))
29+
model: Model = load_model_from_mesh(mesh)
30+
31+
model.material.maps[MAP_DIFFUSE].texture = texture
32+
map_position: Vector3 = Vector3(-8., 0., -8.)
33+
34+
unload_image(image)
35+
36+
set_camera_mode(camera, CAMERA_ORBITAL)
37+
38+
set_target_fps(60)
39+
# -------------------------------------------------------------------------------------
40+
41+
# Main game loop
42+
while not window_should_close():
43+
update_camera(byref(camera))
44+
45+
begin_drawing()
46+
47+
clear_background(RAYWHITE)
48+
49+
begin_mode3d(camera)
50+
51+
draw_model(model, map_position, 1., RED)
52+
draw_grid(20, 1.)
53+
54+
end_mode3d()
55+
56+
draw_texture(texture, screen_width - texture.width - 20, 20, WHITE)
57+
draw_rectangle_lines(screen_width - texture.width - 20, 20, texture.width, texture.height, GREEN)
58+
59+
draw_fps(5, 5)
60+
61+
end_drawing()
62+
63+
unload_texture(texture)
64+
unload_model(model)
65+
66+
close_window()
67+
68+
return 0
69+
70+
71+
if __name__ == '__main__':
72+
main()

0 commit comments

Comments
 (0)