////////////////////// public void Init() { Material floorMat = new Material(Shader.FromFile("floor_shader.hlsl")); floorMat.Transparency = Transparency.Blend; floorMat.SetVector("radius", new Vec4(5, 10, 0, 0)); floorMat.QueueOffset = -11; floorMesh = Model.FromMesh(Mesh.GeneratePlane(new Vec2(40, 40), Vec3.Up, Vec3.Forward), floorMat); floorTr = Matrix.TR(new Vec3(0, -1.5f, 0), Quat.Identity); demoSelectPose.position = new Vec3(0, 0, -0.6f); demoSelectPose.orientation = Quat.LookDir(-Vec3.Forward); Tests.FindTests(); Tests.SetTestActive(startTest); Tests.Initialize(); for (int i = 0; i < Tests.DemoCount; i++) { demoNames.Add(Tests.GetDemoName(i).Substring("Demo".Length)); } if (!Tests.IsTesting) { SK.AddStepper(new RenderCamera(new Pose(0.3f, 0, .5f, Quat.FromAngles(0, -90, 0)), 1000, 1000)); } }
/// <summary>Show a file picker to the user! If one is already up, it'll be cancelled out, /// and this one will replace it.</summary> /// <param name="mode">For opening files, or for saving them?</param> /// <param name="initialFolder">The starting folder. By default (or null), this'll just be /// the working directory.</param> /// <param name="onSelectFile">The function to call when the user has selected a file.</param> /// <param name="onCancel">If the file selection has been cancelled, this'll get called!</param> /// <param name="filters">What file types should show up in the picker?</param> public static void Show(FilePickerMode mode, string initialFolder, Action <string> onSelectFile, Action onCancel, params FileFilter[] filters) { if (_inst != null) { _inst._onCancel?.Invoke(); } if (_inst == null) { _inst = SK.AddStepper(new FilePicker()); Vec3 pos = Input.Head.position + Input.Head.Forward * .5f + Input.Head.Up * 0.2f; _inst._windowPose = new Pose(pos, Quat.LookAt(pos, Input.Head.position)); } _inst.Setup(mode, initialFolder, onSelectFile, onCancel, filters); }
public void Initialize() { // StereoKit will support world understanding features as core // functionality when they become available in OpenXR! In the // meantime, here's some tools for doing this through the Mirage APIs // If the system is capable of acquiring an occlusion mesh, do that! // Otherwise, we can also provide any mesh or model for testing // purposes! occluder = SK.AddStepper(OcclusionMesh.Capable ? new OcclusionMesh() : OcclusionMesh.FromSimulation(Mesh.GeneratePlane(Vec2.One * 10, 10))); // Make it visible and obvious for the demo, by default the material // will work like a solid, invisible occluder. occluder.Material[MatParamName.ColorTint] = new Color(1, 0, 0); occluder.Material.Wireframe = true; }
/// <summary> /// Initializes a new instance of the <see cref="StereoKitComponent"/> class. /// </summary> /// <param name="pipeline">The pipeline to add the component to.</param> /// <param name="name">An optional name for the component.</param> public StereoKitComponent(Pipeline pipeline, string name = nameof(StereoKitComponent)) { this.name = name; // Defer call to SK.AddStepper(this) to PipelineRun to ensure derived classes have finished construction! // Otherwise IStepper.Initialize() could get called before this object is fully constructed. pipeline.PipelineRun += (_, _) => { if (SK.AddStepper(this) == default) { throw new Exception($"Unable to add {this} as a Stepper to StereoKit."); } }; // Remove this stepper when pipeline is no longer running, otherwise Step() will continue to be called! pipeline.PipelineCompleted += (_, _) => { SK.RemoveStepper(this); }; }
static void Main(string[] args) { // Initialize StereoKit! During initialization, we can prepare a few // settings, like the assetsFolder and appName. assetsFolder the // folder that StereoKit will look for assets in when provided a // relative folder name. Settings can also be told to make a // flatscreen app, or how to behave if the preferred initialization // mode fails. SKSettings settings = new SKSettings { appName = "StereoKitPaintTutorial", assetsFolder = "Assets", }; if (!SK.Initialize(settings)) { Environment.Exit(1); } // This is a simple radial hand menu where we'll store some quick // actions! It's activated by a grip motion, and is great for fast, // gesture-like activation of menu items. It also can be used with // multiple HandRadialLayers to nest commands in sub-menus. // // Steppers are classes that implement the IStepper interface, and // once added to StereoKit's stepper list, will have their Step // method called each frame! This is a great way to add fire-and- // forget objects or systems that need to update each frame. SK.AddStepper(new HandMenuRadial( new HandRadialLayer("Root", -90, new HandMenuItem("Undo", null, () => activePainting?.Undo()), new HandMenuItem("Redo", null, () => activePainting?.Redo())))); // Initialize the palette menu, see PaletteMenu.cs! This class // manages the palette UI object for manipulating our brush stroke // size and color. paletteMenu = new PaletteMenu(); // Step the application each frame, until StereoKit is told to exit! // The callback code here is called every frame after input and // system events, but before the draw events! while (SK.Step(() => { // Send input information to the painting, it will handle this // info to create brush strokes. This will also draw the painting // too! activePainting.Step(Handed.Right, paletteMenu.PaintColor, paletteMenu.PaintSize); // Step our palette UI! paletteMenu.Step(); // Step our application's menu! This includes Save/Load Clear and // Quit commands. StepMenuWindow(); })) { ; } // We're done! Clean up StereoKit and all its resources :) SK.Shutdown(); }
public void Initialize() { /// :CodeDoc: Guides Using Hands /// ## Accessing Joints /// /// ![Hand with joints]({{site.url}}/img/screenshots/HandAxes.jpg) /// /// Since hands are so central to interaction, accessing hand information needs /// to be really easy to get! So here's how you might find the fingertip of the right /// hand! If you ignore IsTracked, this'll give you the last known position for that /// finger joint. Hand hand = Input.Hand(Handed.Right); if (hand.IsTracked) { Vec3 fingertip = hand[FingerId.Index, JointId.Tip].position; } /// Pretty straightforward! And if you prefer calling a function instead of using the /// [] operator, that's cool too! You can call `hand.Get(FingerId.Index, JointId.Tip)` /// instead! /// /// If that's too granular for you, there's easy ways to check for pinching and /// gripping! Pinched will tell you if a pinch is currently happening, JustPinched /// will tell you if it just started being pinched this frame, and JustUnpinched will /// tell you if the pinch just stopped this frame! if (hand.IsPinched) { } if (hand.IsJustPinched) { } if (hand.IsJustUnpinched) { } if (hand.IsGripped) { } if (hand.IsJustGripped) { } if (hand.IsJustUngripped) { } /// These are all convenience functions wrapping the `hand.pinchState` bit-flag, so you /// can also use that directly if you want to do some bit-flag wizardry! /// :End: /// :CodeSample: HandMenuRadial HandRadialLayer HandMenuItem /// ### Basic layered hand menu /// /// The HandMenuRadial is an `IStepper`, so it should be registered with /// `StereoKitApp.AddStepper` so it can run by itself! It's recommended to /// keep track of it anyway, so you can remove it when you're done with it /// via `StereoKitApp.RemoveStepper` /// /// The constructor uses a params style argument list that makes it easy and /// clean to provide lists of items! This means you can assemble the whole /// menu on a single 'line'. You can still pass arrays instead if you prefer /// that! handMenu = SK.AddStepper(new HandMenuRadial( new HandRadialLayer("Root", new HandMenuItem("File", null, null, "File"), new HandMenuItem("Edit", null, null, "Edit"), new HandMenuItem("About", null, () => Log.Info(SK.VersionName)), new HandMenuItem("Cancel", null, null)), new HandRadialLayer("File", new HandMenuItem("New", null, () => Log.Info("New")), new HandMenuItem("Open", null, () => Log.Info("Open")), new HandMenuItem("Close", null, () => Log.Info("Close")), new HandMenuItem("Back", null, null, HandMenuAction.Back)), new HandRadialLayer("Edit", new HandMenuItem("Copy", null, () => Log.Info("Copy")), new HandMenuItem("Paste", null, () => Log.Info("Paste")), new HandMenuItem("Back", null, null, HandMenuAction.Back)))); /// :End: Tests.RunForFrames(2); Tests.Hand(new HandJoint[] { new HandJoint(new Vec3(-0.529f, -0.198f, -0.126f), new Quat(-0.744f, -0.530f, 0.156f, -0.376f), 0.004f), new HandJoint(new Vec3(-0.529f, -0.198f, -0.126f), new Quat(-0.744f, -0.530f, 0.156f, -0.376f), 0.010f), new HandJoint(new Vec3(-0.533f, -0.175f, -0.090f), new Quat(-0.786f, -0.550f, 0.126f, -0.254f), 0.009f), new HandJoint(new Vec3(-0.544f, -0.158f, -0.069f), new Quat(-0.729f, -0.564f, 0.027f, -0.387f), 0.008f), new HandJoint(new Vec3(-0.557f, -0.150f, -0.065f), new Quat(-0.585f, -0.548f, -0.140f, -0.582f), 0.006f), new HandJoint(new Vec3(-0.521f, -0.182f, -0.136f), new Quat(-0.277f, -0.826f, 0.317f, -0.376f), 0.004f), new HandJoint(new Vec3(-0.550f, -0.135f, -0.102f), new Quat(-0.277f, -0.826f, 0.317f, -0.376f), 0.009f), new HandJoint(new Vec3(-0.571f, -0.112f, -0.082f), new Quat(-0.244f, -0.843f, 0.256f, -0.404f), 0.008f), new HandJoint(new Vec3(-0.585f, -0.102f, -0.070f), new Quat(-0.200f, -0.866f, 0.165f, -0.428f), 0.007f), new HandJoint(new Vec3(-0.593f, -0.098f, -0.064f), new Quat(-0.172f, -0.874f, 0.110f, -0.440f), 0.005f), new HandJoint(new Vec3(-0.527f, -0.178f, -0.144f), new Quat(-0.185f, -0.817f, 0.370f, -0.401f), 0.004f), new HandJoint(new Vec3(-0.559f, -0.132f, -0.119f), new Quat(-0.185f, -0.817f, 0.370f, -0.401f), 0.009f), new HandJoint(new Vec3(-0.582f, -0.101f, -0.104f), new Quat(-0.175f, -0.809f, 0.371f, -0.420f), 0.008f), new HandJoint(new Vec3(-0.599f, -0.089f, -0.092f), new Quat(-0.109f, -0.856f, 0.245f, -0.443f), 0.007f), new HandJoint(new Vec3(-0.608f, -0.084f, -0.086f), new Quat(-0.075f, -0.871f, 0.180f, -0.450f), 0.005f), new HandJoint(new Vec3(-0.535f, -0.178f, -0.152f), new Quat(-0.132f, -0.786f, 0.408f, -0.445f), 0.003f), new HandJoint(new Vec3(-0.568f, -0.136f, -0.137f), new Quat(-0.132f, -0.786f, 0.408f, -0.445f), 0.008f), new HandJoint(new Vec3(-0.590f, -0.106f, -0.130f), new Quat(-0.131f, -0.762f, 0.432f, -0.464f), 0.007f), new HandJoint(new Vec3(-0.607f, -0.092f, -0.122f), new Quat(-0.071f, -0.810f, 0.332f, -0.477f), 0.006f), new HandJoint(new Vec3(-0.617f, -0.086f, -0.117f), new Quat(-0.029f, -0.836f, 0.260f, -0.482f), 0.004f), new HandJoint(new Vec3(-0.544f, -0.183f, -0.159f), new Quat(-0.060f, -0.749f, 0.481f, -0.452f), 0.003f), new HandJoint(new Vec3(-0.576f, -0.143f, -0.152f), new Quat(-0.060f, -0.749f, 0.481f, -0.452f), 0.007f), new HandJoint(new Vec3(-0.594f, -0.119f, -0.154f), new Quat(-0.061f, -0.684f, 0.534f, -0.493f), 0.006f), new HandJoint(new Vec3(-0.607f, -0.108f, -0.152f), new Quat(0.002f, -0.745f, 0.444f, -0.498f), 0.005f), new HandJoint(new Vec3(-0.616f, -0.102f, -0.150f), new Quat(0.045f, -0.780f, 0.378f, -0.496f), 0.004f), new HandJoint(new Vec3(-0.548f, -0.161f, -0.137f), new Quat(-0.267f, 0.849f, 0.204f, 0.407f), 0.000f), new HandJoint(new Vec3(-0.548f, -0.161f, -0.137f), new Quat(-0.267f, 0.849f, 0.204f, 0.407f), 0.000f) }); }
public void Initialize() { avatar = SK.AddStepper <AvatarSkeleton>(); }