[Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: [Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?

Post by paullee »

Discussion in another thread remind me to post the script for reference :)


Code: Select all

doc = App.ActiveDocument
obj = doc.getObject('Cut001')
box = doc.getObject('Group')
v = doc.addObject('App::Link')
v.setLink(box)
vv = doc.addObject('App::Link')
vv.setLink(v)
vv.ShowElement=False
count = 0
pList = []
if True:  # Just to make below run in python console in 1 go
  for xx in range (0,10):
    for yy in range(0,10):
        for zz in range(0,16):
            xl = xx*1000
            yl = yy*1000
            zl = zz*1000
            v = None
            if obj.Shape.isInside(App.Vector(xl,yl,zl),0,True): # if point lies on a face it's considered inside
                count = count + 1
                pList.append(App.Placement(App.Vector(xl,yl,zl),App.Rotation(App.Vector(0,0,1),0)))
  print(count)
  vv.ElementCount = count
  vv.PlacementList = pList

realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: [Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?

Post by realthunder »

paullee wrote: Sat Aug 14, 2021 10:54 am Is there anything to Links itself can do to optimise, or it is totally hardware ?
This is a software problem. Coin3D rendering is kind of weak on hierarchies of objects. Please try my 'Daily' release with 'Preferences -> Display -> Render cache' set to 'Experimental'. I get 60+ fps on my i5 while in debug mode.

BTW, I have also added new attribute 'Matrix' and 'MatrixList' (for array) in Link so that you can do arbitrary transformation on the linked object. Right now, the experimental renderer still hasn't tapped into the power of modern graphics API, such as hardware instance rendering. When that is ready, we'll probably be able to do what geometry node does in blender.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: [Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?

Post by paullee »

realthunder wrote: Mon Aug 16, 2021 11:53 pm This is a software problem. Coin3D rendering is kind of weak on hierarchies of objects. Please try my 'Daily' release with 'Preferences -> Display -> Render cache' set to 'Experimental'. I get 60+ fps on my i5 while in debug mode.

BTW, I have also added new attribute 'Matrix' and 'MatrixList' (for array) in Link so that you can do arbitrary transformation on the linked object. Right now, the experimental renderer still hasn't tapped into the power of modern graphics API, such as hardware instance rendering. When that is ready, we'll probably be able to do what geometry node does in blender.
Gorgeous ! It really helps even on my i3 with built-in graphics only. Looking forward to this be merged soon :D

In earlier discussion (2017!), I tested @yorik's new feature and built over 20 blocks of (repetitive) multi-storey building, without Links, and I remember I can still rotate slowly. New experimental feature: Hi-res property in Arch

So this Experimental Render Cache only helps Links (with hierarchies of objects) or it helps in general a scene with millions of objects ?


And curious with is the different between Element Count vs Matrix / MatrixList ? Any reference / wiki to read about ?

Thanks :)


Image
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: [Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?

Post by realthunder »

paullee wrote: Tue Aug 17, 2021 3:52 pm So this Experimental Render Cache only helps Links (with hierarchies of objects) or it helps in general a scene with millions of objects ?
It helps in general, but can help more with hierarchies of object, like lots of objects in a group, or many levels of group. It still has its limitation on the number of objects it can handle, though. Once the instance rendering is implemented, it should be able to handle a lot more on moderate hardware.

And curious with is the different between Element Count vs Matrix / MatrixList ? Any reference / wiki to read about ?
The Matrix is for placement, think it as Placement/PlacementList, only that it can now include scale, and other deformation transform, like skew. I remember you wanted this in this post? Even with the new renderer, it still may not be practical to use link array of polygons to cover large surface, but again, it should be doable in the future.

Right now, you can use another option to speed up rendering of largement amount of small primitives when using the experimental render cache, just below the 'Render cache' option, the 'Cache merge threshold'. Normally one object requires at least one opengl draw calls (even for Link). And it starts to slow down on a few thousands. The merge option will merge triangles from different objects together to reduce draw calls. Set it below 1000 to get good result on large amount of objects. The drawback is that it consumes a lot of memory.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: [Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?

Post by paullee »

realthunder wrote: Thu Aug 19, 2021 4:51 am It helps in general, but can help more with hierarchies of object, like lots of objects in a group, or many levels of group. It still has its limitation on the number of objects it can handle, though. Once the instance rendering is implemented, it should be able to handle a lot more on moderate hardware.
...
Right now, you can use another option to speed up rendering of largement amount of small primitives when using the experimental render cache, just below the 'Render cache' option, the 'Cache merge threshold'. Normally one object requires at least one opengl draw calls (even for Link). And it starts to slow down on a few thousands. The merge option will merge triangles from different objects together to reduce draw calls. Set it below 1000 to get good result on large amount of objects. The drawback is that it consumes a lot of memory.
Look forward these be merged :D

The Matrix is for placement, think it as Placement/PlacementList, only that it can now include scale, and other deformation transform, like skew. I remember you wanted this in this post? Even with the new renderer, it still may not be practical to use link array of polygons to cover large surface, but again, it should be doable in the future.
Wow! Yes, instancing / 'Tessellations/Panelisation' in FreeCAD can become a killer feature !
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: [Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?

Post by paullee »

Just have a glance at how in Blender Tissue add-on do about tessellation, not sure if the MatrixList is something that help to do something in this direction ?

A video @dimatar suggested earlier.

phpBB [video]
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: [Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?

Post by paullee »

realthunder wrote: Thu Aug 19, 2021 4:51 am Ping
An interesting finding to report :)

Do the calculation of Link with 1038 ElementCount in another way as method in a FeaturePython class + appLinkExecute

Previously done by a script. 2 ways - 2 performance result !?

1. Previous approach - https://forum.freecadweb.org/viewtopic. ... 50#p524517
  1. A Link (L) is made to a Group of (Arch)Objects
  2. Another Link (LL), with >1000 Element Count, and corresponding PlacementList, is made to above Link
  3. The above Links are created and the PlacementList is calculated by a Script shown in above post and put in the Link object (LL)
  4. As previously report, panning the camera is nearly impossible
  5. But, running the scripts to calculate the Placement (> 1000 Element Count) is just a matter of second
2. Approach with FeaturePython Class + appLinkExecute()
  1. A Link (L) is made to a Group of (Arch)Objects
  2. A FeaturePython Object (FP) (Class Voxel) is created (with appExecuteLink() method)
  3. This Instance Object (FP) has PropertyLink to the Link (L)
  4. This Instance Object (FP) use the Link.Shape as its FP.Shape
  5. This Instance Object (FP) calculated the PlacementList
  6. Another Link (LL) is made to above FP (using its fp.Shape)
  7. FP appLinkExecute() update the LL's PlacementList, with >1000 Element Count
  8. Surprisingly, panning the camera is possible in the case
  9. However, recomputing the Link (LL) take unbearable time (> 1 min < 2min)
Any idea? Thanks !
Class_Voxel.py
(5.82 KiB) Downloaded 52 times
Test_ Voxel_ 5_ Link w ElementCount.FCStd
(63.91 KiB) Downloaded 48 times

phpBB [video]
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: [Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?

Post by paullee »

realthunder wrote: Ping
Trying to debug for a while but has not much idea.

It seems somehow the implementation had some changes it does not work 'as before' :) -

- after FreeCAD_weekly-builds-26306-Linux-Conda_glibc2.12-x86_64.AppImage, around Nov 2021
> (this AppImage works as 'usual')

- before FreeCAD_weekly-builds-26720-Linux-Conda_glibc2.12-x86_64.AppImage, around Dec 2021
> (this AppImage not works as before)

Any pointer the any changes in-between for ease of adapting to latest behaviour ?

Thanks :D
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: [Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?

Post by paullee »

'Gist of syndrome' :)

Before FreeCAD_weekly-builds-26720-Linux-Conda_glibc2.12-x86_64.AppImage
  1. A Link to a SketchObjectPython got a property 'MasterSketch' points to Object B.
  2. The 'original' SketchObjectPythong points to Object A.
So far so good, no problem re-opening the model file :)

With this git, upon re-opening of the same model file :-
  1. While the Link to the SketchObjectPython keeps pointing to Object B;
  2. the 'original' SketchObjectPythong Seems 'Infected' and points to Object B also.
  3. the 'original' SketchObjectPythong get a exclamation mark and display 'error'
  4. Upon recomputing the Link, some properties e.g. the App::PropertyLink 'MasterSketch' get cleaned up
paullee
Veteran
Posts: 5120
Joined: Wed May 04, 2016 3:58 pm

Re: [Link] of (Sketch)ObjectPython / Part FeaturePython lose its 'Proxy Methods' ?

Post by paullee »


Before FreeCAD_weekly-builds-26720-Linux-Conda_glibc2.12-x86_64.AppImage

Screenshot from 2022-04-23 23-29-02.png
Screenshot from 2022-04-23 23-29-02.png (215.44 KiB) Viewed 1203 times
Screenshot from 2022-04-23 23-29-10.png
Screenshot from 2022-04-23 23-29-10.png (222.04 KiB) Viewed 1203 times


FreeCAD_weekly-builds-26720-Linux-Conda_glibc2.12-x86_64.AppImage
- Re-opening the same model file

Screenshot from 2022-04-23 23-26-59.png
Screenshot from 2022-04-23 23-26-59.png (217.2 KiB) Viewed 1203 times
Screenshot from 2022-04-23 23-27-05.png
Screenshot from 2022-04-23 23-27-05.png (221.36 KiB) Viewed 1203 times
Post Reply