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

Fix geometry entity with dynamic color #6245

Merged
merged 3 commits into from
Feb 22, 2018
Merged

Fix geometry entity with dynamic color #6245

merged 3 commits into from
Feb 22, 2018

Conversation

hpinkos
Copy link
Contributor

@hpinkos hpinkos commented Feb 21, 2018

  • Fixes dynamic color when the result parameter is not used
  • Fixes dynamic depth fail color
var viewer = new Cesium.Viewer('cesiumContainer');
viewer.scene.globe.depthTestAgainstTerrain = true;

var lineColor = Cesium.Color.RED;
var depthColor = Cesium.Color.BLUE;

var redLine = viewer.entities.add({
    polyline : {
        positions : Cesium.Cartesian3.fromDegreesArray([-75, 35,
                                                        -125, 35]),
        width : 5,
        followSurface : false,
        material : new Cesium.ColorMaterialProperty(new Cesium.CallbackProperty(function() {
                        return lineColor;
                    }, false)),
        depthFailMaterial : new Cesium.ColorMaterialProperty(new Cesium.CallbackProperty(function() {
                        return depthColor;
                    }, false))
    }
});

Sandcastle.addToolbarButton('Button', function() {
    lineColor = Cesium.Color.ORANGE;
    depthColor = Cesium.Color.PURPLE;
});

viewer.zoomTo(viewer.entities);

@cesium-concierge
Copy link

Signed CLA is on file.

@hpinkos, thanks for the pull request! Maintainers, we have a signed CLA from @hpinkos, so you can review this at any time.

⚠️ I noticed that CHANGES.md has not been updated. If this change updates the public API in any way, fixes a bug, or makes any non-trivial update, please add a bullet point to CHANGES.md and comment on this pull request so we know it was updated. For more info, see the Pull Request Guidelines.


I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

if (!Color.equals(attributes._lastColor, colorScratch)) {
attributes._lastColor = Color.clone(colorScratch, attributes._lastColor);
attributes.color = ColorGeometryInstanceAttribute.toValue(colorScratch, attributes.color);
var resultColor = colorProperty.getValue(time, colorScratch);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a perfect example for why I think we should always prefer

var result = someFunction(resultParameter)
// do more things with result

instead of

someFunction(resultParameter);
//do more things with resultParameter

I think it makes the code easier to follow for someone who is not used to how we use result parameters, and it avoids mistakes like this where the result parameter might not actually be used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you. I think this is in our coding guide, can you check and open a PR if not? Thanks.

@mramato
Copy link
Contributor

mramato commented Feb 21, 2018

Does this fix #5371?

@hpinkos
Copy link
Contributor Author

hpinkos commented Feb 21, 2018

Does this fix #5371?

Nope

@hpinkos
Copy link
Contributor Author

hpinkos commented Feb 22, 2018

@ggetz can you review?

@mramato
Copy link
Contributor

mramato commented Feb 22, 2018

I have a feeling there are quite a few random bugs that this will fix, whether we know it now or not.

@mramato mramato merged commit dd17f3c into master Feb 22, 2018
@mramato mramato deleted the fix-dynamic-colors branch February 22, 2018 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants