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

confused about filemesh stl file #141

Closed
Lumin-cider opened this issue Feb 28, 2024 · 6 comments · Fixed by #142
Closed

confused about filemesh stl file #141

Lumin-cider opened this issue Feb 28, 2024 · 6 comments · Fixed by #142

Comments

@Lumin-cider
Copy link

Lumin-cider commented Feb 28, 2024

Hi there, been trying to use an stl file and is confused about the steps?
Currently I'm trying to create a solid with a stl file and perform simulation, got MeshIO.jl to open the stl file but not sure which parameter I can put the opened file with.
I've tried just using Filemesh(filename =: "stl_filename") which seems like the way to go but ran into the error message saying that I need to convert stl file to json, do I have to do that manually? Would it be possible to provide an example to show the steps?

Thank you.

@GerhardHippmann
Copy link
Collaborator

GerhardHippmann commented Feb 28, 2024

For animation export (i.e. animationFile defined in Scene) meshes are only supported in json format. So in fact you have to convert your stl file. This can be done with the three.js editor (import mesh, export object).

If you do not need animation export, just remove it in the Scene constructor.

@Lumin-cider
Copy link
Author

Would it work if I need multiple meshes for different parts?

@Lumin-cider
Copy link
Author

I have converted the stl file into json file using three.js and placed it inside the same folder as my stl file. I then created an object in Modia3D using the following code:
object = Object3D( parent=:revolute_point, feature=Solid(shape=FileMesh(filename=:"filename.stl", scale=:(0.005, 0.005, 0.005)), solidMaterial="Aluminium", visualMaterial=VisualMaterial(color="Blue"))),
then object is then instantiated and simulated with animation export enable but the following error message appeared:

Export animation to plots/simulate.jl_animation.json ... ┌ Warning: Please convert filename.stl into a .json file.
└ @ Modia3D.AnimationExport C:\Users\user.julia\packages\Modia3D\WNchk\src\AnimationExport\exportAnimation.jl:265
ERROR: MethodError: no method matching iterate(::Nothing)

Closest candidates are:
iterate(::Base.MethodSpecializations)
@ Base reflection.jl:1148
iterate(::Base.MethodSpecializations, ::Nothing)
@ Base reflection.jl:1154
iterate(::Base.MethodSpecializations, ::Int64)
@ Base reflection.jl:1155
...

Stacktrace:
[1] indexed_iterate(I::Nothing, i::Int64)
@ Base .\tuple.jl:95
[2] printObjectToJSON(object::@NamedTuple{…}, elements::@NamedTuple{…}, obj::Modia3D.Composition.Object3D{…}; initPos::StaticArraysCore.SVector{…}, initRot::StaticArraysCore.SMatrix{…})
@ Modia3D.AnimationExport C:\Users\user.julia\packages\Modia3D\WNchk\src\AnimationExport\exportAnimation.jl:367
[3] printObjectToJSON
@ C:\Users\user.julia\packages\Modia3D\WNchk\src\AnimationExport\exportAnimation.jl:324 [inlined]
[4] exportAnimation(scene::Modia3D.Composition.Scene{Float64})
@ Modia3D.AnimationExport C:\Users\user.julia\packages\Modia3D\WNchk\src\AnimationExport\exportAnimation.jl:472
[5] macro expansion
@ C:\Users\user.julia\packages\TimerOutputs\RsWnF\src\TimerOutput.jl:237 [inlined]
[6] macro expansion
@ C:\Users\user.julia\packages\Modia3D\WNchk\src\Composition\dynamics.jl:461 [inlined]
[7] macro expansion
@ C:\Users\user.julia\packages\TimerOutputs\RsWnF\src\TimerOutput.jl:237 [inlined]
[8] macro expansion
@ C:\Users\user.julia\packages\Modia3D\WNchk\src\Composition\dynamics.jl:453 [inlined]
[9] macro expansion
@ C:\Users\user.julia\packages\TimerOutputs\RsWnF\src\TimerOutput.jl:237 [inlined]
[10] computeGeneralizedForces!(mbs::Modia3D.Composition.MultibodyData{…}, qdd_hidden::Vector{…}, _leq::LinearEquations{…})
@ Modia3D.Composition C:\Users\user.julia\packages\Modia3D\WNchk\src\Composition\dynamics.jl:435
[11] macro expansion
@ C:\Users\user.julia\packages\Modia\77g2A\src\StateSelection.jl:978 [inlined]
[12] macro expansion
@ C:\Users\user.julia\packages\TimerOutputs\RsWnF\src\TimerOutput.jl:237 [inlined]
[13] macro expansion
@ C:\Users\user.julia\packages\Modia\77g2A\src\StateSelection.jl:977 [inlined]
[14] getDerivatives(_x::Vector{Float64}, _m::InstantiatedModel{Float64, Float64}, _time::Float64)
@ Main C:\Users\user.julia\packages\Modia\77g2A\src\CodeGeneration.jl:2077
[15] #invokelatest#2
@ Base .\essentials.jl:887 [inlined]
[16] invokelatest
@ Base .\essentials.jl:884 [inlined]
[17] macro expansion
@ Modia C:\Users\user.julia\packages\Modia\77g2A\src\CodeGeneration.jl:1039 [inlined]
[18] macro expansion
@ Modia C:\Users\user.julia\packages\TimerOutputs\RsWnF\src\TimerOutput.jl:237 [inlined]
[19] invokelatest_getDerivatives_without_der_x!(x::Vector{Float64}, m::InstantiatedModel{Float64, Float64}, t::Float64)
@ Modia C:\Users\user.julia\packages\Modia\77g2A\src\CodeGeneration.jl:1017
[20] terminate!(m::InstantiatedModel{Float64, Float64}, x::Vector{Float64}, t::Float64)
@ Modia C:\Users\user.julia\packages\Modia\77g2A\src\CodeGeneration.jl:1309
[21] macro expansion
@ C:\Users\user.julia\packages\Modia\77g2A\src\SimulateAndPlot.jl:240 [inlined]
[22] macro expansion
@ C:\Users\user.julia\packages\TimerOutputs\RsWnF\src\TimerOutput.jl:237 [inlined]
[23] simulate!(m::InstantiatedModel{…}, algorithm::Missing; merge::Nothing, kwargs::@kwargs{…})
@ Modia C:\Users\user.julia\packages\Modia\77g2A\src\SimulateAndPlot.jl:233
[24] simulate!
@ Modia C:\Users\user.julia\packages\Modia\77g2A\src\SimulateAndPlot.jl:187 [inlined]

Did I do something wrong? Do I have to do something extra to the converted json file (e.g. include it as a parameter while building the object)?

@GerhardHippmann GerhardHippmann linked a pull request Feb 29, 2024 that will close this issue
@Lumin-cider
Copy link
Author

Hi, is there a simple example to how filemesh can be used?

@AndreaNeumayr
Copy link
Member

AndreaNeumayr commented Mar 5, 2024

Here is an example: test/Collision/CollidingSphereWithBunnies.jl

@GerhardHippmann
Copy link
Collaborator

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 a pull request may close this issue.

3 participants