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
|
# File 'ext/assimp/assimp_importer.c', line 8
static VALUE read_file(VALUE self, VALUE args)
{
char * file_str;
struct aiScene * scene;
unsigned int flags, array_len, i;
long num_args;
VALUE file_name, read_flags;
flags = 0;
num_args = RARRAY_LEN(args);
if(num_args > 2 || num_args < 1)
rb_raise(rb_eArgError, "wrong number of arguments");
file_name = rb_ary_entry(args, 0);
Check_Type(file_name, T_STRING);
if(num_args > 1){
read_flags = rb_ary_entry(args, 1);
Check_Type(read_flags, T_ARRAY);
array_len = RARRAY_LEN(read_flags);
}
file_str = StringValueCStr(file_name);
if(num_args > 1){
for(i = 0; i < array_len; i++){
VALUE element = rb_ary_entry(read_flags, i);
if(TYPE(element)==T_SYMBOL){
ID sym_id = SYM2ID(element);
if(sym_id==rb_intern("triangulate")){
flags |= aiProcess_Triangulate;
}
if(sym_id==rb_intern("calc_tangent_space")){
flags |= aiProcess_CalcTangentSpace;
}
if(sym_id==rb_intern("make_left_handed")){
flags |= aiProcess_MakeLeftHanded;
}
if(sym_id==rb_intern("gen_normals")){
flags |= aiProcess_GenNormals;
}
if(sym_id==rb_intern("gen_smooth_normals")){
flags |= aiProcess_GenSmoothNormals;
}
if(sym_id==rb_intern("join_identical_vertices")){
flags |= aiProcess_JoinIdenticalVertices;
}
if(sym_id==rb_intern("pretransform_vertices")){
flags |= aiProcess_PreTransformVertices;
}
if(sym_id==rb_intern("validate_data_structure")){
flags |= aiProcess_ValidateDataStructure;
}
if(sym_id==rb_intern("improve_cache_locality")){
flags |= aiProcess_ImproveCacheLocality;
}
if(sym_id==rb_intern("fix_infacing_normals")){
flags |= aiProcess_FixInfacingNormals;
}
if(sym_id==rb_intern("sort_by_p_type")){
flags |= aiProcess_SortByPType;
}
}
}
}
scene = aiImportFile(file_str, flags);
VALUE result;
result = Qnil;
if(!scene)
rb_raise(rb_eIOError, aiGetErrorString());
else{
result = get_Hash_from_aiScene(scene);
aiReleaseImport(scene);
return result;
}
}
|