Beispiel #1
0
        protected override bool Initialize()
        {
            if (Material1 == null || Material2 == null)
            {
                Debug.LogWarning(name + ": Trying to create contact material with at least one unreferenced ShapeMaterial.", this);
                return(false);
            }

            agx.Material        m1  = Material1.GetInitialized <ShapeMaterial>().Native;
            agx.Material        m2  = Material2.GetInitialized <ShapeMaterial>().Native;
            agx.ContactMaterial old = GetSimulation().getMaterialManager().getContactMaterial(m1, m2);
            if (old != null)
            {
                Debug.LogWarning(name + ": Material manager already contains a contact material with this material pair. Ignoring this contact material.", this);
                return(false);
            }

            m_contactMaterial = GetSimulation().getMaterialManager().getOrCreateContactMaterial(m1, m2);

            if (FrictionModel != null)
            {
                m_contactMaterial.setFrictionModel(FrictionModel.GetInitialized <FrictionModel>().Native);
                // When the user changes friction model type (enum = BoxFriction, ScaleBoxFriction etc.)
                // the friction model object will create a new native instance. We'll receive callbacks
                // when this happens so we can assign it to our native contact material.
                FrictionModel.OnNativeInstanceChanged += OnFrictionModelNativeInstanceChanged;
            }

            return(true);
        }
 private Node GetOrCreateMaterial(agx.Material material)
 {
     return(GetOrCreateNode(NodeType.Material,
                            material.getUuid(),
                            true,
                            () => m_materials.Add(material.getUuid(), material)));
 }
Beispiel #3
0
        public ShapeMaterial RestoreLocalDataFrom(agx.Material native)
        {
            Density           = Convert.ToSingle(native.getBulkMaterial().getDensity());
            YoungsWireStretch = Convert.ToSingle(native.getWireMaterial().getYoungsModulusStretch());
            YoungsWireBend    = Convert.ToSingle(native.getWireMaterial().getYoungsModulusBend());

            return(this);
        }
Beispiel #4
0
        public static void AddContactMaterial(string a, string b, double restitution, double friction, double youngsModulus)
        {
            var material_A       = new agx.Material(a);
            var material_B       = new agx.Material(b);
            var contact_material = new agx.ContactMaterial(material_A, material_B);

            contact_material.setFrictionCoefficient(restitution);
            contact_material.setRestitution(friction);
            contact_material.setYoungsModulus(youngsModulus);
            sim_Instance.add(material_A);
            sim_Instance.add(material_B);
            sim_Instance.add(contact_material);
        }
Beispiel #5
0
        /// <summary>
        /// Creates temporary native instance to be added to native
        /// geometries to calculate mass and inertia.
        /// </summary>
        /// <returns></returns>
        public agx.Material CreateTemporaryNative()
        {
            // Use current if we haven't been destroyed.
            if (Native != null)
            {
                return(Native);
            }

            agx.Material tmpMaterial = new agx.Material(name);
            m_material = tmpMaterial;
            Utils.PropertySynchronizer.Synchronize(this);
            m_material = null;
            return(tmpMaterial);
        }
Beispiel #6
0
        private ShapeMaterial RestoreShapeMaterial(ShapeMaterial currentShapeMaterial, agx.Material material)
        {
            if (material == null)
            {
                return(null);
            }

            var materialNode = m_tree.GetNode(material.getUuid());
            // If another shape material has been assigned to the object it's
            // possible to detect that here, e.g.;
            //     materialNode.Asset != null &&
            //     currentShapeMaterial != null &&
            //     materialNode.Assset != currentShapeMaterial
            // For now we're taking the node's asset because the material UUID
            // references the object we're currently processing.
            var refMaterial = materialNode.Asset != null ?
                              materialNode.Asset as ShapeMaterial :
                              currentShapeMaterial;

            return(FileInfo.ObjectDb.GetOrCreateAsset(refMaterial,
                                                      FindName(material.getName(),
                                                               materialNode.Type.ToString()),
                                                      m =>
            {
                m.RestoreLocalDataFrom(material);
                materialNode.Asset = m;
            }));
        }
Beispiel #7
0
 public override void Destroy()
 {
     m_material = null;
 }
Beispiel #8
0
        protected override bool Initialize()
        {
            m_material = new agx.Material(name);

            return(true);
        }