B4A Library ThreeD library (alpha 0.04)

hello,
i publish a 3D library to using at a b4a project (android 5.x+ phone or tablet)

Screenshot_20180415-174124.png Screenshot_20180415-161230.png Screenshot_20180415-161241.png

currently it knows:
Camera
Light
Cube
Vector,Color,Texture
Entity,Mesh,Surface,Vertex
Line (at Surface)

01.02.2019 21:00
OpenGL.zip is my test project.

03.02.2019 19:00
ThreeD.zip is the lib to place unzipped in additional libraries folder.

base of the ThreeD library is a Project in Android Studio 3.3
(which was compiled with SimpleLibraryCompiler)

to do:
line order in grid because lighting
(anytime switch to GLES 3.0 or 3.1 but it is completely different)

note: my android emulator does not show alpha blending!

ThreeD

Author: Markus Rauch
Version: 0.04

    • Functions:
      • clone As Object
      • compareTo (arg0 As E) As Int
      • equals (arg0 As Object) As Boolean
      • finalize
      • hashCode As Int
      • name As String
      • ordinal As Int
      • toString As String
      • valueOf (name As String) As com.rauch.threedimensional.Surface.ETyp
      • values As com.rauch.threedimensional.Surface.ETyp()
    • Properties:
      • DeclaringClass As Class [read only]
  • Camera
    • Fields:
      • ID As String
      • Position As Vector
      • PositionLookAt As Vector
      • Rotate As Vector
      • Scale As Vector
    • Functions:
      • AddMesh (m As Mesh)
      • ClearMeshes
      • ListMeshes As java.util.List
  • Color
    • Fields:
      • Alpha As Float
      • Blue As Float
      • Green As Float
      • Red As Float
    • Functions:
      • Set (Red As Float, Green As Float, Blue As Float, Alpha As Float)
        set the color red,green,blue,alpha
        all r g b a values from 0.0 to 1.0
        Red: 0.0 to 1.0
        Green: 0.0 to 1.0
        Blue: 0.0 to 1.0
        Alpha: 0.0 to 1.0 (1.0 = visible)
  • Cube
    • Fields:
      • ID As String
      • Position As Vector
      • Rotate As Vector
      • Scale As Vector
    • Functions:
      • AddMesh (m As Mesh)
      • ClearMeshes
      • ListMeshes As java.util.List
      • Set (Position As Vector, Length As Float, Width As Float, Height As Float, Color1 As Color)
        create a cube
        Position:
        Length:
        Width:
        Height:
        Color1:
      • SetColor (Red As Float, Green As Float, Blue As Float, Alpha As Float)
        colorize the cube
        (a cube with texture should be white)
        Red:
        Green:
        Blue:
        Alpha:
      • SetColorFaces (Color1 As Color, Color2 As Color, Color3 As Color, Color4 As Color, Color5 As Color, Color6 As Color)
        colorize each face of the cube
        Color1:
        Color2:
        Color3:
        Color4:
        Color5:
        Color6:
      • SetTexture (Bitmap1 As android.graphics.Bitmap)
        give the cube an bitmap/texture for all faces
        Example:<code>Dim bmp As Bitmap = LoadBitmap(File.DirAssets,"wood.png")
        Cube1.SetTexture(bmp)</code>
        Bitmap1:
  • Entity
    • Fields:
      • ID As String
      • Position As Vector
      • Rotate As Vector
      • Scale As Vector
    • Functions:
      • AddMesh (m As Mesh)
      • ClearMeshes
      • ListMeshes As java.util.List
  • Light
    • Fields:
      • ID As String
      • Position As Vector
      • PositionLookAt As Vector
      • Rotate As Vector
      • Scale As Vector
    • Functions:
      • AddMesh (m As Mesh)
      • ClearMeshes
      • ListMeshes As java.util.List
      • SetPosition (Position As Vector)
      • SetPositionLookAt (PositionLookAt As Vector)
  • Line
    • Fields:
      • Color1 As Color
      • ID As String
      • Position As Vector
      • Rotate As Vector
      • Scale As Vector
    • Functions:
      • AddMesh (m As Mesh)
      • ClearMeshes
      • GetP1 As Vector
      • GetP2 As Vector
      • ListMeshes As java.util.List
      • Set (P1 As Vector, P2 As Vector)
      • SetColor (Red As Float, Green As Float, Blue As Float, Alpha As Float)
      • SetColorObj (Color1 As Color)
      • SetP1 (X As Float, Y As Float, Z As Float)
      • SetP12 (X1 As Float, Y1 As Float, Z1 As Float, X2 As Float, Y2 As Float, Z2 As Float)
      • SetP2 (X As Float, Y As Float, Z As Float)
  • Mesh
    • Fields:
      • ID As String
      • Position As Vector
      • Rotate As Vector
      • Scale As Vector
    • Functions:
      • AddMesh (m As Mesh)
      • AddSurface (s As Surface)
      • ClearMeshes
      • ClearSurfaces
      • ListMeshes As java.util.List
      • ListSurfaces As java.util.List
  • Surface
    • Fields:
      • Color1 As Color
    • Functions:
      • AddLine (v1 As Vertex, v2 As Vertex)
      • AddQuad (v1 As Vertex, v2 As Vertex, v3 As Vertex, v4 As Vertex)
        (GL_TRIANGLE_STRIP)
        v1:
        v2:
        v3:
        v4:
      • AddTriangle (v1 As Vertex, v2 As Vertex, v3 As Vertex)
      • AddVertex (v As Vertex)
      • ClearVertices
      • ListVertices As java.util.List
      • SetColor (Red As Float, Green As Float, Blue As Float, Alpha As Float)
        colorize the surface
        (a surface with texture should be white)
        Red: 0 to 1
        Green: 0 to 1
        Blue: 0 to 1
        Alpha: 0 to 1 (1 visible)
      • SetTexture (Bitmap1 As android.graphics.Bitmap)
        give the surface an bitmap/texture
        Example:<code>Dim bmp As Bitmap = LoadBitmap(File.DirAssets,"wood.png")
        Surface1.SetTexture(bmp)</code>
        Bitmap1:
      • SetType (Type As com.rauch.threedimensional.Surface.ETyp)
        set the surface typ LINES,TRIANGLES,TRIANGLE_STRIP (default is TRIANGLES)
        Type:
      • SetTypeLineLoop
      • SetTypeLines
      • SetTypeLineStrip
      • SetTypeTriangles
      • SetTypeTriangleStrip
  • ThreeDimensional
    • Fields:
      • CameraFar As Float
      • CameraFieldOfViewY As Float
      • CameraNear As Float
      • CullBackFace As Boolean
      • LineWidth As Float
    • Functions:
      • AddCube (Cube1 As Cube)
        use AddEntity
      • AddCube2 (x As Float, y As Float, z As Float, l As Float, w As Float, h As Float, r As Float, g As Float, b As Float, a As Float)
        use AddEntity
      • AddEntity (Entity1 As Entity)
        add a entity to your scene camera,light,cube,line,...
        (use in pause mode)
      • CreateCubeWireframe (Position As Vector, Length As Float, Height As Float, Width As Float, Color1 As Color) As Entity
        create a cube with lines
        Position: X,Y,Z
        Length: (X)
        Height: (Y)
        Width: (Z)
        Color1: Object
        Return type: @return:new Entity
      • CreateEntityAxis (Position As Vector, Length As Float, ColorX As Color, ColorY As Color, ColorZ As Color) As Entity
        create a 3d axis Entity with lines
        use returned Entity at AddEntity to add it into scene object list
        Position:
        Length:
        ColorX:
        ColorY:
        ColorZ:
        Return type: @return:new Entity
      • CreateEntityGridXZ (Size As Float, Step As Float, Color1 As Color) As Entity
        create a ground grid entity step ? unit
        use at AddEntity
        Size: X and Z = -Size to Size Step ?
        Step: Gap
        Color1:
        Return type: @return:new Entity
      • Init (Activity1 As Activity) As View
        define the 3d class and add the surface view to a activity
        also add pause and resume
        in pause mode or before it run you can set your scene
        Example:<code>
        Sub Process_Globals
        Dim Three As ThreeDimensional
        Sub Activity_Create(FirstTime As Boolean)
        Activity.AddView( Three.Init(GetActivity),0%x,0%y,100%x,100%y)
        Sub Activity_Resume
        Three.Resume
        Sub Activity_Pause(UserClosed As Boolean)
        Three.Pause
        Sub GetActivity As Object
        Dim R As Reflector
        Return R.GetActivity
        End Sub</code>
        Activity1:
        Return type: @return:View
      • Lerp (a As Float, b As Float, t As Float) As Float
        lerp interpolates from one value (a) to another (b) over a given range (t)
        a:
        b:
        t: is clamped between 0 and 1
        Return type: @return:
      • mm_to_m (mm As Float) As Float
        millimeter to meter
        mm:
        Return type: @return:m
      • Pause
        pause the renderer
      • Resume
        resume the renderer
      • Scene1
        test scene 1
      • Scene1New
        test scene 1 new
      • SceneDefault (camx As Float, camy As Float, camz As Float, centerx As Float, centery As Float, centerz As Float)
        scene with camera and light
        camera position and look at center point
        camx:
        camy:
        camz:
        centerx:
        centery:
        centerz:
      • SceneEmpty
        clear the scene list
        (use in pause mode)
      • SearchEntity (ID As String) As Object
        search in scene object list by id
        ID:
        Return type: @return:Entity Object
  • Vector
    • Fields:
      • X As Float
      • Y As Float
      • Z As Float
    • Functions:
      • Add (V As Vector)
        Add a Vector to it
        V:
      • Direction (A As Vector, B As Vector) As Vector
        static function return a normalized direction vector from 2 positions
        A:
        B:
        Return type: @return:direction Vector
      • Set (X As Float, Y As Float, Z As Float)
        set the vector x,y,z
        X:
        Y:
        Z:
  • Vertex
    • Fields:
      • Normal As Vector
      • Position As Vector
      • TextureUVW As Vector
 

