In ColladaRt, we use the following code to add a texture to the effect:
if(textureElement)
{
CrtImage * image = NULL;
const CrtChar *samplerName = textureElement->getTexture();
const CrtChar *imageName = samplerName;
char *target = new char[ strlen( samplerName ) + 3 ];
strcpy( target, "./" );
strcat( target, samplerName );
daeSIDResolver sidRes( EffectElement, target );
delete[] target;
target = NULL;
if ( sidRes.getElement() != NULL )...
Why do we add a “./” to the target?
The code that is inside the if ( sidRes.getElement() != NULL ) code, is more complex than its else:
if ( sidRes.getElement() != NULL )
{
//More complex code
}
else
{
daeIDRef ref(samplerName);
ref.setContainer(textureElement);
ref.resolveElement();
daeElement * element = ref.getElement();
domImage * domimage = (domImage *) element;
image = ReadImage(domimage);
// image = ReadImage((domImage *) (daeElement*) ref.getElement());
// image = GetImage(samplerName, textureElement->getDocumentURI()->getURI());
if ( image )
{
CrtPrint( "Direct Image Linking!! Your Data is WRONG!! But I'm nice and will load it anyways!" );
imageName = samplerName;
}
}
But both of if and else attempt to load the image. Isn’t it?( But inside the else we don’t add a “./” to the filename ). What do we do in if statement exactly?Here’s the “if” code:
if ( sidRes.getElement() != NULL )
{
daeElement *samp = sidRes.getElement();
daeElement *surf = NULL;
if ( CrtCmp( samp->getTypeName(), "fx_newparam_common" ) )
{
domFx_newparam_common *npc = (domFx_newparam_common *)samp;
if ( npc->getFx_basic_type_common()->getSampler2D() != NULL )
{
const char *str = npc->getFx_basic_type_common()->getSampler2D()->getSource()->getValue();
target = new char[ strlen( str ) + 3 ];
strcpy( target, "./" );
strcat( target, str );
sidRes.setTarget( target );
delete []target;
target = NULL;
surf = sidRes.getElement();
}
}
else if ( CrtCmp( samp->getTypeName(), "common_newparam_type" ) )
{
domCommon_newparam_type *cnp = (domCommon_newparam_type *)samp;
if ( cnp->getSampler2D() != NULL )
{
const char *str = cnp->getSampler2D()->getSource()->getValue();
target = new char[ strlen( str ) + 3 ];
strcpy( target, "./" );
strcat( target, str );
sidRes.setTarget( target );
delete []target;
target = NULL;
surf = sidRes.getElement();
}
}
if ( surf != NULL )
{
if ( CrtCmp( surf->getTypeName(), "fx_newparam_common" ) )
{
domFx_newparam_common *npc = (domFx_newparam_common *)samp;
if ( npc->getFx_basic_type_common()->getSurface() != NULL )
{
domFx_surface_common *sc = npc->getFx_basic_type_common()->getSurface();
if ( sc->getFx_surface_init_common() != NULL &&
sc->getFx_surface_init_common()->getInit_from_array().getCount() > 0 )
{
daeIDRef & ref = sc->getFx_surface_init_common()->getInit_from_array()[0]->getValue();
ref.resolveElement();
daeElement * element = ref.getElement();
domImage * domimage = (domImage *) element;
image = ReadImage(domimage);
// imageName = sc->getFx_surface_init_common()->getInit_from_array()[0]->getValue().getID();
// image = GetImage(imageName, textureElement->getDocumentURI()->getURI());
}
}
}
else if ( CrtCmp( surf->getTypeName(), "common_newparam_type" ) )
{
domCommon_newparam_type *cnp = (domCommon_newparam_type *)surf;
if ( cnp->getSurface() != NULL )
{
domFx_surface_common *sc = cnp->getSurface();
if ( sc->getFx_surface_init_common() != NULL &&
sc->getFx_surface_init_common()->getInit_from_array().getCount() > 0 )
{
daeIDRef & ref = sc->getFx_surface_init_common()->getInit_from_array()[0]->getValue();
ref.resolveElement();
daeElement * element = ref.getElement();
domImage * domimage = (domImage *) element;
image = ReadImage(domimage);
// imageName = sc->getFx_surface_init_common()->getInit_from_array()[0]->getValue().getID();
// image = GetImage(imageName, textureElement->getDocumentURI()->getURI());
}
}
}
}
}