Skip to content

Commit

Permalink
Universal ObjectAttacher, python command line launch, threading, Test…
Browse files Browse the repository at this point in the history
…Site init, Cactus's
  • Loading branch information
MatinAfzal committed Jul 30, 2024
1 parent 82e5acc commit 11029cc
Show file tree
Hide file tree
Showing 13 changed files with 359 additions and 161 deletions.
35 changes: 24 additions & 11 deletions main/Engine2/CellAttach.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import threading
from main.Engine2.Mesh import *
from main.Engine2.Settings2 import *
from .Mesh import *
from .Settings2 import *


class CellAttach:
Expand All @@ -13,6 +13,8 @@ class CellAttach:
def __init__(self, cells: list[object], draw_type=GL_TRIANGLES, shader=None, image=None) -> None:
if ESP:
print("Attaching Cells...")

self.level_name = cells[0].level_name
self.image = image
self.cells = cells

Expand Down Expand Up @@ -81,12 +83,23 @@ def load_world(self):
self.colors.append(CHUNK_COLOR_G)
self.colors.append(CHUNK_COLOR_B)

self.world = Mesh(
vertices=self.world_formatted_vertices,
imagefile=self.image,
material=self.world_shader,
draw_type=self.world_draw_type,
vertex_colors=self.colors,
vertex_uvs=self.world_formatted_uvs,
vertex_normals=self.world_formatted_normals
)
if self.level_name == "tree1":
self.world = Mesh(
vertices=self.world_formatted_vertices,
imagefile=self.image,
material=self.world_shader,
draw_type=self.world_draw_type,
vertex_colors=self.colors,
vertex_uvs=self.world_formatted_uvs,
vertex_normals=self.world_formatted_normals
)
else:
self.world = Mesh(
vertices=self.world_formatted_vertices,
imagefile=self.image,
material=self.world_shader,
draw_type=self.world_draw_type,
vertex_colors=self.colors,
vertex_uvs=self.world_formatted_uvs,
vertex_normals=self.world_formatted_normals
)
2 changes: 1 addition & 1 deletion main/Engine2/Cullings/DistanceCulling.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pygame
from math import sqrt
from main.Engine2.Settings2 import *
from Engine2.Settings2 import *


class DistanceCulling:
Expand Down
4 changes: 3 additions & 1 deletion main/Engine2/Screen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# This file prepares the page with initial processing settings and executes the main loop
import datetime
import os

import pygame
from pygame.locals import *
from .Camera import *
from .Settings2 import *
Expand Down Expand Up @@ -28,7 +30,7 @@ def __init__(self, screen_posX, screen_posY, screen_width, screen_height):
pygame.display.gl_set_attribute(pygame.GL_CONTEXT_PROFILE_MASK, pygame.GL_CONTEXT_PROFILE_CORE)
pygame.display.gl_set_attribute(pygame.GL_DEPTH_SIZE, 24) # GPU DEPTH BUFFER SIZE

self.screen = pygame.display.set_mode((screen_width, screen_height), DOUBLEBUF | OPENGL)
self.screen = pygame.display.set_mode((screen_width, screen_height), DOUBLEBUF | OPENGL, pygame.FULLSCREEN)
pygame.display.set_caption(SCREEN_CAPTION_LOADING)
self.clock = pygame.time.Clock()
self.camera = None
Expand Down
10 changes: 5 additions & 5 deletions main/Engine2/Settings2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from OpenGL.GL import GL_LINES

# Debug settings
ENGINE_STATUS_PRINT = False
ENGINE_STATUS_PRINT = True
ENGINE_REPORT_SAVE = False
ESP = ENGINE_STATUS_PRINT

