B4A Library [BAX] [XUI] SD XUI_View3D (Demo)

Star-Dust

Expert
Licensed User
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

This is a demo version that lasts only a month, I'm releasing it to show the potential of the library. It is still under development, so methods can be subject to change. If you want the full version, make a donation of € 20 for the library (specifying which library you ask) or contact me in private if you want to buy the source

You can find a detailed description of the methods and algorithms used in this thread.

You can find be the version for B4A, B4j,B4i attached . I will not produce a version for B4R. Required XUI 1.72+

SD_XUI_View3D_DEMO

Author: Star-Dust
Version: 0.25
  • Object3D
    • Fields:
      • DrawTime As Int ' statics
      • ListVerticesOnScreen As List ' reserved
      • LoadTime As Int ' statics
      • RotateTime As Int ' statics
      • SortTime As Int ' statics
    • 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 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 (ID 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 max 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
      • getListObject As List
        return List of Type_Polygon
      • getListObjectFromID (IDList As List) As List
        return List of Type_Polygon with specific ID
      • getObj3DCount As Int
        Count of Object
      • 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

Last edited:

MrYang

New Member
Licensed User
Great job!I like it,and I am learning how to show 3D objects with LibGDX。
 

Star-Dust

Expert
Licensed User
This code displays the rotation of objects/polygons on a panel but does not modify the original objects.
B4X:
P3D.Rotate(Null,X,Y,Z).RenderToView(Panel,centerX,centerY,Zoom,ModeDraw)

This code makes the rotations definitive and then represent them in the panel
B4X:
P3D=P3D.Rotate(Null,X,Y,Z)
P3D.RenderToView(Panel,centerX,centerY,Zoom,ModeDraw)
 
Last edited:

Star-Dust

Expert
Licensed User
I am trying to run your project but getting the following error when compiling the B4A code:
B4X:
B4A Version: 8.30
Parsing code.    (0.03s)
Compiling code.    (0.11s)
Compiling layouts code.    (0.01s)
Organizing libraries.    (0.00s)
Generating R file.    (0.07s)
Compiling generated Java code.    Error
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Error occurred during initialization of VM
Could not reserve enough space for object heap
Default for MaxRamForDex=1536 in b4xV5.ini. Have set it to various bigger values but the error persists (2048, 4096, 8192). How do I solve this?
Manifest is as per your sample project. Using it on a Samsung G950F with Android 8.0.0

Thanks

JS
There is no obligation to set up the Manifest with LargHeap, it's just a suggestion. Try to remove it.
It does not use Java or particular libraries, only XUI and BitmapCreator.


It is the first time that presents this problem, it has been tested by several collaborators without any problem. And frankly I do not know what it could be, I'll ask @Erel
 

Erel

Administrator
Staff member
Licensed User
The compilation error is not related to the largeHeap attribute.

Default for MaxRamForDex=1536 in b4xV5.ini. Have set it to various bigger values but the error persists (2048, 4096, 8192). How do I solve this?
Have you changed it while the IDE is closed?

If you are unable to solve it then it is better to start a new thread as it is probably not related to this library.
 

Star-Dust

Expert
Licensed User
I added in the first post also a version of the library for B4J and an example.
It still has some flaws in B4J, which are resolved in the next version not yet released.

It seems that B4XCanvas B4J does not draw lines if they are only 2 points, they should be at least 3 and different from each other. I solved using DrawLine if the points are less than three.

The version for B4I is under construction (see here).

Update: FIX BUGS in Java Library
 
Last edited:

Star-Dust

Expert
Licensed User
Update rel 0.25

released the version for B4i at the first post and updated the library for the latest version of BitmapCreator
 

Star-Dust

Expert
Licensed User
A few explanations:

Add: All methods starting with Add are used to add individual polygons and / or objects that are composed of multiple polygons.
Each polygon can be identified by an ID that must be inserted in the chosen Add method.
the ID is not unique, but more polygons can have the same ID. In this case, if you require the movement, rotation or color change and coordinate of an ID, all the polygons that have that ID will receive the requested change.

Rotate: Used to rotate polygons. If you enter null in the List Polygons field, it will rotate all the polygons present.
Rotate2: Same mwethod Rotate. But use a different mathematical formula for polygon rotation
MoveObj: Moves the polygons shown in the list (null for all polygons) making them slide on the axes.


PointClick: Checks whether the point on the screen corresponds to a polygon and returns its ID.
setColor: To change color to one the most polygons. Indicate the ID value
setVertices: To change the coordinates to one the most polygons. Indicate the ID value

LoadObjFile: Load an object saved in the obj format.
LoadObject3D: Load the saved objects in a proprietary format
SaveObject3D: Save the saved objects in a proprietary format

RenderToView: Used to display polygons on a panel.
It will be necessary to establish which coordinates (x, y) of the panel will serve as the zero point of the axes (usually the center of the panel), the Zoom value (Default = 1) and the Drawing Mode.
The drawing modes are 7.
0 - Transparency (to examine objects in transparency)
1 - Canvas without light effect
2 - Bitmapcreator without light effect
3 - Canvas with light effect
4 - Bitmapcreator with light effectù
10 - Automatic without light effect (Canvas up to 20,000 polygons, upper use BC)
20 - Automatic with light effect (Canvas up to 20 thousand polygons, upper use BC)


Variable for statistical purposes only
  • DrawTime
  • LoadTime
  • RotateTime
  • SortTime
 
Last edited:

alienhunter

Active Member
Licensed User
Hi
i try to view a stl file but it does not work
with this stl format which is a cad exchange format

B4X:
  facet normal  6.324  2.937  0.780
    outer loop
      vertex 1084.003 -1191.998 367.245
      vertex 1083.921 -1190.813 363.450
      vertex 1083.345 -1192.003 372.598
    endloop
  endfacet
 

Star-Dust

Expert
Licensed User
I'm sorry but the stl format has not been thoroughly tested. Try inserting the lines described by the vertices with AddPolygon

I do not expect further updates that best the function that loads STL files. At the moment the project is suspended because he did not have enough auction interest to support the project's maintenance
 
Last edited:

alienhunter

Active Member
Licensed User
I'm sorry but the stl format has not been thoroughly tested. Try inserting the lines described by the vertices with AddPolygon

I do not expect further updates that best the function that loads STL files. At the moment the project is suspended because he did not have enough auction interest to support the project's maintenance
Hi
thank you
You do not have to be sorry , you did a great job there :)
AH
 

Star-Dust

Expert
Licensed User
It was a project I fell in love with, but it was unrequited love.
And all done in B4X, it's not a wrapping.

It took a long time and a careful analysis. On the other hand, in order to continue the project, due to the many resources and time it required, it was necessary to distribute it for a fee, but it was not a success.

Also because there are not many applications in which to use it in its current form. In the future it could become a library to create 3D introduction or 3D views and an game engine .. but at the moment it is not yet mature
 
Last edited:
Top