public virtual void Create() { rootGO = new GameObject(UniqueNames.GetNext("HUDSlider")); fMaterial useMaterial = MaterialUtil.CreateFlatMaterialF(bgColor); backgroundGO = GameObjectFactory.CreateRectangleGO("background", SliderWidth, SliderHeight, useMaterial, true, true); MaterialUtil.DisableShadows(backgroundGO); backgroundGO.RotateD(Vector3f.AxisX, -90.0f); // ?? AppendNewGO(backgroundGO, rootGO, false); handleMaterial = MaterialUtil.CreateFlatMaterialF(handleColor); handleGO = create_handle_go(handleMaterial); if (handleGO != null) { handleGO.Translate(0.001f * Vector3f.AxisY, true); AppendNewGO(handleGO, rootGO, false); handleStart = handleGO.GetLocalFrame(); } create_visuals_geometry(); TickMaterial = MaterialUtil.CreateFlatMaterialF(tickColor); update_geometry(); }
/// <summary> /// This is very hacky. /// </summary> public static void AddDropShadow(HUDStandardItem item, Colorf color, float falloffWidth, Vector2f offset, float fZShift) { if (item is IBoxModelElement == false) { throw new Exception("HUDUtil.AddDropShadow: can only add drop shadow to IBoxModelElement"); } // [TODO] need interface that provides a HUDShape? var shape = item as IBoxModelElement; float w = shape.Size2D.x + falloffWidth; float h = shape.Size2D.y + falloffWidth; fRectangleGameObject meshGO = GameObjectFactory.CreateRectangleGO("shadow", w, h, color, false); meshGO.RotateD(Vector3f.AxisX, -90.0f); fMaterial dropMat = MaterialUtil.CreateDropShadowMaterial(color, w, h, falloffWidth); meshGO.SetMaterial(dropMat); item.AppendNewGO(meshGO, item.RootGameObject, false); BoxModel.Translate(meshGO, offset, fZShift); Vector3 posW = item.RootGameObject.PointToWorld(meshGO.GetLocalPosition()); ((Material)dropMat).SetVector("_Center", new Vector4(posW.x, posW.y, posW.z, 0)); }
/// <summary> /// Create GO / geometry for a single tick, centered at origin /// </summary> protected virtual fGameObject create_tick_go(Vector2f tickSize, fMaterial baseMaterial) { fRectangleGameObject go = GameObjectFactory.CreateRectangleGO("tick", tickSize.x, tickSize.y, baseMaterial, true, false); MaterialUtil.DisableShadows(go); go.RotateD(Vector3f.AxisX, -90.0f); return(go); }
/// <summary> /// This is very hacky. /// </summary> public static void AddDropShadow(HUDStandardItem item, Cockpit cockpit, Colorf color, float falloffWidthPx, Vector2f offset, float fZShift, bool bTrackCockpitScaling = true) { if (item is IBoxModelElement == false) { throw new Exception("HUDUtil.AddDropShadow: can only add drop shadow to IBoxModelElement"); } float falloffWidth = falloffWidthPx * cockpit.GetPixelScale(); // [TODO] need interface that provides a HUDShape? var shape = item as IBoxModelElement; float w = shape.Size2D.x + falloffWidth; float h = shape.Size2D.y + falloffWidth; fRectangleGameObject meshGO = GameObjectFactory.CreateRectangleGO("shadow", w, h, color, false); meshGO.RotateD(Vector3f.AxisX, -90.0f); fMaterial dropMat = MaterialUtil.CreateDropShadowMaterial(color, w, h, falloffWidth); meshGO.SetMaterial(dropMat); item.AppendNewGO(meshGO, item.RootGameObject, false); BoxModel.Translate(meshGO, offset, fZShift); if (bTrackCockpitScaling) { PreRenderBehavior pb = meshGO.AddComponent <PreRenderBehavior>(); pb.ParentFGO = meshGO; pb.AddAction(() => { Vector3f posW = item.RootGameObject.PointToWorld(meshGO.GetLocalPosition()); ((Material)dropMat).SetVector("_Center", new Vector4(posW.x, posW.y, posW.z, 0)); float curWidth = falloffWidthPx * cockpit.GetPixelScale(); Vector2f origSize = shape.Size2D + falloffWidth * Vector2f.One; Vector2f size = cockpit.GetScaledDimensions(origSize); float ww = size.x; float hh = size.y; ((Material)dropMat).SetVector("_Extents", new Vector4(ww / 2, hh / 2, 0, 0)); float newWidth = falloffWidthPx * cockpit.GetPixelScale(); ((Material)dropMat).SetFloat("_FalloffWidth", newWidth); }); } }
// 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); }