テクスチャ イメージを含む .pod ファイルとフォルダーをダウンロードする必要があります。その後、ポッド ファイルをロードする必要があります。きれいな 3D 画像が表示されるはずです。
//podNr is the id of the pod.
NSString *url2 = @"http://(MY URL FOR POD FILE);
NSString *urlIm2 = @"http:(MY URL FOR TEXTURE FOLDER);
NSURL *Url = [NSURL URLWithString:url2];
NSURL *UrlIm = [NSURL URLWithString:urlIm2];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *podFile = [NSString stringWithFormat:@"PODFILE%d.pod",podNr];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:podFile];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/images"];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil]; //Create folder
NSMutableData *urlData = [NSMutableData dataWithContentsOfURL:Url];
NSMutableData *urlImageData = [NSMutableData dataWithContentsOfURL:UrlIm];
NSString *folder = [NSString stringWithContentsOfURL:UrlIm encoding:NSUTF8StringEncoding error:nil];
NSLog(@"FOLDER CONTENT:%@",folder);
if (folder != nil) {
[self getImages:folder andpodNr:podNr];
}
NSLog(@"urlIMAGE:%d",[urlImageData length]);
[urlData writeToFile:filePath atomically:YES];
NSLog(@"sucsesfully written to file:%d",[urlData length]);
[self addContentFromPODFile: filePath];
addImages 関数のコードは次のとおりです。
-(NSMutableArray*) getImages:(NSString *)html andpodNr:(int)podNr
{
NSMutableArray *outPut = [NSMutableArray alloc];
NSString *S = html;
NSString *rest;
while(TRUE)
{
if ([S rangeOfString:@".jpg\""].location == NSNotFound) {
return outPut;
}
else {
//existe .jpg!
int jpgPos = 0;
int rangeOfCom = 0;
NSString *auxS = S;
while (TRUE) {
jpgPos = [auxS rangeOfString:@".jpg\""].location;
rangeOfCom = [auxS rangeOfString:@"\""].location;
if (rangeOfCom == NSNotFound) {
return outPut;
}
if (rangeOfCom > jpgPos) {
break;
}
else {
auxS = [auxS substringFromIndex:rangeOfCom+1];
}
}
NSString *result = [auxS substringToIndex:rangeOfCom];
rest = [auxS substringFromIndex:rangeOfCom+1];
NSLog(@"RESULT:%@",result);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *newResult = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *newPath = [NSString stringWithFormat:@"/images/%@",newResult];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:newPath];
NSString *urlIm2 = @"http://(MY URL FOR IMAGES);
NSLog(@"URL:%@",urlIm2);
NSURL *urlA = [NSURL URLWithString:urlIm2];
NSMutableData *imgData = [NSMutableData dataWithContentsOfURL:urlA];
[imgData writeToFile:filePath atomically:YES];
NSLog(@"Written %d to %@",[[NSMutableData dataWithContentsOfFile:filePath] length],filePath);
}
S = rest;
}
return outPut;
出力は次のとおりです。
2012-11-29 15:12:07.324 homy2[1181:207] FOLDER CONTENT:<!DOCTYPE HTML PUBLIC "- //W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /models/1685740/m/images</title>
</head>
<body>
<h1>Index of /models/1685740/m/images</h1>
<ul><li><a href="/models/1685740/m/"> Parent Directory</a></li>
<li><a href="wood%202.jpg"> wood 2.jpg</a></li>
</ul>
</body></html>
2012-11-29 15:12:07.326 homy2[1181:207] RESULT:wood%202.jpg
2012-11-29 15:12:07.327 homy2[1181:207] URL:http://(MY URL)models/1685740/m/images/wood%202.jpg
2012-11-29 15:12:07.911 homy2[1181:207] Written 50443 to /Users/demianschkolnikmuller/Library/Application Support/iPhone Simulator/4.2/Applications/685E679A-E6D9-4834-952E-9158BB37C2B9/Documents/images/wood 2.jpg
2012-11-29 15:12:07.911 homy2[1181:207] urlIMAGE:315
2012-11-29 15:12:07.913 homy2[1181:207] successfully written to file:21600
2012-11-29 15:12:07.944 homy2[1181:207] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2012-11-29 15:12:07.945 homy2[1181:207] cocos2d: Couldn't add image:wood 2.jpg in CCTextureCache
2012-11-29 15:12:07.946 homy2[1181:207] [***ERROR***] CC3Texture wood%202.jpg-1 could not load texture from file wood 2.jpg
したがって、いくつかのことがあります..ご覧のとおり、file:21600に正常に書き込まれたと表示されるため、ダウンロードして書き込みを行っています...シミュレーターは単にクラッシュします。何か案は?追加情報が必要な場合はお尋ねください。事前に感謝します。長い投稿で申し訳ありません。