Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  3D model file format  (Read 2206 times)
0 Members and 1 Guest are viewing this topic.
Offline theagentd
« Posted 2011-10-08 01:54:00 »

Hi everyone!
I need to start getting some real 3D models into my game soon and get rid of my stupid test graphics soon, and I found myself in a sea of different file formats. I just need something basic.
 - Support for, well, a 3D mesh.
 - Texturing of course.
 - No need for normals as I don't have lighting (yet) (so it would still be a plus)
 - Support for skeleton animation (which I haven't learned yet  Tongue) bones would be awesome as I'll have to animate my units eventually
 - Somewhat easily exportable from 3D software (but I can't do 3D modelling very well myself...)
 - At least some available free 3D models in this format, so I can test it without having to make my own models.
I have nothing against writing my own reader/parser for the format, as long as I have the required information to do it. xd Out of pure interest, what format does the Source engine use? I recon there are an infinite number of 3D models for Garry's Mod and other games based on it so it would be fun to play with them. xD

Myomyomyo.
Offline Chromanoid

Junior Duke


Medals: 3



« Reply #1 - Posted 2011-10-08 15:42:07 »

maybe you can borrow some code from the jme3, it has a blend file loader (files generated by blender). many systems support collada. you could write a converter that uses an existing library to convert the data into your own binary format. Maybe Assimp could be useful for this (afaik it has no direct java integration, but a swig interface). Assimp itself can import many formats and can even export them as collada files.
Offline deepthought
« Reply #2 - Posted 2011-10-09 17:43:43 »

anim8or .an8 format is a good one.  anim8or is free, and has skeletal animation.  I've already created a fairly simple java parser. i can give you that if you want.

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2011-10-09 19:40:02 »

Thanks for the replies!
maybe you can borrow some code from the jme3, it has a blend file loader (files generated by blender). many systems support collada. you could write a converter that uses an existing library to convert the data into your own binary format. Maybe Assimp could be useful for this (afaik it has no direct java integration, but a swig interface). Assimp itself can import many formats and can even export them as collada files.
I'll look into both the JME3 loader and Assimp! Thanks!
anim8or .an8 format is a good one.  anim8or is free, and has skeletal animation.  I've already created a fairly simple java parser. i can give you that if you want.
Sounds neat! I'll do some research on the format and see if it's easy to parse, but code is always welcome! d^_^b

Myomyomyo.
Offline deepthought
« Reply #4 - Posted 2011-10-09 20:15:08 »

here's the parser code

an8file.java
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  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.Vector;


public class an8file extends buildable {

   
   
   // creates a string representation of the file
   // nothing special to look at here
   public static an8file build(File file)
   {
     
      Scanner scan = null;
      try {
         scan = new Scanner(file);
      } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      StringBuilder st = new StringBuilder();
     
      while(scan.hasNext())
      {
         st.append(scan.nextLine()+"\n");
         
      }
     
      return build(st.toString());
     
     
     
   }
   
   //this is where it really gets ugly
   public static an8file build(String file)
   {
      an8file an = new an8file();
   Scanner scan = new Scanner(file);
   // the buildables stack
      Vector buildables= new Vector();
      buildables.add(an);
     
      while(scan.hasNext())
      {
         
      String s = scan.nextLine();
      s.trim();
      if(s.contains("{"))
      {
         chunk c = new chunk();
         
      int bracket= s.indexOf("{");
         
         c.type=s.substring(0, bracket).trim();
     
         buildables.add(c);
         
         ((buildable)buildables.get(buildables.size()-2)).subelements.add(c);
         
      // there is an element in with the chunk declaration
         if(bracket<s.length()-1)
         {
            //one-liners are a special case... ugh
            if(s.contains("}"))
            {
               ((buildable)buildables.lastElement()).subelements.add(s.substring(bracket+1, s.length()-2));
               
               buildables.remove(buildables.size()-1);
            }
           
            else
            {
               ((buildable)buildables.lastElement()).subelements.add(s.substring(bracket+1));
            }
           
         }
         
      }
      else
         if(s.contains("}"))
         {
           
            buildables.remove(buildables.size()-1);
         }
     
         else
         {
            ((buildable)buildables.lastElement()).subelements.add(s);
         }
     
     
         
      }
     
     
     
      // STATE MACHINES SUCK!!!
      return an;
   }
   
   
   public String toString()
   {
      String text = "";
      for(int x=0; x<subelements.size();x++ )
      {
         text+= subelements.get(x).toString()+"\n";
      }
     
      return text;
   }
   
   

   
   
   public static void main(String args[])
{

     
   
an8file a = an8file.build(new File("test.an8"));


System.out.println(((chunk)((chunk)a.subelements.get(0)).subelements.get(0)).subelements.get(0));


try {
   a.save(new File("test2.an8"));
} catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
}

}

   public void save(File file) throws FileNotFoundException {


      PrintStream ps = new PrintStream(new FileOutputStream(file));
     
      ps.print(toString());
     
   }
   
   
   

}



buildable.java

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  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.Vector;


public class an8file extends buildable {

   
   
   // creates a string representation of the file
   // nothing special to look at here
   public static an8file build(File file)
   {
     
      Scanner scan = null;
      try {
         scan = new Scanner(file);
      } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      StringBuilder st = new StringBuilder();
     
      while(scan.hasNext())
      {
         st.append(scan.nextLine()+"\n");
         
      }
     
      return build(st.toString());
     
     
     
   }
   
   //this is where it really gets ugly
   public static an8file build(String file)
   {
      an8file an = new an8file();
   Scanner scan = new Scanner(file);
   // the buildables stack
      Vector buildables= new Vector();
      buildables.add(an);
     
      while(scan.hasNext())
      {
         
      String s = scan.nextLine();
      s.trim();
      if(s.contains("{"))
      {
         chunk c = new chunk();
         
      int bracket= s.indexOf("{");
         
         c.type=s.substring(0, bracket).trim();
     
         buildables.add(c);
         
         ((buildable)buildables.get(buildables.size()-2)).subelements.add(c);
         
      // there is an element in with the chunk declaration
         if(bracket<s.length()-1)
         {
            //one-liners are a special case... ugh
            if(s.contains("}"))
            {
               ((buildable)buildables.lastElement()).subelements.add(s.substring(bracket+1, s.length()-2));
               
               buildables.remove(buildables.size()-1);
            }
           
            else
            {
               ((buildable)buildables.lastElement()).subelements.add(s.substring(bracket+1));
            }
           
         }
         
      }
      else
         if(s.contains("}"))
         {
           
            buildables.remove(buildables.size()-1);
         }
     
         else
         {
            ((buildable)buildables.lastElement()).subelements.add(s);
         }
     
     
         
      }
     
     
     
      // STATE MACHINES SUCK!!!
      return an;
   }
   
   
   public String toString()
   {
      String text = "";
      for(int x=0; x<subelements.size();x++ )
      {
         text+= subelements.get(x).toString()+"\n";
      }
     
      return text;
   }
   
   

   
   
   public static void main(String args[])
{

     
   
an8file a = an8file.build(new File("test.an8"));


System.out.println(((chunk)((chunk)a.subelements.get(0)).subelements.get(0)).subelements.get(0));


try {
   a.save(new File("test2.an8"));
} catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
}

}

   public void save(File file) throws FileNotFoundException {


      PrintStream ps = new PrintStream(new FileOutputStream(file));
     
      ps.print(toString());
     
   }
   
   
   

}


