LDraw.org Discussion Forums

Full Version: Seeking a ldcad animation script method
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(2021-09-29, 4:52)David Manley Wrote: [ -> ]Hmmm, something is not quite right

Corrected with a little bit of coding kragle. I want to make the fix a bit less of a hack and also incorporate the ability to animate crossed 4 bar linkages. Once I've done that, I will release an update.

[Image: good_linkage.gif]
(2021-09-29, 22:45)David Manley Wrote: [ -> ]So presumably I should be using ani:getFrameTime() and ani:getLength() instead of ani:getFrameNr() and ani:getFrameCount()?

If so, is may be worth reflecting the same approach in your Scripting examples page? I used getFrameNr() and getFrameCount() on the basis of the sample examples page. Or is your suggestion something else altogether?

You are right I used the wrong method in the example too, I have corrected it.

Thanks for pointing it out.
I've updated the zip file. The Lua script in it should now deal with both uncrossed and crossed linkage configurations. The zip file also contains some sample LDR files used to test the script. If you encounter any issues when running the script, please post details in this thread.

Here is a sample "crossed" linkage:

[Image: linkage_crossed.png]

You need to explicitly identify whether the model being animated is an uncrossed or crossed configuration. This is done via the macro "scripts/linkages/Rotation Parameters". The macro will prompt for a series of different settings (see image below). The dialog circled in red is the one in which the linkage model configuration is identified (by default the scripts assume an uncrossed model).

[Image: rotation_parameters_prompt.png]

I'm sure that there should be a way for the script to calculate whether a model is uncrossed or crossed. Something based around atan2. I tried working it out but in the end I couldn't so I'm made it a value which the user needs to identify.

Regards,

David
(2021-10-03, 6:31)David Manley Wrote: [ -> ]Here is a sample "crossed" linkage:

With crossed you mean it's at the underside?

If so you could calculate the relative y coordinate and if it's a positive one it's crossed (y being neg up in LDraw).
(2021-10-03, 19:35)Roland Melkert Wrote: [ -> ]With crossed you mean it's at the underside?

If so you could calculate the relative y coordinate and if it's a positive one it's crossed (y being neg up in LDraw).

The term "crossed" comes from the original reference material I used as the basis for the animation script.

My interpretation of this term is that at any stage the driver bar (green beam) is under (i.e. the driver rotation angle is > 180 degrees and < 360 degrees) the invariant bar (white beam), if the driven bar's (red beam) unconstrained rotation point is also under the invariant bar then this is a "crossed" scenario.

Having just written the description in the prior paragraph, I think I have managed to answer my own question! So I'm now going to experiment with the code a bit more to try to remove the need to explicitly specify whether something is crossed or uncrossed.

That being said, I've a suspicion the animation aberration for "crossed" bars may be a consequence of the formula given in the reference material. The formula as originally written didn't seem to cope with obtuse scalene triangles so I ended up using an alternative calculation to derive the required angle.

David
I've updated the zip file with a newer Lua script. The primary visible differences are;
  • that it now works out whether the configuration is "crossed" or "uncrossed", so you no longer have to tell it
  • the dialog to select crossed/uncrossed was put into a separate menu option and an "automatic" option added (which is the default). The automatic option will work out if the configuration is crossed or uncrossed but just in case it miscalculates (always a possibility!), the crossed/uncrossed setting can be manually set to override the automatic option
  • the animation will now display properly when the start position is anywhere in the animation sequence

Other differences within the code are to (a) support a different approach for working out the between frame part rotation and (b) use a slightly differently nomenclature for the parts (e.g. "crank" as opposed to "bar 1").

This has been a useful exercise for me. I've learnt a useful amount more about LDCAD's Lua scripting plus I got to exercise my trigonometry brain, last used many years ago! My thanks to Roland for his helpful posts and guidance which helped me improve the script.

Regards,

David

P.S. I had not realised until earlier today that you could make the animation run more slowly/quickly by clicking the slow animation button/faster animation button multiple times. You live and learn!
(2021-10-08, 5:44)David Manley Wrote: [ -> ]I've updated the zip file with a newer Lua script. The primary visible differences are;
  • that it now works out whether the configuration is "crossed" or "uncrossed", so you no longer have to tell it
  • the dialog to select crossed/uncrossed was put into a separate menu option and an "automatic" option added (which is the default). The automatic option will work out if the configuration is crossed or uncrossed but just in case it miscalculates (always a possibility!), the crossed/uncrossed setting can be manually set to override the automatic option
  • the animation will now display properly when the start position is anywhere in the animation sequence

Other differences within the code are to (a) support a different approach for working out the between frame part rotation and (b) use a slightly differently nomenclature for the parts (e.g. "crank" as opposed to "bar 1").

This has been a useful exercise for me. I've learnt a useful amount more about LDCAD's Lua scripting plus I got to exercise my trigonometry brain, last used many years ago! My thanks to Roland for his helpful posts and guidance which helped me improve the script.

Regards,

David

P.S. I had not realised until earlier today that you could make the animation run more slowly/quickly by clicking the slow animation button/faster animation button multiple times. You live and learn!

Thank you very much 
Now the final aninamtion is perfect 
Thanks again


Here comes a new problem in a new assembly(i'm confussed at how to subfile the assembly,tried several times counld't make the right animation . at last , i find maybe it's not the matter about how to  subfile the assembly )

the left rocker should move follow the right rocker , but I tried , could't make it 


i'v upload  the files to googledrive click here[url=https://drive.google.com/drive/folders/1LM9CYmzlR9ljawToKsb7hOaOSYmktIkp?usp=sharing][/url]

Looking forward to your help
Pages: 1 2