imported obj does not change color

37 views
Skip to first unread message

Guido, Francesco Ritelli

unread,
Oct 2, 2022, 8:36:12 AM10/2/22
to ProjectChrono
Hello,
new to Project Chrono. I have been messing around to familiarize myself with this great project.

I'm unable to change color of objects imported as mesh (obj), here is a sample code. Green line is where I try to set the color.
What am I 'missing? No matter what color I set, it always shows white.

import pychrono.core as ch
import pychrono.irrlicht as chirr
import pychrono.cascade as cascade
from OCC.Core import TopoDS
import math

# Create system
sys = ch.ChSystemSMC()

# Create bodies
# NOTE: pendulum pin
body_pendulum_pin = ch.ChBody()
sys.Add(body_pendulum_pin)
body_pendulum_pin.SetMass(10)
body_pendulum_pin.SetInertiaXX(ch.ChVectorD(20, 20, 20))
body_pendulum_pin.SetPos(ch.ChVectorD(0, 0, 0))
body_pendulum_pin.SetRot(ch.ChMatrix33D(ch.ChVectorD(1, 0, 0),
ch.ChVectorD(0, 0, -1),
ch.ChVectorD(0, 1, 0)))
body_pendulum_pin.SetBodyFixed(True)

mesh_pin = ch.ChTriangleMeshConnected()
mesh_pin.LoadWavefrontMesh(ch.GetChronoDataFile('models/my_models/pendulum_pin.obj'))

vis_shape_pin = ch.ChTriangleMeshShape()
vis_shape_pin.SetMesh(mesh_pin)
vis_shape_pin.SetColor(ch.ChColor(0.5, 0.5, 0.5))
body_pendulum_pin.AddVisualShape(vis_shape_pin)

# ------------------------------------------
# Create the Irrlicht run-time visualization
# ------------------------------------------
vis = chirr.ChVisualSystemIrrlicht()
vis.AttachSystem(sys)
vis.SetWindowSize(1280,720)
vis.SetWindowTitle('Single pendulum')
vis.Initialize()
vis.AddCamera(ch.ChVectorD(0, 0, 0.2), ch.ChVectorD(0, 0, 0))
vis.AddTypicalLights()

# ------------------
# Run the simulation
# ------------------
while vis.Run() :
vis.BeginScene()
vis.Render()
vis.EndScene()
sys.DoStepDynamics(0.05)

Reply all
Reply to author
Forward
0 new messages