Example #1
0
        private void ShowForces(EventType eventType)
        {
            if (m_textLabelStyle == null)
            {
                m_textLabelStyle           = new GUIStyle(GUI.Skin.label);
                m_textLabelStyle.alignment = TextAnchor.MiddleLeft;

                var fonts = Font.GetOSInstalledFontNames();
                foreach (var font in fonts)
                {
                    if (font == "Consolas")
                    {
                        m_textLabelStyle.font = Font.CreateDynamicFontFromOSFont(font, 24);
                        break;
                    }
                }
            }

            var textColor  = Color.Lerp(Color.black, Color.white, 1.0f);
            var valueColor = Color.Lerp(Color.green, Color.white, 0.45f);
            Func <string, agx.Vec3, GUIContent> Vec3Content = (name, v) =>
            {
                return(GUI.MakeLabel(string.Format("{0} [{1}, {2}, {3}] kN",
                                                   GUI.AddColorTag(name, textColor),
                                                   GUI.AddColorTag(v.x.ToString("0.00").PadLeft(7, ' '), valueColor),
                                                   GUI.AddColorTag(v.y.ToString("0.00").PadLeft(7, ' '), valueColor),
                                                   GUI.AddColorTag(v.z.ToString("0.00").PadLeft(7, ' '), valueColor))));
            };

            var shovel            = m_shovels[0].Native;
            var penetrationForce  = new agx.Vec3();
            var penetrationTorque = new agx.Vec3();

            Native.getPenetrationForce(shovel, ref penetrationForce, ref penetrationTorque);
            var separationForce = -Native.getSeparationContactForce(shovel);
            var deformerForce   = -Native.getDeformationContactForce(shovel);
            var contactForce    = -Native.getContactForce(shovel);

            GUILayout.Label(Vec3Content("Penetration force:", 1.0E-3 * penetrationForce), m_textLabelStyle);
            GUILayout.Space(4);
            GUILayout.Label(Vec3Content("Separation force: ", 1.0E-3 * separationForce), m_textLabelStyle);
            GUILayout.Space(4);
            GUILayout.Label(Vec3Content("Deformer force:   ", 1.0E-3 * deformerForce), m_textLabelStyle);
            GUILayout.Space(4);
            GUILayout.Label(Vec3Content("Contact force:    ", 1.0E-3 * contactForce), m_textLabelStyle);
        }
Example #2
0
        private static void PostBuildInternal(string agxDynamicsPath,
                                              string agxPluginPath,
                                              FileInfo targetExecutableFileInfo,
                                              string targetDataPath)
        {
            // Some versions of Unity 2019.3 (fixed in 2019.3.9) isn't consistent
            // where native modules are located. E.g., if Burst is installed, some
            // dll's will be created in <project>_Data/Plugins/x86_64 and if AGX
            // dll's are in <project>_Data/Plugins, the dll's wont load.
            //     - Unity 2019.3 and later:   <project>_Data/Plugins/x86_64
            //     - Unity 2019.2 and earlier: <project>_Data/Plugins
            if (!Directory.Exists(AGXUnity.IO.Environment.GetPlayerPluginPath(targetDataPath)))
            {
                Directory.CreateDirectory(AGXUnity.IO.Environment.GetPlayerPluginPath(targetDataPath));
            }

            // Assuming all dlls are present in the plugins directory and that
            // "Components" are in a folder named "agx" in the plugins directory.
            // Unity will copy the dlls.
            var sourceDirectory      = new DirectoryInfo(IO.Utils.AGXUnityPluginDirectoryFull + Path.DirectorySeparatorChar + "agx");
            var destinationDirectory = new DirectoryInfo(AGXUnity.IO.Environment.GetPlayerAGXRuntimePath(targetDataPath));

            Debug.Log(GUI.AddColorTag("Copying AGX runtime data from: " +
                                      IO.Utils.AGXUnityPluginDirectory +
                                      Path.DirectorySeparatorChar +
                                      "agx" +
                                      " to " +
                                      destinationDirectory.FullName, Color.green));
            CopyDirectory(sourceDirectory, destinationDirectory);

            // Deleting all .meta-files that are present in our "agx" folder.
            foreach (var fi in destinationDirectory.EnumerateFiles("*.meta", SearchOption.AllDirectories))
            {
                fi.Delete();
            }

            VerifyBuild(targetDataPath);

            CheckGenerateEncryptedRuntime(targetExecutableFileInfo);
        }
