I'm trying to build an app where you can click anywhere on a mesh (an
MD2 model) and a sprite will be added to it's material at the point
you clicked.

The approach I've taken is to set up a Composite Material which has a
MovieMaterial layed over the top of the base texture which I add the
sprite to. When the user clicks on it, I position the new Sprite based
on the UVs in the MouseEvent3D.

So far I've got this:
http://www.antifuzz.com/projects/ninjaTest/test4/index.html

The problem is that I'd like this new Sprite always to be the right
way up, not nessecarily the same "way up" as the section of material
on that face as defined by its UVs. You can see in the above demo that
the smiley face is the right way up if you click somewhere on the
character's chest area for instance, but if you click on the legs or
the back of the character, it's upside-down. Is there a way of getting
the "rotation" of the material on a given face so I can compensate for
this when I place the new Sprite?

Any suggestions of how I can acheive this, or suggestions as to any
other better approaches to take?

Thanks!

Here's the relevant code:


                private function init() : void {
                        _material = new 
BitmapMaterial(Cast.bitmap(_ninjaTexture));
                        _md2 = new Md2();
                        _md2.fps = 10;
                        _mesh = _md2.parseGeometry(_ninjaMesh) as Mesh;

                        _mesh.scale(0.015);
                        _mesh.y -= 100;
                        _view.scene.addChild(_mesh);

                        // BRUSH
                        _brush = new _smileyClass();
                        _brush.scaleX = _brush.scaleY = 0.5;

                        // MAKE CANVAS BITMAPDATA
                        var canvas : BitmapData = new BitmapData(500, 500, true,
0x00000000);
                        // we already draw something in the bitmapdata 
rectangle, or the
material won't work
                        var s : Shape = new Shape();
                        s.graphics.beginFill(0x000000, 1);
                        s.graphics.drawRect(0, 0, 500, 500);
                        s.graphics.endFill();
                        canvas.draw(s);
                        // we add our bitmpadata in a movie that we use as 
movieMaterial
Source:
                        var materialBitmap : Bitmap = new Bitmap(canvas);
                        var materialMovie : MovieClip = new MovieClip();
                        materialMovie.addChild(materialBitmap);

                        // SETUP COMPOSITE MATERIAL
                        var movieMaterial : MovieMaterial = new
MovieMaterial(materialMovie);
                        var blackMaterial : BitmapMaterial = new
BitmapMaterial(Cast.bitmap(_ninjaTexture));
                        movieMaterial.blendMode = BlendMode.ADD;
                        var compMaterial : CompositeDrawingMaterial = new
CompositeDrawingMaterial();
                        compMaterial.addMaterial(blackMaterial);
                        compMaterial.addMaterial(movieMaterial);

                        _mesh.material = compMaterial;
                        _mesh.addOnMouseDown(onMouseClickOnObject);
                }


                private function onMouseClickOnObject(e : MouseEvent3D) : void {

                        var myMat : Material = (e.object as Mesh).material;
                        if (CompositeDrawingMaterial(myMat).materialArray[1] is
MovieMaterial) {
                                // we get the movie displayed by the 
movieMaterial
                                var movie : Sprite =
MovieMaterial(CompositeDrawingMaterial(myMat).materialArray[1]).movie;
                                _brush.x = e.uv.u * movie.width - (_brush.width 
/ 2);
                                _brush.y = (1 - e.uv.v) * movie.height - 
(_brush.height / 2);
                                movie.addChild(_brush);
                        }
                }

Reply via email to