fileformats

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ThreeMFUnitMicron     ThreeMFUnit = "micron"
	ThreeMFUnitMillimeter             = "millimeter"
	ThreeMFUnitCentimeter             = "centimeter"
	ThreeMFUnitInch                   = "inch"
	ThreeMFUnitFoot                   = "foot"
	ThreeMFUnitMeter                  = "meter"
)
View Source
const (
	PLYPropertyTypeNone    PLYPropertyType = ""
	PLYPropertyTypeChar                    = "char"
	PLYPropertyTypeUchar                   = "uchar"
	PLYPropertyTypeShort                   = "short"
	PLYPropertyTypeUshort                  = "ushort"
	PLYPropertyTypeInt                     = "int"
	PLYPropertyTypeUint                    = "uint"
	PLYPropertyTypeFloat                   = "float"
	PLYPropertyTypeDouble                  = "double"
	PLYPropertyTypeInt8                    = "int8"
	PLYPropertyTypeUint8                   = "uint8"
	PLYPropertyTypeInt16                   = "int16"
	PLYPropertyTypeUint16                  = "uint16"
	PLYPropertyTypeInt32                   = "int32"
	PLYPropertyTypeUint32                  = "uint32"
	PLYPropertyTypeFloat32                 = "float32"
	PLYPropertyTypeFloat64                 = "float64"
)

Variables

This section is empty.

Functions

func Write3MFMesh added in v0.4.4

func Write3MFMesh(w io.Writer, unit ThreeMFUnit, vertices [][3]float64, triangles [][3]int) (err error)

Write3MFMesh encodes a mesh as a 3MF file.

The mesh is passed as a collection of vertices, and triangles which index into this vertex list starting at 0 for the first vertex.

Types

type MTLFile

type MTLFile struct {
	Materials []*MTLFileMaterial
}

MTLFile represents the contents of a Wavefront mtl file, which is a companion of an obj file.

func (*MTLFile) Write

func (m *MTLFile) Write(w io.Writer) error

type MTLFileMaterial

type MTLFileMaterial struct {
	Name             string
	Ambient          [3]float32
	Diffuse          [3]float32
	Specular         [3]float32
	SpecularExponent float32

	// Texture maps
	AmbientMap   *MTLFileTextureMap
	DiffuseMap   *MTLFileTextureMap
	SpecularMap  *MTLFileTextureMap
	HighlightMap *MTLFileTextureMap
}

MTLFileMaterial is a single material in an MTLFile.

func (*MTLFileMaterial) Write

func (m *MTLFileMaterial) Write(w io.Writer) error

Write encodes m to a writer w.

type MTLFileTextureMap

type MTLFileTextureMap struct {
	Filename string

	// May be nil.
	Options map[string]string
}

MTLFileTextureMap is a configured texture map for an MTLFileMaterial.

type OBJFile

type OBJFile struct {
	MaterialFiles []string

	Vertices     [][3]float64
	VertexColors [][3]float64
	UVs          [][2]float64
	Normals      [][3]float64
	FaceGroups   []*OBJFileFaceGroup
}

An OBJFile represents the contents of a Wavefront obj file.

func (*OBJFile) Write

func (o *OBJFile) Write(w io.Writer) error

Write encodes the file to w and returns the first write error encountered.

type OBJFileFaceGroup

type OBJFileFaceGroup struct {
	// Material is the material name, or "" by default.
	Material string

	// Each face has three vertices, which itself has a
	// vertex, texture, and normal index.
	// If a texture or normal index is 0, it is omitted.
	Faces [][3][3]int
}

An OBJFileFaceGroup is a group of faces with one material in a Wavefront obj file.

type OFFReader

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

An OFFReader reads an OFF file.

For info on the OFF format, see http://segeval.cs.princeton.edu/public/off_format.html.

func NewOFFReader

func NewOFFReader(r io.Reader) (o *OFFReader, err error)

NewOFFReader reads the header from an OFF file and returns the new reader, if successful.

func (*OFFReader) NumFaces

func (o *OFFReader) NumFaces() int

NumFaces returns the total number of faces.

func (*OFFReader) ReadFace

func (o *OFFReader) ReadFace() (faces [][3]float64, err error)

ReadFace reads the next face. If vertices have not been read, they will be loaded first.

If no more faces exist to be read, io.EOF is returned as the error.

type PLYElement added in v0.3.4

type PLYElement struct {
	Name       string
	Count      int64
	Properties []*PLYProperty
}

func NewPLYElementColoredVertex added in v0.3.4

func NewPLYElementColoredVertex(count int64) *PLYElement

func NewPLYElementFace added in v0.3.4

func NewPLYElementFace(count int64) *PLYElement

