-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmvr-parser.go
More file actions
69 lines (54 loc) · 1.77 KB
/
mvr-parser.go
File metadata and controls
69 lines (54 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package MVRParser
import (
"archive/zip"
"encoding/xml"
"fmt"
"io"
GDTFReader "github.com/Patch2PDF/MVR-Parser/internal/gdtfreader"
"github.com/Patch2PDF/MVR-Parser/internal/geometry3d"
MVRXML "github.com/Patch2PDF/MVR-Parser/internal/types/mvrxml"
MVRTypes "github.com/Patch2PDF/MVR-Parser/pkg/types"
)
// Takes a `.mvr` file zip reader and parses it, according to the given config
//
// may contain an entire mesh model of the stage, if configured as such
func ParseMVRZipReader(zipfile *zip.Reader, config MVRTypes.MVRParserConfig) (*MVRTypes.GeneralSceneDescription, error) {
var mvrData MVRXML.GeneralSceneDescription
// TODO: docs + tests
// put all files in zip into the filemap
var fileMap map[string]*zip.File = make(map[string]*zip.File)
for _, file := range zipfile.File {
fileMap[file.Name] = file
}
// parse mvr xml
if fileMap["GeneralSceneDescription.xml"] == nil {
return nil, fmt.Errorf("Invalid MVR: missing GeneralSceneDescription.xml")
}
xmlFile, err := fileMap["GeneralSceneDescription.xml"].Open()
if err != nil {
return nil, err
}
data, err := io.ReadAll(xmlFile)
if err != nil {
return nil, err
}
err = xml.Unmarshal(data, &mvrData)
if err != nil {
return nil, err
}
parseConfig := MVRXML.ParseConfigData{
GDTFTaskMap: &map[string]*GDTFReader.GDTFTask{},
}
parsedData := mvrData.Parse(parseConfig)
refPointers := MVRTypes.CreateRefPointersMap()
GDTFReader.GetGDTFs(parseConfig.GDTFTaskMap, refPointers, fileMap, config)
parsedData.CreateReferencePointer(refPointers)
parsedData.ResolveReference(refPointers)
if config.MeshHandling >= MVRTypes.ReadMeshesIntoModels {
geometry3d.ReadMeshes(fileMap, parsedData)
}
if config.MeshHandling >= MVRTypes.BuildStageModel {
parsedData.GenerateMeshes()
}
return parsedData, nil
}