Menu

Multiple selection of objects in scene

Help
SBlade
2017-08-17
2017-08-17
  • SBlade

    SBlade - 2017-08-17

    Dear All,

    I wish to implement a multiple selection of objects(mostly GLFreeForm) in the scene, as fa as I know GLScene doesn't have a EFFICIENT handling mechanism(other than GetPickedObjects, whcih is too slow) for multiple obejct selection, so what can be done in that regard.

    Regards,

     
  • Jerome.D (BeanzMaster)

    Hi SBlade, check in GLZGimoEx.Pas

    function TGLGizmoEx.InternalGetPickedObjects(const x1, y1, x2, y2: Integer; const guessCount: Integer): TGLPickList;
    
      procedure AddObjectToPicklList(const root: TGLBaseSceneObject; PickList: TGLPickList; X, Y: Integer);
      var
        t:    Integer;
        dist: Single;
        rayStart, rayVector, iPoint, iNormal: TVector;
      begin
        SetVector(rayStart, Viewer.Camera.AbsolutePosition);
        SetVector(rayVector, Viewer.Buffer.ScreenToVector(AffineVectorMake(X, Viewer.Height - Y, 0)));
        NormalizeVector(rayVector);
        for t := 0 to root.Count - 1 do
          if root[t].Visible then
          begin
            if (root[t].RayCastIntersect(rayStart, rayVector, @iPoint, @iNormal)) and
              (VectorDotProduct(rayVector, iNormal) < 0) then
              if PickList.FindObject(root[t]) = -1 then
              begin
                dist := VectorLength(VectorSubtract(iPoint, rayStart));
                PickList.AddHit(root[t], nil, dist, 0);
              end;
            AddObjectToPicklList(root[t], PickList, X, Y);
          end;
      end;
    
    var
      I, J: Integer;
      minx, miny, maxx, maxy: Integer;
    begin
      case FPickMode of
        pmGetPickedObjects:
        begin
          Result := Viewer.Buffer.GetPickedObjects(rect(x1, y1, x2, y2), guessCount);
        end;
    
        pmRayCast:
        begin
          Result := TGLPickList.Create(psMinDepth);
          maxX := MaxInteger(x1, x2);
          maxY := MaxInteger(Y1, Y2);
          minX := MinInteger(x1, x2);
          minY := MinInteger(Y1, Y2);
          for J := minY to maxY do
            for I := minX to maxX do
              //uploading to exclude hanging of application :)
              if (I mod 4 = 0) or (J mod 4 = 0) then
                AddObjectToPicklList(RootObjects, Result, I, J);
          AddObjectToPicklList(RootGizmo, Result, round((x1 + x2) * 0.5), round((y1 + y2) * 0.5));
        end;
    
      else
        begin
          Result := nil;
          Assert(False, glsUnknownType);
        end;
      end;
    end;
    
     

    Last edit: Jerome.D (BeanzMaster) 2017-08-17
  • SBlade

    SBlade - 2017-08-18

    Thank you Jerome for the entrypoint, this heavily relies on raycasting which sometimes may pose a culprits(slow selection is my main interest for the time being, I try to avoid it), isn't there a more openGL native way of doing this?

    Googling reveals one of the techniques such as unique - color scheme. But interestingly reading from framebuffer with readpixels doesn't that fast at all, in which way do I really have to follow to overcome that?
    REgards,

     
  • Jerome.D (BeanzMaster)

    No native way

    Googling reveals one of the techniques such as unique - color scheme. But interestingly reading from framebuffer with readpixels doesn't that fast at all, in which way do I really have to follow to overcome that?

    Have you some links to share ?

     
  • Jerome.D (BeanzMaster)

    Hi Blade thanks for yhe links i take a quick llok. Selecteing by FrameBuffer and with Once ColorID is not a bad idea butr not for multi-selecting.. The Best is what you described in 2 or perhaps 3 passes. I'll must take a loo to the boundingBoxes'functions and see if OOBB is implemented . I think is the "TAABBboundingBox" if i'm remember. but not sure i must take a look.

    I have some questions regarding your project :
    1 - How many maximlum objects do you want selecting ?
    2 - Give me some clue on how you do to perform rendering and how you manage events (like mouse, keyboard..)
    3 - What's your graphic Card ?

    Pehraps we'll can optimize some things in your "common" code.

     
  • SBlade

    SBlade - 2017-08-19

    1) That really depends on the end user demend, but in any case user may want to select all objects in the scene ( say 1K-2K), so even in that case program should be able to handle that properly.

    2) There is really nothing special about it, no fog, no textures etc.. at all. Mostly GLfreeform objects are on the scene, there is not special special handling for mouse or keyboard events as well. The most time consuming is snapping which iterates through vertices of objects in scene, but I can toggle that off before selection.

    My humble demand is: selection must be fast, simply lit screen with smooth or flat shading is enough for me.

    3) What a pity that I have AMD R7,

    Regards,

     

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.