TMaterial is used to maintain and set material properties of objects. It can also be rendered itself to aid the design of the material. It displays the canonical teapot when used this way.
ProtoObjectObjectTObjectTFrameTMaterial
| ambientColor | boundSphere | cullFace | diffuseColor | emissiveColor | flipFace | fullBright | renderObject | scale | shininess | specularColor | subMaterialList | texture | textureMode | transparency | uvAngle | uvOffset | uvScale |
| DefaultAmbient | DefaultDiffuse | DefaultEmission | DefaultShininess | DefaultSpecular | DefaultWhite |
| OpenGLConstants |
| ambientColor |
|---|
| boundSphere |
|---|
| cullFace |
|---|
| diffuseColor |
|---|
| emissiveColor |
|---|
| flipFace |
|---|
| fullBright |
|---|
| renderObject |
|---|
| scale |
|---|
| shininess |
|---|
| specularColor |
|---|
| subMaterialList |
|---|
| texture |
|---|
| textureMode |
|---|
| transparency |
|---|
| uvAngle |
|---|
| uvOffset |
|---|
| uvScale |
|---|
| DefaultAmbient |
|---|
| DefaultDiffuse |
|---|
| DefaultEmission |
|---|
| DefaultShininess |
|---|
| DefaultSpecular |
|---|
| DefaultWhite |
|---|
| accessing |
|---|
| ambientColor |
^ ambientColor. |
| ambientColor: ac |
ambientColor _ ac asFloatArray. |
| boundSphere |
boundSphere ifNil:[ boundSphere _ TBoundSphere localPosition: 0@0@0 radius: scale. boundSphere frame: self.]. ^ boundSphere. |
| color: aColor |
ambientColor _ {aColor red. aColor green. aColor blue. aColor alpha} asFloatArray.
diffuseColor _ ambientColor copy.
|
| cullFace |
^ cullFace. |
| cullFace: bool |
cullFace _ bool. |
| diffuseColor |
^ diffuseColor. |
| diffuseColor: dc |
diffuseColor _ dc asFloatArray. |
| emissiveColor |
^ emissiveColor. |
| emissiveColor: ec |
emissiveColor _ ec asFloatArray. |
| flipFace |
^ flipFace. |
| flipFace: bool |
flipFace _ bool. |
| fullBright |
^ fullBright. |
| fullBright: bool |
fullBright _ bool. |
| hasAlpha |
(ambientColor at: 4) < 1.0 ifTrue: [^ true]. (diffuseColor at: 4) < 1.0 ifTrue: [^ true]. transparency < 1.0 ifTrue:[^ true]. ^ false. |
| scale: scl |
super scale: scl. scale _ scl. boundSphere ifNotNil:[ boundSphere _ TBoundSphere localPosition:0@0@0 radius: scale. boundSphere objectOwner: self. ]. |
| shininess |
^ shininess. |
| shininess: s |
shininess _ s. |
| specularColor |
^ specularColor. |
| specularColor: sc |
specularColor _ sc asFloatArray. |
| subMaterialList |
^ subMaterialList. |
| subMaterialList: sml |
subMaterialList _ sml. |
| texture |
^ texture. |
| texture: txtr |
texture _ txtr. |
| textureMode |
^ textureMode. |
| textureMode: tm |
textureMode _ tm. |
| transparency |
^ transparency. |
| transparency: trans |
transparency _ trans. |
| uvAngle |
^ uvAngle |
| uvAngle: uva |
uvAngle _ uva. |
| uvOffset |
^ uvOffset |
| uvOffset: uvo |
uvOffset _ uvo. |
| uvScale |
^ uvScale. |
| uvScale: uvs |
uvScale _ uvs. |
| copying |
|---|
| postCopy |
super postCopy. ambientColor _ ambientColor copy. diffuseColor _ diffuseColor copy. specularColor _ specularColor copy. emissiveColor _ emissiveColor copy. subMaterialList ifNotNil:[ subMaterialList _ subMaterialList collect:[:mat| mat copy]. ]. ^self |
| initialize |
|---|
| initialize |
super initialize. self ambientColor: #(0.5 0.5 0.5 0.5) asFloatArray. self diffuseColor: #(0.5 0.5 0.5 0.5) asFloatArray. self specularColor: #(0.9 0.9 1.0 1.0) asFloatArray. self emissiveColor: #(0.0 0.0 0.0 1.0) asFloatArray. shininess _ 50.0. cullFace _ true. flipFace _ false. fullBright _ false. textureMode _ GLModulate. visible _ true. scale _ 1.0. transparency _ 1.0. ^self |
| properties-material |
|---|
| getAlpha |
^(ambientColor at: 4)*transparency. |
| getColor |
^Color r: (ambientColor at: 1) g: (ambientColor at: 2) b: (ambientColor at: 3) |
| getSpecularColor |
^Color r: (specularColor at: 1) g: (specularColor at: 2) b: (specularColor at: 3) |
| setAlpha: newAlpha |
self frameChildrenDo:[:each| each setAlpha: newAlpha]. ambientColor at: 4 put: newAlpha. diffuseColor at: 4 put: newAlpha. specularColor at: 4 put: newAlpha. |
| setColor: newColor |
self frameChildrenDo:[:child| child setColor: newColor]. ambientColor at: 1 put: newColor red; at: 2 put: newColor green; at: 3 put: newColor blue. diffuseColor at: 1 put: newColor red; at: 2 put: newColor green; at: 3 put: newColor blue. |
| setSpecularColor: newColor |
self frameChildrenDo:[:child| child setSpecularColor: newColor]. specularColor at: 1 put: newColor red; at: 2 put: newColor green; at: 3 put: newColor blue. |
| render |
|---|
| disable: ogl |
fullBright ifTrue:[ ogl glEnable: GLLighting.] ifFalse:[ " ogl glPopAttrib." ogl glMaterialfv: GLFront with: GLSpecular with: DefaultSpecular. ogl glMaterialfv: GLFront with: GLDiffuse with: DefaultDiffuse. ogl glMaterialfv: GLFront with: GLAmbient with: DefaultAmbient. ogl glMaterialfv: GLFront with: GLEmission with: DefaultEmission. ogl glMaterialfv: GLFront with: GLShininess with: DefaultShininess. ]. texture ifNotNil:[ texture disable: ogl. ogl glTexEnvi: GLTextureEnv with: GLTextureEnvMode with: GLModulate. ]. ogl setCull. |
| enable: ogl |
| trans | fullBright ifTrue:[ ogl glDisable: GLLighting. ogl glColor4fv: diffuseColor. "ogl glColor3fv: DefaultWhite." ] ifFalse:[ " ogl glPushAttrib: GLCurrentBit." transparency = 1.0 ifTrue:[ ogl glMaterialfv: GLFront with: GLSpecular with: specularColor; glMaterialfv: GLFront with: GLDiffuse with: diffuseColor; glMaterialfv: GLFront with: GLAmbient with: ambientColor; glMaterialfv: GLFront with: GLEmission with: emissiveColor; glMaterialfv: GLFront with: GLShininess with: shininess. ] ifFalse:[ trans _ #(1 1 1 1) asFloatArray. trans at: 4 put: transparency. ogl glMaterialfv: GLFront with: GLSpecular with: specularColor*trans; glMaterialfv: GLFront with: GLDiffuse with: diffuseColor*trans; glMaterialfv: GLFront with: GLAmbient with: ambientColor*trans; glMaterialfv: GLFront with: GLEmission with: emissiveColor*trans; glMaterialfv: GLFront with: GLShininess with: shininess. ]. ]. texture ifNotNil:[ texture enable: ogl. ogl glTexEnvi: GLTextureEnv with: GLTextureEnvMode with: textureMode. ]. cullFace ifFalse:[ ogl glDisable: GLCullFace.]. flipFace ifTrue:[ ogl flipFace.]. |
| render: ogl |
self hasAlpha ifFalse:[ ogl glPushMatrix. renderObject ifNil: [ renderObject _ TTeapot new. renderObject scale: scale.]. self enable: ogl. renderObject render: ogl. ogl glPopMatrix.]. |
| renderAlpha: ogl |
ogl glPushMatrix. renderObject ifNil: [ renderObject _ TTeapot new. ]. self enable: ogl. renderObject render: ogl. self disable: ogl. ogl glPopMatrix. |
| class initialization |
|---|
| initialize |
"TMaterial initialize" DefaultSpecular _ #(0.9 0.9 0.9 1.0) asFloatArray. DefaultDiffuse _ #(0.5 0.5 0.5 1.0) asFloatArray. DefaultAmbient _ #(0.5 0.5 0.5 1.0) asFloatArray. DefaultEmission _ #(0.0 0.0 0.0 1.0) asFloatArray. DefaultShininess _ 0.0. DefaultWhite _ #(1 1 1) asFloatArray. |