01-06-2021, 01:30 PM
(This post was last modified: 01-06-2021, 01:33 PM by josemendez.)
(01-06-2021, 09:32 AM)orestissar Wrote: Hello !
Do you have any update on this?
Hi,
I see you're using skinned cloth instead of regular cloth.
Unity's SkinnedMeshRenderer does not accept meshes with no bone weights, which is required for cloth simulation. So Obi removes the mesh from the SkinnedMeshRenderer and renders it itself using Graphics.DrawMesh. You can see the code for this is ObiSkinnedClothRenderer's UpdateRenderer() method.
What Alembic does is it exports SkinnedMeshRenderer's sharedMesh data (since it knows nothing about Obi). So once you enable Obi's LateFixedUpdater component in your code, Alembic will cease to export data for the mesh (as it has moved from SkinnedMeshRenderer's sharedMesh to ObiSkinnedClothRenderer's clothMesh). This is why the cloth disappears from alembic file after a while: you enable the updater after a while using a coroutine, and right at that moment, Obi "hijacks" mesh rendering and Alembic loses track of the mesh.
There's several possible solutions. One would be modifying the AlembicExporter_impl to deal with ObiSkinnedClothRenderer. Another, simpler possibility is to write a simple component that takes the cloth mesh and puts it in a regular MeshRenderer so that Alembic can pick it up. Like this:
Code:
using UnityEngine;
using Obi;
[RequireComponent(typeof(SkinnedMeshRenderer))]
public class SkinnedClothAlembicExposer : MonoBehaviour
{
MeshFilter filter;
ObiSkinnedClothRenderer clothRenderer;
void Start()
{
GameObject alembicCloth = new GameObject(gameObject.name + "(Alembic)",typeof(MeshFilter),typeof(MeshRenderer));
alembicCloth.transform.parent = transform;
filter = alembicCloth.GetComponent<MeshFilter>();
alembicCloth.GetComponent<MeshRenderer>().material = GetComponent<SkinnedMeshRenderer>().material;
}
private void LateUpdate()
{
clothRenderer = GetComponent<ObiSkinnedClothRenderer>();
if (clothRenderer != null)
filter.sharedMesh = clothRenderer.clothMesh;
}
}
Adding this to each of your cloth SkinnedMeshRenderers, it will create a child gameobject with a MeshRenderer and feed it Obi's clothMesh so that Alembic can pick it up. Remember to untick AlembicExporter's Static MeshRenderers checkbox, or it will ignore MeshRenderers too.
kind regards,