powroupi / blender_mmd_tools

mmd_tools is a blender addon for importing Models and Motions of MikuMikuDance.
GNU General Public License v3.0
1.82k stars 277 forks source link

character conversion to pmx with mmd_tools? #80

Open Hogarth-MMD opened 7 years ago

Hogarth-MMD commented 7 years ago

Is it possible to convert a character to pmx using mmd_tools? Someone could import a character into Blender from Blender or Sims or Poser or XNALara or whatever, rename the bones to MMD Japanese bone names and then try to export it to pmx with mmd_tools. Would this be successful? Or will someone need to write a python script which adds all of the necessary pmx custom properties to the model before this could be successful?

Hogarth-MMD commented 6 years ago

Hello @powroupi ! The Sintel baby dragon is being exported by mmd_tools without his wings texture and his wing material is named "Untitled". The disable sphere texture export option is not working for him. Has not this baby dragon been wounded enough and can we not send to him a nice new home in MMD?

Hogarth-MMD commented 6 years ago

Sintel adult dragon has 8 UV maps and Sintel baby dragon has 4 UV maps. Maybe this is causing a problem for exporting of materials with mmd_tools(?).

powroupi commented 6 years ago

Material issues can not be solved completely because it is hard to know which is which, especially node materials. You need to understand the models' material design and convert/fix materials manually for MMD. "Untitled" material means the faces were not assigned to any material or were assigned to a "empty" material slot. :sunglasses:

[EDIT] I don't have the .blend and other files from the Sintel DVDs, sorry. :cry:

Hogarth-MMD commented 6 years ago

Hello @powroupi! There are 4 Sintel DVDs. The files that you need are on Sintel DVD number 4. This is a completely free and legal download which you can download from file sharing web sites. Sintel and the other Blender open movie DVDs have a creative commons license. I highly recommend that you do not deprive yourself of this beautiful generosity.

Hogarth-MMD commented 6 years ago

https://store.blender.org/product/membership/ "Blender Cloud gives you access to all Blender Institute trainings, all Open Movies (film and all assets) and much more. Blender Cloud is our Open Production platform where we make and share animation film projects. " The Blender Foundation offers a service called "Blender Cloud". You can subscribe to this service for a small monthly fee, If I understand correctly, a Blender Cloud member can conveniently download Sintel and other open movie DVDs from a Blender Cloud web site.

Hogarth-MMD commented 6 years ago

I have solved the problem with the mesh deform rigging of Sintel: Transferring of vertex groups from the mesh deform cage object to Sintel, using Blender's data transfer modifier, using the vertex group mask option, and using the project option, instead of the nearest vertex option, with the data transfer modifier.

Hogarth-MMD commented 6 years ago

How does mmd_tools handle 4 or 8 UV maps of a model? Can it combine these UV maps into one UV map when exporting to .pmx?

Hogarth-MMD commented 6 years ago

Hello @powroupi ! Should I just wait patiently for you to download the Sintel DVDs? Or will I be forced to upload .blend files when I need your help with Sintel models?

powroupi commented 6 years ago

mmd_tools can export multiple UV maps of a model in some case.

I'm sorry, I can understand that you will have many questions about Sintel's .blend files, but I'm not a fan of Sintel DVDs. Some .blend files may only work on previous version of Blender, and converting them to MMD would not be easy since they were designed to be animated/rendered in Blender. :cry:

nathanvasil commented 6 years ago

@Hogarth-MMD While MMD Tools can export some add UV maps, as many as the PMX format supports, remember that MMD itself does not use these for any purpose-- if your model uses a second UV channel, you need to figure out to why it uses that second UV channel. Additional UV is often convenient, but rarely necessary.

What you probably need to do to convert that model (I've looked at a a Sintel model on Blendswap, but there are tons of them, not sure I've looked at the same one as you) is to rebake any textures that use add UV onto a single UV channel.

Hogarth-MMD commented 6 years ago

" I'm not a fan of Sintel DVDs. Some .blend files may only work on previous version of Blender,"

This is not a problem. The Sintel-compatible version of Blender is on Sintel DVD 1.

The Sintel-compatible version of Blender (from the Sintel DVD) can also be downloaded from http://graphicall.org

Render Branch Win32 as in Sintel DVD http://graphicall.org/396

Render Branch Win64, as in Sintel DVD http://graphicall.org/397

Render Branch Linux32, As In Sintel DVD http://graphicall.org/398

Render Branch Linux64, As In Sintel DVD http://graphicall.org/399

Hogarth-MMD commented 6 years ago

"converting them to MMD would not be easy since they were designed to be animated/rendered in Blender. "

This is mostly a problem for me, not a problem for you.

Hogarth-MMD commented 6 years ago

In Blender a UV map is assigned to every UV mapped texture image. I looked in PMD editor and PMX editor. There is no option to assign a UV map to a material or texture.

Hogarth-MMD commented 6 years ago

https://sta.sh/02fl5iwrstp3

Hello @powroupi ! Here is the Sintel adult dragon .blend file. It has 9 materials but only 3 of these materials are exported by mmd_tools. Can you please clarify to me why this happens, and how do we fix this issue?

