ModiaSim / Modia3D.jl

Modeling and Simulation of 3D systems
MIT License
74 stars 8 forks source link

confused about filemesh stl file #141

Closed Lumin-cider closed 7 months ago

Lumin-cider commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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

Lumin-cider commented 7 months ago

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)?

Lumin-cider commented 7 months ago

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

AndreaNeumayr commented 7 months ago

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

GerhardHippmann commented 7 months ago

More examples: