Jump to content

Holes in the ground


Dad72
 Share

Recommended Posts

GSG or poly2tri

 

with the first one, you create fist a mesh, then you remove parts with another mesh

with the second one, you create a 2D complex polygon, which can have holes, then it creates the relative plane (with holes)

Link to comment
Share on other sites

The pick() function of a scene gives you the id of the face picked. You are then able to use this to remove the three corresponding indices in the indice array of the meshes. This way you effectively remove the picked face (but not its vertices).

 

Example here (based on the decals PG): http://www.babylonjs-playground.com/#1BAPRM#19

 

Is that what you're looking for?

Link to comment
Share on other sites

That's a bit more complex. I think I would check all vertices close to the picked point, and remove those that are under a certain distance (= hole radius). For each vertex removed, I would have to delete the associated faces in the indices array.

 

Not sure if that would work, I'll try to do it in the PG...

Link to comment
Share on other sites

I managed to get it working: http://www.babylonjs-playground.com/#8OMYN#4

 

But:

1/ I do not remove the vertices, only the faces. So after a while the mes might need to be cleaned (ie remove vertices that are not used)

2/ There should be some possible optimization by looking only into submeshes vertices, instead of all the vertices of the mesh (since pickInfo gives you a submeshID)

 

Good luck :)

Link to comment
Share on other sites

Hi,

 

Still thank you for helping me Jahow for this function. I would go the other way to close the holes. is it possible ?
 
I have this function to create the holes. I would like to create a function: addFaces () that recreate the missing faces.

        var removeFaces = function (pickInfo, radius)	{				var mesh = pickInfo.pickedMesh,			faceID = pickInfo.faceId,			indices_array = mesh.getIndices(),			positions_array = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind),			vertices_toremove = [],			pickpoint = pickInfo.pickedPoint,			current_v = new BABYLON.Vector3.Zero(),			worldmatrix = mesh.getWorldMatrix(),			index,			safety = 1000;					for(var i=0; i<positions_array.length/3; i++)		{			current_v.x = positions_array[i*3];			current_v.y = positions_array[i*3+1];			current_v.z = positions_array[i*3+2];			current_v = BABYLON.Vector3.TransformCoordinates(current_v, worldmatrix);								if(BABYLON.Vector3.Distance(pickpoint, current_v) < radius) 			{				vertices_toremove.push(i);			}		}					for(var i = 0; i < vertices_toremove.length; i++)		{			index = indices_array.indexOf(vertices_toremove[i]);			while(index != -1)			{				indices_array.splice(index - index%3, 3);				break;			}		}					mesh.setIndices(indices_array);    };    var addFaces = function (pickInfo, radius)    {	????    };

 
Thank you for the help.

Link to comment
Share on other sites

Hey dad72, sorry for not responding earlier.

 

Adding the faces back is not trivial, unless we save the indices of the faces we've removed earlier. In this case it's just a matter of putting back those faces in the mesh. But it may not be suitable for every use, since the "removed faces" info can become quite big if you remove a lot of stuff, and must be saved with the mesh otherwise it won't be possible to add its faces back.

 

Herre is an example: http://www.babylonjs-playground.com/#8OMYN#5

The first time you click, faces will be removed. If you click back somewhere on the mesh, the faces around the click will be restored. It still has one problem: since we removed the faces from the mesh, nothing happens if we click in the hole...

 

Here are a few suggestions for you:

- Maybe setting vertices alpha (transparency) to zero would be easier than remove them, because we wouldn't have to actually modify the mesh and clicks in 'holes' would still be detected ; the big drawback is that the mesh would then be classified as "transparent", which may pose other problems

- If you plan to use this exclusively for a heightmap, a simpler & more efficient method can probably be found because all your vertices and faces are on a grid and it is easier to know what to remove/add

- Another method: for each mesh than can have hole in it, create an "inverse mesh" which will hold all the vertices & faces that have been removed from the main mesh. This mesh can be invisible but will still detects when we click on it.

Link to comment
Share on other sites

I like the latter. Thank you Jahow, but the question I ask myself is: Is that if I hide the faces, a character can pass through the holes. The collision is still activate in the holes or no? I wish that a character can pass through this mesh where the holes are.

 

Thank you again Jahow.

Link to comment
Share on other sites

I just think of a solution. From the editor last solution to hide the faces and record them in a .dat. And when one is in game I take all the faces hidden this .dat file and I delete as your first solution. I think it will work like this.

 

I think this time everything is ok.

 

Big thanks Jahow

Link to comment
Share on other sites

Arf, my solution does not work in case the user want to close the hole in the future. it is necessary that I remove the collision on the faces hidden only.

 
So I think Deltakosh is able to answer that :
Can we disable collisions on some faces of a mesh. If so, how? Thank you very much
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...