need help loading 3ds in cocoa

tyzerg
Unregistered
 
Post: #1
hi, i am having a lot of trouble trying to load 3ds files using cocoa. ive looked at many examples/tutorials, and i understand the file format, but cocoa seems to be messing everything up. does anyone have any cocoa source code for 3ds loading?
thanks
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #2
When you say 'cocoa is messing everything up,' be more specific. What's going wrong?

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
tyzerg
Unregistered
 
Post: #3
apparently it is having trouble getting the longs that denote chunk length from the file data. it always gets some incredibly large number, many times larger than the file size itself. it does however seem to read the chunk id shorts properly. i am completely clueless why cocoa is doing this.
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #4
How are you reading the longs? Using standard C calls or NSData or what?

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Member
Posts: 268
Joined: 2005.04
Post: #5
It's probably not Cocoa screwing it up. It sounds like a big/little endian issue.

http://www.webopedia.com/TERM/b/big_endian.html
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #6
Oooh, good call Bachus! I second that...

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
tyzerg
Unregistered
 
Post: #7
this is the code i use to try to find the length of the file(it is stored as a long starting 2 bytes in):
totalLength = *(long *)(buffer+2);
buffer is a pointer to a char which contains the file data

i did take a look at the endians before posting, but it didnt seem to have much effect. although im fairly inexperienced with endians, so i may have been doing it wrong anyway.

if anyone could just give some source code for accessing that long, or even point me over to an open source cocoa 3ds loader i would greatly appreciate it.
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #8
That code will fall right into endian problems. What you'll have to do is swap the byte order around. Try this code for longs. Then convert it for use in shorts, etc.

I haven't tested this code, it's off the top of my head
Code:
long little2Big(long l){
long b = 0;
b |= ((l & 0xF000) >> 16);
b |= ((l & 0x0F00) >> 16);
b |= ((l & 0x00F0) << 16);
b |= ((l & 0x000F) << 16);
return b;
}

I think that should do it. Good luck. Fiddle with it until it returns what you're expecting Wink

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #9
Apple's Endian.h header contains macros for doing endian conversions (search for it or look in the CarbonCore headers folder).

They're a bit different to Steven's, although his may still be correct, I haven't checked.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #10
Why does each say
Quote:Availability:
* Mac OS X: not available
* CarbonLib: not available
* Non-Carbon CFM: not available
then?

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #11
I saw that, but it doesn't really matter whether or not the API calls are in Carbon because the relevant macros are listed at the bottom of the file.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
tyzerg
Unregistered
 
Post: #12
your code doesnt seem to work, it keeps returning 0. but wouldnt it reverse the endian if i just read in the long backwards from the file?
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #13
Yes, or try this (again, from Apple's Endian.h):

Code:
#define Endian32_Swap(value) \
    (((((UInt32)value)<<24) & 0xFF000000) | \
    ((((UInt32)value)<< 8) & 0x00FF0000) | \
    ((((UInt32)value)>> 8) & 0x0000FF00) | \
    ((((UInt32)value)>>24) & 0x000000FF))

Unless I'm going blind, Steven's code appears to rearrange 0x1234 as 0x3412. It shouldn't return zero, though - are you sure you're not doing something else wrong?

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
tyzerg
Unregistered
 
Post: #14
Quote:Originally posted by NCarter
Yes, or try this (again, from Apple's Endian.h):

Code:
#define Endian32_Swap(value) \
    (((((UInt32)value)<<24) & 0xFF000000) | \
    ((((UInt32)value)<< 8) & 0x00FF0000) | \
    ((((UInt32)value)>> 8) & 0x0000FF00) | \
    ((((UInt32)value)>>24) & 0x000000FF))

Unless I'm going blind, Steven's code appears to rearrange 0x1234 as 0x3412. It shouldn't return zero, though - are you sure you're not doing something else wrong?
thanks, that seems to work perfectly Smile
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #15
Well, I told you that it might not be right, but yeah it shouldn't return 0. Oh well, use Apple's code Wink

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Texture Loading in Cocoa... dave05 3 7,914 Dec 11, 2007 03:12 AM
Last Post: DoG
  Loading and using textures with alpha in OpenGL with Cocoa corporatenewt 4 5,668 Dec 8, 2007 02:06 PM
Last Post: Malarkey
  loading textures - cocoa openGL mDmarco 20 9,052 Aug 28, 2007 08:48 PM
Last Post: OneSadCookie
  Cocoa Texture Loading Code Problem Nick 1 2,958 Oct 28, 2005 11:44 PM
Last Post: OneSadCookie
  Quick texture loading in Cocoa? Fenris 20 7,928 Jun 10, 2003 03:18 AM
Last Post: Fenris