Documentation
¶
Overview ¶
Package ply implements the PLY file format and provides utilities for interacting with the data within the rest of polyform.
Index ¶
- Constants
- Variables
- func Load(filepath string) (*modeling.Mesh, error)
- func ReadMesh(in io.Reader) (*modeling.Mesh, error)
- func Save(plyPath string, meshToSave modeling.Mesh, format Format) error
- func Write(out io.Writer, model modeling.Mesh, format Format) error
- type AsciiReader
- type BinaryReader
- type BodyReader
- type Element
- type Format
- type Header
- type ListProperty
- type Property
- type ScalarProperty
- type ScalarPropertyType
Examples ¶
Constants ¶
const VertexElementName = "vertex"
Variables ¶
Functions ¶
func ReadMesh ¶ added in v0.2.0
Example ¶
package main import ( "bytes" "log" "github.com/EliCDavis/polyform/formats/ply" "github.com/EliCDavis/polyform/modeling" ) var exampleFile = []byte(`ply format ascii 1.0 comment This is an example comment obj_info This is example info element vertex 3 property double x property double y property double z end_header 0 0 0 0 1 0 1 0 0 1 1 0 `) func main() { file := bytes.NewBuffer(exampleFile) mesh, _ := ply.ReadMesh(file) log.Println(mesh.Float3Attributes()) positionData := mesh.Float3Attribute(modeling.PositionAttribute) for i := 0; i < positionData.Len(); i++ { log.Println(positionData.At(i).Format("%f %f %f")) } }
Output:
func Write ¶ added in v0.14.0
Example ¶
package main import ( "bytes" "log" "github.com/EliCDavis/polyform/formats/ply" "github.com/EliCDavis/vector/vector3" ) var exampleFile = []byte(`ply format ascii 1.0 comment This is an example comment obj_info This is example info element vertex 3 property double x property double y property double z end_header 0 0 0 0 1 0 1 0 0 1 1 0 `) func main() { file := bytes.NewBuffer(exampleFile) out := &bytes.Buffer{} mesh, _ := ply.ReadMesh(file) scaledMesh := mesh.Scale(vector3.New(2., 2., 2.)) ply.Write(out, scaledMesh, ply.ASCII) log.Println(out.String()) }
Output:
Types ¶
type AsciiReader ¶
type AsciiReader struct {
// contains filtered or unexported fields
}
type BinaryReader ¶ added in v0.2.0
type BinaryReader struct {
// contains filtered or unexported fields
}
type BodyReader ¶ added in v0.10.0
type Element ¶
type Header ¶ added in v0.10.0
type Header struct { Format Format `json:"format"` Elements []Element `json:"elements"` Comments []string `json:"comments"` // Provide informal descriptive and contextual metadata/information ObjInfo []string `json:"objInfo"` // Object information (arbitrary text) }
A PLY Header dictates how to interpret the rest of the file's contents, as well as containing any extra information stored in the comments and obj info
func BuildHeaderFromModel ¶ added in v0.12.0
func ReadHeader ¶ added in v0.10.0
Builds a header from the contents of the reader passed in. Reading from the reader passed in stops once we recieve the "end_header" token
Example ¶
package main import ( "bytes" "fmt" "github.com/EliCDavis/polyform/formats/ply" ) var exampleFile = []byte(`ply format ascii 1.0 comment This is an example comment obj_info This is example info element vertex 3 property double x property double y property double z end_header 0 0 0 0 1 0 1 0 0 1 1 0 `) func main() { file := bytes.NewBuffer(exampleFile) header, _ := ply.ReadHeader(file) fmt.Println(header.Format) fmt.Println(header.Comments[0]) fmt.Println(header.ObjInfo[0]) ele := header.Elements[0] fmt.Printf("%s contains %d elements\n", ele.Name, ele.Count) fmt.Printf("\t%s", ele.Properties[0].Name()) fmt.Printf("\t%s", ele.Properties[1].Name()) }
Output:
func (Header) BuildReader ¶ added in v0.10.0
func (h Header) BuildReader(in io.Reader) BodyReader
Builds a reader to interpret the contents of the body of the PLY format, based on the elements and format of this header.
func (Header) Bytes ¶ added in v0.14.0
Builds a byte array containing the header information in PLY format.
func (Header) TextureFiles ¶ added in v0.14.0
All texture files found within the comments section of the header
type ListProperty ¶
type ListProperty struct { PropertyName string // Name of the property CountType ScalarPropertyType // Data type of the number used to define how many elements are in the list ListType ScalarPropertyType // Data type of the elements in the list }
func (ListProperty) Name ¶
func (lp ListProperty) Name() string
Name of the property as found in the PLY header
type ScalarProperty ¶
type ScalarProperty struct { PropertyName string `json:"name"` // Name of the property Type ScalarPropertyType `json:"type"` // Property type }
func (ScalarProperty) Name ¶
func (sp ScalarProperty) Name() string
Name of the property as found in the PLY header
func (ScalarProperty) Size ¶ added in v0.2.0
func (sp ScalarProperty) Size() int
Size of the property on a per point basis when serialized to binary format
type ScalarPropertyType ¶
type ScalarPropertyType string
const ( Char ScalarPropertyType = "char" UChar ScalarPropertyType = "uchar" // uint8 Short ScalarPropertyType = "short" UShort ScalarPropertyType = "ushort" Int ScalarPropertyType = "int" UInt ScalarPropertyType = "uint" Float ScalarPropertyType = "float" Double ScalarPropertyType = "double" )
func ParseScalarPropertyType ¶ added in v0.14.0
func ParseScalarPropertyType(str string) ScalarPropertyType
Attempts to interpret the string as some scalar property type, and panics if it can't.