animate1978 / MB-Lab

MB-Lab is a character creation tool for Blender 4.0 and above, based off ManuelBastioniLAB
Other
1.76k stars 308 forks source link

Could I use the assets to create a Rust crate? And how would I use them? #356

Closed JonahPlusPlus closed 2 years ago

JonahPlusPlus commented 2 years ago

I believe this question is best suited for @animate1978, if I'm not mistaken. I really love this plugin and wish there was a library version I could use to then generate character models in game. I would love to get some pointers on how to go about it, if it's OK for me to do so. I would of course include any licenses for the base models and generated ones. I would do it in C++, but I'm a bit rusty (no pun intended), so plan on creating a Rust crate instead. I have a bit of experience with 3D graphics programming, and was able to modify the male base mesh to make it fatter by shifting the vertices across the normals.

However, I'm not a great artist, and wouldn't be able to figure out the values for modifying parts of the mesh to create features. So I would love info on how things like morph values and transform values are used and whatever anthropometry and measures data is. Thanks!

Upliner commented 2 years ago

Morph values are deltas (difference) data for each vertex. Just add them to base vertex values to apply the morph. Transform values define which morphs to apply to modify age, mass and muscles.

JonahPlusPlus commented 2 years ago

OK, so morph values come in arrays where I assume to be [value/index, x, y, z], correct? I'm guessing that first integer refers to an index or some identifier? And then in the transform values, I'm guessing the associated morph values are ranges which are mapped from the base value which can be age, mass, and tone, and then the mapped value is multiplied by the morph delta, and then you add them to the base vertex value?

JonahPlusPlus commented 2 years ago

And then the measures option menu in the plugin, is that overriding the morph value, or adding to it, in which case, I'm guessing it is scaled down, in which case, what's the scale? 10%?

JonahPlusPlus commented 2 years ago

https://github.com/animate1978/MB-Lab/issues/356#issuecomment-920429864 Adding to this, I can't seem to find that first integer (the one from first array in that morph values file) in any of the other data files.

JonahPlusPlus commented 2 years ago

After creating a struct to parse the JSON, I think that the first number is the tr_parameter[0] which corresponds to a number in a prop inside the character_data of a Humanoid: https://github.com/animate1978/MB-Lab/blob/99e08d0e7dfeaa4116b9d5f64ca75339d5363f2c/humanoid.py#L976-L981 But I don't see the fourth value being used, so I'm not sure. Also, where is this character_data coming from? The measures section from human_male_measures.json? And if so, what is the other data for? I'm guessing the relations field is for translating JSON fields to some fields in classes, but the score_weights looks important.

JonahPlusPlus commented 2 years ago

Ah, I must have been confusing the morph values, which have 4 values, for the transform values, which have 3. Which would mean that the prop holds a list of strings, which are body part properties. But since the transform files have "base" and "dwarf" in their names, I'm guessing that these aren't ranges but base transformations? But then how are they applied? They aren't 3D vertex positions, and I doubt that they are 2D vectors. This is why I need some help. 😅

JonahPlusPlus commented 2 years ago

Hey @Upliner Got some sleep and thinking more clearly now. So the transform values create the linear factor, which is added to the character data, which is used to combine morphs and the weights generated are used to calculate the morph which modifies the mesh by adding a value generated from the weights and morph data. Am I correct?

JonahPlusPlus commented 2 years ago

Also where are the indices in all of this data? I tried looking for duplicates in the vertices, but didn't find any, so I assume there must be indices, right?

JonahPlusPlus commented 2 years ago

https://github.com/animate1978/MB-Lab/blob/99e08d0e7dfeaa4116b9d5f64ca75339d5363f2c/algorithms.py#L189-L193

I got pretty much most of the basic stuff done, but this is confusing. It's taking all the combinations of min and max, but are all the combinations covered? I think I just realized that I am supposed to load the morphs for human_male, human_male_extras and m_ca01 and combine them, but I still have doubts.

ldo commented 2 years ago

I’ve been looking a bit at this, if it helps. itertools.product() returns the Cartesian product of its arguments, so for example if there are two elements in morph_values, then tags will contain [["max", "min"], ["max", "min"]], and so names will be filled in with

