Commit 6f794abc authored by iSergio's avatar iSergio
Browse files

Added CloudCollection and CumulusCloud for adding procedurally generated clouds to a scene.

parent 4f4bfbd4
Loading
Loading
Loading
Loading
+98 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 iserge.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.collections;

import jsinterop.annotations.*;
import org.cesiumjs.cs.collections.options.CloudCollectionOptions;
import org.cesiumjs.cs.collections.options.CumulusCloudAddOptions;
import org.cesiumjs.cs.core.Cartesian3;
import org.cesiumjs.cs.scene.CumulusCloud;

/**
 * A renderable collection of clouds in the 3D scene.
 *
 * Clouds are added and removed from the collection using {@link CloudCollection#add} and {@link CloudCollection#remove}.
 */
@JsType(isNative = true, namespace = "Cesium", name = "CloudCollection")
public class CloudCollection extends Collection<CumulusCloud> {
    /**
     * This property is for debugging only; it is not for production use nor is it optimized.
     * Renders the billboards with one opaque color for the sake of debugging.
     *
     * Default: false
     */
    @JsProperty
    public boolean debugBillboards;
    /**
     * This property is for debugging only; it is not for production use nor is it optimized.
     * Draws the clouds as opaque, monochrome ellipsoids for the sake of debugging. If debugBillboards is also true,
     * then the ellipsoids will draw on top of the billboards.
     *
     * Default: false
     */
    @JsProperty
    public boolean debugEllipsoids;
//    /**
//     * Returns the number of clouds in this collection.
//     */
//    @JsProperty
//    public int length;
    /**
     * Controls the amount of detail captured in the precomputed noise texture used to render the cumulus clouds.
     * In order for the texture to be tileable, this must be a power of two. For best results, set this to be a power
     * of two between 8.0 and 32.0 (inclusive).
     * Default: 16.0
     */
    @JsProperty
    public float noiseDetail;
    /**
     * Applies a translation to noise texture coordinates to generate different data. This can be modified if the
     * default noise does not generate good-looking clouds.
     * Default: Cartesian3.ZERO
     */
    @JsProperty
    public Cartesian3 noiseOffset;
    /**
     * Determines if billboards in this collection will be shown.
     * Default: true
     */
    @JsProperty
    public boolean show;

    @JsConstructor
    public CloudCollection() {}

    @JsConstructor
    public CloudCollection(CloudCollectionOptions options) {}

    /**
     * Creates and adds a cloud with the specified initial properties to the collection. The added cloud is returned so
     * it can be modified or removed from the collection later.
     * @return The cloud that was added to the collection.
     */
    @JsMethod
    public native CumulusCloud add();

    /**
     * Creates and adds a cloud with the specified initial properties to the collection. The added cloud is returned so
     * it can be modified or removed from the collection later.
     * @param options A template describing the cloud's properties as {@link CumulusCloudAddOptions}
     * @return The cloud that was added to the collection.
     */
    @JsMethod
    public native CumulusCloud add(CumulusCloudAddOptions options);
}
+80 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 iserge.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.collections.options;

import jsinterop.annotations.*;
import org.cesiumjs.cs.core.Cartesian3;
import org.cesiumjs.cs.scene.CumulusCloud;

/**
 * Options object for {@link org.cesiumjs.cs.collections.CloudCollection#CloudCollection(CloudCollectionOptions)}.
 */
@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class CloudCollectionOptions {
    /**
     * Whether to display the clouds.
     * Default: true
     */
    @JsProperty
    public boolean show;
    /**
     * Desired amount of detail in the noise texture.
     * Default: 16.0
     */
    @JsProperty
    public double noiseDetail;
    /**
     * Desired translation of data in noise texture.
     * Default: Cartesian3.ZERO
     */
    @JsProperty
    public Cartesian3 noiseOffset;
    /**
     * For debugging only. Determines if the billboards are rendered with an opaque color.
     * Default: false
     */
    public boolean debugBillboards;
    /**
     * For debugging only. Determines if the clouds will be rendered as opaque ellipsoids.
     * Default: false
     */
    public boolean debugEllipsoids;

    @JsConstructor
    public CloudCollectionOptions() {}

    /**
     * Creates and adds a cloud with the specified initial properties to the collection. The added cloud is returned so it can be modified or removed from the collection later.
     * Performance:
     * Calling add is expected constant time. However, the collection's vertex buffer is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For best performance, add as many clouds as possible before calling update.
     *
     * @return The cloud that was added to the collection.
     */
    @JsMethod
    public native CumulusCloud add();

    /**
     * Creates and adds a cloud with the specified initial properties to the collection. The added cloud is returned so it can be modified or removed from the collection later.
     * Performance:
     * Calling add is expected constant time. However, the collection's vertex buffer is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For best performance, add as many clouds as possible before calling update.
     *
     * @param options A template describing the cloud's properties {@link CumulusCloudAddOptions}
     * @return The cloud that was added to the collection.
     */
    @JsMethod
    public native CumulusCloud add(CumulusCloudAddOptions options);
}
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 iserge.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.collections.options;

