mogaika / god_of_war_browser

https://discord.gg/u6x3Z9v6Ed
41 stars 25 forks source link

Error exporting level WADs to GLB #75

Open max-zilla opened 1 year ago

max-zilla commented 1 year ago

I have been going through the GOW1 stages exporting them so I can use them in blender to make maps, amazing tool. However, two WADs in particular are throwing errors on export. Here is the log output for loading the level (viewing works fine in the browser) and exporting:

ATHN02A (Athens docks)

::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/25 HTTP/1.1" 200 176
::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/579 HTTP/1.1" 200 325
::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/588 HTTP/1.1" 200 325
::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/585 HTTP/1.1" 200 333
::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/576 HTTP/1.1" 200 330
::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/582 HTTP/1.1" 200 299
::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/591 HTTP/1.1" 200 325
::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/594 HTTP/1.1" 200 328
::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/597 HTTP/1.1" 200 324
::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/600 HTTP/1.1" 200 324
2022/07/21 08:03:23 Failed to find color material for physical mat "visuals02A_brokenFacade" (exact true, suffix "MAT_brokenFacade", index 0)
::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/4888 HTTP/1.1" 200 1305150
::1 - - [21/Jul/2022:08:03:23 -0500] "GET /json/pack/ATHN02A.WAD/5154 HTTP/1.1" 200 8457
::1 - - [21/Jul/2022:08:03:23 -0500] "GET /json/pack/ATHN02A.WAD/5195 HTTP/1.1" 200 4220
::1 - - [21/Jul/2022:08:03:23 -0500] "GET /json/pack/ATHN02A.WAD/5235 HTTP/1.1" 200 4233
::1 - - [21/Jul/2022:08:03:23 -0500] "GET /json/pack/ATHN02A.WAD/5275 HTTP/1.1" 200 47311
::1 - - [21/Jul/2022:08:03:23 -0500] "GET /json/pack/ATHN02A.WAD/5316 HTTP/1.1" 200 529306
::1 - - [21/Jul/2022:08:03:23 -0500] "GET /json/pack/ATHN02A.WAD/5081 HTTP/1.1" 200 6658753
::1 - - [21/Jul/2022:08:03:22 -0500] "GET /json/pack/ATHN02A.WAD/4890 HTTP/1.1" 200 32257284
2022/07/21 08:03:33 Failed to find node "lodsandbag02"
2022/07/21 08:03:33 Failed to find node "lodsandbag03"
2022/07/21 08:03:33 Failed to find node "lodsandbag012"
2022/07/21 08:03:33 Failed to find node "lodsandbag013"
2022/07/21 08:03:34 Failed to find node "loddeadbod05"
2022/07/21 08:03:34 Failed to find node "locator1"
2022/07/21 08:03:34 Failed to find node "locator2"
2022/07/21 08:03:34 runtime error: index out of range [0] with length 0
2022/07/21 08:03:34 goroutine 357 [running]:
runtime/debug.Stack()
        C:/go/src/runtime/debug/stack.go:24 +0x83
github.com/gorilla/handlers.recoveryHandler.log({{0x98e738, 0x12229140}, {0x0, 0x0}, 0x1}, {0x1249b920, 0x1, 0x1})
        c:/gopath/pkg/mod/github.com/gorilla/handlers@v1.5.1/recovery.go:89 +0x75
github.com/gorilla/handlers.recoveryHandler.ServeHTTP.func1()
        c:/gopath/pkg/mod/github.com/gorilla/handlers@v1.5.1/recovery.go:74 +0xce
panic({0x89abe0, 0x14954fc0})
        C:/go/src/runtime/panic.go:838 +0x1ba
github.com/mogaika/god_of_war_browser/pack/wad/mesh.(*Mesh).ExportGLTF(0x12086a40, 0x12281f20, 0x12d3f3a4)
        C:/gopath/src/github.com/mogaika/god_of_war_browser/pack/wad/mesh/export_gltf.go:116 +0x1036