Expand Down Expand Up @@ -44,10 +44,10 @@
# SCREEN_POS_Y = 200
SCREEN_POS_X = 100
SCREEN_POS_Y = 30
# SCREEN_WIDTH = 1000
# SCREEN_HEIGHT = 800
SCREEN_WIDTH = 1800
SCREEN_HEIGHT = 1000
SCREEN_WIDTH = 1920
SCREEN_HEIGHT = 1080
# SCREEN_WIDTH = 1800
# SCREEN_HEIGHT = 1000
SCREEN_MULTISAMPLEBUFFERS = 1
SCREEN_MULTISAMPLESAMPLES = 4
SCREEN_DEPTH_SIZE = 24
Expand Down
57 changes: 16 additions & 41 deletions main/ICU.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
from main.Engine2.Screen import *
from main.Engine2.LoadObject import *
from main.Engine2.Light import *
from main.Engine2.Material import *
from main.Engine2.Axes import *
from main.Engine2.CellAttach import *
from main.Engine2.Settings2 import *
from main.Level.ChunkAttach import *
from main.Level.TreeAttach import *
from main.Level.Chunk import *
from main.Engine2.Cullings.DistanceCulling import *
from main.Level.Shematic import *
from Engine2.Screen import *
from Engine2.LoadObject import *
from Engine2.Light import *
from Engine2.Material import *
from Engine2.Axes import *
from Engine2.CellAttach import *
from Level.ObjectAttach import *
from Engine2.Cullings.DistanceCulling import *
from Level.Shematic import *
from time import sleep
from datetime import datetime
from time import time
from math import sqrt


class MultiShaders(Screen):
Expand Down Expand Up @@ -58,6 +54,7 @@ def __init__(self):
self.img_texture = r"Textures\texture.png"
self.img_icu = r"Textures\ICU.png"
self.img_sun = r"Textures\sun.jpeg"
self.img_cactus = r"Textures\cactus.png"

# Loads
if ESP:
Expand Down Expand Up @@ -94,17 +91,16 @@ def __init__(self):
self.sun_start = int(time())

# Object Attach
# self.terrain = ChunkAttach(numberx=30, numberz=30, shader=self.mat, texture=self.img_texture)
self.terrain = ChunkAttach(numberx=15, numberz=15)
self.trees = TreeAttach(numberx=15, numberz=15)
self.terrain = ObjectAttach(object_name="chunk", number_x=10, number_z=10)
self.trees = ObjectAttach(object_name="tree", number_x=10, number_z=10)

# Cell Attaches
cell_start = datetime.now()
if ESP:
print("Cell Attach started at:" + str(cell_start.now()))

self.world = CellAttach(self.terrain.terrain, shader=self.mat, image=self.img_texture)
self.forest = CellAttach(self.trees.forest, shader=self.mat, image=self.img_texture)
self.world = CellAttach(self.terrain.layer, shader=self.mat, image=self.img_texture)
self.forest = CellAttach(self.trees.layer, shader=self.mat, image=self.img_texture)

def initialise(self):
# Variables
Expand All @@ -124,8 +120,8 @@ def camera_init(self):

def display(self):
# glClearColor(0.5, 0.5 ,0.5, 0.5) # Middle gray
# glClearColor(0.58, 0.85 ,0.94, 0.5) # Sky blue
glClearColor(0, 0 ,0, 0.5) # Sky night
glClearColor(0.58, 0.85, 0.94, 0.5) # Sky blue
# glClearColor(0, 0 ,0, 0.5) # Sky night
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

#####
Expand Down Expand Up @@ -185,27 +181,6 @@ def display(self):
if self.x_counter == 0:
self.axes.draw(self.camera, self.light)

# camera_a_position = pygame.Vector3(self.camera.transformation[0, 3], self.camera.transformation[1, 3], self.camera.transformation[2, 3])
# index = 0
# for chunk in self.terrain.terrain:
# if self.culling_distance.chunk_in_distance(self.camera, chunk):
# chunk.draw(self.camera, self.light)
# else:
# camera_b_position = pygame.Vector3(self.camera.transformation[0, 3], self.camera.transformation[1, 3], self.camera.transformation[2, 3])
# move_direction = self.culling_distance.direction_calculator(camera_a_position, camera_b_position)
# if move_direction:
# new_chunk_coordinates = self.culling_distance.coordinates_calculator(self.terrain.terrain[index], move_direction)
# self.terrain.terrain.pop(index)
# shematic_aaa = np.ones(shape=(8, 8)) * 2
# new_chunk = Chunk(position=new_chunk_coordinates, shematic=shematic_aaa, img=self.img_texture, material=self.mat)
# self.terrain.terrain.append(new_chunk)
# index += 1

# glEnable(GL_CULL_FACE)
# glCullFace(GL_BACK)
# self.world.world.draw(self.camera, self.light)

