Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running Obi Cloth In Edit Mode
#1
Pregunta 
Hi,
I want to run obi cloth in edit mode during level design process. 
I could not see any info about this. Pls help. Thanks
Reply
#2
(22-12-2020, 10:07 AM)berko Wrote: Hi,
I want to run obi cloth in edit mode during level design process. 
I could not see any info about this. Pls help. Thanks

Hi there,

You can derive from the ObiUpdater class to update Obi whenever you want, including at edit time. See:
http://obi.virtualmethodstudio.com/tutor...aters.html

Also look up ObiUpdater in the API docs:
http://obi.virtualmethodstudio.com/api.html

You'll see it has several methods to advance the simulation: BeginStep, Substep, EndStep, and Interpolate. You can also check the different existing subclasses of ObiUpdater (ObiFixedUpdater, ObiLateUpdater, etc) for examples on how/when to call these methods. The typical pattern would be:

Code:
BeginStep();
Substep();
Substep();
.
.
.
Substep();
EndStep();
Interpolate();

So: one call to BeginStep() (performs collision detection and clears up cached data), one or more calls to Substep() (advances simulation), one call to EndStep(); (calls collision callbacks) and one call to Interpolate(); (interpolates physics state and triggers rendering).

cheers!
Reply
#3
(22-12-2020, 10:16 AM)josemendez Wrote: Hi there,

You can derive from the ObiUpdater class to update Obi whenever you want, including at edit time. See:
http://obi.virtualmethodstudio.com/tutor...aters.html

Also look up ObiUpdater in the API docs:
http://obi.virtualmethodstudio.com/api.html

You'll see it has several methods to advance the simulation: BeginStep, Substep, EndStep, and Interpolate. You can also check the different existing subclasses of ObiUpdater (ObiFixedUpdater, ObiLateUpdater, etc) for examples on how/when to call these methods. The typical pattern would be:

Code:
BeginStep();
Substep();
Substep();
.
.
.
Substep();
EndStep();
Interpolate();

So: one call to BeginStep() (performs collision detection and clears up cached data), one or more calls to Substep() (advances simulation), one call to EndStep(); (calls collision callbacks) and one call to Interpolate(); (interpolates physics state and triggers rendering).

cheers!
Hi, I tried bu unity crashes at m_SolverImpl.CollisionDetection(stepTime) at line 1396 in  obiolver. I could not figure out. I have modified FixedUpdater to run in EditMode.
Reply
#4
(22-12-2020, 09:49 PM)berko Wrote: Hi, I tried bu unity crashes at m_SolverImpl.CollisionDetection(stepTime) at line 1396 in  obiolver. I could not figure out. I have modified FixedUpdater to run in EditMode.
FixedUpdate is not called in editor. Simply adding [ExecuteInEditMode] to an existing updater won’t do, you need to write your own and call its methods when necessary.

Also note that actors will need to have their Awake() method called. Will write an example for you.
Reply
#5
(23-12-2020, 08:29 AM)josemendez Wrote: FixedUpdate is not called in editor. Simply adding [ExecuteInEditMode] to an existing updater won’t do, you need to write your own and call its methods when necessary.

Also note that actors will need to have their Awake() method called. Will write an example for you.
An example would be be great Jose. Thanks
Reply
#6
Turns out collisions and a few other bits weren't really ready for in-editor simulation. In addition to extending ObiUpdater, you will need to make a few changes:

- Add [ExecuteInEditMode] to BurstColliderWorld.cs/OniColliderWorld.cs. This will allow collision data structures to be initialized in-editor.
- Add [ExecuteInEditMode] to ObiParticleAttachment.cs. This will allow attachments to run in edit mode.
- Comment out lines 1106-1126 of ObiActor.cs. These are intended to override renderable particle positions at edit time, to allow particle positions to reflect changes to the actor's transform in absence of simulation.
- Line 146 of ObiClothRendererBase.cs, remove  "Application.isPlaying" from the if() statement. This was intended to reduce work done in-editor.

With these changes, you can then use this ObiUpdater subclass to step the simulation forward in editor by clicking the inspector's "update" button.

Code:
using UnityEngine;

namespace Obi
{
    /// <summary>
    /// Updater class that will perform simulation at edit time.

    [AddComponentMenu("Physics/Obi/Obi Editor Updater", 801)]
    [ExecuteInEditMode]
    public class ObiEditorUpdater : ObiUpdater
    {

        /// <summary>
        /// Each FixedUpdate() call will be divided into several substeps. Performing more substeps will greatly improve the accuracy/convergence speed of the simulation.
        /// Increasing the amount of substeps is more effective than increasing the amount of constraint iterations.
        /// </summary>
        [Tooltip("Amount of substeps performed per FixedUpdate. Increasing the amount of substeps greatly improves accuracy and convergence speed.")]
        public int substeps = 1;

        [InspectorButton("UpdateEditor")]
        public bool update;

        private void OnValidate()
        {
            substeps = Mathf.Max(1, substeps);
        }

        private void UpdateEditor()
        {
            Step(0.02f);
        }

        private void Step(float timestep)
        {
            ObiProfiler.EnableProfiler();

            BeginStep(timestep);

            float substepDelta = timestep / (float)substeps;

            // Divide the step into multiple smaller substeps:
            for (int i = 0; i < substeps; ++i)
            {
                // Simulate Obi:
                Substep(substepDelta);
            }

            EndStep(substepDelta);

            Interpolate(timestep, timestep);

            ObiProfiler.DisableProfiler();
        }
    }
}

If you describe your use case more accurately, I can come up with better solutions for it after Christmas. Potential improvements include writing an in-editor fixed timestep loop to circumvent the absence of FixedUpdate() calls, supporting simulation reset, updating Unity's rigidbody physics in sync, and some others.

cheers!
Reply