fxlr8

pixi.js + expo getTestContext workaround

Recommended Posts

Hi, I am trying to make `pixi.js` work with `expo`. Current option `expo-pixi` is using pixi v4, not using Typescript and looks messy. I want to take a different approach and make my own version with pixi v5 and a helper/wrapper that will keep original pixi untouched. I am currently stuck at a moment where pixi tries to load a test context for inner needs. `expo-gl` component provides only one gl context so there is no second one for testing needs. Do you guys have any ideas how to workaround this issue? Do we really need tests here? I think native apps on modern phones should be able to provide any gl feature pixi needs. The most obvious is to disable the tests. Maybe you can come up with a better idea.

Share this post


Link to post
Share on other sites

Unfortunately, the only way is to rewrite pixi core that way test context assigned from renderer that is created. If there's no renderer, throw error. I tried to refactor it before but failed to produce something that can be merged into main repo . It worked, so its possible ;)

Edited by ivan.popelyshev

Share this post


Link to post
Share on other sites

What if we make Application constructor accept testContext along with the context? So I could pass or mock the testContext from the outside.
What if we keep testContext in some kind of testSystem class that performs all the tests?
I am really interested in this feature and I am ready to implement it, I just need your guidance so that everything happens the pixi way and runs smooth.

Share this post


Link to post
Share on other sites

Application is a mashup, you need a renderer parameter, and i think there was getTestContext() usage even without renderer - in shader constructor - so you have to do a global hack.

getTestContext() isn't exposed - yep, that's bad, expose it.

I dont know about renderer/app param, but PR exposing getTestContext is gonna be merged for sure, if you make it.

Share this post


Link to post
Share on other sites

instead of getTestContext the file should export the object that has it as a method. Make sure all pixi modules that use it actually refer as "myMagicObject.getTestContext"

Then re-export this object in packages/core/index.js file

then you can modify it from outside: "PIXI.myMagicObject.getTestContext()".

If you just expoet getTestContext itself - internal stuff wont notice your outer hack :(

I'm bad with names so you should choose where to put this thing or ask assistance when you make PR from the rest of pixijs team

Share this post


Link to post
Share on other sites

Is there any way to install my version of PIXI with npm? It is a monorepo and I can't figure out how to install it from git. It says that the package is missing version. How do you PIXI devs do it?

Share this post


Link to post
Share on other sites

I still struggle to link my custom PIXI version into test app. First I tried to import it with the relative path as offered in your issue. But Expo module resolution is a weird black box and I have no luck finding how resolve it correctly. I don't want to publish my own pixi as it is a lerna monorepo which will flood my npm registry with temporary packages.

Share this post


Link to post
Share on other sites

You really should write it in those threads - both your PR and that one - because im not the one who manages all those build tools stuff :) I'm vanilla guy. Just build pixi.js file and use it.. oh right i dont know if its even possible in expo

Edited by ivan.popelyshev

Share this post


Link to post
Share on other sites

By the way, I found a couple of places in PIXI with direct calls to `document`. For example, `createWhiteTexture`. Is there a place for some abstraction to make PIXI run in `document`less environments? Or should I better mock a global document?

image.thumb.png.d32f7155e854f215a148fee7bed1b3f4.png

Share this post


Link to post
Share on other sites

I don't quite understand how objects end up inside PIXI object.
I created testContext object and exported it from core/src/shader/utils, then re-exported them in core/index.ts
But I still can't find it in bundles/pixi.js/index.d.ts type file after build.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.