Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this questionKindly give me the way to create a 3D object in android application
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:
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.
Load your model data (vertices, normals, faces, etc) into ByteBuffer's, so you can use them later in the OpenGL API calls.
You may need to calculate a Transformation Matrix if you want to rotate, move or scale your object into your 3d world (Matrix.rotateM)
Calculate the View Matrix so you can render the 3d object from any point of view (Matrix.setLookAtM).
You may also need to render the object with some perspective (Matrix.frustumM) so it looks more realistic.
Once the MVP Matrix (Model-View-Matrix) is ready, then you can initialize the OpenGL options like Viewport and back color for example.
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).
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.
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.
The Android SDK has a OpenGL API :)
3D with OpenGL
Beyond the Android SDK there are many third party 3D engines which can make creating 3D graphics much easier. The one I used to create a simple 3D game with some imported mesh files was JPCT-AE:
http://www.jpct.net/jpct-ae/
The support forum is excellent and the developer himself usually responds on the forum within 1-2 days. JPCT is game-centric in its design, so there may be better ones out there for pure 3D graphics. There are several tutorials with example code to get you started.
精彩评论