heronarts / LX

Core library for 3D LED lighting engines
https://chromatik.co/
Other
41 stars 25 forks source link

Preferred way to build a model programmatically these days? #66

Closed Geethree closed 2 years ago

Geethree commented 2 years ago

In the past, I would build a model via extending LXModel, adding some points, etc..

Now we can graphically do this and/or via a json file(Awesome work @mcslee!). That said, I still prefer to build things programmatically.

Poking around I see that there is lx.structure.LXBasicFixture where the GridFixture comes from.

Then to add these to the fixture drop down, these are added to the LXRegistry as an array of default fixtures.

So question: Is there a recommended way to generate a model these days?

Currently building out the trees for www.github.com/follybuilders/paradisium

mcslee commented 2 years ago

If you want to build your model statically in code, keep extending LXModel like before and ignore all the LXStructure and LXFixture stuff. Those fixtures are things that would show up in the dynamic model construction system (e.g. not via JSON file, but still via dynamically adding/removing/modifying fixture settings in the left-hand model pane).

If you pass in a LXModel instance at constructor-time, all that stuff is ignored and your static model will be used instead. So, basically - make no changes if you prefer to stick with how it worked before.

Geethree commented 2 years ago

Though, leveraging the new LXStructure and LXFigure construcuts would allow for using the UI to tweak things and save it to the project?

mcslee commented 2 years ago

Yep - if you want to go that route, you can define your own custom LXFixture subclasses and register them. Don't pass an LXModel to the LX constructor. Your custom LXFixture type will be available to add in the left-hand Model column as a fixture type.

You probably want to subclass from LXBasicFixture if you're using a normal protocol type (e.g. artnet/sacn). That'll automatically get you the basics. Take a look at StripFixture to understand the basics of what your subclass needs to implement. It's mainly the methods: size() which indicates how many LEDs are in the fixture, and computePointGeometry() which sets the positions of the points based upon fixture geometry.

Feel free to ping w/ questions if it's not clear or working as expected.

raldi commented 2 years ago

It's not the prettiest code, but if you'd like a working, recent example to read over: https://github.com/titanicsend/LXStudio-TE/blob/main/src/main/java/titanicsend/model/TEWholeModel.java