HI Darko, I'm not sure if it's what you're searching for but here is
how you can :
draw an object, or add an interactive object where you click on a
sphere (or any plane ,hippopotamus, etc...)

You should use a movieMaterial, that way you can add button or any
movieclip to it, but you can also use a bitmap and draws on it's
bitmapdata, circles, lines, etc...
>Here we will draw on a bitmapdata, that will accept transparency:
var canvas:BitmapData=new BitmapData(500,500,true,0x00000000);
>we draw something in the bitmapdata, or the material won't work
var s:Shape = new Shape();
s.graphics.beginFill(0xFFFFFF);
s.graphics.drawRect(0,0,500,500);
s.graphics.endFill();
canvas.draw(s);

>that we add in a clip then in a  a movie Material:
var canvasCont:Bitmap =  new Bitmap(canvas);
var movieCanvas:MovieClip = new MovieClip();
movieCanvas.addchild(canvasCont);
var canvasMaterial:MovieMaterial=new MovieMaterial(movieCanvas);
>wrap the sphere
yourSphere.material=canvasMaterial;
>add our mouseEvent
yourSphere.addOnMouseDown(onMouseClickOnObject);
>the next function will add 2 event to the object : we will draw when mouse 
>will move, but for you this could be on click
function onMouseClickOnObject(e:MouseEvent3D):void {
        e.object.addOnMouseMove(mouseDraw);
        e.object.addOnMouseUp(mouseDrawStop);
}
>here is the main man, we will use UV coordinate returned by the mouseEvent to 
>draw on the bitmapdata contained in the moviematerial, or add something in the 
>moviematerial where te mouse is hitting the sphere:
(the comments are as3 comments so that  you can paste it in your code
editor to ease your reading)
function mouseDraw(e:MouseEvent3D):void {
        //if the material is a movieMaterial and our object is a sphere
        if (Mesh(e.object).material is MovieMaterial && e.object is Sphere) {
                // we get the movie displayed byy the movieMaterial
                var movie:Sprite=MovieMaterial(Mesh(e.object).material).movie;
                // we get the bitmap contained in the movie
                if (movie.getChildAt(0) is Bitmap) {
                        var btm:Bitmap=movie.getChildAt(0) as Bitmap;
                        //we create a matrix that will use the UV coordinate of 
the mouse
to draw on the bitmapdata
                        var m:Matrix = new Matrix();
                        // here you have the main way to get the mousePosition 
on the
sphere projected on your material
                        m.translate(e.uv.u*btm.bitmapData.width,(1-e.uv.v)
*btm.bitmapData.height);
                        //we draw whatever on the bitmapdata
                        btm.bitmapData.draw(yourstuff,m);
                        bumpMap.draw(yourstuff,m);
                        //or we could add something on the movieMaterial at 
that place
                        yourstuff.x = e.uv.u*btm.movie.width;
                        yourstuff.x = (1-e.uv.v)*movie.height;
                        movie.addChild(yourstuff);

                //don't forget, you're map has bood, if you wan't a (almost) 
perfect
you have to wrap something like that,
                //for all the bounds
                        if 
(e.uv.u*btm.bitmapData.width+brush.width>btm.bitmapData.width) {
                                m.identity();
                                
m.translate(e.uv.u*btm.bitmapData.width-btm.bitmapData.width,(1-
e.uv.v)*btm.bitmapData.height);
                                btm.bitmapData.draw(brush,m);
                                bumpMap.draw(brush,m);
                        }
                }
        }
}



> last remove the draw event when mouse is up
function mouseDrawStop(e:MouseEvent3D):void {
        e.object.removeOnMouseMove(mouseDraw);
}

Now that should be easy for you to use coordinates to draw lines, and
whatever.

Hope this will help.
If not, the topic title is so clear that I'm sure many people will
come here later to get that code   ;-)

Reply via email to