Public Group

# Iphone: Importing 3DS objects via OBJ file; export or import issue?

This topic is 2417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,

I have recently downloaded the 30-day trial version of 3DSMAX 2012; and would like to import some of my objects into an IPhone application.
My idea has been to export the file from 3DS in OBJ format and read them from my app afterward. From the App log, i can see that all vertex data are correctly read as i can see exactly the values as they are defined in the OBJ file. However, what i get on the iphone simulator is not what i have drawn on 3DS.

To simplify my investigation, i have imported a cube; with the following vertices (see the attached screenshots; one being the object drawn, second being the object shown in the iphone simulator)

-49.6109f, -37.0908f, 14.4273f,
-10.8045f, 40.7808f, 59.8638f,
76.1792f, 40.7808f, -14.4273f,
37.3728f, -37.0908f, -59.8638f,
-25.655f, -65.3948f, 42.476f,
61.3287f, -65.3948f, -31.8151f,
100.1351f, 12.4768f, 13.6214f,
13.1514f, 12.4768f, 87.9125f,

The code i use in the drawing method is the following:

glVertexPointer(3, GL_FLOAT, 0, [drawObjectTmp getVertices]);

glEnableClientState(GL_VERTEX_ARRAY);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);

With the arrays of drawobjectmp having the exact values described in the OBJ file. Note also that the GL_TRIANGLES option has presented similar results on the screen.

My current assumption is that something has to be done on the objects in 3DS studio max to export the file with a certain vertex "order"; however i am a total beginner in 3DS so it makes my troubleshooting rather slow. I have couple of leads on teslta to transform surface into trianges but it didn't really work out on the simulator screen either. I have tried also exporting the objects with the triange option on; didn't help either.

I am sure it's a trivial issue for any experienced person in opengl and 3ds max; but i am not , yet
so i am open for any suggestions, pointers to good tutorials or demos on this particular topic.
Thanks ))

Babarorhum

##### Share on other sites
So, I don't know much about openGL but have you tried using GL_POLYLGON or some other mode instead of GL_TRIANGLE_STRIP ?

##### Share on other sites
Hello Kobo,
Thanks for your suggestion.
However neither GL_POLYGON nor GL_QUADS options are available for this version openGL. I found on a blog a post describing how to draw polygons with GL_TRIANGE_STRIP, hence my attempt.

Since yesterday i've found out one bug though: the last parameter of the DrawArray method doesn't represent the number of vertices but the total number of elements within the array, e.g. 32 in the example. It helps in a way: it creates more gibberish on the screen; which is some sort of progress right ?

Currently suspecting either the way i export from 3ds studio or something funny in my code to display the vertices.

BabarOrhum

So, I don't know much about openGL but have you tried using GL_POLYLGON or some other mode instead of GL_TRIANGLE_STRIP ?

##### Share on other sites
An update on this question: I have installed the trial version of Lightwave to study the export functionality to OBJ and i have redrawn a similar cube as the 3DS studio version.

It works right away into the Iphone app software which confirms the idea that i am missing some options in 3DS studio either while "designing" the cube or exporting it.

As example, lightwave pulls out the following list of vertices; which is much longer than the previous ones for a similar structure created in 3DS (see above post). I also enclose the screenshot of the created cube in lightwave. One major difference is that each face of the cube is made of triangle. Interesting thing: when i "tesselate" the cube under 3ds studio it gives the same visual appearance (2 triangles per face)but exporting it ,doesn't give the same list.

If any of you has a similar experience and know how to transform geometric structure in 3DS to obtain such result ; you will make my day

-Babarorhum

the Lightwave vertices:
[color="#4e00d7"][color="#000000"] 0.300401f[color="#000000"], -0.718622f[color="#000000"], 2.07324f[color="#000000"],

[color="#4e00d7"][color="#000000"] -1.17128f[color="#000000"], -1.47058f[color="#000000"], 1.03826f[color="#000000"],

[color="#4e00d7"][color="#000000"] -0.187194f[color="#000000"], -2.136f[color="#000000"], 0.122397f[color="#000000"],

[color="#4e00d7"][color="#000000"] 1.28449f[color="#000000"], -1.38403f[color="#000000"], 1.15738f[color="#000000"],

[color="#4e00d7"][color="#000000"] 0.300401f[color="#000000"], -0.718622f[color="#000000"], 2.07324f[color="#000000"],

[color="#4e00d7"][color="#000000"] -0.187194f[color="#000000"], -2.136f[color="#000000"], 0.122397f[color="#000000"],

