Changing color of body during simulation

22 बार देखा गया
नहीं पढ़े गए पहले मैसेज पर जाएं

Roberto Echeverria

नहीं पढ़ी गई,
17 नव॰ 2021, 8:57:27 am17/11/21
ईमेल पाने वाला ProjectChrono
Dear all,

I am trying to change the color of a body during a simulation. The purpose of this is to mark the bodies as soon as they start a collision.

I see that i can extract all the assets from a body.
First i downcast the shapes using CastToChCylinderShape.
Then the colors should be in the list of assets, but in principle there is no CastToChColor.
On the other hand, i see in the development reference that all classes inherited from ChAsset will be automatically downcasted, how does this work? 

Thanks in advance and regards

Roberto



Radu Serban

नहीं पढ़ी गई,
17 नव॰ 2021, 9:47:52 am17/11/21
ईमेल पाने वाला rob...@gmail.com, ProjectChrono

Roberto,

 

Here’s how I would do something like this (using demo_IRR_collision_trimesh.py as an example):

  • After creating the body, attach a color asset to it and cache the asset:
    color_A = chrono.ChColorAsset()
    color_A.SetColor(chrono.ChColor(0.8, 0.4, 0.4))
    body_A.AddAsset(color_A)

  • In the simulation loop, when desired, modify the color of the color asset and let the Irrlicht app know about the update:

color_updated = False

while(myapplication.GetDevice().run()):

    if not color_updated and mysystem.GetChTime() > 5:

        color_A.SetColor(chrono.ChColor(0.4, 0.4, 0.8))

        myapplication.AssetUpdate(body_A)

        color_updated = True

 

    myapplication.BeginScene()

    myapplication.DrawAll()

    myapplication.DoStep()

    myapplication.EndScene()

--Radu

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/dfcc3cbf-adbb-4592-9a74-278432740420n%40googlegroups.com.

सभी प्रषकों को उत्तर दें
लेखक को उत्तर दें
आगे भेजें
0 नया मैसेज