1#-------------------------------------------------------------------------------
2# Name:        pychrono example
3# Purpose:
4#
5# Author:      Alessandro Tasora
6#
7# Created:     1/01/2019
8# Copyright:   (c) ProjectChrono 2019
9#
10#
11# This file shows how to use POV ray for postprocessing, thanks to the
12# utility functions in the unit_POSTPROCESS of Chrono::Engine.
13#
14#-------------------------------------------------------------------------------
15
16print ("Third tutorial: use the postprocess module.");
17
18
19# Load the Chrono::Engine core module and the postprocessing module!
20import pychrono as chrono
21import pychrono.postprocess as postprocess
22
23# We will create two directories for saving some files, we need this:
24import os
25
26
27# Create a physical system,
28my_system = chrono.ChSystemNSC()
29my_systemB = my_system
30
31# Create a body
32body_1= chrono.ChBodyAuxRef()
33my_system.Add(body_1)
34
35# Attach a visualization asset to the body (ex.: a sphere)
36myasset = chrono.ChSphereShape()
37myasset.GetSphereGeometry().rad =0.2
38body_1.GetAssets().push_back(myasset)
39
40# Assets can be shared, ex. to save memory...
41body_2= chrono.ChBodyAuxRef()
42body_2.SetPos(chrono.ChVectorD(0.5,0,0))
43my_system.Add(body_2)
44body_2.GetAssets().push_back(myasset)
45
46#
47# Create an exporter to POVray !!!
48#
49print(chrono.GetChronoDataFile("_template_POV.pov"))
50
51pov_exporter = postprocess.ChPovRay(my_system)
52
53# Important: set where the template is (this path depends to where you execute this script,
54# ex.here we assume you run it from src/demo/python/postprocess/ )
55pov_exporter.SetTemplateFile  ("../../../../data/_template_POV.pov")
56
57# Set the path where it will save all .pov, .ini, .asset and .dat files,
58# this directory will be created if not existing. For example:
59pov_exporter.SetBasePath("povray_pychrono_generated")
60
61
62
63
64 # Tell selectively which physical items you want to render, or use AddAll()
65pov_exporter.Add(body_1)
66pov_exporter.Add(body_2)
67
68
69 # 1) Create the two .pov and .ini files for POV-Ray (this must be done
70 #    only once at the beginning of the simulation).
71pov_exporter.ExportScript()
72
73 # Perform a short simulation
74while (my_system.GetChTime() < 0.2) :
75
76    my_system.DoStepDynamics(0.01)
77
78    print ('time=', my_system.GetChTime() )
79
80    # 2) Create the incremental nnnn.dat and nnnn.pov files that will be load
81    #    by the pov .ini script in POV-Ray (do this at each simulation timestep)
82    pov_exporter.ExportData()
83
84
85
86# That's all! If all worked ok, this python script should
87# have created a  "rendering_frames.pov.ini"  file that you can
88# load in POV-Ray, then when you press 'RUN' you will see that
89# POV-Ray will start rendering a short animation, saving the frames
90# in the directory 'anim'.
91
92
93