# @rbxts/viewport-model

> Typings of Lua class to calculate camera distance/cframe for fitting models into viewport frames

Latest version **1.0.4** (published 2022-10-19) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @rbxts/viewport-model
pnpm add @rbxts/viewport-model
yarn add @rbxts/viewport-model
bun add @rbxts/viewport-model
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2022-10-19 |
| First published | 2022-10-04 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Monzter |
| Maintainers | monzter |
| Keywords | rbxts, viewport, viewportframe, viewportmodel, roblox |

## Links

- npm: https://www.npmjs.com/package/@rbxts/viewport-model
- Repository: https://github.com/MonzterDev/Roblox-TS-Libraries.git#main
- Homepage: https://github.com/MonzterDev/Roblox-TS-Libraries/tree/main#readme
- Issues: https://github.com/MonzterDev/Roblox-TS-Libraries/issues
- npm.io page: https://npm.io/package/@rbxts/viewport-model

## Recent versions

- 1.0.4 (latest) — 2022-10-19
- 1.0.3 — 2022-10-04
- 1.0.2 — 2022-10-04
- 1.0.1 — 2022-10-04
- 1.0.0 — 2022-10-04

## README

# Viewport-Model-TS

This contains the typing for [EgoMoose's Viewport Model](https://gist.github.com/EgoMoose/2fd62ee98754380f6d839267ffe4f588)

## Usage

### Functions

```TS
    new( viewportFrame: ViewportFrame, camera: Camera ): ViewportModelClass;

    /**
     * Does the work to display a Model in the Viewport Frame
     */
    GenerateViewport ( viewportFrame: ViewportFrame, model: Model, orientation?: CFrame ): void

    /**
     * Removes previous Model from Viewport Frame
     */
    CleanViewport (viewportFrame: ViewportFrame) : void
```

### Viewport Model Class Methods

```TS
    /**
     * Used to set the model that is being focused on
     *
     * should be used for new models and/or a change in the current model
     *
     * e.g. parts added/removed from the model or the model cframe changed
     */
    SetModel ( model: Model ): void;

    /**
     * Should be called when something about the viewport frame / camera changes
     *
     * e.g. the frame size or the camera field of view
     */
    Calibrate (): void;

    /**
     * returns a fixed distance that is guarnteed to encapsulate the full model
     *
     * this is useful for when you want to rotate freely around an object w/o expensive calculations
     *
     * focus position can be used to set the origin of where the camera's looking
     *
     * otherwise the model's center is assumed
     */
    GetFitDistance ( focusPosition: Vector3 ): Vector3;

    /**
     * returns the optimal camera cframe that would be needed to best fit
     *
     * the model in the viewport frame at the given orientation.
     *
     * keep in mind this functions best when the model's point-cloud is correct
     *
     * as such models that rely heavily on meshesh, csg, etc will only return an accurate
     *
     * result as their point cloud
     */
    GetMinimumFitCFrame(orientation: CFrame): CFrame;
```

---
_Source: https://npm.io/package/@rbxts/viewport-model · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
