I know that meshes can be combined, thanks to the ComebineMesh feature, but I was wondering the if the opposite is possible… Can you, when two meshes collide, or when a collider intercepts a mesh, take that chunk out of the mesh.
It’s an essential part of an idea that I need for a game I’m making, but I fear that Unity lacks the technique for doing so.
Ok, that’s actually very helpful, and interesting… Do you have any idea to do something as intricate and accurate as creating such a deformation in a wall by using collision?
Here is the whole concept of my idea… with pictures… and even my idea of how to work with the mesh…
We have a wall and a bomb… well bombs explode…
see… it exploded… and it even ‘overlapped’ the wall…
Oh my gosh… that overlapping chunk of the wall is gone…
Here’s my idea of how to solve it…
Here’s what I have so far, code-wise…
function OnTriggerEnter (other : Collider) {
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var vertices = mesh.vertices;
var normals = mesh.normals;
var triangles = mesh.triangles;
var otherMesh : Mesh = other.gameObject.GetComponent(MeshFilter).mesh;
var otherVertices = otherMesh.vertices;
var otherNormals = otherMesh.normals;
var otherTriangles = otherMesh.triangles;
if (tag == "Destroyable") {
var allVertices = vertices + otherVertices;
var allNormals = normals + otherNormals;
var allTriangles = triangles + otherTriangles;
}
I’m just wondering the best way to do this… I’ve tried using Clear () on the verts/normals/triangles, but there’s an array problem there, which isnt compatible… I’m not even sure if the vertices get added in the same spot as it entered…
This is a CSG (constructive solid geometry) problem, and in general at least, such problems usually aren’t trivial to solve.
Unfortunately I don’t really have any suggestions other than to Google ‘csg’ and start researching. (I know there are some CSG libraries available, but I don’t know if/how they could be integrated into Unity, nor whether they’d be suited for a real-time application.)
Maybe others will be able to offer some better suggestions.
[Edit: Just looked at your code more carefully, and I’ll go ahead and tell you that solving any CSG problem is unlikely to reduce to simply combining vertex and index arrays. Unfortunately, it’s much more complicated than that.]
Hmm… Well ok… I’m glad to get some sort of thing to reference… CSG… I’ll go look that up…
Oh… that’s exactly what I mean… I know that it can be done with something like 3ds Max, but that would just create a mesh of it, and it wouldn’t really be dynamic and accurate like I want it… But how to get a CSG into Unity is the thing…
I have written some CSG code and its not trivial. What I would do is cheese it. First, make the wall with many more vertices than necessary. Then define a “blast radius” and when the ball hits the wall, move all vertices in the blast radius to the edge of the blast radius.