q1)I am trying to create a jest test with nullEngine and creating scene and camera out of it. const engine = new NullEngine(); const scene = new Scene(engine);
i created a cube behind the camera. no matter where the box is placed in the scene, the cube is always in Frustum.
but the above function works well in the actual code. when any mesh gets behind the camera, the above function returns false.
q2)const frustumPlanes = Frustum.GetPlanes(scene.getTransformMatrix());
Frustum.GetPlanes accepts transform immutable Matrix as argument… is there a way we can use projection or view matrices…
What is the difference between projection Matrix, Transform Matrix and view Matrix. how can they be used…
q3)when i create any mesh say a cube in my jest test file with nullEngine and scene…
const engine = new NullEngine();
const scene = new Scene(engine);
const myCamera = new PlayerCamera(cameraProperties);
myCamera.target = new Vector3(0, 0, 0);
const box1 = Mesh.CreateBox(“box1”, .1, scene);
box1.position = new Vector3(0, 0.5, 0);
why is this mesh always not active… isActiveMesh(box1) returns false…
In your tests you should call scene.render() to simulate what is happening in reality. This will warm up and compute all the required cached data like matrices values and such.
About the matrices this is a nice article speaking about them Model View Projection.
the third question will have the same answer than the first one.
just want to test that function… isInFrustum(); below is simple test case…
const engine = new NullEngine();
const scene = new Scene(engine);
const myCamera = new Camera(cameraProperties);
myCamera.target = new Vector3(0, 0, 0);
const box2 = Mesh.CreateBox(“box2”, .1, scene);
box2.position = new Vector3(0,0.5,-20);
engine.runRenderLoop(() => {
scene.render();
});
describe(‘isMeshInFrustum tests’, () => {
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation();
});
it('we should get box is in Frustum', () => {
expect(isMeshInFrustum(box1, scene)).toBe(true);
});
it('we should get box2 is not in Frustum', () => {
expect(isMeshInFrustum(box2, scene)).toBe(false);
});
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation();
});
it('we should get box is in Frustum', () => {
expect(isMeshInFrustum(box1, scene)).toBe(true);
});
it('we should get box2 is not in Frustum', () => {
expect(isMeshInFrustum(box2, scene)).toBe(false);
});