Fix cloth painting in prefab window
This commit is contained in:
@@ -54,6 +54,13 @@ namespace FlaxEngine.Tools
|
|||||||
|
|
||||||
Owner.Gizmos.Active = Gizmo;
|
Owner.Gizmos.Active = Gizmo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
Owner.Gizmos.Remove(Gizmo);
|
||||||
|
|
||||||
|
base.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class ClothPaintingGizmo : GizmoBase
|
sealed class ClothPaintingGizmo : GizmoBase
|
||||||
@@ -85,9 +92,19 @@ namespace FlaxEngine.Tools
|
|||||||
return;
|
return;
|
||||||
PaintEnd();
|
PaintEnd();
|
||||||
_cloth = cloth;
|
_cloth = cloth;
|
||||||
_clothParticles = cloth?.GetParticles();
|
_clothParticles = null;
|
||||||
_clothPaint = null;
|
_clothPaint = null;
|
||||||
_hasHit = false;
|
_hasHit = false;
|
||||||
|
if (cloth != null)
|
||||||
|
{
|
||||||
|
_clothParticles = cloth.GetParticles();
|
||||||
|
if (_clothParticles == null || _clothParticles.Length == 0)
|
||||||
|
{
|
||||||
|
// Setup cloth to get proper particles (eg. if cloth is not on a scene like in Prefab Window)
|
||||||
|
cloth.Rebuild();
|
||||||
|
_clothParticles = cloth.GetParticles();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Fill()
|
public void Fill()
|
||||||
|
|||||||
@@ -46,7 +46,10 @@ void Cloth::SetMesh(const ModelInstanceActor::MeshReference& value)
|
|||||||
|
|
||||||
_mesh = value;
|
_mesh = value;
|
||||||
_mesh.Actor = nullptr; // Don't store this reference
|
_mesh.Actor = nullptr; // Don't store this reference
|
||||||
Rebuild();
|
#if WITH_CLOTH
|
||||||
|
if (_cloth)
|
||||||
|
Rebuild();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloth::SetForce(const ForceSettings& value)
|
void Cloth::SetForce(const ForceSettings& value)
|
||||||
@@ -88,18 +91,15 @@ void Cloth::SetFabric(const FabricSettings& value)
|
|||||||
void Cloth::Rebuild()
|
void Cloth::Rebuild()
|
||||||
{
|
{
|
||||||
#if WITH_CLOTH
|
#if WITH_CLOTH
|
||||||
if (_cloth)
|
// Remove old
|
||||||
{
|
if (IsDuringPlay())
|
||||||
// Remove old
|
PhysicsBackend::RemoveCloth(GetPhysicsScene()->GetPhysicsScene(), _cloth);
|
||||||
if (IsDuringPlay())
|
DestroyCloth();
|
||||||
PhysicsBackend::RemoveCloth(GetPhysicsScene()->GetPhysicsScene(), _cloth);
|
|
||||||
DestroyCloth();
|
|
||||||
|
|
||||||
// Create new
|
// Create new
|
||||||
CreateCloth();
|
CreateCloth();
|
||||||
if (IsDuringPlay())
|
if (IsDuringPlay())
|
||||||
PhysicsBackend::AddCloth(GetPhysicsScene()->GetPhysicsScene(), _cloth);
|
PhysicsBackend::AddCloth(GetPhysicsScene()->GetPhysicsScene(), _cloth);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,8 +308,10 @@ void Cloth::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Refresh cloth when settings were changed
|
// Refresh cloth when settings were changed
|
||||||
if (IsDuringPlay())
|
#if WITH_CLOTH
|
||||||
|
if (_cloth)
|
||||||
Rebuild();
|
Rebuild();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
@@ -424,7 +426,6 @@ void Cloth::BeginPlay(SceneBeginData* data)
|
|||||||
#if WITH_CLOTH
|
#if WITH_CLOTH
|
||||||
if (CreateCloth())
|
if (CreateCloth())
|
||||||
LOG(Error, "Failed to create cloth '{0}'", GetNamePath());
|
LOG(Error, "Failed to create cloth '{0}'", GetNamePath());
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Actor::BeginPlay(data);
|
Actor::BeginPlay(data);
|
||||||
@@ -434,10 +435,7 @@ void Cloth::EndPlay()
|
|||||||
{
|
{
|
||||||
Actor::EndPlay();
|
Actor::EndPlay();
|
||||||
|
|
||||||
#if WITH_CLOTH
|
DestroyCloth();
|
||||||
if (_cloth)
|
|
||||||
DestroyCloth();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloth::OnEnable()
|
void Cloth::OnEnable()
|
||||||
@@ -466,11 +464,21 @@ void Cloth::OnDisable()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Cloth::OnDeleteObject()
|
||||||
|
{
|
||||||
|
DestroyCloth();
|
||||||
|
|
||||||
|
Actor::OnDeleteObject();
|
||||||
|
}
|
||||||
|
|
||||||
void Cloth::OnParentChanged()
|
void Cloth::OnParentChanged()
|
||||||
{
|
{
|
||||||
Actor::OnParentChanged();
|
Actor::OnParentChanged();
|
||||||
|
|
||||||
Rebuild();
|
#if WITH_CLOTH
|
||||||
|
if (_cloth)
|
||||||
|
Rebuild();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cloth::OnTransformChanged()
|
void Cloth::OnTransformChanged()
|
||||||
@@ -588,8 +596,11 @@ void Cloth::DestroyCloth()
|
|||||||
_meshDeformation->RemoveDeformer(_mesh.LODIndex, _mesh.MeshIndex, MeshBufferType::Vertex1, deformer);
|
_meshDeformation->RemoveDeformer(_mesh.LODIndex, _mesh.MeshIndex, MeshBufferType::Vertex1, deformer);
|
||||||
_meshDeformation = nullptr;
|
_meshDeformation = nullptr;
|
||||||
}
|
}
|
||||||
PhysicsBackend::DestroyCloth(_cloth);
|
if (_cloth)
|
||||||
_cloth = nullptr;
|
{
|
||||||
|
PhysicsBackend::DestroyCloth(_cloth);
|
||||||
|
_cloth = nullptr;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Recreates the cloth by removing current instance data and creating a new physical cloth object. Does nothing if cloth was not created (eg. no parent mesh).
|
/// Recreates the cloth by removing current instance data and creating a new physical cloth object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
API_FUNCTION() void Rebuild();
|
API_FUNCTION() void Rebuild();
|
||||||
|
|
||||||
@@ -332,6 +332,7 @@ protected:
|
|||||||
void EndPlay() override;
|
void EndPlay() override;
|
||||||
void OnEnable() override;
|
void OnEnable() override;
|
||||||
void OnDisable() override;
|
void OnDisable() override;
|
||||||
|
void OnDeleteObject() override;
|
||||||
void OnParentChanged() override;
|
void OnParentChanged() override;
|
||||||
void OnTransformChanged() override;
|
void OnTransformChanged() override;
|
||||||
void OnPhysicsSceneChanged(PhysicsScene* previous) override;
|
void OnPhysicsSceneChanged(PhysicsScene* previous) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user