# glDisable(GL_CULL_FACE)
self.world.world.draw(self.camera, self.light)
self.forest.world.draw(self.camera, self.light)
self.cube0.draw(self.camera, self.light)
Expand Down
183 changes: 183 additions & 0 deletions main/Level/Cactus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
from Engine2.Utils import format_vertices


class Cactus:
def __init__(self, position, max_height=4, min_height=0, biome="A", img=None, material=None, shematic=None) -> None:
"""
cactus generator
Args:
position (pcenter_ygame.Vector3): tree center vertex position
max_height (int): tree maximum height
min_height (int): tree minimum depth
biome (str): tree biome
"""

self.level_name = "tree1"
self.position = position
self.max_height = max_height
self.min_height = min_height
self.biome = biome
self.image = img
self.material = material
self.texture = img
self.colors = []
self.normals = None
self.leaf_area = [4, 4]
self.shematic = shematic

self.vertices, self.triangles, uvs, uvs_ind, normals, normals_ind = self.level_maker(self.position)
self.vertices = format_vertices(self.vertices, self.triangles)
self.vertex_uvs = format_vertices(uvs, uvs_ind)
self.normals = format_vertices(normals, normals_ind)

for _ in range(len(self.vertices)):
self.colors.append(1)
self.colors.append(1)
self.colors.append(1)

def level_maker(self, center):
"""Tree level maker
Args:
center (pygame.Vector3): chunk center position
Sample:
[TLU, TRU] \n
[TLD, TRD] \n
| | \n
[BLU, BRU] \n
[BLD, BRD] \n
"""

level_vertices = []
level_triangles = []
level_uvs = []
level_uvs_ind = []
level_normals = []
level_normals_ind = []
separator = 0
uv_counter = 0
normal_counter = 0
normals = [(0.0, 0.0, 1.0), (0.0, 0.0, 1.0), (0.0, 0.0, 1.0), (0.0, 0.0, 1.0), (0.0, 1.0, 0.0), (0.0, 1.0, 0.0),
(0.0, 1.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, -1.0), (0.0, 0.0, -1.0), (0.0, 0.0, -1.0),
(0.0, 0.0, -1.0), (0.0, -1.0, 0.0), (0.0, -1.0, 0.0), (0.0, -1.0, 0.0), (0.0, -1.0, 0.0),
(1.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.0, 0.0, 0.0), (-1.0, 0.0, 0.0),
(-1.0, 0.0, 0.0), (-1.0, 0.0, 0.0), (-1.0, 0.0, 0.0)]

center_y = int(self.shematic[3][3]) + 1

# Tree base
for _ in range(0, self.max_height):
# Top vertices
TLU = (center.x - 1, center_y, center.z - 1)
TLD = (center.x - 1, center_y, center.z + 0)
TRU = (center.x + 0, center_y, center.z - 1)
TRD = (center.x + 0, center_y, center.z + 0)

# Bottom vertices
BLU = (center.x - 1, center_y - 1, center.z - 1)
BLD = (center.x - 1, center_y - 1, center.z + 0)
BRU = (center.x + 0, center_y - 1, center.z - 1)
BRD = (center.x + 0, center_y - 1, center.z + 0)

level_vertices.extend([TLU, TLD, TRU, TRD, BLU, BLD, BRU, BRD])
level_triangles.extend([
0 + 8 * separator, 1 + 8 * separator, 2 + 8 * separator, # TRIANGLE 1
2 + 8 * separator, 1 + 8 * separator, 3 + 8 * separator, # TRIANGLE 2
4 + 8 * separator, 5 + 8 * separator, 6 + 8 * separator, # TRIANGLE 3
6 + 8 * separator, 5 + 8 * separator, 7 + 8 * separator, # TRIANGLE 4
1 + 8 * separator, 5 + 8 * separator, 3 + 8 * separator, # TRIANGLE 5
3 + 8 * separator, 5 + 8 * separator, 7 + 8 * separator, # TRIANGLE 6
0 + 8 * separator, 4 + 8 * separator, 2 + 8 * separator, # TRINAGLE 7
2 + 8 * separator, 4 + 8 * separator, 6 + 8 * separator, # TRIANGLE 8
4 + 8 * separator, 0 + 8 * separator, 5 + 8 * separator, # TRIANGLE 9
5 + 8 * separator, 0 + 8 * separator, 1 + 8 * separator, # TRIANGLE 10
6 + 8 * separator, 2 + 8 * separator, 7 + 8 * separator, # TRIANGLE 11
7 + 8 * separator, 2 + 8 * separator, 3 + 8 * separator, # TRIANGLE 12
])

