threedviewer 2.2.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,4 @@
1
1
  import { IRenderer, IRendererOptions, IScene, IModelLoader, ICamera, IControls, IObject3D, Result } from './interfaces';
2
- import { ViewerState } from './entities/ViewerState';
3
2
  import { TypedEventEmitter } from '../events/EventEmitter';
4
3
  import { ViewerEventMap } from './events/ViewerEvents';
5
4
  import { SimpleViewerOptions } from '../types/SimpleViewerOptions';
@@ -7,6 +6,7 @@ import { IPathTracingService } from './services/IPathTracingService';
7
6
  import { IEnvironmentService } from './services/IEnvironmentService';
8
7
  import { ISceneSetupService } from './services/ISceneSetupService';
9
8
  import { IFloorAlignmentService } from './services/IFloorAlignmentService';
9
+ import { ViewerState } from './entities/ViewerState';
10
10
  export interface ViewerDependencies {
11
11
  renderer: IRenderer;
12
12
  scene: IScene;
@@ -25,31 +25,26 @@ export interface ViewerDependencies {
25
25
  * Independent of UI framework and rendering engine
26
26
  */
27
27
  export declare class ViewerCore {
28
- private state;
29
28
  private readonly events;
30
29
  private readonly renderLoopManager;
31
30
  private lastFrameTime;
32
31
  private frameCount;
33
- private stateChangeCallback?;
34
32
  private pathTracingStartTime?;
35
- private screenshotElement;
36
- private isShowingScreenshot;
37
- private screenshotResizeHandler?;
38
- private serializedSceneState?;
39
- private lastModelUrl?;
40
33
  private pathTracingCompleteHandled;
41
34
  private disposed;
35
+ private readonly stateManager;
36
+ private readonly screenshotManager;
37
+ private readonly modelManager;
38
+ private readonly resourceManager;
42
39
  private readonly renderer;
43
40
  private readonly scene;
44
41
  private readonly camera;
45
42
  private readonly controls;
46
- private readonly modelLoader;
47
43
  private readonly options;
48
44
  private readonly rendererOptions?;
49
45
  private readonly sceneSetupService?;
50
46
  private environmentService?;
51
47
  private pathTracingService?;
52
- private readonly floorAlignmentService?;
53
48
  constructor(dependencies: ViewerDependencies);
54
49
  /**
55
50
  * Initialize the viewer
@@ -99,14 +94,6 @@ export declare class ViewerCore {
99
94
  * Restore the 3D scene from screenshot
100
95
  */
101
96
  private restoreFromScreenshot;
102
- /**
103
- * Dispose scene resources while keeping the screenshot
104
- */
105
- private disposeSceneResources;
106
- /**
107
- * Recursively dispose of an object and its children
108
- */
109
- private disposeObject;
110
97
  /**
111
98
  * Dispose of all resources
112
99
  */
@@ -0,0 +1,53 @@
1
+ import { IModelLoader, IObject3D, IScene, ICamera, IControls, Result } from '../interfaces';
2
+ import { IFloorAlignmentService } from '../services/IFloorAlignmentService';
3
+ import { ISceneSetupService } from '../services/ISceneSetupService';
4
+ import { TypedEventEmitter } from '../../events/EventEmitter';
5
+ import { ViewerEventMap } from '../events/ViewerEvents';
6
+ export interface ModelManagerDependencies {
7
+ modelLoader: IModelLoader;
8
+ scene: IScene;
9
+ camera: ICamera;
10
+ controls: IControls;
11
+ floorAlignmentService?: IFloorAlignmentService;
12
+ sceneSetupService?: ISceneSetupService;
13
+ autoFitToObject?: boolean;
14
+ }
15
+ /**
16
+ * Manages model loading, disposal, and scene setup
17
+ */
18
+ export declare class ModelManager {
19
+ private currentModel;
20
+ private lastModelUrl?;
21
+ private readonly modelLoader;
22
+ private readonly scene;
23
+ private readonly camera;
24
+ private readonly controls;
25
+ private readonly floorAlignmentService?;
26
+ private readonly sceneSetupService?;
27
+ private readonly autoFitToObject;
28
+ constructor(dependencies: ModelManagerDependencies);
29
+ /**
30
+ * Get current model
31
+ */
32
+ getCurrentModel(): IObject3D | null;
33
+ /**
34
+ * Get last loaded model URL
35
+ */
36
+ getLastModelUrl(): string | undefined;
37
+ /**
38
+ * Load a 3D model
39
+ */
40
+ loadModel(source: string | IObject3D, events: TypedEventEmitter<ViewerEventMap>): Promise<Result<IObject3D>>;
41
+ /**
42
+ * Dispose current model
43
+ */
44
+ disposeCurrentModel(): void;
45
+ /**
46
+ * Recursively dispose of an object and its children
47
+ */
48
+ private disposeObject;
49
+ /**
50
+ * Dispose all resources
51
+ */
52
+ dispose(): void;
53
+ }
@@ -0,0 +1,40 @@
1
+ import { IScene } from '../interfaces';
2
+ import { IPathTracingService } from '../services/IPathTracingService';
3
+ import { IEnvironmentService } from '../services/IEnvironmentService';
4
+ export interface ResourceManagerDependencies {
5
+ scene: IScene;
6
+ pathTracingService?: IPathTracingService;
7
+ environmentService?: IEnvironmentService;
8
+ }
9
+ /**
10
+ * Manages resource disposal and cleanup
11
+ */
12
+ export declare class ResourceManager {
13
+ private readonly scene;
14
+ private pathTracingService?;
15
+ private environmentService?;
16
+ constructor(dependencies: ResourceManagerDependencies);
17
+ /**
18
+ * Update services (needed after screenshot restoration)
19
+ */
20
+ updateServices(services: {
21
+ pathTracingService?: IPathTracingService;
22
+ environmentService?: IEnvironmentService;
23
+ }): void;
24
+ /**
25
+ * Dispose scene resources (for screenshot mode)
26
+ */
27
+ disposeSceneResources(preservePathTracing?: boolean): void;
28
+ /**
29
+ * Dispose all services
30
+ */
31
+ disposeServices(): void;
32
+ /**
33
+ * Complete disposal of all resources
34
+ */
35
+ dispose(): void;
36
+ /**
37
+ * Trigger garbage collection hint
38
+ */
39
+ private triggerGarbageCollection;
40
+ }
@@ -0,0 +1,38 @@
1
+ import { IRenderer, ICamera, IControls } from '../interfaces';
2
+ import { SerializedSceneState } from '../utils/SceneSerializer';
3
+ export interface ScreenshotManagerDependencies {
4
+ renderer: IRenderer;
5
+ onRestore?: () => Promise<void>;
6
+ }
7
+ /**
8
+ * Manages screenshot capture and restoration functionality
9
+ */
10
+ export declare class ScreenshotManager {
11
+ private screenshotElement;
12
+ private isShowingScreenshot;
13
+ private screenshotResizeHandler?;
14
+ private serializedSceneState?;
15
+ private readonly renderer;
16
+ private readonly onRestore?;
17
+ constructor(dependencies: ScreenshotManagerDependencies);
18
+ /**
19
+ * Check if currently showing a screenshot
20
+ */
21
+ isActive(): boolean;
22
+ /**
23
+ * Capture current frame and replace canvas with screenshot
24
+ */
25
+ captureAndReplace(camera: ICamera, controls: IControls, lastModelUrl?: string, onResourcesDisposed?: () => void): void;
26
+ /**
27
+ * Restore the 3D scene from screenshot
28
+ */
29
+ restore(): Promise<void>;
30
+ /**
31
+ * Get serialized scene state for restoration
32
+ */
33
+ getSerializedState(): SerializedSceneState | undefined;
34
+ /**
35
+ * Clean up resources
36
+ */
37
+ dispose(): void;
38
+ }
@@ -0,0 +1,78 @@
1
+ import { ViewerState } from '../entities/ViewerState';
2
+ import { ThreeViewerError } from '../../errors';
3
+ import { IObject3D } from '../interfaces';
4
+ export interface StateChangeCallback {
5
+ (state: ViewerState): void;
6
+ }
7
+ /**
8
+ * Manages viewer state transitions and notifications
9
+ */
10
+ export declare class StateManager {
11
+ private state;
12
+ private readonly stateChangeCallbacks;
13
+ constructor();
14
+ /**
15
+ * Get current state
16
+ */
17
+ getState(): ViewerState;
18
+ /**
19
+ * Set initialized state
20
+ */
21
+ setInitialized(): void;
22
+ /**
23
+ * Start loading state
24
+ */
25
+ startLoading(): void;
26
+ /**
27
+ * Set loaded state with model
28
+ */
29
+ setLoaded(model: IObject3D): void;
30
+ /**
31
+ * Set error state
32
+ */
33
+ setError(error: ThreeViewerError): void;
34
+ /**
35
+ * Start rendering state
36
+ */
37
+ startRendering(): void;
38
+ /**
39
+ * Update render info
40
+ */
41
+ updateRenderInfo(info: {
42
+ frameCount: number;
43
+ fps: number;
44
+ lastRenderTime: number;
45
+ }): void;
46
+ /**
47
+ * Set disposed state
48
+ */
49
+ setDisposed(): void;
50
+ /**
51
+ * Check if can load model in current state
52
+ */
53
+ canLoad(): boolean;
54
+ /**
55
+ * Check if viewer is initialized
56
+ */
57
+ isInitialized(): boolean;
58
+ /**
59
+ * Get current status
60
+ */
61
+ getStatus(): 'idle' | 'loading' | 'loaded' | 'rendering' | 'error' | 'disposed';
62
+ /**
63
+ * Get current model
64
+ */
65
+ getCurrentModel(): IObject3D | null;
66
+ /**
67
+ * Subscribe to state changes
68
+ */
69
+ onStateChange(callback: StateChangeCallback): () => void;
70
+ /**
71
+ * Clear all callbacks
72
+ */
73
+ clearCallbacks(): void;
74
+ /**
75
+ * Update state and notify listeners
76
+ */
77
+ private updateState;
78
+ }
@@ -0,0 +1,4 @@
1
+ export { StateManager } from './StateManager';
2
+ export { ScreenshotManager } from './ScreenshotManager';
3
+ export { ModelManager } from './ModelManager';
4
+ export { ResourceManager } from './ResourceManager';
@@ -13,7 +13,7 @@ export interface IEnvironmentService {
13
13
  /**
14
14
  * Apply environment to scene
15
15
  */
16
- applyToScene(scene: IScene, texture: ITexture): Result<void>;
16
+ applyToScene(scene: IScene, texture: ITexture, options?: IEnvironmentApplyOptions): Result<void>;
17
17
  /**
18
18
  * Create studio environment
19
19
  */
@@ -32,3 +32,8 @@ export interface IStudioEnvironmentOptions {
32
32
  groundColor?: string;
33
33
  skyColor?: string;
34
34
  }
35
+ export interface IEnvironmentApplyOptions {
36
+ backgroundBlurriness?: number;
37
+ backgroundIntensity?: number;
38
+ environmentIntensity?: number;
39
+ }
@@ -3,6 +3,7 @@ import { IScene } from '../interfaces/IScene';
3
3
  import { IObject3D } from '../interfaces/IObject3D';
4
4
  import { ICamera } from '../interfaces/ICamera';
5
5
  import { IControls } from '../interfaces/IControls';
6
+ import { GridHelperOptions, AxesHelperOptions } from '../../types/options/HelperOptions';
6
7
  /**
7
8
  * Service for setting up scene elements like helpers, lighting, and backgrounds
8
9
  */
@@ -29,12 +30,12 @@ export interface ISceneSetupService {
29
30
  addDynamicGrid(scene: IScene, object: IObject3D, scaleFactor?: number): Result<void>;
30
31
  }
31
32
  export interface IHelperOptions {
32
- grid?: boolean;
33
+ grid?: boolean | GridHelperOptions;
33
34
  gridSize?: number;
34
35
  gridDivisions?: number;
35
36
  gridColor?: string;
36
37
  gridCenterLineColor?: string;
37
- axes?: boolean;
38
+ axes?: boolean | AxesHelperOptions;
38
39
  axesSize?: number;
39
40
  object3DHelper?: boolean;
40
41
  }
@@ -1,4 +1,4 @@
1
- import { IEnvironmentService, IEnvironmentOptions, IStudioEnvironmentOptions } from '../../core/services/IEnvironmentService';
1
+ import { IEnvironmentService, IEnvironmentOptions, IStudioEnvironmentOptions, IEnvironmentApplyOptions } from '../../core/services/IEnvironmentService';
2
2
  import { IScene, ITexture } from '../../core/interfaces/IScene';
3
3
  import { Result } from '../../utils/Result';
4
4
  export declare class ThreeEnvironmentService implements IEnvironmentService {
@@ -7,7 +7,7 @@ export declare class ThreeEnvironmentService implements IEnvironmentService {
7
7
  constructor();
8
8
  initialize(options: IEnvironmentOptions): Promise<Result<void>>;
9
9
  loadEnvironmentMap(url: string): Promise<Result<ITexture>>;
10
- applyToScene(scene: IScene, texture: ITexture): Result<void>;
10
+ applyToScene(scene: IScene, texture: ITexture, options?: IEnvironmentApplyOptions): Result<void>;
11
11
  /**
12
12
  * Get the original environment texture (for path tracing)
13
13
  */
@@ -0,0 +1,21 @@
1
+ import { IGridStyle, IGridOptions, GridType } from './IGridStyle';
2
+ import * as THREE from 'three';
3
+ export declare class GridFactory {
4
+ private static gridStyles;
5
+ /**
6
+ * Create a grid of the specified type
7
+ */
8
+ static createGrid(type: GridType, options: IGridOptions): THREE.Object3D;
9
+ /**
10
+ * Register a custom grid style
11
+ */
12
+ static registerGridStyle(type: GridType | string, style: IGridStyle): void;
13
+ /**
14
+ * Get available grid types
15
+ */
16
+ static getAvailableTypes(): string[];
17
+ /**
18
+ * Dispose of a specific grid style's resources
19
+ */
20
+ static disposeGridStyle(type: GridType): void;
21
+ }
@@ -0,0 +1,7 @@
1
+ import { IGridStyle, IGridOptions } from './IGridStyle';
2
+ import * as THREE from 'three';
3
+ export declare class HexagonalGlassGrid implements IGridStyle {
4
+ name: string;
5
+ createGrid(options: IGridOptions): THREE.Object3D;
6
+ dispose(): void;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { IGridStyle, IGridOptions } from './IGridStyle';
2
+ import * as THREE from 'three';
3
+ export declare class HexagonalWireGrid implements IGridStyle {
4
+ name: string;
5
+ createGrid(options: IGridOptions): THREE.Object3D;
6
+ dispose(): void;
7
+ }
@@ -0,0 +1,45 @@
1
+ import * as THREE from 'three';
2
+ export interface IGridStyle {
3
+ /**
4
+ * Name of the grid style
5
+ */
6
+ name: string;
7
+ /**
8
+ * Create the grid geometry and materials
9
+ */
10
+ createGrid(options: IGridOptions): THREE.Object3D;
11
+ /**
12
+ * Dispose of any resources used by this grid style
13
+ */
14
+ dispose?(): void;
15
+ }
16
+ export interface IGridOptions {
17
+ size: number;
18
+ divisions: number;
19
+ color?: string | number;
20
+ centerLineColor?: string | number;
21
+ opacity?: number;
22
+ styleOptions?: {
23
+ hexRadius?: number;
24
+ tileSize?: number;
25
+ texture?: string;
26
+ normalMap?: string;
27
+ roughnessMap?: string;
28
+ metalness?: number;
29
+ roughness?: number;
30
+ transmission?: number;
31
+ thickness?: number;
32
+ ior?: number;
33
+ height?: number;
34
+ bevelSize?: number;
35
+ randomHeight?: boolean;
36
+ randomRotation?: boolean;
37
+ };
38
+ }
39
+ export declare enum GridType {
40
+ SQUARE_WIRE = "square_wire",
41
+ HEXAGONAL_WIRE = "hexagonal_wire",
42
+ HEXAGONAL_GLASS = "hexagonal_glass",
43
+ STONE_TILES = "stone_tiles",
44
+ CUSTOM = "custom"
45
+ }
@@ -0,0 +1,7 @@
1
+ import { IGridStyle, IGridOptions } from './IGridStyle';
2
+ import * as THREE from 'three';
3
+ export declare class SquareWireGrid implements IGridStyle {
4
+ name: string;
5
+ createGrid(options: IGridOptions): THREE.Object3D;
6
+ dispose(): void;
7
+ }
@@ -0,0 +1,11 @@
1
+ import { IGridStyle, IGridOptions } from './IGridStyle';
2
+ import * as THREE from 'three';
3
+ export declare class StoneTileGrid implements IGridStyle {
4
+ name: string;
5
+ private textureLoader;
6
+ private loadedTextures;
7
+ createGrid(options: IGridOptions): THREE.Object3D;
8
+ private createStoneMaterial;
9
+ private loadTexture;
10
+ dispose(): void;
11
+ }
@@ -0,0 +1,6 @@
1
+ export * from './IGridStyle';
2
+ export * from './GridFactory';
3
+ export * from './SquareWireGrid';
4
+ export * from './HexagonalWireGrid';
5
+ export * from './HexagonalGlassGrid';
6
+ export * from './StoneTileGrid';