aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-30 02:13:48 +1000
committerDavid Walter Seikel2014-05-30 02:13:48 +1000
commitd2178bf76792650ee598ee45114e1c20d18bb936 (patch)
tree94ade909fe608fdf88f12ca801c791a4f988a866 /src
parentHalf arsed generic stuffs creation. (diff)
downloadSledjHamr-d2178bf76792650ee598ee45114e1c20d18bb936.zip
SledjHamr-d2178bf76792650ee598ee45114e1c20d18bb936.tar.gz
SledjHamr-d2178bf76792650ee598ee45114e1c20d18bb936.tar.bz2
SledjHamr-d2178bf76792650ee598ee45114e1c20d18bb936.tar.xz
Slightly less half arsed stuffs creation.
Diffstat (limited to 'src')
-rw-r--r--src/extantz/Evas_3D_demo.c646
-rw-r--r--src/extantz/extantz.c2
-rw-r--r--src/extantz/extantz.h7
-rw-r--r--src/extantz/scenri.c456
-rw-r--r--src/libraries/love.h2
5 files changed, 516 insertions, 597 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}
diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c
index d8a265c..835429f 100644
--- a/src/extantz/extantz.c
+++ b/src/extantz/extantz.c
@@ -324,7 +324,7 @@ static void _draw_gl(Evas_Object *obj)
324 drawGears(gld); 324 drawGears(gld);
325#endif 325#endif
326 326
327 _animate_scene(ourGlobals); 327 animateScene(ourGlobals);
328 animateCamera(ourGlobals->scene); 328 animateCamera(ourGlobals->scene);
329 329
330#if USE_IRR 330#if USE_IRR
diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h
index 17379a6..5095556 100644
--- a/src/extantz/extantz.h
+++ b/src/extantz/extantz.h
@@ -279,13 +279,18 @@ EAPI void finishIrr(globals *ourGlobals);
279void overlay_add(globals *ourGlobals); 279void overlay_add(globals *ourGlobals);
280 280
281EAPI void Evas_3D_Demo_add(globals *ourGlobals); 281EAPI void Evas_3D_Demo_add(globals *ourGlobals);
282Eina_Bool _animate_scene(globals *ourGlobals); 282Eina_Bool animateScene(globals *ourGlobals);
283void Evas_3D_Demo_fini(globals *ourGlobals); 283void Evas_3D_Demo_fini(globals *ourGlobals);
284 284
285Scene_Data *scenriAdd(Evas_Object *win); 285Scene_Data *scenriAdd(Evas_Object *win);
286Evas_3D_Node *cameraAdd(Evas *evas, Scene_Data *scene, Evas_Object *win); 286Evas_3D_Node *cameraAdd(Evas *evas, Scene_Data *scene, Evas_Object *win);
287Eina_Bool animateCamera(Scene_Data *scene); 287Eina_Bool animateCamera(Scene_Data *scene);
288Eina_Bool animateScene(globals *ourGlobals);
288void scenriDel(Scene_Data *scene); 289void scenriDel(Scene_Data *scene);
290void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene, int fake);
291ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner,
292 char *file, MeshType type, float px, float py, float pz, float rx, float ry, float rz, float rw);
293void addMaterial(ExtantzStuffs *e, int face, TextureType type, char *file);
289 294
290winFang *filesAdd(globals *ourGlobals, char *path, Eina_Bool multi, Eina_Bool save); 295winFang *filesAdd(globals *ourGlobals, char *path, Eina_Bool multi, Eina_Bool save);
291void filesShow(winFang *me, Evas_Smart_Cb func, void *data); 296void filesShow(winFang *me, Evas_Smart_Cb func, void *data);
diff --git a/src/extantz/scenri.c b/src/extantz/scenri.c
index 7395582..4ebc64a 100644
--- a/src/extantz/scenri.c
+++ b/src/extantz/scenri.c
@@ -1,5 +1,18 @@
1#include "extantz.h" 1#include "extantz.h"
2 2
3
4Eina_Bool animateScene(globals *ourGlobals)
5{
6 ExtantzStuffs *e;
7
8 EINA_CLIST_FOR_EACH_ENTRY(e, &ourGlobals->stuffs, ExtantzStuffs, node)
9 {
10 if (e->animateStuffs) e->animateStuffs(e);
11 }
12
13 return EINA_TRUE;
14}
15
3static void _on_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo) 16static void _on_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo)
4{ 17{
5 Scene_Data *scene = data; 18 Scene_Data *scene = data;
@@ -159,3 +172,446 @@ void scenriDel(Scene_Data *scene)
159// eo_unref(scene->root_node); 172// eo_unref(scene->root_node);
160 free(scene); 173 free(scene);
161} 174}
175
176
177static const float cube_vertices[] =
178{
179 /* Front */
180 -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0,
181 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0,
182 -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
183 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0,
184
185 /* Back */
186 1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0,
187 -1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
188 1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
189 -1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0,
190
191 /* Left */
192 -1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
193 -1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0,
194 -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0,
195 -1.0, -1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0,
196
197 /* Right */
198 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
199 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0,
200 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
201 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0,
202
203 /* Top */
204 -1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
205 1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0,
206 -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0,
207 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0,
208
209 /* Bottom */
210 1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0,
211 -1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
212 1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0,
213 -1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0,
214};
215
216static const unsigned short cube_indices[] =
217{
218 /* Front */
219 0, 1, 2, 2, 1, 3,
220
221 /* Back */
222 4, 5, 6, 6, 5, 7,
223
224 /* Left */
225 8, 9, 10, 10, 9, 11,
226
227 /* Right */
228 12, 13, 14, 14, 13, 15,
229
230 /* Top */
231 16, 17, 18, 18, 17, 19,
232
233 /* Bottom */
234 20, 21, 22, 22, 21, 23
235};
236
237static const unsigned int pixels0[] =
238{
239 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
240 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
241 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000,
242 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000,
243};
244
245static const unsigned int pixels1[] =
246{
247 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00,
248 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00,
249 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff,
250 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff,
251};
252
253
254static int vertex_count = 0;
255static vertex *sphere_vertices = NULL;
256
257static int index_count = 0;
258static unsigned short *sphere_indices = NULL;
259
260static inline vec3
261_normalize(const vec3 *v)
262{
263 double l = sqrt(v->x * v->x + v->y * v->y + v->z * v->z);
264 vec3 vec;
265
266 vec.x = v->x / l;
267 vec.y = v->y / l;
268 vec.z = v->z / l;
269
270 return vec;
271}
272
273
274static void _sphere_init(int precision)
275{
276 int i, j;
277 unsigned short *index;
278
279 vertex_count = (precision + 1) * (precision + 1);
280 index_count = precision * precision * 6;
281
282 /* Allocate buffer. */
283 sphere_vertices = malloc(sizeof(vertex) * vertex_count);
284 sphere_indices = malloc(sizeof(unsigned short) * index_count);
285
286 for (i = 0; i <= precision; i++)
287 {
288 double lati = (M_PI * (double)i) / (double)precision;
289 double y = cos(lati);
290 double r = fabs(sin(lati));
291
292 for (j = 0; j <= precision; j++)
293 {
294 double longi = (M_PI * 2.0 * j) / precision;
295 vertex *v = &sphere_vertices[i * (precision + 1) + j];
296
297 if (j == 0 || j == precision)
298 v->position.x = 0.0;
299 else
300 v->position.x = r * sin(longi);
301
302 v->position.y = y;
303
304 if (j == 0 || j == precision)
305 v->position.z = r;
306 else
307 v->position.z = r * cos(longi);
308
309 v->normal = v->position;
310
311 if (v->position.x > 0.0)
312 {
313 v->tangent.x = -v->normal.y;
314 v->tangent.y = v->normal.x;
315 v->tangent.z = v->normal.z;
316 }
317 else
318 {
319 v->tangent.x = v->normal.y;
320 v->tangent.y = -v->normal.x;
321 v->tangent.z = v->normal.z;
322 }
323
324 v->color.x = v->position.x;
325 v->color.y = v->position.y;
326 v->color.z = v->position.z;
327 v->color.w = 1.0;
328
329 if (j == precision)
330 v->texcoord.x = 1.0;
331 else if (j == 0)
332 v->texcoord.x = 0.0;
333 else
334 v->texcoord.x = (double)j / (double)precision;
335
336 if (i == precision)
337 v->texcoord.y = 1.0;
338 else if (i == 0)
339 v->texcoord.y = 0.0;
340 else
341 v->texcoord.y = 1.0 - (double)i / (double)precision;
342 }
343 }
344
345 index = &sphere_indices[0];
346
347 for (i = 0; i < precision; i++)
348 {
349 for (j = 0; j < precision; j++)
350 {
351 *index++ = i * (precision + 1) + j;
352 *index++ = i * (precision + 1) + j + 1;
353 *index++ = (i + 1) * (precision + 1) + j;
354
355 *index++ = (i + 1) * (precision + 1) + j;
356 *index++ = i * (precision + 1) + j + 1;
357 *index++ = (i + 1) * (precision + 1) + j + 1;
358 }
359 }
360
361 for (i = 0; i < index_count; i += 3)
362 {
363 vertex *v0 = &sphere_vertices[sphere_indices[i + 0]];
364 vertex *v1 = &sphere_vertices[sphere_indices[i + 1]];
365 vertex *v2 = &sphere_vertices[sphere_indices[i + 2]];
366
367 vec3 e1, e2;
368 float du1, du2, dv1, dv2, f;
369 vec3 tangent;
370
371 e1.x = v1->position.x - v0->position.x;
372 e1.y = v1->position.y - v0->position.y;
373 e1.z = v1->position.z - v0->position.z;
374
375 e2.x = v2->position.x - v0->position.x;
376 e2.y = v2->position.y - v0->position.y;
377 e2.z = v2->position.z - v0->position.z;
378
379 du1 = v1->texcoord.x - v0->texcoord.x;
380 dv1 = v1->texcoord.y - v0->texcoord.y;
381
382 du2 = v2->texcoord.x - v0->texcoord.x;
383 dv2 = v2->texcoord.y - v0->texcoord.y;
384
385 f = 1.0 / (du1 * dv2 - du2 * dv1);
386
387 tangent.x = f * (dv2 * e1.x - dv1 * e2.x);
388 tangent.y = f * (dv2 * e1.y - dv1 * e2.y);
389 tangent.z = f * (dv2 * e1.z - dv1 * e2.z);
390
391 v0->tangent = tangent;
392 }
393
394 for (i = 0; i <= precision; i++)
395 {
396 for (j = 0; j <= precision; j++)
397 {
398 if (j == precision)
399 {
400 vertex *v = &sphere_vertices[i * (precision + 1) + j];
401 v->tangent = sphere_vertices[i * (precision + 1)].tangent;
402 }
403 }
404 }
405}
406
407
408void stuffsSetup(ExtantzStuffs *stuffs, globals *ourGlobals, Scene_Data *scene, int fake)
409{
410 char buf[PATH_MAX];
411 Material *m;
412 Evas_3D_Texture *t, *t1, *ti;
413 Evas_3D_Material *mi, *mj;
414 Evas_3D_Mesh *me;
415
416// TODO - These examples just don't fit neatly into anything I can whip up quickly as a data format.
417// So just fake it for now, and expand the data format later.
418
419 // Textures
420 if (1 == fake)
421 {
422 t = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
423 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels0[0])
424 );
425 eina_array_push(stuffs->textures, t);
426
427 t1 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
428 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels1[0])
429 );
430 eina_array_push(stuffs->textures, t1);
431 }
432
433 EINA_INARRAY_FOREACH(stuffs->stuffs.details.mesh->materials, m)
434 {
435 snprintf(buf, sizeof(buf), "%s/%s", prefix_data_get(), m->texture);
436 ti = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas,
437 evas_3d_texture_file_set(buf, NULL),
438 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_LINEAR, EVAS_3D_TEXTURE_FILTER_LINEAR), // Only for sphere originally.
439 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_NEAREST, EVAS_3D_TEXTURE_FILTER_NEAREST), // Only for sonic originally.
440 evas_3d_texture_wrap_set(EVAS_3D_WRAP_MODE_REPEAT, EVAS_3D_WRAP_MODE_REPEAT)
441 );
442 eina_array_push(stuffs->textures, ti);
443 }
444
445 // Materials.
446 if (1 == fake)
447 {
448 eina_accessor_data_get(stuffs->aTexture, 0, (void **) &t);
449 mi = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas,
450 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
451 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
452 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
453 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
454
455 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
456 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
457 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
458 evas_3d_material_shininess_set(100.0),
459 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t)
460 );
461 eina_array_push(stuffs->materials, mi);
462
463 eina_accessor_data_get(stuffs->aTexture, 1, (void **) &t1);
464 eina_accessor_data_get(stuffs->aTexture, 2, (void **) &ti);
465 mj = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas,
466 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
467 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
468 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
469 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
470
471 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
472 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
473 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
474 evas_3d_material_shininess_set(100.0),
475
476 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t1),
477 evas_3d_material_texture_set(EVAS_3D_MATERIAL_NORMAL, ti)
478 );
479 eina_array_push(stuffs->materials, mj);
480 }
481 else
482 {
483 eina_accessor_data_get(stuffs->aTexture, 0, (void **) &t);
484 mi = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas,
485 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, t),
486
487 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
488 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
489 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
490 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE), // Not for sphere originally.
491
492 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01, 1.0),
493 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0, 1.0),
494 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
495 evas_3d_material_shininess_set(50.0)
496 );
497 eina_array_push(stuffs->materials, mi);
498 }
499
500 // Meshes
501 // TODO - Write real generic cube and sphere stuff later.
502 if (MT_CUBE == stuffs->stuffs.details.mesh->type)
503 {
504 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi);
505 eina_accessor_data_get(stuffs->aMaterial, 1, (void **) &mj);
506 me = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas,
507 evas_3d_mesh_vertex_count_set(24),
508 evas_3d_mesh_frame_add(0),
509
510 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, 12 * sizeof(float), &cube_vertices[ 0]),
511 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, 12 * sizeof(float), &cube_vertices[ 3]),
512 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, 12 * sizeof(float), &cube_vertices[ 6]),
513 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, 12 * sizeof(float), &cube_vertices[10]),
514
515 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, 36, &cube_indices[0]),
516 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
517
518 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_NORMAL_MAP),
519
520 evas_3d_mesh_frame_material_set(0, mi),
521
522 evas_3d_mesh_frame_add(20),
523 evas_3d_mesh_frame_material_set(20, mj)
524 );
525 eina_array_push(stuffs->mesh, me);
526 }
527 else if (MT_SPHERE == stuffs->stuffs.details.mesh->type)
528 {
529 _sphere_init(100);
530
531 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi);
532 me = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas,
533 evas_3d_mesh_vertex_count_set(vertex_count),
534 evas_3d_mesh_frame_add(0),
535 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, sizeof(vertex), &sphere_vertices[0].position),
536 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, sizeof(vertex), &sphere_vertices[0].normal),
537 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TANGENT, sizeof(vertex), &sphere_vertices[0].tangent),
538 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, sizeof(vertex), &sphere_vertices[0].color),
539 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, sizeof(vertex), &sphere_vertices[0].texcoord),
540
541 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, index_count, &sphere_indices[0]),
542 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
543 evas_3d_mesh_frame_material_set(0, mi),
544
545 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_DIFFUSE)
546 );
547 eina_array_push(stuffs->mesh, me);
548 }
549 else
550 {
551 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi);
552 snprintf(buf, sizeof(buf), "%s/%s", prefix_data_get(), stuffs->stuffs.details.mesh->fileName);
553 me = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas,
554 evas_3d_mesh_file_set(EVAS_3D_MESH_FILE_TYPE_MD2, buf, NULL),
555 evas_3d_mesh_frame_material_set(0, mi),
556 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG)
557 );
558 eina_array_push(stuffs->mesh, me);
559 }
560
561 eina_accessor_data_get(stuffs->aMesh, 0, (void **) &me);
562 stuffs->mesh_node = eo_add_custom(EVAS_3D_NODE_CLASS, ourGlobals->evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH),
563 eo_key_data_set("Name", stuffs->stuffs.name, NULL),
564 evas_3d_node_position_set(stuffs->stuffs.details.mesh->pos.x, stuffs->stuffs.details.mesh->pos.y, stuffs->stuffs.details.mesh->pos.z),
565 evas_3d_node_orientation_set(stuffs->stuffs.details.mesh->rot.x, stuffs->stuffs.details.mesh->rot.y, stuffs->stuffs.details.mesh->rot.z, stuffs->stuffs.details.mesh->rot.w),
566 evas_3d_node_mesh_add(me)
567 );
568
569 eo_do(scene->root_node, evas_3d_node_member_add(stuffs->mesh_node));
570 eina_clist_add_head(&(ourGlobals->stuffs), &(stuffs->node));
571}
572
573ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner,
574 char *file, MeshType type, float px, float py, float pz, float rx, float ry, float rz, float rw)
575{
576 ExtantzStuffs *result = calloc(1, sizeof(ExtantzStuffs));
577
578 // TODO - using Eina arrays of any sort seems a bit heavy, might be better to just count and realloc?
579 result->materials = eina_array_new(3);
580 result->mesh = eina_array_new(3);
581 result->textures = eina_array_new(3);
582 result->aMaterial = eina_array_accessor_new(result->materials);
583 result->aMesh = eina_array_accessor_new(result->mesh);
584 result->aTexture = eina_array_accessor_new(result->textures);
585 result->stuffs.details.mesh = calloc(1, sizeof(Mesh));
586 result->stuffs.details.mesh->materials = eina_inarray_new(sizeof(Material), 1);
587 result->stuffs.details.mesh->parts = eina_inarray_new(sizeof(Mesh), 1);
588
589 strcpy(result->stuffs.UUID, uuid);
590 strcpy(result->stuffs.name, name);
591 strcpy(result->stuffs.description, description);
592 strcpy(result->stuffs.owner, owner);
593
594 strcpy(result->stuffs.details.mesh->fileName, file);
595 result->stuffs.details.mesh->type = type;
596 result->stuffs.details.mesh->pos.x = px; result->stuffs.details.mesh->pos.y = py; result->stuffs.details.mesh->pos.z = pz;
597 result->stuffs.details.mesh->rot.x = rx; result->stuffs.details.mesh->rot.y = ry; result->stuffs.details.mesh->rot.z = rz; result->stuffs.details.mesh->rot.w = rw;
598
599 return result;
600}
601
602void addMaterial(ExtantzStuffs *e, int face, TextureType type, char *file)
603{
604 Material *result = calloc(1, sizeof(Material));
605
606 // face -1 means "all of them I think".
607 result->face = face;
608 result->type = type;
609 strcpy(result->texture, file);
610 eina_inarray_push(e->stuffs.details.mesh->materials, result);
611}
612
613void Evas_3D_Demo_fini(globals *ourGlobals)
614{
615 free(sphere_vertices);
616 free(sphere_indices);
617}
diff --git a/src/libraries/love.h b/src/libraries/love.h
index 26fbe06..e99f282 100644
--- a/src/libraries/love.h
+++ b/src/libraries/love.h
@@ -109,12 +109,14 @@ typedef struct _vec2
109 109
110typedef enum 110typedef enum
111{ 111{
112 TT_FACE = -2,
112 TT_NORMAL = -1 113 TT_NORMAL = -1
113} TextureType; 114} TextureType;
114 115
115typedef enum 116typedef enum
116{ 117{
117 MT_CUBE, 118 MT_CUBE,
119 MT_MESH,
118 MT_SPHERE 120 MT_SPHERE
119} MeshType; 121} MeshType;
120 122