Skip to content
mlctrezPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

obj2png

Go Report Card

A Go module for rendering Wavefront OBJ files (with MTL material support) to PNG images using software rasterization.

created by tigwen

Install

go get github.com/mlctrez/obj2png

Requires Go 1.21 or later.

Dependencies

Usage

Basic render with defaults

package main

import (
	"log"

	"github.com/mlctrez/obj2png"
)

func main() {
	options := obj2png.DefaultRenderOptions()
	if err := obj2png.Render("model.obj", "model.png", options); err != nil {
		log.Fatal(err)
	}
}

Render with a specific view angle

options := obj2png.DefaultRenderOptions()
err := obj2png.Render("model.obj", "front_left.png", options, obj2png.ViewFrontLeft)

Available view angles

Constant Description
ViewFrontRight Front-right elevated (default)
ViewFrontLeft Front-left elevated
ViewFront Front center elevated
ViewRight Right side elevated
ViewLeft Left side elevated
ViewBackRight Back-right elevated
ViewBackLeft Back-left elevated
ViewBack Back center elevated
ViewTop Directly above

Custom render options

options := obj2png.RenderOptions{
	Width:  1024,
	Height: 1024,
	Scale:  2,
	Fovy:   30,
	Near:   1,
	Far:    10,
	Eye:    fauxgl.V(3, 3, 3),
	Center: fauxgl.V(0, 0, 0),
	Up:     fauxgl.V(0, 1, 0),
	Light:  fauxgl.V(1.5, 2.7, 1.5).Normalize(),
}
err := obj2png.Render("model.obj", "model_hires.png", options)

Note: when a ViewAngle is provided, it overrides the Eye field in options.

CLI

A command-line tool is included in cmd/main.go for batch rendering directories of OBJ files with index page generation.

# single file
go run ./cmd model.obj output.png

# directory of OBJ files
go run ./cmd ./models ./output

# skip specific directories
go run ./cmd -skip=archive,temp ./models ./output

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

⌂ 换网址