public VertexAnimationFrame() { mGeometry = new Geometry3D(); }
/** * Returns a {@link BoundingBox} for this Object3D and creates it if needed. * Utilizes children's bounding values to calculate its own {@link BoundingBox}. * * @return */ public BoundingBox getBoundingBox() { if (getNumChildren() > 0 && !mGeometry.hasBoundingBox()) { Vector3 min = new Vector3(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE); Vector3 max = new Vector3(-Double.MAX_VALUE, -Double.MAX_VALUE, -Double.MAX_VALUE); for (int i = 0; i < getNumChildren(); i++) { Object3D child = getChildAt(i); updateMaxMinCoords(min, max, child); } if (mGeometry.getVertices() != null) { updateMaxMinCoords(min, max, this); } mGeometry.setBoundingBox(new BoundingBox(min, max)); } return mGeometry.getBoundingBox(); }
/** * The reload method is called whenever the OpenGL context needs to be re-created. When the OpenGL context was lost, * the vertex, uv coord, index etc data needs to be re-uploaded. */ public void reload() { if (!mIsContainerOnly) { mGeometry.reload(); } for (int i = 0, j = mChildren.size(); i < j; i++) { mChildren.get(i).reload(); } if (mGeometry.hasBoundingBox() && getBoundingBox().getVisual() != null) { getBoundingBox().getVisual().reload(); } if (mGeometry.hasBoundingSphere() && mGeometry.getBoundingSphere().getVisual() != null) { mGeometry.getBoundingSphere().getVisual().reload(); } }
/** * Copies another Geometry3D's BufferInfo objects. This means that it * doesn't copy or clone the actual data. It will just use the pointers * to the other Geometry3D's buffers. * * @param geom * * @see BufferInfo */ public void copyFromGeometry3D(Geometry3D geom) { this.mNumIndices = geom.getNumIndices(); this.mNumVertices = geom.getNumVertices(); mBuffers.add(VERTEX_BUFFER_KEY, geom.getVertexBufferInfo()); mBuffers.add(NORMAL_BUFFER_KEY, geom.getNormalBufferInfo()); mBuffers.add(TEXTURE_BUFFER_KEY, geom.getTexCoordBufferInfo()); if (mBuffers.get(COLOR_BUFFER_KEY).buffer == null) { mBuffers.add(COLOR_BUFFER_KEY, geom.getColorBufferInfo()); } mBuffers.add(INDEX_BUFFER_KEY, geom.getIndexBufferInfo()); this.mOriginalGeometry = geom; this.mHasNormals = geom.hasNormals(); this.mHasTextureCoordinates = geom.hasTextureCoordinates(); }
mVerticesArray = getFloatArrayFromBuffer((FloatBuffer) mBuffers.get(VERTEX_BUFFER_KEY).buffer); mNormalsArray = getFloatArrayFromBuffer((FloatBuffer) mBuffers.get(NORMAL_BUFFER_KEY).buffer); mColorsArray = getFloatArrayFromBuffer((FloatBuffer) mBuffers.get(COLOR_BUFFER_KEY).buffer); mTextureCoordsArray = getFloatArrayFromBuffer((FloatBuffer) mBuffers.get(TEXTURE_BUFFER_KEY).buffer); mIndicesArray = getIntArrayFromBuffer(mBuffers.get(INDEX_BUFFER_KEY).buffer); float[] addVertices = getFloatArrayFromBuffer(geometry.getVertices()); if (offset != null) { for (int i = 0, j = addVertices.length; i < j; ++i) { float[] addNormals = getFloatArrayFromBuffer(geometry.getNormals()); float[] addColors = getFloatArrayFromBuffer(geometry.getColors()); float[] addTextureCoords = getFloatArrayFromBuffer(geometry.getTextureCoords()); int[] addIndices = getIntArrayFromBuffer(geometry.getIndices()); int index_offset = 0; if (mVerticesArray != null) { newVertices = concatAllFloat(mVerticesArray, addVertices); newNormals = concatAllFloat(mNormalsArray, addNormals); newColors = concatAllFloat(mColorsArray, addColors); newTextureCoords = concatAllFloat(mTextureCoordsArray, addTextureCoords); newIntIndices = concatAllInt(mIndicesArray, addIndices); setVertices(newVertices, true); setNormals(newNormals, true); setTextureCoords(newTextureCoords, true); setColors(newColors, true); setIndices(newIntIndices, true);
if (mGeometry.hasBoundingBox()) { getBoundingBox().transform(getModelMatrix()); if (mGeometry.hasBoundingSphere()) { mGeometry.getBoundingSphere().transform(getModelMatrix()); if (mFrustumTest && mGeometry.hasBoundingBox()) { BoundingBox bbox = getBoundingBox(); if (!camera.getFrustum().boundsInFrustum(bbox)) { if (mGeometry.hasTextureCoordinates()) { material.setTextureCoords(mGeometry.getTexCoordBufferInfo()); if (mGeometry.hasNormals()) { material.setNormals(mGeometry.getNormalBufferInfo()); material.setVertexColors(mGeometry.getColorBufferInfo()); material.setVertices(mGeometry.getVertexBufferInfo()); int bufferType = mGeometry.getIndexBufferInfo().bufferType == Geometry3D.BufferType.SHORT_BUFFER ? GLES20.GL_UNSIGNED_SHORT : GLES20.GL_UNSIGNED_INT; GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mGeometry.getIndexBufferInfo().bufferHandle); GLES20.glDrawElements(mDrawingMode, mGeometry.getNumIndices(), bufferType, 0); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0); if (mGeometry.hasBoundingBox()) { getBoundingBox().drawBoundingVolume(camera, vpMatrix, projMatrix, vMatrix, mMMatrix);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGeometry.getVertexBufferInfo().bufferHandle); GLES20.glEnableVertexAttribArray(maPositionHandle); GLES20.glVertexAttribPointer(maPositionHandle, 2, GLES20.GL_FLOAT, false, 0, 0); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGeometry.getTexCoordBufferInfo().bufferHandle); GLES20.glEnableVertexAttribArray(maTextureCoordHandle); GLES20.glVertexAttribPointer(maTextureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, 0); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mGeometry.getIndexBufferInfo().bufferHandle); GLES20.glDrawElements(GLES20.GL_TRIANGLES, mGeometry.getNumIndices(), GLES20.GL_UNSIGNED_INT, 0);
for (int i = 0; i < g.getVertices().capacity(); i += 3) { sb.append("v "); sb.append(g.getVertices().get(i)); sb.append(" "); sb.append(g.getVertices().get(i + 1)); sb.append(" "); sb.append(g.getVertices().get(i + 2)); sb.append("\n"); bufferStringWriting(sb, bw); for (int i = 0; i < g.getTextureCoords().capacity(); i += 2) { sb.append("vt "); sb.append(g.getTextureCoords().get(i)); sb.append(" "); sb.append(g.getTextureCoords().get(i + 1)); sb.append("\n"); bufferStringWriting(sb, bw); for (int i = 0; i < g.getNormals().capacity(); i += 3) { sb.append("vn "); sb.append(g.getNormals().get(i)); sb.append(" "); sb.append(g.getNormals().get(i + 1)); sb.append(" "); sb.append(g.getNormals().get(i + 2)); sb.append("\n"); bufferStringWriting(sb, bw); boolean isIntBuffer = g.getIndices() instanceof IntBuffer;
getGeometry().changeBufferUsage(mGeometry.getVertexBufferInfo(), GLES20.GL_DYNAMIC_DRAW); FloatBuffer b = mGeometry.getVertices(); int index = 0; addVertexToBuffer(b, index++, mFrustumCornersTransformed[4]); mGeometry.changeBufferData( mGeometry.getVertexBufferInfo(), mGeometry.getVertices(), 0);
public FloatBuffer getVertices() { if (mOriginalGeometry != null) { return mOriginalGeometry.getVertices(); } return (FloatBuffer) mBuffers.get(VERTEX_BUFFER_KEY).buffer; }
if (o.getGeometry().hasBoundingSphere()) { BoundingSphere bsphere = o.getGeometry().getBoundingSphere(); bsphere.calculateBounds(o.getGeometry()); bsphere.transform(o.getModelMatrix()); BoundingBox bbox = o.getGeometry().getBoundingBox(); bbox.calculateBounds(o.getGeometry()); bbox.transform(o.getModelMatrix());
/** * Calculate the length of the TriangleBlock that will be written. * * @param geom * @return */ private int awdGetGeomLength(Geometry3D geom) { return 24 + (geom.getNumIndices() * 2) + (geom.getNumVertices() * 4) + (geom.getNormals().limit() * 4) + (geom.getTextureCoords().limit() * 4); }
if (mFrustumTest && mGeometry.hasBoundingBox()) { BoundingBox bbox = getBoundingBox(); if (!camera.getFrustum().boundsInFrustum(bbox)) { pickingMaterial.setVertices(mGeometry.getVertexBufferInfo()); pickingMaterial.setColor(mPickingColor); pickingMaterial.applyParams(); int bufferType = mGeometry.getIndexBufferInfo().bufferType == Geometry3D.BufferType.SHORT_BUFFER ? GLES20.GL_UNSIGNED_SHORT : GLES20.GL_UNSIGNED_INT; GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, mGeometry.getIndexBufferInfo().bufferHandle); GLES20.glDrawElements(mDrawingMode, mGeometry.getNumIndices(), bufferType, 0); GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
/** * Maps the (x,y) coordinates of <code>tileName</code> in <code>atlas</code> * to the TextureCoordinates of this BaseObject3D * * Saves a copy of the original TextureCoordinates in case of future mapping. * * @param tileName * @param atlas */ public void setAtlasTile(String tileName, TextureAtlas atlas) { Tile tile = atlas.getTileNamed(tileName); if(mOriginalTextureCoords == null) { mOriginalTextureCoords = this.getGeometry().getTextureCoords().duplicate(); } FloatBuffer fb = FloatBuffer.allocate(mOriginalTextureCoords.capacity()); for (int i = 0; i < fb.capacity(); i++) { double uvIn = mOriginalTextureCoords.get(i); double uvOut; if (i % 2 == 0) { uvOut = (uvIn * (tile.width / atlas.getWidth())) + tile.x / atlas.getWidth(); } else { uvOut = (uvIn * (tile.height / atlas.getHeight())) + tile.y / atlas.getHeight(); } fb.put(i, (float) uvOut); } mGeometry.changeBufferData(mGeometry.getTexCoordBufferInfo(), fb, 0); }
private void updateBox(BoundingBox bb) { FloatBuffer b = mGeometry.getVertices(); int index = 0; bb.copyPoints(mBBoxVertices); addVertexToBuffer(b, index++, mBBoxVertices[0]); addVertexToBuffer(b, index++, mBBoxVertices[1]); addVertexToBuffer(b, index++, mBBoxVertices[2]); addVertexToBuffer(b, index++, mBBoxVertices[3]); addVertexToBuffer(b, index++, mBBoxVertices[0]); addVertexToBuffer(b, index++, mBBoxVertices[4]); addVertexToBuffer(b, index++, mBBoxVertices[5]); addVertexToBuffer(b, index++, mBBoxVertices[1]); addVertexToBuffer(b, index++, mBBoxVertices[5]); addVertexToBuffer(b, index++, mBBoxVertices[6]); addVertexToBuffer(b, index++, mBBoxVertices[2]); addVertexToBuffer(b, index++, mBBoxVertices[6]); addVertexToBuffer(b, index++, mBBoxVertices[7]); addVertexToBuffer(b, index++, mBBoxVertices[3]); addVertexToBuffer(b, index++, mBBoxVertices[7]); addVertexToBuffer(b, index++, mBBoxVertices[4]); mGeometry.changeBufferData( mGeometry.getVertexBufferInfo(), mGeometry.getVertices(), 0); }
/** * Change a specific subset of the buffer's data at the given offset to the given length. * * @param bufferInfo * @param newData * @param index */ public void changeBufferData(BufferInfo bufferInfo, Buffer newData, int index) { this.changeBufferData(bufferInfo, newData, index, false); }
public void updateBoundingBox(BoundingBox boundingBox) { if(mBBoxVertices == null) { mBBoxVertices = new Vector3[8]; mPoints = new Stack<>(); for(int i=0; i<16; i++) { mPoints.push(new Vector3()); if(i < 8) mBBoxVertices[i] = new Vector3(); } init(true); getGeometry().changeBufferUsage(mGeometry.getVertexBufferInfo(), GLES20.GL_DYNAMIC_DRAW); setMaterial(new Material()); } updateBox(boundingBox); }
public FloatBuffer getTextureCoords() { if (mBuffers.get(TEXTURE_BUFFER_KEY).buffer == null && mOriginalGeometry != null) { return mOriginalGeometry.getTextureCoords(); } return (FloatBuffer) mBuffers.get(TEXTURE_BUFFER_KEY).buffer; }
@Override protected void doTask() { // ensure all cameras can see the far side of the skybox float out_radius = (float)skybox.getGeometry().getBoundingSphere().getRadius(); float in_radius = out_radius/(float)Math.sqrt(3); float median_diagonal = in_radius + out_radius; for (int i = 0, j = mCameras.size(); i < j; ++i) if(mCameras.get(i).getFarPlane() < median_diagonal) { mCameras.get(i).setFarPlane(median_diagonal); } } };
@Test public void testApplyCube() { Cube cube = new Cube(1, false, false, false, false, false); cube.getGeometry().getBoundingBox(); visitor.apply(cube); assertNull(visitor.getPickedObject()); }