@kognifai/cogsengine
    Preparing search index...

    Class Control

    A Cogs control tells which canvas we're drawing to. Multiple controls requires separate instances of Cogs New instances are created using

    • create() static method.

    Call

    • release() to shut down Cogs. Note that client event handles on the owning canvas may prevent proper cleanup of Cogs.js memory. See Cogs.js FAQ for details.

    class Control is an

    • EventTarget. Available Cogs event types: "preRender" - Called before each frame is rendered. "postRender" - Called after each frame is rendered.

    Hierarchy

    • EventTarget
      • Control
    Index

    Accessors

    • get canvas(): HTMLCanvasElement

      HTML5 Canvas, either created by Control or passed in using the settings.canvas

      Returns HTMLCanvasElement

      ControlSettings.canvas property.

    • get clientPixelRatio(): number

      Returns the active client pixel ratio as updated on the last render.

      Returns number

    • set clientPixelRatio(ratio: number): void

      Sets the client pixel ratio, will be updated on the next render.

      Parameters

      • ratio: number

      Returns void

    • get continousRendering(): boolean

      Gets Continuous Rendering setting.

      Returns boolean

      use get continuousRendering.

    • get continuousRendering(): boolean

      Gets continuous rendering setting. Use

      Returns boolean

      setContinuousRendering to enable.

    • get currentHeight(): number

      Gets parentElement.clientHeight. Differs from canvas.width if window.devicePixelRatio set

      Returns number

    • get currentWidth(): number

      Gets parentElement.clientWidth. Differs from canvas.width if window.devicePixelRatio set

      Returns number

    • get domElement(): HTMLCanvasElement | HTMLElement

      The root dom element for the control. Either a canvas or a div containing a canvas

      Returns HTMLCanvasElement | HTMLElement

    • get input(): Input

      Returns Input

    • get parentElement(): HTMLElement

      Optional Element used when auto-resizing the canvas. Passed in using the settings.parent

      Returns HTMLElement

      ControlSettings.parent property

    • get reportState(): boolean

      Enable or disable logging Cogs heapsize every 5 seconds.

      Returns boolean

    • set reportState(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get resources(): Resources

      Gets Cogs Resources

      Returns Resources

    • get runtime(): Runtime

      Gets Cogs Runtime

      Returns Runtime

    • get scene(): Scene

      Gets Cogs Scene

      Returns Scene

    Methods

    • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

      The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

      When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

      When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

      When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

      If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

      The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

      MDN Reference

      Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject
      • Optionaloptions: boolean | AddEventListenerOptions

      Returns void

    • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

      MDN Reference

      Parameters

      • event: Event

      Returns boolean

    • Gets the XR control module. 'any' for now until IControlXR have been finalized.

      Returns any

    • Called to shut down Cogs.js, free memory including WEB Assembly. This instance cannot be used after release() called.

      Returns void

    • Releases the XR control module to disable XR

      Returns void

    • Removes the event listener in target's event listener list with the same type, callback, and options.

      MDN Reference

      Parameters

      • type: string
      • callback: EventListenerOrEventListenerObject
      • Optionaloptions: boolean | EventListenerOptions

      Returns void

    • Request full screen. Currently not tested in any example. API can only be initiated by a user gesture.

      Parameters

      • lock: boolean

        True if lock

      • resize: boolean

        True if resize.

      Returns void

    • Resize control. This is for the contents. This typically need to match the canvas size which is set separately.

      Parameters

      • width: number

        Control width pixels

      • height: number

        Control height pixels

      Returns void

    • Legacy. Misnamed variable kept for compatibility

      Parameters

      • value: boolean

        True if enabled

      Returns void

      Use

      setContinuousRendering

    • Enable continuous rendering after startup by passing true. Cogs will redraw the display when needed. Use carefully as enabling will consume a lot of resources. Use triggerUpdate() for manual display redraw.

      Parameters

      • value: boolean

        True if enabled

      Returns void

    • Set the rendering mode.

      Parameters

      Returns void

    • Sets XR control from the external CogsXR package. 'any' for now until IControlXR have been finalized.

      Parameters

      • xr: any

      Returns void

    • Returns void

    • Parameters

      • Optionalforce: boolean

      Returns void

    • Factory method for creating a new Cogs control. See

      Parameters

      Returns Promise<Control>

      Created control

      ControlSettings and Cogs.js documentation for details.

        control = await Cogs.Control.create({
      parent: parentElement,
      onInitialized: function () {
      runtime = control.runtime;
      runtime.Cube.create();
      const cameraController = runtime.OrbitingCameraController.create();
      runtime.scene.camera.components.add(cameraController);
      },
      print: function (text) {
      console.log(text);
      }
      });
      parent.appendChild(control.domElement);