Menu

Addition or Union, Subtraction and intersection bitween tow objects

Help
Mostafa
2018-08-07
2020-11-06
  • Mostafa

    Mostafa - 2018-08-07

    Hi,
    Can I make a new object from Addition or Union, Subtraction and intersection between tow objects in GLScene with new name or one of previous objects name at runtime ? such as 3d studio max or Autocad softwares.
    1-How can I do this?
    2-My objects are of the Basic Geometry, such as a Shpere ,cylinder, cube, and ... . Should objects be of a special type to do this?
    3-Is there any example for this ?

    thank you

     

    Last edit: Mostafa 2018-08-07
  • Jerome.D (BeanzMaster)

    Hi Mostafa,
    Take a look into Samples/Demos/Meshes/CSG
    For CSG operation object must be TGLFreeForm

     

    Last edit: Jerome.D (BeanzMaster) 2018-08-07
  • Mostafa

    Mostafa - 2018-08-07
     

    Last edit: Mostafa 2018-08-07
  • Mostafa

    Mostafa - 2018-08-07

    Thank you jerome

     
  • Mostafa

    Mostafa - 2018-08-18

    Hi Jerome,
    Thank you. I know that you do not have more time for this post and you are busy, but I have a problem and I did not find the answer to what I was looking for. Is the CSG_operation function conditional? I received the following incorrect answers with two spheres and a sphere and one cylinder and a sphere with a cube according to the following codes in feedback example (for change into freeform and then apply CSG_operation). Did I make a mistake? What is the solution to that?

    If you have free time, please answer this question. thanks again

    A-B Operation:

    procedure TForm1.BitBtn3Click(Sender: TObject);
    var
      Mesh : TMeshObject;
    begin
      GLFreeForm3.MeshObjects.Clear;
      GLFreeForm3.StructureChanged;
      GLFreeForm1.Material.PolygonMode := pmFill;
      GLFreeForm2.Material.PolygonMode := pmFill;
    
      if GLFreeForm3.MeshObjects.Count = 0 then
        TMeshObject.CreateOwned(GLFreeForm3.MeshObjects).Mode := momFaceGroups;
    
      Mesh := GLFreeForm3.MeshObjects[0];
    
      CSG_Operation(GLFreeForm1.MeshObjects.Items[0],GLFreeForm2.MeshObjects.Items[0],CSG_Subtraction,Mesh,'1','2');
      GLFreeForm3.StructureChanged;
    
      GLFreeForm1.Material.PolygonMode := pmLines;
      GLFreeForm2.Material.PolygonMode := pmLines;
    
    end;
    

    Results for A-B :

    Intersection Operation :

    procedure TForm1.BitBtn6Click(Sender: TObject);
    var
      Mesh : TMeshObject;
    begin
    
      GLFreeForm3.MeshObjects.Clear;
      GLFreeForm3.StructureChanged;
    
      GLFreeForm1.Material.PolygonMode := pmFill;
      GLFreeForm2.Material.PolygonMode := pmFill;
    
      if GLFreeForm3.MeshObjects.Count = 0 then
        TMeshObject.CreateOwned(GLFreeForm3.MeshObjects).Mode := momFaceGroups;
    
      Mesh := GLFreeForm3.MeshObjects[0];
    
      CSG_Operation(GLFreeForm1.MeshObjects.Items[0],GLFreeForm2.MeshObjects.Items[0],CSG_Intersection,Mesh,'1','2');
      GLFreeForm3.StructureChanged;
    
      GLFreeForm1.Material.PolygonMode := pmLines;
      GLFreeForm2.Material.PolygonMode := pmLines;
    
    end;
    

    Results for Intersection :

     

    Last edit: Mostafa 2018-08-18
  • Paola KS

    Paola KS - 2020-11-04

    Hi, I'm trying to substract an object to another one. I followed the example Samples/Demos/Meshes/CSG. I tried to load my objects in this sample. When I try to substract the objects "stack overflow" error appears . If I try to autocenter in X and Y the 2 objects, this error doesn't appear. Can anyone tell me why?

     
  • Jerome.D (BeanzMaster)

    Hi Paola KS can you attach the 2 meshes for try, i'll make some test next month, after my formation.
    "Stack overflow" suggest the generated mesh with your models have too many faces or vertices. I think is due in the csg operation itself something should be wrong in a loop and produce too many results in faces or vertices

    PS What are you using Delphi or Lazarus ?

    Cheers

     

    Last edit: Jerome.D (BeanzMaster) 2020-11-06
  • Paola KS

    Paola KS - 2020-11-06

    Hi,
    I'm using Delphi.
    In attach there is a copy of your sample (Samples/Demos/Meshes/CSG) that loads my obj (A.obj and B.obj). I need to perform the operation A-B.
    When you click on the button A-B (and also to other kind of operations) you will see the error "stack overflow".
    The error doesn't appear if I try to autocenter in X and Y (not in Z) the GLFreeForm1 and GlFreeForm2 or if I try to scale GLFreeForm1 and GlFreeForm2 of 0,1 in X and Y (not in Z). But I need to perform this operation in the position specified in the obj and with real dimensions.
    Thanks
    Paola

     
  • Jerome.D (BeanzMaster)

    Can you give me the mainformunit.pas and dfm or tell me the parameters of FreeForm1 and 2 and Camera (Position and Scale values)

     

    Last edit: Jerome.D (BeanzMaster) 2020-11-06
  • Jerome.D (BeanzMaster)

    I took a look to your objects i think you must subdivide the objects for having more vertices and faces for computing correctly the CSG operations.

     
  • Paola KS

    Paola KS - 2020-11-06

    I send you in attach the mainformunit.pas and dfm. But, if the problem is due to the number of verticles and faces, I think it should not work also if I try to center the 2 models in x and y, or not? because the number of verticles and faces don't change.

    Thanks
    Paola

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.