Esempio n. 1
0
        // pass bIsScaled=false if the localFrame is not in the un-scaled space of the primitive
        //   (eg like if you computed positions relative to an un-scaled bounding box)
        public void AddSphereL(Frame3f localFrame, float fVisualRadiusDeg, Material mat, bool bIsScaled = true)
        {
            GameObject go     = new GameObject("sphere");
            Vector3f   vScale = parentSO.GetLocalScale();

            go.AddComponent <MeshFilter>();
            go.SetMesh(UnityUtil.GetPrimitiveMesh(PrimitiveType.Sphere));
            var goRen = go.AddComponent <MeshRenderer>();

            goRen.material          = mat;
            go.transform.localScale = new Vector3(1, 1, 1);
            // we are going to be parented to SO, so we will inherit its local scale.
            // assumption is that frames passed in are already in scaled coordinates,
            // so we need to undo that scale
            if (bIsScaled)
            {
                go.transform.position = localFrame.Origin / vScale;
            }
            else
            {
                go.transform.position = localFrame.Origin;
            }
            go.layer = FPlatform.WidgetOverlayLayer;

            UnityUtil.AddChild(parentGO, go, false);

            vObjects.Add(new IndicatorInfo()
            {
                go = go, fVisualRadiusDeg = fVisualRadiusDeg
            });
        }
Esempio n. 2
0
        override public void UpdateGeometry()
        {
            if (sphere == null)
            {
                return;
            }

            sphereMesh.GetComponent <MeshFilter>().sharedMesh = UnityUtil.GetPrimitiveMesh(PrimitiveType.Sphere);
            sphereMesh.transform.localScale = new Vector3(2 * radius, 2 * radius, 2 * radius);

            // if we want to scale away/towards bottom of sphere, then we need to
            //  translate along axis as well...
            Frame3f f      = GetLocalFrame(CoordSpace.ObjectCoords);
            float   fScale = sphere.transform.localScale[1];

            f.Origin -= f.FromFrameV(fScale * centerShift);
            update_shift();
            f.Origin += f.FromFrameV(fScale * centerShift);
            SetLocalFrame(f, CoordSpace.ObjectCoords);

            // apparently this is expensive?
            if (DeferRebuild == false)
            {
                sphereMesh.GetComponent <MeshCollider>().sharedMesh = sphereMesh.GetComponent <MeshFilter>().sharedMesh;
            }

            increment_timestamp();
        }
Esempio n. 3
0
        public static fRectangleGameObject CreateRectangleGO(string sName, float fWidth, float fHeight, fMaterial useMaterial, bool bShareMaterial, bool bCollider)
        {
            GameObject go       = new GameObject(sName);
            Mesh       rectMesh = UnityUtil.GetPrimitiveMesh(PrimitiveType.Quad);

            UnityUtil.RotateMesh(rectMesh, Quaternionf.AxisAngleD(Vector3f.AxisX, 90), Vector3f.Zero);
            initialize_meshgo(go, new fMesh(rectMesh), bCollider, true);
            go.SetMaterial(useMaterial, bShareMaterial);
            return(new fRectangleGameObject(go, fWidth, fHeight));
        }
        void update_box()
        {
            if (nCurMesh != (int)PrimType.Box)
            {
                meshObject.SetMesh(UnityUtil.GetPrimitiveMesh(PrimitiveType.Cube));
                nCurMesh = (int)PrimType.Box;
            }

            Transform parent = meshObject.transform.parent;

            meshObject.transform.parent = null;

            float fHeightSignShift = (Height < 0) ? Height : 0;
            float fAbsHeight       = Math.Abs(Height);
            float fWidthShift      = (Width < 0) ? Width : 0;
            float fAbsWidth        = Math.Abs(Width);
            float fDepthShift      = (Depth < 0) ? Depth : 0;
            float fAbsDepth        = Math.Abs(Depth);

            Vector3f vShift = Vector3f.Zero;

            if (Center == CenterModes.Base)
            {
                vShift = new Vector3f(0, fHeightSignShift + fAbsHeight * 0.5f, 0);
            }
            else if (Center == CenterModes.Corner)
            {
                vShift = new Vector3f(fWidthShift + fAbsWidth * 0.5f,
                                      fHeightSignShift + fAbsHeight * 0.5f, fDepthShift + fAbsDepth * 0.5f);
            }

            meshObject.transform.localPosition = Vector3.zero;
            meshObject.transform.localRotation = Quaternion.identity;

            // default unity box is 1x1x1 cube
            meshObject.transform.localScale = new Vector3f(fAbsWidth, fAbsHeight, fAbsDepth);

            shiftedFrame = Frame.Translated(Frame.FromFrameV(vShift));
            UnityUtil.SetGameObjectFrame(meshObject, shiftedFrame, CoordSpace.WorldCoords);

            meshObject.transform.SetParent(parent, true);
        }
