Wasserwecken / bvhio

Read, write, edit and create .bvh files with hierarchical 3D transforms
MIT License
44 stars 9 forks source link

Bvh files aren't setting as T pose #1

Closed ghost closed 1 year ago

ghost commented 1 year ago

After importing related file (dataset-1_bow_active_001.bvh) and copying your code into python console in Blender, it gives the error which I'll leave;

`import bpy from bpy import data as D from bpy import context as C from mathutils import from math import

~ PYTHON INTERACTIVE CONSOLE 3.10.8 (main, Oct 24 2022, 20:47:11) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]

~

~ Builtin Modules: bpy, bpy.data, bpy.ops, bpy.props, bpy.types, bpy.context, bpy.utils, bgl, blf, mathutils

~ Convenience Imports: from mathutils import ; from math import

~ Convenience Variables: C = bpy.context, D = bpy.data

~

requires two packages:

pip install PyGLM

pip install bvhio

this script will correct the rest pose of the .bvh files from the bandai namco motion set

https://github.com/BandaiNamcoResearchInc/Bandai-Namco-Research-Motiondataset

import glm

! Traceback (most recent call last):

! File "", line 1, in

! ModuleNotFoundError: No module named 'glm'

!

import bvhio

! Traceback (most recent call last):

! File "", line 1, in

! ModuleNotFoundError: No module named 'bvhio'

!

root = bvhio.readAsHierarchy('.\MoCap\Bandai\dataset\Bandai-Namco-Research-Motiondataset-1\data\dataset-1_bow_active_001.bvh')

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'bvhio' is not defined

!

layout = root.layout()

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'root' is not defined

!

set up T-pose

root.loadRestPose()

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'root' is not defined

!

layout[ 0][0].setEuler(( 0, 0, 0)) # joint_Root

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[ 1][0].setEuler(( 0, 0, 0)) # Hips

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[ 1][0].Position = (0, 94, 0) # Hips

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[ 2][0].setEuler(( 0, 0, 0)) # Spine

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[ 3][0].setEuler(( 0, +90, 0)).roll(-90) # Chest

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[ 4][0].setEuler(( 0, 0, 0)) # Neck

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[ 5][0].setEuler(( 0, 0, 0)) # Head

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[ 6][0].setEuler(( 0, 0, -90)) # Shoulder_L

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[ 7][0].setEuler(( 0, 0, 0)) # UpperArm_L

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[ 8][0].setEuler(( 0, 0, 0)) # LowerArm_L

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[ 9][0].setEuler(( 0, 0, 0)) # Hand_L

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[10][0].setEuler(( 0, 0, +90)) # Shoulder_R

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[11][0].setEuler(( 0, 0, 0)) # UpperArm_R

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[12][0].setEuler(( 0, 0, 0)) # LowerArm_R

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[13][0].setEuler(( 0, 0, 0)) # Hand_R

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[14][0].setEuler(( 0, 0, 180)) # UpperLeg_L

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[15][0].setEuler(( 0, 0, 0)) # LowerLeg_L

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[16][0].setEuler(( 0, 0, 0)) # Foot_L

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[17][0].setEuler(( 0, 0, 0)) # Toes_L

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[18][0].setEuler(( 0, 0, 180)) # UpperLeg_R

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[19][0].setEuler(( 0, 0, 0)) # LowerLeg_R

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[20][0].setEuler(( 0, 0, 0)) # Foot_R

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

layout[21][0].setEuler(( 0, 0, 0)) # Toes_R

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'layout' is not defined

!

root.writeRestPose(recursive=True, keep=['position', 'rotation', 'scale'])

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'root' is not defined

!

key frame corrections, turns joints so than Z- axis always points forward

for frame in range(*root.getKeyframeRange()): root.loadPose(frame, recursive=True) layout[ 2][0].roll(-90) # Spine layout[ 3][0].roll(-90) # Chest layout[ 4][0].roll(-90) # Neck layout[ 5][0].roll(-90) # Head layout[10][0].roll(180, recursive=True) # Shoulder_R layout[18][0].roll(180, recursive=True) # UpperLeg_R

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'root' is not defined

!

layout[ 5][0].Rotation *= glm.angleAxis(glm.radians(-90), (1, 0, 0))  # Head

! File "", line 1

! layout[ 5][0].Rotation *= glm.angleAxis(glm.radians(-90), (1, 0, 0)) # Head

! IndentationError: unexpected indent

!

layout[ 9][0].Rotation *= glm.angleAxis(glm.radians(-90), (0, 0, 1))  # Hand_L

! File "", line 1

! layout[ 9][0].Rotation *= glm.angleAxis(glm.radians(-90), (0, 0, 1)) # Hand_L

! IndentationError: unexpected indent

!

layout[13][0].Rotation *= glm.angleAxis(glm.radians(-90), (0, 0, 1))  # Hand_R

! File "", line 1

! layout[13][0].Rotation *= glm.angleAxis(glm.radians(-90), (0, 0, 1)) # Hand_R

! IndentationError: unexpected indent

!

layout[17][0].Rotation *= glm.angleAxis(glm.radians(-90), (0, 0, 1))  # Toes_L

! File "", line 1

! layout[17][0].Rotation *= glm.angleAxis(glm.radians(-90), (0, 0, 1)) # Toes_L

! IndentationError: unexpected indent

!

layout[21][0].Rotation *= glm.angleAxis(glm.radians(-90), (0, 0, 1))  # Toes_R

! File "", line 1

! layout[21][0].Rotation *= glm.angleAxis(glm.radians(-90), (0, 0, 1)) # Toes_R

! IndentationError: unexpected indent

!

root.writePose(frame, recursive=True)

! File "", line 1

! root.writePose(frame, recursive=True)

! IndentationError: unexpected indent

!

scale to meters

root.RestPose.Scale = 0.012

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'root' is not defined

!

root.applyRestposeScale(recursive=True, bake=False, bakeKeyframes=True)

! Traceback (most recent call last):

! File "", line 1, in

! NameError: name 'root' is not defined

!

`