chunk.java

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  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.util.Scanner;
import java.util.Vector;


public class an8file extends buildable {

   
   
   // creates a string representation of the file
   // nothing special to look at here
   public static an8file build(File file)
   {
     
      Scanner scan = null;
      try {
         scan = new Scanner(file);
      } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      StringBuilder st = new StringBuilder();
     
      while(scan.hasNext())
      {
         st.append(scan.nextLine()+"\n");
         
      }
     
      return build(st.toString());
     
     
     
   }
   
   //this is where it really gets ugly
   public static an8file build(String file)
   {
      an8file an = new an8file();
   Scanner scan = new Scanner(file);
   // the buildables stack
      Vector buildables= new Vector();
      buildables.add(an);
     
      while(scan.hasNext())
      {
         
      String s = scan.nextLine();
      s.trim();
      if(s.contains("{"))
      {
         chunk c = new chunk();
         
      int bracket= s.indexOf("{");
         
         c.type=s.substring(0, bracket).trim();
     
         buildables.add(c);
         
         ((buildable)buildables.get(buildables.size()-2)).subelements.add(c);
         
      // there is an element in with the chunk declaration
         if(bracket<s.length()-1)
         {
            //one-liners are a special case... ugh
            if(s.contains("}"))
            {
               ((buildable)buildables.lastElement()).subelements.add(s.substring(bracket+1, s.length()-2));
               
               buildables.remove(buildables.size()-1);
            }
           
            else
            {
               ((buildable)buildables.lastElement()).subelements.add(s.substring(bracket+1));
            }
           
         }
         
      }
      else
         if(s.contains("}"))
         {
           
            buildables.remove(buildables.size()-1);
         }
     
         else
         {
            ((buildable)buildables.lastElement()).subelements.add(s);
         }
     
     
         
      }
     
     
     
      // STATE MACHINES SUCK!!!
      return an;
   }
   
   
   public String toString()
   {
      String text = "";
      for(int x=0; x<subelements.size();x++ )
      {
         text+= subelements.get(x).toString()+"\n";
      }
     
      return text;
   }
   
   

   
   
   public static void main(String args[])
{

     
   
an8file a = an8file.build(new File("test.an8"));


System.out.println(((chunk)((chunk)a.subelements.get(0)).subelements.get(0)).subelements.get(0));


try {
   a.save(new File("test2.an8"));
} catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
}

}

   public void save(File file) throws FileNotFoundException {


      PrintStream ps = new PrintStream(new FileOutputStream(file));
     
      ps.print(toString());
     
   }
   
   
   

}



you'll still have to look up the format, but this will deal with the nested objects. everything is stored within the subelements vectors. check if it's a string or a chunk.

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #5 - Posted 2011-10-10 01:09:11 »

You could just serialize your objects Roll Eyes

Offline theagentd
« Reply #6 - Posted 2011-10-10 01:30:14 »

You could just serialize your objects Roll Eyes
... I don't have any objects to serialize. To even make them I would need to be able to load 3D data in the first place.

Myomyomyo.
Offline deepthought
« Reply #7 - Posted 2011-10-10 18:28:34 »

And if he wanted to change the way his objects looked he'd have to deserialize them, edit, then reserialize.

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
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.

Longarmx (39 views)
2014-10-17 03:59:02

Norakomi (30 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (57 views)
2014-10-14 00:39:48

TehJavaDev (58 views)
2014-10-14 00:35:47

TehJavaDev (48 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!