Code Quality: Renaming on BKE_material.h #73589
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#73589
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Rename BKE functions to include
BKE_material_
prefix.Proposed changes:
("init_def_material", "BKE_materials_init"),
("BKE_material_gpencil_default_free", "BKE_materials_exit"),
("test_object_materials", "BKE_object_materials_test"),
("test_all_objects_materials", "BKE_objects_materials_test_all"),
("give_matarar", "BKE_object_material_array"),
("give_totcolp", "BKE_object_material_num"),
("give_current_material_p", "BKE_object_material_get_p"),
("give_current_material", "BKE_object_material_get"),
("assign_material", "BKE_object_material_assign"),
("assign_matarar", "BKE_object_material_array_assign"),
("give_matarar_id", "BKE_id_material_array"),
("give_totcolp_id", "BKE_id_material_num"),
("assign_material_id", "BKE_id_material_assign"),
("clear_matcopybuf", "BKE_material_copybuf_clear"),
("free_matcopybuf", "BKE_material_copybuf_free"),
("copy_matcopybuf", "BKE_material_copybuf_copy"),
("paste_matcopybuf", "BKE_material_copybuf_paste"),
("BKE_material_init_gpencil_settings", "BKE_gpencil_material_attr_init"),
("BKE_material_add_gpencil", "BKE_gpencil_material_add"),
("BKE_material_gpencil_get", "BKE_gpencil_material"),
("BKE_material_gpencil_default_get", "BKE_gpencil_material_dft"),
("BKE_material_gpencil_settings_get", "BKE_gpencil_material_attr"),
Changed status from 'Needs Triage' to: 'Confirmed'
Added subscribers: @antoniov, @dfelinto
Added subscriber: @brecht
@dfelinto @brecht before doing any renaming, I would like to have some feedback.
Added subscriber: @ideasman42
@ideasman42 I would like to hear your opinions too.
This is a good but we can do much more here, for example:
init_def_material
->BKE_materials_init
, similar to how we init other modules.BKE_material_node_get
: this should actually be removed, only made sense with old Blender material nodes.give_matarar
->BKE_material_array_from_object
give_matarar_id
->BKE_material_array_from_ID
give_totcolp
->BKE_material_num_from_object
(return value instead of pointer, and refactor code as needed)give_totcolp_id
->BKE_material_num_from_ID
give_current_material
->BKE_material_array_get
@brecht I have seen these in
anim_filter.c
:for (a = 1; a <= ob->totcol; a++) {
Material *base = give_current_material(ob, a);
Material *ma = give_node_material(base);```
Yes, that code can be removed, nested materials do not exist anymore.
Renaming patch in D6751
Prefer if batch renaming is handled with a script to more easily apply changes & update names eg: P1241
Some open topics:
Should we use the term 'active' instead of current?
This is more common in Blender, even variable names in C/RNA call this active.
For API calls it's often not clear if this operates on a material, and ID or an object, with the addition of grease pencil we could accept longer names and include
object/ID/gpencil
in all API calls that don't operate directly on Materials?BKE_material_get
too fuzzy, also naming is different fromBKE_material_current_p_get
when they're equivalent functions with only a minor difference, suggest:BKE_material_object_active_get
BKE_material_object_active_get_p
BKE_material_gpencil_get
toBKE_material_gpencil_active_get
Could use
BKE_material_active_from_object
style naming, however it doesn't group get/set functions so neatly.This is still not correct to me, it gets the material at a specified index, and that parameter happens to be named "act". But that isn't necessarily the active material. I suggest
BKE_object_material_get
. There are already other functions withBKE_object_material
prefix in this file.This function is used in just one place to test if the material slot exists. So rather than this hacky returning of pointers to pointers we should really just have a
BKE_object_material_slot_exists()
for that case and remove this from the API.Tsk, my mistake
give_current_material
reads likeget active material
, of course it's accessing via index (index + 1
in fact, better handle that separate from rename).+1 for using
BKE_object_material_
assume this applies toBKE_gpencil_material_
,BKE_id_material_
too.@ideasman42, we linked to VS Code refactoring tools here, which has Rename Symbol.
https://wiki.blender.org/wiki/Style_Guide/Code_Quality_Day
I think that is fine as long as the developer mentions in the patch which header file to look at for changes, and that the rest is just automated renaming.
Then it's also possible to reorder functions, group functions, comment, rename parameters, etc, to make it a consistent whole. That isn't a requirement for these kinds of tasks, but when it's done it takes some iteration and isn't easy to separate from the renaming.
For small/medium refactors which don't require much review/iteration, I'm not so fussed.
When changing many symbols in an API, it's useful to see the result in context, see how the changes fit with whats already there,
sometimes you notice inconsistencies or odd conventions that feed back into better decisions, eg: D2678
I like more the script solution than VS refactor tools for renaming. I use Visual Studio 2019 (big brother of VS) and sometimes the refactor miss code and is very slow if you compare with find/replace. In my job in other languages (not blender) I always have used find/replace scripts with very good results and speed.
Only one comment about the script, it would be better to add
(
at the end of the original and destination strings ("init_def_material"
->"init_def_material("
) to avoid naming conflicts. It could be any situation where one renaming could replace a section of other naming, and the(
avoids that.If you agree, I can prepare the script and we can verify naming again before run it. IMHO, any refactor of parameters, returns, etc, must be in a different task.
EDIT: It looks using
(
at the end of the string breaks the script, so I'm going to remove it.I have tested the script and in my PC takes a few seconds to run.
I'm fine with using scripts when it works well.
If we follow the
BKE_object_material
andBKE_id_material
prefix then it would look like this. I also addedBKE_materials_exit
for consistency withinit
.If both agree, I can commit the changes this afternoon.
It looks good to me now, except I wouldn't use obscure abbrevations for these but instead:
ok, changed, I will do the commit today.
Changed status from 'Confirmed' to: 'Resolved'
Would rather this patch have gone over more review, there are still many inconsistencies in the API naming.
BKE_material_
prefix for object API's (egBKE_material_resize_object
).BKE_gpencil_material_attr_init
andBKE_material_gpencil_init
are similar functions, named differently.BKE_gpencil_material
is a wrapper forBKE_object_material_get
which uses a gpencil fallback, should be named more clearly.Submitted #73623 (Code Quality: Renaming on BKE_material.h #2) to continue this task.
This isn't needed as the replacement uses regular-expressions, surrounding the identifier with
\b
to delimit on word boundaries.