Esempio n. 5
0
        // creates a button with a floating primitive in front of the button shape
        public void CreateMeshIconButton(float fRadius, string sMeshPath, Material bgMaterial,
                                         float fMeshScaleFudge)
        {
            Shape = new HUDShape(HUDShapeType.Disc, fRadius);

            fMesh    iconmesh     = null;
            Material meshMaterial = null;

            try {
                iconmesh     = FResources.LoadMesh(sMeshPath);
                meshMaterial = MaterialUtil.CreateStandardVertexColorMaterial(Color.white);
            } catch { }
            if (iconmesh == null)
            {
                iconmesh     = UnityUtil.GetPrimitiveMesh(PrimitiveType.Sphere);
                meshMaterial = MaterialUtil.CreateStandardMaterial(Color.red);
            }

            float fMeshRadius = fRadius * fMeshScaleFudge;

            base.Create(bgMaterial, iconmesh, meshMaterial, fMeshRadius,
                        Frame3f.Identity.Translated(-fMeshRadius * 0.25f, 2).Rotated(-15.0f, 1));
        }
        override protected void BuildGizmo()
        {
            gizmo.SetName("SurfaceConstrainedGizmo");

            make_materials();

            centerGO = AppendMeshGO("object_origin",
                                    UnityUtil.GetPrimitiveMesh(PrimitiveType.Sphere), srcMaterial, gizmo);
            centerGO.SetLocalScale(WidgetScale);

            Widgets[centerGO] = new SurfaceConstrainedPointWidget(this, this.parentScene)
            {
                RootGameObject = centerGO, StandardMaterial = srcMaterial, HoverMaterial = srcHoverMaterial
            };


            PuncturedDiscGenerator discgen = new PuncturedDiscGenerator()
            {
                StartAngleDeg = 180, EndAngleDeg = 270, OuterRadius = 1.5f, InnerRadius = 0.75f
            };

            discgen.Generate();
            SimpleMesh discmesh = discgen.MakeSimpleMesh();

            MeshTransforms.Rotate(discmesh, Vector3d.Zero, Quaternionf.AxisAngleD(Vector3f.AxisX, 90));
            rotateGO = AppendMeshGO("object_rotate", new fMesh(discmesh), srcMaterial, gizmo);
            rotateGO.SetLocalScale(WidgetScale);

            Widgets[rotateGO] = new AxisRotationWidget(2)
            {
                RootGameObject = rotateGO, StandardMaterial = srcMaterial, HoverMaterial = srcHoverMaterial
            };


            gizmo.Hide();
        }
