Esempio n. 1
0
def make_body_from_name(partname, root_transformation):
    shape1 = TopoDS.TopoDS_Shape()
    if (mydoc.GetNamedShape(shape1, partname)):
        # Make a ChBody representing the TopoDS_Shape part from the CAD:
        mbody1 = cascade.ChBodyEasyCascade(shape1, # shape
                                           1000,   # density (center of mass & inertia automatically computed)
                                           True,    # mesh for visualization?
                                           False)   # mesh for collision?
        mysystem.Add(mbody1)
        # Move the body as for global displacement/rotation (also mbody1 %= root_frame; )
        mbody1.ConcatenatePreTransformation(root_transformation)
        return mbody1
    else:
        raise ValueError("Warning. Body part name cannot be found in STEP file.\n")
Esempio n. 2
0
# Set the global collision margins. This is expecially important for very large or
# very small objects. Set this before creating shapes. Not before creating mysystem.
chrono.ChCollisionModel.SetDefaultSuggestedEnvelope(0.001)
chrono.ChCollisionModel.SetDefaultSuggestedMargin(0.001)

# create a 3dCAD shape using the OCC OpenCascade API (a torus cut by a cylinder)
my_torus = BRepPrimAPI.BRepPrimAPI_MakeTorus(0.1, 0.02).Shape()
my_cylinder = BRepPrimAPI.BRepPrimAPI_MakeCylinder(0.09, 0.1).Shape()
my_shape = BRepAlgoAPI.BRepAlgoAPI_Cut(my_torus, my_cylinder).Shape()

# use it to make a body with proper center of mass and inertia tensor,
# given the CAD shape. Also visualize it.
my_body = cascade.ChBodyEasyCascade(
    my_shape,  # the CAD shape
    1000,  # the density
    True,  # must collide using the triangle mesh geometry?
    True)  # must be visualized?
mysystem.Add(my_body)

# Create a large cube as a floor.

my_floor = chrono.ChBodyEasyBox(1, 0.2, 1, 1000, True)
my_floor.SetPos(chrono.ChVectorD(0, -0.3, 0))
my_floor.SetBodyFixed(True)
mysystem.Add(my_floor)

my_color = chrono.ChColorAsset(0.2, 0.2, 0.5)
my_floor.AddAsset(my_color)

# ---------------------------------------------------------------------
Esempio n. 3
0
tot_rotation = rotation2 % rotation1  # rotate on 1 then on 2, using quaternion product
root_frame = chrono.ChFrameMovingD(chrono.ChVectorD(0, 0, 0), tot_rotation)

# Retrieve some sub shapes from the loaded model, using
# the GetNamedShape() function, that can use path/subpath/subsubpath/part
# syntax and * or ? wildcards, etc.

mrigidBody1 = 0
mrigidBody2 = 0

if load_ok:

    shape1 = TopoDS.TopoDS_Shape()
    if (mydoc.GetNamedShape(shape1, "Assem1/body1")):

        mbody1 = cascade.ChBodyEasyCascade(shape1, 1000)  # density

        mysystem.Add(mbody1)

        mbody1.SetBodyFixed(True)

        # Move the body as for global displacement/rotation (also mbody1 %= root_frame; )
        mbody1.ConcatenatePreTransformation(root_frame)

        mrigidBody1 = mbody1

    else:
        print("Warning. Desired object not found in document \n")

    shape2 = TopoDS.TopoDS_Shape()
    if (mydoc.GetNamedShape(shape2, "Assem1/body2")):
Esempio n. 4
0
my_material = chrono.ChMaterialSurfaceNSC()
my_material.SetFriction(0.5)

# create a 3dCAD shape using the OCC OpenCascade API (a torus cut by a cylinder)
my_torus    = BRepPrimAPI.BRepPrimAPI_MakeTorus(0.1,0.02).Shape()
my_cylinder = BRepPrimAPI.BRepPrimAPI_MakeCylinder(0.09,0.1).Shape()
my_shape    = BRepAlgoAPI.BRepAlgoAPI_Cut(my_torus, my_cylinder).Shape()

# use it to make a body with proper center of mass and inertia tensor,
# given the CAD shape. Also visualize it.
my_tolerance = cascade.ChCascadeTriangulateTolerances(0.1 ,True,0.5)


my_body = cascade.ChBodyEasyCascade(my_shape,# the CAD shape
                                  1000,             # the density
                                  my_tolerance,      # must visualize triangle mesh geometry?
                                  True,              # must collide?
                                  my_material)       # collision material
mysystem.Add(my_body)

    
# Create a large cube as a floor.

my_floor = chrono.ChBodyEasyBox(1, 0.2, 1, # x y z size
                                1000,       # density
                                True,       # must visualize?
                                True,       # must collide?
                                my_material) # collision material
my_floor.SetPos(chrono.ChVectorD(0,-0.3,0))
my_floor.SetBodyFixed(True)
mysystem.Add(my_floor)