Thing is this: I have to dynamically download the pod files with their texture folder.
http://stackoverflow.com/questions/13632435/cocos-3d-crashes-it-says-it-cant-load-a-texture
Any ideas?
A fast, easy to use, free, and community supported 2D game engine
Thing is this: I have to dynamically download the pod files with their texture folder.
http://stackoverflow.com/questions/13632435/cocos-3d-crashes-it-says-it-cant-load-a-texture
Any ideas?
I made several Updates. Apparently, this line
UIImage *jpg = [[UIImage alloc] initWithContentsOfFile:fullpath];
in CCTextureCache
is not working, in fact, jpg remains nil. I looked for the image in the finder, and it is there!
could it be something with permissions? Can my code acces that path?
It might be in Finder is it correctly added to you project and shown on Xcode? Try removing and adding it again and maybe clean the project. That's what I do first when files seem to be missing.
I can't add it to xcode because it is a file I dinamically download.
I can't really tell from the code you posted in your link above, but are you loading the textures into cocos3d as part of the POD loading, or are you loading the textures separately and then applying them to the POD model?
Once you've extracted them from your URL's, are the textures and the POD located in the same directory?
And in reference to your post title, is the app actually crashing because a texture can't be found? I don't see that in the log you posted.
...Bill
Hi Bill! Thanks for your answer.
I am loading the textures into cocos3d as part of the POD loading (automagically).
The textures are in the the folder /images which is in the same folder as the POD file.
Like this:
Path of the texture:/Users/demianschkolnikmuller/Library/Application Support/iPhone Simulator/4.2/Applications/685E679A-E6D9-4834-952E-9158BB37C2B9/Documents/images/texture1.JPG
Path of the POD:/Users/demianschkolnikmuller/Library/Application Support/iPhone Simulator/4.2/Applications/685E679A-E6D9-4834-952E-9158BB37C2B9/Documents/PODFILE1.pod
This is the code where I load the pod file:
podNr is the number of the pod I'm loading.
NSString *url2 = [NSString stringWithFormat:@"http://(PRIVATE URL)/models/%d/m/%d.pod",podNr,podNr];
NSString *urlIm2 = [NSString stringWithFormat:@"http:///(PRIVATE URL)/models/%d/m/images",podNr];
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];
I replaced the url where I get the files, I can't publish it (it is not mine).
This is my getImages function:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *newPath = [NSString stringWithFormat:@"/images/%@",result];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:newPath];
NSString *urlIm2 = [NSString stringWithFormat:@"http://(PRIVATE URL)/models/%d/m/images/%@",podNr,result];
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);
Strange thing is, I can see the file with the finder. I tried with different textures and no success. When I load in xcode the texture with the pod, it works.
with breakpoints I realized that the method UIImage *jpg = [[UIImage alloc] initWithContentsOfFile:fullpath]; in CCTextureCache returns nil, even if the file already is there.
Bill (or anyone) if you need something else or I left something out please tell me and I will gladly post it.
Thanks again for your support!
Naimed.
What's happening in the resource logs ('[rez]')?
Are you seeing errors indicating that the texture couldn't be found during POD loading? What does the POD loader log for the path of the texture file it is trying to find?
Most POD files expect the texture to be located in the same directory. Was the POD model created knowing that its textures would be in a different directory?
...Bill
I dont know what the resource logs are Bill. How do I access them?
The POD model was created knowing the textures would be in a folder. When I load the POD manually into xcode files, it works fine.
This is the log:
2012-12-12 14:54:38.241 homy2[1751:207] URL:http://(my domain)/models/1714082/m/images/mroja.jpg
2012-12-12 14:54:40.404 homy2[1751:207] Written 319983 to /Users/demianschkolnikmuller/Library/Application Support/iPhone Simulator/4.2/Applications/685E679A-E6D9-4834-952E-9158BB37C2B9/Documents/images/mroja.jpg
2012-12-12 14:54:40.405 homy2[1751:207] urlIMAGE:311
2012-12-12 14:54:40.406 homy2[1751:207] sucsesfully written to file:32553
2012-12-12 14:54:40.408 homy2[1751:207] PATH:/Users/demianschkolnikmuller/Library/Application Support/iPhone Simulator/4.2/Applications/685E679A-E6D9-4834-952E-9158BB37C2B9/Documents/images/mroja.jpg
the URL and Written logs are in the previously given method getImages. UrlIMAGE and succesfully written are in the main method from above.
In this example, the POD doesn't appear on screen. It does not appear at all.
Thanks again for your work & patience..!
Hi All + Bill. Somehow I solved the problem. I think it was a texture property problem, the designer changed some stuff he can't remember now, and it works fine. But..
I have another issue now. I want to add the model. Afterwards I want to add a new model, removing the old one. I simply can't do it. I tried getting the POD with getNodeTagged and then releasing it, but it doesn't work. How do I remove a pod file after adding ir with [self addContentFromPODFile: filePath]; ??
Again, thank you Bill and the community so much for the great job!
Greetings, Naimed.
I try this in my world class but then the next POD simply doesn't appear on screen:
-(void) unRender
{
NSLog(@"UNRENDERANDO!!!");
[self removeAllChildren];
[self createAddons];
[newNode release];
}
-(void) createAddons
{
// Create the camera, place it back a bit, and add it to the world
cam = [CC3Camera nodeWithName: @"Camera"];
cam.location = cc3v( 0.0, 0.0, 6.0 );
[self addChild: cam];
// Create a light, place it back and to the left at a specific
// position (not just directional lighting), and add it to the world
CC3Light* lamp = [CC3Light nodeWithName: @"Lamp"];
lamp.location = cc3v( -2.0, 0.0, 0.0 );
lamp.isDirectionalOnly = NO;
[cam addChild: lamp];
}
newNode is the node where I put my POD in.
Is there anything else that gets removed from the world that is important that I am not adding?
Each node is retained internally by its parent in the node hierarchy.
To remove any node (including a POD node) from its parent (and therefore from the scene), simply invoke the remove method on the node you want to remove.
Because the node structure is hierarchical, this will also remove any descendant nodes of that node.
The node will clean up after itself as you would expect. If the parent is the only thing retaining the node when you invoke the remove method, it will be automatically deallocated (as will all its descendant nodes, and any meshes that are only retained by those nodes).
...Bill
I do [self addContentFromPODFile:filePath] , how do I get all nodes added, to release all of them?
[self addContentFromPODFile: filePath];
CC3MeshNode* helloTxt = (CC3MeshNode*)[self getNodeTagged:2];
newNode = [[CC3MeshNode alloc] init];
if (helloTxt != nil) {
[newNode addChild:helloTxt];
}
if (newNode != nil)
{
[self addChild:newNode];
}
Thats my code for adding the POD. How do I remove it? By releasing newNode the POD doesn't get removed. How do I 'grab' the POD added?
Thanks!
@ Naimed
Instead of loading the POD with addContentFromPODFile:, use CC3PODResourceNode nodeFromFile: instead. This will return you the POD node itself.
You can then use getNodeNamed: to retrieve the node you really want from inside the POD node. Don't use getNodeTagged: method, as the tags are assigned dynamically.
The names of all the nodes are logged during loading, so you can determine the structure of your POD node from the logs.
Have a look at the addMascots method of CC3DemoMashUp for an example of using this technique.
...Bill
You must log in to post.