Skip to content

Commit

Permalink
Format all python files
Browse files Browse the repository at this point in the history
  • Loading branch information
Notexe committed Aug 30, 2023
1 parent d2a71de commit 2f79d74
Show file tree
Hide file tree
Showing 16 changed files with 1,990 additions and 1,013 deletions.
4 changes: 2 additions & 2 deletions BlenderUI.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import bpy


def MessageBox(message="", title="Glacier Engine", icon='INFO'):
def MessageBox(message="", title="Glacier Engine", icon="INFO"):
def draw(self, context):
self.layout.label(text=message)

bpy.context.window_manager.popup_menu(draw, title=title, icon=icon)
bpy.context.window_manager.popup_menu(draw, title=title, icon=icon)
49 changes: 25 additions & 24 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
from . import file_borg


from bpy.props import (BoolVectorProperty,
PointerProperty,
)
from bpy.props import (
BoolVectorProperty,
PointerProperty,
)

from bpy.types import (PropertyGroup,
)
from bpy.types import (
PropertyGroup,
)

# ------------------------------------------------------------------------
# Scene Properties
# ------------------------------------------------------------------------

class GlacierSettings(PropertyGroup):

class GlacierSettings(PropertyGroup):
def show_lod_update(self, context):

mesh_obs = [o for o in bpy.context.scene.objects if o.type == 'MESH']
mesh_obs = [o for o in bpy.context.scene.objects if o.type == "MESH"]
for obj in mesh_obs:

should_show = False
for bit in range(8):
if self.show_lod[bit]:
Expand All @@ -43,11 +43,11 @@ def show_lod_update(self, context):
return None

show_lod: BoolVectorProperty(
name='show_lod',
description='Set which LOD levels should be shown',
name="show_lod",
description="Set which LOD levels should be shown",
default=(True, True, True, True, True, True, True, True),
size=8,
subtype='LAYER',
subtype="LAYER",
update=show_lod_update,
)

Expand All @@ -56,11 +56,11 @@ def show_lod_update(self, context):
# Panels
# ------------------------------------------------------------------------
class GLACIER_PT_settingsPanel(bpy.types.Panel):
bl_idname = 'GLACIER_PT_settingsPanel'
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'Glacier'
bl_label = 'Settings'
bl_idname = "GLACIER_PT_settingsPanel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Glacier"
bl_label = "Settings"

def draw(self, context):
glacier_settings = context.scene.glacier_settings
Expand All @@ -69,24 +69,25 @@ def draw(self, context):
layout.label(text="show LOD:")

row = layout.row(align=True)
for i, name in enumerate(["high", " ", " ", " ", " ", " ", " ", "low"]):
for i, name in enumerate(
["high", " ", " ", " ", " ", " ", " ", "low"]
):
row.prop(glacier_settings, "show_lod", index=i, text=name, toggle=True)


# ------------------------------------------------------------------------
# Registration
# ------------------------------------------------------------------------

classes = [
GlacierSettings,
GLACIER_PT_settingsPanel
]
classes = [GlacierSettings, GLACIER_PT_settingsPanel]

modules = [
file_prim,
# file_mjba, # WIP module. enable at own risk
file_borg
file_borg,
]


def register():
from bpy.utils import register_class

Expand All @@ -107,7 +108,7 @@ def unregister():

for cls in classes:
unregister_class(cls)

del bpy.types.Scene.glacier_settings


Expand Down
103 changes: 83 additions & 20 deletions file_aloc/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import ctypes


class PhysicsDataType(enum.IntEnum):
NONE = 0
CONVEX_MESH = 1
Expand All @@ -11,12 +12,14 @@ class PhysicsDataType(enum.IntEnum):
PRIMITIVE = 4
CONVEX_MESH_AND_PRIMITIVE = 5
TRIANGLE_MESH_AND_PRIMITIVE = 6



class PhysicsCollisionType(enum.IntEnum):
NONE = 0
STATIC = 1
RIGIDBODY = 2


class PhysicsCollisionLayerType(enum.IntEnum):
COLLIDE_WITH_ALL = 0
STATIC_COLLIDABLES_ONLY = 1
Expand Down Expand Up @@ -50,66 +53,126 @@ class PhysicsCollisionLayerType(enum.IntEnum):
AI_VISION_BLOCKER_AMBIENT_ONLY = 29
UNUSED_LAST = 30


class PhysicsCollisionPrimitiveType(enum.IntEnum):
BOX = 0
CAPSULE = 1
SPHERE = 2


class PhysicsCollisionSettings(ctypes.Structure):
_fields_ = [
("data_type", ctypes.c_uint32),
("collider_type", ctypes.c_uint32),
]


class Physics:
def __init__(self):
self.data_type = PhysicsDataType.NONE
self.collision_type = PhysicsCollisionType.NONE
if not os.environ['PATH'].startswith(os.path.abspath(os.path.dirname(__file__))):
os.environ['PATH'] = os.path.abspath(os.path.dirname(__file__)) + os.pathsep + os.environ['PATH']
self.lib = ctypes.CDLL(os.path.abspath(os.path.join(os.path.dirname(__file__), "alocgen.dll")), winmode=0)
self.lib.AddConvexMesh.argtypes = (ctypes.c_uint32, ctypes.POINTER(ctypes.c_float), ctypes.c_uint32, ctypes.POINTER(ctypes.c_uint32), ctypes.c_uint64,)
if not os.environ["PATH"].startswith(
os.path.abspath(os.path.dirname(__file__))
):
os.environ["PATH"] = (
os.path.abspath(os.path.dirname(__file__))
+ os.pathsep
+ os.environ["PATH"]
)
self.lib = ctypes.CDLL(
os.path.abspath(os.path.join(os.path.dirname(__file__), "alocgen.dll")),
winmode=0,
)
self.lib.AddConvexMesh.argtypes = (
ctypes.c_uint32,
ctypes.POINTER(ctypes.c_float),
ctypes.c_uint32,
ctypes.POINTER(ctypes.c_uint32),
ctypes.c_uint64,
)
self.lib.AddConvexMesh.restype = ctypes.c_int
self.lib.AddTriangleMesh.argtypes = (ctypes.c_uint32, ctypes.POINTER(ctypes.c_float), ctypes.c_uint32, ctypes.POINTER(ctypes.c_uint32), ctypes.c_uint64,)
self.lib.AddTriangleMesh.argtypes = (
ctypes.c_uint32,
ctypes.POINTER(ctypes.c_float),
ctypes.c_uint32,
ctypes.POINTER(ctypes.c_uint32),
ctypes.c_uint64,
)
self.lib.AddTriangleMesh.restype = ctypes.c_int
self.lib.AddPrimitiveBox.argtypes = (ctypes.POINTER(ctypes.c_float), ctypes.c_uint64, ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),)
self.lib.AddPrimitiveBox.argtypes = (
ctypes.POINTER(ctypes.c_float),
ctypes.c_uint64,
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
)
self.lib.AddPrimitiveBox.restype = ctypes.c_int
self.lib.AddPrimitiveCapsule.argtypes = (ctypes.c_float, ctypes.c_float, ctypes.c_uint64, ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),)
self.lib.AddPrimitiveCapsule.argtypes = (
ctypes.c_float,
ctypes.c_float,
ctypes.c_uint64,
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
)
self.lib.AddPrimitiveCapsule.restype = ctypes.c_int
self.lib.AddPrimitiveSphere.argtypes = (ctypes.c_float, ctypes.c_uint64, ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),)
self.lib.AddPrimitiveSphere.argtypes = (
ctypes.c_float,
ctypes.c_uint64,
ctypes.POINTER(ctypes.c_float),
ctypes.POINTER(ctypes.c_float),
)
self.lib.AddPrimitiveSphere.restype = ctypes.c_int
self.lib.SetCollisionSettings.argtypes = (ctypes.POINTER(PhysicsCollisionSettings),)
self.lib.SetCollisionSettings.argtypes = (
ctypes.POINTER(PhysicsCollisionSettings),
)
self.lib.SetCollisionSettings.restype = ctypes.c_int
self.lib.NewPhysics()

def write(self, filepath):
self.lib.Write(filepath)

def set_collision_settings(self, settings):
self.lib.SetCollisionSettings(ctypes.byref(settings))

def add_convex_mesh(self, vertices_list, indices_list, collider_layer):
vertices = (ctypes.c_float * len(vertices_list))(*vertices_list)
indices = (ctypes.c_uint32 * len(indices_list))(*indices_list)
self.lib.AddConvexMesh(len(vertices_list), vertices, int(len(indices_list) / 3), indices, collider_layer)

self.lib.AddConvexMesh(
len(vertices_list),
vertices,
int(len(indices_list) / 3),
indices,
collider_layer,
)

def add_triangle_mesh(self, vertices_list, indices_list, collider_layer):
vertices = (ctypes.c_float * len(vertices_list))(*vertices_list)
indices = (ctypes.c_uint32 * len(indices_list))(*indices_list)
self.lib.AddTriangleMesh(len(vertices_list), vertices, int(len(indices_list) / 3), indices, collider_layer)
self.lib.AddTriangleMesh(
len(vertices_list),
vertices,
int(len(indices_list) / 3),
indices,
collider_layer,
)

def add_primitive_box(self, half_extents_list, collider_layer, position_list, rotation_list):
def add_primitive_box(
self, half_extents_list, collider_layer, position_list, rotation_list
):
half_extents = (ctypes.c_float * len(half_extents_list))(*half_extents_list)
position = (ctypes.c_float * len(position_list))(*position_list)
rotation = (ctypes.c_float * len(rotation_list))(*rotation_list)
self.lib.AddPrimitiveBox(half_extents, collider_layer, position, rotation)

def add_primitive_capsule(self, radius, length, collider_layer, position_list, rotation_list):

def add_primitive_capsule(
self, radius, length, collider_layer, position_list, rotation_list
):
position = (ctypes.c_float * len(position_list))(*position_list)
rotation = (ctypes.c_float * len(rotation_list))(*rotation_list)
self.lib.AddPrimitiveCapsule(radius, length, collider_layer, position, rotation)

def add_primitive_sphere(self, radius, collider_layer, position_list, rotation_list):

def add_primitive_sphere(
self, radius, collider_layer, position_list, rotation_list
):
position = (ctypes.c_float * len(position_list))(*position_list)
rotation = (ctypes.c_float * len(rotation_list))(*rotation_list)
self.lib.AddPrimitiveSphere(radius, collider_layer, position, rotation)
self.lib.AddPrimitiveSphere(radius, collider_layer, position, rotation)
Loading

0 comments on commit 2f79d74

Please sign in to comment.