Dear Users,

Now, we are seeking users who can give us a hand with expertise to evolve our software more dynamically.
If you are willing to help us, we’d like you to make a registration for “Live2D Creators Circle” via the link below.
Designers, programmers, translators are especially welcomed so far.
(More detailed explanation will be given to you before we ask you to do tasks)

https://docs.google.com/forms/d/1G5KK_GL3ozwPXtTHrpi_ktbsI8UZf8jlYRSlDworyBo/viewform?usp=send_form

Mesh Collider in Unity

Hi, I am having problems with Mesh Colliders in Unity. I will try to explain my situation.

When I add a model to a Unity Scene, based on code from creating canvas, it will add this Mesh configuration for various mesh parameters:

MeshRenderer meshRenderer = goLive2DCanvas.AddComponent<MeshRenderer>(); meshRenderer.sharedMaterial = new Material(Shader.Find("Transparent/Diffuse")); meshRenderer.sharedMaterial.SetColor("_Color", new Color(0,0,0,0)); MeshFilter meshFilter = goLive2DCanvas.AddComponent<MeshFilter>(); meshFilter.mesh = new Mesh(); Mesh mesh = meshFilter.sharedMesh; mesh.name = "L2D_Model"; mesh.vertices = new Vector3[]{ new Vector3 (-10f, 0.0f, 10f), new Vector3 ( 10f, 0.0f, 10f), new Vector3 ( 10f, 0.0f, -10f), new Vector3 (-10f, 0.0f, -10f) }; mesh.triangles = new int[]{ 0, 1, 2, 2, 3, 0 }; mesh.uv = new Vector2[]{ new Vector2 (0.0f, 1.0f), new Vector2 (1.0f, 1.0f), new Vector2 (1.0f, 0.0f), new Vector2 (0.0f, 0.0f) }; mesh.RecalculateNormals(); // 法線の再計算 mesh.RecalculateBounds(); // バウンディングボリュームの再計算 mesh.Optimize();

This is a quad mesh.

I need to use physics from Unity and this mesh for Mesh Collider is very far away to match the Live2D model. When I use the frame debugger, Draw Mesh calls shows the real mesh of the Live2D model. How can I get this mesh for adding to the Mesh Collider and get a real physics collision, etc?

Comments

  • edited November 2015
    Hi, BlackZStudios .
    I also tried in Live2D SDK Sample project (SampleApp1).

    It is as you say .
    Then AddComponent the Rigidbody to Live2D model , the following error came out .


    I think that it can be solved by changing to Box Collider.


    A result of the execution , and worked without error .


    Is this what you were trying to do?
  • edited November 2015
    Hi naotaro, thanks for your reply. Unfortunately, this is not what I am trying to do. I will try to explain the problem in a better way.

    Using "SampleApp1", I have created two same model of "Haru".


    When you add a RigidBody component to the GameObject without Mesh Collider you can get same behavior as you have left checked "Use Gravity". When using the Mesh Collider It will show that error "Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported in Unity 5." You can resolve this using the check box of "Convex"



    When you have activated the Convex, RigidBody and Mesh Collider will do the job. However, here is where the problem comes up.

    If we check the Scene when activate Convex, we can see the Mesh Collider shape in green:



    If check the Inspector, Mesh provided to model is a simple quad or plane:


    What I want to get is the real Mesh of the object once it has been rendered, like Frame Debugger shows after Draw Mesh call: (for example)



    Using this little code for adding a force to one model shows the incorrect behavior:
    if (physics) { rigidbody.AddForce(100.0f, 0.0f, 0.0f); }

    This is a demo when play the Scene


    1.png 198.9K
    2.png 10.6K
    3.png 371K
    4.png 29.3K
    5.png 141.3K
  • hi BlackZStudios, Is this what you were trying to do?
    this is the document of make the model + collision detection

    https://translate.google.com/translate?hl=ja&amp;sl=ja&amp;tl=en&amp;u=http://sites.cybernoids.jp/cubism2/modeler/models/collision&amp;sandbox=1

    thanks!

  • Hi Yuan, thanks for your response!

    I am also using that for hits collision effects of Live2D models. But that is not what I am trying to do.

    The Live2D model has a shape. What I want is create a Mesh Collider with that shape, if is possible.

    Thanks a lot!
  • By the way,

    Is Live2D SDK for Unity limited to use a MeshRenderer? I mean, for a Unity2D game, could be used a SpriteRenderer?

    Thanks again!
  • Hmmm , I don't know SpriteRenderer available .
    I think difficult to make the shape of a Mesh Collider of Live2D model .

    Will you want to be transformed into each part ? ( Use the physical operation)
    For example, animation slime monsters bounce .
  • Hi naotaro,

    Yes, so now I am creating the mesh using the points of every part, using some code like this:
    var parts = live2DModel.getModelImpl().getPartsDataList(); foreach ( var part in parts ) { // For creating mesh live2DModel.getTransformedPoints(live2DModel.getPartsDataIndex(part.getPartsDataID())); }

    The problem appears when transforming those points from (its local pixels) -> (its local space) -> (world space)

    The first transformation seems right, but the second one is not clear for me as x and y values are not as expected

    For the first transformation I am using:

    // CONVERTS COORDINATES TO LOCAL SPACE IN UNITY x = modelMatrix.transformX(xpixel);

    For the second one:
    float[] localToWorldMatrix = new float[16]; for (int x = 0; x < 16; x ++){ localToWorldMatrix[x] = parent.transform.localToWorldMatrix[x]; } L2DMatrix44 worldMatrix = new L2DMatrix44(localToWorldMatrix); xw = worldMatrix.transformX(x);
  • vertex information is taken using getTransformedPoints() .
    But I think that can't mesh of deformation .

    I'm sorry , I don't have ideas to solve this problem .
  • Thanks a lot for your help, I will keep trying to solve this
Sign In or Register to comment.