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

Web3d quantized attributes #3891

Merged
merged 63 commits into from
Jun 30, 2016

Conversation

lasalvavida
Copy link
Contributor

@lasalvavida lasalvavida commented May 2, 2016

This pull request is for reviewing an initial implementation of the WEB3D_quantized_attributes extension to glTF.

There are still a few issues to be resolved both in this implementation and the proposed specification. Feel free to try it out with the included sample model; comments and suggestions are welcome.


TODO

@pjcozzi
Copy link
Contributor

pjcozzi commented May 5, 2016

Update CHANGES.md

LoadResources.prototype.getDecodedBuffer = function(bufferView, decodeBufferAccessors) {
var bufferData = new Uint8Array(0);
var byteShift = 0;
for (var i in decodeBufferAccessors) {
Copy link
Contributor

Choose a reason for hiding this comment

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

With for...in, we always use if (decodeBufferAccessors.hasOwnProperty(i)) {. Maybe it's OK without in this case, but I would rather be consistent.

@pjcozzi
Copy link
Contributor

pjcozzi commented May 5, 2016

Can you include a brief README.md in Specs/Data/Models/Box-Quantized that says this is the box model, but modified so the position and normal attributes are quantized?

@pjcozzi
Copy link
Contributor

pjcozzi commented May 5, 2016

Does the extension spec say anything any quantizing accessors that are used for indices? To keep the implementation simple, it should say that the accessor must only be used for attributes.

var index = 0;
for (var j = 0; j < chunkData.length; j += 2*numComponents) {
for (var k = 0; k < numComponents; k++) {
var encodedValue = (chunkData[j + k*2 + 1] << 8) + chunkData[j + k*2];
Copy link
Contributor

Choose a reason for hiding this comment

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

Throughout, use parentheses instead of no whitespace, e.g., (k * 2).

@lasalvavida
Copy link
Contributor Author

@pjcozzi Will add a README, and yes quantization is only to be used on attributes. I'm currently working on implementing some of the feedback from @mlimper and @MarcoHutter on the glTF issue I opened.

var bufferViews = model.gltf.bufferViews;

var accessorsForBufferViewId = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably put this in its own function that returns accessorsForBufferViewId. See Statements in a function should be at a similar level of abstraction... here.

@lasalvavida
Copy link
Contributor Author

Most specifically, the approach is going to change from unpacking the buffers, to just applying the decodeMatrix to the model matrix and leaving the data as-is, which should be faster and less complicated.

} else {
var inserted = false;
var bufferViewAccessors = accessorsForBufferViewId[bufferViewId];
for (var j in bufferViewAccessors) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same hasOwnProperty comment here and throughout if it is missing anywhere else.

@pjcozzi
Copy link
Contributor

pjcozzi commented May 5, 2016

Most specifically, the approach is going to change from unpacking the buffers, to just applying the decodeMatrix to the model matrix and leaving the data as-is, which should be faster and less complicated.

Yes, exactly!

@pjcozzi
Copy link
Contributor

pjcozzi commented May 5, 2016

Let me know when this is ready for another review.

@lasalvavida
Copy link
Contributor Author

lasalvavida commented May 6, 2016

This update takes in some suggestions from this thread.

In this approach, the model shader is modified to decode the attributes and use the decoded version in places where the original was used. This may not be the best approach, and I am open to suggestions.

In my first go at this, I had tried applying the decode matrix to the model matrix directly to avoid modifying the shaders. It think this is better because it allows for attributes to be quantized or not with the same model matrix with no issues.

@pjcozzi
Copy link
Contributor

pjcozzi commented May 10, 2016

There are jsHint warnings; check the CI - https://travis-ci.org/AnalyticalGraphicsInc/cesium/builds/128397413

@pjcozzi
Copy link
Contributor

pjcozzi commented May 10, 2016

Did you see these comments: #3891 (comment) and #3891 (comment)?

return val.toFixed(16);
});

var newMain = "decoded_" + attributeSemantic;
Copy link
Contributor

Choose a reason for hiding this comment

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

Throughout, use ' instead of ".

@pjcozzi
Copy link
Contributor

pjcozzi commented May 10, 2016

Remind me - what attributes did you test this with? Positions? Or positions and normals?

var matrixName = "decode_" + attributeSemantic + "_matrix";
var decodedAttributeVarName = attributeVarName.replace('a_', 'dec_');

// replace usages of the original attribute with the decoded version, but not the declaration
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know much about regexs, but I suspect there is an easier way to do this. @tfili would know.

Copy link
Contributor

Choose a reason for hiding this comment

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

You would use a negative lookbehind. Something like (?<!vec3 )a_var would match all occurences of a_var what weren't preceded by vec3. However looking it appears that this isn't supported in javascript. You may be stuck doing it this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was the problem I ran into. It does need to do something differently because the current method sets off jshint, but as of right now I don't have a better answer

@pjcozzi
Copy link
Contributor

pjcozzi commented May 10, 2016

In my first go at this, I tried applying the decode matrix to the model matrix directly to avoid modifying the shaders. It think this is better because it allows for attributes to be quantized or not with the same model matrix with no issues.

Let's discuss in person today. There are trade-off to think through, including precision and animations.

@lasalvavida
Copy link
Contributor Author

@pjcozzi Updated. The MilkTruck mismatch model now has mismatched VEC4 - POSITION, VEC3 - NORMAL, and VEC2 - TEXCOORD which covers all mismatched cases. Code coverage confirms this.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 6, 2016

@mlimper once again, thanks so much for the review! It is deeply appreciated.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 6, 2016

@lasalvavida test coverage and everything else look great! I added a task list to the top of this issue so that we'll merge this when other dependencies are merged.

This will ship in Cesium 1.23 no problem!

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 10, 2016

@lasalvavida merge master. There is probably a trivial conflict in CHANGES.md.

@lasalvavida
Copy link
Contributor Author

Will do. I'm also going to quickly add a simple Box test for SCALAR attributes.

@lasalvavida
Copy link
Contributor Author

Updated

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 10, 2016

Nice! This is close. We just need:

  • Add checkbox to online model converter

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 18, 2016

@lasalvavida can you merge in master? There is probably a trivial conflict in CHANGES.md.

@lasalvavida
Copy link
Contributor Author

@pjcozzi The checkbox has been added. This should be good to merge whenever you're ready.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 28, 2016

@pjcozzi The checkbox has been added. This should be good to merge whenever you're ready.

I tested with the Cesium aircraft and balloons models, and it produced the same models with and without checking the quantization box.

@lasalvavida
Copy link
Contributor Author

@pjcozzi I tried to reproduce but I actually can't get the online model converter to work at all right now. It just says An unkown error has occured.

@lilleyse
Copy link
Contributor

lilleyse commented Jun 29, 2016

I'm also seeing some errors on the page:

Cesium.js:476 Blocked script execution in 'about:blank' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.

I tested with the Cesium aircraft and balloons models, and it produced the same models with and without checking the quantization box.

That's doesn't seem right, those models are being quantized fine when I run the converter locally.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 29, 2016

@lasalvavida can you merge in master?

@lasalvavida
Copy link
Contributor Author

@pjcozzi done

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 29, 2016

Code coverage looks good!

This is most likely ready to merge, but I want to wait for CesiumGS/gltf-pipeline#97 (comment) and CesiumGS/gltf-pipeline#97 (comment) in case they reveal any issues in Cesium.

@pjcozzi pjcozzi merged commit e6aba2f into CesiumGS:master Jun 30, 2016
@pjcozzi pjcozzi deleted the web3d-quantized-attributes branch June 30, 2016 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants