Skip to content

Commit

Permalink
Merge pull request #40 from papagiannakis/develop
Browse files Browse the repository at this point in the history
Release 1.2.1
  • Loading branch information
kamarianakis authored Sep 22, 2023
2 parents 74b698f + db5a774 commit 7b8c140
Show file tree
Hide file tree
Showing 48 changed files with 564 additions and 323 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,8 @@ imgui.ini
data/GeometricShapes
*.off
*.pt
Elements/.vscode/settings.json
.vscode/settings.json

#dataset
Elements/pyEEL/notebooks/SciCom/db
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"./Elements",
"-p",
"test_*.py"
"*test*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
Expand Down
2 changes: 1 addition & 1 deletion Elements/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# 1) we don't load dependencies by storing it in __init__.py
# 2) we can import it in setup.py for the same reason
# 3) we can import it into your module
__version__ = '1.2.0'
__version__ = '1.2.1'
16 changes: 9 additions & 7 deletions Elements/definitions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
from pathlib import Path

ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_DIR = Path(__file__).parent

MODEL_DIR = os.path.join(ROOT_DIR, "files", "models")
TEXTURE_DIR = os.path.join(ROOT_DIR, "files", "textures")
SCENES_DIR = os.path.join(ROOT_DIR, "files", "scenes")
SCV_DIR = os.path.join(ROOT_DIR, "files", "scv")
ATLAS_DIR = os.path.join(ROOT_DIR, "files", "atlas_files")
PICKLES_DIR = os.path.join(ROOT_DIR, "files", "pickles")
MODEL_DIR = ROOT_DIR / "files" / "models"
TEXTURE_DIR = ROOT_DIR / "files" / "textures"
SCENES_DIR = ROOT_DIR / "files" / "scenes"
SCV_DIR = ROOT_DIR / "files" / "scv"
ATLAS_DIR = ROOT_DIR / "files" / "atlas_files"
PICKLES_DIR = ROOT_DIR / "files" / "pickles"
SHADER_DIR = ROOT_DIR / "files" / "shaders"
3 changes: 0 additions & 3 deletions Elements/examples/1.Introductory/example_0_ComponentSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
Examples using ECS
This is code examples that create entities, components and systems
Elements.pyECSS (Entity Component Systems in a Scenegraph) package
@Copyright 2021-2022 Dr. George Papagiannakis
"""

from Elements.pyECSS.Entity import Entity
Expand Down
2 changes: 1 addition & 1 deletion Elements/examples/1.Introductory/example_1_empty_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from Elements.pyGLV.GUI.Viewer import SDL2Window

gWindow = SDL2Window(openGLversion=4)
gWindow = SDL2Window(openGLversion=4, windowTitle="A simple empty SDL WINDOW. Hit ESC OR Close the window to quit!")
gWindow.init()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
Running the basic RenderWindow (SDL2Window) with an ImGUIDecorator on top
"""


from Elements.pyGLV.GUI.Viewer import SDL2Window, ImGUIDecorator

from Elements.utils.helper_function import displayGUI_text
example_description = "This is a simple empty scene with ImGUI enabled. Feel free to add your own widgets!"


gWindow = SDL2Window()
gGUI = ImGUIDecorator(gWindow)
Expand All @@ -16,6 +18,7 @@
running = True
while running:
gGUI.display()
displayGUI_text(example_description)
running = gGUI.event_input_process()
gGUI.display_post()
gGUI.shutdown()
8 changes: 7 additions & 1 deletion Elements/examples/1.Introductory/example_3_cube_lookAt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from Elements.pyGLV.GL.Shader import InitGLShaderSystem, Shader, ShaderGLDecorator, RenderGLShaderSystem
from Elements.pyGLV.GL.VertexArray import VertexArray

from Elements.utils.helper_function import displayGUI_text
example_description = \
"This is a scene with some simple geometry, i.e., a colored cube. \n\
The cube and axes are rendered with a simple shader. \n\
You cannot move the camera through the GUI. Hit ESC OR Close the window to quit."

winWidth = 1024
winHeight = 768
Expand Down Expand Up @@ -101,14 +106,15 @@

