Skip navigation
Currently Being Moderated

Bug: TextureMap renders bitmaps upside-down and horizontally mirrored

Jun 21, 2012 3:33 PM

Any bitmaps I bring into a TextureMap come in upside-down and horizontally mirrored.  The upside-down is no big deal, but the the horizontally mirrored is more of a pain to correct.  Here's a demo showing a traditional Flash bitmap on the left and the TextureMap image on the right (you'll have to tweak the dimensions to fit your test image).

 

 

package
{
     import com.adobe.scenegraph.BasicScene;
     import com.adobe.scenegraph.MaterialStandard;
     import com.adobe.scenegraph.MeshUtils;
     import com.adobe.scenegraph.SceneLight;
     import com.adobe.scenegraph.SceneMesh;
     import com.adobe.scenegraph.TextureMap;
     import flash.display.Bitmap;
     import flash.display.BitmapData;
     import flash.geom.Matrix;
     import flash.geom.Vector3D;
     
     [SWF(width = "960", height = "540")]
     
     public class MirroredTextureMap extends BasicScene
     {
          [Embed(source="image.png")]
          protected static const image:Class;
          
          override protected function initLights():void
          {
               var light:SceneLight = new SceneLight(SceneLight.KIND_POINT);
               scene.addChild(light);
          }
          
          override protected function initModels():void
          {
               // The standard Flash image is correct
               var bitmap:Bitmap = new Bitmap(new image().bitmapData);
               stage.addChild(bitmap);
               
               // The TextureMap image is upside-down and horizontally mirrored!
               var material:MaterialStandard = new MaterialStandard();
               material.diffuseMap = new TextureMap(new image().bitmapData);
               var plane:SceneMesh = MeshUtils.createPlane(1, 1);
               plane.material = material;
               plane.appendRotation(90, Vector3D.X_AXIS);
               plane.appendTranslation(.5, 0, -1);
               scene.addChild(plane);
               
               // Upside-down is easy to fix
               plane.appendRotation(180, Vector3D.Z_AXIS, plane.position);
               
               // But horizontally mirrored needs more work
               var mirroredBitmapData:BitmapData = new image().bitmapData;
               var matrix:Matrix = new Matrix( -1, 0, 0, 1, mirroredBitmapData.width, 0);
               var correctBitmapData:BitmapData = new BitmapData(mirroredBitmapData.width, mirroredBitmapData.height);
               correctBitmapData.draw(mirroredBitmapData, matrix);
               material.diffuseMap = new TextureMap(correctBitmapData);
          }
     }
}
 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points