Пример #1
0
void OgreExporter_c::ExportWall(SDLTexture_c &texture, const WadFile_c &file, Name_u name)
{
	NameSet_t::iterator it = setExportedTextures.lower_bound(name);
	if((it != setExportedTextures.end()) && (!setExportedTextures.key_comp()(name, *it)))
	{
		//already exists, ignore
	}
	else
	{
		//store if first, if an error happens, we do not keep reporting it
		setExportedTextures.insert(it, name);		
		try
		{
			file.LoadTexture(texture, file.FindTextureIndex(name));
		}
		catch(std::exception &e)
		{
			std::string name(name.archName, 8);
			std::cout << "Error exporting " << name.c_str() << ": " << e.what() << std::endl;
			return;
		}		

		SaveTexture(texture, name);		
	}
}
Пример #2
0
void CD3DTexture::OnDestroyDevice()
{
  SaveTexture();
  SAFE_RELEASE(m_texture);
  SAFE_RELEASE(m_textureView);
  SAFE_RELEASE(m_renderTarget);
}
Пример #3
0
void LandscapeEditorBase::Toggle()
{
    if(ELE_ACTIVE == state)
    {
        state = ELE_CLOSING;
        
        SaveTexture();
    }
    else if(ELE_NONE == state)
    {
        touchID = INVALID_TOUCH_ID;
        
        SafeRelease(heightmapNode);
        heightmapNode = new HeightmapNode(workingScene, workingLandscape);
        workingScene->AddNode(heightmapNode);
                
        state = ELE_ACTIVE;
        
        SetTool(toolsPanel->CurrentTool());
        
        if(delegate)
        {
            delegate->LandscapeEditorStarted();
        }
        
        ShowAction();
    }
}
void LandscapeEditorBase::Toggle()
{
    if(ELE_ACTIVE == state)
    {
        state = ELE_CLOSING;
        
        SaveTexture();
    }
    else if(ELE_NONE == state)
    {
        touchID = INVALID_TOUCH_ID;
        
        state = ELE_ACTIVE;
        
        SetTool(toolsPanel->CurrentTool());
        
        if(delegate)
        {
            delegate->LandscapeEditorStarted();
        }
        
        ShowAction();
        
        RecreateHeightmapNode();
    }
}
Пример #5
0
void CD3DTexture::OnDestroyDevice(bool fatal)
{
  if (!fatal)
    SaveTexture();
  for (auto it = m_views.begin(); it != m_views.end(); ++it)
    SAFE_RELEASE(it->second);
  SAFE_RELEASE(m_renderTargets[0]);
  SAFE_RELEASE(m_renderTargets[1]);
  SAFE_RELEASE(m_texture);
  m_views.clear();
}
Пример #6
0
// helper function for save frame in picture.
inline void FrameSavingHelper()
{
	if (g_bSaveFrame)
	{
		if (vb[0].prndr != NULL)
		{
			SaveTexture("frame1.tga", GL_TEXTURE_RECTANGLE_NV, vb[0].prndr->ptex, RW(vb[0].prndr->fbw), RH(vb[0].prndr->fbh));
		}

		if (vb[1].prndr != NULL && vb[0].prndr != vb[1].prndr)
		{
			SaveTexture("frame2.tga", GL_TEXTURE_RECTANGLE_NV, vb[1].prndr->ptex, RW(vb[1].prndr->fbw), RH(vb[1].prndr->fbh));
		}

#ifdef _WIN32
		else 
		{
			DeleteFile(L"frame2.tga");
		}
#endif
	}
}
Пример #7
0
void VisibilityToolPanel::ConnectToSignals()
{
	connect(SceneSignals::Instance(),
			SIGNAL(VisibilityToolStateChanged(SceneEditor2*, VisibilityToolSystem::eVisibilityToolState)),
			this,
			SLOT(SetVisibilityToolButtonsState(SceneEditor2*, VisibilityToolSystem::eVisibilityToolState)));
	connect(SceneSignals::Instance(), SIGNAL(VisibilityToolToggled(SceneEditor2*)),
			this, SLOT(EditorToggled(SceneEditor2*)));

	connect(buttonSaveTexture, SIGNAL(clicked()), this, SLOT(SaveTexture()));
	connect(buttonSetVisibilityPoint, SIGNAL(clicked()), this, SLOT(SetVisibilityPoint()));
	connect(buttonSetVisibilityArea, SIGNAL(clicked()), this, SLOT(SetVisibilityArea()));
	connect(sliderWidgetAreaSize, SIGNAL(ValueChanged(int)), this, SLOT(SetVisibilityAreaSize(int)));
}
Пример #8
0
		//----------------------------------------------------------------------
		void SaveTexture(	const std::string& _filename,
							TextureArray2D& _texture,
							bool _verbose)
		{
			#ifdef ENABLE_OPEN_EXR
			float* data = new float[_texture.size.x * _texture.size.y * _texture.layers * 4];
			glBindTexture(_texture.target,_texture.id);
			glGetTexImage(_texture.target,0,GL_RGBA,GL_FLOAT,data);

			for(int l=0;l<_texture.layers;++l)
			{
				std::stringstream out;
				out << _filename << "." << l << ".exr";
				SaveTexture(out.str(),data+(l * _texture.size.x * _texture.size.y * 4),_texture.size.x,_texture.size.y,_verbose);
			}
			delete[] data;
			#endif
		}
