Class: Assimp::MaterialProperty
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- Assimp::MaterialProperty
show all
- Extended by:
- StructAccessors
- Defined in:
- lib/assimp/material.rb
Constant Summary
collapse
- TEX_PROPERTIES =
[ MATKEY_TEXTURE,
MATKEY_UVWSRC,
MATKEY_TEXOP,
MATKEY_MAPPING,
MATKEY_TEXBLEND,
MATKEY_MAPPINGMODE_U,
MATKEY_MAPPINGMODE_V,
MATKEY_MAPPINGMODE_W,
MATKEY_TEXMAP_AXIS,
MATKEY_UVTRANSFORM,
MATKEY_TEXFLAGS ]
- COLOR_PROPERTIES =
[ MATKEY_COLOR_DIFFUSE,
MATKEY_COLOR_AMBIENT,
MATKEY_COLOR_SPECULAR,
MATKEY_COLOR_EMISSIVE,
MATKEY_COLOR_TRANSPARENT,
MATKEY_COLOR_REFLECTIVE ]
- STRING_PROPERTIES =
[ MATKEY_NAME,
MATKEY_GLOBAL_BACKGROUND_IMAGE,
MATKEY_TEXTURE ]
- BOOL_PROPERTIES =
[ MATKEY_TWOSIDED, MATKEY_ENABLE_WIREFRAME ]
- INTEGER_PROPERTIES =
BOOL_PROPERTIES +
[ MATKEY_UVWSRC,
MATKEY_SHADING_MODEL,
MATKEY_MAPPINGMODE_U,
MATKEY_MAPPINGMODE_V,
MATKEY_MAPPINGMODE_W,
MATKEY_BLEND_FUNC,
MATKEY_TEXFLAGS,
MATKEY_MAPPING,
MATKEY_TEXOP ]
- FLOAT_PROPERTIES =
COLOR_PROPERTIES +
[ MATKEY_UVTRANSFORM,
MATKEY_TEXBLEND,
MATKEY_OPACITY,
MATKEY_SHININESS,
MATKEY_REFLECTIVITY,
MATKEY_REFRACTI,
MATKEY_SHININESS_STRENGTH,
MATKEY_BUMPSCALING,
MATKEY_TEXMAP_AXIS ]
Class Method Summary
collapse
Instance Method Summary
collapse
extended, has_ref?, struct_array_attr_accessor, struct_array_attr_checker, struct_array_attr_reader, struct_array_attr_writer, struct_attr_accessor, struct_attr_reader, struct_attr_writer, struct_ref_array_attr_accessor, struct_ref_array_attr_reader, struct_ref_array_attr_writer
Class Method Details
.property(key, val, semantic: 0, index: 0, type: nil) ⇒ Object
175
176
177
178
|
# File 'lib/assimp/material.rb', line 175
def self.property(key, val, semantic: 0, index: 0, type: nil)
p = MaterialProperty::new
p.set_property(key, val, semantic: semantic, index: index, type: type)
end
|
Instance Method Details
#data=(val) ⇒ Object
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
# File 'lib/assimp/material.rb', line 216
def data=(val)
ptr = nil
case type
when :String
length = val.bytesize
ptr = FFI::MemoryPointer::new(length+4+1)
ptr.write_uint(length)
ptr.put_string(4, val)
when :Integer
if val.kind_of? Array
ptr = FFI::MemoryPointer::new(:int, val.length)
ptr.write_array_of_int(val)
else
i = nil
case key
when *BOOL_PROPERTIES
if val.nil? || val == false || val == 0
i = Assimp::FALSE
else
i = Assimp::TRUE
end
when MATKEY_SHADING_MODEL
i = ShadingMode.to_native(val, nil)
when MATKEY_MAPPINGMODE_U, MATKEY_MAPPINGMODE_V, MATKEY_MAPPINGMODE_W
i = TextureMapMode.to_native(val, nil)
when MATKEY_BLEND_FUNC
i = BlendMode.to_native(val, nil)
when MATKEY_TEXFLAGS
i = TextureFlags.to_native(val, nil)
when MATKEY_MAPPING
i = TextureMapping.to_native(val, nil)
when MATKEY_TEXOP
i = TextureOp.to_native(val, nil)
else
i = val
end
ptr = FFI::MemoryPointer::new(:int)
ptr.write_int(i)
end
when :Float
if val.kind_of? Array
ptr = FFI::MemoryPointer::new(:float, val.length)
ptr.write_array_of_float(val)
elsif val.kind_of? FFI::Struct
ptr = FFI::MemoryPointer::new(val.class.size)
ptr.write_array_of_uint8(val.pointer.read_array_of_uint8(val.class.size))
else
ptr = FFI::MemoryPointer::new(:float)
ptr.write_float(val)
end
when :Double
if val.kind_of? Array
ptr = FFI::MemoryPointer::new(:double, val.length)
ptr.write_array_of_double(val)
elsif val.kind_of? FFI::Struct
ptr = FFI::MemoryPointer::new(val.class.size)
ptr.write_array_of_uint8(val.pointer.read_array_of_uint8(val.class.size))
else
ptr.write_double(val)
end
when :Buffer
if val.kind_of? FFI::Pointer
ptr = FFI::MemoryPointer::new(val.size)
ptr.write_array_of_uint8(val.pointer.read_array_of_uint8(val.size))
else
ptr = FFI::MemoryPointer.from_string(val)
end
else
raise ArgumentError::new("Invalid type: #{type.inspect}!")
end
@data = ptr
self[:data] = ptr
self.data_length = (ptr ? ptr.size : 0)
val
end
|
#set_property(key, val, semantic: 0, index: 0, type: nil) ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'lib/assimp/material.rb', line 180
def set_property(key, val, semantic: 0, index: 0, type: nil)
if type
self.type = type
else
case key
when *STRING_PROPERTIES
self.type = :String
when *INTEGER_PROPERTIES
self.type = :Integer
when *FLOAT_PROPERTIES
if ENV["ASSIMP_DOUBLE_PRECISION"]
self.type = :Double
else
self.type = :Float
end
else
raise ArgumentError::new("Could not determine property type!")
end
end
if semantic == 0 && TEX_PROPERTIES.include?(key)
raise ArgumentError::new("Missing semantic for texture property!")
elsif semantic != 0 && ! TEX_PROPERTIES.include?(key)
raise ArgumentError::new("Semantic given for non texture property!")
else
self.semantic = semantic
end
if index != 0 && ! TEX_PROPERTIES.include?(key)
raise ArgumentError::new("Index given for non texture property!")
else
self.index = index
end
self.key = key
self.data = val
self
end
|
#to_s ⇒ Object
362
363
364
|
# File 'lib/assimp/material.rb', line 362
def to_s
"#{key}: #{data}"
end
|