Skip to content

Commit

Permalink
Merge pull request #9 from freemocap/ajc_philip/merge_streams
Browse files Browse the repository at this point in the history
Ajc philip/merge streams
  • Loading branch information
jonmatthis authored Jun 28, 2024
2 parents 75373c0 + 3314180 commit c925f66
Show file tree
Hide file tree
Showing 101 changed files with 4,999 additions and 1,666 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/create_addon_install_zip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Create and Upload Zip

on:
push:
branches:
- main # You can change this to any branch you want to trigger the action on
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Create zip file
run: zip -r freemocap_blender_addon.zip ajc27_freemocap_blender_addon/

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: freemocap_blender_addon
path: freemocap_blender_addon.zip

- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.sha }}
release_name: Release ${{ github.sha }}
draft: true
prerelease: true

- name: Upload to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./freemocap_blender_addon.zip
asset_name: freemocap_blender_addon.zip
asset_content_type: application/zip
25 changes: 16 additions & 9 deletions ajc27_freemocap_blender_addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
logger = logging.getLogger(__name__)

bl_info = {
'name': 'ajc27_freemocap_blender_addon',
'name': 'freemocap_blender_addon',
'author': 'ajc27',
'version': (1, 1, 7),
'blender': (3, 0, 0),
'location': '3D Viewport > Sidebar > Freemocap Adapter',
'description': 'Add-on to adapt the Freemocap Blender output',
'description': 'Add-on for bringing `freemocap` data into a Blender scene',
'category': 'Development',
}

Expand All @@ -50,7 +50,6 @@ def unregister():
print(f"Unregistering property group FMC_ADAPTER_PROPERTIES")
del bpy.types.Scene.fmc_adapter_properties


def register():
import bpy

Expand All @@ -61,20 +60,28 @@ def register():
print(f"Registering class {cls.__name__}")
bpy.utils.register_class(cls)

# this is a sloppy way to add keymaps (shortcuts) to some operators, we can improve this later
if cls.__name__ == "FMC_ADAPTER_run_all":
# Add the keymap configuration
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY')
kmi = km.keymap_items.new(cls.bl_idname, 'R', 'PRESS', shift=True, alt=True)
addon_keymaps.append((km, kmi))
if cls.__name__ == "FMC_ADAPTER_clear_scene":
wm = bpy.context.window_manager
km = wm.keyconfigs.addon.keymaps.new(name='Object Mode', space_type='EMPTY')
kmi = km.keymap_items.new(cls.bl_idname, 'X', 'PRESS', shift=True, alt=True)
addon_keymaps.append((km, kmi))

print("Registering property group FMC_ADAPTER_PROPERTIES")

from .blender_interface import FMC_ADAPTER_PROPERTIES
bpy.types.Scene.fmc_adapter_properties = bpy.props.PointerProperty(type=FMC_ADAPTER_PROPERTIES)

# try:
# from ajc27_freemocap_blender_addon.core_functions.fbx_export import get_io_scene_fbx_addon
# get_io_scene_fbx_addon()
# except Exception as e:
# print(f"Error loading io_scene_fbx addon: {str(e)}")
# raise

print(f"Finished registering {__file__} as add-on!")

addon_keymaps = []

if __name__ == "__main__":
print(f"Running {__file__} as main file ")
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions ajc27_freemocap_blender_addon/blender_interface/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from ajc27_freemocap_blender_addon.blender_interface.main_view3d_panel import VIEW3D_PT_freemocap_adapter
from ajc27_freemocap_blender_addon.blender_interface.main_view3d_panel import VIEW3D_PT_freemocap
from ajc27_freemocap_blender_addon.blender_interface.operators import BLENDER_OPERATORS
from ajc27_freemocap_blender_addon.blender_interface.properties.properties import FMC_ADAPTER_PROPERTIES

