Page MenuHome

Material slot reorder https://developer.blender.org/T43235 (WIP)
ClosedPublic

Authored by Gaia Clary (gaiaclary) on Apr 27 2015, 12:54 AM.

Details

Summary

This Diff implements the Material Slot reorder.
This Diff is a WIP and it probably needs a lot of rework, however i'd like to get some feedback
before i continue on it.

Note: I started with Severin's initial patch P193
There i added support for Materials assigned to Objects and materials assigned to Data
Then finally i added the material assignment swapping for Mesh, Nurbs and Fonts.

I tested the Diff for Mesh objects and there it seems to work nicely.
So for Mesh objects now changing the material order will preserve the material assignments.

Any feedback appreciated.
thanks

Diff Detail

Repository
rB Blender
Branch
master

Event Timeline

Gaia Clary (gaiaclary) retitled this revision from to Material slot reorder https://developer.blender.org/T43235 (WIP).
Gaia Clary (gaiaclary) updated this object.

I need advise for making this better (easier).

I forgot to mention one important property of the current implementation:

The material assignment swapping only takes place in edit mode.
So when you want to keep the materials-Face assignment intact, then you have to reorder the materials in Edit mode.
When you reorder the materials in Object mode, then the reordering effectively changes the assignment of material to faces.
I am unsure if this is a welcome feature or if this is a confusing feature.

Please let me know if this behavior is useful and appreciated.

Campbell Barton (campbellbarton) requested changes to this revision.Apr 27 2015, 12:16 PM
Campbell Barton (campbellbarton) added inline comments.
source/blender/editors/render/render_shading.c
437–440

NULL checks here seem a bit redundant caller can check if state is sane.

447–480

Think this could be made into a generic API function & moved to material.c

BKE_material_id_remap() or BKE_material_id_permutate()

It can take an array of shorts and just do bounds check, then, efa->mat_nr = remap[efa->mat_nr];

This means we can more easily sort materials/reverse... etc.


However implementing this, we would also want to have a similar function for object mode, handling ob->matbits, this complicates a little more, but think its still worth doing.

Once this is done, most of this logic should be in BKE, and the operators can just create & free the remap arrays.

This revision now requires changes to proceed.Apr 27 2015, 12:16 PM
Gaia Clary (gaiaclary) edited edge metadata.

Reworked the Patch according to Ideasman's feedback.

Gaia Clary (gaiaclary) edited edge metadata.

Added support for material reorder in Object mode.

simplified material reorder by using generic function BLI_array_permute()

Removed obsolete function

added null pointer checks (not sure if that is realy necessary)

Campbell Barton (campbellbarton) requested changes to this revision.Apr 27 2015, 9:05 PM
Campbell Barton (campbellbarton) edited edge metadata.
Campbell Barton (campbellbarton) added inline comments.
source/blender/blenkernel/intern/material.c
938

think it would be better to get the array from give_matarar, then this can be done at the start along with matbits.

940–974

all of these mat_nr accesses need bounds checks, its possible they are larger then the array.

source/blender/editors/render/render_shading.c
397

dont need to calloc if its filled right after

This revision now requires changes to proceed.Apr 27 2015, 9:05 PM
source/blender/blenkernel/intern/material.c
957–973

material arrays are ignored here, using give_matarar at the beginning will resolve.

source/blender/blenkernel/intern/material.c
1022–1025

checking selection is incorrect here, it should remap all.

Gaia Clary (gaiaclary) edited edge metadata.

Added range checks,
use give_matarrar() instead of direct call for Mesh->mat
fixed selection for EditFont

Gaia Clary (gaiaclary) edited edge metadata.

Fixed boundary checks,
added comments for missing parts.

This revision was automatically updated to reflect the committed changes.

Here is the blend file that i used to test the diff:

source/blender/blenkernel/intern/material.c
1022

@ideasman42: I am not entirely sure about this part. Maybe its wrong to use BKE_vfont_select_get() in this context?