-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_support.go
More file actions
138 lines (120 loc) · 4.66 KB
/
format_support.go
File metadata and controls
138 lines (120 loc) · 4.66 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package assimp
/*
#cgo linux CFLAGS: -I ./lib/linux
#cgo darwin,amd64 CFLAGS: -I ./lib/darwin
#cgo darwin,arm64 CFLAGS: -I ./lib/darwin_arm
#include <assimp/cimport.h>
#include <assimp/importerdesc.h>
#include <stdlib.h>
*/
import "C"
import (
"strings"
"unsafe"
)
// ImporterDesc represents the metadata about a particular importer
// This is a Go wrapper for C struct aiImporterDesc
type ImporterDesc struct {
Name string // Full name of the importer (i.e. Blender3D importer)
Author string // Original author (left blank if unknown or whole assimp team)
Maintainer string // Current maintainer, left blank if the author maintains
Comments string // Implementation comments, i.e. unimplemented features
Flags uint // Flags indicating some characteristics
MinMajor uint // Minimum format version that can be loaded (major)
MinMinor uint // Minimum format version that can be loaded (minor)
MaxMajor uint // Maximum format version that can be loaded (major)
MaxMinor uint // Maximum format version that can be loaded (minor)
FileExtensions string // List of file extensions this importer can handle
}
// GetSupportedImporterCount returns the number of import file formats available
// in the current Assimp build. Use GetImportFormatDescription to retrieve
// information about specific import formats.
func GetSupportedImporterCount() int {
return int(C.aiGetImportFormatCount())
}
// GetImportFormatDescription returns a description of the nth import file format.
// Use GetSupportedImporterCount() to learn how many import formats are supported.
// Index must be in range 0 to GetSupportedImporterCount()-1.
// Returns nil if index is out of range.
func GetImportFormatDescription(index int) *ImporterDesc {
if index < 0 || index >= GetSupportedImporterCount() {
return nil
}
cDesc := C.aiGetImportFormatDescription(C.size_t(index))
if cDesc == nil {
return nil
}
return &ImporterDesc{
Name: C.GoString(cDesc.mName),
Author: C.GoString(cDesc.mAuthor),
Maintainer: C.GoString(cDesc.mMaintainer),
Comments: C.GoString(cDesc.mComments),
Flags: uint(cDesc.mFlags),
MinMajor: uint(cDesc.mMinMajor),
MinMinor: uint(cDesc.mMinMinor),
MaxMajor: uint(cDesc.mMaxMajor),
MaxMinor: uint(cDesc.mMaxMinor),
FileExtensions: C.GoString(cDesc.mFileExtensions),
}
}
// IsFormatSupported checks if a given file extension is supported by Assimp.
// The extension parameter can include or exclude the leading dot (e.g., "obj" or ".obj").
// Returns true if the format is supported, false otherwise.
func IsFormatSupported(extension string) bool {
// Remove leading dot if present
ext := strings.ToLower(strings.TrimPrefix(extension, "."))
// Create C string for extension
cExt := C.CString(ext)
defer C.free(unsafe.Pointer(cExt))
// Check if there's an importer for this extension
cDesc := C.aiGetImporterDesc(cExt)
return cDesc != nil
}
// GetAllSupportedFormats returns a slice of all supported file extensions.
// Each extension is returned without the leading dot and in lowercase.
func GetAllSupportedFormats() []string {
count := GetSupportedImporterCount()
formats := make([]string, 0)
for i := 0; i < count; i++ {
desc := GetImportFormatDescription(i)
if desc != nil && desc.FileExtensions != "" {
// Split extensions by space or comma
texts := strings.FieldsFunc(desc.FileExtensions, func(r rune) bool {
return r == ' ' || r == ',' || r == ';'
})
for _, ext := range texts {
if ext = strings.TrimSpace(ext); ext != "" {
formats = append(formats, strings.ToLower(ext))
}
}
}
}
return formats
}
// GetImporterInfo returns detailed information about the importer that handles the given extension.
// The extension parameter can include or exclude the leading dot.
// Returns nil if the format is not supported.
func GetImporterInfo(extension string) *ImporterDesc {
// Remove leading dot if present
ext := strings.ToLower(strings.TrimPrefix(extension, "."))
// Create C string for extension
cExt := C.CString(ext)
defer C.free(unsafe.Pointer(cExt))
// Get importer description for this extension
cDesc := C.aiGetImporterDesc(cExt)
if cDesc == nil {
return nil
}
return &ImporterDesc{
Name: C.GoString(cDesc.mName),
Author: C.GoString(cDesc.mAuthor),
Maintainer: C.GoString(cDesc.mMaintainer),
Comments: C.GoString(cDesc.mComments),
Flags: uint(cDesc.mFlags),
MinMajor: uint(cDesc.mMinMajor),
MinMinor: uint(cDesc.mMinMinor),
MaxMajor: uint(cDesc.mMaxMajor),
MaxMinor: uint(cDesc.mMaxMinor),
FileExtensions: C.GoString(cDesc.mFileExtensions),
}
}