modeler

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: BSD-2-Clause Imports: 8 Imported by: 24

Documentation

Overview

Example
package main

import (
	"github.com/qmuntal/gltf"
	"github.com/qmuntal/gltf/modeler"
)

func main() {
	m := modeler.NewModeler()
	positionAccessor := m.AddPosition(0, [][3]float32{{43, 43, 0}, {83, 43, 0}, {63, 63, 40}, {43, 83, 0}, {83, 83, 0}})
	indicesAccessor := m.AddIndices(0, []uint8{0, 1, 2, 3, 1, 0, 0, 2, 3, 1, 4, 2, 4, 3, 2, 4, 1, 3})
	colorIndices := m.AddColor(0, [][3]uint8{{50, 155, 255}, {0, 100, 200}, {255, 155, 50}, {155, 155, 155}, {25, 25, 25}})
	m.Document.Meshes = []gltf.Mesh{{
		Name: "Pyramid",
		Primitives: []gltf.Primitive{
			{
				Indices: gltf.Index(indicesAccessor),
				Attributes: map[string]uint32{
					"POSITION": positionAccessor,
					"COLOR_0":  colorIndices,
				},
			},
		},
	}}
	m.Nodes = []gltf.Node{{Name: "Root", Mesh: gltf.Index(0)}}
	m.Scenes[0].Nodes = append(m.Scenes[0].Nodes, 0)
	if err := gltf.SaveBinary(m.Document, "./example.glb"); err != nil {
		panic(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompressionLevel

type CompressionLevel uint8

CompressionLevel defines the different levels of compression.

const (
	// CompressionNone will not apply any compression.
	CompressionNone CompressionLevel = iota
	// CompressionLossless will reduce the byte size without sacrificing quality.
	CompressionLossless
)

type Modeler

type Modeler struct {
	*gltf.Document
	Compression CompressionLevel
}

Modeler wraps a Document and add useful methods to build it. If Compress is true, all the data added to accessors that support different component types will be evaluated to see if it fits in a smaller component type.

func NewModeler

func NewModeler() *Modeler

NewModeler returns a new Modeler instance.

func (*Modeler) AddColor

func (m *Modeler) AddColor(bufferIndex uint32, data interface{}) uint32

AddColor adds a new COLOR accessor to the Document and fills the buffer with the color data. If success it returns the index of the new accessor.

func (*Modeler) AddImage

func (m *Modeler) AddImage(bufferIndex uint32, name, mimeType string, r io.Reader) (uint32, error)

AddImage adds a new image to the Document and fills the buffer with the image data. If success it returns the index of the new image.

func (*Modeler) AddIndices

func (m *Modeler) AddIndices(bufferIndex uint32, data interface{}) uint32

AddIndices adds a new INDICES accessor to the Document and fills the buffer with the indices data. If success it returns the index of the new accessor.

func (*Modeler) AddJoints

func (m *Modeler) AddJoints(bufferIndex uint32, data interface{}) uint32

AddJoints adds a new JOINTS accessor to the Document and fills the buffer with the joints data. If success it returns the index of the new accessor.

func (*Modeler) AddNormal

func (m *Modeler) AddNormal(bufferIndex uint32, data [][3]float32) uint32

AddNormal adds a new NORMAL accessor to the Document and fills the buffer with the indices data. If success it returns the index of the new accessor.

func (*Modeler) AddPosition

func (m *Modeler) AddPosition(bufferIndex uint32, data [][3]float32) uint32

AddPosition adds a new POSITION accessor to the Document and fills the buffer with the vertices data. If success it returns the index of the new accessor.

func (*Modeler) AddTangent

func (m *Modeler) AddTangent(bufferIndex uint32, data [][4]float32) uint32

AddTangent adds a new TANGENT accessor to the Document and fills the buffer with the indices data. If success it returns the index of the new accessor.

func (*Modeler) AddTextureCoord

func (m *Modeler) AddTextureCoord(bufferIndex uint32, data interface{}) uint32

AddTextureCoord adds a new TEXTURECOORD accessor to the Document and fills the buffer with the texturecoord data. If success it returns the index of the new accessor.

func (*Modeler) AddWeights

func (m *Modeler) AddWeights(bufferIndex uint32, data interface{}) uint32

AddWeights adds a new WEIGHTS accessor to the Document and fills the buffer with the weights data. If success it returns the index of the new accessor.

Jump to

Keyboard shortcuts

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