jcwilk Posted February 4, 2021 Share Posted February 4, 2021 Hi, So I've been trying to get shaders working in typescript (can run them just fine in javascript) but all the examples (eg https://pixijs.io/examples/#/mesh-and-shaders/triangle-color.js) use the following pattern: const geometry = new PIXI.Geometry(); const shader = PIXI.Shader.from(`shader code`); const triangle = new PIXI.Mesh(geometry, shader); but in v5.3.7 the Mesh constructor is defined to take in only an instance of MeshMaterial for its second argument, not an instance of Shader: https://github.com/pixijs/pixi.js/blob/dacad3a452c8f27f4fd2d064cda206182f22ebff/packages/mesh/src/Mesh.ts#L65 even though the member variable shader can return either a Shader or a MeshMaterial: https://github.com/pixijs/pixi.js/blob/dacad3a452c8f27f4fd2d064cda206182f22ebff/packages/mesh/src/Mesh.ts#L83. I'm new to typescript though, so I must be missing something since this would make the most straightforward example usage of shaders done throughout almost all of the shader examples invalid in typescript. Mind giving me a tip about what I'm doing wrong? I'm excited to do typed webgl and appreciate all of your efforts! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 4, 2021 Share Posted February 4, 2021 Its limitation of our types, we dont know what to do with it just put "as any". Mesh can work with any Shader, not only MeshMaterial, provided you modify renderDefault() accordingly if there are other uniforms Quote Link to comment Share on other sites More sharing options...
jcwilk Posted February 4, 2021 Author Share Posted February 4, 2021 Ah thanks for the tip! Looks like that works around it. I ended up having to do: const triangle = new PIXI.Mesh(geometry, shader as PIXI.MeshMaterial); and it looks like it's accepting it now. Thanks! 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.