- Home /
Culling faces from models in the unity editor viewport?
I'm playing around making a Minecraft like game. But instead of generating buildings and levels from code I'm modeling them with a pretty decent workflow I have going. But I am in need of removing/deleting faces that are unviewable in the viewport editor. I've never tried to make a unity editor extension, can someone give me some info on how I could remove certain faces from a model in the editor NOT when the game plays. How do you find a particular face on a model and delete it? My main concern is that they are already 3d models .fbx to be exact. I've never seen any info on culling already made models in unity, only when they are generated procedurally.
I know it can be done though because of tools like probuilder etc.. But I think even those are procedural. Info and tutorials would be appreciated.
Answer by MakeCodeNow · May 22, 2014 at 03:30 PM
If you want to cull individual faces, you'll need to create a new Mesh resource, copy the data from the fbx mesh into it, and then remove all of the backfacing or occluded faces. You'd need to do this every frame that the camera moves.
If you want to cull individual renderer's, that's easier. You just need to determine what is occluded (which it sounds like you have a way to do?) and then set the active flag to false.
If you're not sure how to have a script run in the editor, then add the ExecuteInEditor class attribute. You may also need to manually hook your Update function into EditorApplication.Update.
By mesh resource do you mean having the FBX's in the resource folder? Can you link some info on copying the data from the FBX mesh? Would I have to re-uv the mesh from script or can that be copied over too?
Do you mean load the fbx through script like this? http://answers.unity3d.com/questions/193008/loading-imported-fbx-data-from-script.html this actually makes sense to me.
If you want to cull individual faces, you'll need to create a new $$anonymous$$esh resource, copy the data from the fbx mesh into it, and then remove all of the backfacing or occluded faces. You'd need to do this every frame that the camera moves.
Yeah that's what I want to do. Any tutorials on this or anything? I managed to copy the fbx verts and uvs into a array. I don't really know how delete a specific face, If i just delete the verts of that face will it delete that face automatically or do I need a specific face deletion function?
$$anonymous$$y logic of deleting a face I am still co$$anonymous$$g up with Will be like a raycast in each direction of the faces to check 1 meter if there is another block in front of it, then to delete that face, But yeah I don't understand how to know how to delete a specific face yet. I need some info on that.
Also I was getting a editor error that I $$anonymous$$UST use .sharedmesh ins$$anonymous$$d of .mesh. In doing this I might have messed up the original FBX how can I know if I messed it up or not? I read after using it that it overwrites the model file.
Thanks in advance for your time.
Deleting a cube face means removing the two triangles that represent it from the list of triangles for the entire mesh. You can also delete the verts that those faces use, but that's not strictly necessary.
In your case, you probably want to make a copy of the mesh, i.e. new $$anonymous$$esh() and then set the new mesh verts/uvs/normals to be copies of those from the source mesh, then modify the copy.
1 cube should be 12 tris.
I think that you're at a point now where you know what has to be done and now you need to buckle down and bang on the code for a while. You'll learn fastest that way rather than asking for more and more fine grained advice.
Your answer
Follow this Question
Related Questions
"W" key not working in Unity3D Mac OS X 5 Answers
Select parent object when LOD object is clicked 0 Answers
Cullingmask issue. 0 Answers
How can I zoom the game mode viewport to its native scale? 1 Answer
LOD system with Partial object culling? 2 Answers