prefix_max-max
prefix_max-min
prefix_min-max
prefix_min-min

At least, that’s how it looks to me. ;)

JonahPlusPlus commented 2 years ago

Yeah, I realize that, I was just concerned that not every combination would be found in morphs data.

JonahPlusPlus commented 2 years ago

@ldo Hey, where would I get the indices for the model? I think I got all code needed for calculating and applying morphs done, but need the indices to actually export the generated model.

Noizirom commented 2 years ago

The easiest way to get the indices is to take the vertices count and creating a ranged lists. Example: [I for I in range(Len(bpy.data.objects["my_object"].data.vertices))]

JonahPlusPlus commented 2 years ago

@Noizirom Wait, so there isn't a set of indices? They are just generated from the vertex lists, essentially creating a list of numbers 0 to (number of vertices) - 1? Wouldn't that mean that in order to have a mesh of connected triangles, there would have to be copies of vertices at the same positions? I tried looking for duplicates in the vertex data, but couldn't find any. Also, that would make the model flat-shaded, instead of smooth shaded. This couldn't be it, unless I'm missing something?

Noizirom commented 2 years ago

Maybe I misunderstood. That to generate a quick list of indices without looping through the object. What particular indices are you looking for?

On Sat, Sep 18, 2021, 12:54 PM Jonah Henriksson @.***> wrote:

@Noizirom https://github.com/Noizirom Wait, so there isn't a set of indices? They are just generated from the vertex lists, essentially creating a list of numbers 0 to (number of vertices) - 1? Wouldn't that mean that in order to have a mesh of connected triangles, there would have to be copies of vertices at the same positions? I tried looking for duplicates in the vertex data, but couldn't find any. Also, that would make the model flat-shaded, instead of smooth shaded. This couldn't be it, unless I'm missing something?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/animate1978/MB-Lab/issues/356#issuecomment-922339111, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKYHC3QZKQ4IBADKTSY2I3LUCS733ANCNFSM5EDEF3BA .

Noizirom commented 2 years ago

Sorry I missed most of the conversation. If you trying to track how vertices change in morphs, you want to follow the indices. (Which you discovered) The morphs are typically linear interpolations (lerp) between 2 points. As far as the MB lab morphs the simplest way to explain it is that they are a blend of several morphs. It basically takes a combination of lerps and returns a point. The only close thing I could use to explain that is think of how bezier curve points are calculated (as a visual reference)

On Sat, Sep 18, 2021, 2:39 PM Zion Hill Hill @.***> wrote:

Maybe I misunderstood. That to generate a quick list of indices without looping through the object. What particular indices are you looking for?

On Sat, Sep 18, 2021, 12:54 PM Jonah Henriksson @.***> wrote:

@Noizirom https://github.com/Noizirom Wait, so there isn't a set of indices? They are just generated from the vertex lists, essentially creating a list of numbers 0 to (number of vertices) - 1? Wouldn't that mean that in order to have a mesh of connected triangles, there would have to be copies of vertices at the same positions? I tried looking for duplicates in the vertex data, but couldn't find any. Also, that would make the model flat-shaded, instead of smooth shaded. This couldn't be it, unless I'm missing something?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/animate1978/MB-Lab/issues/356#issuecomment-922339111, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKYHC3QZKQ4IBADKTSY2I3LUCS733ANCNFSM5EDEF3BA .

ldo commented 2 years ago

Definition of faces is done by referencing the vertices by index. c.f. Mesh.from_pydata().

Noizirom commented 2 years ago

To get the face indices I would use [i.vertices for i in ob.data.polygons] To return a nested list of indices. Ex. [[0,1,2,3], [4,5,6,7]...]

Again I was late to the conversation. I apologize if this is not what you are looking for.

On Sat, Sep 18, 2021, 8:27 PM ldo @.***> wrote:

Definition of faces is done by referencing the vertices by index. c.f. Mesh.from_pydata() https://docs.blender.org/api/master/bpy.types.Mesh.html?highlight=from_pydata#bpy.types.Mesh.from_pydata .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/animate1978/MB-Lab/issues/356#issuecomment-922393690, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKYHC3TWCWK4TAY3M2NQ62TUCUU6RANCNFSM5EDEF3BA .