MH2UE4u

A place for unofficial tutorials posted by MH users

Moderator: joepal

MH2UE4u

Postby AssetDK » Tue Feb 25, 2020 7:11 am

:idea: I have started to make a tutorial for getting MH characters to work with UE4, using blender etc. - and there are a few things I can't get done. Please comment here, on the wiki discussion page or add your own sections/tips!

:arrow: http://www.makehumancommunity.org/wiki/Documentation:Saving_models_for_Unreal_Engine_and_how_to_import_them_there
AssetDK
 
Posts: 51
Joined: Wed Dec 25, 2019 1:46 pm

Re: MH2UE4u

Postby [Sandy] » Sat Jul 11, 2020 3:15 pm

:D Hello, everyone of AssetDK and forum.

I thought of a slightly different approach. Use the Blender Python script to modify the bone tail position and roll. The goal is to replace the UE4 3rd person template SK_UE4_Mannequin with a Makehuman created character.

The import from Makehuman to Blender is supposed to use socket. I have not confirmed the operation, but I think that there is no problem using .mh2 instead.

The Makehuman default A-pose works just fine to some extent. The fingers of the character's hands are a little strange. The Apose_ue pose can be a bit better. But it's not perfect. I would be happy if someone with special techniques for making poses could improve it.

Procedure
1. Working with Makehuman
1.1. Pose/Animate - Skeleton: Game engine
1.2. Pose/Animate - Pose: Apose_ue ( The pose is not perfect so I have not registered yet )
1.3. Community - Socket: Check Accept connections

2. Working with Blender
2.1. Create a new project and delete the default cube, camera, lights, etc.
2.2. Scene Properties - Units - Unit Scale: 0.01
2.3. Sidebar - MakeHuman - Settings - Various - Blender unit equals: Centimeter
2.4. Sidebar - MakeHuman - Mesh - Import human - Click the Import human button
2.5. Changed the object name of Armature to "Armature"
2.6. Open Text Editor(Inside the Blender)
2.7. Text Editor - Open: mh2ue.py
2.8. Text Editor: Press Run Script button
2.9. File - Export - FBX(.fbx)
Export setting ( Changes from default settings )
Geometry - smoothing: Face
Armature - Primary Bone Axis: X Axis
Armature - Secondary Bone Axis: -Z Axis
Armature - Add Leaf Bones: Uncheck

3. Working with Unreal Engine
3.1. Create a new project using a third-person template.
3.2. FBX Import
Import setting ( Changes from default settings )
Mesh - Skeleton: SK_UE4_Mannequin
3.3. Replace player character
3.4. Play the game! :lol:
[Sandy]
 
Posts: 20
Joined: Mon Feb 18, 2019 8:12 pm

mh2ue.py

Postby [Sandy] » Mon Jul 13, 2020 3:04 pm

Code: Select all
import bpy
import mathutils

bpy.ops.outliner.orphans_purge()

obj = "Armature"
arm = bpy.data.armatures[0]

bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
bpy.context.view_layer.objects.active = bpy.data.scenes[0].objects[obj]
bpy.ops.object.mode_set(mode='EDIT')

