-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrcbc_xml_minixml.c
158 lines (133 loc) · 5.03 KB
/
rcbc_xml_minixml.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <stdio.h>
#include "rcbc_xml_minixml_visualscene.h"
#include "rcbc_xml_minixml_textures.h"
#include "rcbc_xml_minixml_geometries.h"
#include "rcbc_xml_minixml.h"
#include "console.h"
/**
* Initilize the MiniXML library (not actually required...)
*/
int RCBC_MiniXML_Init() {
LOG("Initilizing MiniXML...");
return 0;
}
/**
* For debugging puroses, dump XML node information
*/
void DumpNodeInfo(mxml_node_t *node) {
DEBUG(DEBUG_VERY_HIGH, "------NODE_PTR: %p------", node);
if(node == NULL) {
DEBUG(DEBUG_VERY_HIGH, "Null Node!");
return;
}
switch(node->type) {
case MXML_IGNORE: DEBUG(DEBUG_VERY_HIGH, "TYPE: MXML_IGNORE"); break;
case MXML_ELEMENT: DEBUG(DEBUG_VERY_HIGH, "TYPE: MXML_ELEMENT"); break;
case MXML_INTEGER: DEBUG(DEBUG_VERY_HIGH, "TYPE: MXML_INTEGER"); break;
case MXML_OPAQUE: DEBUG(DEBUG_VERY_HIGH, "TYPE: MXML_OPAQUE"); break;
case MXML_REAL: DEBUG(DEBUG_VERY_HIGH, "TYPE: MXML_REAL"); break;
case MXML_TEXT: DEBUG(DEBUG_VERY_HIGH, "TYPE: MXML_TEXT"); break;
case MXML_CUSTOM: DEBUG(DEBUG_VERY_HIGH, "TYPE: MXML_CUSTOM"); break;
dafault: DEBUG(DEBUG_VERY_HIGH, "TYPE: BAD TYPE!!!", SYMBOL_WARNING);
}
switch(node->type) {
case MXML_IGNORE: DEBUG(DEBUG_VERY_HIGH, "NO DUMP INFO FOR THIS TYPE"); break;
case MXML_ELEMENT: DEBUG(DEBUG_VERY_HIGH, "NAME: %s", node->value.element.name); break;
case MXML_INTEGER: DEBUG(DEBUG_VERY_HIGH, "NO DUMP INFO FOR THIS TYPE"); break;
case MXML_OPAQUE: DEBUG(DEBUG_VERY_HIGH, "DUMP: %s", node->value.opaque); break;
case MXML_REAL: DEBUG(DEBUG_VERY_HIGH, "NO DUMP INFO FOR THIS TYPE"); break;
case MXML_TEXT: DEBUG(DEBUG_VERY_HIGH, "TEXT: '%s' WS=%d", node->value.text.string, node->value.text.whitespace); break;
case MXML_CUSTOM: DEBUG(DEBUG_VERY_HIGH, "NO DUMP INFO FOR THIS TYPE"); break;
}
}
/**
* Load a model from a COLLADA file
*/
int RCBC_MiniXML_Load(Model* model, List* images, char* filename) {
LOG("[MINIXML]: Opening '%s'...", filename);
if(!model) {
ERROR("Passed NULL model...");
}
if(!images) {
ERROR("Passed NULL image list...");
}
/* Open the file. */
FILE *fp;
mxml_node_t *tree;
fp = fopen(filename, "r");
if(!fp) {
ERROR("Error opening '%s'... %s", filename, SYMBOL_FATAL);
return 1;
}
/* Load the XML file in. */
LOG("[MINIXML]: Parsing '%s'...", filename);
tree = mxmlLoadFile(NULL, fp, MXML_OPAQUE_CALLBACK);
fclose(fp);
if(!tree) {
ERROR("Error parsing '%s'... %s", filename, SYMBOL_FATAL);
return 1;
}
LOG("[MINIXML]: Successfuly loaded... '%s'", SYMBOL_SMILEY);
DumpNodeInfo(tree);
/* Make a tempory structure to store raw COLLADA data befoure conversion. */
ModelTempory* tempory = NEW(ModelTempory);
tempory->model = model;
tempory->images = images;
mxml_node_t* node;
/* Find the up axis. */
char* axis;
node = mxmlFindElement(tree, tree, "asset", NULL, NULL, MXML_DESCEND);
node = mxmlFindElement(node, node, "up_axis", NULL, NULL, MXML_DESCEND);
if(node && node->child) {
axis = node->child->value.opaque;
}
tempory->up_axis = Y_UP;
if(strcasecmp(axis, "X_UP") == 0) {
tempory->up_axis = X_UP;
DEBUG_M("Axis is X_UP.");
} else if(strcasecmp(axis, "Y_UP") == 0) {
DEBUG_M("Axis is Y_UP.");
} else if(strcasecmp(axis, "Z_UP") == 0) {
tempory->up_axis = Z_UP;
DEBUG_M("Axis is Z_UP.");
} else {
WARNING("Unable to determine COLLADA axis orientation. Guessing Y_UP.");
}
node = mxmlFindElement(tree, tree, "library_geometries", NULL, NULL, MXML_DESCEND);
RCBC_MiniXML_ProcessGeometries(tempory, node);
node = mxmlFindElement(tree, tree, "visual_scene", NULL, NULL, MXML_DESCEND);
RCBC_MiniXML_ProcessVisualScene(tempory, node);
node = mxmlFindElement(tree, tree, "library_images", NULL, NULL, MXML_DESCEND);
RCBC_MiniXML_ProcessTextureImages(tempory, node);
node = mxmlFindElement(tree, tree, "library_materials", NULL, NULL, MXML_DESCEND);
RCBC_MiniXML_ProcessTextureMaterial(tempory, node);
node = mxmlFindElement(tree, tree, "library_effects", NULL, NULL, MXML_DESCEND);
RCBC_MiniXML_ProcessTextureEffects(tempory, node);
Hookup_Debug(tempory->sources);
Hookup_Debug(tempory->sinks);
Hookups_Execute(tempory->sources, tempory->sinks);
//Hookups_Execute(tempory->image_sources, tempory->sinks);
Hookups_Execute(tempory->sources, tempory->sinks);
//Hookups_Execute(tempory->image_sources, tempory->sinks);
Hookups_Execute(tempory->sources, tempory->sinks);
//Hookups_Execute(tempory->image_sources, tempory->sinks);
DEBUG_M("[MINIXML]: Hookups processed");
ListNode* itr = tempory->unsorted->first;
while(itr) {
RCBC_SortTriangles(tempory, itr->data);
itr = itr->next;
}
#warning ['TODO']: Consider removing nodes with no geometry or children (camera/light nodes.)
// Free memory
//DEBUG_H("Deleted missing, derefrenceing...");
//Hookups_DerefrenceMissingImages(tempory->image_sources);
DEBUG_H("Deleting missing...");
Hookups_DeleteMissing(tempory->sources, tempory->sinks);
DEBUG_H("Done than, deleting tempory...");
//List_DeleteData(tempory->image_sources);
//DELETE(tempory->image_sources);
//tempory->image_sources == NULL;
DELETE(tempory)
mxmlDelete(tree);
return 0;
}