annotate Renderer/Engine/Collada.cc @ 1384:207e0ed76cf1 draft

minor changes.
author e095732 <e095732@ie.u-ryukyu.ac.jp>
date Fri, 27 Jan 2012 02:10:52 +0900
parents de990f3e0a21
children 2247b81dd68f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include "polygon.h"
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include "SceneGraph.h"
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "SceneGraph.cc"
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "TextureHash.h"
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include "xml.h"
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 #include "SceneGraphRoot.h"
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #include <iostream>
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #include <SDL_image.h>
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 using namespace std;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 static TextureHash sgid_hash;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 extern int is_bmp(const char* name);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 extern void make_black_alpha(SDL_Surface *texture_image);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 typedef struct source {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 char *id;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 union {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 float *array;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 char *alias;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 }u;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 int count;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 struct source *next;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 } SOURCE;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 typedef SOURCE *SOURCE_P;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 typedef struct list {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 SOURCE_P first;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 SOURCE_P end;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 } LIST;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 typedef LIST *LIST_P;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 struct collada_state {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 collada_state(){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 polylist = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 vertex_offset = -1;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 vertex_count = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 normal_offset = -1;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 normal_count = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 texcoord_offset = -1;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 texcoord_count = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 polylist_count = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 vcsum = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 limit = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 vmember = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 images_flag=0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 int polylist;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 int library_images;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 xmlChar *vertices_id;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 char *vertex_src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 int vertex_offset;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 int vertex_count;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 char *normal_src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 int normal_offset;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 int normal_count;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 char *texcoord_src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 int texcoord_offset;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 int texcoord_count;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 float *vcount;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 float *pcount;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 SOURCE_P normal_float;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 SOURCE_P vertex_float;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 SOURCE_P texcoord_float;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 char *vertices_src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 int polylist_count;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 char *name;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 char *tex_picname;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 int images_flag;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 int vcsum;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 int limit;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 int vmember;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 };
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 /*static const char*
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 get_property(const char *name, xmlNodePtr cur){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 xmlAttr *p=cur->properties;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 if (p==0) return "";
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 for ( ;p; p=p->next) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 if ( xmlStrcmp(p->name, (xmlChar*)name) !=0 ) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 xmlNode* n=p->children;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 if ( n==NULL ) return "";
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 const char * v=(const char*)n->content;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 if ( v==NULL ) return "";
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 return v;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 return "";
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 }*/
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 SDL_Surface*
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 load_image(const char *file_name, const char *image_name)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 int alpha_black = is_bmp(file_name);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 /**
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 * image を 32bit(RGBA) に変換する
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 SDL_Surface *texture_image = IMG_Load(file_name);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 if (!texture_image) return 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 SDL_Surface *tmpImage
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w,
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 texture_image->h, 32, redMask,
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 greenMask, blueMask, alphaMask);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 //= SDL_CreateRGBSurface(SDL_HWSURFACE, 0,
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 // 0, 32, redMask,
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 // greenMask, blueMask, alphaMask);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 SDL_Surface *converted;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 converted = SDL_ConvertSurface(texture_image, tmpImage->format,
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 SDL_HWSURFACE);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 //SDL_SetAlpha(converted, 0, 0);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 if (converted != NULL) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 SDL_FreeSurface(texture_image);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 texture_image = converted;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 if (alpha_black) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 make_black_alpha(texture_image);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 // this->gl_tex = SDL_GL_LoadTexture(texture_image);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 return texture_image;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 /* add source list */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 static void
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 addSource(LIST_P list, SOURCE_P src) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 if (list->first == NULL && list->end == NULL) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 list->first = list->end = src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 return;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 list->end->next = src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 list->end = src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 /* compare a with b. Using to compare id */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 /*
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 static int
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 strcmp_a(const char *a, const char *b)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 while (*a && *a++ == *b++);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 if (*a) return 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 return a[-1] > b[-1] ? 1:-1;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 static float
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 get_point(char *id, int position, LIST_P list)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 SOURCE_P cur = list->first;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 for (;cur ; cur=cur->next) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 if (!strcmp_a(id, cur->id)) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 if (cur->count == 0) //alias
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 return get_point(cur->u.alias, position, list);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 float *a = cur->u.array;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 if (position <= cur->count) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 return a[position];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 static SOURCE_P
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 most_match(const char *id , LIST_P list)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 SOURCE_P src = NULL;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 SOURCE_P cur = NULL;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 int tmplength = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 int strlength;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 for (cur=list->first ;cur!=list->end ;cur=cur->next) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 for (strlength=0;id[strlength]==cur->id[strlength];strlength++);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 if (tmplength < strlength) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 tmplength = strlength;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 src = cur;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 }
1378
38c7e8b47c4b minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1376
diff changeset
190 if (src == NULL){
38c7e8b47c4b minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1376
diff changeset
191 fprintf(stderr,"not match");
38c7e8b47c4b minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1376
diff changeset
192 }
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 return src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 void get_texture_image(char *filename, SceneGraphPtr sg, xmlNodePtr cur, TaskManager *manager)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 char image_name[20] = "/tmp/image_XXXXXX";
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 if (filename == NULL || filename[0] == 0) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 return;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 /**
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 * image_name を既に Load していれば何もしない
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 int tex_id;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 /* ball test */
1382
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
207 if (sgid_hash.sg_hash_regist(filename, tex_id) == -1) {
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
208 SDL_Surface *texture_image = load_image(filename, image_name);
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
209 if (texture_image==0) {
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 printf("Can't load image %s\n",filename);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 exit(0);
1382
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
212 }
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 sg->texture_info->texture_id = sg->makeTapestries(manager, texture_image, tex_id);
1382
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
214 tex_id = sg->texture_info->texture_id;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 if (unlink(image_name)) {
1382
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
216 printf("unlink error\n");
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 } else {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 /**
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 * 以前に Load されている Texture を共用
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 sg->texture_info->texture_id = tex_id;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 }
1382
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
224 // 微妙に思う、自分で書き換えた感想 by gongo
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
225 sg->texture_info->t_w = list[tex_id].t_w;
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
226 sg->texture_info->t_h = list[tex_id].t_h;;
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
227 sg->texture_info->pixels_orig = list[tex_id].pixels_orig;
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
228 sg->texture_info->pixels = list[tex_id].pixels;
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
229 sg->texture_info->scale_max = list[tex_id].scale_max;
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
230 sg->texture_info->texture_image = list[tex_id].texture_image;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 void decode_float_array(xmlNodePtr cur,LIST_P list){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 char *id = (char*)xmlGetProp(cur, (xmlChar*)"id");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 src->id = (char*)xmlGetProp(cur, (xmlChar*)"id");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 int count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 src->count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 src->u.array = new float[src->count];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 char *cont =(char*)xmlNodeGetContent(cur);
1384
207e0ed76cf1 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1382
diff changeset
242
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 /* store float inpoint list */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 for (int i = 0; cont != NULL; i++) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 cont = pickup_float(cont, src->u.array+i);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 src->next = NULL;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 addSource(list, src);
1382
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
250 //printf("id:%s count:%d cont:%s\n", id, count, cont);
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 void
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 get_points(xmlNodePtr cur, collada_state *s, TaskManager *manager){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 char *pcont = (char*)xmlNodeGetContent(cur);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 for (int i = 0;i < s->polylist_count;i++){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 s->vcsum += s->vcount[i];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 s->vmember = i;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 s->limit = s->vcsum * 2;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 if (s->texcoord_offset == 2){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 s->limit = s->vcsum * 3;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 s->pcount = new float[s->limit];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 for (int i=0;i<s->limit;i++){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 s->pcount[i] = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 for (int i=0; pcont != NULL; i++) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 pcont = pickup_float(pcont, s->pcount+i);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 SceneGraph*
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 decode_points(collada_state *s, TaskManager *manager, SceneGraphPtr sg){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 int *vertexp;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 vertexp = new int[s->vcsum];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 for (int i=0;i<s->vcsum;i++){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 vertexp[i]=0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 /*
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 * vertex_tableだけはpolygonを作る際にvcountが4の場合重複する点が
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 * 出てくるのでサイズを2倍用意しておく
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 float *vertex_table;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 float *normal_table;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 float *texcoord_table;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 vertex_table = new float[(s->vcsum)*2];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 normal_table = new float[s->vcsum];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 texcoord_table = new float[s->vcsum];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 for (int i=0;i < s->vcsum;i++){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 vertex_table[i] = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 normal_table[i] = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 texcoord_table[i] = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 /**
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 * s->vcsum と s->vertex_float->countの値が違うので大きい方をとりあえず使っておく
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 /* p separate vertex position and nomal position. */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 if (s->texcoord_offset == 2){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 for (int i=0,j=0; i < s->limit; i+=3,j++) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 vertexp[j] = (int)s->pcount[i];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 normal_table[j] = s->normal_float->u.array[(int)s->pcount[i+1]];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[i+2]];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 } else{
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 for (int i=0,j=0; i < s->limit; i+=2,j++) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 vertexp[j] = (int)s->pcount[i];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 normal_table[j] = s->normal_float->u.array[(int)s->pcount[i+1]];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 /* make triangle */
1379
13065ad17328 collada moved but only my mac.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1378
diff changeset
315 int k=0,l=0,size=0;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 for (int i=0;i<s->vmember;i++) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 if (s->vcount[i] == 4) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 vertex_table[k++] = s->vertex_float->u.array[vertexp[l]];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 vertex_table[k++] = s->vertex_float->u.array[vertexp[l+1]];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 vertex_table[k++] = s->vertex_float->u.array[vertexp[l+2]];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 vertex_table[k++] = s->vertex_float->u.array[vertexp[l+1]];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 vertex_table[k++] = s->vertex_float->u.array[vertexp[l+2]];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 vertex_table[k++] = s->vertex_float->u.array[vertexp[l+3]];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 l+=4;
1379
13065ad17328 collada moved but only my mac.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1378
diff changeset
325 size +=2;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 } else if (s->vcount[i]==3) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 vertex_table[k++] = s->vertex_float->u.array[vertexp[l++]];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 vertex_table[k++] = s->vertex_float->u.array[vertexp[l++]];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 vertex_table[k++] = s->vertex_float->u.array[vertexp[l++]];
1379
13065ad17328 collada moved but only my mac.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1378
diff changeset
330 size++;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 /**
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 * (SceneGraph.cc)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 * pickup_normal,pickup_coordinate,pickup_textureの処理
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 * vcsumは頂点の数,countは面の数
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 */
1384
207e0ed76cf1 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1382
diff changeset
339
1379
13065ad17328 collada moved but only my mac.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1378
diff changeset
340 int count = size / 3;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 //polygonの作成
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 sg->pp_num = (count + MAX_SIZE_TRIANGLE - 1) / MAX_SIZE_TRIANGLE;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 sg->pp = new PolygonPack[sg->pp_num];
1379
13065ad17328 collada moved but only my mac.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1378
diff changeset
344 sg->name = s->name;
13065ad17328 collada moved but only my mac.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1378
diff changeset
345 sg->parent_name = "NULL";
13065ad17328 collada moved but only my mac.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1378
diff changeset
346 sg->size = size;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 for (int i = 0;i < sg->pp_num; i++ ){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 PolygonPackPtr pp = sg->pp;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 TrianglePackPtr tri = pp[i].tri;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 // TrianglePack の size のチェック
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 int tri_size = (count < MAX_SIZE_TRIANGLE) ? count : MAX_SIZE_TRIANGLE ;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 pp[i].info.size = tri_size;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 /* default texture peste */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 if (s->images_flag==0) {
1384
207e0ed76cf1 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1382
diff changeset
355 char *default_image = "../Test/xml_file/blend/images/ball.jpg";
207e0ed76cf1 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1382
diff changeset
356 get_texture_image(default_image, sg, (xmlNodePtr)NULL, manager);
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 int k = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 int m = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 int n = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 for (int j = 0; j < tri_size; j++) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 tri[j].normal1.x = normal_table[k++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 tri[j].normal1.y = normal_table[k++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 tri[j].normal1.z = normal_table[k++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 tri[j].normal2.x = normal_table[k++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 tri[j].normal2.y = normal_table[k++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 tri[j].normal2.z = normal_table[k++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 tri[j].normal3.x = normal_table[k++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 tri[j].normal3.y = normal_table[k++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 tri[j].normal3.z = normal_table[k++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 tri[j].ver1.tex_x = texcoord_table[m++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 tri[j].ver1.tex_y = texcoord_table[m++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 tri[j].ver2.tex_x = texcoord_table[m++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 tri[j].ver2.tex_y = texcoord_table[m++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 tri[j].ver3.tex_x = texcoord_table[m++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 tri[j].ver3.tex_y = texcoord_table[m++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
382
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 tri[j].ver1.x = vertex_table[n++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 tri[j].ver1.y = vertex_table[n++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 tri[j].ver1.z = vertex_table[n++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 tri[j].ver2.x = vertex_table[n++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 tri[j].ver2.y = vertex_table[n++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 tri[j].ver2.z = vertex_table[n++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 tri[j].ver3.x = vertex_table[n++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 tri[j].ver3.y = vertex_table[n++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 tri[j].ver3.z = vertex_table[n++];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 sg->c_xyz[0] = sg->c_xyz[1] = sg->c_xyz[2] = 0;
1384
207e0ed76cf1 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1382
diff changeset
399
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 delete []vertexp;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 delete []vertex_table;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 delete []normal_table;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 delete []texcoord_table;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 /* got out of polylist */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 s->polylist = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 return sg;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 static void
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 xml_walk(xmlNodePtr cur, struct collada_state *s, LIST_P list,SceneGraphPtr sg, SceneGraphRoot *root)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 int in_polylist=0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 s->polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 s->polylist=1;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 in_polylist=1;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 s->vertices_id = xmlGetProp(cur, (xmlChar*)"id");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 } else if (!xmlStrcmp(cur->name, (xmlChar*)"library_images")) {
1378
38c7e8b47c4b minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1376
diff changeset
421 s->library_images=1;
38c7e8b47c4b minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1376
diff changeset
422 //library_images is wrote at texture image name. only use one image file
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 } else if (s->library_images && !xmlStrcmp(cur->name, (xmlChar*)"init_from")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 s->tex_picname = (char*)xmlGetProp(cur, (xmlChar*)"init_from");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 get_texture_image(s->tex_picname, sg, cur , root->tmanager);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 s->library_images=0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 s->images_flag=1;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 } else if (!s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"POSITION")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 s->vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"VERTEX")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 s->vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 s->vertex_float = most_match(s->vertices_src+1, list);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"NORMAL")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 s->normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 s->normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 s->normal_float = most_match(s->normal_src+1, list);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"TEXCOORD")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 s->texcoord_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 s->texcoord_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 s->texcoord_float = most_match(s->texcoord_src+1, list);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 char *vcont = (char*)xmlNodeGetContent(cur);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 s->vcount = new float[s->polylist_count];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 for (int i=0; vcont!=NULL; i++) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 /* store vcount list */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 vcont = pickup_float(vcont, s->vcount+i);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 get_points(cur,s,root->tmanager);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 in_polylist = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 decode_float_array(cur,list);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 } else if (!xmlStrcmp(cur->name, (xmlChar*)"node" )) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 s->name = (char*)xmlGetProp(cur, (xmlChar*)"id");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 for (cur=cur->children; cur; cur=cur->next){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 xml_walk(cur,s,list,sg,root);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 void
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 init_list(LIST_P list) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 list->first = NULL;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 list->end = NULL;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
472
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 void
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 SceneGraphRoot::createFromCOLLADAfile(TaskManager *manager, const char *xmlColladafile)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 /*make parse dom*/
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 xmlDocPtr doc;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 xmlNodePtr cur;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
479
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 doc = xmlParseFile(xmlColladafile);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 cur = xmlDocGetRootElement(doc);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
482
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 if (xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 return ;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
486
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 /* node analyze */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 struct collada_state s;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 SceneGraphPtr sg = new SceneGraph(manager);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 for (cur=cur->children; cur; cur=cur->next){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 LIST list;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 init_list(&list);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 xml_walk(cur,&s,&list,sg,this);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 registSceneGraph(decode_points(&s,manager,sg));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 xmlFreeDoc(doc);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 }