commit d5420267859cf3bc068a1aa3bd81ebb5c928fab4
parent 643cce0303a66032db626cfb6c69c0a67aff6c30
Author: vaplv <vaplv@free.fr>
Date: Sun, 6 Jul 2014 17:03:39 +0200
Parse the Ni and illum mtl directives
Diffstat:
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/src/aw_mtl.c b/src/aw_mtl.c
@@ -30,6 +30,8 @@ struct material {
struct color specular;
struct color transmission;
float specular_exp;
+ float refraction_id;
+ size_t illumination; /* Illumination model identifier */
};
static FINLINE void
@@ -51,6 +53,12 @@ material_copy(struct material* dst, const struct material* src)
{
ASSERT(dst && src);
color_copy(&dst->ambient, &src->ambient);
+ color_copy(&dst->diffuse, &src->diffuse);
+ color_copy(&dst->specular, &src->specular);
+ color_copy(&dst->transmission, &src->transmission);
+ dst->specular_exp = src->specular_exp;
+ dst->refraction_id = src->refraction_id;
+ dst->illumination = src->illumination;
return str_copy(&dst->name, &src->name);
}
@@ -59,6 +67,12 @@ material_copy_and_release(struct material* dst, struct material* src)
{
ASSERT(dst && src);
color_copy(&dst->ambient, &src->ambient);
+ color_copy(&dst->diffuse, &src->diffuse);
+ color_copy(&dst->specular, &src->specular);
+ color_copy(&dst->transmission, &src->transmission);
+ dst->specular_exp = src->specular_exp;
+ dst->refraction_id = src->refraction_id;
+ dst->illumination = src->illumination;
return str_copy_and_release(&dst->name, &src->name);
}
@@ -160,6 +174,22 @@ parse_float
return AW_OK;
}
+static INLINE enum aw_result
+parse_size_t
+ (size_t* s, const size_t range_min, const size_t range_max, char** word_tk)
+{
+ char* word;
+ enum aw_result res = AW_OK;
+ ASSERT(s && word_tk && range_min < range_max);
+
+ word = strtok_r(NULL, "\n", word_tk);
+ if(AW_OK != (res = string_to_size_t(word, s)))
+ return res;
+ if(range_min > *s || range_max < *s)
+ return AW_BAD_ARGUMENT;
+ return AW_OK;
+}
+
static enum aw_result
parse_mtl_file(struct aw_mtl* mtl, const char* path, char* content)
{
@@ -187,10 +217,11 @@ parse_mtl_file(struct aw_mtl* mtl, const char* path, char* content)
} 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);
+ res = parse_float(&mtl->newmtl->specular_exp, 0.f, FLT_MAX, &word_tk);
} else if(!strcmp(word, "Ni")) { /* Refraction index */
+ res = parse_float(&mtl->newmtl->refraction_id, 0.001f, 10.f, &word_tk);
} else if(!strcmp(word, "illum")) { /* Illumination model */
+ res = parse_size_t(&mtl->newmtl->illumination, 0, 10, &word_tk);
} else if(!strcmp(word, "d")) { /* Dissolve factor */
} else if(!strcmp(word, "sharpness")) { /* Reflection sharpness */
} else if(!strcmp(word, "map_Ka")) { /* Ambient texture */