cesium icon indicating copy to clipboard operation
cesium copied to clipboard

Polyline material with texture failure

Open ateshuseyin opened this issue 9 years ago • 0 comments

We want to develop a material which have texture uniform for a polyline. But cesium crush with an error message "TypeError: cyclic object value createMaterialId@........". Texture objects have cyclic value and createMaterialId function in PolylineCollection computes id as below;

function createMaterialId(material) {
        var uniforms = Material._uniformList[material.type];
        var length = uniforms.length;
        scratchUniformArray.length = 2.0 * length;

        var index = 0;
        for (var i = 0; i < length; ++i) {
            var uniform = uniforms[i];
            scratchUniformArray[index] = uniform;
            scratchUniformArray[index + 1] = material._uniforms[uniform]();
            index += 2;
        }

        return material.type + ':' + JSON.stringify(scratchUniformArray);
    }

If createMaterialId will be updated as:

function createMaterialId(material) {
        var uniforms = Material._uniformList[material.type];
        var length = uniforms.length;
        scratchUniformArray.length = 2.0 * length;

        var index = 0;
        var uniformValue;
        for (var i = 0; i < length; ++i) {
            var uniform = uniforms[i];
            scratchUniformArray[index] = uniform;
            uniformValue=material._uniforms[uniform]();
            
            if(uniformValue instanceof Texture){
                scratchUniformArray[index + 1] = computeTextureId(uniformValue);
            } else {
                scratchUniformArray[index + 1] = uniformValue;
            }
            index += 2;
        }

        return material.type + ':' + JSON.stringify(scratchUniformArray);
    }

problem can be fixed

ateshuseyin avatar May 25 '17 12:05 ateshuseyin