Hi!

When trying a simple collision case by dropping a cube made from 
ChBodyAuxRef and an imported .stl mesh on top of another trimesh .stl cube, 
they act very strangely. If I change the envelope bullet value to certain 
values (like 0,02) the initial collision is detected, before they merge 
into each other. For other values, the collision is never registered.  I've 
made sure the normals point outward in my .stl mesh, and I've also tried 
with a .obj format with the same result. Is there anything I can try to fix 
this problem?

Thank you!

-- 
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/1521155c-e891-4d33-8cd0-b47798e7353en%40googlegroups.com.
// =============================================================================
// PROJECT CHRONO - http://projectchrono.org
//
// Copyright (c) 2014 projectchrono.org
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found
// in the LICENSE file at the top level of the distribution and at
// http://projectchrono.org/license-chrono.txt.
//
// =============================================================================
// A very simple example that can be used as template project for
// a Chrono::Engine simulator with 3D view.
// =============================================================================

#include "chrono/physics/ChSystemNSC.h"
#include "chrono/physics/ChBodyEasy.h"
#include "chrono/physics/ChInertiaUtils.h"

#include "chrono/geometry/ChTriangleMeshConnected.h"
#include "chrono/assets/ChVisualShapeTriangleMesh.h"
#include "chrono/assets/ChTexture.h"
#include "chrono/core/ChRandom.h"
 
#include "chrono_irrlicht/ChVisualSystemIrrlicht.h"

#include <iostream>
#include <fstream>

using namespace chrono;
//using namespace chrono::geometry;
using namespace chrono::irrlicht;

int main(int argc, char* argv[]) {
    
    // Create a Chrono::Engine physical system + collision system
    ChSystemNSC sys;

    SetChronoDataPath(CHRONO_DATA_DIR);

    ChCollisionModel::SetDefaultSuggestedEnvelope(0.02);
        ChCollisionModel::SetDefaultSuggestedMargin(0.0025);

    sys.SetCollisionSystemType(ChCollisionSystem::Type::BULLET);

    //create surface material
    auto surfacemat = chrono_types::make_shared<ChContactMaterialNSC>();

    auto floorBody = chrono_types::make_shared<ChBodyEasyBox>(20, 1, 20,  // x, 
y, z dimensions
                                                     3000,       // density
                                                     true,       // create 
visualization asset
                                                     true,       // collision 
geometry
                                                     surfacemat // surface 
material
                                                     );
    floorBody->SetPos(ChVector3d(0, -0.5, 0)); 
    floorBody->SetFixed(true);
    
//floorBody->GetVisualShape(0)->SetTexture(GetChronoDataFile("textures/concrete.jpg"));
    sys.Add(floorBody);

    auto surfacemat1 = chrono_types::make_shared<ChContactMaterialNSC>();

    auto block = chrono_types::make_shared<ChBodyEasyBox>(1, 10, 20,  // x, y, 
z dimensions
                                                     3000,       // density
                                                     true,       // create 
visualization asset
                                                     true,       // collision 
geometry
                                                     surfacemat1 // surface 
material
                                                     );
    block->SetPos(ChVector3d(9.5, 5.0, 0));
    block->SetFixed(true);
    sys.Add(block);

    auto surfacemat2 = chrono_types::make_shared<ChContactMaterialNSC>();

    auto block1 = chrono_types::make_shared<ChBodyEasyBox>(2, 0.5, 2,  // x, y, 
z dimensions
                                                     3000,       // density
                                                     true,       // create 
visualization asset
                                                     true,       // collision 
geometry
                                                     surfacemat2 // surface 
material
                                                     );
    block1->SetPos(ChVector3d(0.0, 0.25, 0.0));
    block1->SetFixed(true);
    sys.Add(block1);
    
    
    //Shared contact mat for all meshes

    auto mesh_mat = chrono_types::make_shared<ChContactMaterialNSC>();
    mesh_mat->SetFriction(0.5f);
    mesh_mat->SetRestitution(0.5f);
    //mesh_mat->SetYoungModulus(1e6f);

    // Load the .stl mesh file for the rigid body
    // Create the rigid body based on the .stl mesh

    auto mesh = 
ChTriangleMeshConnected::CreateFromSTLFile("/path_to_file/box.stl", true);

    //mesh->Transform(ChVector3d(0, 0, 0), ChMatrix33<>(1.2));  // scale to a 
different size
    mesh->RepairDuplicateVertexes(1e-9);                      // if meshes are 
not watertight

    // compute mass inertia from mesh 
    double mass;
    ChVector3d cog;
    ChMatrix33<> inertia;
    double density = 1000;
    mesh->ComputeMassProperties(true, mass, cog, inertia);
    ChMatrix33<> principal_inertia_rot;
    ChVector3d principal_I;
    ChInertiaUtils::PrincipalInertia(inertia, principal_I, 
principal_inertia_rot);
    
    auto vish_m = chrono_types::make_shared<ChVisualShapeTriangleMesh>();
    vish_m->SetMesh(mesh);
    vish_m->SetMutable(false);
    vish_m->SetColor(ChColor(1.0f, 0.5f, 0.5f));
    vish_m->SetBackfaceCull(true);
    auto vis_model = chrono_types::make_shared<ChVisualModel>();
    vis_model->AddShape(vish_m);

    auto colli_shape = 
chrono_types::make_shared<ChCollisionShapeTriangleMesh>(mesh_mat, mesh, false, 
false, 0.005);

    auto body = chrono_types::make_shared<ChBodyAuxRef>();

    body->SetFrameCOMToRef(ChFrame<>(cog, principal_inertia_rot));
    body->SetMass(mass * density);
    body->SetInertiaXX(density * principal_I);

    //body->SetPos(ChVector3d(0, 1, 0));
    body->SetFrameRefToAbs(ChFrame<>(ChVector3d(0, 1, 0)));

    sys.Add(body);

    body->AddVisualModel(vis_model);
    body->AddCollisionShape(colli_shape);
    body->EnableCollision(true);

    auto body1 = chrono_types::make_shared<ChBodyAuxRef>();

    body1->SetFrameCOMToRef(ChFrame<>(cog, principal_inertia_rot));
    body1->SetMass(mass * density);
    body1->SetInertiaXX(density * principal_I);

    //body1->SetPos(ChVector3d(0, 10, 0));
    body1->SetFrameRefToAbs(ChFrame<>(ChVector3d(0, 5, 0)));

    sys.Add(body1);

    body1->AddVisualModel(vis_model);
    body1->AddCollisionShape(colli_shape);
    body1->EnableCollision(true);


    // Create the Irrlicht visualization system
    //auto vis = chrono_types::make_shared<ChVisualSystemIrrlicht>();
    ChVisualSystemIrrlicht vis;
    vis.AttachSystem(&sys);
    vis.SetWindowSize(1280, 720);
    vis.SetWindowTitle("STL Mesh Simulation");
    vis.Initialize();
    vis.AddLogo();
    vis.AddSkyBox();
    vis.AddCamera(ChVector3d(3, 2, -4), ChVector3d(0,0,1));
    vis.AddTypicalLights();

    //sys.SetTimestepperType(ChTimestepper::Type::EULER_IMPLICIT_LINEARIZED); 

    // Simulation loop
    while (vis.Run()) {

        vis.BeginScene(true, true, ChColor(0.55f, 0.63f, 0.75f));
        vis.Render();
        vis.EndScene();
        sys.DoStepDynamics(0.005);

        std::cout << "Time: " << sys.GetChTime() << std::endl;
    }

    return 0;
}

Reply via email to