40 const char* VL_NO_MATERIAL_SPECIFIED =
"<VL_NO_MATERIAL_SPECIFIED>";
41 const char* VL_DEFAULT_LIGHT =
"<VL_DEFAULT_LIGHT>";
46 const char* mSemanticString;
84 mDefaultFX->setObjectName( VL_NO_MATERIAL_SPECIFIED );
87 mDefaultFX->shader()->gocMaterial()->setFlatColor( vl::fuchsia );
103 for(
size_t iinp=0; iinp<input_arr.getCount(); ++iinp)
105 domInputLocalOffsetRef input = input_arr.get(iinp);
111 for(
size_t ivert=0; ivert<vertex_inputs.size(); ++ivert)
114 dae_input->
mSemantic = vertex_inputs[ivert]->mSemantic;
115 dae_input->
mSource = vertex_inputs[ivert]->mSource;
116 dae_input->
mOffset = (size_t)input->getOffset();
117 dae_input->
mSet = (size_t)input->getSet();
118 dae_primitive->
mChannels.push_back(dae_input);
132 dae_input->
mOffset = (size_t)input->getOffset();
133 dae_input->
mSet = (size_t)input->getSet();
137 dae_primitive->
mChannels.push_back( dae_input );
152 std::map< daeElementRef, ref<Dae::Mesh> >::iterator it =
mMeshes.find( geometry );
156 if (!geometry->getChild(
"mesh"))
159 domMesh* mesh =
static_cast<domMesh*
>(geometry->getChild(
"mesh"));
166 domVerticesRef vertices = mesh->getVertices();
167 domInputLocal_Array input_array = vertices->getInput_array();
168 for(
size_t i=0; i<input_array.getCount(); ++i)
194 domTriangles_Array triangles_arr = mesh->getTriangles_array();
195 for(
size_t itri=0; itri< triangles_arr.getCount(); ++itri)
197 domTrianglesRef triangles = triangles_arr.get(itri);
202 dae_primitive->
mCount = (size_t)triangles->getCount();
205 domInputLocalOffset_Array input_arr = triangles->getInput_array();
209 dae_primitive->
mP.push_back( triangles->getP() );
212 dae_primitive->
mMaterial = triangles->getMaterial() ? triangles->getMaterial() : VL_NO_MATERIAL_SPECIFIED;
219 domTrifans_Array trifan_arr = mesh->getTrifans_array();
220 for(
size_t itri=0; itri< trifan_arr.getCount(); ++itri)
222 domTrifansRef trifan = trifan_arr.get(itri);
227 dae_primitive->
mCount = (size_t)trifan->getCount();
230 domInputLocalOffset_Array input_arr = trifan->getInput_array();
234 for(
size_t ip=0; ip<trifan->getP_array().getCount(); ++ip)
235 dae_primitive->
mP.push_back( trifan->getP_array().get(ip) );
238 dae_primitive->
mMaterial = trifan->getMaterial() ? trifan->getMaterial() : VL_NO_MATERIAL_SPECIFIED;
245 domTristrips_Array tristrip_arr = mesh->getTristrips_array();
246 for(
size_t itri=0; itri< tristrip_arr.getCount(); ++itri)
248 domTristripsRef tristrip = tristrip_arr.get(itri);
253 dae_primitive->
mCount = (size_t)tristrip->getCount();
256 domInputLocalOffset_Array input_arr = tristrip->getInput_array();
260 for(
size_t ip=0; ip<tristrip->getP_array().getCount(); ++ip)
261 dae_primitive->
mP.push_back( tristrip->getP_array().get(ip) );
264 dae_primitive->
mMaterial = tristrip->getMaterial() ? tristrip->getMaterial() : VL_NO_MATERIAL_SPECIFIED;
271 domPolygons_Array polygon_arr = mesh->getPolygons_array();
272 for(
size_t itri=0; itri< polygon_arr.getCount(); ++itri)
274 domPolygonsRef polygon = polygon_arr.get(itri);
279 dae_primitive->
mCount = (size_t)polygon->getCount();
282 domInputLocalOffset_Array input_arr = polygon->getInput_array();
286 for(
size_t ip=0; ip<polygon->getP_array().getCount(); ++ip)
287 dae_primitive->
mP.push_back( polygon->getP_array().get(ip) );
290 dae_primitive->
mMaterial = polygon->getMaterial() ? polygon->getMaterial() : VL_NO_MATERIAL_SPECIFIED;
297 domPolylist_Array polylist_arr = mesh->getPolylist_array();
298 for(
size_t itri=0; itri< polylist_arr.getCount(); ++itri)
300 domPolylistRef polylist = polylist_arr.get(itri);
305 dae_primitive->
mCount = (size_t)polylist->getVcount()->getValue().getCount();
308 domInputLocalOffset_Array input_arr = polylist->getInput_array();
313 for(
size_t ivc=0; ivc<polylist->getVcount()->getValue().getCount(); ++ivc)
315 domPRef p =
static_cast<domP*
>(domP::create(
mDAE).cast());
316 VL_CHECK(p->typeID() == domP::ID());
317 dae_primitive->
mP.push_back( p );
318 size_t vcount = (size_t)polylist->getVcount()->getValue()[ivc];
319 p->getValue().setCount(vcount * dae_primitive->
mIndexStride);
320 for(
size_t i=0; i<p->getValue().getCount(); ++i)
321 p->getValue().set(i, polylist->getP()->getValue()[ip++]);
325 dae_primitive->
mMaterial = polylist->getMaterial() ? polylist->getMaterial() : VL_NO_MATERIAL_SPECIFIED;
332 domLinestrips_Array linestrip_arr = mesh->getLinestrips_array();
333 for(
size_t itri=0; itri< linestrip_arr.getCount(); ++itri)
335 domLinestripsRef linestrip = linestrip_arr.get(itri);
340 dae_primitive->
mCount = (size_t)linestrip->getCount();
343 domInputLocalOffset_Array input_arr = linestrip->getInput_array();
347 for(
size_t ip=0; ip<linestrip->getP_array().getCount(); ++ip)
348 dae_primitive->
mP.push_back( linestrip->getP_array().get(ip) );
351 dae_primitive->
mMaterial = linestrip->getMaterial() ? linestrip->getMaterial() : VL_NO_MATERIAL_SPECIFIED;
358 domLines_Array line_arr = mesh->getLines_array();
359 for(
size_t itri=0; itri< line_arr.getCount(); ++itri)
361 domLinesRef line = line_arr.get(itri);
366 dae_primitive->
mCount = (size_t)line->getCount();
369 domInputLocalOffset_Array input_arr = line->getInput_array();
373 dae_primitive->
mP.push_back( line->getP() );
376 dae_primitive->
mMaterial = line->getMaterial() ? line->getMaterial() : VL_NO_MATERIAL_SPECIFIED;
387 std::map< daeElementRef, ref<Dae::Source> >::iterator it =
mSources.find(source_el);
389 return it->second.get();
392 VL_CHECK(source_el->typeID() == domSource::ID())
393 domSourceRef source = static_cast<domSource*>(source_el);
395 domSource::domTechnique_commonRef tech_common = source->getTechnique_common();
VL_CHECK(tech_common)
396 domAccessorRef accessor = tech_common->getAccessor();
400 domParam_Array param_array = accessor->getParam_array();
401 size_t attr_count = param_array.getCount() <= 32 ? param_array.getCount() : 32;
402 for(
size_t ipar=0; ipar<attr_count; ++ipar)
404 if (param_array[ipar]->getName() && strlen(param_array[ipar]->getName()))
410 if (source->getFloat_array())
411 dae_source->
init(source->getFloat_array(), accessor->getCount(), accessor->getStride(), accessor->getOffset(), mask);
413 if (source->getInt_array())
414 dae_source->
init(source->getInt_array(), accessor->getCount(), accessor->getStride(), accessor->getOffset(), mask);
416 if (source->getBool_array())
417 dae_source->
init(source->getBool_array(), accessor->getCount(), accessor->getStride(), accessor->getOffset(), mask);
420 Log::error(
"LoadWriterDae: no supported source data found. Only Float_array, Int_array and Bool_array are supported as source data.\n");
427 return dae_source.
get();
446 float transparency = 0;
452 bool use_lighting = strstr(mat->
mDaeEffect->objectName().c_str(),
"blinn:") ||
453 strstr(mat->
mDaeEffect->objectName().c_str(),
"phong:") ||
454 strstr(mat->
mDaeEffect->objectName().c_str(),
"lambert:");
488 if ( strstr(mat->
mDaeEffect->objectName().c_str(),
"constant:") )
520 Log::error(
"LoadWriterDae: technique or profile not supported.\n");
530 std::map< std::string, Dae::Material* > material_map;
534 if (bind_material->getTechnique_common())
536 domInstance_material_Array& material_instances = bind_material->getTechnique_common()->getInstance_material_array();
537 for(
size_t i=0; i<material_instances.getCount(); ++i)
539 daeElement* material = material_instances[i]->getTarget().getElement();
541 std::map< daeElementRef, ref<Dae::Material> >::iterator it =
mMaterials.find( material );
547 material_map[ material_instances[i]->getSymbol() ] = it->second.get();
551 VL_LOG_DEBUG <<
"- LoadWriterDae: material '" << material <<
"' not found!\n";
558 VL_LOG_DEBUG <<
"- LoadWriterDae: technique_COMMON not found!\n";
563 for(
size_t iprim=0; iprim<dae_mesh->
mPrimitives.size(); ++iprim)
567 if (!dae_mesh->
mPrimitives[iprim]->mMaterial.empty())
569 std::map< std::string, Dae::Material* >::iterator it = material_map.find( dae_mesh->
mPrimitives[iprim]->mMaterial );
570 if (it != material_map.end())
572 dae_material = it->second;
576 if ( dae_mesh->
mPrimitives[iprim]->mMaterial != VL_NO_MATERIAL_SPECIFIED)
578 VL_LOG_DEBUG <<
"- LoadWriterDae: material symbol " << dae_mesh->
mPrimitives[iprim]->mMaterial <<
" could not be resolved.\n";
586 dae_node->
mActors.push_back( actor );
592 if (el->typeID() == domNode::ID())
598 mNodes.push_back(this_node);
599 parent->
mChildren.push_back( this_node );
602 domNode* node =
static_cast<domNode*
>(el);
605 domInstance_geometry_Array geometries = node->getInstance_geometry_array();
606 for(
size_t i=0; i<geometries.getCount(); ++i)
608 VL_CHECK(geometries[i]->getUrl().getElement()->typeID() == domGeometry::ID())
609 daeElement* geometry = geometries[i]->getUrl().getElement();
612 this_node->
mMesh.push_back(dae_mesh.
get());
621 domInstance_controller_Array controllers = node->getInstance_controller_array();
622 for(
size_t i=0; i<controllers.getCount(); ++i)
624 VL_CHECK(controllers[i]->getUrl().getElement()->typeID() == domController::ID())
625 daeElement* controller_el = controllers[i]->getUrl().getElement();
630 domController* controller =
static_cast<domController*
>(controller_el);
631 daeElement* geometry = controller->getSkin()->getSource().getElement();
638 this_node->
mMesh.push_back(dae_mesh.
get());
646 for(
size_t ichild=0; ichild<node->getChildren().getCount(); ++ichild)
648 daeElement* child = node->getChildren()[ichild];
650 if ( 0 == strcmp(child->getElementName(),
"matrix") )
652 domMatrix* matrix =
static_cast<domMatrix*
>(child);
654 for(
int i=0; i<16; ++i)
655 local_matrix.
ptr()[i] = (real)matrix->getValue().get(i);
657 this_node->
mTransform->postMultiply(local_matrix);
660 if ( 0 == strcmp(child->getElementName(),
"translate") )
662 domTranslate* tr =
static_cast<domTranslate*
>(child);
667 if ( 0 == strcmp(child->getElementName(),
"rotate") )
669 domRotate* rot =
static_cast<domRotate*
>(child);
670 mat4 m =
mat4::getRotation((real)rot->getValue()[3], (real)rot->getValue()[0], (real)rot->getValue()[1], (real)rot->getValue()[2]);
674 if ( 0 == strcmp(child->getElementName(),
"scale") )
676 domScale* sc =
static_cast<domScale*
>(child);
677 mat4 m =
mat4::getScaling((real)sc->getValue()[0], (real)sc->getValue()[1], (real)sc->getValue()[2]);
681 if ( 0 == strcmp(child->getElementName(),
"lookat") )
683 domLookat* lookat =
static_cast<domLookat*
>(child);
684 vec3 eye ((real)lookat->getValue()[0], (real)lookat->getValue()[1], (real)lookat->getValue()[2]);
685 vec3 look((real)lookat->getValue()[3], (real)lookat->getValue()[4], (real)lookat->getValue()[5]);
686 vec3 up ((real)lookat->getValue()[6], (real)lookat->getValue()[7], (real)lookat->getValue()[8]);
690 if ( 0 == strcmp(child->getElementName(),
"skew") )
694 Log::error(
"LoadWriterDae: <skew> transform not supported yet. Call me if you know how to compute it.\n");
699 domInstance_light_Array lights = node->getInstance_light_array();
700 for(
size_t i=0; i<lights.getCount(); ++i)
702 daeElementRef dae_light = lights[i]->getUrl().getElement();
703 domLight* dom_light =
dynamic_cast<domLight*
>(dae_light.cast());
711 domInstance_node_Array nodes = node->getInstance_node_array();
712 for(
size_t i=0; i<nodes.getCount(); ++i)
714 daeElement* node = nodes[i]->getUrl().getElement();
715 VL_CHECK(node->typeID() == domNode::ID())
720 daeTArray< daeSmartRef<daeElement> > children = node->getChildren();
721 for(
size_t i=0; i<children.getCount(); ++i)
733 std::vector<char> buffer;
742 Log::error(
"LoadWriterDae: failed to open COLLADA document.\n" );
748 parseImages(root->getDescendant(
"library_images"));
754 daeElement* visual_scene = root->getDescendant(
"visual_scene");
757 Log::error(
"LoadWriterDae: <visual_scene> not found!\n" );
764 daeTArray< daeSmartRef<daeElement> > children = visual_scene->getChildren();
765 for(
size_t i=0; i<children.getCount(); ++i)
777 mScene->mTransform->computeWorldMatrixRecursive();
785 for(
size_t inode=0; inode<
mNodes.size(); ++inode )
787 for(
size_t i=0; i<
mNodes[inode]->mActors.size(); ++i)
823 if ( fabs(len_x - 1) > 0.05f || fabs(len_y - 1) > 0.05f || fabs(len_z - 1) > 0.05f )
840 for(
size_t ilight=0; ilight<
mLights.size() && ilight<8; ++ilight)
852 mScene->mTransform->flattenHierarchy();
862 for(
int i=0; uri[i]; ++i)
865 if ( uri[i] ==
'%' && uri[i+1] && uri[i+2] )
869 if (hex1 >=
'0' && hex1 <=
'9')
872 if (hex1 >=
'A' && hex1 <=
'F')
875 if (hex1 >=
'a' && hex1 <=
'f')
882 if (hex2 >=
'0' && hex2 <=
'9')
885 if (hex2 >=
'A' && hex2 <=
'F')
888 if (hex2 >=
'a' && hex2 <=
'f')
894 if (hex1 == -1 || hex2 == -1)
901 char ch = (hex1 << 4) + (hex2);
905 str.push_back(uri[i]);
912 for(
size_t i=0; i<images.getCount(); ++i)
914 if ( strstr( images[i]->getInit_from()->getValue().getProtocol(),
"file") == 0 )
916 Log::error(
Say(
"LoadWriterDae: protocol not supported: %s\n") << images[i]->getInit_from()->getValue().getURI() );
920 std::string full_path =
percentDecode( images[i]->getInit_from()->getValue().getURI() + 6 );
923 mImages[ images[i].cast() ] = image;
931 domLibrary_images* library_images =
static_cast<domLibrary_images*
>(library);
932 const domImage_Array& images = library_images->getImage_array();
940 domLibrary_effects* library_effects =
static_cast<domLibrary_effects*
>(library);
941 const domEffect_Array& effects = library_effects->getEffect_array();
942 for(
size_t i=0; i<effects.getCount(); ++i)
944 domEffect* effect = effects[i].cast();
948 std::string effect_name;
949 if (effect->getName())
950 effect_name = effect->getName();
957 const domFx_profile_abstract_Array& profiles = effect->getFx_profile_abstract_array();
958 for(
size_t i=0; i<profiles.getCount(); ++i)
961 if ( profiles[i]->typeID() == domProfile_COMMON::ID() )
963 domProfile_COMMON* common =
static_cast<domProfile_COMMON*
>(profiles[i].cast());
966 for(
size_t ipar=0; ipar<common->getNewparam_array().getCount(); ++ipar)
968 domCommon_newparam_typeRef newparam = common->getNewparam_array()[ipar];
971 dae_effect->
mNewParams.push_back( dae_newparam );
978 if (newparam->getSurface())
980 domFx_surface_commonRef surface = newparam->getSurface();
982 if ( !surface->getFx_surface_init_common()->getInit_from_array().getCount() )
984 VL_LOG_DEBUG <<
"- 'surface->getFx_surface_init_common()->getInit_from_array().getCount()' is 0: " << __FILE__ <<
":" << __LINE__ <<
"\n";
989 daeElement* ref_image = surface->getFx_surface_init_common()->getInit_from_array()[0]->getValue().getElement();
992 VL_LOG_DEBUG <<
"- 'surface->getFx_surface_init_common()->getInit_from_array()[0]->getValue().getElement()' FAILED: " << __FILE__ <<
":" << __LINE__ <<
"\n";
996 std::map< daeElementRef, ref<Image> >::iterator it =
mImages.find( ref_image );
998 dae_newparam->
mDaeSurface->mImage = it->second.get();
1001 VL_LOG_DEBUG <<
"- 'mImages.find( ref_image )' FAILED: " << __FILE__ <<
":" << __LINE__ <<
"\n";
1007 if (newparam->getSampler2D())
1009 domFx_sampler2D_commonRef sampler2D = newparam->getSampler2D();
1014 daeSIDResolver sid_res( effect, sampler2D->getSource()->getValue() );
1015 domElement* surface_newparam = sid_res.getElement();
1016 if(!surface_newparam)
1018 VL_LOG_DEBUG << (
Say(
"- <surface> '%s' referenced by <sampler2D> '%s' not found!\n") << sampler2D->getSource()->getValue() << newparam->getSid() );
1022 std::map< daeElementRef, ref<Dae::NewParam> >::iterator it =
mDaeNewParams.find(surface_newparam);
1025 dae_newparam->
mDaeSampler2D->mDaeSurface = it->second->mDaeSurface;
1029 VL_LOG_DEBUG <<
"- 'mDaeNewParams.find(surface_newparam)' FAILED: " << __FILE__ <<
":" << __LINE__ <<
"\n";
1034 if( sampler2D->getMinfilter() )
1041 if( sampler2D->getMagfilter() )
1047 if (sampler2D->getWrap_s())
1053 if (sampler2D->getWrap_t())
1063 if ( newparam->getFloat() )
1065 dae_newparam->
mFloat4 =
fvec4((
float)newparam->getFloat()->getValue(), 0, 0, 0);
1068 if ( newparam->getFloat2() )
1070 daeDouble* fptr = &newparam->getFloat2()->getValue()[0];
1071 dae_newparam->
mFloat4 =
fvec4((
float)fptr[0], (
float)fptr[1], 0, 0);
1074 if ( newparam->getFloat3() )
1076 daeDouble* fptr = &newparam->getFloat3()->getValue()[0];
1077 dae_newparam->
mFloat4 =
fvec4((
float)fptr[0], (
float)fptr[1], (
float)fptr[2], 0);
1080 if ( newparam->getFloat4() )
1082 daeDouble* fptr = &newparam->getFloat4()->getValue()[0];
1083 dae_newparam->
mFloat4 =
fvec4((
float)fptr[0], (
float)fptr[1], (
float)fptr[2], (
float)fptr[3]);
1090 if (common->getTechnique()->getBlinn())
1093 effect_name =
"blinn:"+effect_name;
1095 domProfile_COMMON::domTechnique::domBlinnRef blinn = common->getTechnique()->getBlinn();
1102 if (blinn->getShininess())
1103 dae_effect->
mDaeTechniqueCOMMON->mShininess = (
float)blinn->getShininess()->getFloat()->getValue();
1106 if (blinn->getReflectivity())
1107 dae_effect->
mDaeTechniqueCOMMON->mReflectivity = (
float)blinn->getReflectivity()->getFloat()->getValue();
1109 if (blinn->getTransparent())
1115 if (blinn->getTransparency())
1118 dae_effect->
mDaeTechniqueCOMMON->mTransparency = (float)blinn->getTransparency()->getFloat()->getValue();
1122 if (common->getTechnique()->getPhong())
1125 effect_name =
"phong:"+effect_name;
1127 domProfile_COMMON::domTechnique::domPhongRef phong = common->getTechnique()->getPhong();
1134 if (phong->getShininess())
1136 dae_effect->
mDaeTechniqueCOMMON->mShininess = (float)phong->getShininess()->getFloat()->getValue();
1140 if (phong->getReflectivity())
1141 dae_effect->
mDaeTechniqueCOMMON->mReflectivity = (
float)phong->getReflectivity()->getFloat()->getValue();
1143 if (phong->getTransparent())
1149 if (phong->getTransparency())
1152 dae_effect->
mDaeTechniqueCOMMON->mTransparency = (float)phong->getTransparency()->getFloat()->getValue();
1156 if (common->getTechnique()->getLambert())
1159 effect_name =
"lambert:"+effect_name;
1161 domProfile_COMMON::domTechnique::domLambertRef lambert = common->getTechnique()->getLambert();
1171 if (lambert->getReflectivity())
1172 dae_effect->
mDaeTechniqueCOMMON->mReflectivity = (
float)lambert->getReflectivity()->getFloat()->getValue();
1174 if (lambert->getTransparent())
1180 if (lambert->getTransparency())
1183 dae_effect->
mDaeTechniqueCOMMON->mTransparency = (float)lambert->getTransparency()->getFloat()->getValue();
1187 if (common->getTechnique()->getConstant())
1190 effect_name =
"constant:"+effect_name;
1192 domProfile_COMMON::domTechnique::domConstantRef constant = common->getTechnique()->getConstant();
1202 if (constant->getReflectivity())
1203 dae_effect->
mDaeTechniqueCOMMON->mReflectivity = (
float)constant->getReflectivity()->getFloat()->getValue();
1205 if (constant->getTransparent())
1211 if (constant->getTransparency())
1214 dae_effect->
mDaeTechniqueCOMMON->mTransparency = (float)constant->getTransparency()->getFloat()->getValue();
1219 Log::error(
"LoadWriterDae: technique not supported.\n");
1242 for(
size_t iextra=0; iextra<common->getExtra_array().getCount(); ++iextra)
1244 domExtraRef extra = common->getExtra_array()[iextra];
1245 for(
size_t itech=0; itech<extra->getTechnique_array().getCount(); ++itech)
1247 domTechniqueRef tech = extra->getTechnique_array()[itech];
1248 if ( strstr(tech->getProfile(),
"GOOGLEEARTH") )
1250 domAny* double_sided = (domAny*)tech->getChild(
"double_sided");
1253 const char* ptr = double_sided->getValue();
1254 if(strcmp(ptr,
"1") == 0)
1271 bool use_mipmaps =
true;
1279 use_mipmaps =
false;
1286 sampler2D->
mTexture->getTexParameter()->setWrapS(sampler2D->
mWrapS);
1287 sampler2D->
mTexture->getTexParameter()->setWrapT(sampler2D->
mWrapT);
1297 domLibrary_materials* library_materials =
static_cast<domLibrary_materials*
>(library);
1298 const domMaterial_Array& materials = library_materials->getMaterial_array();
1299 for(
size_t i=0; i<materials.getCount(); ++i)
1301 domElement* effect = materials[i]->getInstance_effect()->getUrl().getElement();
1304 VL_LOG_DEBUG <<
"- 'materials[i]->getInstance_effect()->getUrl().getElement()' FAILED: " << __FILE__ <<
":" << __LINE__ <<
"\n";
1308 std::map< daeElementRef, ref<Dae::Effect> >::iterator it =
mEffects.find(effect);
1311 domMaterial* material = materials[i].cast();
1318 VL_LOG_DEBUG <<
"- 'mEffects.find(effect)' FAILED: " << __FILE__ <<
":" << __LINE__ <<
"\n";
1326 domLight::domTechnique_commonRef light_common = dom_light->getTechnique_common();
1329 if (dom_light->getName())
1332 if (dom_light->getID())
1337 if (light_common->getPoint())
1339 domLight::domTechnique_common::domPointRef point = light_common->getPoint();
1341 if (point->getColor())
1343 domFloat3& c = point->getColor()->getValue();
1344 fvec4 color((
float)c[0], (
float)c[1], (
float)c[2], 1);
1350 if (point->getConstant_attenuation())
1352 if (point->getLinear_attenuation())
1354 if (point->getQuadratic_attenuation())
1360 if (light_common->getDirectional())
1362 domLight::domTechnique_common::domDirectionalRef directional = light_common->getDirectional();
1364 if (directional->getColor())
1366 domFloat3& c = directional->getColor()->getValue();
1367 fvec4 color((
float)c[0], (
float)c[1], (
float)c[2], 1);
1376 if (light_common->getSpot())
1378 domLight::domTechnique_common::domSpotRef spot= light_common->getSpot();
1380 if (spot->getColor())
1382 domFloat3& c = spot->getColor()->getValue();
1383 fvec4 color((
float)c[0], (
float)c[1], (
float)c[2], 1);
1389 if (spot->getConstant_attenuation())
1391 if (spot->getLinear_attenuation())
1393 if (spot->getQuadratic_attenuation())
1396 if (spot->getFalloff_angle())
1397 light->
setSpotCutoff( (
float)spot->getFalloff_angle()->getValue() );
1398 if (spot->getFalloff_exponent())
1399 light->
setSpotExponent( (
float)spot->getFalloff_exponent()->getValue() );
1405 if (light_common->getAmbient())
1407 domLight::domTechnique_common::domAmbientRef ambient = light_common->getAmbient();
1409 if (ambient->getColor())
1411 domFloat3& c = ambient->getColor()->getValue();
1412 fvec4 color((
float)c[0], (
float)c[1], (
float)c[2], 1);
1435 for(
size_t i=0; i<
mLights.size(); ++i)
1438 if (
mLights[i]->spotCutoff() != 180)
1452 if (
mLights[i]->position().w() == 0)
1510 for(
size_t i=0; i<
mLights.size(); ++i)
1522 mLights[0]->setObjectName(VL_DEFAULT_LIGHT);
1528 for(
int i=0; SemanticTable[i].mSemanticString; ++i)
1530 if (strcmp(semantic, SemanticTable[i].mSemanticString) == 0)
1531 return SemanticTable[i].mSemantic;
1539 for(
int i=0; SemanticTable[i].mSemanticString; ++i)
1541 if ( semantic == SemanticTable[i].mSemantic )
1542 return SemanticTable[i].mSemanticString;
1552 case FX_SAMPLER_FILTER_COMMON_NEAREST:
return TPF_NEAREST;
1553 case FX_SAMPLER_FILTER_COMMON_LINEAR:
return TPF_LINEAR;
1566 case FX_SAMPLER_WRAP_COMMON_WRAP:
return TPW_REPEAT;
1568 case FX_SAMPLER_WRAP_COMMON_CLAMP:
return TPW_CLAMP;
1574 template<
class T_color_or_texture>
1577 if (!color_or_texture)
1580 if (color_or_texture->getColor())
1582 domFx_color_common& col = color_or_texture->getColor()->getValue();
1583 out_col->
mColor =
fvec4( (
float)col[0], (
float)col[1], (
float)col[2], (
float)col[3] );
1586 if (color_or_texture->getTexture())
1589 daeSIDResolver sid_res( const_cast<domProfile_COMMON*>(common), color_or_texture->getTexture()->getTexture() );
1590 domElement* sampler2D_newparam = sid_res.getElement();
1592 std::map< daeElementRef, ref<Dae::NewParam> >::iterator it =
mDaeNewParams.find(sampler2D_newparam);
1595 VL_CHECK(it->second->mDaeSampler2D)
1596 out_col->
mSampler = it->second->mDaeSampler2D;
1597 if ( it->second->mDaeSampler2D.get() ==
NULL)
1599 VL_LOG_DEBUG <<
"- LoadWriterDae: malformed file: <texture texture=..> points to a <newparam> that does not contain <sampler2D>!\n";
1604 std::map< daeElementRef, ref<Image> >::iterator it =
mImages.find(sampler2D_newparam);
1610 out_col->
mSampler->mDaeSurface->mImage = it->second;
1612 VL_LOG_DEBUG <<
"- LoadWriterDae: malformed file: <texture texture=..> parameter points to an <image> instead of a <sampler2D>!\n" 1613 "VL will create a dummy sampler with the specified image.\n";
1617 VL_LOG_DEBUG <<
"- LoadWriterDae: malformed file: <texture texture=..> could not be resolved to anything!\n";
1622 out_col->
mTexCoord = color_or_texture->getTexture()->getTexcoord();
1638 for(
size_t i=0; i<prim->
mChannels.size(); ++i)
1642 VL_LOG_DEBUG <<
"- LoadWriterDae: cannot generate point cloud: channels have different sizes!\n";
1647 VL_LOG_DEBUG <<
"- LoadWriterDae: cannot generate point cloud: channels must have offset == 0!\n";
1654 prim->
mP[0] =
static_cast<domP*
>(domP::create(
mDAE).cast());
1655 prim->
mP[0]->getValue().setCount( prim->
mChannels[0]->mSource->count() );
1656 for (
size_t i=0; i<prim->
mChannels[0]->mSource->count(); ++i)
1657 prim->
mP[0]->getValue()[i] = i;
1660 size_t total_index_count = 0;
1661 for(
size_t ip=0; ip<prim->
mP.size(); ++ip)
1662 total_index_count += prim->
mP[ip]->getValue().getCount();
1667 std::vector<GLint> vcount;
1670 std::set<Dae::Vert> vert_set;
1671 for(
size_t ip=0, iidx=0; ip<prim->
mP.size(); ++ip)
1673 const domListOfUInts& p = prim->
mP[ip]->getValue();
1677 for(
size_t ivert=0; ivert<p.getCount(); ivert+=prim->
mIndexStride, ++iidx)
1682 for(
size_t ichannel=0; ichannel<prim->
mChannels.size(); ++ichannel)
1685 size_t final_index = 0xFFFFFFFF;
1687 std::set<Dae::Vert>::iterator it = vert_set.find(vert);
1688 if (it == vert_set.end())
1690 vert.
mIndex = final_index = vert_set.size();
1691 vert_set.insert(vert);
1694 final_index = it->mIndex;
1697 (*index_buffer)[iidx] = final_index;
1701 if (vcount.size() == 1)
1744 size_t tex_unit = 0;
1745 for(
size_t ich=0; ich<prim->
mChannels.size(); ++ich )
1750 float* ptr_end =
NULL;
1751 switch(prim->
mChannels[ich]->mSource->dataSize())
1756 vert_attrib = array_f1;
1757 array_f1->
resize( vert_set.size() );
1758 ptr = array_f1->
begin();
1760 ptr_end = ptr + vert_set.size() * 1;
1766 vert_attrib = array_f2;
1767 array_f2->
resize( vert_set.size() );
1768 ptr = array_f2->
at(0).
ptr();
1770 ptr_end = ptr + vert_set.size() * 2;
1776 vert_attrib = array_f3;
1777 array_f3->
resize( vert_set.size() );
1778 ptr = array_f3->
at(0).
ptr();
1780 ptr_end = ptr + vert_set.size() * 3;
1786 vert_attrib = array_f4;
1787 array_f4->
resize( vert_set.size() );
1788 ptr = array_f4->
at(0).
ptr();
1790 ptr_end = ptr + vert_set.size() * 4;
1814 for(std::set<Dae::Vert>::iterator it = vert_set.begin(); it != vert_set.end(); ++it)
1819 prim->
mChannels[ich]->mSource->readData(idx, ptr +prim-> mChannels[ich]->mSource->dataSize()*vert.
mIndex);
1835 size_t degenerate = 0;
1836 for(
size_t i=0; i<norm_new->
size(); ++i)
1839 float l = norm_old->
at(i).
length();
1842 norm_old->
at(i) = norm_new->
at(i);
1846 if ( l < 0.9f || l > 1.1f )
1852 if (
dot(norm_new->
at(i), norm_old->
at(i)) < -0.1f )
1854 norm_old->
at(i) = -norm_old->
at(i);
1860 if (degenerate || flipped)
1861 VL_LOG_DEBUG << (
Say(
"- LoadWriterDae: fixed bad normals in \"%s\": degenerate=%n, flipped=%n (out of %n).\n") << prim->
mGeometry->objectName() << degenerate << flipped << norm_old->
size() );
1874 domElement* asset_el = root->getChild(
"asset");
1877 domAsset* asset =
static_cast<domAsset*
>(asset_el);
1880 if (asset->getUp_axis())
1882 if( asset->getUp_axis()->getValue() == UPAXISTYPE_X_UP )
1890 if( asset->getUp_axis()->getValue() == UPAXISTYPE_Z_UP )
1907 for(
size_t i=0; i<asset->getContributor_array().getCount(); ++i)
1909 const char* tool = asset->getContributor_array()[i]->getAuthoring_tool()->getValue();
1918 const char* google_str = strstr(tool,
"Google SketchUp");
1919 size_t google_str_len = strlen(
"Google SketchUp");
1922 if ( strlen(google_str) > google_str_len )
1924 float version = 1000;
1925 if ( sscanf( google_str + google_str_len,
"%f", &version) )
1927 version = version * 100 + 0.5f;
1949 const char* colladamaya_str = strstr(tool,
"ColladaMaya v");
1950 size_t colladamaya_str_len = strlen(
"ColladaMaya v");
1951 if ( colladamaya_str )
1953 float version = 1000;
1954 if ( strlen(colladamaya_str) > colladamaya_str_len )
1956 if ( sscanf( colladamaya_str + colladamaya_str_len,
"%f", &version) )
1958 version = version * 100 + 0.5f;
1975 const char* colladamax_str = strstr(tool,
"ColladaMax v");
1976 size_t colladamax_str_len = strlen(
"ColladaMax v");
1977 if ( colladamax_str )
1979 float version = 1000;
1980 if ( strlen(colladamax_str) > colladamax_str_len )
1982 if ( sscanf( colladamax_str + colladamax_str_len,
"%f", &version) )
1984 version = version * 100 + 0.5f;
2002 if ( strstr(tool,
"VCGLib | MeshLab") )
bool extractSkins() const
If set to true the skinned geometries will be also exported. Enabled by default.
Associates a Renderable object to an Effect and Transform.
const Renderable * lod(int lod_index) const
Returns the Renderable object representing the LOD level specifed by lod_index.
float clamp(float x, float minval, float maxval)
void setEffect(Effect *effect)
Binds an Effect to an Actor.
COLLADA common technique.
void setTexture(Texture *texture)
The texture sampler by a texture unit.
static Dae::EInputSemantic getSemantic(const char *semantic)
const Vector3 & normalize(T_Scalar *len=NULL)
int isEnabled(EEnable capability) const
Vector3< float > fvec3
A 3 components vector with float precision.
size_t mAttribIndex[MAX_ATTRIBS]
Transform * transform()
Returns the Transform bound tho an Actor.
ref< Dae::Surface > mDaeSurface
Vector3< T_Scalar > getZ() const
ref< Dae::TechniqueCOMMON > mDaeTechniqueCOMMON
void setIndexBuffer(arr_type *index_buffer)
An abstract class representing a file.
< Transparency becomes 1.0 - <transparency>.
void bindMaterials(Dae::Node *dae_node, Dae::Mesh *dae_mesh, domBind_materialRef bind_material)
std::vector< ref< Dae::Primitive > > mPrimitives
If enabled, do depth comparisons and update the depth buffer; Note that even if the depth buffer exis...
float spotCutoff() const
Valid values are from 0.0f to 90.0f plus the special value 180.0f (default) which disables the spot l...
Vector4< float > fvec4
A 4 components vector with float precision.
Matrix4 & setX(const Vector3< T_Scalar > &v)
void parseImages(daeElement *library)
A simple String formatting class.
void setObjectName(const char *name)
The name of the object, by default set to the object's class name in debug builds.
static void warning(const String &message)
Use this function to provide information about situations that might lead to errors or loss of data...
TextureSampler * gocTextureSampler(int unit_index)
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
std::vector< ref< Dae::Input > > mVertexInputs
EnableSet * getEnableSet()
If enabled, use the current lighting parameters to compute the vertex color; Otherwise, simply associate the current color with each vertex, see also Material, LightModel, and Light.
void loadImages(const domImage_Array &images)
Dae::ColorOrTexture mSpecular
VLGRAPHICS_EXPORT ref< Geometry > makeCone(const vec3 &origin, real diameter=1, real height=1, int phi=20, bool bottom=true)
Creates a cone.
void setRenderStateSet(RenderStateSet *rss)
ref< Light > parseLight(domLight *, Transform *)
Dae::Source * getSource(daeElement *source_el)
If enabled, blend the incoming RGBA color values with the values in the color buffers, see also BlendFunc for more information.
std::map< daeElementRef, ref< Dae::NewParam > > mDaeNewParams
void setShininess(float shininess)
Vector3< T_Scalar > getY() const
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
void setPosition(const fvec4 &position)
The position or direction of a light.
void setSpecular(const fvec4 &color)
void parseEffects(daeElement *library)
std::map< daeElementRef, ref< Dae::Mesh > > mMeshes
std::vector< ref< Dae::Node > > mChildren
Wraps an OpenGL texture object representing and managing all the supported texture types...
void setSpecular(const fvec4 &specularcolor)
void setNormalArray(ArrayAbstract *data)
Conventional normal array.
< Transparency is inverted if <authoring_tool> contains the string "Google" or reports ColladaMax or ...
const LoadWriterDae::LoadOptions * loadOptions() const
void setLinearAttenuation(float linearattenuation)
If the light is positional, rather than directional, its intensity is attenuated by the reciprocal of...
void setDiffuse(const fvec4 &diffusecolor)
std::vector< domPRef > mP
Matrix4 & invert(T_Scalar *determinant=NULL)
Dae::ColorOrTexture mDiffuse
PolygonMode * gocPolygonMode()
VLCORE_EXPORT ref< Image > loadImage(VirtualFile *file)
Loads an image from the specified file.
ref< Geometry > mGeometry
const T_VectorType * begin() const
void setSpotCutoff(float spotcutoff)
Valid values are from 0.0f to 90.0f plus the special value 180.0f (default) which disables the spot l...
std::vector< ref< Dae::NewParam > > mNewParams
ref< Dae::Surface > mDaeSurface
ref< ResourceDatabase > mResources
const String & path() const
Returns the path of the file.
size_t size() const
Returns the number of elements of an array.
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
Visualization Library main namespace.
static std::string percentDecode(const char *uri)
Vector3< T_Scalar > getX() const
float dot(float a, float b)
ref< Dae::Effect > mDaeEffect
bool computeMissingNormals() const
Compute normals for those objects that don't have. Enabled by default.
std::map< daeElementRef, ref< Dae::Source > > mSources
void setDiffuse(const fvec4 &color)
COLLADA color or texture input.
void setRenderState(RenderStateNonIndexed *renderstate)
void generateGeometry(Dae::Primitive *primitive, const char *name)
Dae::EPrimitiveType mType
Matrix4 & setZ(const Vector3< T_Scalar > &v)
Dae::ColorOrTexture mEmission
void setEmission(const fvec4 &color)
void parseAsset(domElement *root)
std::map< daeElementRef, ref< Dae::Material > > mMaterials
void setConstantAttenuation(float constantattenuation)
If the light is positional, rather than directional, its intensity is attenuated by the reciprocal of...
ref< Dae::Sampler2D > mSampler
float max(float a, float b)
VLGRAPHICS_EXPORT ref< Geometry > makeTorus(const vec3 &origin, real diameter=1, real thickness=0.2, int phi=10, int theta=10, float tex_coords=0.0f)
Creates torus. This function generates also appropriate normals.
void parseInputs(Dae::Primitive *dae_primitive, const domInputLocalOffset_Array &input_arr, const std::vector< ref< Dae::Input > > &vertex_inputs)
ref< Dae::Mesh > parseGeometry(daeElement *geometry)
void prepareTexture2D(Dae::Sampler2D *sampler2D)
void setCountVector(const std::vector< GLsizei > &vcount)
Sets the vector defining the length of each primitive and automatically computes the pointer vectors ...
static const char * getSemanticString(Dae::EInputSemantic semantic)
void init(domFloat_arrayRef data_src, domUint count, domUint stride, domUint offset, size_t fields_mask)
Initializes an accessor. An accessor can read only up to 32 floats.
void computeNormals(bool verbose=false)
Computes the normals in a "smooth" way, i.e.
LightModel * gocLightModel()
VLGRAPHICS_EXPORT ref< Geometry > makePyramid(const vec3 &origin, real side=1, real height=1)
Creates a pyramid.
void setQuadraticAttenuation(float quadraticattenuation)
If the light is positional, rather than directional, its intensity is attenuated by the reciprocal of...
void transform(const mat4 &matr, bool normalize=true)
Transforms vertices and normals belonging to this geometry.
void parseMaterials(daeElement *library)
T * as()
Casts an Object to the specified class.
std::vector< ref< Dae::Input > > mChannels
vl::ETexParamFilter mMinFilter
void setAmbient(const fvec4 &color)
DrawCall * mergeTriangleStrips()
Merges all the PT_TRIANGLE_STRIP DrawElementsUInt objects into one single PT_TRIANGLE_STRIP DrawEleme...
Matrix4 & setY(const Vector3< T_Scalar > &v)
void setSpotExponent(float spotexponent)
void setSpotDirection(const fvec3 &spotdirection)
Shader * shader(int lodi=0, int pass=0)
Utility function, same as 'lod(lodi)->at(pass);'.
Defines the sequence of Shader objects used to render an Actor.
std::vector< ref< Light > > mLights
static Matrix4 & getRotation(Matrix4 &out, float degrees, float x, float y, float z)
std::vector< ref< Dae::Mesh > > mMesh
T_VectorType & at(size_t i)
Effect * effect()
Returns the Effect bound to an Actor.
bool load(VirtualFile *file)
void multiplyTransparency(float alpha)
const std::string & objectName() const
The name of the object, by default set to the object's class name.
fvec3 vec3
Defined as: 'typedef fvec3 vec3'. See also VL_PIPELINE_PRECISION.
void mergeDrawCallsWithTriangles(EPrimitiveType primitive_type)
Merges all the draw calls that use the given primitive type or PT_TRIANGLES into one single PT_TRIANG...
Dae::ColorOrTexture mTransparent
RenderStateSet * getRenderStateSet()
static Matrix4 & getTranslation(Matrix4 &out, const Vector3< float > &v)
void bindTransform(Transform *transform)
If NULL follows the camera otherwise the given transformation node.
const fvec4 & position() const
The position or direction of a light.
void setValue(const fvec4 &color)
std::map< daeElementRef, ref< Image > > mImages
bool fixBadNormals() const
Fix normals that are flipped compared to the polygon winding order. Enabled by default.
static Matrix4 & getScaling(Matrix4 &out, const Vector3< float > &v)
ref< Transform > mTransform
Wraps the OpenGL function glLight().
vl::ETexParamFilter mMagFilter
The ref<> class is used to reference-count an Object.
Dae::ColorOrTexture mAmbient
ref< Effect > setup_vl_Effect(Dae::Material *mat)
Vector3< T_Scalar > rgb() const
std::string toStdString() const
Returns a UTF8 encoded std::string.
void parseNode(daeElement *el, Dae::Node *parent)
VLGRAPHICS_EXPORT ref< Geometry > makeUVSphere(const vec3 &origin, real diameter=1, int phi=20, int theta=20)
Creates a uv sphere.
long long load(std::vector< char > &data)
Loads the entire file in the specified vector.
static ETexParamWrap translateWrapMode(domFx_sampler_wrap_common wrap)
void setIndexBuffer(arr_type *index_buffer)
The BufferObject containing the indices used to render.
void setTwoSide(bool twoside)
static Matrix4 getLookAt(const Vector3< float > &eye, const Vector3< float > &at, const Vector3< float > &up)
If enabled, normal vectors are scaled to unit length after transformation, see also vl::EN_RESCALE_NO...
std::vector< ref< Actor > > mActors
ref< Dae::Sampler2D > mDaeSampler2D
void enable(EEnable capability)
Dae::EOpaqueMode mOpaqueMode
void set(EPolygonMode frontface, EPolygonMode backface)
std::vector< ref< Dae::Node > > mNodes
const ArrayAbstract * normalArray() const
Conventional normal array.
std::map< daeElementRef, ref< Dae::Effect > > mEffects
const fvec4 & ambient() const
The ResourceDatabase class contains and manipulates a set of resources.
void setAmbient(const fvec4 &ambientcolor)
static ETexParamFilter translateSampleFilter(domFx_sampler_filter_common filter)
Collection< DrawCall > & drawCalls()
Returns the list of DrawCall objects bound to a Geometry.
const T_Scalar & w() const
const T_Scalar & a() const
void setEnableSet(EnableSet *es)
If enabled, cull polygons based on their winding in window coordinates, see also CullFace.
void parseColor(const domProfile_COMMON *common, const T_color_or_texture &color_or_texture, Dae::ColorOrTexture *out_col)