Is there a python code to find and delete back-faces? As a way to do "back-face culling".
If you know a little bit of python you can modify and expand upon this snippet:
from: http://freespace.virgin.net/hugo.elias/routines/r_dot.htm When deciding if a polygon is facing the camera, you need only calculate the dot product of the normal vector of that polygon, with a vector from the camera to one of the polygon's vertices.
- If the dot product is less than zero, the polygon is facing the camera.
- If the value is greater than zero, it is facing away from the camera.
this could be further optimized, but I think that obfuscates the concepts. Run this code from 3dview (a 3d view context) either through a camera or user/perspective view - with the object you want to work on selected and in
from mathutils import Vector def get_locals(context): region = context.region rv3d = context.space_data.region_3d obj = context.active_object vertlist = obj.data.vertices return region, rv3d, obj, vertlist
def select_front_facing(context): region, rv3d, obj, vertlist = get_locals(context) # neat eye location code with the help of paleajed eye = Vector(rv3d.view_matrix[:3]) eye.length = rv3d.view_distance eye_location = rv3d.view_location + eye for idx, polygon in enumerate(obj.data.polygons): vert_index = polygon.vertices pnormal = obj.matrix_world * polygon.normal world_coordinate = obj.matrix_world * vertlist[vert_index].co result_vector = eye_location - world_coordinate dot_value = pnormal.dot(result_vector.normalized()) if dot_value < 0.0: polygon.select = False else: polygon.select = True
Here is a short working demo, you can run this from text editor: https://gist.github.com/zeffii/5766177
I use it in my basic SVG renderer, to fake a wireframe material which occludes back-facing, it isn't perfect for all possible use-cases but it works to 'select back-facing'. You can run the SVG renderer directly from the Text Editor, and it will set every front facing Polygon to the
select == True state.
Have you looked at this Blender Artists thread? (Post #9) They changed the object's material to a node material. In the nodes, they mapped the back faces of the object to alpha zero using a geometry node.
Summary: you can make the back faces transparent to simulate back-face culling. I'm not sure how much faster it will be, but it will be nicer than deleting portions of your geometry.
And then, for the adventurous amongst you, I made a patch for Blender source code that allows getting occlusion information for BMesh elements.
state = bmelem.occlusion_get(rv3d)
rv3d being a RegionView3D
Get the patch here.