//------------------------------
	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;
	}
Esempio n. 2
0
void UtilTest::SetEnvironmentMap()
	{
	// Make a bitmap texture map.
	BitmapTex *map = NewDefaultBitmapTex();
	
	// Get the UVGen
	StdUVGen *uvGen = map->GetUVGen();
	
	// Set up the coords. to be screen environment.
	uvGen->SetCoordMapping(UVMAP_SCREEN_ENV);

	// Set the bitmap file.
	map->SetMapName(_T("A_MAX.TGA"));

	// Make this the new environment map.
	ip->SetEnvironmentMap(map);
	}
Esempio n. 3
0
void Import::LoadMaterials (dScene& scene, MaterialCache& materialCache)
{
    dScene::Iterator iter (scene);
    for (iter.Begin(); iter; iter ++) {
        dScene::dTreeNode* const materialNode = iter.GetNode();
        dNodeInfo* const info = scene.GetInfoFromNode(materialNode);
        if (info->IsType(dMaterialNodeInfo::GetRttiType())) {
            MaterialProxi material;
            material.m_mtl = NewDefaultStdMat();
            StdMat* const stdMtl = (StdMat*)material.m_mtl;

            dMaterialNodeInfo* const materialInfo = (dMaterialNodeInfo*) info;
            stdMtl->SetName(materialInfo->GetName());

            dVector ambient (materialInfo->GetAmbientColor());
            dVector difusse (materialInfo->GetDiffuseColor());
            dVector specular (materialInfo->GetSpecularColor());
            float shininess (materialInfo->GetShininess());
            //float shininessStr (materialInfo->GetShinStr());
            float transparency (materialInfo->GetOpacity());

            stdMtl->SetAmbient(*((Point3*)&ambient), 0);
            stdMtl->SetDiffuse(*((Point3*)&difusse), 0);
            stdMtl->SetSpecular(*((Point3*)&specular), 0);
            stdMtl->SetShinStr(shininess / 100.0f, 0);
            stdMtl->SetOpacity(transparency, 0);


            if (materialInfo->GetDiffuseTextId() != -1) {
                dScene::dTreeNode* textNode = scene.FindTextureByTextId(materialNode, materialInfo->GetDiffuseTextId());
                if (textNode) {
                    _ASSERTE (textNode);
                    //				BitmapTex* bmtex;
                    //				const TCHAR* txtName;

                    dTextureNodeInfo* textureInfo = (dTextureNodeInfo*) scene.GetInfoFromNode(textNode);
                    TCHAR txtNameBuffer[256];
                    sprintf (txtNameBuffer, "%s/%s", m_path, textureInfo->GetPathName());

                    const TCHAR* txtName = txtNameBuffer;
                    BitmapTex* bmtex = (BitmapTex*)NewDefaultBitmapTex();
                    bmtex->SetMapName((TCHAR*)txtName);

                    txtName = textureInfo->GetPathName();
                    bmtex->SetName (txtName);
                    bmtex->GetUVGen()->SetMapChannel(1);

                    stdMtl->SetSubTexmap(ID_DI, bmtex);
                    stdMtl->SetTexmapAmt(ID_DI, 1.0f, 0);
                    stdMtl->EnableMap(ID_DI, TRUE);

                    //					const char* materialOpanacity = segment.m_opacityTextureName;
                    //					if (materialOpanacity[0]) {
                    //						BitmapTex* bmtex;
                    //						const TCHAR* txtName;
                    //
                    //						txtName = segment.m_opacityPathName;
                    //						bmtex = (BitmapTex*)NewDefaultBitmapTex();
                    //						bmtex->SetMapName((TCHAR*)txtName);
                    //
                    //						txtName = materialName;
                    //						bmtex->SetName (txtName);
                    //						bmtex->GetUVGen()->SetMapChannel(2);
                    //
                    //						stdMtl->SetSubTexmap(ID_OP, bmtex);
                    //						stdMtl->SetTexmapAmt(ID_OP, 1.0f, 0);
                    //						stdMtl->EnableMap(ID_OP, TRUE);
                    //					}
                    //				materialCache.AddMaterial(material, segment.m_textureName);
                }
            }
            materialCache.AddMaterial(material, materialInfo->GetId());
        }
    }
}