Example #3
0
        /// <summary>
        /// Read data given root/robot element in a XML document.
        /// </summary>
        /// <param name="root"></param>
        public override void Read(XElement root, bool optional)
        {
            // Reading mandatory 'name'.
            base.Read(root, false);

            // Reading material declarations - materials that can be referenced with name.
            var materials = new List <Material>();

            foreach (var materialElement in root.Elements("material"))
            {
                var material = Instantiate <Material>(materialElement);

                // Material reference under the robot?
                // <material name="foo">
                //   <color rgba="1 0 0 1"/>
                // </material>
                // <material name="foo"/>
                // It's a no-op.
                if (material.IsReference && GetMaterial(material.name) != null)
                {
                    Object.DestroyImmediate(material);
                    continue;
                }

                if (m_materialTable.ContainsKey(material.Name))
                {
                    throw new UrdfIOException($"{Utils.GetLineInfo( materialElement )}: Non-unique material name '{material.Name}'.");
                }

                m_materialTable.Add(material.Name, materials.Count);
                materials.Add(material);
            }
            m_materials = materials.ToArray();

            // Reading links defined under the "robot" scope.
            var links           = new List <Link>();
            var localMaterials  = new HashSet <string>();
            var warningBeginStr = GUI.AddColorTag("URDF Warning", Color.yellow);

            foreach (var linkElement in root.Elements("link"))
            {
                var link = Instantiate <Link>(linkElement);

                if (m_linkTable.ContainsKey(link.Name))
                {
                    throw new UrdfIOException($"{Utils.GetLineInfo( linkElement )}: Non-unique link name '{link.Name}'.");
                }

                // Render materials with unique name is added to the global
                // library as we instantiate the model.
                var newDefinedMaterials = link.Visuals.Where(visual => visual.Material != null &&
                                                             !visual.Material.IsReference &&
                                                             !localMaterials.Contains(visual.Material.Name) &&
                                                             GetMaterial(visual.Material.Name) == null).Select(visual => visual.Material.Name).ToArray();
                foreach (var newDefinedMaterialName in newDefinedMaterials)
                {
                    localMaterials.Add(newDefinedMaterialName);
                }

                var missingMaterialReferences = link.Visuals.Where(visual => visual.Material != null &&
                                                                   visual.Material.IsReference &&
                                                                   !localMaterials.Contains(visual.Material.Name) &&
                                                                   GetMaterial(visual.Material.Name) == null).Select(visual => visual.Material).ToArray();
                if (missingMaterialReferences.Length > 0)
                {
                    Debug.LogWarning($"{warningBeginStr}: {link.Name} contains " +
                                     $"{missingMaterialReferences.Length} missing material references:");
                    foreach (var missingMaterialReference in missingMaterialReferences)
                    {
                        Debug.LogWarning($"    {Utils.GetLineInfo( missingMaterialReference.LineNumber )}: <material name = \"{missingMaterialReference.Name}\"/>");
                    }
                }

                m_linkTable.Add(link.Name, links.Count);
                links.Add(link);

                RequiresResourceLoader = RequiresResourceLoader || FindRequiresResourceLoader(link);
            }
            m_links = links.ToArray();

            // Reading joints defined under the "robot" scope.
            var joints = new List <UJoint>();

            foreach (var jointElement in root.Elements("joint"))
            {
                var joint = Instantiate <UJoint>(jointElement);

                if (m_jointTable.ContainsKey(joint.Name))
                {
                    throw new UrdfIOException($"{Utils.GetLineInfo( jointElement )}: Non-unique link name '{joint.Name}'.");
                }
                if (GetLink(joint.Parent) == null)
                {
                    throw new UrdfIOException($"{Utils.GetLineInfo( jointElement )}: Joint parent link with name {joint.Parent} doesn't exist.");
                }
                var childLink = GetLink(joint.Child);
                if (childLink == null)
                {
                    throw new UrdfIOException($"{Utils.GetLineInfo( jointElement )}: Joint child link with name {joint.Child} doesn't exist.");
                }

                m_jointTable.Add(joint.Name, joints.Count);
                joints.Add(joint);

                // Avoiding warning for "world" type of links, i.e., 'parentLink' of
                // this joint may have inertial == null.
                if (childLink.Inertial == null && childLink.Collisions.Length == 0)
                {
                    Debug.LogWarning($"{warningBeginStr} [{Utils.GetLineInfo( childLink.LineNumber )}]: Intermediate link '{childLink.Name}' is defined without " +
                                     $"<inertial> and <collision> which results in default mass (1) and default inertia diagonal (1, 1, 1).");
                }
            }
            m_joints = joints.ToArray();

            // Verifying "mimic" references in the joints.
            foreach (var joint in Joints)
            {
                if (joint.Mimic.Enabled && GetJoint(joint.Mimic.Joint) == null)
                {
                    throw new UrdfIOException($"{Utils.GetLineInfo( joint.LineNumber )}: Mimic joint '{joint.Mimic.Joint}' isn't defined.");
                }
            }
        }
