• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
tom_mai78101

What is happening to my 3D model? I don't even...

3 posts in this topic

[img]http://i.imgur.com/7slga.png[/img][img]http://i.imgur.com/4cU08.png[/img]

I don't know what is happening to my little 3D model. It's a simple model of a cube I made and exported from Blender. I suspected it has to do with how I read the Wavefront OBJ file, but the only instructions I get is from a Youtube video teaching me how to load a 3D model from a file.

Here's the codes:

[CODE]
public class Model {

public List<Vector3f> vertices = new ArrayList<Vector3f>();
public List<Vector3f> normals = new ArrayList<Vector3f>();
public List<Face> faces = new ArrayList<Face>();
public static AssetManager assets;

public FloatBuffer vertexBuffer;
public float angle;

public Model(){
angle = 0f;
}

public void draw(GL10 gl){
gl.glFrontFace(GL10.GL_CW);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); //size = the size of 1 vertex

gl.glRotatef(angle, 1f, 0f, 0f);
gl.glRotatef(angle, 0f, 1f, 0f);
gl.glRotatef(angle, 0f, 0f, 1f);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, vertices.size());
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
angle += 2f;
if (angle > 360.0f)
angle = 0;
}
}
[/CODE]

[CODE]
public class Load {
public static Model load3D(String filename, Context c) throws FileNotFoundException, IOException {
AssetManager assets = c.getAssets();
BufferedReader reader = new BufferedReader(new InputStreamReader(assets.open(filename)));
Model m = new Model();
String line;
while(true) {
line = reader.readLine();
if (line == null)
break;
Log.d("DEBUG", line);
if (line.startsWith("v")) {
float x = Float.valueOf(line.split(" ")[1]);
float y = Float.valueOf(line.split(" ")[2]);
float z = Float.valueOf(line.split(" ")[3]);
Vector3f v = new Vector3f(x, y, z);
m.vertices.add(v);
}
else
if (line.startsWith("f")) {
String[] tokens = line.split(" ");
for (int i = 1; i < tokens.length; i++) {
m.faces.add(new Face(Integer.valueOf(tokens[i])));
}
}
}
reader.close();
ByteBuffer buffer = ByteBuffer.allocateDirect(m.vertices.size() * 4 * 3);
buffer.order(ByteOrder.nativeOrder());
m.vertexBuffer = buffer.asFloatBuffer();
for (Vector3f v : m.vertices) {
m.vertexBuffer.put(v.toFloatArray());
}
m.vertexBuffer.position(0);
return m;
}
}
[/CODE]

And here's the video:

[media]http://www.youtube.com/watch?v=izKAvSV3qk0[/media]

Excellent tutorial, by the way...

And finally, the OBJ file contents (for the curious):

[CODE]
# Blender v2.63 (sub 0) OBJ File: ''
# www.blender.org
mtllib Cube.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 1.000000 1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
usemtl Material
s off
f 1 2 3 4
f 5 8 7 6
f 1 5 6 2
f 2 6 7 3
f 3 7 8 4
f 5 1 4 8
[/CODE]

Would anyone want to take a peek? Edited by tom_mai78101
0

Share this post


Link to post
Share on other sites
I am not great with Java, so excuse me if I overlook stuff :)

Anyway, it seems you are drawing with glDrawArrays, while the obj format works with faces/indices. Are you converting everything in one buffer with the faces/indices into consideration? If so, are the values what you expect them to be? Did you take into account that the obj format starts its indices at 1 instead of 0?

If you want to make use of the indexbuffer, take a look at glDrawElements instead of glDrawArrays.

Hope it helps :)
0

Share this post


Link to post
Share on other sites
The problems are:[list=1]
[*]I am not used to Wavefront OBJ file formats. As you can see in the "f", the indices are numbered as such, but in the tutorial video, it shows up with many other values and slant lines (dividers).
[/list]
EDIT: Found the options. Someone mentioned the location for it is in the Export options instead of the User Preferences menu, where I was looking at the wrong place all the time.

NINJA EDIT:

Apparently, I'm asking the wrong questions. But still, the problem is problematic.

[quote]
Are you converting everything in one buffer with the faces/indices into consideration? If so, are the values what you expect them to be? Did you take into account that the obj format starts its indices at 1 instead of 0?
[/quote][list=1]
[*]Not exactly in one buffer. The faces have only 1 value per each index. Should I redesign the buffer so that each value is stored per index? And can a face has only 1 index stored?
[*]I don't know what values to expect. But I believed it may be the values in the OBJ file.
[*]Uh. From the tutorial, it did mentioned that indices start from 1. So the author wrote something different in the code than in mine, because there are more values in the author's video than mine. In the video, a face contains "XXX/YYY/ZZZ", while my face contains only the XXX part. That's the most confusing thing I've ever encountered. Since I created the OBJ by exporting from Blender, I didn't edit the values inside the file, so I'm pretty sure that Integer.valueof(String[].split()) worked like a charm.
[/list] Edited by tom_mai78101
0

Share this post


Link to post
Share on other sites
I just recently did a simple wavefront obj importer.

Gotchas that got me were

1) As mentioned earlier, the indices start from 1 instead of 0. This is the kind of thinking that lead to the first day of the month being the 1st instead of the 0th. So naive.

2) The faces that I read in were triangle fans. So 3 indices specifies 1 triangle, 4 indices specifies 2 triangles, 5 indices specifies 3 triangles etc. If you want to render a bunch of these faces in one go (depending on whether render speed is crucial to you) you might want to convert them to e.g. triangle lists. (or you can tristrip them).
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0