10-08-2021, 09:32 AM
(This post was last modified: 10-08-2021, 09:35 AM by josemendez.)
(10-08-2021, 09:09 AM)TheMunk Wrote: Hi there, quick question;
How does one disable simulation on a client but retain particles? I.e. read particle positions from the networked host but still do the rendering using Obi. Disabling the updater removes any particles. I found that disabling all constraints and gravity in the solver and particle attachments on the rope was the only way. Am I missing something?
Usually, there's no point in updating rope/cloth/softbody/fluid meshes and rendering particles if the simulation is not running: the current mesh -in whatever state it was left after the last update- is used for rendering.
All updater components update and render in sync. However the ObiUpdater class is meant to be extended in any way you need. You can easily create your own Updater component that can independently perform solving and update rendering. As an example, here's a modified ObiFixedUpdater with a "solve" toggle that lets you disable simulation only, but keeps particle rendering going:
Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
namespace Obi
{
/// <summary>
/// Updater class that will perform simulation during FixedUpdate(). This is the most physically correct updater,
/// and the one to be used in most cases. Also allows to perform substepping, greatly improving convergence.
[AddComponentMenu("Physics/Obi/Obi Fixed Updater", 801)]
[ExecuteInEditMode]
public class ObiFixedUpdater : 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 = 4;
public bool solve = true;
private float accumulatedTime;
private void OnValidate()
{
substeps = Mathf.Max(1, substeps);
}
private void Awake()
{
accumulatedTime = 0;
}
private void OnDisable()
{
Physics.autoSimulation = true;
}
private void FixedUpdate()
{
if (solve)
{
ObiProfiler.EnableProfiler();
BeginStep(Time.fixedDeltaTime);
float substepDelta = Time.fixedDeltaTime / (float)substeps;
// Divide the step into multiple smaller substeps:
for (int i = 0; i < substeps; ++i)
Substep(Time.fixedDeltaTime, substepDelta, substeps - i);
EndStep(substepDelta);
ObiProfiler.DisableProfiler();
accumulatedTime -= Time.fixedDeltaTime;
}
}
private void Update()
{
ObiProfiler.EnableProfiler();
Interpolate(Time.fixedDeltaTime, accumulatedTime);
ObiProfiler.DisableProfiler();
if (solve)
accumulatedTime += Time.deltaTime;
}
}
}