B4A Library [BAX] [XUI] SD XUI_View3D

I created a library to display polygons in 3D. It is also possible to use it to create 3D XUI views.
This library can be used to create 3D models from code or load them from obj files.
To create a 2D drawing app, to create games, animations, introductions, and 3D effects
You can find a detailed description of the methods and algorithms used in this thread.

At the same time I do not authorize to open or decompile in order to obtain the original source. I do not authorize any changes to the source.
You can use the library in your applications, including commercial ones, by inserting the author's acknowledgment of this library.


The examples must be updated to select the complete version of the library (no longer SD_XUIView3D_DEMO but SD_XUIView3D)
If you want you can make a donation for this library, I would be grateful.


SD_XUI_View3D

Author:
Star-Dust
Version: 0.26
  • Object3D
    • Fields:
      • DrawTime As Int
      • light_intensity As Int
      • ListVerticesOnScreen As List
      • LoadTime As Int
      • RotateTime As Int
      • SortTime As Int
    • Functions:
      • AddArcX (ID As Int, StartDegree As Int, EndDegree As Int, X As Float, Y As Float, Z As Float, R As Int, BorderColor As Int, FillColor As Int) As Object3D
        Add Arc or Circle (StartDegree=0, EndDegree=360) - round X axis
      • AddArcY (ID As Int, StartDegree As Int, EndDegree As Int, X As Float, Y As Float, Z As Float, R As Int, BorderColor As Int, FillColor As Int) As Object3D
        Add Arc or Circle (StartDegree=0, EndDegree=360) - round Y axis
      • AddArcZ (ID As Int, StartDegree As Int, EndDegree As Int, X As Float, Y As Float, Z As Float, R As Int, BorderColor As Int, FillColor As Int) As Object3D
        Add Arc or Circle (StartDegree=0, EndDegree=360) - round Z axis
      • AddBitmapCreator (ID As Int, Bmc As b4a.example.bitmapcreator, P_TopLeft As Point3D_Type, P_TopRight As Point3D_Type, P_DownLeft As Point3D_Type, P_DownRight As Point3D_Type) As Object3D
      • AddCube (ID As Int, X1 As Float, Y1 As Float, Z1 As Float, X2 As Float, Y2 As Float, Z2 As Float, BorderColor As Int, FillColor As Int()) As Object3D
        Create Cube - Add 6 Polygon - Set Array as Color (min 1, max 6 Color)
        AddCube(121,10,10,10,-10,-10,-10,xui.Color_Black,array as int(xui.Color_White))
        AddCube(121,10,10,10,-10,-10,-10,xui.Color_Black,array as int(xui.Color_White,xui.Color_Black))
      • AddImage (ID As Int, Image As B4XBitmap, P_TopLeft As Point3D_Type, P_TopRight As Point3D_Type, P_DownLeft As Point3D_Type, P_DownRight As Point3D_Type) As Object3D
        Add Image - Set Coordinate
      • AddObj3D (Obj3d As Type_Polygon) As String
        For internal use
      • AddPolygon (ID As Int, PointList As Point3D_Type(), BorderColor As Int, FillColor As Int) As Object3D
        Add Polygon, trace path
      • AddRec (ID As Int, X1 As Float, Y1 As Float, Z1 As Float, X2 As Float, Y2 As Float, Z2 As Float, BorderColor As Int, FillColor As Int) As Object3D
        Add rectangle, Set TopLeft and DownRight
      • AddSpere (ID_Start As Int, X As Float, Y As Float, Z As Float, R As Int, BorderColor As Int, FillColor As Int) As Object3D
        Create Sphere - Add 300 Polygon
      • AddSpere2 (IDStart As Int, X As Float, Y As Float, Z As Float, R As Int, BorderColor As Int, FillColor As Int, StartLatitude As Int, StopLatitude As Int, StartLongitude As Int, StopLongitude As Int, OrizontalStep As Int, VerticalStep As Int) As Object3D
        Create Sphere - Add 300 Polygon
        Latitude : 0-360
        Longitude: 0-180
      • Class_Globals As String
      • Clear As String
        Clear all Object
      • CtP (X As Float, Y As Float, Z As Float) As Point3D_Type
        Coordinate To Point
      • CutObj (IDlist As List) As Object3D
        Erase Object List, and returns a new list. If the ID list is empty, it does not perform any operation
      • Initialize As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • LoadObiectj3D (Path As String, FileName As String) As Boolean
        e.g. LoadObiectj3D(File.DirInternal,"object.ddd")
      • LoadObjFile (ID As Int, Path As String, filename As String, BorderColor As Int, FillColor As Int, LimitsPolygon As Int) As String
        LimitsPolygon Set 0 to no-limit
      • LoadStlFile (ID As Int, Path As String, filename As String, BorderColor As Int, FillColor As Int, RatioOfSize As Float) As String
      • MoveObj (IDlist As List, X As Int, Y As Int, Z As Int) As Object3D
        Move Object List, set IDList to null for rotate all Polygon
      • PointClick (x As Int, y As Int, Advise As Boolean) As Int
        Vwerify if point is internal of any Polygon/object - Response -1 if is external
      • RenderToView (V As B4XView, CenterX As Int, CenterY As Int, ZoomValue As Float, DrawMode As Int) As String
        Select the most suitable method for the draw based on the number of polygons contained
        DrawMode 0-Traslucent
        1-Canvas without depth color 2-BitmapCreator without depth color 10-Automatic (Canvas if less 20mil polygon)
        3-Canvas with depth color 4-BitmapCreator with depth color 20-Automatic (Canvas if less 20mil polygon)
      • Rotate (IDList As List, DegreeX As Int, DegreeY As Int, DegreeZ As Int) As Object3D
      • Rotate2 (IDList As List, DegreeX As Int, DegreeY As Int, DegreeZ As Int) As Object3D
        Rotate Polygon List, Set IDList to null for rotate all Polygon (Alternative formulas)
      • RotateX (IDList As List, Degree As Int) As Object3D
      • RotateY (IDList As List, Degree As Int) As Object3D
      • RotateZ (IDList As List, Degree As Int) As Object3D
      • SaveObiectj3D (Path As String, FileName As String) As Boolean
        e.g. SaveObiectj3D(File.DirInternal,"object.ddd")
      • setColor (IDList As List, BorderColor As Int, FillColor As Int) As Object3D
      • setVertices (OriginalVertices As Point3D_Type, X As Float, Y As Float, Z As Float) As String
        Set New Values of Vertices
    • Properties:
      • ListObject As List [read only]
        return List of Type_Polygon
      • Obj3DCount As Int [read only]
        Count of Object