Example #4
0
        private static void PostBuildExternal(string agxDynamicsPath,
                                              string agxPluginPath,
                                              FileInfo targetExecutableFileInfo,
                                              string targetDataPath)
        {
            // Finding loaded modules/binaries in current process located
            // in current environment AGX Dynamics directory. Additional
            // modules/binaries that are optional, i.e., possibly located
            // in another directory, are also included here.
            var loadedAgxModulesPaths = new List <string>();

            using (new DynamicallyLoadedDependencies()) {
                var process = Process.GetCurrentProcess();
                foreach (ProcessModule module in process.Modules)
                {
                    if (module.FileName.IndexOf("[In Memory]") >= 0)
                    {
                        continue;
                    }

                    var isMatch = module.FileName.IndexOf(agxDynamicsPath) == 0 ||
                                  IsOutOfInstallDependency(module.FileName);
                    if (isMatch)
                    {
                        loadedAgxModulesPaths.Add(module.FileName);
                    }
                }
            }

            // Finding additional modules/binaries which an AGX Dynamics
            // runtime may depend on, e.g., vcruntimeIII.dll and msvcpIII.dll.
            var agxDepDir = AGXUnity.IO.Environment.Get(AGXUnity.IO.Environment.Variable.AGX_DEPENDENCIES_DIR);

            if (!string.IsNullOrEmpty(agxDepDir))
            {
                var agxDepDirInfo = new DirectoryInfo(agxDepDir);
                foreach (var file in agxDepDirInfo.EnumerateFiles("*.dll", SearchOption.AllDirectories))
                {
                    foreach (var dependency in m_additionalDependencies)
                    {
                        if (System.Text.RegularExpressions.Regex.IsMatch(file.Name, dependency))
                        {
                            loadedAgxModulesPaths.Add(file.FullName);
                        }
                    }
                }
            }

            if (loadedAgxModulesPaths.Count == 0)
            {
                Debug.LogWarning(GUI.AddColorTag("Copy AGX Dynamics binaries - no binaries found in current process.", Color.red));
                return;
            }

            // dllTargetPath: ./<name>_Data/Plugins
            var dllTargetPath = AGXUnity.IO.Environment.GetPlayerPluginPath(targetDataPath);

            if (!Directory.Exists(dllTargetPath))
            {
                Directory.CreateDirectory(dllTargetPath);
            }

            // agxRuntimeDataPath: ./<name>_Data/Plugins/agx
            var agxRuntimeDataPath = AGXUnity.IO.Environment.GetPlayerAGXRuntimePath(targetDataPath);

            if (!Directory.Exists(agxRuntimeDataPath))
            {
                Directory.CreateDirectory(agxRuntimeDataPath);
            }

            Debug.Log("Copying Components to: " + GUI.AddColorTag(agxRuntimeDataPath + Path.DirectorySeparatorChar + "Components", Color.green));
            CopyDirectory(new DirectoryInfo(agxPluginPath + Path.DirectorySeparatorChar + "Components"),
                          new DirectoryInfo(agxRuntimeDataPath + Path.DirectorySeparatorChar + "Components"));

            var targetDataDir = agxRuntimeDataPath + Path.DirectorySeparatorChar + "data";

            Debug.Log("Copying data to: " + GUI.AddColorTag(targetDataDir, Color.green));
            if (!Directory.Exists(targetDataDir))
            {
                Directory.CreateDirectory(targetDataDir);
            }
            CopyDirectory(new DirectoryInfo(agxDynamicsPath + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "TerrainMaterials"),
                          new DirectoryInfo(targetDataDir + Path.DirectorySeparatorChar + "TerrainMaterials"));

            foreach (var modulePath in loadedAgxModulesPaths)
            {
                var moduleFileInfo = new FileInfo(modulePath);
                try {
                    moduleFileInfo.CopyTo(dllTargetPath + Path.DirectorySeparatorChar + moduleFileInfo.Name, true);
                    string additionalInfo = "";
                    if (IsOutOfInstallDependency(modulePath))
                    {
                        additionalInfo = GUI.AddColorTag($" ({modulePath})", Color.yellow);
                    }
                    Debug.Log("Successfully copied: " +
                              GUI.AddColorTag(dllTargetPath + Path.DirectorySeparatorChar, Color.green) +
                              GUI.AddColorTag(moduleFileInfo.Name, Color.Lerp(Color.blue, Color.white, 0.75f)) +
                              additionalInfo);
                }
                catch (Exception e) {
                    Debug.Log("Failed copying: " +
                              GUI.AddColorTag(dllTargetPath + Path.DirectorySeparatorChar, Color.red) +
                              GUI.AddColorTag(moduleFileInfo.Name, Color.red) +
                              ": " + e.Message);
                }
            }

            CheckGenerateEncryptedRuntime(targetExecutableFileInfo);
        }