BLENDER_USER_INTERFACE_CLASSES = [FMC_ADAPTER_PROPERTIES,
VIEW3D_PT_freemocap_adapter,
VIEW3D_PT_freemocap,
*BLENDER_OPERATORS,
]
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import logging

from bpy.types import Panel
import bpy

logger = logging.getLogger(__name__)


class VIEW3D_PT_freemocap_adapter(Panel):
class VIEW3D_PT_freemocap(bpy.types.Panel):
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Freemocap Adapter"
bl_label = "Freemocap Adapter"
bl_category = "💀FreeMoCap"
bl_label = "💀FreeMoCap"

def draw(self, context):
layout = self.layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import bpy
from ajc27_freemocap_blender_addon.core_functions.empties.reorient_empties import reorient_empties
from ajc27_freemocap_blender_addon.core_functions.meshes.attach_mesh_to_rig import attach_mesh_to_rig
from ajc27_freemocap_blender_addon.core_functions.meshes.rigid_body_meshes.attach_rigid_body_meshes_to_rig import create_rigid_body_meshes
from ajc27_freemocap_blender_addon.core_functions.rig.add_rig import add_rig
from bpy.types import Operator

Expand Down Expand Up @@ -49,7 +49,7 @@ def execute(self, context):

try:
print('Executing Add Body Mesh...')
attach_mesh_to_rig(body_mesh_mode=fmc_adapter_tool.body_mesh_mode)
create_rigid_body_meshes(body_mesh_mode=fmc_adapter_tool.body_mesh_mode)
except Exception as e:
print(f"Error while adding body mesh: {e}")
return {'CANCELLED'}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math as m
import time

from ajc27_freemocap_blender_addon.freemocap_data_handler.operations.enforce_rigid_bones import enforce_rigid_bones
from ajc27_freemocap_blender_addon.freemocap_data_handler.operations.enforce_rigid_bodies import enforce_rigid_bodies
from ajc27_freemocap_blender_addon.freemocap_data_handler.utilities.load_data import load_freemocap_data
from bpy.types import Operator

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bpy
from bpy.props import StringProperty, BoolProperty


from ajc27_freemocap_blender_addon.freemocap_data_handler.utilities.load_data import get_test_recording_path


