assimp-ffi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,226 @@
1
+ module Assimp
2
+
3
+ callback :log_stream_callback, [:string, :string], :void
4
+
5
+ class LogStream < FFI::Struct
6
+ extend StructAccessors
7
+ layout :callback, :log_stream_callback,
8
+ :user, :pointer
9
+ struct_attr_accessor :callback, :user
10
+
11
+ def self.detach_all
12
+ Assimp::aiDetachAllLogStreams
13
+ self
14
+ end
15
+
16
+ def self.debugger
17
+ Assimp::aiGetPredefinedLogStream(:DEBUGGER, nil)
18
+ end
19
+
20
+ def self.file(path)
21
+ Assimp::aiGetPredefinedLogStream(:FILE, path)
22
+ end
23
+
24
+ def self.stdout
25
+ Assimp::aiGetPredefinedLogStream(:STDOUT, nil)
26
+ end
27
+
28
+ def self.stderr
29
+ Assimp::aiGetPredefinedLogStream(:STDERR, nil)
30
+ end
31
+
32
+ def self.verbose(bool)
33
+ Assimp::aiEnableVerboseLogging(bool)
34
+ self
35
+ end
36
+
37
+ def self.error_string
38
+ Assimp::aiGetErrorString
39
+ end
40
+
41
+ def user=(mess)
42
+ @user = FFI::MemoryPointer.from_string(mess)
43
+ self[:user] = @user
44
+ end
45
+
46
+ def attach(&block)
47
+ if block_given?
48
+ @block = FFI::Function.new(:void, [:string, :string], &block)
49
+ self.callback = @block
50
+ end
51
+ Assimp::aiAttachLogStream(self)
52
+ end
53
+
54
+ def callback=(c)
55
+ @block = c
56
+ self[:callback] = c
57
+ end
58
+
59
+ def detach
60
+ Assimp::aiDetachLogStream(self)
61
+ end
62
+
63
+ end
64
+
65
+ typedef :int, :bool
66
+
67
+ FALSE = 0
68
+ TRUE = 1
69
+
70
+ attach_function :aiApplyPostProcessing, [Scene.by_ref, PostProcessSteps], :pointer
71
+ attach_function :aiGetPredefinedLogStream, [DefaultLogStream, :string], LogStream.by_value
72
+ attach_function :aiAttachLogStream, [LogStream.by_ref], :void
73
+ attach_function :aiEnableVerboseLogging, [:bool], :void
74
+ attach_function :aiDetachLogStream, [LogStream.by_ref], Return
75
+ attach_function :aiDetachAllLogStreams, [], :void
76
+ attach_function :aiGetErrorString, [], :string
77
+
78
+ class PropertyStore < FFI::ManagedStruct
79
+ layout :dummy, :char
80
+
81
+ def initialize
82
+ super(Assimp::aiCreatePropertyStore)
83
+ end
84
+
85
+ def self.release(ptr)
86
+ Assimp::aiReleasePropertyStore(ptr)
87
+ end
88
+
89
+ def self.config_setter(*args)
90
+ args.each { |name, type|
91
+ prop = name.upcase.to_s
92
+ meth_name = name.to_s.downcase + "="
93
+ if type == :bool
94
+ define_method(meth_name) do |bool|
95
+ raise "Invalid bool value #{bool.inspect}" unless bool == Assimp::TRUE || bool == Assimp::FALSE
96
+ Assimp::aiSetImportPropertyInteger(self, prop, bool)
97
+ bool
98
+ end
99
+ elsif type == :int
100
+ define_method(meth_name) do |val|
101
+ Assimp::aiSetImportPropertyInteger(self, prop, val)
102
+ val
103
+ end
104
+ elsif type == :float
105
+ define_method(meth_name) do |val|
106
+ Assimp::aiSetImportPropertyFloat(self, prop, val)
107
+ val
108
+ end
109
+ elsif type == :matrix4x4
110
+ define_method(meth_name) do |mat|
111
+ Assimp::aiSetImportPropertyMatrix(self, prop, mat)
112
+ mat
113
+ end
114
+ elsif type == :string
115
+ define_method(meth_name) do |str|
116
+ s = String::new
117
+ s.data = str
118
+ Assimp::aiSetImportPropertyString(self, prop, s)
119
+ str
120
+ end
121
+ elsif type == :string_array
122
+ define_method(meth_name) do |args|
123
+ str = args.collect { |a| a =~ /\s/ ? "\'"+a+"\'" : a }.join(" ")
124
+ s = String::new
125
+ s.data = str
126
+ Assimp::aiSetImportPropertyString(self, prop, s)
127
+ args
128
+ end
129
+ end
130
+ }
131
+ end
132
+
133
+ config_setter [:glob_measure_time, :bool],
134
+ [:import_no_skeleton_meshes, :bool],
135
+ [:pp_sbbc_max_bones, :int],
136
+ [:pp_ct_max_smoothing_angle, :float],
137
+ [:pp_ct_texture_channel_index, :int],
138
+ [:pp_gsn_max_smoothing_angle, :float],
139
+ [:import_mdl_colormap, :string],
140
+ [:pp_rrm_exclude_list, :string_array],
141
+ [:pp_ptv_keep_hierarchy, :bool],
142
+ [:pp_ptv_normalize, :bool],
143
+ [:pp_ptv_add_root_transformation, :bool],
144
+ [:pp_ptv_root_transformation, :matrix4x4],
145
+ [:pp_fd_remove, :bool],
146
+ [:pp_fd_checkarea, :bool],
147
+ [:pp_og_exclude_list, :string_array],
148
+ [:pp_slm_triangle_limit, :int],
149
+ [:pp_slm_vertex_limit, :int],
150
+ [:pp_lbw_max_weights, :int],
151
+ [:pp_db_threshold, :float],
152
+ [:pp_db_all_or_none, :bool],
153
+ [:pp_icl_ptcache_size, :int]
154
+
155
+ end
156
+
157
+ attach_function :aiCreatePropertyStore, [], :pointer
158
+ attach_function :aiReleasePropertyStore, [:pointer], :void
159
+ attach_function :aiSetImportPropertyInteger, [PropertyStore.by_ref, :string, :int], :void
160
+ attach_function :aiSetImportPropertyFloat, [PropertyStore.by_ref, :string, :ai_real], :void
161
+ attach_function :aiSetImportPropertyString, [PropertyStore.by_ref, :string, String.by_ref], :void
162
+ attach_function :aiSetImportPropertyMatrix, [PropertyStore.by_ref, :string, Matrix4x4.by_ref], :void
163
+
164
+ attach_function :aiImportFile, [:string, PostProcessSteps], Scene.by_ref
165
+ attach_function :aiImportFileEx, [:string, PostProcessSteps, FileIO.by_ref], Scene.by_ref
166
+ attach_function :aiImportFileExWithProperties, [:string, PostProcessSteps, FileIO.by_ref, PropertyStore.by_ref], Scene.by_ref
167
+
168
+ def self.import_file(file, flags: 0, fs: nil, props: nil)
169
+ if props
170
+ s = Assimp::aiImportFileExWithProperties(file, flags, fs, props)
171
+ else
172
+ s = Assimp::aiImportFileEx(file, flags, fs)
173
+ end
174
+ raise "Could not load model #{file}: #{Assimp::LogStream::error_string}!" if s.pointer.null?
175
+ s
176
+ end
177
+
178
+ attach_function :aiImportFileFromMemory, [:pointer, :uint, :uint, :string], Scene.by_ref
179
+ attach_function :aiImportFileFromMemoryWithProperties, [:pointer, :uint, :uint, :string, PropertyStore.by_ref], Scene.by_ref
180
+
181
+ def self.import_file_from_memory(buffer, flags: 0, hint: "", props: nil)
182
+ if props
183
+ s = Assimp::aiImportFileFromMemoryWithProperties(buffer, buffer.size, flags, hint, props)
184
+ else
185
+ s = Assimp::aiImportFileFromMemory(buffer, buffer.size, flags, hint)
186
+ end
187
+ raise "Could not load model: #{Assimp::LogStream::error_string}!" if s.pointer.null?
188
+ s
189
+ end
190
+
191
+ attach_function :aiReleaseImport, [Scene.by_ref], :void
192
+ attach_function :aiIsExtensionSupported, [:string], :bool
193
+
194
+ def self.extension_supported?(extension)
195
+ Assimp::aiIsExtensionSupported(extension)
196
+ end
197
+
198
+ attach_function :aiGetExtensionList, [String.by_ref], :void
199
+
200
+ def self.extension_list
201
+ s = String::new
202
+ Assimp::aiGetExtensionList(s)
203
+ s
204
+ end
205
+
206
+ attach_function :aiGetMemoryRequirements, [Scene.by_ref, MemoryInfo.by_ref], :void
207
+
208
+ attach_function :aiCreateQuaternionFromMatrix, [Quaternion.by_ref, Matrix3x3.by_ref], :void
209
+ attach_function :aiDecomposeMatrix, [Matrix4x4.by_ref, Vector3D.by_ref, Quaternion.by_ref, Vector3D.by_ref], :void
210
+ attach_function :aiTransposeMatrix4, [Matrix4x4.by_ref], :void
211
+ attach_function :aiTransposeMatrix3, [Matrix3x3.by_ref], :void
212
+ attach_function :aiTransformVecByMatrix3, [Vector3D.by_ref, Matrix3x3.by_ref], :void
213
+ attach_function :transform_vec_by_matrix4, :aiTransformVecByMatrix4, [Vector3D.by_ref, Matrix4x4.by_ref], :void
214
+ attach_function :aiMultiplyMatrix4, [Matrix4x4.by_ref, Matrix4x4.by_ref], :void
215
+ attach_function :aiMultiplyMatrix3, [Matrix3x3.by_ref, Matrix3x3.by_ref], :void
216
+ attach_function :aiIdentityMatrix4, [Matrix4x4.by_ref], :void
217
+ attach_function :aiIdentityMatrix3, [Matrix3x3.by_ref], :void
218
+ attach_function :aiGetImportFormatCount, [], :size_t
219
+ attach_function :aiGetImportFormatDescription, [:size_t], ImporterDesc.by_ref
220
+
221
+ def self.import_format_descriptions
222
+ count = Assimp::aiGetImportFormatCount
223
+ count.times.collect { |i| aiGetImportFormatDescription(i) }
224
+ end
225
+
226
+ end
@@ -0,0 +1,42 @@
1
+ module Assimp
2
+
3
+ ImporterFlags = bitmask(:importer_flags, [
4
+ :SupportTextFlavour,
5
+ :SupportBinaryFlavour,
6
+ :SupportCompressedFlavour,
7
+ :LimitedSupport,
8
+ :Experimental
9
+ ])
10
+
11
+ class ImporterDesc < FFI::Struct
12
+ extend StructAccessors
13
+ layout :name, :string,
14
+ :author, :string,
15
+ :maintainer, :string,
16
+ :comments, :string,
17
+ :flags, ImporterFlags,
18
+ :min_major, :uint,
19
+ :min_minor, :uint,
20
+ :max_major, :uint,
21
+ :max_minor, :uint,
22
+ :file_extensions, :string
23
+ struct_attr_reader :name,
24
+ :author,
25
+ :maintainer,
26
+ :comments,
27
+ :flags,
28
+ :min_major,
29
+ :min_minor,
30
+ :max_major,
31
+ :max_minor,
32
+ :file_extensions
33
+ def to_s
34
+ name
35
+ end
36
+
37
+ end
38
+
39
+ #Following function is not found in the ubuntu distribution
40
+ #attach_function :aiGetImporterDesc, [:string], ImporterDesc.ptr
41
+
42
+ end
@@ -0,0 +1,49 @@
1
+ module Assimp
2
+
3
+ LightSourceType = enum( :light_source_type, [
4
+ :UNDEFINED,
5
+ :DIRECTIONAL,
6
+ :POINT,
7
+ :SPOT,
8
+ :AMBIENT,
9
+ :AREA
10
+ ])
11
+
12
+ class Light < FFI::Struct
13
+ extend StructAccessors
14
+ layout :name, String,
15
+ :type, LightSourceType,
16
+ :position, Vector3D,
17
+ :direction, Vector3D,
18
+ :up, Vector3D,
19
+ :attenuation_constant, :float,
20
+ :attenuation_linear, :float,
21
+ :attenuation_quadratic, :float,
22
+ :color_diffuse, Color3D,
23
+ :color_dspecular, Color3D,
24
+ :color_ambiant, Color3D,
25
+ :angle_inner_cone, :float,
26
+ :angle_outer_cone, :float,
27
+ :size, Vector2D
28
+ struct_attr_accessor :name,
29
+ :type,
30
+ :position,
31
+ :direction,
32
+ :up,
33
+ :attenuation_constant,
34
+ :attenuation_linear,
35
+ :attenuation_quadratic,
36
+ :color_diffuse,
37
+ :color_dspecular,
38
+ :color_ambiant,
39
+ :angle_inner_cone,
40
+ :angle_outer_cone,
41
+ :size
42
+
43
+ def to_s
44
+ name
45
+ end
46
+
47
+ end
48
+
49
+ end