Search in sources :

Example 21 with Material

use of net.drewke.tdme.engine.model.Material in project tdme by andreasdr.

the class EngineTest method createWallModel.

/**
	 * Create wall model
	 * @return
	 */
private Model createWallModel() {
    // wall model
    Model wall = new Model("wall", "wall", UpVector.Y_UP, RotationOrder.XYZ, null);
    // wall material
    Material wallMaterial = new Material("wall");
    wall.getMaterials().put("wall", wallMaterial);
    //	group
    Group wallGroup = new Group(wall, null, "wall", "wall");
    //	faces entity
    //		far plane
    FacesEntity groupFacesEntityFarPlane = new FacesEntity(wallGroup, "wall");
    wallMaterial.getAmbientColor().set(1f, 1f, 1f, 1f);
    wallMaterial.getDiffuseColor().set(1f, 1f, 1f, 1f);
    groupFacesEntityFarPlane.setMaterial(wallMaterial);
    //	faces entity 
    ArrayList<FacesEntity> groupFacesEntities = new ArrayList<FacesEntity>();
    groupFacesEntities.add(groupFacesEntityFarPlane);
    //	vertices
    ArrayList<Vector3> vertices = new ArrayList<Vector3>();
    // left, near, far plane
    vertices.add(new Vector3(-4f, 0f, +4f));
    // left, far, far plane
    vertices.add(new Vector3(-4f, +4f, +4f));
    // right far, far plane
    vertices.add(new Vector3(+4f, +4f, +4f));
    // right, near, far plane
    vertices.add(new Vector3(+4f, 0f, +4f));
    //	normals
    ArrayList<Vector3> normals = new ArrayList<Vector3>();
    //		far plane
    normals.add(new Vector3(0f, 0f, -1f));
    // texture coordinates
    ArrayList<TextureCoordinate> textureCoordinates = new ArrayList<TextureCoordinate>();
    textureCoordinates.add(new TextureCoordinate(0f, 0f));
    textureCoordinates.add(new TextureCoordinate(0f, 1f));
    textureCoordinates.add(new TextureCoordinate(1f, 1f));
    textureCoordinates.add(new TextureCoordinate(1f, 0f));
    //	faces ground far plane
    ArrayList<Face> facesFarPlane = new ArrayList<Face>();
    facesFarPlane.add(new Face(wallGroup, 0, 1, 2, 0, 0, 0, 0, 1, 2));
    facesFarPlane.add(new Face(wallGroup, 2, 3, 0, 0, 0, 0, 2, 3, 0));
    // set up faces entity
    groupFacesEntityFarPlane.setFaces(facesFarPlane);
    // setup ground group
    wallGroup.setVertices(vertices);
    wallGroup.setNormals(normals);
    wallGroup.setTextureCoordinates(textureCoordinates);
    wallGroup.setFacesEntities(groupFacesEntities);
    // determine features
    wallGroup.determineFeatures();
    // register group
    wall.getGroups().put("wall", wallGroup);
    wall.getSubGroups().put("wall", wallGroup);
    // prepare for indexed rendering
    ModelHelper.prepareForIndexedRendering(wall);
    //
    return wall;
}
Also used : FacesEntity(net.drewke.tdme.engine.model.FacesEntity) Group(net.drewke.tdme.engine.model.Group) Model(net.drewke.tdme.engine.model.Model) Object3DModel(net.drewke.tdme.engine.Object3DModel) PrimitiveModel(net.drewke.tdme.engine.primitives.PrimitiveModel) ArrayList(java.util.ArrayList) Material(net.drewke.tdme.engine.model.Material) Vector3(net.drewke.tdme.math.Vector3) TextureCoordinate(net.drewke.tdme.engine.model.TextureCoordinate) Face(net.drewke.tdme.engine.model.Face)

Aggregations

Material (net.drewke.tdme.engine.model.Material)21 FacesEntity (net.drewke.tdme.engine.model.FacesEntity)15 Model (net.drewke.tdme.engine.model.Model)10 Vector3 (net.drewke.tdme.math.Vector3)10 ArrayList (java.util.ArrayList)9 Face (net.drewke.tdme.engine.model.Face)9 Group (net.drewke.tdme.engine.model.Group)8 TextureCoordinate (net.drewke.tdme.engine.model.TextureCoordinate)5 StringTokenizer (java.util.StringTokenizer)4 Joint (net.drewke.tdme.engine.model.Joint)4 HashMap (net.drewke.tdme.utils.HashMap)3 BufferedReader (java.io.BufferedReader)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 Object3D (net.drewke.tdme.engine.Object3D)2 Element (org.w3c.dom.Element)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1