github.com/mogaika/god_of_war_browser/pack/wad/mdl.(*Model).ExportGLTF.func2()
        C:/gopath/src/github.com/mogaika/god_of_war_browser/pack/wad/mdl/export_gltf.go:45 +0x40
github.com/mogaika/god_of_war_browser/utils/gltfutils.(*GLTFCacher).GetCachedOr(0x12d3f3a4, 0x109b, 0x12d3edd0)
        C:/gopath/src/github.com/mogaika/god_of_war_browser/utils/gltfutils/gltfutils.go:47 +0x64
github.com/mogaika/god_of_war_browser/pack/wad/mdl.(*Model).ExportGLTF(0x12acecd0, 0x12281470, 0x12d3f3a4)
        C:/gopath/src/github.com/mogaika/god_of_war_browser/pack/wad/mdl/export_gltf.go:44 +0x2b1
github.com/mogaika/god_of_war_browser/pack/wad/obj.(*Object).ExportGLTF.func1()
        C:/gopath/src/github.com/mogaika/god_of_war_browser/pack/wad/obj/export_gltf.go:205 +0x65
github.com/mogaika/god_of_war_browser/utils/gltfutils.(*GLTFCacher).GetCachedOr(0x12d3f3a4, 0x108a, 0x12d3f10c)
        C:/gopath/src/github.com/mogaika/god_of_war_browser/utils/gltfutils/gltfutils.go:47 +0x64
github.com/mogaika/god_of_war_browser/pack/wad/obj.(*Object).ExportGLTF(0x135adf10, 0x12281180, 0x12d3f3a4)
        C:/gopath/src/github.com/mogaika/god_of_war_browser/pack/wad/obj/export_gltf.go:204 +0xbbd
github.com/mogaika/god_of_war_browser/pack/wad/inst.(*Instance).ExportGLTF(0x12bd3270, 0x12281120, 0x12d3f3a4)
        C:/gopath/src/github.com/mogaika/god_of_war_browser/pack/wad/inst/export_gltf.go:45 +0x415
github.com/mogaika/god_of_war_browser/pack/wad/cxt.(*Chunk).ExportGLTF(0xca222c, 0x13e0cc70, 0x12d3f3a4)
        C:/gopath/src/github.com/mogaika/god_of_war_browser/pack/wad/cxt/export_gltf.go:40 +0x2bf
github.com/mogaika/god_of_war_browser/pack/wad/cxt.(*Chunk).HttpAction(0xca222c, 0x13e0cc40, {0x990d48, 0x12be6090}, 0x132ad800, {0x13dce01b, 0x8})
        C:/gopath/src/github.com/mogaika/god_of_war_browser/pack/wad/cxt/actions.go:42 +0x8cf
reflect.Value.call({0x15cd6c30, 0x121a5cf8, 0x13}, {0x8c369e, 0x4}, {0x12d3f82c, 0x5, 0x5})
        C:/go/src/reflect/value.go:556 +0x652
reflect.Value.Call({0x15cd6c30, 0x121a5cf8, 0x13}, {0x12d3f82c, 0x5, 0x5})
        C:/go/src/reflect/value.go:339 +0x82
github.com/mogaika/god_of_war_browser/pack/wad.(*Wad).WebHandlerCallResourceHttpAction(0x14075840, {0x990d48, 0x12be6090}, 0x132ad800, 0x19, {0x13dce01b, 0x8})
        C:/gopath/src/github.com/mogaika/god_of_war_browser/pack/wad/webhandlers.go:72 +0x572
github.com/mogaika/god_of_war_browser/web.HandlerActionPackFileParam({0x990d48, 0x12be6090}, 0x132ad800)
        C:/gopath/src/github.com/mogaika/god_of_war_browser/web/handlers.go:196 +0x2b6
net/http.HandlerFunc.ServeHTTP(0x8ec8d4, {0x990d48, 0x12be6090}, 0x132ad800)
        C:/go/src/net/http/server.go:2084 +0x34
github.com/gorilla/mux.(*Router).ServeHTTP(0x12229140, {0x990d48, 0x12be6090}, 0x132ad700)
        c:/gopath/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x1d1
