Search in sources :

Example 1 with Scene

use of org.cesiumjs.cs.scene.Scene in project gwt-cs by iSergio.

the class ParticleSystem method buildPanel.

@Override
public void buildPanel() {
    ViewerPanel csVPanel = new ViewerPanel();
    // Set the random number seed for consistent results.
    Math.setRandomNumberSeed(3);
    // Make sure viewer is at the desired time.
    csVPanel.getViewer().clock().startTime = start.clone();
    csVPanel.getViewer().clock().stopTime = stop.clone();
    csVPanel.getViewer().clock().currentTime = start.clone();
    // Loop at the end
    csVPanel.getViewer().clock().clockRange = ClockRange.LOOP_STOP();
    csVPanel.getViewer().clock().multiplier = 1;
    // Set timeline to simulation bounds
    csVPanel.getViewer().timeline().zoomTo(start, stop);
    // Compute the entity position property.
    circularPosition = computeCirclularFlight(-112.110693, 36.0994841, 0.03);
    staticPosition = Cartesian3.fromDegrees(-112.110693, 36.0994841, 1000);
    TimeIntervalOptions timeIntervalOptions = new TimeIntervalOptions();
    timeIntervalOptions.start = start;
    timeIntervalOptions.stop = stop;
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.gltf");
    modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    entityOptions.position = new ConstantPositionProperty(staticPosition);
    entity = csVPanel.getViewer().entities().add(entityOptions);
    csVPanel.getViewer().trackedEntity = entity;
    ParticleSystemOptions particleSystemOptions = new ParticleSystemOptions();
    particleSystemOptions.image = GWT.getModuleBaseURL() + "SampleData/fire.png";
    particleSystemOptions.startColor = Color.RED().withAlpha(0.7f);
    particleSystemOptions.endColor = Color.YELLOW().withAlpha(0.3f);
    particleSystemOptions.startScale = viewModel.startScale;
    particleSystemOptions.endScale = viewModel.endScale;
    particleSystemOptions.minimumLife = viewModel.minimumLife;
    particleSystemOptions.maximumLife = viewModel.maximumLife;
    particleSystemOptions.minimumSpeed = viewModel.minimumSpeed;
    particleSystemOptions.maximumSpeed = viewModel.maximumSpeed;
    particleSystemOptions.minimumWidth = viewModel.particleSize;
    particleSystemOptions.minimumHeight = viewModel.particleSize;
    particleSystemOptions.maximumWidth = viewModel.particleSize;
    particleSystemOptions.maximumHeight = viewModel.particleSize;
    particleSystemOptions.rate = viewModel.rate;
    particleSystemOptions.bursts = new ParticleBurst[] { ParticleBurst.create(5.0, 300, 500), ParticleBurst.create(10.0, 50, 100), ParticleBurst.create(15.0, 200, 300) };
    particleSystemOptions.lifeTime = 16;
    particleSystemOptions.emitter = new CircleEmitter(0.5);
    particleSystemOptions.emitterModelMatrix = computeEmitterModelMatrix();
    particleSystemOptions.forces = new org.cesiumjs.cs.scene.particle.ParticleSystem.ApplyForce[] { new org.cesiumjs.cs.scene.particle.ParticleSystem.ApplyForce() {

        @Override
        public void function(Particle particle, double dt) {
            Cartesian3 position = particle.position;
            Cartesian3.normalize(position, gravityScratch);
            Cartesian3.multiplyByScalar(gravityScratch, viewModel.gravity * dt, gravityScratch);
            particle.velocity = Cartesian3.add(particle.velocity, gravityScratch, particle.velocity);
        }
    } };
    particleSystem = (org.cesiumjs.cs.scene.particle.ParticleSystem) csVPanel.getViewer().scene().primitives().add(new org.cesiumjs.cs.scene.particle.ParticleSystem(particleSystemOptions));
    csVPanel.getViewer().scene().preRender().addEventListener(new Event.Listener() {

        @Override
        public void function(Object... o) {
            Scene scene = (Scene) o[0];
            JulianDate time = (JulianDate) o[1];
            particleSystem.modelMatrix = computeModelMatrix(entity, time);
            // Account for any changes to the emitter model matrix.
            particleSystem.emitterModelMatrix = computeEmitterModelMatrix();
            // Spin the emitter if enabled.
            if (viewModel.spin) {
                viewModel.heading += 1.0;
                viewModel.pitch += 1.0;
                viewModel.roll += 1.0;
                rotationHTBox.setValue(viewModel.heading + "");
                rotationPTBox.setValue(viewModel.pitch + "");
                rotationRTBox.setValue(viewModel.roll + "");
            }
        }
    });
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(createWidget(), 20, 20);
    contentPanel.add(new HTML("<p>Particle systems.</p>"));
    contentPanel.add(aPanel);
    initWidget(contentPanel);
}
Also used : ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) Particle(org.cesiumjs.cs.scene.particle.Particle) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) TimeIntervalOptions(org.cesiumjs.cs.core.options.TimeIntervalOptions) TimeIntervalCollection(org.cesiumjs.cs.collections.TimeIntervalCollection) Scene(org.cesiumjs.cs.scene.Scene) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions) CircleEmitter(org.cesiumjs.cs.scene.emitters.CircleEmitter) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) SliderEvent(org.cleanlogic.showcase.client.examples.slider.SliderEvent) JsObject(org.cesiumjs.cs.js.JsObject) ParticleSystemOptions(org.cesiumjs.cs.scene.particle.options.ParticleSystemOptions)

