commit 643cce0303a66032db626cfb6c69c0a67aff6c30
parent a4fde9c937876a4cd828173cacec08ac684901d7
Author: vaplv <vaplv@free.fr>
Date: Sun, 6 Jul 2014 16:45:52 +0200
Parse the Tf and Ns mtl directives
Diffstat:
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/aw_c.h b/src/aw_c.h
@@ -30,8 +30,8 @@ string_to_size_t(const char* str, size_t* i)
}
/* Read `filename' and store its content in `file'. `file' is internally
- * allocated by the provided allocator and consequentle the callee should
- * deallocate it by using the same allocator */
+ * allocated by the provided allocator and consequently the callee should
+ * deallocate it with the same allocator */
extern LOCAL_SYM enum aw_result
read_file
(struct mem_allocator* allocator,
diff --git a/src/aw_mtl.c b/src/aw_mtl.c
@@ -8,6 +8,8 @@
#include <rsys/ref_count.h>
#include <rsys/str.h>
+#include <float.h>
+
struct color {
float value[3];
char is_CIEXYZ;
@@ -26,6 +28,8 @@ struct material {
struct color ambient;
struct color diffuse;
struct color specular;
+ struct color transmission;
+ float specular_exp;
};
static FINLINE void
@@ -140,6 +144,22 @@ parse_color(struct color* col, char** word_tk)
return AW_OK;
}
+static INLINE enum aw_result
+parse_float
+ (float* f, const float range_min, const float range_max, char** word_tk)
+{
+ char* word;
+ enum aw_result res = AW_OK;
+ ASSERT(f && word_tk && range_min < range_max);
+
+ word = strtok_r(NULL, "\n", word_tk);
+ if(AW_OK != (res = string_to_float(word, f)))
+ return res;
+ if(range_min > *f || range_max < *f)
+ return AW_BAD_ARGUMENT;
+ return AW_OK;
+}
+
static enum aw_result
parse_mtl_file(struct aw_mtl* mtl, const char* path, char* content)
{
@@ -165,7 +185,10 @@ parse_mtl_file(struct aw_mtl* mtl, const char* path, char* content)
} else if(!strcmp(word, "Ks")) { /* Specular reflectivity */
res = parse_color(&mtl->newmtl->specular, &word_tk);
} else if(!strcmp(word, "Tf")) { /* Transimission filter */
+ res = parse_color(&mtl->newmtl->transmission, &word_tk);
} else if(!strcmp(word, "Ns")) { /* Specular exponent */
+ res = parse_float
+ (&mtl->newmtl->specular_exp, -FLT_MAX, FLT_MAX, &word_tk);
} else if(!strcmp(word, "Ni")) { /* Refraction index */
} else if(!strcmp(word, "illum")) { /* Illumination model */
} else if(!strcmp(word, "d")) { /* Dissolve factor */