コード例 #1
0
ファイル: import.go プロジェクト: pombredanne/rand
// Import reads the file using the FileIO interface and returns it's content.
//
// The flags parameter is a bitwise combination of pre-defined PostFlags which
// determine if and how post processing of the data should occur.
//
// The properties map defines various importer properties to utilize.
//
// If successfull the data is returned in the Scene structure which should be
// considered read-only (as the assimp library owns the memory), and a nil
// error is returned.
//
// If failure occurs a nil *Scene and a human-readable error is returned.
func Import(filepath string, flags PostFlags, fs FileIO, properties map[Prop]interface{}) (*Scene, error) {
	if len(filepath) == 0 {
		return nil, errors.New("empty file path")
	}
	s := &Scene{
		fs: aiFileIO(fs),
	}
	if len(properties) > 0 {
		s.props = createPropertyStore()
		for k, v := range properties {
			s.props.Set(string(k), v)
		}
		s.c = C.aiImportFileExWithProperties(
			C.CString(filepath),
			C.uint(flags),
			(*[0]byte)(unsafe.Pointer(s.fs.c)),
			s.props.c,
		)
	} else {
		s.c = C.aiImportFileEx(
			C.CString(filepath),
			C.uint(flags),
			(*[0]byte)(unsafe.Pointer(s.fs.c)),
		)
	}
	if s.c == nil {
		err := errors.New(C.GoString(C.aiGetErrorString()))
		return nil, err
	}

	runtime.SetFinalizer(s, func(f *Scene) {
		C.aiReleaseImport(f.c)
	})
	return s, nil
}
コード例 #2
0
ファイル: Import.go プロジェクト: krux02/assimp
func GetErrorString() string {
	return C.GoString(C.aiGetErrorString())
}