How to use the cesium.WebGLConstants function in cesium

To help you get started, we’ve selected a few cesium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AnalyticalGraphicsInc / gltf-pipeline / lib / writeResources.js View on Github external
'use strict';
const Cesium = require('cesium');
const mime = require('mime');
const addBuffer = require('./addBuffer');
const ForEach = require('./ForEach');
const getImageExtension = require('./getImageExtension');
const mergeBuffers = require('./mergeBuffers');
const removeUnusedElements = require('./removeUnusedElements');

const defaultValue = Cesium.defaultValue;
const defined = Cesium.defined;
const WebGLConstants = Cesium.WebGLConstants;

// .crn (Crunch) is not a supported mime type, so add it
mime.define({'image/crn': ['crn']}, true);

// .glsl shaders are text/plain type
mime.define({'text/plain': ['glsl']}, true);

module.exports = writeResources;

/**
 * Write glTF resources as data uris, buffer views, or files.
 *
 * @param {Object} gltf A javascript object containing a glTF asset.
 * @param {Object} [options] Object with the following properties:
 * @param {String} [options.name] The name of the glTF asset, for writing separate resources.
 * @param {Boolean} [options.separateBuffers=false] Whether to save buffers as separate files.
github AnalyticalGraphicsInc / gltf-pipeline / lib / compressDracoMeshes.js View on Github external
const ForEach = require('./ForEach');
const numberOfComponentsForType = require('./numberOfComponentsForType');
const readAccessorPacked = require('./readAccessorPacked');
const removeUnusedElements = require('./removeUnusedElements');
const replaceWithDecompressedPrimitive = require('./replaceWithDecompressedPrimitive');
const splitPrimitives = require('./splitPrimitives');

const arrayFill = Cesium.arrayFill;
const Cartesian3 = Cesium.Cartesian3;
const Check = Cesium.Check;
const clone = Cesium.clone;
const ComponentDatatype = Cesium.ComponentDatatype;
const defaultValue = Cesium.defaultValue;
const defined = Cesium.defined;
const RuntimeError = Cesium.RuntimeError;
const WebGLConstants = Cesium.WebGLConstants;

// Prepare encoder for compressing meshes.
const encoderModule = draco3d.createEncoderModule({});

module.exports = compressDracoMeshes;

/**
 * Compresses meshes using Draco compression in the glTF model.
 *
 * @param {Object} gltf A javascript object containing a glTF asset.
 * @param {Object} options The same options object as {@link processGltf}
 * @param {Object} options.dracoOptions Options defining Draco compression settings.
 * @param {Number} [options.dracoOptions.compressionLevel=7] A value between 0 and 10 specifying the quality of the Draco compression. Higher values produce better quality compression but may take longer to decompress. A value of 0 will apply sequential encoding and preserve face order.
 * @param {Number} [options.dracoOptions.quantizePositionBits=14] A value between 0 and 30 specifying the number of bits used for positions. Lower values produce better compression, but will lose precision. A value of 0 does not set quantization.
 * @param {Number} [options.dracoOptions.quantizeNormalBits=10] A value between 0 and 30 specifying the number of bits used for normals. Lower values produce better compression, but will lose precision. A value of 0 does not set quantization.
 * @param {Number} [options.dracoOptions.quantizeTexcoordBits=12] A value between 0 and 30 specifying the number of bits used for texture coordinates. Lower values produce better compression, but will lose precision. A value of 0 does not set quantization.
github AnalyticalGraphicsInc / gltf-pipeline / specs / lib / removePipelineExtrasSpec.js View on Github external
'use strict';
const Cesium = require('cesium');
const addPipelineExtras = require('../../lib/addPipelineExtras');
const removePipelineExtras = require('../../lib/removePipelineExtras');

const WebGLConstants = Cesium.WebGLConstants;

describe('removePipelineExtras', () => {
    it('removes pipeline extras', () => {
        const gltf = {
            buffers: [
                {
                    byteLength: 100
                }
            ],
            extensions: {
                KHR_techniques_webgl: {
                    shaders: [
                        {
                            type: WebGLConstants.VERTEX_SHADER,
                            uri: 'data:,'
                        }
github AnalyticalGraphicsInc / gltf-pipeline / specs / lib / addPipelineExtrasSpec.js View on Github external
'use strict';
const Cesium = require('cesium');
const addPipelineExtras = require('../../lib/addPipelineExtras');

const WebGLConstants = Cesium.WebGLConstants;

describe('addPipelineExtras', () => {
    it('adds pipeline extras to glTF 1.0 assets', () => {
        const gltf = {
            buffers: {
                sampleBuffer0: {
                    byteLength: 100
                }
            },
            shaders: {
                sample0VS: {
                    type: WebGLConstants.VERTEX_SHADER,
                    uri: 'data:,'
                }
            },
            images: {
github AnalyticalGraphicsInc / gltf-pipeline / specs / lib / octEncodeNormalsSpec.js View on Github external
'use strict';
var Cesium = require('cesium');
var AttributeCompression = Cesium.AttributeCompression;
var Cartesian2 = Cesium.Cartesian2;
var Cartesian3 = Cesium.Cartesian3;
var WebGLConstants = Cesium.WebGLConstants;
var octEncodeNormals = require('../../lib/octEncodeNormals');

describe('octEncodeNormals', function() {
   it('oct-encodes normals', function(done) {
       var normals = new Float32Array([1.0, 0.0, 0.0,
                                       0.0, 1.0, 0.0,
                                       0.0, 0.0, 1.0]);
       var normalBuffer = Buffer.from(normals.buffer.slice(0));
       var gltf = {
           accessors : {
               normalAccessor : {
                   byteOffset : 0,
                   byteStride : 0,
                   bufferView : 'bufferView',
                   componentType : WebGLConstants.FLOAT,
                   count : 3,
github AnalyticalGraphicsInc / gltf-pipeline / specs / lib / getAccessorByteStrideSpec.js View on Github external
'use strict';
const Cesium = require('cesium');
const getAccessorByteStride = require('../../lib/getAccessorByteStride');

const WebGLConstants = Cesium.WebGLConstants;

describe('getAccessorByteStride', () => {
    it('gets accessor byte stride', () => {
        const gltf = {
            accessors: [
                {
                    componentType: WebGLConstants.FLOAT,
                    count: 24,
                    type: 'VEC3',
                    min: [-1.0, -1.0, -1.0],
                    max: [1.0, 1.0, 1.0]
                },
                {
                    bufferView: 0,
                    componentType: WebGLConstants.FLOAT,
                    count: 24,
github AnalyticalGraphicsInc / gltf-pipeline / lib / byteLengthForComponentType.js View on Github external
'use strict';
var Cesium = require('cesium');

var WebGLConstants = Cesium.WebGLConstants;

module.exports = byteLengthForComponentType;

/**
 * Utility function for retrieving the byte length of a component type.
 * As per the spec:
 *     5120 (BYTE)           : 1
 *     5121 (UNSIGNED_BYTE)  : 1
 *     5122 (SHORT)          : 2
 *     5123 (UNSIGNED_SHORT) : 2
 *     5126 (FLOAT)          : 4
 *
 * Allowed by extension:
 *     5125 (UNSIGNED_INT)   : 4
 *
 * @param {Number} [componentType]
github AnalyticalGraphicsInc / gltf-pipeline / specs / lib / MergeDuplicatePropertiesSpec.js View on Github external
'use strict';
var Cesium = require('cesium');
var clone = require('clone');

var MergeDuplicateProperties = require('../../lib/MergeDuplicateProperties');

var WebGLConstants = Cesium.WebGLConstants;

describe('MergeDuplicateProperties', function() {
    var mergeAccessors = MergeDuplicateProperties.mergeAccessors;
    describe('mergeAccessors', function() {
        var testGltf = {
            accessors: {
                accessorA: {
                    bufferView: 'bufferView',
                    byteOffset: 0,
                    byteStride: 0,
                    componentType: WebGLConstants.BYTE,
                    count: 3,
                    type: 'SCALAR'
                },
                accessorB: {
                    bufferView: 'bufferView',
github AnalyticalGraphicsInc / gltf-pipeline / lib / compressTexture.js View on Github external
var Jimp = require('jimp');
var os = require('os');
var path = require('path');
var Promise = require('bluebird');
var uuid = require('uuid');
var getImageExtension = require('./getImageExtension');
var getTempDirectory = require('./getTempDirectory');

Jimp.prototype.getBufferAsync = Promise.promisify(Jimp.prototype.getBuffer);

var CesiumMath = Cesium.Math;
var combine = Cesium.combine;
var defaultValue = Cesium.defaultValue;
var defined = Cesium.defined;
var DeveloperError = Cesium.DeveloperError;
var WebGLConstants = Cesium.WebGLConstants;

module.exports = compressTexture;

var pvrTexToolExtensions = ['.jpeg', '.jpg', '.png', '.bmp'];
var etc2compExtensions = ['.png'];
var crunchExtensions = ['.jpeg', '.jpg', '.png', '.bmp'];
var astcencExtensions = ['.jpeg', '.jpg', '.png', '.bmp', '.gif'];

var compressToolDirectory = path.join(__dirname, '../bin/', os.platform());
var pvrTexToolPath = path.join(compressToolDirectory, 'PVRTexToolCLI');
var etc2compPath = path.join(compressToolDirectory, 'EtcTool');
var crunchPath = path.join(compressToolDirectory, 'crunch');
var astcencPath = path.join(compressToolDirectory, 'astcenc');

var formats = ['pvrtc1', 'pvrtc2', 'etc1', 'etc2', 'astc', 'dxt1', 'dxt3', 'dxt5', 'crunch-dxt1', 'crunch-dxt5'];
var astcBlockSizes = ['4x4', '5x4', '5x5', '6x5', '6x6', '8x5', '8x6', '8x8', '10x5', '10x6', '10x8', '10x10', '12x10', '12x12'];
github AnalyticalGraphicsInc / gltf-pipeline / lib / octEncodeNormals.js View on Github external
'use strict';
var Cesium = require('cesium');
var byteLengthForComponentType = require('./byteLengthForComponentType');
var findAccessorMinMax = require('./findAccessorMinMax');
var ForEach = require('./ForEach');
var getAccessorByteStride = require('./getAccessorByteStride');
var numberOfComponentsForType = require('./numberOfComponentsForType');
var readBufferComponent = require('./readBufferComponent');
var writeBufferComponent = require('./writeBufferComponent');

var AttributeCompression = Cesium.AttributeCompression;
var Cartesian2 = Cesium.Cartesian2;
var Cartesian3 = Cesium.Cartesian3;
var DeveloperError = Cesium.DeveloperError;
var ShaderSource = Cesium.ShaderSource;
var WebGLConstants = Cesium.WebGLConstants;
var defined = Cesium.defined;

module.exports = octEncodeNormals;

/**
 * Oct-encodes the normal vectors of this model, converting each normal vector from three floating point numbers
 * down to two bytes. Modifies the model shader for decoding.
 *
 * The glTF asset must be initialized for the pipeline.
 *
 * @param {Object} gltf A glTF hierarchy.
 * @returns {Object} The glTF asset with oct-encoded normals when the operation completes.
 *
 * @see addPipelineExtras
 * @see loadGltfUris
 */