Ejemplo n.º 1
0
        public void SetHandIcon(Mesh m, int iSide)
        {
            SpatialDevice h = (iSide == 0) ? Left : Right;

            if (h.HandIcon != null)
            {
                h.HandIcon.transform.parent = null;
                GameObject.Destroy(h.HandIcon);
            }

            h.HandIcon =
                UnityUtil.CreateMeshGO("hand_icon", m, MaterialUtil.CreateStandardVertexColorMaterial(Color.white), false);
            h.HandIcon.transform.localScale    = 0.3f * Vector3.one;
            h.HandIcon.transform.localPosition = new Vector3(0.0f, -0.3f, -0.3f);
            h.HandIcon.transform.SetParent(h.Hand.transform, false);
            h.HandIcon.SetLayer(FPlatform.CursorLayer);
        }
        public void SetHandIcon(Mesh m, int iSide)
        {
            SpatialDevice h = (iSide == 0) ? Left : Right;

            if (h.HandIcon != null)
            {
                h.HandIcon.transform.parent = null;
                h.HandIcon.Destroy();
            }

            h.HandIcon =
                UnityUtil.CreateMeshGO("hand_icon", m, MaterialUtil.CreateStandardVertexColorMaterial(Color.white), false);
            float s = SceneGraphConfig.VRHandArrowRadius;

            h.HandIcon.transform.localScale    = s * 0.3f * Vector3.one;
            h.HandIcon.transform.localPosition = new Vector3(0.0f, -0.3f * s, -0.3f * s);
            h.HandIcon.transform.SetParent(h.Hand.transform, false);
            h.HandIcon.SetLayer(FPlatform.CursorLayer);
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
 public static Material ToUnityMaterial(SOMaterial m)
 {
     if (m.Type == SOMaterial.MaterialType.TextureMap)
     {
         Material unityMat = new Material(Shader.Find("Standard"));
         unityMat.SetName(m.Name);
         unityMat.color = m.RGBColor;
         //if (m.Alpha < 1.0f)
         //    MaterialUtil.SetupMaterialWithBlendMode(unityMat, MaterialUtil.BlendMode.Transparent);
         unityMat.mainTexture = m.MainTexture;
         return(unityMat);
     }
     else if (m.Type == SOMaterial.MaterialType.PerVertexColor)
     {
         return(MaterialUtil.CreateStandardVertexColorMaterial(m.RGBColor));
     }
     else if (m.Type == SOMaterial.MaterialType.TransparentRGBColor)
     {
         return(MaterialUtil.CreateTransparentMaterial(m.RGBColor));
     }
     else if (m.Type == SOMaterial.MaterialType.StandardRGBColor)
     {
         return(MaterialUtil.CreateStandardMaterial(m.RGBColor));
     }
     else if (m.Type == SOMaterial.MaterialType.UnlitRGBColor)
     {
         return(MaterialUtil.CreateFlatMaterial(m.RGBColor));
     }
     else if (m is UnitySOMaterial)
     {
         return((m as UnitySOMaterial).unityMaterial);
     }
     else
     {
         return(MaterialUtil.CreateStandardMaterial(Color.black));
     }
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public static fMaterial ToMaterialf(SOMaterial m)
        {
            fMaterial unityMat = null;

            if (m.Type == SOMaterial.MaterialType.TextureMap)
            {
                unityMat       = new Material(Shader.Find("Standard"));
                unityMat.name  = m.Name;
                unityMat.color = m.RGBColor;
                //if (m.Alpha < 1.0f)
                //    MaterialUtil.SetupMaterialWithBlendMode(unityMat, MaterialUtil.BlendMode.Transparent);
                unityMat.mainTexture = m.MainTexture;
            }
            else if (m.Type == SOMaterial.MaterialType.PerVertexColor)
            {
                unityMat              = MaterialUtil.CreateStandardVertexColorMaterial(m.RGBColor);
                unityMat.renderQueue += m.RenderQueueShift;
                unityMat.SetInt("_Cull", (int)m.CullingMode);
            }
            else if (m.Type == SOMaterial.MaterialType.FlatShadedPerVertexColor)
            {
                unityMat              = MaterialUtil.CreateFlatShadedVertexColorMaterialF(m.RGBColor);
                unityMat.renderQueue += m.RenderQueueShift;
                unityMat.SetInt("_Cull", (int)m.CullingMode);
            }
            else if (m.Type == SOMaterial.MaterialType.TransparentRGBColor)
            {
                unityMat              = MaterialUtil.CreateTransparentMaterial(m.RGBColor);
                unityMat.renderQueue += m.RenderQueueShift;
            }
            else if (m.Type == SOMaterial.MaterialType.StandardRGBColor)
            {
                unityMat              = MaterialUtil.CreateStandardMaterial(m.RGBColor);
                unityMat.renderQueue += m.RenderQueueShift;
            }
            else if (m.Type == SOMaterial.MaterialType.UnlitRGBColor)
            {
                unityMat              = MaterialUtil.CreateFlatMaterial(m.RGBColor);
                unityMat.renderQueue += m.RenderQueueShift;
            }
            else if (m.Type == SOMaterial.MaterialType.DepthWriteOnly)
            {
                unityMat              = MaterialUtil.CreateDepthWriteOnly();
                unityMat.renderQueue += m.RenderQueueShift;
            }
            else if (m.Type == SOMaterial.MaterialType.StandardMesh)
            {
                fMeshMaterial meshMat = MaterialUtil.CreateStandardMeshMaterial(m.RGBColor);
                meshMat.renderQueue += m.RenderQueueShift;
                if (m is SOMeshMaterial)
                {
                    meshMat.InitializeFromSOMaterial(m as SOMeshMaterial);
                }
                unityMat = meshMat;
            }
            else if (m is UnitySOMeshMaterial)
            {
                unityMat = (m as UnitySOMeshMaterial).meshMaterial;
            }
            else if (m is UnitySOMaterial)
            {
                unityMat = (m as UnitySOMaterial).unityMaterial;
            }
            else
            {
                unityMat = MaterialUtil.CreateStandardMaterial(Color.black);
            }

            if ((m.Hints & SOMaterial.HintFlags.UseTransparentPass) != 0)
            {
                SetupMaterialWithBlendMode(unityMat, BlendMode.Transparent);
            }

            if (m.MaterialCustomizerF != null)
            {
                m.MaterialCustomizerF(unityMat);
            }

            return(unityMat);
        }
Ejemplo n.º 7
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;
        }