void create_sub_items(MenuItem topItem, float fParentRadius, float fParentAngleMin, float fParentAngleMax) { float fInnerRadius = fParentRadius + SubItemRadialPadding; float fOuterRadius = fInnerRadius + SubItemRadialWidth; int nItems = topItem.SubItems.Count; //float fParentAngleSpan = fParentAngleMax - fParentAngleMin; float fParentAngleMid = 0.5f * (fParentAngleMax + fParentAngleMin); //float fSubMenuSpan = 180.0f - (WedgePadding * (float)(nItems-1)); //float fWedgeSpan = fSubMenuSpan / (float)nItems; float fWedgeSpan = 45.0f; float fSubMenuSpan = nItems * fWedgeSpan + (float)(nItems - 1) * WedgePadding; int nSlicesPerWedge = 16; float fCurAngle = fParentAngleMid - fSubMenuSpan * 0.5f; for (int i = 0; i < nItems; ++i) { MenuItem item = topItem.SubItems[i]; Mesh m = MeshGenerators.CreatePuncturedDisc(fInnerRadius, fOuterRadius, nSlicesPerWedge, fCurAngle, fCurAngle + fWedgeSpan); float fMidAngleRad = (fCurAngle + fWedgeSpan * 0.5f) * Mathf.Deg2Rad; Vector2 vMid = new Vector2(Mathf.Cos(fMidAngleRad), Mathf.Sin(fMidAngleRad)); GameObject itemGO = AppendMeshGO(item.Label, m, itemMaterial, menuContainer); itemGO.transform.Rotate(Vector3.right, -90.0f); // ?? topItem.SubItems[i].GO = itemGO; // [TODO] this is to improve font centering. Right now we do absolute centering // but visually this looks wrong because weight of font is below center-y. // Right thing would be to align at top of lowercase letters, rather than center-y // (to fix in future) float fudge = 0.0f; if (nItems == 2 && i == 1) { fudge = -0.1f; } TextLabelGenerator textGen = new TextLabelGenerator() { Text = item.Label, Scale = SubItemTextScale, Translate = vMid * (fInnerRadius + (TextCenterPointFactor + fudge) * SubItemRadialWidth), Align = TextLabelGenerator.Alignment.HVCenter }; List <GameObject> vTextElems = textGen.Generate(); AddVisualElements(vTextElems, true); // actually want these GOs to be parented to itemGO UnityUtil.AddChildren(itemGO, vTextElems, true); itemGO.SetVisible(false); if (item.SubItems != null) { create_sub_items(item, fOuterRadius, fCurAngle, fCurAngle + fWedgeSpan); } fCurAngle += WedgePadding + fWedgeSpan; } }
public CylinderSO Create(SOMaterial defaultMaterial) { cylinder = new GameObject(UniqueNames.GetNext("Cylinder")); AssignSOMaterial(defaultMaterial); // need to do this to setup BaseSO material stack Material useMaterial = CurrentMaterial; topCap = AppendMeshGO("topCap", MeshGenerators.CreateDisc(radius, 1, 16), useMaterial, cylinder); topCap.transform.localPosition += 0.5f * height * Vector3.up; bottomCap = AppendMeshGO("bottomCap", MeshGenerators.CreateDisc(radius, 1, 16), useMaterial, cylinder); bottomCap.transform.RotateAround(Vector3.zero, Vector3.right, 180.0f); bottomCap.transform.localPosition -= 0.5f * height * Vector3.up; body = AppendMeshGO("body", MeshGenerators.CreateCylider(radius, height, 16), useMaterial, cylinder); body.transform.localPosition -= 0.5f * height * Vector3.up; update_shift(); cylinder.transform.position += centerShift; increment_timestamp(); return(this); }
public static fRingGameObject CreateRingGO(string sName, float fInnerRadius, float fOuterRadius, fMaterial material, bool bShareMaterial, bool bCollider) { GameObject go = new GameObject(sName); fMesh ringMesh = MeshGenerators.CreatePuncturedDisc(fInnerRadius, fOuterRadius, 32); initialize_meshgo(go, ringMesh, bCollider, true); go.SetMaterial(material, bShareMaterial); return(new fRingGameObject(go, new fMesh(go.GetSharedMesh()), fOuterRadius, fInnerRadius)); }
public void Create(Material defaultMaterial) { button = new GameObject(string.Format("HUDButton{0}", button_counter++)); buttonDisc = AppendMeshGO("disc", MeshGenerators.CreateTrivialDisc(Radius, 32), defaultMaterial, button); buttonDisc.transform.Rotate(Vector3.right, -90.0f); // ?? }
public void Create(PrimitiveType eType, Material bgMaterial, Material primMaterial) { button = new GameObject(string.Format("HUDButton{0}", button_counter++)); buttonDisc = AppendMeshGO("disc", MeshGenerators.CreateTrivialDisc(Radius, 32), bgMaterial, button); buttonDisc.transform.Rotate(Vector3.right, -90.0f); // ?? GameObject prim = AppendUnityPrimitiveGO("primitive", eType, primMaterial, button); float primSize = Radius * 0.7f; prim.transform.localScale = new Vector3(primSize, primSize, primSize); prim.transform.Translate(0.0f, 0.0f, -primSize); prim.transform.Rotate(-15.0f, 45.0f, 0.0f, Space.Self); }
Mesh make_button_body_mesh() { if (Shape.Type == HUDShapeType.Disc) { return(MeshGenerators.CreateTrivialDisc(Shape.Radius, Shape.Slices)); } else if (Shape.Type == HUDShapeType.Rectangle) { return(MeshGenerators.CreateTrivialRect(Shape.Width, Shape.Height, Shape.UseUVSubRegion == true ? MeshGenerators.UVRegionType.CenteredUVRectangle : MeshGenerators.UVRegionType.FullUVSquare)); } else { throw new Exception("[HUDButton::make_button_body_mesh] unknown shape type!"); } }
public void Create(Material defaultMaterial) { cylinder = new GameObject("f3Cylinder"); topCap = AppendMeshGO("topCap", MeshGenerators.CreateDisc(radius, 2, 16), defaultMaterial, cylinder); topCap.transform.position += 0.5f * height * Vector3.up; bottomCap = AppendMeshGO("bottomCap", MeshGenerators.CreateDisc(radius, 2, 16), defaultMaterial, cylinder); bottomCap.transform.RotateAround(Vector3.zero, Vector3.right, 180.0f); bottomCap.transform.position -= 0.5f * height * Vector3.up; body = AppendMeshGO("body", MeshGenerators.CreateCylider(radius, height, 16), defaultMaterial, cylinder); body.transform.position -= 0.5f * height * Vector3.up; cylinder.transform.position += 0.5f * height * Vector3.up; }
// 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; }
/// <summary> /// Create a fMesh of the shape/dimensions specified by Shape /// </summary> public static fMesh MakeBackgroundMesh(HUDShape Shape) { if (Shape.Type == HUDShapeType.Disc) { return(MeshGenerators.CreateTrivialDisc(Shape.Radius, Shape.Slices)); } else if (Shape.Type == HUDShapeType.Rectangle) { return(MeshGenerators.CreateTrivialRect(Shape.Width, Shape.Height, Shape.UseUVSubRegion == true ? MeshGenerators.UVRegionType.CenteredUVRectangle : MeshGenerators.UVRegionType.FullUVSquare)); } else if (Shape.Type == HUDShapeType.RoundRect) { return(MeshGenerators.CreateRoundRect(Shape.Width, Shape.Height, Shape.Radius, Shape.Slices, Shape.UseUVSubRegion == true ? MeshGenerators.UVRegionType.CenteredUVRectangle : MeshGenerators.UVRegionType.FullUVSquare, Shape.RoundRectSharpCorners)); } else { throw new Exception("HUDUtil.MakeBackgroundMesh: unknown shape type!"); } }
// creates a button in the desired geometry shape public void Create() { entry = new GameObject(UniqueNames.GetNext("HUDTextEntry")); Mesh mesh = MeshGenerators.CreateTrivialRect(Width, Height, MeshGenerators.UVRegionType.FullUVSquare); backgroundMaterial = MaterialUtil.CreateFlatMaterialF(BackgroundColor); activeBackgroundMaterial = MaterialUtil.CreateFlatMaterialF(ActiveBackgroundColor); bgMesh = AppendMeshGO("background", mesh, backgroundMaterial, entry); bgMesh.transform.Rotate(Vector3.right, -90.0f); // ?? BoxPosition horzAlign = BoxPosition.CenterLeft; if (AlignmentHorz == HorizontalAlignment.Center) { horzAlign = BoxPosition.Center; } else if (AlignmentHorz == HorizontalAlignment.Right) { horzAlign = BoxPosition.CenterRight; } textMesh = GameObjectFactory.CreateTextMeshGO( "text", Text, TextColor, TextHeight, horzAlign, SceneGraphConfig.TextLabelZOffset); Vector2f toPos = BoxModel.GetBoxPosition(this, horzAlign); BoxModel.Translate(textMesh, Vector2f.Zero, toPos); AppendNewGO(textMesh, entry, false); cursor = GameObjectFactory.CreateRectangleGO("cursor", Height * 0.1f, Height * 0.8f, Colorf.VideoBlack, false); BoxModel.Translate(cursor, Vector2f.Zero, this.Bounds2D.CenterLeft, -Height * 0.1f); cursor.RotateD(Vector3f.AxisX, -90.0f); AppendNewGO(cursor, entry, false); cursor.SetVisible(false); }
override public void UpdateGeometry() { if (cylinder == null) { return; } topCap.GetComponent <MeshFilter>().sharedMesh = MeshGenerators.CreateDisc(radius, 1, 16); topCap.transform.localPosition = 0.5f * height * Vector3.up; bottomCap.GetComponent <MeshFilter>().sharedMesh = MeshGenerators.CreateDisc(radius, 1, 16); bottomCap.transform.localPosition = -0.5f * height * Vector3.up; body.SetMesh(MeshGenerators.CreateCylider(radius, height, 16)); body.transform.localPosition = -0.5f * height * Vector3.up; // if we want to scale away/towards bottom of cylinder, then we need to // translate along axis as well... Frame3f f = GetLocalFrame(CoordSpace.ObjectCoords); float fScale = cylinder.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) { topCap.GetComponent <MeshCollider>().sharedMesh = topCap.GetComponent <MeshFilter>().sharedMesh; bottomCap.GetComponent <MeshCollider>().sharedMesh = bottomCap.GetComponent <MeshFilter>().sharedMesh; body.GetComponent <MeshCollider>().sharedMesh = body.GetComponent <MeshFilter>().sharedMesh; } increment_timestamp(); }
public void Create() { menuContainer = new GameObject(UniqueNames.GetNext("HUDRadialMenu")); itemMaterial = MaterialUtil.CreateFlatMaterial(ItemColor); highlightMaterial = MaterialUtil.CreateFlatMaterial(HighlightColor); float fInnerRadius = Radius * DeadZoneRadiusFactor; centerPoint = AppendUnityPrimitiveGO("center_point", PrimitiveType.Sphere, highlightMaterial, menuContainer, false); centerPoint.transform.localScale = fInnerRadius * 0.25f * Vector3.one; int nItems = TopLevelItems.Count; float fWedgeSpan = (AngleSpan / (float)nItems) - WedgePadding; int nSlicesPerWedge = 64 / nItems; float fCurAngle = AngleShift; for (int i = 0; i < nItems; ++i) { Mesh m = MeshGenerators.CreatePuncturedDisc(fInnerRadius, Radius, nSlicesPerWedge, fCurAngle, fCurAngle + fWedgeSpan); float fMidAngleRad = (fCurAngle + fWedgeSpan * 0.5f) * Mathf.Deg2Rad; Vector2 vMid = new Vector2(Mathf.Cos(fMidAngleRad), Mathf.Sin(fMidAngleRad)); TopLevelItems[i].GO = AppendMeshGO(TopLevelItems[i].Label, m, itemMaterial, menuContainer); TopLevelItems[i].GO.transform.Rotate(Vector3.right, -90.0f); // ?? // [TODO] this is to improve font centering. Right now we do absolute centering // but visually this looks wrong because weight of font is below center-y. // Right thing would be to align at top of lowercase letters, rather than center-y // (to fix in future) float fudge = 0.0f; if (nItems == 2 && i == 1) { fudge = -0.1f; } TextLabelGenerator textGen = new TextLabelGenerator() { Text = TopLevelItems[i].Label, Scale = TextScale, Translate = vMid * (TextCenterPointFactor + fudge) * Radius, Align = TextLabelGenerator.Alignment.HVCenter }; AddVisualElements(textGen.Generate(), true); // debug: add red dots at center points to see how well text is aligned... //GameObject tmp = AppendUnityPrimitiveGO("center", PrimitiveType.Sphere, MaterialUtil.CreateStandardMaterial(Color.red), RootGameObject); //tmp.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f); //tmp.transform.position = textGen.Translate; if (TopLevelItems[i].SubItems != null) { create_sub_items(TopLevelItems[i], Radius, fCurAngle, fCurAngle + fWedgeSpan); } fCurAngle += WedgePadding + fWedgeSpan; } }
fMesh make_background_mesh() { return(new fMesh( MeshGenerators.CreateTrivialRect(Width, Height, MeshGenerators.UVRegionType.FullUVSquare))); }
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; }