[color="#4e00d7"][color="#000000"] -1.17128f[color="#000000"], -0.0143543f[color="#000000"], -0.0197569f[color="#000000"],

[color="#4e00d7"][color="#000000"] -0.187194f[color="#000000"], -0.679765f[color="#000000"], -0.935616f[color="#000000"],

[color="#4e00d7"][color="#000000"] -0.187194f[color="#000000"], -2.136f[color="#000000"], 0.122397f[color="#000000"],

[color="#4e00d7"][color="#000000"] -1.17128f[color="#000000"], -1.47058f[color="#000000"], 1.03826f[color="#000000"],

[color="#4e00d7"][color="#000000"] -1.17128f[color="#000000"], -0.0143543f[color="#000000"], -0.0197569f[color="#000000"],

[color="#4e00d7"][color="#000000"] -0.187194f[color="#000000"], -2.136f[color="#000000"], 0.122397f[color="#000000"],

[color="#4e00d7"][color="#000000"] 0.300401f[color="#000000"], 0.737608f[color="#000000"], 1.01523f[color="#000000"],

[color="#4e00d7"][color="#000000"] -1.17128f[color="#000000"], -0.0143543f[color="#000000"], -0.0197569f[color="#000000"],

[color="#4e00d7"][color="#000000"] -1.17128f[color="#000000"], -1.47058f[color="#000000"], 1.03826f[color="#000000"],

[color="#4e00d7"][color="#000000"] 0.300401f[color="#000000"], -0.718622f[color="#000000"], 2.07324f[color="#000000"],

[color="#4e00d7"][color="#000000"] 0.300401f[color="#000000"], 0.737608f[color="#000000"], 1.01523f[color="#000000"],

[color="#4e00d7"][color="#000000"] -1.17128f[color="#000000"], -1.47058f[color="#000000"], 1.03826f[color="#000000"],

[color="#4e00d7"][color="#000000"] 0.300401f[color="#000000"], 0.737608f[color="#000000"], 1.01523f[color="#000000"],

[color="#4e00d7"][color="#000000"] 0.300401f[color="#000000"], -0.718622f[color="#000000"], 2.07324f[color="#000000"],

[color="#4e00d7"][color="#000000"] 1.28449f[color="#000000"], -1.38403f[color="#000000"], 1.15738f[color="#000000"],

[color="#4e00d7"][color="#000000"] 1.28449f[color="#000000"], 0.0721975f[color="#000000"], 0.0993714f[color="#000000"],

[color="#4e00d7"][color="#000000"] 0.300401f[color="#000000"], 0.737608f[color="#000000"], 1.01523f[color="#000000"],

[color="#4e00d7"][color="#000000"] 1.28449f[color="#000000"], -1.38403f[color="#000000"], 1.15738f[color="#000000"],

[color="#4e00d7"][color="#000000"] 1.28449f[color="#000000"], 0.0721975f[color="#000000"], 0.0993714f[color="#000000"],

[color="#4e00d7"][color="#000000"] 1.28449f[color="#000000"], -1.38403f[color="#000000"], 1.15738f[color="#000000"],

[color="#4e00d7"][color="#000000"] -0.187194f[color="#000000"], -2.136f[color="#000000"], 0.122397f[color="#000000"],

[color="#4e00d7"][color="#000000"] -0.187194f[color="#000000"], -0.679765f[color="#000000"], -0.935616f[color="#000000"],

[color="#4e00d7"][color="#000000"] 1.28449f[color="#000000"], 0.0721975f[color="#000000"], 0.0993714f[color="#000000"],

[color="#4e00d7"][color="#000000"] -0.187194f[color="#000000"], -2.136f[color="#000000"], 0.122397f[color="#000000"],

[color="#4e00d7"][color="#000000"] 0.300401f[color="#000000"], 0.737608f[color="#000000"], 1.01523f[color="#000000"],

[color="#4e00d7"][color="#000000"] 1.28449f[color="#000000"], 0.0721975f[color="#000000"], 0.0993714f[color="#000000"],

[color="#4e00d7"][color="#000000"] -0.187194f[color="#000000"], -0.679765f[color="#000000"], -0.935616f[color="#000000"],

[color="#4e00d7"][color="#000000"] -1.17128f[color="#000000"], -0.0143543f[color="#000000"], -0.0197569f[color="#000000"],

[color="#4e00d7"][color="#000000"] 0.300401f[color="#000000"], 0.737608f[color="#000000"], 1.01523f[color="#000000"],

[color="#4e00d7"][color="#000000"] -0.187194f[color="#000000"], -0.679765f[color="#000000"], -0.935616f