func (*PLYElement) DecodeInstanceBinary added in v0.3.4

func (p *PLYElement) DecodeInstanceBinary(b binary.ByteOrder, r io.Reader) ([]PLYValue, error)

func (*PLYElement) DecodeInstanceString added in v0.3.4

func (p *PLYElement) DecodeInstanceString(line string) ([]PLYValue, error)

func (*PLYElement) Encode added in v0.3.4

func (p *PLYElement) Encode() string

func (*PLYElement) IsStandardFace added in v0.4.2

func (p *PLYElement) IsStandardFace() bool

func (*PLYElement) IsStandardVertex added in v0.4.2

func (p *PLYElement) IsStandardVertex() bool

type PLYFormat added in v0.3.4

type PLYFormat int
const (
	PLYFormatASCII PLYFormat = iota
	PLYFormatBinaryLittle
	PLYFormatBinaryBig
)

type PLYHeader added in v0.3.4

type PLYHeader struct {
	Format   PLYFormat
	Elements []*PLYElement
}

func NewPLYHeaderDecode added in v0.3.4

func NewPLYHeaderDecode(data string) (*PLYHeader, error)

func NewPLYHeaderRead added in v0.3.4

func NewPLYHeaderRead(r io.Reader) (*PLYHeader, error)

func (*PLYHeader) Encode added in v0.3.4

func (p *PLYHeader) Encode() string

type PLYMeshWriter added in v0.3.4

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

A PLYMeshWriter encodes a colored mesh PLY file.

This may use buffering as it writes the file, but the full file will always be flushed by the time the last triangle is written.

func NewPLYMeshWriter added in v0.3.4

func NewPLYMeshWriter(w io.Writer, numCoords, numTris int) (*PLYMeshWriter, error)

NewPLYMeshWriter creates a new PLYMeshWriter and writes the file header.

func (*PLYMeshWriter) WriteCoord added in v0.3.4

func (p *PLYMeshWriter) WriteCoord(c [3]float64, color [3]uint8) error

WriteCoord writes the next coordinate to the file.

This should be called exactly numCoords times.

func (*PLYMeshWriter) WriteTriangle added in v0.3.4

func (p *PLYMeshWriter) WriteTriangle(coords [3]int) (err error)

WriteTriangle writes the next triangle to the file.

This should be called exactly numTris times.

type PLYProperty added in v0.3.4

type PLYProperty struct {
	// May be PLYPropertyTypeNone for non-lists.
	LenType PLYPropertyType

	ElemType PLYPropertyType
	Name     string
}

func NewPLYPropertyString added in v0.3.4

func NewPLYPropertyString(lineData string) (*PLYProperty, error)

type PLYPropertyType added in v0.3.4

type PLYPropertyType string

func (PLYPropertyType) DecodeBinary added in v0.3.4

func (p PLYPropertyType) DecodeBinary(b binary.ByteOrder, data []byte) (PLYValue, error)

func (PLYPropertyType) Parse added in v0.3.4

func (p PLYPropertyType) Parse(s string) (PLYValue, error)

func (PLYPropertyType) Size added in v0.3.4

func (p PLYPropertyType) Size() int

func (PLYPropertyType) Validate added in v0.3.4

func (p PLYPropertyType) Validate() error

type PLYReader added in v0.3.4

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

A PLYReader reads arbitrary PLY files.

func NewPLYReader added in v0.3.4

func NewPLYReader(r io.Reader) (*PLYReader, error)

func (*PLYReader) Header added in v0.4.2

func (p *PLYReader) Header() PLYHeader

Header gets the file header that was read when the reader was created.

The caller should not modify the returned object.

func (*PLYReader) Read added in v0.3.4

func (p *PLYReader) Read() ([]PLYValue, *PLYElement, error)

Read reads the next element row from the file.

If all element rows have been read, io.EOF is returned. If reading fails for some other reason, a different error is returned, such as io.UnexpectedEOF.

type PLYValue added in v0.3.4

type PLYValue interface {
	EncodeString() string
	EncodeBinary(encoding binary.ByteOrder) []byte
	LengthValue() (int, error)
}

type PLYValueFloat32 added in v0.3.4

type PLYValueFloat32 struct {
	Value float32
}

func (PLYValueFloat32) EncodeBinary added in v0.3.4

func (p PLYValueFloat32) EncodeBinary(b binary.ByteOrder) []byte

func (PLYValueFloat32) EncodeString added in v0.3.4

func (p PLYValueFloat32) EncodeString() string

func (PLYValueFloat32) LengthValue added in v0.3.4

func (p PLYValueFloat32) LengthValue() (int, error)

type PLYValueFloat64 added in v0.3.4

