File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package GDTFMeshReader
2+
3+ import (
4+ "fmt"
5+ "io"
6+ "path/filepath"
7+
8+ "github.com/Patch2PDF/GDTF-Mesh-Reader/pkg/MeshTypes"
9+ FileHandlers "github.com/Patch2PDF/GDTF-Mesh-Reader/pkg/file_handlers"
10+ Primitives "github.com/Patch2PDF/GDTF-Mesh-Reader/pkg/primitives"
11+ )
12+
13+ type ModelReaderConf struct {
14+ File * io.Reader
15+ Filename * string
16+ PrimitiveType string
17+ }
18+
19+ func GetModel (conf ModelReaderConf , desiredSize MeshTypes.Vector ) (* MeshTypes.Mesh , error ) {
20+ var mesh * MeshTypes.Mesh
21+
22+ if conf .PrimitiveType == "undefined" && conf .File != nil && conf .Filename != nil && * conf .Filename != "" {
23+ filetype := filepath .Ext (* conf .Filename )
24+ switch filetype {
25+ case ".gltf" , ".glb" :
26+ meshes , err := FileHandlers .LoadGLTF (* conf .File , desiredSize )
27+ if err != nil {
28+ return nil , err
29+ }
30+ mesh = meshes [0 ]
31+ case ".3ds" :
32+ data , err := io .ReadAll (* conf .File )
33+ if err != nil {
34+ return nil , err
35+ }
36+ mesh , err = FileHandlers .Load3DS (& data , & desiredSize )
37+ if err != nil {
38+ return nil , err
39+ }
40+ default :
41+ return nil , fmt .Errorf ("unknown model type %s" , filetype )
42+ }
43+ } else if conf .PrimitiveType != "undefined" && Primitives .Primitives [conf .PrimitiveType ] != nil {
44+ tempMesh := Primitives .Primitives [conf .PrimitiveType ].Copy ()
45+ mesh = & tempMesh
46+ mesh .ScaleToDimensions (& desiredSize )
47+ }
48+
49+ return mesh , nil
50+ }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import (
1010 "github.com/qmuntal/gltf"
1111)
1212
13- func LoadGLTF (file io.ReadCloser , desiredSize Types.Vector ) ([]* Types.Mesh , error ) {
13+ func LoadGLTF (file io.Reader , desiredSize Types.Vector ) ([]* Types.Mesh , error ) {
1414 var doc gltf.Document
1515 gltf .NewDecoder (file ).Decode (& doc )
1616
You can’t perform that action at this time.
0 commit comments