edit dynamical object material via LUA script

Typically: "How do I... ", "How can I... " questions
Post Reply
gustavo.duarte
Posts: 7
Joined: 27 Feb 2020, 18:46

edit dynamical object material via LUA script

Post by gustavo.duarte »

is it possible to edit the dynamical object material via script, without remote api?
my idea is to create an interface with 4 buttons, each button will set a friction coefficient of the object

i use example : simple Ackermann

Code: Select all

function sysCall_threadmain()
    -- Put some initialization code here:
    -- Retrieving of some handles and setting of some initial values:
    steeringLeft=sim.getObjectHandle('nakedCar_steeringLeft')
    steeringRight=sim.getObjectHandle('nakedCar_steeringRight')
    motorLeft=sim.getObjectHandle('nakedCar_motorLeft')
    motorRight=sim.getObjectHandle('nakedCar_motorRight')
    
    d_right=sim.getObjectHandle('nakedCar_frontRightWheel_respondable')
    d_left=sim.getObjectHandle('nakedCar_frontLeftWheel_respondable')
    r_left=sim.getObjectHandle('nakedCar_rearLeftWheel_respondable')
    r_right=sim.getObjectHandle('nakedCar_rearRightWheel_respondable')
    
    r1= sim.setShapeMaterial(d_right, sim.bullet_body_friction (0.3))
    r2= sim.setShapeMaterial(d_left, sim.bullet_body_friction (0.3))
    r3= sim.setShapeMaterial(r_right, sim.bullet_body_friction (0.3))
    r4= sim.setShapeMaterial (r_left, sim.bullet_body_friction (0.3))

Lua runtime error : attempt to call field 'bullet_body_friction' (a number value)


Gustavo Duarte, Brazil.

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: edit dynamical object material via LUA script

Post by coppelia »

Hello Gustavo,

have a look at the sim.setEngineBoolParameter, sim.setEngineFloatParameter and sim.setEngineInt32Parameter, and the engine parameter identifiers.

But keep in mind that you can't change material properties once simulation has started. So you will have to call above API functions from within an add-on, or customization script.

Cheers

Ark27
Posts: 9
Joined: 07 Jun 2020, 12:19

Re: edit dynamical object material via LUA script

Post by Ark27 »

Hi,
I am getting the following error and I have tried my best to fix this but unfortunately I am unable to fix it.
This worked in the previous version (VREP).
One of the function's argument type is not correct. (in function 'sim.setEngineFloatParam')
stack traceback:
[C]: in function 'sim.setEngineFloatParameter'


Code Lines:

Code: Select all

sim.setEngineFloatParam(sim.vortex_body_primlinearaxisfriction,LHFingerRespondable,Friction)
sim.setEngineFloatParam(sim.vortex_body_seclinearaxisfriction,LHFingerRespondable,Friction)
sim.setEngineFloatParam(sim.vortex_body_primangularaxisfriction,LHFingerRespondable,Friction)
sim.setEngineFloatParam(sim.vortex_body_secangularaxisfriction,LHFingerRespondable,Friction)
sim.setEngineFloatParam(sim.vortex_body_normalangularaxisfriction,LHFingerRespondable,Friction)
sim.setEngineInt32Param(sim.vortex_body_primlinearaxisfrictionmodel,LHFingerRespondable,sim.vortex_bodyfrictionmodel_scaledbox)
sim.setEngineInt32Param(sim.vortex_body_seclinearaxisfrictionmodel,LHFingerRespondable,sim.vortex_bodyfrictionmodel_scaledbox)
sim.setEngineInt32Param(sim.vortex_body_primangulararaxisfrictionmodel,LHFingerRespondable,sim.vortex_bodyfrictionmodel_scaledbox)
sim.setEngineInt32Param(sim.vortex_body_secmangulararaxisfrictionmodel,LHFingerRespondable,sim.vortex_bodyfrictionmodel_scaledbox)
sim.setEngineInt32Param(sim.vortex_body_normalmangulararaxisfrictionmodel,LHFingerRespondable,sim.vortex_bodyfrictionmodel_scaledbox)

Any help to fix this is really appreciated. And if you need more info please let me know!!
Thanks

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: edit dynamical object material via LUA script

Post by coppelia »

Make sure you identify which line is generating that error exactly (there must be a line number in the error message). Then, before calling the incriminating function, simply print the arguments to the status bar with print: then you will see if maybe something is wrong with the arguments.

Cheers

Post Reply