use of net.drewke.tdme.engine.model.Model in project tdme by andreasdr.
the class Tools method createGroundModel.
/**
* Creates a ground plate
* @param width
* @param depth
* @param float y
* @return ground model
*/
public static Model createGroundModel(float width, float depth, float y) {
// ground model
Model ground = new Model("ground", "ground", UpVector.Y_UP, RotationOrder.XYZ, null);
// material
Material groundMaterial = new Material("ground");
groundMaterial.getSpecularColor().set(0f, 0f, 0f, 1f);
ground.getMaterials().put("ground", groundMaterial);
// group
Group groundGroup = new Group(ground, null, "ground", "ground");
// faces entity
// ground
FacesEntity groupFacesEntityGround = new FacesEntity(groundGroup, "ground group faces entity ground");
groupFacesEntityGround.setMaterial(groundMaterial);
// 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(-width, y, -depth));
// left, far, ground
groundVertices.add(new Vector3(-width, y, +depth));
// right far, ground
groundVertices.add(new Vector3(+width, y, +depth));
// right, near, ground
groundVertices.add(new Vector3(+width, y, -depth));
// 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, 0f));
groundTextureCoordinates.add(new TextureCoordinate(0f, 1f));
groundTextureCoordinates.add(new TextureCoordinate(1f, 1f));
groundTextureCoordinates.add(new TextureCoordinate(1f, 0f));
// 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
ground.getGroups().put("ground", groundGroup);
ground.getSubGroups().put("ground", groundGroup);
// prepare for indexed rendering
ModelHelper.prepareForIndexedRendering(ground);
//
return ground;
}
use of net.drewke.tdme.engine.model.Model in project tdme by andreasdr.
the class LevelEditorEntityLibrary method addEmpty.
/**
* Add a empty
* @param name
* @param description
* @return level editor entity
* @throws Exception
*/
public LevelEditorEntity addEmpty(int id, String name, String description) throws Exception {
String cacheId = "leveleditor.empty";
LevelEditorEntity levelEditorEntity = null;
// create entity
Model model = DAEReader.read("resources/tools/leveleditor/models", "arrow.dae");
levelEditorEntity = new LevelEditorEntity(id == ID_ALLOCATE ? allocateEntityId() : id, EntityType.EMPTY, name, description, null, cacheId, model.getId().replace("\\", "_").replace("/", "_").replace(":", "_") + ".png", model, new Vector3());
// add empty
addEntity(levelEditorEntity);
//
return levelEditorEntity;
}
use of net.drewke.tdme.engine.model.Model in project tdme by andreasdr.
the class Object3DVBORenderer method prepareTransparentFaces.
/**
* Renders transparent faces
* TODO: guess this should be optimized regarding GL commands
* skinned mesh is not supported when using GPU
* @param transparent render faces
*/
protected void prepareTransparentFaces(ArrayList<TransparentRenderFace> transparentRenderFaces) {
// all those faces should share the object and object 3d group, ...
Object3DGroup object3DGroup = transparentRenderFaces.get(0).object3DGroup;
Object3D object3D = (Object3D) object3DGroup.object;
// model view matrix to be used with given transparent render faces
modelViewMatrix = (object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(object3DGroup.groupTransformationsMatrix)).multiply(object3D.transformationsMatrix).multiply(renderer.getModelViewMatrix());
//
Model model = ((Object3D) object3DGroup.object).getModel();
FacesEntity[] facesEntities = object3DGroup.group.getFacesEntities();
FacesEntity facesEntity = null;
// attributes we collect for a transparent render face group
boolean depthBuffer = false;
Color4 effectColorAdd = ((Object3D) object3D).getEffectColorAdd();
Color4 effectColorMul = ((Object3D) object3D).getEffectColorMul();
Material material = null;
boolean textureCoordinates = false;
// render transparent faces
Key transparentRenderFacesGroupKey = keyPool.allocate();
for (int i = 0; i < transparentRenderFaces.size(); i++) {
TransparentRenderFace transparentRenderFace = transparentRenderFaces.get(i);
int facesEntityIdx = transparentRenderFace.facesEntityIdx;
// check if to use depth buffer
depthBuffer = ((Object3D) transparentRenderFace.object3DGroup.object).isPickable();
// determine if faces entity and so material did switch between last face and current face
if (facesEntity != facesEntities[facesEntityIdx]) {
facesEntity = facesEntities[facesEntityIdx];
material = facesEntity.getMaterial();
}
textureCoordinates = facesEntity.isTextureCoordinatesAvailable();
// create group key
TransparentRenderFacesGroup.createKey(transparentRenderFacesGroupKey, model, object3DGroup, facesEntityIdx, effectColorAdd, effectColorMul, depthBuffer, material, textureCoordinates);
// get group
TransparentRenderFacesGroup trfGroup = transparentRenderFacesGroups.get(transparentRenderFacesGroupKey);
if (trfGroup == null) {
// we do not have the group, create group
trfGroup = transparentRenderFacesGroupPool.allocate();
trfGroup.set(this, model, object3DGroup, facesEntityIdx, effectColorAdd, effectColorMul, depthBuffer, material, textureCoordinates);
Key hashtableKey = keyPool.allocate();
transparentRenderFacesGroupKey.cloneInto(hashtableKey);
if (transparentRenderFacesGroups.put(hashtableKey, trfGroup) != null) {
System.out.println("Object3DVBORenderer::prepareTransparentFaces::key already exists");
System.out.println("-->" + transparentRenderFacesGroupKey);
System.out.println("-->" + hashtableKey);
}
}
// add face vertices
for (int vertexIdx = 0; vertexIdx < 3; vertexIdx++) {
short arrayIdx = transparentRenderFace.object3DGroup.mesh.indices[transparentRenderFace.faceIdx * 3 + vertexIdx];
trfGroup.addVertex(modelViewMatrix.multiply(transparentRenderFace.object3DGroup.mesh.transformedVertices[arrayIdx], transformedVertex), modelViewMatrix.multiplyNoTranslation(transparentRenderFace.object3DGroup.mesh.transformedNormals[arrayIdx], transformedNormal), transparentRenderFace.object3DGroup.mesh.textureCoordinates != null ? transparentRenderFace.object3DGroup.mesh.textureCoordinates[arrayIdx] : null);
}
}
keyPool.release(transparentRenderFacesGroupKey);
}
use of net.drewke.tdme.engine.model.Model 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.Model in project tdme by andreasdr.
the class Object3DGroup method createGroups.
/**
* Creates object 3d groups from given object3d base object
* @param object 3d base
* @param use mesh manager
* @return object 3d group array
*/
protected static Object3DGroup[] createGroups(Object3DBase object, boolean useMeshManager, Engine.AnimationProcessingTarget animationProcessingTarget) {
ArrayList<Object3DGroup> object3DGroups = new ArrayList<Object3DGroup>();
Model model = object.getModel();
createGroups(object, object3DGroups, model.getSubGroups(), model.hasAnimations(), useMeshManager, animationProcessingTarget);
Object3DGroup[] object3DGroupArray = new Object3DGroup[object3DGroups.size()];
object3DGroups.toArray(object3DGroupArray);
return object3DGroupArray;
}
Aggregations