//------------------------------ BitmapTex* MaterialCreator::createTexture( const COLLADAFW::EffectCommon& effectCommon, const COLLADAFW::Texture& texture ) { BitmapTex* bitmapTexture = NewDefaultBitmapTex(); COLLADAFW::SamplerID samplerId = texture.getSamplerId(); const COLLADAFW::Sampler* sampler = effectCommon.getSamplerPointerArray()[ samplerId ]; const COLLADAFW::UniqueId& imageUniqueId = sampler->getSourceImage(); const COLLADAFW::Image* image = getFWImageByUniqueId( imageUniqueId ); if ( !image ) return 0; COLLADABU::URI imageUri( getFileInfo().absoluteFileUri, image->getImageURI().getURIString() ); COLLADABU::NativeString imageFileName( imageUri.toNativePath().c_str(), COLLADABU::NativeString::ENCODING_UTF8 ); bitmapTexture->SetMapName(const_cast<char*>(imageFileName.c_str())); bitmapTexture->LoadMapFiles(0); UVGen* uvGen = bitmapTexture->GetTheUVGen(); StdUVGen* stdUVGen = (StdUVGen*)uvGen; // reset all flags //stdUVGen->SetFlag(U_WRAP|V_WRAP, 1); //stdUVGen->SetFlag(U_MIRROR|V_MIRROR, 0); int tiling = 0; if ( sampler->getWrapS() == COLLADAFW::Sampler::WRAP_MODE_WRAP ) { tiling += 1<<0; } else if ( sampler->getWrapS() == COLLADAFW::Sampler::WRAP_MODE_MIRROR ) { tiling += 1<<2; } if ( sampler->getWrapT() == COLLADAFW::Sampler::WRAP_MODE_WRAP ) { tiling += 1<<1; } else if ( sampler->getWrapT() == COLLADAFW::Sampler::WRAP_MODE_MIRROR ) { tiling += 1<<3; } stdUVGen->SetTextureTiling(tiling); return bitmapTexture; }
Texmap* NifImporter::CreateTexture(const string& filename) { if (filename.empty()) return NULL; BitmapManager *bmpMgr = TheManager; if (bmpMgr->CanImport(filename.c_str())){ BitmapTex *bmpTex = NewDefaultBitmapTex(); string name = filename; if (name.empty()) { TCHAR buffer[MAX_PATH]; _tcscpy(buffer, PathFindFileName(filename.c_str())); PathRemoveExtension(buffer); name = buffer; } bmpTex->SetName(name.c_str()); bmpTex->SetMapName(const_cast<TCHAR*>(FindImage(filename).c_str())); bmpTex->SetAlphaAsMono(TRUE); bmpTex->SetAlphaSource(ALPHA_DEFAULT); bmpTex->SetFilterType(FILTER_PYR); if (showTextures) { bmpTex->SetMtlFlag(MTL_TEX_DISPLAY_ENABLED, TRUE); bmpTex->ActivateTexDisplay(TRUE); bmpTex->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); } if (UVGen *uvGen = bmpTex->GetTheUVGen()){ uvGen->SetTextureTiling(0); } return bmpTex; } return NULL; }
Texmap* NifImporter::CreateTexture(TexDesc& desc) { BitmapManager *bmpMgr = TheManager; if (NiSourceTextureRef texSrc = desc.source){ string filename = texSrc->GetTextureFileName(); if (bmpMgr->CanImport(filename.c_str())){ BitmapTex *bmpTex = NewDefaultBitmapTex(); string name = texSrc->GetName(); if (name.empty()) { TCHAR buffer[MAX_PATH]; _tcscpy(buffer, PathFindFileName(filename.c_str())); PathRemoveExtension(buffer); name = buffer; } bmpTex->SetName(name.c_str()); bmpTex->SetMapName(const_cast<TCHAR*>(FindImage(filename).c_str())); bmpTex->SetAlphaAsMono(TRUE); bmpTex->SetAlphaSource(ALPHA_DEFAULT); switch (desc.filterMode) { case FILTER_TRILERP: bmpTex->SetFilterType(FILTER_PYR); break; case FILTER_BILERP: bmpTex->SetFilterType(FILTER_SAT); break; case FILTER_NEAREST: bmpTex->SetFilterType(FILTER_NADA); break; } if (UVGen *uvGen = bmpTex->GetTheUVGen()){ if (uvGen && uvGen->IsStdUVGen()) { StdUVGen *uvg = (StdUVGen*)uvGen; uvg->SetMapChannel(desc.uvSet + 1); } switch (desc.clampMode) { case WRAP_S_WRAP_T : uvGen->SetTextureTiling(3); break; case WRAP_S_CLAMP_T: uvGen->SetTextureTiling(1); break; case CLAMP_S_WRAP_T: uvGen->SetTextureTiling(2); break; case CLAMP_S_CLAMP_T:uvGen->SetTextureTiling(0); break; } if (desc.hasTextureTransform) { if (RefTargetHandle ref = uvGen->GetReference(0)){ TexCoord trans = desc.translation; TexCoord tiling = desc.tiling; float wangle = TODEG(desc.wRotation); setMAXScriptValue(ref, "U_Offset", 0, trans.u); setMAXScriptValue(ref, "V_Offset", 0, trans.v); setMAXScriptValue(ref, "U_Tiling", 0, tiling.u); setMAXScriptValue(ref, "V_Tiling", 0, tiling.v); setMAXScriptValue(ref, "W_Angle", 0, wangle); } } } if (showTextures) { bmpTex->SetMtlFlag(MTL_TEX_DISPLAY_ENABLED, TRUE); bmpTex->ActivateTexDisplay(TRUE); bmpTex->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); } return bmpTex; } } return NULL; }