Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

[RELEASED] MagicaCloth2 - Hybrid Cloth Simulation

Discussion in 'Assets and Asset Store' started by hoshos, Feb 5, 2023.

  1. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    upload_2024-5-7_11-41-28.png number of vertices of [ProxyMesh]
     
  2. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Thank you for your reply.
    It seems that the number of vertices of the mesh being used is within the permissible range.
    MaxDistance is a relatively simple operation, so it's strange that it would increase the load.
    Just to be sure, I retested the MaxDistance curve settings, but no problems were found.
    This could be due to a factor somewhere else.

    In order to find out the cause, I would like Unity Profiler data on the actual iPhone.
    If you have profiler data, it is possible to analyze in detail how much load is being placed on which process.
    Please provide profiler data.
    Please refer to the next page for information on connecting the profiler to the actual device.
    (It's Japanese, so please translate)
    https://light11.hatenadiary.com/entry/2019/08/19/001302

    You can then save it using the disk icon at the top right of the profile window.
     
  3. Seaky

    Seaky

    Joined:
    Mar 18, 2018
    Posts:
    5
    Hello guys,

    I have some trouble. I need to morph character's model on the fly, and using the colliders is pretty hard to fit the character perfectly.
    So I am planning to add the magica cloth component to the character's model, using the points on the magica cloth component of the character model to collide with the points on the cloth model.
    But I am not familiar the code and the comments being Japanese makes it hard to understand.
    So my question is, which classes should I modify to reach my goal?
     
  4. DrMeatball

    DrMeatball

    Joined:
    Nov 21, 2021
    Posts:
    116

    Got it fixed - ty for your help!

    (the problem was related to using PolyFew to LOD the hair down, something got corrupt in the process - I redid the hair mesh and it is working as expected woot!)
     
  5. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Hello.
    Does morphing mean a BlendShapes feature?
    If so, unfortunately you cannot use MagicaCloth to sway the deforming vertices of BlendShapes.
    Currently not compatible with BlendShapes.
     
  6. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    good!
    If the shape of the mesh changes significantly, the vertex paint data may shift.
    If this happens, open the Vertex Paint panel and check the status.
     
    DrMeatball likes this.
  7. Seaky

    Seaky

    Joined:
    Mar 18, 2018
    Posts:
    5
    Morphing includes both bones and blendshapes. I know that the current Magica Cloth doesn't support this. So I am planning to add some code to it, but I have some trouble understanding the source code.
    Could you please tell me what classes or functions should be modified in order to implement my requirements?
    To support character morphing, my plan is to add sphere colliders to the character just like the MagicaCloth component adds dots to the cloth mesh.
    And I also want to allow multiple clothes to be put on. So I am planning to allow the dots of the MagicaCloth component to collider with each other.
    @hoshos
     
  8. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    Due to the particularity of our project, we are temporarily unable to provide you with the Unity Profiling Tool project, but it may take a while for our Unity engineers to transform the project before we can provide you with the Profiling Project. Also, how do I send a profiling project to you? Email?
     
  9. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Hello.
    We are very sorry, but we cannot provide support regarding modifications.
    The same goes for advice regarding modifications.
    This is also in MagicaCloth's Terms of Service.
    https://magicasoft.jp/en/mc2_about/#Support

    There are two reasons for this.
    First, just a few lines of explanation will not do justice to what you are trying to accomplish.
    A more intimate discussion is needed if you are going to help with such a modification.
    Otherwise, we cannot support the source code.
    But we can't take the time to do this.

    Then there is the issue of support time.
    Assisting with such a modification would probably require several or more interactions.
    On average, I spend two hours each day supporting MagicaCloth.
    As an individual developer, this time is not negligible and can sometimes delay the original development effort.
    For this reason, I decided before I released this asset that I would not provide support for modifications.

    We have received a number of similar requests for modifications in the past, but have turned them all down.
    Some companies offered to pay a substantial amount of money.
    Please understand these reasons.
     
  10. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Please send a DM via the following email or this forum.

    support@magicasoft.jp

    You can send a DM by clicking on my account in this forum and selecting "Start a Conversation".
    I think DM is probably easier.
     
  11. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Update:2.8.0

    v2.8.0 has been released on the Asset Store!
    https://u3d.as/2Zc3

    Now supports negative scale
    It can also be used even if the character is reversed by negative scale.
    This is useful for 2D games etc.




    Release Note:
    Added: Negative scale is now supported. Negative scale can be set for only one axis, XYZ.
    Improvement: Some presets were readjusted.
    Improvement: The push direction of the plain collider is now displayed.
    Fixed: Fixed a problem that the collider works even if it is disabled from the beginning.

    How to Update
    Please follow the following steps to update the software as much as possible.
    (1)Backup your project
    (2)Delete the MagicaCloth2 folder from the Unity editor
    (3)Import the latest MagicaCloth2 from PackageManager
     
    DrMeatball likes this.
  12. oukaitou

    oukaitou

    Joined:
    Jan 10, 2014
    Posts:
    19
    Hi, [one MagicaCloth with multiple root bones] vs [multiple MagicaCloth and one root bone for each], is there any big difference with performance?
     
  13. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Hello.
    There is little difference in performance.
    MagicaCloth stores all component data in one huge array.
    All simulations are then run in a single process.
    Therefore, the number of components has no effect.

    However, it is better to reduce the number of components as much as possible, since each component has its own specific processing.
    Therefore, fewer components will improve performance, albeit slightly.
    In this case, [one MagicaCloth with multiple root bones] is advantageous.
     
    oukaitou likes this.
  14. KenjiJU

    KenjiJU

    Joined:
    Dec 31, 2012
    Posts:
    24
    Hello, I wonder if someone could help me figure out the logic in what I'm trying to do.

    The method I want to work with is a prefab character is spawned in the scene, and then the outfit is a prefab that's spawned onto the character using a script that aligns the outfit's bones with the character's. (Purpose of this is to allow many outfits to be added to the character without having to maintain one giant file whenever a new outfit is added.)

    Code (CSharp):
    1.     void Start()
    2.     {
    3.         GameObject spawnedGameObject = Instantiate(outfitPrefab, transform);
    4.  
    5.         SkinnedMeshRenderer[] skinnedMeshRenderers = spawnedGameObject.GetComponentsInChildren<SkinnedMeshRenderer>();
    6.  
    7.         foreach (SkinnedMeshRenderer spawnedSkinnedMeshRenderer in skinnedMeshRenderers)
    8.         {
    9.             spawnedSkinnedMeshRenderer.bones = originalSkinnedMeshRenderer.bones;
    10.             spawnedSkinnedMeshRenderer.rootBone = rootBone;
    11.         }
    12.  
    13.         spawnedGameObject.SetActive(true);
    14.     }
    15.  
    The problem I'm having is that I'm not sure what to do with the magica colliders. The magica cloth script and colliders are on the outfit. Doing it this way, the colliders seem to stay misaligned. If I assign them manually from the character's rig while the game is running, it works properly. I'm just not sure how to do this part.

    Thanks
     
  15. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Hello.
    If you want to transplant the costume to another skeleton, you will also need to replace the Transform inside MagicaCloth.
    And the collider must also be ported.
    These steps are explained in the following documents:
    There are also sample scenes, so please check them out.
    https://magicasoft.jp/en/mc2_dressup/
     
    KenjiJU likes this.
  16. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    After updating to version 2.7, all runtime builds created in previous versions do not get physical effects, MeshCloth can work normally, whether it is a pre-build or a runtime build, but BoneCloth does not work properly with runtime builds, only pre-builds do. Disabling the restart component does not take effect. The Components panel shows that it has been successfully built. Even I can't get physics by recreating the component, unless using a prebuild. This is an issue that occurs in the Unity editor, and in the example scene you provided, BoneCloth works fine. Unity version 2021.3.23
     
  17. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
  18. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Hello.
    Generally updates do not cause simulations to stop working, so we don't know what the cause is.
    First, try to check if your vertex paint data is corrupted.
    Open vertex paint mode and check that the movement and stationary attributes are painted correctly.
     
  19. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    I've tried recreating the vertex draw data, but the real-time simulation still doesn't work, switch to pre-build, and it works, so there shouldn't be any broken vertex paint data as you said, I opened the vertex paint panel and saw that it was the same as before, and after I rolled back to version 2.42, it was able to simulate in real time.
     
  20. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Thank you for the detailed information.
    Many features have been added since v2.4.2, so it's possible that one of them is causing the problem.

    I have one request.
    I would like an image of the information message that appears at the top of the MagicaCloth inspector when it doesn't work when running in the editor.
    It's the same as the previous image, but I think the previous image is information before execution.
    I would like to know the content of the information message during execution.
     
  21. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    upload_2024-6-4_10-21-8.png You should be talking about this picture
     
  22. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Thank you for the pictures.
    It's in good condition.
    I'm still not sure why it doesn't work.

    Can you provide me the project or prefab that has this problem?
    It seems like there's an unexpected problem.
    If possible, please send me a DM.
    You can send a DM from my account's "Start a Conversation" page.
     
  23. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    This is a business project for my affiliated organization and may not be able to provide documentation.
     
  24. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    Also, I've tried dragging a hair prefab with a solver directly into a game at runtime or just putting it in the scene at the beginning, and it can be built in real time, as well as creating prefabs using code. The only difference in the project is that the bones set up in the Hair Solver component are re-addressed from the hair attached to the character's bones due to the need to replace the hair. Because the hair is a separate prefab, it cannot be placed with the character.
     
  25. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    I understand about the project.
    I would like you to test one thing.
    Place a MagicaSettings component in the scene.
    Then try setting "Initialization Location" to "Awake".
    https://magicasoft.jp/en/mc2_settings_component/

    Does anything change when you run it like this?
     
  26. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    As you said it did, it didn't make the simulation run successfully upload_2024-6-5_15-29-25.png I've tried all the combinations of settings for this component once, but I still can't simulate it in real time
     
  27. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Thank you for testing.
    I thought that the initialization method changed slightly in v2.6.0, which might have been the cause, but it seems that was not the case.
    After testing, please return the contents of MagicaSettings to the default.
    In other words, it is recommended that "Initialization Location" be set to "Start".

    Just to confirm, you are loading the hair prefab at runtime and dressing the character, right?
    In other words, are you programmatically replacing the SkinnedMeshRenderer and MagicaCloth bones?
    And that is the only part that isn't working, is it?
    If that is the case, please double-check that you are following the dressing steps.
    https://magicasoft.jp/en/mc2_dressup/
     
  28. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    I looked up the code, and it did exactly as you said initializing and pausing the build at the appropriate steps. Once the setup was complete, the build was made, and I even used these steps to wrap around again before and after the function was executed. to make sure that no steps were missed, but it still didn't succeed in the simulation, and said that if there was a problem with this step, then MeshCloth and Bone spring would have the same problems, but they would be simulated in real time or pre-built. can get the effect of simulation normally.
     
  29. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    What struck me even more strange was that I was running the game, dragging hair into the scene, and manually replacing the root bones of its SkinMeshRender and Cloth components, which actually simulated it normally.
     
  30. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    When I compared the Anmated Position of Gizoms with the Cloth component of the character's hair open in the scene and the Gizoms of the Cloth component that was dragged and dropped directly into the scene, I found that the balls that could be simulated correctly were red, and the balls that could not be simulated correctly were all the same color.
     
  31. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
  32. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Thank you for the test.
    I still don't know the cause.
    This problem is very difficult to solve without reproduction data.

    I have one suggestion.
    I will send you all archives from v2.4.2 to v2.8.0.
    Can you test which version it stops working from?
     
  33. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    Of course, I have a part of the local version, so I'll test it first
     
  34. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    Version 2.51 works fine
     
  35. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    Version 2.50 works fine
     
  36. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    I tested: 2.50 2.51 2.52 2.60 2.61 2.7 and found the following issue: 2.51 2.52 will appear after the Mesh Cloth is loaded into the scene, the mesh will not be displayed, this problem has also occurred before, the Cloth component must be closed and opened once again for the mesh to be visible, the simulation is correct, in the 2.60 version this problem was fixed, but the Bone Cloth cannot be built in real time. This is the problem we are talking about so far, and the conclusion is that the problem started to appear in version 2.60, and the problem still exists in 2.61 and 2.7.
     
  37. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    Latest 2.8 This issue has not been fixed!
     
  38. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Thank you for the detailed test.
    We have narrowed down the problem a little.
    Since this issue started in v2.6.0, it is probably related to the change in the execution order of components.
    The following is the update history for v2.6.0.

    ====================================================
    Added: Added an anchor function. This disables the inertia of a specific object. It can be used for moving floors and vehicles. You can also adjust the strength of the anchor.
    Fixed: Fixed an issue where the simulation was disrupted when lag occurred due to load.
    Fixed: Fixed an issue where the effect of moving wind was weakened during slow playback.
    Fixed: Fixed an issue where the simulation was disrupted when the character moved during slow playback.
    Improved: Changed the initialization timing of MagicaCloth from Awake() to Start(). It is easier to process data before initialization. This setting can also be changed back to Awake() via MagicaSettings and API.
    Improved: Increased the execution order of the MagicaCloth component by (+5). The MagicaCloth component is executed after the normal MonoBehaviour component.
    Improved: Increased the execution order of the MagicaSettings component by (-50). MagicaSettings components are executed before normal MonoBehaviour components.
    ====================================================

    It is worth noting that the initialization timing has been changed from Awake() to Start(), and that the execution priority of the MagicaCloth component has been increased by (+5).
    Therefore, we would like you to test by reverting this change.
    The test procedure is as follows.


    Please use the latest v2.8.0 MagicaCloth for testing.
    Place the MagicaSettings component in the scene and change the initialization location to Awake.
    magica_exec_order-0.jpg

    Open ScriptExecutionOrder in ProjectSettings and delete the MagicaCloth in the image. You can delete it with the (-) button.
    magica_exec_order-1.jpg


    Try running it in this state and see if the problem is fixed.
     
  39. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    Following your guidelines, I took the test. The problem has been fixed! But the issue of the Mesh Cloth disappearing that existed in 2.5 before reappeared, I switched back to start, the MeshCloth returned correctly, and the Bone Cloth could not be built in real time again. And I found a hidden danger in the test, if the Magica Settings component is present in both scenes, then the Magica Settings component that opens the scene for the first time can really control the execution of the Magica Cloth component. The settings of the Magica Settings of the second opened scene will not take effect. Because of the general switching scenes, the characters will not go to the Destory.
     
  40. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    I tested it again and tried to change the stat to not Avak alone, not to execute "Offenscrib Dropseld Inprojek Setins Anderdelett McGecca Cross Inter Imech", consistent with the results just now, Meshcloth could not be displayed and needed to be turned on and off once in the component, Borncloth's hair was able to build normally in real time
     
  41. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    Before, you asked me to try to change Start to Awake, and the reason why I didn't fix this problem at that time was: there are two scenes in the project, and there are Magcia Settings in both scenes, and the logic of our project startup is that the game must go through the first scene to start, and I have been starting the game in the second scene before, and since the characters will not be destoryed, I modified the Magica Setting of the second scene. What actually works is the Magica Setting that hasn't been modified in the first scene, so it didn't work out.
     
  42. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Thank you for the test.
    Based on the situation, it seems to be related to the order in which components are executed.
    However, I cannot investigate this because I do not know your program code.
    I have one request.
    Could you please explain in pseudocode what steps you take to build MagicaCloth during the game?
    For example, something like this:

    - Load the hair prefab from the asset bundle
    - Execute initialization for the MagicaCloth component
    - Replace the hair renderer bone with the body bone to wear it on
    - Replace the MagiaCloth bone with the body bone to wear it on
    - Transfer the hair collider to the body to wear it on
    - Execute BuildAndRun() for MagicaCloth

    I would like to know the steps you actually take.
     
  43. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    At the moment, I am spending the Dragon Boat Festival holiday, and I will check the code in detail after the festival and give you an answer
     
    hoshos likes this.
  44. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    I looked at the code for the Dressing Component, and we did the replacement of the root bone in the SkinMesh Render component, then the initialization of the Cloth component, then the replacement of the bones of the Cloth component and the addition of colliders, and finally the running of the Cloth.
     
  45. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    I've tried to modify the code for our dress-up based on the steps you gave you an example. The Cloth component was initialized first, and then the root bone of the SkinMeshRender component was replaced. Fixed an issue where Bone Cloth could not be built in real-time when Magica Setting was defaulted to Start.
     
  46. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Thank you for the detailed explanation.
    I'm also relieved that the problem seems to have been solved!

    As you pointed out, MagicaCloth initialization must be performed first.
    Initialization collects and records the Transform information required to build MagicaCloth.
    For this reason, if the Transform is manipulated before initialization, it may not run properly.
    The recommended sequence of operations is as follows:

    (1) Load prefabs
    (2) Manually initialize all MagicaCloth (Initialize())
    (3) Replace renderer bones
    (4) Replace MagicaCloth bones
    (5) Other, such as porting colliders
    (6) Start building MagicaCloth (BuildAndRun())
     
  47. AlanParrick

    AlanParrick

    Joined:
    Oct 6, 2022
    Posts:
    50
    Yes! I think you could update this in the documentation to explain the importance of this step, which can avoid a lot of problems. In some versions, mistakes in this step do not cause problems, which is not taken seriously. So much so that new problems arise after the updated version.
     
  48. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Yes, we will update the documentation regarding this initialization order at a later date.
    Thank you!
     
  49. glumleaf

    glumleaf

    Joined:
    Jan 30, 2016
    Posts:
    25
    Reposting this here as I accidentally posted it in the Magica Cloth 1 thread:

    Hello! I'm wondering how I can access the transform data (rotation, position, etc) of a bone controlled by MagicaCloth via a script? I'm trying to manually rotate something to match the rotation of a bone controlled by MagicaCloth, but when I try to access the bone transform data in Update or LateUpdate, it's as if the bone is at its resting position.
     
  50. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    959
    Hello.
    Please use the MagicaManager's OnPostsimulation event in the same way in Ver2.
    https://magicasoft.jp/en/mc2_api_magicamanager/#OnPostSimulation

    However, unlike Ver1, this event is not exposed in the Inspector.
    You must register it from a script.
    The following explanation is the same as what I wrote in the Ver1 forum, but I will post it here just in case.

    ------------------------------------------------------------------------------------
    MagicaCloth runs the simulation after LateUpdate.
    In other words, it is later than LateUpdate, and just before rendering.
    And in MagicaCloth, the Transform position is reset once rendering is complete.
    Therefore, even if you check the Transform position in the next frame, the results of the simulation will not be reflected.
    The only way is to read the Transform position immediately after the MagicaCloth simulation is complete.