--global-fix
This commit is contained in:
2
examples/assets/Untitled.mtl
Normal file
2
examples/assets/Untitled.mtl
Normal file
@@ -0,0 +1,2 @@
|
||||
# Blender 4.4.3 MTL File: 'None'
|
||||
# www.blender.org
|
||||
57
examples/assets/Untitled.obj
Normal file
57
examples/assets/Untitled.obj
Normal file
@@ -0,0 +1,57 @@
|
||||
# Blender 4.4.3
|
||||
# www.blender.org
|
||||
mtllib Untitled.mtl
|
||||
o Cube
|
||||
v -1.000000 -1.000000 1.000000
|
||||
v -1.000000 -1.000000 -1.000000
|
||||
v 1.000000 -1.000000 1.000000
|
||||
v 1.000000 -1.000000 -1.000000
|
||||
v -0.000000 4.229822 0.000000
|
||||
v -1.000000 3.229822 1.000000
|
||||
v -0.000000 4.229822 -0.000000
|
||||
v -1.000000 3.229822 -1.000000
|
||||
v 0.000000 4.229822 0.000000
|
||||
v 1.000000 3.229822 1.000000
|
||||
v 0.000000 4.229822 -0.000000
|
||||
v 1.000000 3.229822 -1.000000
|
||||
vn -0.5774 -0.5774 0.5774
|
||||
vn -0.5774 -0.5774 -0.5774
|
||||
vn 0.5774 -0.5774 0.5774
|
||||
vn 0.5774 -0.5774 -0.5774
|
||||
vn -0.3002 0.9054 0.3002
|
||||
vn -0.6507 0.3914 0.6507
|
||||
vn -0.3002 0.9054 -0.3002
|
||||
vn -0.6507 0.3914 -0.6507
|
||||
vn 0.3002 0.9054 0.3002
|
||||
vn 0.6507 0.3914 0.6507
|
||||
vn 0.3002 0.9054 -0.3002
|
||||
vn 0.6507 0.3914 -0.6507
|
||||
vt 0.750000 0.625000
|
||||
vt 0.750000 0.625000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.577197 0.500000
|
||||
vt 0.577197 0.750000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.375000 0.000000
|
||||
vt 0.577197 0.000000
|
||||
vt 0.577197 0.250000
|
||||
vt 0.375000 0.250000
|
||||
vt 0.125000 0.500000
|
||||
vt 0.125000 0.750000
|
||||
vt 0.875000 0.500000
|
||||
vt 0.875000 0.750000
|
||||
vt 0.625000 0.500000
|
||||
vt 0.625000 0.750000
|
||||
vt 0.577197 1.000000
|
||||
vt 0.375000 1.000000
|
||||
s 1
|
||||
f 11/1/11 7/1/7 5/2/5 9/1/9
|
||||
f 4/3/4 12/4/12 10/5/10 3/6/3
|
||||
f 1/7/1 6/8/6 8/9/8 2/10/2
|
||||
f 2/11/2 4/3/4 3/6/3 1/12/1
|
||||
f 2/10/2 8/9/8 12/4/12 4/3/4
|
||||
f 5/2/5 7/1/7 8/13/8 6/14/6
|
||||
f 7/1/7 11/1/11 12/15/12 8/13/8
|
||||
f 11/1/11 9/1/9 10/5/10 12/4/12
|
||||
f 9/1/9 5/2/5 6/14/6 10/16/10
|
||||
f 3/6/3 10/5/10 6/17/6 1/18/1
|
||||
BIN
examples/assets/bricksx64.png
Normal file
BIN
examples/assets/bricksx64.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.5 KiB |
BIN
examples/assets/dark-atmosphere-background-008-312381.mp3
Normal file
BIN
examples/assets/dark-atmosphere-background-008-312381.mp3
Normal file
Binary file not shown.
BIN
examples/assets/dark-atmosphere-background-009-312380.mp3
Normal file
BIN
examples/assets/dark-atmosphere-background-009-312380.mp3
Normal file
Binary file not shown.
BIN
examples/assets/sword-sound.mp3
Normal file
BIN
examples/assets/sword-sound.mp3
Normal file
Binary file not shown.
BIN
examples/assets/texture.png
Normal file
BIN
examples/assets/texture.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 616 B |
BIN
examples/assets/water.png
Normal file
BIN
examples/assets/water.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
151
examples/game.py
Normal file
151
examples/game.py
Normal file
@@ -0,0 +1,151 @@
|
||||
import my3dengine as m3d
|
||||
from OpenGL.GL import *
|
||||
import time
|
||||
import numpy as np
|
||||
|
||||
class Game:
|
||||
def __init__(self):
|
||||
self.WIDTH, self.HEIGHT = m3d.get_fullscreen()
|
||||
self.window = m3d.Window("3D Game", self.WIDTH, self.HEIGHT)
|
||||
self.keys = m3d.Key
|
||||
self.escape_was_pressed = False
|
||||
|
||||
self.sources = [
|
||||
m3d.AudioSource(position=[0, 0, 3], sound_path="assets/dark-atmosphere-background-009-312380.mp3", emit_radius=5, volume=1.0, loop=False, fade_duration=1.0),
|
||||
]
|
||||
|
||||
# FPS counter
|
||||
self.last_fps_time = time.time()
|
||||
self.frames = 0
|
||||
|
||||
self.camera = m3d.Camera(
|
||||
position=(0, 0, 3),
|
||||
target=(0, 0, 0),
|
||||
up=(0, 1, 0),
|
||||
fov=60,
|
||||
aspect=self.WIDTH / self.HEIGHT,
|
||||
)
|
||||
|
||||
self.listener = m3d.AudioListener(self.camera.position)
|
||||
|
||||
self.ui = m3d.UI(self.WIDTH, self.HEIGHT)
|
||||
|
||||
self.meshes = [
|
||||
m3d.Mesh.cube(),
|
||||
m3d.Mesh.sphere(),
|
||||
m3d.Mesh.capsule(),
|
||||
m3d.Mesh.cube(),
|
||||
m3d.Mesh.plane(),
|
||||
m3d.Mesh.from_obj("assets/untitled.obj"),
|
||||
]
|
||||
|
||||
# WODA
|
||||
self.water = m3d.Mesh.water(
|
||||
size=20.0,
|
||||
resolution=64, # 🧠 Mniejsze resolution = lepsze FPS
|
||||
wave_speed=0.01,
|
||||
wave_height=0.5,
|
||||
wave_scale=(0.4, 0.6),
|
||||
second_wave=True,
|
||||
color=(0.0, 0.4, 0.8),
|
||||
backface=True
|
||||
)
|
||||
self.water.set_position(15, 0, 15)
|
||||
self.water.set_texture("assets/water.png")
|
||||
self.water.set_uv_transform((10, 10), (0, 0))
|
||||
|
||||
# Pozycje
|
||||
self.meshes[0].set_position(0, 0, 0)
|
||||
self.meshes[1].set_position(0, 0, 5)
|
||||
self.meshes[2].set_position(2, 0, 0)
|
||||
self.meshes[3].set_position(-4, 0, 0)
|
||||
self.meshes[4].set_position(0, -4, 0)
|
||||
self.meshes[5].set_position(-8, 0, 0)
|
||||
|
||||
# Skale
|
||||
self.meshes[2].scale_uniform(2)
|
||||
self.meshes[3].set_scale(1, 0.2, 1)
|
||||
self.meshes[4].scale_uniform(15)
|
||||
self.meshes[5].scale_uniform(0.5)
|
||||
|
||||
# Tekstury
|
||||
for i in range(6):
|
||||
self.meshes[i].set_texture("assets/bricksx64.png")
|
||||
|
||||
# UV
|
||||
self.meshes[5].set_uv_transform(tiling=(10, 10), offset=(0.1, 0.1))
|
||||
self.meshes[4].set_uv_transform(tiling=(10, 10), offset=(0.1, 0.1))
|
||||
self.meshes[1].set_uv_transform(tiling=(5, 5), offset=(0.1, 0.1))
|
||||
self.meshes[2].set_uv_transform(tiling=(5, 5), offset=(0.1, 0.1))
|
||||
|
||||
# OpenGL ustawienia
|
||||
glEnable(GL_DEPTH_TEST)
|
||||
glEnable(GL_CULL_FACE)
|
||||
glCullFace(GL_BACK)
|
||||
|
||||
def update(self, dt, window):
|
||||
self.camera.handle_input(dt, window)
|
||||
|
||||
glViewport(0, 0, self.WIDTH, self.HEIGHT)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||
|
||||
self.listener.position[:] = self.camera.position
|
||||
|
||||
cam_pos = self.camera.position
|
||||
cam_dir = m3d.normalize(self.camera.target - cam_pos)
|
||||
view_proj = self.camera.view_proj_matrix
|
||||
|
||||
m3d.update_audio_system(self.listener, self.sources)
|
||||
|
||||
if (
|
||||
self.water.is_in_fov(cam_pos, cam_dir, self.camera.fov)
|
||||
and np.linalg.norm(self.water.position - cam_pos) < 150
|
||||
):
|
||||
self.water.update_water()
|
||||
self.water.shader.use()
|
||||
self.camera.set_uniforms(self.water.shader)
|
||||
self.water.draw(
|
||||
cam_pos=cam_pos,
|
||||
cam_dir=cam_dir,
|
||||
fov_deg=self.camera.fov,
|
||||
view_proj_matrix=view_proj
|
||||
)
|
||||
|
||||
# Rysuj inne meshe
|
||||
for mesh in self.meshes:
|
||||
if (
|
||||
not mesh.is_in_fov(cam_pos, cam_dir, self.camera.fov)
|
||||
or np.linalg.norm(mesh.position - cam_pos) > 150
|
||||
):
|
||||
continue
|
||||
|
||||
mesh.shader.use()
|
||||
self.camera.set_uniforms(mesh.shader)
|
||||
mesh.draw(
|
||||
cam_pos=cam_pos,
|
||||
cam_dir=cam_dir,
|
||||
fov_deg=self.camera.fov,
|
||||
view_proj_matrix=view_proj,
|
||||
debug=False
|
||||
)
|
||||
|
||||
# FPS tracking
|
||||
self.frames += 1
|
||||
current_time = time.time()
|
||||
if current_time - self.last_fps_time >= 1.0:
|
||||
print(f"FPS: {self.frames}")
|
||||
self.frames = 0
|
||||
self.last_fps_time = current_time
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
m3d.init()
|
||||
self.window.run(self.update)
|
||||
finally:
|
||||
self.water.destroy()
|
||||
for mesh in self.meshes:
|
||||
mesh.destroy()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = Game()
|
||||
app.run()
|
||||
73
examples/test.py
Normal file
73
examples/test.py
Normal file
@@ -0,0 +1,73 @@
|
||||
import time
|
||||
import my3dengine as m3d
|
||||
from my3dengine.camera import Camera
|
||||
from OpenGL.GL import *
|
||||
|
||||
class Game:
|
||||
def __init__(self):
|
||||
self.WIDTH, self.HEIGHT = m3d.get_fullscreen()
|
||||
self.window = m3d.Window("3D Game", self.WIDTH, self.HEIGHT)
|
||||
self.keys = m3d.Key
|
||||
self.escape_was_pressed = False
|
||||
|
||||
self.camera = Camera(
|
||||
position=(20, 20, 50),
|
||||
target=(8, 8, 8),
|
||||
up=(0, 1, 0),
|
||||
fov=60,
|
||||
aspect=self.WIDTH / self.HEIGHT,
|
||||
)
|
||||
|
||||
self.base = m3d.Mesh.from_obj("assets/untitled.obj")
|
||||
self.base.set_texture("assets/bricksx64.png")
|
||||
|
||||
spacing = 1.1
|
||||
self.positions = []
|
||||
for x in range(4):
|
||||
for y in range(4):
|
||||
for z in range(4):
|
||||
self.positions.append((x * spacing, y * spacing, z * spacing))
|
||||
|
||||
# FPS counter
|
||||
self.last_fps_time = time.time()
|
||||
self.frames = 0
|
||||
|
||||
def update(self, dt, window):
|
||||
self.camera.handle_input(dt, window)
|
||||
|
||||
glViewport(0, 0, self.WIDTH, self.HEIGHT)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||
|
||||
view = self.camera.view_matrix
|
||||
proj = self.camera.projection_matrix
|
||||
view_proj = proj @ view
|
||||
|
||||
# Rysujemy tę samą siatkę w wielu pozycjach
|
||||
for pos in self.positions:
|
||||
self.base.set_position(*pos)
|
||||
self.base.draw(
|
||||
cam_pos=self.camera.position,
|
||||
cam_dir=m3d.normalize(self.camera.target - self.camera.position),
|
||||
fov_deg=self.camera.fov,
|
||||
view_proj_matrix=view_proj,
|
||||
debug=False
|
||||
)
|
||||
|
||||
# FPS tracking
|
||||
self.frames += 1
|
||||
current_time = time.time()
|
||||
if current_time - self.last_fps_time >= 1.0:
|
||||
print(f"FPS: {self.frames}")
|
||||
self.frames = 0
|
||||
self.last_fps_time = current_time
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
m3d.init()
|
||||
self.window.run(self.update)
|
||||
finally:
|
||||
self.base.destroy()
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = Game()
|
||||
app.run()
|
||||
Reference in New Issue
Block a user