Пример #1
0
        public static GameObject MakeNewNodeGo(RouteMan rman, LcNode node, float nodesize, string cname)
        {
            var go     = new GameObject();
            var nodego = go.AddComponent <NodeGo>();

            nodego.rman                  = rman;
            nodego.node                  = node;
            nodego.name                  = node.name;
            nodego.nodeName              = node.name;
            nodego.nodePt                = node.pt;
            nodego.nodeTransform         = node.transform;
            nodego.nodeTransformSetCount = node.transformSetCount;
            nodego.lastmsg               = "";
            if (node.transform != null)
            {
                nodego.nodePtWc = node.transform.TransformPoint(node.pt);
            }
            go.name = node.name;
            go.transform.localPosition = node.pt;

            var sph = GraphUtil.CreateMarkerSphere(node.name + "-sph", node.pt, nodesize, cname);

            node.go = sph;
            if (rman != null && rman.garnish != RouterGarnishE.none)
            {
                var text = node.name + "\n" + node.pt;
                GraphUtil.addFloatingTextStatic(go, node.pt, text, cname, 90);
            }

            sph.transform.parent    = go.transform;
            node.transform          = sph.transform;
            node.transformSetCount += 1;
            return(go);
        }
Пример #2
0
        void CreateGos()
        {
            if (emlist == null)
            {
                return;  // nothing to do
            }
            DeleteGos(); // delete any old ones before we redraw the new ones

            if (ermarkgo == null)
            {
                ermarkgo = new GameObject("ErrMarkers");
                ermarkgo.transform.parent = rman.rgo.transform;
            }

            int i      = 0;
            var scname = "green";
            var tcname = "red";

            foreach (var em in emlist)
            {
                var sname = "campt" + i;
                var tname = "pathpt" + i;
                var ssph  = GraphUtil.CreateMarkerSphere(sname, em.source, size: 1.1f * emsize, clr: scname);
                ssph.transform.parent = ermarkgo.transform;
                var tsph = GraphUtil.CreateMarkerSphere(tname, em.target, size: 1.1f * emsize, clr: tcname);
                tsph.transform.parent = ermarkgo.transform;
                i += 1;
            }
        }
Пример #3
0
        void CreateGrcGos()
        {
            //Debug.Log("CreateGrcGos "+ gogencount);
            var grc = GetGraphCtrl();

            sman.leditor.SetGraphCtrl(grc);
            if (grcgos == null)
            {
                grcgos = new GameObject("GraphCtrl-" + gogencount);
                var gccomp = grcgos.AddComponent <GraphCtrlComp>();
                gccomp.Init(this, grctrl);
                grcgos.transform.parent = sman.rgo.transform;
                grcnodes = new GameObject("nodes");
                grcnodes.transform.parent = grcgos.transform;
                grclinks = new GameObject("links");
                grclinks.transform.parent = grcgos.transform;
                gogencount++;
            }
            if (linksvisible)
            {
                foreach (var lnkname in grc.linknamelist)
                {
                    var lnk = grc.GetLink(lnkname);
                    if (!CheckCapUseVisibility(lnk))
                    {
                        continue;
                    }
                    var clrname = linkcolor(lnk);
                    var linkrad = linkradius(lnk);
                    var go      = LinkGo.MakeLinkGo(sman, lnk, linkrad, clrname, 1 - linkTrans, this.flatlinks);
                    go.transform.parent = grclinks.transform;
                }
            }
            if (nodesvisible)
            {
                //Debug.Log("Recreating nodegos");
                foreach (string lptname in grc.linkpoints())
                {
                    var node = grc.GetNode(lptname);
                    if (!CheckCapUseVisibility(node))
                    {
                        continue;
                    }
                    CreateNodeGo(node);
                }
                if (showNearestPoint)
                {
                    var tup   = FindClosestPointOnLineCloud(nearestPointRef);
                    var npt   = tup.Item2;
                    var nname = "linknearsph-";

                    var pnsph = GraphUtil.CreateMarkerSphere(nname, npt, size: 2.5f * sman.linknodescale * markerNodeSize, clr: "red", alf: 1 - linkTrans);
                    pnsph.transform.parent = grcgos.transform;
                }
            }
            stats_nodes_links.x = grc.GetNodeCount();
            stats_nodes_links.y = grc.GetLinkCount();
        }
