Load texture from res folder

This commit is contained in:
bloeys
2022-02-05 23:59:41 +04:00
parent 8e96cf7050
commit 50c2ab650f
4 changed files with 13 additions and 18 deletions

View File

@ -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])}}