Is there a method to verify the current instance being used?
This is what I am logging to the console:
import { OrthographicCamera } from 'three';
// Later in the file:
console.log(camera instanceof OrthographicCamera, camera);
and the result is false
, but when I check the value of camera
, I see this:
https://i.stack.imgur.com/gDJ9o.png
I'm unsure why it indicates that the camera isn't an instance, so is there a way to gather more information on what it actually represents?
This is where the camera is initialized:
export function Camera(options?: CameraOptions) {
return function (target: new () => object) {
return class GameCamera extends target {
readonly camera!: Camera;
constructor() {
super();
const dim = this.cameraDimensions();
// create the Three camera
this.camera = new OrthographicCamera(dim.left, dim.right, dim.top, dim.bottom, options?.near ?? 0, options?.far ?? 100);
}
}
}
}}
The camera is created within the Decorator and added to the gameObjects
array. When I access the activeCamera
, it refers to the above decorator extending target
.
This is where I perform the instanceof
comparison:
@Injectable({ providedIn: 'root' })
export class Camera {
get activeCamera() {
return Engine.activeCamera;
}
mouseToWorldPoint(mousePoint: Vector3) {
if (this.activeCamera) {
// Here is the verification:
console.log(camera instanceof OrthographicCamera, camera);
}
}
}
This is how the camera is retrieved:
export class Engine {
static gameObjects: GameObject[] = [];
static get activeCamera() {
return this.gameObjects.find(i => i.gameObjectType === 'camera' && i.isActive === true) as GameCamera | undefined;
};
}
I have organized the project into multiple npm workspaces:
{
"name": "game-engine",
"version": "1.0.0",
"scripts": {
"start": "npm run start --workspace=test"
},
"workspaces": [
"test",
"packages/core",
"packages/common",
"packages/input",
"packages/objects"
]
}
2 of the workspaces depend on modules from the three module.
- class
GameCamera
belongs to thepackages/objects
module (creates the camera). - class
Camera
belongs to thepackages/common
module (verifies the instance).
Note: This setup has been functioning like this for some time and this issue seems to have recently surfaced.