type PLYValueFloat64 struct {
	Value float64
}

func (PLYValueFloat64) EncodeBinary added in v0.3.4

func (p PLYValueFloat64) EncodeBinary(b binary.ByteOrder) []byte

func (PLYValueFloat64) EncodeString added in v0.3.4

func (p PLYValueFloat64) EncodeString() string

func (PLYValueFloat64) LengthValue added in v0.3.4

func (p PLYValueFloat64) LengthValue() (int, error)

type PLYValueInt16 added in v0.3.4

type PLYValueInt16 struct {
	Value int16
}

func (PLYValueInt16) EncodeBinary added in v0.3.4

func (p PLYValueInt16) EncodeBinary(b binary.ByteOrder) []byte

func (PLYValueInt16) EncodeString added in v0.3.4

func (p PLYValueInt16) EncodeString() string

func (PLYValueInt16) LengthValue added in v0.3.4

func (p PLYValueInt16) LengthValue() (int, error)

type PLYValueInt32 added in v0.3.4

type PLYValueInt32 struct {
	Value int32
}

func (PLYValueInt32) EncodeBinary added in v0.3.4

func (p PLYValueInt32) EncodeBinary(b binary.ByteOrder) []byte

func (PLYValueInt32) EncodeString added in v0.3.4

func (p PLYValueInt32) EncodeString() string

func (PLYValueInt32) LengthValue added in v0.3.4

func (p PLYValueInt32) LengthValue() (int, error)

type PLYValueInt64 added in v0.3.4

type PLYValueInt64 struct {
	Value int64
}

func (PLYValueInt64) EncodeBinary added in v0.3.4

func (p PLYValueInt64) EncodeBinary(b binary.ByteOrder) []byte

func (PLYValueInt64) EncodeString added in v0.3.4

func (p PLYValueInt64) EncodeString() string

func (PLYValueInt64) LengthValue added in v0.3.4

func (p PLYValueInt64) LengthValue() (int, error)

type PLYValueInt8 added in v0.3.4

type PLYValueInt8 struct {
	Value int8
}

func (PLYValueInt8) EncodeBinary added in v0.3.4

func (p PLYValueInt8) EncodeBinary(b binary.ByteOrder) []byte

func (PLYValueInt8) EncodeString added in v0.3.4

func (p PLYValueInt8) EncodeString() string

func (PLYValueInt8) LengthValue added in v0.3.4

func (p PLYValueInt8) LengthValue() (int, error)

type PLYValueList added in v0.3.4

type PLYValueList struct {
	Length PLYValue
	Values []PLYValue
}

func (PLYValueList) EncodeBinary added in v0.3.4

func (p PLYValueList) EncodeBinary(encoding binary.ByteOrder) []byte

func (PLYValueList) EncodeString added in v0.3.4

func (p PLYValueList) EncodeString() string

func (PLYValueList) LengthValue added in v0.3.4

func (p PLYValueList) LengthValue() (int, error)

type PLYValueUint16 added in v0.3.4

type PLYValueUint16 struct {
	Value uint16
}

func (PLYValueUint16) EncodeBinary added in v0.3.4

func (p PLYValueUint16) EncodeBinary(b binary.ByteOrder) []byte

func (PLYValueUint16) EncodeString added in v0.3.4

func (p PLYValueUint16) EncodeString() string

func (PLYValueUint16) LengthValue added in v0.3.4

func (p PLYValueUint16) LengthValue() (int, error)

type PLYValueUint32 added in v0.3.4

type PLYValueUint32 struct {
	Value uint32
}

func (PLYValueUint32) EncodeBinary added in v0.3.4

func (p PLYValueUint32) EncodeBinary(b binary.ByteOrder) []byte

func (PLYValueUint32) EncodeString added in v0.3.4

func (p PLYValueUint32) EncodeString() string

func (PLYValueUint32) LengthValue added in v0.3.4

func (p PLYValueUint32) LengthValue() (int, error)

type PLYValueUint64 added in v0.3.4

type PLYValueUint64 struct {
	Value uint64
}

func (PLYValueUint64) EncodeBinary added in v0.3.4

func (p PLYValueUint64) EncodeBinary(b binary.ByteOrder) []byte

func (PLYValueUint64) EncodeString added in v0.3.4

func (p PLYValueUint64) EncodeString() string

func (PLYValueUint64) LengthValue added in v0.3.4

func (p PLYValueUint64) LengthValue() (int, error)

type PLYValueUint8 added in v0.3.4

type PLYValueUint8 struct {
	Value uint8
}

func (PLYValueUint8) EncodeBinary added in v0.3.4

func (p PLYValueUint8) EncodeBinary(b binary.ByteOrder) []byte

