Python Complete Access to ColorBand Properties #17481

Closed
opened 2008-08-14 11:30:02 +02:00 by Emilio José Encinas Mir · 15 comments

%%%In the patch I edited two files:

  • ./source/blender/python/api2_2x/Material.h
  • ./source/blender/python/api2_2x/Material.c

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

  • SHADER - Returns the value assigned to Shader Input for ColRamps
  • ENERGY - Returns the value assigned to Energy Input for ColRamps
  • NORMAL - Returns the value assigned to Normal Input for ColRamps
  • RESULT - Returns the value assigned to Result Input for ColRamps

Material.ColorBandMethod

  • BLEND - Returns the value of Blend Method for ColRamps
  • MIX - Returns the same value of Blend, added to avoid confusion between Blend internal name and Mix name showed in the GUI
  • ADD - Returns the value of Add Method for ColRamps
  • MULT - Returns the value of Multiply Method for ColRamps
  • SUB - Returns the value of Substract Method for ColRamps
  • SCREEN - Returns the value of Screen Method for ColRamps
  • DIV - Returns the value of Divide Method for ColRamps
  • DIFF - Returns the value of Difference Method for ColRamps
  • DARK - Returns the value of Darken Method for ColRamps
  • LIGHT - Returns the value of Lighten Method for ColRamps
  • OVERLAY - Returns the value of Overlay Method for ColRamps
  • DODGE - Returns the value of Dodge Method for ColRamps
  • BURN - Returns the value of Burn Method for ColRamps
  • HUE - Returns the value of Hue Method for ColRamps
  • SAT - Returns the value of Saturation Method for ColRamps
  • VAL - Returns the value of Value Method for ColRamps
  • COLOR - Returns the value of Color Method for ColRamps

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")%%%

%%%In the patch I edited two files: - ./source/blender/python/api2_2x/Material.h - ./source/blender/python/api2_2x/Material.c 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 - SHADER - Returns the value assigned to Shader Input for ColRamps - ENERGY - Returns the value assigned to Energy Input for ColRamps - NORMAL - Returns the value assigned to Normal Input for ColRamps - RESULT - Returns the value assigned to Result Input for ColRamps Material.ColorBandMethod - BLEND - Returns the value of Blend Method for ColRamps - MIX - Returns the same value of Blend, added to avoid confusion between Blend internal name and Mix name showed in the GUI - ADD - Returns the value of Add Method for ColRamps - MULT - Returns the value of Multiply Method for ColRamps - SUB - Returns the value of Substract Method for ColRamps - SCREEN - Returns the value of Screen Method for ColRamps - DIV - Returns the value of Divide Method for ColRamps - DIFF - Returns the value of Difference Method for ColRamps - DARK - Returns the value of Darken Method for ColRamps - LIGHT - Returns the value of Lighten Method for ColRamps - OVERLAY - Returns the value of Overlay Method for ColRamps - DODGE - Returns the value of Dodge Method for ColRamps - BURN - Returns the value of Burn Method for ColRamps - HUE - Returns the value of Hue Method for ColRamps - SAT - Returns the value of Saturation Method for ColRamps - VAL - Returns the value of Value Method for ColRamps - COLOR - Returns the value of Color Method for ColRamps 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'

Changed status to: 'Open'

%%%Trying to add the Diff files...%%%

%%%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.%%%

%%%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.%%%

%%%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.%%%

%%%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.%%%

%%%assigning to self.%%%
Member

%%%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.%%%

%%%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):

  • MatInstance.colorbandDiffuseInput
  • MatInstance.colorbandDiffuseMethod
  • MatInstance.colorbandDiffuseFactor
  • MatInstance.colorbandSpecularInput
  • MatInstance.colorbandSpecularMethod
  • MatInstance.colorbandSpecularFactor

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. %%%

%%%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): - MatInstance.colorbandDiffuseInput - MatInstance.colorbandDiffuseMethod - MatInstance.colorbandDiffuseFactor - MatInstance.colorbandSpecularInput - MatInstance.colorbandSpecularMethod - MatInstance.colorbandSpecularFactor 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.%%%

%%%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.%%%

%%%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%%%

%%%too busy to review atm. assigning to ken%%%
Member

%%%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. %%%

%%%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.%%%

%%%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.%%%
Member

%%%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! %%%

%%%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! %%%
Member

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#17481
No description provided.