Fix #35362: using dyntopo gives wrong render results
Made it so dynamic topology will flush changes from SculptSession->bm to Object->me. Used the same approach as sculptsession_bm_to_me does, but instead of using DAG_id_tag_update used in-place DerivedMesh release. Otherwise this lead to some update issues resulting in missed object after render. Also fixed multires modifier not being applied for render when rendering from dyntopo sculpt mode. P.S. Apparently sculpsession_bm_to_me was declared in BKE_paint.h but implemented in object.c. Rather confusing and better make it so this functions are declared and implemented in consistent files. But will solve this in a separate commit.
This commit is contained in:
@@ -172,5 +172,6 @@ typedef struct SculptSession {
|
||||
void free_sculptsession(struct Object *ob);
|
||||
void free_sculptsession_deformMats(struct SculptSession *ss);
|
||||
void sculptsession_bm_to_me(struct Object *ob, int reorder);
|
||||
void sculptsession_bm_to_me_for_render(struct Object *object);
|
||||
|
||||
#endif
|
||||
|
@@ -1527,7 +1527,7 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
|
||||
{
|
||||
int unsupported = 0;
|
||||
|
||||
if (sculpt_dyntopo)
|
||||
if (sculpt_dyntopo && !useRenderParams)
|
||||
unsupported = TRUE;
|
||||
|
||||
if (scene->toolsettings->sculpt->flags & SCULPT_ONLY_DEFORM)
|
||||
|
@@ -272,30 +272,65 @@ void free_sculptsession_deformMats(SculptSession *ss)
|
||||
}
|
||||
|
||||
/* Write out the sculpt dynamic-topology BMesh to the Mesh */
|
||||
void sculptsession_bm_to_me(struct Object *ob, int reorder)
|
||||
static void sculptsession_bm_to_me_update_data_only(Object *ob, bool reorder)
|
||||
{
|
||||
SculptSession *ss = ob->sculpt;
|
||||
|
||||
if (ss->bm) {
|
||||
if (ob->data) {
|
||||
BMIter iter;
|
||||
BMFace *efa;
|
||||
BM_ITER_MESH (efa, &iter, ss->bm, BM_FACES_OF_MESH) {
|
||||
BM_elem_flag_set(efa, BM_ELEM_SMOOTH,
|
||||
ss->bm_smooth_shading);
|
||||
}
|
||||
if (reorder)
|
||||
BM_log_mesh_elems_reorder(ss->bm, ss->bm_log);
|
||||
BM_mesh_bm_to_me(ss->bm, ob->data, FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sculptsession_bm_to_me(Object *ob, int reorder)
|
||||
{
|
||||
if (ob && ob->sculpt) {
|
||||
SculptSession *ss = ob->sculpt;
|
||||
|
||||
if (ss->bm) {
|
||||
if (ob->data) {
|
||||
BMIter iter;
|
||||
BMFace *efa;
|
||||
BM_ITER_MESH (efa, &iter, ss->bm, BM_FACES_OF_MESH) {
|
||||
BM_elem_flag_set(efa, BM_ELEM_SMOOTH,
|
||||
ss->bm_smooth_shading);
|
||||
}
|
||||
if (reorder)
|
||||
BM_log_mesh_elems_reorder(ss->bm, ss->bm_log);
|
||||
BM_mesh_bm_to_me(ss->bm, ob->data, FALSE);
|
||||
}
|
||||
}
|
||||
sculptsession_bm_to_me_update_data_only(ob, reorder);
|
||||
|
||||
/* ensure the objects DerivedMesh mesh doesn't hold onto arrays now realloc'd in the mesh [#34473] */
|
||||
DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
void sculptsession_bm_to_me_for_render(Object *object)
|
||||
{
|
||||
if (object && object->sculpt) {
|
||||
if (object->sculpt->bm) {
|
||||
/* Ensure no points to old arrays are stored in DM
|
||||
*
|
||||
* Apparently, we could not use DAG_id_tag_update
|
||||
* here because this will lead to the while object
|
||||
* surface to disappear, so we'll release DM in place.
|
||||
*/
|
||||
if (object->derivedFinal) {
|
||||
object->derivedFinal->needsFree = 1;
|
||||
object->derivedFinal->release(object->derivedFinal);
|
||||
object->derivedFinal = NULL;
|
||||
}
|
||||
if (object->sculpt->pbvh) {
|
||||
BKE_pbvh_free(object->sculpt->pbvh);
|
||||
object->sculpt->pbvh = NULL;
|
||||
}
|
||||
|
||||
sculptsession_bm_to_me_update_data_only(object, false);
|
||||
|
||||
/* In contrast with sculptsession_bm_to_me no need in
|
||||
* DAG tag update here - derived mesh was freed and
|
||||
* old pointers are nowhere stored.
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void free_sculptsession(Object *ob)
|
||||
{
|
||||
if (ob && ob->sculpt) {
|
||||
|
@@ -40,6 +40,7 @@
|
||||
|
||||
#include "BLF_translation.h"
|
||||
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
#include "DNA_userdef_types.h"
|
||||
@@ -53,6 +54,7 @@
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_node.h"
|
||||
#include "BKE_multires.h"
|
||||
#include "BKE_paint.h"
|
||||
#include "BKE_report.h"
|
||||
#include "BKE_sequencer.h"
|
||||
#include "BKE_screen.h"
|
||||
@@ -539,6 +541,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
|
||||
const short is_write_still = RNA_boolean_get(op->ptr, "write_still");
|
||||
struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL;
|
||||
const char *name;
|
||||
Object *active_object = CTX_data_active_object(C);
|
||||
|
||||
/* only one render job at a time */
|
||||
if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_RENDER))
|
||||
@@ -572,7 +575,10 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
|
||||
WM_cursor_wait(1);
|
||||
|
||||
/* flush multires changes (for sculpt) */
|
||||
multires_force_render_update(CTX_data_active_object(C));
|
||||
multires_force_render_update(active_object);
|
||||
|
||||
/* flush changes from dynamic topology sculpt */
|
||||
sculptsession_bm_to_me_for_render(active_object);
|
||||
|
||||
/* cleanup sequencer caches before starting user triggered render.
|
||||
* otherwise, invalidated cache entries can make their way into
|
||||
|
Reference in New Issue
Block a user