func (PLYValueUint8) EncodeString added in v0.3.4

func (p PLYValueUint8) EncodeString() string

func (PLYValueUint8) LengthValue added in v0.3.4

func (p PLYValueUint8) LengthValue() (int, error)

type PLYWriter

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

A PLYWriter encodes an arbitrary PLY file.

This may use buffering as it writes the file, but the full file will always be flushed by the time the last element is written.

func NewPLYWriter

func NewPLYWriter(w io.Writer, h *PLYHeader) (*PLYWriter, error)

NewPLYWriter creates a new PLYWriter and writes the file header.

func (*PLYWriter) Write added in v0.3.4

func (p *PLYWriter) Write(fields []PLYValue) error

Write writes a single element row.

It is assumed that the fields are in the correct order and in the correct type for the current element.

type STLReader

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

An STLReader reads STL files.

func NewSTLReader

func NewSTLReader(r io.Reader) (*STLReader, error)

NewSTLReader creates an STL reader by reading the header of an STL file.

func (*STLReader) IsBinary added in v0.4.0

func (s *STLReader) IsBinary() bool

IsBinary returns true if this file is encoded in the binary STL format, rather than the ASCII format.

func (*STLReader) NumTriangles

func (s *STLReader) NumTriangles() uint32

NumTriangles gets the total number of triangles in the file as reported by the header, if this is a binary file. If it is an ASCII file, this always returns 0.

func (*STLReader) ReadTriangle

func (s *STLReader) ReadTriangle() (normal [3]float32, vertices [3][3]float32, err error)

ReadTriangle reads the next triangle from the file, or returns an error if no more triangles can be read.

The error io.EOF is returned when the file ended and there are no more triangles to be read. When the file ends abruptly and incorrectly, io.ErrUnexpectedEOF is returned instead.

type STLWriter

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

An STLWriter writes a triangle mesh in the STL format.

func NewSTLWriter

func NewSTLWriter(w io.Writer, numTris uint32) (*STLWriter, error)

NewSTLWriter creates an STLWriter and writes a header, which requires knowledge of the total number of triangles being written.

func (*STLWriter) WriteTriangle

func (s *STLWriter) WriteTriangle(normal [3]float32, faces [3][3]float32) error

WriteTriangle writes a triangle to the file.

This should be called exactly the number of times passed to NewSTLWriter.

type SVGWriter added in v0.2.23

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

An SVGWriter encodes paths to SVG files.

func NewSVGWriter added in v0.2.23

func NewSVGWriter(w io.Writer, viewbox [4]float64) (*SVGWriter, error)

NewSVGWriter creates writes an SVG header and returns a new SVGWriter.

The viewbox argument specifies the bounding box of the image as [minX, minY, width, height].

func (*SVGWriter) WriteEnd added in v0.2.23

func (s *SVGWriter) WriteEnd() error

WriteEnd writes any necessary footer information.

func (*SVGWriter) WritePoly added in v0.2.23

func (s *SVGWriter) WritePoly(points [][2]float64, attrs map[string]string) error

WritePoly writes a polygon or a polyline depending on whether the final point matches up with the first.

func (*SVGWriter) WritePolyPath added in v0.4.2

func (s *SVGWriter) WritePolyPath(paths [][][2]float64, attrs map[string]string) error

WritePolyPath writes one or more polygons into a single path element. Each polygon is either closed or left open depending on whether the final point matches up with the first.

type SegmentCSVReader added in v0.3.3

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

A SegmentCSVReader reads a CSV file encoding a 2D mesh where each row is one segment.

func NewSegmentCSVReader added in v0.3.3

func NewSegmentCSVReader(r io.Reader) *SegmentCSVReader

NewSegmentCSVReader creates a SegmentCSVReader that wraps an underlying io.Reader.

func (*SegmentCSVReader) Read added in v0.3.3

func (s *SegmentCSVReader) Read() ([4]float64, error)

Read reads a segment from the file.

Returns io.EOF if the file is complete.

type SegmentCSVWriter added in v0.3.3

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

A SegmentCSVWriter writes a CSV file encoding a 2D mesh where each row is one segment.

func NewSegmentCSVWriter added in v0.3.3

func NewSegmentCSVWriter(w io.Writer) *SegmentCSVWriter

NewSegmentCSVWriter creates a SegmentCSVWriter that wraps an underlying io.Writer.

func (*SegmentCSVWriter) Write added in v0.3.3

func (s *SegmentCSVWriter) Write(seg [4]float64) error

Write writes a segment to the file.

The segment is stored as {x1, y1, x2, y2}.

type ThreeMFUnit added in v0.4.4

type ThreeMFUnit string

Jump to

Keyboard shortcuts

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