Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[RELEASED] MagicaCloth2 - Hybrid Cloth Simulation

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

  1. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    645
    Perfect, thanks. I'll write an editor script that remembers the initial pose and will apply itself before play, or something like that, since scrubbing in the timeline in edit mode does alter the pose. That way there won't be any issues. I know FinalIK does something similar (and I had to write my own system for that as well to get it working with timeline properly in edit mode without breaking play mode ... so this makes sense).

    I still don't understand why some models work fine when scrubbed in the timeline while others dont, but maybe its just the luck of the draw regarding how the pose is changed.

    If you haven't, can you add a line about this in your documentation about use with timeline? It took me a whole day of work to figure out that's what was going wrong ... at first I thought the data just corrupted so I played with git reverts. If its already there, I just didn't notice it, so oops.

    Anyway, thanks so much.
     
  2. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    I'm still not sure what the cause of this problem is, but it could be a real bug.
    So if you find a reliably reproducible procedure, please contact me again.
    I would like to add the basic pose specifications for vertex painting to the document at a later date.
     
  3. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Update:2.1.7

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


    Release Note:
    Fix: Fixed an issue where proxy mesh normal calculation was wrong. This solves the problem of distorted irregularities and shadows on the display mesh.
    Fix: Fixed a rare issue where a division by 0 error occurred when calculating tangents for proxy meshes.
    Fix: Fixed a rare divide-by-zero error in TriangleBending constraints.
    Fix: Fixed an internal error that occurred when the capsule collider had a length of 0.
    Fix: Fixed a rare issue where a division by 0 error occurred when vertices collided with multiple colliders during collider collision detection.


    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
     
    yohei-washizaki-aktsk likes this.
  4. snorki

    snorki

    Joined:
    Sep 19, 2022
    Posts:
    3
    Hi. I'm having a problem where MagicaCloth distorts vertices that are not included. They are set as invalid in the paint mode.
    Screenshots are respectively:
    1 - MagicaCloth turned off,
    2 - MagicaCloth turned on,
    3 - Paint mode view. magicascreenshot1.png magicascreenshot2.png magicascreenshot3.png
     
  5. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Hello.
    What version of MagicaCloth are you using?
    Lower than v2.1.7?
    If it is lower, try updating the version to the latest v2.1.7.
     
  6. MrNani

    MrNani

    Joined:
    Jun 20, 2020
    Posts:
    6
    Hello everyone, I'm currently developing a side-scrolling action-adventure game and I'm trying to use MagicaCloth2 to simulate chains. However, I'm facing an issue when using horizontal flipping in runtime where the positions of the skeletal physics simulation and the chain mesh are not aligned properly.
    normal.jpg normalTransform.jpg

    Under normal circumstances....
    bug.jpg bugTransform.jpg

    When encountering a bug, ...
    After testing, it was found that this bug does not occur in MagicaCloth; rather, it only manifests in MagicaCloth2.
    I would greatly appreciate your assistance and guidance in resolving this matter.
     
    Last edited: Jul 19, 2023
  7. snorki

    snorki

    Joined:
    Sep 19, 2022
    Posts:
    3
    It fixed it a bit but still some issues with the mesh. upload_2023-7-19_11-59-14.png
     
  8. snorki

    snorki

    Joined:
    Sep 19, 2022
    Posts:
    3
    Found a solution. I am using more than 4 bones per vertex. Switching to Standard (4 bones) skinning fixed it.
    Question is: Can you set MagicaCloth to more than 4 bones for proxy mesh generation?
     
  9. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Hello.
    Ver2.x does not support minus scale yet.
    Ver1.x is already supported.
    Negative scale support is pending as it requires rework in various ways.
    However, we plan to support it in the future and it has been added to the roadmap.
    https://magicasoft.jp/en/mc2_roadmap/

    Therefore, I am sorry but I cannot use it until it is implemented.
    It will be implemented later this year.
     
  10. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    I'm relieved that it seems to have been resolved.
    As you pointed out, MagicaCloth does not support vertex weights of 5 or more bones.
    Currently, weights with 5 bones or more are ignored.
    So you may get results like this.

    This limitation is described in the document, but I think it was difficult to understand.
    https://magicasoft.jp/en/mc2_meshclothstartguide/#Other_conditions

    There are currently no plans to support weights of more than 5 bones in the future.
    Therefore, I'm sorry, but please try to set the vertex weight to 4 bones or less.
    I would like to modify it so that it will be clearly displayed as a warning when vertex weights of 5 bones or more are found.
     
    snorki likes this.
  11. MrNani

    MrNani

    Joined:
    Jun 20, 2020
    Posts:
    6
    Thank you for your patient explanation~
     
  12. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    979
    Latest Unity (2023.2.0b1, 2023.1.5f1) makes error when using MagicaCloth 2.

    Top level scope allocation is permitted only on the main thread.
    UnityEngine.StackTraceUtility:ExtractStackTrace ()
    Unity.Collections.Memory/Unmanaged/Array:Resize (void*,long,long,Unity.Collections.AllocatorManager/AllocatorHandle,long,int) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/Memory.cs:79)
    Unity.Collections.Memory/Unmanaged:Allocate (long,int,Unity.Collections.AllocatorManager/AllocatorHandle) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/Memory.cs:20)
    Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashMapData:AllocateHashMap<Unity.Mathematics.int4, bool> (int,int,Unity.Collections.AllocatorManager/AllocatorHandle,Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashMapData*&) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/UnsafeParallelHashMap.cs:133)
    Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashMap`2<Unity.Mathematics.int4, bool>:.ctor (int,Unity.Collections.AllocatorManager/AllocatorHandle) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/UnsafeParallelHashMap.cs:1134)
    Unity.Collections.NativeParallelHashMap`2<Unity.Mathematics.int4, bool>:.ctor (int,Unity.Collections.AllocatorManager/AllocatorHandle) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/NativeParallelHashMap.cs:118)
    Unity.Collections.NativeParallelHashSet`1<Unity.Mathematics.int4>:.ctor (int,Unity.Collections.AllocatorManager/AllocatorHandle) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/NativeParallelHashSet.cs:39)
    MagicaCloth2.VirtualMesh/Optimize_EdgeToTrianlgeJob:Execute () (at Assets/MagicaCloth2/Scripts/Core/VirtualMesh/Function/VirtualMeshOptimization.cs:107)
    Unity.Jobs.IJobExtensions/JobStruct`1<MagicaCloth2.VirtualMesh/Optimize_EdgeToTrianlgeJob>:Execute (MagicaCloth2.VirtualMesh/Optimize_EdgeToTrianlgeJob&,intptr,intptr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,int)
    Unity.Jobs.LowLevel.Unsafe.JobsUtility:Schedule (Unity.Jobs.LowLevel.Unsafe.JobsUtility/JobScheduleParameters&)
    Unity.Jobs.IJobExtensions:Run<MagicaCloth2.VirtualMesh/Optimize_EdgeToTrianlgeJob> (MagicaCloth2.VirtualMesh/Optimize_EdgeToTrianlgeJob)
    MagicaCloth2.VirtualMesh:RemoveDuplicateTriangles () (at Assets/MagicaCloth2/Scripts/Core/VirtualMesh/Function/VirtualMeshOptimization.cs:51)
    MagicaCloth2.VirtualMesh:Optimization () (at Assets/MagicaCloth2/Scripts/Core/VirtualMesh/Function/VirtualMeshOptimization.cs:23)
    MagicaCloth2.ClothEditorManager/<>c__DisplayClass20_1:<CreateOrUpdateEditMesh>b__0 () (at Assets/MagicaCloth2/Scripts/Editor/Cloth/ClothEditorManager.cs:619)
    System.Threading._ThreadPoolWaitCallback:performWaitCallback ()

    ArgumentException: Could not allocate native memory. If this allocation was made from a managed thread outside of a job, you must use Allocator.Persistent or Allocator.TempJob.
    Unity.Collections.Memory+Unmanaged+Array.Resize (System.Void* oldPointer, System.Int64 oldCount, System.Int64 newCount, Unity.Collections.AllocatorManager+AllocatorHandle allocator, System.Int64 size, System.Int32 align) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/Memory.cs:79)
    Unity.Collections.Memory+Unmanaged.Allocate (System.Int64 size, System.Int32 align, Unity.Collections.AllocatorManager+AllocatorHandle allocator) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/Memory.cs:20)
    Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashMapData.AllocateHashMap[TKey,TValue] (System.Int32 length, System.Int32 bucketLength, Unity.Collections.AllocatorManager+AllocatorHandle label, Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashMapData*& outBuf) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/UnsafeParallelHashMap.cs:133)
    Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashMap`2[TKey,TValue]..ctor (System.Int32 capacity, Unity.Collections.AllocatorManager+AllocatorHandle allocator) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/UnsafeParallelHashMap.cs:1134)
    Unity.Collections.NativeParallelHashMap`2[TKey,TValue]..ctor (System.Int32 capacity, Unity.Collections.AllocatorManager+AllocatorHandle allocator) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/NativeParallelHashMap.cs:118)
    Unity.Collections.NativeParallelHashSet`1[T]..ctor (System.Int32 capacity, Unity.Collections.AllocatorManager+AllocatorHandle allocator) (at ./Library/PackageCache/com.unity.collections@2.2.0/Unity.Collections/NativeParallelHashSet.cs:39)
    MagicaCloth2.VirtualMesh+Optimize_EdgeToTrianlgeJob.Execute () (at Assets/MagicaCloth2/Scripts/Core/VirtualMesh/Function/VirtualMeshOptimization.cs:107)
    Unity.Jobs.IJobExtensions+JobStruct`1[T].Execute (T& data, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <3e2118a0a67041869c87922a11f4a02f>:0)
    Unity.Jobs.LowLevel.Unsafe.JobsUtility:Schedule_Injected(JobScheduleParameters&, JobHandle&)
    Unity.Jobs.LowLevel.Unsafe.JobsUtility:Schedule(JobScheduleParameters&)
    Unity.Jobs.IJobExtensions:Run(Optimize_EdgeToTrianlgeJob)
    MagicaCloth2.VirtualMesh:RemoveDuplicateTriangles() (at Assets/MagicaCloth2/Scripts/Core/VirtualMesh/Function/VirtualMeshOptimization.cs:51)
    MagicaCloth2.VirtualMesh:Optimization() (at Assets/MagicaCloth2/Scripts/Core/VirtualMesh/Function/VirtualMeshOptimization.cs:23)
    MagicaCloth2.<>c__DisplayClass20_1:<CreateOrUpdateEditMesh>b__0() (at Assets/MagicaCloth2/Scripts/Editor/Cloth/ClothEditorManager.cs:619)
    System.Threading._ThreadPoolWaitCallback:performWaitCallback()
     
  13. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Hello.
    Thank you for your report.
    This issue has also been confirmed here and is currently being fixed.
    We will update the market as soon as the fix is completed, so please wait for a while.
     
    Kichang-Kim likes this.
  14. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Update:2.1.8

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

    Fixed an issue that caused an error with Unity2023.1.5 or higher.
    It also fixes some error issues.

    Release Note:
    Important Note: A warning message is now displayed when the vertex weight of the skinning mesh used in MeshCloth uses 5 or more bones. Up to 4 weights are allowed per vertex and more are ignored. This is the specification from the beginning of the release.
    Fix: Fixed an issue that caused an error in Unity 2023.1.5 and higher versions.
    Fix: Worked around an issue where conflicts such as window IDs would cause errors when other external assets draw GUIs in the scene view.
    Fix: Fixed a rare error that occurred when a character was deleted while creating cloth data.
    Improvement: Supported help button in MagicaSettings component. I can open the document.


    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
     
  15. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    101
    Is it possible to "freeze" the proxy mesh so that MagicaCloth doesn't re-calculate it when I change the mesh (for example, move a bone or change a blendshape weight)?

    And is it possible to only calculate the proxy mesh for a part of mesh? For example, for a full body mesh, I'd like to only add a MeshCloth for the breast part (for obvious reason :p). I know that I can just generate a MeshCloth for the whole body, then paint the unused vertices as invalid. However I'd like to add MeshCloth at runtime, and it seems very wasteful to calculate proxy mesh for all the body parts that are not simulated.
     
    Last edited: Jul 26, 2023
  16. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Recalculation cannot be stopped.
    MagicaCloth automatically recalculates when parameters or meshes are changed.
    This is the same at runtime, proxy meshes are created on the fly as needed.

    This is a big change from Ver1.x.
    In Ver1.x, the proxy mesh was not created unless the creation button was manually pressed.
    I think the Ver1.x method is what you call the "freeze" function.
    However, this method was abolished in Ver2.x because problems occurred one after another mainly due to version differences.
    Please understand.

    Also, proxy meshes are created using only areas set to move and fixed in vertex paint.
    In other words, vertices with invalid attributes are not included in the proxy mesh.
    Therefore, please be assured that vertices unrelated to the simulation will not be calculated.
    However, this is a runtime-only process.
    All of them are displayed because it is necessary to perform vertex painting when setting them.
    You should be able to see the effect by checking the gizmo display of the proxy mesh at runtime.
     
  17. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    101
    I really hope that we can freeze the process of recalculating the proxy mesh. Or even better: allow us to import our own proxy mesh from .obj or .fbx.

    Thank for your reply. I understand it's currently not impossible to do that, and please take it as a feature request.

    Another question: does MeshCloth initialize itself when it's gameObject get activated? For example, the scene has to game objects:

    * Mesh (activated)
    * MeshCloth (deactivated)

    Then I activate the MeshCloth's game object at runtime. Does MeshCloth get initialized when the scene is loaded, or when it's activated, or both?
     
  18. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    There is also an opinion that it would be more convenient to have a "freeze" function, so we are considering it.
    We call this the "Bake" feature, and it's already on our roadmap.
    https://magicasoft.jp/en/mc2_roadmap/

    About initialization.
    Initialization of MagicaCloth is executed when MagicaCloth components become active.
    That is, when the MeshCloth gameObject becomes active.
    (Timing of Awake())

    Be careful about initialization.
    Initialization should be done with the same pose as vertex painting in the editor.
    This means that if the initialization is run after the character has started animating, it will behave strangely.
    Please note this point.

    It is also possible to call initialization manually if for some reason the GameObject cannot be activated.
    This will be Initialize().
    https://magicasoft.jp/en/mc2_api_magicacloth/#Initialize

    This works even if the GameObject is inactive.
    Please use it according to the situation.
     
  19. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    101
    Thank you very much for the answer!

    What if I create MeshCloth component at runtime, and the character has started animating? Would it be a problem?
     
  20. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    The component must be added and initialized before the character's animation runs.
    Basically, if you set MagicaCloth at the time the character is instantiated, there should be no problems.
    See the following documentation for run-time generation.
    https://magicasoft.jp/en/mc2_runtime_build/

    The important thing is that MagicaCloth initialization must be done with the character's base pose.
    This is usually an A pose or a T pose.
     
  21. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    101
    This page says:

    But what if the character's pose has changed during these "a few frames"? How do I know the MagicaCloth has been initialized and it's safe to animate my character?
     
  22. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    I understand your question, but no problem.
    It certainly takes a few frames to create the cloth data in the background and start working.
    However, necessary information such as character poses are collected and recorded during initialization.
    Therefore, there is no problem even if the animation changes while creating the cloth data.
    However, if the pose changes too much from the initial pose, there is a small problem that the collision detection will malfunction.
    In that case, it is better to disable the character until the cloth data is completed.
    The OnBuildComplete event is useful for this.
    But in most cases it shouldn't be a problem.
    https://magicasoft.jp/en/mc2_api_magicacloth/#OnBuildComplete
     
  23. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    101
    Thank you very much for the answers so far!

    If you don't mind, I've got another question. How is the vertex paint information stored? I noticed that on this page: https://magicasoft.jp/en/mc2_runtime_build, there is no example to set vertex paint texture for BoneCloth, only for MeshCloth. Is this intentional? How to do vertex paint for BoneCloth at runtime?

    And when I do it in Editor time, I notice one little unexpected thing:

    For a BoneCloth, when I do the following steps in this order:

    1. Set the bones at rest pose
    2. Paint fixed/moving vertices
    3. Move the bones (in editor mode)
    4. Run the game

    The vertex paint is messed up. I know it's not the proper way to use MagicaCloth, because when I run the game the bones are not at rest pose. But if I do this:

    1. Set the bones at rest pose
    2. Do not paint any vertices. In other words, leave the root bones as fixed and others as moving.
    3. Move the bones (in editor mode)
    4. Run the game

    It works! It's a bit weird that it works this way... why does moving the bones affect painted vertex attributes? How is the painted information stored?
     
  24. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Vertex painting is recorded in position coordinates.
    It's not a vertex or transform index.
    This vertex paint data is saved in the ClothSerialize2 class.
    By manipulating this data, it is possible to change the vertex paint.
    https://magicasoft.jp/en/mc2_api_clothserializedata2/

    As described above, vertex painting is recorded by coordinates, so if you move the vertex position after painting, it will shift.
    However, each vertex is now connected to the closest one in the paint data.
    Therefore, even if you move the vertices a little, it will work as it is.
    For example, adjusting the vertices of the mesh slightly.

    Also, vertex paint is empty until the end user manually changes it.
    When BoneCloth is executed in this empty state, the system automatically assigns fixed and moving attributes.
    That's the reason for the second behavior.
     
  25. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    101
    Thank you very much again. Now I understand it better.

    (I'd suggest having a button to "clear" paint data tho, cause the user might want to go back to the automatical assignment. Now the workaround seems to be to create a brand new BoneCloth or write an editor script to clear ClothSerializeData2)
     
  26. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Unfortunately there are no plans to implement a clear button anytime soon.
    This is because running vertex paint empty is deprecated in the first place.
    Being able to run it even when it's empty is like a first aid measure.
    However, I will record it as a development memo.
     
  27. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    101
    If the Bake feature you mentioned above bakes vertex painting too, then I agree there isn't much needed for a "clear" button.
     
    hoshos likes this.
  28. VoxelBoy

    VoxelBoy

    Joined:
    Nov 7, 2008
    Posts:
    240
    Hi, I'm trying to set up a Basketball Net using Magic Cloth 2 but I must be missing something.
    The proxy mesh is simulating fine at runtime but the render mesh is not being updated to the shape of the proxy mesh.
    I read the documentation several times to see what I might be missing but I couldn't figure it out.

    Here's my setup:
    upload_2023-8-3_11-25-42.png

    The SkinBoneCount being 1 gives me the feeling that there aren't enough "bones" to modify the render mesh. I can't figure out what I need to do.

    If anyone can point out what I'm missing, I'd appreciate it, thanks!
     
  29. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Hello.
    Sorry, maybe this is a bug specific to v2.1.8.
    In v2.1.8, SkinnedMeshRenderer does not work if (null) is included in the bone list.
    This is due to the enhancement of the render mesh verification, but it was overkill and will be abolished in the next version.
    Just in case, I will send a preview version of the upcoming v2.1.9 to your DM.
    Please test if this version solves your problem.
     
  30. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    101
    Is it possible to manually apply force to MeshCloth or BoneCloth? Something similar to Unity's RigidBody.AddForce()?

    If not, what's the proper way to add forces to a simulated part? Move the bone transforms directly?
     
  31. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    I realized that you forgot to implement AddForce() as you said.
    This is technically possible, I just forgot to implement AddForce().
    This function will be implemented in the near future.
    It will probably be implemented within a month.
     
  32. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    101
    Good to know! Thank you for the hard work!
     
  33. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Update:2.1.9

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

    BoneCloth has a function to automatically build a mesh from the Transform hierarchy, but the algorithm has been greatly improved.
    It also fixes some error issues.


    Release Note:
    Added: Added AddForce() API to apply external force.
    Improvement: Improved BoneCloth's mesh connection algorithm.
    Fix: Fixed an issue where an error would occur if two vertices were at exactly the same position.
    Fix: Fixed an issue where the SkinnedMeshRenderer's bone list contained (null) not working. This is a bug in the verification algorithm enhanced in v2.1.8.
    Fix: Fixed position not resetting correctly when disabling/enabling colliders.


    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
     
    YoheiW likes this.
  34. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    101
    Could you point me out some direction to profiling the performance of Magica Cloth?

    I'm experiencing a bit of weird situation. When I enable the MagicaCloth components in my scene, my FPS drops from 60+ to 45+. But to my surprise, SetSimulationFrequency doesn't seen to affect the performance much: I tried 30, 60 and 90 and it doesn't affect my FPS.

    I tried to profile it with Unity's built-in Profiler, but I don't know where to look at: it shows that my CPU is mostly idle and waiting for GPU rendering, which makes no sense cause MagicaCloth does affect the FPS significantly, and it runs on CPU iirc. I guess MagicaCloth's simulation(s) run on a separate thread/process so I can't easily see them in Profiler?

    Another question about 2.1.9:

    First of all I'm very grateful to the new AddForce() method. However I'm a bit of confused at the with/without depth part. How does the depth affects the force?
     
    Last edited: Aug 9, 2023
  35. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    MagicaCloth's simulation time can be easily checked with a profiler.
    Set the display to TimeLine and check the MagicaManager block as shown in the image below.

    mc2-profiler-1.jpg

    As a point of caution, when executing in the editor, processing will be slowed down due to various monitoring.
    This is summarized in the following document, so please read it.

    https://magicasoft.jp/en/mc2_performance/

    Also, MagicaCloth is CPU-dependent and does not use the GPU at all.

    The depth effect of AddForce() is a setting that causes less force to be applied near the base of the baseline.
    Depths are automatically assigned at runtime according to their distance from the root.
    So the root is 0.0 and the tip is 1.0.
    See the following documentation for baselines and depth.

    https://magicasoft.jp/en/mc2_baseline/

    You can check the numerical value by turning ON the depth check in the gizmo panel.
     
  36. the_unity_saga

    the_unity_saga

    Joined:
    Sep 17, 2016
    Posts:
    246
    hello, your work is great. I do not regret buying this asset.

    however, some projects I have (for whatever reason) will break due to the inclusion of shadergraph dependency.

    I was wondering if you can repackage your asset demo packages as 3 separate subpackages:
    1. Built-In-Demo.package
    2. URP-Demo.package
    3. HDRP-Demo.package

    in this way, the shadergraph dependency will not automatically be included in fresh import, but also maybe I suggest a 4th package

    4. Built-In-StandardShader.package

    as, it would help other users who have the same issue, or other users who do not wish for shadergraph.

    anyway, it is fine if you do not do this, I was only suggestion

    thank you again for your hard work, and I hope to see more of your work in the future.
     
  37. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Hello.
    This is a thorny issue.
    I know there is a feature that allows demoscenes to be distributed in a separate package from the assets.
    However, since most of the end-users who buy assets are beginners, we decided not to separate the demo scene.
    For beginners, the operation of installing the demo scene separately is too high a threshold.

    Also, I didn't want to use Shader Graph if possible, but it was absolutely necessary to support the current three render pipelines.
    I myself am overwhelmed by the complexity of Unity's rendering system.
    I understand your request, but I'm sorry, but there are no immediate plans to respond.
    This is the final result after much thought.
     
  38. chipchuh

    chipchuh

    Joined:
    Apr 5, 2022
    Posts:
    2
    When will it be possible to grab the cloth at any place and move it with the cursor? Willing to pay 200 usd for it
     
  39. bearcoree

    bearcoree

    Joined:
    Mar 8, 2016
    Posts:
    72
    Heya, love the asset, amazing that it's just a single component now. Makes working with the system a lot easier!

    I seem to be running into a bug, where the mesh of a SkinnedMeshRenderer is not updating with the MagicaCloth, if it had it's RootBone changed.

    I use this script to update the RootBone of the SkinnedMeshRenderer: https://forum.unity.com/threads/how-to-move-a-skinned-mesh-renderer-over-to-another-model.921854/

    The Gizmos are correctly moving, but the mesh itself is not updating according to the MagicaCloth.

    Unity_ZUOXHPi8gq.jpg

    The reason why I had to change the RootBone of the SkinnedMeshRenderer is that the magica cloth system does not support more than 4 bone weights. I do need 8 bone weights on much of the character like the face, so I exported the outfit separately and imported it with the supported 4 bone weights.

    Then I used the aforementioned script to make the outfit follow the bones of the Character. This way I only have 1 bone structure in engine.

    I have tried to replace the SkinnedMeshRenderer with a normal MeshRenderer and it works as expected, tho of course I do need the SkinnedMeshRenderer.

    Any idea if there's anything I can do to make this setup work?
    Can you reproduce this bug on your end?
    Is this specifically unsupported?
     
  40. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Hello.
    We have received many requests to grab and move the cloth.
    Rest assured, this feature is already on our roadmap.
    However, it will be some time before it is implemented.
     
  41. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Hello.
    First, what version of MagicaCloth are you using?
    If you are using v2.1.8, please update to v2.1.9 as the SkinnedMeshRenderer bug has been fixed.
    Also, is this RootBone change done when editing the editor?
    Or do you do it at runtime?
     
  42. RabberDakk

    RabberDakk

    Joined:
    Feb 23, 2019
    Posts:
    6
    • I want to temporarily turn off the Cloth Simulation when moving/rotating the model momentarily, is there a good way to do this? I would like to do it in a way other than Movement Speed Limit / Rotation Speed Limit.
     
  43. RabberDakk

    RabberDakk

    Joined:
    Feb 23, 2019
    Posts:
    6
    i am manually editing max collider count = 320 with per-update
    Can you make this value editable?
     
  44. Imperatoss

    Imperatoss

    Joined:
    Mar 24, 2018
    Posts:
    51
    If i have Icons Activated

    upload_2023-8-17_2-33-14.png

    I get the following error while starting the Project

    ========== OUTPUTTING STACK TRACE ==================

    0x00007FF7D6151A1C (Unity) ExtractHandles
    0x00007FF7D6151AEA (Unity) ExtractReadWriteHandles
    0x00007FF7D614CEFC (Unity) JobExtractedHandles::JobExtractedHandles
    0x00007FF7D6163F7C (Unity) `anonymous namespace'::ScheduleManagedJobParallelFor_Internal
    0x00007FF7D6163278 (Unity) ScheduleManagedJobParallelFor
    0x00007FF7D565B27E (Unity) JobsUtility_CUSTOM_ScheduleParallelFor_Injected
    0x000002C9FE6D7B43 (Mono JIT Code) (wrapper managed-to-native) Unity.Jobs.LowLevel.Unsafe.JobsUtility:ScheduleParallelFor_Injected (Unity.Jobs.LowLevel.Unsafe.JobsUtility/JobScheduleParameters&,int,int,Unity.Jobs.JobHandle&)
    0x000002C9FE6D7A2B (Mono JIT Code) Unity.Jobs.LowLevel.Unsafe.JobsUtility:ScheduleParallelFor (Unity.Jobs.LowLevel.Unsafe.JobsUtility/JobScheduleParameters&,int,int)
    0x000002CA227C4F2B (Mono JIT Code) Unity.Jobs.IJobParallelForExtensions:Run<MagicaCloth2.JobUtility/SerialNumberJob> (MagicaCloth2.JobUtility/SerialNumberJob,int)
    0x000002CA227C4C8B (Mono JIT Code) [D:\Projectpath\Assets\MagicaCloth2\Scripts\Core\Utility\Jobs\JobUtility.cs:167] MagicaCloth2.JobUtility:SerialNumberRun (Unity.Collections.NativeArray`1<int>,int)
    0x000002CA49755E0B (Mono JIT Code) [D:\Projectpath\Character\Assets\MagicaCloth2\Scripts\Core\VirtualMesh\Function\VirtualMeshReduction.cs:835] MagicaCloth2.VirtualMesh:OrganizeStoreVirtualMesh (MagicaCloth2.ReductionWorkData)
    0x000002CA2282A3FB (Mono JIT Code) [D:\Projectpath\Character\Assets\MagicaCloth2\Scripts\Core\VirtualMesh\Function\VirtualMeshReduction.cs:117] MagicaCloth2.VirtualMesh:Reduction (MagicaCloth2.ReductionSettings,System.Threading.CancellationToken)
    0x000002CA227B464B (Mono JIT Code) [D:\Projectpath\Character\Assets\MagicaCloth2\Scripts\Editor\Cloth\ClothEditorManager.cs:588] MagicaCloth2.ClothEditorManager/<>c__DisplayClass20_0:<CreateOrUpdateEditMesh>b__0 ()
    0x000002CA227B3364 (Mono JIT Code) System.Threading.Tasks.Task:InnerInvoke ()
    0x000002C86BC2D4E4 (Mono JIT Code) System.Threading.Tasks.Task:Execute ()
    0x000002C86BC2D493 (Mono JIT Code) System.Threading.Tasks.Task:ExecutionContextCallback (object)
    0x000002C83D31E17E (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
    0x000002C83D31DCEB (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
    0x000002C86BC2D19B (Mono JIT Code) System.Threading.Tasks.Task:ExecuteWithThreadLocal (System.Threading.Tasks.Task&)
    0x000002C86BC2C51B (Mono JIT Code) System.Threading.Tasks.Task:ExecuteEntry (bool)
    0x000002C86BC2C22B (Mono JIT Code) System.Threading.Tasks.Task:System.Threading.IThreadPoolWorkItem.ExecuteWorkItem ()
    0x000002C869B9945A (Mono JIT Code) System.Threading.ThreadPoolWorkQueue:Dispatch ()
    0x000002C869B988EB (Mono JIT Code) System.Threading._ThreadPoolWaitCallback:performWaitCallback ()
    0x000002C869B989D5 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_bool (object,intptr,intptr,intptr)
    0x00007FF99CB8E084 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\mini\mini-runtime.c:3445] mono_jit_runtime_invoke
    0x00007FF99CACEB84 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\object.c:3066] do_runtime_invoke
    0x00007FF99CB0B957 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\threadpool.c:386] worker_callback
    0x00007FF99CB0E9F0 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\threadpool-worker-default.c:502] worker_thread
    0x00007FF99CAFD2FB (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\threads.c:1268] start_wrapper_internal
    0x00007FF99CAFD4D6 (mono-2.0-bdwgc) [C:\build\output\Unity-Technologies\mono\mono\metadata\threads.c:1344] start_wrapper
    0x00007FF9FCB87614 (KERNEL32) BaseThreadInitThunk
    0x00007FF9FE1626B1 (ntdll) RtlUserThreadStart

    ========== END OF STACKTRACE ===========

    After deleting Magica2 i can start the Project. And i can start it if i deactivate Gizmos in SceneView.
    The Problem only occurs when starting the Project. I´m using Unity 2022.2.21f1
     
  45. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Hello.
    What you can currently do when teleporting is to reset the simulation.
    Without resetting, a large move would mess up the simulation quite a bit.
    Reset can be executed with the following API.
    https://magicasoft.jp/en/mc2_api_magicacloth/#ResetCloth

    However, we are currently implementing a new feature for teleporting.
    It automatically detects teleports and allows you to choose between resetting after teleporting or maintaining your pose.
    It may be released as early as August.

    Also, sorry it's hard to make the maximum number of colliders editable.
    Since this is referenced from various places as a constant, it cannot be easily output to the outside.
    By the way, can you tell me why you need more than 32 colliders?
     
    hopeful likes this.
  46. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Hello.
    I just tested with Unity2022.2.21f1 + MagicaCloth2.1.9, but there were no particular problems.
    Is the version of MagicaCloth you are currently using 2.1.9?
    If you have an earlier version, first update to v2.1.9 and try again.
     
  47. RabberDakk

    RabberDakk

    Joined:
    Feb 23, 2019
    Posts:
    6
    > we are currently implementing a new feature for teleporting.
    Thanks a lot! I'll wait for that feature to be added.

    > can you tell me why you need more than 32 colliders?

    I have edited a free asset called SAColliderBuilder (author: Nora) a bit to automatically generate MagicaClothColliders matched to character's mesh. About 150~ colliders are generated, of which only the necessary colliders are used depending on the target cloth, but about 50-90 colliders are needed. Even with more Colliders, cloth simulation is still working correctly (great performance, thanks!). Number of colliders automatically generated varies with the number of bone, but I have never seen more than 200.
    This is my reason for increasing the number of colliders.
     
  48. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Thank you for your explanation.
    I understand how to use it.
    We have already received several requests to use more than 32 colliders.
    I'm worried about performance, but I'd like to consider whether the number of colliders can be expanded without limit.
    I'm currently doing teleport related work, so I'd like to test it after that.
     
  49. kodra_dev

    kodra_dev

    Joined:
    Oct 31, 2022
    Posts:
    101
    If my mesh has multiple uv sets, is it possible to tell MagicaCloth to sample vertex paint map via a specific uv?

    It seems like the VirtualMesh has only one uv field and so I guess... no? Is there a way to work around it?

    And I think it would be better off taking vertex colors instead of sampling from a texture...
     
    Last edited: Aug 21, 2023
  50. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    821
    Paintmaps cannot be used if the render mesh has sub-meshes.
    That is when you have multiple UVs, which is currently the specification.
    https://magicasoft.jp/en/mc2_vertexpaint/#Link_to_Render_Mesh

    It's technically possible to support sub-mesh, but it's on hold because it would make the setup quite complicated.

    However, I think that the correspondence of painting by vertex color is an interesting proposal.
    Vertex colors can be easily retrieved and assigned to paint attributes.
    However, the vertex color must be created by the end user in advance using a modeling tool such as Blender/Maya.
    Want a vertex color paint implementation?