running = True
# MAIN RENDERING LOOP
scene.init(imgui=False, windowWidth = winWidth, windowHeight = winHeight, windowTitle = "A Cube Scene via ECSS")
scene.init(imgui=True, windowWidth = winWidth, windowHeight = winHeight, windowTitle = "A Cube Scene via ECSS")

# pre-pass scenegraph to initialise all GL context dependent geometry, shader classes
# needs an active GL context
scene.world.traverse_visit(initUpdate, scene.world.root)

while running:
running = scene.render()
displayGUI_text(example_description)
scene.world.traverse_visit(renderUpdate, scene.world.root)
scene.render_post()

Expand Down
26 changes: 15 additions & 11 deletions Elements/examples/1.Introductory/example_4_cube_axes_terrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

from OpenGL.GL import GL_LINES

from Elements.utils.helper_function import displayGUI_text
example_description = \
"This is a scene with a cube, a terrain and axes. \n\
The cube and axes are rendered with a simple shader. \n\
You move the camera through the GUI or the camera. Hit ESC OR Close the window to quit."

winWidth = 1024
winHeight = 768

Expand Down Expand Up @@ -44,11 +50,6 @@
mesh4 = scene.world.addComponent(node4, RenderMesh(name="mesh4"))


axes = scene.world.createEntity(Entity(name="axes"))
scene.world.addEntityChild(rootEntity, axes)
axes_trans = scene.world.addComponent(axes, BasicTransform(name="axes_trans", trs=util.identity()))
axes_mesh = scene.world.addComponent(axes, RenderMesh(name="axes_mesh"))

