Panuchka Posted April 4, 2017 Share Posted April 4, 2017 I am struggling with a similar problem like in this thread, but the solution provided here seems not so ideal... I have many modules in my game, and if I use Babylon.js in any of those, I import it using: import Babylon from 'babylonjs' So there isn't any good way to include Canvas2D similarly? I understand it is somehow baked to Babylon.js, but how do I use it? I'm downloading all the dependencies from the npm, including Babylon.js. Then I bundle everything using Webpack. Ideally, I would like to use Canvas2D (for example) like this: import Babylon from 'babylonjs' import Canvas2D from 'babylonjs' Please help, I've been scratching my head for hours now... brianzinn 1 Quote Link to comment Share on other sites More sharing options...
Nikos123 Posted April 4, 2017 Share Posted April 4, 2017 I just use a vanilla Canvas so I don't need to depend on babylon. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 4, 2017 Share Posted April 4, 2017 Can you try to add something like that at the end of canvas2d file: if (((typeof window != "undefined" && window.module) || (typeof module != "undefined")) && typeof module.exports != "undefined") { module.exports = BABYLON.Canvas2D; }; Quote Link to comment Share on other sites More sharing options...
brianzinn Posted April 4, 2017 Share Posted April 4, 2017 If you are using NPM, I don't think 'babylonjs' includes Canvas2D. Canvas2D is a separate file that you can get from here: https://github.com/BabylonJS/Babylon.js/tree/master/dist I've been scratching my head for days, so 'hours' isn't so bad!! Even if you get the import Canvas2D then I suspect you will get issues with loading. If you get it working, please let us know how. Cheers. Quote Link to comment Share on other sites More sharing options...
Panuchka Posted April 4, 2017 Author Share Posted April 4, 2017 Why isn't Canvas2D included here in the npm package at all?https://www.npmjs.com/package/babylonjs @Deltakosh I can try that, but the Canvas2D should be included to the npm first! Can you do that? Quote Link to comment Share on other sites More sharing options...
brianzinn Posted April 4, 2017 Share Posted April 4, 2017 I think Canvas2D was split off in November to reduce size of babylonjs, but it would be great if it was included in the npm! Quote Link to comment Share on other sites More sharing options...
brianzinn Posted April 4, 2017 Share Posted April 4, 2017 Also, maybe you have done it to simplify your imports, but if you use explicit imports (instead of default) might be a good practice. ie: import { Mesh, Vector3, Color3 } from 'babylonjs' Since you are using webpack, explicit imports will reduce the size of your generated javascript. If your editor has ESLint then it will pickup on unused/missing imports. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 4, 2017 Share Posted April 4, 2017 It will be included for 3.0: https://github.com/BabylonJS/Babylon.js/blob/master/Tools/Npm/package.json brianzinn 1 Quote Link to comment Share on other sites More sharing options...
Panuchka Posted April 5, 2017 Author Share Posted April 5, 2017 Is there ETA for 3.0? If the full release is far far away in the future, could we have 3.0 alpha/beta builds in npm too? Or include Canvas2D for 2.5? If I can't get this to work, I guess I have to do the UI using html/css I would prefer using just Babylon.js though, with Canvas2D. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 5, 2017 Share Posted April 5, 2017 Let me update the npm version for 2.5 with canvas then Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 5, 2017 Share Posted April 5, 2017 Ok actually I prefered publishing a 3.0.0-alpha version Panuchka 1 Quote Link to comment Share on other sites More sharing options...
brianzinn Posted April 12, 2017 Share Posted April 12, 2017 Is there any intention to also include babylon.inspector.bundle.js with the 3.0 npm? Thanks. HugoMcPhee 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 13, 2017 Share Posted April 13, 2017 Sure! Please update the npm package here: https://github.com/BabylonJS/Babylon.js/blob/master/Tools/Npm/package.json Quote Link to comment Share on other sites More sharing options...
HugoMcPhee Posted May 21, 2017 Share Posted May 21, 2017 I'm facing a similar issue but trying to import the glTF File Loader, Would it be okay to include the loaders in the npm package aswell? Or would it be better to have a separate npm repository for the plugins? If making them available through npm isn't an option, Is there some way to import the SceneLoader from the glTF loader? In a es2015 project - glTF loader worked fine following the tutorials ( by including it as a script in index.html) but with a typescript project the same thing isn't working Is there a recommended way to "import" a babylonjs plugin? Thanks Quote Link to comment Share on other sites More sharing options...
brianzinn Posted May 22, 2017 Share Posted May 22, 2017 i don't know a recommended way, but I just copied the .ts file from babylonjs source and modified it be removing any "BABYLON." references. Then my code was just this: SceneLoader.RegisterPlugin(new OBJFileLoader()) SceneLoader.ImportMesh(...) Anyway, I'm sure this isn't the recommended way, but will get you going until you find something hopefully better. HugoMcPhee 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 29, 2017 Share Posted May 29, 2017 No problem to add them to the npm package. Please do a PR to update the package desc: https://github.com/BabylonJS/Babylon.js/tree/master/Tools/Npm Quote Link to comment Share on other sites More sharing options...
Andy Zhuang Posted June 10, 2017 Share Posted June 10, 2017 On 06/04/2017 at 0:33 AM, Deltakosh said: Ok actually I prefered publishing a 3.0.0-alpha version Hi, @Deltakosh, it still not contain Canvas2d in the latest release in NPM (https://www.npmjs.com/package/babylonjs) I need this to work. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 10, 2017 Share Posted June 10, 2017 Yep I replaced it with gui Quote Link to comment Share on other sites More sharing options...
Andy Zhuang Posted June 11, 2017 Share Posted June 11, 2017 14 hours ago, Deltakosh said: Yep I replaced it with gui I am confusing. Why remove Canvas2D? Cann't we keep both? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 11, 2017 Share Posted June 11, 2017 It is not removed. Just moved to Extensions repo. Canvas2D is still a great framework but the main contributor is sick so I needed to remove Canvas2D from the main repo to not block the release of Babylon.js 3.0 So yes we will definitely keep both. Quote Link to comment Share on other sites More sharing options...
Andy Zhuang Posted June 12, 2017 Share Posted June 12, 2017 Thanks for clearing. Now I get the extensions repository: https://github.com/BabylonJS/Extensions 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.