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: 452
  • ThreeD.zip
    29.4 KB · Views: 432
Last edited:

MarkusR

Well-Known Member
Licensed User
Longtime User
Hi Markus ,
should this code not draw a triangle , instead of a line ?

hi,
its because the draw mode, i had add for you
Surface1.SetTypeLineStrip
Surface1.SetTypeLineLoop

typical line mode is from to from to from to

see gl constants
GL_LINES
GL_LINE_STRIP
GL_LINE_LOOP
 

alienhunter

Active Member
Licensed User
Longtime User
hi,
its because the draw mode, i had add for you
Surface1.SetTypeLineStrip
Surface1.SetTypeLineLoop

typical line mode is from to from to from to

see gl constants
GL_LINES
GL_LINE_STRIP
GL_LINE_LOOP

Markus ,
that is awesome , thank you very much
triangle.PNG

how would you draw a shaded disk like that , or anything round
i assume only with SetTypeLineLoop
i could not find anything else


Capture.PNG


:) also please if you have time
can we have
cullface
 

MarkusR

Well-Known Member
Licensed User
Longtime User
Markus ,that is awesome , thank you very much
how would you draw a shaded disk like that , or anything round
i assume only with SetTypeLineLoop
i could not find anything else

:) also please if you have time can we have cullface

i think i would make a circle in 360°/10 = 36 steps, looks almost round.

i gave you a flag Three.CullBackFace = True
off (default) looks better for transparent objects

here are some supported drawmodes from open gl es explained with pictures in the pc version.
most of the open gl commands did not exists in open gl es.
https://wiki.delphigl.com/index.php/glBegin
 

alienhunter

Active Member
Licensed User
Longtime User
Markus
thank you very much
and thanks for the link

this is powerful Markus , good job

:eek: holy
your lib
~9000 triangles 1.25 MB Ascii Format on a Emulator
Capture.PNG
$80k CAD/CAM software
Capture1.PNG

~53000 Triangles 9.9 Mb Ascii
Capture.PNG
Capture1.PNG

AH
 
Last edited:

alienhunter

Active Member
Licensed User
Longtime User
Hi Markus

:) can we have this if possible , rotate/scale/Translate , with not rebuilding the scene ?
or i am missing something
thanks again for your lib
 

MarkusR

Well-Known Member
Licensed User
Longtime User
Hi Markus

:) can we have this if possible , rotate/scale/Translate , with not rebuilding the scene ?
or i am missing something
thanks again for your lib

each entity (basis class) have a Position & Rotate vector, its used every frame draw in real time. u can just change the values.
i had add scale there for you.
 

alienhunter

Active Member
Licensed User
Longtime User
Markus ,
thank you for your support , I think that is all what i needed for now
i will start building my stuff and let you know on this thread.

Just in case if there a Tochevent in Opengl ES, like selecting the item ?

Thank you /Vielen Dank fuer deine Hilfe
Gruss
AH
 

MarkusR

Well-Known Member
Licensed User
Longtime User
Markus ,
thank you for your support , I think that is all what i needed for now
i will start building my stuff and let you know on this thread.
Just in case if there a Tochevent in Opengl ES, like selecting the item ?
Thank you /Vielen Dank fuer deine Hilfe
Gruss
AH

not that i know, let me know if you need something ..
 

alienhunter

Active Member
Licensed User
Longtime User
Hi
Just wanted to share with you my APP with your library
it is in very early stages but this is my first CNC code produced , so hurray .. :)
icons and other will be better , they are just copies from a other CAM system

cnc001.PNG

thank you again for your time and help
i will keep you posted
AH
 

alienhunter

Active Member
Licensed User
Longtime User
nice, it seems you put a lot of work in this cnc tool.

Yes Sir
now i try to develop simple cutting algorithms ... for now
drive the tool in X Y on 45 degrees and so on
it will look something like this ... just a sample ... not correct yet
Capture.PNG
 

Attachments

  • Capture.PNG
    Capture.PNG
    10 KB · Views: 220
Last edited:

Adamdam

Active Member
Licensed User
Longtime User
Hi, sir

Can I add click position ? or
I need to get which object I clicked ?

Best regards
 

Adamdam

Active Member
Licensed User
Longtime User
Dear Eng. Markus
Greetings,
Is the library any way to find "what object that I catch/clicked on the view" ??
Or " find the location of click/double-click say in the view (3D position) " ??
Best regards
 

Adamdam

Active Member
Licensed User
Longtime User
Dear Eng. Markus
Greetings,
Is the library any way to find "what object that I catch/clicked on the view" ??
Or " find the location of click/double-click say in the view (3D position) " ??
Best regards
hello,
i publish a 3D library to using at a b4a project (android 5.x+ phone or tablet)

View attachment 66700 View attachment 66692 View attachment 66693

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
 

MarkusR

Well-Known Member
Licensed User
Longtime User
Dear Eng. Markus
Greetings,
Is the library any way to find "what object that I catch/clicked on the view" ??
Or " find the location of click/double-click say in the view (3D position) " ??
Best regards
sorry, it is not implemented. for my need i used a object listbox to select a 3d object.
 
Top