31 #ifndef _wrapper_collada_CPP_
32 #define _wrapper_collada_CPP_
55 daeElement* geomLib =
root->add(
"library_geometries");
56 daeElement* geom = geomLib->add(
"geometry");
57 geom->setAttribute(
"id", (polygon_name +
"-geom_id").c_str());
58 daeElement* mesh = geom->add(
"mesh");
61 daeElement* source = mesh->add(
"source");
62 source->setAttribute(
"id", (geom->getAttribute(
"id") +
"-positions").c_str());
63 domFloat_array* fa = daeSafeCast<domFloat_array>(source->add(
"float_array"));
64 fa->setId((source->getAttribute(
"id") +
"-array").c_str());
65 fa->setCount((
int)cloud->points.size()*3);
67 domAccessor* acc = daeSafeCast<domAccessor>(source->add(
"technique_common accessor"));
68 acc->setSource(
makeUriRef(fa->getId()).c_str());
69 std::list<std::string> params = cdom::tokenize(
"X Y Z",
" ");
70 acc->setStride(params.size());
71 acc->setCount((
int)cloud->points.size());
72 for (cdom::tokenIter iter = params.begin(); iter != params.end(); iter++)
74 daeElement* p = acc->add(
"param");
75 p->setAttribute(
"name", iter->c_str());
76 p->setAttribute(
"type",
"float");
80 daeElement* source1 = mesh->add(
"source");
81 source1->setAttribute(
"id", (geom->getAttribute(
"id") +
"-normals").c_str());
82 domFloat_array* fa1 = daeSafeCast<domFloat_array>(source1->add(
"float_array"));
83 fa1->setId((source1->getAttribute(
"id") +
"-array").c_str());
84 fa1->setCount((
int)normal->points.size()*3);
86 domAccessor* acc1 = daeSafeCast<domAccessor>(source1->add(
"technique_common accessor"));
87 acc1->setSource(
makeUriRef(fa1->getId()).c_str());
88 std::list<std::string> params1 = cdom::tokenize(
"X Y Z",
" ");
89 acc1->setStride(params1.size());
90 acc1->setCount((
int)normal->points.size());
91 for (cdom::tokenIter iter = params1.begin(); iter != params1.end(); iter++)
93 daeElement* p = acc1->add(
"param");
94 p->setAttribute(
"name", iter->c_str());
95 p->setAttribute(
"type",
"float");
99 daeElement* vertices = mesh->add(
"vertices");
100 vertices->setAttribute(
"id", (geom->getAttribute(
"id") +
"-vertices").c_str());
101 daeElement* verticesInput = vertices->add(
"input");
102 verticesInput->setAttribute(
"semantic",
"POSITION");
103 verticesInput->setAttribute(
"source",
makeUriRef(geom->getAttribute(
"id") +
"-positions").c_str());
106 domPolygons* polygons = daeSafeCast<domPolygons>(mesh->add(
"polygons"));
107 polygons->setCount(1);
108 polygons->setMaterial(
"mtl");
111 domP* p = daeSafeCast<domP>(polygons->add(
"p"));
112 daeTArray<long long unsigned int> Arr;
113 for (
long long unsigned int i = 0; i < (
long long unsigned int)cloud->points.size(); i++)
121 sprintf(str,
"%f %f %f %f",r,g,b,a);
123 daeElement* effectLib =
root->add(
"library_effects");
124 daeElement* effect = effectLib->add(
"effect");
125 effect->setAttribute(
"id", (polygon_name +
"-effect").c_str());
126 daeElement* profile = effect->add(
"profile_COMMON");
127 daeElement* technique = profile->add(
"technique");
128 technique->setAttribute(
"sid",
"phong1");
129 daeElement* phong = technique->add(
"phong");
130 daeElement* emission = phong->add(
"emission color");
131 emission->setCharData(str);
132 daeElement* ambient = phong->add(
"ambient color");
133 ambient->setCharData(str);
134 daeElement* diffuse = phong->add(
"diffuse color");
135 diffuse->setCharData(str);
136 daeElement* specular = phong->add(
"specular color");
137 specular->setCharData(str);
138 daeElement* shininess = phong->add(
"shininess float");
139 shininess->setCharData(
"2.0");
140 daeElement* reflective = phong->add(
"reflective color");
141 reflective->setCharData(str);
142 daeElement* reflectivity = phong->add(
"reflectivity float");
143 reflectivity->setCharData(
"0.5");
144 daeElement* transparent = phong->add(
"transparent color");
145 transparent->setCharData(str);
146 daeElement* transparency = phong->add(
"transparency float");
147 transparency->setCharData(
"1.0");
150 daeElement* materialLib =
root->add(
"library_materials");
151 daeElement* material = materialLib->add(
"material");
152 material->setAttribute(
"id", (polygon_name +
"-material").c_str());
153 daeElement* instance_effect = material->add(
"instance_effect");
154 instance_effect->setAttribute(
"url", (
"#" + polygon_name +
"-effect").c_str());
162 node->setAttribute(
"id", (
"#" + polygon_name +
"-node").c_str());
163 node->add(
"scale")->setCharData(
"1 1 1");
166 daeElement* instanceGeom = node->add(
"instance_geometry");
167 instanceGeom->setAttribute(
"url",
makeUriRef((polygon_name +
"-geom_id").c_str()).c_str());
170 daeElement* instanceMaterial = instanceGeom->add(
"bind_material technique_common instance_material");
171 instanceMaterial->setAttribute(
"symbol",
"mtl");
172 instanceMaterial->setAttribute(
"target",
makeUriRef((polygon_name +
"-material").c_str()).c_str());
184 template<
typename T_wc>
186 daeTArray<T_wc> result;
187 for (
size_t i = 0; i < count; i++)
188 result.append(rawArray[i]);
193 return std::string(
"#") + id;
197 const std::string& srcID,
198 const std::string& paramNames,
202 daeElement* src = mesh->add(
"source");
205 src->setAttribute(
"id", srcID.c_str());
207 domFloat_array* fa = daeSafeCast<domFloat_array>(src->add(
"float_array"));
209 fa->setId((src->getAttribute(
"id") +
"-array").c_str());
210 fa->setCount(valueCount);
213 domAccessor* acc = daeSafeCast<domAccessor>(src->add(
"technique_common accessor"));
215 acc->setSource(
makeUriRef(fa->getId()).c_str());
217 std::list<std::string> params = cdom::tokenize(paramNames,
" ");
218 acc->setStride(params.size());
219 acc->setCount(valueCount/params.size());
220 for (cdom::tokenIter iter = params.begin(); iter != params.end(); iter++) {
222 daeElement* p = acc->add(
"param");
223 p->setAttribute(
"name", iter->c_str());
224 p->setAttribute(
"type",
"float");
232 daeTArray<double> Arr;
234 for (
size_t i = 0; i < pc->points.size(); i++)
236 Arr.append(pc->points[i].x);
237 Arr.append(pc->points[i].y);
238 Arr.append(pc->points[i].z);
245 const std::string& semantic,
246 const std::string& srcID,
248 domInput_local_offset* input = daeSafeCast<domInput_local_offset>(triangles->add(
"input"));
250 input->setSemantic(semantic.c_str());
251 input->setOffset(offset);
252 domUrifragment source(*triangles->getDAE(), srcID);
253 input->setSource(source);
254 if (semantic ==
"TEXCOORD")
261 daeElement* geomLib = root->add(
"library_geometries");
262 daeElement* geom = geomLib->add(
"geometry");
263 std::string geomID =
"cubeGeom";
264 geom->setAttribute(
"id", geomID.c_str());
265 daeElement* mesh = geom->add(
"mesh");
268 domFloat posArray[] = { -10, -10, -10,
276 int count =
sizeof(posArray)/
sizeof(posArray[0]);
277 my_addSource(mesh, geomID +
"-positions",
"X Y Z", posArray, count);
280 domFloat normalArray[] = { 1, 0, 0,
286 count =
sizeof(normalArray)/
sizeof(normalArray[0]);
287 my_addSource(mesh, geomID +
"-normals",
"X Y Z", normalArray, count);
290 domFloat uvArray[] = { 0, 0,
294 count =
sizeof(uvArray)/
sizeof(uvArray[0]);
295 my_addSource(mesh, geomID +
"-uv",
"S T", uvArray, count);
298 daeElement* vertices = mesh->add(
"vertices");
299 vertices->setAttribute(
"id", (geomID +
"-vertices").c_str());
300 daeElement* verticesInput = vertices->add(
"input");
301 verticesInput->setAttribute(
"semantic",
"POSITION");
302 verticesInput->setAttribute(
"source",
makeUriRef(geomID +
"-positions").c_str());
306 domUint indices[] = { 0, 1, 0, 1, 1, 1, 2, 1, 2,
307 1, 1, 1, 3, 1, 3, 2, 1, 2,
308 0, 2, 0, 4, 2, 1, 1, 2, 2,
309 4, 2, 1, 5, 2, 3, 1, 2, 2,
310 1, 4, 0, 5, 4, 1, 3, 4, 2,
311 5, 4, 1, 7, 4, 3, 3, 4, 2,
312 5, 0, 0, 4, 0, 1, 7, 0, 2,
313 4, 0, 1, 6, 0, 3, 7, 0, 2,
314 4, 5, 0, 0, 5, 1, 6, 5, 2,
315 0, 5, 1, 2, 5, 3, 6, 5, 2,
316 3, 3, 0, 7, 3, 1, 2, 3, 2,
317 7, 3, 1, 6, 3, 3, 2, 3, 2 };
318 count =
sizeof(indices)/
sizeof(indices[0]);
320 domTriangles* triangles = daeSafeCast<domTriangles>(mesh->add(
"triangles"));
321 triangles->setCount(count/(3*3));
322 triangles->setMaterial(
"mtl");
324 my_addInput(triangles,
"VERTEX", geomID +
"-vertices", 0);
325 my_addInput(triangles,
"NORMAL", geomID +
"-normals", 1);
326 my_addInput(triangles,
"TEXCOORD", geomID +
"-uv", 2);
328 domP* p = daeSafeCast<domP>(triangles->add(
"p"));
334 daeElement* imageLib = root->add(
"library_images");
335 daeElement* image = imageLib->add(
"image");
336 image->setAttribute(
"id",
"img");
337 image->setAttribute(
"name",
"myimage");
338 image->setAttribute(
"format",
"png");
339 image->setAttribute(
"height",
"375");
340 image->setAttribute(
"width",
"500");
341 image->setAttribute(
"depth",
"3");
343 image->add(
"init_from")->setCharData(
"../texture.bmp");
351 std::string str(
"file://home/mike/workingcopy/arpua/utils/wrapper_collada/bin/texture1.png");
390 daeElement* effectLib = root->add(
"library_effects");
391 daeElement* effect = effectLib->add(
"effect");
392 effect->setAttribute(
"id",
"cubeEffect");
393 daeElement* profile = effect->add(
"profile_COMMON");
396 daeElement* newparam = profile->add(
"newparam");
397 newparam->setAttribute(
"sid",
"sampler");
400 daeElement* sampler = newparam->add(
"sampler2D");
401 daeSafeCast<domInstance_image>(sampler->add(
"instance_image"))->setUrl(
"#img");
402 sampler->add(
"minfilter")->setCharData(
"LINEAR");
403 sampler->add(
"magfilter")->setCharData(
"LINEAR");
405 daeElement* technique = profile->add(
"technique");
406 technique->setAttribute(
"sid",
"common");
407 daeElement* texture = technique->add(
"phong diffuse texture");
408 texture->setAttribute(
"texture",
"sampler");
409 texture->setAttribute(
"texcoord",
"uv0");
414 daeElement* materialLib = root->add(
"library_materials");
416 daeElement* material = materialLib->add(
"material");
417 material->setAttribute(
"id",
"cubeMaterial");
418 material->add(
"instance_effect")->setAttribute(
"url",
makeUriRef(
"cubeEffect").c_str());
424 daeElement* visualSceneLib = root->add(
"library_visual_scenes");
425 daeElement*
visualScene = visualSceneLib->add(
"visual_scene");
426 visualScene->setAttribute(
"id",
"cubeScene");
429 daeElement* node = visualScene->add(
"node");
430 node->setAttribute(
"id",
"cubeNode");
431 node->add(
"rotate")->setCharData(
"1 0 0 45");
432 node->add(
"translate")->setCharData(
"0 10 0");
435 daeElement* instanceGeom = node->add(
"instance_geometry");
436 instanceGeom->setAttribute(
"url",
makeUriRef(
"cubeGeom").c_str());
439 daeElement* instanceMaterial = instanceGeom->add(
"bind_material technique_common instance_material");
440 instanceMaterial->setAttribute(
"symbol",
"mtl");
441 instanceMaterial->setAttribute(
"target",
makeUriRef(
"cubeMaterial").c_str());
443 daeElement* bindVertexInput = instanceMaterial->add(
"bind_vertex_input");
444 bindVertexInput->setAttribute(
"semantic",
"uv0");
445 bindVertexInput->setAttribute(
"input_semantic",
"TEXCOORD");
446 bindVertexInput->setAttribute(
"input_set",
"0");
449 root->add(
"scene instance_visual_scene")->setAttribute(
"url",
makeUriRef(
"cubeScene").c_str());
void my_addEffect(daeElement *root)
void my_addInput(daeElement *triangles, const std::string &semantic, const std::string &srcID, int offset)
daeTArray< double > pcl_pointcloud_tp_daearray(pcl::PointCloud< pcl::PointXYZ >::Ptr pc)
void my_addGeometry(daeElement *root)
The actual wrapper collada class definition.
void my_addMaterial(daeElement *root)
void my_addImage(daeElement *root)
void add_polygon_fixed_color(std::string polygon_name, pcl::PointCloud< pcl::PointXYZ >::Ptr cloud, pcl::PointCloud< pcl::PointXYZ >::Ptr normal, float r, float g, float b, float a)
void my_addSource(daeElement *mesh, const std::string &srcID, const std::string ¶mNames, domFloat values[], int valueCount)
daeTArray< T_wc > rawArrayToDaeArray(T_wc rawArray[], size_t count)
void my_addVisualScene(daeElement *root)
std::string makeUriRef(const std::string &id)