步骤1:将场景中的家具按类别分类。将name.txt文件,按类别提取模型,放在一个文件夹里面。
步骤2:每一个文件夹中的家具 最好先 规格化,用3Dmax读入。根据 给定的几个场景,选择对应的家具,放到 “场景文件夹”(命名:livingroom001,study001等)中。
步骤3:对于“场景文件夹”中的所有家具,再规格化(方便显示家具)。
步骤2:每一个文件夹中的家具 最好先 规格化,用3Dmax读入。根据 给定的几个场景,选择对应的家具,放到 “场景文件夹”(命名:livingroom001,study001等)中。
步骤3:对于“场景文件夹”中的所有家具,再规格化(方便显示家具)。
步骤4:根据给定的场景,在3Dmax软件读入模型,对家具缩放、旋转、平移操作,满足场景的大致比例要求。
源代码:
#include <iostream>
#include <string>
#include <fstream>
#include<cstring>
using namespace std;
char*StrCat(const char*dest,const char*src) //字符串连接函数
{int dl=strlen(dest);
int sl=strlen(src);
char*a=new char[dl+sl+1];
memset(a,0,dl+sl+1);
for(int i=0;i<dl;i++)
{a[i]=dest[i];}
for(int i=dl;i<dl+sl+1;i++)
{a[i]=src[i-dl];}
return a;
}
int ReadIn(const char *SourceFile,const char *NewFile) //复制同名文件,由A文件夹到B文件夹
{
ifstream in;
ofstream out;
in.open(SourceFile,ios::binary);//打开源文件
if(in.fail())//打开源文件失败
{
cout<<"Error 1: Fail to open the source file."<<endl;
in.close();
out.close();
return 0;
}
out.open(NewFile,ios::binary);//创建目标文件
if(out.fail())//创建文件失败
{
cout<<"Error 2: Fail to create the new file."<<endl;
out.close();
in.close();
return 0;
}
else//复制文件
{
out<<in.rdbuf();
out.close();
in.close();
return 1;
}
}
int main ( )
{
string s[10000];
string t1[10000],t2[10000];
ifstream inf;
inf.open("f:\\SRP\\names.txt"); //打开某路径上的names.txt格式的文件
int i=0;
while( getline(inf,s[i])) //将txt文件中每一行数据读入s[]
{
i++;
}
for(int j=0;j<i;j++) //s[]字符串数组以'|'字符为界,分割成一个文件名数组t1[],一个文件内容关键字数组t2[]
{
int temp=s[j].find("|",0);
t1[j]=s[j].substr(0,temp);
t2[j]=s[j].substr(temp+1);
}
char ssite[256], nsite[256];
char TypeName[256];
cout<<"Start!!!"<<endl;
while(1)
{
cout<<"请输入要写入的物品种类:";
cin>>TypeName;
cout<<"请输入源文件夹路径:";
cin>>ssite;
cout<<"请输入新文件夹的路径:";
cin>>nsite;
char temp;
for(int j=0; j<i; j++)
{
if(t2[j].find(TypeName)!=string::npos) //检索该串中是否有该关键字符串,如果有,则复制该文件到对应文件夹
{
string s1=StrCat(StrCat(ssite,t1[j].c_str()),".obj");
string s2=StrCat(StrCat(nsite,t1[j].c_str()),".obj");
string p1=StrCat(StrCat(ssite,t1[j].c_str()),".mtl");
string p2=StrCat(StrCat(nsite,t1[j].c_str()),".mtl");
if(ReadIn(s1.c_str(), s2.c_str()) && ReadIn(p1.c_str(), p2.c_str()))
{
cout<<"Copy Succeeded!"<<endl;
}
else
{
cout<<"Copy Error!"<<endl;
}
}
}
cin.get();
cout<<"是否结束?(Y/N)"<<endl;
cin>>temp;if(temp=='Y')break;
system("cls");
}
cin.get();
}