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

Preprocess data #38

Open
artursahak opened this issue Mar 13, 2021 · 12 comments
Open

Preprocess data #38

artursahak opened this issue Mar 13, 2021 · 12 comments

Comments

@artursahak
Copy link

Dear Zhan-xu, thank you for your huge work.
Could you provide some insight on how to generate rigging joints and skinning data the way you have in .txt format?

`joints ankle_r -0.11857700 0.06815820 -0.27102600
joints tail_4 -0.00000002 0.31470800 -0.34982900
joints collar -0.00000000 0.28504700 0.02488300
joints face -0.00000000 0.31088600 0.05898700
joints arm_l1 0.11882800 0.20566000 -0.00539320

skin 10 mouth_r 1.0000
skin 11 mouth 0.4000 mouth_r 0.6000
skin 12 mouth 0.7000 mouth_r 0.3000
skin 13 mouth 0.7000 mouth_r 0.3000
skin 14 mouth 0.7000 mouth_r 0.3000 `

@zhan-xu
Copy link
Owner

zhan-xu commented Mar 13, 2021

Hi, to get the information you will need some parser for your input format. This part is not so elegant and requires some manual check on the parser results (partially due to the inconsistency of different formats of rigged models). That is why I didn't release code for this.

There are some off-the-shelf parsers that I know:
pycollada https://pycollada.readthedocs.io/en/latest/
open3D 0.11.0 supports fbx gltf http://www.open3d.org/2020/10/15/open3d-0-11-0/
assimp: https://www.assimp.org/
and also shipped parser from Blender and Maya.

In my project, I initially use .dae models (collada). I found no parser can be used for all downloaded models. In the end I use pycollada and Maya to get the information, and check the results manually.

I released a Maya script to parse FBX format, as a reference that you can start from:
#8 (comment)
Note the limitation of this code (only for single geometry component, but you can definitely change that).

@artursahak
Copy link
Author

Thank you very much. I tried with .blv or other mocap formats in ascii but got confused. I'll tell you if I make up any other method for this task.
(By the way, I tried something similar to this but on 2d images and then sending coordinates to blender to edit the rigged skeleton automatically), but what you did here is quite impressive.

@FishWoWater
Copy link

FishWoWater commented Apr 5, 2021

@zhan-xu Hi! I have tried your fbx parser with fbx models downloaded elsewhere. It seems that the texture or vertex color information is lost during the parsing process. Is there any way to restore this information or parse from fbx using mayapy? Also, how can I save obj, riginfo along with texture back into fbx? Can you offer some tutorials / blogs / links about this? Thanks !!!!!

@zhan-xu
Copy link
Owner

zhan-xu commented Apr 6, 2021

Hi. My fbx parser if a very preliminary one and has many limitations. For your question, I think you need cmds.polyEditUV to get vertex UV, and cmds.polyColorPerVertex to get vertex color. In function record_obj, write the UV and color according to OBJ format.

Another possibility is instead of using record_obj, try something like:

cmds.select(geo_list[0]) # select a mesh.
cmds.file(output_filename, force=True, op="groups=0;ptgroups=0;materials=0;smoothing=0;normals=1", typ="OBJexport", pr=True, es=True) # save the selected mesh to OBJ file

There are several options you can choose for parameter "op". You need to figure out which flag to use to save vertex color and uv.

To reassemble rig_info and obj back to fbx, you can use RigNet/maya_save_fbx.py with mayapy. Still, i didn't consider color and texture here, but if your obj file already has that information, I assume they will be loaded when you open the OBJ.

@FishWoWater
Copy link

Thanks for your quick and detailed reply!!!
I will try that!
Wish you all the best

@FishWoWater
Copy link

FishWoWater commented Apr 9, 2021

Hi. My fbx parser if a very preliminary one and has many limitations. For your question, I think you need cmds.polyEditUV to get vertex UV, and cmds.polyColorPerVertex to get vertex color. In function record_obj, write the UV and color according to OBJ format.

