Hey Spog,

That demo is almost 2 years old... I've found that class back deep on my disc. You'll just have to take a look at BitmapMaterial, Mesh and PhongMaterial classes for proper 2.x calls/props to port it.
And do some clean up...

The sphere looks always smooth (what, in probably any case, is what
you want).
I guess that class isn't 100% useless afterall :))

Looking at it now, I think that if the source would be animated with lights moving arround,
that it could become very nice...

Don't forget post the result!

Fabrice

package away3d.core.material
{
        
    import away3d.core.*;
    import away3d.core.math.*;
    import away3d.core.scene.*;
    import away3d.core.draw.*;
    import away3d.core.render.*;
    import away3d.core.utils.*;
    import flash.display.*;
    import flash.geom.*;
    import away3d.core.material.*;

public class DiscoBallMaterial implements ITriangleMaterial, IUVMaterial, INeighbours
    {
        public var bitmap:BitmapData;
        public var rect:Rectangle;
        public var smooth:Boolean;
        public var debug:Boolean;
        public var repeat:Boolean;
                
        public var eTri0:ScreenVertex = new ScreenVertex();
        public var eTri1:ScreenVertex = new ScreenVertex();
        public var eTri2:ScreenVertex = new ScreenVertex();
                
        internal var mapping:Matrix;
                
        public function get useNeighbours():Boolean
        {
            return true;
        }

        public function get width():Number
        {
            return bitmap.width;
        }

        public function get height():Number
        {
            return bitmap.height;
        }

public function DiscoBallMaterial(bitmap:BitmapData, init:Object = null)
        {
            this.bitmap = bitmap;
            init = Init.parse(init);
            smooth = init.getBoolean("smooth", false);
        }

public function renderTriangle(tri:DrawTriangle, session:RenderSession):void
        {
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 mapping:Matrix = tri.texturemapping || 
tri.transformUV(this);
                        var normal:Object = null;
                
                        var norm1:Number3D;
                        var norm2:Number3D;
                        var norm3:Number3D;
                        norm1 = tri.face.neighbour01.normal;
                        norm2 = tri.face.neighbour12.normal;
                        norm3 = tri.face.neighbour20.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);
                
        }


    }
}




On Jan 29, 2009, at 10:36 AM, spog wrote:


Hi List,
I'm new to Away3D.
I'm trying to do some kind of a disco/mirror-ball with away3D.
What I need is a sphere made out of plenty of planes/mirrors.
The ball should then be located in a dark room and illuminated
by a number of colored lights.

As a first try I made a sphere with 30x20 segments and a
ColorShadingMaterial. The whole scene is then lighted by three
DirectionalLight3D.

http://www.low-res.de/misc/discoball/

This is quite good for what I want to archive. But I think if I'm
going
to add more light sources the performance will suffer somewhen.

After I saw this example by Fabrice

http://www.closier.nl/playground/discoball.swf

I thougt, that instead of using DirectionalLight3D an environment
mapping
for the lightsources will be musch more efficient. But I don't get how
the example
from Fabrice was done.
I guess this was just some kind of "early version" of
EnviroBitmapMaterial.
Am I right? Because when I try to user EnviroBitmapMaterial, I never
see
the single segments of the sphere (like it is with
ColorShadingMaterial ).
The sphere looks always smooth (what, in probably any case, is what
you want).
But in my case I don't want a smooth sphere ;)

Is there any way to have an enviroment mapping that looks like the
example from
fabrice? Can somebody hint me, how to archive that?

Thanks and greetings,
Spog

Reply via email to