Attachments

  • OpenGL.zip
    319.4 KB · Views: 443
  • ThreeD.zip
    29.4 KB · Views: 419
Last edited:

MarkusR

Well-Known Member
Licensed User
Longtime User
some background knowledge:

https://developer.android.com/guide/topics/graphics/opengl.html

OpenGL ES 1.0 and 1.1 - This API specification is supported by Android 1.0 and higher.
OpenGL ES 2.0 - This API specification is supported by Android 2.2 (API level 8) and higher.
OpenGL ES 3.0 - This API specification is supported by Android 4.3 (API level 18) and higher.
OpenGL ES 3.1 - This API specification is supported by Android 5.0 (API level 21) and higher.

OpenGL ES 3.0/3.1 API Packages
android.opengl - This package provides the interface to the OpenGL ES 3.0/3.1 classes.
Version 3.0 is available starting with Android 4.3 (API level 18).
Version 3.1 is available starting with Android 5.0 (API level 21).
GLES30
GLES31
GLES31Ext (Android Extension Pack)

https://www.khronos.org/registry/OpenGL-Refpages/es3.1/

Learn how to develop mobile graphics using OpenGL ES 2
http://www.learnopengles.com/android-lesson-one-getting-started/
 

MarkusR

Well-Known Member
Licensed User
Longtime User
container packing planning visually business application at phone/tablet using device orientation to look easy from top or bottom. (wip)
Screenshot_2018-04-24-17-11-14.png Screenshot_2018-04-24-17-11-28.png Screenshot_2018-04-24-17-11-53.png
 

