Search Unity

[RELEASED] MagicaCloth2 - Hybrid Cloth Simulation

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

  1. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    Thank you!

    Another problem is I disabled all the Gizmos of magica but they're still shown in scene view.
    Unity 2022.2 URP

    upload_2023-3-1_17-13-47.png
     
  2. Faisal_Azizi_

    Faisal_Azizi_

    Joined:
    Feb 5, 2021
    Posts:
    25
    Basically is there a way to add the points manually (fixed, moving) to the mesh cloth?
     
  3. Fearinhell

    Fearinhell

    Joined:
    Oct 2, 2021
    Posts:
    17
    I followed those instructions and I still have 35 errors. They seem to be with Jobs which was replaced by Collections. I had checked my version before ever attempting to install magicacloth 2. Collections was/is at 1.4.0 and Burst is at 1.8.3. Mathmatics was there but now I have uninstalled it. Looks like I dont have IJobParallelForDefer, that name space doesnt exist and I think that is most of the errors. I did a completel uninstall of the three packages, and at one point in time a jobs package appeared but is now gone again since collections reinstalled. Other ideas? Oh! Jobs Custom .11.0-preview.6 is back. It wasnt there until I installed magicacloth 2. It has reference to this name space. I removed that custom jobs preview that would show up and dissappear on its own whims and once I got it removed the errors are resolved.
     
    Last edited: Mar 1, 2023
  4. Fearinhell

    Fearinhell

    Joined:
    Oct 2, 2021
    Posts:
    17
    Is there a way to fill in all of the paint dots like in version 1? Im not seeing that and it will take me hours per piece of clothing to get all these dots filled in even at max circle settings, I just have to keep going around in circles because inside/outside etc dots.

    Also has someone updated that Dress Up API Test code to work with version 2? The script for Version 1 doesnt work with version 2. Thanks.
     
    Last edited: Mar 1, 2023
  5. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Hello.
    This check is valid only for gizmo display.
    3D icons do not disappear with this check.
    Gizmo display and 3D icons are two different things.
    This is also true for regular components such as Camera and AudioSource.
    The 3D icon can be changed using the slide bar as shown below.
    icon3d-1.jpg
     
    Spikebor likes this.
  6. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Unfortunately, no.
    Point attributes cannot be changed at runtime.
     
  7. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Hello.
    Strange situation, but I am relieved that the problem is solved.

    First of all, the Jobs package is no longer needed in either V1 or V2.
    The Jobs package has been merged into Collections 1.4.0 and removed.
    Only Burst and Collections are needed for both V1 and V2.
    Mathematices is also required, but it is automatically included when Burst is installed.
    Anyway, I assume the error was caused by unnecessary Jobs remaining.
     
  8. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    There is no fill function.
    This was withdrawn from implementation because we did not want to add more buttons.
    However, we will consider re-implementing it since other users have requested the same thing.

    About the change of clothes.
    First, V2 is a destructive update.
    It is not compatible with V1 and should be considered a completely different asset.
    Therefore, V1 code cannot be appropriated.
    Please refer to the following document for information on how to dress V2.
    https://magicasoft.jp/en/mc2_dressup/
     
  9. Fearinhell

    Fearinhell

    Joined:
    Oct 2, 2021
    Posts:
    17
    Also a all select to select all of the colliders on the character would be fantastic. Ive spent the last two days making colliders for v1 and Id still be dragging colliders.
     
  10. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Thanks for your input.
    Perhaps a feature that automatically positions the collider according to the human body would be the first thing to go in.
    This feature has been requested a lot, and in fact I would like to have it myself.
    However, it is low on my priority list because I need to add the missing features first.
     
  11. huanghonghong

    huanghonghong

    Joined:
    Jul 8, 2021
    Posts:
    6
    Hello.
    Is mesh collider support?
     
  12. Faisal_Azizi_

    Faisal_Azizi_

    Joined:
    Feb 5, 2021
    Posts:
    25
    upload_2023-3-3_13-9-13.png
    I been getting this error when i try to use texture as a paint mode. that method works in the included models but when i try it on my own model it does not work.
    upload_2023-3-3_13-11-12.png
     
  13. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Hello.
    Unfortunately, mesh colliders are not supported.
     
  14. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Hello.
    This is a bad error.
    Did this occur after you pressed the Run button?
    Or did it occur during the edit before execution?
     
  15. Faisal_Azizi_

    Faisal_Azizi_

    Joined:
    Feb 5, 2021
    Posts:
    25
    This happens when i assign the paint map. and it start showing in the edit time
     
  16. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Okay, I will look into it.
    By the way, is the Unity editor version 2021 or 2022?
     
  17. Faisal_Azizi_

    Faisal_Azizi_

    Joined:
    Feb 5, 2021
    Posts:
    25
    upload_2023-3-3_16-21-56.png
    This error is thrown the moment you assign the paint map
     
  18. Faisal_Azizi_

    Faisal_Azizi_

    Joined:
    Feb 5, 2021
    Posts:
    25
    Thank you! the unity version is 2022.
     
  19. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Thank you very much.
    I will look into the issue.
     
    the_unity_saga and Faisal_Azizi_ like this.
  20. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    upload_2023-3-3_19-49-9.png

    Do you know about the issue with Mesh Cloth ? the moving part will be black like this. I think it is using proxy mesh for rendering.
    Unity 2022.2.8f1 HDRP, Magica Cloth2 ver 2.0.3 (newest)
     
  21. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Hello.
    I've been having trouble figuring out what the cause of this problem is.
    I have a request, can I borrow this character's prefab with MagicaCloth set?
    If possible, please start "Start a Conversation" from my account.
    If so, you don't have to worry about other people seeing the download URL.
    Reproducing the problem will help us determine the cause.
     
    Spikebor likes this.
  22. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    Yup I'll slide in DM now
     
  23. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    281
    Okay after I changed Import setting to Optimize Mesh>Everything instead of None, and Normals>Calculate instead of Import then the issue is no more. I still don't know what the problem is with the mesh, but post here for anyone has same problem.

    upload_2023-3-3_21-36-28.png
     
  24. the_unity_saga

    the_unity_saga

    Joined:
    Sep 17, 2016
    Posts:
    268
    Sir Dev, hello.

    thank you for your hard work.

    I have a problem, unsure if this is a bug:

    - I choose UnityChanKAGURA_URP demo (or built-in, etc)
    - Everything works, for ONE model
    - I DUPLICATE UnityCHanKAGURA_MC2, for testing purposes, the duplicated copy works for animations, BUT not for simulation on hair ponytail, and 'sode L' and 'sode R', but! The 'wing' works in real time, and can be disabled and enabled as expected,

    why does some of the simulation "break" on duplication?? How should we currently perform correct duplication with working simulation on our prefabs/assets?

    Thanks again.
     
  25. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    @Spikebor
    Thanks for the prefab.
    I was able to reproduce the problem here in the same environment!
    Very helpful.

    After a little research, it seems that this is due to the fact that the mesh does not include tangents.

    model-tangent-1.jpg

    So changing the tangents to Calculate cures it.
    I will now look into the details of the cause.
     
  26. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Hello.
    Did you duplicate a MagicaCloth component that has entered the run state?
    You cannot duplicate a MagicaCloth component once it has entered the Run state.
    Duplication must be done before entering the run state.
    That is, Instantiate() from a prefab, etc.
     
    the_unity_saga likes this.
  27. the_unity_saga

    the_unity_saga

    Joined:
    Sep 17, 2016
    Posts:
    268
    thank you !!
     
  28. Fearinhell

    Fearinhell

    Joined:
    Oct 2, 2021
    Posts:
    17
    That would be wonderful!
     
  29. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Hello.
    I am trying to find out the cause of the error, but there is no error here.
    Could you please tell me about the following

    (1) Full stack trace
    I would like to know the full stack trace of the error.
    This can be seen by changing the following options from the Jobs menu

    * Turn off Burst/Enabled Compilation
    * Turn ON Leak Detection/Full Stack Traces (Expensive)
    * Turn on JobsDebugger

    Could you please give me the full text of the error in this state?
    Please restore the checks after the test.

    (2) Paint Texture
    Is the paint map that causes the error different from a normal texture?
    Do they have any special characteristics?
    Also, does the error occur even if the paint map that causes the error is set to a different mesh?
    For example, I can add MagicaCloth to a simple Plane mesh and set the corresponding paintmap.
    In other words, is this paintmap itself likely to be the cause?
     
    Faisal_Azizi_ likes this.
  30. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Update: 2.0.4

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

    Release Note:
    Fix: When a mesh does not exist in the Renderer specified in MeshCloth, an internal error occurs and the operation becomes unstable.
    Fix: Internal error occurs and drawing becomes black when tangent line does not exist on the mesh specified by MeshCloth.
    Fix: The algorithm for mapping a render mesh to a proxy mesh in MeshCloth is incorrect, causing artifacts such as shading in drawings.

    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


    https://magicasoft.jp/en/mc2_releasenote/
     
    Last edited: Mar 6, 2023
  31. Hummy91

    Hummy91

    Joined:
    Jun 7, 2017
    Posts:
    67
    I'm getting this error when I instantiate a prefab that has a MagicaCloth component on it:
    Code (CSharp):
    1. System.NullReferenceException: Object reference not set to an instance of an object
    2.   at MagicaCloth2.DistanceConstraint.CreateData (MagicaCloth2.VirtualMesh proxyMesh, MagicaCloth2.ClothParameters& parameters) [0x00365]
    Are prefabs not supported? My projects inventory system spawns skinned prefabs for various clothing items when they are equipped by the player for context.
     
  32. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Don't worry, instantiation from prefabs is naturally supported.
    Without it, it is impossible to create a game in Unity.

    I just don't know the cause of this error.
    I would like more detailed information.

    (1)
    The error does not include the line number of the code.
    Is this all that is being displayed?
    Is there a full stack trace shown that includes line numbers?

    (2)
    Is this error at build time?
    Or is it in the editor environment?

    (3)
    What is the instantiation procedure?
    For example, a character that has been instantiated once and is now operational cannot be instantiated again.
    Also, instantiation at special timing other than Start()/Update(), etc.
    Do you perform any special instantiation like this?
     
  33. Faisal_Azizi_

    Faisal_Azizi_

    Joined:
    Feb 5, 2021
    Posts:
    25
    There are two errors. one error happens the moment you add the paint texture. Another happens when you play the game. When you apply the paint texture it does not show the dots or anything as normal and i am faced with the following error.


    IndexOutOfRangeException: Index 6386 is out of range of '4096' Length.
    Unity.Collections.NativeArray`1[T].FailOutOfRangeError (System.Int32 index) (at <f7bcd9bfa40c4821acdda68a85850616>:0)
    Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at <f7bcd9bfa40c4821acdda68a85850616>:0)
    Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at <f7bcd9bfa40c4821acdda68a85850616>:0)
    MagicaCloth2.ClothProcess+GenerateSelectionJob.Execute (System.Int32 vindex) (at Assets/_Client/Plugins/MagicaCloth2/Scripts/Core/Cloth/ClothProcess.cs:947)
    Unity.Jobs.IJobParallelForExtensions+ParallelForJobStruct`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at <f7bcd9bfa40c4821acdda68a85850616>:0)
    Unity.Jobs.LowLevel.Unsafe.JobsUtility:ScheduleParallelFor_Injected(JobScheduleParameters&, Int32, Int32, JobHandle&)
    Unity.Jobs.LowLevel.Unsafe.JobsUtility:ScheduleParallelFor(JobScheduleParameters&, Int32, Int32)
    Unity.Jobs.IJobParallelForExtensions:Run(GenerateSelectionJob, Int32)
    MagicaCloth2.ClothProcess:GenerateSelectionDataFromPaintMap(VirtualMesh, TransformRecord, List`1, List`1, SelectionData&) (at Assets/_Client/Plugins/MagicaCloth2/Scripts/Core/Cloth/ClothProcess.cs:892)
    MagicaCloth2.<>c__DisplayClass19_1:<CreateOrUpdateEditMesh>b__1() (at Assets/_Client/Plugins/MagicaCloth2/Scripts/Editor/Cloth/ClothEditorManager.cs:642)
    System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()


    I have tested the same texture with the the included unity chan model and it seems to be working fine. Also i have used the paint map that is included in the demo on my model and still does not work. it leads me to believe that its not coming from the paint texture itself. the following is the paint texture settings.
    upload_2023-3-7_14-48-0.png

    Note: the same texture works for the demo model.

    And the second error happens when i run the game as follows:


    /// stack trace for when you run
    [MC2] Cloth build failure!: outfit.02
    0x00007ff7146af9fd (Unity) StackWalker::GetCurrentCallstack
    0x00007ff7146b66f9 (Unity) StackWalker::ShowCallstack
    0x00007ff715651943 (Unity) GetStacktrace
    0x00007ff715d07ea3 (Unity) DebugStringToFile
    0x00007ff713789966 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    0x0000018d4fa9e1e3 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
    0x0000018d4fa9e0fb (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    0x0000018d4fa9de40 (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
    0x0000018d50b132f5 (Mono JIT Code) UnityEngine.Debug:LogError (object)
    0x0000018d721e66ab (Mono JIT Code) [Develop.cs:26] MagicaCloth2.Develop:LogError (object&)
    0x0000018d721e6593 (Mono JIT Code) [ClothProcess.cs:286] MagicaCloth2.ClothProcess:StartBuild ()
    0x0000018d721e639b (Mono JIT Code) [ClothProcess.cs:297] MagicaCloth2.ClothProcess:AutoBuild ()
    0x0000018d721e6313 (Mono JIT Code) [MagicaCloth.cs:90] MagicaCloth2.MagicaCloth:Start ()
    0x0000018d7c98d4c8 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    0x00007ffdfc4c0384 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke
    0x00007ffdfc3feb34 (mono-2.0-bdwgc) [object.c:3066] do_runtime_invoke
    0x00007ffdfc3feccc (mono-2.0-bdwgc) [object.c:3113] mono_runtime_invoke
    0x00007ff7145d3f14 (Unity) scripting_method_invoke
    0x00007ff7145b3864 (Unity) ScriptingInvocation::Invoke
    0x00007ff7145a2f7b (Unity) MonoBehaviour::InvokeMethodOrCoroutineChecked
    0x00007ff7145a3086 (Unity) MonoBehaviour::InvokeMethodOrCoroutineChecked
    0x00007ff71459d502 (Unity) MonoBehaviour::DelayedStartCall
    0x00007ff71407a134 (Unity) DelayedCallManager::Update
    0x00007ff714290a89 (Unity) `InitPlayerLoopCallbacks'::`2'::EarlyUpdateScriptRunDelayedStartupFrameRegistrator::Forward
    0x00007ff71427835a (Unity) ExecutePlayerLoop
    0x00007ff7142784e6 (Unity) ExecutePlayerLoop
    0x00007ff71427e430 (Unity) PlayerLoop
    0x00007ff7151f29ef (Unity) PlayerLoopController::UpdateScene
    0x00007ff7151ddb25 (Unity) PlayerLoopController::EnterPlayMode
    0x00007ff7151ed77a (Unity) PlayerLoopController::SetIsPlaying
    0x00007ff7151f0e80 (Unity) Application::TickTimer
    0x00007ff71565759a (Unity) MainMessageLoop
    0x00007ff71565c3b4 (Unity) WinMain
    0x00007ff7169d448e (Unity) __scrt_common_main_seh
    0x00007ffe51c326bd (KERNEL32) BaseThreadInitThunk
    0x00007ffe5374dfb8 (ntdll) RtlUserThreadStart


    upload_2023-3-7_14-49-34.png

    upload_2023-3-7_14-54-52.png
    these are the model importer settings

    the following is when i apply the paint map to another model. one thing to note is that i was able to make certain other models work.

    System.IndexOutOfRangeException: Index {0} is out of range of '{1}' Length.
    This Exception was thrown from a job compiled with Burst, which has limited exception support.
    0x00007ffe0338f509 (e3cd52dc187bd694da4fbbdddc5d325) [unknown:0] Unity.Jobs.IJobParallelForExtensions.ParallelForJobStruct`1<MagicaCloth2.ClothProcess.GenerateSelectionJob>.Execute(ref MagicaCloth2.ClothProcess.GenerateSelectionJob jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, ref Unity.Jobs.LowLevel.Unsafe.JobRanges ranges, int jobIndex) -> void_73c04fea4d034adcf3d7ccb459d2c985 from UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
    0x00007ffe0338eb76 (e3cd52dc187bd694da4fbbdddc5d325) 4cd7d5bdfff8ffdd21be454bdbea12e5
    0x00007ff71422a670 (Unity) ExecuteJob
    0x00007ff71422a9e5 (Unity) ExecuteJobCopyData
    0x00007ff71422b70f (Unity) ForwardJobForEachToManaged
    0x00007ff71422d511 (Unity) `anonymous namespace'::ScheduleManagedJobParallelFor_Internal
    0x00007ff71422c858 (Unity) ScheduleManagedJobParallelFor
    0x00007ff7137149ce (Unity) JobsUtility_CUSTOM_ScheduleParallelFor_Injected
    0x0000018d7209a4b3 (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&)
    0x0000018d7209a3a3 (Mono JIT Code) Unity.Jobs.LowLevel.Unsafe.JobsUtility:ScheduleParallelFor (Unity.Jobs.LowLevel.Unsafe.JobsUtility/JobScheduleParameters&,int,int)
    0x0000018d721566f3 (Mono JIT Code) Unity.Jobs.IJobParallelForExtensions:Run<MagicaCloth2.ClothProcess/GenerateSelectionJob> (MagicaCloth2.ClothProcess/GenerateSelectionJob,int)
    0x0000018d72154b6b (Mono JIT Code) [ClothProcess.cs:894] MagicaCloth2.ClothProcess:GenerateSelectionDataFromPaintMap (MagicaCloth2.VirtualMesh,MagicaCloth2.TransformRecord,System.Collections.Generic.List`1<MagicaCloth2.RenderSetupData>,System.Collections.Generic.List`1<MagicaCloth2.ClothProcess/PaintMapData>,MagicaCloth2.SelectionData&)
    0x0000018d7210433b (Mono JIT Code) [ClothEditorManager.cs:642] MagicaCloth2.ClothEditorManager/<>c__DisplayClass19_1:<CreateOrUpdateEditMesh>b__1 ()
    0x0000018c7a2b99e4 (Mono JIT Code) System.Threading.Tasks.Task:InnerInvoke ()
    0x0000018c7a2714a4 (Mono JIT Code) System.Threading.Tasks.Task:Execute ()
    0x0000018c7a2713e3 (Mono JIT Code) System.Threading.Tasks.Task:ExecutionContextCallback (object)
    0x0000018c60487f7e (Mono JIT Code) System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
    0x0000018c60487b4b (Mono JIT Code) System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
    0x0000018c7a2710fb (Mono JIT Code) System.Threading.Tasks.Task:ExecuteWithThreadLocal (System.Threading.Tasks.Task&)
    0x0000018c7a27095b (Mono JIT Code) System.Threading.Tasks.Task:ExecuteEntry (bool)
    0x0000018c7a2705fb (Mono JIT Code) System.Threading.Tasks.Task:System.Threading.IThreadPoolWorkItem.ExecuteWorkItem ()
    0x0000018c7a26e31a (Mono JIT Code) System.Threading.ThreadPoolWorkQueue:Dispatch ()
    0x0000018c7a26da9b (Mono JIT Code) System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
    0x0000018c7a26dbc5 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_bool (object,intptr,intptr,intptr)
    0x00007ffdfc4c0384 (mono-2.0-bdwgc) [mini-runtime.c:3445] mono_jit_runtime_invoke
    0x00007ffdfc3feb34 (mono-2.0-bdwgc) [object.c:3066] do_runtime_invoke
    0x00007ffdfc43bd07 (mono-2.0-bdwgc) [threadpool.c:386] worker_callback
    0x00007ffdfc43eda0 (mono-2.0-bdwgc) [threadpool-worker-default.c:502] worker_thread
    0x00007ffdfc42d6ab (mono-2.0-bdwgc) [threads.c:1268] start_wrapper_internal
    0x00007ffdfc42d886 (mono-2.0-bdwgc) [threads.c:1344] start_wrapper
    0x00007ffe51c326bd (KERNEL32) BaseThreadInitThunk
    0x00007ffe5374dfb8 (ntdll) RtlUserThreadStart

     
    Last edited: Mar 7, 2023
  34. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Thank you for the detailed report.
    I understand where the error is occurring.
    However, I have thought about it for a long time and cannot figure out why this error is occurring.
    The problem area is not particularly difficult.
    I am just getting the paintmap color from the UV of the mesh and converting it to a vertex attribute.

    Can you provide the relevant model data to resolve this issue?
    I have just sent a DM to you.
    If it is possible, I would appreciate your cooperation.
     
    Faisal_Azizi_ likes this.
  35. Finley3D

    Finley3D

    Joined:
    Jan 12, 2019
    Posts:
    3
    Hello, I am currently trying out bone cloth.
    In my project, I need to update mesh collider sometimes by using "SkinnedMeshRenderer.BakeMesh".
    If I rotate bones manually, the mesh collider does update correctly, but the bones rotated by Magica Cloth don't.
    Any ideas on this? Thanks.
     
  36. Hummy91

    Hummy91

    Joined:
    Jun 7, 2017
    Posts:
    67
    (1) Ah sorry, I posted the error assuming instantiation wasn't supported. The full stack trace for this error was:
    Code (CSharp):
    1. System.NullReferenceException: Object reference not set to an instance of an object
    2.   at MagicaCloth2.DistanceConstraint.CreateData (MagicaCloth2.VirtualMesh proxyMesh, MagicaCloth2.ClothParameters& parameters) [0x00365] in C:\Users\RR\P\2021\Assets\External\MagicaCloth2\Scripts\Core\Cloth\Constraints\DistanceConstraint.cs:260
    3. UnityEngine.Debug:LogError (object)
    4. MagicaCloth2.DistanceConstraint:CreateData (MagicaCloth2.VirtualMesh,MagicaCloth2.ClothParameters&) (at Assets/External/MagicaCloth2/Scripts/Core/Cloth/Constraints/DistanceConstraint.cs:296)
    5. MagicaCloth2.ClothProcess/<>c__DisplayClass9_0:<BuildAsync>b__1 () (at Assets/External/MagicaCloth2/Scripts/Core/Cloth/ClothProcess.cs:700)
    6. System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
    7.  
    (2) This is in the editor during play mode.

    (3) The instantiation procedure:
    Basically a MonoBehaviour in the scene. (Item)
    On the script (Item) is a reference to a clothing prefab (right now it's simply a skinned mesh prefab with the MagicaCloth component on it).
    I instantiate this prefab when a spawn method is called during play mode. (Right now I am testing it via some custom editor wear/unwear buttons).
    The instantiation is done through GameObject.Instantiate in a second script (ClothingController). And then the skinned mesh has it's bones updated to the bones of the character that it is for.

    Hm. The only 'special' thing about my spawn procedure is that I'm doing it using a button with a custom editor that overrides the inspector GUI for the MonoBehaviour (Item) which calls instantiate using Wear/Unwear methods. The logic for that looks like:

    Could the EditorUtility.SetDirty be causing problems?

    Code (CSharp):
    1.         private void DrawGUI_Clothing()
    2.         {
    3.             //    ClothingController is a monobehaviour script.
    4.             bool worn = clothingController.IsWearing(item);
    5.             string txt = worn ? "Unwear" : "Wear";
    6.             if( GUI.Button(EditorGUILayout.GetControlRect(), txt) )
    7.             {
    8.                 if( Application.isPlaying )
    9.                 {
    10.                     //    This will instantiate or destroy a skinned mesh prefab and set it up to follow the characters body mesh.
    11.                     if( worn ) clothingController.Unwear(item);
    12.                     else clothingController.Wear(item);
    13.                 }
    14.                 else
    15.                 {
    16.                     //    Editor version simply calls gameObject.SetActive( true/false ).
    17.                     if( worn )
    18.                     {                                
    19.                         clothingController.Wear_InEditor(item);
    20.                     }
    21.                     else {
    22.                         clothingController.Unwear_InEditor(item);
    23.                     }
    24.  
    25.                     //    Could this be an issue?
    26.                     EditorUtility.SetDirty(item);
    27.                     EditorUtility.SetDirty(clothingController);
    28.                 }
    29.             }
    30.         }
    For reference: The actual spawn code when the Wear method is called:

    Code (CSharp):
    1.         public void CreatePrefab()
    2.         {
    3.             switch (Type)
    4.             {
    5.                 case ItemType.Generic: break;
    6.                 case ItemType.Clothing:
    7.                     if( InstantiatedObject != null )
    8.                     {
    9.                         Destroy(InstantiatedObject);
    10.                     }
    11.                     InstantiatedObject = GameObject.Instantiate(Definition.ItemData_Clothing.ActivePrefab, transform);
    12.                     InstantiatedObject.transform.localPosition = Vector3.zero;
    13.                     InstantiatedObject.transform.localRotation = Quaternion.identity;
    14.                     Renderer = InstantiatedObject.GetComponentInChildren<SkinnedMeshRenderer>();
    15.                 break;
    16.                 case ItemType.Weapon: break;
    17.                 case ItemType.Consumable: break;
    18.             }
    19.         }
     
    Last edited: Mar 7, 2023
  37. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Hello.
    This is difficult.
    BoneCloth resets the registered Transform posture at the start of the frame.
    This reset is performed before Update() and FixedUpdate().
    Therefore, even if you get the posture of Transform with Update() etc., it will be the original posture that has not been simulated.
    Therefore, even if you perform BakeMesh() with Update() etc., the posture after simulation will not be obtained.
    This process is necessary to calculate the Transform frame start pose, so it cannot be removed.

    There is currently only one workaround available.
    That is to do a BakeMesh() right after the simulation completes.
    The following OnPostSimulation callback function should help with this.
    https://magicasoft.jp/en/mc2_api_magicamanager/#OnPostSimulation
     
    Finley3D likes this.
  38. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Hello.
    Thank you for your detailed report!
    However, I have thought about it for a while and cannot figure out the cause of this error.
    First of all, I don't understand the conditions under which a null reference error occurs in the following part

    Code (CSharp):
    1. System.NullReferenceException: Object reference not set to an instance of an object
    2.   at MagicaCloth2.DistanceConstraint.CreateData (MagicaCloth2.VirtualMesh proxyMesh, MagicaCloth2.ClothParameters& parameters) [0x00365] in C:\Users\RR\P\2021\Assets\External\MagicaCloth2\Scripts\Core\Cloth\Constraints\DistanceConstraint.cs:260
    3. UnityEngine.Debug:LogError (object)
    4. MagicaCloth2.DistanceConstraint:CreateData (MagicaCloth2.VirtualMesh,MagicaCloth2.ClothParameters&) (at Assets/External/MagicaCloth2/Scripts/Core/Cloth/Constraints/DistanceConstraint.cs:296)
    5. MagicaCloth2.ClothProcess/<>c__DisplayClass9_0:<BuildAsync>b__1 () (at Assets/External/MagicaCloth2/Scripts/Core/Cloth/ClothProcess.cs:700)
    6. System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()
    7.  
    There should be no null reference error in this part by design.
    Therefore, it is highly likely that the problem is occurring somewhere else, not in this part.

    We have already done the same thing with the RuntimeDressUp sample scene regarding the instantiation and dressing of the prefab with GUI buttons.
    I also tried creating a simple custom inspector and Instantiate() from a button, but the problem did not occur.
    SetDirty(), I don't think it matters because this code is not executed during the run due to the if minute.

    So, I would like to ask you to please give me a minimal project that causes this problem.
    This problem may be difficult to solve unless we can actually reproduce it here.
    If possible, could you send me a project to start a conversation from my [Start a Conversation]?
    Thank you in advance for your consideration.
     
  39. Finley3D

    Finley3D

    Joined:
    Jan 12, 2019
    Posts:
    3
    Nice, I solved it.
    It works perfectly now.
    Thanks, greatly appreciate it.
     
  40. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Thank you for confirming this.
    This was the only way to solve the problem, so I am relieved that it was resolved.
     
    Finley3D likes this.
  41. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    This is an additional reply.
    Just curious, is it possible that the number of lines in Constraints\DistanceConstraint.cs:260 in this error could be 263?
    If the error is occurring at 263 lines, then I have found one problematic area.
    Could you please double check the number of lines where the error occurs?
    Is it possible that the error is on this line?

    upload_2023-3-8_16-33-14.png

    For example, maybe it is 3 lines off due to some add-on.
     
  42. Hummy91

    Hummy91

    Joined:
    Jun 7, 2017
    Posts:
    67
    The error takes me to line 296: I may be on a slightly older version of MagicaCloth2 (I haven't updated this week). Should I update?
    I think it's also worth clarifying, the prefab that I instantiate has a SkinnedMeshRenderer component on it. But there is no bone hierarchy or root saved with this prefab. When it gets instantiated I dynamically update the renderers bone list and root bone. Wondering if that could be causing problems?


     
  43. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    I would like to have the latest version of MagicaCloth if possible.
    Also, line 296 is part A of the image.
    What I would like to know is which source code part B corresponds to.
    I predict that it will be line 263 of the image I posted one post ago.

    DistanceConstraintIssue-2.jpg

    About the prefab.
    There is a problem with the structure of this prefab.
    SkinnedMeshRenderer may work fine, but MagicaCloth's porting will not work.
    MagicaCloth requires that all necessary bones be contained within the prefab.
    This is almost the same as the bones required by SkinnedMeshRenderer.
    If any of these bones are missing when prefabricated, some error should occur.
    There is a sample scene and documentation on how to change clothes using prefabrication.
    Please refer to these two.
    https://magicasoft.jp/en/mc2_dressup/

    mc2_dressup-1.jpg
     
  44. Onat-H

    Onat-H

    Joined:
    Mar 11, 2015
    Posts:
    195
    What’s the best approach to use mesh cloth with LODs? Does it automatically disable the simulation when the referenced mesh ist not rendered? I think that might be the easiest way :)

    Thanks for this amazing asset!
     
  45. Hummy91

    Hummy91

    Joined:
    Jun 7, 2017
    Posts:
    67
    Ah I see. I checked and you are correct, line 260 does point to the line you mentioned:

    (This is after updating to the latest version).

    I never installed the example scenes as our project is quite mature. When we create the prefabs, the skinned mesh renderer component does have bones as it is skinned to the character at the time the prefab is saved. However, because the skinned mesh renderer is saved as a prefab separate from the character, the prefab itself has no bones until it is instantiated. (Unity clears the bone references etc by itself).

    This is currently how our entire project handles character attachments and clothing and we don't intend to change it as including a bone hierarchy with every skinned prefab that uses a single skeleton would be wasteful and also awkward for our artists.
    In the case of MagicaCloth2 "Mesh Cloth", the bones shouldn't matter should they? Is there a possible work around for this?
     
  46. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Hello.
    Unfortunately, there is no dedicated function for LOD.
    Therefore, it is necessary to set MagicaCloth for all LODs and switch MagicaCloth Enable/Disable in conjunction with drawing.
    Currently, this is the only way.
     
  47. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Thank you for the images!
    First of all, we have identified the error, which is one step forward.
    I would like to switch to a dedicated conversation about this issue as it involves the passing of files.
    Also, please note that this conversation is expected to be a lengthy one.
    I will send a DM to you.
     
    Last edited: Mar 9, 2023
  48. tenos

    tenos

    Joined:
    Jul 3, 2014
    Posts:
    2
    Hi ,What's the simulation algorithm in Magica?
    "Mass Spring Systems" or "Position Based Dynamics" or others ?


    Is their a plan that change code comments to English ?
     
  49. hoshos

    hoshos

    Joined:
    Mar 7, 2015
    Posts:
    920
    Hello.
    MagicaCloth is PBD (Position Based Dynamics).
    However, I have made various arrangements in various places.

    I am Japanese, so please forgive that my comments are in Japanese.
    I understand only simple English.
    However, I try to add English comments to the methods that are opened to the outside such as API.
     
  50. Creiz

    Creiz

    Joined:
    Jun 6, 2017
    Posts:
    130
    Is there a "Weight" funtionality? For example I set it to 0, no simulation occurs, I set it to 1, simulation is in full?

    It's useful for example if I want to stop simulating during a cutscene or reduce the effects of a bonecloth simulation for just a little bit, then go back to normal.