github.com/gorilla/handlers.recoveryHandler.ServeHTTP({{0x98e738, 0x12229140}, {0x0, 0x0}, 0x1}, {0x990d48, 0x12be6090}, 0x132ad700)
        c:/gopath/pkg/mod/github.com/gorilla/handlers@v1.5.1/recovery.go:78 +0x8a
github.com/gorilla/handlers.loggingHandler.ServeHTTP({{0x98ee90, 0x12006110}, {0x98e710, 0x122562e8}, 0x8ec7c0}, {0x9909e4, 0x13562500}, 0x132ad700)
        c:/gopath/pkg/mod/github.com/gorilla/handlers@v1.5.1/logging.go:47 +0x9a
net/http.serverHandler.ServeHTTP({0x12066990}, {0x9909e4, 0x13562500}, 0x132ad700)
        C:/go/src/net/http/server.go:2916 +0x371
net/http.(*conn).serve(0x1646a060, {0x990f30, 0x12256348})
        C:/go/src/net/http/server.go:1966 +0x67d
created by net/http.(*Server).Serve
        C:/go/src/net/http/server.go:3071 +0x498

::1 - - [21/Jul/2022:08:03:33 -0500] "GET /action/ATHN02A.WAD/25/gltf_all? HTTP/1.1" 500 0
::1 - - [21/Jul/2022:08:03:39 -0500] "GET /ws/status HTTP/1.1" 200 0
2022/07/21 08:03:39 HERR: {"error":"wad web handler return error: File ATHN02A.WAD-0[WAD_Athn02A] parsing error: Cannot find handler for tag 0378 (WAD_Athn02A)"}

The other error occurred was PAND00C (Pandora rings):

2022/07/21 08:10:12 Failed to find node "locator5"
2022/07/21 08:10:14 runtime error: index out of range [0] with length 0
2022/07/21 08:10:14 goroutine 22 [running]:

...there may be others, but so far (through that much of the list) everything else has worked. I did notice that when ATHN02A said Cannot find handler for tag 0378 (WAD_Athn02A), there is indeed no 0378 entry on the list for that WAD.

max-zilla commented 1 year ago

was able to work around this by modifying pack/wad/mesh/export_gltf.go around line 114:

if colorAccessors != nil {
        for iLayer := 0; iLayer<object.LayersCount; iLayer++ {
                if iLayer < len(colorAccessors) {
                        attributes[fmt.Sprintf("COLOR_%d", iLayer)] = colorAccessors[iLayer]
                } else {
                        colors := make([][4]uint8, verticesCount)
                        for iVertex := range object.Vertices {
                                colors[iVertex] = [4]uint8{95, 95, 103, 255}
                        }
                        attributes[fmt.Sprintf("COLOR_%d", iLayer)] = modeler.WriteColor(doc, colors)
                }
        }
}

It seems to fail when trying to set COLOR_ attribute when iLayer exceeds length of colorAccessors (something missing vertex data?) so here i replace missing vertex color with the default grey color that seems used in many maps. kind of a hack fix so not making a PR for now

Spaynt commented 9 months ago

was able to work around this by modifying pack/wad/mesh/export_gltf.go around line 114:

if colorAccessors != nil {
      for iLayer := 0; iLayer<object.LayersCount; iLayer++ {
              if iLayer < len(colorAccessors) {
                      attributes[fmt.Sprintf("COLOR_%d", iLayer)] = colorAccessors[iLayer]
              } else {
                      colors := make([][4]uint8, verticesCount)
                      for iVertex := range object.Vertices {
                              colors[iVertex] = [4]uint8{95, 95, 103, 255}
                      }
                      attributes[fmt.Sprintf("COLOR_%d", iLayer)] = modeler.WriteColor(doc, colors)
              }
      }
}

It seems to fail when trying to set COLOR_ attribute when iLayer exceeds length of colorAccessors (something missing vertex data?) so here i replace missing vertex color with the default grey color that seems used in many maps. kind of a hack fix so not making a PR for now

where is it located?