Beispiel #1
0
        /// <summary>
        /// Gets the <see cref="MaterialProperties"/> for the given rigid body, position and shape
        /// feature.
        /// </summary>
        /// <param name="body">The rigid body.</param>
        /// <param name="positionLocal">
        /// The local position on the rigid body for which the material properties should be returned.
        /// </param>
        /// <param name="featureIndex">
        /// The index of the shape feature from which the material properties are needed. For a
        /// <see cref="CompositeShape"/> the feature index is the index of the child of the composite
        /// shape. For a <see cref="TriangleMeshShape"/> the feature index is the index of a triangle.
        /// </param>
        /// <returns>
        /// The <see cref="MaterialProperties"/> of the given rigid body at the given position and
        /// child feature.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="body"/> is <see langword="null"/>.
        /// </exception>
        public MaterialProperties GetProperties(RigidBody body, Vector3 positionLocal, int featureIndex)
        {
            if (body == null)
            {
                throw new ArgumentNullException("body");
            }

            // No child feature - use default material.
            if (featureIndex < 0)
            {
                return(DefaultMaterial.GetProperties(body, positionLocal, featureIndex));
            }

            IMaterial material = null;

            // Try to find entry in list.
            if (featureIndex < Materials.Count)
            {
                material = Materials[featureIndex];
            }

            if (material == null)
            {
                // Check if feature is a rigid body.
                var compositeShape = body.Shape as CompositeShape;
                if (compositeShape != null && featureIndex < compositeShape.Children.Count)
                {
                    var childBody = compositeShape.Children[featureIndex] as RigidBody;
                    if (childBody != null)
                    {
                        material = childBody.Material;
                    }
                }
            }

            if (material == null)
            {
                // Fallback: Use DefaultMaterial.
                material = DefaultMaterial;
            }

            return(material.GetProperties(body, positionLocal, featureIndex));
        }