import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import org.cesiumjs.cs.core.Cartesian2;
import org.cesiumjs.cs.core.Cartesian3;
import org.cesiumjs.cs.scene.enums.CloudType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class CumulusCloudAddOptions {
    @JsProperty
    public boolean show;
    @JsProperty
    public Cartesian3 position;
    @JsProperty
    public Cartesian2 scale;
    @JsProperty
    public Cartesian3 maximumSize;
    @JsProperty
    public double slice;
    /**
     * {@link CloudType}
     */
    @JsProperty
    public Number cloudType;
    @JsProperty
    public Number brightness;
}
+90 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 iserge.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.scene;

import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import org.cesiumjs.cs.collections.CloudCollection;
import org.cesiumjs.cs.core.Cartesian2;
import org.cesiumjs.cs.core.Cartesian3;

/**
 * A cumulus cloud billboard positioned in the 3D scene, that is created and rendered using a CloudCollection.
 * A cloud is created and its initial properties are set by calling {@link CloudCollection#add} and {@link CloudCollection#remove}.
 *
 * Performance:
 * Similar to Billboard, reading a property, e.g., {@link CumulusCloud#show}, takes constant time. Assigning to a property is
 * constant time but results in CPU to GPU traffic when {@link CloudCollection#update} is called. The per-cloud traffic is
 * the same regardless of how many properties were updated. If most clouds in a collection need to be updated,
 * it may be more efficient to clear the collection with {@link CloudCollection#removeAll} and add new clouds instead
 * of modifying each one.
 */
@JsType(isNative = true, namespace = "Cesium", name = "CumulusCloud")
public class CumulusCloud {
    /**
     * Gets or sets the brightness of the cloud. This can be used to give clouds a darker, grayer appearance.
     * Default: 1.0
     */
    @JsProperty
    public float brightness;
    /**
     * Gets or sets the maximum size of the cumulus cloud rendered on the billboard. This defines a maximum ellipsoid
     * volume that the cloud can appear in. Rather than guaranteeing a specific size, this specifies a boundary for
     * the cloud to appear in, and changing it can affect the shape of the cloud.
     *
     * Changing the z-value of maximumSize has the most dramatic effect on the cloud's appearance because it changes
     * the depth of the cloud, and thus the positions at which the cloud-shaping texture is sampled.
     *
     * To modify the billboard's actual size, modify the cloud's scale property.
     *
     * @see CumulusCloud#scale
     */
    @JsProperty
    public Cartesian3 maximumSize;
    /**
     * Gets or sets the Cartesian position of this cumulus cloud.
     */
    @JsProperty
    public Cartesian3 position;
    /**
     * Gets or sets the scale of the cumulus cloud billboard in meters. The scale property will affect the size of the billboard, but not the cloud's actual appearance.
     *
     * To modify the cloud's appearance, modify its maximumSize and slice properties.
     *
     * @see CumulusCloud#maximumSize
     * @see CumulusCloud#slice
     */
    @JsProperty
    public Cartesian2 scale;
    /**
     * Determines if this cumulus cloud will be shown. Use this to hide or show a cloud, instead of removing it
     * and re-adding it to the collection.
     * Default: true
     */
    @JsProperty
    public boolean show;

    /**
     * Gets or sets the "slice" of the cloud that is rendered on the billboard, i.e. the specific cross-section of the
     * cloud chosen for the billboard's appearance. Given a value between 0 and 1, the slice specifies how deeply
     * into the cloud to intersect based on its maximum size in the z-direction.
     *
     * Default: -1.0
     */
    @JsProperty
    public float slice;
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 iserge.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.cesiumjs.cs.scene.enums;

import jsinterop.annotations.JsProperty;
import jsinterop.annotations.JsType;
import org.cesiumjs.cs.collections.CloudCollection;

/**
 * Specifies the type of the cloud that is added to a {@link CloudCollection} in {@link CloudCollection#add}.
 */
@JsType(isNative = true, namespace = "Cesium", name = "CloudType")
public class CloudType {
    /**
     * Cumulus cloud.
     */
    @JsProperty(name = "CUMULUS")
    public static native Number CUMULUS();
}