25.gif
31.gif
33.gif

34.gif
35.gif
38.gif

41.gif
 

Attachments

  • sample2.zip
    9.9 KB · Views: 653
  • Sample3 Pacman.zip
    10.8 KB · Views: 649
  • Jsample1.zip
    95.6 KB · Views: 611
  • sample1.zip
    81.6 KB · Views: 643
  • iSample1.zip
    351.4 KB · Views: 549
  • SD_XUI_View3D 0.28.zip
    21.9 KB · Views: 234
  • jSD_XUI_View3D 0.28.zip
    21.9 KB · Views: 225
  • iSD_XUI_View3D 0.28.zip
    156.3 KB · Views: 201
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
I was asked how to figure out which face of the 3D object was touched with the mouse.

I am attaching a cross-platform B4XPages example which allows you to understand how to do it
 

Attachments

  • View3D_Sample_FaceID.zip
    3.3 KB · Views: 207

PABLO2013

Well-Known Member
Licensed User
Longtime User
greetings thank you.
In my sample I cannot choose the correct face, in a cube if I touch face 1 (it is shown on the screen as the one in front), face 2 is selected. Through the case I selected the correct face, how to improve this, thank you.





B4X:
If Action=1  Then 'Tuoch UP
        Dim Pt As Int = P3D.PointClick(X,Y,True)
    End If

        If Pt>-1 Then
            Dim pnt As Type_Polygon=P3D.ListObject.Get(Pt-1)      
'            ll1t.Text=$"Touch Face ID:${pnt.ID} - N.Vertice: ${pnt.ListVertices.Size}"$
            Log($"Touch Face ID:${pnt.ID} - N.Vertice: ${pnt.ListVertices.Size}"$)
        End If



B4X:
If Action=1  Then 'Tuoch UP
        Dim Pt As Int = P3D.PointClick(X,Y,True)
    End If

    Case 1
           Pt=4
        Case 2
            Pt=1
        Case 3
           Pt=2
        Case 4
           Pt=3  



        If Pt>-1 Then
            Dim pnt As Type_Polygon=P3D.ListObject.Get(Pt-1)      
'            ll1t.Text=$"Touch Face ID:${pnt.ID} - N.Vertice: ${pnt.ListVertices.Size}"$
            Log($"Touch Face ID:${pnt.ID} - N.Vertice: ${pnt.ListVertices.Size}"$)
        End If



Other another thing , how used P3D.setColor
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
greetings thank you.
In my sample I cannot choose the correct face, in a cube if I touch face 1 (it is shown on the screen as the one in front), face 2 is selected. Through the case I selected the correct face, how to improve this, thank you.





B4X:
If Action=1  Then 'Tuoch UP
        Dim Pt As Int = P3D.PointClick(X,Y,True)
    End If

        If Pt>-1 Then
            Dim pnt As Type_Polygon=P3D.ListObject.Get(Pt-1)   
'            ll1t.Text=$"Touch Face ID:${pnt.ID} - N.Vertice: ${pnt.ListVertices.Size}"$
            Log($"Touch Face ID:${pnt.ID} - N.Vertice: ${pnt.ListVertices.Size}"$)
        End If



B4X:
If Action=1  Then 'Tuoch UP
        Dim Pt As Int = P3D.PointClick(X,Y,True)
    End If

    Case 1
           Pt=4
        Case 2
            Pt=1
        Case 3
           Pt=2
        Case 4
           Pt=3



        If Pt>-1 Then
            Dim pnt As Type_Polygon=P3D.ListObject.Get(Pt-1)   
'            ll1t.Text=$"Touch Face ID:${pnt.ID} - N.Vertice: ${pnt.ListVertices.Size}"$
            Log($"Touch Face ID:${pnt.ID} - N.Vertice: ${pnt.ListVertices.Size}"$)
        End If



Other another thing , how used P3D.setColor
Identifying the clicked face is not always easy also due to the perspective, the library has not been developed and updated for years and may have some imperfections.

As for setColor these are the parameters:
B4X:
setColor(IDList As List, BorderColor As Int, FillColor As Int)

An example of use:
B4X:
setColor(array As Int(1), xui.Color_Balck, xui.Color_White)

In the ID field, instead of a single internal number, there is a list so as to allow you to change the color of several groups at the same time
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
IMPORTANT.
I removed the library because someone opened the sources (B4Xlib) without my consent. From now on only an updated compiled version will be available. There will no longer be a B4XLib version available. I reserve the right to publish the next updates in a limited version.

I do not authorize to open or decompile in order to obtain the original source. I do not authorize any changes to the source.
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
A new example with sensor-based 3D motion. The example can be found in the attachment

video_2024-03-19_09-55-18-ezgif.com-optimize.gif


This is an example that I didn't attach.
1-ezgif.com-optimize.gif
 

Attachments

  • 3Dsensor.zip
    9.7 KB · Views: 123
Last edited:
Top