void InitializeSpatialInput() { Left = new SpatialDevice(); Right = new SpatialDevice(); Left.CursorDefaultMaterial = MaterialUtil.CreateTransparentMaterial(ColorUtil.ForestGreen, 0.6f); Left.CursorHitMaterial = MaterialUtil.CreateStandardMaterial(ColorUtil.ForestGreen); Left.CursorClickableMaterial = 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(Colorf.VideoRed); Right.CursorClickableMaterial = 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(SceneGraphConfig.VRHandTipOffset, SceneGraphConfig.VRHandArrowRadius, SceneGraphConfig.VRHandStickLength, SceneGraphConfig.VRHandStickWidth, 16); Left.Hand = UnityUtil.CreateMeshGO("left_hand", leftHandMesh, Left.HandMaterial); UnityUtil.TranslateMesh(leftHandMesh, 0, -SceneGraphConfig.VRHandStickLength, 0); 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(SceneGraphConfig.VRHandTipOffset, SceneGraphConfig.VRHandArrowRadius, SceneGraphConfig.VRHandStickLength, SceneGraphConfig.VRHandStickWidth, 16); Right.Hand = UnityUtil.CreateMeshGO("right_hand", rightHandMesh, Right.HandMaterial); UnityUtil.TranslateMesh(rightHandMesh, 0, -SceneGraphConfig.VRHandStickLength, 0); 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; }
virtual public AxisAlignedBox3f GetTransformedBoundingBox() { return(UnityUtil.GetBoundingBox(RootGameObject)); }
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(); }