rbdl / rbdl-toolkit

Application for visualizing and working with rbdl models
European Union Public License 1.2
19 stars 11 forks source link

rbdl-toolkit load lua model with meshes different with the result with Meshup tools. #33

Closed wangchangys closed 2 years ago

wangchangys commented 2 years ago

Hi, there. The work about these projects around rbdl is amazing, and i recently learn a lot . I want to load the lua four link model with meshes created myself. The meshes of each frame is created from a STL file to an .obj file by blender, and the base coordiante of the STL file is exactly concide with the body frame of each body. When i use the Meshup tool to load the lua model, everything goes fine, and the meshes showed right. However, when i use the rbdl-toolkit, the orientation of the meshbody is different. I dont know why. I can solve this problem by adding rotaions of the object in lua file, but i thought it could be better load the file as same as the Meshup tool, cause the stl coordinate is designed right. And what's more when i use rbdl-toolkit to load the human lua file created by ModelFactory with matlab, the result is not right, and when i use meshup tool, it works fine .

The lua file is as follows: print("Lua: start Constructing four link_2") l1=1 --1.0 l2=8 --8.0 l3=5 --6.0 why 5 will be calculated slow and maybe not right? p_x0=5 --5.0 p_y0=3.0*0

print("Lua: Making the meshes") meshes = { link1 = { color = { 1, 0, 0 }, --mesh_center = { 0, 0, 0 }, src = "link1.obj", translate={0,0,0}, scale={1.5,1,1}, rotate={ axis={0,0,1}, angle=0, } }, link2 = { color = { 0.3, 0.5, 0 }, --mesh_center = { 0, 0, 0 }, src = "link2.obj", translate={0,0,0}, rotate={ axis={0,0,1}, angle=0, } }, link3 = { dimensions = { 0.05, l3, 0.05 }, color = { 0, 0, 1 }, mesh_center = { 0, l3/2, 0 }, src = "unit_cube.obj", }, }

inertiaMatrix = { {5.0,0. ,0. }, {0. ,5.0,0. }, {0. ,0. ,5.0} } bodies = { link1 = { mass = 1.0, com = {0.0,l1/2,0.}, inertia = inertiaMatrix}, link2 = { mass = 3., com = {0.,l2/2,0.}, inertia = inertiaMatrix}, link3 = { mass = 3., com = {0.,l3/2,0.}, inertia = inertiaMatrix}, }

print("Lua: Making the model") model = { animation_settings = { force_scale = 0.1, torque_scale = 0.1, force_color = {1., 1., 0.}, torque_color = {0., 1., 0.}, force_transparency = 0.25, torque_transparency = 0.25, --frames_scale=5, }, gravity = {0., -9.81, 0.}, configuration = { axis_front = { 1, 0, 0,}, axis_right = { 0, -1, 0,}, axis_up = { 0, 0, 1,}, }, constraint_sets = { PinJoint = { {constraint_type = "loop", name = "x", predecessor_body = "ROOT", successor_body = "K3", predecessor_transform = { E = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, }, r = {p_x0, p_y0, 0.000}, }, successor_transform = { E = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, }, r = {0.0, l3, 0.0,}, }, axis = {0, 0, 0, 1, 0, 0}, stabilization_coefficient = 1.0, baumgarte_enabled = false, }, {constraint_type = "loop", name = "y", predecessor_body = "ROOT", successor_body = "K3", predecessor_transform = { E = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, }, r = {p_x0, p_y0, 0.000}, }, successor_transform = { E = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, }, r = {0.0, l3, 0.0,}, }, axis = {0, 0, 0, 0, 1, 0}, stabilization_coefficient = 1.0, baumgarte_enabled = false, }, }, }, points = { {name = "mass1",body = "K1",point = bodies.link1.com,}, {name = "mass2",body = "K2",point = bodies.link2.com,}, {name = "mass3",body = "K3",point = bodies.link3.com,}, --{name = "p1",body = "K2",point = {1,2,3},color={0,0,1},}, }, frames = {
{ name = "K1", parent = "ROOT", body = bodies.link1, visuals = {meshes.link1}, joint = {{0.,0.,1.,0.,0.,0.}}, joint_frame = { E = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, }, r = {0, 0, 0.0}, }, -- points={ -- K1_p1={coordinates={1,2,3},color={0,1,0.5},draw_line=1,line_width=1,}, -- } }, { name = "K2", parent = "K1", body = bodies.link2, visuals = {meshes.link2}, joint = {{0.,0.,1.,0.,0.,0.}}, joint_frame = { E = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, }, r = {0.,l1, 0.}, } }, { name = "K3", parent = "K2", body = bodies.link3, visuals = {meshes.link3}, joint = {{0.,0.,1.,0.,0.,0.},}, joint_frame = { E = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, }, r = {0.,l2, 0.}, } }, }, }