Example #5
0
        private static void OnPostProcessBuild(BuildTarget target, string targetPathFilename)
        {
            if (!EditorSettings.Instance.BuildPlayer_CopyBinaries)
            {
                return;
            }

            if (target != BuildTarget.StandaloneWindows64 && target != BuildTarget.StandaloneWindows)
            {
                Debug.LogWarning(GUI.AddColorTag("Copy AGX Dynamics binaries - unsupported build target: ",
                                                 Color.red) +
                                 target.ToString());
                return;
            }

            var nativeIsX64 = agx.agxSWIG.isBuiltWith(agx.BuildConfiguration.USE_64BIT_ARCHITECTURE);

            if ((target == BuildTarget.StandaloneWindows64) != nativeIsX64)
            {
                Debug.LogWarning(GUI.AddColorTag("Copy AGX Dynamics binaries - x86/x64 architecture mismatch: ",
                                                 Color.red) +
                                 "Build target = " +
                                 target.ToString() +
                                 ", AGX Dynamics build: " +
                                 (nativeIsX64 ? "x64" : "x86"));
                return;
            }

            var agxDynamicsPath = AGXUnity.IO.Environment.AGXDynamicsPath;

            if (string.IsNullOrEmpty(agxDynamicsPath))
            {
                Debug.LogWarning(GUI.AddColorTag("Copy AGX Dynamics binaries - unable to find AGX Dynamics directory.",
                                                 Color.red));
                return;
            }

            var agxPluginPath = AGXUnity.IO.Environment.Get(AGXUnity.IO.Environment.Variable.AGX_PLUGIN_PATH);

            if (string.IsNullOrEmpty(agxPluginPath))
            {
                Debug.LogWarning(GUI.AddColorTag("Copy AGX Dynamics binaries - unable to find AGX_PLUGIN_PATH.", Color.red));
                return;
            }

            var targetExecutableFileInfo = new FileInfo(targetPathFilename);

            if (!targetExecutableFileInfo.Exists)
            {
                Debug.LogWarning(GUI.AddColorTag("Target executable doesn't exist: ", Color.red) + targetPathFilename);
                return;
            }

            // Application.dataPath is 'Assets' folder here in Editor but
            // Application.dataPath is '<name>_Data' in the Player. We're
            // explicitly constructing '<name>_Data' here.
            var targetDataPath = targetExecutableFileInfo.Directory.FullName +
                                 Path.DirectorySeparatorChar +
                                 Path.GetFileNameWithoutExtension(targetExecutableFileInfo.Name) +
                                 "_Data";


            if (IO.Utils.AGXDynamicsInstalledInProject)
            {
                PostBuildInternal(agxDynamicsPath,
                                  agxPluginPath,
                                  targetExecutableFileInfo,
                                  targetDataPath);
            }
            else
            {
                PostBuildExternal(agxDynamicsPath,
                                  agxPluginPath,
                                  targetExecutableFileInfo,
                                  targetDataPath);
            }
        }
