BabylonJS-CharacterController icon indicating copy to clipboard operation
BabylonJS-CharacterController copied to clipboard

BabylonJS ES6 Module support

Open allaaaaan opened this issue 3 years ago • 6 comments

Hi there,

Really nice project, appreciate it. May I ask if my project is using BJS ES6 module, how can I get this lib to work without hard forking? Or is there any plan of adding BJS ES6 module support to this? Thank you in advance!!

allaaaaan avatar Dec 14 '21 00:12 allaaaaan

I would like to do that but not quite sure how. Show me some code snippet as to how you would like to use and let me see if I can work something out

ssatguru avatar Dec 17 '21 00:12 ssatguru

Thanks for the replay @ssatguru

Basically, you just need to replace your BJS dependencies to ES6 module version BJS ES6 Module image

Then replace the import usage within your code image

allaaaaan avatar Dec 17 '21 00:12 allaaaaan

What about users who are using the non es6 version of BABYLONJS ? Would I have to maintain a separate version for them?

ssatguru avatar Dec 19 '21 19:12 ssatguru

Yes, normally that is how it works. Two seperate repos.

BTW, do you have any existing project using this lib?

allaaaaan avatar Dec 20 '21 08:12 allaaaaan

Ok. This might take some time. I would suggest that for now just fork and use it. Its just one file. You can probably just add the source itself to your project. Yes I do have a project which uses this. This was actually part of that project . I moved it out thinking it might be useful to others. The project - https://github.com/ssatguru/Vishva.ts/tree/modularize

ssatguru avatar Dec 21 '21 01:12 ssatguru

Got it working in es6 with straight javascript (versus typescript): Here's the file: cc.js.zip

and then in my entry file i've got the following imports (some of these aren't needed just for character controller, but here you go anyway):

import { Engine } from '@babylonjs/core/Engines/engine'
import { Texture } from '@babylonjs/core/Materials/Textures/texture'
import { CubeTexture } from '@babylonjs/core/Materials/Textures/cubeTexture'
import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial'
import { Vector3, Color3 } from '@babylonjs/core/Maths/math'
import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera'
import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight'
import { DirectionalLight } from '@babylonjs/core/Lights/directionalLight'
import { CreateSphere } from "@babylonjs/core/Meshes/Builders/sphereBuilder";
import { CreateGround } from "@babylonjs/core/Meshes/Builders/groundBuilder";
import { CreateGroundFromHeightMap } from "@babylonjs/core/Meshes/Builders/groundBuilder";
import { CreateBox} from "@babylonjs/core/Meshes/Builders/boxBuilder"
import { ShadowGenerator } from '@babylonjs/core/Lights/Shadows/shadowGenerator'
import { ShadowGeneratorSceneComponent } from '@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent'
import { EnvironmentHelper } from '@babylonjs/core/Helpers/sceneHelpers'

import {CharacterController} from './cc'
import { SceneLoader } from "@babylonjs/core/Loading/sceneLoader"
import { GLTFLoader } from "@babylonjs/loaders/glTF/2.0/glTFLoader"```

bigrig2212 avatar Nov 27 '22 20:11 bigrig2212