Search in sources :

Example 1 with PerInstanceColorAppearance

use of org.cesiumjs.cs.scene.apperances.PerInstanceColorAppearance 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)

Aggregations

HTML (com.google.gwt.user.client.ui.HTML)1 BillboardCollection (org.cesiumjs.cs.collections.BillboardCollection)1 GeometryInstance (org.cesiumjs.cs.core.geometry.GeometryInstance)1 RectangleGeometry (org.cesiumjs.cs.core.geometry.RectangleGeometry)1 BoxGeometryOptions (org.cesiumjs.cs.core.geometry.options.BoxGeometryOptions)1 RectangleGeometryOptions (org.cesiumjs.cs.core.geometry.options.RectangleGeometryOptions)1 GeometryInstanceOptions (org.cesiumjs.cs.core.options.GeometryInstanceOptions)1 CesiumTerrainProvider (org.cesiumjs.cs.core.providers.CesiumTerrainProvider)1 CesiumTerrainProviderOptions (org.cesiumjs.cs.core.providers.options.CesiumTerrainProviderOptions)1 Primitive (org.cesiumjs.cs.scene.Primitive)1 Scene (org.cesiumjs.cs.scene.Scene)1 PerInstanceColorAppearance (org.cesiumjs.cs.scene.apperances.PerInstanceColorAppearance)1 PerInstanceColorAppearanceOptions (org.cesiumjs.cs.scene.apperances.options.PerInstanceColorAppearanceOptions)1 BillboardOptions (org.cesiumjs.cs.scene.options.BillboardOptions)1 PrimitiveOptions (org.cesiumjs.cs.scene.options.PrimitiveOptions)1 ViewerPanel (org.cesiumjs.cs.widgets.ViewerPanel)1