saharan / OimoPhysics

A cross-platform 3D physics engine
MIT License
863 stars 68 forks source link

"Hello World" on the server side with OimoPhysics #57

Closed 8Observer8 closed 1 year ago

8Observer8 commented 1 year ago

Hello. I will describe my steps. Please, write what step is wrong.

I created a new folder and the package.json file using this command:

npm init -y

I installed the engine:

npm i saharan/OimoPhysics

I added "type": "module" to the package.json file:

{
  "name": "oimophysics-server-js",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "oimophysics": "github:saharan/OimoPhysics"
  }
}

I created the src/server/app.js file:

import "oimophysics";

const world = new OIMO.World();
world.gravity = new OIMO.Vec3(0, -9.8, 0);
console.log(world.gravity);

I tried to run app.js with nodemon src/server/app.js but I had this error:

const world = new OIMO.World();
              ^

ReferenceError: OIMO is not defined
pschroen commented 1 year ago

Hi Ivan, I tried these steps and getting the previous issue I opened #56.

Here's what works for me with your steps, installing the previous version of v1.2.3 and using the named export of oimo.

npm i saharan/OimoPhysics#v1.2.3
import { oimo } from 'oimophysics';

const world = new oimo.dynamics.World();
world.gravity = new oimo.common.Vec3(0, -9.8, 0);
console.log(world.gravity);

A good reference for how to use the JavaScript module is the three.js example by @VBT-YTokan, which includes an export wrapper for the OIMO.* syntax.

https://threejs.org/examples/physics_oimo_instancing.html https://github.com/mrdoob/three.js/blob/dev/examples/jsm/physics/OimoPhysics.js https://github.com/mrdoob/three.js/blob/dev/examples/jsm/libs/OimoPhysics/index.js

8Observer8 commented 1 year ago

Hi! Thank you very much! It works!

But it looks like 1.2.2 has been installed instead of 1.2.3:

image

But I think it doesn't matter.

pschroen commented 1 year ago

Ah, you're right. It's a mistake in that release though, it is v1.2.3 but the package.json wasn't updated.

https://github.com/saharan/OimoPhysics/blob/v1.2.3/package.json#L3 https://github.com/saharan/OimoPhysics/blob/297090ff00847f7a6cefbacd114388477b338b7a/package.json#L3

8Observer8 commented 1 year ago

I installed the last 1.2.4 version and it works!

npm i saharan/OimoPhysics#v1.2.4

app.js

import { oimo } from "oimophysics";

const world = new oimo.dynamics.World();
world.gravity = new oimo.common.Vec3(0, -9.8, 0);
console.log(world.gravity);

node app.js

Output: oimo_common_Vec3 { x: 0, y: -9.8, z: 0 }

I tried these steps and getting the previous issue I opened https://github.com/saharan/OimoPhysics/issues/56.

Thanks for the useful information. I'll keep it on mind.

pschroen commented 1 year ago

Hi @8Observer8, I should add that we were setting the gravity incorrectly in these tests, essentially you were just setting the property gravity and reading it back on the next line.

To get and set the gravity in OimoPhysics you use getGravity() and setGravity(gravity), so for example:

import { oimo } from "oimophysics";

const world = new oimo.dynamics.World();
world.setGravity(new oimo.common.Vec3(0, -9.8, 0));
console.log(world.getGravity()); // oimo_common_Vec3 { x: 0, y: -9.8, z: 0 }

And I should also add that the gravity is already set to -9.80665 by default.

import { oimo } from "oimophysics";

const world = new oimo.dynamics.World();
console.log(world.getGravity()); // oimo_common_Vec3 { x: 0, y: -9.80665, z: 0 }
8Observer8 commented 1 year ago

Thank you very much!

8Observer8 commented 1 year ago

I tried these steps and getting the previous issue I opened https://github.com/saharan/OimoPhysics/issues/56

I ran a physics loop on the server side and I have the same error:

file:///E:/_Projects/node_modules/oimophysics/bin/js_modules/OimoPhysics.js:17879
                let st = HxOverrides.now() / 1000;
                         ^

ReferenceError: HxOverrides is not defined
    at oimo_dynamics_World.step (file:///E:/_Projects/node_modules/oimophysics/bin/js_modules/OimoPhysics.js:17879:12)
    at ServerGameCore.<anonymous> (file:///E:/_Projects/Physics/OimoPhysics/multiplayer-ws-oimophysics-webgl-rollup-js/src/server/server-game-core.js:93:24)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7)

Using of 1.2.3 instead of 1.2.4 is the solution.

8Observer8 commented 1 year ago

I completed the first version of the demo with an authoritarian server, where you can navigate in cooperative and single player modes from the first and third person. Made to show models, animations made in Blender and interactive interactions on WebGL. Demo in browser: https://8observer8.github.io/webgl10-js/room-webgl-js/

image