Пример #9
0
void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
	PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
	bool isIntensity, bool scaleByHalf, unsigned int cbufid,
	const float *colmat)
{
	g_renderer->ResetAPIState(); // reset any game specific settings

	// Make sure to resolve anything we need to read from.
	const GLuint read_texture = (srcFormat == PEControl::Z24) ?
		FramebufferManager::ResolveAndGetDepthTarget(srcRect) :
		FramebufferManager::ResolveAndGetRenderTarget(srcRect);

	GL_REPORT_ERRORD();

	if (type != TCET_EC_DYNAMIC || g_ActiveConfig.bCopyEFBToTexture)
	{
		FramebufferManager::SetFramebuffer(framebuffer);

		GL_REPORT_ERRORD();

		glActiveTexture(GL_TEXTURE0+9);
		glBindTexture(GL_TEXTURE_2D, read_texture);

		glViewport(0, 0, virtual_width, virtual_height);

		if (srcFormat == PEControl::Z24)
		{
			s_DepthMatrixProgram.Bind();
			if (s_DepthCbufid != cbufid)
				glUniform4fv(s_DepthMatrixUniform, 5, colmat);
			s_DepthCbufid = cbufid;
		}
		else
		{
			s_ColorMatrixProgram.Bind();
			if (s_ColorCbufid != cbufid)
				glUniform4fv(s_ColorMatrixUniform, 7, colmat);
			s_ColorCbufid = cbufid;
		}

		TargetRectangle R = g_renderer->ConvertEFBRectangle(srcRect);
		glUniform4f(srcFormat == PEControl::Z24 ? s_DepthCopyPositionUniform : s_ColorCopyPositionUniform,
			R.left, R.top, R.right, R.bottom);
		GL_REPORT_ERRORD();

		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		GL_REPORT_ERRORD();
	}

	if (false == g_ActiveConfig.bCopyEFBToTexture)
	{
		int encoded_size = TextureConverter::EncodeToRamFromTexture(
			addr,
			read_texture,
			srcFormat == PEControl::Z24,
			isIntensity,
			dstFormat,
			scaleByHalf,
			srcRect);

		u8* dst = Memory::GetPointer(addr);
		u64 const new_hash = GetHash64(dst,encoded_size,g_ActiveConfig.iSafeTextureCache_ColorSamples);

		// Mark texture entries in destination address range dynamic unless caching is enabled and the texture entry is up to date
		if (!g_ActiveConfig.bEFBCopyCacheEnable)
			TextureCache::MakeRangeDynamic(addr,encoded_size);
		else if (!TextureCache::Find(addr, new_hash))
			TextureCache::MakeRangeDynamic(addr,encoded_size);

		hash = new_hash;
	}

	FramebufferManager::SetFramebuffer(0);

	GL_REPORT_ERRORD();

	if (g_ActiveConfig.bDumpEFBTarget)
	{
		static int count = 0;
		SaveTexture(StringFromFormat("%sefb_frame_%i.png", File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
			count++), GL_TEXTURE_2D, texture, virtual_width, virtual_height, 0);
	}

	g_renderer->RestoreAPIState();
}
void CGLWorkspace::DrawToTexture()
{
	WorkLog.write("Begin: CGLWorkspace::DrawToTexture");
	if(!iWorkspaceChanged && !iSaveSnapshot){
		WorkLog.write("End: CGLWorkspace::DrawToTexture");
		return;
	}
	iWorkspaceChanged = false;

	//Set up rendering to texture
	//render to ext buffer (texture behind)
	iActualTextureFBO->bind();


	//glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, iFBO);
	// clear buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	//draw 3D texture slice to texture
	QListIterator<CGLImage*> images(iImages);
	int imageHeightSum = 0;
	glDisable(GL_BLEND);

	while (images.hasNext())
	{
		glColor4f(1,1,1,1);
		CGLImage *im = images.next();
		imageHeightSum += im->GetSize().y();
		//im->PrepareActualTexture();
		//glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, iFBO);
		glViewport(0, 0,iActualTextureInfo.width, iActualTextureInfo.height);					// Reset The Current Viewport
		glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
		glLoadIdentity();							// Reset The Projection Matrix
		//map to texture as to workspace (in widget)

		int left = GetPosition().x()+GetBorders().left;
		int right = 	GetSize().x()+GetPosition().x()-GetBorders().right;
		int bottom=CGLWidget::GetInstance()->GetSize().y()-GetPosition().y()-GetSize().y()+GetBorders().bottom;
		int top = CGLWidget::GetInstance()->GetSize().y()-GetPosition().y()-GetBorders().top;
		glOrtho(left, 
			right ,
			bottom,
			top,
			0.1, 90);

		glMatrixMode(GL_MODELVIEW); 
		glLoadIdentity();						// Reset The Modelview Matrix
		im->Translate();
		glColor4f(1,1,1,1);
		glDisable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
		im->DrawBorderRect();
		im->DrawInnerRect();

		if(iActiveImage==im)
		{
			im->DrawSelection();
		}
		glColor4f(1,1,1,1);
		im->DrawImage();
		im->DrawManipulation();
		im->DrawIcons();
		im->DrawSlider();
		im->DrawTexts();
	}
	if(iSaveSnapshot)
	{
		iSaveSnapshot = false;
		SaveTexture(*iSaveSnapshotFileName);

	}
	//glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	iActualTextureFBO->release();
	WorkLog.write("End: CGLWorkspace::DrawToTexture");
	return;
}
Пример #11
0
		//----------------------------------------------------------------------
		void SaveTexture(	const std::string& _filename,
							Texture2D& _texture,
							bool _verbose)
		{
			#ifdef ENABLE_OPEN_EXR
			float* data = new float[_texture.size.x * _texture.size.y * 4];
			glBindTexture(_texture.target,_texture.id);
			glGetTexImage(_texture.target,0,GL_RGBA,GL_FLOAT,data);
			SaveTexture(_filename,data,_texture.size.x,_texture.size.y,_verbose);
			delete[] data;
			#else
			try
			{
				ilInit();
				
				ILuint imgH;
				ilGenImages(1, &imgH);
				ilBindImage(imgH);

				float* data = new float[_texture.size.x * _texture.size.y * 4];
				glBindTexture(_texture.target,_texture.id);
				glGetTexImage(_texture.target,0,GL_RGBA,GL_FLOAT,data);

				ILboolean result;
				result = ilTexImage(_texture.size.x, _texture.size.y, 1, 4, IL_RGBA, IL_FLOAT, data);
				assert(result);

				ilEnable(IL_FILE_OVERWRITE);
//				result = ilSave(IL_EXR, _filename.c_str());
//				result = ilSave(IL_TYPE_UNKNOWN, _filename.c_str());
				#if WIN32
				result = ilSaveImage(s2ws(_filename).c_str());			
				#else
				result = ilSaveImage(_filename.c_str());
				#endif

				if(!result)
				{
					ILenum errorID = ilGetError();
					if(errorID != IL_NO_ERROR)
					{
						Error("Save image error :  %s",_filename.c_str());
						Error("Error ID :  %d",errorID);
					}
				}
				assert(result);

				delete[] data;

				if(_verbose)
				{
					Info("Save image : %s",_filename.c_str());
				}

				ilDeleteImages(1, &imgH);
				ilShutDown();
			}
			catch (const std::exception &e) 
			{
				Error("Unable to write texture \"%s\": %s",_filename.c_str(),e.what());
			}
			#endif
		}
