refactor pyray into separate module

This commit is contained in:
richard 2021-10-08 04:47:58 +01:00
parent 8666f0cff8
commit ec752bdab7
24 changed files with 2394 additions and 2055 deletions

View file

@ -27,9 +27,9 @@ See https://github.com/electronstudio/raylib-python-cffi/blob/master/dynamic/tes
If you use the ``rl.`` prefix then code will work on both static and dynamic bindings.
.. warning::
.. tip::
If you access functions via ``raylib.pyray`` then there is no difference at all, but be warned this hasn't been tested.
If you access functions via ``import pyray`` then there is no difference at all, but be warned this hasn't been tested much.
.. important::

View file

@ -58,4 +58,29 @@ try:
except Exception as e:
print(e)
from .pyray import PyRay
LIGHTGRAY =( 200, 200, 200, 255 )
GRAY =( 130, 130, 130, 255 )
DARKGRAY =( 80, 80, 80, 255 )
YELLOW =( 253, 249, 0, 255 )
GOLD =( 255, 203, 0, 255 )
ORANGE =( 255, 161, 0, 255 )
PINK =( 255, 109, 194, 255 )
RED =( 230, 41, 55, 255 )
MAROON =( 190, 33, 55, 255 )
GREEN =( 0, 228, 48, 255 )
LIME =( 0, 158, 47, 255 )
DARKGREEN =( 0, 117, 44, 255 )
SKYBLUE =( 102, 191, 255, 255 )
BLUE =( 0, 121, 241, 255 )
DARKBLUE =( 0, 82, 172, 255 )
PURPLE =( 200, 122, 255, 255 )
VIOLET =( 135, 60, 190, 255 )
DARKPURPLE =( 112, 31, 126, 255 )
BEIGE =( 211, 176, 131, 255 )
BROWN =( 127, 106, 79, 255 )
DARKBROWN =( 76, 63, 47, 255 )
WHITE =( 255, 255, 255, 255 )
BLACK =( 0, 0, 0, 255 )
BLANK =( 0, 0, 0, 0 )
MAGENTA =( 255, 0, 255, 255 )
RAYWHITE =( 245, 245, 245, 255 )

View file

@ -1 +0,0 @@
../../raylib/pyray.py

View file

@ -1 +0,0 @@
../../raylib/pyray.pyi

View file

@ -30,7 +30,7 @@ setup(
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
packages=["raylib"],
packages=["raylib", "pyray"],
include_package_data=True,
install_requires=["cffi>=1.14.5","inflection"],
)

View file

@ -1 +0,0 @@
../test_pyray.py

45
dynamic/test_pyray.py Normal file
View file

@ -0,0 +1,45 @@
"""
This shows how to use the Pyray wrapper around the static binding.
"""
import pyray as pr
pr.init_window(800, 450, "Raylib texture test")
pr.set_target_fps(60)
image = pr.gen_image_color(800, 400, (0,0,0,255) )
texture = pr.load_texture_from_image(image)
pr.update_texture(texture, image.data)
camera = pr.Camera3D([18.0, 16.0, 18.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0], 45.0, 0)
image = pr.load_image("examples/models/resources/heightmap.png")
texture = pr.load_texture_from_image(image)
mesh = pr.gen_mesh_heightmap(image, (16, 8, 16))
model = pr.load_model_from_mesh(mesh)
model.materials.maps[pr.MATERIAL_MAP_DIFFUSE].texture = texture
pr.unload_image(image)
pr.set_camera_mode(camera, pr.CAMERA_ORBITAL)
pos = pr.get_mouse_position()
ray = pr.get_mouse_ray(pos, camera)
rayhit = pr.get_collision_ray_ground(ray, 0)
print(str(rayhit.position.x))
while not pr.window_should_close():
pr.update_camera(camera)
pr.begin_drawing()
pr.clear_background(pr.RAYWHITE)
pr.begin_mode_3d(camera)
pr.draw_model(model, (-8.0, 0.0, -8.0), 1.0, pr.RED)
pr.draw_grid(20, 1.0)
pr.end_mode_3d()
pr.draw_text("This mesh should be textured", 190, 200, 20, pr.VIOLET)
pr.end_drawing()
pos = pr.get_mouse_position()
ray = pr.get_mouse_ray(pos, camera)
rayhit = pr.get_collision_ray_ground(ray, 0)
#print(str(rayhit.position.x))
pr.close_window()