Esempio n. 1
0
        static public GameObject EmitDebugAABB(string name, Vector3 center, Vector3f dims, Color color, GameObject inCoords = null)
        {
            if (FPlatform.InMainThread() == false)
            {
                ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugAABB(name, center, dims, color, inCoords); });
                return(null);
            }

            if (inCoords != null)
            {
                Transform curt = inCoords.transform;
                while (curt != null)
                {
                    center = curt.TransformPoint(center);
                    curt   = curt.parent;
                }
            }
            GameObject box = GameObject.CreatePrimitive(PrimitiveType.Cube);

            box.SetName(name);
            box.transform.position   = center;
            box.transform.localScale = dims;
            box.GetComponent <MeshRenderer> ().material.color = color;
            return(box);
        }
Esempio n. 2
0
        static public GameObject EmitDebugLine(string name, Vector3f start, Vector3f end, float diameter, Colorf startColor, Colorf endColor,
                                               GameObject parent = null, bool bIsInWorldPos = true)
        {
            if (FPlatform.InMainThread() == false)
            {
                ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugLine(name, start, end, diameter, startColor, endColor, parent, bIsInWorldPos); });
                return(null);
            }

            GameObject line = new GameObject();

            line.SetName(name);
            line.transform.position = (bIsInWorldPos) ? start : Vector3f.Zero;
            line.AddComponent <LineRenderer>();
            LineRenderer lr = line.GetComponent <LineRenderer>();

            lr.material   = MaterialUtil.CreateParticlesMaterial();
            lr.startColor = startColor;
            lr.endColor   = endColor;
            lr.startWidth = lr.endWidth = diameter;
            lr.SetPosition(0, start);
            lr.SetPosition(1, end);

            if (parent != null)
            {
                lr.useWorldSpace = bIsInWorldPos;
                line.transform.SetParent(parent.transform, bIsInWorldPos);
            }

            return(line);
        }
Esempio n. 3
0
        /// <summary>
        /// Show a save-file dialog and with the provided file types.
        /// Returns path to selected file, or null if Cancel is clicked.
        /// Uses system file dialog, via tinyfiledialogs.
        /// filterPatterns specified like this: new string[] { "*.stl", "*.obj" }
        /// Note that tinyfiledialogs does not support multiple save-types in save dialog
        /// </summary>
        static public void GetSaveFileName_Async(string sDialogTitle, string sInitialPathAndFile,
                                                 string[] filterPatterns, string sPatternDesc, Action <string> OnSelectedF, Action OnCanceledF = null)
        {
#if (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX)
            ThreadPool.QueueUserWorkItem(delegate {
                // tinyfd changes CWD (?), and this makes Unity unhappy
                string curDirectory = Directory.GetCurrentDirectory();

                IntPtr p = tinyfd_saveFileDialog(sDialogTitle, sInitialPathAndFile,
                                                 filterPatterns.Length, filterPatterns, sPatternDesc);

                try {
                    Directory.SetCurrentDirectory(curDirectory);
                } catch (Exception) {
                    // [RMS] sometimes this results in an exception? I am confused...
                }

                if (p == IntPtr.Zero)
                {
                    if (OnCanceledF != null)
                    {
                        ThreadMailbox.PostToMainThread(OnCanceledF);
                    }
                    return;
                }

                string s = stringFromChar(p);
                ThreadMailbox.PostToMainThread(() => {
                    OnSelectedF(s);
                });
            });
#else
            // [TODO] implement
#endif
        }
Esempio n. 4
0
        static public fGameObject EmitDebugMesh(string name, DMesh3 meshIn, Colorf color, GameObject parent = null, bool bIsInWorldPos = true)
        {
            DMesh3 mesh = new DMesh3(meshIn);

            if (FPlatform.InMainThread() == false)
            {
                ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugMesh(name, mesh, color, parent, bIsInWorldPos); });
                return(null);
            }
            fMeshGameObject fMeshGO = GameObjectFactory.CreateMeshGO(name, new fMesh(mesh), false, true);

            fMeshGO.SetMaterial(MaterialUtil.CreateStandardMaterialF(color));
            if (parent != null)
            {
                parent.AddChild(fMeshGO, bIsInWorldPos);
            }
            return(fMeshGO);
        }
Esempio n. 5
0
        static public void EmitDebugFrame(string name, Frame3f f, float fAxisLength, float diameter = 0.05f)
        {
            if (FPlatform.InMainThread() == false)
            {
                ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugFrame(name, f, fAxisLength, diameter); });
                return;
            }

            GameObject frame = new GameObject(name);
            GameObject x     = EmitDebugLine(name + "_x", f.Origin, f.Origin + fAxisLength * f.X, diameter, Color.red);

            x.transform.parent = frame.transform;
            GameObject y = EmitDebugLine(name + "_y", f.Origin, f.Origin + fAxisLength * f.Y, diameter, Color.green);

            y.transform.parent = frame.transform;
            GameObject z = EmitDebugLine(name + "_z", f.Origin, f.Origin + fAxisLength * f.Z, diameter, Color.blue);

            z.transform.parent = frame.transform;
        }
Esempio n. 6
0
        static public GameObject EmitDebugFrame(string name, Frame3f f, float fAxisLength, float diameter = 0.05f, GameObject parent = null)
        {
            if (FPlatform.InMainThread() == false)
            {
                ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugFrame(name, f, fAxisLength, diameter); });
                return(null);
            }

            GameObject frameObj = new GameObject(name);

            /*GameObject x = */ EmitDebugLine(name + "_x", f.Origin, f.Origin + fAxisLength * f.X, diameter, Color.red, frameObj, false);
            /*GameObject y = */ EmitDebugLine(name + "_y", f.Origin, f.Origin + fAxisLength * f.Y, diameter, Color.green, frameObj, false);
            /*GameObject z = */ EmitDebugLine(name + "_z", f.Origin, f.Origin + fAxisLength * f.Z, diameter, Color.blue, frameObj, false);
            if (parent != null)
            {
                frameObj.transform.SetParent(parent.transform, false);
            }
            return(frameObj);
        }
Esempio n. 7
0
        static public GameObject EmitDebugSphere(string name, Vector3 position, float diameter, Color color, GameObject parent = null, bool bIsInWorldPos = true)
        {
            if (FPlatform.InMainThread() == false)
            {
                ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugSphere(name, position, diameter, color, parent, bIsInWorldPos); });
                return(null);
            }

            GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            sphere.SetName(name);
            sphere.transform.position   = position;
            sphere.transform.localScale = new Vector3(diameter, diameter, diameter);
            sphere.GetComponent <MeshRenderer> ().material.color = color;

            if (parent != null)
            {
                sphere.transform.SetParent(parent.transform, bIsInWorldPos);
            }

            return(sphere);
        }
Esempio n. 8
0
        static public fGameObject EmitDebugBox(string name, Box3d box, Colorf color, GameObject parent = null, bool bIsInWorldPos = true)
        {
            if (FPlatform.InMainThread() == false)
            {
                ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugBox(name, box, color, parent, bIsInWorldPos); });
                return(null);
            }
            TrivialBox3Generator boxgen = new TrivialBox3Generator()
            {
                Box = box, NoSharedVertices = true, Clockwise = true
            };

            boxgen.Generate();
            DMesh3          mesh    = boxgen.MakeDMesh();
            fMeshGameObject fMeshGO = GameObjectFactory.CreateMeshGO(name, new fMesh(mesh), false, true);

            fMeshGO.SetMaterial(MaterialUtil.CreateStandardMaterialF(color));
            if (parent != null)
            {
                parent.AddChild(fMeshGO, bIsInWorldPos);
            }
            return(fMeshGO);
        }
Esempio n. 9
0
        static public GameObject EmitDebugCurve(string name, Vector3d[] curve, bool bClosed,
                                                float diameter, Colorf startColor, Colorf endColor,
                                                GameObject parent = null, bool bIsInWorldPos = true)
        {
            if (FPlatform.InMainThread() == false)
            {
                ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugCurve(name, curve, bClosed, diameter, startColor, endColor, parent, bIsInWorldPos); });
                return(null);
            }

            GameObject line = new GameObject();

            line.SetName(name);
            line.AddComponent <LineRenderer> ();
            LineRenderer lr = line.GetComponent <LineRenderer> ();

            lr.material   = MaterialUtil.CreateParticlesMaterial();
            lr.startColor = startColor;
            lr.endColor   = endColor;
            lr.startWidth = lr.endWidth = diameter;
            Vector3[] verts = new Vector3[curve.Length];
            for (int i = 0; i < curve.Length; ++i)
            {
                verts[i] = (Vector3)curve[i];
            }
            lr.positionCount = curve.Length;
            lr.SetPositions(verts);
            lr.loop          = bClosed;
            lr.useWorldSpace = (parent == null && bIsInWorldPos);

            if (parent != null)
            {
                line.transform.SetParent(parent.transform, bIsInWorldPos);
            }

            return(line);
        }