Wasserwecken commented 1 year ago

okay, it looks like the PyGlm package is not installed correctly.

How did you install the package? With the given command from the gist? I gonna check it out in about few hours, i had to work, sorry.

I never tried to execute my script within blender. The script was intended to be used purely with python to create a new .bvh file to be imported.

I guess the dependencies have to be installed for the specific python version that blender is using. So if you have multiple python versions installed, pls check if you installed the dependencies for the required blender python version.

Wasserwecken commented 1 year ago

After some research, yes blender does use its own python environment. I could not make it work after some simple tests.

So please try to execute the gist code within a standard python environment or jupyter notebook.

I gonna try tomorrow to update the gist to run it from the console.

ghost commented 1 year ago

I couldn't use juypter notebook (I'm totally ignorance about writing code) and now trying to use that through standard python environment with chatgpt' assistance. I will inform you as well. Thanks for your response.

ghost commented 1 year ago

Unfortunately, I couldn't solve that. Have you had a chance to modify it?

Wasserwecken commented 1 year ago

I changed the gist so the script runs from the command line. https://gist.github.com/Wasserwecken/58ae6579be8ac43508b9b347956afc9a

BUT, the process is VERY slow, because how i implemented it. the LAFAN1 dataset took me about 2 hours to convert. Sorry for that.

I hope that helps

Please do not apply that script to the lafan1 data set, the transformation are diffrent. Use this gist for the LAFAN1 dataset: https://gist.github.com/Wasserwecken/0802f3a678931e8408f7b78ecb99b00a

Wasserwecken commented 1 year ago

Did it solve your problem?

ghost commented 1 year ago

Can I take your 5 minutes whenever you're available? Because I'm using linux mx and its directory style is a little different than other operation systems and I can't modify a code properly because of my lackness about programming.

ghost commented 1 year ago

$ python3 converter.py Traceback (most recent call last): File "/home/fuckoff/Masaüstü/Animasyon/Motion capture/Bandai Namco/Bandai-Namco-Research-Motiondataset-master/dataset/Bandai-Namco-Research-Motiondataset-1/data/converter.py", line 4, in import bvhio File "/home/fuckoff/.local/lib/python3.9/site-packages/bvhio/init.py", line 1, in from .lib.bvh import BvhContainer, BvhJoint File "/home/fuckoff/.local/lib/python3.9/site-packages/bvhio/lib/bvh/init.py", line 1, in from .BvhContainer import BvhContainer File "/home/fuckoff/.local/lib/python3.9/site-packages/bvhio/lib/bvh/BvhContainer.py", line 1, in from .BvhJoint import BvhJoint File "/home/fuckoff/.local/lib/python3.9/site-packages/bvhio/lib/bvh/BvhJoint.py", line 2, in from SpatialTransform import Pose ModuleNotFoundError: No module named 'SpatialTransform'

It gives this parameters, btw I'm using Linux (MX)?

If you will have some time I can show that directly to you?

Wasserwecken commented 1 year ago

Oh i forget to name another python package that is needed. please run pip install spatial-transform and try it again.

But, im using windows only. I cannot give you advides how to organize your directories and work with the command line. But it looks like your close to run it :)

ghost commented 1 year ago

I entered related (spatial-transform) script but after trying to use base code, it said "glm" has no "vec3" attribute. I tried all of these with some of my friends but they couldn't it too :)

Wasserwecken commented 1 year ago

thats a pitfall of the pyglm package.

pip uninstall glm pip install PyGLM

they use the same name in the code. try run this and then the scrpt again

ghost commented 1 year ago

Result;

python3 converter.py dataset-1_walk_masculinity_002.bvh Traceback (most recent call last): File "/home/fuckoff/Masaüstü/Animasyon/Motion capture/Bandai Namco/Bandai-Namco-Research-Motiondataset-master/dataset/Bandai-Namco-Research-Motiondataset-1/data/converter.py", line 87, in destinationDir = sys.argv[2] IndexError: list index out of range

Wasserwecken commented 1 year ago

you have to provide two directories, this does not work with single files, like the example in my prvious answer:

python converter.py .sourceDir\ .destinationDir

ghost commented 1 year ago

What should be exact parameter with these two directories?

Source (source bvh files in here): /home/fuckoff/Masaüstü/Animasyon/Motion capture/Bandai Namco/Bandai-Namco-Research-Motiondataset-master/dataset/Bandai-Namco-Research-Motiondataset-1/data/

Destination (outputs should be here): /home/fuckoff/Masaüstü/Animasyon/Motion capture/Outputs/

I'm asking that because when I entered related parameter, it said;

root@mx:/home/fuckoff/Masaüstü/Animasyon/Motion capture/Bandai Namco/Bandai-Namco-Research-Motiondataset-master/dataset/Bandai-Namco-Research-Motiondataset-1/data# python3 converter.py ./home/fuckoff/Masaüstü/Animasyon/Motion capture/Bandai Namco/Bandai-Namco-Research-Motiondataset-master/dataset/Bandai-Namco-Research-Motiondataset-1/data/ ./home/fuckoff/Masaüstü/Animasyon/Motion capture/Outputs/ Source path does not exist

ghost commented 1 year ago

I did it! Thanks for your guidance sir, I'll buy coffee to you when I get Germany :)