How to check a pixel value color on a 3D object?

Software: Away3D 3.x

mingram8, Newbie
Posted: 05 October 2011 10:35 PM   Total Posts: 2

I have a spinning globe, each country is a different color in one big bitmap. Each color performs a different method when clicked. It works fine 2D, The problem is I cannot get it to work when the object becomes 3D. I am new to Away3D so I assume this is a basic question, but how do I do this? This is my code:

var img:MovieClip = new worldMap() as MovieClip;

    
// create a BitmapData object with the following parameters: width, height, transparent, color
    
var bmpData:BitmapData = new BitmapData(img.widthimg.heighttrue);
 
    
// draws a copy of the img MovieClip in to the BitmapData
    
bmpData.draw(img);
 
    
// adds a Bitmap to the stage with the BitmapData (copy of the img1) information to display
    
var bmp:Bitmap = new Bitmap(bmpData);
    
bmp.img.height;
    
addChild(bmp);

var 
newMaterial:MovieMaterial = new MovieMaterial(img);

//makes the material
var sphere:Sphere = new Sphere({material:newMaterialradius:300,segmentsH:18,segmentsW:26});
view.scene.addChild(sphere);

//create globe and adds to view.

sphere.addEventListener(MouseEvent3D.MOUSE_UP,doIt);


function 
doIt(event:MouseEvent3D):void 
{
 trace
('hit');
      var 
pixelInformation:uint bmpData.getPixel32(mouseXmouseY);
    
trace(pixelInformationpixelInformation.toString(16));
 var 
jank pixelInformation.toString(16);
 if (
jank == 'ff0000ff'{
  trace
('different color');
 
}
 } 
   

Avatar
theMightyAtom, Sr. Member
Posted: 06 October 2011 07:30 AM   Total Posts: 669   [ # 1 ]

The mouse event returns includes the uv of the position on the target object.
From that you can find the pixel it is over, rather than the mouseX, mouseY

something like…
var pixelInformation:uint = bmpData.getPixel32(event.uv.x, event.uv.y);

Also, make sure your bmpData is within scope, and available to the function.

   

mingram8, Newbie
Posted: 06 October 2011 08:52 AM   Total Posts: 2   [ # 2 ]

It isn’t right but it got me on the right track. Thank you.

Now it returns a different number but everything I click is the hex d6d6e2 . Very odd.

   

Avatar
theMightyAtom, Sr. Member
Posted: 06 October 2011 10:40 AM   Total Posts: 669   [ # 3 ]

Sorry about that, wasn’t ‘til afterwards I realised you where using 3.x, of which I remember very little :O) Glad to hear you found a solution.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X