Another possibility is instead of using record_obj, try something like:

cmds.select(geo_list[0]) # select a mesh.
cmds.file(output_filename, force=True, op="groups=0;ptgroups=0;materials=0;smoothing=0;normals=1", typ="OBJexport", pr=True, es=True) # save the selected mesh to OBJ file

There are several options you can choose for parameter "op". You need to figure out which flag to use to save vertex color and uv.

To reassemble rig_info and obj back to fbx, you can use RigNet/maya_save_fbx.py with mayapy. Still, i didn't consider color and texture here, but if your obj file already has that information, I assume they will be loaded when you open the OBJ.

I was able to use

cmds.file(output_filename, force=True, op="groups=0;ptgroups=0;materials=1;smoothing=0;normals=1", typ="OBJexport", pr=True, es=True) # save the selected mesh to OBJ file

to save the material into .mtl file and load the obj.
But when I tried to get vertex color by

for geo in geoList:
        vtxIndexList = cmds.getAttr(geo + ".vrts", multiIndices=True)
        for i in vtxIndexList:
            print(cmds.polyColorPerVertex(geo + ".vtx[" + str(i) + "]", query=True, rgb=True))
            # print(i)
            # print(cmds.polyEditUV)
            pos = cmds.xform( geo + ".vtx[" + str(i) + "]", query=True, translation=True, worldSpace=True )

in record_obj function, it saied RuntimeError: No components were found to query.
can you give some idea about this bug? I tried to use cmds.select to select the object or vertex but failed. Also , it worked well in edit mode but failed in query mode

@zhan-xu
Copy link
Owner

zhan-xu commented Apr 13, 2021

Hi, I just tried by myself and had the same problem.
I think the first thing is to make sure whether the color comes from vertex color or texture. If they come from texture, you will need to query UV.

Take a look at the this https://gamedev.stackexchange.com/a/66270
Seems Maya is not able to export OBJ with vertex color. Not quite sure about this though.

@FishWoWater
Copy link

@zhan-xu Got it! Thanks!!!

@sunshineatnoon
Copy link

Hi, to get the information you will need some parser for your input format. This part is not so elegant and requires some manual check on the parser results (partially due to the inconsistency of different formats of rigged models). That is why I didn't release code for this.

There are some off-the-shelf parsers that I know: pycollada https://pycollada.readthedocs.io/en/latest/ open3D 0.11.0 supports fbx gltf http://www.open3d.org/2020/10/15/open3d-0-11-0/ assimp: https://www.assimp.org/ and also shipped parser from Blender and Maya.

In my project, I initially use .dae models (collada). I found no parser can be used for all downloaded models. In the end I use pycollada and Maya to get the information, and check the results manually.

I released a Maya script to parse FBX format, as a reference that you can start from: #8 (comment) Note the limitation of this code (only for single geometry component, but you can definitely change that).

Hi, Could you please elaborate more on how to process meshes with multiple components? Thanks!

@zhan-xu
Copy link
Owner

zhan-xu commented Oct 23, 2022

sorry but i don't have a ready-to-use parser for any fbx format. Maybe you can search if there is any latest python library that support it. My maya [script](new link) can only preprocess single component. I am not sure how hard it is to modify it for multiple components. Check Line 160 where I take [0] only and you might start from there. Or you can try if some software or library can convert multiple-component mesh to single-component one.

@sunshineatnoon
Copy link

sorry but i don't have a ready-to-use parser for any fbx format. Maybe you can search if there is any latest python library that support it. My maya [script](new link) can only preprocess single component. I am not sure how hard it is to modify it for multiple components. Check Line 160 where I take [0] only and you might start from there. Or you can try if some software or library can convert multiple-component mesh to single-component one.

Thanks for the reply, I ended up using Maya to combine all components into a single component.

@siddharthKatageri
Copy link

Hi @sunshineatnoon, Can you please share your script for converting parsing .fbx files (that handles all the present components)?
Thanks!

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

5 participants