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:
@ -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])}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user