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.
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.
/** 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.
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?
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. :-/
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.
This code prints the names of all the materials in the scene:
/** 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?
Is this 3ds loader avaliable from anywhere?
Look in the shared code section.
http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=share;action=display;num=1061796369
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.
A quick comment…
Be carefull with pr face materials… it will kill performance. What you really need is pr object material…
[quote]A quick comment…
Be carefull with pr face materials… it will kill performance. What you really need is pr object material…
[/quote]
Depends on how you implement the renderer.