annotate Renderer/Engine/Collada.cc @ 1396:ad841dcdbe67 draft

collada moved. But only cube.
author e095732 <e095732@ie.u-ryukyu.ac.jp>
date Tue, 31 Jan 2012 17:10:53 +0900
parents 555d2a31cf0c
children e19296785c07
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;
1390
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
51 vtable_size =0;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
53 images_flag=0;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 int polylist;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 int library_images;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 xmlChar *vertices_id;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 char *vertex_src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 int vertex_offset;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 int vertex_count;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 char *normal_src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 int normal_offset;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 int normal_count;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 char *texcoord_src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 int texcoord_offset;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 int texcoord_count;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 float *vcount;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 float *pcount;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 SOURCE_P normal_float;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 SOURCE_P vertex_float;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 SOURCE_P texcoord_float;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 char *vertices_src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 int polylist_count;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 char *name;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 char *tex_picname;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 int images_flag;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 int vcsum;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 int limit;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 int vmember;
1390
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
89 int vtable_size;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 };
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 /*static const char*
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 get_property(const char *name, xmlNodePtr cur){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 xmlAttr *p=cur->properties;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 if (p==0) return "";
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 for ( ;p; p=p->next) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 if ( xmlStrcmp(p->name, (xmlChar*)name) !=0 ) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 xmlNode* n=p->children;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 if ( n==NULL ) return "";
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 const char * v=(const char*)n->content;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 if ( v==NULL ) return "";
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 return v;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 }
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 return "";
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 }*/
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 SDL_Surface*
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 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
110 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 int alpha_black = is_bmp(file_name);
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 * image を 32bit(RGBA) に変換する
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 SDL_Surface *texture_image = IMG_Load(file_name);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 if (!texture_image) return 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 SDL_Surface *tmpImage
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 = SDL_CreateRGBSurface(SDL_HWSURFACE, texture_image->w,
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 texture_image->h, 32, redMask,
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 greenMask, blueMask, alphaMask);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 //= SDL_CreateRGBSurface(SDL_HWSURFACE, 0,
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 // 0, 32, redMask,
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 // greenMask, blueMask, alphaMask);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 SDL_Surface *converted;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 converted = SDL_ConvertSurface(texture_image, tmpImage->format,
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 SDL_HWSURFACE);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 //SDL_SetAlpha(converted, 0, 0);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 if (converted != NULL) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 SDL_FreeSurface(texture_image);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 texture_image = converted;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 if (alpha_black) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 make_black_alpha(texture_image);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 // this->gl_tex = SDL_GL_LoadTexture(texture_image);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 return texture_image;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 /* add source list */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 static void
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 addSource(LIST_P list, SOURCE_P src) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 if (list->first == NULL && list->end == NULL) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 list->first = list->end = src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 return;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 list->end->next = src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 list->end = src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 }
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 /* compare a with b. Using to compare id */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 /*
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 static int
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 strcmp_a(const char *a, const char *b)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 while (*a && *a++ == *b++);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 if (*a) return 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 return a[-1] > b[-1] ? 1:-1;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 static float
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 get_point(char *id, int position, LIST_P list)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 SOURCE_P cur = list->first;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 for (;cur ; cur=cur->next) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 if (!strcmp_a(id, cur->id)) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 if (cur->count == 0) //alias
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 return get_point(cur->u.alias, position, list);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 float *a = cur->u.array;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 if (position <= cur->count) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 return a[position];
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 */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 static SOURCE_P
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 most_match(const char *id , LIST_P list)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 SOURCE_P src = NULL;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 SOURCE_P cur = NULL;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 int tmplength = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 int strlength;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 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
186 for (strlength=0;id[strlength]==cur->id[strlength];strlength++);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 if (tmplength < strlength) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 tmplength = strlength;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 src = cur;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 }
1378
38c7e8b47c4b minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1376
diff changeset
192 if (src == NULL){
38c7e8b47c4b minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1376
diff changeset
193 fprintf(stderr,"not match");
38c7e8b47c4b minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1376
diff changeset
194 }
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 return src;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 }
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 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
199 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 char image_name[20] = "/tmp/image_XXXXXX";
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 if (filename == NULL || filename[0] == 0) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 return;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 }
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 * image_name を既に Load していれば何もしない
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 */
1391
1ea6e4eb2b0a remove error.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1390
diff changeset
207 int tex_id;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 /* ball test */
1382
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
209 if (sgid_hash.sg_hash_regist(filename, tex_id) == -1) {
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
210 SDL_Surface *texture_image = load_image(filename, image_name);
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
211 if (texture_image==0) {
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 printf("Can't load image %s\n",filename);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 exit(0);
1382
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
214 }
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 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
216 tex_id = sg->texture_info->texture_id;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 if (unlink(image_name)) {
1382
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
218 printf("unlink error\n");
1376
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 } else {
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 * 以前に Load されている Texture を共用
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 sg->texture_info->texture_id = tex_id;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 }
1382
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
226 // 微妙に思う、自分で書き換えた感想 by gongo
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
227 sg->texture_info->t_w = list[tex_id].t_w;
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
228 sg->texture_info->t_h = list[tex_id].t_h;;
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
229 sg->texture_info->pixels_orig = list[tex_id].pixels_orig;
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
230 sg->texture_info->pixels = list[tex_id].pixels;
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
231 sg->texture_info->scale_max = list[tex_id].scale_max;
de990f3e0a21 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1379
diff changeset
232 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
233 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 void decode_float_array(xmlNodePtr cur,LIST_P list){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 SOURCE_P src = (SOURCE_P)malloc(sizeof(SOURCE));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 src->id = (char*)xmlGetProp(cur, (xmlChar*)"id");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
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;
1390
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
260 if (s->vcount[i]==4){
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
261 s->vtable_size +=6;
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
262 } else {
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
263 s->vtable_size +=3;
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
264 }
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 s->limit = s->vcsum * 2;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 if (s->texcoord_offset == 2){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 s->limit = s->vcsum * 3;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 s->pcount = new float[s->limit];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 for (int i=0;i<s->limit;i++){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 s->pcount[i] = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 for (int i=0; pcont != NULL; i++) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 pcont = pickup_float(pcont, s->pcount+i);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 SceneGraph*
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 decode_points(collada_state *s, TaskManager *manager, SceneGraphPtr sg){
1390
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
280
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 /*
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 * vertex_tableだけはpolygonを作る際にvcountが4の場合重複する点が
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 * 出てくるのでサイズを2倍用意しておく
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 float *vertex_table;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 float *normal_table;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 float *texcoord_table;
1390
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
288 vertex_table = new float[s->vtable_size*3];
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
289 normal_table = new float[s->vtable_size*3];
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
290 texcoord_table = new float[s->vtable_size*2];
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
291 bzero(vertex_table,sizeof(float)*s->vtable_size*3);
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
292 bzero(normal_table,sizeof(float)*s->vtable_size*3);
b4f6539fecf6 delete vertexp.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1385
diff changeset
293 bzero(texcoord_table,sizeof(float)*s->vtable_size*2);
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
295 /* p separate vertex position and nomal position. */
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 /* make triangle */
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
297 int k=0,j=0,l=0,count=0;
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
298 if (s->texcoord_offset == 2){
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
299 for (int i=0;i<s->polylist_count;i++) {
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
300 if (s->vcount[i] == 4) {
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
301 vertex_table[k] = s->vertex_float->u.array[(int)s->pcount[l]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
302 vertex_table[k+1] = s->vertex_float->u.array[(int)s->pcount[l]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
303 vertex_table[k+2] = s->vertex_float->u.array[(int)s->pcount[l]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
304 vertex_table[k+3] = s->vertex_float->u.array[(int)s->pcount[l+3]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
305 vertex_table[k+4] = s->vertex_float->u.array[(int)s->pcount[l+3]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
306 vertex_table[k+5] = s->vertex_float->u.array[(int)s->pcount[l+3]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
307 vertex_table[k+6] = s->vertex_float->u.array[(int)s->pcount[l+6]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
308 vertex_table[k+7] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
309 vertex_table[k+8] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
310 vertex_table[k+9] = s->vertex_float->u.array[(int)s->pcount[l+6]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
311 vertex_table[k+10] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
312 vertex_table[k+11] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
313 vertex_table[k+12] = s->vertex_float->u.array[(int)s->pcount[l+9]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
314 vertex_table[k+13] = s->vertex_float->u.array[(int)s->pcount[l+9]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
315 vertex_table[k+14] = s->vertex_float->u.array[(int)s->pcount[l+9]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
316 vertex_table[k+15] = s->vertex_float->u.array[(int)s->pcount[l]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
317 vertex_table[k+16] = s->vertex_float->u.array[(int)s->pcount[l]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
318 vertex_table[k+17] = s->vertex_float->u.array[(int)s->pcount[l]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
319
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
320 normal_table[k] = s->normal_float->u.array[(int)s->pcount[l+1]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
321 normal_table[k+1] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
322 normal_table[k+2] = s->normal_float->u.array[(int)s->pcount[l+1]*3*2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
323 normal_table[k+3] = s->normal_float->u.array[(int)s->pcount[l+4]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
324 normal_table[k+4] = s->normal_float->u.array[(int)s->pcount[l+4]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
325 normal_table[k+5] = s->normal_float->u.array[(int)s->pcount[l+4]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
326 normal_table[k+6] = s->normal_float->u.array[(int)s->pcount[l+7]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
327 normal_table[k+7] = s->normal_float->u.array[(int)s->pcount[l+7]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
328 normal_table[k+8] = s->normal_float->u.array[(int)s->pcount[l+7]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
329 normal_table[k+9] = s->normal_float->u.array[(int)s->pcount[l+7]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
330 normal_table[k+10] = s->normal_float->u.array[(int)s->pcount[l+7]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
331 normal_table[k+11] = s->normal_float->u.array[(int)s->pcount[l+7]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
332 normal_table[k+12] = s->normal_float->u.array[(int)s->pcount[l+10]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
333 normal_table[k+13] = s->normal_float->u.array[(int)s->pcount[l+10]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
334 normal_table[k+14] = s->normal_float->u.array[(int)s->pcount[l+10]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
335 normal_table[k+15] = s->normal_float->u.array[(int)s->pcount[l+1]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
336 normal_table[k+16] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
337 normal_table[k+17] = s->normal_float->u.array[(int)s->pcount[l+1]*3+2];
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
338
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
339 texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[l+2]*2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
340 texcoord_table[j+1] = s->texcoord_float->u.array[(int)s->pcount[l+2]*2+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
341 texcoord_table[j+2] = s->texcoord_float->u.array[(int)s->pcount[l+5]*2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
342 texcoord_table[j+3] = s->texcoord_float->u.array[(int)s->pcount[l+5]*2+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
343 texcoord_table[j+4] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
344 texcoord_table[j+5] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
345 texcoord_table[j+6] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
346 texcoord_table[j+7] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
347 l+=12;
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
348 j+=8;
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
349 k+=18;
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
350 count +=2;
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
351 } else if (s->vcount[i]==3) {
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
352 vertex_table[k] = s->vertex_float->u.array[(int)s->pcount[l]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
353 vertex_table[k+1] = s->vertex_float->u.array[(int)s->pcount[l]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
354 vertex_table[k+2] = s->vertex_float->u.array[(int)s->pcount[l]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
355 vertex_table[k+3] = s->vertex_float->u.array[(int)s->pcount[l+3]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
356 vertex_table[k+4] = s->vertex_float->u.array[(int)s->pcount[l+3]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
357 vertex_table[k+5] = s->vertex_float->u.array[(int)s->pcount[l+3]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
358 vertex_table[k+6] = s->vertex_float->u.array[(int)s->pcount[l+6]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
359 vertex_table[k+7] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
360 vertex_table[k+8] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+2];
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
361
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
362 normal_table[k] = s->normal_float->u.array[(int)s->pcount[l+1]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
363 normal_table[k+1] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
364 normal_table[k+2] = s->normal_float->u.array[(int)s->pcount[l+1]*3*2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
365 normal_table[k+3] = s->normal_float->u.array[(int)s->pcount[l+4]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
366 normal_table[k+4] = s->normal_float->u.array[(int)s->pcount[l+4]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
367 normal_table[k+5] = s->normal_float->u.array[(int)s->pcount[l+4]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
368 normal_table[k+6] = s->normal_float->u.array[(int)s->pcount[l+7]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
369 normal_table[k+7] = s->normal_float->u.array[(int)s->pcount[l+7]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
370 normal_table[k+8] = s->normal_float->u.array[(int)s->pcount[l+7]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
371
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
372 texcoord_table[j] = s->texcoord_float->u.array[(int)s->pcount[l+2]*2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
373 texcoord_table[j+1] = s->texcoord_float->u.array[(int)s->pcount[l+2]*2+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
374 texcoord_table[j+2] = s->texcoord_float->u.array[(int)s->pcount[l+5]*2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
375 texcoord_table[j+3] = s->texcoord_float->u.array[(int)s->pcount[l+5]*2+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
376 texcoord_table[j+4] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
377 texcoord_table[j+5] = s->texcoord_float->u.array[(int)s->pcount[l+8]*2+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
378 l+=9;
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
379 j+=6;
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
380 k+=9;
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
381 count++;
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
382 }
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
383 }
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
384 }else{
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
385 for (int i=0;i<s->polylist_count;i++) {
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
386 if (s->vcount[i] == 4) {
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
387 vertex_table[k] = s->vertex_float->u.array[(int)s->pcount[l]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
388 vertex_table[k+1] = s->vertex_float->u.array[(int)s->pcount[l]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
389 vertex_table[k+2] = s->vertex_float->u.array[(int)s->pcount[l]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
390 vertex_table[k+3] = s->vertex_float->u.array[(int)s->pcount[l+2]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
391 vertex_table[k+4] = s->vertex_float->u.array[(int)s->pcount[l+2]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
392 vertex_table[k+5] = s->vertex_float->u.array[(int)s->pcount[l+2]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
393 vertex_table[k+6] = s->vertex_float->u.array[(int)s->pcount[l+4]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
394 vertex_table[k+7] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
395 vertex_table[k+8] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
396 vertex_table[k+9] = s->vertex_float->u.array[(int)s->pcount[l+4]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
397 vertex_table[k+10] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
398 vertex_table[k+11] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
399 vertex_table[k+12] = s->vertex_float->u.array[(int)s->pcount[l+6]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
400 vertex_table[k+13] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
401 vertex_table[k+14] = s->vertex_float->u.array[(int)s->pcount[l+6]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
402 vertex_table[k+15] = s->vertex_float->u.array[(int)s->pcount[l]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
403 vertex_table[k+16] = s->vertex_float->u.array[(int)s->pcount[l]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
404 vertex_table[k+17] = s->vertex_float->u.array[(int)s->pcount[l]*3+2];
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
405
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
406 normal_table[k] = s->normal_float->u.array[(int)s->pcount[l+1]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
407 normal_table[k+1] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
408 normal_table[k+2] = s->normal_float->u.array[(int)s->pcount[l+1]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
409 normal_table[k+3] = s->normal_float->u.array[(int)s->pcount[l+3]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
410 normal_table[k+4] = s->normal_float->u.array[(int)s->pcount[l+3]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
411 normal_table[k+5] = s->normal_float->u.array[(int)s->pcount[l+3]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
412 normal_table[k+6] = s->normal_float->u.array[(int)s->pcount[l+5]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
413 normal_table[k+7] = s->normal_float->u.array[(int)s->pcount[l+5]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
414 normal_table[k+8] = s->normal_float->u.array[(int)s->pcount[l+5]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
415 normal_table[k+9] = s->normal_float->u.array[(int)s->pcount[l+5]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
416 normal_table[k+10] = s->normal_float->u.array[(int)s->pcount[l+5]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
417 normal_table[k+11] = s->normal_float->u.array[(int)s->pcount[l+5]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
418 normal_table[k+12] = s->normal_float->u.array[(int)s->pcount[l+7]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
419 normal_table[k+13] = s->normal_float->u.array[(int)s->pcount[l+7]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
420 normal_table[k+14] = s->normal_float->u.array[(int)s->pcount[l+7]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
421 normal_table[k+15] = s->normal_float->u.array[(int)s->pcount[l+1]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
422 normal_table[k+16] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
423 normal_table[k+17] = s->normal_float->u.array[(int)s->pcount[l+1]*3+2];
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
424
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
425 printf ("%f, %f, %f\n",vertex_table[k],vertex_table[k+1],vertex_table[k+2]);
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
426 printf ("%f, %f, %f\n",vertex_table[k+3],vertex_table[k+4],vertex_table[k+5]);
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
427 printf ("%f, %f, %f\n",vertex_table[k+6],vertex_table[k+7],vertex_table[k+8]);
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
428 printf ("%f, %f, %f\n",vertex_table[k+9],vertex_table[k+10],vertex_table[k+11]);
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
429 printf ("%f, %f, %f\n",vertex_table[k+12],vertex_table[k+13],vertex_table[k+14]);
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
430 printf ("%f, %f, %f\n",vertex_table[k+15],vertex_table[k+16],vertex_table[k+17]);
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
431 l+=8;
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
432 k+=18;
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
433 count +=2;
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
434 } else if (s->vcount[i]==3) {
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
435 vertex_table[k] = s->vertex_float->u.array[(int)s->pcount[l]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
436 vertex_table[k+1] = s->vertex_float->u.array[(int)s->pcount[l]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
437 vertex_table[k+2] = s->vertex_float->u.array[(int)s->pcount[l]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
438 vertex_table[k+3] = s->vertex_float->u.array[(int)s->pcount[l+2]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
439 vertex_table[k+4] = s->vertex_float->u.array[(int)s->pcount[l+2]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
440 vertex_table[k+5] = s->vertex_float->u.array[(int)s->pcount[l+2]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
441 vertex_table[k+6] = s->vertex_float->u.array[(int)s->pcount[l+4]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
442 vertex_table[k+7] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
443 vertex_table[k+8] = s->vertex_float->u.array[(int)s->pcount[l+4]*3+2];
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
444
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
445 normal_table[k] = s->normal_float->u.array[(int)s->pcount[l+1]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
446 normal_table[k+1] = s->normal_float->u.array[(int)s->pcount[l+1]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
447 normal_table[k+2] = s->normal_float->u.array[(int)s->pcount[l+1]*3+22];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
448 normal_table[k+3] = s->normal_float->u.array[(int)s->pcount[l+3]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
449 normal_table[k+4] = s->normal_float->u.array[(int)s->pcount[l+3]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
450 normal_table[k+5] = s->normal_float->u.array[(int)s->pcount[l+3]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
451 normal_table[k+6] = s->normal_float->u.array[(int)s->pcount[l+5]*3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
452 normal_table[k+7] = s->normal_float->u.array[(int)s->pcount[l+5]*3+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
453 normal_table[k+8] = s->normal_float->u.array[(int)s->pcount[l+5]*3+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
454
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
455 printf ("%f, %f, %f\n",vertex_table[k],vertex_table[k+1],vertex_table[k+2]);
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
456 printf ("%f, %f, %f\n",vertex_table[k+3],vertex_table[k+4],vertex_table[k+5]);
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
457 printf ("%f, %f, %f\n",vertex_table[k+6],vertex_table[k+7],vertex_table[k+8]);
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
458 l+=6;
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
459 k+=9;
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
460 count++;
1392
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
461 }
555d2a31cf0c collada moved
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1391
diff changeset
462 }
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
465
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
466
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
467
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
468
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 /**
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 * (SceneGraph.cc)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 * pickup_normal,pickup_coordinate,pickup_textureの処理
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
472 * sg->sizeは頂点の数,countは面の数
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 */
1384
207e0ed76cf1 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1382
diff changeset
474
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 //polygonの作成
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 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
477 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
478 sg->name = s->name;
13065ad17328 collada moved but only my mac.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1378
diff changeset
479 sg->parent_name = "NULL";
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
480 sg->size = count*3;
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 for (int i = 0;i < sg->pp_num; i++ ){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 PolygonPackPtr pp = sg->pp;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 TrianglePackPtr tri = pp[i].tri;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 // TrianglePack の size のチェック
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 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
486 pp[i].info.size = tri_size;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 /* default texture peste */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 if (s->images_flag==0) {
1384
207e0ed76cf1 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1382
diff changeset
489 char *default_image = "../Test/xml_file/blend/images/ball.jpg";
207e0ed76cf1 minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1382
diff changeset
490 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
491 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 int k = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 int m = 0;
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
494 for (int j = 0; j < tri_size; j++,k+=9,m+=6) {
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
495 tri[j].ver1.x = vertex_table[k];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
496 tri[j].ver1.y = vertex_table[k+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
497 tri[j].ver1.z = vertex_table[k+2];
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
498
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
499 tri[j].ver2.x = vertex_table[k+3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
500 tri[j].ver2.y = vertex_table[k+4];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
501 tri[j].ver2.z = vertex_table[k+5];
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
502
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
503 tri[j].ver3.x = vertex_table[k+6];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
504 tri[j].ver3.y = vertex_table[k+7];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
505 tri[j].ver3.z = vertex_table[k+8];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
506
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
507 tri[j].normal1.x = normal_table[k];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
508 tri[j].normal1.y = normal_table[k+1];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
509 tri[j].normal1.z = normal_table[k+2];
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
511 tri[j].normal2.x = normal_table[k+3];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
512 tri[j].normal2.y = normal_table[k+4];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
513 tri[j].normal2.z = normal_table[k+5];
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
514
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
515 tri[j].normal3.x = normal_table[k+6];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
516 tri[j].normal3.y = normal_table[k+7];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
517 tri[j].normal3.z = normal_table[k+8];
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
518
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
519 tri[j].ver1.tex_x = texcoord_table[m];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
520 tri[j].ver1.tex_y = texcoord_table[m+1];
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
521
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
522 tri[j].ver2.tex_x = texcoord_table[m+2];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
523 tri[j].ver2.tex_y = texcoord_table[m+3];
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
524
1396
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
525 tri[j].ver3.tex_x = texcoord_table[m+4];
ad841dcdbe67 collada moved. But only cube.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1392
diff changeset
526 tri[j].ver3.tex_y = texcoord_table[m+5];
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
527
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
529
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 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
532
1376
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 delete []vertex_table;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 delete []normal_table;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 delete []texcoord_table;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
536
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 /* got out of polylist */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 s->polylist = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 return sg;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
541
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 static void
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 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
544 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 int in_polylist=0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 if (!xmlStrcmp(cur->name, (xmlChar*)"polylist")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 s->polylist_count = atoi((char*)xmlGetProp(cur, (xmlChar*)"count"));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 s->polylist=1;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 in_polylist=1;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vertices")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 s->vertices_id = xmlGetProp(cur, (xmlChar*)"id");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 } else if (!xmlStrcmp(cur->name, (xmlChar*)"library_images")) {
1378
38c7e8b47c4b minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1376
diff changeset
553 s->library_images=1;
38c7e8b47c4b minor changes.
e095732 <e095732@ie.u-ryukyu.ac.jp>
parents: 1376
diff changeset
554 //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
555 } 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
556 s->tex_picname = (char*)xmlGetProp(cur, (xmlChar*)"init_from");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 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
558 s->library_images=0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 s->images_flag=1;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 } else if (!s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"POSITION")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 s->vertices_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 } else if (s->polylist && !xmlStrcmp(cur->name, (xmlChar*)"input")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
566 char *semantic = (char*)xmlGetProp(cur, (xmlChar*)"semantic");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
567 if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"VERTEX")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
568 s->vertex_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 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
570 } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"NORMAL")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 s->normal_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 s->normal_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 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
574 } else if (!xmlStrcmp((xmlChar*)semantic, (xmlChar*)"TEXCOORD")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 s->texcoord_src = (char*)xmlGetProp(cur, (xmlChar*)"source");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 s->texcoord_offset = atoi((char*)xmlGetProp(cur, (xmlChar*)"offset"));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 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
578 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 } else if (!xmlStrcmp(cur->name, (xmlChar*)"vcount")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 char *vcont = (char*)xmlNodeGetContent(cur);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 s->vcount = new float[s->polylist_count];
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 for (int i=0; vcont!=NULL; i++) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 /* store vcount list */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 vcont = pickup_float(vcont, s->vcount+i);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 } else if (!xmlStrcmp(cur->name, (xmlChar*)"p")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 get_points(cur,s,root->tmanager);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 in_polylist = 0;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 } else if (!xmlStrcmp(cur->name, (xmlChar*)"float_array")) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 decode_float_array(cur,list);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 } else if (!xmlStrcmp(cur->name, (xmlChar*)"node" )) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 s->name = (char*)xmlGetProp(cur, (xmlChar*)"id");
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 for (cur=cur->children; cur; cur=cur->next){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 xml_walk(cur,s,list,sg,root);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 void
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 init_list(LIST_P list) {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 list->first = NULL;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 list->end = NULL;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
603
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
604
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 void
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 SceneGraphRoot::createFromCOLLADAfile(TaskManager *manager, const char *xmlColladafile)
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 {
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 /*make parse dom*/
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 xmlDocPtr doc;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 xmlNodePtr cur;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
611
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 doc = xmlParseFile(xmlColladafile);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 cur = xmlDocGetRootElement(doc);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
614
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 if (xmlStrcmp(cur->name, (xmlChar*)"COLLADA")){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 return ;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
618
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 /* node analyze */
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 struct collada_state s;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 SceneGraphPtr sg = new SceneGraph(manager);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 for (cur=cur->children; cur; cur=cur->next){
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
623 LIST list;
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 init_list(&list);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 xml_walk(cur,&s,&list,sg,this);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 }
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 registSceneGraph(decode_points(&s,manager,sg));
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 xmlFreeDoc(doc);
ae0398dd61d2 add Collada.cc
Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 }