Python Complete Access to ColorBand Properties #17481
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
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-addons#17481
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?
%%%In the patch I edited two files:
This patch I've done achieves fullaccess to the Color Bands of a material instance. While it remains the actual mode Material.Modes.RAMPCOL* to know if a Color Band is active or not and the list of color points with the MatInstance.colorbandDiffuse o MatInstance.colorbandSpecular, the patch adds functions to the Python Material Instance to make fully accesible. The Functions added are:
For Diffuse RampCol:
MatInstance.getColorBandDiffuseFactor() - Returns the actual Factor
MatInstance.getColorBandDiffuseMethod() - Returns the actual Method
MatInstance.getColorBandDiffuseInput() - Returns the actual Input
MatInstance.setColorBandDiffuseFactor(float) - Sets/Chages the Factor
MatInstance.setColorBandDiffuseMethod(int) - Sets/Changes the Method
MatInstance.setColorBandDiffuseInput(int) - Sets/Changes the Input
For Specular RampCol:
MatInstance.getColorBandSpecularFactor() - Returns the actual Factor
MatInstance.getColorBandSpecularMethod() - Returns the actual Method
MatInstance.getColorBandSpecularInput() - Returns the actual Input
MatInstance.setColorBandSpecularFactor(float) - Sets/Chages the Factor
MatInstance.setColorBandSpecularMethod(int) - Sets/Changes the Method
MatInstance.setColorBandSpecularInput(int) - Sets/Changes the Input
In adittion, to make it easy to use the Patch adds two Dictionary to de Material Class, so among the Material.Modes and Material.Shaders thera are two dictionaries more:
Material.ColorBandInput
Material.ColorBandMethod
The only file I haven't patched is the ./source/blender/python/api2_2x/doc/Material.py, but the only thing to do is add all the new information to it.
I added the two diff files of Material.c and Material.h based on the stable source release Blender 2.46 tar package downloaded from the web. (If it's of help, I would say that the diff files are generated with the comand "diff original_file modified_by_me_file > dif_file")%%%
Changed status to: 'Open'
%%%Trying to add the Diff files...%%%
%%%I add a new Diff file. Is the same diff of Material.c but using the command "diff -u" instead of "diff". I named it "Material_c(Version with diff -u).diff" so I think it's clear what file match each version.%%%
%%%Changed the lines in Material.c where I forget to change EXPP_IValueClamped from 'h' to 'i'. Will try tomorrow, but for now i'm getting "Segement Violation" when trying to use any of the setColorBand* functions. The getColorBand* functions seems to work properly for my tryings.%%%
%%%Adding a new Diff file, changed the value clamped type from "byte" to "int", it was an error I forgot to replace.%%%
%%%assigning to self.%%%
%%%I took a look at this patch too; couple of things to point out:
(1) The preference in the API is to use attributes over methods where possible. Since all of the get* methods take no arguments and the set* methods take single ints or floats, they should probably be replaced using getsetters.
(2) We usually require the doc files to be included before accepting a patch; additionally, there should be some test scripts to verify the new code works correctly and has the necessary exceptions, clamping, etc.
Campbell; I'd be happy to review this if you'd prefer.%%%
%%%OK. I edited the file again. Following the sugestion from Ken Mughes, I moved all to attributes instead of methods. Now the Path add this Values (The names of attributes are self explanatory):
Using the new values with the old ones MatInstance.colorbandDiffuse and MatInstance.colorbandSpecular you can read or write all the information about any of the two Color Ramps. To Know if thay are Active you need to use the method (MatInstance.mode & Material.Modes.RAMPCOL) or (MatInstance.mode & Material.Modes.RAMPSPEC) wich is the actual method, so the patch only adds new attributes without breaking any Script compatibility with the Material element.
I think now thet the only change that is needed with the new patch is to add the new attributes and dictionaries to the doc. %%%
%%%First of all: Added the new Diff file.
For Ken Mughes: Yes, I'm trying the patch with two Python Script. The first of it writes the colorbands data in to a file. The second would load the data from the file and set a material to use that config so with the two Scripts I'm testing the read and the write part of it. If it's needed I can upload some code for people to try it too.%%%
%%%To make it easier, I modified my source/blender/python/api2_2x/doc/Material.py and added the new data to the doc. I'm uploading the diff file of Material.py with this message, so I think the Patch is now complete. Please, try it and let me know any new information.%%%
%%%too busy to review atm. assigning to ken%%%
%%%Yes, it makes it easier for us to test the patch if you give us a test script. So please do upload to the tracker as well. %%%
%%%OK, to make it easier, instead of storing data into a file and then loading, you can use a simple Script. For example:
print "Material Diffuse Colorband Factor:",MatInstance.colorbandDiffuseFactor
And then you can run Blender from a console and view the output results.
Or you can use a Script like:
MatInstance=new Material("MaterialName")
MatInstance.mode=MatInstance.mode | Material.Mode.RAMPCOL
MatInstance.colorbandDiffuseFactor=0.5
MatInstance.colorbandDiffuseMethod=Material.ColorBandMethod.BLEND
MatInstance.colorbandDiffuseInput=Material.ColorBandInput.RESULT
MatInstance.colorbandDiffuse- [x]=[0,0,0,0,0]
MatInstance.colorbandDiffuse- [x]=[1,1,1,1,1]
Then you can select the material "MaterialName" for an objecto of the scene and check the colorband settings.
I'm now having troubles compiling Blender because I'm now on Windows XP 64bit and I can't try the patch. In some days I will return tu a linux based PC so I will continue with the patch and the Scripts for uploading here. Meanwhile, there is anywhere on the net a guide to build/compile a Blender in Windows XP 64? If I could build Blender in my Windows I will be able to work with the patch and the scripts.%%%
%%%Took a little time and work to patch this in. Made some minor changes to capitalization. Hardest part was it looks like your text editor changed tabs to spaces, so had to apply a lot of the changes by comparing lines in the patch to the original.
Committing to svn. Thanks for the contribution! %%%
Changed status from 'Open' to: 'Archived'