In this post you will learn setting up 3d lines in PaperVision 3D 2, using not standard Lines3D class, which is raw, but using Vertex3D that allow you to build 3D lines with gradients or effects on separated layer.

After I imported collada 3D model of the ship I tried to create gradient lines for the ground. That lines should go to the horizon and fade out there. I was surprised to find out that PV3D 2 doesnt support gradient lines but this is not a problem for someone who reads my blog, in fact it is really easy to set up a small extension which will be easy to remove if needed and will not affect at all the usual lines making.

I could make this gradient lines using vertex3DInstance method of the Vertex3D class, which returns 2D coordinates of an Vertex3D. Something like this:

 
var groundSprite:Sprite=new Sprite();
var SVertex:Vertex3D=new Vertex3D(-250,-20,25000);
var SVertex2:Vertex3D=new Vertex3D(-250,-20,-150);
groundSprite.graphics.lineStyle(1);
groundSprite.graphics.lineGradientStyle(GradientType.LINEAR, [0xFF0000,
     0x00FF00, 0x0000FF], [1, 1, 1], [0, 128, 255]);
groundSprite.graphics.moveTo(SVertex.vertex3DInstance.x, SVertex.vertex3DInstance.y);
groundSprite.graphics.lineTo(SVertex2.vertex3DInstance.x, SVertex2.vertex3DInstance.y);
 

Here, we take the 2D screen coordinates of the "SVertex" instance of Vertex3D class and drawing the lines in the way we like it !
This is much faster and flexible than using PaperVision 2 Lines3D class. At present time the Lines3D class could improve, but my method is still faster because it avoids odd code.

This code does set up a gradient line using flash.display.GradientType native package and org.papervision3d.core.geom.renderables.Vertex3D PV3D package. It works fine, you can rotate, move and do whatever you want with this vertexes in 3D space and draw gradient line between them but this method is not very handy because you have to deal with the sprite, its depth, position and so on, beside, using graphics of one more display object will decrease the framerate, and thats why I decided to dig deeper and improve the PV3D 2 by adding gradient lines functionality.

On this links you can find more info about this packages:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Graphics.html#lineGradientStyle()
http://www.flashbookmarks.com/PV3D-GreatWhite-DOC/org/papervision3d/core/geom/renderables/Vertex3D.html

Please pay attention to this small but important detail in this code snippet:

 
r-=offsetR
g-=offsetG
b-=offsetB
 

the values can go below 0 and be negative (like -1). When an uint numeral is going negative, it becomes 2^32-1(which is the maximal value of the uint and equals to 0xFFFFFFFF). Probably this is a mistake of Adobe developers, the negative uint should become 0, not 2^32-1.
This issue is solved by setting a check:

 
if(r>256){r=0}
if(g>256){g=0}
if(b>256){b=0}
var newColour:uint = r << 16 | g << 8 | b
 

Enjoy http://alexgblog.com/?p=501