示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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;
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
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);
        }