separator += 1
center_y += 1

# Texture atlas locations
atlas_length = 1
atlas_height = 1
HM_F = 0 # Horizontal Multiplier to first border
HM_L = 1 # Horizontal Multiplier to last border
VM_F = 0 # Vertical Multiplier to first border
VM_L = 1 # Vertical Multiplier to last border
BD = 0.0000000099 # border_deficiency
ONE = 1 + BD

uvs_face = [
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_L),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_L),
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_L),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_L),
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_L),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_L),
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_L),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_L),
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_L),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_L),
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_F),
(ONE / atlas_length * HM_F, ONE / atlas_height * VM_L),
(ONE / atlas_length * HM_L, ONE / atlas_height * VM_L)
]

# UV vertices
for i in range(24):
level_uvs.append(uvs_face[i])

# UV triangles
level_uvs_ind.extend([
20 + 24 * uv_counter, 21 + 24 * uv_counter, 22 + 24 * uv_counter, # TRIANGLE 1
22 + 24 * uv_counter, 21 + 24 * uv_counter, 23 + 24 * uv_counter, # TRIANGLE 2
4 + 24 * uv_counter, 5 + 24 * uv_counter, 6 + 24 * uv_counter, # TRIANGLE 3
6 + 24 * uv_counter, 5 + 24 * uv_counter, 7 + 24 * uv_counter, # TRIANGLE 4
8 + 24 * uv_counter, 9 + 24 * uv_counter, 10 + 24 * uv_counter, # TRIANGLE 5
10 + 24 * uv_counter, 9 + 24 * uv_counter, 11 + 24 * uv_counter, # TRIANGLE 6
16 + 24 * uv_counter, 17 + 24 * uv_counter, 18 + 24 * uv_counter, # TRIANGLE 7
18 + 24 * uv_counter, 17 + 24 * uv_counter, 19 + 24 * uv_counter, # TRIANGLE 8
0 + 24 * uv_counter, 1 + 24 * uv_counter, 2 + 24 * uv_counter, # TRIANGLE 9
2 + 24 * uv_counter, 1 + 24 * uv_counter, 3 + 24 * uv_counter, # TRIANGLE 10
12 + 24 * uv_counter, 13 + 24 * uv_counter, 14 + 24 * uv_counter, # TRIANGLE 11
14 + 24 * uv_counter, 13 + 24 * uv_counter, 15 + 24 * uv_counter, # TRIANGLE 12
])

uv_counter += 1

# Normals
for i in range(24):
level_normals.append(normals[i])

level_normals_ind.extend([
0 + 24 * normal_counter, 1 + 24 * normal_counter, 2 + 24 * normal_counter,
2 + 24 * normal_counter, 1 + 24 * normal_counter, 3 + 24 * normal_counter,
4 + 24 * normal_counter, 5 + 24 * normal_counter, 6 + 24 * normal_counter,
6 + 24 * normal_counter, 5 + 24 * normal_counter, 7 + 24 * normal_counter,
8 + 24 * normal_counter, 9 + 24 * normal_counter, 10 + 24 * normal_counter,
10 + 24 * normal_counter, 9 + 24 * normal_counter, 11 + 24 * normal_counter,
12 + 24 * normal_counter, 13 + 24 * normal_counter, 14 + 24 * normal_counter,
14 + 24 * normal_counter, 13 + 24 * normal_counter, 15 + 24 * normal_counter,
16 + 24 * normal_counter, 17 + 24 * normal_counter, 18 + 24 * normal_counter,
18 + 24 * normal_counter, 17 + 24 * normal_counter, 19 + 24 * normal_counter,
20 + 24 * normal_counter, 21 + 24 * normal_counter, 22 + 24 * normal_counter,
22 + 24 * normal_counter, 21 + 24 * normal_counter, 23 + 24 * normal_counter
])

normal_counter += 1

return level_vertices, level_triangles, level_uvs, level_uvs_ind, level_normals, level_normals_ind
Loading

0 comments on commit 11029cc

Please sign in to comment.