-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix billboard subregion not displayed #12958
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
Changes from 13 commits
0c9a523
3363ee8
981e206
cae6a02
452dd19
08ecab0
5d00fca
6f1349b
f73f2f2
1d6d5e6
4ed382f
829a768
84890e6
85fabf5
d34e3cc
55b2ba8
9b42731
034653c
e6ac78f
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 |
|---|---|---|
|
|
@@ -251,23 +251,67 @@ BillboardTexture.prototype.loadImage = async function (id, image) { | |
| * @param {string} id An identifier to detect whether the image already exists in the atlas. | ||
| * @param {BoundingRectangle} subRegion An {@link BoundingRectangle} defining a region of an existing image, measured in pixels from the bottom-left of the image. | ||
| */ | ||
| BillboardTexture.prototype.addImageSubRegion = async function (id, subRegion) { | ||
| BillboardTexture.prototype.addImageSubRegion = function (id, subRegion) { | ||
| this._id = id; | ||
| this._loadState = BillboardLoadState.LOADING; | ||
| this._loadError = undefined; | ||
| this._hasSubregion = true; | ||
|
|
||
| let index; | ||
| const atlas = this._billboardCollection.textureAtlas; | ||
| const indexOrPromise = atlas.addImageSubRegion(id, subRegion); | ||
|
|
||
| if (typeof indexOrPromise === "number") { | ||
| this.setImageSubRegion(indexOrPromise, subRegion); | ||
| return; | ||
| } | ||
|
|
||
| this.loadImageSubRegion(id, subRegion, indexOrPromise); | ||
| }; | ||
|
|
||
| /** | ||
| * @see {TextureAtlas#addImageSubRegion} | ||
| * @private | ||
| * @param {string} id An identifier to detect whether the image already exists in the atlas. | ||
| * @param {BoundingRectangle} subRegion An {@link BoundingRectangle} defining a region of an existing image, measured in pixels from the bottom-left of the image. | ||
| * @param {Promise<number>} indexPromise A promise that resolves to the image region index. | ||
| * @returns {Promise<number | undefined>} | ||
| */ | ||
| BillboardTexture.prototype.loadImageSubRegion = async function ( | ||
| id, | ||
| subRegion, | ||
| indexPromise, | ||
| ) { | ||
| let index; | ||
| try { | ||
| index = await atlas.addImageSubRegion(id, subRegion); | ||
| this._loadState = BillboardLoadState.LOADING; | ||
| index = await indexPromise; | ||
| } catch (error) { | ||
| // There was an error loading the referenced image | ||
| this._loadState = BillboardLoadState.ERROR; | ||
| this._loadError = error; | ||
| return; | ||
| } | ||
|
|
||
| if (this._id !== id) { | ||
| // Another load was initiated and resolved resolved before this one. This operation is cancelled. | ||
| return; | ||
| } | ||
|
|
||
|
Comment on lines
+293
to
+313
Contributor
Author
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. This is a race condition that is handled by
Contributor
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. Can you elaborate? So this is a separate bug from what's originally being fixed in this PR?
Contributor
Author
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. Yes, I caught this from just comparing the two functions it's unrelated to the original issue |
||
| this._loadState = BillboardLoadState.LOADED; | ||
|
|
||
| this.setImageSubRegion(index, subRegion); | ||
| }; | ||
|
|
||
| /** | ||
| * @see {TextureAtlas#addImageSubRegion} | ||
| * @private | ||
| * @param {number | undefined} index The resolved index in the {@link TextureAtlas} | ||
| * @param {BoundingRectangle} subRegion An {@link BoundingRectangle} defining a region of an existing image, measured in pixels from the bottom-left of the image. | ||
| */ | ||
| BillboardTexture.prototype.setImageSubRegion = function (index, subRegion) { | ||
| if (index && this._index === index) { | ||
| return; | ||
| } | ||
|
|
||
| if (!defined(index) || index === -1) { | ||
| this._loadState = BillboardLoadState.FAILED; | ||
| this._index = -1; | ||
|
|
@@ -280,7 +324,6 @@ BillboardTexture.prototype.addImageSubRegion = async function (id, subRegion) { | |
| this._height = subRegion.height; | ||
|
|
||
| this._index = index; | ||
| this._loadState = BillboardLoadState.LOADED; | ||
|
|
||
| this.dirty = true; | ||
| }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.