1
\$\begingroup\$

Suppose I have two meshes (Let call me first MeshShirt and second - MeshBody) Meshes are aligned (if i render both MeshShirt "covers" MeshBody). But some parts of the body are not "under" the MeshShirt (because MeshShirt shape differs from MeshBody)

How can i "pull up" parts of MeshShirt which are under MeshBody and hold other parts in their places? Of course i want save shape of MeshShirt if it possible

I think about following algorithm

  1. mark all points of MeshShire which under MehsBody by tracing intersection of its normals and MeshBody.

    But if MeshShirt "hidden" parts have complex shape normal tracing will not work. So some way to detect bad points is needed

  2. move every marked point to the plane of its nearest triangle of MeshBody.

    But i afraid that these algoritm may produce significant deformation of MeshShirt. So some shape preserved deformation is needed too.

Sorry for my poor English and fuzzy problem definition

\$\endgroup\$
7
  • \$\begingroup\$ Physics cloth? they are expensive... Or if you mean at modelling time, you better ask on your tool's forums. \$\endgroup\$
    – Kroltan
    Dec 3, 2014 at 9:54
  • \$\begingroup\$ Expensive and hard to implement too :) But i not need realistic cloth simulation. It i suppose to run these algo in some initial phase of my program work. \$\endgroup\$
    – Daiver
    Dec 3, 2014 at 9:59
  • \$\begingroup\$ "Initial" as in boot time, or shipped? If your shirt model has a common distance between each vertex, you can try moving the conflicting points, then rearranging the vertices connected to it recursively, until everything is within a threshold of your average distance. This works okay at your asset pipeline, and at load screens, but not very much in realtime. \$\endgroup\$
    – Kroltan
    Dec 3, 2014 at 10:05
  • \$\begingroup\$ > "Initial" as in boot time, or shipped. I can't catch difference, sorry. Case of algo usage: user provide some model. Some my procedure preprocess this model, and this algo is final step of preprocess procedure. After preprocess user can view model in viewport and do some other things. I understand that this question is not pure gamedev question but i don't know appropriate resource for it. I will add some additional info to post \$\endgroup\$
    – Daiver
    Dec 3, 2014 at 10:16
  • \$\begingroup\$ "shipped" would be that you have the models before shipping the game to users. But by your description it's the first option. Well, my suggestion while not optimal (I'm not a expert on this) works quite okay, I've used it before with custom colliders, to approximate them to a user-supplied model. \$\endgroup\$
    – Kroltan
    Dec 3, 2014 at 10:19

1 Answer 1

1
\$\begingroup\$

First, find the average, minimum and maximum distance all vertices in the shirt mesh. Let those be Da, Di and Dx, respectively.

Also let Dai = Di/Da and Dax = Dx/Da.

Then, you test each point of your shirt mesh Ms to know if it's inside the body mesh Mb, possibly using the Jordan Curve Theorem, which is based on raycasting. Store all vertices which are found to be inside the mesh in a list, then for each vertex Vc:

  • Get the nearest vertex Vn of Mb, trace a ray from Vc to Vn, store the contact point Pc
  • Move Vc to Pc

After this, you should have a relatively distorted model of your shirt. You then loop again on each Vc:

  • For each vertex Vx connected to Vc:
    • Get the distance of Vc to Vx
      • If it's greater than Dx, move Vx to a point Dax units away from Vc
      • If it's smaller than Di, move Vx to a point Dai units away from Vc
    • Repeat step 3 for all the vertices connected to Vx

I assume you know how to find the distance between vertices, and how to get a new vertex from a vertex, direction and distance. If not, it would be great to learn that.

This should work for most meshes, but it's quite expensive, so I don't recommend doing this at runtime. If possible, run it once just and save the final mesh somewhere you can keep using it without recalculating.

This works the best for meshes with relatively close edge lengths, that is, a even distribution of vertices along the surface, though it works OK for other meshes too.

I hope this is clearer than the discussion in the comments.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Thank you for answer! I'll try to implement these algorithm and apply it to my meshes. Also, If some Vx is Vc too what i should do? Just move it like other Vx's? \$\endgroup\$
    – Daiver
    Dec 4, 2014 at 11:32
  • \$\begingroup\$ @Dark_Daiver Yes, that will help reduce distortion produced in the first part of the algorithm. \$\endgroup\$
    – Kroltan
    Dec 4, 2014 at 13:28
  • \$\begingroup\$ @Dark_Daiver So, did you get it to work? If this answer is fit, feel free to click the green checkmark to mark this answer as valid. You can always remove it if a better answer is added. :) \$\endgroup\$
    – Kroltan
    Dec 8, 2014 at 12:18
  • \$\begingroup\$ I know about green check mark =) But i have limited time to do these task. Also now i am debugging first stage of algo (searching bad vertices) \$\endgroup\$
    – Daiver
    Dec 8, 2014 at 12:21
  • \$\begingroup\$ @Dark_Daiver Okay, I hope you manage to do it! \$\endgroup\$
    – Kroltan
    Dec 8, 2014 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .