use of net.drewke.tdme.engine.model.FacesEntity in project tdme by andreasdr.
the class TransparentRenderFacesPool method createTransparentRenderFaces.
/**
* Creates an array of transparent render faces from
* @param model view matrix
* @param object3D group
* @param faces entity index
* @param face index
* @param face index for texture coordinates
* @return
*/
protected void createTransparentRenderFaces(Matrix4x4 modelViewMatrix, Object3DGroup object3DGroup, int facesEntityIdx, int faceIdx) {
// retrieve objects we need
FacesEntity[] facesEntities = object3DGroup.group.getFacesEntities();
FacesEntity facesEntity = facesEntities[facesEntityIdx];
Face[] faces = facesEntity.getFaces();
Vector3[] groupTransformedVertices = object3DGroup.mesh.transformedVertices;
// objects we will use for calculations
float distanceFromCamera;
// create transparent render faces
for (int i = 0; i < faces.length; i++) {
// check for pool overflow
if (size() >= FACES_MAX) {
System.out.println("TransparentRenderFacesPool::createTransparentRenderFaces(): Too many transparent render faces");
break;
}
// set up face
int[] faceVertexIndices = faces[i].getVertexIndices();
tmpVector3.set(0.0f, 0.0f, 0.0f);
tmpVector3.add(groupTransformedVertices[faceVertexIndices[0]]);
tmpVector3.add(groupTransformedVertices[faceVertexIndices[1]]);
tmpVector3.add(groupTransformedVertices[faceVertexIndices[2]]);
tmpVector3.scale(1.0f / 3.0f);
modelViewMatrix.multiply(tmpVector3, tmpVector3);
distanceFromCamera = -tmpVector3.getZ();
// create transparent render face
TransparentRenderFace transparentRenderFace = transparentRenderFacesPool.allocate();
transparentRenderFace.object3DGroup = object3DGroup;
transparentRenderFace.facesEntityIdx = facesEntityIdx;
transparentRenderFace.faceIdx = faceIdx;
transparentRenderFace.distanceFromCamera = distanceFromCamera;
transparentRenderFaces.add(transparentRenderFace);
faceIdx++;
}
}
use of net.drewke.tdme.engine.model.FacesEntity in project tdme by andreasdr.
the class ModelUtilitiesInternal method equals.
/**
* Compute if model 1 equals model 2
* @param model 1
* @param model 2
* @return model1 equals model2
*/
public static boolean equals(Object3DModelInternal object3DModel1Internal, Object3DModelInternal object3DModel2Internal) {
// check number of object 3d groups
if (object3DModel1Internal.object3dGroups.length != object3DModel2Internal.object3dGroups.length)
return false;
//
for (int i = 0; i < object3DModel1Internal.object3dGroups.length; i++) {
Object3DGroup object3DGroupModel1 = object3DModel1Internal.object3dGroups[i];
Object3DGroup object3DGroupModel2 = object3DModel2Internal.object3dGroups[i];
FacesEntity[] facesEntitiesModel1 = object3DGroupModel1.group.getFacesEntities();
FacesEntity[] facesEntitiesModel2 = object3DGroupModel2.group.getFacesEntities();
// check transformation matrix
if (object3DGroupModel1.group.getTransformationsMatrix().equals(object3DGroupModel2.group.getTransformationsMatrix()) == false)
return false;
// check number of faces entities
if (facesEntitiesModel1.length != facesEntitiesModel2.length)
return false;
// check each faces entity
for (int j = 0; j < facesEntitiesModel1.length; j++) {
FacesEntity facesEntityModel1 = facesEntitiesModel1[j];
FacesEntity facesEntityModel2 = facesEntitiesModel2[j];
// TODO: check if it should be allowed to have NULL material
if (facesEntityModel1.getMaterial() == null && facesEntityModel2.getMaterial() != null)
return false;
if (facesEntityModel1.getMaterial() != null && facesEntityModel2.getMaterial() == null)
return false;
if (facesEntityModel1.getMaterial() != null && facesEntityModel2.getMaterial() != null && facesEntityModel1.getMaterial().getId().equals(facesEntityModel2.getMaterial().getId()) == false) {
return false;
}
// check faces
Face[] facesModel1 = facesEntityModel1.getFaces();
Face[] facesModel2 = facesEntityModel2.getFaces();
// number of faces in faces entity
if (facesModel1.length != facesModel2.length)
return false;
// face indices
for (int k = 0; k < facesModel1.length; k++) {
// vertex indices
int[] vertexIndicesModel1 = facesModel1[k].getVertexIndices();
int[] vertexIndicesModel2 = facesModel2[k].getVertexIndices();
if (vertexIndicesModel1[0] != vertexIndicesModel2[0] || vertexIndicesModel1[1] != vertexIndicesModel2[1] || vertexIndicesModel1[2] != vertexIndicesModel2[2]) {
return false;
}
// TODO: maybe other indices
}
// TODO: check vertices, normals and such
}
}
//
return true;
}
use of net.drewke.tdme.engine.model.FacesEntity in project tdme by andreasdr.
the class ModelUtilitiesInternal method computeModelStatistics.
/**
* Compute model statistics
* @param object 3d model internal
* @return model statistics
*/
public static ModelStatistics computeModelStatistics(Object3DModelInternal object3DModelInternal) {
HashMap<String, Integer> materialCountById = new HashMap<String, Integer>();
int opaqueFaceCount = 0;
int transparentFaceCount = 0;
for (Object3DGroup object3DGroup : object3DModelInternal.object3dGroups) {
// check each faces entity
FacesEntity[] facesEntities = object3DGroup.group.getFacesEntities();
int facesEntityIdxCount = facesEntities.length;
for (int faceEntityIdx = 0; faceEntityIdx < facesEntityIdxCount; faceEntityIdx++) {
FacesEntity facesEntity = facesEntities[faceEntityIdx];
int faces = facesEntity.getFaces().length;
// material
Material material = facesEntity.getMaterial();
// determine if transparent
boolean transparentFacesEntity = false;
// via material
if (material != null) {
if (material.hasTransparency() == true)
transparentFacesEntity = true;
}
// setup material usage
String materialId = material == null ? "tdme.material.none" : material.getId();
Integer materialCount = materialCountById.get(materialId);
if (materialCount == null) {
materialCountById.put(materialId, 1);
} else {
materialCount++;
}
// skip, if requested
if (transparentFacesEntity == true) {
// keep track of rendered faces
transparentFaceCount += faces;
// skip to next entity
continue;
}
opaqueFaceCount += faces;
}
}
// determine final material count
int materialCount = 0;
for (Integer material : materialCountById.getValuesIterator()) {
materialCount++;
}
//
return new ModelStatistics(opaqueFaceCount, transparentFaceCount, materialCount);
}
use of net.drewke.tdme.engine.model.FacesEntity in project tdme by andreasdr.
the class PrimitiveModel method createBoundingBoxModel.
/**
* Creates a model from bounding box
* @param bounding box
* @param id
* @return model
*/
public static Model createBoundingBoxModel(BoundingBox boundingBox, 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 : boundingBox.getVertices()) {
vertices.add(vertex.clone());
}
// normals
ArrayList<Vector3> normals = new ArrayList<Vector3>();
normals.add(new Vector3(-1.0f, 0.0f, 0.0f));
normals.add(new Vector3(+1.0f, 0.0f, 0.0f));
normals.add(new Vector3(0.0f, -1.0f, 0.0f));
normals.add(new Vector3(0.0f, +1.0f, 0.0f));
normals.add(new Vector3(0.0f, 0.0f, -1.0f));
normals.add(new Vector3(0.0f, 0.0f, +1.0f));
// 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.FacesEntity in project tdme by andreasdr.
the class Object3DGroup method dispose.
/**
* Dispose
*/
protected void dispose() {
// dispose text
Engine engine = Engine.getInstance();
TextureManager textureManager = engine.getTextureManager();
// dispose textures
FacesEntity[] facesEntities = group.getFacesEntities();
for (int j = 0; j < facesEntities.length; j++) {
// get entity's material
Material material = facesEntities[j].getMaterial();
// skip if no material was set up
if (material == null)
continue;
// diffuse texture
int glDiffuseTextureId = materialDiffuseTextureIdsByEntities[j];
if (glDiffuseTextureId != Object3DGroup.GLTEXTUREID_NONE && glDiffuseTextureId != Object3DGroup.GLTEXTUREID_NOTUSED) {
// remove texture from texture manager
if (material.getDiffuseTexture() != null)
textureManager.removeTexture(material.getDiffuseTexture().getId());
// mark as removed
materialDiffuseTextureIdsByEntities[j] = Object3DGroup.GLTEXTUREID_NONE;
}
// specular texture
int glSpecularTextureId = materialSpecularTextureIdsByEntities[j];
if (glSpecularTextureId != Object3DGroup.GLTEXTUREID_NONE && glSpecularTextureId != Object3DGroup.GLTEXTUREID_NOTUSED) {
// remove texture from texture manager
if (material.getDiffuseTexture() != null)
textureManager.removeTexture(material.getSpecularTexture().getId());
// mark as removed
materialSpecularTextureIdsByEntities[j] = Object3DGroup.GLTEXTUREID_NONE;
}
// displacement texture
int glDisplacementTextureId = materialDisplacementTextureIdsByEntities[j];
if (glDisplacementTextureId != Object3DGroup.GLTEXTUREID_NONE && glDisplacementTextureId != Object3DGroup.GLTEXTUREID_NOTUSED) {
// remove texture from texture manager
if (material.getDisplacementTexture() != null)
textureManager.removeTexture(material.getDisplacementTexture().getId());
// mark as removed
materialDisplacementTextureIdsByEntities[j] = Object3DGroup.GLTEXTUREID_NONE;
}
// normal texture
int glNormalTextureId = materialNormalTextureIdsByEntities[j];
if (glNormalTextureId != Object3DGroup.GLTEXTUREID_NONE && glNormalTextureId != Object3DGroup.GLTEXTUREID_NOTUSED) {
// remove texture from texture manager
if (material.getNormalTexture() != null)
textureManager.removeTexture(material.getNormalTexture().getId());
// mark as removed
materialNormalTextureIdsByEntities[j] = Object3DGroup.GLTEXTUREID_NONE;
}
}
}
Aggregations