Comments (4)
I'm not sure what version you're on, but on the latest if you want to change the mesh, you should only need to call deformable.ChangeMesh(someMesh)
However, for the Elastic Deformable, simply swapping the mesh is not enough because you also need to reset the additional position and velocity data used for the elastic calculations. If you don't reset the data it will look like this:
To reset the dynamic data, all you need to call is DisposeData()
followed by AllocateData()
Here's the example script I wrote to test changing meshes at runtime. Let me know if it works for ya!
using Deform;
using UnityEngine;
public class MeshSwapExample : MonoBehaviour
{
[SerializeField] private Deformable deformable;
[SerializeField] private Mesh swapMesh;
[SerializeField] private KeyCode swapKey = KeyCode.Space;
private Mesh to, from;
private void Start()
{
to = swapMesh;
from = deformable.GetOriginalMesh();
}
private void Update()
{
if (deformable == null)
return;
if (Input.GetKeyDown(swapKey))
{
deformable.ChangeMesh(to);
(to, from) = (from, to);
if (deformable is ElasticDeformable elasticDeformable)
{
// You would normally want to call Complete() before disposing/changing the data to finish any running jobs that are using the data,
// but the deformable.ChangeMesh() call above already calls Complete() so it's not necessary in this case:
// elasticDeformable.Complete();
elasticDeformable.DisposeData();
elasticDeformable.AllocateData();
}
}
}
}
from deform.
Thanks, I will test that! I had found a dirty solution: remove the ElasticDeformable & create a new one :") I know it's sad... but I had to find something :')
I will try that. I suggest to add an Utility function for the future :)
from deform.
Well unfortunatly, I have the same behavior as before... It works fine, but when I leave the play mode, I have 140+ error "A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details."
from deform.
Hmmm I an unable to reproduce this behavior on my end. Do you mind sharing a repro project, or the exact Unity/Deform version + some code I can run that should cause the error?
from deform.
Related Issues (20)
- Bend not applied to plane or any other "flat" model HOT 1
- Deformer are destroyed on play HOT 2
- How to make Elastic Deformalble work?
- Shading breaks HOT 3
- Undo always crashes the Unity HOT 1
- LatticeDeformer behaves differently in edit mode compared to play mode
- Error `Object reference not set to an instance of an object` on Editor stop HOT 2
- Editor bug in 2021.3.4 / Deform 1.2.1: Cannot add menu item HOT 8
- Unwanted dependencies HOT 2
- How to modify deformer's params in script? HOT 1
- CurveDisplaceDeformer exception
- Object with a lattice deformable are incorrectly translated in the world HOT 11
- Moving the lattice to the root of the scene causes exceptions HOT 2
- Applying a lattice deformer causes lattice point to be beside the mesh to deform.
- After removing from project, my physics are different? HOT 1
- Update the MeshCollider HOT 1
- How to do a mirror
- Access Lattice Points via Script HOT 3
- About LatticeDeformer.controlPoints HOT 1
- The following error occurs when importing in Unity 2022.3 : Unable to import newly created asset HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deform.