Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve RefMeshes API #87

Merged
merged 10 commits into from
Dec 3, 2024
Merged

Improve RefMeshes API #87

merged 10 commits into from
Dec 3, 2024

Conversation

VEZY
Copy link
Owner

@VEZY VEZY commented Dec 1, 2024

The API for creating the geometry of a plant is currently terrible.

We first have to define reference meshes, put them in a RefMeshes structure, and put that structure into the root node of the mtg.

Then, each node has a given geometry that points to the reference mesh, to its position in the vector of reference meshes in the RefMeshes structure, its transformations, tapering, and finaly the actual mesh of the node (which is lazily reconstructed).

I think we can improve that by removing the RefMeshes structure altogether, and only giving a reference to the reference mesh to the node. This way we simplify greatly the API.

The API would be something like:

internode_refmesh = cylinder()
leaf_refmesh = leaf_mesh()

traverse!(mtg) do node
    if symbol(node) == "Internode"
        transformation = [...]
        node.geometry = Geometry(internode_refmesh, transformation)
    elseif symbol(node) == "Leaf"
        transformation = [...]
        node.geometry = Geometry(leaf_refmesh, transformation)
    end
end

And if the user wants to add more information into its reference mesh, it can still wrap it into a RefMesh structure as follows:

RefMesh("Internode", internode_refmesh, RGB(220 / 255, 220 / 255, 220 / 255))

Now if some reference meshes are given directly as meshes, we need to give each a default name and compute the normals of their vertex when we write them to disc in the OPF.

We also need to change how we write the OPF altogether, because currently we use the index of the reference mesh. But we could make a dictionary of keys refmesh and values index + any other needed information (material, normals...), if the mesh/refmesh is not in this dict, we add it, if it is, we just extract the information. In this case, we should write different parts of the OPF at different times. Starting with the topology, and slowly growing the meshBDD and other header information. I don't know if that's possible though.

@VEZY
Copy link
Owner Author

VEZY commented Dec 3, 2024

What changed: we don't use RefMeshes anymore, we just create a RefMesh per organ type, and use a reference in the node geometry. As long as we use the same RefMesh, it is only a reference (because its structure is immutable).
When we read an OPF, we parse the reference meshes in an array first, and reuse them throughout the OPF parsing.
When we write an OPF, we traverse the MTG to get all kind of reference meshes, and then we write them (check if that's well implemented though).

Now we don't have to have an attribute in the root node anymore, which saves time.

I also renamed geometry into Geometry, and removed the ref_mesh_index argument, as we automatically compute it at writing now.

@VEZY VEZY merged commit 41c46d0 into main Dec 3, 2024
7 checks passed
@VEZY VEZY deleted the improve-refmesh-API branch December 3, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant