Page 3 of 3

Re: Animated Vector Graphics Scene Graph

Posted: Sun Oct 19, 2025 10:15 pm
by idle
skywalk wrote: Sun Oct 19, 2025 8:21 pm Hi idle!
Can you explain the intent of Right-Mouse-Clicks?
It seems to work as a pan feature, but it also seems to jump more than intended?
Maybe the moving objects are confusing the hit spot?
It's just testing that the scene pan works, hold right button down and move the scene around where the mouse is.
The pan is so you can scroll an area which you could clip.

I'm currently sorting out the hit tests and events and restructuring object properties to reduce the size of the structure
and working on selecting and setting object properties which isn't straight forward and I still haven't got it right, I need a way to make it dynamic so you are free to add or remove elements from within an object and still be able to identify an element in an object. currently I'm doing that in an array so after you create an object it's returning the index of the item in the display list where the index is incremented when you add a path item

Code: Select all

index = AVGAddPathCircle(*scene, circle1, 0, 0, 50)
AVGVectorSourceColor(*scene, circle1, RGBA(0, 128, 255, 255))
AVGFillPath(*scene, circle1)
index1 = AVGAddPathCircle(*scene, circle1, 0, 0, 20)
AVGVectorSourceColor(*scene, circle1, RGBA(128, 128, 255, 255),RGBA(255, 255, 0, 255))
AVGFillPath(*scene, circle1) 
I really need a map in AvgObjects but I don't want to do that as a map is minimum of 2048 bytes
I could use squint then the overhead is only 8 bytes but it adds another 3k lines of code but then
then I can logically map multiple scenes layers objects and items as
scene0:layer0:object0:children scene0:layer0:object0:item0 and then store the pointer to items in an an object to object0 so there's no need to process the key as it's a direct pointer to the node in the graph so looking up an item in an object is just the "ID" which is a lot quicker than "scene0:layer0:object0:item"+"ID"
and I might be able to preserve zorder to if I key as hex so I won't need to use a list to look up the map entry

Re: Animated Vector Graphics Scene Graph

Posted: Sun Oct 19, 2025 11:02 pm
by idle
miso wrote: Sun Oct 19, 2025 10:04 pm I just missed that. Nice code. I might copy your license header style.
I was going to use Eclipse 2 as it looks like Ellipse to me but it's a long and complicated license.
Eclipse 2 basically stipulates that you have to share changes to the code back to the author and publish the source on request but it doesn't mean your whole program just the library of code but it gets murky. So MIT is much easier and well you can do what you like with it, though I would hope that if people can contribute to it that they would share contributions back to the community.

Re: Animated Vector Graphics Scene Graph

Posted: Sun Oct 19, 2025 11:31 pm
by skywalk
Yes!
MIT license is preferred.
I got lost in legalese with eclipse 2. :shock:

I like the fast array approach as I sometimes place 20k objects on a layer. I redraw my scenes with a hardcoded algo and it is still fast enough for user. This is not a game though. More like a custom graphical report.

As is, the pan feature is cool. Maybe the motion objects are messing with the origin?

Re: Animated Vector Graphics Scene Graph

Posted: Sun Oct 19, 2025 11:36 pm
by minimy
Very very nice lib, now work smooth.
I like the function to pick in the objects.
When I look at my code and compare it to yours, mine looks like it was written by a five year old kid. :lol:
Thank you very much for share.

Re: Animated Vector Graphics Scene Graph

Posted: Mon Oct 20, 2025 4:11 am
by idle
skywalk wrote: Sun Oct 19, 2025 11:31 pm Yes!
MIT license is preferred.
I got lost in legalese with eclipse 2. :shock:

I like the fast array approach as I sometimes place 20k objects on a layer. I redraw my scenes with a hardcoded algo and it is still fast enough for user. This is not a game though. More like a custom graphical report.

As is, the pan feature is cool. Maybe the motion objects are messing with the origin?
I've fixed up the select move and clicks I can post it now but it's in-between modification and will take me a day or two to change.

The problem with an array is that you can't easily modify it at runtime. Currently the display list is a "list" of drawing commands so you are free to insert or delete elements at will by id but that means you need to foreach on the list to find the items you want to insert modify or delete and then the properties array would be a mess.
so to provide O(1) lookups, insert, delete modify it wants a map think of web browsers they use map of a map or list to access elements I can do this in one structure and still preserve the speed of a list. The cost of the O(1) look up will be 8 memory access vs the list with 1 memory access times the depth of the list to the item. So It's not expensive in the scheme of things.

Currently zorder is preserved by iterating a list of object IDs that are looked up in the map of objects. so you get an object which has a display list of drawing commands() as you add Paths it increments the array of parameters for the object so you can get back the ID of the element to access its properties. I'm changing those properties so that the item holds the properties to reduce the overhead of the properties array which is currently 432 bytes per item.

so here I added activeColor and hoverColor to the spVectorSourceColor structure and removed them from params

Code: Select all

