[Tweener] PV3d Tweening ColorMaterial.fillColor
Kenneth Weiss
kweiss at chrome-fusion.com
Sat Nov 22 05:00:11 PST 2008
Ok so I had to use my brain after all.... I have to say it was much
easier when I spent the time actually reading the code... :-)
Here is the package that allows you to tween the fillColor property of
a PaperVision3D ColorMaterial.
package
{
import caurina.transitions.Tweener;
import caurina.transitions.AuxFunctions;
public class PaperVisionColorMaterialProperty
{
//this package is based on the package
caurina.transitions.SpecialPropertiesDefault and
//allows you to tween the color of a colorMaterial.
public function PaperVisionColorMaterialProperty ()
{
trace ("PaperVisionColorMaterialProperty is a static class and
should not be instantiated.")
}
/**
* Registers all the special properties to the Tweener class, so the
Tweener knows what to do with them.
*/
public static function init():void
{
// pv3d
Tweener.registerSpecialProperty("_material_color_r",
_material_color_property_get, _material_color_property_set,
["redOffset"]);
Tweener.registerSpecialProperty("_material_color_g",
_material_color_property_get, _material_color_property_set,
["greenOffset"]);
Tweener.registerSpecialProperty("_material_color_b",
_material_color_property_get, _material_color_property_set,
["blueOffset"]);
Tweener.registerSpecialPropertySplitter("fillColor",
_material_color_splitter);
}
/**
* Splits the fillColor parameter into specific color variables
*
* @param p_value Number The original _color value
* @return Array An array containing the .name and .value of
all new properties
*/
public static function _material_color_splitter (p_value:*):Array
{
var nArray:Array = new Array();
if (p_value == null)
{
// No parameter passed, so just resets the color
nArray.push({name:"_material_color_r", value:0});
nArray.push({name:"_material_color_g", value:0});
nArray.push({name:"_material_color_b", value:0});
} else {
// A color tinting is passed, so converts it to the object values
nArray.push({name:"_material_color_r",
value:AuxFunctions.numberToR(p_value)});
nArray.push({name:"_material_color_g",
value:AuxFunctions.numberToG(p_value)});
nArray.push({name:"_material_color_b",
value:AuxFunctions.numberToB(p_value)});
}
return nArray;
}
public static function _material_color_property_get (p_obj:Object,
p_parameters:Array):Number
{
var colorProperty:Number = 0;
if(p_parameters[0] == "redOffset")
colorProperty = AuxFunctions.numberToR(p_obj.fillColor) ;
else if(p_parameters[0] == "greenOffset")
colorProperty = AuxFunctions.numberToG(p_obj.fillColor) ;
else if(p_parameters[0] == "blueOffset")
colorProperty = AuxFunctions.numberToB(p_obj.fillColor) ;
return colorProperty;
}
public static function _material_color_property_set (p_obj:Object,
p_value:Number, p_parameters:Array):void
{
var colorProperty:Number = p_obj.fillColor;
switch(p_parameters[0]){
case "redOffset" : colorProperty = (colorProperty & 0x00ffff) |
(p_value << 16); break;
case "greenOffset" : colorProperty = (colorProperty & 0xff00ff) |
(p_value << 8); break;
case "blueOffset" : colorProperty = (colorProperty & 0xffff00) |
(p_value << 0); break;
}
p_obj.fillColor = colorProperty;
}
}
}
On 16 Nov 2008, at 14:49, Kenneth Weiss wrote:
> Just discovered Tweener recently and I love it.
> I would like to tween the fillColor of a ColorMaterial.
>
> The following gets tweened but not correctly because it interpolates
> the hex value.
> Tweener.addTween(cube.materials.getMaterialByName("front"),
> {fillColor:0xe12188, time:1.0, transition:"linear"});
>
> I assume that I need to do something with :
> Tweener.registerSpecialPropertySplitter("_color", _color_splitter);
>
> And somehow:
> Tweener.registerSpecialProperty("fillColor", _ fillColor_get, _
> fillColor_set);
>
> And I know it works for "_color" in a normal MovieClip, so I'm sure
> it's possible.
>
> I was wondering if someone has already been through this and
> wouldn't mind sharing code.
>
> Cheers,
>
> K
>
> Kenneth Weiss
> kweiss at chrome-fusion.com
> mobile: +353 861755033
> home: +353 12824038
> web: www.chrome-fusion.com
> music: www.myspace.com/shorttermproject
>
> _______________________________________________
> Tweener mailing list
> Tweener at lists.caurinauebi.com
> http://lists.caurinauebi.com/listinfo.cgi/tweener-caurinauebi.com
Kenneth Weiss
kweiss at chrome-fusion.com
mobile: +353 861755033
home: +353 12824038
web: www.chrome-fusion.com
music: www.myspace.com/shorttermproject
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.caurinauebi.com/pipermail/tweener-caurinauebi.com/attachments/20081122/e3a9ecef/attachment.htm>
More information about the Tweener
mailing list