-
Notifications
You must be signed in to change notification settings - Fork 250
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
Export public API via index.js #157
Changes from all commits
5524a73
863be07
0f6298d
da16e7b
ef85de6
6b66d6f
0b22358
a880aab
8d43261
c58e5de
545fce1
c5bf895
4bf4745
c752a1a
0c9d382
5687191
d3c8e01
3395a4f
a64d119
9f292b5
404401b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,43 @@ | ||
module.exports = { | ||
gltfPipeline : require('./lib/gltfPipeline'), | ||
AccessorReader : require('./lib/AccessorReader'), | ||
addCesiumRTC : require('./lib/addCesiumRTC'), | ||
addDefaults : require('./lib/addDefaults'), | ||
addExtensionsUsed : require('./lib/addExtensionsUsed'), | ||
addPipelineExtras : require('./lib/addPipelineExtras'), | ||
bakeAmbientOcclusion : require('./lib/bakeAmbientOcclusion'), | ||
byteLengthForComponentType : require('./lib/byteLengthForComponentType'), | ||
combineMeshes : require('./lib/combineMeshes'), | ||
combineNodes : require('./lib/combineNodes'), | ||
compressIntegerAccessors : require('./lib/compressIntegerAccessors'), | ||
compressTextureCoordinates : require('./lib/compressTextureCoordinates'), | ||
convertDagToTree : require('./lib/convertDagToTree'), | ||
encodeImages : require('./lib/encodeImages'), | ||
findAccessorMinMax : require('./lib/findAccessorMinMax'), | ||
generateNormals : require('./lib/generateNormals'), | ||
getAccessorByteStride : require('./lib/getAccessorByteStride'), | ||
getBinaryGltf : require('./lib/getBinaryGltf'), | ||
getUniqueId : require('./lib/getUniqueId'), | ||
loadGltfUris : require('./lib/loadGltfUris'), | ||
mergeBuffers : require('./lib/mergeBuffers'), | ||
mergeDuplicateAccessors : require('./lib/mergeDuplicateAccessors'), | ||
mergeDuplicateVertices : require('./lib/mergeDuplicateVertices'), | ||
numberOfComponentsForType : require('./lib/numberOfComponentsForType'), | ||
octEncodeNormals : require('./lib/octEncodeNormals'), | ||
optimizeForVertexCache : require('./lib/optimizeForVertexCache'), | ||
packArray : require('./lib/packArray'), | ||
parseBinaryGltf : require('./lib/parseBinaryGltf'), | ||
Pipeline : require('./lib/Pipeline'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this correct? Shouldn't the capitalization put this first? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I didn't know that was a common thing to do. If so I'll correct it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mramato, I can't find a point of reference for this. Which way should this go? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't really matter in this case. Since this won't be auto-sorted, whatever you guys want to do is fine. |
||
quantizeAttributes : require('./lib/quantizeAttributes'), | ||
readAccessor : require('./lib/readAccessor'), | ||
readBufferComponent : require('./lib/readBufferComponent'), | ||
readGltf : require('./lib/readGltf'), | ||
removeDuplicatePrimitives : require('./lib/removeDuplicatePrimitives'), | ||
removePipelineExtras : require('./lib/removePipelineExtras'), | ||
RemoveUnusedProperties : require('./lib/RemoveUnusedProperties'), | ||
removeUnusedVertices : require('./lib/removeUnusedVertices'), | ||
uninterleaveAndPackBuffers : require('./lib/uninterleaveAndPackBuffers'), | ||
writeAccessor : require('./lib/writeAccessor'), | ||
writeBinaryGltf : require('./lib/writeBinaryGltf'), | ||
writeBufferComponent : require('./lib/writeBufferComponent'), | ||
writeGltf : require('./lib/writeGltf') | ||
}; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main problem with exposing a lot of these functions is that they may rely on previous steps, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be enough to just put the dependencies in the doc until we work out custom pipelines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think that's ok for now. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,24 @@ var defaultValue = Cesium.defaultValue; | |
var byteLengthForComponentType = require('./byteLengthForComponentType'); | ||
var getAccessorByteStride = require('./getAccessorByteStride'); | ||
var numberOfComponentsForType = require('./numberOfComponentsForType'); | ||
var readBufferComponentType = require('./readBufferComponentType'); | ||
var writeBufferComponentType = require('./writeBufferComponentType'); | ||
var readBufferComponent = require('./readBufferComponent'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I used the JetBrains refactor tool and it must have missed those. |
||
var writeBufferComponent = require('./writeBufferComponent'); | ||
|
||
module.exports = AccessorReader; | ||
|
||
/** | ||
* Reads an accessor incrementally. This is useful to keep overhead low when | ||
* memory consumption is important. | ||
* | ||
* The glTF asset must be initialized for the pipeline. | ||
* | ||
* @param {Object} gltf A javascript object containing a glTF asset. | ||
* @param {Object} accessor The accessor object from glTF to read. | ||
* @constructor | ||
* | ||
* @see addPipelineExtras | ||
* @see loadGltfUris | ||
*/ | ||
function AccessorReader(gltf, accessor) { | ||
var bufferViews = gltf.bufferViews; | ||
var buffers = gltf.buffers; | ||
|
@@ -30,13 +43,21 @@ function AccessorReader(gltf, accessor) { | |
this.source = buffer.extras._pipeline.source; | ||
} | ||
|
||
/** | ||
* Read data at the current index into components. | ||
* Data will be read into components starting at index 0. | ||
* Components will be grown if the number of components for the accessor is greater than the array size. | ||
* | ||
* @param {Array} components The array to read the data into. | ||
* @returns {Array} components with data written into it. | ||
*/ | ||
AccessorReader.prototype.read = function(components) { | ||
if (this.index >= this.count) { | ||
return undefined; | ||
} | ||
var componentByteLength = byteLengthForComponentType(this.componentType); | ||
for (var i = 0; i < this.numberOfComponents; i++) { | ||
var data = readBufferComponentType(this.source, | ||
var data = readBufferComponent(this.source, | ||
this.componentType, | ||
this.byteOffset + (this.byteStride * this.index) + (componentByteLength * i) | ||
); | ||
|
@@ -49,6 +70,16 @@ AccessorReader.prototype.read = function(components) { | |
return components; | ||
}; | ||
|
||
/** | ||
* Write data at the current index into the accessor data. | ||
* Specifying a componentType different from the accessor's componentType can be done for a use case like attribute compression. | ||
* The data is being read, compressed, and then written back as a different, smaller data type. This is done in place | ||
* and then the gaps can be removed using uninterleaveAndPackBuffers. | ||
* | ||
* @param {Array} data The data to write into the accessor. | ||
* @param {Number} [componentType=this.componentType] The component type to use for writing the data. | ||
* @param {Number} [dataOffset=0] Read starting from a different position in the data array. | ||
*/ | ||
AccessorReader.prototype.write = function(data, componentType, dataOffset) { | ||
componentType = defaultValue(componentType, this.componentType); | ||
dataOffset = defaultValue(dataOffset, 0); | ||
|
@@ -58,22 +89,33 @@ AccessorReader.prototype.write = function(data, componentType, dataOffset) { | |
byteStride = byteLengthForComponentType(componentType) * this.numberOfComponents; | ||
} | ||
for (var i = 0; i < this.numberOfComponents; i++) { | ||
writeBufferComponentType(this.source, | ||
writeBufferComponent(this.source, | ||
componentType, | ||
data[i + dataOffset], | ||
this.byteOffset + (byteStride * this.index) + (componentByteLength * i) | ||
); | ||
} | ||
}; | ||
|
||
/** | ||
* Get if the AccessorReader is at the end of the accessor data. | ||
* | ||
* @returns {Boolean} True if there is more data to read, false if not. | ||
*/ | ||
AccessorReader.prototype.hasNext = function() { | ||
return this.index < this.count; | ||
}; | ||
|
||
/** | ||
* Increment AccessorReader.index by one. | ||
*/ | ||
AccessorReader.prototype.next = function() { | ||
this.index++; | ||
}; | ||
|
||
/** | ||
* Set AccessorReader.index to zero. | ||
*/ | ||
AccessorReader.prototype.reset = function() { | ||
this.index = 0; | ||
}; |
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.
In there a reason we just don't just
module.exports = require('./lib');
here instead of requiring every object individually?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.
There are some files we don't export.
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 think manually maintaining this list could be error prone and easy to forget about. Some other options would be to have a
private
folder at the same level oflib
to make the decision more conscious during development; or you could just export everything and mark private objects@private
.That being said, I'm okay if you go the manual route until it becomes a pain.