求助!在android中导入OBJ的3D模型怎么导入,求具体方法
4个回答
展开全部
下面的List可用ArrayList替换
InputStream input;
BufferedReader reader;
try
{
List<String> verticeLines = new List<String>();
List<String> textureLines = new List<String>();
List<String> normalLines = new List<String>();
List<String> verticeIndiceLines = new List<String>();
List<String> textureIndiceLines = new List<String>();
List<String> normalIndiceLines = new List<String>();
input=new FileInputStream(data);
reader = new BufferedReader(new InputStreamReader(input));
String line = null;
while((line = reader.readLine()) != null)
{
//?狦琌猔秆┪?フ膥尿铬筁
if(line.startsWith("//") ||line.startsWith("#")|| line.trim().equals(""))
{
continue;
}
String SPACE=" ";
String SLASH="/";
String[] st=RemoveNull(line.split(SPACE));
String lineType = st[0];
if(lineType.equals("v"))
{//郴翴畒夹
verticeLines.Add(st[1]);
verticeLines.Add(st[2]);
verticeLines.Add(st[3]);
}
else if(lineType.equals("vt"))
{//郴翴?借畒夹
textureLines.Add(st[1]);
textureLines.Add(st[2]);
}
else if(lineType.equals("vn"))
{//郴翴猭?秖
normalLines.Add(st[1]);
normalLines.Add(st[2]);
normalLines.Add(st[3]);
}
else if(lineType.equals("f"))
{//?à?癸莱?郴翴??借?猭?秖
//?舱畒夹
String v1=st[1];
String v2=st[2];
String v3=st[3];
String[] st1=v1.split(SLASH);
String[] st2=v2.split(SLASH);
String[] st3=v3.split(SLASH);
//顶点
verticeIndiceLines.Add(st1[0]);
verticeIndiceLines.Add(st2[0]);
verticeIndiceLines.Add(st3[0]);
//纹理
textureIndiceLines.Add(st1[1]);
textureIndiceLines.Add(st2[1]);
textureIndiceLines.Add(st3[1]);
//正常
normalIndiceLines.Add(st1[2]);
normalIndiceLines.Add(st2[2]);
normalIndiceLines.Add(st3[2]);
}
}
//郴翴畒夹:3?????郴翴
int indicesSize=verticeIndiceLines.Count();
indices=new short[indicesSize];
int verticeSize=indicesSize*3;
vertices=new float[verticeSize];
//?借畒夹:埃3т?砀?郴翴??2Τㄢ?畒夹
int textureSize=indicesSize*2;
textures=new float[textureSize];
//猭?秖:–?郴翴常Τ?舱猭?秖??3Τ3?よ??秖
int normalSize=indicesSize*3;
normals =new float[normalSize];
for(int i=0;i<verticeIndiceLines.Count();i++)
{
//郴翴
indices[i]=(short)i;
int indice=Integer.valueOf(verticeIndiceLines.Item(i))-1;
//郴翴畒夹
vertices[i*3]=Float.valueOf(verticeLines.Item(indice*3));
vertices[i*3+1]=Float.valueOf(verticeLines.Item(indice*3+1));
vertices[i*3+2]=Float.valueOf(verticeLines.Item(indice*3+2));
if(!textureIndiceLines.Item(i).equals("")){
int textureIndice=Integer.valueOf(textureIndiceLines.ItemOrDefault(i, "0"))-1;
textures[i*2]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2,"0"));
textures[i*2+1]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2+1,"0"));
System.out.println(textureIndiceLines.Item(i));
}
//猭?秖畒夹
int normalIndice=Integer.valueOf(normalIndiceLines.Item(i))-1;
normals[i*3]=Float.valueOf(normalLines.Item(normalIndice*3));
normals[i*3+1]=Float.valueOf(normalLines.Item(normalIndice*3+1));
normals[i*3+2]=Float.valueOf(normalLines.Item(normalIndice*3+2));
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}。
InputStream input;
BufferedReader reader;
try
{
List<String> verticeLines = new List<String>();
List<String> textureLines = new List<String>();
List<String> normalLines = new List<String>();
List<String> verticeIndiceLines = new List<String>();
List<String> textureIndiceLines = new List<String>();
List<String> normalIndiceLines = new List<String>();
input=new FileInputStream(data);
reader = new BufferedReader(new InputStreamReader(input));
String line = null;
while((line = reader.readLine()) != null)
{
//?狦琌猔秆┪?フ膥尿铬筁
if(line.startsWith("//") ||line.startsWith("#")|| line.trim().equals(""))
{
continue;
}
String SPACE=" ";
String SLASH="/";
String[] st=RemoveNull(line.split(SPACE));
String lineType = st[0];
if(lineType.equals("v"))
{//郴翴畒夹
verticeLines.Add(st[1]);
verticeLines.Add(st[2]);
verticeLines.Add(st[3]);
}
else if(lineType.equals("vt"))
{//郴翴?借畒夹
textureLines.Add(st[1]);
textureLines.Add(st[2]);
}
else if(lineType.equals("vn"))
{//郴翴猭?秖
normalLines.Add(st[1]);
normalLines.Add(st[2]);
normalLines.Add(st[3]);
}
else if(lineType.equals("f"))
{//?à?癸莱?郴翴??借?猭?秖
//?舱畒夹
String v1=st[1];
String v2=st[2];
String v3=st[3];
String[] st1=v1.split(SLASH);
String[] st2=v2.split(SLASH);
String[] st3=v3.split(SLASH);
//顶点
verticeIndiceLines.Add(st1[0]);
verticeIndiceLines.Add(st2[0]);
verticeIndiceLines.Add(st3[0]);
//纹理
textureIndiceLines.Add(st1[1]);
textureIndiceLines.Add(st2[1]);
textureIndiceLines.Add(st3[1]);
//正常
normalIndiceLines.Add(st1[2]);
normalIndiceLines.Add(st2[2]);
normalIndiceLines.Add(st3[2]);
}
}
//郴翴畒夹:3?????郴翴
int indicesSize=verticeIndiceLines.Count();
indices=new short[indicesSize];
int verticeSize=indicesSize*3;
vertices=new float[verticeSize];
//?借畒夹:埃3т?砀?郴翴??2Τㄢ?畒夹
int textureSize=indicesSize*2;
textures=new float[textureSize];
//猭?秖:–?郴翴常Τ?舱猭?秖??3Τ3?よ??秖
int normalSize=indicesSize*3;
normals =new float[normalSize];
for(int i=0;i<verticeIndiceLines.Count();i++)
{
//郴翴
indices[i]=(short)i;
int indice=Integer.valueOf(verticeIndiceLines.Item(i))-1;
//郴翴畒夹
vertices[i*3]=Float.valueOf(verticeLines.Item(indice*3));
vertices[i*3+1]=Float.valueOf(verticeLines.Item(indice*3+1));
vertices[i*3+2]=Float.valueOf(verticeLines.Item(indice*3+2));
if(!textureIndiceLines.Item(i).equals("")){
int textureIndice=Integer.valueOf(textureIndiceLines.ItemOrDefault(i, "0"))-1;
textures[i*2]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2,"0"));
textures[i*2+1]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2+1,"0"));
System.out.println(textureIndiceLines.Item(i));
}
//猭?秖畒夹
int normalIndice=Integer.valueOf(normalIndiceLines.Item(i))-1;
normals[i*3]=Float.valueOf(normalLines.Item(normalIndice*3));
normals[i*3+1]=Float.valueOf(normalLines.Item(normalIndice*3+1));
normals[i*3+2]=Float.valueOf(normalLines.Item(normalIndice*3+2));
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}。
展开全部
下面的List可用ArrayList替换
InputStream input;
BufferedReader reader;
try
{
List verticeLines = new List();
List textureLines = new List();
List normalLines = new List();
List verticeIndiceLines = new List();
List textureIndiceLines = new List();
List normalIndiceLines = new List();
input=new FileInputStream(data);
reader = new BufferedReader(new InputStreamReader(input));
String line = null;
while((line = reader.readLine()) != null)
{
//?狦琌猔秆┪?フ膥尿铬筁
if(line.startsWith("//") ||line.startsWith("#")|| line.trim().equals(""))
{
continue;
}
String SPACE=" ";
String SLASH="/";
String[] st=RemoveNull(line.split(SPACE));
String lineType = st[0];
if(lineType.equals("v"))
{//郴翴畒夹
verticeLines.Add(st[1]);
verticeLines.Add(st[2]);
verticeLines.Add(st[3]);
}
else if(lineType.equals("vt"))
{//郴翴?借畒夹
textureLines.Add(st[1]);
textureLines.Add(st[2]);
}
else if(lineType.equals("vn"))
{//郴翴猭?秖
normalLines.Add(st[1]);
normalLines.Add(st[2]);
normalLines.Add(st[3]);
}
else if(lineType.equals("f"))
{//?à?癸莱?郴翴??借?猭?秖
//?舱畒夹
String v1=st[1];
String v2=st[2];
String v3=st[3];
String[] st1=v1.split(SLASH);
String[] st2=v2.split(SLASH);
String[] st3=v3.split(SLASH);
//顶点
verticeIndiceLines.Add(st1[0]);
verticeIndiceLines.Add(st2[0]);
verticeIndiceLines.Add(st3[0]);
//纹理
textureIndiceLines.Add(st1[1]);
textureIndiceLines.Add(st2[1]);
textureIndiceLines.Add(st3[1]);
//正常
normalIndiceLines.Add(st1[2]);
normalIndiceLines.Add(st2[2]);
normalIndiceLines.Add(st3[2]);
}
}
//郴翴畒夹:3?????郴翴
int indicesSize=verticeIndiceLines.Count();
indices=new short[indicesSize];
int verticeSize=indicesSize*3;
vertices=new float[verticeSize];
//?借畒夹:埃3т?砀?郴翴??2Τㄢ?畒夹
int textureSize=indicesSize*2;
textures=new float[textureSize];
//猭?秖:–?郴翴常Τ?舱猭?秖??3Τ3?よ??秖
int normalSize=indicesSize*3;
normals =new float[normalSize];
for(int i=0;i
{
//郴翴
indices[i]=(short)i;
int indice=Integer.valueOf(verticeIndiceLines.Item(i))-1;
//郴翴畒夹
vertices[i*3]=Float.valueOf(verticeLines.Item(indice*3));
vertices[i*3+1]=Float.valueOf(verticeLines.Item(indice*3+1));
vertices[i*3+2]=Float.valueOf(verticeLines.Item(indice*3+2));
if(!textureIndiceLines.Item(i).equals("")){
int textureIndice=Integer.valueOf(textureIndiceLines.ItemOrDefault(i, "0"))-1;
textures[i*2]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2,"0"));
textures[i*2+1]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2+1,"0"));
System.out.println(textureIndiceLines.Item(i));
}
//猭?秖畒夹
int normalIndice=Integer.valueOf(normalIndiceLines.Item(i))-1;
normals[i*3]=Float.valueOf(normalLines.Item(normalIndice*3));
normals[i*3+1]=Float.valueOf(normalLines.Item(normalIndice*3+1));
normals[i*3+2]=Float.valueOf(normalLines.Item(normalIndice*3+2));
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
InputStream input;
BufferedReader reader;
try
{
List verticeLines = new List();
List textureLines = new List();
List normalLines = new List();
List verticeIndiceLines = new List();
List textureIndiceLines = new List();
List normalIndiceLines = new List();
input=new FileInputStream(data);
reader = new BufferedReader(new InputStreamReader(input));
String line = null;
while((line = reader.readLine()) != null)
{
//?狦琌猔秆┪?フ膥尿铬筁
if(line.startsWith("//") ||line.startsWith("#")|| line.trim().equals(""))
{
continue;
}
String SPACE=" ";
String SLASH="/";
String[] st=RemoveNull(line.split(SPACE));
String lineType = st[0];
if(lineType.equals("v"))
{//郴翴畒夹
verticeLines.Add(st[1]);
verticeLines.Add(st[2]);
verticeLines.Add(st[3]);
}
else if(lineType.equals("vt"))
{//郴翴?借畒夹
textureLines.Add(st[1]);
textureLines.Add(st[2]);
}
else if(lineType.equals("vn"))
{//郴翴猭?秖
normalLines.Add(st[1]);
normalLines.Add(st[2]);
normalLines.Add(st[3]);
}
else if(lineType.equals("f"))
{//?à?癸莱?郴翴??借?猭?秖
//?舱畒夹
String v1=st[1];
String v2=st[2];
String v3=st[3];
String[] st1=v1.split(SLASH);
String[] st2=v2.split(SLASH);
String[] st3=v3.split(SLASH);
//顶点
verticeIndiceLines.Add(st1[0]);
verticeIndiceLines.Add(st2[0]);
verticeIndiceLines.Add(st3[0]);
//纹理
textureIndiceLines.Add(st1[1]);
textureIndiceLines.Add(st2[1]);
textureIndiceLines.Add(st3[1]);
//正常
normalIndiceLines.Add(st1[2]);
normalIndiceLines.Add(st2[2]);
normalIndiceLines.Add(st3[2]);
}
}
//郴翴畒夹:3?????郴翴
int indicesSize=verticeIndiceLines.Count();
indices=new short[indicesSize];
int verticeSize=indicesSize*3;
vertices=new float[verticeSize];
//?借畒夹:埃3т?砀?郴翴??2Τㄢ?畒夹
int textureSize=indicesSize*2;
textures=new float[textureSize];
//猭?秖:–?郴翴常Τ?舱猭?秖??3Τ3?よ??秖
int normalSize=indicesSize*3;
normals =new float[normalSize];
for(int i=0;i
{
//郴翴
indices[i]=(short)i;
int indice=Integer.valueOf(verticeIndiceLines.Item(i))-1;
//郴翴畒夹
vertices[i*3]=Float.valueOf(verticeLines.Item(indice*3));
vertices[i*3+1]=Float.valueOf(verticeLines.Item(indice*3+1));
vertices[i*3+2]=Float.valueOf(verticeLines.Item(indice*3+2));
if(!textureIndiceLines.Item(i).equals("")){
int textureIndice=Integer.valueOf(textureIndiceLines.ItemOrDefault(i, "0"))-1;
textures[i*2]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2,"0"));
textures[i*2+1]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2+1,"0"));
System.out.println(textureIndiceLines.Item(i));
}
//猭?秖畒夹
int normalIndice=Integer.valueOf(normalIndiceLines.Item(i))-1;
normals[i*3]=Float.valueOf(normalLines.Item(normalIndice*3));
normals[i*3+1]=Float.valueOf(normalLines.Item(normalIndice*3+1));
normals[i*3+2]=Float.valueOf(normalLines.Item(normalIndice*3+2));
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-13
展开全部
下面的List可用ArrayList替换
InputStream input;
BufferedReader reader;
try
{
List<String> verticeLines = new List<String>();
List<String> textureLines = new List<String>();
List<String> normalLines = new List<String>();
List<String> verticeIndiceLines = new List<String>();
List<String> textureIndiceLines = new List<String>();
List<String> normalIndiceLines = new List<String>();
input=new FileInputStream(data);
reader = new BufferedReader(new InputStreamReader(input));
String line = null;
while((line = reader.readLine()) != null)
{
//�狦琌猔秆┪�フ膥尿铬筁
if(line.startsWith("//") ||line.startsWith("#")|| line.trim().equals(""))
{
continue;
}
String SPACE=" ";
String SLASH="/";
String[] st=RemoveNull(line.split(SPACE));
String lineType = st[0];
if(lineType.equals("v"))
{//郴翴畒夹
verticeLines.Add(st[1]);
verticeLines.Add(st[2]);
verticeLines.Add(st[3]);
}
else if(lineType.equals("vt"))
{//郴翴�借畒夹
textureLines.Add(st[1]);
textureLines.Add(st[2]);
}
else if(lineType.equals("vn"))
{//郴翴猭�秖
normalLines.Add(st[1]);
normalLines.Add(st[2]);
normalLines.Add(st[3]);
}
else if(lineType.equals("f"))
{//�à�癸莱�郴翴��借�猭�秖
//�舱畒夹
String v1=st[1];
String v2=st[2];
String v3=st[3];
String[] st1=v1.split(SLASH);
String[] st2=v2.split(SLASH);
String[] st3=v3.split(SLASH);
//顶点
verticeIndiceLines.Add(st1[0]);
verticeIndiceLines.Add(st2[0]);
verticeIndiceLines.Add(st3[0]);
//纹理
textureIndiceLines.Add(st1[1]);
textureIndiceLines.Add(st2[1]);
textureIndiceLines.Add(st3[1]);
//正常
normalIndiceLines.Add(st1[2]);
normalIndiceLines.Add(st2[2]);
normalIndiceLines.Add(st3[2]);
}
}
//郴翴畒夹:3�����郴翴
int indicesSize=verticeIndiceLines.Count();
indices=new short[indicesSize];
int verticeSize=indicesSize*3;
vertices=new float[verticeSize];
//�借畒夹:埃3т�砀�郴翴��2Τㄢ�畒夹
int textureSize=indicesSize*2;
textures=new float[textureSize];
//猭�秖:–�郴翴常Τ�舱猭�秖��3Τ3�よ��秖
int normalSize=indicesSize*3;
normals =new float[normalSize];
for(int i=0;i<verticeIndiceLines.Count();i++)
{
//郴翴
indices[i]=(short)i;
int indice=Integer.valueOf(verticeIndiceLines.Item(i))-1;
//郴翴畒夹
vertices[i*3]=Float.valueOf(verticeLines.Item(indice*3));
vertices[i*3+1]=Float.valueOf(verticeLines.Item(indice*3+1));
vertices[i*3+2]=Float.valueOf(verticeLines.Item(indice*3+2));
if(!textureIndiceLines.Item(i).equals("")){
int textureIndice=Integer.valueOf(textureIndiceLines.ItemOrDefault(i, "0"))-1;
textures[i*2]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2,"0"));
textures[i*2+1]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2+1,"0"));
System.out.println(textureIndiceLines.Item(i));
}
//猭�秖畒夹
int normalIndice=Integer.valueOf(normalIndiceLines.Item(i))-1;
normals[i*3]=Float.valueOf(normalLines.Item(normalIndice*3));
normals[i*3+1]=Float.valueOf(normalLines.Item(normalIndice*3+1));
normals[i*3+2]=Float.valueOf(normalLines.Item(normalIndice*3+2));
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
InputStream input;
BufferedReader reader;
try
{
List<String> verticeLines = new List<String>();
List<String> textureLines = new List<String>();
List<String> normalLines = new List<String>();
List<String> verticeIndiceLines = new List<String>();
List<String> textureIndiceLines = new List<String>();
List<String> normalIndiceLines = new List<String>();
input=new FileInputStream(data);
reader = new BufferedReader(new InputStreamReader(input));
String line = null;
while((line = reader.readLine()) != null)
{
//�狦琌猔秆┪�フ膥尿铬筁
if(line.startsWith("//") ||line.startsWith("#")|| line.trim().equals(""))
{
continue;
}
String SPACE=" ";
String SLASH="/";
String[] st=RemoveNull(line.split(SPACE));
String lineType = st[0];
if(lineType.equals("v"))
{//郴翴畒夹
verticeLines.Add(st[1]);
verticeLines.Add(st[2]);
verticeLines.Add(st[3]);
}
else if(lineType.equals("vt"))
{//郴翴�借畒夹
textureLines.Add(st[1]);
textureLines.Add(st[2]);
}
else if(lineType.equals("vn"))
{//郴翴猭�秖
normalLines.Add(st[1]);
normalLines.Add(st[2]);
normalLines.Add(st[3]);
}
else if(lineType.equals("f"))
{//�à�癸莱�郴翴��借�猭�秖
//�舱畒夹
String v1=st[1];
String v2=st[2];
String v3=st[3];
String[] st1=v1.split(SLASH);
String[] st2=v2.split(SLASH);
String[] st3=v3.split(SLASH);
//顶点
verticeIndiceLines.Add(st1[0]);
verticeIndiceLines.Add(st2[0]);
verticeIndiceLines.Add(st3[0]);
//纹理
textureIndiceLines.Add(st1[1]);
textureIndiceLines.Add(st2[1]);
textureIndiceLines.Add(st3[1]);
//正常
normalIndiceLines.Add(st1[2]);
normalIndiceLines.Add(st2[2]);
normalIndiceLines.Add(st3[2]);
}
}
//郴翴畒夹:3�����郴翴
int indicesSize=verticeIndiceLines.Count();
indices=new short[indicesSize];
int verticeSize=indicesSize*3;
vertices=new float[verticeSize];
//�借畒夹:埃3т�砀�郴翴��2Τㄢ�畒夹
int textureSize=indicesSize*2;
textures=new float[textureSize];
//猭�秖:–�郴翴常Τ�舱猭�秖��3Τ3�よ��秖
int normalSize=indicesSize*3;
normals =new float[normalSize];
for(int i=0;i<verticeIndiceLines.Count();i++)
{
//郴翴
indices[i]=(short)i;
int indice=Integer.valueOf(verticeIndiceLines.Item(i))-1;
//郴翴畒夹
vertices[i*3]=Float.valueOf(verticeLines.Item(indice*3));
vertices[i*3+1]=Float.valueOf(verticeLines.Item(indice*3+1));
vertices[i*3+2]=Float.valueOf(verticeLines.Item(indice*3+2));
if(!textureIndiceLines.Item(i).equals("")){
int textureIndice=Integer.valueOf(textureIndiceLines.ItemOrDefault(i, "0"))-1;
textures[i*2]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2,"0"));
textures[i*2+1]=Float.valueOf(textureLines.ItemOrDefault(textureIndice*2+1,"0"));
System.out.println(textureIndiceLines.Item(i));
}
//猭�秖畒夹
int normalIndice=Integer.valueOf(normalIndiceLines.Item(i))-1;
normals[i*3]=Float.valueOf(normalLines.Item(normalIndice*3));
normals[i*3+1]=Float.valueOf(normalLines.Item(normalIndice*3+1));
normals[i*3+2]=Float.valueOf(normalLines.Item(normalIndice*3+2));
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-13
展开全部
同样的疑问!!!有没有开源的什么引擎或方法!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询