Example 2 with Scene

use of org.cesiumjs.cs.scene.Scene in project gwt-cs by iSergio.

the class Cardboard method buildPanel.

@Override
public void buildPanel() {
    ViewerOptions viewerOptions = new ViewerOptions();
    viewerOptions.vrButton = true;
    ViewerPanel csVPanel = new ViewerPanel(viewerOptions);
    csVPanel.getViewer().scene().globe.enableLighting = true;
    CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
    cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
    cesiumTerrainProviderOptions.requestVertexNormals = true;
    csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
    csVPanel.getViewer().scene().globe.depthTestAgainstTerrain = true;
    // Follow the path of a plane. See the interpolation Sandcastle example.
    Math.setRandomNumberSeed(3);
    start = JulianDate.fromDate(new JsDate(2015, 2, 25, 16));
    stop = JulianDate.addSeconds(start, 360, new JulianDate());
    csVPanel.getViewer().clock().startTime = start.clone();
    csVPanel.getViewer().clock().stopTime = stop.clone();
    csVPanel.getViewer().clock().currentTime = start.clone();
    csVPanel.getViewer().clock().clockRange = ClockRange.LOOP_STOP();
    csVPanel.getViewer().clock().multiplier = 1.0;
    double lon = -112.110693;
    double lat = 36.0994841;
    double radius = 0.03;
    String modelURI = GWT.getModuleBaseURL() + "SampleData/models/CesiumBalloon/CesiumBalloon.glb";
    EntityOptions entityOptions = new EntityOptions();
    TimeIntervalOptions timeIntervalOptions = new TimeIntervalOptions();
    timeIntervalOptions.start = start;
    timeIntervalOptions.stop = stop;
    entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
    entityOptions.position = computeCirclularFlight(lon, lat, radius);
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(modelURI);
    modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    entity = csVPanel.getViewer().entities().add(entityOptions);
    SampledPropertyInterpolationOptions sampledPropertyInterpolationOptions = new SampledPropertyInterpolationOptions();
    sampledPropertyInterpolationOptions.interpolationDegree = 2;
    sampledPropertyInterpolationOptions.interpolationAlgorithm = HermitePolynomialApproximation.instance();
    ((SampledPositionProperty) entity.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
    // Set initial camera position and orientation to be when in the model's reference frame.
    final org.cesiumjs.cs.scene.Camera camera = csVPanel.getViewer().camera;
    camera.position = new Cartesian3(0.25, 0.0, 0.0);
    camera.direction = new Cartesian3(1.0, 0.0, 0.0);
    camera.up = new Cartesian3(0.0, 0.0, 1.0);
    camera.right = new Cartesian3(0.0, -1.0, 0.0);
    csVPanel.getViewer().scene().preRender().addEventListener(new Scene.Listener() {

        @Override
        public void function(Scene scene, JulianDate time) {
            Cartesian3 position = entity.position.getValue(time);
            if (position == null || !Cesium.defined(position)) {
                return;
            }
            Matrix4 transform;
            if (!Cesium.defined(entity.orientation)) {
                transform = Transforms.eastNorthUpToFixedFrame(position);
            } else {
                Quaternion orientation = (Quaternion) entity.orientation.getValue(time);
                if (!Cesium.defined(orientation)) {
                    return;
                }
                transform = Matrix4.fromRotationTranslation(Matrix3.fromQuaternion(orientation), position);
            }
            // Save camera state
            Cartesian3 offset = camera.position.clone();
            Cartesian3 direction = camera.direction.clone();
            Cartesian3 up = camera.up.clone();
            // Set camera to be in model's reference frame.
            camera.lookAtTransform(transform);
            // Reset the camera state to the saved state so it appears fixed in the model's frame.
            offset.clone(camera.position);
            direction.clone(camera.direction);
            up.clone(camera.up);
            Cartesian3.cross(direction, up, camera.right);
        }
    });
    // Add a few more balloons flying with the one the viewer is in.
    int numBalloons = 12;
    for (int i = 0; i < numBalloons; ++i) {
        double balloonRadius = (Math.nextRandomNumber() * 2.0 - 1.0) * 0.01 + radius;
        entityOptions = new EntityOptions();
        timeIntervalOptions = new TimeIntervalOptions();
        timeIntervalOptions.start = start;
        timeIntervalOptions.stop = stop;
        entityOptions.availability = new TimeIntervalCollection(new TimeInterval[] { new TimeInterval(timeIntervalOptions) });
        entityOptions.position = computeCirclularFlight(lon, lat, balloonRadius);
        modelGraphicsOptions = new ModelGraphicsOptions();
        modelGraphicsOptions.uri = new ConstantProperty<>(modelURI);
        modelGraphicsOptions.minimumPixelSize = new ConstantProperty<>(64);
        entityOptions.model = new ModelGraphics(modelGraphicsOptions);
        Entity balloon = csVPanel.getViewer().entities().add(entityOptions);
        sampledPropertyInterpolationOptions = new SampledPropertyInterpolationOptions();
        sampledPropertyInterpolationOptions.interpolationDegree = 2;
        sampledPropertyInterpolationOptions.interpolationAlgorithm = HermitePolynomialApproximation.instance();
        ((SampledPositionProperty) balloon.position).setInterpolationOptions(sampledPropertyInterpolationOptions);
    }
    contentPanel.add(new HTML("<p>Configure viewer to add a button enabling look at a mobile device with cardboard.</p>"));
    contentPanel.add(csVPanel);
    initWidget(contentPanel);
}
Also used : CesiumTerrainProviderOptions(org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions) Entity(org.cesiumjs.cs.datasources.Entity) SampledPropertyInterpolationOptions(org.cesiumjs.cs.datasources.properties.options.SampledPropertyInterpolationOptions) ViewerOptions(org.cesiumjs.cs.widgets.options.ViewerOptions) HTML(com.google.gwt.user.client.ui.HTML) JsDate(org.cesiumjs.cs.js.JsDate) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) CesiumTerrainProvider(org.cesiumjs.cs.core.providers.CesiumTerrainProvider) SampledPositionProperty(org.cesiumjs.cs.datasources.properties.SampledPositionProperty) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) TimeIntervalOptions(org.cesiumjs.cs.core.options.TimeIntervalOptions) TimeIntervalCollection(org.cesiumjs.cs.collections.TimeIntervalCollection) Scene(org.cesiumjs.cs.scene.Scene) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)

