assimp-ffi 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c2f350f15b0e5131cd2404dadc2a26aad6d818abf3eab0fb7766e47e99eef6cd
4
+ data.tar.gz: d28e89aefa90d07b6a0e04812d0590b7fd117ac5b3cc933920d549e0813b521c
5
+ SHA512:
6
+ metadata.gz: f13d6c65bc8a7074c0e9b1b471d2667707ab14f20890bfb951e703bb77f2d17e4c765252884ff0ac2c226e72680bd47273d7715f1f13de2fe33f5a7b8b5c379c
7
+ data.tar.gz: 61796c36f6d41e14e116a1e3c5d831e2534175298ab7af5eeead0bf31dfb619253f154a62d0b14bb1403dd8aa3ba1f293a04079448a50e7f5d6371eaf4e23fd9
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2019, Brice Videau
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # assimp-ruby
2
+ Open Asset Import Library ruby bindings
data/assimp.gemspec ADDED
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'assimp-ffi'
3
+ s.version = "0.1.0"
4
+ s.author = "Brice Videau"
5
+ s.email = "brice.videau@imag.fr"
6
+ s.homepage = "https://github.com/Kerilk/assimp-ruby"
7
+ s.summary = "Open Asset Import Library bindings"
8
+ s.description = "FFI bindings of Assimp (Open Asset Import Library bindings) for version 4.1.0 onward"
9
+ s.files = Dir['assimp.gemspec', 'LICENSE', 'README.md', 'lib/**/*']
10
+ s.has_rdoc = false
11
+ s.license = 'BSD-2-Clause'
12
+ s.required_ruby_version = '>= 2.1.0'
13
+ s.add_dependency 'ffi', '~> 1.9', '>=1.9.19'
14
+ end
@@ -0,0 +1,131 @@
1
+ module Assimp
2
+
3
+ class VectorKey < FFI::Struct
4
+ extend StructAccessors
5
+ layout :time, :double,
6
+ :value, Vector3D
7
+ struct_attr_accessor :time,
8
+ :value
9
+ end
10
+
11
+ class QuatKey < FFI::Struct
12
+ extend StructAccessors
13
+ layout :time, :double,
14
+ :value, Quaternion
15
+ struct_attr_accessor :time,
16
+ :value
17
+ end
18
+
19
+ class MeshKey < FFI::Struct
20
+ extend StructAccessors
21
+ layout :time, :double,
22
+ :value, :uint
23
+ struct_attr_accessor :time,
24
+ :value
25
+ end
26
+
27
+ class MeshMorphKey < FFI::Struct
28
+ extend StructAccessors
29
+ layout :time, :double,
30
+ :values, :pointer, #uint[num_values_and_weights]
31
+ :weights, :pointer, #double[num_values_and_weights]
32
+ :num_values_and_weights, :uint
33
+ struct_attr_accessor :time,
34
+ :num_values_and_weights
35
+ struct_array_attr_accessor [:values, :uint, :num_values_and_weights],
36
+ [:weights, :double, :num_values_and_weights]
37
+ end
38
+
39
+ AnimBehaviour = enum(:anim_behavior, [
40
+ :DEFAULT,
41
+ :CONSTANT,
42
+ :LINEAR,
43
+ :REPEAT
44
+ ])
45
+
46
+ class NodeAnim < FFI::Struct
47
+ extend StructAccessors
48
+ layout :node_name, String,
49
+ :num_position_keys, :uint,
50
+ :position_keys, :pointer, #VectorKey
51
+ :num_rotation_keys, :uint,
52
+ :rotation_keys, :pointer, #QuatKey
53
+ :num_scaling_keys, :uint,
54
+ :scaling_keys, :pointer, #VectorKey
55
+ :pre_state, AnimBehaviour,
56
+ :post_state, AnimBehaviour
57
+ struct_attr_accessor :node_name,
58
+ :num_position_keys,
59
+ :num_rotation_keys,
60
+ :num_scaling_keys,
61
+ :pre_state,
62
+ :post_state
63
+
64
+ struct_array_attr_accessor [:position_keys, VectorKey],
65
+ [:rotation_keys, QuatKey],
66
+ [:scaling_keys, VectorKey]
67
+
68
+ def to_s
69
+ node_name
70
+ end
71
+
72
+ end
73
+
74
+ class MeshAnim < FFI::Struct
75
+ extend StructAccessors
76
+ layout :name, String,
77
+ :num_keys, :uint,
78
+ :keys, :pointer #MeshKey
79
+ struct_attr_accessor :name,
80
+ :num_keys
81
+ struct_array_attr_accessor [:keys, MeshKey]
82
+
83
+ def to_s
84
+ name
85
+ end
86
+
87
+ end
88
+
89
+ class MeshMorphAnim < FFI::Struct
90
+ extend StructAccessors
91
+ layout :name, String,
92
+ :num_keys, :uint,
93
+ :keys, :pointer #MeshMorphKey
94
+ struct_attr_accessor :name,
95
+ :num_keys
96
+ struct_array_attr_accessor [:keys, MeshMorphKey]
97
+
98
+ def to_s
99
+ name
100
+ end
101
+
102
+ end
103
+
104
+ class Animation < FFI::Struct
105
+ extend StructAccessors
106
+ layout :name, String,
107
+ :duration, :double,
108
+ :ticks_per_second, :double,
109
+ :num_channels, :uint,
110
+ :channels, :pointer, #NodeAnim*
111
+ :num_mesh_channels, :uint,
112
+ :mesh_channels, :pointer, #MeshAnim*
113
+ :num_morph_mesh_channels, :uint,
114
+ :morph_mesh_channels, :pointer #MeshMorphAnim*
115
+ struct_attr_accessor :name,
116
+ :duration,
117
+ :ticks_per_second,
118
+ :num_channels,
119
+ :num_mesh_channels,
120
+ :num_morph_mesh_channels
121
+ struct_ref_array_attr_accessor [:channels, NodeAnim],
122
+ [:mesh_channels, MeshAnim],
123
+ [:morph_mesh_channels, MeshMorphAnim]
124
+
125
+ def to_s
126
+ name
127
+ end
128
+
129
+ end
130
+
131
+ end
@@ -0,0 +1,197 @@
1
+ module Assimp
2
+ extend FFI::Library
3
+ ffi_lib 'assimp'
4
+
5
+ class String < FFI::Struct
6
+ end
7
+
8
+ module StructAccessors
9
+
10
+ def self.extended(mod)
11
+ mod.instance_variable_set(:@__has_ref, false)
12
+ end
13
+
14
+ def has_ref?
15
+ @__has_ref
16
+ end
17
+
18
+ def struct_attr_reader(*args)
19
+ args.each { |attr|
20
+ raise "Invalid attribute #{attr.inspect}!" unless @layout.members.include?(attr)
21
+ if @layout[attr].type.kind_of?( FFI::StructByValue ) && @layout[attr].type.struct_class == Assimp::String
22
+ define_method(attr) { self[attr].data }
23
+ else
24
+ define_method(attr) { self[attr] }
25
+ end
26
+ }
27
+ end
28
+
29
+ def struct_attr_writer(*args)
30
+ args.each { |attr|
31
+ raise "Invalid attribute #{attr.inspect}!" unless @layout.members.include?(attr)
32
+ if @layout[attr].type.kind_of?( FFI::StructByValue ) && @layout[attr].type.struct_class == Assimp::String
33
+ define_method(attr.to_s+"=") { |o| self[attr].data = o }
34
+ elsif @layout[attr].type.kind_of?( FFI::StructByValue ) && @layout[attr].type.struct_class.has_ref?
35
+ @__has_ref = true
36
+ define_method(attr.to_s+"=") { |o| self.instance_variable_set(:"@#{attr}", o); self[attr] = o }
37
+ else
38
+ define_method(attr.to_s+"=") { |o| self[attr] = o }
39
+ end
40
+ }
41
+ end
42
+
43
+ def struct_attr_accessor(*args)
44
+ struct_attr_reader(*args)
45
+ struct_attr_writer(*args)
46
+ end
47
+
48
+ def struct_array_attr_reader(*args)
49
+ args.each { |attr, klass, count|
50
+ raise "Invalid attribute #{attr.inspect}!" unless @layout.members.include?(attr)
51
+ t = nil
52
+ s = nil
53
+ if klass.kind_of? Symbol
54
+ t = Assimp::find_type(klass)
55
+ s = t.size
56
+ define_method(attr) do
57
+ n = ( count ? self[count] : self[:"num_#{attr}"] )
58
+ p = self[attr]
59
+ if n == 0 || p.null?
60
+ []
61
+ else
62
+ n.times.collect { |i|
63
+ p.get(t, i*s)
64
+ }
65
+ end
66
+ end
67
+ elsif klass.kind_of?(Class) && klass < FFI::Struct
68
+ s = klass.size
69
+ define_method(attr) do
70
+ n = ( count ? self[count] : self[:"num_#{attr}"] )
71
+ p = self[attr]
72
+ if n == 0 || p.null?
73
+ []
74
+ else
75
+ n.times.collect { |i|
76
+ klass.new(p+i*s)
77
+ }
78
+ end
79
+ end
80
+ else
81
+ raise "Invalid type: #{klass.inspect} for #{attr.inspect}!"
82
+ end
83
+ }
84
+ end
85
+
86
+ def struct_array_attr_writer(*args)
87
+ args.each { |attr, klass, count|
88
+ raise "Invalid attribute #{attr.inspect}!" unless @layout.members.include?(attr)
89
+ @__has_ref = true
90
+ t = nil
91
+ s = nil
92
+ if klass.kind_of? Symbol
93
+ t = Assimp::find_type(klass)
94
+ s = t.size
95
+ define_method(:"#{attr}=") do |values|
96
+ values = [] if values.nil?
97
+ if count
98
+ self[count] = values.length
99
+ else
100
+ self[:"num_#{attr}"] = values.length
101
+ end
102
+ ptr = (values.length == 0 ? nil : FFI::MemoryPointer::new(t, values.length))
103
+ values.each_with_index { |v, i|
104
+ ptr.put(t, i*s, v)
105
+ }
106
+ self.instance_variable_set(:"@#{attr}", ptr)
107
+ self[attr] = ptr
108
+ values
109
+ end
110
+ elsif klass.kind_of?(Class) && klass < FFI::Struct
111
+ s = klass.size
112
+ k = klass
113
+ define_method(:"#{attr}=") do |values|
114
+ values = [] if values.nil?
115
+ if count
116
+ self[count] = values.length
117
+ else
118
+ self[:"num_#{attr}"] = values.length
119
+ end
120
+ ptr = (values.length == 0 ? nil : FFI::MemoryPointer::new(klass, values.length))
121
+ values.each_with_index { |v, i|
122
+ ptr.put_array_of_uint8(i*s, v.pointer.read_array_of_uint8(s))
123
+ }
124
+ if k.has_ref?
125
+ self.instance_variable_set(:"@#{attr}", [ptr, values])
126
+ else
127
+ self.instance_variable_set(:"@#{attr}", ptr)
128
+ end
129
+ self[attr] = ptr
130
+ values
131
+ end
132
+ else
133
+ raise "Invalid type: #{klass.inspect} for #{attr.inspect}!"
134
+ end
135
+ }
136
+ end
137
+
138
+ def struct_array_attr_checker(*args)
139
+ args.each { |attr, klass, count|
140
+ raise "Invalid attribute #{attr.inspect}!" unless @layout.members.include?(attr)
141
+ define_method(:"#{attr}?") do
142
+ ! self[attr].null?
143
+ end
144
+ }
145
+ end
146
+
147
+ def struct_array_attr_accessor(*args)
148
+ struct_array_attr_reader(*args)
149
+ struct_array_attr_writer(*args)
150
+ struct_array_attr_checker(*args)
151
+ end
152
+
153
+ def struct_ref_array_attr_reader(*args)
154
+ args.each { |attr, klass, count|
155
+ raise "Invalid attribute #{attr.inspect}!" unless @layout.members.include?(attr)
156
+ define_method(attr) do
157
+ n = ( count ? self[count] : self[:"num_#{attr}"] )
158
+ p = self[attr]
159
+ if n == 0 || p.null?
160
+ []
161
+ else
162
+ ptrs = p.read_array_of_pointer(self[:"num_#{attr}"])
163
+ ptrs.collect { |ptr| ptr.null? ? nil : klass::new(ptr) }
164
+ end
165
+ end
166
+ }
167
+ end
168
+
169
+ def struct_ref_array_attr_writer(*args)
170
+ args.each { |attr, klass, count|
171
+ raise "Invalid attribute #{attr.inspect}!" unless @layout.members.include?(attr)
172
+ @__has_ref = true
173
+ define_method(:"#{attr}=") do |values|
174
+ values = [] if values.nil?
175
+ if count
176
+ self[count] = values.length
177
+ else
178
+ self[:"num_#{attr}"] = values.length
179
+ end
180
+ ptr = (values.length == 0 ? nil : FFI::MemoryPointer::new(:pointer, values.length))
181
+ ptr.write_array_of_pointer(values.collect(&:pointer)) if ptr
182
+ self.instance_variable_set(:"@#{attr}", [ptr, values.dup])
183
+ self[attr] = ptr
184
+ values
185
+ end
186
+ }
187
+ end
188
+
189
+ def struct_ref_array_attr_accessor(*args)
190
+ struct_ref_array_attr_reader(*args)
191
+ struct_ref_array_attr_writer(*args)
192
+ struct_array_attr_checker(*args)
193
+ end
194
+
195
+ end
196
+
197
+ end
@@ -0,0 +1,25 @@
1
+ module Assimp
2
+
3
+ class Camera < FFI::Struct
4
+ extend StructAccessors
5
+ layout :name, String,
6
+ :position, Vector3D,
7
+ :up, Vector3D,
8
+ :look_at, Vector3D,
9
+ :horizontal_fov, :float,
10
+ :clip_plane_near, :float,
11
+ :aspect, :float
12
+ struct_attr_accessor :name,
13
+ :position,
14
+ :up,
15
+ :look_at,
16
+ :horizontal_fov,
17
+ :clip_plane_near,
18
+ :aspect
19
+ def to_s
20
+ name
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,24 @@
1
+ module Assimp
2
+
3
+ class Color4D < FFI::Struct
4
+ extend StructAccessors
5
+ layout :r, :ai_real,
6
+ :g, :ai_real,
7
+ :b, :ai_real,
8
+ :a, :ai_real
9
+ struct_attr_accessor :r, :g, :b, :a
10
+
11
+ def set(r, g, b, a)
12
+ self.r = r
13
+ self.g = g
14
+ self.b = b
15
+ self.a = a
16
+ self
17
+ end
18
+
19
+ def to_s
20
+ "[#{r}, #{g}, #{b}, #{a}]"
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,34 @@
1
+ module Assimp
2
+
3
+ Components = bitmask(:components, [
4
+ :NORMALS, 1,
5
+ :TANGENTS_AND_BITANGENTS,
6
+ :COLORS,
7
+ :TEXCOORDS,
8
+ :BONEWEIGHTS,
9
+ :ANIMATIONS,
10
+ :TEXTURES,
11
+ :LIGHTS,
12
+ :CAMERAS,
13
+ :MESHES,
14
+ :MATERIALS,
15
+ :COLORS0, 20,
16
+ :COLORS1,
17
+ :COLORS2,
18
+ :COLORS3,
19
+ :COLORS4,
20
+ :TEXCOORDS0, 25,
21
+ :TEXCOORDS1,
22
+ :TEXCOORDS2,
23
+ :TEXCOORDS3,
24
+ :TEXCOORDS4,
25
+ :TEXCOORDS5,
26
+ :TEXCOORDS6,
27
+ ])
28
+
29
+ UVTRAFO_SCALING = 0x1
30
+ UVTRAFO_ROTATION = 0x2
31
+ UVTRAFO_TRANSLATION = 0x4
32
+ UVTRAFO_ALL = UVTRAFO_SCALING | UVTRAFO_ROTATION | UVTRAFO_TRANSLATION
33
+
34
+ end
@@ -0,0 +1,25 @@
1
+ module Assimp
2
+
3
+ if ENV["ASSIMP_DOUBLE_PRECISION"]
4
+ typedef :double, :ai_real
5
+ typedef :long_long, :ai_int
6
+ typedef :ulong_long, :ai_uint
7
+ else
8
+ typedef :float, :ai_real
9
+ typedef :int, :ai_int
10
+ typedef :uint, :ai_uint
11
+ end
12
+
13
+ MATH_PI = 3.141592653589793238462643383279
14
+ MATH_TWO_PI = MATH_PI * 2.0
15
+ MATH_HALF_PI = MATH_PI * 0.5
16
+
17
+ def deg_to_rad(x)
18
+ x * 0.0174532925
19
+ end
20
+
21
+ def rad_to_deg(x)
22
+ x * 57.2957795
23
+ end
24
+
25
+ end
@@ -0,0 +1,58 @@
1
+ module Assimp
2
+
3
+ class ExportFormatDesc < FFI::ManagedStruct
4
+ extend StructAccessors
5
+ layout :id, :string,
6
+ :description, :string,
7
+ :file_extension, :string
8
+ struct_attr_reader :id,
9
+ :description,
10
+ :file_extension
11
+
12
+ def self.release(ptr)
13
+ Assimp::aiReleaseExportFormatDescription(ptr)
14
+ end
15
+
16
+ end
17
+
18
+ attach_function :aiGetExportFormatCount, [], :size_t
19
+ attach_function :aiGetExportFormatDescription, [:size_t], ExportFormatDesc.ptr
20
+ attach_function :aiReleaseExportFormatDescription, [ExportFormatDesc.ptr], :void
21
+
22
+ def self.export_format_descriptions
23
+ count = Assimp::aiGetExportFormatCount
24
+ count.times.collect { |i|
25
+ Assimp::aiGetExportFormatDescription(i)
26
+ }
27
+ end
28
+
29
+ attach_function :aiCopyScene, [Scene.ptr, :pointer], :void
30
+ attach_function :aiFreeScene, [Scene.ptr], :void
31
+ attach_function :aiExportScene, [Scene.ptr, :string, :string, PostProcessSteps], Return
32
+ attach_function :aiExportSceneEx, [Scene.ptr, :string, :string, FileIO.ptr, PostProcessSteps], Return
33
+
34
+ class ExportDataBlob < FFI::Struct
35
+ extend StructAccessors
36
+ layout :size, :size_t,
37
+ :data, :pointer,
38
+ :name, String,
39
+ :next, ExportDataBlob.ptr
40
+ struct_attr_reader :size,
41
+ :data,
42
+ :name,
43
+ :next
44
+
45
+ def to_s
46
+ name
47
+ end
48
+
49
+ def self.releaser(ptr)
50
+ Assimp::aiReleaseExportBlob(ptr)
51
+ end
52
+
53
+ end
54
+
55
+ attach_function :aiExportSceneToBlob, [Scene.ptr, :string, PostProcessSteps], :pointer #ExportDataBlob.ptr
56
+ attach_function :aiReleaseExportBlob, [ExportDataBlob.ptr], :void
57
+
58
+ end
@@ -0,0 +1,48 @@
1
+ module Assimp
2
+
3
+ class FileIO < FFI::Struct
4
+ end
5
+
6
+ class File < FFI::Struct
7
+ end
8
+
9
+ callback :file_write_proc, [File.ptr, :string, :size_t, :size_t], :size_t
10
+ callback :file_read_proc, [File.ptr, :string, :size_t, :size_t], :size_t
11
+ callback :file_tell_proc, [File.ptr], :size_t
12
+ callback :file_flush_proc, [File.ptr], :void
13
+ callback :file_seek, [File.ptr, :size_t, Origin], Return
14
+
15
+ callback :file_open_proc, [FileIO.ptr, :string, :string], File.ptr
16
+ callback :file_close_proc, [FileIO.ptr, File.ptr], :void
17
+
18
+ typedef :pointer, :user_data #byte
19
+
20
+ class FileIO
21
+ extend StructAccessors
22
+ layout :open_proc, :file_open_proc,
23
+ :close_proc, :file_close_proc,
24
+ :user_data, :user_data
25
+ struct_attr_accessor :open_proc,
26
+ :close_proc
27
+ struct_attr_reader :user_data
28
+ end
29
+
30
+ class File
31
+ extend StructAccessors
32
+ layout :read_proc, :file_read_proc,
33
+ :write_proc, :file_write_proc,
34
+ :tell_proc, :file_tell_proc,
35
+ :file_size_proc, :file_tell_proc,
36
+ :seek_proc, :file_seek,
37
+ :flush_proc, :file_flush_proc,
38
+ :user_data, :user_data
39
+ struct_attr_accessor :read_proc,
40
+ :write_proc,
41
+ :tell_proc,
42
+ :file_size_proc,
43
+ :seek_proc,
44
+ :flush_proc
45
+ struct_attr_reader :user_data
46
+ end
47
+
48
+ end