Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i create a 3D object in android application? [closed]

Tags:

android

Kindly give me the way to create a 3D object in android application

like image 318
sruthi Avatar asked Dec 29 '22 06:12

sruthi


1 Answers

To draw a 3D Object you may need to use the OpenGL ES API. Here you have the main steps you may need to implement in order to load you own 3D object:

  1. Extend the GLSurfaceView.Renderer class so from the onDrawFrame you make all the OpenGL API calls to setup the GL environment and draw the 3d object.

  2. Load your model data (vertices, normals, faces, etc) into ByteBuffer's, so you can use them later in the OpenGL API calls.

  3. You may need to calculate a Transformation Matrix if you want to rotate, move or scale your object into your 3d world (Matrix.rotateM)

  4. Calculate the View Matrix so you can render the 3d object from any point of view (Matrix.setLookAtM).

  5. You may also need to render the object with some perspective (Matrix.frustumM) so it looks more realistic.

  6. Once the MVP Matrix (Model-View-Matrix) is ready, then you can initialize the OpenGL options like Viewport and back color for example.

  7. Create a new OpenGL program compiled with a Vertex and a Fragment Shader that will execute on the GPU to process and render your object (this step is executed only once).

  8. Configure the OpenGL program previously created (glUseProgram) and configure the input attributes (glEnableVertexAttribArray) so you can push the model's data like the vertices to be drawn.

  9. Finally, draw the object by drawing all the triangles or elements (points, lines) that makes all of the object (glDrawElements or glDrawArrays).

You may also want to check this github repository android-3D-model-viewer that implements all of this into an open source demo, published in the play store as well, that can render 3d wavefront *.obj files.

like image 154
Andrés Oviedo Avatar answered Mar 31 '23 17:03

Andrés Oviedo