Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (562)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  3dsLoader Details  (Read 2231 times)
0 Members and 1 Guest are viewing this topic.
Offline Mr_Ridd

Senior Newbie




Java games rock!


« Posted 2004-01-10 09:21:49 »

Howzit

I got the general 3dsLoader and it work fine but how the hell do you implement it. I've looked at some other C++ tutorials but it's quite different.

Code samples would be appreciated.


Shot.
Offline tom
« Reply #1 - Posted 2004-01-10 10:00:39 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
      /** Draws the meshes in the specified scene. */
      public void draw(Scene3ds scene3ds) {
            GL.glColor3f(1, 1, 1);
            for (int meshIdx=0; meshIdx<scene3ds.meshes(); meshIdx++) {
                  Mesh3ds mesh3ds = scene3ds.mesh(meshIdx);
                  Vertex3ds[] vertexArray = mesh3ds.vertexArray();
                  Face3ds[] faceArray = mesh3ds.faceArray();
                  TexCoord3ds[] texCoordArray = mesh3ds.texCoordArray();
                  for (int faceMatIdx=0; faceMatIdx<mesh3ds.faceMats(); faceMatIdx++) {
                        FaceMat3ds faceMat = mesh3ds.faceMat(faceMatIdx);
                        Texture texture = textures[faceMat.material()];
                        if (texture != null) {
                              GL.glEnable(GL.GL_TEXTURE_2D);
                              GL.glBindTexture(GL.GL_TEXTURE_2D, texture.textureId);
                        } else {
                              GL.glDisable(GL.GL_TEXTURE_2D);
                        }

                        // enable filtering
                       GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_NEAREST);
                        GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
                       
                        GL.glBegin(GL.GL_TRIANGLES);
                        for (int faceIdx=0; faceIdx<faceMat.faces(); faceIdx++) {
                              int face = faceMat.face(faceIdx);
                              int p0 = faceArray[faceIdx].P0;
                              int p1 = faceArray[faceIdx].P1;
                              int p2 = faceArray[faceIdx].P2;
                              if (mesh3ds.texCoords() > 0) {
                                    GL.glTexCoord2f(texCoordArray[p0].U, texCoordArray[p0].V);
                                    GL.glVertex3f(vertexArray[p0].X, vertexArray[p0].Y, vertexArray[p0].Z);
                                    GL.glTexCoord2f(texCoordArray[p1].U, texCoordArray[p1].V);
                                    GL.glVertex3f(vertexArray[p1].X, vertexArray[p1].Y, vertexArray[p1].Z);
                                    GL.glTexCoord2f(texCoordArray[p2].U, texCoordArray[p2].V);
                                    GL.glVertex3f(vertexArray[p2].X, vertexArray[p2].Y, vertexArray[p2].Z);
                              } else {
                                    GL.glVertex3f(vertexArray[p0].X, vertexArray[p0].Y, vertexArray[p0].Z);
                                    GL.glVertex3f(vertexArray[p1].X, vertexArray[p1].Y, vertexArray[p1].Z);
                                    GL.glVertex3f(vertexArray[p2].X, vertexArray[p2].Y, vertexArray[p2].Z);
                              }
                        }
                        GL.glEnd();
                  }
            }
      }


-"textures" is an array of textures that corresponds with the Scene3ds material list.
-You will have to calculate the normals yourself if you use ligthing.

Offline Mr_Ridd

Senior Newbie




Java games rock!


« Reply #2 - Posted 2004-01-10 15:19:31 »

Ok cool, it worked, but I had to go back on the Z -axis to -210 and accross on the X-axis to 50 before I could see anything.

Why is that?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline renanse

Junior Member




Intelligence is light to a dark world.


« Reply #3 - Posted 2004-01-10 19:53:12 »

Seems like that would be a hard question to answer without first knowing the contents of the data you are importing or the way you set up GL.    :-/

Renanse  (ruh-NON-say)
Offline Mr_Ridd

Senior Newbie




Java games rock!


« Reply #4 - Posted 2004-01-12 02:56:07 »

I managed to import the model.  I was importing in 3D space so what I did was divide every vertex by 10 which made the distance between the points shorter.

I'm not sure if I've got the full API because some of the methods that are in the javadoc are not in the classes.

The other problem is that it's not importing the textures.
Offline tom
« Reply #5 - Posted 2004-01-12 07:52:37 »

This code prints the names of all the materials in the scene:
1  
2  
3  
4  
5  
6  
7  
      /** Prints the material names of all the materials in the scene.*/
      public void printMaterials(Scene3ds scene3ds) {
            for (int matIdx=0; matIdx<scene3ds.materials(); matIdx++) {
                  Material3ds material = scene3ds.material(matIdx);
                  System.out.println(material.name());
            }
      }


It does not give you the name of the texture but the name of the material. You'll have to rename the material in 3d studio to the path of the texture.

Wich methods are in the javadoc but not in the classes?

Offline Middy

Junior Member




Java games rock!


« Reply #6 - Posted 2004-01-26 17:54:19 »

Is this 3ds loader avaliable from anywhere?

When do I get my makeMyGameAsILike() extension?
Offline tom
« Reply #7 - Posted 2004-01-26 18:36:49 »

Look in the shared code section.

http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=share;action=display;num=1061796369

Offline ap_kelly

Junior Member




Java rocks!


« Reply #8 - Posted 2004-10-20 21:04:53 »

I completely missed this thread regarding the loading of 3ds files.

As Tom is correct in pointing out the library doesn't load any textures for you, since each person may have their own implementation of a texture manager. However as Tom also says it does load material names. If those material names are the path to your texture then its a simple process. However this seems impractical, so what you may need to do is setup a hashmap, that maps material names onto textures, these textures can then be loaded indipendantly of the 3ds model.

Hope that helps.

Andy.

Offline Middy

Junior Member




Java games rock!


« Reply #9 - Posted 2004-10-21 14:54:07 »

A quick comment...

Be carefull with pr face materials... it will kill performance. What you really need is pr object material....

When do I get my makeMyGameAsILike() extension?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #10 - Posted 2004-10-21 15:34:14 »

Quote
A quick comment...

Be carefull with pr face materials... it will kill performance. What you really need is pr object material....


Depends on how you implement the renderer.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (25 views)
2014-09-21 02:42:18

BurntPizza (17 views)
2014-09-21 01:30:30

moogie (19 views)
2014-09-21 00:26:15

UprightPath (26 views)
2014-09-20 20:14:06

BurntPizza (29 views)
2014-09-19 03:14:18

Dwinin (44 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (100 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56

mitcheeb (71 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!