diff options
Diffstat (limited to '')
-rw-r--r-- | src/extantz/Evas_3D_demo.c | 96 | ||||
-rw-r--r-- | src/extantz/extantz.c | 5 | ||||
-rw-r--r-- | src/extantz/extantz.h | 35 | ||||
-rw-r--r-- | src/extantz/scenri.c | 141 |
4 files changed, 158 insertions, 119 deletions
diff --git a/src/extantz/Evas_3D_demo.c b/src/extantz/Evas_3D_demo.c deleted file mode 100644 index e9265da..0000000 --- a/src/extantz/Evas_3D_demo.c +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | #include "extantz.h" | ||
2 | |||
3 | |||
4 | static void _animateCube(ExtantzStuffs *stuffs) | ||
5 | { | ||
6 | static float angle = 0.0f; | ||
7 | static int frame = 0; | ||
8 | static int inc = 1; | ||
9 | Evas_3D_Mesh *m; | ||
10 | |||
11 | eina_accessor_data_get(stuffs->aMesh, 0, (void **) &m); | ||
12 | |||
13 | angle += 0.5; | ||
14 | if (angle > 360.0) angle -= 360.0f; | ||
15 | |||
16 | frame += inc; | ||
17 | if (frame >= 20) inc = -1; | ||
18 | else if (frame <= 0) inc = 1; | ||
19 | |||
20 | eo_do(stuffs->mesh_node, | ||
21 | evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0), | ||
22 | evas_3d_node_mesh_frame_set(m, frame) | ||
23 | ); | ||
24 | } | ||
25 | |||
26 | static void _animateSphere(ExtantzStuffs *stuffs) | ||
27 | { | ||
28 | static float earthAngle = 0.0f; | ||
29 | |||
30 | earthAngle += 0.3; | ||
31 | if (earthAngle > 360.0) earthAngle -= 360.0f; | ||
32 | eo_do(stuffs->mesh_node, | ||
33 | evas_3d_node_orientation_angle_axis_set(earthAngle, 0.0, 1.0, 0.0) | ||
34 | ); | ||
35 | } | ||
36 | |||
37 | static void _animateSonic(ExtantzStuffs *stuffs) | ||
38 | { | ||
39 | static int sonicFrame = 0; | ||
40 | Evas_3D_Mesh *m; | ||
41 | |||
42 | eina_accessor_data_get(stuffs->aMesh, 0, (void **) &m); | ||
43 | sonicFrame += 32; | ||
44 | if (sonicFrame > 256 * 50) sonicFrame = 0; | ||
45 | eo_do(stuffs->mesh_node, | ||
46 | evas_3d_node_mesh_frame_set(m, sonicFrame) | ||
47 | ); | ||
48 | } | ||
49 | |||
50 | void Evas_3D_Demo_add(globals *ourGlobals) | ||
51 | { | ||
52 | char buf[PATH_MAX]; | ||
53 | ExtantzStuffs *eStuffs; | ||
54 | |||
55 | ourGlobals->scene = scenriAdd(ourGlobals->win); | ||
56 | |||
57 | // TODO - For now lets just pretend we got stuffs sent from our love. | ||
58 | sprintf(buf, FAKE_UUID); | ||
59 | eStuffs = addStuffs(buf, "onefang's test bed", | ||
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 | ||
66 | ); | ||
67 | addMaterial(eStuffs, -1, TT_NORMAL, "normal_lego.png"); | ||
68 | eStuffs->animateStuffs = (aniStuffs) _animateCube; | ||
69 | stuffsSetup(eStuffs, ourGlobals, ourGlobals->scene, 1); | ||
70 | |||
71 | sprintf(buf, FAKE_UUID); | ||
72 | eStuffs = addStuffs(buf, "onefang's left testicle", | ||
73 | "Just a pretend world for testing SledjHamr.", | ||
74 | "12345678-1234-4321-abcd-0123456789ab", | ||
75 | "earth.omg", | ||
76 | MT_SPHERE, | ||
77 | 0.0, 0.0, 0.0, | ||
78 | 1.0, 0.0, 0.0, 0.0 | ||
79 | ); | ||
80 | addMaterial(eStuffs, 1, TT_FACE, "EarthDiffuse.png"); | ||
81 | eStuffs->animateStuffs = (aniStuffs) _animateSphere; | ||
82 | stuffsSetup(eStuffs, ourGlobals, ourGlobals->scene, 2); | ||
83 | |||
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 | ||
92 | ); | ||
93 | addMaterial(eStuffs, -1, TT_FACE, "sonic.png"); | ||
94 | eStuffs->animateStuffs = (aniStuffs) _animateSonic; | ||
95 | stuffsSetup(eStuffs, ourGlobals, ourGlobals->scene, 3); | ||
96 | } | ||
diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index e102165..7c90b8a 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c | |||
@@ -108,6 +108,7 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev) | |||
108 | // TODO - For now, assume it's a file:// URL. | 108 | // TODO - For now, assume it's a file:// URL. |
109 | t += 7; | 109 | t += 7; |
110 | //strcat(t, "/index.omg"); | 110 | //strcat(t, "/index.omg"); |
111 | strcpy(ourGlobals->scene->sim, t); | ||
111 | PI("Loading local sim from %s", t); | 112 | PI("Loading local sim from %s", t); |
112 | 113 | ||
113 | // TODO - Later do the same with eet files in C code, but keep both implementations. | 114 | // TODO - Later do the same with eet files in C code, but keep both implementations. |
@@ -118,8 +119,8 @@ static Eina_Bool _data(void *data, int type, Ecore_Con_Event_Server_Data *ev) | |||
118 | lua_remove(ourGlobals->scene->L, -2); // Removes "loaded" | 119 | lua_remove(ourGlobals->scene->L, -2); // Removes "loaded" |
119 | scenriLua = lua_gettop(ourGlobals->scene->L); | 120 | scenriLua = lua_gettop(ourGlobals->scene->L); |
120 | 121 | ||
121 | push_lua(ourGlobals->scene->L, "@ ( $ $ )", scenriLua, "loadSim", t); | 122 | push_lua(ourGlobals->scene->L, "@ ( $ )", scenriLua, "loadSim", t, 0); |
122 | // Evas_3D_Demo_add(ourGlobals, t); | 123 | PI("Loaded local sim from %s", t); |
123 | } | 124 | } |
124 | else | 125 | else |
125 | { | 126 | { |
diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h index 1526626..5882e10 100644 --- a/src/extantz/extantz.h +++ b/src/extantz/extantz.h | |||
@@ -141,26 +141,9 @@ typedef struct _Scene_Data | |||
141 | 141 | ||
142 | Evas_3D_Light *light; | 142 | Evas_3D_Light *light; |
143 | 143 | ||
144 | Eina_Clist stuffs; | 144 | char sim[PATH_MAX]; |
145 | /* | 145 | Eina_Clist stuffs, loading; |
146 | Evas_3D_Mesh *mesh; | 146 | |
147 | Evas_3D_Node *mesh_node; | ||
148 | Evas_3D_Material *material0; | ||
149 | Evas_3D_Material *material1; | ||
150 | Evas_3D_Texture *texture0; | ||
151 | Evas_3D_Texture *texture1; | ||
152 | Evas_3D_Texture *texture_normal; | ||
153 | |||
154 | Evas_3D_Mesh *mesh2; | ||
155 | Evas_3D_Node *mesh2_node; | ||
156 | Evas_3D_Material *material2; | ||
157 | Evas_3D_Texture *texture2; | ||
158 | |||
159 | Evas_3D_Mesh *mesh3; | ||
160 | Evas_3D_Node *mesh3_node; | ||
161 | Evas_3D_Material *material3; | ||
162 | Evas_3D_Texture *texture_diffuse; | ||
163 | */ | ||
164 | cameraMove *move; | 147 | cameraMove *move; |
165 | 148 | ||
166 | Evas_Object_Event_Cb clickCb; | 149 | Evas_Object_Event_Cb clickCb; |
@@ -169,6 +152,16 @@ typedef struct _Scene_Data | |||
169 | 152 | ||
170 | typedef void (* aniStuffs)(void *stuffs); | 153 | typedef void (* aniStuffs)(void *stuffs); |
171 | 154 | ||
155 | typedef enum | ||
156 | { | ||
157 | ES_NORMAL = -1, | ||
158 | ES_PRE = 1, | ||
159 | ES_PART, | ||
160 | ES_LOADED, | ||
161 | ES_RENDERED, | ||
162 | ES_TRASHED | ||
163 | } ES_Stages; | ||
164 | |||
172 | typedef struct _extantzStuffs | 165 | typedef struct _extantzStuffs |
173 | { | 166 | { |
174 | Stuffs stuffs; | 167 | Stuffs stuffs; |
@@ -183,6 +176,8 @@ typedef struct _extantzStuffs | |||
183 | Eina_Accessor *aTexture; | 176 | Eina_Accessor *aTexture; |
184 | aniStuffs animateStuffs; | 177 | aniStuffs animateStuffs; |
185 | Eina_Clist node; | 178 | Eina_Clist node; |
179 | ES_Stages stage; | ||
180 | int fake; | ||
186 | } ExtantzStuffs; | 181 | } ExtantzStuffs; |
187 | 182 | ||
188 | 183 | ||
diff --git a/src/extantz/scenri.c b/src/extantz/scenri.c index e7d30c4..2a02996 100644 --- a/src/extantz/scenri.c +++ b/src/extantz/scenri.c | |||
@@ -28,6 +28,8 @@ | |||
28 | #define THINGASM "thingasm" | 28 | #define THINGASM "thingasm" |
29 | 29 | ||
30 | 30 | ||
31 | static Ecore_Idle_Enterer *idler; | ||
32 | |||
31 | 33 | ||
32 | static void _animateCube(ExtantzStuffs *stuffs) | 34 | static void _animateCube(ExtantzStuffs *stuffs) |
33 | { | 35 | { |
@@ -173,6 +175,101 @@ static void _on_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void | |||
173 | 175 | ||
174 | } | 176 | } |
175 | 177 | ||
178 | static int _preallocateStuffs(lua_State *L) | ||
179 | { | ||
180 | ExtantzStuffs *result = NULL; | ||
181 | Scene_Data *scene = NULL; | ||
182 | int count, i; | ||
183 | |||
184 | pull_lua(L, 1, "%", &count); | ||
185 | lua_getfield(L, LUA_REGISTRYINDEX, "sceneData"); | ||
186 | scene = (Scene_Data *) lua_touserdata(L, -1); | ||
187 | |||
188 | result = calloc(count, sizeof(ExtantzStuffs)); | ||
189 | |||
190 | for (i = 0; i < count; i++) | ||
191 | { | ||
192 | // TODO - using Eina arrays of any sort seems a bit heavy, might be better to just count and realloc? | ||
193 | result[i].materials = eina_array_new(3); | ||
194 | result[i].mesh = eina_array_new(3); | ||
195 | result[i].textures = eina_array_new(3); | ||
196 | result[i].aMaterial = eina_array_accessor_new(result[i].materials); | ||
197 | result[i].aMesh = eina_array_accessor_new(result[i].mesh); | ||
198 | result[i].aTexture = eina_array_accessor_new(result[i].textures); | ||
199 | result[i].stuffs.details.mesh = calloc(1, sizeof(Mesh)); | ||
200 | result[i].stuffs.details.mesh->materials = eina_inarray_new(sizeof(Material), 1); | ||
201 | result[i].stuffs.details.mesh->parts = eina_inarray_new(sizeof(Mesh), 1); | ||
202 | result[i].scene = scene; | ||
203 | result[i].stage = ES_PRE; | ||
204 | eina_clist_add_head(&(scene->loading), &(result[i].node)); | ||
205 | } | ||
206 | |||
207 | return 0; | ||
208 | } | ||
209 | |||
210 | static int _partFillStuffs(lua_State *L) | ||
211 | { | ||
212 | ExtantzStuffs *result = NULL; | ||
213 | Scene_Data *scene = NULL; | ||
214 | char *name, *file; | ||
215 | double px, py, pz, rx, ry, rz, rw; | ||
216 | |||
217 | pull_lua(L, 1, "$ $ # # # # # # #", &name, &file, &px, &py, &pz, &rx, &ry, &rz, &rw); | ||
218 | lua_getfield(L, LUA_REGISTRYINDEX, "sceneData"); | ||
219 | scene = (Scene_Data *) lua_touserdata(L, -1); | ||
220 | |||
221 | EINA_CLIST_FOR_EACH_ENTRY(result, &(scene->loading), ExtantzStuffs, node) | ||
222 | { | ||
223 | if (ES_PRE == result->stage) | ||
224 | { | ||
225 | strcpy(result->stuffs.name, name); | ||
226 | |||
227 | strcpy(result->stuffs.file, file); | ||
228 | result->stuffs.details.mesh->pos.x = px; result->stuffs.details.mesh->pos.y = py; result->stuffs.details.mesh->pos.z = pz; | ||
229 | 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; | ||
230 | result->stage = ES_PART; | ||
231 | break; | ||
232 | } | ||
233 | } | ||
234 | |||
235 | return 0; | ||
236 | } | ||
237 | |||
238 | static int _finishStuffs(lua_State *L) | ||
239 | { | ||
240 | ExtantzStuffs *result = NULL; | ||
241 | Scene_Data *scene = NULL; | ||
242 | char *uuid, *name, *file, *description, *owner, *mesh; | ||
243 | int type, fake; | ||
244 | |||
245 | pull_lua(L, 1, "$ $ $ $ $ $ % % ", &uuid, &name, &file, &description, &owner, &mesh, &type, &fake); | ||
246 | lua_getfield(L, LUA_REGISTRYINDEX, "sceneData"); | ||
247 | scene = (Scene_Data *) lua_touserdata(L, -1); | ||
248 | |||
249 | EINA_CLIST_FOR_EACH_ENTRY(result, &(scene->loading), ExtantzStuffs, node) | ||
250 | { | ||
251 | if (strcmp(file, result->stuffs.name) == 0) | ||
252 | { | ||
253 | strcpy(result->stuffs.UUID, uuid); | ||
254 | strcpy(result->stuffs.name, name); | ||
255 | strcpy(result->stuffs.description, description); | ||
256 | strcpy(result->stuffs.owner, owner); | ||
257 | strcpy(result->stuffs.details.mesh->fileName, mesh); | ||
258 | |||
259 | result->stuffs.details.mesh->type = type; | ||
260 | result->fake = fake; | ||
261 | result->stage = ES_LOADED; | ||
262 | |||
263 | lua_pushlightuserdata(L, (void *) result); | ||
264 | |||
265 | PI("LOADED %s", name); | ||
266 | return 1; | ||
267 | } | ||
268 | } | ||
269 | |||
270 | return 0; | ||
271 | } | ||
272 | |||
176 | static int _addStuffsL(lua_State *L) | 273 | static int _addStuffsL(lua_State *L) |
177 | { | 274 | { |
178 | ExtantzStuffs *result = NULL; | 275 | ExtantzStuffs *result = NULL; |
@@ -219,6 +316,38 @@ static int _stuffsSetupL(lua_State *L) | |||
219 | return 0; | 316 | return 0; |
220 | } | 317 | } |
221 | 318 | ||
319 | static Eina_Bool _stuffsLoader(void *data) | ||
320 | { | ||
321 | ExtantzStuffs *result = NULL, *e1; | ||
322 | Scene_Data *scene = data; | ||
323 | |||
324 | // TODO - If there's lots of them, only do some. | ||
325 | EINA_CLIST_FOR_EACH_ENTRY_SAFE(result, e1, &(scene->loading), ExtantzStuffs, node) | ||
326 | { | ||
327 | if (ES_PART == result->stage) | ||
328 | { | ||
329 | int scenriLua; | ||
330 | |||
331 | lua_getglobal(scene->L, "package"); | ||
332 | lua_getfield(scene->L, lua_gettop(scene->L), "loaded"); | ||
333 | lua_remove(scene->L, -2); // Removes "package" | ||
334 | lua_getfield(scene->L, lua_gettop(scene->L), "scenriLua"); | ||
335 | lua_remove(scene->L, -2); // Removes "loaded" | ||
336 | scenriLua = lua_gettop(scene->L); | ||
337 | |||
338 | push_lua(scene->L, "@ ( $ $ )", scenriLua, "finishLoadStuffs", scene->sim, result->stuffs.file, 0); | ||
339 | } | ||
340 | if (ES_LOADED == result->stage) | ||
341 | { | ||
342 | eina_clist_remove(&(result->node)); | ||
343 | stuffsSetup(result, result->scene, result->fake); | ||
344 | result->stage = ES_RENDERED; | ||
345 | } | ||
346 | } | ||
347 | |||
348 | return ECORE_CALLBACK_RENEW; | ||
349 | } | ||
350 | |||
222 | Scene_Data *scenriAdd(Evas_Object *win) | 351 | Scene_Data *scenriAdd(Evas_Object *win) |
223 | { | 352 | { |
224 | Scene_Data *scene; | 353 | Scene_Data *scene; |
@@ -230,6 +359,7 @@ Scene_Data *scenriAdd(Evas_Object *win) | |||
230 | scene = calloc(1, sizeof(Scene_Data)); | 359 | scene = calloc(1, sizeof(Scene_Data)); |
231 | scene->evas = evas; | 360 | scene->evas = evas; |
232 | eina_clist_init(&(scene->stuffs)); | 361 | eina_clist_init(&(scene->stuffs)); |
362 | eina_clist_init(&(scene->loading)); | ||
233 | 363 | ||
234 | scene->root_node = eo_add_custom(EVAS_3D_NODE_CLASS, evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE)); | 364 | scene->root_node = eo_add_custom(EVAS_3D_NODE_CLASS, evas, evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE)); |
235 | 365 | ||
@@ -308,6 +438,12 @@ Scene_Data *scenriAdd(Evas_Object *win) | |||
308 | scenriLua = lua_gettop(scene->L); | 438 | scenriLua = lua_gettop(scene->L); |
309 | 439 | ||
310 | // Define our functions. | 440 | // Define our functions. |
441 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "preallocateStuffs", "preallocate a bunch of stuffs.", _preallocateStuffs, | ||
442 | "number", 0); | ||
443 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "partFillStuffs", "Put some info into a stuffs.", _partFillStuffs, | ||
444 | "string,string,number,number,number,number,number,number,number", 0); | ||
445 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "finishStuffs", "Put rest of info into a stuffs.", _finishStuffs, | ||
446 | "string,string,string,string,string,number,number,number,number,number,number,number,number", 0); | ||
311 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "addStuffs", "Add an in world stuffs.", _addStuffsL, | 447 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "addStuffs", "Add an in world stuffs.", _addStuffsL, |
312 | "string,string,string,string,string,number,number,number,number,number,number,number,number", 0); | 448 | "string,string,string,string,string,number,number,number,number,number,number,number,number", 0); |
313 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "addMaterial", "Add a material to an in world stuffs.", _addMaterialL, | 449 | push_lua(scene->L, "@ ( = $ $ & $ )", skang, THINGASM, scenriLua, "addMaterial", "Add a material to an in world stuffs.", _addMaterialL, |
@@ -322,6 +458,8 @@ Scene_Data *scenriAdd(Evas_Object *win) | |||
322 | doLuaString(scene->L, buf, "scenriLua"); | 458 | doLuaString(scene->L, buf, "scenriLua"); |
323 | } | 459 | } |
324 | 460 | ||
461 | idler = ecore_idler_add(_stuffsLoader, scene); | ||
462 | |||
325 | return scene; | 463 | return scene; |
326 | } | 464 | } |
327 | 465 | ||
@@ -575,7 +713,6 @@ static void _sphere_init(int precision) | |||
575 | } | 713 | } |
576 | } | 714 | } |
577 | 715 | ||
578 | |||
579 | void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) | 716 | void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) |
580 | { | 717 | { |
581 | char buf[PATH_MAX]; | 718 | char buf[PATH_MAX]; |
@@ -584,6 +721,7 @@ void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) | |||
584 | Evas_3D_Material *mi, *mj; | 721 | Evas_3D_Material *mi, *mj; |
585 | Evas_3D_Mesh *me; | 722 | Evas_3D_Mesh *me; |
586 | 723 | ||
724 | PI("REZZING %s", stuffs->stuffs.name); | ||
587 | // TODO - These examples just don't fit neatly into anything I can whip up quickly as a data format. | 725 | // TODO - These examples just don't fit neatly into anything I can whip up quickly as a data format. |
588 | // So just fake it for now, and expand the data format later. | 726 | // So just fake it for now, and expand the data format later. |
589 | 727 | ||
@@ -774,6 +912,7 @@ ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner, | |||
774 | result->stuffs.details.mesh->type = type; | 912 | result->stuffs.details.mesh->type = type; |
775 | result->stuffs.details.mesh->pos.x = px; result->stuffs.details.mesh->pos.y = py; result->stuffs.details.mesh->pos.z = pz; | 913 | result->stuffs.details.mesh->pos.x = px; result->stuffs.details.mesh->pos.y = py; result->stuffs.details.mesh->pos.z = pz; |
776 | 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; | 914 | 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; |
915 | result->stage = ES_NORMAL; | ||
777 | 916 | ||
778 | return result; | 917 | return result; |
779 | } | 918 | } |