Documentation
¶
Overview ¶
Package ply implements the PLY file format and provides utilities for interacting with the data within the rest of polyform.
Index ¶
- Constants
- func Load(filepath string) (*modeling.Mesh, error)
- func ReadMesh(reader 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, texture string) error
- type Artifact
- type ArtifactNode
- type Element
- type Format
- type Header
- type ListProperty
- type ManifestNode
- type MeshReader
- type MeshWriter
- type Property
- type PropertyReader
- type PropertyWriter
- type ReadNode
- type ScalarProperty
- type ScalarPropertyType
- type Vector1PropertyReader
- type Vector1PropertyWriter
- type Vector2PropertyReader
- type Vector2PropertyWriter
- type Vector3PropertyReader
- type Vector3PropertyWriter
- type Vector4PropertyReader
- type Vector4PropertyWriter
Examples ¶
Constants ¶
const VertexElementName = "vertex"
Variables ¶
This section is empty.
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"))
}
}
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())
}
Types ¶
type ArtifactNode ¶ added in v0.21.3
func (ArtifactNode) Out ¶ added in v0.32.0
func (pn ArtifactNode) Out(out *nodes.StructOutput[manifest.Artifact])
type Element ¶
type Element struct {
Name string `json:"name"`
Count int64 `json:"count"`
Properties []Property `json:"properties"`
}
func (Element) DeterministicPointSize ¶ added in v0.30.0
func (Element) PropertyStart ¶ added in v0.30.0
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 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())
}
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 ManifestNode ¶ added in v0.25.0
type ManifestNode struct {
Name nodes.Output[string] `description:"Name of the main file in the manifest, defaults to 'model.ply'"`
Mesh nodes.Output[modeling.Mesh]
}
func (ManifestNode) Out ¶ added in v0.32.0
func (pn ManifestNode) Out(out *nodes.StructOutput[manifest.Manifest])
type MeshReader ¶ added in v0.19.0
type MeshReader struct {
// PLY Element containing the mesh attribute data on a per vertex basis
//
// example: "vertex"
AttributeElement string
// All defined translations from PLY data to mesh attributes
Properties []PropertyReader
// Whether or not to load extra ply data that wasn't defined by the
// property readers
LoadUnspecifiedProperties bool
}
Builds a modeling.Mesh from PLY data
type MeshWriter ¶ added in v0.19.0
type MeshWriter struct {
Format Format
Properties []PropertyWriter
// Whether or not to save extra ply data that wasn't defined by the
// property writers
WriteUnspecifiedProperties bool
}
type PropertyReader ¶ added in v0.19.0
type PropertyReader interface {
// contains filtered or unexported methods
}
type PropertyWriter ¶ added in v0.19.0
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.
func (ScalarPropertyType) Size ¶ added in v0.19.0
func (spt ScalarPropertyType) Size() int
type Vector1PropertyReader ¶ added in v0.19.0
type Vector1PropertyWriter ¶ added in v0.19.0
type Vector1PropertyWriter struct {
ModelAttribute string
PlyProperty string
Type ScalarPropertyType
}
func (Vector1PropertyWriter) MeshQualifies ¶ added in v0.19.0
func (vpw Vector1PropertyWriter) MeshQualifies(mesh modeling.Mesh) bool
func (Vector1PropertyWriter) Properties ¶ added in v0.19.0
func (vpw Vector1PropertyWriter) Properties() []Property
type Vector2PropertyReader ¶ added in v0.19.0
type Vector2PropertyWriter ¶ added in v0.19.0
type Vector2PropertyWriter struct {
ModelAttribute string
PlyPropertyX string
PlyPropertyY string
Type ScalarPropertyType
}
func (Vector2PropertyWriter) MeshQualifies ¶ added in v0.19.0
func (v3pw Vector2PropertyWriter) MeshQualifies(mesh modeling.Mesh) bool
func (Vector2PropertyWriter) Properties ¶ added in v0.19.0
func (v3pw Vector2PropertyWriter) Properties() []Property
type Vector3PropertyReader ¶ added in v0.19.0
type Vector3PropertyWriter ¶ added in v0.19.0
type Vector3PropertyWriter struct {
ModelAttribute string
PlyPropertyX string
PlyPropertyY string
PlyPropertyZ string
Type ScalarPropertyType
}
func (Vector3PropertyWriter) MeshQualifies ¶ added in v0.19.0
func (v3pw Vector3PropertyWriter) MeshQualifies(mesh modeling.Mesh) bool
func (Vector3PropertyWriter) Properties ¶ added in v0.19.0
func (v3pw Vector3PropertyWriter) Properties() []Property
type Vector4PropertyReader ¶ added in v0.19.0
type Vector4PropertyWriter ¶ added in v0.19.0
type Vector4PropertyWriter struct {
ModelAttribute string
PlyPropertyX string
PlyPropertyY string
PlyPropertyZ string
PlyPropertyW string
Type ScalarPropertyType
}
func (Vector4PropertyWriter) MeshQualifies ¶ added in v0.19.0
func (v4pw Vector4PropertyWriter) MeshQualifies(mesh modeling.Mesh) bool
func (Vector4PropertyWriter) Properties ¶ added in v0.19.0
func (v4pw Vector4PropertyWriter) Properties() []Property