AlternativaPlatform / Alternativa3D

Alternativa3D Flash GPU accelerated 3D engine
http://alternativaplatform.com/en/technologies/alternativa3d/
376 stars 127 forks source link

Z ordering wrong on Android #12

Closed TrickyWidget closed 12 years ago

TrickyWidget commented 12 years ago

Everything works fine on Windows. However, when I take my code to Android, the Z ordering of objects is all wrong. The following code produces these outputs:

Windows 7 64 Home Premium, Adobe AIR 3.3:http://i49.tinypic.com/20jo2kg.png - Right

Android 3.2.1 Le Pan II, Adobe AIR 3.3: http://i50.tinypic.com/1z1sgtc.png - Wrong

(Flex 4.6 SDK, AIR 3.3 SDK, Alternativa3D 8.27, FlashDevelop 4.0.4 RTM with default "AIR Mobile AS3 App" profile)

package 
{
    import alternativa.engine3d.core.Camera3D;
    import alternativa.engine3d.core.Object3D;
    import alternativa.engine3d.core.View;
    import alternativa.engine3d.lights.OmniLight;
    import alternativa.engine3d.materials.StandardMaterial;
    import alternativa.engine3d.primitives.Box;
    import alternativa.engine3d.resources.BitmapTextureResource;
    import flash.display.BitmapData;
    import flash.display.Stage3D;
    import flash.events.Event;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;

    [SWF(width = "1024", height = "720")]

    public class Main extends Sprite 
    {
        public var
            stage3D     :Stage3D = stage.stage3Ds[0],
            scene       :Object3D = new Object3D(),
            camera      :Camera3D;

        public function Main():void 
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;

            stage3D = stage.stage3Ds[0];
            stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContext3dCreate);
            stage3D.requestContext3D();
        }

        private function onContext3dCreate(event:Event):void
        {
            camera = new Camera3D(1, 10000);
            camera.view = new View(stage.stageWidth, stage.stageHeight);
            camera.view.hideLogo();
            camera.rotationX = -.5;
            camera.rotationY = -1;
            scene.addChild(camera);
            addChild(camera.view);

            var light:OmniLight = new OmniLight(0xffffff, 5000, 10000);
            scene.addChild(light);

            var normalMap:BitmapTextureResource = new BitmapTextureResource(new BitmapData(1, 1, false, 0x7f7fff));
            normalMap.upload(stage3D.context3D);

            var texture:BitmapTextureResource = new BitmapTextureResource(new BitmapData(1, 1, false, 0xff0000));
            texture.upload(stage3D.context3D);
            var material:StandardMaterial = new StandardMaterial(texture, normalMap);

            var boxSize:uint = 50;
            var boxCount:int = 10;
            for (var x:int = 0; x < boxCount; x++)
                for (var z:int = 0; z < boxCount; z++)
                {
                    var box:Box = new Box(boxSize - 5, 10, boxSize - 5);
                    box.geometry.upload(stage3D.context3D);
                    box.getSurface(0).material = material;
                    box.x = (boxSize * x) - (boxCount * boxSize);
                    box.y = 50;
                    box.z = boxSize * z;
                    scene.addChild(box);
                }

            camera.render(stage3D);
        }
    }
}
TrickyWidget commented 12 years ago

Ah, my bad. Turns out AIR requires depthAndStencil set to true in application.xml (under initialWindow) to properly render 3D on Android. I set that and all is well!

Yaski commented 12 years ago

ok