Example #1
0
        (function() {
            var state = new State(new ShaderGeneratorProxy());
            var fakeRenderer = mockup.createFakeRenderer();
            fakeRenderer.validateProgram = function() {
                return true;
            };
            fakeRenderer.getProgramParameter = function() {
                return true;
            };
            fakeRenderer.isContextLost = function() {
                return false;
            };

            state.setGraphicContext(fakeRenderer);
            var camera0 = new Camera();
            camera0.setViewport(new Viewport());
            camera0.setRenderOrder(Camera.NESTED_RENDER);
            var geom = Shape.createTexturedQuadGeometry(
                -10 / 2.0,
                0,
                -10 / 2.0,
                20,
                0,
                0,
                0,
                0,
                20,
                1,
                1
            );
            camera0.addChild(geom);

            var cull = new CullVisitor();
            var rs = new RenderStage();
            var sg = new StateGraph();
            rs.setViewport(camera0.getViewport());

            cull.setRenderStage(rs);
            cull.setStateGraph(sg);

            cull.pushProjectionMatrix(mat4.create());
            cull.pushModelViewMatrix(mat4.create());
            cull.pushModelViewMatrix(mat4.create());
            cull.pushStateSet(new StateSet());

            camera0.accept(cull);

            assert.isOk(
                cull.rootRenderStage === cull.currentRenderBin,
                'renderStage should stay the render bin and id '
            ); // + cull.rootRenderStage === cull.currentRenderBin);

            rs.draw(state);
        })();
Example #2
0
    test( 'IntersectionVisitor with 1 camera', function () {

        var camera = new Camera();
        camera.setViewport( new Viewport() );
        camera.setViewMatrix( Matrix.makeLookAt( [ 0, 0, -10 ], [ 0, 0, 0 ], [ 0, 1, 0 ], [] ) );
        camera.setProjectionMatrix( Matrix.makePerspective( 60, 800 / 600, 0.1, 100.0, [] ) );
        camera.addChild( Shape.createTexturedQuadGeometry( -0.5, -0.5, 0, 1, 0, 0, 0, 1, 0, 1, 1 ) );

        var pShadow = new ShadowedScene();
        var child = new Node();
        pShadow.addChild( child );
        pShadow.addChild( child );
        pShadow.addChild( child );
        var di = new DummyIntersector();
        var iv = new IntersectionVisitor();
        iv.setIntersector( di );
        camera.accept( iv );

        assert.equalVector( di.stackTransforms[ 0 ], [ 0.1536, -0.1152, -9.8002 ], 0.001, 'check end transform point' );
    } );
Example #3
0
        (function() {
            var canvas = mockup.createCanvas();
            var viewer = new mockup.Viewer(canvas);
            viewer.setupManipulator();
            viewer.init();
            viewer.frame();
            var cull = viewer.getCamera().getRenderer()._cullVisitor;

            var camera0 = new Camera();
            camera0.setRenderOrder(Camera.NESTED_RENDER);
            var node0 = new Node();
            var node1 = new Node();
            camera0.addChild(node0);
            camera0.addChild(node1);

            var camera1 = new Camera();
            camera1.setRenderOrder(Camera.NESTED_RENDER);
            var node00 = new Node();
            var node10 = new Node();
            camera1.addChild(node00);
            camera1.addChild(node10);

            camera0.addChild(camera1);

            //var cull = new CullVisitor();
            var rs = new RenderStage();
            var sg = new StateGraph();
            cull.setRenderStage(rs);
            cull.setStateGraph(sg);

            cull.pushProjectionMatrix(mat4.create());
            cull.pushModelViewMatrix(mat4.create());
            cull.pushModelViewMatrix(mat4.create());
            camera0.accept(cull);

            assert.isOk(
                cull.rootRenderStage === cull.currentRenderBin,
                'renderStage should stay the render bin and id '
            ); //+ cull.rootRenderStage === cull.currentRenderBin
            mockup.removeCanvas(canvas);
        })();
