public static void Translate(fGameObject go, Vector2f delta, float z = 0) { Vector3f cur = go.GetLocalPosition(); cur.x += delta.x; cur.y += delta.y; cur.z += z; go.SetLocalPosition(cur); }
void update_indicator(CreateDropPrimitiveButton button, FScene scene) { if (button == null || buttonTypes.ContainsKey(button) == false) { return; } SOType t = buttonTypes[button]; if (t.hasTag(SOType.TagPrimitive) == false) { return; } scene.DefaultPrimitiveType = t; if (indicatorButton != null) { indicatorButton.RemoveGO(indicatorGO); } indicatorButton = button; indicatorGO.SetPosition(Vector3f.Zero); indicatorGO.SetRotation(Quaternionf.Identity); indicatorGO.SetLocalScale(fIndicatorSize * Vector3f.One); indicatorGO.SetLocalPosition( indicatorGO.GetLocalPosition() + fIndicatorShift * (Vector3f.AxisY - 1 * Vector3f.AxisZ + Vector3f.AxisX)); indicatorButton.AppendNewGO(indicatorGO, indicatorButton.RootGameObject, false); indicatorGO.Show(); }
DropMaterialButton add_material_button(Cockpit cockpit, string sName, float fHUDRadius, float dx, float dy, float fButtonRadius, Material bgMaterial, SOMaterial material) { DropMaterialButton button = new DropMaterialButton() { TargetScene = cockpit.Scene, Material = material }; button.Create(fButtonRadius, bgMaterial); HUDUtil.PlaceInSphere(button, fHUDRadius, dx, dy); button.Name = sName; button.OnClicked += (s, e) => { cockpit.Scene.DefaultSOMaterial = material; if (indicatorButton != null) { indicatorButton.RemoveGO(indicatorGO); } indicatorButton = button; indicatorGO.SetPosition(Vector3f.Zero); indicatorGO.SetRotation(Quaternionf.Identity); indicatorGO.SetLocalScale(fIndicatorSize * Vector3f.One); indicatorGO.SetLocalPosition( indicatorGO.GetLocalPosition() + fIndicatorShift * (Vector3f.AxisY - 4 * Vector3f.AxisZ + Vector3f.AxisX)); indicatorButton.AppendNewGO(indicatorGO, indicatorButton.RootGameObject, false); }; button.OnDoubleClicked += (s, e) => { if (cockpit.Scene.Selected.Count > 0) { button.DoSetMaterial(cockpit.Scene.Selected, button.Material); } }; return(button); }
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); }