Hi Fabrice,
today I found the time to look at your class and tried to find out how
to use it with Away3D 2.2.
Finally, it does something:
http://www.low-res.de/misc/discoball/discoMat_V1.html
But, as you may see, there are some oddities. The Environment-Image
seems to move according to the rotation of the sphere and I get some
strange triangles on one side of the sphere. I can't figure out, why
that is happening ( obviously because I'm not knowing what I'm doing
at all... ;)
It would be great if you could point me in the right direction to find
out what is happening there.
I guess that the rotation of the ball is taken into account somewhere
and thats why the texture is moving according to the rotation, but I
can't see where that is happening.
It took me some time to figure out where I have to make changes to the
class. In the end, there was not much, that I needed to change (as far
as I could assess it )
Here is what I did so far:
I made the DiscoballMaterial extend BitmapMaterial ( to use all the
interface implementations for ITriangleMaterial, IUVMaterial )
and then I just tweeked "renderTriangle" a bit. It looks like that
now:
override public function renderTriangle(tri : DrawTriangle) : void {
var _session : AbstractRenderSession = tri.source.session;
function nscreen(_v0 : ScreenVertex, _v1 : ScreenVertex, _v2 :
ScreenVertex) : Number3D {
var d1x : Number = _v1.x - _v0.x;
var d1y : Number = _v1.y - _v0.y;
var d1z : Number = _v1.z - _v0.z;
var d2x : Number = _v2.x - _v0.x;
var d2y : Number = _v2.y - _v0.y;
var d2z : Number = _v2.z - _v0.z;
var pa : Number = d1y * d2z - d1z * d2y;
var pb : Number = d1z * d2x - d1x * d2z;
var pc : Number = d1x * d2y - d1y * d2x;
var pdd : Number = Math.sqrt( pa * pa + pb * pb + pc * pc );
return new Number3D( pa / pdd, pb / pdd, pc / pdd );
}
var norm1 : Number3D = tri.face.parent.neighbour01
( tri.face ).normal;
var norm2 : Number3D = tri.face.parent.neighbour12
( tri.face ).normal;
var norm3 : Number3D = tri.face.parent.neighbour20
( tri.face ).normal;
var nn : Number3D = nscreen( tri.v0, tri.v1, tri.v2 );
nn.normalize( 1 );
eTri0.x = width * ((((nn.x + norm1.x) * .5) * .5) + .5);
eTri0.y = height * ( ((((nn.y + norm1.y) * .5) * .5) + .5));
eTri1.x = width * ((((nn.x + norm2.x) * .5) * .5) + .5);
eTri1.y = height * ( ((((nn.y + norm2.y) * .5) * .5) + .5));
eTri2.x = width * ((((nn.x + norm3.x) * .5) * .5) + .5);
eTri2.y = height * ( ((((nn.y + norm3.y) * .5) * .5) + .5));
var mat : Matrix = new Matrix( eTri1.x - eTri0.x, eTri1.y - eTri0.y,
eTri2.x - eTri0.x, eTri2.y - eTri0.y, eTri0.x, eTri0.y );
mat.invert( );
_session.renderTriangleBitmap( this.bitmap, mat, tri.v0, tri.v1,
tri.v2, smooth, false, _session.graphics );
}
It would be really great, if you could point me in the right
direction.
cheers,
spog