aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_test/imp_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/mimesh/libg3d-0.0.8/plugins/import/imp_test/imp_test.c')
-rw-r--r--src/others/mimesh/libg3d-0.0.8/plugins/import/imp_test/imp_test.c164
1 files changed, 164 insertions, 0 deletions
diff --git a/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_test/imp_test.c b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_test/imp_test.c
new file mode 100644
index 0000000..0b4e062
--- /dev/null
+++ b/src/others/mimesh/libg3d-0.0.8/plugins/import/imp_test/imp_test.c
@@ -0,0 +1,164 @@
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
23#include <g3d/types.h>
24#include <g3d/context.h>
25#include <g3d/material.h>
26#include <g3d/matrix.h>
27#include <g3d/primitive.h>
28#include <g3d/object.h>
29#include <g3d/texture.h>
30
31static gboolean test_primitive_transfrom(G3DModel *model);
32static gboolean test_texture_uv(G3DContext *context, G3DModel *model);
33
34/*****************************************************************************/
35/* plugin interface */
36/*****************************************************************************/
37
38
39EAPI
40gboolean plugin_load_model_from_stream(G3DContext *context, G3DStream *stream,
41 G3DModel *model, gpointer user_data)
42{
43 guint32 test = 1;
44
45 switch(test) {
46 case 0:
47 return test_primitive_transfrom(model);
48 break;
49 case 1:
50 return test_texture_uv(context, model);
51 break;
52 default:
53 break;
54 }
55 return FALSE;
56}
57
58EAPI
59gchar *plugin_description(G3DContext *context)
60{
61 return g_strdup("Test plugin.");
62}
63
64EAPI
65gchar **plugin_extensions(G3DContext *context)
66{
67 return g_strsplit("test", ":", 0);
68}
69
70/****************************************************************************/
71
72static gboolean test_primitive_transfrom(G3DModel *model)
73{
74 G3DObject *sphere, *cntr;
75 G3DMaterial *material;
76 G3DTransformation *tf;
77 G3DFloat matrix[16];
78 /* gint32 i, j; */
79
80 cntr = g_new0(G3DObject, 1);
81 cntr->name = g_strdup("container");
82
83 tf = g_new0(G3DTransformation, 1);
84 g3d_matrix_identity(tf->matrix);
85 g3d_matrix_scale(1.0, 1.0, 2.0, tf->matrix);
86 cntr->transformation = tf;
87 model->objects = g_slist_append(model->objects, cntr);
88
89 material = g3d_material_new();
90 model->materials = g_slist_append(model->materials, material);
91
92 /* 1 */
93 sphere = g3d_primitive_sphere(1.0, 36, 36, material);
94 cntr->objects = g_slist_append(cntr->objects, sphere);
95
96 /* 2 */
97 sphere = g3d_primitive_sphere(1.0, 6, 6, material);
98 cntr->objects = g_slist_append(cntr->objects, sphere);
99
100 tf = g_new0(G3DTransformation, 1);
101 g3d_matrix_identity(tf->matrix);
102 g3d_matrix_translate(2.5, 1.0, 1.0, tf->matrix);
103 sphere->transformation = tf;
104
105 /* 3 */
106 sphere = g3d_primitive_sphere(1.0, 12, 12, material);
107 cntr->objects = g_slist_append(cntr->objects, sphere);
108
109 g3d_matrix_identity(matrix);
110 g3d_matrix_translate(5, 2.0, 2.0, matrix);
111 g3d_matrix_scale(2.0, 2.0, 1.0, matrix);
112 g3d_object_transform(sphere, matrix);
113
114 return TRUE;
115}
116
117static gboolean test_texture_uv(G3DContext *context, G3DModel *model)
118{
119 G3DObject *box;
120 G3DMaterial *material;
121 G3DFace *face;
122 GSList *item;
123
124 material = g3d_material_new();
125 material->r = 1.0;
126 material->g = 0.8;
127 material->b = 0.2;
128 material->a = 0.9;
129 material->name = g_strdup("default texture");
130 material->tex_image = g3d_texture_load_cached(context, model,
131 "test-texture.png");
132
133 box = g3d_primitive_box(1.0, 1.0, 1.0, material);
134 box->name = g_strdup("test box");
135
136 if(material->tex_image != NULL) {
137 material->tex_image->tex_env = G3D_TEXENV_REPLACE;
138
139 for(item = box->faces; item != NULL; item = item->next) {
140 face = (G3DFace *)item->data;
141 face->tex_image = material->tex_image;
142 face->flags |= G3D_FLAG_FAC_TEXMAP;
143
144#define MIN_U 0.0
145#define MAX_U 1.0
146#define MIN_V -0.5
147#define MAX_V 1.5
148
149 face->tex_vertex_data[0 * 2 + 0] = MIN_U;
150 face->tex_vertex_data[0 * 2 + 1] = MIN_V;
151 face->tex_vertex_data[1 * 2 + 0] = MIN_U;
152 face->tex_vertex_data[1 * 2 + 1] = MAX_V;
153 face->tex_vertex_data[2 * 2 + 0] = MAX_U;
154 face->tex_vertex_data[2 * 2 + 1] = MAX_V;
155 face->tex_vertex_data[3 * 2 + 0] = MAX_U;
156 face->tex_vertex_data[3 * 2 + 1] = MIN_V;
157 }
158 }
159
160 model->objects = g_slist_append(model->objects, box);
161 model->materials = g_slist_append(model->materials, material);
162
163 return TRUE;
164}