bones = [
("pelvis", (0.0000, -0.0355, 9.7054), 1.204043940106203e-07),
("spine_01", (0.0000, -2.4676, 19.0955), 1.2043376784731663e-07),
("spine_02", (0.0000, 1.5651, 13.3223), 1.2037928343033855e-07),
("spine_03", (0.0000, 2.3111, 13.8404), 1.2036994689879066e-07),
("clavicle_l", (13.9182, 6.9506, -2.6710), 1.6761107444763184),
("upperarm_l", (9.9434, 1.1179, -11.7326), 2.410767078399658),
("lowerarm_l", (14.7201, -8.7915, -11.2146), 2.0401418209075928),
("hand_l", (7.4183, -4.7717, -6.2159), 0.7742447257041931),
("index_01_l", (1.6298, -1.3284, -3.7365), 1.688023328781128),
("index_02_l", (0.7641, -0.6676, -3.2386), 1.9376062154769897),
("index_03_l", (1.1548, -1.0154, -3.0254), 1.7928578853607178),
("middle_01_l", (2.0408, -1.2455, -3.9771), 1.37657630443573),
("middle_02_l", (0.9041, -0.8173, -3.4393), 1.6097930669784546),
("middle_03_l", (1.8408, -0.8000, -3.0472), 1.26283860206604),
("pinky_01_l", (1.9121, -0.2855, -3.0024), 0.8965443968772888),
("pinky_02_l", (1.0753, -0.2280, -2.7759), 1.1303706169128418),
("pinky_03_l", (1.0301, -0.4317, -2.7689), 1.1524299383163452),
("ring_01_l", (2.0167, -0.8928, -3.8422), 1.0971653461456299),
("ring_02_l", (0.8418, -0.5747, -3.3239), 1.3844847679138184),
("ring_03_l", (1.5493, -0.7850, -3.0117), 1.1123979091644287),
("thumb_01_l", (0.1295, -3.2002, -2.1717), -2.6270177364349365),
("thumb_02_l", (0.1767, -2.4893, -3.2052), -2.6139678955078125),
("thumb_03_l", (-0.3584, -2.9914, -2.7248), -2.2586119174957275),
("clavicle_r", (13.9182, -6.9506, 2.6710), -1.8446810245513916),
("upperarm_r", (9.9435, -1.1179, 11.7327), -2.4663352966308594),
("lowerarm_r", (14.7202, 8.7916, 11.2146), -2.40354061126709),
("hand_r", (7.4183, 4.7717, 6.2159), 2.52095627784729),
("index_01_r", (1.6298, 1.3285, 3.7367), 2.510608673095703),
("index_02_r", (0.7641, 0.6676, 3.2386), 2.400984048843384),
("index_03_r", (1.1548, 1.0154, 3.0254), 2.5221238136291504),
("middle_01_r", (2.0409, 1.2455, 3.9772), 2.3247838020324707),
("middle_02_r", (0.9042, 0.8173, 3.4393), 2.1239285469055176),
("middle_03_r", (1.8408, 0.8000, 3.0473), 2.3496832847595215),
("pinky_01_r", (1.9122, 0.2855, 3.0024), 2.030719757080078),
("pinky_02_r", (1.0752, 0.2280, 2.7757), 1.8695118427276611),
("pinky_03_r", (1.0300, 0.4316, 2.7686), 1.8647516965866089),
("ring_01_r", (2.0165, 0.8928, 3.8419), 2.0638554096221924),
("ring_02_r", (0.8418, 0.5747, 3.3239), 1.8805898427963257),
("ring_03_r", (1.5493, 0.7850, 3.0117), 2.062621593475342),
("thumb_01_r", (0.1295, 3.2001, 2.1717), -2.507920503616333),
("thumb_02_r", (0.1767, 2.4893, 3.2052), -2.5038182735443115),
("thumb_03_r", (-0.3584, 2.9914, 2.7248), -2.5201525688171387),
("neck_01", (0.0000, -2.2521, 9.0137), 1.2046517383623723e-07),
("head", (0.0000, 0.2141, 9.2883), 1.203985817710418e-07),
("thigh_l", (-3.9585, -0.9659, 32.0754), 0.022982334718108177),
("calf_l", (-2.1573, -4.7335, 29.8874), -0.019580373540520668),
("foot_l", (-0.2906, -0.2511, 19.5951), 0.030697213485836983),
("ball_l", (0.9077, -19.5579, -0.8815), -1.5856081247329712),
("thigh_r", (-3.9585, 0.9659, -32.0755), 0.268565833568573),
("calf_r", (-2.1573, 4.7335, -29.8876), 0.12452912330627441),
("foot_r", (-0.2906, 0.2511, -19.5950), 0.060352873057127),
("ball_r", (0.9077, 19.5579, 0.8815), 0.014443517662584782)
]

for bone in bones:
    arm.edit_bones[bone[0]].tail = arm.edit_bones[bone[0]].head + mathutils.Vector(bone[1])
    arm.edit_bones[bone[0]].roll = bone[2]
[Sandy]
 
Posts: 20
Joined: Mon Feb 18, 2019 8:12 pm

Re: MH2UE4u

Postby Grajo » Thu Jul 16, 2020 10:55 am

Hi MH2UE4u,

I am new to this Open Source great tool, and to the forum.
Thank you very much for sharing this info/knowledge. I think I will give it a shot at some point when I feel more comfortable with UE.

Best!
Grajo
 
Posts: 1
Joined: Thu Jul 16, 2020 10:29 am
Location: Monpellier, France

Re: MH2UE4u

Postby [Sandy] » Fri Jul 24, 2020 1:24 pm

Hi Grajo. I wish your project with makehuman and Unreal Engine a success.

And I registered Apose_ue to the asset.
[Sandy]
 
Posts: 20
Joined: Mon Feb 18, 2019 8:12 pm

Re: MH2UE4u

Postby nomorecookies » Thu Jul 30, 2020 5:04 pm

Wow! that is pretty cool!

I see what you mean about the pose though. it seems it was posed to compensate for the hunchback, but really, it should not be. that causes other animations to be leaned back. for example, the generic NPC anim pack. if you look at any of those, you can see they are leaned back the exact amount of the original pose compensation.

I am having a strange issue aside from all of that. there is a thing coming from the top of the spine of my character, all the way to the floor. it is like the type of problems you get when you forget to set the retargeting iptions in different scenarios. i did everything per instructions, and assigned directly to the ue4 mannequin skeleton. everything works great, just that strange extension from the back top of the spine, about a 45 degree angle, all the way to the floor.

any help fixing that would be appreciated. also, the UEFY script has a pose mechanic built in. i could perhaps pose an fbx and send that over to you if you would like to change the pose.

Thanks again for making this, it is really useful!

side note, if i just use the pose and not the script and then just retarget within UE4 i do not have the same issue with the extension to the floor.
be well
nomorecookies
 
Posts: 81
Joined: Thu Jul 30, 2020 1:34 pm

Re: MH2UE4u

Postby nomorecookies » Fri Jul 31, 2020 5:43 am