##### Share on other sites
On the 3DS side you did not unpack the vertices. You have a pool of non-duplicate vertices.
You have not run over the faces of the object and have not duplicated the vertices according to the vertex indices on the faces.

Additionally, it is extremely unwise to import .3ds files. You should instead be making your own file format, or in the very least importing from COLLADA or FBX.

Importing directly from .3ds means you are asking users to store overly large model files on a small iOS device with limited storage capacity. After you breach 20 megabytes your app can no longer be downloaded without having an actual Macintosh computer.

COLLADA and FBX reduce some of the data stored but still contain a lot of data you don’t need. The reason for using them, however, is that all 3D software can create these files.
Meaning that importing from .3ds requires users to use one specific software package instead of allowing them to use their choice.

Ultimately, the only wise path to follow is to make COLLADA or FBX files and then extract only the data you need from them and put them into your own file format.

L. Spiro

##### Share on other sites
Hello,
Thank you for your reply and the very valuable advises.

The plan plan has been to read from the .OBJ file instead of .3DS file. Do you see any practical challenge in using such file format compare to the Collada or FBX format ? (except one is about parsing strings and xml).

Thank you also for noting the 20Meg hard limit; i was unaware of such restriction but must confess i do not fully comprehend it: games such as Infinity Blade are rather heavy on the storage capacity; however they do not seem to need a computer to be downloaded. Has it been always the case or has it changed very recently ? Is there any specific conditions for such behaviour ? (e.g. country specific limitation, iphone using mobile network (i.e. excl phone connecting to WIFI, a specific operator; only on iphones not ipad etc...)

As for your advice for the dupplication of vertices; i understand the principles behind the operation however my knowledge is fairly limited in the 3DS tool domain such as Lightware or 3DS; so i cannot match it with the right terminology and features in the modellers. Do you have a specific and common term which would help me to find the function to use in 3DS? For example, i have been looking into the optimization , merge options but have been unsuccesful so far.

Cheers,
Babarorum

On the 3DS side you did not unpack the vertices. You have a pool of non-duplicate vertices.
You have not run over the faces of the object and have not duplicated the vertices according to the vertex indices on the faces.

Additionally, it is extremely unwise to import .3ds files. You should instead be making your own file format, or in the very least importing from COLLADA or FBX.

Importing directly from .3ds means you are asking users to store overly large model files on a small iOS device with limited storage capacity. After you breach 20 megabytes your app can no longer be downloaded without having an actual Macintosh computer.

COLLADA and FBX reduce some of the data stored but still contain a lot of data you don’t need. The reason for using them, however, is that all 3D software can create these files.
Meaning that importing from .3ds requires users to use one specific software package instead of allowing them to use their choice.

Ultimately, the only wise path to follow is to make COLLADA or FBX files and then extract only the data you need from them and put them into your own file format.

L. Spiro

##### Share on other sites
20 megabytes is the limit for cell download. For WiFi there is no limit.
But you should aim for the cell downloads when possible; I have been on dates and asked my partner to check out a game I made only to have been disappointed that it was over 20 megabytes and receive instead, “I’ll check it out when I get home”.

Duplicating vertices.
Traverse the list of faces on each object.
For each face you will get a triangle fan. In your case 4 points for each face, which resolves to 2 triangles.

Converting a fan to triangles means taking the first point with each other 2 points increasingly.
Since that is obviously difficult to explain in words, here is code:

for ( unsigned int i = 2; i < totalFacePoints; ++i ) { unsigned int index0 = 0; // Use point 0 for ALL triangles. unsigned int index1 = i - 1; unsigned int index2 = i; }

The faces will have index data that allows you to look up vertices, normals, etc., inside the pools of vertices and normals, etc.
What you have posted is a vertex pool. It is nothing more than an array of unique vertices. There are 8 unique vertices (8 corners on the cube).
As you know, many faces share the same vertices. When you duplicate the vertices correctly you will have 36 of them.

There is no special terminology.

As for using OBJ files, I find them fairly unwieldy. They contain data that is not typical of games and need to be converted to something usable for games. COLLADA and FBX are more suited for games.

L. Spiro

##### Share on other sites
Not to mention OBJ files cannot be animated as the file format does not support skeletal or keyframe animations.

##### Share on other sites
With a bit of delay, thanks both of you. It helped a lot !

1. 1
2. 2
JoeJ
20
3. 3
4. 4
frob
12
5. 5

• 13
• 18
• 13
• 20
• 13
• ### Forum Statistics

• Total Topics
632194
• Total Posts
3004681

×