Procedure AVGVectorSourceColor(*scene.AVGScene, objectID, color,hoverColor=0, id=0, *userdata=0)
  If FindMapElement(*scene\objects(), Str(objectID))
    Protected *obj.AVGObject = *scene\objects()
    AddElement(*obj\avg\dl())
    *obj\avg\dl()\ptVectorSourceColor = AllocateStructure(spVectorSourceColor)
    *obj\avg\dl()\ptVectorSourceColor\Color = color
    *obj\avg\dl()\ptVectorSourceColor\ActiveColor = color 
    ;*obj\params[*scene\nextitem]\color = color 
    If hoverColor
      *obj\avg\dl()\ptVectorSourceColor\hoverColor = hoverColor   
      ;*obj\params[*scene\nextitem]\hovercolor = hoverColor 
    Else 
      *obj\avg\dl()\ptVectorSourceColor\hoverColor = Color 
      ;*obj\params[*scene\nextitem]\hovercolor = color
    EndIf 
    *obj\avg\dl()\func = @RtVectorSourceColor()
    *obj\avg\dl()\ptVectorSourceColor\params\id = *scene\nextitem
    *obj\avg\dl()\ptVectorSourceColor\params\userdata = *userdata
    *obj\avg\dl()\ptVectorSourceColor\params\type = #spVectorSourceColor 
    *obj\ptrDisplayListItem[*scene\nextitem] = *obj\avg\dl() 
  EndIf
EndProcedure

so when you hover it swaps the color as it walks the display list and doesn't need to look up the properties index but I still need to look up the map of objects

when you want to change the colors outside of a callback

Code: Select all

Procedure AVGSetObjectColors(*scene.AVGScene, object.s, color.l=0,hoverColor.l=0,index=0)
  If FindMapElement(*scene\objects(),Str(*scene\ObjectByName(object)))
    *obj.AVGObject = *scene\objects() 
    If index < 20 
      Protected *dl.DisplaylistPtr = *obj\ptrDisplayListItem[index]   
      If *dl\item\type = #spVectorSourceColor 
        Protected *ptr.spVectorSourceColor = *dl\item 
        If *ptr\Color <> color 
          *ptr\Color = color
        EndIf 
        If *ptr\hoverColor <> hoverColor 
          *ptr\hoverColor = hoverColor 
        EndIf   
      EndIf 
    EndIf
  EndIf 
EndProcedure

So it has to look up the item from the map by name to get the display list then set *dl pointer from the properties
This is a slight improvement but it still has the overhead of the array albeit reduced in size though if you wanted to remove or add elements the index is borked. so I would need a properties list or a properties map which is out of the question as the overhead of a map is 64 elements x 32 bytes 2048 bytes so that leaves a list but to cut to the chase, if I use squint, I get the benefit of a map to a map at only the cost of 8 memory access vs 1 times the depth of a list of properties. so as soon as you have more than 8 items in an object your wining and with squint there is no overhead it's just a pointer
So that's why I'm going all foo, the cost of the price of convivence to users to do what ever they want and it'll be way easier to adapt as it becomes an in memory db on pointers so I can do the lot with one structure.

The only shenanigans I need to do is set an index keys as key.s = "Circle:"+ RSet(Hex(index),4,"0")
and then the order is preserved in the trie.

Re: Animated Vector Graphics Scene Graph

Posted: Mon Oct 20, 2025 4:18 am
by idle
minimy wrote: Sun Oct 19, 2025 11:36 pm Very very nice lib, now work smooth.
I like the function to pick in the objects.
When I look at my code and compare it to yours, mine looks like it was written by a five year old kid. :lol:
Thank you very much for share.
Nope yours looks uncomplicated, I think I just like complicated. I've spent all day thinking about and tried to justify my reasoning in previous post. so I will try it tomorrow.

Re: Animated Vector Graphics Scene Graph

Posted: Mon Oct 20, 2025 6:34 pm
by Andre
Don't know if I will need it one day, but looks very good and useful! Thank you :D

Re: Animated Vector Graphics Scene Graph

Posted: Tue Oct 21, 2025 7:51 am
by idle
Andre wrote: Mon Oct 20, 2025 6:34 pm Don't know if I will need it one day, but looks very good and useful! Thank you :D
Thanks, and maybe one day it will be complete. :)

Updated 0.2.8a
I didn't have much time to do anything but reduced the object size getting the animation onto a pointer and fixed up the object selection and moving objects

Something funcky is going on with the switch, motion blur for free! 8) but not intended.

Re: Animated Vector Graphics Scene Graph

Posted: Tue Oct 21, 2025 9:35 am
by Mesa
Thank you, it's very usefull.

I hope to see primitives or parametric primitives.

And why not, to be a part of PureBasic as library or functions of vector library, who knows...

M.

Re: Animated Vector Graphics Scene Graph

Posted: Tue Oct 21, 2025 10:14 am
by idle
Yes I have parametric shapes in mind.
They'll be a lot of work I expect.