aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/extantz/Evas_3D_demo.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/extantz/Evas_3D_demo.c646
1 files changed, 51 insertions, 595 deletions
diff --git a/src/extantz/Evas_3D_demo.c b/src/extantz/Evas_3D_demo.c
index 2d3d46e..e9265da 100644
--- a/src/extantz/Evas_3D_demo.c
+++ b/src/extantz/Evas_3D_demo.c
@@ -1,237 +1,6 @@
1#include "extantz.h" 1#include "extantz.h"
2 2
3 3
4static const float cube_vertices[] =
5{
6 /* Front */
7 -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0,
8 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0,
9 -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
10 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0,
11
12 /* Back */
13 1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0,
14 -1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
15 1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
16 -1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0,
17
18 /* Left */
19 -1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
20 -1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0,
21 -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0,
22 -1.0, -1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0,
23
24 /* Right */
25 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
26 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0,
27 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
28 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0,
29
30 /* Top */
31 -1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
32 1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0,
33 -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0,
34 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0,
35
36 /* Bottom */
37 1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0,
38 -1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
39 1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0,
40 -1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0,
41};
42
43static const unsigned short cube_indices[] =
44{
45 /* Front */
46 0, 1, 2, 2, 1, 3,
47
48 /* Back */
49 4, 5, 6, 6, 5, 7,
50
51 /* Left */
52 8, 9, 10, 10, 9, 11,
53
54 /* Right */
55 12, 13, 14, 14, 13, 15,
56
57 /* Top */
58 16, 17, 18, 18, 17, 19,
59
60 /* Bottom */
61 20, 21, 22, 22, 21, 23
62};
63
64static const unsigned int pixels0[] =
65{
66 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
67 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
68 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000,
69 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000,
70};
71
72static const unsigned int pixels1[] =
73{
74 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00,
75 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00,
76 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff,
77 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff,
78};
79
80
81static int vertex_count = 0;
82static vertex *sphere_vertices = NULL;
83
84static int index_count = 0;
85static unsigned short *sphere_indices = NULL;
86
87static inline vec3
88_normalize(const vec3 *v)
89{
90 double l = sqrt(v->x * v->x + v->y * v->y + v->z * v->z);
91 vec3 vec;
92
93 vec.x = v->x / l;
94 vec.y = v->y / l;
95 vec.z = v->z / l;
96
97 return vec;
98}
99
100
101static void
102_sphere_init(int precision)
103{
104 int i, j;
105 unsigned short *index;
106
107 vertex_count = (precision + 1) * (precision + 1);
108 index_count = precision * precision * 6;
109
110 /* Allocate buffer. */
111 sphere_vertices = malloc(sizeof(vertex) * vertex_count);
112 sphere_indices = malloc(sizeof(unsigned short) * index_count);
113
114 for (i = 0; i <= precision; i++)
115 {
116 double lati = (M_PI * (double)i) / (double)precision;
117 double y = cos(lati);
118 double r = fabs(sin(lati));
119
120 for (j = 0; j <= precision; j++)
121 {
122 double longi = (M_PI * 2.0 * j) / precision;
123 vertex *v = &sphere_vertices[i * (precision + 1) + j];
124
125 if (j == 0 || j == precision)
126 v->position.x = 0.0;
127 else
128 v->position.x = r * sin(longi);
129
130 v->position.y = y;
131
132 if (j == 0 || j == precision)
133 v->position.z = r;
134 else
135 v->position.z = r * cos(longi);
136
137 v->normal = v->position;
138
139 if (v->position.x > 0.0)
140 {
141 v->tangent.x = -v->normal.y;
142 v->tangent.y = v->normal.x;
143 v->tangent.z = v->normal.z;
144 }
145 else
146 {
147 v->tangent.x = v->normal.y;
148 v->tangent.y = -v->normal.x;
149 v->tangent.z = v->normal.z;
150 }
151
152 v->color.x = v->position.x;
153 v->color.y = v->position.y;
154 v->color.z = v->position.z;
155 v->color.w = 1.0;
156
157 if (j == precision)
158 v->texcoord.x = 1.0;
159 else if (j == 0)
160 v->texcoord.x = 0.0;
161 else
162 v->texcoord.x = (double)j / (double)precision;
163
164 if (i == precision)
165 v->texcoord.y = 1.0;
166 else if (i == 0)
167 v->texcoord.y = 0.0;
168 else
169 v->texcoord.y = 1.0 - (double)i / (double)precision;
170 }
171 }
172
173 index = &sphere_indices[0];
174
175 for (i = 0; i < precision; i++)
176 {
177 for (j = 0; j < precision; j++)
178 {
179 *index++ = i * (precision + 1) + j;
180 *index++ = i * (precision + 1) + j + 1;
181 *index++ = (i + 1) * (precision + 1) + j;
182
183 *index++ = (i + 1) * (precision + 1) + j;
184 *index++ = i * (precision + 1) + j + 1;
185 *index++ = (i + 1) * (precision + 1) + j + 1;
186 }
187 }
188
189 for (i = 0; i < index_count; i += 3)
190 {
191 vertex *v0 = &sphere_vertices[sphere_indices[i + 0]];
192 vertex *v1 = &sphere_vertices[sphere_indices[i + 1]];
193 vertex *v2 = &sphere_vertices[sphere_indices[i + 2]];
194
195 vec3 e1, e2;
196 float du1, du2, dv1, dv2, f;
197 vec3 tangent;
198
199 e1.x = v1->position.x - v0->position.x;
200 e1.y = v1->position.y - v0->position.y;
201 e1.z = v1->position.z - v0->position.z;
202
203 e2.x = v2->position.x - v0->position.x;
204 e2.y = v2->position.y - v0->position.y;
205 e2.z = v2->position.z - v0->position.z;
206
207 du1 = v1->texcoord.x - v0->texcoord.x;
208 dv1 = v1->texcoord.y - v0->texcoord.y;
209
210 du2 = v2->texcoord.x - v0->texcoord.x;
211 dv2 = v2->texcoord.y - v0->texcoord.y;
212
213 f = 1.0 / (du1 * dv2 - du2 * dv1);
214
215 tangent.x = f * (dv2 * e1.x - dv1 * e2.x);
216 tangent.y = f * (dv2 * e1.y - dv1 * e2.y);
217 tangent.z = f * (dv2 * e1.z - dv1 * e2.z);
218
219 v0->tangent = tangent;
220 }
221
222 for (i = 0; i <= precision; i++)
223 {
224 for (j = 0; j <= precision; j++)
225 {
226 if (j == precision)
227 {
228 vertex *v = &sphere_vertices[i * (precision + 1) + j];
229 v->tangent = sphere_vertices[i * (precision + 1)].tangent;
230 }
231 }
232 }
233}
234
235static void _animateCube(ExtantzStuffs *stuffs) 4static void _animateCube(ExtantzStuffs *stuffs)
236{ 5{
237 static float angle = 0.0f; 6 static float angle = 0.0f;
@@ -240,6 +9,7 @@ static void _animateCube(ExtantzStuffs *stuffs)
240 Evas_3D_Mesh *m; 9 Evas_3D_Mesh *m;
241 10
242 eina_accessor_data_get(stuffs->aMesh, 0, (void **) &m); 11 eina_accessor_data_get(stuffs->aMesh, 0, (void **) &m);
12
243 angle += 0.5; 13 angle += 0.5;
244 if (angle > 360.0) angle -= 360.0f; 14 if (angle > 360.0) angle -= 360.0f;
245 15
@@ -253,388 +23,74 @@ static void _animateCube(ExtantzStuffs *stuffs)
253 ); 23 );
254} 24}
255 25
256Eina_Bool _animate_scene(globals *ourGlobals) 26static void _animateSphere(ExtantzStuffs *stuffs)
257{ 27{
258 static float earthAngle = 0.0f; 28 static float earthAngle = 0.0f;
259 static int sonicFrame = 0;
260 ExtantzStuffs *e;
261 29
262 Scene_Data *scene = ourGlobals->scene;
263
264 EINA_CLIST_FOR_EACH_ENTRY(e, &ourGlobals->stuffs, ExtantzStuffs, node)
265 {
266 if (e->animateStuffs) e->animateStuffs(e);
267 }
268
269 // Animate sonic.
270 sonicFrame += 32;
271 if (sonicFrame > 256 * 50) sonicFrame = 0;
272 eo_do(scene->mesh2_node,
273 evas_3d_node_mesh_frame_set(scene->mesh2, sonicFrame)
274 );
275
276 // Animate earth.
277 earthAngle += 0.3; 30 earthAngle += 0.3;
278 if (earthAngle > 360.0) earthAngle -= 360.0f; 31 if (earthAngle > 360.0) earthAngle -= 360.0f;
279 eo_do(scene->mesh3_node, 32 eo_do(stuffs->mesh_node,
280 evas_3d_node_orientation_angle_axis_set(earthAngle, 0.0, 1.0, 0.0) 33 evas_3d_node_orientation_angle_axis_set(earthAngle, 0.0, 1.0, 0.0)
281 ); 34 );
282
283 return EINA_TRUE;
284} 35}
285 36
286static void _sonic_setup(globals *ourGlobals, Scene_Data *scene) 37static void _animateSonic(ExtantzStuffs *stuffs)
287{ 38{
288 char buf[PATH_MAX]; 39 static int sonicFrame = 0;
289 40 Evas_3D_Mesh *m;
290 // Setup an MD2 mesh.
291 snprintf(buf, sizeof(buf), "%s/sonic.png", prefix_data_get());
292 scene->texture2 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
293 evas_3d_texture_file_set(buf, NULL),
294 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_NEAREST, EVAS_3D_TEXTURE_FILTER_NEAREST),
295 evas_3d_texture_wrap_set(EVAS_3D_WRAP_MODE_REPEAT, EVAS_3D_WRAP_MODE_REPEAT)
296 );
297
298 scene->material2 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas,
299 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture2),
300
301 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
302 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
303 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
304 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
305
306 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01, 1.0),
307 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0, 1.0),
308 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
309 evas_3d_material_shininess_set(50.0)
310 );
311
312 snprintf(buf, sizeof(buf), "%s/sonic.md2", prefix_data_get());
313 scene->mesh2 = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas,
314 evas_3d_mesh_file_set(EVAS_3D_MESH_FILE_TYPE_MD2, buf, NULL),
315 evas_3d_mesh_frame_material_set(0, scene->material2),
316 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG)
317 );
318 41
319 scene->mesh2_node = eo_add_custom(EVAS_3D_NODE_CLASS, ourGlobals->evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH), 42 eina_accessor_data_get(stuffs->aMesh, 0, (void **) &m);
320 eo_key_data_set("Name", "sonic", NULL), 43 sonicFrame += 32;
321 evas_3d_node_position_set(0.0, 0.0, 0.0), 44 if (sonicFrame > 256 * 50) sonicFrame = 0;
322 evas_3d_node_orientation_set(-0.7071067811865475, 0.0, 0.0, 0.7071067811865475), 45 eo_do(stuffs->mesh_node,
323 evas_3d_node_mesh_add(scene->mesh2) 46 evas_3d_node_mesh_frame_set(m, sonicFrame)
324 ); 47 );
325
326 eo_do(scene->root_node, evas_3d_node_member_add(scene->mesh2_node));
327} 48}
328 49
329static void _earth_setup(globals *ourGlobals, Scene_Data *scene) 50void Evas_3D_Demo_add(globals *ourGlobals)
330{ 51{
331 char buf[PATH_MAX]; 52 char buf[PATH_MAX];
53 ExtantzStuffs *eStuffs;
332 54
333 // Setup earth material. 55 ourGlobals->scene = scenriAdd(ourGlobals->win);
334 snprintf(buf, sizeof(buf), "%s/EarthDiffuse.png", prefix_data_get());
335 scene->texture_diffuse = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
336 evas_3d_texture_file_set(buf, NULL),
337 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_LINEAR, EVAS_3D_TEXTURE_FILTER_LINEAR)
338 );
339
340 scene->material3 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas,
341 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture_diffuse),
342
343 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
344 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
345 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
346 56
347 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01, 1.0), 57 // TODO - For now lets just pretend we got stuffs sent from our love.
348 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0, 1.0), 58 sprintf(buf, FAKE_UUID);
349 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0), 59 eStuffs = addStuffs(buf, "onefang's test bed",
350 evas_3d_material_shininess_set(50.0) 60 "Just a pretend bed with MLP scripts for testing SledjHamr.",
61 "12345678-1234-4321-abcd-0123456789ab",
62 "onefang%%27s%%20test%%20bed.omg",
63 MT_CUBE,
64 0.0, 4.0, 10.0,
65 1.0, 0.0, 0.0, 0.0
351 ); 66 );
352 67 addMaterial(eStuffs, -1, TT_NORMAL, "normal_lego.png");
353 // Setup earth mesh. 68 eStuffs->animateStuffs = (aniStuffs) _animateCube;
354 _sphere_init(100); 69 stuffsSetup(eStuffs, ourGlobals, ourGlobals->scene, 1);
355 70
356 scene->mesh3 = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas, 71 sprintf(buf, FAKE_UUID);
357 evas_3d_mesh_vertex_count_set(vertex_count), 72 eStuffs = addStuffs(buf, "onefang's left testicle",
358 evas_3d_mesh_frame_add(0), 73 "Just a pretend world for testing SledjHamr.",
359 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, sizeof(vertex), &sphere_vertices[0].position), 74 "12345678-1234-4321-abcd-0123456789ab",
360 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, sizeof(vertex), &sphere_vertices[0].normal), 75 "earth.omg",
361 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TANGENT, sizeof(vertex), &sphere_vertices[0].tangent), 76 MT_SPHERE,
362 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, sizeof(vertex), &sphere_vertices[0].color), 77 0.0, 0.0, 0.0,
363 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, sizeof(vertex), &sphere_vertices[0].texcoord), 78 1.0, 0.0, 0.0, 0.0
364
365 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, index_count, &sphere_indices[0]),
366 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
367 evas_3d_mesh_frame_material_set(0, scene->material3),
368
369 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_DIFFUSE)
370 ); 79 );
371 80 addMaterial(eStuffs, 1, TT_FACE, "EarthDiffuse.png");
372 scene->mesh3_node = eo_add_custom(EVAS_3D_NODE_CLASS, ourGlobals->evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH), 81 eStuffs->animateStuffs = (aniStuffs) _animateSphere;
373 eo_key_data_set("Name", "earth", NULL), 82 stuffsSetup(eStuffs, ourGlobals, ourGlobals->scene, 2);
374 evas_3d_node_position_set(0.0, 0.0, 0.0), 83
375 evas_3d_node_mesh_add(scene->mesh3) 84 sprintf(buf, FAKE_UUID);
85 eStuffs = addStuffs(buf, "Sonic the bed hog.",
86 "Just a pretend avatar for testing SledjHamr.",
87 "12345678-1234-4321-abcd-0123456789ab",
88 "sonic.md2",
89 MT_MESH,
90 0.0, 0.0, 0.0,
91 -0.7071067811865475, 0.0, 0.0, 0.7071067811865475
376 ); 92 );
377 93 addMaterial(eStuffs, -1, TT_FACE, "sonic.png");
378 eo_do(scene->root_node, evas_3d_node_member_add(scene->mesh3_node)); 94 eStuffs->animateStuffs = (aniStuffs) _animateSonic;
379} 95 stuffsSetup(eStuffs, ourGlobals, ourGlobals->scene, 3);
380
381/* For now lets just pretend we got stuffs sent from our love.
382
383Stuffs =
384{
385 name = "Test sim",
386 description = 'onefangs test SledjHamr sim.',
387-- owner = '12345678-1234-4321-abcd-0123456789ab',
388 details =
389 {
390 stuffs =
391 {
392 Mesh =
393 {
394 fileName = 'onefang%27s%20test%20bed.omg',
395 pos = {0.0, 4.0, 10.0},
396 size = {1.0, 1.0, 1.0},
397 rot = {1.0, 0.0, 0.0, 0.0},
398 },
399 Mesh =
400 {
401 fileName = 'sonic.omg',
402 pos = {0.0, 0.0, 0.0},
403 size = {1.0, 1.0, 1.0},
404 rot = {-0.7071067811865475, 0.0, 0.0, 0.7071067811865475},
405 },
406 Mesh =
407 {
408 fileName = 'earth.omg',
409 pos = {0.0, 0.0, 0.0},
410 size = {1.0, 1.0, 1.0},
411 rot = {1.0, 0.0, 0.0, 0.0},
412 },
413 },
414 },
415}
416
417
418Stuffs =
419{
420 name = "onefang's test bed",
421 description = 'Just a pretend bed with MLP scripts for testing SledjHamr.',
422-- owner = '12345678-1234-4321-abcd-0123456789ab',
423 details =
424 {
425 Mesh =
426 {
427 kind = 'cube',
428 materials = {'normal_lego.png'},
429 },
430 },
431}
432
433
434Stuffs =
435{
436 name = "onefang's left testicle",
437 description = 'Just a pretend world for testing SledjHamr.',
438-- owner = '12345678-1234-4321-abcd-0123456789ab',
439 details =
440 {
441 Mesh =
442 {
443 kind = 'sphere',
444-- insert prim parameters here
445 materials = {'EarthDiffuse.png'},
446 },
447 },
448}
449
450
451Stuffs =
452{
453 name = "Sonic the bed hog.",
454 description = 'Just a pretend avatar for testing SledjHamr.',
455-- owner = '12345678-1234-4321-abcd-0123456789ab',
456 details =
457 {
458 Mesh =
459 {
460 fileName = 'sonic.md2',
461 materials = {'sonic.png'},
462 },
463 },
464}
465
466*/
467
468void stuffs_setup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene, int fake)
469{
470 char buf[PATH_MAX];
471 Material *m;
472 Evas_3D_Texture *t, *t1, *ti;
473 Evas_3D_Material *mi, *mj;
474 Evas_3D_Mesh *me;
475
476 // TODO - using Eina arrays of any sort seems a bit heavy, might be better to just count and realloc?
477 stuffs->materials = eina_array_new(3);
478 stuffs->mesh = eina_array_new(3);
479 stuffs->textures = eina_array_new(3);
480 stuffs->aMaterial = eina_array_accessor_new(stuffs->materials);
481 stuffs->aMesh = eina_array_accessor_new(stuffs->mesh);
482 stuffs->aTexture = eina_array_accessor_new(stuffs->textures);
483
484// TODO - These examples just don't fit neatly into anything I can whip up quickly as a data format.
485// So just fake it for now, and expand the data format later.
486
487 // Textures
488 if (1 == fake)
489 {
490 t = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
491 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels0[0])
492 );
493 eina_array_push(stuffs->textures, t);
494
495 t1 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
496 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels1[0])
497 );
498 eina_array_push(stuffs->textures, t1);
499 }
500 else if (2 == fake)
501 {
502 }
503 else if (3 == fake)
504 {
505 }
506
507 EINA_INARRAY_FOREACH(stuffs->stuffs.details.mesh->materials, m)
508 {
509 snprintf(buf, sizeof(buf), "%s/%s", prefix_data_get(), m->texture);
510 ti = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas, evas_3d_texture_file_set(buf, NULL));
511 eina_array_push(stuffs->textures, ti);
512 }
513
514 // Materials.
515 if (1 == fake)
516 {
517 eina_accessor_data_get(stuffs->aTexture, 0, (void **) &t);
518 mi = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas,
519 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
520 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
521 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
522 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
523
524 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
525 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
526 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
527 evas_3d_material_shininess_set(100.0),
528 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t)
529 );
530 eina_array_push(stuffs->materials, mi);
531
532 eina_accessor_data_get(stuffs->aTexture, 1, (void **) &t1);
533 eina_accessor_data_get(stuffs->aTexture, 2, (void **) &ti);
534 mj = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas,
535 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
536 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
537 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
538 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
539
540 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
541 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
542 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
543 evas_3d_material_shininess_set(100.0),
544
545 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t1),
546 evas_3d_material_texture_set(EVAS_3D_MATERIAL_NORMAL, ti)
547 );
548 eina_array_push(stuffs->materials, mj);
549 }
550 else if (2 == fake)
551 {
552 }
553 else if (3 == fake)
554 {
555 }
556
557 // Meshes
558 // TODO - Write real generic cube and sphere stuff later.
559 if (MT_CUBE == stuffs->stuffs.details.mesh->type)
560 {
561 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi);
562 eina_accessor_data_get(stuffs->aMaterial, 1, (void **) &mj);
563 me = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas,
564 evas_3d_mesh_vertex_count_set(24),
565 evas_3d_mesh_frame_add(0),
566
567 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, 12 * sizeof(float), &cube_vertices[ 0]),
568 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, 12 * sizeof(float), &cube_vertices[ 3]),
569 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, 12 * sizeof(float), &cube_vertices[ 6]),
570 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, 12 * sizeof(float), &cube_vertices[10]),
571
572 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, 36, &cube_indices[0]),
573 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
574
575 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_NORMAL_MAP),
576
577 evas_3d_mesh_frame_material_set(0, mi),
578
579 evas_3d_mesh_frame_add(20),
580 evas_3d_mesh_frame_material_set(20, mj)
581 );
582 eina_array_push(stuffs->mesh, me);
583 stuffs->animateStuffs = (aniStuffs) _animateCube;
584 }
585 else if (MT_CUBE == stuffs->stuffs.details.mesh->type)
586 {
587 }
588 else
589 {
590 }
591
592 eina_accessor_data_get(stuffs->aMesh, 0, (void **) &me);
593 stuffs->mesh_node = eo_add_custom(EVAS_3D_NODE_CLASS, ourGlobals->evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH),
594 eo_key_data_set("Name", stuffs->stuffs.name, NULL),
595 evas_3d_node_position_set(stuffs->stuffs.details.mesh->pos.x, stuffs->stuffs.details.mesh->pos.y, stuffs->stuffs.details.mesh->pos.z),
596 evas_3d_node_mesh_add(me)
597 );
598
599 eo_do(scene->root_node, evas_3d_node_member_add(stuffs->mesh_node));
600 eina_clist_add_head(&(ourGlobals->stuffs), &(stuffs->node));
601}
602
603Material bedMat;
604Mesh bedMesh;
605ExtantzStuffs eStuffs;
606
607void Evas_3D_Demo_add(globals *ourGlobals)
608{
609
610 bedMat.face = -1; // face -1 means "all of them I think".
611 bedMat.type = TT_NORMAL;
612 sprintf(bedMat.texture, "normal_lego.png");
613
614 sprintf(bedMesh.fileName, "onefang%%27s%%20test%%20bed.omg");
615 bedMesh.type = MT_CUBE;
616 bedMesh.pos.x = 0.0; bedMesh.pos.y = 4.0; bedMesh.pos.z = 10.0;
617 bedMesh.rot.x = 1.0; bedMesh.rot.y = 0.0; bedMesh.rot.z = 0.0; bedMesh.rot.w = 0.0;
618 bedMesh.materials = eina_inarray_new(sizeof(Material), 1);
619 bedMesh.materials = eina_inarray_new(sizeof(Mesh), 1);
620 eina_inarray_push(bedMesh.materials, &bedMat);
621
622 sprintf(eStuffs.stuffs.UUID, FAKE_UUID);
623 sprintf(eStuffs.stuffs.name, "onefang's test bed");
624 sprintf(eStuffs.stuffs.description, "Just a pretend bed with MLP scripts for testing SledjHamr.");
625 sprintf(eStuffs.stuffs.owner, "12345678-1234-4321-abcd-0123456789ab");
626 eStuffs.stuffs.details.mesh = &bedMesh;
627
628 ourGlobals->scene = scenriAdd(ourGlobals->win);
629
630 stuffs_setup(&eStuffs, ourGlobals, ourGlobals->scene, 1);
631
632 _sonic_setup(ourGlobals, ourGlobals->scene);
633 _earth_setup(ourGlobals, ourGlobals->scene);
634}
635
636void Evas_3D_Demo_fini(globals *ourGlobals)
637{
638 free(sphere_vertices);
639 free(sphere_indices);
640} 96}