-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Web3d quantized attributes #3891
Conversation
Update CHANGES.md |
LoadResources.prototype.getDecodedBuffer = function(bufferView, decodeBufferAccessors) { | ||
var bufferData = new Uint8Array(0); | ||
var byteShift = 0; | ||
for (var i in decodeBufferAccessors) { |
There was a problem hiding this comment.
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.
Can you include a brief README.md in |
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]; |
There was a problem hiding this comment.
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)
.
@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 = {}; |
There was a problem hiding this comment.
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.
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) { |
There was a problem hiding this comment.
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.
Yes, exactly! |
Let me know when this is ready for another review. |
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. |
There are jsHint warnings; check the CI - https://travis-ci.org/AnalyticalGraphicsInc/cesium/builds/128397413 |
Did you see these comments: #3891 (comment) and #3891 (comment)? |
return val.toFixed(16); | ||
}); | ||
|
||
var newMain = "decoded_" + attributeSemantic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throughout, use '
instead of "
.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Let's discuss in person today. There are trade-off to think through, including precision and animations. |
@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. |
@mlimper once again, thanks so much for the review! It is deeply appreciated. |
@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! |
@lasalvavida merge master. There is probably a trivial conflict in CHANGES.md. |
Will do. I'm also going to quickly add a simple Box test for SCALAR attributes. |
Updated |
Nice! This is close. We just need:
|
@lasalvavida can you merge in master? There is probably a trivial conflict in CHANGES.md. |
… web3d-quantized-attributes
… web3d-quantized-attributes
… web3d-quantized-attributes
… web3d-quantized-attributes
I tested with the Cesium aircraft and balloons models, and it produced the same models with and without checking the quantization box. |
… web3d-quantized-attributes
@pjcozzi I tried to reproduce but I actually can't get the online model converter to work at all right now. It just says |
I'm also seeing some errors on the page:
That's doesn't seem right, those models are being quantized fine when I run the converter locally. |
@lasalvavida can you merge in master? |
… web3d-quantized-attributes
@pjcozzi done |
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. |
… web3d-quantized-attributes
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