lscm

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 7 Imported by: 0

README

Least Square Conformal Mapping

Least Squares Conformal Mapping (LSCM) is a mathematical technique that helps flatten and map irregular surfaces onto a 2D plane while preserving the angles between neighboring points as much as possible.

This is particularly useful for tasks like texture mapping in 3D graphics.

Usage

See demo/main.go for an example of how to read a Wavefront .obj file into a mesh and generate texture coordinates using LSCM. An example face model is provided without vertex coordinates. The demo takes several minutes to run.

go run demo/main.go
Example

Below is an animation of the face model after adding LSCM-generated vertex coordinates. The texture is generated using the vertex coordinates to draw red-black triangles for each face. Rendering was done with g3n.

human-face

Credits

See the paper at https://dl.acm.org/doi/10.1145/566654.566590.

Code is based on https://github.com/icemiliang/lscm.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunLSCM added in v1.0.0

func RunLSCM(mesh *Mesh) error

func WriteObj added in v1.0.0

func WriteObj(w io.Writer, m *Mesh) error

WriteObj writes a Wavefront .obj file content to the writer.

This only supports vertices, texture coordinates, normals, and faces.

Types

type Mesh

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

func NewMesh

func NewMesh(points []float32, uvs []float32, normals []float32, indices []uint32, fixedIndices []uint32) (*Mesh, error)

NewMesh creates a Mesh object from the buffers provided. The buffers provided may be modified by LSCM.

Parameters:

  • points: slice of vertex coordinates, every 3 elements representing a vertex
  • uvs: slice of texture coordinates, every 2 elements representing a vertex, the values will be overwritten by LSCM
  • normals: may be nil, it is only included for convenience and not used by LSCM
  • indices: slice of vertex indices for each face, every 3 elements representing a face
  • fixedIndices: slice of vertex indices for fixed uvs for LSCM, at least 2 are required

If the wrong number of points, uvs, indices, or fixedIndices is detected, an error is returned.

func ParseObj added in v1.0.0

func ParseObj(obj string) (*Mesh, error)

ParseObj parses a Wavefront .obj file content into a Mesh.

At least two of the vertex lines need "fix 0.0, 0.0" post-fixed to the line to indicate fixed vertices for LSCM The coordinates are fixed texture coordinates for those vertexes.

This does not support all obj properties. Only parses vertices, normals, and faces while ignoring other lines. Assumes the corresponding normal indices are the same as the vertex indices.

func (*Mesh) GetNormals added in v1.0.0

func (m *Mesh) GetNormals() []float32

func (*Mesh) GetPoints added in v1.0.0

func (m *Mesh) GetPoints() []float32

func (*Mesh) GetUVs added in v1.0.0

func (m *Mesh) GetUVs() []float32

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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