AssetDK-
That is a nice start with the wiki!
one thing i noticed though, you have the eye set to shader model eye. this is incorrect according to Epic. that eye shader is meant to be used only with the particular geometry of the included eye in 'ContentExamples' which is the same eye, although not exportable, that is from 'DigitalHuman'. Epic says that the eye shader is highly dependent on the geometry and characteristics of that particular eye, and suggests you should only use it with such. an easier, perhaps more appropriate way to make the MH eye work in UE4 is to set blend mode to alpha composite and leave it as default lit. in this scenario you may wish to connect the alpha channel to refraction, but i have not fully testing lighting on that.
here is the quote from Epic

"WARNING: The Eye shader in UE4 is highly technical and has been developed such that there are very strong dependencies between the shader code, the Material, the shape of the geometry, and the geometry's UV layout. Building an eye from scratch using this shader is not recommended without extensive experience in shader development. To that end, we strongly recommend, for those creating realistic humanoid eyes, that you extract the eye geometry from this example and use the eye Material as-is, replacing the necessary textures to suit your purpose. "

from this https://docs.unrealengine.com/en-US/Resources/Showcases/PhotorealisticCharacter/index.html page.
nomorecookies
 
Posts: 81
Joined: Thu Jul 30, 2020 1:34 pm

Re: MH2UE4u

Postby [Sandy] » Fri Jul 31, 2020 1:13 pm

Hi.
nomorecookies wrote:Wow! that is pretty cool!

Your praise has made me quite motivated! By the way, I'm not good at English, so there may be parts of you that don't understand exactly what you want to say.

nomorecookies wrote:the UEFY script has a pose mechanic built in.

Are you using UEFY? The python script I wrote assumes that you use makehuman game engine skeleton.
[Sandy] wrote:1.1. Pose/Animate - Skeleton: Game engine


nomorecookies wrote:I see what you mean about the pose though. it seems it was posed to compensate for the hunchback, but really, it should not be. that causes other animations to be leaned back. for example, the generic NPC anim pack. if you look at any of those, you can see they are leaned back the exact amount of the original pose compensation.

"Apose_ue" is applied to correct the difference between makehuman's A pose and Unreal's A pose. I'm checking using third-person animations, anim starter packs, MCO_MOCAP Basics, but do you think these animations are also weird?

nomorecookies wrote:I am having a strange issue aside from all of that. there is a thing coming from the top of the spine of my character, all the way to the floor. it is like the type of problems you get when you forget to set the retargeting iptions in different scenarios. i did everything per instructions, and assigned directly to the ue4 mannequin skeleton. everything works great, just that strange extension from the back top of the spine, about a 45 degree angle, all the way to the floor.

Does this behavior occur even with naked characters? Or does it happen when you wear certain clothes? If you experience any symptoms with a particular garment, what is the name of the garment? It may be useful for investigating the cause.

I hope your problem will be solved.
[Sandy]
 
Posts: 20
Joined: Mon Feb 18, 2019 8:12 pm

Re: MH2UE4u

Postby nomorecookies » Sat Aug 01, 2020 2:22 am

Hello.

Please keep in mind, these are just opinions based on what i think i see. the way the animations work with your pose may be exactly how they should look



Are you using UEFY? The python script I wrote assumes that you use makehuman game engine skeleton.

No. I was just mentioning its perfectly matched pose to the Mannequin

"Apose_ue" is applied to correct the difference between makehuman's A pose and Unreal's A pose. I'm checking using third-person animations, anim starter packs, MCO_MOCAP Basics, but do you think these animations are also weird?

Yes. Any animation looks strange to me, due to the inital "Apose_ue" position. I will attempt to include screenshots to better illustrate what i mean.

Here is your included Apose_ue:
Image
Here is the pose that is perfectly matched to the Ue4 Mannequin (this is the pose that uefy makes when is dos its pose matching):
Image
As can be seen, 'Apose_ue' is leaned back. This does make the initial walk and run animations look better (less hunchbacked), but it looks strange when you use an animation that was alreay standing up straight. it causes a lean back effect, when it should be a normal standing posture.


Does this behavior occur even with naked characters? Or does it happen when you wear certain clothes? If you experience any symptoms with a particular garment, what is the name of the garment? It may be useful for investigating the cause.

Naked character, but it had hair. I think perhaps this issue was my error. i will get back to you about this issue. here is a screenshot just for reference.
Image

I hope your problem will be solved.

Thank you, me too!


Again, thank you very much for this. It really is something i had been hoping for, for a long time.
Be well!
Last edited by nomorecookies on Sat Aug 01, 2020 6:15 am, edited 1 time in total.
nomorecookies
 
Posts: 81
Joined: Thu Jul 30, 2020 1:34 pm

Re: MH2UE4u

Postby nomorecookies » Sat Aug 01, 2020 4:15 am

Sadly i have been unable to find a solution to the 'anchor' problem. Many, Many attempts. including or not including body parts, hair, etc. nothing is fixing it.
Perhaps the code that is posted on this page is slightly different than what you have locally on your computer?
Maybe you could post the script again, just to make sure.

Thank you
nomorecookies
 
Posts: 81
Joined: Thu Jul 30, 2020 1:34 pm

Next

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest