GraphN comes with a general-purpose API that contains various computer graphics focused libraries. To kick things off, let's create a simple scatter setup where we instance a mesh in our scene on all the vertices of a newly created torus:
And this is what the code would look like:
This is what every line does:
First, we import the Scene and GNMesh libraries. Scene is your gateway to all scene/level interactions; this is where you can query the object that's currently selected, get all meshes in the scene, get an object by its name, create an object, etc... GNMesh is our custom mesh processing library. You can create geometry from scratch with it, or pass it a mesh from your scene, and it'll create its GNMesh equivalent, from which you can query all mesh properties you want.
Scene.getObjectsByNames takes the name of our object, and creates a SceneContainer object that contains the object "pCube1".
GNMesh.createTorus creates a torus mesh. The torus created here won't be visible in your scene, as GNMesh only creates objects in memory. Rest assured, We'll bake it into the scene in a bit.
Scene.createMeshInstancer creates a mesh instancer object. Its only required inputs are the container you want to instantiate; in this case scatter_obj, and the positions where you want to create instances, in this case, that would be the torus' vertices, which are retrieved with torus_mesh.positions()
Finally, we bake our torus into a real mesh with Scene.createMesh, which takes our torus mesh as an input, and creates an actual mesh in our scene.
You've probably noticed a func_id argument being passed to a couple of function calls in there. GraphN has a caching API, and whenever you make a function call such as Scene.createMesh, giving it a func_id will allow you to cache its result, so you could go back to your torus, update its divisions, then run Scene.createMesh again and it'll update the mesh in your scene since it's now bound by that func_id.
To give you another basic example, without a func_id, the function call Scene.createMeshInstancer would create a new instancer object in your scene every time you run it, instead of simply updating the existing instancer on every run.