Пример #4
0
        void AttachFrameImageToBackground()
        {
            DeactivateBackgroundImage();
            var o     = 0.5f;
            var w     = Screen.width + 0.5f;
            var h     = Screen.height + 0.5f;
            var gap   = 0.1f;
            var zdist = cam.farClipPlane - gap;

            var pos   = cam.transform.position;
            var pos00 = cam.ScreenToWorldPoint(new Vector3(o, o, zdist));
            var pos01 = cam.ScreenToWorldPoint(new Vector3(o, h, zdist));
            var pos10 = cam.ScreenToWorldPoint(new Vector3(w, o, zdist));
            var pos11 = cam.ScreenToWorldPoint(new Vector3(w, h, zdist));
            var poscn = cam.transform.position + cam.transform.forward * zdist;


            pos00 = Vector3.Lerp(pos, pos00, lamb);
            pos01 = Vector3.Lerp(pos, pos01, lamb);
            pos10 = Vector3.Lerp(pos, pos10, lamb);
            pos11 = Vector3.Lerp(pos, pos11, lamb);
            poscn = Vector3.Lerp(pos, poscn, lamb);

            bcango = new GameObject("bgcanvas");
            var bcan = bcango.AddComponent <Canvas>();

            bcan.renderMode              = RenderMode.WorldSpace;
            bcan.transform.position      = poscn;
            bcan.transform.localRotation = camgo.transform.localRotation;
            bcan.transform.parent        = camgo.transform;
            bcan.transform.localScale    = new Vector3(Vector3.Magnitude(pos10 - pos00) / 100, Vector3.Magnitude(pos01 - pos00) / 100, 1);

            if (showSpheres)
            {
                var sgo00 = GraphUtil.CreateMarkerSphere("csph-00", pos00, 20, "purple");
                sgo00.transform.parent = bcango.transform;
                var sgo01 = GraphUtil.CreateMarkerSphere("csph-01", pos01, 20, "purple");
                sgo01.transform.parent = bcango.transform;
                var sgo10 = GraphUtil.CreateMarkerSphere("csph-10", pos10, 20, "purple");
                sgo10.transform.parent = bcango.transform;
                var sgo11 = GraphUtil.CreateMarkerSphere("csph-11", pos11, 20, "purple");
                sgo11.transform.parent = bcango.transform;
                var sgo = GraphUtil.CreateMarkerSphere("csph-cen", poscn, 30, "purple");
                sgo.transform.parent = bcango.transform;
            }

            if (showBackground)
            {
                var tex = LoadImage();
                rawimage                    = bcango.AddComponent <RawImage>();
                rawimage.texture            = tex;
                rawimage.transform.position = poscn;
                rawimage.transform.parent   = camgo.transform;
            }
        }
Пример #5
0
        void CreateLinkCloudGos()
        {
            var lcld = getLinkCloud();

            if (linkcloudgos == null)
            {
                linkcloudgos                  = new GameObject();
                linkcloudgos.name             = "LinkCloud-" + gogencount;
                linkcloudgos.transform.parent = rman.rgo.transform;
                gogencount++;
            }
            if (linksvisible)
            {
                foreach (var lnkname in lcld.linknamelist)
                {
                    var lnk   = lcld.GetLink(lnkname);
                    var cname = linkcolor(lnk.name);
                    var go    = LinkGo.MakeNewLinkGo(rman, lnk, linkRadius, cname);
                    go.transform.parent = linkcloudgos.transform;
                }
            }
            if (nodesvisible)
            {
                foreach (string lptname in lcld.linkpoints())
                {
                    var lpt   = lcld.GetNode(lptname);
                    var cname = nodecolor(lpt.name);
                    var go    = NodeGo.MakeNewNodeGo(rman, lpt, linkNodeSize, cname);
                    go.transform.parent = linkcloudgos.transform;
                }
                if (showNearestPoint)
                {
                    var npt   = FindClosestPointOnLineCloud(nearestPointRef);
                    var nname = "linknearsph-";
                    var pnsph = GraphUtil.CreateMarkerSphere(nname, npt, size: 2.5f * linkNodeSize, clr: "red");
                    pnsph.transform.parent = linkcloudgos.transform;
                }
            }
            stats_nodes_links.x = lcld.nodecount();
            stats_nodes_links.y = lcld.linkcount();
        }
Пример #6
0
        public static GameObject MakeNodeGo(SceneMan sman, LcNode node, float nodesize, string cname, float alf, bool addcollider = true)
        {
            var go     = new GameObject();
            var nodego = go.AddComponent <NodeGo>();

            nodego.sman                  = sman;
            nodego.node                  = node;
            nodego.name                  = node.name;
            nodego.nodeName              = node.name;
            nodego.nodePt                = node.pt;
            nodego.lng                   = node.lng;
            nodego.lat                   = node.lat;
            nodego.nodeTransform         = node.transform;
            nodego.nodeTransformSetCount = node.transformSetCount;
            nodego.lastmsg               = "";
            if (node.transform != null)
            {
                nodego.nodePtWc = node.transform.TransformPoint(node.pt);
            }
            go.name = node.name;
            go.transform.localPosition = node.pt;

            var sph = GraphUtil.CreateMarkerSphere(node.name + "-sph", node.pt, nodesize, cname, alf);

            node.go = sph;
            if (sman != null && sman.garnish != RouteGarnishE.none)
            {
                var text = node.name + "\n" +
                           node.pt + "\n" +
                           node.lat.ToString("f6") + ", " + node.lng.ToString("f6");
                GraphUtil.addFloatingTextStatic(go, node.pt, text, cname, 90);
            }
            if (addcollider)
            {
                sph.AddComponent <SphereCollider>();
            }
            sph.transform.parent    = go.transform;
            node.transform          = sph.transform;
            node.transformSetCount += 1;
            return(go);
        }
Пример #7
0
        public void StartStretchMode(string selname)
        {
            var lcld = getLinkCloud();

            if (lcld.isnodename(selname))
            {
                if (nodeMoveMode == nodeMoveModeE.move)
                {
                    // turn purple and start stretching
                    this.nodeMoveMode = nodeMoveModeE.stretch;
                    var lpt  = lcld.GetNode(selname);
                    var csph = GraphUtil.CreateMarkerSphere(name, lpt.pt, linkNodeSize * 2, "purple");
                    csph.transform.parent = lpt.go.transform;
                    lcld.StartStretchNode(selname);
                }
                else
                {
                    // now stop stretching
                    lcld.finishStretchMovement(selname);
                    nodeMoveMode = nodeMoveModeE.move;
                    rman.RequestRefresh(selname);
                }
            }
        }
Пример #8
0
        void CreatePathGos()
        {
            if (_path == null)
            {
                return;                // nothing to do
            }
            DeletePathGos();

            if (pathgo == null)
            {
                pathgo = new GameObject("Path-" + gogeninst);
                gogeninst++;
            }
            pathgo.transform.parent = sman.rgo.transform;
            int i     = 0;
            int ilast = path.waypts.Count - 1;
            var lclr  = sman.getcolorname(SceneMan.RmColorModeE.pathlink);
            var nclr  = sman.getcolorname(SceneMan.RmColorModeE.pathnode);

            foreach (var w in _path.waypts)
            {
                var    lnk   = w.link;
                string wname = "way:" + i + " (" + lnk.name + ")";
                if (visible)
                {
                    var pathcyl = GraphUtil.CreatePipe(wname, lnk.node1.pt, lnk.node2.pt, pathRadius, clr: lclr);
                    pathcyl.transform.parent = pathgo.transform;
                    if (i != ilast)
                    {
                        var mkname = "pathsph-" + pathsphcnt;
                        var psph   = GraphUtil.CreateMarkerSphere(mkname, w.toNode.pt, size: pathNodeSize, clr: nclr);
                        psph.transform.parent = pathgo.transform;
                        w.toNode.transform    = pathgo.transform;

                        //RegionMan.Log("path point i:" + i +"  w.tolpt.pt:"+w.tolpt.pt+ "  w.tolpt.ptwc:" + w.tolpt.ptwc);
                    }
                    if (showNearestWegPoints)
                    {
                        var npt   = w.link.FindClosestPointOnLink(nearestPointRef);
                        var nname = "nearsph-" + pathsphcnt;
                        var pnsph = GraphUtil.CreateMarkerSphere(nname, npt, size: 1.5f * pathNodeSize, clr: "orange");
                        pnsph.transform.parent = pathgo.transform;
                    }
                }
                i++;
                pathsphcnt++;
            }
            if (showNearestPathPoint)
            {
                float pathdst = 0;
                FindClosestPointOnPath(nearestPointRef, out pathdst);
                var pp    = path.MovePositionAlongPath(pathdst);
                var nspwc = sman.rgo.transform.TransformPoint(pp.pt);
                var nname = "nearpathsph";
                //RegionMan.Log("pp pp.pt:" + pp.pt + "  pp.ptwc:" + pp.ptwc);
                var go = new GameObject();
                go.name = nname + "-go";
                go.transform.position = nspwc;
                var cname = "lilac";
                var pnsph = GraphUtil.CreateMarkerSphere(nname, nspwc, size: 1.1f * pathNodeSize, clr: cname);
                if (sman != null)
                {
                    //                    if (sman.garnish != RouterGarnishE.none || sman.statusctrl.outMode != StatusCtrl.outModeE.geninfo)
                    if (sman.garnish != RouteGarnishE.none)
                    {
                        //RegionMan.Log("Adding text");
                        addFloatingText(go, nspwc, "Hello Sphere", cname, yrot: 0, yoff: 1.1f);
                    }
                }
                pnsph.transform.parent = go.transform;
                go.transform.parent    = pathgo.transform;
            }
        }
Пример #9
0
        void CreateBirdFormGos()
        {
            if (birdgoes == null)
            {
                birdgoes                  = new GameObject();
                birdgoes.name             = "Birds";
                birdgoes.transform.parent = sman.rgo.transform;
            }
            if (birdformgo != null)
            {
                Destroy(birdformgo);
                birdformgo = null;
            }
            var curpos = birdgo.transform.position;
            var currot = birdgo.transform.localRotation;

            switch (birdform)
            {
            case BirdFormE.sphere:
            {
                birdformgo = GraphUtil.CreateMarkerSphere("sphere", Vector3.zero, size: 0.3f, clr: "yellow");
                birdformgo.transform.localRotation = currot;
                birdformgo.transform.localPosition = curpos;
                movingAnimationScript  = "";
                restingAnimationScript = "";
                //BirdFlyHeight = 1.5f;
                birdgo.name = "Sphere";
                break;
            }

            case BirdFormE.longsphere:
            {
                birdformgo = GraphUtil.CreateMarkerSphere("sphere", Vector3.zero, size: 0.2f, clr: "yellow");
                var nosept = new Vector3(0, 0, 0.1f);

                var gonose = GraphUtil.CreateMarkerSphere("nose", nosept, size: 0.1f, clr: "red");
                gonose.transform.parent = birdformgo.transform;

                birdformgo.transform.localScale    = new Vector3(0.25f, 0.25f, 0.5f);      // somehow adding the nose made the sphere bigger ??
                birdformgo.transform.localRotation = currot;
                birdformgo.transform.localPosition = curpos;
                movingAnimationScript  = "";
                restingAnimationScript = "";
                //BirdFlyHeight = 1.5f;
                //                        birdformgo.transform.Rotate(90, 0, 0);
                birdgo.name = "Olive";
                break;
            }

            default:
            case BirdFormE.hummingbird:
            {
                var objPrefab = Resources.Load <GameObject>("hummingbird");
                birdformgo = Instantiate <GameObject>(objPrefab) as GameObject;
                var s = 0.5e-3f;
                birdformgo.transform.localScale    = new Vector3(s, s, s);
                birdformgo.transform.localRotation = currot;
                birdformgo.transform.localPosition = curpos;
                movingAnimationScript  = "";
                restingAnimationScript = "";
                //BirdFlyHeight = 1.5f;
                birdgo.name = "Bird";
                break;
            }

            case BirdFormE.person:
            {
                //if (birdresourcename=="")
                //{
                //    birdresourcename = "girl004";
                //}
                birdformgo = person.LoadPersonGo("-ava-bc");
                if (person.hasHololens)
                {
                    person.ActivateHololens(true);
                }
                var s = 1.0f;
                birdformgo.transform.localScale    = new Vector3(s, s, s);
                birdformgo.transform.localRotation = currot;
                //var noise = GraphAlgos.GraphUtil.GetRanFloat(0, 0.6f,"jnygen");
                var newpos = new Vector3(curpos.x + 0.3f, curpos.y - 1.55f, curpos.z);
                birdformgo.transform.localPosition = newpos;
                movingAnimationScript  = "Animations/PersonWalk";
                restingAnimationScript = "Animations/PersonIdle";
                //BirdFlyHeight = 1.5f;
                birdgo.name = birdresourcename;
                if (person)
                {
                    if (person.hasCamera)
                    {
                        person.AddCamera(birdformgo, "BirdCtrl CreateBirdFormGos");
                    }
                    if (person.grabbedMainCamera)
                    {
                        person.GrabMainCamera();
                    }
                }
                break;
            }

            case BirdFormE.car:
            {
                //Debug.Log("Loading car resourcename:" + birdresourcename);
                if (birdresourcename == "")
                {
                    birdresourcename = "car001";
                }
                //var objPrefab = Resources.Load<GameObject>("Cars/"+birdresourcename);
                //birdformgo = Instantiate<GameObject>(objPrefab);
                birdformgo = VehicleMan.LoadCarGo(birdgo, birdresourcename);
                //var s = 1.0f;
                //birdformgo.transform.localScale = new Vector3(s, s, s);
                birdformgo.transform.localRotation = currot;
                var noise  = GraphAlgos.GraphUtil.GetRanFloat(0, 0.5f, "jnygen");
                var newpos = new Vector3(curpos.x + 1.2f + noise, curpos.y - 1.55f, curpos.z);
                birdformgo.transform.localPosition += newpos;
                movingAnimationScript  = "";
                restingAnimationScript = "";
                //BirdFlyHeight = 1.5f;
                birdgo.name = birdresourcename;
                if (person)
                {
                    if (person.hasCamera)
                    {
                        person.AddCamera(birdformgo, "BirdCtrl CreateBirdFormGos");
                    }
                    if (person.grabbedMainCamera)
                    {
                        person.GrabMainCamera();
                    }
                }
                break;
            }
            }
//            birdformgo.transform.parent = birdgo.transform;
            birdformgo.transform.SetParent(birdgo.transform, true);// should be false....

            lastbirdform = birdform;
        }
Пример #10
0
        void AttachQuadImageToBackground()
        {
            DeactivateBackgroundImage();
            var o     = 0.5f;
            var w     = Screen.width + 0.5f;
            var h     = Screen.height + 0.5f;
            var gap   = 0.1f;
            var zdist = cam.farClipPlane - gap;

            var pos   = cam.transform.position;
            var pos00 = cam.ScreenToWorldPoint(new Vector3(o, o, zdist));
            var pos01 = cam.ScreenToWorldPoint(new Vector3(o, h, zdist));
            var pos10 = cam.ScreenToWorldPoint(new Vector3(w, o, zdist));
            var pos11 = cam.ScreenToWorldPoint(new Vector3(w, h, zdist));
            var poscn = cam.transform.position + cam.transform.forward * zdist;



            pos00 = Vector3.Lerp(pos, pos00, lamb);
            pos01 = Vector3.Lerp(pos, pos01, lamb);
            pos10 = Vector3.Lerp(pos, pos10, lamb);
            pos11 = Vector3.Lerp(pos, pos11, lamb);
            poscn = Vector3.Lerp(pos, poscn, lamb);

            quadgo = GameObject.CreatePrimitive(PrimitiveType.Quad);
            quadgo.transform.position      = poscn;
            quadgo.transform.localRotation = camgo.transform.localRotation;
            quadgo.transform.parent        = camgo.transform;
            quadgo.transform.localScale    = new Vector3(Vector3.Magnitude(pos10 - pos00), Vector3.Magnitude(pos01 - pos00), 1);

            if (showSpheres)
            {
                var sgo00 = GraphUtil.CreateMarkerSphere("csph-00", pos00, 20, "purple");
                sgo00.transform.parent = quadgo.transform;
                var sgo01 = GraphUtil.CreateMarkerSphere("csph-01", pos01, 20, "purple");
                sgo01.transform.parent = quadgo.transform;
                var sgo10 = GraphUtil.CreateMarkerSphere("csph-10", pos10, 20, "purple");
                sgo10.transform.parent = quadgo.transform;
                var sgo11 = GraphUtil.CreateMarkerSphere("csph-11", pos11, 20, "purple");
                sgo11.transform.parent = quadgo.transform;
                var sgo = GraphUtil.CreateMarkerSphere("csph-cen", poscn, 30, "purple");
                sgo.transform.parent = quadgo.transform;
            }

            bool addLight = false;

            if (addLight)
            {
                var lightob = new GameObject("quadlight");
                var dlight  = lightob.AddComponent <Light>();
                dlight.type = LightType.Directional;
                lightob.transform.SetParent(quadgo.transform);
                lightob.transform.localRotation = Quaternion.Euler(66, 0, 0);
            }

            if (showBackground)
            {
                var tex  = LoadImage();
                var rend = quadgo.GetComponent <Renderer>();
                rend.material.mainTexture = tex;
            }
        }
