Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing in Blender #2

Open
dniku opened this issue Jun 18, 2020 · 2 comments
Open

Importing in Blender #2

dniku opened this issue Jun 18, 2020 · 2 comments

Comments

@dniku
Copy link

dniku commented Jun 18, 2020

I'm having trouble importing models in Blender. I know this dataset is meant for Unity, but I still hope for some help with Blender specifically.

Here is the script that I eventually came up with to import a single FBX file:

from pathlib import Path
import bpy

rocketbox_root = Path('/path/to/cloned/Microsoft-Rocketbox')
avatar_path = rocketbox_root / 'Assets/Avatars/Adults/Female_Adult_01/Export/Female_Adult_01.fbx'

bpy.ops.object.delete(use_global=False, confirm=False)  # delete cube
bpy.ops.import_scene.fbx(filepath=str(avatar_path))

# Fix paths to textures
for im in bpy.data.images:
    im.filepath = im.filepath.replace('../../../../../temp/Humans/with_opacity_version/f001/textures', '../Textures')

# Workaround: make opacity texture fully transparent
bpy.data.materials['f001_opacity'].blend_method = 'CLIP'
bpy.data.materials['f001_opacity'].alpha_threshold = 1

In order to use it, launch Blender, switch to the "Scripting" tab, create a new script via the "+ New" button, paste this code and change the rocketbox_root variable to the path of the cloned repository.

In this script, I replace paths to textures which are hardcoded in the FBX file. In addition, I disable the opacity texture by making all polygons associated with it fully transparent. Here is what the imported model looks like without that step:

01_no_opacity_fix

If I set blend method to "alpha blend", I get this:

02_opacity_alpha_blend

The result with my workaround (mode = alpha clip, clip threshold = 1) is as follows:

03_opacity_alpha_clip_1

All of these images are rendered with the Eevee renderer, on white background. I am using Blender 2.83.

I am also not sure what the purpose is for the eyelash opacity textures. The eyelashes are already baked into the color map for the head texture, why duplicate them in the opacity texture?

Are there any guidelines for importing the models in Blender? Ideally, I would prefer a Python script that does everything, not instructions on what things need to be changed in the GUI.

@margonzalezfranco
Copy link
Contributor

I will need to investigate more. Certainly the ideal would be to use the alpha blend. But for the moment I think your clipping should be enough for now.
At the moment we don't have guidelines for blender, other than it should be similar to the preprocessing we are doing for Unity. Let me know if you want to contribute some specifics on that. send me an email and we can talk about how we can support you.
I will leave this issue open in case someone can give more info.

@rexfanyc
Copy link

rexfanyc commented Feb 8, 2023

I also wrote a script to recursively search the cloned repository for models and missing textures, for the opacity textures I utilized the same blend mode setting

import os
import bpy

rocketbox_root = '/path/to/cloned/Microsoft-Rocketbox'
filename = 'Female_Adult_01.fbx'

# recursively iterate through the repository and find specific avatar to import, with automatic_bone_orientation checked
for root, dirs, files in os.walk(rocketbox_root):
    for name in files:
        if name.endswith(filename):
          path_to_file = os.path.join(root, name)
          bpy.ops.import_scene.fbx( filepath = path_to_file, automatic_bone_orientation=True )

# find missing textures in the repository 
bpy.ops.file.find_missing_files(directory = rocketbox_root)

# make opacity texture fully transparent
for material in bpy.data.materials:
    if material.name.endswith('opacity'):
        bpy.data.materials[material.name].blend_method = 'CLIP'
        bpy.data.materials[material.name].alpha_threshold = 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants