Skip to content

Commit

Permalink
add eyelids and setRigBoneAttr
Browse files Browse the repository at this point in the history
  • Loading branch information
IzaZed committed Jun 23, 2024
1 parent b674f88 commit 7d99e29
Show file tree
Hide file tree
Showing 30 changed files with 474 additions and 67 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def read_file(name):
return f.read()


version = 'v3.2'
version = '3.2'
shortdesc = "Uplogic utility for UPBGE."
longdesc = '\n\n'.join([read_file(name) for name in [
'README.md',
Expand All @@ -31,7 +31,7 @@ def read_file(name):
author='Leopold Auersperg-Castell',
author_email='[email protected]',
url='https://github.com/UPBGE/uplogic',
download_url='https://github.com/UPBGE/uplogic/archive/refs/tags/v3.2.tar.gz',
download_url=f'https://github.com/UPBGE/uplogic/archive/refs/tags/{version}.tar.gz',
license='GPLv2',
packages=[
'uplogic',
Expand Down
14 changes: 7 additions & 7 deletions uplogic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ def on_stop_callback():
get_mainloop().stop(
"""

from collections import deque

__version__ = '3.2'

import signal
import time
import os, sys
import bge
from .utils import load_user_module
from .utils import make_valid_name
from .input import key_tap
Expand All @@ -74,14 +79,9 @@ def on_stop_callback():
from . import shaders
from . import ui
from . import utils
import bge
import bpy
import signal
import time
import os, sys


__version__ = '3.2'
from collections import deque


class MainLoop:
Expand Down
1 change: 1 addition & 0 deletions uplogic/animation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from .action import ACTION_STARTED # noqa
from .action import ULAction, Action # noqa
from .sequence import ULSequence, Sequence # noqa
from .rig import Rig
25 changes: 16 additions & 9 deletions uplogic/animation/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,18 @@ def intensity(self) -> float:

@intensity.setter
def intensity(self, value: float):
value = float(value)
if not value:
self.game_object.stopAction(self.layer)
if not self.is_playing:
if value == self._intensity:
return
if not self.is_playing or value == self._intensity:
value = float(value)
if value <= 0:
if self.is_playing:
self.game_object.stopAction(self.layer)
return
# if not self.is_playing:
# return
self._intensity = clamp(value, 0, 1)
self._restart_action()
self._act_system._get_uppermost_layer(self.game_object)

@property
def speed(self) -> float:
Expand All @@ -219,7 +222,8 @@ def speed(self, value: float):
if not self.is_playing or value == self._speed:
return
self._speed = value
self._restart_action()
if self.intensity > 0:
self._restart_action()

def _restart_action(self):
'''Restart action to use updated values.
Expand Down Expand Up @@ -270,6 +274,7 @@ def _restart_action(self):
def update(self):
'''This is called each frame.
'''
# print(self.name, self.is_playing)
self._locked = False
game_object = self.game_object
if game_object.invalid:
Expand Down Expand Up @@ -336,11 +341,14 @@ def resume(self):
self._frozen_speed = -1

def stop(self):
'''Stop playback of this action.
'''
self._act_system.remove(self)

def disable(self):
self.game_object.stopAction(self.layer)

def _stop(self):
'''Stop playback of this action.
'''
self.stopped = True
self.on_finish()
self.game_object.stopAction(self.layer)
Expand All @@ -355,7 +363,6 @@ def restart(self):
self.start_frame,
self.end_frame,
layer=self.layer,
# priority=self.priority,
blendin=self.blendin,
play_mode=self.play_mode,
speed=self.speed,
Expand Down
14 changes: 11 additions & 3 deletions uplogic/animation/actionsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ActionSystem():
usually addressed indirectly through `Action` and is not intended for
manual use.
'''
layers: dict = {}
layers: dict[KX_GameObject, dict] = {}

def __init__(self, name: str):
self.actions: list = []
Expand Down Expand Up @@ -72,13 +72,21 @@ def get_layer(cls, game_object: KX_GameObject, layer: int = 0):
action = cls.layers.get(game_object, {}).get(str(layer))
return action

@classmethod
def _get_uppermost_layer(cls, object):
layers = cls.layers.get(object, {})
found = False
for action in layers.values().__reversed__():
if found:
action.disable()
elif action.intensity >= 1.0:
found = True

def update(self):
"""This is called each frame.
"""
for action in self.actions:
action.update()
# if action.layer_weight >= 1.0:
# pass

def add(self, action):
'''Add a `Action` to this system.
Expand Down
109 changes: 106 additions & 3 deletions uplogic/animation/rig.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,116 @@
from bge.types import BL_ArmatureChannel, BL_ArmatureObject
from bge.logic import ROT_MODE_QUAT, ROT_MODE_XYZ
from bge.logic import ROT_MODE_XYZ
from uplogic.utils.objects import GameObject
from mathutils import Vector, Quaternion, Matrix, Euler
from mathutils import Vector, Quaternion, Matrix


class RigBone():

def __init__(self, bone: BL_ArmatureChannel, armature: BL_ArmatureObject) -> None:
self.bone = bone
self.armature = armature
self.bone.rotation_mode = ROT_MODE_XYZ
self._armature = self.armature.blenderObject.data
# self.bone.rotation_mode = rotation_mode

@property
def name(self):
return self.bone.name

@name.setter
def name(self, val):
self._armature.blenderObject.bones[self.bone.name].name = val

@property
def constraints(self):
return self.armature.blenderObject.pose.bones[self.bone.name].constraints

@property
def head(self):
return self._armature.bones[self.bone.name].head

@head.setter
def head(self, value):
self._armature.bones[self.bone.name].head = value

@property
def head_local(self):
return self._armature.bones[self.bone.name].head_local

@head_local.setter
def head_local(self, value):
self._armature.bones[self.bone.name].head_local = value

@property
def tail(self):
return self._armature.bones[self.bone.name].tail

@tail.setter
def tail(self, value):
self._armature.bones[self.bone.name].tail = value

@property
def tail_local(self):
return self._armature.bones[self.bone.name].tail_local

@tail_local.setter
def tail_local(self, value):
self._armature.bones[self.bone.name].tail_local = value

@property
def inherit_rotation(self):
return self._armature.bones[self.bone.name].use_inherit_rotation

@inherit_rotation.setter
def inherit_rotation(self, value):
self._armature.bones[self.bone.name].use_inherit_rotation = value

@property
def inherit_scale(self):
return self._armature.bones[self.bone.name].use_inherit_scale

@inherit_scale.setter
def inherit_scale(self, value):
self._armature.bones[self.bone.name].use_inherit_scale = value

@property
def connected(self):
return self._armature.bones[self.bone.name].use_connect

@connected.setter
def connected(self, value):
self._armature.bones[self.bone.name].use_connect = value

@property
def deform(self):
return self._armature.bones[self.bone.name].use_deform

@deform.setter
def deform(self, value):
self._armature.bones[self.bone.name].use_deform = value

@property
def local_location(self):
return self._armature.bones[self.bone.name].use_local_location

@local_location.setter
def local_location(self, value):
self._armature.bones[self.bone.name].use_local_location = value

@property
def relative_parent(self):
return self._armature.bones[self.bone.name].use_relative_parent

@relative_parent.setter
def relative_parent(self, value):
self._armature.bones[self.bone.name].use_relative_parent = value

@property
def scale_easing(self):
return self._armature.bones[self.bone.name].use_scale_easing

@scale_easing.setter
def scale_easing(self, value):
self._armature.bones[self.bone.name].use_scale_easing = value

@property
def pose_matrix_cleaned(self):
Expand Down Expand Up @@ -40,9 +141,11 @@ def worldOrientation(self):

@worldOrientation.setter
def worldOrientation(self, val: Matrix):
_mode = self.bone.rotation_mode
self.bone.rotation_mode = ROT_MODE_XYZ
self.bone.rotation_euler = Vector(val.to_euler())
self.armature.blenderObject.update_tag()
self.bone.rotation_mode = _mode


class RigBones(dict):
Expand Down
2 changes: 1 addition & 1 deletion uplogic/audio/fmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __init__(self, name, position=Vector((0, 0, 0)), channel='default') -> None:
@property
def volume(self):
return self.evt.get_volume()

@volume.setter
def volume(self, vol):
self.evt.set_volume(vol)
Expand Down
20 changes: 12 additions & 8 deletions uplogic/audio/sound.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def lowpass(self, val):
sound.position = self.sound.position + DELTA_TIME()
sound.volume = self.sound.volume
sound.pitch = self.sound.pitch
schedule_callback(self.sound.stop, .5)
schedule_callback(self.sound.stop)
self.sound = sound

def update(self):
Expand Down Expand Up @@ -516,13 +516,17 @@ def update(self, init=False):
else (1 - cs) * sustained
)
master_volume = self.aud_system.volume
handle.volume = self.volume * mult * master_volume
handle.cone_volume_outer = (
self.cone_outer_volume *
self.volume *
mult *
master_volume
)
try:
handle.volume = self.volume * mult * master_volume

handle.cone_volume_outer = (
self.cone_outer_volume *
self.volume *
mult *
master_volume
)
except Exception:
pass
elif handle.status:
master_volume = self.aud_system.volume
handle.volume = self.volume * master_volume
Expand Down
8 changes: 5 additions & 3 deletions uplogic/console/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from uplogic.utils.math import world_to_screen
from uplogic.utils.math import cycle
from uplogic.utils.math import clamp
from uplogic.input import key_down, mouse_down, key_pulse, mouse_wheel
from uplogic.input.keyboard import key_down, key_pulse
from uplogic.input.mouse import mouse_down, mouse_wheel
import bpy, blf
import sys, os
from datetime import datetime
Expand Down Expand Up @@ -43,7 +44,6 @@ def _get_globals():
def enable(toggle_key='F12', visible=False):
get_console(True, toggle_key=toggle_key, visible=visible)
sys.stdout = Console()
debug('On-Screen Console active; Check System Console for Errors.')


def disable():
Expand All @@ -52,13 +52,14 @@ def disable():
console = get_console()
if console:
console.stop()
consoles = GlobalDB.retrieve('uplogic.consoles')
consoles.remove('default')


class Console(StringIO):

def write(self, __s: str) -> int:
log(__s)
# sys.__stdout__.write(__s)


class ErrorConsole(StringIO):
Expand Down Expand Up @@ -263,6 +264,7 @@ def get_console(create=False, toggle_key='F12', visible=False) -> ConsoleLayout:
if console is None and create:
console = ConsoleLayout(toggle_key=toggle_key, visible=visible)
consoles.put('default', console)
debug('On-Screen Console active; Check System Console for Errors.')
return console


Expand Down
Loading

0 comments on commit 7d99e29

Please sign in to comment.