Пример #11
0
        public void CreateBirdFormGos(bool posttransform = false)
        {
            Transform pvt = null;

            if (birdformgo != null)
            {
                pvt = birdformgo.transform;
                Destroy(birdformgo);
                birdformgo = null;
            }
            var shrink = 1f;

            if (posttransform)
            {
                // todo: we should probably be translating and rotating too
                //       so we need to test shifted scenes (like when we do error correction)
                //       with "change bird form"
                shrink = rman.rgoScale;
            }
            switch (birdform)
            {
            case BirdFormE.sphere:
            {
                var sphsize = shrink * 0.2f;
                birdformgo = GraphUtil.CreateMarkerSphere("sphere", Vector3.zero, size: sphsize, clr: "yellow");
                break;
            }

            case BirdFormE.olive:
            {
                birdformgo = GraphUtil.CreateMarkerSphere("sphere", Vector3.zero, size: 0.2f, clr: "olive");
                birdformgo.transform.localScale = shrink * (new Vector3(0.2f, 0.2f, 0.28f));

                var nosept = shrink * (new Vector3(0, 0, 0.1f));
                var gonose = GraphUtil.CreateMarkerSphere("nose", nosept, size: shrink * 0.1f, clr: "red");
                gonose.transform.parent = birdformgo.transform;
                break;
            }

            default:
            case BirdFormE.hummingbird:
            {
                var objPrefab = (GameObject)Resources.Load("hummingbird");
                birdformgo = Instantiate(objPrefab) as GameObject;
                var s        = shrink * 0.5e-3f;
                var minscale = 0.1375f * s;         // value experimentally discovered
                if (s * rman.rgoScale < minscale)
                {
                    s = minscale / rman.rgoScale;
                }
                birdformgo.transform.localScale = new Vector3(s, s, s);
                break;
            }

            case BirdFormE.utahteapot:
            {
                var objPrefab = (GameObject)Resources.Load("teapot");
                birdformgo = Instantiate(objPrefab) as GameObject;
                birdformgo.GetComponent <Renderer>().material.SetColor("_Color", GraphUtil.getcolorbyname("chinawhite"));
                var s = shrink * 60.0f;
                birdformgo.transform.localScale = new Vector3(s, s, s);
                birdformgo.transform.Rotate(0, 90, 0);
                break;
            }
            }
            var pt   = birdgo.transform.position;
            var text = "Hummingbird\n" + pt;

            addFloatingText(birdgo, pt, text, "yellow");
            if (posttransform)
            {
                //rman.GlobInvTransGo(birdformgo);
                //var s = rman.rgoScale;
                //birdformgo.transform.localScale = new Vector3(s, s, s);
                //birdformgo.transform.Rotate(0, rman.rgoRotate, 0);
                //birdformgo.transform.Translate(rman.rgoTranslate);
            }
            birdformgo.transform.parent = birdgo.transform;
        }