RobynsVeil opened this issue on Jan 24, 2009 · 490 posts
bagginsbill posted Thu, 28 May 2009 at 10:25 PM
Quote - Thanks for that, Bill. Really going to try to keep my questions to one concept at a time...
Quote - def PM(x, lbl): return Add(x).labelled("PM:" + lbl)
PM makes a parameter node - takes a number and a label.--Um, this "parameter node" is a math_function (Add) node?
Yes. If you look in many of my shaders, you'll see nodes whose label is PM:something. These are parameter nodes - nodes that I've called out where you are to be aware that you can change this parameter. It also tells my parmatic utility that it is a shader parameter and people can manage parameter values on the figure using parmatic. They don't have to use VSS. Parmatic can create a dial on the figure for each of these parameter nodes, and no matter how many of them there are, they only have to spin one dial to change all the ones that have the same label, across many material zones. That's another story, not worth going into right now. It suffices to understand that a parameter node is something I want the user to clearly see it's for tweaking or connecting things into the shader at that point. In most of my newer shaders, I automagically arrange all these down the left side of the material room so they can be found easily. I didn't show you how to do that in this demo. One thing at a time.
Quote -
--with all the goodies stubbed in, like what value it's going to accept (x) and "PM:" plus the label?
Yes - it says what it does. It creates a Math:Add node, plugs x into Value_1 and labels it "PM:" + label.
Quote - That init function... that's a new critter for me.
--Are we actually creating a new class, upon which objects can be based?
The "class CSB" statement is creating the new class. The init is the constructor for the class, i.e. this is the procedure for building an instance of the class. There are many "plumbing" functions in Python class definitions like this - they all begin and end with double underscore. The init function is just one of them. Another would be add, which is instructions on what to do if an instance of this class is used in an expression involving the + operator, as in a + b, where a is an instance of the class. There are tons of these and they are magical because of the name. Over time you can get to know them all. But the first and most important is the constructor method. The matmatic node classes are filled with these. That's why you can do stuff like Clouds() + Spots(). That's adding two nodes together, which requires the creation of yet another node to represent the sum.
Quote -
--So, when defining a class, that init thingie is pretty much required?
No it isn't required. You can inherit the constructor of the base class, and if there are no additional steps to build your particular type of object, then you don't have to implement your own constructor. However, if you have additional steps, or additional arguments to process that the base class doesn't already understand, then you must implement a constructor.
Quote -
--This is not a constructor, just a class definition?
I don't know what you're referring to when you used the word "This". CSB is a class, and init is a member function of the class whose job is to be the constructor for the class. CSB is not the constructor, init is, and init is not a class, it is the constructor for the CSB class.
Quote -
--And you define this class "CSB" as an object-type class with that parameter "object"?
Yes, the argument to a class declaration is the list of base classes from which your new class is derived, or inherits from. Since I had no need of some interesting base class I derived from the most basic class (or type) that Python has - the object class. This is the base class of everything and it's what you use when you have nothing in particular in mind to start with. All I wanted was a very simple type of object that has three attributes and one new method (mix), in addition to the methods that all objects have, because they are objects.
Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)