<commit_before>package asset

import (
	"fmt"
	"math"
	"strings"

	"github.com/go-gl/mathgl/mgl32"
	"github.com/omustardo/gome/model/mesh"
)

// This code is originally based on https://gist.github.com/davemackintosh/67959fa9dfd9018d79a4
// and https://en.wikipedia.org/wiki/Wavefront_.obj_file
// and http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/
//
// Unfortunately, found this list after implementing... I should probably use one of these instead:
// Other Golang OBJ loaders from https://github.com/mmchugh/gomobile-examples/issues/6
//https://github.com/go-qml/qml/blob/v1/examples/gopher/wavefront.go https://github.com/peterhellberg/wavefront/blob/master/wavefront.go
//https://github.com/Stymphalian/go.gl/blob/master/jgl/obj_filereader.go
//https://github.com/tobscher/go-three/blob/master/loaders/obj.go
//https://github.com/adam000/read-obj/tree/master/obj https://github.com/adam000/read-obj/blob/master/mtl/mtl.go
//https://github.com/udhos/negentropia/blob/master/webserv/src/negentropia/world/obj/obj.go
//https://github.com/fogleman/pt/blob/master/pt/obj.go
//https://github.com/luxengine/lux/blob/master/utils/objloader.go
//https://github.com/gmacd/obj/blob/master/obj.go
//https://github.com/gographics/goviewer/blob/master/loader/wavefront.go
//https://github.com/sf1/go3dm
//https://github.com/peterudkmaya11/lux/blob/master/utils/objloader.go

// LoadOBJ creates a mesh from an obj file.
func LoadOBJ(path string) (mesh.Mesh, error) {
	return loadOBJ(path, false)
}

// LoadOBJNormalized creates a mesh from an obj file.
// The loaded OBJ is scaled to be as large as possible while still fitting in a unit sphere.
func LoadOBJNormalized(path string) (mesh.Mesh, error) {
	return loadOBJ(path, true)
}

func loadOBJ(path string, normalize bool) (mesh.Mesh, error) {
	fileData, err := loadFile(path)
	if err != nil {
		return mesh.Mesh{}, err
	}
	verts, normals, textureCoords, err := loadOBJData(fileData)
	if err != nil {<commit_msg>Add TODO for loading materials in OBJ files<commit_after>package asset

import (
	"fmt"
	"math"
	"strings"

	"github.com/go-gl/mathgl/mgl32"
	"github.com/omustardo/gome/model/mesh"
)

// This code is originally based on https://gist.github.com/davemackintosh/67959fa9dfd9018d79a4
// and https://en.wikipedia.org/wiki/Wavefront_.obj_file
// and http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/
//
// Unfortunately, found this list after implementing... I should probably use one of these instead:
// Other Golang OBJ loaders from https://github.com/mmchugh/gomobile-examples/issues/6
//https://github.com/go-qml/qml/blob/v1/examples/gopher/wavefront.go https://github.com/peterhellberg/wavefront/blob/master/wavefront.go
//https://github.com/Stymphalian/go.gl/blob/master/jgl/obj_filereader.go
//https://github.com/tobscher/go-three/blob/master/loaders/obj.go
//https://github.com/adam000/read-obj/tree/master/obj https://github.com/adam000/read-obj/blob/master/mtl/mtl.go
//https://github.com/udhos/negentropia/blob/master/webserv/src/negentropia/world/obj/obj.go
//https://github.com/fogleman/pt/blob/master/pt/obj.go
//https://github.com/luxengine/lux/blob/master/utils/objloader.go
//https://github.com/gmacd/obj/blob/master/obj.go
//https://github.com/gographics/goviewer/blob/master/loader/wavefront.go
//https://github.com/sf1/go3dm
//https://github.com/peterudkmaya11/lux/blob/master/utils/objloader.go
//
// TODO: Consider supporting materials (mtl tag). Info on specific MTL tags: http://nendowingsmirai.yuku.com/forum/viewtopic/id/1723#.WHmLqhsrIuU
// Ns = Phong specular component.
// Kd = Diffuse color weighted by the diffuse coefficient.
// Ka = Ambient color weighted by the ambient coefficient.
// Ks = Specular color weighted by the specular coefficient.
// d = Dissolve factor (pseudo-transparency). Values are from 0-1. 0 is completely transparent, 1 is opaque.
// Ni = Refraction index. Values range from 1 upwards. A value of 1 will cause no refraction. A higher value implies refraction.
// illum = (0, 1, or 2) 0 to disable lighting, 1 for ambient & diffuse only (specular color set to black), 2 for full lighting (see below)
// sharpness = ?
// map_Kd = Diffuse color texture map.
// map_Ks = Specular color texture map.
// map_Ka = Ambient color texture map.
// map_Bump = Bump texture map.
// map_d = Opacity texture map.
// refl = reflection type and filename (?)

// LoadOBJ creates a mesh from an obj file.
func LoadOBJ(path string) (mesh.Mesh, error) {
	return loadOBJ(path, false)
}

// LoadOBJNormalized creates a mesh from an obj file.
// The loaded OBJ is scaled to be as large as possible while still fitting in a unit sphere.
func LoadOBJNormalized(path string) (mesh.Mesh, error) {
	return loadOBJ(path, true)
}

func loadOBJ(path string, normalize bool) (mesh.Mesh, error) {
	fileData, err := loadFile(path)
	if err != nil {
		return mesh.Mesh{}, err
	}
	verts, normals, textureCoords, err := loadOBJData(fileData)
	if err != nil {
{'fraction_non_alphanumeric': 0.14288581175998394, 'fraction_numerical': 0.014449127031908489, 'mean_word_length': 3.910344827586207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 32, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2434570', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1713, 'n_words': 389}