rexfile

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2020 License: Apache-2.0 Imports: 4 Imported by: 7

Documentation

Index

Constants

View Source
const (
	Raw24 = iota
	Jpeg
	Png
)
View Source
const (
	// NotSpecified is used if no material or no texture image is set
	NotSpecified = 0x7fffffffffffffff
)

Variables

This section is empty.

Functions

func NewCube

func NewCube(id, matID uint64, size float32) (Mesh, Material)

NewCube returns a new cube with size (meters)

func SampleRex

func SampleRex() []byte

SampleRex returns a valid REX buffer containing colored points

func WriteDataBlockHeader

func WriteDataBlockHeader(w io.Writer, hdr DataBlockHeader) error

WriteDataBlockHeader writes the given data block header to the writer

Types

type DataBlockHeader

type DataBlockHeader struct {
	Type    uint16
	Version uint16
	Size    uint32 // the Size is the size of the data block w/o the data block header
	ID      uint64
}

DataBlockHeader stores the header information of a data block

func ReadDataBlockHeader

func ReadDataBlockHeader(r io.Reader) (DataBlockHeader, error)

ReadDataBlockHeader reads a data block header from reader

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder which can be used to read and decode REX files from a stream

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates a new REX decoder with a given input stream

func (*Decoder) Decode

func (dec *Decoder) Decode() (*Header, *File, error)

Decode reads the input from the reader and returns a valid REX datastructure.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder is used to dump a valid REX file buffer into a writer

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder creates a new REX encoder

func (*Encoder) Encode

func (enc *Encoder) Encode(r File) error

Encode encodes a given REX file buffer into the writer stream. The function returns the number of bytes being written to the writer and nil if no error occurs.

type File

type File struct {
	LineSets      []LineSet
	Texts         []Text
	PointLists    []PointList
	Meshes        []Mesh
	Materials     []Material
	Images        []Image
	SceneNodes    []SceneNode
	Tracks        []Track
	UnknownBlocks uint
}

File represents a complete valid REX file which can either be stored locally or sent to an arbirary writer with the Encoder.

func (*File) Header

func (f *File) Header() *Header

Header generates a proper header for the File datastructure

type Header struct {
	Magic     [4]byte
	Version   uint16
	Crc       uint32
	NrBlocks  uint16
	StartAddr uint16
	SizeBytes uint64
	Reserved  [42]byte
}

Header defines the structure of the REX header

func CreateHeader

func CreateHeader() *Header

CreateHeader returns a valid fresh header block

func ReadHeader

func ReadHeader(r io.Reader) (*Header, error)

ReadHeader reads the REX header from a given file

func (Header) String

func (h Header) String() string

String nicely print header

func (*Header) Write

func (h *Header) Write(w io.Writer) error

Write converts the REX header and a dummy CSR and writes it to the given writer

type Image

type Image struct {
	ID          uint64
	Compression uint32
	Data        []byte
}

Image datastructure

func ReadImage

func ReadImage(r io.Reader, hdr DataBlockHeader) (*Image, error)

ReadImage reads a REX image w/o block header

func (*Image) GetSize

func (block *Image) GetSize() int

GetSize returns the estimated size of the block in bytes

func (*Image) Write

func (block *Image) Write(w io.Writer) error

Write writes the image including the data header to the given writer

type LineSet

type LineSet struct {
	ID     uint64
	Colors mgl32.Vec4
	Points []mgl32.Vec3
}

LineSet stores a list of 3D points which form a polyline. Number of lines are size(p)-1. The color is (RGBA)

func ReadLineSet

func ReadLineSet(r io.Reader, hdr DataBlockHeader) (*LineSet, error)

ReadLineSet reads the block

func (*LineSet) GetSize

func (block *LineSet) GetSize() int

GetSize returns the estimated size of the block in bytes

func (*LineSet) Write

func (block *LineSet) Write(w io.Writer) error

Write writes the lineset to the given writer

type Material

type Material struct {
	ID          uint64
	KaRgb       mgl32.Vec3
	KaTextureID uint64
	KdRgb       mgl32.Vec3
	KdTextureID uint64
	KsRgb       mgl32.Vec3
	KsTextureID uint64
	Ns          float32
	Alpha       float32 // 1 is full opaque
}

Material datastructure

func NewMaterial

func NewMaterial(id uint64) Material

NewMaterial creates a new default material (gray)

func ReadMaterial

func ReadMaterial(r io.Reader, hdr DataBlockHeader) (*Material, error)

