Skip to content

Commit

Permalink
add: GlowLayer declarative inclusion list test
Browse files Browse the repository at this point in the history
  • Loading branch information
brianzinn committed Aug 6, 2021
1 parent 41173f5 commit 7f82c35
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
6 changes: 3 additions & 3 deletions test/hostConfig.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CreatedInstance } from '../src/CreatedInstance';
import { CustomProps } from '../src/CustomProps';
import renderer, { Container } from '../src/ReactBabylonJSHostConfig';
import { Engine, FreeCamera, Mesh, NullEngine, PBRMaterial, Scene, StandardMaterial, Vector3 } from '@babylonjs/core';
import { CameraLifecycleListener, FallbackLifecycleListener, NodeLifecycleListener } from '../src/customHosts';
import { AbstractMeshLifecycleListener, CameraLifecycleListener, FallbackLifecycleListener } from '../src/customHosts';
import { PBRClearCoatConfiguration } from '@babylonjs/core/Materials/PBR/pbrClearCoatConfiguration';

describe(' > Reconciler tests', function testSuite() {
Expand Down Expand Up @@ -78,7 +78,7 @@ describe(' > Reconciler tests', function testSuite() {
assert.ok(logger.notCalled, 'console.warn should not be called.');
});

it('Create box (Mesh) should be assigned NodeLifecycleListener', async function test() {
it('Create box (Mesh) should be assigned AbstractMeshLifecycleListener', async function test() {
const container = getRootContainerInstance();

const createdInstance: CreatedInstance<any> | undefined = renderer.createInstance('box', {
Expand All @@ -88,7 +88,7 @@ describe(' > Reconciler tests', function testSuite() {

assert.notStrictEqual(createdInstance, undefined);
assert.notStrictEqual(createdInstance!.lifecycleListener, undefined);
assert.ok(createdInstance?.lifecycleListener instanceof NodeLifecycleListener, `expecting node lifecycle listener: ${createdInstance?.lifecycleListener}`);
assert.ok(createdInstance?.lifecycleListener instanceof AbstractMeshLifecycleListener, `expecting node lifecycle listener: ${createdInstance?.lifecycleListener}`);
});

it('Create "assignFrom" should defer construction and included delayed creation props', async function test() {
Expand Down
41 changes: 40 additions & 1 deletion test/render.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { AbstractMesh, ArcRotateCamera, Camera, Color4, Engine, NullEngine, Scene, Vector3 } from "@babylonjs/core";
import { AbstractMesh, ArcRotateCamera, Camera, EffectLayer, Engine, GlowLayer, NullEngine, Scene, Vector3 } from "@babylonjs/core";
import sinon from "sinon";
import assert from 'assert';

Expand Down Expand Up @@ -142,4 +142,43 @@ describe(' > Reconciler/Render tests', function testSuite() {
assert.ok(camera instanceof ArcRotateCamera, 'Should be ArcRotateCamera');
assert.ok(Vector3.Up().equals(camera.target), 'should be the same as Vector3.Up');
})

it('GlowLayer should include children to inclusion list (when configured).', async function test() {
const container: Container = getRootContainerInstance();
const reconciler: ReconcilerInstance = createReconciler({});


const sceneGraph = (
<SceneContext.Provider value={{
scene: container.scene,
sceneReady: true
}}>
<arcRotateCamera name='camera1' alpha={0} beta={Math.PI / 3} radius={10} target={Vector3.Zero()} />
<hemisphericLight name='light1' direction={Vector3.Up()} />
<glowLayer name='glow1' addIncludeOnlyChildren>
<box
name="box"
size={2}
position={new Vector3(0, 1.2, 0)}
>
<standardMaterial name='boxMat' />
</box>
</glowLayer>

</SceneContext.Provider>
)
reconciler.render(sceneGraph, container, () => { /* empty for now */ }, null)

const box: AbstractMesh | undefined = container.scene.meshes.find(m => m.name === 'box');
assert.ok(box !== undefined)

const effectLayers: EffectLayer[] = container.scene.effectLayers;
assert.strictEqual(1, effectLayers.length, 'glow layer should be part of scene');
assert.ok(effectLayers[0] instanceof GlowLayer);

const glowLayer: GlowLayer = effectLayers[0] as GlowLayer;
assert.ok(glowLayer.hasMesh(box));
assert.strictEqual((glowLayer as any)._includedOnlyMeshes.length, 1);
assert.strictEqual((glowLayer as any)._includedOnlyMeshes[0], box.uniqueId);
})
})

0 comments on commit 7f82c35

Please sign in to comment.