Skip to content

Commit b29ce05

Browse files
committed
SolidMaterial, MassProperties, VisualMaterial in Solid(..) and VisualMaterial in Visual(..) improved to handle corner cases:
- SolidMaterial=="" is treated as SolidMaterial = nothing - VisualMaterial=="" is treated as Shapes.VisualMaterial() - massProperties==nothing && solidMaterial==nothing is treated as MassProperties(), that is massless.
1 parent 37b5863 commit b29ce05

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/Composition/massPropertiesComputation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function addOrSubtractMassPropertiesOfChildToRoot!(obj_root::Object3D{F}, obj_ch
104104
m = m_root + m_child
105105

106106
# common center of mass (parent + child)
107-
@assert(m > 0.0)
107+
@assert(m >= 0.0)
108108
rCM = (m_root * rCM_root + m_child * rCM_child_new)/m
109109

110110
# I: substract new common mass multiplied with skew matrices of

src/Shapes/massProperties.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct MassProperties{F <: Modia3D.VarFloatType} <: Modia3D.AbstractMassProperti
1515
#---------------- different constructors for MassProperties -----------------
1616
# Constructor 0: takes mass, centerOfMass and inertiaMatrix as input values
1717
function MassProperties{F}(mass::Number, centerOfMass::AbstractVector, inertiaMatrix::AbstractMatrix) where F <: Modia3D.VarFloatType
18-
@assert(mass > 0.0)
18+
@assert(mass >= 0.0)
1919
new(mass, centerOfMass, inertiaMatrix)
2020
end
2121
end

src/Shapes/solid.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Generate a [Solid](@ref) with physical behavior of a rigid body with mass, visua
2424
computed from `shape` and `solidMaterial`. It is also possible to define only the mass of the solid and compute the
2525
center of mass and inertia tensor from `shape` (e.g. `MassPropertiesFromShapeAndMass(mass=4.5)`) or explicitly
2626
define all mass properties (e.g. `MassProperties(mass=4.5, centerOfMass=[1.0,2.0,3.0], Ixx=4.0, Iyy=5.0, Izz=6.0,
27-
Ixy=4.5, Ixz=4.6, Iyz=5.5)`).
27+
Ixy=4.5, Ixz=4.6, Iyz=5.5)`).
2828
2929
- `collision`: Defines if the solid is considered in [Collision Handling](@ref). `collision=true` requires definition
3030
of `shape`, mass properties (defined by `solidMaterial` or `massProperties`) and contact material (defined by
@@ -105,20 +105,25 @@ struct Solid{F <: Modia3D.VarFloatType} <: Modia3D.AbstractObject3DFeature
105105
contactMaterial = ""
106106
end
107107

108+
if typeof(solidMaterial) == String && solidMaterial == ""
109+
solidMaterial = nothing
110+
end
111+
108112
if typeof(solidMaterial) == String
109113
solidMaterial = solidMaterialPalette[1][solidMaterial]
110114
end
111115

112-
if typeof(visualMaterial) == String
113-
visualMaterial = Shapes.visualMaterialPalette[visualMaterial]
116+
if typeof(visualMaterial) == String
117+
visualMaterial = visualMaterial == "" ? Shapes.VisualMaterial() : Shapes.visualMaterialPalette[visualMaterial]
114118
end
115119

116120
if typeof(shape) == FileMesh
117121
(shape.centroid, shape.shortestEdge, shape.longestEdge, shape.objPoints, shape.facesIndizes) = getMeshInfos(shape.filename, shape.scaleFactor)
118122
(shape.volume, shape.centroidAlgo, shape.inertia) = computeMassProperties(shape.objPoints, shape.facesIndizes; bodyCoords=false)
119123
end
120124

121-
massProperties = createMassProperties(F, massProperties, shape, solidMaterial)
125+
massProperties = isnothing(massProperties) && isnothing(solidMaterial) ? MassProperties{F}() : createMassProperties(F, massProperties, shape, solidMaterial)
126+
122127
contactSphereRadius::Union{Nothing,F} = isnothing(contactSphereRadius) || F(contactSphereRadius) <= F(0) ? nothing : F(contactSphereRadius)
123128
(isFlat, contactSphereRadius) = setContactSphereRadius(shape, contactSphereRadius, F)
124129
new(shape, solidMaterial, massProperties, collision, contactMaterial, setCollisionSmoothingRadius(shape, F(collisionSmoothingRadius)), visualMaterial, isFlat, contactSphereRadius)

src/Shapes/visual.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
convertStringToVisualMaterial(visualMaterial::Shapes.VisualMaterial) = visualMaterial
22

3-
convertStringToVisualMaterial(visualMaterial::AbstractString) = Shapes.visualMaterialPalette[visualMaterial]
3+
convertStringToVisualMaterial(visualMaterial::AbstractString) = visualMaterial == "" ? Shapes.VisualMaterial() : Shapes.visualMaterialPalette[visualMaterial]
4+
45

56
"""
67
Visual(;

0 commit comments

Comments
 (0)