ThreePresenter API Documentation - v0.1.2
    Preparing search index...

    Class ThreePresenter

    ThreePresenter - Main 3D Scene Presenter Component

    Manages the complete 3D viewing experience including model loading, rendering, camera controls, lighting, and user interactions.

    This class is responsible for:

    • Loading and displaying 3D models from scene.json configuration
    • Managing Three.js scene, camera, renderer, and controls
    • Providing UI controls (visibility, lighting, camera reset, screenshots)
    • Handling model transformations (position, rotation, scale)
    • Supporting multiple 3D file formats (GLB, PLY, OBJ, etc.)
    • Auto-centering and normalizing model sizes
    const presenter = new ThreePresenter(mountElement);
    await presenter.loadScene(sceneDescription);
    presenter.setModelVisibility('model_id', false);
    Index

    Constructors

    Methods

    • Toggle picking mode for annotation placement

      Returns void

    • Smoothly animate the camera controls target to a new position

      Parameters

      • targetPosition: Vector3

      Returns void

    • Load a new scene description

      Parameters

      • sceneDesc: SceneDescription

        Scene description object defining models, environment, and settings

      • preserveCamera: boolean = false

        If true, keeps current camera position instead of reframing

      Returns Promise<void>

      Load a simple scene with one model:

      await presenter.loadScene({
      models: [{
      id: 'venus',
      file: 'venus.glb',
      rotation: [-90, 0, 0]
      }]
      });

      Load a complex scene with multiple models and environment settings:

      await presenter.loadScene({
      rotationUnits: 'deg',
      models: [
      {
      id: 'building',
      file: 'building.glb',
      title: 'Main Building',
      position: [0, 0, 0],
      rotation: [0, 45, 0],
      scale: 1.5
      },
      {
      id: 'terrain',
      file: 'terrain.ply',
      position: [0, -5, 0]
      }
      ],
      environment: {
      showGround: true,
      background: '#87CEEB',
      headLightOffset: [15, 30]
      },
      annotations: [
      {
      id: 'entrance',
      label: 'Main Entrance',
      type: 'point',
      geometry: [10, 2, 5]
      }
      ]
      });
    • Apply transforms from ModelDefinition to a loaded Object3D

      • position: [x,y,z]
      • rotation: [x,y,z] in radians or degrees (auto-detect)
      • scale: single number or [x,y,z]

      Parameters

      Returns void

    • Apply environment settings (ground, background, scale indicator)

      Parameters

      • env: any

      Returns void

    • Setup orbit controls and viewport gizmo

      Returns Promise<void>

    • Load a single model.

      This method performs the following steps for each model:

      1. URL Resolution: Resolves the full URL of the model file using the configured FileUrlResolver.
      2. Loading: Fetches and parses the model file (PLY, GLTF, GLB, etc.) using ModelLoader.
        • Automatically detects format from extension.
        • Applies material overrides (color, roughness, metalness) if specified.
      3. Transformation: Applies position, rotation, and scale transformations defined in the model definition.
      4. Visibility: Sets the initial visibility state.
      5. Statistics: Calculates geometry statistics (vertex count, bounding box, etc.).
      6. Scene Addition: Adds the model to the Three.js scene and registers it in the models map.

      Parameters

      • modelDef: ModelDefinition

        The model definition containing file path and properties.

      Returns Promise<void>

    • Load a model file based on its extension

      Parameters

      Returns Promise<Object3D<Object3DEventMap>>

    • Frame the scene - position models and camera without scaling Models without predefined positions are translated so:

      • Bottom of bbox is at y=0
      • Center of X and Z axes are at origin Camera is positioned at appropriate distance based on scene size

      Returns void

    • Apply transformations to a specific model without saving to scene Useful for live preview while editing

      Parameters

      • modelId: string
      • Optionalposition: [number, number, number] | null
      • Optionalrotation: [number, number, number] | null
      • Optionalscale: number | [number, number, number] | null

      Returns void

    • Set visibility of a model by ID

      Parameters

      • modelId: string
      • visible: boolean

      Returns void

    • Get visibility of a specific model

      Parameters

      • modelId: string

      Returns boolean

    • Get visibility of all models

      Returns Record<string, boolean>

    • Set background color without reloading the scene

      Parameters

      • color: string

        Hex color string (e.g., '#404040')

      Returns void

    • Toggle ground visibility without reloading the scene

      Parameters

      • visible: boolean

        Whether the ground should be visible

      Returns void

    • Set head light offset without reloading the scene

      Parameters

      • thetaDeg: number

        Horizontal angle in degrees

      • phiDeg: number

        Vertical angle in degrees

      Returns void

    • Calculate triangle and vertex counts for a loaded model

      Parameters

      • modelId: string

        The ID of the model to analyze

      Returns
          | {
              triangles: number;
              vertices: number;
              bbox: { x: number; y: number; z: number };
              textures: {
                  count: number;
                  dimensions: { width: number; height: number }[];
              };
          }
          | null

      Object with triangle and vertex counts, or null if model not found

    Properties

    renderer: WebGLRenderer
    scene: Scene
    camera: PerspectiveCamera | OrthographicCamera
    orthographicCamera: OrthographicCamera | null = null
    perspectiveCamera: PerspectiveCamera
    isOrthographic: boolean = false
    controls: any
    models: Record<string, THREE.Object3D> = {}

    Map of loaded runtime 3D objects, keyed by their model ID.

    These are the actual THREE.Object3D instances in the scene. Their initial state (visibility, position, etc.) is derived from the ModelDefinition configuration.

    currentScene: SceneDescription | null = null
    mount: HTMLDivElement
    ground: GridHelper | null = null
    scaleIndicator: ScaleIndicator | null = null
    viewportGizmo: any = null
    isPickingMode: boolean = false
    onPointPicked: ((point: [number, number, number]) => void) | null = null
    onLightChange?: (enabled: boolean) => void
    onEnvChange?: (enabled: boolean) => void
    onPickingModeChange?: (enabled: boolean) => void
    onCameraModeChange?: (isOrthographic: boolean) => void
    initialCameraPosition: Vector3 = ...
    initialControlsTarget: Vector3 = ...
    lightEnabled: boolean = true
    modelStats: Record<string, GeometryStats> = {}
    sceneBBoxSize: Vector3 = ...
    fileUrlResolver: FileUrlResolver
    onLoadProgress?: (progress: LoadingProgress) => void
    onLoadComplete?: (modelId: string) => void
    onLoadError?: (modelId: string, error: Error) => void
    annotationManager: AnnotationManager
    cameraManager: CameraManager
    lightingManager: LightingManager
    modelLoader: ModelLoader
    inputController: InputController
    renderLoop: RenderLoop