Open Virus5600 opened 6 months ago
To anyone who might stumble here, here's a sample class I managed to create. I googled the equations and check if the methods will work properly. Feel free to modify this one as you see fit.
export default class Vector3 {
#x;
#y;
#z;
constructor(x, y, z) {
this.#x = x;
this.#y = y;
this.#z = z;
}
length() {
return Math.sqrt(this.#x * this.#x + this.#y * this.#y + this.#z * this.#z);
}
normalized() {
let scalar = (1 / (this.length() || 1));
this.#x *= scalar;
this.#y *= scalar;
this.#z *= scalar;
return this;
}
static add(v1, v2) {
return new Vector3(
v1.x + v2.x,
v1.y + v2.y,
v1.z + v2.z
);
}
static subtract(v1, v2) {
return new Vector3(
v1.x - v2.x,
v1.y - v2.y,
v1.z - v2.z
);
}
static multiply(v1, num) {
return new Vector3(
v1.x * num,
v1.y * num,
v1.z * num
);
}
static divide(v1, v2) {
return new Vector3(
v1.x / v2.x,
v1.y / v2.y,
v1.z / v2.z
);
}
static distance(v1, v2) {
return Math.sqrt(
Math.pow(v1.x - v2.x, 2) +
Math.pow(v1.y - v2.y, 2) +
Math.pow(v1.z - v2.z, 2)
);
}
// GETTER
get x() { return this.#x; }
get y() { return this.#y; }
get z() { return this.#z; }
}
Version used for the module: 1.11.0-beta Minimum Engine Version: 1.20.80
Importing the
Vector3
interface in an ES6M JavaScript file throws a Syntax Error saying that Vector3 does not exists. Googling left me with no answer while scouring the documentation felt useless since there's no way to identify if the said interface is available in its1.11.0-beta
or if it was changed into something else completely.The import goes as this:
The error goes like this:
I've tried the following keywords:
Vector
Vector3D
Vector3d
Vector3
So far, nothing works.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.