basilisk-engine 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of basilisk-engine might be problematic. Click here for more details.

basilisk/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ from .engine import Engine
2
+ from .scene import Scene
3
+ from .nodes.node import Node
4
+ from .mesh.mesh import Mesh
5
+ from .mesh.cube import cube
6
+ from .render.image import Image
7
+ from .render.material import Material
8
+ from .render.shader_handler import ShaderHandler
9
+ from .draw import draw
10
+ from .render.camera import FreeCamera, StaticCamera
11
+ from .render.sky import Sky
basilisk/config.py ADDED
@@ -0,0 +1,3 @@
1
+ class Config():
2
+ def __init__(self) -> None:
3
+ ...
basilisk/engine.py ADDED
@@ -0,0 +1,171 @@
1
+ import os
2
+ os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
3
+ import pygame as pg
4
+ import moderngl as mgl
5
+ from .config import Config
6
+ from .input.mouse import Mouse
7
+ import time
8
+
9
+ class Engine():
10
+ win_size: tuple
11
+ """Size of the engine window in pixels"""
12
+ ctx: mgl.Context
13
+ """ModernGL context used by the engine"""
14
+ scene: any
15
+ """Scene currently being updated and rendered by the engine"""
16
+ clock: pg.Clock
17
+ """Pygame clock used to keep track of time between frames"""
18
+ config: Config
19
+ """Object containing all global attributes"""
20
+ delta_time: float
21
+ """Time in seconds that passed between the last frame"""
22
+ time: float
23
+ """Total time the engine has been running"""
24
+ running: bool
25
+ """True if the engine is still running"""
26
+ events: list
27
+ """List of all pygame"""
28
+ keys: list
29
+ """bool list containing the state of all keys this frame"""
30
+ previous_keys: list
31
+ """bool list containing the state of all keys at the previous frame"""
32
+ mouse: Mouse
33
+ """Object containing information about the user's mouse"""
34
+ root: str
35
+ """Path to the root directory containing internal data"""
36
+
37
+ def __init__(self, win_size=(800, 800), title="Basilisk Engine", vsync=False, grab_mouse=True, headless=False) -> None:
38
+ """
39
+ Basilisk Engine Class. Sets up the engine enviornment and allows the user to interact with Basilisk
40
+ Args:
41
+ win_size: tuple
42
+ The initial window size of the engine
43
+ title: str
44
+ The title of the engine window
45
+ vsync: bool
46
+ Flag for running engine with vsync enabled
47
+ headless: bool
48
+ Flag for headless rendering
49
+ """
50
+ # Save the window size
51
+ self.win_size = win_size
52
+
53
+ pg.init()
54
+ # Initialize pygame and OpenGL attributes
55
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_MAJOR_VERSION, 3)
56
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_MINOR_VERSION, 3)
57
+ pg.display.gl_set_attribute(pg.GL_CONTEXT_PROFILE_MASK, pg.GL_CONTEXT_PROFILE_CORE)
58
+ # Pygame display init
59
+ if headless:
60
+ pg.display.set_mode((300, 50), vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF)
61
+ pg.display.iconify()
62
+ else:
63
+ pg.display.set_mode(self.win_size, vsync=vsync, flags=pg.OPENGL | pg.DOUBLEBUF | pg.RESIZABLE)
64
+ pg.display.set_caption(title)
65
+ pg.display.set_icon(pg.image.load("basilisk.png"))
66
+
67
+ # MGL context setup
68
+ self.ctx = mgl.create_context()
69
+ self.ctx.enable(flags=mgl.DEPTH_TEST | mgl.CULL_FACE | mgl.BLEND)
70
+
71
+ # Global attributes referenced by the handlers
72
+ self.headless = headless
73
+ self.set_configurations()
74
+ self.root = os.path.dirname(__file__)
75
+ print(self.root)
76
+
77
+ # Time variables
78
+ self.clock = pg.time.Clock()
79
+ self.delta_time = 0
80
+ self.time = 0
81
+
82
+ # Initialize input lists
83
+ self.keys = pg.key.get_pressed()
84
+ self.previous_keys = self.keys
85
+ self.mouse = Mouse(grab=grab_mouse)
86
+
87
+ # Scene being used by the engine
88
+ self.scene = None
89
+
90
+ # Set the scene to running
91
+ self.running = True
92
+
93
+ def update(self) -> None:
94
+ """
95
+ Updates all input, physics, and time variables. Renders the current scene.
96
+ """
97
+
98
+ # Tick the clock and get delta time
99
+ self.delta_time = self.clock.tick() / 1000
100
+ self.time += self.delta_time
101
+ pg.display.set_caption(f"FPS: {round(self.clock.get_fps())}")
102
+
103
+ # Get inputs and events
104
+ self.events = pg.event.get()
105
+ self.keys = pg.key.get_pressed()
106
+ self.mouse.update(self.events)
107
+
108
+ # Loop through all pygame events
109
+ for event in self.events:
110
+ if event.type == pg.QUIT: # Quit the engine
111
+ self.quit()
112
+ return
113
+ if event.type == pg.VIDEORESIZE:
114
+ # Updates the viewport
115
+ self.win_size = (event.w, event.h)
116
+ self.ctx.viewport = (0, 0, event.w, event.h)
117
+ self.scene.camera.use()
118
+ self.scene.frame.set_textures()
119
+
120
+
121
+ # Update the scene if possible
122
+ if self.scene: self.scene.update()
123
+ # Render after the scene and engine has been updated
124
+ self.render()
125
+
126
+ # Update the previous input lists for the next frame
127
+ self.previous_keys = self.keys
128
+
129
+ def render(self) -> None:
130
+ """
131
+ Renders the scene currently being used by the engine
132
+ """
133
+
134
+ # Set the ctx for rendering
135
+ self.ctx.screen.use()
136
+ self.ctx.clear()
137
+
138
+ # Render the scene
139
+ if self.scene:self.scene.render()
140
+
141
+ # Flip pygame display buffer
142
+ pg.display.flip()
143
+
144
+ def set_configurations(self):
145
+ """
146
+ Sets global configurations. These attributs are not used by the engine, just the handlers
147
+ """
148
+
149
+ # Create a config object
150
+ self.config = Config()
151
+
152
+ # Set the attributes on the config object
153
+ setattr(self.config, "chunk_size", 40)
154
+ setattr(self.config, "render_distance", 5)
155
+
156
+ def quit(self) -> None:
157
+ """
158
+ Stops the engine and releases all memory
159
+ """
160
+
161
+ pg.quit()
162
+ self.ctx.release()
163
+ self.running = False
164
+
165
+ @property
166
+ def scene(self): return self._scene
167
+
168
+ @scene.setter
169
+ def scene(self, value):
170
+ self._scene = value
171
+ if self._scene: self._scene.set_engine(self)
basilisk/scene.py ADDED
@@ -0,0 +1,128 @@
1
+ import moderngl as mgl
2
+ import glm
3
+ from .render.shader_handler import ShaderHandler
4
+ from .mesh.mesh import Mesh
5
+ from .render.material import Material
6
+ from .render.material_handler import MaterialHandler
7
+ from .render.light_handler import LightHandler
8
+ from .render.camera import Camera, FreeCamera
9
+ from .nodes.node_handler import NodeHandler
10
+ from .physics.physics_engine import PhysicsEngine
11
+ from .collisions.collider_handler import ColliderHandler
12
+ from .draw.draw_handler import DrawHandler
13
+ from .render.sky import Sky
14
+ from .render.frame import Frame
15
+
16
+
17
+ class Scene():
18
+ engine: any
19
+ """Parent engine of the scene"""
20
+ ctx: mgl.Context
21
+ """Reference to the engine context"""
22
+
23
+ def __init__(self) -> None:
24
+ """
25
+ Basilisk scene object. Contains all nodes for the scene
26
+ """
27
+
28
+ self.engine = None
29
+ self.ctx = None
30
+
31
+ self.camera = None
32
+ self.shader_handler = None
33
+ self.node_handler = None
34
+ self.material_handler = None
35
+ self.light_handler = None
36
+ self.draw_handler = None
37
+ self.sky = None
38
+ self.frame = None
39
+
40
+ def update(self) -> None:
41
+ """
42
+ Updates the physics and in the scene
43
+ """
44
+
45
+ self.camera.update()
46
+ self.node_handler.update()
47
+
48
+ def render(self) -> None:
49
+ """
50
+ Renders all the nodes with meshes in the scene
51
+ """
52
+
53
+ self.frame.use()
54
+ self.shader_handler.write()
55
+ self.sky.render()
56
+ self.node_handler.render()
57
+ self.draw_handler.render()
58
+
59
+ if self.engine.headless: return
60
+ self.frame.render()
61
+
62
+ def add_node(self,
63
+ position: glm.vec3=None,
64
+ scale: glm.vec3=None,
65
+ rotation: glm.quat=None,
66
+ forward: glm.vec3=None,
67
+ mesh: Mesh=None,
68
+ material: Material=None,
69
+ velocity: glm.vec3=None,
70
+ rotational_velocity: glm.quat=None,
71
+ physics: bool=False,
72
+ mass: float=None,
73
+ collisions: bool=False,
74
+ collider: str=None,
75
+ static_friction: float=None,
76
+ kinetic_friction: float=None,
77
+ elasticity: float=None,
78
+ collision_group : float=None,
79
+ name: str='',
80
+ tags: list[str]=None,
81
+ static: bool=True):
82
+
83
+ if material: self.material_handler.add(material)
84
+ else: material = self.material_handler.base
85
+
86
+ return self.node_handler.add(position, scale, rotation, forward, mesh, material, velocity, rotational_velocity, physics, mass, collisions, collider, static_friction, kinetic_friction, elasticity, collision_group, name, tags, static)
87
+
88
+
89
+ def set_engine(self, engine: any) -> None:
90
+ """
91
+ Sets the back references to the engine and creates handlers with the context
92
+ """
93
+
94
+ self.engine = engine
95
+ self.ctx = engine.ctx
96
+
97
+ self.camera = FreeCamera()
98
+ self.shader_handler = ShaderHandler(self)
99
+ self.physics_engine = PhysicsEngine()
100
+ self.node_handler = NodeHandler(self)
101
+ self.collider_handler = ColliderHandler(self)
102
+ self.material_handler = MaterialHandler(self)
103
+ self.light_handler = LightHandler(self)
104
+ self.draw_handler = DrawHandler(self)
105
+ self.frame = Frame(self)
106
+ self.sky = Sky(self.engine)
107
+
108
+ @property
109
+ def camera(self): return self._camera
110
+ @property
111
+ def sky(self): return self._sky
112
+
113
+ @camera.setter
114
+ def camera(self, value: Camera):
115
+ if not value: return
116
+ if not isinstance(value, Camera):
117
+ raise TypeError(f'Scene: Invalid camera type: {type(value)}. Expected type bsk.Camera')
118
+ self._camera = value
119
+ self._camera.scene = self
120
+
121
+ @sky.setter
122
+ def sky(self, value: Sky):
123
+ if not value: return
124
+ if not isinstance(value, Sky):
125
+ raise TypeError(f'Scene: Invalid sky type: {type(value)}. Expected type bsk.Sky')
126
+ self._sky = value
127
+ self._sky.write()
128
+
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.1
2
+ Name: basilisk-engine
3
+ Version: 0.0.1
4
+ Summary: Python 3D Framework
5
+ Home-page: https://basilisk-website.vercel.app/
6
+ Author: Name
7
+ Author-email: basiliskengine@gmail.com
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: numpy
10
+ Requires-Dist: pillow
11
+ Requires-Dist: pygame-ce
12
+ Requires-Dist: moderngl
13
+ Requires-Dist: PyGLM
14
+ Requires-Dist: numba
15
+
16
+ # Basilisk Engine
17
+ ![image](https://github.com/user-attachments/assets/5e39445c-e0da-452c-9f18-e590cca948c4)
18
+ Basilisk Engine is a Python package for effortless 3D rendering and simulation.
19
+
20
+ ## Learn more at the [Basilisk Engine Website](https://basilisk-website.vercel.app)
21
+
22
+ # Features
23
+ ## Rendering
24
+ Basilisk Engine uses a versatile and efficient physically based rendering pipeline, allowing for photorealistic and stylized rendering in real-time.
25
+
26
+ <p align="center">
27
+ <img src="mud.png" alt="mud" width="400"/>
28
+ <img src="foil.png" alt="foil" width="400"/>
29
+ <img src="cloth.png" alt="mud" width="400"/>
30
+ <img src="floor.png" alt="mud" width="400"/>
31
+ </p>
32
+
33
+ ## Physics
34
+
35
+ ## Performance
36
+
37
+ # Getting Started
38
+ ...
@@ -0,0 +1,8 @@
1
+ basilisk/__init__.py,sha256=hJVKd8NebPIdDzhfRMZsOElR5w2wGkrsW7WJqb0tpB0,368
2
+ basilisk/config.py,sha256=ynTRlX633DGoEtZOeAK8KNJF6offV3k3XFD7cia3Keg,61
3
+ basilisk/engine.py,sha256=R1COiHLHNgsfIJ72U_XxAR2oftBRsVYyYOrVqTr48Xc,5709
4
+ basilisk/scene.py,sha256=ow3w2ZouBdn7E1xw39-aMu7_gbsnDxzeNi1mqbYqa-M,4452
5
+ basilisk_engine-0.0.1.dist-info/METADATA,sha256=HFZUa45YFHSowm4nExijxFuTmQMU6JioaHB4Js201OY,1118
6
+ basilisk_engine-0.0.1.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
7
+ basilisk_engine-0.0.1.dist-info/top_level.txt,sha256=enlSYSf7CUyAly1jmUCNNGInTbaFUjGk4SKwyckZQkw,9
8
+ basilisk_engine-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.2.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ basilisk