Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to unset image uniform for Material #9385

Closed
nmschulte-aviture opened this issue Feb 17, 2021 · 1 comment · Fixed by #9644
Closed

Unable to unset image uniform for Material #9385

nmschulte-aviture opened this issue Feb 17, 2021 · 1 comment · Fixed by #9644

Comments

@nmschulte-aviture
Copy link
Contributor

It seems not possible to "unset" the image uniform for a Material.

Just as I can create a Material with image: undefined, I expect I can set image = undefined to achieve the same state.
However, it seems setting image = Cesium.Material.DefaultImageId ('czm_defaultImage') does not work either; nothing can achieve this, the only work-around is to create a new Material (and destroy the old one).

See the following demo (paste into Sandcastle):

var viewer = new Cesium.Viewer("cesiumContainer");
var scene = viewer.scene;
var rectangle = scene.primitives.add(
  new Cesium.Primitive({
    geometryInstances: new Cesium.GeometryInstance({
      geometry: new Cesium.RectangleGeometry({
        rectangle: Cesium.Rectangle.fromDegrees(
          -120.0,
          20.0,
          -60.0,
          40.0
        ),
        vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
      }),
    }),
    appearance: new Cesium.MaterialAppearance({
      flat: true,
      material: Cesium.Material.fromType(Cesium.Material.ImageType, {
        // image: '../images/Cesium_Logo_Color.jpg',
        // image: '../images/checkerboard.png',
        image: undefined,
        color: Cesium.Color.RED.withAlpha(0.5),
      }),
    }),
  })
);

Sandcastle.addToolbarButton('"Cesium_Logo_Color.jpg"', function() {
  rectangle.appearance.material.uniforms.image = '../images/Cesium_Logo_Color.jpg';
});
Sandcastle.addToolbarButton('undefined', function() {
  rectangle.appearance.material.uniforms.image = undefined;
});
Sandcastle.addToolbarButton('Cesium.Material.DefaultImageId', function() {
  rectangle.appearance.material.uniforms.image = Cesium.Material.DefaultImageId;
});
Sandcastle.addToolbarButton('"czm_defaultImage"', function() {
  rectangle.appearance.material.uniforms.image = 'czm_defaultImage';
});
Sandcastle.addToolbarButton('""', function() {
  rectangle.appearance.material.uniforms.image = '';
});
Sandcastle.addToolbarButton('"does_not_exist"', function() {
  rectangle.appearance.material.uniforms.image = 'does_not_exist';
});
Sandcastle.addToolbarButton('"checkerboard.png"', function() {
  rectangle.appearance.material.uniforms.image = '../images/checkerboard.png';
});
@dzungpng
Copy link
Contributor

I can confirm that this is the current behavior. It would make more sense if setting image to undefined removes the previous image from the geometry.

I made this Sandcastle which could be a potential workaround: link. Although it also removes the base color of the geometry and setting base color to RED again does not seem to have an effect. I tried setting requestRenderMode = true and call requestRender after setting the image to undefined but that did not help.

This might be related to an older issue here: #5080

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants