Page 1 of 1
OpenSim Model with STL File Created Using MATLAB DOESN'T Open
Posted: Tue Feb 20, 2024 4:05 pm
by deepaksingh
The following is the code i wrote in matlab and it updates and saves the file and i can see the script change as well when i open the new .osim file in Notepad however the file doesn't open in OpenSim.
Code: Select all
clear
clc
import org.opensim.modeling.*
% Constructing Filepaths of osim Model and CAD stl file:
Filepath = "J:\temp\Deepak\OpenSim\Models\ImportGeomertyTrial\Gait2354_Simbody";
Modelfilename = "gait2354_simbody.osim";
CADfilename = "afoPlate.stl";
Modelfilepath = fullfile(Filepath, Modelfilename)
CADfilepath = fullfile(Filepath, CADfilename)
% Opening osim Model as a Model Class:
HumanBodyModel = Model(Modelfilepath)
% Opening CAD stl file as a Body Class:
CADpart = Body()
%CADpart.RenameType(extractBefore(CADfilepath, "."))
CADpart.attachGeometry(Mesh(CADfilepath))
CADpart.scaleAttachedGeometry(Vec3(2))
% Adding CAD stl Body class into osim Model Class:
HumanBodyModel.addBody(CADpart)
% Saving combined Model:
combinedModelFilename = strcat(extractBefore(Modelfilename, "."), "_with_", extractBefore(CADfilename, "."), ".osim")
HumanBodyModel.print(fullfile(Filepath, combinedModelFilename))
Re: OpenSim Model with STL File Created Using MATLAB DOESN'T Open
Posted: Wed Feb 21, 2024 2:59 pm
by tkuchida
It would be helpful to post the error message. Scanning the code, I see two potential issues:
(1) You are calling the default constructor for the Body class, which I believe creates a body with mass set to NaN (
https://github.com/opensim-org/opensim- ... dy.cpp#L47).
(2) You should call
HumanBodyModel.initSystem(); before saving to file.
The "dynamic walker" example on GitHub might be helpful if you haven't seen it already (buildWalker_Complete.m,
https://github.com/opensim-org/opensim- ... Complete.m).
Re: OpenSim Model with STL File Created Using MATLAB DOESN'T Open
Posted: Fri Feb 23, 2024 7:35 am
by deepaksingh
Thank you so much for your response! After considering your reply and making changes to the code this is what i have:
Code: Select all
%References:
% https://simtk.org/plugins/phpBB/viewtopicPhpbb.php?f=91&t=11924&p=37599&start=0&view=
% https://simtk.org/plugins/phpBB/viewtopicPhpbb.php?f=91&t=17581&p=0&start=0&view=&sid=213c74f2deb6d15e507c592c14b4bb4d
% https://github.com/opensim-org/opensim-core/blob/main/Bindings/Java/Matlab/Dynamic_Walking_Tutorials/Dynamic_Walker_Builder/buildWalker_Complete.m
clear
clc
import org.opensim.modeling.*
%% Constructing Filepaths of osim Model and CAD stl file:
Filepath = "J:\temp\Deepak\OpenSim\Models\ImportGeomertyTrial\Gait2354_Simbody"
Modelfilename = "gait2354_simbody.osim"
CADfilename = "afoPlate.stl"
Modelfilepath = fullfile(Filepath, Modelfilename);
CADfilepath = fullfile(Filepath, CADfilename);
%% Opening osim Model as a Model Class:
HumanBodyModel = Model(Modelfilepath);
%% Get a reference to the ground object
ground = HumanBodyModel.getGround();
%% Opening CAD stl file as a Body Class:
CADpart = Body();
CADpart.setName(extractBefore(CADfilename, "."));
CADpart.setMass(20);
CADpart.setInertia(Inertia(1,1,1,0,0,0));
CADpart.attachGeometry(Mesh(CADfilepath));
%CADpart.scaleAttachedGeometry(Vec3(2))
%% Adding CAD stl Body class into osim Model Class:
HumanBodyModel.addBody(CADpart)
%% Finalizing everything:
HumanBodyModel.finalizeConnections();
%% Initialize the System (checks model consistency).
HumanBodyModel.initSystem();
%% Saving combined Model:
CombinedModelFilename = strcat(extractBefore(Modelfilename, "."), "_with_", extractBefore(CADfilename, "."), ".osim")
HumanBodyModel.print(fullfile(Filepath, CombinedModelFilename));
if ans==1
display(['Combined File Saved Successfully!']);
else
display(['There is an error. File didn''t save']);
end
Now the file gets saved and the model opens in OpenSim as well, however, i can't see the model even though i can see everything in Navigator and Topology View.
Re: OpenSim Model with STL File Created Using MATLAB DOESN'T Open
Posted: Fri Feb 23, 2024 3:25 pm
by tkuchida
You may need to adjust the Geometry Search Path (see the "User Preferences" page in the documentation:
https://simtk-confluence.stanford.edu:8 ... references).
Re: OpenSim Model with STL File Created Using MATLAB DOESN'T Open
Posted: Fri Feb 23, 2024 3:48 pm
by deepaksingh
Thank you, Dr. Uchida! I am facing some interesting issues still:
1. When i import a simpler CAD file "afoPlate.stl" (73 KB), the model opens and i can visualize everything.
2. When i open a more compelx CAD file "Fuselage_Tail_D311_1.stl" in my case (877,525 KB), I can't see anything.
3. I am using OpenSim 4.3 in Windows.
4. I can send you a zip file with everything over your email if you would like to help troubleshoot since i can't attach large files here.