# a simple triangle
vertexData = np.array([
[0.0, 0.0, 0.0, 1.0],
Expand Down Expand Up @@ -148,7 +149,7 @@
## ADD AXES ##
axes = scene.world.createEntity(Entity(name="axes"))
scene.world.addEntityChild(rootEntity, axes)
axes_trans = scene.world.addComponent(axes, BasicTransform(name="axes_trans", trs=util.identity()))
axes_trans = scene.world.addComponent(axes, BasicTransform(name="axes_trans", trs=util.translate(0.0, 0.001, 0.0)))
axes_mesh = scene.world.addComponent(axes, RenderMesh(name="axes_mesh"))
axes_mesh.vertex_attributes.append(vertexAxes)
axes_mesh.vertex_attributes.append(colorAxes)
Expand Down Expand Up @@ -205,21 +206,24 @@
## OR
# model_cube = trans4.trs @ util.scale(0.3) @ util.translate(0.0,0.5,0.0) ## TAMPER WITH OBJECT's TRS

model_terrain_axes = terrain.getChild(0).trs # notice that terrain.getChild(0) == terrain_trans
model_terrain = terrain.getChild(0).trs # notice that terrain.getChild(0) == terrain_trans
# OR
# model_terrain_axes = util.translate(0.0,0.0,0.0) ## COMPLETELY OVERRIDE OBJECT's TRS
# model_terrain = util.translate(0.0,0.0,0.0) ## COMPLETELY OVERRIDE OBJECT's TRS
model_axes = axes_trans.trs

while running:
running = scene.render()
displayGUI_text(example_description)
scene.world.traverse_visit(renderUpdate, scene.world.root)
scene.world.traverse_visit_pre_camera(camUpdate, orthoCam)
scene.world.traverse_visit(camUpdate, scene.world.root)

view = gWindow._myCamera # updates view via the imgui
mvp_cube = projMat @ view @ model_cube
mvp_terrain_axes = projMat @ view @ model_terrain_axes
axes_shader.setUniformVariable(key='modelViewProj', value=mvp_terrain_axes, mat4=True)
terrain_shader.setUniformVariable(key='modelViewProj', value=mvp_terrain_axes, mat4=True)
mvp_terrain = projMat @ view @ model_terrain
mvp_axes = projMat @ view @ model_axes
axes_shader.setUniformVariable(key='modelViewProj', value=mvp_axes, mat4=True)
terrain_shader.setUniformVariable(key='modelViewProj', value=mvp_terrain, mat4=True)
shaderDec4.setUniformVariable(key='modelViewProj', value=mvp_cube, mat4=True)
scene.render_post()

Expand Down
7 changes: 7 additions & 0 deletions Elements/examples/1.Introductory/example_5_lights_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
from Elements.utils.terrain import generateTerrain
from Elements.utils.obj_to_mesh import obj_to_mesh

from Elements.utils.helper_function import displayGUI_text
example_description = \
"This is a scene with a cube, a terrain and axes. The scene is being lit using \n\
the Blinn-Phong algorithm. You may move the camera using the mouse or the GUI. \n\
You may see the ECS Scenegraph showing Entities & Components of the scene and \n\
various information about them. Hit ESC OR Close the window to quit."

#Light
Lposition = util.vec(2.0, 5.5, 2.0) #uniform lightpos
Expand Down Expand Up @@ -222,6 +228,7 @@

while running:
running = scene.render()
displayGUI_text(example_description)
scene.world.traverse_visit(renderUpdate, scene.world.root)
scene.world.traverse_visit_pre_camera(camUpdate, orthoCam)
scene.world.traverse_visit(camUpdate, scene.world.root)
Expand Down
15 changes: 12 additions & 3 deletions Elements/examples/1.Introductory/example_6_import_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
from Elements.utils.terrain import generateTerrain
from Elements.utils.obj_to_mesh import obj_to_mesh

from Elements.utils.helper_function import displayGUI_text
example_description = \
"This is a scene with the famous Newell teapot. This example demonstrates the \n\
ability to load complex objects instead of inputing them manually. \n\
The scene is being lit using the Blinn-Phong algorithm. \n\
You may move the camera using the mouse or the GUI. \n\
You may see the ECS Scenegraph showing Entities & Components of the scene and \n\
various information about them. Hit ESC OR Close the window to quit."

#Light
Lposition = util.vec(2.0, 5.5, 2.0) #uniform lightpos
Expand Down Expand Up @@ -112,9 +120,9 @@
## object load

# NOTICE THAT OBJECTS WITH UVs are currently NOT SUPPORTED
obj_to_import = os.path.join(MODEL_DIR, "teapot.obj")
# obj_to_import = os.path.join(models_dirname, "cow.obj")
# obj_to_import = os.path.join(models_dirname, "teddy.obj")
obj_to_import = MODEL_DIR / "teapot.obj"
# obj_to_import = MODEL_DIR / "cow.obj"
# obj_to_import = MODEL_DIR / "teddy.obj"

obj_color = [168/255, 168/255 , 210/255, 1.0]
vert , ind, col = obj_to_mesh(obj_to_import, color=obj_color)
Expand Down Expand Up @@ -202,6 +210,7 @@

while running:
running = scene.render()
displayGUI_text(example_description)
scene.world.traverse_visit(renderUpdate, scene.world.root)
scene.world.traverse_visit_pre_camera(camUpdate, orthoCam)
scene.world.traverse_visit(camUpdate, scene.world.root)
Expand Down
29 changes: 20 additions & 9 deletions Elements/examples/2.Intermediate/example_10_cube_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@

from Elements.definitions import TEXTURE_DIR

from Elements.utils.helper_function import displayGUI_text
example_description = \
"This example demonstrates the cube map texture, i.e., \n\
we encapsulate the scene into a huge cube and apply texture to them\n\
creating the illusion of a scenery. \n\
You may move the camera using the mouse or the GUI. \n\
You may see the ECS Scenegraph showing Entities & Components of the scene and \n\
various information about them. Hit ESC OR Close the window to quit."


winWidth = 1024
winHeight = 768
scene = Scene()
Expand Down Expand Up @@ -144,17 +154,17 @@

gWindow._myCamera = view # otherwise, an imgui slider must be moved to properly update

# skybox_texture_locations = os.path.join(TEXTURE_DIR, "Skyboxes", "Cloudy")
skybox_texture_locations = os.path.join(TEXTURE_DIR, "Skyboxes", "Sea")
front_img = os.path.join(skybox_texture_locations, "front.jpg")
right_img = os.path.join(skybox_texture_locations,"right.jpg")
left_img = os.path.join(skybox_texture_locations,"left.jpg")
back_img = os.path.join(skybox_texture_locations,"back.jpg")
bottom_img = os.path.join(skybox_texture_locations,"bottom.jpg")
top_img = os.path.join(skybox_texture_locations,"top.jpg")
# skybox_texture_locations = TEXTURE_DIR / "Skyboxes" / "Cloudy"
skybox_texture_locations = TEXTURE_DIR / "Skyboxes" / "Sea"
front_img = skybox_texture_locations / "front.jpg"
right_img = skybox_texture_locations / "right.jpg"
left_img = skybox_texture_locations / "left.jpg"
back_img = skybox_texture_locations / "back.jpg"
bottom_img = skybox_texture_locations / "bottom.jpg"
top_img = skybox_texture_locations / "top.jpg"


mat_img = os.path.join(TEXTURE_DIR, "dark_wood_texture.jpg")
mat_img = TEXTURE_DIR / "dark_wood_texture.jpg"

face_data = get_texture_faces(front_img,back_img,top_img,bottom_img,left_img,right_img)
face_data_2 = get_single_texture_faces(mat_img)
Expand All @@ -166,6 +176,7 @@

while running:
running = scene.render()
displayGUI_text(example_description)
scene.world.traverse_visit(renderUpdate, scene.world.root)
scene.world.traverse_visit_pre_camera(camUpdate, orthoCam)
scene.world.traverse_visit(camUpdate, scene.world.root)
Expand Down
14 changes: 11 additions & 3 deletions Elements/examples/2.Intermediate/example_7_cameraSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
from Elements.utils.normals import Convert
from OpenGL.GL import GL_LINES

from Elements.utils.helper_function import displayGUI_text
example_description = \
"This is the first examples that demonstrates the usage of the Camera System \n\
instead of the use of the lookAt function to create the view matrix. \n\
You may move the camera using the mouse or the ECSS Graph. \n\n\
NOTE: To change any TRS via the ECSS GUI, only this TRS must be toggled on!\n\n\
You may see the ECS Scenegraph showing Entities & Components of the scene and \n\
various information about them. Hit ESC OR Close the window to quit."


class GameObjectEntity(Entity):
def __init__(self, name=None, type=None, id=None) -> None:
Expand Down Expand Up @@ -242,9 +251,7 @@ def main(imguiFlag = False):


while running:
#running = scene._gContext.event_input_process()
#if not running :
# continue

scene.world.traverse_visit(transUpdate, scene.world.root)
scene.world.traverse_visit_pre_camera(camUpdate, mainCamera.camera)
scene.world.traverse_visit(camUpdate, scene.world.root)
Expand All @@ -256,6 +263,7 @@ def main(imguiFlag = False):

# call SDLWindow/ImGUI display() and ImGUI event input process
running = scene.render()
displayGUI_text(example_description)
# call the GL State render System
scene.world.traverse_visit(renderUpdate, scene.world.root)
# ImGUI post-display calls and SDLWindow swap
Expand Down
10 changes: 9 additions & 1 deletion Elements/examples/2.Intermediate/example_8_textures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

from OpenGL.GL import GL_LINES

from Elements.utils.helper_function import displayGUI_text
example_description = \
"This example demonstrates the ability to apply image textures to geometry. \n\
You may move the camera using the mouse or the GUI. \n\
You may see the ECS Scenegraph showing Entities & Components of the scene and \n\
various information about them. Hit ESC OR Close the window to quit."

winWidth = 1024
winHeight = 768
scene = Scene()
Expand Down Expand Up @@ -199,12 +206,13 @@
# OR
# model_terrain_axes = util.translate(0.0,0.0,0.0) ## COMPLETELY OVERRIDE OBJECT's TRS

texturePath = os.path.join(TEXTURE_DIR, "uoc_logo.png")
texturePath = TEXTURE_DIR / "uoc_logo.png"
texture = Texture(texturePath)
shaderDec4.setUniformVariable(key='ImageTexture', value=texture, texture=True)

while running:
running = scene.render()
displayGUI_text(example_description)
scene.world.traverse_visit(renderUpdate, scene.world.root)
scene.world.traverse_visit_pre_camera(camUpdate, orthoCam)
scene.world.traverse_visit(camUpdate, scene.world.root)
Expand Down
Loading

0 comments on commit 7b8c140

Please sign in to comment.