Пример #12
0
void M2toX3D(tabbed_ostream s, Model *m, bool init, const char* fn, bool xhtml)
{
	LogExportData(wxT("X3D"),m->modelname,wxString(fn, wxConvUTF8));
    s << "<!-- Exported with WoWModelViewer -->" << std::endl;

    s.tab();
    s << "<Scene>" << std::endl;
    
    s.tab();

    // define background
    s   << "<Background skyColor='" 
        << 70.f/256.f << " " 
        << 94.f/256.f << " "
        << 121.f/256.f << " "
        << "'/>" << std::endl;

    // define all textures
    typedef std::map<int, wxString> texMap;
    texMap textures;

    if (!fn)
        fn = "texture";

    size_t num_rot = 0;
    if (modelExport_X3D_CenterModel)
    {
        // move viewpoint back
        s << "<Viewpoint position='0 0 " << m->pos.z << "'/>" << std::endl;

        // create rotation transforms only if there is an actual rotation
        float rot[3] = { m->rot.x, m->rot.y, m->rot.z };
        for (size_t n=0; n < 3; ++n)
            if (rot[n] != 0.f)
            {   
                s << "<Transform rotation='" << (n == 0) << " " << (n == 1) << " " << (n == 2) << " " 
                  << PIOVER180d*rot[n] << "'>" << std::endl;
                num_rot++;
                s.tab();
            }

        // translate object to center
        Vec3D p = calcCenteringTransform(m, init);
        s << "<Transform translation='" << p.x << " " << p.y << " " << p.z << "'>" << std::endl;
        s.tab();
    }

    for (size_t i=0; i<m->passes.size(); i++) 
    {
        ModelRenderPass &p = m->passes[i];
        if (p.init(m)) 
        {
            s << "<Shape>"  << std::endl;

            size_t counter;

            // write material, color etc.

            s.tab();
            s << "<Appearance>" << std::endl;

            s.tab();

#ifdef NONSTANDARDBLENDMODE
            if (!xhtml)
            {
                writeBlendMode(s, p.blendmode);
                if (p.noZWrite)
                    s << "<DepthMode readOnly='TRUE' />" << std::endl;
            }
#endif
            
            s   << "<Material diffuseColor='"
                << p.ocol.x << " " 
                << p.ocol.y << " " 
                << p.ocol.z << "' ";

            s.toggle();

            if (p.useEnvMap)
                s << "shininess='18.0' ";

#ifndef NONSTANDARDBLENDMODE
            if (!xhtml) 
            {
                s   << "emissiveColor='" 
                    << p.ecol.x << " " 
                    << p.ecol.y << " " 
                    << p.ecol.z << "' "

                    << "transparency='" << 1.f - p.ocol.w << "' ";
            }
#endif
            s << "/>" << std::endl;
            s.toggle();

            // has the texture been used before?
            // no : save texture, create a map entry and define it
            // yes: reuse the previously defined texture
            if (!textures.count(p.tex))
            {
                wxString texName(fn, wxConvUTF8);
                texName = texName.AfterLast(SLASH).BeforeLast('.');
                texName << wxT("_") << p.tex;

                wxString texFilename(fn, wxConvUTF8);
                texFilename = texFilename.BeforeLast(SLASH);
                texFilename += SLASH;
                texFilename += texName;
                texFilename += wxString(wxT(".png"));
                SaveTexture(texFilename);

                textures[p.tex] = texName;

                s << "<ImageTexture DEF='" << textures[p.tex] << "' url='"
                  << texFilename.AfterLast(SLASH).c_str() << "' />" << std::endl;
            }
            else
                s << "<ImageTexture USE='" << textures[p.tex] << "'/>" << std::endl;

            s.rtab();
            s << "</Appearance>" << std::endl;

            // ---------------- write all indices here -----------------

            s << "<IndexedFaceSet solid='false' ";
            s.toggle();

            // write normals
            counter = 0;
            s << "coordIndex='" << std::endl;
            for (size_t k=0; k<p.indexCount; k+=3)
            {
                s << counter+1 << " " << counter+2 << " " << counter+0 << " -1 ";
                counter += 3;
            }
            s << "'>" << std::endl;
            s.toggle();

            // ----------------- write all data here -----------------

            // write vertices
            s.tab();
            s << "<Coordinate DEF='pl_" << i << "' point='" << std::endl;
            s.tab();
            for (size_t k = 0, b=p.indexStart; k<p.indexCount; k++,b++) 
            {
                uint16 a = m->indices[b];
                Vec3D v;

                if (m->vertices == NULL || init == true) 
                    v = m->origVertices[a].pos;
                else
                    v = m->vertices[a];

                s << v.x << " " << v.y << " " << v.z << std::endl;
            }
            s.rtab();
            s << "' />" << std::endl;

            // write normals
            s << "<Normal vector='" << std::endl;
            s.tab();
            for (size_t k = 0, b=p.indexStart; k<p.indexCount; k++,b++) 
            {
                uint16 a = m->indices[b];
                Vec3D v = m->origVertices[a].normal;

                s << v.x << " " << v.y << " " << v.z << std::endl;
            }
            s.rtab();
            s << "' />" << std::endl;

            // write texcoords
            s << "<TextureCoordinate point='" << std::endl;
            s.tab();
            for (size_t k = 0, b=p.indexStart; k<p.indexCount; k++,b++)
            {
                uint16 a = m->indices[b];
                Vec2D v = m->origVertices[a].texcoords;
                s << v.x << " " << 1-v.y << std::endl;
            }
            s.rtab();
            s << "' />" << std::endl;

            s.rtab();
            s << "</IndexedFaceSet>" << std::endl;

            s.rtab();
            s << "</Shape>" << std::endl << std::endl;
        }
    }

    if (m->animated && modelExport_X3D_ExportAnimation)
        M2toX3DAnim(s, m);

    if (modelExport_X3D_CenterModel)
    {
        // close translation
        s.rtab();
        s << "</Transform>" << std::endl;

        // close all rotations
        for (size_t n = 0; n < num_rot; ++n)
        {
            s.rtab();
            s << "</Transform>" << std::endl;
        }
    }

    s.rtab();
    s << "</Scene>" << std::endl;

    s.rtab();
}
Пример #13
0
// MilkShape 3D
void ExportMS3D_M2(Attachment *att, Model *m, const char *fn, bool init)
{
	wxFFileOutputStream f(wxString(fn, wxConvUTF8), wxT("w+b"));

	if (!f.IsOk()) {
		wxLogMessage(wxT("Error: Unable to open file '%s'. Could not export model."), fn);
		return;
	}
	LogExportData(wxT("MS3D"),m->modelname,wxString(fn, wxConvUTF8));
	unsigned short numVerts = 0;
	unsigned short numFaces = 0;
	unsigned short numGroups = 0;
	ModelData *verts = NULL;
	GroupData *groups = NULL;

	//we need the initial position anyway
	InitCommon(att, true, verts, groups, numVerts, numGroups, numFaces);
	//wxLogMessage(wxT("Num Verts: %i, Num Faces: %i, Num Groups: %i"), numVerts, numFaces, numGroups);
	//wxLogMessage(wxT("Vert[0] BoneID: %i, Group[0].m.name = %s"),verts[0].boneid, groups[0].m->name);
	wxLogMessage(wxT("Init Common Complete."));

	// Write the header
	ms3d_header_t header;
	strncpy(header.id, "MS3D000000", sizeof(header.id));
	header.version = 4;

	// Header
	f.Write(reinterpret_cast<char *>(&header), sizeof(ms3d_header_t));
	wxLogMessage(wxT("Header Data Written."));
	// Vertex Count
	f.Write(reinterpret_cast<char *>(&numVerts), sizeof(numVerts));
	//wxLogMessage(wxT("NumVerts: %i"),numVerts);
	
	// Write Vertex data?
	for (size_t i=0; i<numVerts; i++) {
		ms3d_vertex_t vert;
		vert.boneId = verts[i].boneid;
		vert.flags = 0; //SELECTED;
		vert.referenceCount = 0; // what the?
		vert.vertex[0] = verts[i].vertex.x;
		vert.vertex[1] = verts[i].vertex.y;
		vert.vertex[2] = verts[i].vertex.z;
		f.Write(reinterpret_cast<char *>(&vert), sizeof(ms3d_vertex_t));
	}
	wxLogMessage(wxT("Vertex Data Written."));
	// ---------------------------

	// Triangle Count
	f.Write(reinterpret_cast<char *>(&numFaces), sizeof(numFaces));
	//wxLogMessage(wxT("NumFaces: %i"),numFaces);

	// Write Triangle Data?
	for (size_t i=0; i<(unsigned int)numVerts; i+=3) {
		ms3d_triangle_t tri;
		tri.flags = 0; //SELECTED;
		tri.groupIndex = (unsigned char)verts[i].groupIndex;
		tri.smoothingGroup = 1; // 1 - 32

		for (ssize_t j=0; j<3; j++) {
			tri.vertexIndices[j] = (word)i+j;
			tri.s[j] = verts[i+j].tu;
			tri.t[j] = verts[i+j].tv;
			
			tri.vertexNormals[j][0] = verts[i+j].normal.x;
			tri.vertexNormals[j][1] = verts[i+j].normal.y;
			tri.vertexNormals[j][2] = verts[i+j].normal.z;
		}

		f.Write(reinterpret_cast<char *>(&tri), sizeof(ms3d_triangle_t));
	}
	wxLogMessage(wxT("Triangle Data Written."));
	// ---------------------------

	// Number of groups
	f.Write(reinterpret_cast<char *>(&numGroups), sizeof(numGroups));
	//wxLogMessage(wxT("NumGroups: %i"),numGroups);

	unsigned short indiceCount = 0;
	for (unsigned short i=0; i<(unsigned int)numGroups; i++) {
		wxString groupName(wxString::Format(wxT("Geoset_%i"), i));

		const char flags = 0; // SELECTED
		f.Write(&flags, sizeof(flags));

		char name[32];
		strncpy(name, groupName.mb_str(), sizeof(name));
		f.Write(name, sizeof(name));

		unsigned short faceCount = groups[i].p.indexCount / 3;
		f.Write(reinterpret_cast<char *>(&faceCount), sizeof(faceCount));
		
		for (ssize_t k=0; k<faceCount; k++) {
			//triIndices[k] = indiceCount;
			f.Write(reinterpret_cast<char *>(&indiceCount), sizeof(indiceCount));
			indiceCount++;
		}

		unsigned char gIndex = (char)i;
		f.Write(reinterpret_cast<char *>(&gIndex), sizeof(gIndex));
	}
	wxLogMessage(wxT("Group Data Written."));

	// Number of materials (pretty much identical to groups, each group has its own material)
	f.Write(reinterpret_cast<char *>(&numGroups), sizeof(numGroups));
	
	for (unsigned short i=0; i<(unsigned int)numGroups; i++) {
		wxString matName(wxString::Format(wxT("Material_%i"), i));

		ModelRenderPass p = groups[i].p;
		if (p.init(groups[i].m)) {
			ms3d_material_t mat;
			memset(mat.alphamap, '\0', sizeof(mat.alphamap));

			strncpy(mat.name, matName.mb_str(), sizeof(mat.name));
			mat.ambient[0] = 0.7f;
			mat.ambient[1] = 0.7f;
			mat.ambient[2] = 0.7f;
			mat.ambient[3] = 1.0f;
			mat.diffuse[0] = p.ocol.x;
			mat.diffuse[1] = p.ocol.y;
			mat.diffuse[2] = p.ocol.z;
			mat.diffuse[3] = p.ocol.w;
			mat.specular[0] = 0.0f;
			mat.specular[1] = 0.0f;
			mat.specular[2] = 0.0f;
			mat.specular[3] = 1.0f;
			mat.emissive[0] = p.ecol.x;
			mat.emissive[1] = p.ecol.y;
			mat.emissive[2] = p.ecol.z;
			mat.emissive[3] = p.ecol.w;
			mat.transparency = p.ocol.w;

			if (p.useEnvMap) {
				mat.shininess = 30.0f;
				mat.mode = 1;
			} else {
				mat.shininess = 0.0f;
				mat.mode = 0;
			}
/*
			unsigned int bindtex = 0;
			if (groups[i].m->specialTextures[p.tex]==-1) 
				bindtex = groups[i].m->textures[p.tex];
			else 
				bindtex = groups[i].m->replaceTextures[groups[i].m->specialTextures[p.tex]];
*/
			wxString texName = GetM2TextureName(m,p,i);
			texName << wxT(".tga");
			strncpy(mat.texture, texName.mb_str(), sizeof(mat.texture));

			f.Write(reinterpret_cast<char *>(&mat), sizeof(ms3d_material_t));

			wxString texFilename(fn, wxConvUTF8);
			texFilename = texFilename.BeforeLast(SLASH);
			texFilename += SLASH;
			texFilename += texName;
			wxLogMessage(wxT("Exporting Image: %s"),texFilename.c_str());
			SaveTexture(texFilename);
		}
	}
	wxLogMessage(wxT("Material Data Written."));

	if (init)
	{
		float fps = 1.0f;
		float fCurTime = 0.0f;
		int totalFrames = 0;

		f.Write(reinterpret_cast<char *>(&fps), sizeof(fps));
		f.Write(reinterpret_cast<char *>(&fCurTime), sizeof(fCurTime));
		f.Write(reinterpret_cast<char *>(&totalFrames), sizeof(totalFrames));
		
		// number of joints
		unsigned short numJoints = 0;

		f.Write(reinterpret_cast<char *>(&numJoints), sizeof(numJoints));
	}
	else
	{
		float fps = 25.0f;
		float fCurTime = 0.0f;
		int totalFrames = ceil((m->anims[m->anim].timeEnd - m->anims[m->anim].timeStart) / 1000.0f * fps);

		f.Write(reinterpret_cast<char *>(&fps), sizeof(fps));
		f.Write(reinterpret_cast<char *>(&fCurTime), sizeof(fCurTime));
		f.Write(reinterpret_cast<char *>(&totalFrames), sizeof(totalFrames));
		
		// number of joints
		unsigned short numJoints = (unsigned short)m->header.nBones;

		f.Write(reinterpret_cast<char *>(&numJoints), sizeof(numJoints));

		for (size_t i=0; i<numJoints; i++)
		{
			ms3d_joint_t joint;

			int parent = m->bones[i].parent;

			joint.flags = 0; // SELECTED
			memset(joint.name, '\0', sizeof(joint.name));
			snprintf(joint.name, sizeof(joint.name), "Bone_%i", i);
			memset(joint.parentName, '\0', sizeof(joint.parentName));
			if (parent != -1) snprintf(joint.parentName, sizeof(joint.parentName), "Bone_%i", parent);

			joint.rotation[0] = 0;
			joint.rotation[1] = 0;
			joint.rotation[2] = 0;

			Vec3D p = FixPivot(m, (int)i, m->bones[i].pivot);
			joint.position[0] = p.x;
			joint.position[1] = p.y;
			joint.position[2] = p.z;

			joint.numKeyFramesRot = (unsigned short)m->bones[i].rot.data[m->anim].size();
			joint.numKeyFramesTrans = (unsigned short)m->bones[i].trans.data[m->anim].size();

			f.Write(reinterpret_cast<char *>(&joint), sizeof(ms3d_joint_t));

			if (joint.numKeyFramesRot > 0)
			{
				ms3d_keyframe_rot_t *keyFramesRot = new ms3d_keyframe_rot_t[joint.numKeyFramesRot];
				for (size_t j=0; j<joint.numKeyFramesRot; j++)
				{
					keyFramesRot[j].time = m->bones[i].rot.times[m->anim][j] / 1000.0f;
					Vec3D euler = QuatToEuler(m->bones[i].rot.data[m->anim][j]);
					keyFramesRot[j].rotation[0] = euler.x;
					keyFramesRot[j].rotation[1] = euler.y;
					keyFramesRot[j].rotation[2] = euler.z;
				}

				f.Write(reinterpret_cast<char *>(keyFramesRot), sizeof(ms3d_keyframe_rot_t) * joint.numKeyFramesRot);
				wxDELETEA(keyFramesRot);
			}

			if (joint.numKeyFramesTrans > 0)
			{
				ms3d_keyframe_pos_t *keyFramesTrans = new ms3d_keyframe_pos_t[joint.numKeyFramesTrans];
				for (size_t j=0; j<joint.numKeyFramesTrans; j++)
				{
					keyFramesTrans[j].time = m->bones[i].trans.times[m->anim][j] / 1000.0f;
					keyFramesTrans[j].position[0] = m->bones[i].trans.data[m->anim][j].x;
					keyFramesTrans[j].position[1] = m->bones[i].trans.data[m->anim][j].y;
					keyFramesTrans[j].position[2] = m->bones[i].trans.data[m->anim][j].z;
				}

				f.Write(reinterpret_cast<char *>(keyFramesTrans), sizeof(ms3d_keyframe_pos_t) * joint.numKeyFramesTrans);
				wxDELETEA(keyFramesTrans);
			}
		}
	}
	f.Close();
	wxLogMessage(wxT("Finished Milkshape Export."));

	if (verts){
		//wxLogMessage("verts found. Deleting...");
		wxDELETEA(verts);
	}
	if (groups){
		//wxLogMessage("groups found. Deleting...");
		wxDELETEA(groups);
	}

	//wxLogMessage(wxT("Finished Milkshape Cleanup.\n"));
}
Пример #14
0
// Handles the GUI events
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext )
{
    switch( nControlID )
    {
        case IDC_TOGGLEFULLSCREEN:
		{
            DXUTToggleFullScreen();
			break;
		}
        case IDC_TOGGLEREF:
		{
            DXUTToggleREF();
			break;
		}
        case IDC_CHANGEDEVICE:
		{
            gD3DSettingsDlg.SetActive( !gD3DSettingsDlg.IsActive() );
			break;
		}
        case IDC_TEXT:
        case IDC_EXPOSURE:
        {
            gLog2Exposure = (gSampleUI.GetSlider(IDC_EXPOSURE)->GetValue() / 100.0f - 0.5f) * 33.33333;
			WCHAR wstr[MAX_PATH];
			swprintf_s(wstr, MAX_PATH, 
				L"Texture Size: %d x %d\n" 
                L"logRGB L1: %.2f%%\n"
                //L"logRGB RMSE: %.4f\n"
                //L"Relative error: %.2f%%\n"
                //L"mPSNR: %.2f%%\n"
                L"Exposure: %.2f\n"
				L"Compression Time: %0.2f ms\n"
				L"Compression Rate: %0.2f Mp/s\n", 
				gTexWidth, gTexHeight,
                gError, gLog2Exposure,
				gCompTime, gCompRate);
			gSampleUI.GetStatic(IDC_TEXT)->SetText(wstr);
			break;
		}
		case IDC_MT:
		{
			// Shut down all previous threading abilities.
			DestroyThreads();
			
			gMultithreaded = gSampleUI.GetCheckBox(IDC_MT)->GetChecked();
					
			if (gMultithreaded)
			{
				InitWin32Threads();
			}

			// Recompress the texture.
			RecompressTexture();
			gSampleUI.SendEvent(IDC_TEXT, true, gSampleUI.GetStatic(IDC_TEXT));

			break;
		}
		case IDC_PROFILE:
		{ 
			gCompressionFunc = (CompressionFunc*)gSampleUI.GetComboBox(IDC_PROFILE)->GetSelectedData();

			// Recompress the texture.
			RecompressTexture();
			gSampleUI.SendEvent(IDC_TEXT, true, gSampleUI.GetStatic(IDC_TEXT));

			break;
		}
		case IDC_LOAD_TEXTURE:
		{
			// Store the current working directory.
			TCHAR workingDirectory[MAX_PATH];
			GetCurrentDirectory(MAX_PATH, workingDirectory);

			// Open a file dialog.
			OPENFILENAME openFileName;
			WCHAR file[MAX_PATH];
			file[0] = 0;
			ZeroMemory(&openFileName, sizeof(OPENFILENAME));
			openFileName.lStructSize = sizeof(OPENFILENAME);
			openFileName.lpstrFile = file;
			openFileName.nMaxFile = MAX_PATH;
			openFileName.lpstrFilter = L"DDS\0*.dds\0\0";
			openFileName.nFilterIndex = 1;
			openFileName.lpstrInitialDir = NULL;
			openFileName.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
			if(GetOpenFileName(&openFileName))
			{
				//CreateTextures(openFileName.lpstrFile);
                SAFE_RELEASE(gUncompressedSRV);
                LoadTexture(openFileName.lpstrFile);
			}

			// Restore the working directory. GetOpenFileName changes the current working directory which causes problems with relative paths to assets.
			SetCurrentDirectory(workingDirectory);

            RecompressTexture();
			gSampleUI.SendEvent(IDC_TEXT, true, gSampleUI.GetStatic(IDC_TEXT));
			
			break;
		}
		case IDC_RECOMPRESS:
		{
			// Recompress the texture.
			RecompressTexture();
			gSampleUI.SendEvent(IDC_TEXT, true, gSampleUI.GetStatic(IDC_TEXT));

			break;
		}
		case IDC_SAVE_TEXTURE:
		{
			// Store the current working directory.
			TCHAR workingDirectory[MAX_PATH];
			GetCurrentDirectory(MAX_PATH, workingDirectory);

			// Open a file dialog.
			OPENFILENAME openFileName;
			WCHAR file[MAX_PATH];
			file[0] = 0;
			ZeroMemory(&openFileName, sizeof(OPENFILENAME));
			openFileName.lStructSize = sizeof(OPENFILENAME);
			openFileName.lpstrFile = file;
			openFileName.nMaxFile = MAX_PATH;
			openFileName.lpstrFilter = L"DDS\0*.dds\0\0";
			openFileName.lpstrDefExt = L"dds";
			openFileName.nFilterIndex = 1;
			openFileName.lpstrInitialDir = NULL;
			openFileName.Flags = OFN_PATHMUSTEXIST;
            
			if(GetSaveFileName(&openFileName))
			{
				SaveTexture(gCompressedSRV,openFileName.lpstrFile);
			}

			// Restore the working directory. GetOpenFileName changes the current working directory which causes problems with relative paths to assets.
			SetCurrentDirectory(workingDirectory);

			break;
		}
		case IDC_IMAGEVIEW:
		{
			gImageView = (EImageView)(INT_PTR)gSampleUI.GetComboBox(IDC_IMAGEVIEW)->GetSelectedData();

			break;
		}
	}
}