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

Interpolate custom vertex attributes on triangles crossing the IDL #6644

Merged

Conversation

likangning93
Copy link
Contributor

@likangning93 likangning93 commented May 31, 2018

Fixes #4739.

Looks like #1894 is going to be a little more involved though, because the "custom" attributes on polylines probably can't be generically interpolated. Might have to do something similar to the current plan for polylines on terrain (#6615) which is going to create geometry that's already split across the IDL.
It's trickier for standard polylines though because a model matrix may be involved...

@cesium-concierge
Copy link

Signed CLA is on file.

@likangning93, thanks for the pull request! Maintainers, we have a signed CLA from @likangning93, 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.

🌍 🌎 🌏

@likangning93 likangning93 force-pushed the customVertexAttribsTrianglesIDL branch from 1e77d98 to a76957d Compare May 31, 2018 19:41
@likangning93
Copy link
Contributor Author

Thanks buddy, I updated CHANGES and then force-pushed to cover my shaaaame

var customAttributeNames = [];
for (var attributeName in attributes) {
if (attributes.hasOwnProperty(attributeName)) {
if (!NAMED_ATTRIBUTES[attributeName] && defined(attributes[attributeName])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be an && instead of a nested if

@@ -2106,7 +2150,7 @@ define([
}

insertedIndex = insertSplitPoint(currentAttributes, currentIndices, currentIndexMap, indices, resultIndex < 3 ? i + resultIndex : -1, point);
computeTriangleAttributes(i0, i1, i2, point, positions, normals, tangents, bitangents, texCoords, extrudeDirections, currentAttributes, insertedIndex);
computeTriangleAttributes(i0, i1, i2, point, positions, normals, tangents, bitangents, texCoords, extrudeDirections, currentAttributes, customAttributeNames, customAttributesLength, attributes, insertedIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're changing this code around anyway, can we make this an options instead of having 50 parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought the gazillion parameters thing might have been an attempt at increasing performance for a hot area of code by avoiding dictionary access.

If that were true the custom attributes code would be "slow," but I think it's acceptable since the geometry that triggers this shouldn't have as much triangle density.

Copy link
Contributor

Choose a reason for hiding this comment

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

Normally I would agree with @hpinkos but since this a local private function only called in a few places; I'm not sure turning it into an options object buys us anything in terms of code clarity/easy of maintenance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, yeah this is fine then

@hpinkos
Copy link
Contributor

hpinkos commented Jun 4, 2018

Overall this looks really good @likangning93! @bagnell do you have any additional feedback?

@@ -1919,13 +1919,46 @@ define([
var p0Scratch = new Cartesian3();
var p1Scratch = new Cartesian3();
var p2Scratch = new Cartesian3();
var barycentricScratch = new Cartesian3();
function interpolateAndPackCartesian3(i0, i1, i2, coords, sourceValues, currentValues, insertedIndex, normalize) {
Copy link
Contributor

@bagnell bagnell Jun 4, 2018

Choose a reason for hiding this comment

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

Since this and the below function only differ with the cartesian type and the number of components, why not generate them?

function generateInterpolateFunction(cartesian, numberOfComponents) {
    var p0Scratch = new cartesian();
    // ...
    return function(i0, i1, /*...*/) {
        var p0 = cartesian.fromArray(sourceValues, i0 * numberOfComponents, p0Scratch);
        // ...
    };
}
var interpolateAndPackCartesian3 = generateInterpolateFunction(Carteisan3, 3);

Copy link
Contributor

Choose a reason for hiding this comment

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

@mramato Does this impact performance? If so, it might be fine since this most likely only gets executed in a web worker.

Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming we're not constantly regenerating the function over and over, then performance should be the same.

var currentValues = currentAttribute.values;
switch(componentsPerAttribute) {
case 4:
var q0 = Cartesian4.fromArray(sourceValues, i0 * 4, q0Scratch);
Copy link
Contributor

Choose a reason for hiding this comment

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

You could generate this code with the function mentioned above.

@bagnell
Copy link
Contributor

bagnell commented Jun 4, 2018

Just have the one comment. The rest looks good.

@likangning93
Copy link
Contributor Author

@hpinkos @bagnell this up-to-date.

@bagnell bagnell merged commit 6fdf2b7 into CesiumGS:master Jun 5, 2018
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.

5 participants