Example #4
0
        (function() {
            var camera0 = new Camera();

            var geom = Shape.createTexturedQuadGeometry(-5.0, -5, 0, 10, 0, 0, 0, 10, 0, 1, 1);
            geom.getBoundingBox = function() {
                var bb = new BoundingBox();
                bb._min = [-6131940, -6297390, -6356750];
                bb._max = [6353000, 6326310, 6317430];
                return bb;
            };
            camera0.addChild(geom);

            var eye = [-8050356.805171473, 5038241.363464848, 5364184.10053209];
            var target = [110530, 14460, -19660];

            //        var dFar = 15715646.446620844;
            //        var dNear = 6098715.042224069;

            //var matrixOffset = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 9520443.940837447, 0, 0, 0, -9539501.699646605, 1];
            // var projectionResult = [
            //      0.9742785792574936, 0, 0, 0,
            //      0, 1.7320508075688774, 0, 0,
            //      0, 0, -2.1890203449875116, -1,
            //      0, 0, -19059947.8295044, 0];

            // osg
            //      var projectionResult = [0.9742785792574936, 0, 0, 0, 0, 1.7320508075688774, 0, 0, 0, 0, -1.002002002002002, -1, 0, 0, -2.0020020020020022, 0]

            var dFar = 21546781.95939;
            var dNear = 267579.84430311248;
            //      var bbmax = [6353000, 6326310, 6317430];
            //      var bbmin = [-6131940, -6297390, -6356750];
            //      var bbCornerFar = 1;
            //      var bbCornerNear = 6;

            mat4.lookAt(camera0.getViewMatrix(), vec3.add(vec3.create(), eye, target), target, [
                0,
                0,
                1
            ]);
            mat4.perspective(
                camera0.getProjectionMatrix(),
                Math.PI / 180 * 60,
                800 / 450,
                1.0,
                1000.0
            );

            var stack = [];

            var setCullSettings = function(settings) {
                if (this._computedNear !== undefined) {
                    stack.push([this._computedNear, this._computedFar]);
                }
                CullSettings.prototype.setCullSettings.call(this, settings);
            };
            CullVisitor.prototype.setCullSettings = setCullSettings;

            var resultProjection;

            var popProjectionMatrix = function() {
                resultProjection = this.getCurrentProjectionMatrix();
                CullVisitor.prototype.popProjectionMatrix.call(this);
            };

            var supposedProjection = [
                0.97427857925749362,
                0,
                0,
                0,
                0,
                1.7320508075688774,
                0,
                0,
                0,
                0,
                -1.0241512629639544,
                -1,
                0,
                0,
                -530789.63819638337,
                0
            ];
            var cull = new CullVisitor();
            var rs = new RenderStage();
            var sg = new StateGraph();
            cull.popProjectionMatrix = popProjectionMatrix;
            cull.setRenderStage(rs);
            cull.setStateGraph(sg);

            cull.pushProjectionMatrix(mat4.create());
            cull.pushModelViewMatrix(mat4.create());
            cull.pushModelViewMatrix(mat4.create());

            camera0.accept(cull);
            assert.isOk(
                mockup.checkNear(stack[1][0], dNear, 1.0),
                'near should be ' + dNear + ' and is ' + stack[1][0]
            );
            assert.isOk(
                mockup.checkNear(stack[1][1], dFar, 1.0),
                'near should be ' + dFar + ' and is ' + stack[1][1]
            );
            assert.isOk(
                mockup.checkNear(resultProjection, supposedProjection, 1.0),
                'check projection matrix [' +
                    resultProjection.toString() +
                    '] [' +
                    supposedProjection.toString() +
                    ']'
            );
        })();
Example #5
0
        (function() {
            var camera0 = new Camera();

            var mt = new MatrixTransform();
            mat4.fromTranslation(mt.getMatrix(), [0, 0, 10]);
            var geom = Shape.createTexturedQuadGeometry(-5.0, -5, 0, 10, 0, 0, 0, 10, 0, 1, 1);
            mt.addChild(geom);
            camera0.addChild(mt);

            mat4.lookAt(camera0.getViewMatrix(), [0, 0, 20], [0, 0, 10], [0, 1, 0]);
            mat4.perspective(
                camera0.getProjectionMatrix(),
                Math.PI / 180 * 60,
                800 / 600,
                1.0,
                1000.0
            );

            var stack = [];

            var setCullSettings = function(settings) {
                if (this._computedNear !== undefined) {
                    stack.push([this._computedNear, this._computedFar]);
                }
                CullSettings.prototype.setCullSettings.call(this, settings);
            };
            CullVisitor.prototype.setCullSettings = setCullSettings;

            var resultProjection;

            var popProjectionMatrix = function() {
                resultProjection = this.getCurrentProjectionMatrix();
                CullVisitor.prototype.popProjectionMatrix.call(this);
            };

            var supposedProjection = [
                1.299038105676658,
                0,
                0,
                0,
                0,
                1.7320508075688774,
                0,
                0,
                0,
                0,
                -49.999750101250868,
                -1,
                0,
                0,
                -499.79750101250352,
                0
            ];
            var cull = new CullVisitor();
            var rs = new RenderStage();
            var sg = new StateGraph();
            cull.popProjectionMatrix = popProjectionMatrix;
            cull.setRenderStage(rs);
            cull.setStateGraph(sg);

            cull.pushProjectionMatrix(mat4.create());
            cull.pushModelViewMatrix(mat4.create());
            cull.pushModelViewMatrix(mat4.create());

            camera0.accept(cull);
            assert.isOk(
                mockup.checkNear(stack[1][0], 10),
                'near should be 10 and is ' + stack[1][0]
            );
            assert.isOk(
                mockup.checkNear(stack[1][1], 10),
                'near should be 10 and is ' + stack[1][1]
            );
            assert.isOk(
                mockup.checkNear(resultProjection, supposedProjection, 1e-3),
                'check projection matrix [' +
                    resultProjection.toString() +
                    '] [' +
                    supposedProjection.toString() +
                    ']'
            );
        })();