Removing faces from a cube

Software: Away3D 4.x

dj_ouf, Newbie
Posted: 20 February 2014 06:43 PM   Total Posts: 9

Hi

How can I remove some faces from a cube mesh created ?
I searched, and I found I have to use :
FaceHelper.removeFace(mesh, index, subGeomIndice)

But I don’t get it, how can I know what index is the face in my geometry ? And what about this parameter subGeomIndice ?

And finally, is FaceHelper the best solution for my goal ?

Thanks

   

Avatar
Fabrice Closier, Administrator
Posted: 20 February 2014 08:41 PM   Total Posts: 1265   [ # 1 ]

If you do not know the indice how do you expect to tell the engine which face to delete? Looking at your model and say “delete the ugly face that I’m looking at right now” will certainly not work :D

That you use the helper or your own code, you still have the same problem:
when you add a face, its composed of 3 indices, each one good for 3 coordinates x,y,z and 2 uvs. I will not even take in account normals, tangents etc.. this data, is stored in buffers, at least 2. in compactgeometry case, you have an indices buffer and a data buffer holding all your data or the “classic” geometry holding one buffer per type of data. The classic is more friendly for vertex manipulation. Both geometries have subgeometries. It is basically an extra same class holding more information over the mesh than couldn’t fit in the first subgeometry, or because you use another material. Because of gpu requirements and the way stage3D works, the data has to be ordered this way…

If you do work on a mesh with a single material, aprox 20k or lower faces, you will probably work only into subgeometry 0 (the first one)

So you actually say with the helper.removeFace method: remove in my mesh, in the first subgeometry, the xx face. Keep in mind that if you do keep track of your faces, that you need to update your indices after each time you do alter the mesh. Because indices are reindexed after each update. If you are familair with as3 in general, its like removing a child at a certain indice. The numChildren is updated each time, and you have to take care that your child indice is actually the one you want.

‘is FaceHelper the best solution for my goal’
In case you go for own code, there are also some nice neurone killers that you need take in account, like shared indices, empty buffers, too big buffers, normal update (if you work a with a cube, you do not want it renders weirdly if lighted, which is one of the reason why the cube primitive has more data in there than one would expect) and many other fun cases!

Looking at some of the helper’s methods and in some other classes generating geometries, you should get a better idea about the way data that is organized in order to manipulate it.
You will be able to delete and get the mesh with one face less only and only if you update everything propperly, otherwize Away will either throw a nice error at you or simply refuse to render anything!


   

dj_ouf, Newbie
Posted: 22 February 2014 12:55 AM   Total Posts: 9   [ # 2 ]

Thanks you Fabrice for your explanations.

I realise now that was a little bit stupid question, as I didn’t thought about all the complex structure and dependencies for the data behind the friendly API !

I use to pratice a little bit modeling, and I thought it would be the same, removing or adding a face in a software like maya is trivial.

By the way, as you spoke about subgeometry, can you tell me why sometimes I can add the material directly on the mesh, and others on the indice 0 of the subgeomtry ? I guess it’s depending on how the 3D mesh add been made ?

For my case, I think I’ll create my mesh by creating the faces manually, as I just require a cube without 2 faces.

ps : by the way, are you french ?

   

Avatar
Fabrice Closier, Administrator
Posted: 22 February 2014 06:43 PM   Total Posts: 1265   [ # 3 ]

When you select/delete a face in maya or any other editor, more or less the same happends as when you would do it in Away. So many of these features are taken for granted, but when the time comes to write your own… well now you know its not that easy wink

That’s because a material set on a subGeometry has priority. It often occurs on models exported as Collada. In Prefab or AwayBuilder, you would have to either remove the materials on the submeshes and keep the mesh material or assign a material per submesh and no mesh material.

yes, you can use 12 faces, keep in mind that if lighted, you will have to set the vertexNormals for the 3 vertices equivalent to the face normal and that you will not be able to share indices (only v0/v2 of face 1 per side and v1/v2), and not share with other sides. if you do not do this or let the engine calculate the normals, you will see “rounded” edges on your geometry once lighted.

If you store the faces from 0 to 11 while building it, you can easylly keep track of 1 or more removed faces and you have the face index for free if you do use the helper or code similar logic. The index on your side is simply the pointer as the index/3 into indices buffer. The correspondant x is the first index value in indices x 3, adding +1, gives you y and + 1 the z. Multiplying by two this index, you get the uv’s. Repeat same routine for the two remaining points of your face.
In case you use compactSubgeometry, you have to do the same except you have an offset to add (the component offset) and the stride, the value required during aloop to find the next occurance of the same typed value.

Note that if you would want to edit using the mouse, the mouseEvent3D set on your mesh would return you an index as well. This way you would not have to keep track of the faces, yet you still would need to reorganize the buffers.

ps: oui, amuses toi bien smile

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X