return model

ju6ge commented 2 years ago

Thanks I put a lot of effort into making the tools as usable as possible. I think mostly more documentation is needed, about stuff like how to correctly create the meshes.

This is a very simple fix … The thing about meshup is that it did a lot of things to the meshes that are not standard. So when using old models that where based on meshup, the meshes need to be converted. Most notably meshup rescales the meshes to be of unit size and uses a non standard coordinate layout which is why the meshes are rotated. (Saying that meshup loads them correctly is not quite true to my ears because I have been ripping my hair out a lot because of meshups handling of meshes :angry: )

RBDL-Toolkit uses the builtin Qt-3D mesh loader which supports more than just .obj files (I think you could just try to use the stl files directly). In the extras folder of the rbdl-toolkit repository there are some python scripts that you can run on the meshes to convert the to the format that the toolkit expects. In general I think that there should be a wiki page detailing in which format to export self created meshes, but at the moment my time for further improving the docs and code is very limited.

ju6ge commented 2 years ago

About the result of the Model Factory:

Model Factory was created with meshup in mind. But there is are good reasons why rbdl-toolkit does not behave like meshup! The main reason is that meshup is full of bugs, which I have had a lot of discussions about and I did not want to replicate inconsistent and unpredicatable behavior into the toolkit. (If you don't believe me just look at the code of meshup, it is a mess).

So please for the love of good do not use meshup anymore as a reference, when things work there it is because the models you are using where originally designed for it and people just changed them around until they looked alright. But that does not mean that the model code is interpreted by meshup in the way you think it is! When things work in meshup it is because you do not see how broken the models are!

I have put a lot of effort into making sure that the toolkit interprets the model files in a predictable and consistent way …

wangchangys commented 2 years ago

@ju6ge ,thank you for your advice, and i tried to use the stl file, the rbdl-toolkit showed right. thanks a lot.

wangchangys commented 2 years ago

@ju6ge Hi, another problem. when i load the " model_deLeva_reduced_meshes_updated.lua" file in the example with rbdl-toolkit, the human shows right. But i want change the direction of the human, and i change the lua file as follows: name = "Pelvis", parent = "ROOT", visuals = {{ src = "meshes/pelvis.obj", dimensions = { 0.2539306288858127, 0.3047167546629752, 0.14015175687556886,}, mesh_center = { 0.0, 0.0, 0.02335862614592814,}, color = { 0.2, 0.7, 0.3,}, },}, joint_frame = { r = { 1.0, 0.0, 0.0,}, E = {{ 0.0, 1.0, 0.0,}, { 1.0, 0.0, 0.0,}, { 0.0, 0.0, 1.0,},}, },

In the Matrix E, i change it from a identity matirx to that one, some bodies of the human will not rotate(I just load the file without animations or kinematics). I think as the Pelvis body rotate, and the following bodies are all connected with it ,thus they should rotate too.

ju6ge commented 2 years ago

That is something you will have to figure out for yourself. I can not provide model support and debugging services. If there are questions to the code or obvious bugs I will respond to the best of my ability, but as I said my time is very limited at the moment. I definitively don't have the time to try and figure out what you are trying to achieve and provide the solution.

wangchangys commented 2 years ago

That is something you will have to figure out for yourself. I can not provide model support and debugging services. If there are questions to the code or obvious bugs I will respond to the best of my ability, but as I said my time is very limited at the moment. I definitively don't have the time to try and figure out what you are trying to achieve and provide the solution.

I understand, thank you