Esempio n. 7
0
        public void Create(Cockpit cockpit)
        {
            base.Create();

            float fHUDRadius    = 0.75f;
            float fButtonRadius = 0.06f;

            Color bgColor = new Color(0.7f, 0.7f, 1.0f, 0.7f);

            Material bgMaterial = (bgColor.a == 1.0f) ?
                                  MaterialUtil.CreateStandardMaterial(bgColor) : MaterialUtil.CreateTransparentMaterial(bgColor);

            List <SOMaterial> materials = new List <SOMaterial>()
            {
                SOMaterial.CreateStandard("default", ColorUtil.StandardBeige),
                SOMaterial.CreateStandard("standard_white", Colorf.VideoWhite),
                SOMaterial.CreateStandard("standard_black", Colorf.VideoBlack),
                SOMaterial.CreateStandard("middle_grey", new Colorf(0.5f)),

                SOMaterial.CreateStandard("standard_green", Colorf.VideoGreen),
                SOMaterial.CreateStandard("forest_green", Colorf.ForestGreen),
                SOMaterial.CreateStandard("teal", Colorf.Teal),
                SOMaterial.CreateStandard("light_green", Colorf.LightGreen),

                SOMaterial.CreateStandard("standard_blue", Colorf.VideoBlue),
                SOMaterial.CreateStandard("navy", Colorf.Navy),
                SOMaterial.CreateStandard("cornflower_blue", Colorf.CornflowerBlue),
                SOMaterial.CreateStandard("light_steel_blue", Colorf.LightSteelBlue),

                SOMaterial.CreateStandard("standard_red", Colorf.VideoRed),
                SOMaterial.CreateStandard("fire_red", Colorf.FireBrick),
                SOMaterial.CreateStandard("hot_pink", Colorf.HotPink),
                SOMaterial.CreateStandard("light_pink", Colorf.LightPink),


                SOMaterial.CreateStandard("standard_yellow", Colorf.VideoYellow),
                SOMaterial.CreateStandard("standard_orange", Colorf.Orange),
                SOMaterial.CreateStandard("saddle_brown", Colorf.SaddleBrown),
                SOMaterial.CreateStandard("wheat", Colorf.Wheat),


                SOMaterial.CreateStandard("standard_cyan", Colorf.VideoCyan),
                SOMaterial.CreateStandard("standard_magenta", Colorf.VideoMagenta),
                SOMaterial.CreateStandard("silver", Colorf.Silver),
                SOMaterial.CreateStandard("dark_slate_grey", Colorf.DarkSlateGrey)
            };


            float        fRight     = -41.0f;
            float        df         = -7.25f;
            float        df_fudge   = -0.2f;
            List <float> AngleSteps = new List <float>()
            {
                fRight, fRight + df, fRight + 2 * df, fRight + 3 * df
            };
            float fVertStep = 6.75f;
            float fTop      = 2.0f;

            int ri = 0, ci = 0;

            foreach (SOMaterial m in materials)
            {
                float fXFudge = df_fudge * (float)ri * (float)ci;
                float fX      = AngleSteps[ci++] + fXFudge;
                float fY      = fTop - (float)ri * fVertStep;
                if (ci == AngleSteps.Count)
                {
                    ci = 0; ri++;
                }

                var button = add_material_button(cockpit, m.Name, fHUDRadius,
                                                 fX, fY, fButtonRadius, bgMaterial, m);
                AddChild(button);
                buttons.Add(button);
            }


            fMesh    iconMesh     = null;
            Material iconMaterial = null;

            try {
                iconMesh     = new fMesh(Resources.Load <Mesh>("tool_icons/star"));
                iconMaterial = MaterialUtil.CreateStandardVertexColorMaterial(Color.white);
            } catch { }
            if (iconMesh == null)
            {
                iconMesh     = new fMesh(UnityUtil.GetPrimitiveMesh(PrimitiveType.Sphere));
                iconMaterial = MaterialUtil.CreateStandardMaterial(Color.yellow);
            }
            indicatorGO = new fMeshGameObject(iconMesh);
            indicatorGO.SetName("active_star");
            indicatorGO.SetMesh(iconMesh);
            indicatorGO.SetMaterial(iconMaterial);
            indicatorGO.SetLocalScale(fIndicatorSize * Vector3f.One);
            indicatorGO.SetLocalPosition(indicatorGO.GetLocalPosition() +
                                         fIndicatorShift * (Vector3f.AxisY - 4 * Vector3f.AxisZ + Vector3f.AxisX));

            indicatorButton = buttons[0];   // this is default material
            indicatorButton.AppendNewGO(indicatorGO, indicatorButton.RootGameObject, false);
        }
        public void Create(Cockpit cockpit)
        {
            base.Create();

            float    fHUDRadius    = 0.7f;
            float    fButtonRadius = 0.08f;
            Color    bgColor       = new Color(0.7f, 0.7f, 1.0f, 0.7f);
            Material bgMaterial    = (bgColor.a == 1.0f) ?
                                     MaterialUtil.CreateStandardMaterial(bgColor) : MaterialUtil.CreateTransparentMaterial(bgColor);
            Material primMaterial = MaterialUtil.CreateStandardMaterial(Color.yellow);


            var addCylinderButton = add_primitive_button(cockpit, "addCylinder", fHUDRadius, -45.0f, 0.0f,
                                                         PrimitiveType.Cylinder, 0.7f, bgMaterial, primMaterial,
                                                         () => {
                return(new CylinderSO().Create(cockpit.Scene.DefaultSOMaterial));
            });

            AddChild(addCylinderButton);
            buttons.Add(addCylinderButton);
            buttonTypes[addCylinderButton] = SOTypes.Cylinder;


            var addBoxButton = add_primitive_button(cockpit, "addBox", fHUDRadius, -45.0f, -15.0f,
                                                    PrimitiveType.Cube, 0.7f, bgMaterial, primMaterial,
                                                    () => {
                return(new BoxSO().Create(cockpit.Scene.DefaultSOMaterial));
            });

            AddChild(addBoxButton);
            buttons.Add(addBoxButton);
            buttonTypes[addBoxButton] = SOTypes.Box;


            var addSphereButton = add_primitive_button(cockpit, "addSphere", fHUDRadius, -45.0f, -30.0f,
                                                       PrimitiveType.Sphere, 0.85f, bgMaterial, primMaterial,
                                                       () => {
                return(new SphereSO().Create(cockpit.Scene.DefaultSOMaterial));
            });

            AddChild(addSphereButton);
            buttons.Add(addSphereButton);
            buttonTypes[addSphereButton] = SOTypes.Sphere;


            var addPivotButton = add_primitive_button(cockpit, "addPivot", fHUDRadius, -60.0f, 0.0f,
                                                      PrimitiveType.Sphere, 0.7f, bgMaterial, primMaterial,
                                                      () => {
                return(new PivotSO().Create(cockpit.Scene.PivotSOMaterial, cockpit.Scene.FrameSOMaterial,
                                            FPlatform.WidgetOverlayLayer));
            },
                                                      new pivotIconGenerator()
            {
                SphereMaterial = cockpit.Scene.SelectedMaterial,
                FrameMaterial  = cockpit.Scene.FrameMaterial, PrimSize = fButtonRadius * 0.7f
            });

            AddChild(addPivotButton);
            buttons.Add(addPivotButton);
            buttonTypes[addPivotButton] = SOTypes.Pivot;


            //var addCurveButton = add_curve_button(cockpit, "addCurve", fHUDRadius, -60.0f, -15.0f,
            //    bgMaterial, primMaterial,
            //    () => {
            //        return new PolyCurveSO().Create(cockpit.ActiveScene.DefaultSOMaterial);
            //    });
            //AddChild(addCurveButton);


            /*
             *          HUDButton addBunnyButton = HUDBuilder.CreateGeometryIconClickButton(
             *              new HUDShape(HUDShapeType.Disc, fButtonRadius ),
             *              fHUDRadius, -45.0f, -30.0f, bgColor,
             *              new meshIconGenerator() { MeshPath = "icon_meshes/bunny_1k", UseMaterial = primMaterial, UseSize = fButtonRadius * 0.7f });
             *          addBunnyButton.Name = "addBunnyButton";
             *          addBunnyButton.OnClicked += (s, e) => {
             *              // TODO add existing mesh to scene
             *              cockpit.Parent.Scene.AddBox();
             *          };
             *          cockpit.AddUIElement(addBunnyButton, true);
             */



            // initialize selected-primitive indicator icon
            fMesh     iconMesh     = null;
            fMaterial iconMaterial = null;

            try {
                iconMesh     = new fMesh(Resources.Load <Mesh>("tool_icons/star"));
                iconMaterial = MaterialUtil.CreateStandardVertexColorMaterialF(Color.white);
            } catch { }
            if (iconMesh == null)
            {
                iconMesh     = new fMesh(UnityUtil.GetPrimitiveMesh(PrimitiveType.Sphere));
                iconMaterial = MaterialUtil.CreateStandardMaterialF(Color.yellow);
            }
            indicatorGO = new fMeshGameObject(iconMesh);
            indicatorGO.SetName("active_star");
            indicatorGO.SetMesh(iconMesh);
            indicatorGO.SetMaterial(iconMaterial);
            indicatorGO.SetLocalScale(fIndicatorSize * Vector3f.One);
            indicatorGO.SetLocalPosition(indicatorGO.GetLocalPosition() +
                                         fIndicatorShift * (Vector3f.AxisY - 1 * Vector3f.AxisZ + Vector3f.AxisX));

            indicatorButton = buttons[0];   // this is default material
            indicatorButton.AppendNewGO(indicatorGO, indicatorButton.RootGameObject, false);
        }
Esempio n. 9
0
        public void Create(Cockpit cockpit)
        {
            base.Create();
            this.cockpit = cockpit;

            float fHUDRadius    = 0.7f;
            float fButtonRadius = 0.06f;

            Colorf bgColor     = new Color(0.7f, 0.7f, 1.0f, 0.7f);
            Colorf activeColor = new Colorf(ColorUtil.SelectionGold, 0.7f);

            defaultMaterial = (bgColor.a == 1.0f) ?
                              MaterialUtil.CreateStandardMaterialF(bgColor) : MaterialUtil.CreateTransparentMaterialF(bgColor);
            activeMaterial = (activeColor.a == 1.0f) ?
                             MaterialUtil.CreateStandardMaterialF(activeColor) : MaterialUtil.CreateTransparentMaterialF(activeColor);

            List <toolInfo> toolNames = new List <toolInfo>()
            {
                new toolInfo()
                {
                    identifier = "cancel", sMeshPath = "tool_icons/cancel", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = SnapDrawPrimitivesTool.Identifier, sMeshPath = "tool_icons/draw_primitive", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = DrawTubeTool.Identifier, sMeshPath = "tool_icons/draw_tube", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = DrawCurveTool.Identifier, sMeshPath = "tool_icons/draw_curve", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = DrawSurfaceCurveTool.Identifier, sMeshPath = "tool_icons/draw_surface_curve", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = RevolveTool.Identifier, sMeshPath = "tool_icons/revolve", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = TwoPointMeasureTool.Identifier, sMeshPath = "tool_icons/measure", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = SculptCurveTool.Identifier, sMeshPath = "tool_icons/sculpt_curve", fMeshScaleFudge = 1.2f
                },
                new toolInfo()
                {
                    identifier = PlaneCutTool.Identifier, sMeshPath = "tool_icons/plane_cut", fMeshScaleFudge = 1.2f
                }
            };


            float        fRight     = -43.0f;
            float        df         = -11.0f;
            List <float> AngleSteps = new List <float>()
            {
                fRight, fRight + df, fRight + 2 * df
            };
            float fVertStep = 11.0f;
            float fTop      = 0.0f;

            int ri = 0, ci = 0;

            toolButtons    = new List <ActivateToolButton>();
            toolButtonInfo = new List <toolInfo>();
            foreach (toolInfo t in toolNames)
            {
                float fX = AngleSteps[ci++];
                float fY = fTop - (float)ri * fVertStep;
                if (ci == AngleSteps.Count)
                {
                    ci = 0; ri++;
                }

                var button = add_tool_button(cockpit, t.identifier, fHUDRadius,
                                             fX, fY, fButtonRadius, t);
                AddChild(button);
                toolButtons.Add(button);

                toolInfo ti = new toolInfo();
                ti        = t;
                ti.button = button;
                toolButtonInfo.Add(ti);
            }


            // build indicators
            string[] paths = { "tool_icons/star_green", "tool_icons/star_red" };
            for (int k = 0; k < 2; ++k)
            {
                Mesh     iconMesh     = null;
                Material iconMaterial = null;
                try {
                    iconMesh     = Resources.Load <Mesh>(paths[k]);
                    iconMaterial = MaterialUtil.CreateStandardVertexColorMaterial(Color.white);
                } catch { }
                if (iconMesh == null)
                {
                    iconMesh     = UnityUtil.GetPrimitiveMesh(PrimitiveType.Sphere);
                    iconMaterial = MaterialUtil.CreateStandardMaterial((k == 0) ? Color.green : Color.red);
                }
                indicator[k]      = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                indicator[k].name = (k == 0) ? "left_tool_star" : "right_tool_star";
                Component.Destroy(indicator[k].GetComponent <Collider>());
                indicator[k].SetMesh(iconMesh);
                indicator[k].GetComponent <Renderer>().material = iconMaterial;


                // have to add to some button because we need them to be in GO tree
                //  when we do AddChild() on cockpit...that sets up layer, size, etc
                indicatorButton[k] = toolButtons[0];
                indicator[k].transform.localScale     = fIndicatorSize * Vector3.one;
                indicator[k].transform.localPosition +=
                    fIndicatorShiftXY * (Vector3.up + Vector3.right * ((k == 0) ? -1 : 1)) - fIndicatorShiftZ * Vector3.forward;
                indicatorButton[k].AppendNewGO(indicator[k], indicatorButton[k].RootGameObject, false);
                indicator[k].Hide();
            }


            // listen for changes
            cockpit.Context.ToolManager.OnToolActivationChanged += on_tool_changed;
        }