How to do Vec3 Math with BabylonLite?

Hi !

(Am I right to assume there’s no Playground for BabylonLite to share a repro ?)

I’m trying to port a BabylonJS project to BabylonLite, but can’t find the Math functions.

I’ve added BabylonLite via npm
Here’s my package.json

{
  "name": "gu-yen-lite",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "preview": "vite preview"
  },
  "devDependencies": {
    "@babylonjs/lite": "*",
    "typescript": "~6.0.2",
    "vite": "^8.0.4"
  },
  "dependencies": {
    "bootstrap-icons": "^1.13.1",
    "earcut": "^3.0.2"
  }
}

But I can’t find a way to import/use the vec3 functions described here

Did I miss a dependancy, or are the math functions not exported yet in the npm version ?

Thanks !

The link you provided leads to shader vectors. Do you need them or you need “usual” vectors from here? - Babylon.js docs

Oups, wrong link indeed, it’s the “usual ones” I’m trying to use.

That’s a total miss if they are not exported. I will check that as soon as I’m at my desk

This is just a basic example

import type { Vec3 } from "babylon-lite";
import { normalizeVec3 } from "babylon-lite";

const v: Vec3 = { x: 3, y: 0, z: 4 };

const [x, y, z] = normalizeVec3(v.x, v.y, v.z);

I have it working for normalizeVec3, but not for the other methods, like addVec3

Some of them are not exported.

Missing from the public root export (import { … } from “babylon-lite”) compared to packages/babylon-lite/src/math/index.ts:
vec3
Vec3Up
addVec3
subVec3
scaleVec3
dotVec3
crossVec3
lengthVec3
negateVec3
lerpVec3
writeVec3

There is also a subtle mismatch for normalizeVec3:
Public root exports ./math/normalize-vec3.js, which takes (x, y, z) and returns a tuple.
Internal math barrel exports ./math/normalize-vec3-object.js, which takes Vec3 and returns Vec3.

I’ll fix that!

Is the same with Vec4 or how does one deal with quaternions :thinking:

Here we are:
fix: complete math and color exports by deltakosh · Pull Request #244 · BabylonJS/Babylon-Lite

yes quaternion are also exported :wink:

Thanks !

Do the Babylon team intends to update the npm package while quickfixing or should we build Babylon Lite ourselves ?

no I’ll do it as soon as the PR land.
I want the smoother experience for my lovely early adopters :slight_smile:

I believe those newly exported functions be part of the one-shot document spec: Babylon-Lite/docs/lite/architecture/00-overview.md at master · BabylonJS/Babylon-Lite · GitHub

I believe there are a few exported functions that are not reflected back.

Gosh! I need an automatic system.

will fix that!