WaterMaterial is not a constructor ?

i am useing babylonjs-materials. but have a error

this my code:


How to use babylonjs-materials correctly


I made changes to my code, but there were new problems

How do I get water fragment. fx and water vertex. fx these two files

Hello @ShareQiu1994 , how are you doing?

Can you give a little more information about your project? Are you using webpack?

cc @RaananW who is our build GURU

i’ll analyze it and let you know! Seems like something on our side is missing

@srzerbetto yeah, i am useing webpack . this is my code
http://devmodels.oss-cn-shenzhen.aliyuncs.com/devtest/liubofang/code/jinan3D_2.zip

@RaananW okay. Waiting for your message

So, that’s not an issue with babylon, but an interesting feature of es6 modules and the way they are imported.

The UMD packages we offer (which are the ones you are using) are populating the global BABYLON namespace. When you import * as BABYLON from "babylonjs" you are getting a replication of the BABYLON global namespace, but this package will not be extended when import "babylonjs-materials is executed.

There are a few different solutions:

  1. (My favorite) - Use the es6 packages instead of UMD. you are already using “import”, you are already using es6, why not use a more modern varient?
  2. use window.BABYLON instead of BABYLON. This will use the global namespace.
  3. Don’t “import * as BABYLON…”, but simply import "babylonjs". The global BABYLON namespace will be available.
1 Like

thanks, ES6 packages is not suitable for me because the documentation explains it too little. I used the second method slove it