g3n / engine

Go 3D Game Engine (http://g3n.rocks)
https://discord.gg/NfaeVr8zDg
BSD 2-Clause "Simplified" License
2.8k stars 295 forks source link

.obj loader problem #127

Closed dariotarantini closed 5 years ago

dariotarantini commented 5 years ago

Hi, im tryng to load a obj model. Here is the code:

package main
import (
    "github.com/g3n/engine/graphic"
    "github.com/g3n/engine/light"
    "github.com/g3n/engine/loader/obj"
    "github.com/g3n/engine/math32"
    "github.com/g3n/engine/util/application"
)
func main() {
    app, _ := application.Create(application.Options{
        Title:  "ee",
        Width:  800,
        Height: 600,
    })
    dec, err := obj.Decode("e.obj", "e.mtl")
    if err != nil {
        panic(err.Error())
    }
    group, err := dec.NewGroup()
    if err != nil {
        panic(err.Error())
    }
    app.Scene().Add(group)
    ambientLight := light.NewAmbient(&math32.Color{1.0, 1.0, 1.0}, 0.8)
    app.Scene().Add(ambientLight)
    pointLight := light.NewPoint(&math32.Color{1, 1, 1}, 5.0)
    pointLight.SetPosition(1, 0, 2)
    app.Scene().Add(pointLight)
    // Add an axis helper to the scene
    axis := graphic.NewAxisHelper(0.5)
    app.Scene().Add(axis)
    app.CameraPersp().SetPosition(0, 0, 3)
    app.Run()
}

i get this error:

panic: open /home/gate.bmp: no such file or directory

goroutine 1 [running, locked to thread]:
main.main()
    /home/dario/Scrivania/e/main.go:26 +0x2ba
exit status 2
danaugrs commented 5 years ago

Hi - does the file /home/gate.bmp exist?

dariotarantini commented 5 years ago

Hi - does the file /home/gate.bmp exist?

no, of course. I don't understand what that file mean

danaugrs commented 5 years ago

The file /home/gate.bmp is an image so it's probably a texture referenced inside your e.mtl material file. You can open your .mtl file in any text editor to see which textures it references. Did you generate your .obj and .mtl using some software or grabbed them from somewhere? If you grabbed them from somewhere you need to grab the textures as well and make sure they match the paths inside the .mtl file. Alternatively you can pass in "" instead of the e.mtl file in your call to obj.Decode() and it should load the model with a default material. Like so: dec, err := obj.Decode("e.obj", "")

dariotarantini commented 5 years ago

It work! thanks!