When the simulation is run, a set of .pov and .ini files are saved on disk, so that one can use POVray later to do high-quality rendering of simulations.
Note: the same assets can be used to render animations in real-time in the interactive 3D view of Irrlicht, as explained in demo_IRR_assets.cpp
Textures, colors, asset levels with transformations. This section shows how to add more advanced types of assets.
The following part is very important because this is what makes this demo different from the demo_IRR_assets, that used Irrlicht. We need to create a postprocessor of type chrono::postprocess::ChPovRay and tell him that we are going to export our visualization assets:
Now you have to write the usual while() loop to perform the simulation. Note that before running the loop you need to use pov_exporter.ExportScript(); , and for each timestep you must use pov_exporter.ExportData(); actually this is the instruction that creates the many .dat and .pov files in the output directory.
If you want to generate a .mpeg or .avi animation from the rendered .bmp images, we suggest to use the VirtualDub tool:
In the following we report the entire source code for reference.
#include "chrono/assets/ChVisualShapeBox.h"
#include "chrono/assets/ChCamera.h"
#include "chrono/assets/ChVisualShapeCylinder.h"
#include "chrono/assets/ChVisualShapeModelFile.h"
#include "chrono/assets/ChVisualShapeSphere.h"
#include "chrono/assets/ChTexture.h"
#include "chrono/physics/ChParticleCloud.h"
#include "chrono/physics/ChSystemNSC.h"
#include "chrono/core/ChRandom.h"
#include "chrono_postprocess/ChPovRay.h"
#include "chrono_thirdparty/filesystem/path.h"
int main(int argc, char* argv[]) {
std::cout << "Copyright (c) 2017 projectchrono.org\nChrono version: " << CHRONO_VERSION << std::endl;
if (!filesystem::create_directory(filesystem::path(out_dir))) {
std::cout << "Error creating directory " << out_dir << std::endl;
return 1;
}
" \
light_source { \
<2, 10, -3> \
color rgb<1.2,1.2,1.2> \
area_light <4, 0, 0>, <0, 0, 4>, 8, 8 \
adaptive 1 \
jitter\
} \
object{ Grid(1,0.02, rgb<0.7,0.8,0.8>, rgbt<1,1,1,1>) rotate <0, 0, 90> } \
");
floor->SetFixed(true);
floor->EnableCollision(true);
boxfloor->SetColor(
ChColor(0.3f, 0.3f, 0.6f));
body->SetFixed(true);
for (int j = 0; j < 20; j++) {
smallbox->SetColor(
ChColor(j * 0.05f, 1 - j * 0.05f, 0.0f));
body->AddVisualShape(smallbox,
ChFrame<>(pos, rot));
}
camera->SetAngle(50);
body->AddCamera(camera);
particles->AddCollisionShape(particle_shape);
particles->EnableCollision(true);
for (int np = 0; np < 100; ++np)
particles->AddVisualShape(sphereparticle);
std::cout <<
"time= " << sys.
GetChTime() << std::endl;
}
return 0;
}
@ BULLET
Bullet-based collision detection system.
Definition ChCollisionSystem.h:45
Definition of a visual color.
Definition ChColor.h:30
Representation of a transform with translation and rotation.
Definition ChCoordsys.h:28
Representation of a 3D transform.
Definition ChFrame.h:33
Definition of a 3x3 fixed-size matrix to represent 3D rotations and inertia tensors.
Definition ChMatrix33.h:31
virtual void SetCollisionSystemType(ChCollisionSystem::Type type)
Set the collision detection system used by this Chrono system to the specified type.
Definition ChSystem.cpp:324
int DoStepDynamics(double step_size)
Advance the dynamics simulation by a single time step of given length.
Definition ChSystem.cpp:1632
double GetChTime() const
Get the simulation time of this system.
Definition ChSystem.h:154
void Add(std::shared_ptr< ChPhysicsItem > item)
Attach an arbitrary ChPhysicsItem (e.g.
Definition ChSystem.cpp:196
Class for a physical system in which contact is modeled using a non-smooth (complementarity-based) me...
Definition ChSystemNSC.h:29
Class for post processing implementation that generates scripts for POVray.
Definition ChPovRay.h:33
void SetCustomPOVcommandsScript(const std::string &text)
Set a string (a text block) of custom POV commands that you can optionally append to the POV script f...
Definition ChPovRay.h:166
void ExportData()
This function is used at each timestep to export data formatted in a way that it can be load with the...
void ExportScript()
Export the script that will be used by POV to process all the exported data and render the complete a...
Definition ChPovRay.h:184
void SetLight(ChVector3d location, ChColor color, bool cast_shadow)
Set the default light position and color - will write this in the output .pov file.
void SetTemplateFile(const std::string &filename)
Set the filename of the template for the script generation.
Definition ChPovRay.h:84
void AddAll()
Add all ChPhysicsItem objects in the system to the list of objects to render.
void SetBasePath(const std::string &mpath)
Set the path where all files (.ini, .pov, .assets etc) will be saved.
Definition ChPovRay.h:80
Namespace with classes for the POSTPROCESS module.
Definition ChApiPostProcess.h:54
std::shared_ptr< T > make_shared(Args &&... args)
Replacement for make_shared guaranteed to use operator new rather than placement new in order to avoi...
Definition ChTypes.h:66
Main namespace for the Chrono package.
Definition ChCamera.cpp:17
const std::string & GetChronoOutputPath()
Obtain the path to the output directory for Chrono demos.
Definition ChGlobal.cpp:52
const ChQuaterniond QUNIT(1., 0., 0., 0.)
Constant unit quaternion: {1, 0, 0, 0} , corresponds to no rotation (diagonal rotation matrix)
Definition ChQuaternion.h:431
std::string GetChronoDataFile(const std::string &filename)
Get the full path to the specified filename, given relative to the Chrono data directory (thread safe...
Definition ChGlobal.cpp:37
ChVector3< double > ChVector3d
Alias for double-precision vectors.
Definition ChVector3.h:283
ChQuaterniond QuatFromAngleX(double angle)
Convert from a rotation about X axis to a quaternion.
Definition ChRotation.cpp:188
ChQuaterniond QuatFromAngleY(double angle)
Convert from a rotation about Y axis to a quaternion.
Definition ChRotation.cpp:192