The Mixed Reality Forums here are no longer being used or maintained.
There are a few other places we would like to direct you to for support, both from Microsoft and from the community.
The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.
For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.
If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.
And always feel free to hit us up on Twitter @MxdRealityDev.
Draw line in GameScene
Hey guys,
I have a question regarding to the Bezier Curve drawing. It seems like Handles.Drawline() only works for Scene view....How I can draw lines and curves in game view?
Thanks.
Best Answers
-
OptionsJackson mod
I would start with this function:
http://docs.unity3d.com/ScriptReference/Handles.MakeBezierPoints.htmlIt is going to give you an array of Vector3's representing the Bezier curve, then you can draw a geometric primitive at those points with:
http://docs.unity3d.com/ScriptReference/GameObject.CreatePrimitive.htmlfor (int i = 0; i < bezierPoints.Length; i++) {
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.scale = Vector3.one / 3.0f;
cube.transform.position = bezierPoints[i];
}You could also create a single mesh with these points using:
http://docs.unity3d.com/ScriptReference/Mesh.html5
Answers
Handles is a Unity class that is only supported in the Editor:
http://docs.unity3d.com/ScriptReference/Handles.html
If you want to render geometry on your curve, you will probably want to render a set of primitives at different points on the line (with respect to the line's rotation at that point)
@Jackson Is there any sample that I can follow somehow?
I would start with this function:
http://docs.unity3d.com/ScriptReference/Handles.MakeBezierPoints.html
It is going to give you an array of Vector3's representing the Bezier curve, then you can draw a geometric primitive at those points with:
http://docs.unity3d.com/ScriptReference/GameObject.CreatePrimitive.html
for (int i = 0; i < bezierPoints.Length; i++) {
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.scale = Vector3.one / 3.0f;
cube.transform.position = bezierPoints[i];
}
You could also create a single mesh with these points using:
http://docs.unity3d.com/ScriptReference/Mesh.html
@Jackson That makes great sense, thanks!
@Jackson A quick follow up, how can I get to the points array that build with Handles? aren't they in the customized Editor?
Just saw that - It looks like you might need to implement your own Bezier curve function to run in the game. This can be done as a function of time to get all of the positions from the start (time = 0) to the end (time = 1) of the curve.
Math:
http://mathworld.wolfram.com/BezierCurve.html
You could also probably find some Unity source code that you might be able to use in the asset store or some Bezier curve code tutorials online!
Here's one tutorial:
http://devmag.org.za/2011/04/05/bzier-curves-a-tutorial/
@Jackson I figured it out:)
I can't help having a try. Thanks for your sharing.
For lines take a look at Unity LineRenderer component which you can add to a GameObject. If you figure out Bezier curve points, you can likely feed them to LineRenderer . Example for SetPositions method here on sine wave. These are available in Unity 5.6.
In Formation, Inc.
I approve randyiform, I used the LineRenderer to draw in the scene and it works fine!