mirror of
https://github.com/bloeys/nmage.git
synced 2025-12-29 13:28:20 +00:00
Load texture from res folder
This commit is contained in:
@ -24,7 +24,7 @@ type Texture struct {
|
||||
Pixels []byte
|
||||
}
|
||||
|
||||
func LoadPNG(file string) (Texture, error) {
|
||||
func LoadPNGTexture(file string) (Texture, error) {
|
||||
|
||||
if tex, ok := GetTexturePath(file); ok {
|
||||
return tex, nil
|
||||
|
||||
8
main.go
8
main.go
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/bloeys/assimp-go/asig"
|
||||
"github.com/bloeys/gglm/gglm"
|
||||
"github.com/bloeys/nmage/assets"
|
||||
"github.com/bloeys/nmage/engine"
|
||||
"github.com/bloeys/nmage/input"
|
||||
"github.com/bloeys/nmage/logging"
|
||||
@ -86,6 +87,13 @@ func main() {
|
||||
logging.ErrLog.Fatalln("Failed to load cube mesh. Err: ", err)
|
||||
}
|
||||
|
||||
//Load textures
|
||||
tex, err := assets.LoadPNGTexture("./res/textures/Low poly planet.png")
|
||||
if err != nil {
|
||||
logging.ErrLog.Fatalln("Failed to load texture. Err: ", err)
|
||||
}
|
||||
cubeMesh.AddTexture(tex)
|
||||
|
||||
//Set mesh textures on material
|
||||
for _, v := range cubeMesh.TextureIDs {
|
||||
simpleMat.AddTextureID(v)
|
||||
|
||||
@ -9,7 +9,6 @@ import (
|
||||
"github.com/bloeys/nmage/asserts"
|
||||
"github.com/bloeys/nmage/assets"
|
||||
"github.com/bloeys/nmage/buffers"
|
||||
"github.com/bloeys/nmage/logging"
|
||||
)
|
||||
|
||||
type Mesh struct {
|
||||
@ -18,6 +17,10 @@ type Mesh struct {
|
||||
Buf buffers.Buffer
|
||||
}
|
||||
|
||||
func (m *Mesh) AddTexture(tex assets.Texture) {
|
||||
m.TextureIDs = append(m.TextureIDs, tex.TexID)
|
||||
}
|
||||
|
||||
func NewMesh(name, modelPath string, postProcessFlags asig.PostProcess) (*Mesh, error) {
|
||||
|
||||
scene, release, err := asig.ImportFile(modelPath, asig.PostProcessTriangulate|postProcessFlags)
|
||||
@ -42,22 +45,6 @@ func NewMesh(name, modelPath string, postProcessFlags asig.PostProcess) (*Mesh,
|
||||
}
|
||||
mesh.Buf.SetLayout(layoutToUse...)
|
||||
|
||||
//Load diffuse textures
|
||||
mat := scene.Materials[sceneMesh.MaterialIndex]
|
||||
if asig.GetMaterialTextureCount(mat, asig.TextureTypeDiffuse) > 0 {
|
||||
texInfo, err := asig.GetMaterialTexture(mat, asig.TextureTypeDiffuse, 0)
|
||||
if err != nil {
|
||||
logging.ErrLog.Fatalf("Failed to get material texture of index 0. Err: %e\n", err)
|
||||
}
|
||||
|
||||
tex, err := assets.LoadPNG(texInfo.Path)
|
||||
if err != nil {
|
||||
logging.ErrLog.Fatalf("Loading PNG with path '%s' failed. Err: %e\n", texInfo.Path, err)
|
||||
}
|
||||
|
||||
mesh.TextureIDs = append(mesh.TextureIDs, tex.TexID)
|
||||
}
|
||||
|
||||
var values []float32
|
||||
arrs := []arrToInterleave{{V3s: sceneMesh.Vertices}, {V3s: sceneMesh.Normals}, {V2s: v3sToV2s(sceneMesh.TexCoords[0])}}
|
||||
|
||||
|
||||
BIN
res/textures/Low poly planet.png
Executable file
BIN
res/textures/Low poly planet.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 468 KiB |
Reference in New Issue
Block a user