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: 637
  • Sample3 Pacman.zip
    10.8 KB · Views: 631
  • Jsample1.zip
    95.6 KB · Views: 590
  • sample1.zip
    81.6 KB · Views: 623
  • iSample1.zip
    351.4 KB · Views: 533
  • SD_XUI_View3D 0.28.zip
    21.9 KB · Views: 210
  • jSD_XUI_View3D 0.28.zip
    21.9 KB · Views: 203
  • iSD_XUI_View3D 0.28.zip
    156.3 KB · Views: 186
Last edited:

MrYang

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

Star-Dust

Expert
Licensed User
Longtime User
Great job!I like it,and I am learning how to show 3D objects with LibGDX。
This library does not use OpenGL or GDX, because it was born as an XUI library and could also work for B4i and B4j. Obviously it would be much faster with OpenGL or GDX

Like all my libreries, it has been created entirely with B4X, I do not use Java or C
 
Last edited:

Star-Dust

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

Star-Dust

Expert
Licensed User
Longtime User
Update rel. 0.24

Update Library (method) and Sample
 

Erel

B4X founder
Staff member
Licensed User
Longtime 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.
 

Johan Schoeman

Expert
Licensed User
Longtime User
The compilation error is not related to the largeHeap attribute.


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.
Fixed! Removed my previous posts so that it does not clutter the thread of this great project.

1.png
 
Last edited:

Star-Dust

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

Star-Dust

Expert
Licensed User
Longtime User
Update Demo Library
 

alienhunter

Active Member
Licensed User
Longtime 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
Longtime 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
Longtime 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
Longtime 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:

Star-Dust

Expert
Licensed User
Longtime User
After a long and troubled reflection that has lasted for months now, I decided to release the complete library in B4XLib format (see post #1). This will improve performance.

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.
 
Last edited:

hicaltech87

Member
halo sir, i try to use your lib, to make learning media app in physical education. i create walking animation with obj format so there are so many obj file. Any advice to make list of obj to load all obj file and become serial animation from obj file 1 to end?
 

Star-Dust

Expert
Licensed User
Longtime User
halo sir, i try to use your lib, to make learning media app in physical education. i create walking animation with obj format so there are so many obj file. Any advice to make list of obj to load all obj file and become serial animation from obj file 1 to end?
For an animation I don't know if this library is a right choice. On the blog it would work fine but on mobile devices you have to be sure they have high performance.

Finally file is not a frame? how long should the frame remain before moving on to the next one?
 
Top