00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "builderPrim.h"
00020 #include <notify.h>
00021
00022 #ifdef __GNUC__
00023 #pragma implementation
00024 #endif
00025
00026
00027
00028
00029
00030
00031
00032
00033 BuilderPrim &BuilderPrim::
00034 nonindexed_copy(const BuilderPrimTempl<BuilderVertexI> ©,
00035 const BuilderBucket &bucket) {
00036 clear();
00037
00038 set_type(copy.get_type());
00039
00040 if (copy.has_normal()) {
00041 nassertr(bucket.get_normals() != (Normalf *)NULL, *this);
00042 set_normal(bucket.get_normals()[copy.get_normal()]);
00043 }
00044 if (copy.has_color()) {
00045 nassertr(bucket.get_colors() != (Colorf *)NULL, *this);
00046 set_color(bucket.get_colors()[copy.get_color()]);
00047 }
00048 if (copy.has_pixel_size()) {
00049 set_pixel_size(copy.get_pixel_size());
00050 }
00051
00052 int num_verts = copy.get_num_verts();
00053 int i;
00054 for (i = 0; i < num_verts; i++) {
00055 const BuilderVertexI &cv = copy.get_vertex(i);
00056 BuilderVertex v;
00057 if (cv.has_coord()) {
00058 v.set_coord(cv.get_coord_value(bucket));
00059 }
00060
00061 if (cv.has_normal()) {
00062 v.set_normal(cv.get_normal_value(bucket));
00063 }
00064
00065 if (cv.has_texcoord()) {
00066 v.set_texcoord(cv.get_texcoord_value(bucket));
00067 }
00068
00069 if (cv.has_color()) {
00070 v.set_color(cv.get_color_value(bucket));
00071 }
00072
00073 if (cv.has_pixel_size()) {
00074 v.set_pixel_size(cv.get_pixel_size());
00075 }
00076 add_vertex(v);
00077 }
00078 return *this;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 void BuilderPrim::
00095 flatten_vertex_properties() {
00096 int num_verts = get_num_verts();
00097 int i;
00098
00099 if (has_overall_normal()) {
00100 set_normal(get_normal());
00101
00102 for (i = 0; i < num_verts; i++) {
00103 get_vertex(i).clear_normal();
00104 }
00105 }
00106
00107 if (has_overall_color()) {
00108 set_color(get_color());
00109
00110 for (i = 0; i < num_verts; i++) {
00111 get_vertex(i).clear_color();
00112 }
00113 }
00114
00115 if (has_overall_pixel_size()) {
00116 set_pixel_size(get_pixel_size());
00117
00118 for (i = 0; i < num_verts; i++) {
00119 get_vertex(i).clear_pixel_size();
00120 }
00121 }
00122 }
00123
00124
00125
00126
00127
00128
00129
00130 void BuilderPrim::
00131 fill_geom(Geom *geom, const PTA_BuilderV &v_array,
00132 GeomBindType n_attr, const PTA_BuilderN &n_array,
00133 GeomBindType t_attr, const PTA_BuilderTC &t_array,
00134 GeomBindType c_attr, const PTA_BuilderC &c_array,
00135 const BuilderBucket &, int, int, int) {
00136
00137
00138
00139
00140
00141
00142 geom->set_coords((PTA_Vertexf &)v_array);
00143
00144 if (n_attr != G_OFF) {
00145 geom->set_normals((PTA_Normalf &)n_array, n_attr);
00146 }
00147
00148 if (t_attr != G_OFF) {
00149 geom->set_texcoords((PTA_TexCoordf &)t_array, t_attr);
00150 }
00151
00152 if (c_attr != G_OFF) {
00153 geom->set_colors((PTA_Colorf &)c_array, c_attr);
00154 }
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 void BuilderPrimI::
00170 flatten_vertex_properties() {
00171 }
00172
00173
00174
00175
00176
00177
00178
00179 void BuilderPrimI::
00180 fill_geom(Geom *geom, const PTA_ushort &v_array,
00181 GeomBindType n_attr, PTA_ushort n_array,
00182 GeomBindType t_attr, PTA_ushort t_array,
00183 GeomBindType c_attr, PTA_ushort c_array,
00184 const BuilderBucket &bucket,
00185 int num_prims, int num_components, int num_verts) {
00186 PTA_Vertexf v_data = bucket.get_coords();
00187 PTA_Normalf n_data = bucket.get_normals();
00188 PTA_TexCoordf t_data = bucket.get_texcoords();
00189 PTA_Colorf c_data = bucket.get_colors();
00190
00191
00192 if (n_attr == G_OFF) {
00193 n_data = NULL;
00194 n_array = NULL;
00195 }
00196 if (t_attr == G_OFF) {
00197 t_data = NULL;
00198 t_array = NULL;
00199 }
00200 if (c_attr == G_OFF) {
00201 c_data = NULL;
00202 c_array = NULL;
00203 }
00204
00205 int n_len =
00206 (n_attr==G_PER_VERTEX) ? num_verts :
00207 (n_attr==G_PER_COMPONENT) ? num_components :
00208 (n_attr==G_PER_PRIM) ? num_prims :
00209 (n_attr==G_OVERALL) ? 1 : 0;
00210 int t_len =
00211 (t_attr==G_PER_VERTEX) ? num_verts :
00212 (t_attr==G_PER_COMPONENT) ? num_components :
00213 (t_attr==G_PER_PRIM) ? num_prims :
00214 (t_attr==G_OVERALL) ? 1 : 0;
00215 int c_len =
00216 (c_attr==G_PER_VERTEX) ? num_verts :
00217 (c_attr==G_PER_COMPONENT) ? num_components :
00218 (c_attr==G_PER_PRIM) ? num_prims :
00219 (c_attr==G_OVERALL) ? 1 : 0;
00220
00221
00222 if (n_attr != G_OFF &&
00223 memcmp(v_array, n_array, sizeof(ushort) * n_len)==0) {
00224 n_array = v_array;
00225 }
00226 if (t_attr != G_OFF) {
00227 if (memcmp(v_array, t_array, sizeof(ushort) * t_len)==0) {
00228 t_array = v_array;
00229 } else if (t_len <= n_len &&
00230 memcmp(n_array, t_array, sizeof(ushort) * t_len)==0) {
00231 t_array = n_array;
00232 }
00233 }
00234 if (c_attr != G_OFF) {
00235 if (memcmp(v_array, c_array, sizeof(ushort) * c_len)==0) {
00236 c_array = v_array;
00237 } else if (c_len <= n_len &&
00238 memcmp(n_array, c_array, sizeof(ushort) * c_len)==0) {
00239 c_array = n_array;
00240 } else if (c_len <= t_len &&
00241 memcmp(t_array, c_array, sizeof(ushort) * c_len)==0) {
00242 c_array = t_array;
00243 }
00244 }
00245
00246 geom->set_coords(v_data, v_array);
00247
00248 if (n_attr != G_OFF) {
00249 geom->set_normals(n_data, n_attr, n_array);
00250 }
00251
00252 if (t_attr != G_OFF) {
00253 geom->set_texcoords(t_data, t_attr, t_array);
00254 }
00255
00256 if (c_attr != G_OFF) {
00257 geom->set_colors(c_data, c_attr, c_array);
00258 }
00259 }
00260