Example 3 with Scene

use of org.cesiumjs.cs.scene.Scene in project gwt-cs by iSergio.

the class HeadingPitchRoll method buildPanel.

@Override
public void buildPanel() {
    ViewerPanel csVPanel = new ViewerPanel();
    pathPosition = new SampledPositionProperty();
    PathGraphicsOptions pathGraphicsOptions = new PathGraphicsOptions();
    pathGraphicsOptions.show = new ConstantProperty<>(true);
    pathGraphicsOptions.leadTime = new ConstantProperty<>(0);
    pathGraphicsOptions.trailTime = new ConstantProperty<>(60);
    pathGraphicsOptions.width = new ConstantProperty<>(10);
    pathGraphicsOptions.resolution = new ConstantProperty<>(1);
    pathGraphicsOptions.material = PolylineGlowMaterialProperty.create(Color.PALEGOLDENROD(), 0.3);
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.position = pathPosition;
    entityOptions.name = "path";
    entityOptions.path = new PathGraphics(pathGraphicsOptions);
    Entity entityPath = csVPanel.getViewer().entities().add(entityOptions);
    final org.cesiumjs.cs.scene.Camera camera = csVPanel.getViewer().camera;
    final ScreenSpaceCameraController controller = csVPanel.getViewer().scene().screenSpaceCameraController();
    final Cartesian3 center = new Cartesian3();
    final org.cesiumjs.cs.core.HeadingPitchRoll hpRoll = new org.cesiumjs.cs.core.HeadingPitchRoll();
    final HeadingPitchRange hpRange = new HeadingPitchRange();
    position = Cartesian3.fromDegrees(-123.0744619, 44.0503706, 5000.0);
    speedVector = new Cartesian3();
    final Transforms.LocalFrameToFixedFrame fixedFrameTransform = Transforms.localFrameToFixedFrameGenerator("north", "west");
    FromGltfOptions fromGltfOptions = new FromGltfOptions();
    fromGltfOptions.url = GWT.getModuleBaseURL() + "SampleData/models/CesiumAir/Cesium_Air.glb";
    // , fixedFrameTransform);
    fromGltfOptions.modelMatrix = Transforms.headingPitchRollToFixedFrame(position, hpRoll, Ellipsoid.WGS84());
    fromGltfOptions.minimumPixelSize = 128;
    planePrimitive = (Model) csVPanel.getViewer().scene().primitives().add(Model.fromGltf(fromGltfOptions));
    planePrimitive.readyPromise().then(new Fulfill<Model>() {

        @Override
        public void onFulfilled(Model model) {
            ModelAnimationOptions modelAnimationOptions = new ModelAnimationOptions();
            modelAnimationOptions.speedup = 0.5;
            modelAnimationOptions.loop = ModelAnimationLoop.REPEAT();
            model.activeAnimations.addAll(modelAnimationOptions);
            // Zoom to model
            r = 2.0 * max(model.boundingSphere().radius, ((PerspectiveFrustum) camera.frustum).near);
            controller.minimumZoomDistance = r * 0.5;
            Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere().center, center);
            double heading = Math.toRadians(230.0);
            double pitch = Math.toRadians(-20.0);
            hpRange.heading = heading;
            hpRange.pitch = pitch;
            hpRange.range = r * 50.0;
            camera.lookAt(center, hpRange);
        }
    });
    fromBehind = new CheckBox();
    fromBehind.getElement().getStyle().setColor("white");
    fromBehind.setWidth("100px");
    fromBehind.setValue(false);
    final com.google.gwt.user.client.ui.Label headingLabel = new Label();
    headingLabel.getElement().getStyle().setColor("white");
    headingLabel.setText("Heading:°");
    final com.google.gwt.user.client.ui.Label pitchLabel = new Label();
    pitchLabel.getElement().getStyle().setColor("white");
    pitchLabel.setText("Pitch:°");
    final com.google.gwt.user.client.ui.Label rollLabel = new Label();
    rollLabel.getElement().getStyle().setColor("white");
    rollLabel.setText("Roll:°");
    final com.google.gwt.user.client.ui.Label speedLabel = new Label();
    speedLabel.getElement().getStyle().setColor("white");
    speedLabel.setText("Speed:m/s");
    FlexTable flexTable = new FlexTable();
    flexTable.setWidget(0, 0, headingLabel);
    flexTable.setHTML(1, 0, "<font color=\"white\">← to left/→ to right</font>");
    flexTable.setWidget(2, 0, pitchLabel);
    flexTable.setHTML(3, 0, "<font color=\"white\">↑ to up/↓ to down</font>");
    flexTable.setWidget(4, 0, rollLabel);
    flexTable.setHTML(5, 0, "<font color=\"white\">← + ⇧ left/→ + ⇧ right</font>");
    flexTable.setWidget(6, 0, speedLabel);
    flexTable.setHTML(7, 0, "<font color=\"white\">↑ + ⇧ to speed up/↓ + ⇧ to speed down</font>");
    flexTable.setHTML(8, 0, "<font color=\"white\">Following aircraft</font>");
    flexTable.setWidget(8, 1, fromBehind);
    AbsolutePanel aPanel = new AbsolutePanel();
    aPanel.add(csVPanel);
    aPanel.add(flexTable, 20, 20);
    contentPanel.add(new HTML("<p>Click on the 3D window then use the keyboard to change settings.</p>"));
    contentPanel.add(aPanel);
    csVPanel.getViewer().scene().preRender().addEventListener(new Scene.Listener() {

        @Override
        public void function(Scene scene, JulianDate time) {
            headingLabel.setText("Heading:" + Math.toDegrees(hpRoll.heading) + "°");
            pitchLabel.setText("Pitch:" + Math.toDegrees(hpRoll.pitch) + "°");
            rollLabel.setText("Roll:" + Math.toDegrees(hpRoll.roll) + "°");
            speedLabel.setText("Speed:" + speed + "m/s");
            speedVector = Cartesian3.multiplyByScalar(Cartesian3.UNIT_X(), speed / 10, speedVector);
            position = Matrix4.multiplyByPoint(planePrimitive.modelMatrix, speedVector, position);
            pathPosition.addSample(JulianDate.now(), position);
            Transforms.headingPitchRollToFixedFrame(position, hpRoll, Ellipsoid.WGS84(), fixedFrameTransform, planePrimitive.modelMatrix);
            if (fromBehind.getValue()) {
                // Zoom to model
                Matrix4.multiplyByPoint(planePrimitive.modelMatrix, planePrimitive.boundingSphere().center, center);
                hpRange.heading = hpRoll.heading;
                hpRange.pitch = hpRoll.pitch;
                camera.lookAt(center, hpRange);
            }
        }
    });
    RootPanel.get().addDomHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(KeyDownEvent keyDownEvent) {
            switch(keyDownEvent.getNativeKeyCode()) {
                case 40:
                    if (keyDownEvent.getNativeEvent().getShiftKey()) {
                        speed = max(--speed, 1);
                    } else {
                        hpRoll.pitch -= deltaRadians;
                        if (hpRoll.pitch < -Math.TWO_PI()) {
                            hpRoll.pitch += Math.TWO_PI();
                        }
                    }
                    break;
                case 38:
                    if (keyDownEvent.getNativeEvent().getShiftKey()) {
                        // speed up
                        speed = min(++speed, 100);
                    } else {
                        // pitch up
                        hpRoll.pitch += deltaRadians;
                        if (hpRoll.pitch > Math.TWO_PI()) {
                            hpRoll.pitch -= Math.TWO_PI();
                        }
                    }
                    break;
                case 39:
                    if (keyDownEvent.getNativeEvent().getShiftKey()) {
                        // roll right
                        hpRoll.roll += deltaRadians;
                        if (hpRoll.roll > Math.TWO_PI()) {
                            hpRoll.roll -= Math.TWO_PI();
                        }
                    } else {
                        // turn right
                        hpRoll.heading += deltaRadians;
                        if (hpRoll.heading > Math.TWO_PI()) {
                            hpRoll.heading -= Math.TWO_PI();
                        }
                    }
                    break;
                case 37:
                    if (keyDownEvent.getNativeEvent().getShiftKey()) {
                        // roll left until
                        hpRoll.roll -= deltaRadians;
                        if (hpRoll.roll < 0.0) {
                            hpRoll.roll += Math.TWO_PI();
                        }
                    } else {
                        // turn left
                        hpRoll.heading -= deltaRadians;
                        if (hpRoll.heading < 0.0) {
                            hpRoll.heading += Math.TWO_PI();
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }, KeyDownEvent.getType());
    initWidget(contentPanel);
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) FromGltfOptions(org.cesiumjs.cs.scene.options.FromGltfOptions) KeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) com.google.gwt.user.client.ui(com.google.gwt.user.client.ui) SampledPositionProperty(org.cesiumjs.cs.datasources.properties.SampledPositionProperty) ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) ModelAnimationOptions(org.cesiumjs.cs.scene.options.ModelAnimationOptions) PathGraphics(org.cesiumjs.cs.datasources.graphics.PathGraphics) Scene(org.cesiumjs.cs.scene.Scene) PathGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.PathGraphicsOptions) PathGraphics(org.cesiumjs.cs.datasources.graphics.PathGraphics) org.cesiumjs.cs.core(org.cesiumjs.cs.core) Model(org.cesiumjs.cs.scene.Model) ScreenSpaceCameraController(org.cesiumjs.cs.scene.ScreenSpaceCameraController)

