@@ -193,17 +193,22 @@ Object.defineProperties(TextureAtlas.prototype, {
193193} ) ;
194194
195195/**
196- * Get integer pixel coordinates for a given image or image region .
196+ * Get the texture coordinates for reading the associated image in shaders .
197197 * @param {number } index The index of the image region.
198198 * @param {BoundingRectangle } [result] The object into which to store the result.
199199 * @return {BoundingRectangle } The modified result parameter or a new BoundingRectangle instance if one was not provided.
200200 * @private
201+ * @example
202+ * const index = await atlas.addImage("myImage", image);
203+ * const rectangle = atlas.computeTextureCoordinates(index);
204+ * BoundingRectangle.pack(rectangle, bufferView);
201205 */
202- TextureAtlas . prototype . computePixelCoordinates = function ( index , result ) {
206+ TextureAtlas . prototype . computeTextureCoordinates = function ( index , result ) {
203207 //>>includeStart('debug', pragmas.debug);
204208 Check . typeOf . number . greaterThanOrEquals ( "index" , index , 0 ) ;
205209 //>>includeEnd('debug');
206210
211+ const texture = this . _texture ;
207212 const rectangle = this . _rectangles [ index ] ;
208213
209214 if ( ! defined ( result ) ) {
@@ -219,6 +224,9 @@ TextureAtlas.prototype.computePixelCoordinates = function (index, result) {
219224 return result ;
220225 }
221226
227+ const atlasWidth = texture . width ;
228+ const atlasHeight = texture . height ;
229+
222230 const width = rectangle . width ;
223231 const height = rectangle . height ;
224232 let x = rectangle . x ;
@@ -232,36 +240,10 @@ TextureAtlas.prototype.computePixelCoordinates = function (index, result) {
232240 y += parentRectangle . y ;
233241 }
234242
235- result . x = x ;
236- result . y = y ;
237- result . width = width ;
238- result . height = height ;
239-
240- return result ;
241- } ;
242-
243- /**
244- * Get the texture coordinates for reading the associated image in shaders.
245- * @param {number } index The index of the image region.
246- * @param {BoundingRectangle } [result] The object into which to store the result.
247- * @return {BoundingRectangle } The modified result parameter or a new BoundingRectangle instance if one was not provided.
248- * @private
249- * @example
250- * const index = await atlas.addImage("myImage", image);
251- * const rectangle = atlas.computeTextureCoordinates(index);
252- * BoundingRectangle.pack(rectangle, bufferView);
253- */
254- TextureAtlas . prototype . computeTextureCoordinates = function ( index , result ) {
255- result = this . computePixelCoordinates ( index , result ) ;
256-
257- const texture = this . _texture ;
258- const atlasWidth = texture . width ;
259- const atlasHeight = texture . height ;
260-
261- result . x /= atlasWidth ;
262- result . y /= atlasHeight ;
263- result . width /= atlasWidth ;
264- result . height /= atlasHeight ;
243+ result . x = x / atlasWidth ;
244+ result . y = y / atlasHeight ;
245+ result . width = width / atlasWidth ;
246+ result . height = height / atlasHeight ;
265247
266248 return result ;
267249} ;
0 commit comments