aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw_color.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw_color.c')
-rw-r--r--src/others/mimesh/libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw_color.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw_color.c b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw_color.c
new file mode 100644
index 0000000..6b76e50
--- /dev/null
+++ b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_ldraw/imp_ldraw_color.c
@@ -0,0 +1,124 @@
1/* $Id$ */
2
3/*
4 libg3d - 3D object loading library
5
6 Copyright (C) 2005-2009 Markus Dahms <mad@automagically.de>
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21*/
22#include <g3d/material.h>
23
24#include "imp_ldraw_types.h"
25
26typedef struct {
27 gint32 id;
28 const gchar *name;
29 G3DFloat r;
30 G3DFloat g;
31 G3DFloat b;
32 G3DFloat a;
33} LDrawColorDef;
34
35static LDrawColorDef ldraw_colors[] = {
36 { 0, "Black", 0.13, 0.13, 0.13, 1.0 },
37 { 1, "Blue", 0.00, 0.20, 0.70, 1.0 },
38 { 2, "Green", 0.00, 0.55, 0.08, 1.0 },
39 { 3, "Teal", 0.00, 0.60, 0.62, 1.0 },
40 { 4, "Red", 0.77, 0.00, 0.15, 1.0 },
41 { 5, "Dark Pink", 0.87, 0.40, 0.58, 1.0 },
42 { 6, "Brown", 0.36, 0.13, 0.00, 1.0 },
43 { 7, "Gray", 0.76, 0.76, 0.76, 1.0 },
44 { 8, "Dark Gray", 0.39, 0.37, 0.32, 1.0 },
45 { 9, "Light Blue", 0.42, 0.67, 0.86, 1.0 },
46 { 10, "Bright Green", 0.42, 0.93, 0.56, 1.0 },
47 { 11, "Cyan", 0.20, 0.65, 0.65, 1.0 },
48 { 12, "Light Red", 1.00, 0.52, 0.48, 1.0 },
49 { 13, "Pink", 0.98, 0.64, 0.78, 1.0 },
50 { 14, "Yellow", 1.00, 0.86, 0.00, 1.0 },
51 { 15, "White", 1.00, 1.00, 1.00, 1.0 },
52
53 { 17, "Light Green", 0.73, 1.00, 0.81, 1.0 },
54 { 18, "Light Yellow", 0.99, 0.91, 0.59, 1.0 },
55 { 20, "Light Violet", 0.84, 0.77, 0.90, 1.0 },
56 { 28, "Dark Tan", 0.77, 0.59, 0.31, 1.0 },
57 { 32, "Trans Gray", 0.39, 0.37, 0.32, 0.9 },
58 { 33, "Trans Blue", 0.00, 0.13, 0.63, 0.9 },
59 { 36, "Trans Red", 0.77, 0.00, 0.15, 0.9 },
60 { 39, "Trans Light Gray", 0.76, 0.76, 0.76, 0.9 }, /* FIXME */
61 { 40, "Trans Gray", 0.39, 0.37, 0.32, 0.9 },
62 { 41, "Trans Light Cyan", 0.68, 0.94, 0.93, 0.95 },
63 { 46, "Trans Yellow", 0.79, 0.69, 0.00, 0.9 },
64 { 47, "Clear (trans white)", 1.00, 1.00, 1.00, 0.9 },
65 { 72, "Dark Stone Gray", 0.39, 0.37, 0.38, 1.0 },
66 { 272, "Dark Blue", 0.00, 0.11, 0.41, 1.0 },
67 { 288, "Dark Green", 0.15, 0.27, 0.17, 1.0 },
68 { 320, "Dark Red", 0.47, 0.00, 0.11, 1.0 },
69 { 334, "Chrome Gold", 0.88, 0.43, 0.07, 1.0 },
70 { 336, "Earth Orange", 0.82, 0.51, 0.02, 1.0 },
71 { 383, "Chrome Silver", 0.88, 0.88, 0.88, 1.0 },
72 { 431, "Light Green", 0.73, 1.00, 0.81, 1.0 },
73 { 463, "Light Red", 1.00, 0.52, 0.48, 1.0 },
74 { 484, "Dark Orange", 0.70, 0.24, 0.00, 1.0 },
75 { 494, "Electric Contact", 0.82, 0.82, 0.82, 1.0 },
76 { 495, "Light Yellow", 0.99, 0.91, 0.59, 1.0 },
77 { 503, "Light Gray", 0.90, 0.89, 0.85, 1.0 },
78
79 { -1, NULL, 0,0,0,0 }
80};
81
82gboolean ldraw_color_init(LDrawLibrary *lib)
83{
84 G3DMaterial *material;
85 gint32 i;
86
87 lib->colordb = g_hash_table_new(g_int_hash, g_int_equal);
88
89 for(i = 0; ldraw_colors[i].id >= 0; i ++) {
90 material = g3d_material_new();
91 material->name = g_strdup(ldraw_colors[i].name);
92 material->r = ldraw_colors[i].r;
93 material->g = ldraw_colors[i].g;
94 material->b = ldraw_colors[i].b;
95 material->a = ldraw_colors[i].a;
96 g_hash_table_insert(lib->colordb, &(ldraw_colors[i].id), material);
97 lib->colorlist = g_slist_append(lib->colorlist, material);
98#if DEBUG > 2
99 g_debug("LDraw: adding color '%s' with id %d",
100 ldraw_colors[i].name, ldraw_colors[i].id);
101#endif
102 }
103 return TRUE;
104}
105
106G3DMaterial *ldraw_color_lookup(LDrawLibrary *lib, guint32 colid)
107{
108 G3DMaterial *material;
109 guint32 fbid = 0;
110
111 /* current color */
112 if(colid == 16)
113 return NULL;
114
115 material = g_hash_table_lookup(lib->colordb, &colid);
116 if(material == NULL) { /* fall back */
117#if DEBUG > 0
118 g_debug("LDraw: failed to lookup color %u", colid);
119#endif
120 material = g_hash_table_lookup(lib->colordb, &fbid);
121 }
122 return material;
123}
124