Fix T92120 (partially): No bone custom shape with curve object meshes

This part of the drawing code assumes that the bone custom object
has only one evaluated geometry component, and it also uses the
object type to check which data to draw, with the functions like
`DRW_cache_object_surface_get` that just take an object input.
Those functions usually work on evaluated objects, which use the
instancing system to access a temporary object with `object.data`
replaced for data types that don't match the original object.

That assumption used to work, but now curve, point cloud, or volume
objects can have an evaluated mesh which is not accessed with the
same object for render engine drawing.

The "correct" solution for the way this code is structured would be to
loop through all of the geometry components and try to get GPU batches
from every one of them. However, that significantly increases complexity
in an area that should probably be refactored anyway. This patch treats
the mesh as a special case, and only draws the evaluated mesh.

The **best** solution in my opinion might be refactoring this area to
use the instancing system with some sort of viewport-only flag so
the custom shape instances aren't added in the render.

The solution is "partial" because the "Wireframe" option only works
for meshes from mesh objects, even after this fix, and because other
data besides meshes is not displayed at all.

Differential Revision: https://developer.blender.org/D13038
This commit is contained in:
Hans Goudey 2021-11-24 10:39:33 -05:00
parent 56b068a664
commit a07089dcb1
Notes: blender-bot 2023-02-13 17:27:38 +01:00
Referenced by issue #93525, 3.0.0 crash at startup loading armature custom bone curve
Referenced by issue #93439, Armature widgets from hidden collections are invisible.
Referenced by issue #92120, Bone custom curve shape makes it invisible
1 changed files with 17 additions and 4 deletions

View File

@ -26,6 +26,7 @@
#include "DNA_armature_types.h"
#include "DNA_constraint_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_view3d_types.h"
@ -39,6 +40,7 @@
#include "BKE_armature.h"
#include "BKE_deform.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
#include "DEG_depsgraph_query.h"
@ -52,6 +54,8 @@
#include "overlay_private.h"
#include "draw_cache_impl.h"
#define BONE_VAR(eBone, pchan, var) ((eBone) ? (eBone->var) : (pchan->var))
#define BONE_FLAG(eBone, pchan) ((eBone) ? (eBone->flag) : (pchan->bone->flag))
@ -535,13 +539,22 @@ static void drw_shgroup_bone_custom_solid(ArmatureDrawContext *ctx,
const float outline_color[4],
Object *custom)
{
/* The custom object is not an evaluated object, so its object->data field hasn't been replaced
* by #data_eval. This is bad since it gives preference to an object's evaluated mesh over any
* other data type, but supporting all evaluated geometry components would require a much larger
* refactor of this area. */
Mesh *mesh = BKE_object_get_evaluated_mesh(custom);
if (mesh == NULL) {
return;
}
/* TODO(fclem): arg... less than ideal but we never iter on this object
* to assure batch cache is valid. */
drw_batch_cache_validate(custom);
DRW_mesh_batch_cache_validate(mesh);
struct GPUBatch *surf = DRW_cache_object_surface_get(custom);
struct GPUBatch *edges = DRW_cache_object_edge_detection_get(custom, NULL);
struct GPUBatch *ledges = DRW_cache_object_loose_edges_get(custom);
struct GPUBatch *surf = DRW_mesh_batch_cache_get_surface(mesh);
struct GPUBatch *edges = DRW_mesh_batch_cache_get_edge_detection(mesh, NULL);
struct GPUBatch *ledges = DRW_mesh_batch_cache_get_loose_edges(mesh);
BoneInstanceData inst_data;
DRWCallBuffer *buf;