The same recast.js, but different logic. Why “recastInjection === function” is error in 5.0.0?
How to fix it?
The same recast.js, but different logic. Why “recastInjection === function” is error in 5.0.0?
Adding @Cedric but I believe in 5.0 you need to rely on the latest recast version
Yes, you have to use the latest version.
The latest of recast not just babylon sorry for the confusion
You mean the someone version in the future, and I can’t use it now?
He means the latest version of recast installed. Check here for copies of what should be the most reliable dependencies. Babylon.js/dist/preview release at master · BabylonJS/Babylon.js · GitHub
Really? I use the the latest version of recast installed (^5.0.0-beta.11) follow the Babylon.js/dist/preview release at master · BabylonJS/Babylon.js · GitHub
I see the babylon.js is same as @babylonjs in logic:
The different is : use “@babylonjs/core” I can read source code easier; but use “babylonjs” I can only read code in babylon.js file.
babylon doesn’t ship with recast, you have to import it yourself. so you can either install it via npm , copy/paste it from repo i linked, add a script tag to head of your html using either github cdn or the babylon cdn. many options. you’re getting the error “recast is not ready” is because you have to import it, then instantiate it by calling the default export (i think). so something like this: (babylon code isnt correct, but i think you will get the point)
import initRecastAsync from './recast.js'
initRecastAsync().then(RecastIntance => {
Babylon.RecastJsPlugin(RecastInstance)
})
very similar to the ammojs plugin if you’re using that
All what @jeremy-coleman said, thanks a lot for this
I import it in index.html : script src=“https://preview.babylonjs.com/recast.js”> . And it worked successfully in version 4.2.1
But in vesion 5.0.0, it can’t work. I found source code is different compared with 4.2.1 :
The recastInjection is Recast that from recast.js
I think the type must be “function”, and must error…
I have imported “https://preview.babylonjs.com/recast.js” in index.html. when I use version 4.2.1, it work successfully, but it can’t work in version 5.0.0
What more should I do?
As the error message says you need to await Recast();
before creating the plugin
But “Recast” is Undefined in typescript project
do not place it in your html
just as @jeremy-coleman mentionned:
import initRecastAsync from './recast.js'
initRecastAsync().then(RecastIntance => {
Babylon.RecastJsPlugin(RecastInstance)
})
Thanks, it can woked.
In version 5.0.0:
I need copy core from https://preview.babylonjs.com/recast.js to local project. Then need to add “declare var Recast: () => Promise” in .d.ts file to make sure typescript work successfully.
After that, call first:
Recast().then(RecastIntance => {
new RecastJSPlugin(RecastIntance)
// other
})
I think it’s more troubling than in version 4.2.1.
In version 4.2.1, I only need to place it in my html,and then it can work successfully if I’m following doc :Creating A Navigation Mesh | Babylon.js Documentation.
Why change it in version 5.0.0?
It’s in the 5.0 breaking changes
Recast.js needs to be initialized before creating the plugin with
await Recast();
since Recast introduced an async init in their library.
Babylon.js/what’s new.md at master · BabylonJS/Babylon.js (github.com)
It has to be async because any binary wasm module above 4kb has to be initialized async. Overall it can be faster because u can parse the js stuff and wasm in parallel. If not, its just annoying and slower lol, just like u said.
Thank you very much!
Thanks a lot!