Documentation
¶
Overview ¶
Package model is the plain Go data of a 3D model that a loader reads from a file (SPEC §27.9): meshes, materials, images and a tree of nodes with float64 transforms. It has no GPU and no window, so a test can check it as it is. The loaders are in model/stl and model/obj, and viewport3d.Upload makes the meshes, the materials and the items of a scene from it.
Index ¶
Constants ¶
const TagModelReadFailed = "ModelReadFailed"
TagModelReadFailed is the tag of the error of a loader that could not read its input: an I/O error of the reader or the file system, or a context that was done. The cause is wrapped, so errors.Is(err, context.Canceled) works; the metadata has the offset or the line that was reached, and the file name when there is one.
Flutter: no counterpart
Variables ¶
var DefaultColor = [4]float32{0.78, 0.8, 0.82, 1}
DefaultColor is the color of a material that has none: an opaque light gray.
Flutter: no counterpart
Functions ¶
func DetectImageType ¶
DetectImageType returns the media type of an image from the extension of its name, or from its first bytes when the name does not say: "image/png", "image/jpeg", "image/gif", "image/bmp", "image/webp", or "" when it is none of them.
Flutter: no counterpart
Types ¶
type AlphaMode ¶
type AlphaMode uint8
AlphaMode is how the alpha of a material is used.
Flutter: no counterpart
type Image ¶
type Image struct {
// Name is the name in the file, or empty.
Name string
// URI is where the image was read from: the path in the file system of the loader, or empty.
URI string
// Type is the media type, such as "image/png" or "image/jpeg"; empty when the file name and the data do not tell.
Type string
// Data are the bytes of the file. Upload decodes them (ui.InstantiateImageCodec) when it makes a texture.
Data []byte
}
Image is an image as the file gave it, encoded.
Flutter: no counterpart
type Material ¶
type Material struct {
// Name is the name in the file, or empty.
Name string
// BaseColor is the color, red, green, blue and alpha from 0 to 1, not premultiplied. The zero value (all four 0) stands for the
// default, an opaque light gray; use Color to read it.
BaseColor [4]float32
// BaseColorImage is the image that the color is multiplied by, or nil.
BaseColorImage *Image
// Specular is the color of the highlight (the Ks of an MTL file) and Shininess its exponent (the Ns).
Specular [3]float32
Shininess float32
// Metallic and Roughness are the metallic-roughness values of a physically based material (from glTF, §28.5), from 0 to 1.
Metallic, Roughness float32
// Emissive is the color that the material gives out.
Emissive [3]float32
// AlphaMode and AlphaCutoff say how the alpha is used.
AlphaMode AlphaMode
AlphaCutoff float32
// DoubleSided draws the back faces too.
DoubleSided bool
}
Material is the look of a mesh.
Flutter: no counterpart
type Mesh ¶
type Mesh struct {
// Name is the name in the file, or empty.
Name string
// Primitive is what the indices make.
Primitive Primitive
// Positions are x, y and z of each vertex in float32. A loader that was asked for more digits than float32 has (Float64 in its
// options) and found them in the file leaves Positions nil and fills Positions64 instead: exactly one of the two is set.
Positions []float32
// Positions64 are the positions in float64, when the loader was asked for them and the file has more digits than float32 does.
Positions64 []float64
// Normals are x, y and z of each vertex, of length 1; nil when the file has none (the renderer shades flat).
Normals []float32
// TexCoords are u and v of each vertex; nil when the file has none.
TexCoords []float32
// Colors are red, green, blue and alpha of each vertex, not premultiplied; nil when the file has none.
Colors []byte
// Indices are the vertices of the primitives: 3, 2 or 1 for each, by Primitive.
Indices []uint32
// Material is the material of the mesh, or nil for the default.
Material *Material
}
Mesh is the geometry of one material: vertices and the indices of the primitives that they make.
Flutter: no counterpart
func (*Mesh) Bounds ¶
Bounds is the box of the vertices that the indices use (the box of every vertex when there are no indices), in the mesh's own coordinates; empty for a mesh with none. An index outside the vertices is left out.
Flutter: no counterpart
func (*Mesh) PrimitiveCount ¶
PrimitiveCount is the number of triangles, segments or points.
Flutter: no counterpart
type Model ¶
type Model struct {
// Name is the name in the file, or empty.
Name string
// Nodes are the top of the tree.
Nodes []*Node
// Meshes, Materials and Images are every one of the model, each once; the nodes and the meshes point to them.
Meshes []*Mesh
Materials []*Material
Images []*Image
// Units are the units of the positions, when the file says.
Units Units
}
Model is what a file holds.
Flutter: no counterpart
func (*Model) Bounds ¶
Bounds is the box of the model in the coordinates of its top nodes, in float64: the boxes of the meshes of every node, moved by the transforms from the node up to the top. It is empty for a model with no geometry.
Flutter: no counterpart
func (*Model) TriangleCount ¶
TriangleCount is the number of triangles of the meshes that the nodes use, a mesh that several nodes use counted for each.
Flutter: no counterpart
type Node ¶
type Node struct {
// Name is the name in the file, or empty.
Name string
// Transform takes the node's meshes to its parent's coordinates, in float64. The zero value is not a transform: loaders set
// the identity (Mat4Identity); NewNode does too.
Transform vecmath.Mat4
// Meshes are drawn with the node's transform; several nodes may have the same mesh.
Meshes []*Mesh
// Children are nodes in the coordinates of this one.
Children []*Node
}
Node is a part of the tree of a model: a transform, meshes and children.
Flutter: no counterpart
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
parse
Package parse has the small text readers that the loaders of package model share: fields, integers and decimal numbers read from byte slices with no allocation (an OBJ file of a million triangles has some seven million of them).
|
Package parse has the small text readers that the loaders of package model share: fields, integers and decimal numbers read from byte slices with no allocation (an OBJ file of a million triangles has some seven million of them). |
|
vtx
Package vtx is the table that welds equal vertices for the loaders of package model: a hash table from a key of three integers (the bits of a position, or its cell on a grid) to the number of the vertex that was first seen with it.
|
Package vtx is the table that welds equal vertices for the loaders of package model: a hash table from a key of three integers (the bits of a position, or its cell on a grid) to the number of the vertex that was first seen with it. |
|
Package obj reads Wavefront OBJ files, with the subset of MTL that matters to a viewer, into a model.Model (SPEC §27.9).
|
Package obj reads Wavefront OBJ files, with the subset of MTL that matters to a viewer, into a model.Model (SPEC §27.9). |
|
Package stl reads STL files, the binary and the ASCII kind (SPEC §27.9), into a model.Model.
|
Package stl reads STL files, the binary and the ASCII kind (SPEC §27.9), into a model.Model. |