-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to deploy example with box2d-wasm on Node.js hosting. #65
Comments
define a if NodeJS itself is retrieving the wasm (i.e. you are computing physics server-side), then you probably want to set this URL to return otherwise, if it's a client accessing box2d.js via the Web, and the client wishes to run the .wasm in their own browser: you would want to return an |
It seams like it is an issue for Render, because I deployed my example on Glitch and it works:
I used this initialization code without init-box2d.js import Box2DLib from "box2d-wasm";
export let box2d = null;
export function initBox2D() {
return new Promise(resolve => {
Box2DLib().then((re) => {
box2d = re;
resolve();
});
});
} I created the topic on Render forum: https://community.render.com/t/unable-to-deploy-example-with-box2d-wasm/13689 |
@Birch-san Thank you very much! It is the solution for Render: init-box2d.js import Box2DLib from "box2d-wasm";
export let box2d = null;
export function initBox2D() {
return new Promise(resolve => {
Box2DLib({
locateFile: (url, scriptDirectory) => "file:///opt/render/project/src/node_modules/box2d-wasm/dist/umd/Box2D.simd.wasm"
}).then((re) => {
box2d = re;
resolve();
});
});
} app.js import { box2d, initBox2D } from "./init-box2d.js";
async function init() {
await initBox2D();
const {
b2Vec2,
b2World
} = box2d;
const gravity = new b2Vec2(0, -3);
const world = new b2World(gravity);
const g = world.GetGravity();
console.log("gravity = ", g);
}
init(); |
Small update for localhost: init-box2d.js import Box2DLib from "box2d-wasm";
export let box2d = null;
export function initBox2D(localhost = true) {
return new Promise(resolve => {
Box2DLib({
locateFile: (url, scriptDirectory) => {
if (url.endsWith(".wasm") && !localhost) {
return "file:///opt/render/project/src/node_modules/box2d-wasm/dist/umd/Box2D.simd.wasm";
}
return scriptDirectory + url;
}
}).then((re) => {
box2d = re;
resolve();
});
});
} |
I can show the example code if needed, but there is some problem with the library itself. I tried to deploy on render.com It can be an issue of render.com
I try to use physics on the server side. My example just creates a physical world on the server side and sends the gravity value to the client, and the client shows it.
init-box2d.js
app.js
This is a full code of my example that is ready to deploy on render.com: https://github.com/8Observer8/send-gravity-from-server-to-client-box2d-wasm-js
The text was updated successfully, but these errors were encountered: