Ply.Property (Ply v0.1.0)

Copy Markdown View Source

One property of a PLY element.

A property is either a scalar (property float x) or a variable-length list (property list uchar int vertex_indices), where the count is stored inline before the values.

Property names are kept as strings. They come from the file and are arbitrary, so converting them to atoms would let an untrusted file exhaust the VM's atom table.

Summary

Types

Either a scalar type, or {:list, count_type, value_type} for a variable-length list.

t()

Functions

Builds a list property.

Whether this property is a variable-length list.

Builds a scalar property.

Renders the property as a PLY header line (without a trailing newline).

Byte width of a scalar property, or :variable for a list.

Types

kind()

@type kind() :: Ply.Types.t() | {:list, Ply.Types.t(), Ply.Types.t()}

Either a scalar type, or {:list, count_type, value_type} for a variable-length list.

t()

@type t() :: %Ply.Property{name: String.t(), type: kind()}

Functions

list(name, count_type, value_type)

@spec list(String.t(), Ply.Types.t(), Ply.Types.t()) :: t()

Builds a list property.

iex> Ply.Property.list("vertex_indices", :uint8, :int32)
%Ply.Property{name: "vertex_indices", type: {:list, :uint8, :int32}}

list?(property)

@spec list?(t()) :: boolean()

Whether this property is a variable-length list.

iex> Ply.Property.list?(Ply.Property.scalar("x", :float32))
false

scalar(name, type)

@spec scalar(String.t(), Ply.Types.t()) :: t()

Builds a scalar property.

iex> Ply.Property.scalar("x", :float32)
%Ply.Property{name: "x", type: :float32}

to_header_line(property)

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

Renders the property as a PLY header line (without a trailing newline).

width(property)

@spec width(t()) :: pos_integer() | :variable

Byte width of a scalar property, or :variable for a list.

iex> Ply.Property.width(Ply.Property.scalar("x", :float32))
4