ply

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: MIT Imports: 20 Imported by: 2

README

PLY Format

PLY format implementation for interfacing with polyform meshes.

Saving and Loading

package example

import (
    "github.com/EliCDavis/polyform/formats/ply"
    "github.com/EliCDavis/vector/vector3"
)

func ExampleReadWrite() {
    mesh, _ := ply.Load("model.ply")
    scaledMesh := mesh.Scale(vector3.New(2., 2., 2.))
    ply.Save("scaled.ply", scaledMesh, ply.ASCII)
}

Documentation

Overview

Package ply implements the PLY file format and provides utilities for interacting with the data within the rest of polyform.

Index

Examples

Constants

View Source
const VertexElementName = "vertex"

Variables

View Source
var GuassianSplatVertexAttributes map[string]bool = map[string]bool{
	"x":       true,
	"y":       true,
	"z":       true,
	"scale_0": true,
	"scale_1": true,
	"scale_2": true,
	"rot_0":   true,
	"rot_1":   true,
	"rot_2":   true,
	"rot_3":   true,
	"f_dc_0":  true,
	"f_dc_1":  true,
	"f_dc_2":  true,
	"opacity": true,
}

Functions

func Load

func Load(filepath string) (*modeling.Mesh, error)

Build a polyform mesh from the contents of the ply file specied at the filepath

func ReadMesh added in v0.2.0

func ReadMesh(in io.Reader) (*modeling.Mesh, error)
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 Save

func Save(plyPath string, meshToSave modeling.Mesh, format Format) error

Save writes the mesh to the path specified in PLY format

func Write added in v0.14.0

func Write(out io.Writer, model modeling.Mesh, format Format) error
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
}

func (*AsciiReader) ReadMesh

func (ar *AsciiReader) ReadMesh(vertexAttributes map[string]bool) (*modeling.Mesh, error)

type BinaryReader added in v0.2.0

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

func (*BinaryReader) ReadMesh added in v0.2.0

func (le *BinaryReader) ReadMesh(vertexAttributes map[string]bool) (*modeling.Mesh, error)

type BodyReader added in v0.10.0

type BodyReader interface {
	ReadMesh(vertexAttributes map[string]bool) (*modeling.Mesh, error)
}

type Element

type Element struct {
	Name       string     `json:"name"`
	Count      int64      `json:"count"`
	Properties []Property `json:"properties"`
}

func (Element) Write

func (e Element) Write(out io.Writer) error

type Format

type Format string

Format of the data contained within the body of the PLY file

const (
	ASCII              Format = "ascii"
	BinaryBigEndian    Format = "binary_little_endian"
	BinaryLittleEndian Format = "binary_big_endian"
)

func (Format) String added in v0.14.0

func (f Format) String() string

Human readable string representing the format value

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 BuildHeaderFromModel(model modeling.Mesh, format Format) Header

func ReadHeader added in v0.10.0

func ReadHeader(in io.Reader) (Header, error)

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

func (h Header) Bytes() []byte

Builds a byte array containing the header information in PLY format.

func (Header) TextureFiles added in v0.14.0

func (h Header) TextureFiles() []string

All texture files found within the comments section of the header

func (Header) Write added in v0.12.0

func (h Header) Write(out io.Writer) (err error)

Writes the contents of the header out in PLY format to the writer provided.

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

func (ListProperty) Write

func (lp ListProperty) Write(out io.Writer) (err error)

Writes out the definition of the property in PLY format

type Property

type Property interface {
	Name() string              // Name of the property as found in the PLY header
	Write(out io.Writer) error // Writes out the definition of the property in PLY format
}

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

func (ScalarProperty) Write

func (sp ScalarProperty) Write(out io.Writer) (err error)

Writes out the definition of the property in PLY 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.

Jump to

Keyboard shortcuts

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