Example 4 with Scene

use of org.cesiumjs.cs.scene.Scene in project gwt-cs by iSergio.

the class CesiumInspector method buildPanel.

@Override
public void buildPanel() {
    ViewerPanel csVPanel = new ViewerPanel();
    Scene scene = csVPanel.getViewer().scene();
    Globe globe = csVPanel.getViewer().scene().globe;
    globe.depthTestAgainstTerrain = true;
    CesiumTerrainProviderOptions cesiumTerrainProviderOptions = new CesiumTerrainProviderOptions();
    cesiumTerrainProviderOptions.url = "https://assets.agi.com/stk-terrain/world";
    cesiumTerrainProviderOptions.requestVertexNormals = true;
    cesiumTerrainProviderOptions.requestWaterMask = true;
    csVPanel.getViewer().terrainProvider = new CesiumTerrainProvider(cesiumTerrainProviderOptions);
    // Add Cesium Inspector
    csVPanel.getViewer().extend(viewerCesiumInspectorMixin.instance());
    // Add Primitives
    PrimitiveOptions primitiveOptions = new PrimitiveOptions();
    primitiveOptions.asynchronous = false;
    GeometryInstanceOptions geometryInstanceOptions = new GeometryInstanceOptions();
    BoxGeometryOptions boxGeometryOptions = new BoxGeometryOptions();
    boxGeometryOptions.vertexFormat = PerInstanceColorAppearance.VERTEX_FORMAT();
    boxGeometryOptions.dimensions = new Cartesian3(400000.0, 300000.0, 500000.0);
    geometryInstanceOptions.geometry = BoxGeometry.createGeometry(BoxGeometry.fromDimensions(boxGeometryOptions));
    geometryInstanceOptions.modelMatrix = Matrix4.multiplyByTranslation(Transforms.eastNorthUpToFixedFrame(Cartesian3.fromDegrees(-105.0, 45.0)), new Cartesian3(0.0, 0.0, 250000), new Matrix4());
    geometryInstanceOptions.attributes = JsObject.createObject().cast();
    JsObject.$(geometryInstanceOptions.attributes, "color", ColorGeometryInstanceAttribute.fromColor(Color.RED().withAlpha(0.5f)));
    primitiveOptions.geometryInstances = new GeometryInstance[] { new GeometryInstance(geometryInstanceOptions) };
    PerInstanceColorAppearanceOptions perInstanceColorAppearanceOptions = new PerInstanceColorAppearanceOptions();
    perInstanceColorAppearanceOptions.closed = true;
    primitiveOptions.appearance = new PerInstanceColorAppearance(perInstanceColorAppearanceOptions);
    scene.primitives().add(new Primitive(primitiveOptions));
    primitiveOptions = new PrimitiveOptions();
    primitiveOptions.asynchronous = false;
    geometryInstanceOptions = new GeometryInstanceOptions();
    RectangleGeometryOptions rectangleGeometryOptions = new RectangleGeometryOptions();
    rectangleGeometryOptions.rectangle = Rectangle.fromDegrees(-100.0, 30.0, -93.0, 37.0);
    rectangleGeometryOptions.height = 100000;
    rectangleGeometryOptions.vertexFormat = PerInstanceColorAppearance.VERTEX_FORMAT();
    geometryInstanceOptions.geometry = RectangleGeometry.createGeometry(new RectangleGeometry(rectangleGeometryOptions));
    geometryInstanceOptions.attributes = JsObject.createObject().cast();
    JsObject.$(geometryInstanceOptions.attributes, "color", ColorGeometryInstanceAttribute.fromColor(Color.BLUE()));
    primitiveOptions.geometryInstances = new GeometryInstance[] { new GeometryInstance(geometryInstanceOptions) };
    primitiveOptions.appearance = new PerInstanceColorAppearance();
    scene.primitives().add(new Primitive(primitiveOptions));
    BillboardCollection billboards = (BillboardCollection) scene.primitives().add(new BillboardCollection());
    BillboardOptions billboardOptions = new BillboardOptions();
    billboardOptions.position = Cartesian3.fromDegrees(-75.59777, 40.03883, 150000);
    billboardOptions.image = GWT.getModuleBaseURL() + "images/Cesium_Logo_overlay.png";
    billboards.add(billboardOptions);
    contentPanel.add(new HTML("<p>Use the cesium inspector as a debugging tool for different primitives</p>"));
    contentPanel.add(csVPanel);
    initWidget(contentPanel);
}
Also used : ViewerPanel(org.cesiumjs.cs.widgets.ViewerPanel) BillboardCollection(org.cesiumjs.cs.collections.BillboardCollection) CesiumTerrainProviderOptions(org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions) BillboardOptions(org.cesiumjs.cs.scene.options.BillboardOptions) RectangleGeometryOptions(org.cesiumjs.cs.core.geometry.options.RectangleGeometryOptions) PerInstanceColorAppearance(org.cesiumjs.cs.scene.apperances.PerInstanceColorAppearance) GeometryInstance(org.cesiumjs.cs.core.geometry.GeometryInstance) RectangleGeometry(org.cesiumjs.cs.core.geometry.RectangleGeometry) HTML(com.google.gwt.user.client.ui.HTML) Scene(org.cesiumjs.cs.scene.Scene) Primitive(org.cesiumjs.cs.scene.Primitive) GeometryInstanceOptions(org.cesiumjs.cs.core.options.GeometryInstanceOptions) PerInstanceColorAppearanceOptions(org.cesiumjs.cs.scene.apperances.options.PerInstanceColorAppearanceOptions) CesiumTerrainProvider(org.cesiumjs.cs.core.providers.CesiumTerrainProvider) BoxGeometryOptions(org.cesiumjs.cs.core.geometry.options.BoxGeometryOptions) PrimitiveOptions(org.cesiumjs.cs.scene.options.PrimitiveOptions)

