use of net.drewke.tdme.engine.model.Material in project tdme by andreasdr.
the class LevelEditorView method createLevelEditorGroundPlateModel.
/**
* Creates a level editor ground plate
* @return ground
*/
private Model createLevelEditorGroundPlateModel() {
// ground selectedEntity
Model groundPlate = new Model("leveleditor.ground", "leveleditor.ground", UpVector.Y_UP, RotationOrder.XYZ, (BoundingBox) BoundingBox.createBoundingVolume(new Vector3(0f, -0.01f, 0f), new Vector3(1f, +0.01f, 1f)));
// material
Material groundPlateMaterial = new Material("ground");
groundPlateMaterial.getDiffuseColor().setAlpha(0.75f);
groundPlateMaterial.setDiffuseTexture("resources/tools/leveleditor/textures", "groundplate.png");
groundPlateMaterial.getSpecularColor().set(0f, 0f, 0f, 1f);
groundPlate.getMaterials().put("ground", groundPlateMaterial);
// group
Group groundGroup = new Group(groundPlate, null, "ground", "ground");
// faces entity
// ground
FacesEntity groupFacesEntityGround = new FacesEntity(groundGroup, "leveleditor.ground.facesentity");
groupFacesEntityGround.setMaterial(groundPlateMaterial);
// faces entity
ArrayList<FacesEntity> groupFacesEntities = new ArrayList<FacesEntity>();
groupFacesEntities.add(groupFacesEntityGround);
// vertices
ArrayList<Vector3> groundVertices = new ArrayList<Vector3>();
// left, near, ground
groundVertices.add(new Vector3(0.0f, 0.0f, 0.0f));
// left, far, ground
groundVertices.add(new Vector3(0.0f, 0.0f, +groundPlateDepth));
// right far, ground
groundVertices.add(new Vector3(+groundPlateWidth, 0.0f, +groundPlateDepth));
// right, near, ground
groundVertices.add(new Vector3(+groundPlateWidth, 0.0f, 0.0f));
// normals
ArrayList<Vector3> groundNormals = new ArrayList<Vector3>();
// ground
groundNormals.add(new Vector3(0f, 1f, 0f));
// texture coordinates
ArrayList<TextureCoordinate> groundTextureCoordinates = new ArrayList<TextureCoordinate>();
groundTextureCoordinates.add(new TextureCoordinate(0f, 1f));
groundTextureCoordinates.add(new TextureCoordinate(0f, 0f));
groundTextureCoordinates.add(new TextureCoordinate(1f, 0f));
groundTextureCoordinates.add(new TextureCoordinate(1f, 1f));
// faces ground
ArrayList<Face> groundFacesGround = new ArrayList<Face>();
groundFacesGround.add(new Face(groundGroup, 0, 1, 2, 0, 0, 0, 0, 1, 2));
groundFacesGround.add(new Face(groundGroup, 2, 3, 0, 0, 0, 0, 2, 3, 0));
// set up faces entity
groupFacesEntityGround.setFaces(groundFacesGround);
// setup ground group
groundGroup.setVertices(groundVertices);
groundGroup.setNormals(groundNormals);
groundGroup.setTextureCoordinates(groundTextureCoordinates);
groundGroup.setFacesEntities(groupFacesEntities);
// register group
groundPlate.getGroups().put(groundGroup.getId(), groundGroup);
groundPlate.getSubGroups().put(groundGroup.getId(), groundGroup);
// prepare for indexed rendering
ModelHelper.prepareForIndexedRendering(groundPlate);
//
return groundPlate;
}
use of net.drewke.tdme.engine.model.Material in project tdme by andreasdr.
the class Object3DGroup method setupTextures.
/**
* Set up textures for given object3d group and faces entity
* @param renderer
* @param object 3D group
* @param faces entity idx
*/
protected static void setupTextures(GLRenderer renderer, Object3DGroup object3DGroup, int facesEntityIdx) {
FacesEntity[] facesEntities = object3DGroup.group.getFacesEntities();
Material material = facesEntities[facesEntityIdx].getMaterial();
// get material or use default
if (material == null)
material = Material.getDefaultMaterial();
// load diffuse texture
if (object3DGroup.materialDiffuseTextureIdsByEntities[facesEntityIdx] == GLTEXTUREID_NONE) {
if (material.getDiffuseTexture() != null) {
//
object3DGroup.materialDiffuseTextureIdsByEntities[facesEntityIdx] = Engine.getInstance().getTextureManager().addTexture(material.getDiffuseTexture());
} else {
object3DGroup.materialDiffuseTextureIdsByEntities[facesEntityIdx] = GLTEXTUREID_NOTUSED;
}
}
// load specular texture
if (renderer.isSpecularMappingAvailable() == true && object3DGroup.materialSpecularTextureIdsByEntities[facesEntityIdx] == GLTEXTUREID_NONE) {
//
if (material.getSpecularTexture() != null) {
//
object3DGroup.materialSpecularTextureIdsByEntities[facesEntityIdx] = Engine.getInstance().getTextureManager().addTexture(material.getSpecularTexture());
} else {
object3DGroup.materialSpecularTextureIdsByEntities[facesEntityIdx] = GLTEXTUREID_NOTUSED;
}
}
// load displacement texture
if (renderer.isDisplacementMappingAvailable() == true && object3DGroup.materialDisplacementTextureIdsByEntities[facesEntityIdx] == GLTEXTUREID_NONE) {
//
if (material.getDisplacementTexture() != null) {
object3DGroup.materialDisplacementTextureIdsByEntities[facesEntityIdx] = Engine.getInstance().getTextureManager().addTexture(material.getDisplacementTexture());
} else {
object3DGroup.materialDisplacementTextureIdsByEntities[facesEntityIdx] = GLTEXTUREID_NOTUSED;
}
}
// load normal texture
if (renderer.isNormalMappingAvailable() == true && object3DGroup.materialNormalTextureIdsByEntities[facesEntityIdx] == GLTEXTUREID_NONE) {
if (material.getNormalTexture() != null) {
object3DGroup.materialNormalTextureIdsByEntities[facesEntityIdx] = Engine.getInstance().getTextureManager().addTexture(material.getNormalTexture());
} else {
object3DGroup.materialNormalTextureIdsByEntities[facesEntityIdx] = GLTEXTUREID_NOTUSED;
}
}
}
use of net.drewke.tdme.engine.model.Material in project tdme by andreasdr.
the class PrimitiveModel method createOrientedBoundingBoxModel.
/**
* Creates a model from oriented bounding box
* @param bounding box
* @param id
* @return model
*/
public static Model createOrientedBoundingBoxModel(OrientedBoundingBox orientedBoundingBox, String id) {
// ground model
Model model = new Model(id, id, UpVector.Y_UP, RotationOrder.XYZ, null);
// material
Material material = new Material("tdme.primitive.material");
material.getAmbientColor().set(0.5f, 0.5f, 0.5f, 1.0f);
material.getDiffuseColor().set(1.0f, 0.5f, 0.5f, 0.5f);
material.getSpecularColor().set(0f, 0f, 0f, 1f);
model.getMaterials().put(material.getId(), material);
// group
Group group = new Group(model, null, "group", "group");
// faces entity
FacesEntity groupFacesEntity = new FacesEntity(group, "faces entity");
groupFacesEntity.setMaterial(material);
// faces entity
ArrayList<FacesEntity> groupFacesEntities = new ArrayList<FacesEntity>();
groupFacesEntities.add(groupFacesEntity);
// triangle vertices indexes
int[][] fvi = OrientedBoundingBox.facesVerticesIndexes;
// vertices
ArrayList<Vector3> vertices = new ArrayList<Vector3>();
for (Vector3 vertex : orientedBoundingBox.vertices) {
vertices.add(vertex.clone());
}
Vector3[] axes = orientedBoundingBox.axes;
// normals
ArrayList<Vector3> normals = new ArrayList<Vector3>();
normals.add(axes[0].clone().scale(-1f));
normals.add(axes[0].clone());
normals.add(axes[1].clone().scale(-1f));
normals.add(axes[1].clone());
normals.add(axes[2].clone().scale(-1f));
normals.add(axes[2].clone());
// faces
ArrayList<Face> faces = new ArrayList<Face>();
// left
faces.add(new Face(group, fvi[0][0], fvi[0][1], fvi[0][2], 0, 0, 0));
faces.add(new Face(group, fvi[1][0], fvi[1][1], fvi[1][2], 0, 0, 0));
// right
faces.add(new Face(group, fvi[2][0], fvi[2][1], fvi[2][2], 1, 1, 1));
faces.add(new Face(group, fvi[3][0], fvi[3][1], fvi[3][2], 1, 1, 1));
// top
faces.add(new Face(group, fvi[4][0], fvi[4][1], fvi[4][2], 2, 2, 2));
faces.add(new Face(group, fvi[5][0], fvi[5][1], fvi[5][2], 2, 2, 2));
// bottom
faces.add(new Face(group, fvi[6][0], fvi[6][1], fvi[6][2], 3, 3, 3));
faces.add(new Face(group, fvi[7][0], fvi[7][1], fvi[7][2], 3, 3, 3));
// near
faces.add(new Face(group, fvi[8][0], fvi[8][1], fvi[8][2], 4, 4, 4));
faces.add(new Face(group, fvi[9][0], fvi[9][1], fvi[9][2], 4, 4, 4));
// far
faces.add(new Face(group, fvi[10][0], fvi[10][1], fvi[10][2], 5, 5, 5));
faces.add(new Face(group, fvi[11][0], fvi[11][1], fvi[11][2], 5, 5, 5));
// set up faces entity
groupFacesEntity.setFaces(faces);
// setup group vertex data
group.setVertices(vertices);
group.setNormals(normals);
group.setFacesEntities(groupFacesEntities);
// determine features
group.determineFeatures();
// register group
model.getGroups().put("group", group);
model.getSubGroups().put("group", group);
// prepare for indexed rendering
ModelHelper.prepareForIndexedRendering(model);
//
return model;
}
use of net.drewke.tdme.engine.model.Material in project tdme by andreasdr.
the class PrimitiveModel method createCapsuleModel.
/**
* Creates a model from capsule
* @param sphere
* @param id
* @param number of x segments
* @param number of y segments
* @return model
*/
public static Model createCapsuleModel(Capsule capsule, String id, int segmentsX, int segmentsY) {
// capsule properties
float radius = capsule.radius;
Vector3 a = capsule.a;
Vector3 b = capsule.b;
// rotation quaternion
Quaternion rotationQuaternion = new Quaternion();
rotationQuaternion.identity();
// angle between a and b
Vector3 yAxis = new Vector3(0f, -1f, 0f);
Vector3 abNormalized = a.clone().sub(b).normalize();
float[] abNormalizedVectorXYZ = abNormalized.getArray();
Vector3 rotationAxis;
if (Math.abs(abNormalizedVectorXYZ[0]) < MathTools.EPSILON && Math.abs(abNormalizedVectorXYZ[2]) < MathTools.EPSILON) {
rotationAxis = new Vector3(abNormalizedVectorXYZ[1], 0f, 0f);
} else {
rotationAxis = Vector3.computeCrossProduct(yAxis, abNormalized).normalize();
}
float angle = Vector3.computeAngle(yAxis, abNormalized, yAxis);
rotationQuaternion.rotate(angle, rotationAxis);
// ground model
Model model = new Model(id, id, UpVector.Y_UP, RotationOrder.XYZ, null);
// material
Material material = new Material("tdme.primitive.material");
material.getAmbientColor().set(0.5f, 0.5f, 0.5f, 1.0f);
material.getDiffuseColor().set(1.0f, 0.5f, 0.5f, 0.5f);
material.getSpecularColor().set(0f, 0f, 0f, 1f);
model.getMaterials().put(material.getId(), material);
// group
Group group = new Group(model, null, "group", "group");
// faces entity
FacesEntity groupFacesEntity = new FacesEntity(group, "faces entity");
groupFacesEntity.setMaterial(material);
// faces entity
ArrayList<FacesEntity> groupFacesEntities = new ArrayList<FacesEntity>();
groupFacesEntities.add(groupFacesEntity);
// vertices
ArrayList<Vector3> vertices = new ArrayList<Vector3>();
for (int i = 0; i < (segmentsY + 2) * segmentsX; i++) vertices.add(null);
// top half sphere
for (int ySegment = segmentsY / 2; ySegment <= segmentsY; ySegment++) for (int xSegment = 0; xSegment < segmentsX; xSegment++) {
Vector3 vertex = new Vector3();
rotationQuaternion.multiply(new Vector3((float) (Math.sin(Math.PI * ySegment / segmentsY) * Math.cos(Math.PI * 2 * xSegment / segmentsX)), (float) (Math.cos(Math.PI * ySegment / segmentsY)), (float) (Math.sin(Math.PI * ySegment / segmentsY) * Math.sin(Math.PI * 2 * xSegment / segmentsX))), vertex);
vertex.scale(radius);
vertex.add(a);
vertices.set(ySegment * segmentsX + xSegment, vertex);
}
// bottom half sphere
for (int i = 0; i < (segmentsY + 1) * segmentsX; i++) vertices.add(null);
for (int ySegment = 0; ySegment <= segmentsY / 2; ySegment++) for (int xSegment = 0; xSegment < segmentsX; xSegment++) {
Vector3 vertex = new Vector3();
rotationQuaternion.multiply(new Vector3((float) (Math.sin(Math.PI * ySegment / segmentsY) * Math.cos(Math.PI * 2 * xSegment / segmentsX)), (float) (Math.cos(Math.PI * ySegment / segmentsY)), (float) (Math.sin(Math.PI * ySegment / segmentsY) * Math.sin(Math.PI * 2 * xSegment / segmentsX))), vertex);
vertex.scale(radius);
vertex.add(b);
vertices.set(ySegment * segmentsX + xSegment, vertex);
}
// normals
ArrayList<Vector3> normals = new ArrayList<Vector3>();
// faces
ArrayList<Face> faces = new ArrayList<Face>();
int vi0, vi1, vi2;
int ni;
for (int y = 0; y <= segmentsY + 1; y++) {
for (int x = 0; x < segmentsX; x++) {
vi0 = ((y + 0) % (segmentsY + 1)) * segmentsX + ((x + 0) % (segmentsX));
vi1 = ((y + 1) % (segmentsY + 1)) * segmentsX + ((x + 1) % (segmentsX));
vi2 = ((y + 1) % (segmentsY + 1)) * segmentsX + ((x + 0) % (segmentsX));
ni = normals.size();
for (Vector3 normal : ModelHelper.computeNormals(new Vector3[] { vertices.get(vi0), vertices.get(vi1), vertices.get(vi2) })) {
normals.add(normal);
}
faces.add(new Face(group, vi0, vi1, vi2, ni + 0, ni + 1, ni + 2));
vi0 = ((y + 0) % (segmentsY + 1)) * segmentsX + ((x + 0) % (segmentsX));
vi1 = ((y + 0) % (segmentsY + 1)) * segmentsX + ((x + 1) % (segmentsX));
vi2 = ((y + 1) % (segmentsY + 1)) * segmentsX + ((x + 1) % (segmentsX));
ni = normals.size();
for (Vector3 normal : ModelHelper.computeNormals(new Vector3[] { vertices.get(vi0), vertices.get(vi1), vertices.get(vi2) })) {
normals.add(normal);
}
faces.add(new Face(group, vi0, vi1, vi2, ni + 0, ni + 1, ni + 2));
}
}
// set up faces entity
groupFacesEntity.setFaces(faces);
// setup group vertex data
group.setVertices(vertices);
group.setNormals(normals);
group.setFacesEntities(groupFacesEntities);
// determine features
group.determineFeatures();
// register group
model.getGroups().put("group", group);
model.getSubGroups().put("group", group);
// prepare for indexed rendering
ModelHelper.prepareForIndexedRendering(model);
//
return model;
}
use of net.drewke.tdme.engine.model.Material in project tdme by andreasdr.
the class PrimitiveModel method createSphereModel.
/**
* Creates a model from oriented bounding box
* @param sphere
* @param id
* @param number of x segments
* @param number of y segments
* @return model
*/
public static Model createSphereModel(Sphere sphere, String id, int segmentsX, int segmentsY) {
// sphere properties
float radius = sphere.radius;
Vector3 center = sphere.center;
// ground model
Model model = new Model(id, id, UpVector.Y_UP, RotationOrder.XYZ, null);
// material
Material material = new Material("tdme.primitive.material");
material.getAmbientColor().set(0.5f, 0.5f, 0.5f, 1.0f);
material.getDiffuseColor().set(1.0f, 0.5f, 0.5f, 0.5f);
material.getSpecularColor().set(0f, 0f, 0f, 1f);
model.getMaterials().put(material.getId(), material);
// group
Group group = new Group(model, null, "group", "group");
// faces entity
FacesEntity groupFacesEntity = new FacesEntity(group, "faces entity");
groupFacesEntity.setMaterial(material);
// faces entity
ArrayList<FacesEntity> groupFacesEntities = new ArrayList<FacesEntity>();
groupFacesEntities.add(groupFacesEntity);
// vertices
ArrayList<Vector3> vertices = new ArrayList<Vector3>();
for (int i = 0; i < (segmentsY + 1) * segmentsX; i++) vertices.add(null);
for (int ySegment = 0; ySegment <= segmentsY; ySegment++) for (int xSegment = 0; xSegment < segmentsX; xSegment++) {
Vector3 vertex = new Vector3((float) (Math.sin(Math.PI * ySegment / segmentsY) * Math.cos(Math.PI * 2 * xSegment / segmentsX)), (float) (Math.cos(Math.PI * ySegment / segmentsY)), (float) (Math.sin(Math.PI * ySegment / segmentsY) * Math.sin(Math.PI * 2 * xSegment / segmentsX))).scale(radius).add(center);
vertices.set(ySegment * segmentsX + xSegment, vertex);
}
// normals
ArrayList<Vector3> normals = new ArrayList<Vector3>();
// faces
ArrayList<Face> faces = new ArrayList<Face>();
int vi0, vi1, vi2;
int ni;
for (int y = 0; y <= segmentsY; y++) {
for (int x = 0; x < segmentsX; x++) {
vi0 = ((y + 0) % (segmentsY + 1)) * segmentsX + ((x + 0) % (segmentsX));
vi1 = ((y + 1) % (segmentsY + 1)) * segmentsX + ((x + 1) % (segmentsX));
vi2 = ((y + 1) % (segmentsY + 1)) * segmentsX + ((x + 0) % (segmentsX));
ni = normals.size();
for (Vector3 normal : ModelHelper.computeNormals(new Vector3[] { vertices.get(vi0), vertices.get(vi1), vertices.get(vi2) })) {
normals.add(normal);
}
faces.add(new Face(group, vi0, vi1, vi2, ni + 0, ni + 1, ni + 2));
vi0 = ((y + 0) % (segmentsY + 1)) * segmentsX + ((x + 0) % (segmentsX));
vi1 = ((y + 0) % (segmentsY + 1)) * segmentsX + ((x + 1) % (segmentsX));
vi2 = ((y + 1) % (segmentsY + 1)) * segmentsX + ((x + 1) % (segmentsX));
ni = normals.size();
for (Vector3 normal : ModelHelper.computeNormals(new Vector3[] { vertices.get(vi0), vertices.get(vi1), vertices.get(vi2) })) {
normals.add(normal);
}
faces.add(new Face(group, vi0, vi1, vi2, ni + 0, ni + 1, ni + 2));
}
}
// set up faces entity
groupFacesEntity.setFaces(faces);
// setup group vertex data
group.setVertices(vertices);
group.setNormals(normals);
group.setFacesEntities(groupFacesEntities);
// determine features
group.determineFeatures();
// register group
model.getGroups().put("group", group);
model.getSubGroups().put("group", group);
// prepare for indexed rendering
ModelHelper.prepareForIndexedRendering(model);
//
return model;
}
Aggregations