1

enter image description here

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

enter image description here

Desired effect

enter image description here

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 enter image description here

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

zeronofreya
  • 359
  • 1
  • 8
  • Do you mean the occluded vert, (ie the one that appears to be nearest the origin in image above)? If we consider faces here, would say it is the vert joined to all back faces. ie faces whose normals face primarily away from view. – batFINGER Sep 09 '21 at 03:48
  • Could add the face indices calc all the normals, however would do same as here https://blender.stackexchange.com/questions/230545/rounded-corners-for-2d-rectangle and use the mesh API provides. – batFINGER Sep 09 '21 at 03:56
  • @batFINGER Thanks for the reply, I added the description – zeronofreya Sep 09 '21 at 04:57
  • Hmmm akin to a freestyle render on screen. GPU is not really my thing so spit-balling here: could project from view https://blender.stackexchange.com/a/160388/15543 (via cam, use view instead) then texture faces with a gpu buffer image of the bg. Or work out some routine to process the flattened mesh finding crossing points. – batFINGER Sep 09 '21 at 05:45

0 Answers0