Page MenuHome

Fix lightprobe creation from python data API
ClosedPublic

Authored by swann (slumber) on Dec 11 2019, 3:48 PM.

Details

Summary

Description of the problem

Until now, it is only possible to correctly add a lightprobe in python via an operator:
bpy.ops.object.lightprobe_add()

Description of the proposed solution

The idea of this patch is to fix the lack of consistency lightprobe creation without operator.
It allow creation of different lightprobe type directly via bpy.data.lightprobes.new(name, type) (such as for curves).

In order to make it possible I had to:

  1. Add a function BKE_lightprobe_configure in charge of lightprobe settings configuration (avoid code redundancy)
  2. Allow an object to take lightprobe datablock as data during is initialization.

A short example of this patch usage

lp = bpy.data.lightprobes.new('some_name','PLANAR')

bpy.data.objects.new('toto', lp)

Diff Detail

Repository
rB Blender

Event Timeline

swann (slumber) retitled this revision from Unify lightprobe creation for python API to Unify lightprobe creation from python API.Dec 12 2019, 5:59 PM
swann (slumber) edited the summary of this revision. (Show Details)
swann (slumber) retitled this revision from Unify lightprobe creation from python API to Fix lightprobe creation from python data API.Dec 13 2019, 11:05 AM
swann (slumber) edited the summary of this revision. (Show Details)
Clément Foucault (fclem) requested changes to this revision.Thu, Jan 16, 7:57 PM

I'm fine with the exposed feature. If you fix the assert I'll accept the patch.

source/blender/editors/object/object_add.c
608

The assert BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(probe, id)); is triggered here if you create lightprobe using the add menu (normal workflow).

This revision now requires changes to proceed.Thu, Jan 16, 7:57 PM

Thanks for the review @Clément Foucault (fclem) !
I took care of the BLI_assert by detaching lightprobe configuration from lightprobe init.

swann (slumber) edited the summary of this revision. (Show Details)Fri, Jan 17, 2:03 PM

Ok now it does not crash but adding a Cubemap Lightprobe the normal way (through add menu) is setting the default parameters of a grid probe. Making it way small.

Sorry for the error,
I removed type from BKE_lightprobe_add parameters and added BKE_lightprobe_configure in rna_Main_lightprobe_new.
By doing this way it avoid wrong default parameters inheritance.

This revision is now accepted and ready to land.Fri, Jan 17, 6:24 PM