If I have a sequence of meshes where the vertices keep on changing while the faces remain the same. How can I create an animated visualization or save in a video/gif? Sorry, but I can't figure it out from the documentation.
This should work:
scene = mesh(my_mesh)
meshplot = scene[end]
meshplot[1] = new_mesh
You can make the vertices an Observable Array, and update that array.
I am doing this:
scene = mesh(vertices,faces)
meshplot = scene[end]
meshplot[1].val = convert_arguments(Mesh,new_vertices,faces)[1]
I don't see any change in the rendered window.
Try update!(scene)?
Still unchanged. It did update the scene (the camera view got back to the original), but the mesh remains unchanged.
Btw, I also want to interact using the mouse while the vertices updates. I don't want it to go back to original view.
Why would you change my example code to:
meshplot[1].val
?!?
Updating the private field val is exactly why it doesn't update the plot...
What happens if you do:
overts = Node(vertices)
scene = mesh(overts, faces)
overts[] = new_vertices
# update!(scene)
(This is the Observables solution, Simon's solution is equally valid).
@SimonDanisch It was giving the following error:
ERROR: MethodError: Cannotconvertan object of type GLNormalMesh to an object of type Array{Float64,2}
then I checked typeof(meshplot[1]) and it was Observables.Observable{GLNormalMesh}
meshplot[1].val was of type GLNormalMesh so I tried assigning to it.
Ok, well the mistake must have been, that you were trying to update it with something that isn't a Mesh, but setting the val directly doesn't help with that (it just circumvents propagating the update to the plot) ;)
I thought you already have a mesh - but if you don't @asinghvi17 solution might be the way to go!
@asinghvi17 Thanks! it is working as I want.
@SimonDanisch I used convert_arguments(Mesh,new_vertices,faces)[1] to get a GLNormalMesh. Do I need a different type of mesh?
It's not the type but the way it was assigned. Try meshplot[1][] = newmesh?
Got it! Working perfectly :)
I am new to Julia. Is this kind of assignment specific to Makie or something we can find in Julia too? And if it is not a lot of work for you, I would like to know why this work and the previous one doesn't.
Sorry, you actually run into some pretty confusing behavior of Makie - I didn't realize immediately, because you didn't post the code you actually tried ;) So you should always post what your current code looks like!
The confusing behaviour is that plot[1] returns the signal from convert_arguments(args....)
while plot[1] = new_args... actually corresponds to the input arguments.
So if you do:
meshplot = mesh(arg1, arg2, arg3)[end]
# you will need to do:
meshplot[1] = new_arg1;
meshplot[2] = new_arg2;
meshplot[3] = new_arg3;
This was a work around that I introduced at some point - will try to reevaluate if this is still needed, since it's indeed super confusing!
If I am recording this sequence using record function. The camera view is reset when the record loop executes. Here is what I am doing.
msh = mesh(vertices[1,:,:],faces)
After this, I adjust the camera view using the mouse. Next I do
record(msh,"out.gif",1:size(vertices,1)) do i
msh[end][1][] = convert_arguments(Mesh,vertices[i,:,:],faces)[1]
end
During the recording, the camera view is reset. How can I render and save with my desired camera view?
put scene.center = false in front of record
Awesome! center is not a member of scene so scene.center doesn't exist but scene[:center]=false works perfectly.
Did you try it?
julia> using Makie
julia> scene = scatter(rand(4))
julia> scene.center = false
false
Works!
Sorry, my bad. It works. In REPL I was using tabs to scene. and it didn't show center so I tried scene[:center] and it worked.
I see ;) Yeah it's enabled via getproperty which doesn't work with autocomplete :(
You can add it to propertynames for it to work I think?
Oh, good point! I was meaning to research how I can make autocomplete work :)