alienhunter

Active Member
Licensed User
Longtime User
Thanks
i mean just a line without any surface in space (einfache 3D linie im Raum )
gruss Alfred/AH
 

MarkusR

Well-Known Member
Licensed User
Longtime User
Thanks
i mean just a line without any surface in space (einfache 3D linie im Raum )
gruss Alfred/AH
i made a note, i will try later this week
 

alienhunter

Active Member
Licensed User
Longtime User
thank you very much :)
now i am pushing it , after i made some test this lib is working great , can we have basic objects , like sphere ,cylinder anything
that you might want to give us and you have time
thanks again AH
 

MarkusR

Well-Known Member
Licensed User
Longtime User
as i remember geometric shapes are not part of this used gl es version but can be done
with triangles. gl es is very different in compare with gl for pc.
 

alienhunter

Active Member
Licensed User
Longtime User
Thank you Markus ,
here i have my line in space, you have this in your
code

Capture1.PNG Capture.PNG


B4X:
Dim Entity1 As Entity
    Dim Mesh1 As Mesh
    Entity1.AddMesh(Mesh1)

    Dim Surface1 As Surface
    Surface1.SetTypeLines
    Surface1.Color1.Set(1,0,0,1)
    Mesh1.AddSurface(Surface1)
       
    Dim Vertex1 As Vertex
    Vertex1.Position.Set(-10,5,0)
    Dim Vertex2 As Vertex
    Vertex2.Position.Set( 10,10,10)
    Surface1.AddLine(Vertex1,Vertex2)
    Three.AddEntity(Entity1)

just have to get used to XYZ is different to what i am doing the whole day in the real CAD world ;)

AH
 

MarkusR

Well-Known Member
Licensed User
Longtime User
just have to get used to XYZ is different to what i am doing the whole day in the real CAD world ;)
yes, there is no norm about the axis name and sign.
typically -x left to x right y top to -y bottom z front to -z back
 

agraham

Expert
Licensed User
Longtime User
A little bug? If you add that line code to the end of MyScene in your OpenGL example the line looks black until you rotate the scene with the bottom slider when it turns red for 180 degrees then turns black for the other 180 degrees even though the light source is co-located with the camera.
 

MarkusR

Well-Known Member
Licensed User
Longtime User
A little bug? If you add that line code to the end of MyScene in your OpenGL example the line looks black until you rotate the scene with the bottom slider when it turns red for 180 degrees then turns black for the other 180 degrees even though the light source is co-located with the camera.
thanks Andrew, i updated this lib,
i disabled the light because the line did not really have a surface normal.
(i tested it with a up vector as normal but this looked wrong in lightning.)
 

alienhunter

Active Member
Licensed User
Longtime User
i updated this ThreeD lib , it have now a Line Entity
B4X:
Dim Line1 As Line
Line1.SetColor(1,0,0,1)
Line1.SetP12(-10,2,0,10,2,0)
Three.AddEntity(Line1)

Thank you very much
(vielen Dank und Gruss aus Canada)
Alfred/AH
 
Last edited:

alienhunter

Active Member
Licensed User
Longtime User
Markus
this is powerful stuff , this is real life cnc-code with lines ;) thank you again

Capture.PNG

how would i control the clipping with large models when i zoom out
Capture1.PNG
 

MarkusR

Well-Known Member
Licensed User
Longtime User

alienhunter

Active Member
Licensed User
Longtime User
Hi Markus ,

should this code not draw a triangle , instead of a line ?
https://developer.android.com/guide/topics/graphics/opengl#java


B4X:
Dim Entity1 As Entity
    Dim Mesh1 As Mesh
    Entity1.AddMesh(Mesh1)
    
    Dim Surface1 As Surface
    Surface1.SetTypeLines
    Surface1.Color1.Set(1,0,0,1)
    Dim vert1,vert2,vert3 As Vertex
    vert1.Position.Set(1,1,1)
    vert2.Position.Set(2,2,2)
    vert3.Position.Set(3,3,3)
    
    Surface1.AddTriangle(vert1,vert2,vert3)
    Mesh1.AddSurface(Surface1)
    Three.AddEntity(Entity1)

thanks AH
 
Top