Pure gpu drawing, no entity
Is there a way to hide the occluded face?
import bpy
import gpu
from gpu_extras.batch import batch_for_shader
coords = (
(-1, -1, -1), (+1, -1, -1),
(-1, +1, -1), (+1, +1, -1),
(-1, -1, +1), (+1, -1, +1),
(-1, +1, +1), (+1, +1, +1))
indices = (
(0, 1), (0, 2), (1, 3), (2, 3),
(4, 5), (4, 6), (5, 7), (6, 7),
(0, 4), (1, 5), (2, 6), (3, 7))
shader = gpu.shader.from_builtin('3D_UNIFORM_COLOR')
batch = batch_for_shader(shader, 'LINES', {"pos": coords}, indices=indices)
def draw():
shader.bind()
shader.uniform_float("color", (1, 0, 0, 1))
batch.draw(shader)
bpy.types.SpaceView3D.draw_handler_add(draw, (), 'WINDOW', 'POST_VIEW')
The above is a simple example,let me add it with a model
Current display
Desired effect
Certain effects can be achieved through the calculation of normals
def get_front_faces(_bm, _rgn, _rv3d, _matrix):
if not _rv3d:
raise Exception('get_front_idx: rv3d error')
if not _rgn:
raise Exception('get_front_idx: rgn error')
eye = Vector(_rv3d.view_matrix[2][:3])
eye.length = _rv3d.view_distance
eye_location = _rv3d.view_location + eye
faces = []
rv = None
is_perspective = _rv3d.is_perspective
if not is_perspective:
co = location_3d_to_region_2d(_rgn, _rv3d, eye_location)
rv = region_2d_to_vector_3d(_rgn, _rv3d, co) * -1
rv.normalize()
for bmf in [bmf for bmf in _bm.faces if bmf.is_valid]:
if is_perspective:
center = _matrix @ bmf.calc_center_median()
rv = eye_location - center
rv.normalize()
dot_value = bmf.normal.dot(rv)
if dot_value < 0:
continue
else:
faces.append(bmf)
return faces
But it won’t work for complex faces

As you can see, the inner surface should be occluded, I don’t want to show it


