Hey Spog,
Nice to see you found your way!

The flickering might be because you do not test if neighbourg face normal is valid. but forget about this, since when the other problem will be fixed, it will no longer be an issue, since you will never see it from that angle.

For the rotations, little guess would be that you use the object space normals without transform.

try do something like this if you use latest trunk (you should)
var t:Matrix3D = tri.view.cameraVarsStore.viewTransformDictionary[tri.source];

or for previous versions
var t:Matrix3D = tri.source.viewTransform;

in both versions, repeat same rotate method for each normals. norm1, norm2 and norm3
should work like this:
first make a class var instead of each normals as new Number3D instead of a var.
private var norm1: Number3D =  new Number3D();

then in code for the 3 after you retreive the matrix t.
norm1.rotate(tri.face.parent.neighbour01( tri.face ).normal), t);
norm2.rotate(tri.face.parent.neighbour12( tri.face ).normal), t);
norm3.rotate(tri.face.parent.neighbour20( tri.face ).normal), t);

rest should do just fine. You're almost there!
yet no garanty... I'm in the middle of a DVD :))

Fabrice

On Feb 1, 2009, at 8:17 PM, spog wrote:


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

Reply via email to