class FMC_ADAPTER_PROPERTIES(bpy.types.PropertyGroup):
Expand All @@ -22,7 +22,7 @@ class FMC_ADAPTER_PROPERTIES(bpy.types.PropertyGroup):
recording_path: StringProperty(
name="FreeMoCap recording path",
description="Path to a freemocap recording",
default="",
default=get_test_recording_path(),
subtype='FILE_PATH',
)
center_of_mass_past_frames: bpy.props.IntProperty(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import List, Dict

import numpy as np

from ajc27_freemocap_blender_addon.data_models.mediapipe_names.virtual_trajectories import \
MEDIAPIPE_VIRTUAL_TRAJECTORY_DEFINITIONS
get_media_pipe_virtual_trajectory_definition


def validate_marker_definitions(virtual_marker_definitions: dict):
Expand Down Expand Up @@ -50,11 +51,12 @@ def calculate_virtual_trajectories(body_frame_name_xyz: np.ndarray,
"""
Create virtual markers from the body data using the marker definitions.
"""
mediapipe_virtual_trajectory_definitions = get_media_pipe_virtual_trajectory_definition()
print("Creating virtual markers...")
validate_marker_definitions(MEDIAPIPE_VIRTUAL_TRAJECTORY_DEFINITIONS)
validate_marker_definitions(mediapipe_virtual_trajectory_definitions)

virtual_trajectories = {}
for virtual_trajectory_name, virtual_trajectory_definition in MEDIAPIPE_VIRTUAL_TRAJECTORY_DEFINITIONS.items():
for virtual_trajectory_name, virtual_trajectory_definition in mediapipe_virtual_trajectory_definitions.items():
print(f"Calculating virtual marker trajectory: {virtual_trajectory_name} \n"
f"Component trajectories: {virtual_trajectory_definition['marker_names']} \n"
f" weights: {virtual_trajectory_definition['marker_weights']}\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import bpy
import numpy as np
from ajc27_freemocap_blender_addon.data_models.mediapipe_names.mediapipe_heirarchy import MEDIAPIPE_HIERARCHY
from ajc27_freemocap_blender_addon.data_models.mediapipe_names.mediapipe_heirarchy import get_mediapipe_hierarchy


def translate_empty_and_its_children(empty_name: str,
frame_index: int,
delta: Union[List[float], Tuple[float, float, float], np.ndarray]):
mediapipe_hierarchy = get_mediapipe_hierarchy()
if isinstance(delta, np.ndarray) or isinstance(delta, tuple):
delta = list(delta)

Expand All @@ -28,10 +29,10 @@ def translate_empty_and_its_children(empty_name: str,
pass

# If empty has children then call this function for every child
if empty_name in MEDIAPIPE_HIERARCHY.keys():
if empty_name in mediapipe_hierarchy.keys():
print(
f"Translating children of empty {empty_name}: {MEDIAPIPE_HIERARCHY[empty_name]['children']}")
for child in MEDIAPIPE_HIERARCHY[empty_name]['children']:
f"Translating children of empty {empty_name}: {mediapipe_hierarchy[empty_name]['children']}")
for child in mediapipe_hierarchy[empty_name]['children']:
translate_empty_and_its_children(empty_name=child,
frame_index=frame_index,
delta=delta)
20 changes: 11 additions & 9 deletions ajc27_freemocap_blender_addon/core_functions/main_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import numpy as np
from ajc27_freemocap_blender_addon.core_functions.load_videos.load_videos import load_videos
from ajc27_freemocap_blender_addon.core_functions.meshes.attach_mesh_to_rig import attach_mesh_to_rig
from ajc27_freemocap_blender_addon.core_functions.rig.add_rig import add_rig
from ajc27_freemocap_blender_addon.core_functions.meshes.rigid_body_meshes.attach_rigid_body_meshes_to_rig import create_rigid_body_meshes
from ajc27_freemocap_blender_addon.core_functions.rig.add_rig import add_rig, AddRigMethods
from ajc27_freemocap_blender_addon.freemocap_data_handler.utilities.get_or_create_freemocap_data_handler import (
get_or_create_freemocap_data_handler,
)
Expand All @@ -18,11 +18,11 @@
from .meshes.skelly_mesh.attach_skelly_mesh import attach_skelly_mesh_to_rig
from .rig.save_bone_and_joint_angles_from_rig import save_bone_and_joint_angles_from_rig
from .setup_scene.make_parent_empties import create_parent_empty
from .setup_scene.scene_objects.create_scene_objects import create_scene_objects
from .setup_scene.set_start_end_frame import set_start_end_frame
from ..data_models.bones.bone_definitions import get_bone_definitions
from ..data_models.parameter_models.parameter_models import Config
from ..freemocap_data_handler.helpers.saver import FreemocapDataSaver
from ..freemocap_data_handler.operations.enforce_rigid_bones.enforce_rigid_bones import enforce_rigid_bones
from ..freemocap_data_handler.operations.enforce_rigid_bodies.enforce_rigid_bodies import enforce_rigid_bodies
from ..freemocap_data_handler.operations.fix_hand_data import fix_hand_data
from ..freemocap_data_handler.operations.put_skeleton_on_ground import put_skeleton_on_ground

Expand Down Expand Up @@ -151,7 +151,7 @@ def put_data_in_inertial_reference_frame(self):
def enforce_rigid_bones(self):
print("Enforcing rigid bones...")
try:
self.freemocap_data_handler = enforce_rigid_bones(
self.freemocap_data_handler = enforce_rigid_bodies(
handler=self.freemocap_data_handler
)

Expand Down Expand Up @@ -199,10 +199,10 @@ def add_rig(self):
try:
print("Adding rig...")
self.rig = add_rig(
empty_names=self.empty_names,
bone_data=self.freemocap_data_handler.metadata["bone_data"],
rig_name=self.rig_name,
parent_object=self._data_parent_object,
add_rig_method=AddRigMethods.BY_BONE,
keep_symmetry=self.config.add_rig.keep_symmetry,
add_fingers_constraints=self.config.add_rig.add_fingers_constraints,
use_limit_rotation=self.config.add_rig.use_limit_rotation,
Expand Down Expand Up @@ -233,11 +233,14 @@ def save_bone_and_joint_data_from_rig(self):
def attach_rigid_body_mesh_to_rig(self):
if self.rig is None:
raise ValueError("Rig is None!")

if self.empties is None:
raise ValueError("Empties have not been created yet!")

try:
print("Adding rigid_body_bone_meshes...")
attach_mesh_to_rig(
body_mesh_mode=self.config.add_body_mesh.body_mesh_mode,
create_rigid_body_meshes(
bone_data=self.freemocap_data_handler.metadata["bone_data"],
rig=self.rig,
empties=self.empties,
parent_object=self._rigid_body_meshes_parent_object,
Expand All @@ -256,7 +259,6 @@ def attach_skelly_mesh_to_rig(self):
attach_skelly_mesh_to_rig(
rig=self.rig,
body_dimensions=body_dimensions,
empties=self.empties
)
except Exception as e:
print(f"Failed to attach mesh to rig: {e}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create_center_of_mass_mesh(parent_object: bpy.types.Object,
location_constraint.target = center_of_mass_empty

center_of_mass_material = create_checkerboard_material(name="center_of_mass_material",
square_scale=10,
square_scale=2,
color1=(0, .5, 1, 1),
color2=(1, 0, 1, 1),
roughness=0.5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,29 @@

import bpy

from .rigid_body_meshes.helpers.put_meshes_on_empties import put_bone_meshes_on_empties
from ajc27_freemocap_blender_addon.core_functions.meshes.rigid_body_meshes.helpers.put_meshes_on_empties import put_rigid_body_meshes_on_empties
from ajc27_freemocap_blender_addon.data_models.bones.bone_definitions import BoneDefinition


def attach_mesh_to_rig(rig: bpy.types.Object,
parent_object: bpy.types.Object,
body_mesh_mode: str = "custom",
mesh_path: str = None,
empties: Dict[str, bpy.types.Object] = None,
):
def create_rigid_body_meshes(rig: bpy.types.Object,
parent_object: bpy.types.Object,
bone_data: Dict[str, BoneDefinition],
empties: Dict[str, bpy.types.Object] = None,
):
try:
if body_mesh_mode == "file":

mesh_from_file(mesh_path, rig)
if empties is None:
print(f"Must provide empties for custom body mesh")
raise ValueError(f"Must provide empties for custom body mesh")

elif body_mesh_mode == "custom":
if empties is None:
print(f"Must provide empties for custom body mesh")
raise ValueError(f"Must provide empties for custom body mesh")
put_rigid_body_meshes_on_empties(empties=empties,
bone_data=bone_data,
parent_empty=parent_object)

put_bone_meshes_on_empties(empties=empties, parent_empty=parent_object)

# Deselect all
bpy.ops.object.select_all(action='DESELECT')
print("Body mesh added successfully.")
return rig

else:
print(f"Invalid body_mesh_mode: {body_mesh_mode}")
raise ValueError(f"Invalid body_mesh_mode: {body_mesh_mode}")
# Deselect all
bpy.ops.object.select_all(action='DESELECT')
print("Body mesh added successfully.")
return rig
except Exception as e:
print(f"Failed to attach mesh to rig: {type(e).__name__}: {e}")
print(e)
Expand Down
Loading

0 comments on commit c925f66

Please sign in to comment.