SplatViewer.Camera (SplatViewer v0.1.0)

Copy Markdown View Source

A starting viewpoint for a scene.

No splat format carries a camera. A .sog file is a list of gaussians and nothing else, so a viewer that opens without one points wherever its default happens to point — which, for most real captures, is at nothing.

SplatTools.prepare/3 derives one of these when it converts a capture, and the right thing to do with it is store it beside the file. This struct is what travels between the two.

Summary

Types

t()

A point or direction in the scene's own coordinate space.

Functions

Builds a camera from a map, accepting either atom or string keys.

Builds a camera, raising on anything invalid.

Renders a camera as the JSON the browser hook reads.

Types

t()

@type t() :: %SplatViewer.Camera{fov: number(), position: vector(), target: vector()}

vector()

@type vector() :: {number(), number(), number()}

A point or direction in the scene's own coordinate space.

Functions

new(camera)

@spec new(map() | t()) :: {:ok, t()} | {:error, String.t()}

Builds a camera from a map, accepting either atom or string keys.

Both because it arrives two ways: as a struct from splat_tools in the same VM, or as JSON out of a database column, where the keys are strings and the vectors are lists rather than tuples.

iex> SplatViewer.Camera.new(%{"position" => [1, 2, 3], "target" => [0, 0, 0]})
{:ok, %SplatViewer.Camera{position: {1, 2, 3}, target: {0, 0, 0}, fov: 50.0}}

new!(input)

@spec new!(map() | t()) :: t()

Builds a camera, raising on anything invalid.

to_json(camera)

@spec to_json(t()) :: String.t()

Renders a camera as the JSON the browser hook reads.

iex> camera = SplatViewer.Camera.new!(%{position: [2, 1, -2], target: [0, 0, 0]})
iex> camera |> SplatViewer.Camera.to_json() |> Jason.decode!()
%{"fov" => 50.0, "position" => [2, 1, -2], "target" => [0, 0, 0]}