powroupi commented 6 years ago

It has 9 materials but only 3 of these materials are exported by mmd_tools.

Yeah, mmd_tools only export the materials which are necessary. GEO-dragonA_body has 6 materials (body_tmp, head_tmp, wings_tmp, main_whole_SC, main_whole_indi, main_whole_82ze) not assigned any face, so they are not exported.

You can go to edit mode, and check a material is used by what faces. :)

Hogarth-MMD commented 6 years ago

Okay, I am glad that there is a simple, reasonable explanation for this issue. There is no idiot incompetence going on with the programmer of mmd_tools causing the non-export of 6 materials. :smile: So, I am getting a bad export of materials because the adult dragon and baby dragon have more than one diffuse texture on the same material.

Hogarth-MMD commented 6 years ago

Hello @powroupi ! Using Blender python, how can I detect if a material has no faces?

Hogarth-MMD commented 6 years ago
import bpy

polygons_materials = []
materials_no_polygons = []
for p in bpy.context.active_object.data.polygons:
    polygons_materials.append((p.material_index, p.index))

for m in range(len(bpy.context.active_object.data.materials)):
    materials_of_polygons = [mat[0] for mat in polygons_materials]
    if materials_of_polygons.count(m) == 0:
        materials_no_polygons.append(bpy.context.active_object.data.materials[m])

print('\n')
print("materials with no polygons = ")
for m in materials_no_polygons:
    print(m)
Hogarth-MMD commented 6 years ago

Is that the best method? I was hoping for a simple one line of Blender python code to find the empty materials.

powroupi commented 6 years ago

Maybe try this :smile:

used_material_indices = set(p.material_index for p in bpy.context.active_object.data.polygons)
print([m for i, m in enumerate(bpy.context.active_object.data.materials) if i not in used_material_indices])
Hogarth-MMD commented 6 years ago

Splitting materials by UV maps using Python is very difficult. I think it might be easier to do it manually.

In Blender, ALL vertexes-of-faces of a mesh object are stored as part of every uv_layer. If you want to use Python to detect which vertices have not been unwrapped for a specific UV layer, you need to look at the UV co-ordinate of that vertex. In Blender 2.79, if a vertex has not been unwrapped on a UV layer, it has one of 4 possible UV co-ordinates: 0,0 , 0,1 , 1,0 or 1,1 BUT, in Sintel dragons, all vertices which have not been unwrapped on a UV layer have a UV co-ordinate which is approximately, but not exactly, equal to 0,1 .

This is a completely obscure and undocumented fact of Blender python, which I deduced myself.

powroupi commented 6 years ago

When you create a UV map in Blender, all vertices have a initial UV co-ordinate on the UV map, and actually we unwrap faces, not vertices.

[EDIT] It is difficult/impossible to tell whether a face was unwrapped or not.

Hogarth-MMD commented 6 years ago

In the UV editor,enable "Keep UV and edit mode mesh selection in sync". Change to Face selection mode. Select a UV face. Click Select, Select Linked. The UV unwrapped faces of the mesh will be selected for the mesh in 3D view edit mode. You can then assign a material to these faces.

I don't know how or if this can be done using Python.

nathanvasil commented 6 years ago

What are you trying to do in Python? Assign a material to faces? Blender isn't going to know which island (selection of UV linked faces) you want to affect.

In edit mode, with a face selected:

bpy.context.object.active_material_index = 1 (or whatever) bpy.ops.object.material_slot_assign()

You should just be able to do these steps and see what the header prints out in debug mode, right?

Hogarth-MMD commented 6 years ago

What I am trying to do is split materials by uv maps in the Sintel dragon models. I hope that you are wrong about selecting linked faces being the same as island selection.

powroupi commented 6 years ago

@Hogarth-MMD , I guess you can't split materials by uv maps. One texture usually use one UV map, but one material can use multiple textures with different blend modes and UV maps.

If a model uses multiple UV maps, it usually means that you need to write some MME shaders after converting it from Blender to MMD to achieve similar render result. Otherwise, you may use some techniques of baking textures like @nathanvasil said (I have no experience of that yet though). :sweat_smile:

Hogarth-MMD commented 6 years ago

Maybe try this smile

used_material_indices = set(p.material_index for p in bpy.context.active_object.data.polygons)
print([m for i, m in enumerate(bpy.context.active_object.data.materials) if i not in used_material_indices])

Thanks, is there any reason why used_material_indices should be a set instead of a list?

powroupi commented 6 years ago

is there any reason why used_material_indices should be a set instead of a list?

set([1,1,1,3,5,5,1,6,6,6,3,1,1,3,6]) = {1, 3, 5, 6}, so there won't be any duplicates. :smile: (although the print result is the same if you change used_material_indices to a list)

Hogarth-MMD commented 6 years ago

https://sta.sh/01zyyhmhpqw

Here is a download of 2 beautiful butterflies from the Sintel DVD and a butterfly wings flapping animation. I converted these to MMD using this really cool Blender add-on. I cannot remember the name of this add-on, but if remember the name of this add-on, then I will post this information. :smile: