Hello everyone
I'm currently following a course "Game Development" where we learn everything from design to 3d drawing to programming. The language we use is C++, however I'd like to learn Java as well and have there for decided to create a large project (together with a number of other students) in this programming language.
Since we're mostly all beginners I wanted to begin with simple basics but have quick results to keep motivation high. What I mean is, for example implementing the models we create in 3DS MAX in Java and use those. Though I should note that we haven't reached this chapter yet for C++ in our course.
I started gathering information yesterday around the internet and combined several tutorials into one little Java program, and after succesfully importing a model I made from 3DS MAX I started to play around with it a little more (camera, lights). I noticed that it wasn't textured though so I moved on to that and started Googling. Currently I have this code, which I've taken mostly from this site:
https://users.cs.jmu.edu/bernstdh/web/common/lectures/slides_java3d-texture-mapping.php
However, in the slides there does appear to be a shortage of information. I'm missing two array variables: vertices and faces. If anyone has any idea on how these variables should look like it would be a great help.
TD;DR: I'm missing two array variables, vertices and faces. Having no idea what they should look like.
This is my current source:
/**
* @(#)ShowModel.java
*
*
* @author
* @version 1.00 2010/1/31
*/
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;
import com.sun.j3d.utils.image.TextureLoader;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.event.*;
import java.awt.*;
import java.io.FileReader;
import java.io.IOException;
public class ShowModel {
public ShowModel() {
SimpleUniverse universe;
BranchGroup group;
universe = new SimpleUniverse();
group = createCube();
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(group);
Vector3f translationVector = new Vector3f(0F, 1F, 5F);
positionCamera(translationVector, universe);
}
private static Appearance createTexturedAppearance(String name){
// Variables
Appearance appearance;
ImageComponent2D image;
Texture2D texture;
TextureLoader textureLoader;
// Load the image
textureLoader = new TextureLoader(name, null);
image = textureLoader.getImage();
// Create the texture
texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image.getWidth(), image.getHeight());
texture.setImage(0, image); // setImage(int mipmapLevel, ImageComponent image)
// Create the appearance
appearance = new Appearance();
appearance.setTexture(texture);
return appearance;
}
private static Scene loadSceneFromFile(String location) throws IOException {
// Variables
ObjectFile file;
file = new ObjectFile(ObjectFile.RESIZE);
return file.load(new FileReader(location));
}
private void positionCamera(Vector3f translationVector, SimpleUniverse universe){
// Variables
ViewingPlatform vp;
TransformGroup vpGroup;
Transform3D vpTranslation;
vp = universe.getViewingPlatform();
vpGroup = vp.getMultiTransformGroup().getTransformGroup(0);
vpTranslation = new Transform3D();
// Transforms the viewing platform
vpTranslation.setTranslation(translationVector);
vpGroup.setTransform(vpTranslation);
}
private void positionCamera(String anchor){
}
private static BranchGroup createCube(){
// Variables
Appearance appearance;
BranchGroup branchGroup;
QuadArray face;
Shape3D node;
// Texture coordinates
final float texcoords[][] =
{
{0.0f, 1.0f},
{0.0f, 0.0f},
{1.0f, 0.0f},
{1.0f, 1.0f}
};
// Textures
final String textures[] =
{
"prop_fountain_stairs_diffuse.jpg",
"prop_fountain_stairs_diffuse.jpg",
"prop_fountain_stairs_diffuse.jpg",
"prop_fountain_stairs_diffuse.jpg",
"prop_fountain_stairs_diffuse.jpg",
"prop_fountain_stairs_diffuse.jpg",
};
// Create an empty branchgroup
branchGroup = new BranchGroup();
// Create each face
for(int f=0; f<faces.length; f++){
// Create a QuadArray to hold each face
face = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
// Add the vertices to the QuadArray
for(int v=0; v<faces[f].length; v++) {
face.setCoordinates(v, vertices[faces[f][v]]);
// Set the texture coordinates
for(int i=0; i<4; i++){
face.setTextureCoordinate(i, texcoords[i]);
}
}
// Create a node to hold the face
node = new Shape3D(face);
// Add an appearance
appearance = createTexturedAppearance(textures[f]);
node.setAppearance(appearance);
// Add the node to the branchgroup
branchGroup.addChild(node);
}
return branchGroup;
}
}