virtual protected void make_materials() { float fAlpha = 0.5f; srcMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.CgRed, fAlpha); srcHoverMaterial = MaterialUtil.CreateStandardMaterial(ColorUtil.CgRed); }
// Use this for initialization public void Start() { dx = 0; dy = 0; vPlaneCursorPos = Vector3.zero; vSceneCursorPos = vPlaneCursorPos; CursorDefaultMaterial = MaterialUtil.CreateTransparentMaterial(Color.grey, 0.2f); CursorHitMaterial = MaterialUtil.CreateTransparentMaterial(Color.yellow, 0.8f); CursorCapturingMaterial = MaterialUtil.CreateTransparentMaterial(Color.cyan, 0.3f); CursorVisualAngleInDegrees = 1.5f; Cursor = GameObject.CreatePrimitive(PrimitiveType.Sphere); Cursor.name = "cursor"; Cursor.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f); MeshRenderer ren = Cursor.GetComponent <MeshRenderer> (); ren.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; ren.receiveShadows = false; ren.material = CursorDefaultMaterial; xformObject = GameObject.CreatePrimitive(PrimitiveType.Plane); xformObject.name = "cursor_plane"; MeshRenderer ren2 = xformObject.GetComponent <MeshRenderer> (); ren2.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; ren2.receiveShadows = false; ren2.material = MaterialUtil.CreateTransparentMaterial(Color.cyan, 0.2f); ren2.enabled = false; }
public virtual fMaterial MakeHoverMaterial(AxisGizmoFlags widget) { switch (widget) { case AxisGizmoFlags.AxisRotateX: case AxisGizmoFlags.AxisTranslateX: case AxisGizmoFlags.PlaneTranslateX: if (XHover == null) { XHover = MaterialUtil.CreateTransparentMaterial(Colorf.VideoRed); if (OverrideRenderQueue != -1) { XHover.renderQueue = OverrideRenderQueue; } } return(XHover); case AxisGizmoFlags.AxisRotateY: case AxisGizmoFlags.AxisTranslateY: case AxisGizmoFlags.PlaneTranslateY: if (YHover == null) { YHover = MaterialUtil.CreateTransparentMaterial(Colorf.VideoGreen); if (OverrideRenderQueue != -1) { YHover.renderQueue = OverrideRenderQueue; } } return(YHover); case AxisGizmoFlags.AxisRotateZ: case AxisGizmoFlags.AxisTranslateZ: case AxisGizmoFlags.PlaneTranslateZ: if (ZHover == null) { ZHover = MaterialUtil.CreateTransparentMaterial(Colorf.VideoBlue); if (OverrideRenderQueue != -1) { ZHover.renderQueue = OverrideRenderQueue; } } return(ZHover); case AxisGizmoFlags.UniformScale: if (AllHover == null) { AllHover = MaterialUtil.CreateTransparentMaterial(Colorf.VideoWhite); if (OverrideRenderQueue != -1) { AllHover.renderQueue = OverrideRenderQueue; } } return(AllHover); default: throw new Exception("DefaultAxisGizmoWidgetFactory.MakeHoverMaterial: invalid widget type " + widget.ToString()); } }
public void BeginSetWorldScale(Frame3f center, Frame3f plane, float minr) { deadzone_r = minr; hitFrame = plane; mYes = MaterialUtil.CreateTransparentMaterial(ColorUtil.PivotYellow, 0.5f); mNo = MaterialUtil.CreateTransparentMaterial(ColorUtil.MiddleGrey, 0.3f); go = UnityUtil.CreatePrimitiveGO("worldscale_ball", PrimitiveType.Sphere, mNo); UnityUtil.SetGameObjectFrame(go, center, CoordSpace.WorldCoords); }
public void Start() { ShowTarget = false; targetGO = GameObject.CreatePrimitive(PrimitiveType.Sphere); visibleMaterial = MaterialUtil.CreateTransparentMaterial(Color.red, 0.8f); hiddenMaterial = MaterialUtil.CreateTransparentMaterial(Color.red, 0.4f); targetGO.GetComponent <MeshRenderer>().material = hiddenMaterial; targetGO.SetLayer(FPlatform.WidgetOverlayLayer); MaterialUtil.DisableShadows(targetGO); targetGO.SetName("camera_target"); }
public void Initialize(Cockpit cockpit) { Frame3 cockpitF = cockpit.GetLocalFrame(CoordSpace.WorldCoords); float fHUDRadius = 0.7f; Color bgColor = new Color(0.7f, 0.7f, 1.0f); Material bgMaterial = MaterialUtil.CreateTransparentMaterial(bgColor, 0.7f); Material primMaterial = MaterialUtil.CreateStandardMaterial(Color.yellow); HUDButton addCylinderButton = new HUDButton() { Radius = 0.08f }; addCylinderButton.Create(PrimitiveType.Cylinder, bgMaterial, primMaterial); Frame3 cylFrame = addCylinderButton.GetObjectFrame(); Frame3 cylHUDFrame = make_hud_sphere_frame(fHUDRadius, -45.0f, 0.0f); addCylinderButton.SetObjectFrame( cylFrame.Translated(cylHUDFrame.Origin) .Rotated(Quaternion.FromToRotation(cylFrame.Z, cylHUDFrame.Z))); addCylinderButton.OnClicked += (s, e) => { cockpit.Parent.Scene.AddCylinder(); }; cockpit.AddUIElement(addCylinderButton, true); HUDButton addBoxButton = new HUDButton() { Radius = 0.08f }; addBoxButton.Create(PrimitiveType.Cube, bgMaterial, primMaterial); Frame3 boxFrame = addBoxButton.GetObjectFrame(); Frame3 boxHUDFrame = make_hud_sphere_frame(fHUDRadius, -45.0f, -15.0f); addBoxButton.SetObjectFrame( boxFrame.Translated(boxHUDFrame.Origin) .Rotated(Quaternion.FromToRotation(boxFrame.Z, boxHUDFrame.Z))); addBoxButton.OnClicked += (s, e) => { cockpit.Parent.Scene.AddBox(); }; cockpit.AddUIElement(addBoxButton, true); }
public static HUDButton CreateGeometryIconClickButton(HUDShape shape, float fHUDRadius, float fAngleHorz, float fAngleVert, Color bgColor, IGameObjectGenerator addGeometry = null) { Material mat = (bgColor.a == 1.0f) ? MaterialUtil.CreateStandardMaterial(bgColor) : MaterialUtil.CreateTransparentMaterial(bgColor); HUDButton button = new HUDButton() { Shape = shape }; button.Create(mat); if (addGeometry != null) { button.AddVisualElements(addGeometry.Generate(), true); } HUDUtil.PlaceInSphere(button, fHUDRadius, fAngleHorz, fAngleVert); return(button); }
public static HUDButton CreateMeshClickButton( Mesh mesh, Color color, float fMeshScale, Quaternion meshRotation, HUDSurface hudSurf, float dx, float dy, IGameObjectGenerator addGeometry = null) { Material mat = (color.a < 1.0f) ? MaterialUtil.CreateTransparentMaterial(color, color.a) : MaterialUtil.CreateStandardMaterial(color); HUDButton button = new HUDButton(); button.Create(mesh, mat, fMeshScale, meshRotation); if (addGeometry != null) { button.AddVisualElements(addGeometry.Generate(), true); } hudSurf.Place(button, dx, dy); return(button); }
static public GameObject EmitDebugCursorSphere(string name, float diameter, Color color) { if (FContext.ActiveContext_HACK.MouseCameraController is VRMouseCursorController) { GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.SetName(name); sphere.transform.position = (FContext.ActiveContext_HACK.MouseCameraController as VRMouseCursorController).CurrentCursorPosWorld; sphere.transform.localScale = new Vector3(diameter, diameter, diameter); sphere.GetComponent <MeshRenderer>().material = MaterialUtil.CreateTransparentMaterial(color, 0.5f); MaterialUtil.DisableShadows(sphere); sphere.SetLayer(FPlatform.HUDLayer); return(sphere); } else { throw new Exception("DebugUtil.EmitDebugCursorSphere: only works for VRMouseCursorController!"); } }
public static HUDButton CreateMeshClickButton( Mesh mesh, Color color, float fMeshScale, Quaternion meshRotation, float fHUDRadius, float fAngleHorz, float fAngleVert, IGameObjectGenerator addGeometry = null) { Material mat = (color.a < 1.0f) ? MaterialUtil.CreateTransparentMaterial(color, color.a) : MaterialUtil.CreateStandardMaterial(color); HUDButton button = new HUDButton(); button.Create(mesh, mat, fMeshScale, meshRotation); if (addGeometry != null) { button.AddVisualElements(addGeometry.Generate(), true); } HUDUtil.PlaceInSphere(button, fHUDRadius, fAngleHorz, fAngleVert); return(button); }
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)); } }
// Use this for initialization public void Start() { fCursorSpeedNormalization = 1.0f; fCurPlaneX = 0; fCurPlaneY = 0; vPlaneCursorPos = Vector3.zero; vSceneCursorPos = vPlaneCursorPos; CursorDefaultMaterial = MaterialUtil.CreateTransparentMaterial(Color.grey, 0.6f); //CursorHitMaterial = MaterialUtil.CreateTransparentMaterial (Color.yellow, 0.8f); CursorHitMaterial = MaterialUtil.CreateStandardMaterial(Color.yellow); CursorCapturingMaterial = MaterialUtil.CreateTransparentMaterial(Color.yellow, 0.75f); CursorVisualAngleInDegrees = 1.5f; standardCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16); UnityUtil.TranslateMesh(standardCursorMesh, 0, -2.0f, 0); activeToolCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 1.0f, 16); UnityUtil.TranslateMesh(activeToolCursorMesh, 0, -2.0f, 0); Cursor = UnityUtil.CreateMeshGO("cursor", standardCursorMesh, CursorDefaultMaterial); Cursor.SetSharedMesh(standardCursorMesh); Cursor.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f); Cursor.transform.localRotation = Quaternion.AngleAxis(45.0f, new Vector3(1, 0, 1).normalized); MaterialUtil.DisableShadows(Cursor); xformObject = GameObject.CreatePrimitive(PrimitiveType.Plane); xformObject.SetName("cursor_plane"); MaterialUtil.DisableShadows(xformObject); xformObject.GetComponent <MeshRenderer>().material = MaterialUtil.CreateTransparentMaterial(Color.cyan, 0.2f); xformObject.GetComponent <MeshRenderer>().enabled = false; lastMouseEventTime = FPlatform.RealTime(); mouseInactiveState = false; }
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); }
public virtual void initialize(fGameObject go, Colorf color) { r = ((GameObject)go).AddComponent <LineRenderer>(); r.useWorldSpace = false; r.material = MaterialUtil.CreateTransparentMaterial(color); }
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); }
void InitializeSpatialInput() { Left = new SpatialDevice(); Right = new SpatialDevice(); Left.CursorDefaultMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.ForestGreen, 0.6f); Left.CursorHitMaterial = MaterialUtil.CreateStandardMaterial(ColorUtil.SelectionGold); Left.CursorCapturingMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.SelectionGold, 0.75f); Left.HandMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.ForestGreen, 0.3f); Right.CursorDefaultMaterial = MaterialUtil.CreateTransparentMaterial(Colorf.DarkRed, 0.6f); Right.CursorHitMaterial = MaterialUtil.CreateStandardMaterial(ColorUtil.PivotYellow); Right.CursorCapturingMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.PivotYellow, 0.75f); Right.HandMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.CgRed, 0.3f); CursorVisualAngleInDegrees = 1.5f; standardCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16); UnityUtil.TranslateMesh(standardCursorMesh, 0, -2.0f, 0); activeToolCursorMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 1.0f, 16); UnityUtil.TranslateMesh(activeToolCursorMesh, 0, -2.0f, 0); Left.Cursor = UnityUtil.CreateMeshGO("left_cursor", standardCursorMesh, Left.CursorDefaultMaterial); Left.Cursor.transform.localScale = 0.3f * Vector3.one; Left.Cursor.transform.localRotation = Quaternion.AngleAxis(45.0f, new Vector3(1, 0, 1).normalized); MaterialUtil.DisableShadows(Left.Cursor); Left.Cursor.SetLayer(FPlatform.CursorLayer); Left.SmoothedHandFrame = Frame3f.Identity; var leftHandMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16); Left.Hand = UnityUtil.CreateMeshGO("left_hand", leftHandMesh, Left.HandMaterial); UnityUtil.TranslateMesh(leftHandMesh, 0, -1.0f, 0); Left.Hand.transform.localScale = 0.1f * Vector3.one; Left.Hand.transform.rotation = Quaternion.FromToRotation(Vector3.up, Vector3.forward); Left.Hand.SetLayer(FPlatform.HUDLayer); Left.Laser = new GameObject("left_laser"); Left.LaserRen = Left.Laser.AddComponent <LineRenderer>(); Left.LaserRen.SetPositions(new Vector3[2] { Vector3.zero, 100 * Vector3.up }); Left.LaserRen.startWidth = Left.LaserRen.endWidth = 0.01f; Left.LaserRen.material = MaterialUtil.CreateFlatMaterial(ColorUtil.ForestGreen, 0.2f); Left.Laser.SetLayer(FPlatform.CursorLayer); Left.Laser.transform.parent = Left.Cursor.transform; Right.Cursor = UnityUtil.CreateMeshGO("right_cursor", standardCursorMesh, Right.CursorDefaultMaterial); Right.Cursor.transform.localScale = 0.3f * Vector3.one; Right.Cursor.transform.localRotation = Quaternion.AngleAxis(45.0f, new Vector3(1, 0, 1).normalized); MaterialUtil.DisableShadows(Right.Cursor); Right.Cursor.SetLayer(FPlatform.CursorLayer); Right.SmoothedHandFrame = Frame3f.Identity; var rightHandMesh = MeshGenerators.Create3DArrow(1.0f, 1.0f, 1.0f, 0.5f, 16); Right.Hand = UnityUtil.CreateMeshGO("right_hand", rightHandMesh, Right.HandMaterial); UnityUtil.TranslateMesh(rightHandMesh, 0, -1.0f, 0); Right.Hand.transform.localScale = 0.1f * Vector3.one; Right.Hand.transform.rotation = Quaternion.FromToRotation(Vector3.up, Vector3.forward); Right.Hand.SetLayer(FPlatform.HUDLayer); Right.Laser = new GameObject("right_laser"); Right.LaserRen = Right.Laser.AddComponent <LineRenderer>(); Right.LaserRen.SetPositions(new Vector3[2] { Vector3.zero, 100 * Vector3.up }); Right.LaserRen.startWidth = Right.LaserRen.endWidth = 0.01f; Right.LaserRen.material = MaterialUtil.CreateFlatMaterial(ColorUtil.CgRed, 0.2f); Right.Laser.SetLayer(FPlatform.CursorLayer); Right.Laser.transform.parent = Right.Cursor.transform; spatialInputInitialized = true; }
public void Create(Scene parentScene, TransformableSceneObject target) { this.parentScene = parentScene; this.target = target; this.parentScene.SelectionChangedEvent += OnSceneSelectionChanged; gizmo = new GameObject("TransformGizmo"); float fAlpha = 0.5f; xMaterial = MaterialUtil.CreateTransparentMaterial(Color.red, fAlpha); yMaterial = MaterialUtil.CreateTransparentMaterial(Color.green, fAlpha); zMaterial = MaterialUtil.CreateTransparentMaterial(Color.blue, fAlpha); x = AppendMeshGO("x_translate", (Mesh)Resources.Load("meshes/transform_gizmo_x", typeof(Mesh)), xMaterial, gizmo); Widgets [x] = new AxisTranslationWidget(0, parentScene); y = AppendMeshGO("y_translate", (Mesh)Resources.Load("meshes/transform_gizmo_y", typeof(Mesh)), yMaterial, gizmo); Widgets [y] = new AxisTranslationWidget(1, parentScene); z = AppendMeshGO("z_translate", (Mesh)Resources.Load("meshes/transform_gizmo_z", typeof(Mesh)), zMaterial, gizmo); Widgets [z] = new AxisTranslationWidget(2, parentScene); rotate_x = AppendMeshGO("x_rotate", (Mesh)Resources.Load("meshes/axisrotate_x", typeof(Mesh)), xMaterial, gizmo); Widgets [rotate_x] = new AxisRotationWidget(0, parentScene); rotate_y = AppendMeshGO("y_rotate", (Mesh)Resources.Load("meshes/axisrotate_y", typeof(Mesh)), yMaterial, gizmo); Widgets [rotate_y] = new AxisRotationWidget(1, parentScene); rotate_z = AppendMeshGO("z_rotate", (Mesh)Resources.Load("meshes/axisrotate_z", typeof(Mesh)), zMaterial, gizmo); Widgets [rotate_z] = new AxisRotationWidget(2, parentScene); // plane translation widgets translate_xy = AppendMeshGO("xy_translate", (Mesh)Resources.Load("meshes/plane_translate_xy", typeof(Mesh)), zMaterial, gizmo); Widgets [translate_xy] = new PlaneTranslationWidget(2, parentScene); translate_xz = AppendMeshGO("xz_translate", (Mesh)Resources.Load("meshes/plane_translate_xz", typeof(Mesh)), yMaterial, gizmo); Widgets [translate_xz] = new PlaneTranslationWidget(1, parentScene); translate_yz = AppendMeshGO("yz_translate", (Mesh)Resources.Load("meshes/plane_translate_yz", typeof(Mesh)), xMaterial, gizmo); Widgets [translate_yz] = new PlaneTranslationWidget(0, parentScene); // disable shadows on widget components foreach (var go in GameObjects) { go.GetComponent <MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; } eCurrentFrameMode = FrameType.LocalFrame; SetActiveFrame(eCurrentFrameMode); int nWidgetLayer = LayerMask.NameToLayer(SceneGraphConfig.WidgetOverlayLayerName); foreach (var go in GameObjects) { go.layer = nWidgetLayer; } }
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(FScene parentScene, List <TransformableSO> targets) { this.parentScene = parentScene; this.targets = targets; gizmo = new GameObject("TransformGizmo"); float fAlpha = 0.5f; xMaterial = MaterialUtil.CreateTransparentMaterial(Color.red, fAlpha); yMaterial = MaterialUtil.CreateTransparentMaterial(Color.green, fAlpha); zMaterial = MaterialUtil.CreateTransparentMaterial(Color.blue, fAlpha); xHoverMaterial = MaterialUtil.CreateStandardMaterial(Color.red); yHoverMaterial = MaterialUtil.CreateStandardMaterial(Color.green); zHoverMaterial = MaterialUtil.CreateStandardMaterial(Color.blue); allMaterial = MaterialUtil.CreateTransparentMaterial(Color.white, fAlpha); allHoverMaterial = MaterialUtil.CreateStandardMaterial(Color.white); x = AppendMeshGO("x_translate", (Mesh)Resources.Load("transform_gizmo/axis_translate_x", typeof(Mesh)), xMaterial, gizmo); Widgets[x] = new AxisTranslationWidget(0) { RootGameObject = x, StandardMaterial = xMaterial, HoverMaterial = xHoverMaterial, TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); } }; y = AppendMeshGO("y_translate", (Mesh)Resources.Load("transform_gizmo/axis_translate_y", typeof(Mesh)), yMaterial, gizmo); Widgets [y] = new AxisTranslationWidget(1) { RootGameObject = y, StandardMaterial = yMaterial, HoverMaterial = yHoverMaterial, TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); } }; z = AppendMeshGO("z_translate", (Mesh)Resources.Load("transform_gizmo/axis_translate_z", typeof(Mesh)), zMaterial, gizmo); Widgets [z] = new AxisTranslationWidget(2) { RootGameObject = z, StandardMaterial = zMaterial, HoverMaterial = zHoverMaterial, TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); } }; rotate_x = AppendMeshGO("x_rotate", (Mesh)Resources.Load("transform_gizmo/axisrotate_x", typeof(Mesh)), xMaterial, gizmo); Widgets [rotate_x] = new AxisRotationWidget(0) { RootGameObject = rotate_x, StandardMaterial = xMaterial, HoverMaterial = xHoverMaterial }; rotate_y = AppendMeshGO("y_rotate", (Mesh)Resources.Load("transform_gizmo/axisrotate_y", typeof(Mesh)), yMaterial, gizmo); Widgets [rotate_y] = new AxisRotationWidget(1) { RootGameObject = rotate_y, StandardMaterial = yMaterial, HoverMaterial = yHoverMaterial }; rotate_z = AppendMeshGO("z_rotate", (Mesh)Resources.Load("transform_gizmo/axisrotate_z", typeof(Mesh)), zMaterial, gizmo); Widgets [rotate_z] = new AxisRotationWidget(2) { RootGameObject = rotate_z, StandardMaterial = zMaterial, HoverMaterial = zHoverMaterial }; // plane translation widgets translate_xy = AppendMeshGO("xy_translate", (Mesh)Resources.Load("transform_gizmo/plane_translate_xy", typeof(Mesh)), zMaterial, gizmo); Widgets [translate_xy] = new PlaneTranslationWidget(2) { RootGameObject = translate_xy, StandardMaterial = zMaterial, HoverMaterial = zHoverMaterial, TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); } }; translate_xz = AppendMeshGO("xz_translate", (Mesh)Resources.Load("transform_gizmo/plane_translate_xz", typeof(Mesh)), yMaterial, gizmo); Widgets [translate_xz] = new PlaneTranslationWidget(1) { RootGameObject = translate_xz, StandardMaterial = yMaterial, HoverMaterial = yHoverMaterial, TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); } }; translate_yz = AppendMeshGO("yz_translate", (Mesh)Resources.Load("transform_gizmo/plane_translate_yz", typeof(Mesh)), xMaterial, gizmo); Widgets [translate_yz] = new PlaneTranslationWidget(0) { RootGameObject = translate_yz, StandardMaterial = xMaterial, HoverMaterial = xHoverMaterial, TranslationScaleF = () => { return(1.0f / parentScene.GetSceneScale()); } }; uniform_scale = AppendMeshGO("uniform_scale", Resources.Load <Mesh>("transform_gizmo/uniform_scale"), allMaterial, gizmo); Widgets[uniform_scale] = new UniformScaleWidget(parentScene.ActiveCamera) { RootGameObject = uniform_scale, StandardMaterial = allMaterial, HoverMaterial = allHoverMaterial, ScaleMultiplierF = () => { return(1.0f / parentScene.GetSceneScale()); } }; gizmoGeomBounds = UnityUtil.GetGeometryBoundingBox(new List <GameObject>() { x, y, z, rotate_x, rotate_y, rotate_z, translate_xy, translate_xz, translate_yz, uniform_scale }); // disable shadows on widget components foreach (var go in GameObjects) { MaterialUtil.DisableShadows(go); } eCurrentFrameMode = FrameType.LocalFrame; SetActiveFrame(eCurrentFrameMode); SetLayer(FPlatform.WidgetOverlayLayer); // seems like possibly this geometry will be shown this frame, before PreRender() // is called, which means that on next frame the geometry will pop. // So we hide here and show in PreRender gizmo.Hide(); }