Thank you for your reply. 
Unfortunately I am not able to share this particular mesh, but the 
performance problem is not unique to it. I tried some high poly meshes I 
found online (for example this 
https://sketchfab.com/3d-models/car-model-blender-2be4c41ccc774fc79f3e598e0091e3b9),
 
and saw the same issue. Then I tried a lower poly version of my robot, and 
I got to an acceptable performance (<25ms to render a frame) at less than 
50k polys, which is very low.
Gazebo (with ogre as rendering engine) can handle the big mesh without too 
much trouble.
I will attach a modified version of the assets demo source that reproduces 
this issue.
I am using nvidia driver 510.85.02, Optix 7.2.0 and Chrono 
commit 8626c8bb65fceb59129a003ed916377065cd3a1b (the last one that was 
compatible with Optix 7.2.0).
Kind regards, 
Patrick

On Wednesday, 7 December 2022 at 23:09:13 UTC-8 Patrick Op wrote:

> Hi,
> I am evaluating the viability of project chrono for a robotics simulation 
> application. As part of this, I need to import a large mesh (~1.3 million 
> faces) into my simulation. The whole thing uses the same, single color 
> visual material.
>
> auto body= std::make_shared<ChBodyEasyMesh>( 
>                       filename,
>                       7000,
>                       true,
>                       true,
>                       false,
>                       std::make_shared<ChMaterialSurfaceSMC>());
>
> This works fine. However, it really slows down my camera sensor. I have a 
> single camera sensor (ChCameraSensor) facing the mesh.
>
> auto cam = chrono_types::make_shared<ChCameraSensor>(floorBody,
>                                                            40,
>                                                            pose,
>                                                            width,
>                                                            height,
>                                                            1.4, 
>                                                            1,
>                                                           
>  CameraLensModelType::PINHOLE, 
>                                                            false);
>
> Rendering a frame (specifically, the ChSensorManager::Update() call) takes 
> over 100ms, where it only takes a few milliseconds if I have some simple 
> cubes in the frame.
> I have tried the following things to speed it up:
> 1. Reduce camera resolution by 10x, this had no effect!
> 2. Add more cameras to see if it scales at all, this had no effect!
> 3. Increased MaxEngines on the SensorManager, no effect
> 4. Set RayRecursions on the SensorManager to 0, no effect
> 5. Adding no extra filters to the camera, no effect
> 6. Use ChVisualSystemIrrlicht to visualize, this performed even worse
> 7. Run on a powerful desktop with a high end GPU, this performed slightly 
> better, but not by much
> 8. nvidia-smi shows that the GPU is not being utilized anywhere near 100%
>
> I am really surprised by this, as the settings on the cameras do not seem 
> to influence this at all. Is there something I can do about this, or can 
> Chrono Sensors just not handle large meshes like that?
> What is it the sensor manager doing with all this time?
>
> Kind regards, 
> Patrick
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/projectchrono/191c7a20-0cfb-496b-a1f4-551a1f4c9b96n%40googlegroups.com.
#include "chrono/physics/ChSystemNSC.h"
#include "chrono_sensor/ChSensorManager.h"
#include "chrono_sensor/sensors/ChCameraSensor.h"
#include "chrono_sensor/filters/ChFilterVisualize.h"
#include "chrono/physics/ChBodyEasy.h"
#include "chrono/physics/ChLinkMate.h"
#include "chrono/assets/ChTexture.h"
#include "chrono/core/ChRealtimeStep.h"


using namespace chrono;
using namespace chrono::sensor;
const unsigned int width = 1200;
const unsigned int height = 1000;
const std::string meshfile = "/home/patrick/gztest/teslaobj.obj"; 

int main(int argc, char* argv[]) {
        // Set path to Chrono data directory
        SetChronoDataPath(CHRONO_DATA_DIR);

        // Create a Chrono physical system
        ChSystemNSC sys;

        // Create floor to anchor the camera to
        auto floorBody = std::make_shared<ChBodyEasyBox>(10, 2, 10,  // x, y, z dimensions
                        3000,       // density
                        true,       // create visualization asset
                        false       // no collision geometry
                        );
        floorBody->SetPos(ChVector<>(0, -2, 0));
        floorBody->SetBodyFixed(true);

        sys.Add(floorBody);
      
        // create a simple red material
        auto material = std::make_shared<ChVisualMaterial>();
        material->SetAmbientColor(ChColor(1,0,0));
        material->SetDiffuseColor(ChColor(1,0,0));
        material->SetSpecularColor(ChColor(1,0,0));

        // add a high poly mesh (from here, converted using blender https://sketchfab.com/3d-models/car-model-blender-2be4c41ccc774fc79f3e598e0091e3b9)
        auto addMesh = [&](const std::string& name) {
                auto imported= std::make_shared<ChBodyEasyMesh>(
                                name,
                                7000, 
                                true,
                                true,
                                false,
                                std::make_shared<ChMaterialSurfaceSMC>());
                imported->SetPos(ChVector<>(0, 0, 0));
                imported->GetVisualShape(0)->AddMaterial(material);
                imported->SetBodyFixed(true);
                sys.Add(imported);
        };
        addMesh(meshfile);


        // Add sensor manager, light, and camera
        auto manager = chrono_types::make_shared<ChSensorManager>(&sys);
        manager->scene->AddPointLight({-10.f, 0.0f, 0.f}, {2.2f / 2, 1.8902f / 2, 1.7568f / 2}, 50.0f);
        auto addCam = [&] (const std::string& name, const auto& pose) {

                auto cam = chrono_types::make_shared<ChCameraSensor>(floorBody,
                                40,
                                pose,
                                width,
                                height,
                                1.4,
                                1,
                                CameraLensModelType::PINHOLE,
                                false);
                cam->PushFilter(chrono_types::make_shared<ChFilterVisualize>(2400, 2000, name));
                manager->AddSensor(cam);
        };
        addCam("testcam",chrono::ChFrame<double> {{-8.f, 5.0f, 0.f}, {1.5 / 2, 1.8902f / 2, 1.7568f / 2}});


        // Run the render loop
        ChRealtimeStepTimer realtime_timer;
        const double step_size = 0.025;

        while (true) {

                auto start = std::chrono::steady_clock::now();
                // This call is slow!
                manager->Update();

                sys.DoStepDynamics(step_size);

                realtime_timer.Spin(step_size);
                auto end = std::chrono::steady_clock::now();
                std::cout<< "frame took " << std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count()<< " ms" << std::endl;
        }

        return 0;
}

Reply via email to