Example 5 with Scene

use of org.cesiumjs.cs.scene.Scene in project gwt-cs by iSergio.

the class Picking method pickPosition.

private void pickPosition() {
    ModelGraphicsOptions modelGraphicsOptions = new ModelGraphicsOptions();
    modelGraphicsOptions.uri = new ConstantProperty<>(GWT.getModuleBaseURL() + "SampleData/models/CesiumMilkTruck/CesiumMilkTruck-kmc.gltf");
    EntityOptions entityOptions = new EntityOptions();
    entityOptions.position = new ConstantPositionProperty(Cartesian3.fromDegrees(-123.0744619, 44.0503706));
    entityOptions.name = "milktruck";
    entityOptions.model = new ModelGraphics(modelGraphicsOptions);
    final Entity modelEntity = viewerPanel.getViewer().entities().add(new Entity(entityOptions));
    viewerPanel.getViewer().zoomTo(modelEntity);
    LabelGraphicsOptions labelGraphicsOptions = new LabelGraphicsOptions();
    labelGraphicsOptions.show = new ConstantProperty<>(false);
    labelGraphicsOptions.horizontalOrigin = new ConstantProperty<>(HorizontalOrigin.LEFT());
    entityOptions = new EntityOptions();
    entityOptions.label = new LabelGraphics(labelGraphicsOptions);
    final Entity labelEntity = viewerPanel.getViewer().entities().add(new Entity(entityOptions));
    _handler = new ScreenSpaceEventHandler(viewerPanel.getViewer().scene().canvas());
    _handler.setInputAction(new ScreenSpaceEventHandler.Listener<MouseMoveEvent>() {

        @Override
        public void function(MouseMoveEvent event) {
            boolean foundPosition = false;
            Scene scene = viewerPanel.getViewer().scene();
            PickedObject pickedObject = scene.pick(event.endPosition);
            if (scene.pickPositionSupported() && pickedObject != null && pickedObject.id == modelEntity) {
                Cartesian3 cartesian = viewerPanel.getViewer().scene().pickPosition(event.endPosition);
                if (cartesian != null) {
                    Cartographic cartographic = Cartographic.fromCartesian(cartesian);
                    String lon = new BigDecimal(Math.toDegrees(cartographic.longitude)).setScale(2, RoundingMode.HALF_EVEN).toString();
                    String lat = new BigDecimal(Math.toDegrees(cartographic.latitude)).setScale(2, RoundingMode.HALF_EVEN).toString();
                    String height = new BigDecimal(cartographic.height).setScale(2, RoundingMode.HALF_EVEN).toString();
                    labelEntity.position = new ConstantPositionProperty(cartesian);
                    labelEntity.label.show = new ConstantProperty<>(true);
                    labelEntity.label.text = new ConstantProperty<>("(" + lon + ", " + lat + ", " + height + ")");
                    Camera camera = scene.camera();
                    labelEntity.label.eyeOffset = new ConstantProperty<>(new Cartesian3(0.0, 0.0, ((PerspectiveFrustum) camera.frustum).near * 1.5 - (double) Cartesian3.distance(cartesian, camera.position)));
                    foundPosition = true;
                }
            }
            if (!foundPosition) {
                labelEntity.label.show = new ConstantProperty<>(false);
            }
        }
    }, ScreenSpaceEventType.MOUSE_MOVE());
}
Also used : Entity(org.cesiumjs.cs.datasources.Entity) MouseMoveEvent(org.cesiumjs.cs.core.events.MouseMoveEvent) LabelGraphics(org.cesiumjs.cs.datasources.graphics.LabelGraphics) Scene(org.cesiumjs.cs.scene.Scene) ModelGraphics(org.cesiumjs.cs.datasources.graphics.ModelGraphics) EntityOptions(org.cesiumjs.cs.datasources.options.EntityOptions) BigDecimal(java.math.BigDecimal) ModelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions) Camera(org.cesiumjs.cs.scene.Camera) LabelGraphicsOptions(org.cesiumjs.cs.datasources.graphics.options.LabelGraphicsOptions)

Aggregations

Scene (org.cesiumjs.cs.scene.Scene)5 EntityOptions (org.cesiumjs.cs.datasources.options.EntityOptions)4 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)4 Entity (org.cesiumjs.cs.datasources.Entity)3 ModelGraphics (org.cesiumjs.cs.datasources.graphics.ModelGraphics)3 ModelGraphicsOptions (org.cesiumjs.cs.datasources.graphics.options.ModelGraphicsOptions)3 HTML (com.google.gwt.user.client.ui.HTML)2 TimeIntervalCollection (org.cesiumjs.cs.collections.TimeIntervalCollection)2 TimeIntervalOptions (org.cesiumjs.cs.core.options.TimeIntervalOptions)2 CesiumTerrainProvider (org.cesiumjs.cs.core.providers.CesiumTerrainProvider)2 CesiumTerrainProviderOptions (org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions)2 SampledPositionProperty (org.cesiumjs.cs.datasources.properties.SampledPositionProperty)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)1 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 com.google.gwt.user.client.ui (com.google.gwt.user.client.ui)1 BigDecimal (java.math.BigDecimal)1 BillboardCollection (org.cesiumjs.cs.collections.BillboardCollection)1 org.cesiumjs.cs.core (org.cesiumjs.cs.core)1