diff --git a/src/com/Communication.ts b/src/com/Communication.ts index 1f52043a..d832216d 100644 --- a/src/com/Communication.ts +++ b/src/com/Communication.ts @@ -120,6 +120,11 @@ export class DIVECommunication { let returnValue: Actions[Action]['RETURN'] = false; switch (action) { + case 'START_RENDER': { + this.renderer.StartRenderer(this.scene, this.controller.object); + returnValue = true; + break; + } case 'GET_ALL_SCENE_DATA': { returnValue = this.getAllSceneData( payload as Actions['GET_ALL_SCENE_DATA']['PAYLOAD'], diff --git a/src/com/__test__/Communication.test.ts b/src/com/__test__/Communication.test.ts index 6abe7277..96648588 100644 --- a/src/com/__test__/Communication.test.ts +++ b/src/com/__test__/Communication.test.ts @@ -92,6 +92,7 @@ jest.mock('../../toolbox/select/SelectTool', () => { const mockRenderer = { render: jest.fn(), OnResize: jest.fn(), + StartRenderer: jest.fn(), } as unknown as DIVERenderer; const mockScene = { @@ -288,6 +289,12 @@ describe('dive/communication/DIVECommunication', () => { ).not.toThrow(); }); + it('should perform action START_RENDER', () => { + const success = testCom.PerformAction('START_RENDER'); + expect(mockRenderer.StartRenderer).toHaveBeenCalledTimes(1); + expect(success).toBe(true); + }); + it('should perform action ADD_OBJECT', () => { const payload = { entityType: 'light', diff --git a/src/com/actions/index.ts b/src/com/actions/index.ts index d7ce7d96..e8f48201 100644 --- a/src/com/actions/index.ts +++ b/src/com/actions/index.ts @@ -1,3 +1,4 @@ +import START_RENDER from './renderer/startrender.ts'; import SET_BACKGROUND from './scene/setbackground.ts'; import RESET_CAMERA from './camera/resetcamera.ts'; import SET_CAMERA_LAYER from './camera/setcameralayer.ts'; @@ -28,6 +29,7 @@ import EXPORT_SCENE from './scene/exportscene.ts'; import LAUNCH_AR from './scene/launchar.ts'; export interface Actions { + START_RENDER: START_RENDER; GET_ALL_SCENE_DATA: GET_ALL_SCENE_DATA; GET_ALL_OBJECTS: GET_ALL_OBJECTS; GET_OBJECTS: GET_OBJECTS; diff --git a/src/com/actions/renderer/startrender.ts b/src/com/actions/renderer/startrender.ts new file mode 100644 index 00000000..8d06ecfd --- /dev/null +++ b/src/com/actions/renderer/startrender.ts @@ -0,0 +1,5 @@ +export default interface START_RENDER { + DESCRIPTION: 'Starts the render process.'; + PAYLOAD: undefined; + RETURN: boolean; +} diff --git a/src/dive.ts b/src/dive.ts index 871fddc5..7eb66451 100644 --- a/src/dive.ts +++ b/src/dive.ts @@ -23,6 +23,7 @@ import pkgjson from '../package.json'; export type DIVESettings = { autoResize: boolean; + autoStart: boolean; displayAxes: boolean; renderer: Partial; perspectiveCamera: Partial; @@ -31,6 +32,7 @@ export type DIVESettings = { export const DIVEDefaultSettings: DIVESettings = { autoResize: true, + autoStart: true, displayAxes: false, renderer: DIVERendererDefaultSettings, perspectiveCamera: DIVEPerspectiveCameraDefaultSettings, @@ -266,9 +268,6 @@ export default class DIVE { this.addResizeObserver(); } - // whene everything is done, start the renderer - this.renderer.StartRenderer(this.scene, this.perspectiveCamera); - // eslint-disable-next-line @typescript-eslint/no-explicit-any (window as any).DIVE = { PrintScene: () => { @@ -307,6 +306,11 @@ export default class DIVE { @@@@@@@ @@@@@@ `); + + if (this._settings.autoStart) { + // when everything is done, start the renderer + this.renderer.StartRenderer(this.scene, this.perspectiveCamera); + } } public Dispose(): void { diff --git a/src/toolbox/Toolbox.ts b/src/toolbox/Toolbox.ts index 2e4a0d84..62f9fbf9 100644 --- a/src/toolbox/Toolbox.ts +++ b/src/toolbox/Toolbox.ts @@ -1,7 +1,7 @@ import type DIVEOrbitControls from '../controls/OrbitControls.ts'; import { type DIVEScene } from '../scene/Scene.ts'; import { type DIVEBaseTool } from './BaseTool.ts'; -import { type DIVESelectTool } from './select/SelectTool.ts'; +import { DIVESelectTool } from './select/SelectTool.ts'; export type ToolType = 'select' | 'none'; @@ -22,8 +22,6 @@ export default class DIVEToolbox { private _selectTool: DIVESelectTool | null; public get selectTool(): DIVESelectTool { if (!this._selectTool) { - const DIVESelectTool = require('./select/SelectTool.ts') - .DIVESelectTool as typeof import('./select/SelectTool.ts').DIVESelectTool; this._selectTool = new DIVESelectTool( this._scene, this._controller,