use of net.drewke.tdme.engine.model.Material 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.Material in project tdme by andreasdr.
the class DAEReader method readGeometry.
/**
* Reads a geometry
* @param authoring tools
* @param path name
* @param model
* @param group
* @param xml root
* @param xml node id
* @param material symbols
* @throws Exception
*/
public static void readGeometry(AuthoringTool authoringTool, String pathName, Model model, Group group, Element xmlRoot, String xmlNodeId, HashMap<String, String> materialSymbols) throws Exception {
StringTokenizer t;
//
FacesEntity facesEntity = null;
ArrayList<FacesEntity> facesEntities = new ArrayList<FacesEntity>(Arrays.asList(group.getFacesEntities()));
int verticesOffset = group.getVertices().length;
ArrayList<Vector3> vertices = new ArrayList<Vector3>(Arrays.asList(group.getVertices()));
int normalsOffset = group.getNormals().length;
ArrayList<Vector3> normals = new ArrayList<Vector3>(Arrays.asList(group.getNormals()));
int textureCoordinatesOffset = group.getTextureCoordinates() != null ? group.getTextureCoordinates().length : 0;
ArrayList<TextureCoordinate> textureCoordinates = group.getTextureCoordinates() != null ? new ArrayList<TextureCoordinate>(Arrays.asList(group.getTextureCoordinates())) : new ArrayList<TextureCoordinate>();
Element xmlLibraryGeometries = getChildrenByTagName(xmlRoot, "library_geometries").get(0);
for (Element xmlGeometry : getChildrenByTagName(xmlLibraryGeometries, "geometry")) {
if (xmlGeometry.getAttribute("id").equals(xmlNodeId)) {
Element xmlMesh = getChildrenByTagName(xmlGeometry, "mesh").get(0);
ArrayList<Element> xmlPolygonsList = new ArrayList<Element>();
// try to read from triangles
for (Element xmlTriangesElement : getChildrenByTagName(xmlMesh, "triangles")) {
xmlPolygonsList.add(xmlTriangesElement);
}
// try to read from polylist
for (Element xmlPolyListElement : getChildrenByTagName(xmlMesh, "polylist")) {
xmlPolygonsList.add(xmlPolyListElement);
}
// try to read from polygons
for (Element xmlPolygonsElement : getChildrenByTagName(xmlMesh, "polygons")) {
xmlPolygonsList.add(xmlPolygonsElement);
}
// parse from xml polygons elements
for (Element xmlPolygons : xmlPolygonsList) {
ArrayList<Face> faces = new ArrayList<Face>();
facesEntity = new FacesEntity(group, xmlNodeId);
if (xmlPolygons.getNodeName().toLowerCase().equals("polylist")) {
t = new StringTokenizer(getChildrenByTagName(xmlPolygons, "vcount").get(0).getTextContent());
while (t.hasMoreTokens()) {
int vertexCount = Integer.parseInt(t.nextToken());
if (vertexCount != 3) {
throw new ModelFileIOException("we only support triangles in " + xmlNodeId);
}
}
}
// parse triangles
int xmlInputs = -1;
int xmlVerticesOffset = -1;
String xmlVerticesSource = null;
int xmlNormalsOffset = -1;
String xmlNormalsSource = null;
int xmlTexCoordOffset = -1;
String xmlTexCoordSource = null;
int xmlColorOffset = -1;
String xmlColorSource = null;
// material
String xmlMaterialId = xmlPolygons.getAttribute("material");
String materialSymbol = materialSymbols.get(xmlMaterialId);
if (materialSymbol != null)
xmlMaterialId = materialSymbol.substring(1);
if (xmlMaterialId != null && xmlMaterialId.length() > 0) {
Material material = model.getMaterials().get(xmlMaterialId);
if (material == null) {
// parse material as we do not have it yet
material = readMaterial(authoringTool, pathName, model, xmlRoot, xmlMaterialId);
}
// set it up
facesEntity.setMaterial(material);
}
// parse input sources
HashSet<Integer> xmlInputSet = new HashSet<Integer>();
for (Element xmlTrianglesInput : getChildrenByTagName(xmlPolygons, "input")) {
// check for vertices sources
if (xmlTrianglesInput.getAttribute("semantic").equals("VERTEX")) {
xmlVerticesOffset = Integer.parseInt(xmlTrianglesInput.getAttribute("offset"));
xmlVerticesSource = xmlTrianglesInput.getAttribute("source").substring(1);
xmlInputSet.add(xmlVerticesOffset);
} else // check for normals sources
if (xmlTrianglesInput.getAttribute("semantic").equals("NORMAL")) {
xmlNormalsOffset = Integer.parseInt(xmlTrianglesInput.getAttribute("offset"));
xmlNormalsSource = xmlTrianglesInput.getAttribute("source").substring(1);
xmlInputSet.add(xmlNormalsOffset);
}
// check for texture coordinate sources
if (xmlTrianglesInput.getAttribute("semantic").equals("TEXCOORD")) {
xmlTexCoordOffset = Integer.parseInt(xmlTrianglesInput.getAttribute("offset"));
xmlTexCoordSource = xmlTrianglesInput.getAttribute("source").substring(1);
xmlInputSet.add(xmlTexCoordOffset);
}
// check for color coordinate sources
if (xmlTrianglesInput.getAttribute("semantic").equals("COLOR")) {
xmlColorOffset = Integer.parseInt(xmlTrianglesInput.getAttribute("offset"));
xmlColorSource = xmlTrianglesInput.getAttribute("source").substring(1);
xmlInputSet.add(xmlColorOffset);
}
}
xmlInputs = xmlInputSet.size();
// get vertices source
for (Element xmlVertices : getChildrenByTagName(xmlMesh, "vertices")) {
if (xmlVertices.getAttribute("id").equals(xmlVerticesSource)) {
for (Element xmlVerticesInput : getChildrenByTagName(xmlVertices, "input")) {
if (xmlVerticesInput.getAttribute("semantic").equalsIgnoreCase("position")) {
xmlVerticesSource = xmlVerticesInput.getAttribute("source").substring(1);
} else if (xmlVerticesInput.getAttribute("semantic").equalsIgnoreCase("normal")) {
xmlNormalsSource = xmlVerticesInput.getAttribute("source").substring(1);
}
}
}
}
// check for triangles vertices sources
if (xmlVerticesSource == null) {
throw new ModelFileIOException("Could not determine triangles vertices source for '" + xmlNodeId + "'");
}
// check for triangles normals sources
if (xmlNormalsSource == null) {
throw new ModelFileIOException("Could not determine triangles normal source for '" + xmlNodeId + "'");
}
// load vertices, normals, texture coordinates
for (Element xmlMeshSource : getChildrenByTagName(xmlMesh, "source")) {
// vertices
if (xmlMeshSource.getAttribute("id").equals(xmlVerticesSource)) {
Element xmlFloatArray = getChildrenByTagName(xmlMeshSource, "float_array").get(0);
String valueString = xmlFloatArray.getTextContent();
t = new StringTokenizer(valueString, " \n\r");
while (t.hasMoreTokens()) {
Vector3 v = new Vector3(Float.parseFloat(t.nextToken()), Float.parseFloat(t.nextToken()), Float.parseFloat(t.nextToken()));
vertices.add(v);
}
} else // normals
if (xmlMeshSource.getAttribute("id").equals(xmlNormalsSource)) {
Element xmlFloatArray = getChildrenByTagName(xmlMeshSource, "float_array").get(0);
String valueString = xmlFloatArray.getTextContent();
t = new StringTokenizer(valueString, " \n\r");
while (t.hasMoreTokens()) {
Vector3 v = new Vector3(Float.parseFloat(t.nextToken()), Float.parseFloat(t.nextToken()), Float.parseFloat(t.nextToken()));
normals.add(v);
}
}
// texture coordinates
if (xmlTexCoordSource != null) {
if (xmlMeshSource.getAttribute("id").equals(xmlTexCoordSource)) {
Element xmlFloatArray = getChildrenByTagName(xmlMeshSource, "float_array").get(0);
String valueString = xmlFloatArray.getTextContent();
t = new StringTokenizer(valueString, " \n\r");
while (t.hasMoreTokens()) {
TextureCoordinate tc = new TextureCoordinate(Float.parseFloat(t.nextToken()), Float.parseFloat(t.nextToken()));
textureCoordinates.add(tc);
}
}
}
}
// load faces
for (Element xmlPolygon : getChildrenByTagName(xmlPolygons, "p")) {
String valueString = xmlPolygon.getTextContent();
t = new StringTokenizer(valueString, " \n\r");
int[] vi = new int[3];
int viIdx = 0;
int[] ni = new int[3];
int niIdx = 0;
int[] ti = xmlTexCoordSource == null ? null : new int[3];
int tiIdx = 0;
int valueIdx = 0;
boolean valid = true;
while (t.hasMoreTokens()) {
int value = Integer.parseInt(t.nextToken());
if (valueIdx % xmlInputs == xmlVerticesOffset) {
vi[viIdx++] = value;
// validate
if (value < 0 || value >= vertices.size() - verticesOffset) {
valid = false;
}
// fix for some strange models
if (xmlNormalsSource != null && xmlNormalsOffset == -1) {
ni[niIdx++] = value;
// validate
if (value < 0 || value >= normals.size() - normalsOffset) {
valid = false;
}
}
}
if (xmlNormalsOffset != -1 && valueIdx % xmlInputs == xmlNormalsOffset) {
ni[niIdx++] = value;
// validate
if (value < 0 || value >= normals.size() - normalsOffset) {
valid = false;
}
}
if (xmlTexCoordOffset != -1 && valueIdx % xmlInputs == xmlTexCoordOffset) {
ti[tiIdx++] = value;
// validate
if (value < 0 || value >= textureCoordinates.size() - textureCoordinatesOffset) {
valid = false;
}
}
if (viIdx == 3 && niIdx == 3 && (ti == null || tiIdx == 3)) {
// only add valid faces
if (valid) {
// add face
Face f = new Face(group, vi[0] + verticesOffset, vi[1] + verticesOffset, vi[2] + verticesOffset, ni[0] + normalsOffset, ni[1] + normalsOffset, ni[2] + normalsOffset);
if (ti != null) {
f.setTextureCoordinateIndices(ti[0] + textureCoordinatesOffset, ti[1] + textureCoordinatesOffset, ti[2] + textureCoordinatesOffset);
}
faces.add(f);
}
viIdx = 0;
niIdx = 0;
tiIdx = 0;
valid = true;
}
valueIdx++;
}
}
// add faces entities if we have any
if (faces.isEmpty() == false) {
facesEntity.setFaces(faces);
facesEntities.add(facesEntity);
}
}
}
}
// set up group
group.setVertices(vertices);
group.setNormals(normals);
if (textureCoordinates.size() > 0)
group.setTextureCoordinates(textureCoordinates);
group.setFacesEntities(facesEntities);
// create normal tangents and bitangents
ModelHelper.createNormalTangentsAndBitangents(group);
// determine features
group.determineFeatures();
}
use of net.drewke.tdme.engine.model.Material in project tdme by andreasdr.
the class WFObjReader method readMaterials.
/**
* Reads a wavefront object material library
* @param path name
* @param file name
* @return
*/
private static HashMap<String, Material> readMaterials(String pathName, String fileName) throws IOException {
HashMap<String, Material> materials = new HashMap<String, Material>();
Material current = null;
//
DataInputStream inputStream = new DataInputStream(FileSystem.getInstance().getInputStream(pathName, fileName));
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
float alpha = 1.0f;
while ((line = reader.readLine()) != null) {
line = line.trim();
// skip on comments
if (line.startsWith("#")) {
continue;
}
// determine index of first ' ' which will separate command from arguments
int commandEndIdx = line.indexOf(' ');
if (commandEndIdx == -1)
commandEndIdx = line.length();
// determine command
String command = line.substring(0, commandEndIdx).trim().toLowerCase();
// determine arguments if any exist
String arguments = command.length() + 1 > line.length() ? "" : line.substring(command.length() + 1);
// parse
if (command.equals("newmtl")) {
String name = arguments;
current = new Material(name);
materials.put(name, current);
} else if (command.equals("map_ka")) {
current.setDiffuseTexture(pathName, arguments);
} else if (command.equals("map_kd")) {
current.setDiffuseTexture(pathName, arguments);
} else if (command.equals("ka")) {
StringTokenizer t = new StringTokenizer(arguments, " ");
current.getAmbientColor().set(Float.parseFloat(t.nextToken()), Float.parseFloat(t.nextToken()), Float.parseFloat(t.nextToken()), alpha);
} else if (command.equals("kd")) {
StringTokenizer t = new StringTokenizer(arguments, " ");
current.getDiffuseColor().set(Float.parseFloat(t.nextToken()), Float.parseFloat(t.nextToken()), Float.parseFloat(t.nextToken()), alpha);
} else if (command.equals("ks")) {
StringTokenizer t = new StringTokenizer(arguments, " ");
current.getSpecularColor().set(Float.parseFloat(t.nextToken()), Float.parseFloat(t.nextToken()), Float.parseFloat(t.nextToken()), alpha);
} else if (command.equals("tr")) {
alpha = Float.parseFloat(arguments);
current.getAmbientColor().setAlpha(alpha);
current.getDiffuseColor().setAlpha(alpha);
current.getSpecularColor().setAlpha(alpha);
current.getEmissionColor().setAlpha(alpha);
} else if (command.equals("d")) {
alpha = Float.parseFloat(arguments);
current.getAmbientColor().setAlpha(alpha);
current.getDiffuseColor().setAlpha(alpha);
current.getSpecularColor().setAlpha(alpha);
current.getEmissionColor().setAlpha(alpha);
}
}
// Close the input stream
inputStream.close();
//
return materials;
}
use of net.drewke.tdme.engine.model.Material in project tdme by andreasdr.
the class TMReader method readMaterial.
/**
* Read material
* @param input stream
* @throws IOException
* @throws ModelFileIOException
* @return material
*/
private static Material readMaterial(InputStream is) throws IOException, ModelFileIOException {
String id = readString(is);
Material m = new Material(id);
m.getAmbientColor().set(readFloatArray(is));
m.getDiffuseColor().set(readFloatArray(is));
m.getSpecularColor().set(readFloatArray(is));
m.getEmissionColor().set(readFloatArray(is));
m.setShininess(readFloat(is));
String diffuseTexturePathName = readString(is);
String diffuseTextureFileName = readString(is);
if (diffuseTextureFileName != null && diffuseTexturePathName != null) {
m.setDiffuseTexture(diffuseTexturePathName, diffuseTextureFileName);
}
String specularTexturePathName = readString(is);
String specularTextureFileName = readString(is);
if (specularTextureFileName != null && specularTexturePathName != null) {
m.setSpecularTexture(specularTexturePathName, specularTextureFileName);
}
String normalTexturePathName = readString(is);
String normalTextureFileName = readString(is);
if (normalTextureFileName != null && normalTexturePathName != null) {
m.setNormalTexture(normalTexturePathName, normalTextureFileName);
}
String displacementTexturePathName = readString(is);
String displacementTextureFileName = readString(is);
if (displacementTextureFileName != null && displacementTexturePathName != null) {
m.setDisplacementTexture(displacementTexturePathName, displacementTextureFileName);
}
return m;
}
use of net.drewke.tdme.engine.model.Material in project tdme by andreasdr.
the class Object3DVBORenderer method renderObjectsOfSameType.
/**
* Renders multiple objects of same type(with same model)
* @param engine
* @param objects of same type/ with same models
* @param collect render faces
* @param skinning shader
*/
protected void renderObjectsOfSameType(ArrayList<Object3D> objects, boolean collectTransparentFaces, SkinningShader skinningShader) {
// do pre render steps
for (int i = 0; i < objects.size(); i++) {
Object3D object = objects.get(i);
for (int j = 0; j < object.object3dGroups.length; j++) {
Object3DGroup object3DGroup = object.object3dGroups[j];
((Object3DGroupVBORenderer) object3DGroup.renderer).preRender(this);
}
}
//
ShadowMapping shadowMapping = engine.getShadowMapping();
modelViewMatrixBackup.set(renderer.getModelViewMatrix());
// render faces entities
int currentFrontFace = -1;
Object3D firstObject = objects.get(0);
// all objects share the same object 3d group structure, so we just take the first one
int[] boundVBOBaseIds = null;
int[] boundVBOTangentBitangentIds = null;
int[] boundSkinningIds = null;
for (int object3DGroupIdx = 0; object3DGroupIdx < firstObject.object3dGroups.length; object3DGroupIdx++) {
Object3DGroup object3DGroup = firstObject.object3dGroups[object3DGroupIdx];
// render each faces entity
FacesEntity[] facesEntities = object3DGroup.group.getFacesEntities();
int faceIdx = 0;
int facesEntityIdxCount = facesEntities.length;
for (int faceEntityIdx = 0; faceEntityIdx < facesEntityIdxCount; faceEntityIdx++) {
FacesEntity facesEntity = facesEntities[faceEntityIdx];
boolean isTextureCoordinatesAvailable = facesEntity.isTextureCoordinatesAvailable();
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;
}
// skip, if requested
if (transparentFacesEntity == true) {
// add to transparent render faces, if requested
int objectCount = objects.size();
for (int objectIdx = 0; objectIdx < objectCount; objectIdx++) {
Object3D object = objects.get(objectIdx);
Object3DGroup _object3DGroup = object.object3dGroups[object3DGroupIdx];
// set up textures
Object3DGroup.setupTextures(renderer, object3DGroup, faceEntityIdx);
// set up transparent render faces
if (collectTransparentFaces == true) {
transparentRenderFacesPool.createTransparentRenderFaces((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix).multiply(modelViewMatrixBackup), object.object3dGroups[object3DGroupIdx], faceEntityIdx, faceIdx);
}
}
// keep track of rendered faces
faceIdx += faces;
// skip to next entity
continue;
}
// optional texture coordinates
if (isTextureCoordinatesAvailable == true) {
// enable texturing client state if not yet done
if (renderer.renderingTexturingClientState == false) {
renderer.enableClientState(renderer.CLIENTSTATE_TEXTURECOORD_ARRAY);
renderer.renderingTexturingClientState = true;
}
} else {
// disable texturing client state if not yet done
if (renderer.renderingTexturingClientState == true) {
renderer.disableClientState(renderer.CLIENTSTATE_TEXTURECOORD_ARRAY);
renderer.renderingTexturingClientState = false;
}
}
// draw this faces entity for each object
int objectCount = objects.size();
for (int objectIdx = 0; objectIdx < objectCount; objectIdx++) {
Object3D object = objects.get(objectIdx);
Object3DGroup _object3DGroup = object.object3dGroups[object3DGroupIdx];
// set up material on first object
if (objectIdx == 0) {
// set up material
setupMaterial(_object3DGroup, faceEntityIdx);
} else {
// only set up textures
Object3DGroup.setupTextures(renderer, _object3DGroup, faceEntityIdx);
}
// check transparency via effect
if (object.effectColorMul.getAlpha() < 1.0f - MathTools.EPSILON || object.effectColorAdd.getAlpha() < -MathTools.EPSILON) {
// add to transparent render faces, if requested
if (collectTransparentFaces == true) {
transparentRenderFacesPool.createTransparentRenderFaces((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix).multiply(modelViewMatrixBackup), _object3DGroup, faceEntityIdx, faceIdx);
}
// skip to next object
continue;
}
// bind buffer base objects if not bound yet
int[] currentVBOGlIds = ((Object3DGroupVBORenderer) _object3DGroup.renderer).vboBaseIds;
if (boundVBOBaseIds != currentVBOGlIds) {
boundVBOBaseIds = currentVBOGlIds;
// texture coordinates
if (isTextureCoordinatesAvailable == true) {
renderer.bindTextureCoordinatesBufferObject(currentVBOGlIds[3]);
}
// vertices
renderer.bindVerticesBufferObject(currentVBOGlIds[1]);
// normals
renderer.bindNormalsBufferObject(currentVBOGlIds[2]);
// indices
renderer.bindIndicesBufferObject(currentVBOGlIds[0]);
}
// bind tangent, bitangend buffers if not yet bound
int[] currentVBOTangentBitangentIds = ((Object3DGroupVBORenderer) _object3DGroup.renderer).vboTangentBitangentIds;
if (renderer.isNormalMappingAvailable() && currentVBOTangentBitangentIds != null && currentVBOTangentBitangentIds != boundVBOTangentBitangentIds) {
// tangent
renderer.bindTangentsBufferObject(currentVBOTangentBitangentIds[0]);
// bitangent
renderer.bindBitangentsBufferObject(currentVBOTangentBitangentIds[1]);
}
// set up GPU skinning, if required
if (Engine.animationProcessingTarget == Engine.AnimationProcessingTarget.GPU && _object3DGroup.mesh.skinning == true && skinningShader != null) {
_object3DGroup.mesh.setupSkinningTransformationsMatrices(_object3DGroup.groupTransformationsMatricesVector);
skinningShader.initSkinning(renderer, _object3DGroup.mesh);
int[] currentSkinningIds = ((Object3DGroupVBORenderer) _object3DGroup.renderer).vboSkinningIds;
if (boundSkinningIds != currentSkinningIds) {
boundSkinningIds = currentSkinningIds;
renderer.bindSkinningVerticesJointsBufferObject(currentSkinningIds[0]);
renderer.bindSkinningVerticesVertexJointsIdxBufferObject(currentSkinningIds[1]);
renderer.bindSkinningVerticesVertexJointsWeightBufferObject(currentSkinningIds[2]);
}
}
// set up local -> world transformations matrix
renderer.getModelViewMatrix().set((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix).multiply(modelViewMatrixBackup));
renderer.onUpdateModelViewMatrix();
// set up front face
int objectFrontFace = matrix4x4Negative.isNegative(renderer.getModelViewMatrix()) == false ? renderer.FRONTFACE_CCW : renderer.FRONTFACE_CW;
if (objectFrontFace != currentFrontFace) {
renderer.setFrontFace(objectFrontFace);
currentFrontFace = objectFrontFace;
}
// set up effect color
renderer.setEffectColorMul(object.effectColorMul.getArray());
renderer.setEffectColorAdd(object.effectColorAdd.getArray());
renderer.onUpdateEffect();
// do transformation start to shadow mapping
if (shadowMapping != null) {
shadowMapping.startObjectTransformations((_object3DGroup.mesh.skinning == true ? modelViewMatrix.identity() : modelViewMatrix.set(_object3DGroup.groupTransformationsMatrix)).multiply(object.transformationsMatrix));
}
// draw
renderer.drawIndexedTrianglesFromBufferObjects(faces, faceIdx);
// do transformations end to shadow mapping
if (shadowMapping != null) {
shadowMapping.endObjectTransformations();
}
}
// done skinning
if (skinningShader != null) {
skinningShader.doneSkinning(renderer);
}
// keep track of rendered faces
faceIdx += faces;
}
}
// unbind buffers
renderer.unbindBufferObjects();
// restore model view matrix / view matrix
renderer.getModelViewMatrix().set(modelViewMatrixBackup);
}
Aggregations