royibernthal Posted April 9, 2017 Share Posted April 9, 2017 Is it supposed to be possible to change the texture of a Sprite2D after it has been rendered? Whenever I try to do that I'm getting the following error: Quote TypeError: this.modelRenderCache is null If it is supposed to be possible I'll make a PG to demonstrate the error. If not, is the alternative to create multiple Sprite2D each with its own texture? Quote Link to comment Share on other sites More sharing options...
royibernthal Posted April 10, 2017 Author Share Posted April 10, 2017 @Nockawa I know you probably won't see this ping for a while, but when you get back. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 11, 2017 Share Posted April 11, 2017 Hiya Royi. https://www.babylonjs-playground.com/#14IJD3#24 After about 10 secs, sprite2d (s1) should change texture. Hope this helps. Quote Link to comment Share on other sites More sharing options...
royibernthal Posted April 11, 2017 Author Share Posted April 11, 2017 Hey Changed to 3 seconds. I think the problem is with hasAlpha, perhaps because in this PG the second texture is a jpg without alpha. It's worth trying with another transparent png just to make sure that's not the case. https://www.babylonjs-playground.com/#14IJD3#29 This PG throws this error: Quote babylon.canvas2d.js:9972 Uncaught TypeError: Cannot read property '_partData' of null at GroupInstanceInfo.get [as transparentData] (babylon.canvas2d.js:9972) at ScreenSpaceCanvas2D.Group2D._renderTransparentData (babylon.canvas2d.js:12017) at ScreenSpaceCanvas2D.Group2D._groupRender (babylon.canvas2d.js:11889) at ScreenSpaceCanvas2D.Canvas2D._render (babylon.canvas2d.js:17921) at e.callback (babylon.canvas2d.js:16702) at e.notifyObservers (babylon.js:2) at r.render (babylon.js:13) at index.js:223 at n._renderLoop (babylon.js:5) Locally I get this error for a different code that is quite complex to reproduce, but same idea: Quote TypeError: this.modelRenderCache is null[Learn More] babylon.canvas2d.min.js:6:21059 t<.get file:///D:/Projects/someProject/client/src/lib/babylon.canvas2d.min.js:6:21059 n.prototype._renderTransparentData file:///D:/Projects/someProject/client/src/lib/babylon.canvas2d.min.js:7:24988 n.prototype._groupRender file:///D:/Projects/someProject/client/src/lib/babylon.canvas2d.min.js:7:22514 n.prototype._render file:///D:/Projects/someProject/client/src/lib/babylon.canvas2d.min.js:11:13599 n/a._afterRenderObserver< file:///D:/Projects/someProject/client/src/lib/babylon.canvas2d.min.js:10:15698 Observable.prototype.notifyObservers file:///D:/Projects/someProject/client/src/lib/babylon.max.js:4968:21 Scene.prototype.render file:///D:/Projects/someProject/client/src/lib/babylon.max.js:22755:13 Application/< file:///D:/Projects/someProject/client/src/app.js:4471:45 Engine.prototype._renderLoop file:///D:/Projects/someProject/client/src/lib/babylon.max.js:8827:21 bound They both seem to be related to transparent data. Locally both of the textures I'm using are transparent pngs. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Nockawa Posted April 18, 2017 Share Posted April 18, 2017 This is clearly immutable so far, so you can't change it, unless if you're lucky (I won't explain the details). I've created an issue labeled as "enhancement" because it's not a bug to me, but I don't expect to do it anytime soon. royibernthal 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 18, 2017 Share Posted April 18, 2017 Object.defineProperty(GroupInstanceInfo.prototype, "transparentData", { get: function () { if (!this._transparentData) { this._transparentData = new Array(this._partCount); for (var i = 0; i < this._partCount; i++) { var zoff = this.modelRenderCache._partData[i]._zBiasOffset; this._transparentData[i] = new TransparentGroupInfoPartData(this._strides[i], zoff); } } return this._transparentData; }, enumerable: true, configurable: true }); There it is, the zoff line. Hey @Nockawa, first of all, welcome back! I hope you had some fun "out west" in the west. We sure miss you when you're gone. Someday, you may actually get to play with BJS, instead-of always working on it. Immutable, huh? That means... unchangeable. hmm. If we had a function... sprite.setInitialTexture(someTexture, hasAlpha, etc)... that function COULD re-initialize the sprite as if it were a new sprite, yes? The 'Initial' part COULD indicate to users... that the sprite is being re-created to accomplish this. I think you agree, this issue is going to arise again, because... making a new sprite2d with rect2d and text2d (like the #29 PG demo)... is a substantial amount of code lines. There will be future others who will try to re-use a sprite2D, instead-of making a new one (esp if they ONLY need to change the texture or atlas). So, I'm thinking about ways to make it APPEAR as-if they changed the texture, when actually, they re-created/re-initialized... using the new texture/atlas. Not sure if that would work. Just thinkin' and inkin'. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.