Example #6
0
        private void OnGUI()
        {
            AGXDynamicsForUnityLogoGUI();

            EditorGUILayout.LabelField(GUI.MakeLabel("Thank you for using AGX Dynamics for Unity!", true),
                                       InspectorEditor.Skin.LabelMiddleCenter);

            GUILayout.Space(6);

            var fieldColor = EditorGUIUtility.isProSkin ?
                             Color.white :
                             Color.black;
            var fieldErrorColor = Color.Lerp(Color.red,
                                             Color.black,
                                             0.25f);

            var versionInfo = PackageUpdateHandler.FindCurrentVersion();

            InspectorGUI.SelectableTextField(GUI.MakeLabel("Version"),
                                             (versionInfo.IsValid ?
                                              versionInfo.VersionString :
                                              "git checkout").Color(fieldColor),
                                             InspectorEditor.Skin.Label);

            string agxDynamicsVersion = s_agxInfo.Version;

            if (string.IsNullOrEmpty(agxDynamicsVersion))
            {
                agxDynamicsVersion = GUI.AddColorTag("Unknown",
                                                     fieldErrorColor);
            }
            else
            {
                agxDynamicsVersion = GUI.AddColorTag(agxDynamicsVersion,
                                                     fieldColor);
            }

            InspectorGUI.SelectableTextField(GUI.MakeLabel("AGX Dynamics version"),
                                             agxDynamicsVersion,
                                             InspectorEditor.Skin.Label);

            InspectorGUI.LicenseEndDateField(s_agxInfo);

            InspectorGUI.BrandSeparator(1, 8);

            GUILayout.Label(GUI.MakeLabel("Online Documentation", true), InspectorEditor.Skin.Label);

            using (new EditorGUILayout.HorizontalScope(GUILayout.Width(200))) {
                if (InspectorGUI.Link(GUI.MakeLabel("AGX Dynamics for Unity")))
                {
                    Application.OpenURL(TopMenu.AGXDynamicsForUnityManualURL);
                }
                GUILayout.Label(" - ", InspectorEditor.Skin.Label);
                if (InspectorGUI.Link(GUI.MakeLabel("Examples")))
                {
                    Application.OpenURL(TopMenu.AGXDynamicsForUnityExamplesURL);
                }
            }

            using (new EditorGUILayout.HorizontalScope(GUILayout.Width(200))) {
                if (InspectorGUI.Link(GUI.MakeLabel("AGX Dynamics user manual")))
                {
                    Application.OpenURL(TopMenu.AGXUserManualURL);
                }
                GUILayout.Label(" - ", InspectorEditor.Skin.Label);
                if (InspectorGUI.Link(GUI.MakeLabel("AGX Dynamics API Reference")))
                {
                    Application.OpenURL(TopMenu.AGXAPIReferenceURL);
                }
            }

            InspectorGUI.BrandSeparator(1, 8);

            GUILayout.Label("Support", EditorStyles.boldLabel);
            EditorGUILayout.SelectableLabel("Please refer to the information received when purchasing your license for support contact information.",
                                            InspectorEditor.Skin.LabelWordWrap);
        }