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

Validator - check that normals are unit length #116

Closed
wants to merge 12 commits into from

Conversation

rms13
Copy link
Contributor

@rms13 rms13 commented Jul 26, 2017

Fixes #112

Checks that normals are of unit length for i3dm and pnts.
Also checks that normal up and normal right are orthogonal for i3dm.

Created a helper function in utility.js for converting an oct-encoded vector to Catresian3, like cesium's AttributeCompression.octDecodeInRange, but without normalization.

Copy link
Contributor

@lilleyse lilleyse left a comment

Choose a reason for hiding this comment

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

Looks good!

result.z = 1.0 - (Math.abs(result.x) + Math.abs(result.y));

if (result.z < 0.0)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: put on one line: if (result.z < 0.0) {

@@ -183,22 +188,89 @@ function validateI3dm(content) {
return 'Feature table property NORMAL_RIGHT is required when NORMAL_UP is present.';
}

if (defined(!featureTableJson.NORMAL_UP) && defined(featureTableJson.NORMAL_RIGHT)) {
if (!defined(featureTableJson.NORMAL_UP) && defined(featureTableJson.NORMAL_RIGHT)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catches.

var i;

if (defined(featureTableJson.NORMAL_UP)) {
featureTable.featuresLength = featuresLength * 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

Better practice is for featureTable.featuresLength to always be set to featuresLength, and then set the componentLength argument of getPropertyArray to 3.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also make any similar changes in validatePnts.


if (defined(featureTableJson.NORMAL_UP)) {
featureTable.featuresLength = featuresLength * 3;
componentDatatype = ComponentDatatype.fromName(defaultValue(featureTableJson.NORMAL_UP.componentType, 'FLOAT', 3));
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the last argument of the defaultValue.

if(octUp) {
octDecodeWithoutNormalization(normalUp[i*2], normalUp[i*2+1], 65535, normalUpVec3);
} else {
Cartesian3.fromElements(normalUp[i*3], normalUp[i*3+1], normalUp[i*3+2], normalUpVec3);
Copy link
Contributor

Choose a reason for hiding this comment

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

Cartesian3.unpack is a little cleaner to use here.


if(defined(normalUp) && defined(normalRight)) {
for(i = 0; i < featuresLength; i++) {
var normalUpVec3 = new Cartesian3();
Copy link
Contributor

Choose a reason for hiding this comment

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

Put this outside of the for loop so that we only have to allocate a Cartesian3 once.

Also rename to normalUp.

return 'normal defined in NORMAL_UP must be of length 1.0';
}
var normalRightMagnitude = Cartesian3.magnitude(normalRightVec3);
if(Math.abs(normalRightMagnitude - 1.0) > Cesium.Math.EPSILON2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Throughout for style purposes add a space like if (

@rms13
Copy link
Contributor Author

rms13 commented Aug 24, 2017

@lilleyse Should be good now!

@lilleyse lilleyse closed this Mar 14, 2020
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.

None yet

2 participants