static public fGameObject EmitDebugMesh(string name, DMesh3 meshIn, Colorf color, GameObject parent = null, bool bIsInWorldPos = true) { DMesh3 mesh = new DMesh3(meshIn); if (FPlatform.InMainThread() == false) { ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugMesh(name, mesh, color, parent, bIsInWorldPos); }); return(null); } fMeshGameObject fMeshGO = GameObjectFactory.CreateMeshGO(name, new fMesh(mesh), false, true); fMeshGO.SetMaterial(MaterialUtil.CreateStandardMaterialF(color)); if (parent != null) { parent.AddChild(fMeshGO, bIsInWorldPos); } return(fMeshGO); }
public static HUDButton CreateGeometryIconClickButton(HUDShape shape, float fHUDRadius, float fAngleHorz, float fAngleVert, Colorf bgColor, IGameObjectGenerator addGeometry = null) { fMaterial mat = (bgColor.a == 1.0f) ? MaterialUtil.CreateStandardMaterialF(bgColor) : MaterialUtil.CreateTransparentMaterialF(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( fMesh mesh, Colorf color, float fMeshScale, Quaternionf meshRotation, HUDSurface hudSurf, float dx, float dy, IGameObjectGenerator addGeometry = null) { fMaterial mat = (color.a < 1.0f) ? MaterialUtil.CreateTransparentMaterialF(color, color.a) : MaterialUtil.CreateStandardMaterialF(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); }
public static HUDButton CreateMeshClickButton( fMesh mesh, Colorf color, float fMeshScale, Quaternionf meshRotation, float fHUDRadius, float fAngleHorz, float fAngleVert, IGameObjectGenerator addGeometry = null) { fMaterial mat = (color.a < 1.0f) ? MaterialUtil.CreateTransparentMaterialF(color, color.a) : MaterialUtil.CreateStandardMaterialF(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); }
static public fGameObject EmitDebugBox(string name, Box3d box, Colorf color, GameObject parent = null, bool bIsInWorldPos = true) { if (FPlatform.InMainThread() == false) { ThreadMailbox.PostToMainThread(() => { DebugUtil.EmitDebugBox(name, box, color, parent, bIsInWorldPos); }); return(null); } TrivialBox3Generator boxgen = new TrivialBox3Generator() { Box = box, NoSharedVertices = true, Clockwise = true }; boxgen.Generate(); DMesh3 mesh = boxgen.MakeDMesh(); fMeshGameObject fMeshGO = GameObjectFactory.CreateMeshGO(name, new fMesh(mesh), false, true); fMeshGO.SetMaterial(MaterialUtil.CreateStandardMaterialF(color)); if (parent != null) { parent.AddChild(fMeshGO, bIsInWorldPos); } return(fMeshGO); }
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); }
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; }