ReadMaterial reads a REX material

func (*Material) GetSize

func (block *Material) GetSize() int

GetSize returns the estimated size of the block in bytes

func (*Material) Write

func (block *Material) Write(w io.Writer) error

Write writes the material to the given writer

type Mesh

type Mesh struct {
	ID         uint64
	Name       string
	Coords     []mgl32.Vec3
	Normals    []mgl32.Vec3
	TexCoords  []mgl32.Vec2
	Colors     []mgl32.Vec3
	Triangles  []Triangle
	MaterialID uint64
}

Mesh datastructure

func ReadMesh

func ReadMesh(r io.Reader, hdr DataBlockHeader) (*Mesh, error)

ReadMesh reads a REX mesh

func (*Mesh) GetSize

func (block *Mesh) GetSize() int

GetSize returns the estimated size of the block in bytes

func (Mesh) String

func (m Mesh) String() string

String nicely print mesh

func (*Mesh) Write

func (block *Mesh) Write(w io.Writer) error

Write writes the mesh to the given writer

type PointList

type PointList struct {
	ID     uint64
	Points []mgl32.Vec3
	Colors []mgl32.Vec3
}

PointList stores a list of (colored) 3D points

func ReadPointList

func ReadPointList(r io.Reader, hdr DataBlockHeader) (*PointList, error)

ReadPointList reads the block

func (*PointList) GetSize

func (block *PointList) GetSize() int

GetSize returns the estimated size of the block in bytes

func (*PointList) Write

func (block *PointList) Write(w io.Writer) error

Write writes the pointlist to the given writer

type SceneGraph

type SceneGraph struct {
	GUID string    `json:"guid,omitempty"`
	Name string    `json:"name"`
	Root SceneNode `json:"root"`
}

SceneGraph describes the complete scenegraph tree with one root node

type SceneNode

type SceneNode struct {
	ID          uint64      `json:"id"`
	GeometryID  uint64      `json:"geometryId"`
	Name        string      `json:"name"`
	Translation mgl32.Vec3  `json:"translation"`
	Rotation    mgl32.Vec4  `json:"rotation"`
	Scale       mgl32.Vec3  `json:"scale"`              // TODO scale is only one float !!!!
	Children    []SceneNode `json:"children,omitempty"` // not serialized to binary block!
}

SceneNode is a description of a scenegraph node and can reference a REX geometry block

func NewSceneNode

func NewSceneNode(id, geomID uint64, name string) SceneNode

NewSceneNode creates a new empty SceneNode pointing to no geometry

func ReadSceneNode

func ReadSceneNode(r io.Reader, hdr DataBlockHeader) (*SceneNode, error)

ReadSceneNode reads the block

func (*SceneNode) GetSize

func (block *SceneNode) GetSize() int

GetSize returns the estimated size of the block in bytes

func (*SceneNode) Write

func (block *SceneNode) Write(w io.Writer) error

Write writes the scenenode

type Text

type Text struct {
	ID       uint64
	Red      float32
	Green    float32
	Blue     float32
	Alpha    float32
	Position mgl32.Vec3
	FontSize float32
	Text     string
}

Text datastructure

func ReadText

func ReadText(r io.Reader, hdr DataBlockHeader) (*Text, error)

ReadText reads a REX text

func (*Text) GetSize

func (block *Text) GetSize() int

GetSize returns the estimated size of the block in bytes

func (*Text) Write

func (block *Text) Write(w io.Writer) error

Write writes the track to the given writer

type Track

type Track struct {
	ID         uint64
	NrOfPoints uint32
	Timestamp  int64 // UNIX time - seconds since January 1, 1970 UTC
	Points     []TrackElement
}

Track consists of a list of 3D points with orientation

func ReadTrack

func ReadTrack(r io.Reader, hdr DataBlockHeader) (*Track, error)

ReadTrack reads a REX track

func (*Track) GetSize

func (block *Track) GetSize() int

GetSize returns the estimated size of the block in bytes

func (*Track) Write

func (block *Track) Write(w io.Writer) error

Write writes the track to the given writer

type TrackElement

type TrackElement struct {
	Point       mgl32.Vec3
	Orientation mgl32.Vec3
	Confidence  float32
}

A TrackElement for a track consists of its x,y,z coordinate, the orientation which is denoted as a normalized normal vector pointing from the device to the world (LookAt vector) and a confidence value.

type Triangle

type Triangle struct {
	V0 uint32
	V1 uint32
	V2 uint32
}

Triangle defines three indices

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL